diff --git a/src/main/java/com/chint/application/dtos/RoutOrderFieldParam.java b/src/main/java/com/chint/application/dtos/RoutOrderFieldParam.java new file mode 100644 index 00000000..996dbe09 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/RoutOrderFieldParam.java @@ -0,0 +1,19 @@ +package com.chint.application.dtos; + +import lombok.Data; + +import java.util.List; + +@Data +public class RoutOrderFieldParam { + private Integer pageNum; + private Integer pageSize; + private List extensionFieldList; + private String queryDate; + + @Data + public static class extensionField { + private String fieldName; + private String fieldValue; + } +} diff --git a/src/main/java/com/chint/application/dtos/mapper/RouteOrderMapper.java b/src/main/java/com/chint/application/dtos/mapper/RouteOrderMapper.java new file mode 100644 index 00000000..1571b554 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/mapper/RouteOrderMapper.java @@ -0,0 +1,31 @@ +package com.chint.application.dtos.mapper; + +import cn.hutool.core.bean.BeanUtil; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.user.User; +import com.chint.domain.repository.UserRepository; +import com.chint.domain.value_object.RouteOrderFiledVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class RouteOrderMapper { + + @Autowired + private UserRepository userRepository; + + public RouteOrderFiledVO mapToFiledVO(RouteOrder routeOrder) { + RouteOrderFiledVO routeOrderFiledVO = BeanUtil.copyProperties(routeOrder, RouteOrderFiledVO.class); + List routeOrderExtensionFileds = routeOrder + .getRouteCustomExtensionFieldList() + .stream() + .map(it -> BeanUtil.copyProperties(it, RouteOrderFiledVO.RouteOrderExtensionFiled.class)) + .toList(); + routeOrderFiledVO.setRouteCustomExtensionFieldList(routeOrderExtensionFileds); + User byUserEmployeeNo = userRepository.findByUserEmployeeNo(routeOrderFiledVO.getUserId()); + routeOrderFiledVO.setUserName(byUserEmployeeNo.getName()); + return routeOrderFiledVO; + } +} diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index d275e3f9..64cb42c3 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -1,6 +1,7 @@ package com.chint.application.out; +import com.chint.application.dtos.RoutOrderFieldParam; import com.chint.application.dtos.response.LegRes; import com.chint.application.dtos.response.RouteOrderPageRes; import com.chint.application.dtos.response.RouteOrderRes; @@ -40,6 +41,7 @@ public class OrderOutController { @Autowired private UserRepository userRepository; + @Autowired private OrderDomainService orderDomainService; @@ -115,9 +117,6 @@ public class OrderOutController { return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); } - - - @ApiOperation("查询能够同步的行程节点") @PostMapping("/query/legs") public Result> queryLegs(@RequestBody OrderQueryData queryData) { @@ -129,4 +128,11 @@ public class OrderOutController { return Result.Success(SUCCESS, legResList); } + @ApiOperation("查询单日行程规划单") + @PostMapping("/query/route/filed") + public Result> queryRoutOrderField(@RequestBody RoutOrderFieldParam param) { + return Result.Success(SUCCESS, orderQuery.queryRouteOrderFiled(param)); + } + + } diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 8a9d04c1..390b3c0b 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -1,14 +1,17 @@ package com.chint.application.queryies; import cn.hutool.core.bean.BeanUtil; +import com.chint.application.dtos.RoutOrderFieldParam; import com.chint.application.dtos.response.*; import com.chint.application.dtos.trip.*; +import com.chint.application.dtos.mapper.RouteOrderMapper; import com.chint.application.queryies.estimate.EstimatePrice; import com.chint.domain.aggregates.location.basedata.CountryLevelInfoEntity; import com.chint.domain.aggregates.location.basedata.DistrictPOIInfoEntity; import com.chint.domain.aggregates.location.basedata.PrefectureLevelCityInfoEntity; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.user.User; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.*; import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; @@ -18,6 +21,7 @@ import com.chint.infrastructure.cache.RouteCacheService; import com.chint.infrastructure.constant.FSSCConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.util.BaseContext; +import com.chint.infrastructure.util.DateTimeUtil; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.user.UserHttpRequest; @@ -27,10 +31,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -55,6 +56,9 @@ public class OrderQuery { @Autowired private CityRepository cityRepository; + @Autowired + private RouteOrderMapper routeOrderMapper; + @Autowired private EstimatePrice estimatePrice; @@ -567,7 +571,7 @@ public class OrderQuery { order.getLegItems() != null && !order.getLegItems().isEmpty() && order.getLegItems().stream().anyMatch(leg -> !leg.getLegType().equals(LEG_TYPE_OTHER))) - .filter(order->order.getSupplierName() == null) + .filter(order -> order.getSupplierName() == null) .sorted(Comparator.comparing(RouteOrder::getUpdateTime).reversed()) .map(order -> { User user = userRepository.findByUserEmployeeNo(order.getUserId()); @@ -575,4 +579,48 @@ public class OrderQuery { }) .toList(); } + + public PageResult queryRouteOrderFiled(RoutOrderFieldParam param) { + String queryDate = param.getQueryDate(); + if (queryDate == null) { + throw new NotFoundException("只支持查询一天的数据"); + } + LocalDateTime startOfDay = DateTimeUtil.startOfDay(queryDate); + LocalDateTime endOfDay = DateTimeUtil.endOfDay(queryDate); + List routeOrders = routeRepository.queryAllInOneDayAndEffective(startOfDay, endOfDay); + + List routeOrderFiledVOList = routeOrders + .stream() + .filter(it -> { + boolean res = true; + List extensionFieldList = param.getExtensionFieldList(); + if (extensionFieldList != null && !extensionFieldList.isEmpty()) { + for (RoutOrderFieldParam.extensionField paramExtensionField : extensionFieldList) { + List routeCustomExtensionFieldList = it.getRouteCustomExtensionFieldList(); + if (routeCustomExtensionFieldList != null && !routeCustomExtensionFieldList.isEmpty()) { + Optional first = routeCustomExtensionFieldList.stream() + .filter(routeExtensionField -> routeExtensionField.getFieldName().equals(paramExtensionField.getFieldName())) + .findFirst(); + res = first + .map(routeCustomExtensionField -> routeCustomExtensionField.getFieldValue() + .equals(paramExtensionField.getFieldValue())) + .orElse(false); + } else { + res = false; + } + } + } + return res; + }) + .map(routeOrderMapper::mapToFiledVO).toList(); + + int size = routeOrderFiledVOList.size(); + if (param.getPageSize() != null && param.getPageNum() != null) { + routeOrderFiledVOList = routeOrderFiledVOList.stream() + .skip((long) (param.getPageNum() - 1) * param.getPageSize()) + .limit(param.getPageSize()) + .toList(); + } + return PageResult.totalPageNum(size, routeOrderFiledVOList); + } } diff --git a/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java index 22fa0710..2862111b 100644 --- a/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java @@ -5,6 +5,7 @@ import com.chint.domain.aggregates.order.ApprovalEvent; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteRequest; import com.chint.domain.value_object.OrderSaveData; +import com.chint.domain.value_object.RouteOrderFiledVO; import java.util.List; diff --git a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java index c68a6aa8..07f84449 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -5,6 +5,7 @@ import com.chint.application.commands.OrderCreateCommand; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.user.User; import com.chint.domain.factoriy.leg.RouteLegFactory; +import com.chint.domain.repository.UserRepository; import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.OrderSaveData; import com.chint.domain.value_object.UserLoginParam; @@ -23,6 +24,9 @@ public class RouteOrderFactory implements OrderFactory { @Autowired private RouteLegFactory routeLegFactory; + @Autowired + private UserRepository userRepository; + @Value("${chint.envMark}") private String envMark; diff --git a/src/main/java/com/chint/domain/repository/RouteRepository.java b/src/main/java/com/chint/domain/repository/RouteRepository.java index 583775ae..1e8a2651 100644 --- a/src/main/java/com/chint/domain/repository/RouteRepository.java +++ b/src/main/java/com/chint/domain/repository/RouteRepository.java @@ -11,6 +11,8 @@ import java.util.List; public interface RouteRepository { RouteOrder queryById(Long orderId); + List queryAllInOneDayAndEffective(LocalDateTime start, LocalDateTime end); + void deleteById(Long orderId); RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode); diff --git a/src/main/java/com/chint/domain/value_object/OrderQueryData.java b/src/main/java/com/chint/domain/value_object/OrderQueryData.java index 7007fdb5..2dcfab47 100644 --- a/src/main/java/com/chint/domain/value_object/OrderQueryData.java +++ b/src/main/java/com/chint/domain/value_object/OrderQueryData.java @@ -22,4 +22,6 @@ public class OrderQueryData extends BaseQuery { private String keywords; @ApiModelProperty("供应商标识") private String supplierName; + private String customFieldName; + private String customFieldValue; } diff --git a/src/main/java/com/chint/domain/value_object/RouteOrderFiledVO.java b/src/main/java/com/chint/domain/value_object/RouteOrderFiledVO.java index 84347afd..81433331 100644 --- a/src/main/java/com/chint/domain/value_object/RouteOrderFiledVO.java +++ b/src/main/java/com/chint/domain/value_object/RouteOrderFiledVO.java @@ -24,5 +24,12 @@ public class RouteOrderFiledVO { @Embedded.Nullable private ApproveOrderNo approveOrderNo; @ApiModelProperty("自定义字段") - private List routeCustomExtensionFieldList; + private List routeCustomExtensionFieldList; + + @Data + public static class RouteOrderExtensionFiled { + private String fieldName; + private String fieldValue; + private String extension; + } } diff --git a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java index a9a1a8b9..3c76625d 100644 --- a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java @@ -31,6 +31,11 @@ public class RouteRepositoryImpl implements RouteRepository { return routeCacheService.getRouteById(orderId); } + @Override + public List queryAllInOneDayAndEffective(LocalDateTime start, LocalDateTime end) { + return jdbcRouteRepository.findByCreateTimeBetweenAndApproveOrderNo_ActualOrderNoNotNull(start, end); + } + @Override public void deleteById(Long orderId) { jdbcRouteRepository.deleteById(orderId); @@ -45,7 +50,6 @@ public class RouteRepositoryImpl implements RouteRepository { if (routeOrder == null) { routeOrder = jdbcRouteRepository.findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(fakeOrderNo, sysCode); } -// return jdbcRouteRepository.findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(fakeOrderNo, sysCode); return routeOrder; } @@ -55,7 +59,6 @@ public class RouteRepositoryImpl implements RouteRepository { if (routeOrder == null) { routeOrder = jdbcRouteRepository.findByApproveOrderNo_ActualOrderNoAndApproveOrderNo_SysCode(actualOrderNo, sysCode); } -// return jdbcRouteRepository.findByApproveOrderNo_ActualOrderNoAndApproveOrderNo_SysCode(actualOrderNo, sysCode); return routeOrder; } @@ -92,7 +95,7 @@ public class RouteRepositoryImpl implements RouteRepository { @Override public RouteOrder save(RouteOrder routeOrder) { - if(routeOrder.getRouteId() != null){ + if (routeOrder.getRouteId() != null) { routeCacheService.invalidateRouteCache(routeOrder.getRouteId()); } RouteOrder save = jdbcRouteRepository.save(routeOrder); diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRepository.java index 8f21a75e..79d12289 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRepository.java @@ -4,6 +4,7 @@ import com.chint.domain.aggregates.order.RouteOrder; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -14,6 +15,7 @@ import java.util.List; public interface JdbcRouteRepository extends CrudRepository { Page findByCreateUser(String userId, Pageable pageable); + List findByCreateTimeBetweenAndApproveOrderNo_ActualOrderNoNotNull(LocalDateTime start, LocalDateTime end); List findByUserId(String employeeNo); @@ -40,4 +42,9 @@ public interface JdbcRouteRepository extends CrudRepository { List findByCreateTimeBetween(LocalDateTime createTime, LocalDateTime createTime2); Page findAllBy(PageRequest pageResult); + + @Query(""" +select * from route_order r1 left join route_custom_extension_field r2 on r1.route_id = r2.route_id where + """) + List findByField(); } diff --git a/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java b/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java index bf099398..fee858f9 100644 --- a/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java +++ b/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java @@ -1,9 +1,6 @@ package com.chint.infrastructure.util; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.YearMonth; -import java.time.ZoneId; +import java.time.*; import java.time.format.DateTimeFormatter; public class DateTimeUtil { @@ -20,7 +17,7 @@ public class DateTimeUtil { return formatter.format(localDateTime); } - public static String timeToStrCommon(LocalDateTime time){ + public static String timeToStrCommon(LocalDateTime time) { return formatter.format(time); } @@ -72,4 +69,13 @@ public class DateTimeUtil { // 格式化日期时间 return lastMonthDateTime.format(formatterDateYYYYMM); } + + public static LocalDateTime startOfDay(String date) { + LocalDate parse = LocalDate.parse(date, formatterDate); + return LocalDateTime.of(parse, LocalTime.MIN); + } + public static LocalDateTime endOfDay(String date) { + LocalDate parse = LocalDate.parse(date, formatterDate); + return LocalDateTime.of(parse, LocalTime.MAX); + } } diff --git a/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java b/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java index 969912db..53d9e561 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; /** * 差旅 + * * @Author:nxj * @Date:2024/4/24 16:40 */ @@ -17,19 +18,19 @@ public class TravelApplicationRequest { @Value("${amap.baseUrl}") private String baseUrl; //创建差旅申请单 - private final static String APPLY_RECORD_CREATE="/ws/boss/enterprise/openapi/apply/record/create"; + private final static String APPLY_RECORD_CREATE = "/ws/boss/enterprise/openapi/apply/record/create"; //修改差旅申请单 - private final static String APPLY_RECORD_UPDATE="/ws/boss/enterprise/openapi/apply/record/update"; + private final static String APPLY_RECORD_UPDATE = "/ws/boss/enterprise/openapi/apply/record/update"; @Autowired private AmapRequest amapRequest; - public TravelApplicationDtoResponse apply(TravelApplicationDto dto){ - return amapRequest.post(baseUrl+APPLY_RECORD_CREATE,dto, TravelApplicationDtoResponse.class); + public TravelApplicationDtoResponse apply(TravelApplicationDto dto) { + return amapRequest.post(baseUrl + APPLY_RECORD_CREATE, dto, TravelApplicationDtoResponse.class); } - public TravelApplicationDtoResponse modify(TravelApplicationDto dto){ - return amapRequest.post(baseUrl+APPLY_RECORD_UPDATE,dto, TravelApplicationDtoResponse.class); + public TravelApplicationDtoResponse modify(TravelApplicationDto dto) { + return amapRequest.post(baseUrl + APPLY_RECORD_UPDATE, dto, TravelApplicationDtoResponse.class); } }