fix: 临时行程规划单转存redis

feat:提交审批单之后自动同步到商旅平台
This commit is contained in:
lulz1 2024-06-20 14:22:10 +08:00
parent ce85c7e2b8
commit 01ad704f98
18 changed files with 347 additions and 149 deletions

View File

@ -7,5 +7,7 @@ import lombok.Data;
@Data @Data
public class AddLegData { public class AddLegData {
private Long routeId; private Long routeId;
private String sysCode;
private String fakeOrderNo;
private LegData legData; private LegData legData;
} }

View File

@ -82,6 +82,19 @@ public class FSSCController {
String redirectUrl = getRedirectUrl(sysCode, employeeNo, it.getCompanyCode()); String redirectUrl = getRedirectUrl(sysCode, employeeNo, it.getCompanyCode());
it.setRedirectUrl(redirectUrl); 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 { } else {
return Result.Success(SUCCESS, List.of()); return Result.Success(SUCCESS, List.of());
} }

View File

@ -58,16 +58,27 @@ public class OrderOutController {
@ApiOperation("根据临时单号和系统编码查询订单") @ApiOperation("根据临时单号和系统编码查询订单")
@PostMapping("/query/billcode") @PostMapping("/query/billcode")
public Result<RouteOrderRes> queryOrderByBillCodeAndSysCode(@RequestBody OrderQueryData queryData) { public Result<RouteOrderRes> queryOrderByBillCodeAndSysCode(@RequestBody OrderQueryData queryData) {
RouteOrder routeOrder = orderQuery.queryByBillCodeAndSysCode(queryData.getBillcode(), queryData.getSysCode()) String billcode = queryData.getBillcode();
.reloadStatus(); String sysCode = queryData.getSysCode();
return Result.Success(SUCCESS, orderQuery.queryRouteRes(routeOrder)); RouteOrder routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, billcode);
if (routeOrder == null) {
routeOrder = orderQuery.queryByBillCodeAndSysCode(billcode, sysCode);
}
return Result.Success(SUCCESS, orderQuery.queryRouteRes(routeOrder.reloadStatus()));
} }
@ApiOperation("查询行程规划订单详情") @ApiOperation("查询行程规划订单详情")
@PostMapping("/query") @PostMapping("/query")
public Result<RouteOrderRes> queryOrder(@RequestBody OrderQueryData queryData) { public Result<RouteOrderRes> 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); RouteOrderRes routeOrderRes = orderQuery.queryRouteRes(routeOrder);
return Result.Success(SUCCESS, routeOrderRes); return Result.Success(SUCCESS, routeOrderRes);
} }

View File

@ -1,11 +1,9 @@
package com.chint.application.services; package com.chint.application.services;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.commands.*; import com.chint.application.commands.*;
import com.chint.application.dtos.AddLegData; import com.chint.application.dtos.AddLegData;
import com.chint.application.dtos.DeleteLegData; import com.chint.application.dtos.DeleteLegData;
import com.chint.domain.aggregates.order.Leg; 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.aggregates.order.RouteOrder;
import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.exceptions.OrderException; 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.service.order_sync.SyncAdapter;
import com.chint.domain.value_object.*; import com.chint.domain.value_object.*;
import com.chint.domain.value_object.enums.CurrencyType; 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.DataMessageConstant;
import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
@ -34,9 +31,8 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR;
import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; import static com.chint.infrastructure.constant.RouteConstant.*;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE;
@Service @Service
public class OrderApplicationService { public class OrderApplicationService {
@ -70,14 +66,14 @@ public class OrderApplicationService {
public RouteOrder saveOrder(OrderSaveData orderSaveData) { public RouteOrder saveOrder(OrderSaveData orderSaveData) {
RouteOrder order; RouteOrder order;
if (orderSaveData.getRouteId() != null) { 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); order.reloadStatus(orderSaveData, legFactory);
if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
throw new OrderException(DataMessageConstant.DATA_INVALID); throw new OrderException(DataMessageConstant.DATA_INVALID);
} }
} else { } else {
// order = orderFactory.createOrder(orderSaveData); // order = orderFactory.createOrder(orderSaveData);
throw new NotFoundException(CommonMessageConstant.NOT_FOUND); throw new NotFoundException(NOT_FOUND);
} }
RouteOrder routeOrder = orderDomainService.saveOrder(order); RouteOrder routeOrder = orderDomainService.saveOrder(order);
//这里保存订单之后需要为每个新添加的leg执行规划中事件 //这里保存订单之后需要为每个新添加的leg执行规划中事件
@ -87,122 +83,124 @@ public class OrderApplicationService {
@Transactional @Transactional
public RouteOrder addLegToOrder(AddLegData addLegData) { public RouteOrder addLegToOrder(AddLegData addLegData) {
RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) //这里也先去redis查询如果没有的话 再查询数据库
.orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); RouteOrder routeOrder = Optional.ofNullable(routeRepository
order.reloadStatus(); .findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo()))
checkLegDataTime(addLegData, order); .orElseGet(() -> Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId()))
.orElseThrow(() -> new NotFoundException(NOT_FOUND))).reloadStatus();
checkLegDataTime(addLegData, routeOrder);
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
List<Leg> legs = processLegData(legData, order); List<Leg> legs = processLegData(legData, routeOrder); //创建差旅行程单
legDomainService.queryLocation(legs); legDomainService.queryLocation(legs);
RouteOrder routeOrder = orderDomainService.saveOrder(order);
legs.forEach(leg -> { legs.forEach(leg -> {
leg.reloadStatus(); handleLegEvents(leg, addLegData.getLegData(), routeOrder);
legDomainService.addPreEvent(leg); routeOrder.addLeg(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();
}
}); });
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 @Transactional
public void changeLeg(AddLegData addLegData) { public void changeLeg(AddLegData addLegData) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
// 查找 Leg 并确保 RouteOrder 存在
//如果被修改的行程类型是火车或者飞机 就不需要结束时间 时间设置为开始时间当天的24小时 Leg leg = Optional.ofNullable(legRepository.findByLegId(Long.valueOf(legData.getLegId())))
String endTime = legData.getEndTime(); .orElseThrow(() -> new NotFoundException(NOT_FOUND));
if (legData.legType.equals(LEG_TYPE_TRAIN) || legData.legType.equals(LEG_TYPE_AIRPLANE)) { RouteOrder routeOrder = routeRepository.queryById(leg.getRouteId());
endTime = null; if (routeOrder == null) {
throw new NotFoundException(NOT_FOUND);
} }
Leg leg = Optional.ofNullable( checkLegDataTime(addLegData, routeOrder);
legRepository.findByLegId(Long.valueOf(legData.getLegId())) // 创建一个临时变量来避免 Lambda 表达式中的变量修改问题
).orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)).reloadStatus(); final Long legId = leg.getLegId();
leg.setCurrencyType(CurrencyType.getByCode(legData.getCurrencyType())); // 找到 LegItem
Leg oldLeg = BeanUtil.copyProperties(leg, Leg.class); leg = routeOrder.getLegItems().stream()
.filter(legItem -> legItem.getLegId().equals(legId))
.findFirst()
.orElseThrow(() -> new NotFoundException(NOT_FOUND))
.reloadStatus();
RouteOrder order = routeRepository.queryById(leg.getRouteId()).reloadStatus(); Leg oldLeg = leg.deepClone();
checkLegDataTime(addLegData, order);
//变更内容代码 // leg 进行更新
leg.setStartTime(LocalDateTime.parse(legData.getStartTime(), formatter)); leg.update(legData);
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());
}
}
// 对更新的行程补充地理信息
legDomainService.queryLocation(List.of(oldLeg, leg)); legDomainService.queryLocation(List.of(oldLeg, leg));
//保存变更事件理由 handleLegChangeEvent(leg, legData);
leg = legDomainService.addChangeEvent(leg, legData.getChangeReason()); // 保存 routeOrder 并重新加载状态
routeRepository.save(routeOrder);
//推送未同步事件 // 发送 BPM 保存结果
leg = legDomainService.addApproveEvent(leg);
legRepository.save(leg).reloadStatus();
//发送bpm保存结果
Command.of(BPMLegChangeCommand.class) Command.of(BPMLegChangeCommand.class)
.routeId(addLegData.getRouteId()) .routeId(addLegData.getRouteId())
.reason(addLegData.getLegData().getChangeReason()) .reason(addLegData.getLegData().getChangeReason())
.oldLeg(oldLeg) .oldLeg(oldLeg)
.routeOrder(order) .routeOrder(routeOrder)
.newleg(leg) .newleg(leg)
.changeType(1) .changeType(1)
.sendToQueue(); .sendToQueue();
} }
private Leg handleLegChangeEvent(Leg leg, LegData legData) {
// 保存变更事件理由
legDomainService.addChangeEvent(leg, legData.getChangeReason());
// 推送未同步事件
legDomainService.addApproveEvent(leg);
return leg;
}
private List<Leg> processLegData(LegData legData, RouteOrder order) { private List<Leg> processLegData(LegData legData, RouteOrder order) {
if (legData.getCurrencyType() == null) { if (legData.getCurrencyType() == null) {
legData.setCurrencyType(CurrencyType.RENMINBI.getCode()); legData.setCurrencyType(CurrencyType.RENMINBI.getCode());
} }
List<Leg> legs = switch (legData.legType) { return switch (legData.legType) {
case LegConstant.LEG_TYPE_TRAIN -> legFactory.createTrainLeg(legData); case LegConstant.LEG_TYPE_TRAIN -> legFactory.createTrainLeg(legData);
case LegConstant.LEG_TYPE_AIRPLANE -> legFactory.createFlightLeg(legData); case LegConstant.LEG_TYPE_AIRPLANE -> legFactory.createFlightLeg(legData);
default -> Collections.singletonList(legFactory.createLeg(legData)); default -> Collections.singletonList(legFactory.createLeg(legData));
}; };
legs.forEach(order::addLeg);
return legs;
} }
public RouteOrder deleteLegToOrder(DeleteLegData deleteLegData) { public RouteOrder deleteLegToOrder(DeleteLegData deleteLegData) {
RouteOrder order = Optional.ofNullable(routeRepository.queryById(deleteLegData.getRouteId())) 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()); order.deleteLeg(deleteLegData.getLegNo());
return orderDomainService.saveOrder(order); return orderDomainService.saveOrder(order);
} }

View File

@ -4,12 +4,15 @@ package com.chint.domain.aggregates.order;
import com.chint.domain.exceptions.LegEventException; import com.chint.domain.exceptions.LegEventException;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.value_object.LegData; 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.domain.value_object.enums.CurrencyType;
import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.util.DateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Column;
@ -92,6 +95,47 @@ public class Leg implements Serializable {
return new Leg(legId); 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() { public boolean legIsInternal() {
if (this.originLocation != null && !this.originLocation.isInternal()) { if (this.originLocation != null && !this.originLocation.isInternal()) {
@ -131,6 +175,52 @@ public class Leg implements Serializable {
.orElse(null); .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() { public Leg reloadStatus() {
if (eventList == null || eventList.isEmpty()) { if (eventList == null || eventList.isEmpty()) {
this.eventList = new ArrayList<>(); this.eventList = new ArrayList<>();

View File

@ -222,6 +222,7 @@ public class RouteOrder implements Serializable {
if (this.routeRequestList == null) { if (this.routeRequestList == null) {
this.routeRequestList = new ArrayList<>(); this.routeRequestList = new ArrayList<>();
} }
this.routeRequestList = new ArrayList<>(this.routeRequestList);
this.routeRequestList.add(routeRequest); this.routeRequestList.add(routeRequest);
return this; return this;
} }
@ -248,6 +249,7 @@ public class RouteOrder implements Serializable {
if (this.approveEvents == null) { if (this.approveEvents == null) {
this.approveEvents = new ArrayList<>(); this.approveEvents = new ArrayList<>();
} }
this.approveEvents = new ArrayList<>(this.approveEvents);
this.approveEvents.add(approvalEvent); this.approveEvents.add(approvalEvent);
return this; return this;
} }

View File

@ -64,8 +64,11 @@ public class RouteOrderFactory implements OrderFactory {
generate = generate + envMark; generate = generate + envMark;
} }
routeOrder.setRouteOrderNo(generate); 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()); routeOrder.setUserId(loginParam.getSfno());
ApproveOrderNo approveOrderNo = new ApproveOrderNo(); ApproveOrderNo approveOrderNo = new ApproveOrderNo();

View File

@ -19,10 +19,12 @@ public interface RouteRepository {
RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode); RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode);
RouteOrder findByActualOrderNoAndSysCode(String actualOrderNo,String sysCode); RouteOrder findByActualOrderNoAndSysCode(String actualOrderNo, String sysCode);
RouteOrder findByOrderNo(String orderNo); RouteOrder findByOrderNo(String orderNo);
List<RouteOrder> findByOrderNoIn(List<String> orderNo);
List<RouteOrder> findByOrderNoIn(List<String> orderNo);
Page<RouteOrder> findByOrderNoFuzzy(OrderQueryData orderQueryData); Page<RouteOrder> findByOrderNoFuzzy(OrderQueryData orderQueryData);
Page<RouteOrder> findByInstructions(OrderQueryData orderQueryData); Page<RouteOrder> findByInstructions(OrderQueryData orderQueryData);
@ -31,17 +33,22 @@ public interface RouteRepository {
void deleteByEmployeeNo(String employeeNo); void deleteByEmployeeNo(String employeeNo);
List<RouteOrder> findByEmployeeNo(String employeeNo); List<RouteOrder> findByEmployeeNo(String employeeNo);
PageResult<RouteOrder> pageQuery(OrderQueryData orderQueryData); PageResult<RouteOrder> pageQuery(OrderQueryData orderQueryData);
List<RouteOrder> findByActualOrderNoNotNull(OrderQueryData orderQueryData); List<RouteOrder> findByActualOrderNoNotNull(OrderQueryData orderQueryData);
List<RouteOrder> findAllByEmployeeNo(String employeeNo); List<RouteOrder> findAllByEmployeeNo(String employeeNo);
Page<RouteOrder> findByTime(OrderQueryData queryData); Page<RouteOrder> findByTime(OrderQueryData queryData);
// Page<RouteOrder> findByTime(OrderQueryData queryData); // Page<RouteOrder> findByTime(OrderQueryData queryData);
List<RouteOrder> findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd); List<RouteOrder> findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd);
RouteOrder findTempRouteOrderBySysCodeAndBillCode(String sysCode, String billCode);
RouteOrder saveTempRouteOrder(RouteOrder routeOrder, Long hours);
} }

View File

@ -51,39 +51,24 @@ public class LegDomainService {
List<OrderDetail> orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); List<OrderDetail> orderDetailList = orderDetailRepository.findByLegId(leg.getLegId());
orderDetailList.forEach(OrderDetail::reloadStatus); orderDetailList.forEach(OrderDetail::reloadStatus);
leg.reloadStatus(); leg.reloadStatus();
if (!orderDetailList.isEmpty()) { if (orderDetailList.isEmpty()) {
String lastOrderStatus = orderDetailList.get(orderDetailList.size() - 1).getOrderStatus(); return leg;
//如果是未同步状态 就不进行订单检查
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);
}
} }
String lastOrderStatus = orderDetailList.get(orderDetailList.size() - 1).getOrderStatus();
List<OrderDetail> details = orderDetailList.stream().filter(orderDetail -> orderDetail.getOrderStatus().equals(ORDER_EVENT_ORDERED_NAME) || // 如果是未同步状态 就不进行订单检查
orderDetail.getOrderStatus().equals(ORDER_EVENT_PAYED_NAME)).toList(); if (leg.getLegStatus().equals(LEG_STATUS_APPROVAL)) {
if (!details.isEmpty() && leg.getLegStatus() < LEG_EVENT_ORDERED) { return leg;
LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_ORDERED); }
leg.addEvent(legEvent); if (isRefundEvent(lastOrderStatus, leg)) {
return legRepository.save(leg);
}
if (isCancelEvent(lastOrderStatus, leg)) {
return legRepository.save(leg);
}
if (isOrderedOrPayedEvent(orderDetailList, leg)) {
return legRepository.save(leg); return legRepository.save(leg);
} }
if (leg.getLegStatus().equals(LEG_STATUS_CHANGE)) { if (leg.getLegStatus().equals(LEG_STATUS_CHANGE)) {
//如果发现该订单
LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL); LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL);
leg.addEvent(legEvent); leg.addEvent(legEvent);
return legRepository.save(leg); return legRepository.save(leg);
@ -91,6 +76,39 @@ public class LegDomainService {
return leg; 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<OrderDetail> orderDetailList, Leg leg) {
List<OrderDetail> 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) { public void deleteByLegNo(String legNo) {
Leg byLegNo = legRepository.findByLegNo(legNo); Leg byLegNo = legRepository.findByLegNo(legNo);
if (byLegNo == null) { if (byLegNo == null) {
@ -124,6 +142,9 @@ public class LegDomainService {
} }
public Leg addPreEvent(Leg leg) { public Leg addPreEvent(Leg leg) {
if(leg.getEventList() == null){
leg.setEventList(new ArrayList<>());
}
if (leg.getEventList().isEmpty()) { if (leg.getEventList().isEmpty()) {
LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_PREPARE); LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_PREPARE);
leg.addEvent(legEvent); leg.addEvent(legEvent);

View File

@ -8,17 +8,16 @@ import com.chint.domain.exceptions.OrderException;
import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order.RouteOrderFactory;
import com.chint.domain.factoriy.order_detail.OrderDetailFactory; 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.ApproveRouteData;
import com.chint.domain.value_object.UserLoginParam; import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.constant.RouteConstant;
import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.command.Command; 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.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.CTripOrderSearchRequest;
import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; 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.flight.*;
import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity; 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.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.LYSearchRequest;
import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse; import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse;
import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse; 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 jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -86,6 +85,9 @@ public class OrderDomainService {
@Autowired @Autowired
private SupplierRepository supplierRepository; private SupplierRepository supplierRepository;
@Autowired
private RedisTemplate<String, RouteOrder> redisTemplate;
private Set<String> companyBlackList = new HashSet<>(); private Set<String> companyBlackList = new HashSet<>();
public RouteOrder saveOrder(RouteOrder routeOrder) { public RouteOrder saveOrder(RouteOrder routeOrder) {
@ -113,16 +115,26 @@ public class OrderDomainService {
public RouteOrder createOrder(OrderCreateCommand command) { public RouteOrder createOrder(OrderCreateCommand command) {
User user = command.getUser(); User user = command.getUser();
UserLoginParam loginParam = user.getUserLoginParam(); 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())) .findByFakeOrderNoAndSysCode(loginParam.getBillcode(), loginParam.getSyscode()))
.orElseGet(() -> { .orElseGet(() -> {
RouteOrder order = routeOrderFactory.createRoute(command); RouteOrder createOrder = routeOrderFactory.createRoute(command);
order.setStandardLevel(user.getStandardLevel()); createOrder.setStandardLevel(user.getStandardLevel());
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(RouteConstant.APPROVAL_EVENT_PREPARE); ApprovalEvent approvalEvent = routeOrderFactory
order.addApprovalEvent(approvalEvent); .createApprovalEvent(RouteConstant.APPROVAL_EVENT_PREPARE);
this.saveOrder(order); createOrder.addApprovalEvent(approvalEvent);
return order; return createOrder;
}); });
//将创建号的临时单号保存到redis当中
routeRepository.saveTempRouteOrder(routeOrder, 48L);
return routeOrder;
} }
@ -178,7 +190,6 @@ public class OrderDomainService {
} }
private boolean isSpecialEventType(Integer orderEventType) { private boolean isSpecialEventType(Integer orderEventType) {
return orderEventType.equals(ORDER_EVENT_ETA) || return orderEventType.equals(ORDER_EVENT_ETA) ||
orderEventType.equals(ORDER_EVENT_CHANGE) || orderEventType.equals(ORDER_EVENT_CHANGE) ||

View File

@ -88,8 +88,10 @@ public class RouteRequestDomainService {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
List<Leg> legs = legDomainService.queryLegsCanSync(routeOrder, it); List<Leg> legs = legDomainService.queryLegsCanSync(routeOrder, it);
List<Long> legIdList = legs.stream().map(Leg::getLegId).collect(Collectors.toList()); List<Long> legIdList = legs.stream().map(Leg::getLegId).collect(Collectors.toList());
RouteRequest routeRequest = createRouteRequest(routeOrder, legIdList, it.getName()); if(!legIdList.isEmpty()){
syncRouteRequest(routeRequest, it); RouteRequest routeRequest = createRouteRequest(routeOrder, legIdList, it.getName());
syncRouteRequest(routeRequest, it);
}
}) })
)); ));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))

View File

@ -117,7 +117,19 @@ public class LegEventHandler implements LegEventService {
@Override @Override
public void approveRoute(OrderApprovalStartCommand command) { public void approveRoute(OrderApprovalStartCommand command) {
ApproveRouteData data = command.getData(); 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()) { if (routeOrder.getLegItems().isEmpty()) {
throw new OrderException(CommonMessageConstant.LEG_ERROR); throw new OrderException(CommonMessageConstant.LEG_ERROR);
} }
@ -134,7 +146,7 @@ public class LegEventHandler implements LegEventService {
routeOrder.addApprovalEvent(approvalEvent); routeOrder.addApprovalEvent(approvalEvent);
//当sysCode为H3BPM的时候 实用单号更新行程规划单的单号 //当sysCode为H3BPM的时候 实用单号更新行程规划单的单号
if (data.getSysCode().equals(H3_BPM)) { if (sysCode.equals(H3_BPM)) {
String generate = OrderNo.generate(H3_BPM, data.getActualOrderNo()); String generate = OrderNo.generate(H3_BPM, data.getActualOrderNo());
if (!envMark.equals("prod")) { if (!envMark.equals("prod")) {
routeOrder.setRouteOrderNo(generate + envMark); routeOrder.setRouteOrderNo(generate + envMark);

View File

@ -14,7 +14,7 @@ public class LegData {
public final String startTime; public final String startTime;
public final String endTime; public String endTime;
public final Long originId; public final Long originId;

View File

@ -13,6 +13,7 @@ public class OrderQueryData extends BaseQuery {
@ApiModelProperty("需要同步的行程规划单ID") @ApiModelProperty("需要同步的行程规划单ID")
private Long routeId; private Long routeId;
private String billcode; private String billcode;
private String fakeOrderNo;
private String actualOrderNo; private String actualOrderNo;
private String sysCode; private String sysCode;
private List<Integer> approvalStatusCodes; private List<Integer> approvalStatusCodes;

View File

@ -1,5 +1,6 @@
package com.chint.infrastructure.repository; package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.domain.value_object.OrderQueryData; 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.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Repository @Repository
public class RouteRepositoryImpl implements RouteRepository { public class RouteRepositoryImpl implements RouteRepository {
@ -26,6 +29,9 @@ public class RouteRepositoryImpl implements RouteRepository {
@Autowired @Autowired
private RouteCacheService routeCacheService; private RouteCacheService routeCacheService;
@Autowired
private RedisTemplate<String, RouteOrder> redisTemplate;
@Override @Override
public RouteOrder queryById(Long orderId) { public RouteOrder queryById(Long orderId) {
// jdbcRouteRepository.findByRouteId(orderId); // jdbcRouteRepository.findByRouteId(orderId);
@ -184,4 +190,23 @@ public class RouteRepositoryImpl implements RouteRepository {
public List<RouteOrder> findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd) { public List<RouteOrder> findByCreateTimeBetween(LocalDateTime createTimeStart, LocalDateTime createTimeEnd) {
return jdbcRouteRepository.findByCreateTimeBetween(createTimeStart, 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;
}
} }

View File

@ -250,7 +250,7 @@ public class CTripTest {
@Test @Test
void search() { void search() {
BaseContext.setCurrentUser(user); BaseContext.setCurrentUser(user);
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32002090029"); SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31472498556");
System.out.println(response); System.out.println(response);
} }

View File

@ -820,7 +820,7 @@ public class LYTest {
@Test @Test
void searchTrain() { void searchTrain() {
TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DTC24061977736328100"); TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24050672496002495");
Gson gson = new Gson(); Gson gson = new Gson();
String json = gson.toJson(trainOrderDetail); String json = gson.toJson(trainOrderDetail);
System.out.println(json); System.out.println(json);
@ -828,7 +828,7 @@ public class LYTest {
@Test @Test
void searchHotel() { void searchHotel() {
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240406120100189791"); HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240511131800297715");
Gson gson = new Gson(); Gson gson = new Gson();
String json = gson.toJson(hotelOrderDetail); String json = gson.toJson(hotelOrderDetail);
System.out.println(json); System.out.println(json);

View File

@ -310,9 +310,9 @@ class RouteApplicationTests {
@Test @Test
void loginSign() { void loginSign() {
String sfno = "190401151"; String sfno = "230615020";
String syscode = "FSSC"; String syscode = "FSSC";
String billcode = "CLSQ240225000099"; String billcode = "CLSQ240620004123";
String companycode = "正泰集团股份有限公司"; String companycode = "正泰集团股份有限公司";
String timespan = "1708908662738"; String timespan = "1708908662738";
String s = Digest.md5(sfno + syscode + billcode + companycode + LOGIN_SECRET_KEY + timespan); String s = Digest.md5(sfno + syscode + billcode + companycode + LOGIN_SECRET_KEY + timespan);