diff --git a/src/main/java/com/chint/application/dtos/AddLegData.java b/src/main/java/com/chint/application/dtos/AddLegData.java index e8add5a0..de333ea4 100644 --- a/src/main/java/com/chint/application/dtos/AddLegData.java +++ b/src/main/java/com/chint/application/dtos/AddLegData.java @@ -7,5 +7,7 @@ import lombok.Data; @Data public class AddLegData { private Long routeId; + private String sysCode; + private String fakeOrderNo; private LegData legData; } diff --git a/src/main/java/com/chint/application/out/FSSCController.java b/src/main/java/com/chint/application/out/FSSCController.java index 70832423..0cc28e40 100644 --- a/src/main/java/com/chint/application/out/FSSCController.java +++ b/src/main/java/com/chint/application/out/FSSCController.java @@ -82,6 +82,19 @@ public class FSSCController { String redirectUrl = getRedirectUrl(sysCode, employeeNo, it.getCompanyCode()); it.setRedirectUrl(redirectUrl); }); + + //特殊处理 + for (FsscSystem fsscSystem : fsscSystemList) { + String timespan = user.getUserLoginParam().getTimespan(); + SystemCode sysCode = systemCodeRepository.findBySysCode(fsscSystem.getSystemCode()); + if(timespan != null && timespan.endsWith("-M")) { + sysCode.setIfImmediateResponse(1); + } else { + sysCode.setIfImmediateResponse(0); + } + String redirectUrl = getRedirectUrl(sysCode, employeeNo, fsscSystem.getCompanyCode()); + fsscSystem.setRedirectUrl(redirectUrl); + } } else { return Result.Success(SUCCESS, List.of()); } diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 6ee91a30..b9ce12df 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -58,16 +58,27 @@ public class OrderOutController { @ApiOperation("根据临时单号和系统编码查询订单") @PostMapping("/query/billcode") public Result queryOrderByBillCodeAndSysCode(@RequestBody OrderQueryData queryData) { - RouteOrder routeOrder = orderQuery.queryByBillCodeAndSysCode(queryData.getBillcode(), queryData.getSysCode()) - .reloadStatus(); - return Result.Success(SUCCESS, orderQuery.queryRouteRes(routeOrder)); + String billcode = queryData.getBillcode(); + String sysCode = queryData.getSysCode(); + RouteOrder routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, billcode); + if (routeOrder == null) { + routeOrder = orderQuery.queryByBillCodeAndSysCode(billcode, sysCode); + } + return Result.Success(SUCCESS, orderQuery.queryRouteRes(routeOrder.reloadStatus())); } @ApiOperation("查询行程规划订单详情") @PostMapping("/query") public Result queryOrder(@RequestBody OrderQueryData queryData) { - RouteOrder routeOrder = orderQuery.queryById(queryData.getRouteId()).reloadStatus(); + String fakeOrderNo = queryData.getFakeOrderNo(); + String sysCode = queryData.getSysCode(); + RouteOrder routeOrder; + if (fakeOrderNo != null && sysCode != null) { + routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo); + } else { + routeOrder = orderQuery.queryById(queryData.getRouteId()).reloadStatus(); + } RouteOrderRes routeOrderRes = orderQuery.queryRouteRes(routeOrder); return Result.Success(SUCCESS, routeOrderRes); } diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index c8c2af82..97dd5ae9 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -1,11 +1,9 @@ package com.chint.application.services; -import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.*; import com.chint.application.dtos.AddLegData; import com.chint.application.dtos.DeleteLegData; import com.chint.domain.aggregates.order.Leg; -import com.chint.domain.aggregates.order.LegExtensionField; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.OrderException; @@ -18,7 +16,6 @@ import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.value_object.*; import com.chint.domain.value_object.enums.CurrencyType; -import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.DataMessageConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.echo_framework.command.Command; @@ -34,9 +31,8 @@ import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR; -import static com.chint.infrastructure.constant.LegConstant.*; -import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; -import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; +import static com.chint.infrastructure.constant.RouteConstant.*; @Service public class OrderApplicationService { @@ -70,14 +66,14 @@ public class OrderApplicationService { public RouteOrder saveOrder(OrderSaveData orderSaveData) { RouteOrder order; if (orderSaveData.getRouteId() != null) { - order = Optional.ofNullable(routeRepository.queryById(orderSaveData.getRouteId())).orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); + order = Optional.ofNullable(routeRepository.queryById(orderSaveData.getRouteId())).orElseThrow(() -> new NotFoundException(NOT_FOUND)); order.reloadStatus(orderSaveData, legFactory); if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { throw new OrderException(DataMessageConstant.DATA_INVALID); } } else { // order = orderFactory.createOrder(orderSaveData); - throw new NotFoundException(CommonMessageConstant.NOT_FOUND); + throw new NotFoundException(NOT_FOUND); } RouteOrder routeOrder = orderDomainService.saveOrder(order); //这里保存订单之后,需要为每个新添加的leg执行规划中事件 @@ -87,122 +83,124 @@ public class OrderApplicationService { @Transactional public RouteOrder addLegToOrder(AddLegData addLegData) { - RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) - .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); - order.reloadStatus(); - checkLegDataTime(addLegData, order); + //这里也先去redis查询如果没有的话 ,再查询数据库 + RouteOrder routeOrder = Optional.ofNullable(routeRepository + .findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo())) + .orElseGet(() -> Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) + .orElseThrow(() -> new NotFoundException(NOT_FOUND))).reloadStatus(); + checkLegDataTime(addLegData, routeOrder); LegData legData = addLegData.getLegData(); - List legs = processLegData(legData, order); + List legs = processLegData(legData, routeOrder); //创建差旅行程单 legDomainService.queryLocation(legs); - RouteOrder routeOrder = orderDomainService.saveOrder(order); legs.forEach(leg -> { - leg.reloadStatus(); - legDomainService.addPreEvent(leg); - - //如果是变更事件,推送变更事件 - if (legData.getChangeReason() != null) { - //保存变更事件理由 - leg = legDomainService.addChangeEvent(leg, legData.getChangeReason()); - } - - //如果订单状态已经处于审批中, 那么为这个新增的leg也提交审批状态 - if (order.getApproveOrderNo().getActualOrderNo() != null || order.getOrderStatus() >= ORDER_STATUS_APPROVAL) { - leg = legDomainService.addApproveEvent(leg); - } - leg.setRouteId(routeOrder.getRouteId()); - legRepository.save(leg); - - if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { - Command.of(BPMLegChangeCommand.class).routeOrder(order).newleg(leg.reloadStatus()).routeId(order.getRouteId()).changeType(0).sendToQueue(); - } + handleLegEvents(leg, addLegData.getLegData(), routeOrder); + routeOrder.addLeg(leg); }); - return routeOrder; // 仅在所有操作完成后保存一次 + if (routeOrder.getApprovalStatusCode().equals(APPROVAL_EVENT_PREPARE)) { + return routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 ,将行程规划单保存到redis + } else { + return routeRepository.save(routeOrder); // 仅在所有操作完成后保存一次 + } + } + + private void handleLegEvents(Leg leg, LegData legData, RouteOrder routeOrder) { + legDomainService.addPreEvent(leg); + + if (legData.getChangeReason() != null) { + legDomainService.addChangeEvent(leg, legData.getChangeReason()); + } + + if (isOrderInApprovalState(routeOrder)) { + legDomainService.addApproveEvent(leg); + } + + leg.setRouteId(routeOrder.getRouteId()); + + if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { + sendLegChangeCommand(leg, routeOrder); + } + } + + private boolean isOrderInApprovalState(RouteOrder routeOrder) { + return routeOrder.getApproveOrderNo().getActualOrderNo() != null + || routeOrder.getOrderStatus() >= ORDER_STATUS_APPROVAL; + } + + private void sendLegChangeCommand(Leg leg, RouteOrder routeOrder) { + Command.of(BPMLegChangeCommand.class) + .routeOrder(routeOrder) + .newleg(leg.reloadStatus()) + .routeId(routeOrder.getRouteId()) + .changeType(0) + .sendToQueue(); } @Transactional public void changeLeg(AddLegData addLegData) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LegData legData = addLegData.getLegData(); - - //如果被修改的行程类型是火车或者飞机, 就不需要结束时间 , 时间设置为开始时间当天的24小时 - String endTime = legData.getEndTime(); - if (legData.legType.equals(LEG_TYPE_TRAIN) || legData.legType.equals(LEG_TYPE_AIRPLANE)) { - endTime = null; + // 查找 Leg 并确保 RouteOrder 存在 + Leg leg = Optional.ofNullable(legRepository.findByLegId(Long.valueOf(legData.getLegId()))) + .orElseThrow(() -> new NotFoundException(NOT_FOUND)); + RouteOrder routeOrder = routeRepository.queryById(leg.getRouteId()); + if (routeOrder == null) { + throw new NotFoundException(NOT_FOUND); } - Leg leg = Optional.ofNullable( - legRepository.findByLegId(Long.valueOf(legData.getLegId())) - ).orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)).reloadStatus(); - leg.setCurrencyType(CurrencyType.getByCode(legData.getCurrencyType())); - Leg oldLeg = BeanUtil.copyProperties(leg, Leg.class); + checkLegDataTime(addLegData, routeOrder); + // 创建一个临时变量来避免 Lambda 表达式中的变量修改问题 + final Long legId = leg.getLegId(); + // 找到 LegItem + leg = routeOrder.getLegItems().stream() + .filter(legItem -> legItem.getLegId().equals(legId)) + .findFirst() + .orElseThrow(() -> new NotFoundException(NOT_FOUND)) + .reloadStatus(); - RouteOrder order = routeRepository.queryById(leg.getRouteId()).reloadStatus(); - checkLegDataTime(addLegData, order); + Leg oldLeg = leg.deepClone(); - //变更内容代码 - leg.setStartTime(LocalDateTime.parse(legData.getStartTime(), formatter)); - if (endTime != null) { - leg.setEndTime(LocalDateTime.parse(endTime, formatter)); - } else { - leg.setEndTime(LocalDateTime.parse(legData.getStartTime(), formatter).plusHours(23).plusMinutes(59).plusSeconds(59)); - } - leg.setOriginId(legData.getOriginId()); - leg.setDestinationId(legData.getDestinationId()); - if (leg.getLegType().equals(LEG_TYPE_HOTEL)) { - leg.setDestinationId(legData.getOriginId()); - } - - //如果是用车和其他类型,需要保存扩展字段 - if ((leg.getLegType().equals(LEG_TYPE_OTHER) || leg.getLegType().equals(LEG_TYPE_TAXI)) && legData.getLegExtensionFieldData() != null) { - LegExtensionFieldData legExtensionFieldData = legData.getLegExtensionFieldData(); - LegExtensionField legExtensionField = leg.getLegExtensionField(); - legExtensionField.setAmountType(legExtensionFieldData.getAmountType()); - legExtensionField.setExpenseExplanation(legExtensionFieldData.getExpenseExplanation()); - legExtensionField.setOriginDescription(legExtensionFieldData.getOriginDescription()); - legExtensionField.setDestinationDescription(legExtensionFieldData.getDestinationDescription()); - legExtensionField.setEstimatedAmount(legExtensionFieldData.getEstimatedAmount()); - if (legExtensionFieldData.getLocationIds() != null) { - legExtensionField.addLocationIdsAsString(legExtensionFieldData.getLocationIds()); - } - } + // 对 leg 进行更新 + leg.update(legData); + // 对更新的行程补充地理信息 legDomainService.queryLocation(List.of(oldLeg, leg)); - //保存变更事件理由 - leg = legDomainService.addChangeEvent(leg, legData.getChangeReason()); - - //推送未同步事件 - leg = legDomainService.addApproveEvent(leg); - - legRepository.save(leg).reloadStatus(); - //发送bpm保存结果 + handleLegChangeEvent(leg, legData); + // 保存 routeOrder 并重新加载状态 + routeRepository.save(routeOrder); + // 发送 BPM 保存结果 Command.of(BPMLegChangeCommand.class) .routeId(addLegData.getRouteId()) .reason(addLegData.getLegData().getChangeReason()) .oldLeg(oldLeg) - .routeOrder(order) + .routeOrder(routeOrder) .newleg(leg) .changeType(1) .sendToQueue(); } + private Leg handleLegChangeEvent(Leg leg, LegData legData) { + // 保存变更事件理由 + legDomainService.addChangeEvent(leg, legData.getChangeReason()); + // 推送未同步事件 + legDomainService.addApproveEvent(leg); + return leg; + } + private List processLegData(LegData legData, RouteOrder order) { if (legData.getCurrencyType() == null) { legData.setCurrencyType(CurrencyType.RENMINBI.getCode()); } - List legs = switch (legData.legType) { + return switch (legData.legType) { case LegConstant.LEG_TYPE_TRAIN -> legFactory.createTrainLeg(legData); case LegConstant.LEG_TYPE_AIRPLANE -> legFactory.createFlightLeg(legData); default -> Collections.singletonList(legFactory.createLeg(legData)); }; - legs.forEach(order::addLeg); - return legs; } public RouteOrder deleteLegToOrder(DeleteLegData deleteLegData) { RouteOrder order = Optional.ofNullable(routeRepository.queryById(deleteLegData.getRouteId())) - .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)).reloadStatus(); + .orElseThrow(() -> new NotFoundException(NOT_FOUND)).reloadStatus(); order.deleteLeg(deleteLegData.getLegNo()); return orderDomainService.saveOrder(order); } diff --git a/src/main/java/com/chint/domain/aggregates/order/Leg.java b/src/main/java/com/chint/domain/aggregates/order/Leg.java index 1dc1cd80..a84d7d20 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -4,12 +4,15 @@ package com.chint.domain.aggregates.order; import com.chint.domain.exceptions.LegEventException; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; +import com.chint.domain.value_object.LegExtensionFieldData; import com.chint.domain.value_object.enums.CurrencyType; import com.chint.infrastructure.constant.LegConstant; +import com.chint.infrastructure.util.DateTimeUtil; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Column; @@ -92,6 +95,47 @@ public class Leg implements Serializable { return new Leg(legId); } + public Leg deepClone() { + Leg clonedLeg = new Leg(); + BeanUtils.copyProperties(this, clonedLeg); + // 深克隆 eventList + if (this.eventList != null) { + clonedLeg.eventList = this.eventList.stream() + .map(event -> { + LegEvent clonedEvent = new LegEvent(); + BeanUtils.copyProperties(event, clonedEvent); + return clonedEvent; + }) + .toList(); + } + // 深克隆 legExtensionField + if (this.legExtensionField != null) { + clonedLeg.legExtensionField = new LegExtensionField(); + BeanUtils.copyProperties(this.legExtensionField, clonedLeg.legExtensionField); + } + // 深克隆 orderDetails + if (this.orderDetails != null) { + clonedLeg.orderDetails = this.orderDetails.stream() + .map(orderDetail -> { + OrderDetail clonedOrderDetail = new OrderDetail(); + BeanUtils.copyProperties(orderDetail, clonedOrderDetail); + return clonedOrderDetail; + }) + .toList(); + } + // 深克隆 originLocation + if (this.originLocation != null) { + clonedLeg.originLocation = new Location(); + BeanUtils.copyProperties(this.originLocation, clonedLeg.originLocation); + } + // 深克隆 destinationLocation + if (this.destinationLocation != null) { + clonedLeg.destinationLocation = new Location(); + BeanUtils.copyProperties(this.destinationLocation, clonedLeg.destinationLocation); + } + return clonedLeg; + } + public boolean legIsInternal() { if (this.originLocation != null && !this.originLocation.isInternal()) { @@ -131,6 +175,52 @@ public class Leg implements Serializable { .orElse(null); } + public Leg update(LegData legData) { + DateTimeFormatter formatter = DateTimeUtil.formatter; + this.setCurrencyType(CurrencyType.getByCode(legData.getCurrencyType())); + // 更新开始时间 + this.startTime = LocalDateTime.parse(legData.getStartTime(), formatter); + if (legData.legType.equals(LEG_TYPE_TRAIN) || legData.legType.equals(LEG_TYPE_AIRPLANE)) { + legData.setEndTime(null); + } + // 更新结束时间 + if (legData.getEndTime() != null) { + this.endTime = LocalDateTime.parse(legData.getEndTime(), formatter); + } else { + this.endTime = LocalDateTime.parse(legData.getStartTime(), formatter) + .plusHours(23) + .plusMinutes(59) + .plusSeconds(59); + } + // 更新起点和终点 + this.originId = legData.getOriginId(); + this.destinationId = legData.getDestinationId(); + // 如果是酒店类型,起点和终点相同 + if (LEG_TYPE_HOTEL == (this.legType)) { + this.destinationId = legData.getOriginId(); + } + // 更新扩展字段 + if ((LEG_TYPE_OTHER == (this.legType) || LEG_TYPE_TAXI == (this.legType)) && + legData.getLegExtensionFieldData() != null) { + updateLegExtensionFields(legData.getLegExtensionFieldData()); + } + return this; + } + + private void updateLegExtensionFields(LegExtensionFieldData legExtensionFieldData) { + if (this.legExtensionField == null) { + this.legExtensionField = new LegExtensionField(); + } + this.legExtensionField.setAmountType(legExtensionFieldData.getAmountType()); + this.legExtensionField.setExpenseExplanation(legExtensionFieldData.getExpenseExplanation()); + this.legExtensionField.setOriginDescription(legExtensionFieldData.getOriginDescription()); + this.legExtensionField.setDestinationDescription(legExtensionFieldData.getDestinationDescription()); + this.legExtensionField.setEstimatedAmount(legExtensionFieldData.getEstimatedAmount()); + if (legExtensionFieldData.getLocationIds() != null) { + this.legExtensionField.addLocationIdsAsString(legExtensionFieldData.getLocationIds()); + } + } + public Leg reloadStatus() { if (eventList == null || eventList.isEmpty()) { this.eventList = new ArrayList<>(); diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java index 06c5d5db..0380a419 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -222,6 +222,7 @@ public class RouteOrder implements Serializable { if (this.routeRequestList == null) { this.routeRequestList = new ArrayList<>(); } + this.routeRequestList = new ArrayList<>(this.routeRequestList); this.routeRequestList.add(routeRequest); return this; } @@ -248,6 +249,7 @@ public class RouteOrder implements Serializable { if (this.approveEvents == null) { this.approveEvents = new ArrayList<>(); } + this.approveEvents = new ArrayList<>(this.approveEvents); this.approveEvents.add(approvalEvent); return this; } 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 464bcd3b..17d5fbee 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -64,8 +64,11 @@ public class RouteOrderFactory implements OrderFactory { generate = generate + envMark; } routeOrder.setRouteOrderNo(generate); - - + routeOrder.setRouteCustomExtensionFieldList(List.of()); + routeOrder.setOrderDetails(List.of()); + routeOrder.setRouteRequestList(List.of()); + routeOrder.setCreateUser(String.valueOf(user.getUserId())); + routeOrder.setUpdateUser(String.valueOf(user.getUserId())); //根据项目需求,需要保存假审批订单号,真审批订单号 ,创建的时候保存假审批订单号 routeOrder.setUserId(loginParam.getSfno()); ApproveOrderNo approveOrderNo = new ApproveOrderNo(); diff --git a/src/main/java/com/chint/domain/repository/RouteRepository.java b/src/main/java/com/chint/domain/repository/RouteRepository.java index 7782870e..b4fb4cf7 100644 --- a/src/main/java/com/chint/domain/repository/RouteRepository.java +++ b/src/main/java/com/chint/domain/repository/RouteRepository.java @@ -19,10 +19,12 @@ public interface RouteRepository { RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode); - RouteOrder findByActualOrderNoAndSysCode(String actualOrderNo,String sysCode); + RouteOrder findByActualOrderNoAndSysCode(String actualOrderNo, String sysCode); RouteOrder findByOrderNo(String orderNo); - List findByOrderNoIn(List orderNo); + + List findByOrderNoIn(List orderNo); + Page findByOrderNoFuzzy(OrderQueryData orderQueryData); Page findByInstructions(OrderQueryData orderQueryData); @@ -31,17 +33,22 @@ public interface RouteRepository { void deleteByEmployeeNo(String employeeNo); - List findByEmployeeNo(String employeeNo); + List findByEmployeeNo(String employeeNo); PageResult pageQuery(OrderQueryData orderQueryData); List findByActualOrderNoNotNull(OrderQueryData orderQueryData); + List findAllByEmployeeNo(String employeeNo); Page findByTime(OrderQueryData queryData); -// Page findByTime(OrderQueryData queryData); + // Page findByTime(OrderQueryData queryData); List findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd); + + RouteOrder findTempRouteOrderBySysCodeAndBillCode(String sysCode, String billCode); + + RouteOrder saveTempRouteOrder(RouteOrder routeOrder, Long hours); } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 07b4b956..9dd67a9e 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -51,39 +51,24 @@ public class LegDomainService { List orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); orderDetailList.forEach(OrderDetail::reloadStatus); leg.reloadStatus(); - if (!orderDetailList.isEmpty()) { - String lastOrderStatus = orderDetailList.get(orderDetailList.size() - 1).getOrderStatus(); - //如果是未同步状态 ,就不进行订单检查 - if (leg.getLegStatus().equals(LEG_STATUS_APPROVAL)) { - return leg; - } - - if (lastOrderStatus.equals(ORDER_EVENT_REFUND_NAME)) { - if (!leg.getLastLegEvent().getEventType().equals(LEG_EVENT_NOT_ORDERED)) { - LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED); - leg.addEvent(legEvent); - return legRepository.save(leg); - } - } - - if (lastOrderStatus.equals(ORDER_EVENT_CANCEL_NAME)) { - LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_CANCEL); - leg.addEvent(legEvent); - return legRepository.save(leg); - } + if (orderDetailList.isEmpty()) { + return leg; } - - List details = orderDetailList.stream().filter(orderDetail -> orderDetail.getOrderStatus().equals(ORDER_EVENT_ORDERED_NAME) || - orderDetail.getOrderStatus().equals(ORDER_EVENT_PAYED_NAME)).toList(); - if (!details.isEmpty() && leg.getLegStatus() < LEG_EVENT_ORDERED) { - LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_ORDERED); - leg.addEvent(legEvent); + String lastOrderStatus = orderDetailList.get(orderDetailList.size() - 1).getOrderStatus(); + // 如果是未同步状态 ,就不进行订单检查 + if (leg.getLegStatus().equals(LEG_STATUS_APPROVAL)) { + return leg; + } + if (isRefundEvent(lastOrderStatus, leg)) { + return legRepository.save(leg); + } + if (isCancelEvent(lastOrderStatus, leg)) { + return legRepository.save(leg); + } + if (isOrderedOrPayedEvent(orderDetailList, leg)) { return legRepository.save(leg); } - - if (leg.getLegStatus().equals(LEG_STATUS_CHANGE)) { - //如果发现该订单 LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL); leg.addEvent(legEvent); return legRepository.save(leg); @@ -91,6 +76,39 @@ public class LegDomainService { return leg; } + private boolean isRefundEvent(String lastOrderStatus, Leg leg) { + if (lastOrderStatus.equals(ORDER_EVENT_REFUND_NAME)) { + if (!leg.getLastLegEvent().getEventType().equals(LEG_EVENT_NOT_ORDERED)) { + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED); + leg.addEvent(legEvent); + } + return true; + } + return false; + } + + private boolean isCancelEvent(String lastOrderStatus, Leg leg) { + if (lastOrderStatus.equals(ORDER_EVENT_CANCEL_NAME)) { + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_CANCEL); + leg.addEvent(legEvent); + return true; + } + return false; + } + + private boolean isOrderedOrPayedEvent(List orderDetailList, Leg leg) { + List details = orderDetailList.stream() + .filter(orderDetail -> orderDetail.getOrderStatus().equals(ORDER_EVENT_ORDERED_NAME) || + orderDetail.getOrderStatus().equals(ORDER_EVENT_PAYED_NAME)) + .toList(); + if (!details.isEmpty() && leg.getLegStatus() < LEG_EVENT_ORDERED) { + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_ORDERED); + leg.addEvent(legEvent); + return true; + } + return false; + } + public void deleteByLegNo(String legNo) { Leg byLegNo = legRepository.findByLegNo(legNo); if (byLegNo == null) { @@ -124,6 +142,9 @@ public class LegDomainService { } public Leg addPreEvent(Leg leg) { + if(leg.getEventList() == null){ + leg.setEventList(new ArrayList<>()); + } if (leg.getEventList().isEmpty()) { LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_PREPARE); leg.addEvent(legEvent); diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index 5bbf89bb..de6c496a 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -8,17 +8,16 @@ import com.chint.domain.exceptions.OrderException; import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order_detail.OrderDetailFactory; -import com.chint.domain.repository.*; +import com.chint.domain.repository.CompanyBlackListRepository; +import com.chint.domain.repository.OrderDetailRepository; +import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.SupplierRepository; import com.chint.domain.value_object.ApproveRouteData; import com.chint.domain.value_object.UserLoginParam; import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.command.Command; -import com.chint.infrastructure.repository.jdbc.JdbcLegRepository; -import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import com.chint.infrastructure.util.DateTimeUtil; -import com.chint.interfaces.rest.bpm.BPMParamFactory; -import com.chint.interfaces.rest.bpm.BPMRequest; import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; @@ -28,7 +27,6 @@ import com.chint.interfaces.rest.ctrip.dto.search.car.OrderFee; import com.chint.interfaces.rest.ctrip.dto.search.flight.*; import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity; import com.chint.interfaces.rest.ctrip.dto.search.hotel.RefundInfo; -import com.chint.interfaces.rest.data_center.user.UserHttpRequest; import com.chint.interfaces.rest.ly.LYSearchRequest; import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse; import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse; @@ -37,6 +35,7 @@ import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailRespons import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -86,6 +85,9 @@ public class OrderDomainService { @Autowired private SupplierRepository supplierRepository; + @Autowired + private RedisTemplate redisTemplate; + private Set companyBlackList = new HashSet<>(); public RouteOrder saveOrder(RouteOrder routeOrder) { @@ -113,16 +115,26 @@ public class OrderDomainService { public RouteOrder createOrder(OrderCreateCommand command) { User user = command.getUser(); UserLoginParam loginParam = user.getUserLoginParam(); - return Optional.ofNullable(routeRepository + // 从 Redis 查找 + RouteOrder tempOrder = routeRepository + .findTempRouteOrderBySysCodeAndBillCode(loginParam.getSyscode(), loginParam.getBillcode()); + if (tempOrder != null) { + return tempOrder; + } + // 从数据库查找 + RouteOrder routeOrder = Optional.ofNullable(routeRepository .findByFakeOrderNoAndSysCode(loginParam.getBillcode(), loginParam.getSyscode())) .orElseGet(() -> { - RouteOrder order = routeOrderFactory.createRoute(command); - order.setStandardLevel(user.getStandardLevel()); - ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(RouteConstant.APPROVAL_EVENT_PREPARE); - order.addApprovalEvent(approvalEvent); - this.saveOrder(order); - return order; + RouteOrder createOrder = routeOrderFactory.createRoute(command); + createOrder.setStandardLevel(user.getStandardLevel()); + ApprovalEvent approvalEvent = routeOrderFactory + .createApprovalEvent(RouteConstant.APPROVAL_EVENT_PREPARE); + createOrder.addApprovalEvent(approvalEvent); + return createOrder; }); + //将创建号的临时单号保存到redis当中 + routeRepository.saveTempRouteOrder(routeOrder, 48L); + return routeOrder; } @@ -178,7 +190,6 @@ public class OrderDomainService { } - private boolean isSpecialEventType(Integer orderEventType) { return orderEventType.equals(ORDER_EVENT_ETA) || orderEventType.equals(ORDER_EVENT_CHANGE) || diff --git a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java index cae28c9a..39f1ae42 100644 --- a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -88,8 +88,10 @@ public class RouteRequestDomainService { CompletableFuture.runAsync(() -> { List legs = legDomainService.queryLegsCanSync(routeOrder, it); List legIdList = legs.stream().map(Leg::getLegId).collect(Collectors.toList()); - RouteRequest routeRequest = createRouteRequest(routeOrder, legIdList, it.getName()); - syncRouteRequest(routeRequest, it); + if(!legIdList.isEmpty()){ + RouteRequest routeRequest = createRouteRequest(routeOrder, legIdList, it.getName()); + syncRouteRequest(routeRequest, it); + } }) )); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index a8a4803d..6a9798ab 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -117,7 +117,19 @@ public class LegEventHandler implements LegEventService { @Override public void approveRoute(OrderApprovalStartCommand command) { ApproveRouteData data = command.getData(); - RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getFakeOrderNo(), data.getSysCode()).reloadStatus(); + String fakeOrderNo = data.getFakeOrderNo(); + String sysCode = data.getSysCode(); + //先查看是否已保存到数据库,再从redis获取,如果没有的话再从数据库获取 + RouteOrder routeOrder = routeRepository. + findByActualOrderNoAndSysCode(data.getActualOrderNo(), sysCode); + if (routeOrder == null) { + routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo); + } + if (routeOrder == null) { + routeOrder = routeRepository + .findByFakeOrderNoAndSysCode(fakeOrderNo, sysCode); + } + routeOrder.reloadStatus(); if (routeOrder.getLegItems().isEmpty()) { throw new OrderException(CommonMessageConstant.LEG_ERROR); } @@ -134,7 +146,7 @@ public class LegEventHandler implements LegEventService { routeOrder.addApprovalEvent(approvalEvent); //当sysCode为H3BPM的时候 ,实用单号更新行程规划单的单号 - if (data.getSysCode().equals(H3_BPM)) { + if (sysCode.equals(H3_BPM)) { String generate = OrderNo.generate(H3_BPM, data.getActualOrderNo()); if (!envMark.equals("prod")) { routeOrder.setRouteOrderNo(generate + envMark); diff --git a/src/main/java/com/chint/domain/value_object/LegData.java b/src/main/java/com/chint/domain/value_object/LegData.java index 08f2429d..9da5c5d7 100644 --- a/src/main/java/com/chint/domain/value_object/LegData.java +++ b/src/main/java/com/chint/domain/value_object/LegData.java @@ -14,7 +14,7 @@ public class LegData { public final String startTime; - public final String endTime; + public String endTime; public final Long originId; 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 2dcfab47..9543b7f3 100644 --- a/src/main/java/com/chint/domain/value_object/OrderQueryData.java +++ b/src/main/java/com/chint/domain/value_object/OrderQueryData.java @@ -13,6 +13,7 @@ public class OrderQueryData extends BaseQuery { @ApiModelProperty("需要同步的行程规划单ID") private Long routeId; private String billcode; + private String fakeOrderNo; private String actualOrderNo; private String sysCode; private List approvalStatusCodes; diff --git a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java index e31c1b82..24f5adeb 100644 --- a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java @@ -1,5 +1,6 @@ package com.chint.infrastructure.repository; +import com.chint.domain.aggregates.order.ApproveOrderNo; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.repository.RouteRepository; import com.chint.domain.value_object.OrderQueryData; @@ -11,11 +12,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Repository; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; @Repository public class RouteRepositoryImpl implements RouteRepository { @@ -26,6 +29,9 @@ public class RouteRepositoryImpl implements RouteRepository { @Autowired private RouteCacheService routeCacheService; + @Autowired + private RedisTemplate redisTemplate; + @Override public RouteOrder queryById(Long orderId) { // jdbcRouteRepository.findByRouteId(orderId); @@ -184,4 +190,23 @@ public class RouteRepositoryImpl implements RouteRepository { public List findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd) { return jdbcRouteRepository.findByCreateTimeBetween(createTimeStart, createTimeEnd); } + + @Override + public RouteOrder findTempRouteOrderBySysCodeAndBillCode(String sysCode, String billCode) { + String redisKey = "TemporaryRouteOrder:" + sysCode + "-" + billCode; + // 从 Redis 查找 + RouteOrder order = redisTemplate.opsForValue().get(redisKey); + if (order != null) { + return order; + } + return findByFakeOrderNoAndSysCode(sysCode, billCode); + } + + @Override + public RouteOrder saveTempRouteOrder(RouteOrder routeOrder, Long hours) { + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + String redisKey = "TemporaryRouteOrder:" + approveOrderNo.getSysCode() + "-" + approveOrderNo.getFakeOrderNo(); + redisTemplate.opsForValue().set(redisKey, routeOrder, hours, TimeUnit.HOURS); + return routeOrder; + } } diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 5ea3d079..5d36ef96 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -250,7 +250,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32002090029"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31472498556"); System.out.println(response); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 4041a50b..2c6b6f13 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -820,7 +820,7 @@ public class LYTest { @Test void searchTrain() { - TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DTC24061977736328100"); + TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24050672496002495"); Gson gson = new Gson(); String json = gson.toJson(trainOrderDetail); System.out.println(json); @@ -828,7 +828,7 @@ public class LYTest { @Test void searchHotel() { - HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240406120100189791"); + HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240511131800297715"); Gson gson = new Gson(); String json = gson.toJson(hotelOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index aa5f6879..5c66bac0 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -310,9 +310,9 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "190401151"; + String sfno = "230615020"; String syscode = "FSSC"; - String billcode = "CLSQ240225000099"; + String billcode = "CLSQ240620004123"; String companycode = "正泰集团股份有限公司"; String timespan = "1708908662738"; String s = Digest.md5(sfno + syscode + billcode + companycode + LOGIN_SECRET_KEY + timespan);