流程不重复发起调整
This commit is contained in:
parent
c8d88f707c
commit
42eafa33d2
|
@ -0,0 +1,356 @@
|
||||||
|
package com.chint.domain.service;
|
||||||
|
|
||||||
|
import com.chint.application.commands.BPMAuditCommand;
|
||||||
|
import com.chint.domain.aggregates.order.Leg;
|
||||||
|
import com.chint.domain.aggregates.order.OrderDetail;
|
||||||
|
import com.chint.domain.aggregates.order.RouteOrder;
|
||||||
|
import com.chint.domain.aggregates.system.ProcessInitiationControl;
|
||||||
|
import com.chint.domain.exceptions.NotFoundException;
|
||||||
|
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.infrastructure.constant.CommonMessageConstant;
|
||||||
|
import com.chint.infrastructure.repository.jdbc.JdbcLegRepository;
|
||||||
|
import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository;
|
||||||
|
import com.chint.infrastructure.repository.jdbc.JdbcProcessInitiationControlRepository;
|
||||||
|
import com.chint.infrastructure.util.DelayDispatch;
|
||||||
|
import com.chint.interfaces.rest.bpm.BPMParamFactory;
|
||||||
|
import com.chint.interfaces.rest.bpm.BPMRequest;
|
||||||
|
import com.chint.interfaces.rest.bpm.dto.ANExceedStandardDto;
|
||||||
|
import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto;
|
||||||
|
import com.chint.interfaces.rest.bpm.dto.RescheduleDto;
|
||||||
|
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;
|
||||||
|
import com.chint.interfaces.rest.ctrip.dto.search.flight.ChangeInfo;
|
||||||
|
import com.chint.interfaces.rest.ctrip.dto.search.flight.FlightOrderInfoEntity;
|
||||||
|
import com.chint.interfaces.rest.ly.LYSearchRequest;
|
||||||
|
import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse;
|
||||||
|
import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailResponse;
|
||||||
|
import com.chint.interfaces.rest.user.UserHttpRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.chint.infrastructure.constant.BPMConstant.*;
|
||||||
|
import static com.chint.infrastructure.constant.BPMConstant.REFUND_TYPE_FLIGHT;
|
||||||
|
import static com.chint.infrastructure.constant.BelongSystemConstant.BELONG_SYS_CODE_ANFSSC;
|
||||||
|
import static com.chint.infrastructure.constant.LegConstant.*;
|
||||||
|
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_OTHER;
|
||||||
|
import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_CHANGE;
|
||||||
|
import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_REFUND;
|
||||||
|
import static com.chint.infrastructure.constant.SupplierNameConstant.*;
|
||||||
|
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y_BPM_NAME;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class BPMOrderDomainService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RouteRepository routeRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BPMParamFactory bpmParamFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BPMRequest bpmRequest;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CTripOrderSearchRequest cTripOrderSearchRequest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LYSearchRequest lySearchRequest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcOrderDetailRepository jdbcOrderDetailRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcLegRepository jdbcLegRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcProcessInitiationControlRepository jdbcProcessInitiationControlRepository;
|
||||||
|
|
||||||
|
//超标
|
||||||
|
@Transactional
|
||||||
|
public void toBpmAuditETA(BPMAuditCommand command) {
|
||||||
|
OrderDetail orderDetail = command.getExtensionData();
|
||||||
|
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 1);
|
||||||
|
//不为空表示已推动过超标,直接返回结果
|
||||||
|
if (!byOrderNoAndTag.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
|
||||||
|
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
|
||||||
|
String employeeNo = orderDetail.getEmployeeNo();//用户id
|
||||||
|
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();//用户编号
|
||||||
|
//获取公司编号
|
||||||
|
//安能超标
|
||||||
|
if (BELONG_SYS_CODE_ANFSSC.equals(sysCode)) {
|
||||||
|
ANExceedStandardDto anExceedStandardDto = switch (command.getProductType()) {
|
||||||
|
case LEG_TYPE_TRAIN -> bpmParamFactory.ANCreatAuditParamByTrain(orderDetail);
|
||||||
|
case LEG_TYPE_AIRPLANE -> bpmParamFactory.ANCreatAuditParamByFlight(orderDetail);
|
||||||
|
case LEG_TYPE_HOTEL -> bpmParamFactory.ANCreatAuditParamByHotel(orderDetail);
|
||||||
|
case LEG_TYPE_TAXI -> bpmParamFactory.ANCreatAuditParamByCar(orderDetail);
|
||||||
|
case LEG_TYPE_OTHER -> bpmParamFactory.ANCreatAuditParamByOther(orderDetail);
|
||||||
|
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
|
||||||
|
};
|
||||||
|
Long legId = orderDetail.getLegId();//节点id
|
||||||
|
Leg leg = jdbcLegRepository.findByLegId(legId);
|
||||||
|
anExceedStandardDto.setApplyNo(routeOrder.getApproveOrderNo().getFakeOrderNo())//申请单号
|
||||||
|
.setLegNo(leg == null ? "" : leg.getLegNo());//行程编号
|
||||||
|
DelayDispatch.attemptToSend(() -> bpmRequest.ANExceedStandard(anExceedStandardDto).getSuccess(),
|
||||||
|
0);
|
||||||
|
} else {
|
||||||
|
//其它
|
||||||
|
ExceedStandardDto exceedStandardDto = switch (command.getProductType()) {
|
||||||
|
case LEG_TYPE_TRAIN -> bpmParamFactory.creatAuditParamByTrain(orderDetail);
|
||||||
|
case LEG_TYPE_AIRPLANE -> bpmParamFactory.creatAuditParamByFlight(orderDetail);
|
||||||
|
case LEG_TYPE_HOTEL -> bpmParamFactory.creatAuditParamByHotel(orderDetail);
|
||||||
|
case LEG_TYPE_TAXI -> bpmParamFactory.creatAuditParamByCar(orderDetail);
|
||||||
|
case LEG_TYPE_OTHER -> bpmParamFactory.creatAuditParamByOther(orderDetail);
|
||||||
|
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
|
||||||
|
};
|
||||||
|
exceedStandardDto.setReason(command.getReason());
|
||||||
|
DelayDispatch.attemptToSend(() -> bpmRequest.exceedStandard(exceedStandardDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
//结束保存推送信息
|
||||||
|
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
||||||
|
processInitiationControl.setOrderNo(orderDetail.getOrderNo())
|
||||||
|
.setTag(1);
|
||||||
|
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
||||||
|
}
|
||||||
|
|
||||||
|
//改签
|
||||||
|
@Transactional
|
||||||
|
public void toBpmReschedule(BPMAuditCommand command) {
|
||||||
|
OrderDetail orderDetail = command.getExtensionData();
|
||||||
|
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
|
||||||
|
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
|
||||||
|
String reason = command.getReason();
|
||||||
|
//创建改签对象
|
||||||
|
RescheduleDto rescheduleDto = new RescheduleDto();
|
||||||
|
rescheduleDto.setFee(orderDetail.getPrice() == null ? new BigDecimal(0) : new BigDecimal(orderDetail.getPrice()))//费用
|
||||||
|
.setOrderNo(orderDetail.getOrderNo())//订单号
|
||||||
|
.setReason(reason);//原因
|
||||||
|
//携程
|
||||||
|
if (orderDetail.getSupplierName().equals(SUPPLIER_C_TRIP)) {
|
||||||
|
//退票
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 3);
|
||||||
|
//不为空表示已推动过退票,直接返回结果
|
||||||
|
if (!byOrderNoAndTag.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Integer rebookId = null;//默认为空
|
||||||
|
rescheduleDto.setOrderSource(SUPPLIER_C_TRIP_BPM_NAME);//携程商旅
|
||||||
|
//查询订单明细
|
||||||
|
SearchOrderResponse searchOrderResponse = cTripOrderSearchRequest.searchOrderResponseByOrderId(orderDetail.getOrderNo());
|
||||||
|
//机票改签
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
//设置改签原时间、改签后时间、改签原因
|
||||||
|
rebookId = setCTripChangeFlight(rescheduleDto, searchOrderResponse);
|
||||||
|
rescheduleDto.setOrderType(RESCHEDULE_TYPE_FLIGHT);
|
||||||
|
//改签
|
||||||
|
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo() + "-" + rebookId, 2);
|
||||||
|
//不为空表示已推动过改签,直接返回结果
|
||||||
|
if (!byOrderNoAndTag.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//机票退票
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
String refundResonDesc = "";
|
||||||
|
try {
|
||||||
|
FlightOrderInfoEntity flightOrderInfoList = searchOrderResponse.getItineraryList().get(0).getFlightOrderInfoList().get(0);
|
||||||
|
refundResonDesc = flightOrderInfoList.getRefundInfo().get(0).getRefundResonDesc();
|
||||||
|
rescheduleDto.setReason(StringUtils.isNotBlank(refundResonDesc) ? refundResonDesc : "计划有变,更改行程");
|
||||||
|
} catch (Exception e) {
|
||||||
|
//如果越界标识没有值
|
||||||
|
rescheduleDto.setReason("计划有变,更改行程");
|
||||||
|
}
|
||||||
|
rescheduleDto.setOrderType(REFUND_TYPE_FLIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
String employeeNo = orderDetail.getEmployeeNo();
|
||||||
|
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();
|
||||||
|
//发送
|
||||||
|
DelayDispatch.attemptToSend(() -> bpmRequest.reschedule(rescheduleDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
||||||
|
0);
|
||||||
|
|
||||||
|
//结束保存推送信息
|
||||||
|
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
processInitiationControl.setOrderNo(orderDetail.getOrderNo() + "-" + rebookId);
|
||||||
|
processInitiationControl.setTag(2);
|
||||||
|
}
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
processInitiationControl.setOrderNo(orderDetail.getOrderNo());
|
||||||
|
processInitiationControl.setTag(3);
|
||||||
|
}
|
||||||
|
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
||||||
|
}
|
||||||
|
|
||||||
|
//同程
|
||||||
|
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) {
|
||||||
|
//改签
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 2);
|
||||||
|
//不为空表示已推动过改签,直接返回结果
|
||||||
|
if (!byOrderNoAndTag.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//退票
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 3);
|
||||||
|
//不为空表示已推动过退票,直接返回结果
|
||||||
|
if (!byOrderNoAndTag.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rescheduleDto.setOrderSource(SUPPLIER_L_Y_BPM_NAME);//同程商旅
|
||||||
|
//火车票改签
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_TRAIN) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
TrainDetailResponse trainDetailResponse = lySearchRequest.getTrainOrderDetail(orderDetail.getOrderNo());
|
||||||
|
setLYChangeTrain(rescheduleDto, trainDetailResponse);//火车票只支持一次改签
|
||||||
|
rescheduleDto.setOrderType(RESCHEDULE_TYPE_TRAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
//火车票退票
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_TRAIN) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
rescheduleDto.setOrderType(REFUND_TYPE_TRAIN);
|
||||||
|
rescheduleDto.setReason("计划有变,更改行程");//目前没有原因
|
||||||
|
}
|
||||||
|
//机票改签
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
// 将LocalDateTime对象格式化成字符串
|
||||||
|
String rebookStartTime = orderDetail.getStartTime().format(formatter);
|
||||||
|
rescheduleDto.setRebookStartTime(rebookStartTime);//变更后时间
|
||||||
|
|
||||||
|
FlightOrderResponse flightOrderResponse = lySearchRequest.getFlightOrderDetail(orderDetail.getOrderNo());
|
||||||
|
//原订单
|
||||||
|
String parentOrderSerialNo = flightOrderResponse.getData().getOrderDetails().getParentOrderSerialNo();
|
||||||
|
OrderDetail orderDetailOld = jdbcOrderDetailRepository.findFirstByOrderNo(parentOrderSerialNo);
|
||||||
|
String startTime = orderDetailOld.getStartTime().format(formatter);
|
||||||
|
rescheduleDto.setStartTime(startTime);
|
||||||
|
rescheduleDto.setOrderType(RESCHEDULE_TYPE_FLIGHT);
|
||||||
|
rescheduleDto.setReason("计划有变,更改行程");//目前没有原因
|
||||||
|
}
|
||||||
|
|
||||||
|
//机票退票
|
||||||
|
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
rescheduleDto.setOrderType(REFUND_TYPE_FLIGHT);
|
||||||
|
rescheduleDto.setReason("计划有变,更改行程");
|
||||||
|
}
|
||||||
|
|
||||||
|
String employeeNo = orderDetail.getEmployeeNo();
|
||||||
|
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();
|
||||||
|
//发送
|
||||||
|
DelayDispatch.attemptToSend(() -> bpmRequest.reschedule(rescheduleDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
||||||
|
0);
|
||||||
|
|
||||||
|
//结束保存推送信息
|
||||||
|
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
||||||
|
processInitiationControl.setOrderNo(orderDetail.getOrderNo());
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
||||||
|
processInitiationControl.setTag(2);
|
||||||
|
}
|
||||||
|
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
||||||
|
processInitiationControl.setTag(3);
|
||||||
|
}
|
||||||
|
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//携程机票改签
|
||||||
|
private Integer setCTripChangeFlight(RescheduleDto rescheduleDto, SearchOrderResponse searchOrderResponse) {
|
||||||
|
List<ItineraryEntity> itineraryList = searchOrderResponse.getItineraryList();
|
||||||
|
try {
|
||||||
|
ItineraryEntity itineraryEntity = itineraryList.get(0);
|
||||||
|
FlightOrderInfoEntity flightOrderInfoList = itineraryEntity.getFlightOrderInfoList().get(0);
|
||||||
|
//改签前时间
|
||||||
|
String createTime = flightOrderInfoList.getFlightInfo().get(0).getTakeoffTime();
|
||||||
|
List<ChangeInfo> changeInfoList = flightOrderInfoList.getPassengerInfo().get(0).getSequenceInfo().get(0).getChangeInfo();
|
||||||
|
//多次改签
|
||||||
|
if (changeInfoList.size() >= 2) {
|
||||||
|
ChangeInfo changeInfoOld = changeInfoList.get(changeInfoList.size() - 2);
|
||||||
|
String cTakeOffTimeOld = changeInfoOld.getCTakeOffTime();//前一次改签时间
|
||||||
|
ChangeInfo changeInfoNew = changeInfoList.get(changeInfoList.size() - 1);
|
||||||
|
String cTakeOffTimeNew = changeInfoNew.getCTakeOffTime();//最后一次改签时间
|
||||||
|
String rebookReasonDescNew = changeInfoNew.getRebookReasonDesc();//最后一次改签原因
|
||||||
|
//设置值
|
||||||
|
rescheduleDto.setStartTime(cTakeOffTimeOld)
|
||||||
|
.setRebookStartTime(cTakeOffTimeNew)
|
||||||
|
.setReason(rebookReasonDescNew);
|
||||||
|
return changeInfoNew.getRebookId();
|
||||||
|
} else {
|
||||||
|
ChangeInfo changeInfo = changeInfoList.get(changeInfoList.size() - 1);
|
||||||
|
//改签后时间
|
||||||
|
String cTakeOffTime = changeInfo.getCTakeOffTime();
|
||||||
|
//改签原因
|
||||||
|
String RebookReasonDesc = changeInfo.getRebookReasonDesc();
|
||||||
|
rescheduleDto.setStartTime(createTime)
|
||||||
|
.setRebookStartTime(cTakeOffTime)
|
||||||
|
.setReason(RebookReasonDesc);
|
||||||
|
return changeInfo.getRebookId();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
rescheduleDto.setStartTime("")
|
||||||
|
.setRebookStartTime("")
|
||||||
|
.setReason("计划有变,更改行程");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//火车票改签
|
||||||
|
private void setLYChangeTrain(RescheduleDto rescheduleDto, TrainDetailResponse trainDetailResponse) {
|
||||||
|
TrainDetailResponse.TrainDetailData data = trainDetailResponse.getData();
|
||||||
|
String trainNoOld = data.getTrainNo();//原车次
|
||||||
|
String planBeginDateOld = data.getPlanBeginDate();//原时间
|
||||||
|
rescheduleDto.setStartTime(planBeginDateOld)
|
||||||
|
.setTrainNumber(trainNoOld);//原车次
|
||||||
|
if (!data.getItems().isEmpty()) {
|
||||||
|
TrainDetailResponse.Item item = data.getItems().get(0);
|
||||||
|
String seatClassOld = item.getSeatClass();//原席别
|
||||||
|
TrainDetailResponse.ChangeInfo changeInfo = item.getChangeInfo();
|
||||||
|
//如果是空表示是改签后订单
|
||||||
|
if (Objects.isNull(changeInfo)) {
|
||||||
|
//获取原订单的changeInfo
|
||||||
|
String parentOrderSerialNo = data.getParentOrderSerialNo();
|
||||||
|
TrainDetailResponse parentTrainDetailResponse = lySearchRequest.getTrainOrderDetail(parentOrderSerialNo);
|
||||||
|
if (parentTrainDetailResponse != null) {
|
||||||
|
changeInfo = parentTrainDetailResponse.getData().getItems().get(0).getChangeInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
String planBeginDateNew = "";
|
||||||
|
String trainNoNew = "";
|
||||||
|
String seatClassNew = "";
|
||||||
|
//不为空
|
||||||
|
if (!Objects.isNull(changeInfo)) {
|
||||||
|
planBeginDateNew = changeInfo.getPlanBeginDate();//改签后时间
|
||||||
|
trainNoNew = changeInfo.getTrainNo();//改签后车次
|
||||||
|
seatClassNew = changeInfo.getChangeItem().getSeatClass();//改签后席别
|
||||||
|
}
|
||||||
|
//设置值
|
||||||
|
rescheduleDto.setRebookStartTime(planBeginDateNew)
|
||||||
|
.setSeatingStandard(seatClassOld)//原席别
|
||||||
|
.setRebookTrainNumber(trainNoNew)//改签后车次
|
||||||
|
.setRebookSeatingStandard(seatClassNew)//改签后席别
|
||||||
|
.setReason("计划有变,更改行程");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -114,7 +114,7 @@ public class OrderDomainService {
|
||||||
private JdbcLegRepository jdbcLegRepository;
|
private JdbcLegRepository jdbcLegRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcProcessInitiationControlRepository jdbcProcessInitiationControlRepository;
|
private BPMOrderDomainService bpmOrderDomainService;
|
||||||
|
|
||||||
private Set<String> companyBlackList = new HashSet<>();
|
private Set<String> companyBlackList = new HashSet<>();
|
||||||
|
|
||||||
|
@ -272,287 +272,14 @@ public class OrderDomainService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ListenTo(command = "BPMAuditCommand", order = 0)
|
@ListenTo(command = "BPMAuditCommand", order = 0)
|
||||||
@Transactional
|
|
||||||
public void toBpmAudit(BPMAuditCommand command) {
|
public void toBpmAudit(BPMAuditCommand command) {
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_ETA)) {
|
if (command.getOperationType().equals(ORDER_EVENT_ETA)) {
|
||||||
toBpmAuditETA(command);
|
bpmOrderDomainService.toBpmAuditETA(command);
|
||||||
} else if (
|
} else if (
|
||||||
(command.getOperationType().equals(ORDER_EVENT_CHANGE) || command.getOperationType().equals(ORDER_EVENT_REFUND)) &&
|
(command.getOperationType().equals(ORDER_EVENT_CHANGE) || command.getOperationType().equals(ORDER_EVENT_REFUND)) &&
|
||||||
(command.getProductType().equals(LEG_TYPE_TRAIN) || command.getProductType().equals(LEG_TYPE_AIRPLANE))
|
(command.getProductType().equals(LEG_TYPE_TRAIN) || command.getProductType().equals(LEG_TYPE_AIRPLANE))
|
||||||
) {
|
) {
|
||||||
toBpmReschedule(command);
|
bpmOrderDomainService.toBpmReschedule(command);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void toBpmAuditETA(BPMAuditCommand command) {
|
|
||||||
OrderDetail orderDetail = command.getExtensionData();
|
|
||||||
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 1);
|
|
||||||
//不为空表示已推动过超标,直接返回结果
|
|
||||||
if (!byOrderNoAndTag.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
|
|
||||||
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
|
|
||||||
String employeeNo = orderDetail.getEmployeeNo();//用户id
|
|
||||||
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();//用户编号
|
|
||||||
//获取公司编号
|
|
||||||
//安能超标
|
|
||||||
if (BELONG_SYS_CODE_ANFSSC.equals(sysCode)) {
|
|
||||||
ANExceedStandardDto anExceedStandardDto = switch (command.getProductType()) {
|
|
||||||
case LEG_TYPE_TRAIN -> bpmParamFactory.ANCreatAuditParamByTrain(orderDetail);
|
|
||||||
case LEG_TYPE_AIRPLANE -> bpmParamFactory.ANCreatAuditParamByFlight(orderDetail);
|
|
||||||
case LEG_TYPE_HOTEL -> bpmParamFactory.ANCreatAuditParamByHotel(orderDetail);
|
|
||||||
case LEG_TYPE_TAXI -> bpmParamFactory.ANCreatAuditParamByCar(orderDetail);
|
|
||||||
case LEG_TYPE_OTHER -> bpmParamFactory.ANCreatAuditParamByOther(orderDetail);
|
|
||||||
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
|
|
||||||
};
|
|
||||||
Long legId = orderDetail.getLegId();//节点id
|
|
||||||
Leg leg = jdbcLegRepository.findByLegId(legId);
|
|
||||||
anExceedStandardDto.setApplyNo(routeOrder.getApproveOrderNo().getFakeOrderNo())//申请单号
|
|
||||||
.setLegNo(leg == null ? "" : leg.getLegNo());//行程编号
|
|
||||||
DelayDispatch.attemptToSend(() -> bpmRequest.ANExceedStandard(anExceedStandardDto).getSuccess(),
|
|
||||||
0);
|
|
||||||
} else {
|
|
||||||
//其它
|
|
||||||
ExceedStandardDto exceedStandardDto = switch (command.getProductType()) {
|
|
||||||
case LEG_TYPE_TRAIN -> bpmParamFactory.creatAuditParamByTrain(orderDetail);
|
|
||||||
case LEG_TYPE_AIRPLANE -> bpmParamFactory.creatAuditParamByFlight(orderDetail);
|
|
||||||
case LEG_TYPE_HOTEL -> bpmParamFactory.creatAuditParamByHotel(orderDetail);
|
|
||||||
case LEG_TYPE_TAXI -> bpmParamFactory.creatAuditParamByCar(orderDetail);
|
|
||||||
case LEG_TYPE_OTHER -> bpmParamFactory.creatAuditParamByOther(orderDetail);
|
|
||||||
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
|
|
||||||
};
|
|
||||||
exceedStandardDto.setReason(command.getReason());
|
|
||||||
DelayDispatch.attemptToSend(() -> bpmRequest.exceedStandard(exceedStandardDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
//结束保存推送信息
|
|
||||||
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
|
||||||
processInitiationControl.setOrderNo(orderDetail.getOrderNo())
|
|
||||||
.setTag(1);
|
|
||||||
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
|
||||||
}
|
|
||||||
@Transactional
|
|
||||||
public void toBpmReschedule(BPMAuditCommand command) {
|
|
||||||
OrderDetail orderDetail = command.getExtensionData();
|
|
||||||
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
|
|
||||||
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
|
|
||||||
String reason = command.getReason();
|
|
||||||
//创建改签对象
|
|
||||||
RescheduleDto rescheduleDto = new RescheduleDto();
|
|
||||||
rescheduleDto.setFee(orderDetail.getPrice() == null ? new BigDecimal(0) : new BigDecimal(orderDetail.getPrice()))//费用
|
|
||||||
.setOrderNo(orderDetail.getOrderNo())//订单号
|
|
||||||
.setReason(reason);//原因
|
|
||||||
//携程
|
|
||||||
if (orderDetail.getSupplierName().equals(SUPPLIER_C_TRIP)) {
|
|
||||||
//退票
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 3);
|
|
||||||
//不为空表示已推动过退票,直接返回结果
|
|
||||||
if (!byOrderNoAndTag.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Integer rebookId = null;//默认为空
|
|
||||||
rescheduleDto.setOrderSource(SUPPLIER_C_TRIP_BPM_NAME);//携程商旅
|
|
||||||
//查询订单明细
|
|
||||||
SearchOrderResponse searchOrderResponse = cTripOrderSearchRequest.searchOrderResponseByOrderId(orderDetail.getOrderNo());
|
|
||||||
//机票改签
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
//设置改签原时间、改签后时间、改签原因
|
|
||||||
rebookId = setCTripChangeFlight(rescheduleDto, searchOrderResponse);
|
|
||||||
rescheduleDto.setOrderType(RESCHEDULE_TYPE_FLIGHT);
|
|
||||||
//改签
|
|
||||||
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo() + "-" + rebookId, 2);
|
|
||||||
//不为空表示已推动过改签,直接返回结果
|
|
||||||
if (!byOrderNoAndTag.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//机票退票
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
String refundResonDesc = "";
|
|
||||||
try {
|
|
||||||
FlightOrderInfoEntity flightOrderInfoList = searchOrderResponse.getItineraryList().get(0).getFlightOrderInfoList().get(0);
|
|
||||||
refundResonDesc = flightOrderInfoList.getRefundInfo().get(0).getRefundResonDesc();
|
|
||||||
rescheduleDto.setReason(StringUtils.isNotBlank(refundResonDesc) ? refundResonDesc : "计划有变,更改行程");
|
|
||||||
} catch (Exception e) {
|
|
||||||
//如果越界标识没有值
|
|
||||||
rescheduleDto.setReason("计划有变,更改行程");
|
|
||||||
}
|
|
||||||
rescheduleDto.setOrderType(REFUND_TYPE_FLIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
String employeeNo = orderDetail.getEmployeeNo();
|
|
||||||
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();
|
|
||||||
//发送
|
|
||||||
DelayDispatch.attemptToSend(() -> bpmRequest.reschedule(rescheduleDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
|
||||||
0);
|
|
||||||
|
|
||||||
//结束保存推送信息
|
|
||||||
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
processInitiationControl.setOrderNo(orderDetail.getOrderNo() + "-" + rebookId);
|
|
||||||
processInitiationControl.setTag(2);
|
|
||||||
}
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
processInitiationControl.setOrderNo(orderDetail.getOrderNo());
|
|
||||||
processInitiationControl.setTag(3);
|
|
||||||
}
|
|
||||||
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
|
||||||
}
|
|
||||||
|
|
||||||
//同程
|
|
||||||
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) {
|
|
||||||
//改签
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 2);
|
|
||||||
//不为空表示已推动过改签,直接返回结果
|
|
||||||
if (!byOrderNoAndTag.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//退票
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
List<ProcessInitiationControl> byOrderNoAndTag = jdbcProcessInitiationControlRepository.findByOrderNoAndTag(orderDetail.getOrderNo(), 3);
|
|
||||||
//不为空表示已推动过退票,直接返回结果
|
|
||||||
if (!byOrderNoAndTag.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rescheduleDto.setOrderSource(SUPPLIER_L_Y_BPM_NAME);//同程商旅
|
|
||||||
//火车票改签
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_TRAIN) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
TrainDetailResponse trainDetailResponse = lySearchRequest.getTrainOrderDetail(orderDetail.getOrderNo());
|
|
||||||
setLYChangeTrain(rescheduleDto, trainDetailResponse);//火车票只支持一次改签
|
|
||||||
rescheduleDto.setOrderType(RESCHEDULE_TYPE_TRAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
//火车票退票
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_TRAIN) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
rescheduleDto.setOrderType(REFUND_TYPE_TRAIN);
|
|
||||||
rescheduleDto.setReason("计划有变,更改行程");//目前没有原因
|
|
||||||
}
|
|
||||||
//机票改签
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
// 将LocalDateTime对象格式化成字符串
|
|
||||||
String rebookStartTime = orderDetail.getStartTime().format(formatter);
|
|
||||||
rescheduleDto.setRebookStartTime(rebookStartTime);//变更后时间
|
|
||||||
|
|
||||||
FlightOrderResponse flightOrderResponse = lySearchRequest.getFlightOrderDetail(orderDetail.getOrderNo());
|
|
||||||
//原订单
|
|
||||||
String parentOrderSerialNo = flightOrderResponse.getData().getOrderDetails().getParentOrderSerialNo();
|
|
||||||
OrderDetail orderDetailOld = jdbcOrderDetailRepository.findFirstByOrderNo(parentOrderSerialNo);
|
|
||||||
String startTime = orderDetailOld.getStartTime().format(formatter);
|
|
||||||
rescheduleDto.setStartTime(startTime);
|
|
||||||
rescheduleDto.setOrderType(RESCHEDULE_TYPE_FLIGHT);
|
|
||||||
rescheduleDto.setReason("计划有变,更改行程");//目前没有原因
|
|
||||||
}
|
|
||||||
|
|
||||||
//机票退票
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE) && command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
rescheduleDto.setOrderType(REFUND_TYPE_FLIGHT);
|
|
||||||
rescheduleDto.setReason("计划有变,更改行程");
|
|
||||||
}
|
|
||||||
|
|
||||||
String employeeNo = orderDetail.getEmployeeNo();
|
|
||||||
String accountCompany = routeOrder.getApproveOrderNo().getAccountCompany();
|
|
||||||
//发送
|
|
||||||
DelayDispatch.attemptToSend(() -> bpmRequest.reschedule(rescheduleDto, sysCode, employeeNo, accountCompany).getSuccess(),
|
|
||||||
0);
|
|
||||||
|
|
||||||
//结束保存推送信息
|
|
||||||
ProcessInitiationControl processInitiationControl = new ProcessInitiationControl();
|
|
||||||
processInitiationControl.setOrderNo(orderDetail.getOrderNo());
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_CHANGE)) {
|
|
||||||
processInitiationControl.setTag(2);
|
|
||||||
}
|
|
||||||
if (command.getOperationType().equals(ORDER_EVENT_REFUND)) {
|
|
||||||
processInitiationControl.setTag(3);
|
|
||||||
}
|
|
||||||
jdbcProcessInitiationControlRepository.save(processInitiationControl);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//携程机票改签
|
|
||||||
private Integer setCTripChangeFlight(RescheduleDto rescheduleDto, SearchOrderResponse searchOrderResponse) {
|
|
||||||
List<ItineraryEntity> itineraryList = searchOrderResponse.getItineraryList();
|
|
||||||
try {
|
|
||||||
ItineraryEntity itineraryEntity = itineraryList.get(0);
|
|
||||||
FlightOrderInfoEntity flightOrderInfoList = itineraryEntity.getFlightOrderInfoList().get(0);
|
|
||||||
//改签前时间
|
|
||||||
String createTime = flightOrderInfoList.getFlightInfo().get(0).getTakeoffTime();
|
|
||||||
List<ChangeInfo> changeInfoList = flightOrderInfoList.getPassengerInfo().get(0).getSequenceInfo().get(0).getChangeInfo();
|
|
||||||
//多次改签
|
|
||||||
if (changeInfoList.size() >= 2) {
|
|
||||||
ChangeInfo changeInfoOld = changeInfoList.get(changeInfoList.size() - 2);
|
|
||||||
String cTakeOffTimeOld = changeInfoOld.getCTakeOffTime();//前一次改签时间
|
|
||||||
ChangeInfo changeInfoNew = changeInfoList.get(changeInfoList.size() - 1);
|
|
||||||
String cTakeOffTimeNew = changeInfoNew.getCTakeOffTime();//最后一次改签时间
|
|
||||||
String rebookReasonDescNew = changeInfoNew.getRebookReasonDesc();//最后一次改签原因
|
|
||||||
//设置值
|
|
||||||
rescheduleDto.setStartTime(cTakeOffTimeOld)
|
|
||||||
.setRebookStartTime(cTakeOffTimeNew)
|
|
||||||
.setReason(rebookReasonDescNew);
|
|
||||||
return changeInfoNew.getRebookId();
|
|
||||||
} else {
|
|
||||||
ChangeInfo changeInfo = changeInfoList.get(changeInfoList.size() - 1);
|
|
||||||
//改签后时间
|
|
||||||
String cTakeOffTime = changeInfo.getCTakeOffTime();
|
|
||||||
//改签原因
|
|
||||||
String RebookReasonDesc = changeInfo.getRebookReasonDesc();
|
|
||||||
rescheduleDto.setStartTime(createTime)
|
|
||||||
.setRebookStartTime(cTakeOffTime)
|
|
||||||
.setReason(RebookReasonDesc);
|
|
||||||
return changeInfo.getRebookId();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
rescheduleDto.setStartTime("")
|
|
||||||
.setRebookStartTime("")
|
|
||||||
.setReason("计划有变,更改行程");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//火车票改签
|
|
||||||
private void setLYChangeTrain(RescheduleDto rescheduleDto, TrainDetailResponse trainDetailResponse) {
|
|
||||||
TrainDetailResponse.TrainDetailData data = trainDetailResponse.getData();
|
|
||||||
String trainNoOld = data.getTrainNo();//原车次
|
|
||||||
String planBeginDateOld = data.getPlanBeginDate();//原时间
|
|
||||||
rescheduleDto.setStartTime(planBeginDateOld)
|
|
||||||
.setTrainNumber(trainNoOld);//原车次
|
|
||||||
if (!data.getItems().isEmpty()) {
|
|
||||||
TrainDetailResponse.Item item = data.getItems().get(0);
|
|
||||||
String seatClassOld = item.getSeatClass();//原席别
|
|
||||||
TrainDetailResponse.ChangeInfo changeInfo = item.getChangeInfo();
|
|
||||||
//如果是空表示是改签后订单
|
|
||||||
if (Objects.isNull(changeInfo)) {
|
|
||||||
//获取原订单的changeInfo
|
|
||||||
String parentOrderSerialNo = data.getParentOrderSerialNo();
|
|
||||||
TrainDetailResponse parentTrainDetailResponse = lySearchRequest.getTrainOrderDetail(parentOrderSerialNo);
|
|
||||||
if (parentTrainDetailResponse != null) {
|
|
||||||
changeInfo = parentTrainDetailResponse.getData().getItems().get(0).getChangeInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
String planBeginDateNew = "";
|
|
||||||
String trainNoNew = "";
|
|
||||||
String seatClassNew = "";
|
|
||||||
//不为空
|
|
||||||
if (!Objects.isNull(changeInfo)) {
|
|
||||||
planBeginDateNew = changeInfo.getPlanBeginDate();//改签后时间
|
|
||||||
trainNoNew = changeInfo.getTrainNo();//改签后车次
|
|
||||||
seatClassNew = changeInfo.getChangeItem().getSeatClass();//改签后席别
|
|
||||||
}
|
|
||||||
//设置值
|
|
||||||
rescheduleDto.setRebookStartTime(planBeginDateNew)
|
|
||||||
.setSeatingStandard(seatClassOld)//原席别
|
|
||||||
.setRebookTrainNumber(trainNoNew)//改签后车次
|
|
||||||
.setRebookSeatingStandard(seatClassNew)//改签后席别
|
|
||||||
.setReason("计划有变,更改行程");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue