diff --git a/src/main/java/com/chint/manage/controller/ManageController.java b/src/main/java/com/chint/manage/controller/ManageController.java index ac2b672d..6d456235 100644 --- a/src/main/java/com/chint/manage/controller/ManageController.java +++ b/src/main/java/com/chint/manage/controller/ManageController.java @@ -1,11 +1,13 @@ package com.chint.manage.controller; import com.chint.infrastructure.util.PageResult; -import com.chint.manage.entity.dto.StandardQueryDto; +import com.chint.infrastructure.util.Result; +import com.chint.manage.entity.dto.OrderPageDto; import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.excel.OrderExceedStandardExcel; -import com.chint.manage.entity.excel.TrainOrderDetailExcel; -import com.chint.manage.entity.dto.ConsumptionDetailDto; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; +import com.chint.manage.entity.query.StandardQuery; import com.chint.manage.service.ManageService; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -14,7 +16,10 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.io.File; import java.io.FileInputStream; @@ -31,13 +36,13 @@ public class ManageController { @ApiOperation("消费明细查询接口") @PostMapping("/query") - public PageResult query(@RequestBody ConsumptionDetailDto dto){ + public PageResult query(@RequestBody ConsumptionDetailQuery dto){ return manageService.pageConsumptionDetail(dto); } @ApiOperation("消费明细导出接口") @PostMapping("/export") - public ResponseEntity export(@RequestBody ConsumptionDetailDto dto) { + public ResponseEntity export(@RequestBody ConsumptionDetailQuery dto) { dto.setPageNum(1); dto.setPageSize(Integer.MAX_VALUE); File file = manageService.saveConsumptionDetail(dto); @@ -55,13 +60,13 @@ public class ManageController { @ApiOperation("超标报表查询接口") @PostMapping("/standard/query") - public PageResult standardQuery(@RequestBody StandardQueryDto dto){ + public PageResult standardQuery(@RequestBody StandardQuery dto){ return manageService.standardQuery(dto); } @ApiOperation("超标报表导出接口") @PostMapping("/standard/export") - public ResponseEntity standardExport(@RequestBody StandardQueryDto dto){ + public ResponseEntity standardExport(@RequestBody StandardQuery dto){ dto.setPageNum(1); dto.setPageSize(Integer.MAX_VALUE); File file = manageService.standardExport(dto); @@ -77,4 +82,10 @@ public class ManageController { .body(resource); } + @ApiOperation("行程单查询接口") + @PostMapping("/order/pageQuery") + public Result> orderPageQuery(@RequestBody OrderPageQuery dto){ + return manageService.orderPageQuery(dto); + } + } diff --git a/src/main/java/com/chint/manage/entity/dto/OrderPageDto.java b/src/main/java/com/chint/manage/entity/dto/OrderPageDto.java new file mode 100644 index 00000000..2986af22 --- /dev/null +++ b/src/main/java/com/chint/manage/entity/dto/OrderPageDto.java @@ -0,0 +1,50 @@ +package com.chint.manage.entity.dto; + +import com.chint.application.dtos.response.LocationRes; +import com.chint.domain.aggregates.order.ApprovalEvent; +import com.chint.domain.aggregates.order.Leg; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class OrderPageDto { + private Long routeId; + //差旅订单单号 + private String routeOrderNo; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime startTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime endTime; + private String userId; + private String userName; + //差标等级 + private String standardLevel; + //申请说明 + private String instructions; + private String actualOrderNo; + private List approveEvents; + + private String approvalStatus; + + private List legItems; + + //差旅订单总价值 + private List locationResList; + + public String getApprovalStatus() { + if (this.approveEvents != null && !this.approveEvents.isEmpty()) { + ApprovalEvent lastApprovalEvent = getLastApprovalEvent(); + if (lastApprovalEvent != null) { + lastApprovalEvent.reloadStatus(); + this.approvalStatus = lastApprovalEvent.getEventName(); + } + } + return approvalStatus; + } + private ApprovalEvent getLastApprovalEvent() { + return this.approveEvents.isEmpty() ? null : this.approveEvents.get(this.approveEvents.size() - 1); + } +} diff --git a/src/main/java/com/chint/manage/entity/dto/ConsumptionDetailDto.java b/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java similarity index 74% rename from src/main/java/com/chint/manage/entity/dto/ConsumptionDetailDto.java rename to src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java index 34285e48..dfd37b77 100644 --- a/src/main/java/com/chint/manage/entity/dto/ConsumptionDetailDto.java +++ b/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java @@ -1,4 +1,4 @@ -package com.chint.manage.entity.dto; +package com.chint.manage.entity.query; import com.chint.domain.value_object.BaseQuery; import lombok.Data; @@ -9,7 +9,7 @@ import lombok.Data; * @Date:2024/5/8 8:58 */ @Data -public class ConsumptionDetailDto extends BaseQuery{ +public class ConsumptionDetailQuery extends BaseQuery{ /** * 0-火车 1飞机 2酒店 3打车 */ diff --git a/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java b/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java new file mode 100644 index 00000000..22345f3e --- /dev/null +++ b/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java @@ -0,0 +1,14 @@ +package com.chint.manage.entity.query; + +import com.chint.domain.value_object.BaseQuery; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class OrderPageQuery extends BaseQuery { + private String supplierName;// 申请人 + private String actualOrderNo; //申请单号 + private List userIds=new ArrayList<>(); +} diff --git a/src/main/java/com/chint/manage/entity/dto/StandardQueryDto.java b/src/main/java/com/chint/manage/entity/query/StandardQuery.java similarity index 75% rename from src/main/java/com/chint/manage/entity/dto/StandardQueryDto.java rename to src/main/java/com/chint/manage/entity/query/StandardQuery.java index f4a2ce34..bac68d28 100644 --- a/src/main/java/com/chint/manage/entity/dto/StandardQueryDto.java +++ b/src/main/java/com/chint/manage/entity/query/StandardQuery.java @@ -1,10 +1,10 @@ -package com.chint.manage.entity.dto; +package com.chint.manage.entity.query; import com.chint.domain.value_object.BaseQuery; import lombok.Data; @Data -public class StandardQueryDto extends BaseQuery { +public class StandardQuery extends BaseQuery { private String applicant="";// 申请人 private String companyName=""; // 出差公司 private String orderNo=""; //订单号 diff --git a/src/main/java/com/chint/manage/mapper/JdbcConsumptionDetailRepository.java b/src/main/java/com/chint/manage/mapper/JdbcConsumptionDetailRepository.java index a70cd6ca..f93e1b2e 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcConsumptionDetailRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcConsumptionDetailRepository.java @@ -1,15 +1,14 @@ package com.chint.manage.mapper; -import com.chint.domain.aggregates.order.OrderDetail; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.dto.OrderPageDto; import com.chint.manage.entity.excel.BaseExcel; -import com.chint.manage.entity.excel.TrainOrderDetailExcel; -import com.chint.manage.entity.dto.ConsumptionDetailDto; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; public interface JdbcConsumptionDetailRepository { - Page findAllByProductType(String productType, String param2, String param3, Pageable pageable); + Page orderPageQueryByDto(OrderPageQuery dto); - PageResult pageConsumptionDetail(ConsumptionDetailDto dto); + PageResult pageConsumptionDetail(ConsumptionDetailQuery dto); } \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java index 5bd2dca5..16eefa9f 100644 --- a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java +++ b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java @@ -2,12 +2,17 @@ package com.chint.manage.mapper.impl; import com.chint.domain.aggregates.order.*; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.dto.OrderPageDto; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; import com.chint.manage.entity.excel.*; -import com.chint.manage.entity.dto.ConsumptionDetailDto; import com.chint.manage.mapper.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.*; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; @@ -39,30 +44,32 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Override - public Page findAllByProductType(String productType, String supplierName, String orderNo, Pageable pageable) { - String query = "SELECT * FROM order_detail " + - "WHERE product_type = :productType " + - "AND (:supplierName IS NULL OR supplier_name = :supplierName) " + - "AND (:orderNo IS NULL OR order_no = :orderNo) " + - "ORDER BY order_id"; + public Page orderPageQueryByDto(OrderPageQuery dto) { + String query = "SELECT * FROM route_order " + + "WHERE 1 = 1 " + + "AND (:actualOrderNo IS NULL OR actual_order_no = :actualOrderNo ) "; + + if (!dto.getUserIds().isEmpty()) { + query+="AND user_id IN (:userIds)"; + } Map params = new HashMap<>(); - params.put("productType", productType); - params.put("supplierName", supplierName); - params.put("orderNo", orderNo); - params.put("offset", pageable.getOffset()); - params.put("limit", pageable.getPageSize()); + params.put("actualOrderNo", dto.getActualOrderNo()); + PageRequest pageRequest = PageRequest + .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("route_id").descending()); + params.put("offset", pageRequest.getOffset()); + params.put("limit", pageRequest.getPageSize()); String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(OrderDetail.class)); + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(OrderPageDto.class)); long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); - return new PageImpl<>(results, pageable, count); + return new PageImpl<>(results, pageRequest, count); } @Override - public PageResult pageConsumptionDetail(ConsumptionDetailDto dto) { + public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { if (dto.getUserName()==null){ dto.setUserName(""); } diff --git a/src/main/java/com/chint/manage/service/ManageService.java b/src/main/java/com/chint/manage/service/ManageService.java index 2e2305fd..66c46e42 100644 --- a/src/main/java/com/chint/manage/service/ManageService.java +++ b/src/main/java/com/chint/manage/service/ManageService.java @@ -1,8 +1,12 @@ package com.chint.manage.service; +import com.chint.application.dtos.response.RouteOrderPageRes; import com.chint.infrastructure.util.PageResult; -import com.chint.manage.entity.dto.ConsumptionDetailDto; -import com.chint.manage.entity.dto.StandardQueryDto; +import com.chint.infrastructure.util.Result; +import com.chint.manage.entity.dto.OrderPageDto; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; +import com.chint.manage.entity.query.StandardQuery; import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.excel.OrderExceedStandardExcel; @@ -15,11 +19,13 @@ import java.io.File; */ public interface ManageService { - PageResult pageConsumptionDetail(ConsumptionDetailDto dto); + PageResult pageConsumptionDetail(ConsumptionDetailQuery dto); - File saveConsumptionDetail(ConsumptionDetailDto dto); + File saveConsumptionDetail(ConsumptionDetailQuery dto); - PageResult standardQuery(StandardQueryDto dto); + PageResult standardQuery(StandardQuery dto); - File standardExport(StandardQueryDto dto); + File standardExport(StandardQuery dto); + + Result> orderPageQuery(OrderPageQuery dto); } diff --git a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java index 85a1594b..5b660f01 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -1,22 +1,28 @@ package com.chint.manage.service.impl; +import com.chint.application.dtos.response.LocationRes; +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.user.User; +import com.chint.domain.repository.UserRepository; +import com.chint.domain.service.LegDomainService; +import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.util.PageResult; +import com.chint.infrastructure.util.Result; import com.chint.manage.entity.OrderExceedStandard; -import com.chint.manage.entity.dto.ConsumptionDetailDto; -import com.chint.manage.entity.dto.StandardQueryDto; +import com.chint.manage.entity.dto.OrderPageDto; import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.excel.OrderExceedStandardExcel; -import com.chint.manage.entity.excel.TrainOrderDetailExcel; -import com.chint.manage.entity.dto.ConsumptionDetailDto; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; +import com.chint.manage.entity.query.StandardQuery; import com.chint.manage.mapper.JdbcOrderExceedStandardRepository; import com.chint.manage.mapper.impl.JdbcConsumptionDetailRepositoryImpl; import com.chint.manage.service.ManageService; import com.chint.manage.util.ExcelUtil; - import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; @@ -24,6 +30,10 @@ import org.springframework.stereotype.Service; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + +import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; /** * @@ -36,19 +46,25 @@ public class ManageServiceImpl implements ManageService { private JdbcConsumptionDetailRepositoryImpl jdbcConsumptionDetailRepository; @Autowired private JdbcOrderExceedStandardRepository jdbcOrderExceedStandardRepository; + @Autowired + private LegDomainService legDomainService; + @Autowired + private UserRepository userRepository; + @Autowired + private JdbcRouteRepository jdbcRouteRepository; @Override - public PageResult pageConsumptionDetail(ConsumptionDetailDto dto) { + public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { return jdbcConsumptionDetailRepository.pageConsumptionDetail(dto); } @Override - public File saveConsumptionDetail(ConsumptionDetailDto dto) { + public File saveConsumptionDetail(ConsumptionDetailQuery dto) { return ExcelUtil.exportReport(jdbcConsumptionDetailRepository.pageConsumptionDetail(dto).getRecords()); } @Override - public PageResult standardQuery(StandardQueryDto dto) { + public PageResult standardQuery(StandardQuery dto) { PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndCompanyNameContainsAndActualOrderNoContainsAndOrderNoContains(dto.getApplicant(), @@ -62,10 +78,34 @@ public class ManageServiceImpl implements ManageService { } @Override - public File standardExport(StandardQueryDto dto) { + public File standardExport(StandardQuery dto) { return ExcelUtil.exportReport(standardQuery(dto).getRecords()); } + @Override + public Result> orderPageQuery(OrderPageQuery dto) { + + Page page= jdbcConsumptionDetailRepository.orderPageQueryByDto(dto); + //处理信息 + List list=page.getContent(); + //查询行程和审批单信息 + List routeIdList=list.stream().map(OrderPageDto::getRouteId).toList(); + List routeOrders=jdbcRouteRepository.findByRouteIdIn(routeIdList); + + List orders = list + .stream() + .map(routeOrder -> { + RouteOrder order=routeOrders.stream().filter(s->s.getRouteId().equals(routeOrder.getRouteId())).toList().get(0); + routeOrder.setApproveEvents(order.getApproveEvents()); + routeOrder.setLegItems(order.getLegItems()); + legDomainService.queryLocation(routeOrder.getLegItems()); + User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); + return getRouteOrderPageRes(routeOrder, user); + }) + .toList(); + return Result.Success(SUCCESS,PageResult.totalPageNum(page.getTotalElements(), orders)); + } + private static List getOrderExceedStandardExcels(Page page) { List orderList = page.getContent(); List excelList = new ArrayList<>(); @@ -80,4 +120,18 @@ public class ManageServiceImpl implements ManageService { } return excelList; } + + private static OrderPageDto getRouteOrderPageRes(OrderPageDto res, User user) { + List legItems=res.getLegItems(); + List locationRes = legItems + .stream() + .flatMap(leg -> Stream.of(leg.getOriginLocation(), leg.getDestinationLocation())) + .map(LocationRes::copyFrom) + .distinct() + .filter(Objects::nonNull) + .toList(); + res.setLocationResList(locationRes); + res.setUserName(user.getName()); + return res; + } } diff --git a/src/test/java/com/chint/ManageTest.java b/src/test/java/com/chint/ManageTest.java index cfbad8b0..c1ec1bda 100644 --- a/src/test/java/com/chint/ManageTest.java +++ b/src/test/java/com/chint/ManageTest.java @@ -4,13 +4,17 @@ import com.chint.domain.aggregates.order.OrderDetail; import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import com.chint.infrastructure.util.PageResult; import com.chint.manage.entity.OrderExceedStandard; -import com.chint.manage.entity.dto.ConsumptionDetailDto; +import com.chint.manage.entity.dto.OrderPageDto; import com.chint.manage.entity.excel.BaseExcel; +import com.chint.manage.entity.query.ConsumptionDetailQuery; +import com.chint.manage.entity.query.OrderPageQuery; import com.chint.manage.mapper.JdbcOrderExceedStandardRepository; +import com.chint.manage.mapper.impl.JdbcConsumptionDetailRepositoryImpl; import com.chint.manage.service.ManageService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; import java.math.BigDecimal; @@ -22,6 +26,16 @@ public class ManageTest { @Autowired private JdbcOrderExceedStandardRepository jdbcOrderExceedStandardRepository; + @Autowired + private JdbcConsumptionDetailRepositoryImpl jdbcConsumptionDetailRepository; + + + @Test + void pageQuery(){ + OrderPageQuery dto=new OrderPageQuery(); + Page page= jdbcConsumptionDetailRepository.orderPageQueryByDto(dto); + System.out.println(page); + } @Test void update(){ @@ -47,7 +61,7 @@ public class ManageTest { @Test void pageManageService(){ - ConsumptionDetailDto dto=new ConsumptionDetailDto(); + ConsumptionDetailQuery dto=new ConsumptionDetailQuery(); dto.setPageNum(1); dto.setPageSize(10); dto.setProductType(0);