调整退款订单生成逻辑

This commit is contained in:
lulz1 2024-04-15 17:42:24 +08:00
parent cf0986a837
commit 3e46fbeb4a
13 changed files with 369 additions and 332 deletions

View File

@ -38,7 +38,8 @@ import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
import static com.chint.infrastructure.constant.SupplierNameConstant.*;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y;
@RestController
@RequestMapping("/OrderDetail")
@ -177,82 +178,134 @@ public class OrderDetailController {
@TransitionTo(command = "RefundOrderGenerateCommand", order = 0)
public void generateCTripRefund(RefundOrderGenerateCommand command) {
orderDetailRepository.findByOrderNo(command.getOrderNo()).ifPresent(orderDetail -> {
String newOrderNo = command.getOrderNo() + "-" + command.getRecordId();
String type = command.getType();
Optional<OrderDetail> byOrderNo = orderDetailRepository.findByOrderNo(newOrderNo);
if (byOrderNo.isPresent()) {
return;
}
String newOrderNo = generateNewOrderNo(command);
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
if (routeOrder.getOrderDetails().stream().map(OrderDetail::getOrderNo).toList().contains(newOrderNo)) {
return;
}
Integer productType = orderDetail.getProductType();
orderDetail.setOrderId(null);
orderDetail = getOrCreateOrderDetail(newOrderNo, orderDetail);
Long orderId = orderDetail.getOrderId();
orderDetail = findMatchingOrderDetailInRoute(orderId, routeOrder).orElse(orderDetail);
orderDetail.setOrderNo(newOrderNo);
OrderEvent orderEvent = new OrderEvent();
orderEvent.setEventType(Integer.valueOf(type));
orderEvent.setHappenTime(LocalDateTime.now());
orderEvent.setOutStatus(orderEvent.translateOrderEvent(Integer.parseInt(type)));
orderDetail.setOrderEventList(List.of(orderEvent));
addOrderEvent(orderDetail, command.getType(), LocalDateTime.now());
orderDetail.setPrice(command.getAmount());
if (productType == 0) {
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
trainOrderDetail.setOrderAmount(command.getAmount());
trainOrderDetail.setOrderStatus(type);
trainOrderDetail.setOrderNo(newOrderNo);
trainOrderDetail.setDetailId(newOrderNo);
trainOrderDetail.setCreateTime(command.getCreateTime());
trainOrderDetail.setId(null);
if (trainOrderDetail.getSupplier().equals(SUPPLIER_L_Y_EXTENSION_NAME)) {
orderExtensionCreator.of(SUPPLIER_L_Y).updateTrainOrderDetailData(trainOrderDetail, command.getOrderInfo());
}
}
if (productType == 1) {
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
flightOrderDetail.setOrderAmount(command.getAmount());
flightOrderDetail.setOrderStatus(type);
flightOrderDetail.setOrderNo(newOrderNo);
flightOrderDetail.setDetailId(newOrderNo);
flightOrderDetail.setCreateTime(command.getCreateTime());
flightOrderDetail.setId(null);
if (flightOrderDetail.getSupplier().equals(SUPPLIER_C_TRIP_CN_NAME)) {
orderExtensionCreator.of(SUPPLIER_C_TRIP).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo());
} else {
orderExtensionCreator.of(SUPPLIER_L_Y).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo());
}
}
if (productType == 2) {
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
hotelOrderDetail.setOrderAmount(command.getAmount());
hotelOrderDetail.setOrderStatus("3");
hotelOrderDetail.setOrderNo(newOrderNo);
hotelOrderDetail.setDetailId(newOrderNo);
hotelOrderDetail.setCreateTime(command.getCreateTime());
hotelOrderDetail.setId(null);
List<HotelOrderDetailCustomer> customers = hotelOrderDetail.getCustomers();
List<HotelOrderDetailCustomer> newCustomers = new ArrayList<>();
for (HotelOrderDetailCustomer customer : customers) {
customer.setId(null);
newCustomers.add(customer);
}
hotelOrderDetail.setCustomers(newCustomers);
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y_CN_NAME) && hotelOrderDetail.getSupplier().equals(SUPPLIER_L_Y_EXTENSION_NAME)) {
orderExtensionCreator.of(SUPPLIER_L_Y).updateHotelOrderDetailData(hotelOrderDetail, command.getOrderInfo());
}
}
if (productType == 3) {
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
carOrderDetail.setOrderAmount(command.getAmount());
carOrderDetail.setOrderStatus("3");
carOrderDetail.setOrderNo(newOrderNo);
carOrderDetail.setDetailId(newOrderNo);
carOrderDetail.setCreateTime(command.getCreateTime());
carOrderDetail.setId(null);
}
routeOrder.addOrderDetail(orderDetail);
processProductSpecificDetails(orderDetail, command, newOrderNo);
List<OrderDetail> orderDetails = new ArrayList<>(routeOrder
.getOrderDetails()
.stream()
.filter(it -> !it.getOrderId().equals(orderId))
.toList());
orderDetails.add(orderDetail);
routeOrder.setOrderDetails(orderDetails);
routeRepository.save(routeOrder);
});
}
private String generateNewOrderNo(RefundOrderGenerateCommand command) {
return command.getOrderNo() + "-" + command.getRecordId();
}
private OrderDetail getOrCreateOrderDetail(String newOrderNo, OrderDetail orderDetail) {
return orderDetailRepository.findByOrderNo(newOrderNo).orElseGet(() -> {
orderDetail.setOrderId(null);
return orderDetail;
});
}
private Optional<OrderDetail> findMatchingOrderDetailInRoute(Long orderId, RouteOrder routeOrder) {
return routeOrder.getOrderDetails().stream()
.filter(detail -> detail.getOrderId().equals(orderId))
.findFirst();
}
private void addOrderEvent(OrderDetail orderDetail, String type, LocalDateTime happenTime) {
OrderEvent orderEvent = new OrderEvent();
orderEvent.setEventType(Integer.valueOf(type));
orderEvent.setHappenTime(happenTime);
orderEvent.setOutStatus(orderEvent.translateOrderEvent(Integer.parseInt(type)));
orderDetail.setOrderEventList(List.of(orderEvent));
}
private void processProductSpecificDetails(OrderDetail orderDetail, RefundOrderGenerateCommand command, String newOrderNo) {
Integer productType = orderDetail.getProductType();
switch (productType) {
case 0:
updateTrainOrderDetail(orderDetail, command, newOrderNo);
break;
case 1:
updateFlightOrderDetail(orderDetail, command, newOrderNo);
break;
case 2:
updateHotelOrderDetail(orderDetail, command, newOrderNo);
break;
case 3:
updateCarOrderDetail(orderDetail, command, newOrderNo);
break;
}
}
private void updateTrainOrderDetail(OrderDetail orderDetail, RefundOrderGenerateCommand command, String newOrderNo) {
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
trainOrderDetail.setOrderAmount(command.getAmount());
trainOrderDetail.setOrderStatus(command.getType());
trainOrderDetail.setOrderNo(newOrderNo);
trainOrderDetail.setDetailId(newOrderNo);
trainOrderDetail.setCreateTime(command.getCreateTime());
trainOrderDetail.setId(null);
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) {
trainOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateTrainOrderDetailData(trainOrderDetail, command.getOrderInfo());
}
orderDetail.setTrainOrderDetail(trainOrderDetail);
}
private void updateFlightOrderDetail(OrderDetail orderDetail, RefundOrderGenerateCommand command, String newOrderNo) {
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
flightOrderDetail.setOrderAmount(command.getAmount());
flightOrderDetail.setOrderStatus(command.getType());
flightOrderDetail.setOrderNo(newOrderNo);
flightOrderDetail.setDetailId(newOrderNo);
flightOrderDetail.setCreateTime(command.getCreateTime());
flightOrderDetail.setId(null);
if (orderDetail.getSupplierName().equals(SUPPLIER_C_TRIP)) {
flightOrderDetail = orderExtensionCreator.of(SUPPLIER_C_TRIP).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo());
} else {
flightOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo());
}
orderDetail.setFlightOrderDetail(flightOrderDetail);
}
private void updateHotelOrderDetail(OrderDetail orderDetail, RefundOrderGenerateCommand command, String newOrderNo) {
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
hotelOrderDetail.setOrderAmount(command.getAmount());
hotelOrderDetail.setOrderStatus("3");
hotelOrderDetail.setOrderNo(newOrderNo);
hotelOrderDetail.setDetailId(newOrderNo);
hotelOrderDetail.setCreateTime(command.getCreateTime());
hotelOrderDetail.setId(null);
List<HotelOrderDetailCustomer> customers = hotelOrderDetail.getCustomers();
List<HotelOrderDetailCustomer> newCustomers = new ArrayList<>();
for (HotelOrderDetailCustomer customer : customers) {
customer.setId(null);
newCustomers.add(customer);
}
hotelOrderDetail.setCustomers(newCustomers);
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) {
hotelOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateHotelOrderDetailData(hotelOrderDetail, command.getOrderInfo());
orderDetail.setHotelOrderDetail(hotelOrderDetail);
}
}
private void updateCarOrderDetail(OrderDetail orderDetail, RefundOrderGenerateCommand command, String newOrderNo) {
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
carOrderDetail.setOrderAmount(command.getAmount());
carOrderDetail.setOrderStatus("3");
carOrderDetail.setOrderNo(newOrderNo);
carOrderDetail.setDetailId(newOrderNo);
carOrderDetail.setCreateTime(command.getCreateTime());
carOrderDetail.setId(null);
orderDetail.setCarOrderDetail(carOrderDetail);
}
}

View File

@ -117,7 +117,7 @@ public class OrderOutController {
@ApiOperation("查询行程规划订单自定义字段")
@PostMapping("/query/custom/fields")
public Result<List<ApproveCustomField>> queryLeg(@RequestBody OrderQueryData queryData) {
public Result<List<ApproveCustomField>> queryCustomFields(@RequestBody OrderQueryData queryData) {
RouteOrder routeOrder = routeRepository
.findByActualOrderNoAndSysCode(queryData.getActualOrderNo(), queryData.getSysCode());
List<ApproveCustomField> approveCustomFieldList = routeOrder.getRouteCustomExtensionFieldList()

View File

@ -8,6 +8,7 @@ import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.RouteRequestRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.infrastructure.util.BigDecimalCalculator;
import com.chint.interfaces.rest.ly.dto.carorderdatapushback.PriceDetail;
import com.chint.interfaces.rest.ly.dto.hotelorderdatapushbach.Resident;
import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse;
@ -417,7 +418,7 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory {
HotelDetailResponse.Data data = (HotelDetailResponse.Data) hotelOrderInfo;
HotelDetailResponse.OrderInfo orderInfo = data.getOrderInfo();
HotelDetailResponse.HotelInfo hotelInfo = data.getHotelInfo();
List<HotelDetailResponse.RefundInfo> refundInfoList = data.getRefundInfoList();
if (hotelInfo != null && orderInfo != null) {
hotelOrderDetail.setOrderNo(orderInfo.getOrderSerialNo())
.setDetailId(orderInfo.getOrderSerialNo())
@ -437,23 +438,16 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory {
.setRefundAmount(String.valueOf(orderInfo.getRefundPrice()))
.setAgreementHotel(orderInfo.getProtocolType() == 0 ? "" : "");
//下单成功的总金额要和退款状态的总金额区分开
if (hotelOrderDetail.getOrderStatus().equals(FSSC_FLIGHT_STATUS_SUCCESS)) {
hotelOrderDetail.setOrderAmount(String.valueOf(orderInfo.getTotalPrice()));
}
//配置付款类型
if (orderInfo.getPaymentType() == 1) {
hotelOrderDetail.setPaymentType("0");
hotelOrderDetail.setCompanyAmount(String.valueOf(orderInfo.getCompanyPrice()));
hotelOrderDetail.setPersonalAmount(KEEP_TWO_DECIMAL_ZERO);
} else {
hotelOrderDetail.setPaymentType("1");
hotelOrderDetail.setCompanyAmount(KEEP_TWO_DECIMAL_ZERO);
hotelOrderDetail.setPersonalAmount(String.valueOf(orderInfo.getPersonalPrice()));
}
List<HotelDetailResponse.RefundInfo> refundInfoList = data.getRefundInfoList();
//如果是退款状态的话要进入这里进行更新
if (refundInfoList != null &&
!refundInfoList.isEmpty() &&
@ -497,11 +491,29 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory {
if (!list.isEmpty()) {
hotelOrderDetail.setStandardItems(list.get(0));
}
//下单成功的总金额要和退款状态的总金额区分开
if (hotelOrderDetail.getOrderStatus().equals(FSSC_FLIGHT_STATUS_SUCCESS)) {
String totalPrice = String.valueOf(room.getSalesPrice());
hotelOrderDetail.setOrderAmount(totalPrice);
}
hotelOrderDetail.setCompanyAmount(String.valueOf(room.getCompanyPrice()));
hotelOrderDetail.setPersonalAmount(String.valueOf(room.getPersonalPrice()));
}
return hotelOrderDetail;
}
private String checkAndAddRefundPrice(List<HotelDetailResponse.RefundInfo> refundInfoList, String totalPrice) {
if (refundInfoList != null && !refundInfoList.isEmpty()) {
for (HotelDetailResponse.RefundInfo refundInfo : refundInfoList) {
totalPrice = BigDecimalCalculator.add(totalPrice, String.valueOf(refundInfo.getRefundPrice()));
}
}
return totalPrice;
}
@Override
public OtherOrderDetail createOtherOrderDetail(Object otherOrderDetailData) {
return null;

View File

@ -33,7 +33,4 @@ public class ApproveRouteData {
private String endTime;
@ApiModelProperty("自定义字段")
private List<ApproveCustomField> approveCustomFieldList;
}

View File

@ -99,7 +99,7 @@ public class CTripUserSaveRequest {
userNameRepository.findByEmployeeNo(user.getEmployeeNo()).ifPresentOrElse(it -> authenticationEntity.setName(it.getIdName()),
() -> authenticationEntity.setName(user.getName()));
authenticationEntity.setEmployeeID(user.getEmployeeNo());
authenticationEntity.setValid(user.getWorkStatus());
authenticationEntity.setValid(user.getWorkStatus().charAt(0));
authenticationEntity.setSubAccountName(subAccountName);
return authenticationEntity;
}

View File

@ -6,7 +6,7 @@ import lombok.Data;
public class AuthenticationEntity {
private String EmployeeID;
private String Name;
private String Valid; //在职情况 A-在职业务操作为新建卡或者更新卡I-离职业务操作为关卡
private char Valid; //在职情况 A-在职业务操作为新建卡或者更新卡I-离职业务操作为关卡
private String RankName; // 职级名称中文职级的中文名跟英文名只能传递其中一个如果需要使用该字段需提前联系实施经理在携程后台进行配置
private String SubAccountName; //子账户即确定该人员信息落在那个结算主体中用于确定后续订单费用归属
}

View File

@ -99,8 +99,6 @@ public class CommonController {
case 3 -> getOrderHotel(notification);
case 5 -> getOrderTrain(notification);
case 6 -> getOrderCar(notification);
//50进行行程数据回推
case 50 -> getOrderType(notification);
default -> new LYNoteResponse("100", "OK");
};
}
@ -113,17 +111,11 @@ public class CommonController {
*/
private LYNoteResponse getOrderCar(Notification notification) {
Object notifyData = notification.notifyData;
int subNotifyType = notification.getSubNotifyType();
if (Objects.nonNull(notifyData)) {
JSONObject jsonObj = JSON.parseObject(notifyData.toString());
ResultBackCar.DataObject orderCar = jsonObj.toJavaObject(ResultBackCar.DataObject.class);
String orderSerialNo = orderCar.getOrder().getOrderSerialNo();
String travelApplyNo = orderCar.getTravelData().getTravelApplyNo();
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(orderSerialNo);
orderTravel.setTravelNo(travelApplyNo);
saveOrderTravel(orderTravel);
lyCallBackDataHandler.carCallBackData(orderSerialNo, 0);
lyCallBackDataHandler.carCallBackData(orderSerialNo);
}
return new LYNoteResponse("100", "OK");
}
@ -136,19 +128,10 @@ public class CommonController {
*/
public LYNoteResponse getOrderTrain(Notification notification) {
Object notifyData = notification.notifyData;
int subNotifyType = notification.getSubNotifyType();
if (Objects.nonNull(notifyData)) {
JSONObject jsonObj = JSON.parseObject(notifyData.toString());
ResultBackTrain orderTrain = jsonObj.toJavaObject(ResultBackTrain.class);
int ruleViolate = orderTrain.getRuleViolate() ? 1 : 0;
if (subNotifyType == 16) {
changeTrain(ruleViolate, subNotifyType, orderTrain.getOrderNo());
}
String foulReason = orderTrain.getFoulReason();//超标原因
lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo(), Integer.valueOf(ruleViolate), foulReason, subNotifyType);
if (subNotifyType == 2 || subNotifyType == 3 || subNotifyType == 1) {
sendMsg(orderTrain.getTravelData().getTravelApplyNo());
}
lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo());
}
return new LYNoteResponse("100", "OK");
}
@ -168,8 +151,7 @@ public class CommonController {
ResultBackHotel.DataObject dataObject = resultBackHotel.getData();
int ruleViolate = dataObject.getOrderInfo().getRuleViolate() ? 1 : 0;
String orderSerialNo = dataObject.getOrderInfo().getOrderSerialNo();
String foulReason = dataObject.getOrderInfo().getFoulReason();//超标原因
lyCallBackDataHandler.hotelCallBackData(orderSerialNo, ruleViolate, foulReason);
lyCallBackDataHandler.hotelCallBackData(orderSerialNo);
if (ruleViolate == 0) {
sendMsg(dataObject.getTravelData().getTravelApplyNo());
}
@ -185,29 +167,13 @@ public class CommonController {
*/
public LYNoteResponse getOrderFlight(Notification notification) {
Object notifyData = notification.notifyData;
int subNotifyType = notification.getSubNotifyType();
if (Objects.nonNull(notifyData)) {
JSONObject jsonObj = JSON.parseObject(notifyData.toString());
ResultBackFly resultBackFly = jsonObj.toJavaObject(ResultBackFly.class);
ResultBackFly.DataObject dataObject = resultBackFly.getData();
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(dataObject.getOrderDetails().getOrderSerialNo());
// orderTravel.setTravelNo(dataObject.getOrderDetails().getTravelOrderNo());
// saveOrderTravel(orderTravel);
int ruleViolate = dataObject.getOrderDetails().getRuleViolate() ? 1 : 0;
String orderSerialNo = dataObject.getOrderDetails().getOrderSerialNo();
//改签
if (subNotifyType == 9) {
changeFlight(ruleViolate, subNotifyType, orderSerialNo);
}
String foulReason = dataObject.getOrderDetails().getFoulReason();//超标原因
//正常流程
lyCallBackDataHandler.flightCallBackData(orderSerialNo, ruleViolate, foulReason, subNotifyType);
if (subNotifyType == 2 || subNotifyType == 3 || subNotifyType == 1) {
sendMsg(dataObject.getOrderDetails().getTravelOrderNo());
}
lyCallBackDataHandler.flightCallBackData(orderSerialNo);
}
return new LYNoteResponse("100", "OK");
}
@ -218,61 +184,61 @@ public class CommonController {
* @param notification
* @return
*/
public LYNoteResponse getOrderType(Notification notification) {
int subNotifyType = notification.getSubNotifyType();
Class<?> objClass = notification.getClass();
Object object = GetObjectNature.getObject(objClass, "notifyData", notification);
Gson gson = new Gson();
NotifyData common = gson.fromJson(object.toString(), NotifyData.class);
boolean emptyHotel = Objects.nonNull(common.getTravelBizOrderList().getHotelOrderList());
boolean emptyFly = Objects.nonNull(common.getTravelBizOrderList().getFlightOrderList());
boolean emptyCar = Objects.nonNull(common.getTravelBizOrderList().getCarOrderList());
boolean emptyTrain = Objects.nonNull(common.getTravelBizOrderList().getTrainOrderList());
if (emptyHotel) {//酒店
NotifyData.HotelOrder hotelOrder = common.getTravelBizOrderList().getHotelOrderList().get(0);
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(hotelOrder.getOrderInfo().getOrderSerialNo());
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
saveOrderTravel(orderTravel);
String foulReason = hotelOrder.getOrderInfo().getFoulReason();//超标原因
return lyCallBackDataHandler.hotelCallBackData(hotelOrder.getOrderInfo().getOrderSerialNo(), hotelOrder.getOrderInfo().getRuleViolate() ? 1 : 0, foulReason);
} else if (emptyFly) {//机票originalOrderNo
NotifyData.OrderDetails flyOrder = common.getTravelBizOrderList().getFlightOrderList().get(0).getOrderDetails();
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(flyOrder.getOrderSerialNo());
orderTravel.setTravelNo(flyOrder.getTravelOrderNo());
saveOrderTravel(orderTravel);
int ruleViolate = flyOrder.getRuleViolate() ? 1 : 0;
//改签
if (subNotifyType == 9) {
changeFlight(ruleViolate, subNotifyType, flyOrder.getOrderSerialNo());
}
String foulReason = flyOrder.getFoulReason();//超标原因
return lyCallBackDataHandler.flightCallBackData(flyOrder.getOrderSerialNo(), flyOrder.getRuleViolate() ? 1 : 0, foulReason, subNotifyType);
} else if (emptyTrain) {//火车票
NotifyData.TrainOrderList.OrderTrain orderTrain = common.getTravelBizOrderList().getTrainOrderList().get(0);
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(orderTrain.getOrderNo());
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
saveOrderTravel(orderTravel);
int ruleViolate = orderTrain.getRuleViolate() ? 1 : 0;
if (subNotifyType == 16) {
changeTrain(ruleViolate, subNotifyType, orderTrain.getOrderNo());
}
String foulReason = orderTrain.getFoulReason();//超标原因
return lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo(), orderTrain.getRuleViolate() ? 1 : 0, foulReason, subNotifyType);
} else if (emptyCar) {
NotifyData.CarOrderList.Order orderCar = common.getTravelBizOrderList().getCarOrderList().get(0).getOrder();
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(orderCar.getOrderSerialNo());
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
saveOrderTravel(orderTravel);
return lyCallBackDataHandler.carCallBackData(orderCar.getOrderSerialNo(), 0);
} else {
return new LYNoteResponse("100", "OK");
}
}
// public LYNoteResponse getOrderType(Notification notification) {
// int subNotifyType = notification.getSubNotifyType();
// Class<?> objClass = notification.getClass();
// Object object = GetObjectNature.getObject(objClass, "notifyData", notification);
// Gson gson = new Gson();
// NotifyData common = gson.fromJson(object.toString(), NotifyData.class);
// boolean emptyHotel = Objects.nonNull(common.getTravelBizOrderList().getHotelOrderList());
// boolean emptyFly = Objects.nonNull(common.getTravelBizOrderList().getFlightOrderList());
// boolean emptyCar = Objects.nonNull(common.getTravelBizOrderList().getCarOrderList());
// boolean emptyTrain = Objects.nonNull(common.getTravelBizOrderList().getTrainOrderList());
// if (emptyHotel) {//酒店
// NotifyData.HotelOrder hotelOrder = common.getTravelBizOrderList().getHotelOrderList().get(0);
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(hotelOrder.getOrderInfo().getOrderSerialNo());
// orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
// saveOrderTravel(orderTravel);
// String foulReason = hotelOrder.getOrderInfo().getFoulReason();//超标原因
// return lyCallBackDataHandler.hotelCallBackData(hotelOrder.getOrderInfo().getOrderSerialNo(), hotelOrder.getOrderInfo().getRuleViolate() ? 1 : 0, foulReason);
// } else if (emptyFly) {//机票originalOrderNo
// NotifyData.OrderDetails flyOrder = common.getTravelBizOrderList().getFlightOrderList().get(0).getOrderDetails();
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(flyOrder.getOrderSerialNo());
// orderTravel.setTravelNo(flyOrder.getTravelOrderNo());
// saveOrderTravel(orderTravel);
// int ruleViolate = flyOrder.getRuleViolate() ? 1 : 0;
// //改签
// if (subNotifyType == 9) {
// changeFlight(ruleViolate, subNotifyType, flyOrder.getOrderSerialNo());
// }
// String foulReason = flyOrder.getFoulReason();//超标原因
// return lyCallBackDataHandler.flightCallBackData(flyOrder.getOrderSerialNo(), flyOrder.getRuleViolate() ? 1 : 0, foulReason, subNotifyType);
//
// } else if (emptyTrain) {//火车票
// NotifyData.TrainOrderList.OrderTrain orderTrain = common.getTravelBizOrderList().getTrainOrderList().get(0);
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(orderTrain.getOrderNo());
// orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
// saveOrderTravel(orderTravel);
// int ruleViolate = orderTrain.getRuleViolate() ? 1 : 0;
// if (subNotifyType == 16) {
// changeTrain(ruleViolate, subNotifyType, orderTrain.getOrderNo());
// }
// String foulReason = orderTrain.getFoulReason();//超标原因
// return lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo(), orderTrain.getRuleViolate() ? 1 : 0, foulReason, subNotifyType);
// } else if (emptyCar) {
// NotifyData.CarOrderList.Order orderCar = common.getTravelBizOrderList().getCarOrderList().get(0).getOrder();
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(orderCar.getOrderSerialNo());
// orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
// saveOrderTravel(orderTravel);
// return lyCallBackDataHandler.carCallBackData(orderCar.getOrderSerialNo(), 0);
// } else {
// return new LYNoteResponse("100", "OK");
// }
// }
public void sendMsg(String travelApplyNo) {

View File

@ -2,8 +2,6 @@ package com.chint.interfaces.rest.ly.in;
import com.chint.application.commands.OrderStatusChangeCommand;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.OrderEvent;
import com.chint.domain.aggregates.order.OrderTravel;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.RouteRequestDomainService;
@ -18,9 +16,7 @@ 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.hotel.HotelDetailResponse;
import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailResponse;
import com.chint.interfaces.rest.ly.dto.strokepush.Param;
import com.chint.interfaces.rest.ly.dto.strokepush.StrokeController;
import com.chint.interfaces.rest.ly.dto.strokepush.StrokePushDTO;
import com.chint.interfaces.rest.ly.tools.LYOrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -29,7 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import static com.chint.infrastructure.constant.LYConstant.*;
import static com.chint.infrastructure.constant.OrderConstant.*;
import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_REFUND;
@Component
public class LYCallBackDataHandler {
@ -54,7 +50,7 @@ public class LYCallBackDataHandler {
private RouteRequestDomainService routeRequestDomainService;
public LYNoteResponse trainCallBackData(String orderNo, Integer isRuleViolate, String foulReason, int subNotifyType) {
public LYNoteResponse trainCallBackData(String orderNo) {
TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail(orderNo);
TrainDetailResponse.TrainDetailData data = trainOrderDetail.getData();
TrainDetailResponse.TravelData travelData = data.getTravelData();
@ -62,11 +58,11 @@ public class LYCallBackDataHandler {
Integer productType = L_Y_PRODUCT_TYPE_TRAIN;
String travelNo = travelData.getTravelApplyNo();
Integer evenType = LYOrderUtil.mapTrainStatus(data.getOrderStatus());
return dataHandler(orderNo, isRuleViolate, travelNo, data, productType, outStatus, evenType, foulReason, subNotifyType);
return dataHandler(orderNo, travelNo, data, productType, outStatus, evenType);
}
public LYNoteResponse flightCallBackData(String orderNo, Integer isRuleViolate, String foulReason, int subNotifyType) {
public LYNoteResponse flightCallBackData(String orderNo) {
FlightOrderResponse flightOrderDetail = lySearchRequest.getFlightOrderDetail(orderNo);
FlightOrderResponse.Data data = flightOrderDetail.getData();
FlightOrderResponse.OrderDetails orderDetails = data.getOrderDetails();
@ -74,10 +70,10 @@ public class LYCallBackDataHandler {
String outStatus = orderDetails.getOrderStatusText();
Integer evenType = LYOrderUtil.mapFlightStatus(orderDetails.getOrderStatus().toString());
Integer productType = L_Y_PRODUCT_TYPE_FLY;
return dataHandler(orderNo, isRuleViolate, travelNo, data, productType, outStatus, evenType, foulReason, subNotifyType);
return dataHandler(orderNo, travelNo, data, productType, outStatus, evenType);
}
public LYNoteResponse hotelCallBackData(String orderNo, Integer isRuleViolate, String foulReason) {
public LYNoteResponse hotelCallBackData(String orderNo) {
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail(orderNo);
HotelDetailResponse.Data data = hotelOrderDetail.getData();
HotelDetailResponse.OrderInfo orderInfo = data.getOrderInfo();
@ -87,10 +83,18 @@ public class LYCallBackDataHandler {
orderInfo.getOrderStatus()
));
Integer productType = L_Y_PRODUCT_TYPE_HOTEL;
return dataHandler(orderNo, isRuleViolate, travelNo, data, productType, outStatus, evenType, foulReason, 0);
if (!evenType.equals(ORDER_EVENT_REFUND)) {
//如果订单信息里面没有退款的那么就在进行一次检查
List<HotelDetailResponse.RefundInfo> refundInfoList = data.getRefundInfoList();
if (refundInfoList != null && !refundInfoList.isEmpty()) {
return dataHandler(orderNo, travelNo, data, productType, "提前离店", ORDER_EVENT_REFUND);
}
}
return dataHandler(orderNo, travelNo, data, productType, outStatus, evenType);
}
public LYNoteResponse carCallBackData(String orderNo, Integer isRuleViolate) {
public LYNoteResponse carCallBackData(String orderNo) {
CarDetailResponse carDetailResponse = lySearchRequest.getCarDetailResponse(orderNo);
CarDetailResponse.DataWrapper data = carDetailResponse.getData();
@ -100,49 +104,31 @@ public class LYCallBackDataHandler {
Integer evenType = LYOrderUtil.mapCarStatus(orderDetailInfo.getOrderStatus()
);
Integer productType = L_Y_PRODUCT_TYPE_CAR;
return dataHandler(orderNo, isRuleViolate, travelNo, data, productType, outStatus, evenType, "其它", 0);
return dataHandler(orderNo, travelNo, data, productType, outStatus, evenType);
}
private LYNoteResponse dataHandler(String orderNo, Integer isRuleViolate, String travelNo,
private LYNoteResponse dataHandler(String orderNo, String travelNo,
Object data, Integer productType,
String outStatus, Integer evenType, String foulReason, int subNotifyType) {
String outStatus, Integer evenType) {
OrderDetail orderDetail = getOrderDetail(travelNo, data, productType);
if (orderDetail.getOrderEventList() == null) {
orderDetail.setOrderEventList(new ArrayList<>());
}
Command.of(OrderStatusChangeCommand.class)
.orderDetail(orderDetail)
.orderNo(orderNo)
.outStatus(outStatus)
.eventType(evenType)
.sendToQueue();
return new LYNoteResponse("100", "OK");
}
private OrderDetail getOrderDetail(String travelNo, Object data, Integer productType) {
RouteOrder byOrderNo = routeRequestDomainService.getRouteOrder(travelNo);
SupplierCallbackData supplierCallbackData =
SupplierCallbackData.of(SupplierNameConstant.SUPPLIER_L_Y, byOrderNo.getUserId())
.data(data)
.productType(productType);
OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData);
if (orderDetail.getOrderEventList() == null) {
orderDetail.setOrderEventList(new ArrayList<>());
}
List<Integer> list = orderDetail
.getOrderEventList()
.stream()
.map(OrderEvent::getEventType)
.toList();
if (isRuleViolate.equals(L_Y_IS_RULE_VIOLATE) && !list.contains(ORDER_EVENT_ETA)) {
Command.of(OrderStatusChangeCommand.class)
.orderDetail(orderDetail)
.orderNo(orderNo)
.outStatus(outStatus)
.eventType(ORDER_EVENT_ETA)
.extension(foulReason)//超标原因
.sendToQueue();
} else if (isRuleViolate.equals(L_Y_IS_RULE_VIOLATE) &&
!(subNotifyType == 16 || subNotifyType == 9 || ORDER_EVENT_CHANGE == evenType || ORDER_EVENT_REFUND == evenType)
) {
//已经推送过的超标
return new LYNoteResponse("100", "OK");
} else {
Command.of(OrderStatusChangeCommand.class)
.orderDetail(orderDetail)
.orderNo(orderNo)
.outStatus(outStatus)
.eventType(evenType)
.sendToQueue();
}
return new LYNoteResponse("100", "OK");
return supplierService.handleSupplierCallback(supplierCallbackData);
}
}

View File

@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.SFConstant.*;
@ -79,94 +80,113 @@ public class PushUser {
}
public List<User> getUserSFDataFromOpenApiBatch() {
int start;
int pageSize = 1000;
int page = 1;
List<User> list = new ArrayList<>();
while (true) {
log.info("Pull user. page={}", page);
start = (page - 1) * 1000;
Gson gson = new Gson();
AccessKeyDTO akSkLoad = akSkLoad();
DataCenterOption option = new DataCenterOption();
option.setSk(akSkLoad.sk);
option.setAk(akSkLoad.ak);
option.setUrl(OPENAI_BASE_URL);
DataCenterService dataCenterService = new DataCenterService(option);
LinkedHashMap map = new LinkedHashMap<String, Object>();
map.put("start", start);
map.put("pageSize", pageSize);
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
boolean shouldContinue = true;
if (!result.getSuccess()) {
log.error("Get user error. statusCode={}", result.getCode());
continue;
}
while (shouldContinue) {
int start = (page - 1) * pageSize;
log.info("Pulling user data. Page={}", page);
try {
AccessKeyDTO akSkLoad = akSkLoad();
DataCenterOption option = new DataCenterOption();
option.setSk(akSkLoad.sk);
option.setAk(akSkLoad.ak);
option.setUrl(OPENAI_BASE_URL);
DataCenterService dataCenterService = new DataCenterService(option);
Type type = new TypeToken<List<UserDataDTO>>() {
}.getType();
LinkedHashMap<String, Object> parameters = new LinkedHashMap<>();
parameters.put("start", start);
parameters.put("orgs", List.of("A70000021"));
parameters.put("pageSize", pageSize);
if (result.getData() == null) {
continue;
}
List<UserDataDTO> userDataDTOs = gson.fromJson(result.getData().toString(), type);
List<User> users = userDataDTOs.stream()
.filter(it-> !it.getStatus().equals("A"))
.filter(it -> it.getLoginUsername() != null)
.filter(it -> it.getCompany() != null)
.filter(it -> jtCompanyDomainService.ifCompanyInJT(null, it.getCompany())
|| it.getCompany().equals("A70000056"))
.map(userData -> {
User user = new User();
user.setCompanyCode(userData.getCompany());
user.setWorkStatus(userData.getStatus());
user.setGender(userData.getGender());
user.setName(userData.getUname());
user.setPhoneNumber(userData.getMobilePhone());
user.setCompanyName(userData.getCompany_cn());
user.setManaLevel(userData.getCust_manaLevel());
user.setProfLevel(userData.getCust_profLevel());
user.setQualityLevel(userData.getCust_qualityLevel());
user.setEmployeeNo(userData.getLoginUsername());
return user;
})
.toList();
if (isNullOrEmpty(users)) {
break;
}
if (page % 10 == 0) {
log.info("Pull user wating...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, parameters);
if (!result.getSuccess()) {
log.error("Failed to get user data. StatusCode={}", result.getCode());
continue;
}
List<UserDataDTO> userDataDTOs = parseUserData(result);
if (userDataDTOs.isEmpty()) {
shouldContinue = false;
continue;
}
List<User> users = transformUsers(userDataDTOs);
if (users.isEmpty()) {
shouldContinue = false;
continue;
}
if (page % 10 == 0) {
log.info("Pausing after 10 pages...");
Thread.sleep(1000);
}
users.forEach(this::loadAndSaveUser);
page++;
list.addAll(users);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread was interrupted", e);
} catch (Exception e) {
log.error("An error occurred: {}", e.getMessage(), e);
shouldContinue = false;
}
// if(page == 4){
// break;
// }
users.forEach(user -> userHttpRequest.loadRankCode(user));
page++;
list.addAll(users);
}
list = list.stream().filter(user -> user.getEmployeeNo() != null).toList();
return list.stream()
.filter(user -> user.getEmployeeNo() != null)
.collect(Collectors.toList());
}
for (User user : list) {
Optional.ofNullable(userRepository.findByUserEmployeeNo(user.getEmployeeNo())).ifPresentOrElse(
this::asyncUser,()->{
userRepository.save(user);
asyncUser(user);
}
);
}
private List<UserDataDTO> parseUserData(DataCenterResult result) {
Type type = new TypeToken<List<UserDataDTO>>() {
}.getType();
return new Gson().fromJson(result.getData().toString(), type);
}
return list;
private List<User> transformUsers(List<UserDataDTO> userDataDTOs) {
return userDataDTOs.stream()
.filter(it -> it.getStatus().equals("A"))
.filter(it -> it.getLoginUsername() != null && it.getCompany() != null)
.map(this::mapToUser)
.toList();
}
private User mapToUser(UserDataDTO userData) {
User user = new User();
user.setCompanyCode(userData.getCompany());
user.setWorkStatus(userData.getStatus());
user.setGender(userData.getGender());
user.setName(userData.getUname());
user.setPhoneNumber(userData.getMobilePhone());
user.setCompanyName(userData.getCompany_cn());
user.setManaLevel(userData.getCust_manaLevel());
user.setProfLevel(userData.getCust_profLevel());
user.setQualityLevel(userData.getCust_qualityLevel());
user.setEmployeeNo(userData.getLoginUsername());
return user;
}
private void loadAndSaveUser(User user) {
userHttpRequest.loadRankCode(user);
Optional.ofNullable(userRepository.findByUserEmployeeNo(user.getEmployeeNo()))
.ifPresentOrElse(
it -> {
// user.setUserId(it.getUserId());
if (it.checkSyncTime()) {
it.setWorkStatus(user.getWorkStatus());
asyncUser(it);
}
},
() -> {
if (user.checkSyncTime()) {
asyncUser(user);
}
}
);
}
public void asyncUser(User user) {

View File

@ -75,10 +75,10 @@ public class UserSFRequest {
}
public List<UserDataDTO> getUserSFDataFromOpenApiBycompanyName(String companyName) {
// public List<UserDataDTO> getUserSFDataFromOpenApiBycompanyName(String companyName) {
//
// }
return null;
}
public DataCenterResult requestToDataCenter(LinkedHashMap<String, Object> map) {
AccessKeyDTO akSkLoad = akSkLoad();

View File

@ -1,5 +1,8 @@
package com.chint.interfaces.rest.user.dto;
import lombok.Data;
@Data
public class AccessKeyDTO {
public String ak;
public String sk;

View File

@ -829,9 +829,9 @@ public class LYTest {
System.out.println(json);
}
// @Test
@Test
void searchHotel() {
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240325155100629867");
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240317122300088705");
Gson gson = new Gson();
String json = gson.toJson(hotelOrderDetail);
System.out.println(json);

View File

@ -167,7 +167,7 @@ class RouteApplicationTests {
System.out.println(postRequest.getReDirectUrl("http://10.10.100.129:8089" + "/MobileOA/api/FsscSSO?loginUser=230615020&data=%2F%23%2Fexpenseclaim%3FbillDefineId%3Dfcc76666fb1211e98e2019f4db5548fd%26scene%3DWRITE%26isNew%3Dtrue%26goback%3Dfalse"));
}
// @Test
// @Test
void syncUserTo() {
User user = new User();
user.setCompanyCode("A10000001");
@ -263,7 +263,7 @@ class RouteApplicationTests {
System.out.println(orderInfo.getOrderSerialNo());
}
@Test
@Test
void loginSign() {
String sfno = "240412063";
String syscode = "FSSC";
@ -278,7 +278,7 @@ class RouteApplicationTests {
// log.trace("trace");
}
@Test
@Test
void loginSignProd() {
String sfno = "240412063";
String syscode = "FSSC";
@ -323,9 +323,10 @@ class RouteApplicationTests {
routeRepository.deleteById(875L);
}
// @Test
@Test
void deleteOrderDetail() {
orderDetailRepository.deleteById(2609L);
orderDetailRepository.deleteById(2977L);
// orderDetailRepository.deleteById(2975L);
}
// @Test
@ -1006,12 +1007,12 @@ class RouteApplicationTests {
}
// @Test
// @Test
void pushUserInfo() {
pushUser.getUserSFDataFromOpenApiBatch();
}
// @Test
// @Test
void deleteByOrderId() {
orderDetailRepository.deleteById(1647L);
orderDetailRepository.deleteById(1648L);
@ -1057,7 +1058,7 @@ class RouteApplicationTests {
locationRepository.saveAll(allLevelThreeAndFour);
}
// @Test
// @Test
void generateIfAirport() {
List<Location> airportLocation = new ArrayList<>();
AirportSearchResponse response = cTripAirportRequest.getAirport();
@ -1103,7 +1104,7 @@ class RouteApplicationTests {
locationRepository.saveAll(airportLocation);
}
// @Test
// @Test
void updateCounty() {
List<Location> byLocationType = locationRepository.findByLocationType(5);
for (Location location : byLocationType) {
@ -1114,7 +1115,7 @@ class RouteApplicationTests {
locationRepository.saveAll(byLocationType);
}
// @Test
// @Test
void updateAirportPath() {
List<Location> byLocationType = locationRepository.findByLocationType(7);
for (Location location : byLocationType) {
@ -1124,7 +1125,7 @@ class RouteApplicationTests {
locationRepository.saveAll(byLocationType);
}
// @Test
// @Test
void generateLocationType() {
List<Location> all = locationRepository.findAll();
all.forEach(it -> {
@ -1195,7 +1196,6 @@ class RouteApplicationTests {
}
@Test
void addRanks() {
@ -1228,45 +1228,45 @@ class RouteApplicationTests {
}
// @Test
// @Test
void testQueryCity() {
Location location = locationRepository.findById(373L);
Location cityLocation = lyOrderSyncAdapter.getCityLocation(location);
System.out.println(cityLocation);
}
// @Test
void testTimeFor(){
// @Test
void testTimeFor() {
LocalDateTime localDateTime = DateTimeUtil.strToTimeMM("2024-03-04 00:23:26.727");
System.out.println(localDateTime);
}
// @Test
void testFindOrderRecord(){
// @Test
void testFindOrderRecord() {
CTripHotelRecord hotelRecordByRecordId = cTripOrderDetail.findHotelRecordByRecordId("98494942");
System.out.println(hotelRecordByRecordId);
}
// @Test
void testInBlackList(){
// @Test
void testInBlackList() {
orderDomainService.checkCompanyNameIfBlack("乐清正泰电器销售有限公司");
}
@Test
void testSplit(){
void testSplit() {
String str = "20240301";
System.out.println(str.substring(0, 5));
System.out.println(lastMonthStr());
}
@Test
void testsplit2(){
void testsplit2() {
String inputOrderNo = "FSSC-CLSQ240409000001dev#NBWSAW";
String orderNo = null;
if (inputOrderNo.contains("-")) {
String[] split = inputOrderNo.split("-");
orderNo = split[1];
if(orderNo.contains("#")){
if (orderNo.contains("#")) {
String[] split1 = orderNo.split("#");
orderNo = split1[0];
}