同步代码

This commit is contained in:
lulz1 2024-02-26 17:41:36 +08:00
parent c4885c2aa8
commit bb302bfb7a
41 changed files with 537 additions and 147 deletions

View File

@ -1,5 +1,6 @@
package com.chint.application.commands; package com.chint.application.commands;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -11,6 +12,7 @@ public class OrderStatusChangeCommand extends Command {
private String orderNo; private String orderNo;
private String outStatus; private String outStatus;
private Integer orderEventType; private Integer orderEventType;
private OrderDetail orderDetail;
public OrderStatusChangeCommand eventType(Integer eventType) { public OrderStatusChangeCommand eventType(Integer eventType) {
this.orderEventType = eventType; this.orderEventType = eventType;
@ -26,4 +28,9 @@ public class OrderStatusChangeCommand extends Command {
this.outStatus = outStatus; this.outStatus = outStatus;
return this; return this;
} }
public OrderStatusChangeCommand orderDetail(OrderDetail orderDetail) {
this.orderDetail = orderDetail;
return this;
}
} }

View File

@ -0,0 +1,12 @@
package com.chint.application.dtos.trip;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class ExtendedFieldParam implements Serializable {
@JsonProperty("isExceed")
private boolean isExceed;
}

View File

@ -62,7 +62,7 @@ public class ScheduleDetail {
protected String ParentScheduleNum; protected String ParentScheduleNum;
@JsonProperty("ExtendedField") @JsonProperty("ExtendedField")
protected String ExtendedField; protected ExtendedFieldParam ExtendedField;
@JsonProperty("QuoteGroupNum") @JsonProperty("QuoteGroupNum")
protected String QuoteGroupNum; protected String QuoteGroupNum;
@ -114,6 +114,8 @@ public class ScheduleDetail {
@JsonProperty("RealScheduleNum") @JsonProperty("RealScheduleNum")
protected String RealScheduleNum; protected String RealScheduleNum;
// Constructor, getters and setters // Constructor, getters and setters
public static ScheduleDetailBuilder builder(){ public static ScheduleDetailBuilder builder(){
@ -213,10 +215,10 @@ public class ScheduleDetail {
return this; return this;
} }
public ScheduleDetailBuilder extendedField(String extendedField) { // public ScheduleDetailBuilder extendedField(String extendedField) {
scheduleDetail.setExtendedField(extendedField); // scheduleDetail.setExtendedField(extendedField);
return this; // return this;
} // }
public ScheduleDetailBuilder quoteGroupNum(String quoteGroupNum) { public ScheduleDetailBuilder quoteGroupNum(String quoteGroupNum) {
scheduleDetail.setQuoteGroupNum(quoteGroupNum); scheduleDetail.setQuoteGroupNum(quoteGroupNum);
@ -312,6 +314,9 @@ public class ScheduleDetail {
} }
public ScheduleDetail build() { public ScheduleDetail build() {
ExtendedFieldParam extendedFieldParam = new ExtendedFieldParam();
extendedFieldParam.setExceed(false);
scheduleDetail.setExtendedField(extendedFieldParam);
return scheduleDetail; return scheduleDetail;
} }
} }

View File

@ -5,6 +5,7 @@ import com.chint.application.dtos.DeleteLegData;
import com.chint.application.queryies.OrderQuery; import com.chint.application.queryies.OrderQuery;
import com.chint.application.services.OrderApplicationService; import com.chint.application.services.OrderApplicationService;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.service.OrderDetailDomainService;
import com.chint.domain.value_object.*; import com.chint.domain.value_object.*;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -24,6 +25,9 @@ public class OrderController {
@Autowired @Autowired
private OrderApplicationService orderApplicationService; private OrderApplicationService orderApplicationService;
@Autowired
private OrderDetailDomainService orderDetailDomainService;
@Autowired @Autowired
private OrderQuery orderQuery; private OrderQuery orderQuery;
@ -69,4 +73,12 @@ public class OrderController {
orderApplicationService.deleteLegToOrder(deleteLegData); orderApplicationService.deleteLegToOrder(deleteLegData);
return Result.Success(SUCCESS); return Result.Success(SUCCESS);
} }
@Transactional
@ApiOperation("同步行程规划单的订单状态")
@PostMapping("/sync/order")
public Result<String> reloadOrderDetail(@RequestBody SyncLegData syncLegData) {
orderDetailDomainService.syncOrderDetailStatusByRouteId(syncLegData.getRouteId());
return Result.Success(SUCCESS);
}
} }

View File

@ -2,6 +2,7 @@ package com.chint.application.in;
import com.chint.application.queryies.OrderQuery; import com.chint.application.queryies.OrderQuery;
import com.chint.application.services.OrderApplicationService; import com.chint.application.services.OrderApplicationService;
import com.chint.domain.service.SystemDomainService;
import com.chint.domain.value_object.ApprovalLegData; import com.chint.domain.value_object.ApprovalLegData;
import com.chint.domain.value_object.ApproveLegData; import com.chint.domain.value_object.ApproveLegData;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
@ -22,6 +23,9 @@ public class OrderPublicController {
@Autowired @Autowired
private OrderApplicationService orderApplicationService; private OrderApplicationService orderApplicationService;
@Autowired
private SystemDomainService systemDomainService;
@Autowired @Autowired
private OrderQuery orderQuery; private OrderQuery orderQuery;
@ -29,6 +33,7 @@ public class OrderPublicController {
@ApiOperation("提交审批行程规划单") @ApiOperation("提交审批行程规划单")
@PostMapping("/approve") @PostMapping("/approve")
public Result<String> approveOrder(@RequestBody ApproveLegData approveLegData) { public Result<String> approveOrder(@RequestBody ApproveLegData approveLegData) {
systemDomainService.checkSystemCode(approveLegData.getSysCode());
orderApplicationService.approve(approveLegData); orderApplicationService.approve(approveLegData);
return Result.Success(SUCCESS); return Result.Success(SUCCESS);
} }
@ -49,4 +54,5 @@ public class OrderPublicController {
return Result.Success(SUCCESS); return Result.Success(SUCCESS);
} }
} }

View File

@ -4,6 +4,7 @@ package com.chint.application.out;
import com.chint.application.commands.OrderCreateCommand; import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.OrderException; import com.chint.domain.exceptions.OrderException;
import com.chint.domain.service.SystemDomainService;
import com.chint.domain.service.auth.AuthenticateService; import com.chint.domain.service.auth.AuthenticateService;
import com.chint.domain.value_object.UserLoginParam; import com.chint.domain.value_object.UserLoginParam;
import com.chint.domain.value_object.UserLoginResult; import com.chint.domain.value_object.UserLoginResult;
@ -41,6 +42,9 @@ public class LoginController {
@Autowired @Autowired
private UserHttpRequest userHttpRequest; private UserHttpRequest userHttpRequest;
@Autowired
private SystemDomainService systemDomainService;
@Transactional @Transactional
@GetMapping("/login") @GetMapping("/login")
public Result<UserLoginResult> login(@RequestParam("sfno") String sfno, public Result<UserLoginResult> login(@RequestParam("sfno") String sfno,
@ -53,15 +57,8 @@ public class LoginController {
String originalString = sfno + syscode + billcode + companycode + AuthMessageConstant.LOGIN_SECRET_KEY + timespan; String originalString = sfno + syscode + billcode + companycode + AuthMessageConstant.LOGIN_SECRET_KEY + timespan;
String generateSign = Digest.md5(originalString); String generateSign = Digest.md5(originalString);
if (generateSign.equals(sign)) { if (generateSign.equals(sign)) {
//公司名称转为中文转为编号 //创建订单先对sysCode进行检查
/*if (StringCheck.isFirstCharacterChinese(companycode)) { systemDomainService.checkSystemCode(syscode);
User user = new User(Long.valueOf(sfno));
user.setUserLoginParam(new UserLoginParam());
BaseContext.setCurrentUser(user);
userHttpRequest.loadUserInfo(user);
BaseContext.removeCurrentUser();
companycode = user.getCompanyCode();
}*/
// 创建 UserLoginParam 对象 // 创建 UserLoginParam 对象
UserLoginParam userLoginParam = new UserLoginParam(sfno, syscode, billcode, companycode, timespan); UserLoginParam userLoginParam = new UserLoginParam(sfno, syscode, billcode, companycode, timespan);

View File

@ -11,7 +11,6 @@ import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.UserRepository; import com.chint.domain.repository.UserRepository;
import com.chint.domain.value_object.*; import com.chint.domain.value_object.*;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.PageResult;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -25,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
import static com.chint.infrastructure.constant.OrderConstant.*;
@RestController @RestController
@RequestMapping("/order") @RequestMapping("/order")
@ -61,6 +61,11 @@ public class OrderOutController {
User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId());
routeOrderRes.setUserName(user.getName()); routeOrderRes.setUserName(user.getName());
routeOrderRes.setOrderDetailRes(orderDetailResList); routeOrderRes.setOrderDetailRes(orderDetailResList);
routeOrderRes.setOrderDetailRes(routeOrderRes
.getOrderDetailRes()
.stream()
.filter(it -> !it.getOrderStatus().equals(ORDER_EVENT_CANCEL_NAME) && !it.getOrderStatus().equals(ORDER_EVENT_PREPARE_NAME))
.toList());
return Result.Success(SUCCESS, routeOrderRes); return Result.Success(SUCCESS, routeOrderRes);
} }
@ -81,6 +86,7 @@ public class OrderOutController {
public Result<FlightPriceData> estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) { public Result<FlightPriceData> estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) {
return Result.Success(SUCCESS, orderQuery.queryFlightPrice(priceQueryData)); return Result.Success(SUCCESS, orderQuery.queryFlightPrice(priceQueryData));
} }
@ApiOperation("查询酒店估算价格") @ApiOperation("查询酒店估算价格")
@PostMapping("/estimate/hotel") @PostMapping("/estimate/hotel")
public Result<HotelPriceData> estimateHotelPrice(@RequestBody PriceQueryData priceQueryData) { public Result<HotelPriceData> estimateHotelPrice(@RequestBody PriceQueryData priceQueryData) {
@ -88,6 +94,7 @@ public class OrderOutController {
} }
@ApiOperation("根据Id查询行程规划单-元年数据") @ApiOperation("根据Id查询行程规划单-元年数据")
@PostMapping("/query/tripCallback") @PostMapping("/query/tripCallback")
public Result<TripCallback> queryTripCallbackData(@RequestBody OrderQueryData queryData) { public Result<TripCallback> queryTripCallbackData(@RequestBody OrderQueryData queryData) {

View File

@ -17,6 +17,7 @@ import com.chint.infrastructure.constant.DataMessageConstant;
import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.constant.RouteConstant;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -44,6 +45,8 @@ public class OrderApplicationService {
@Autowired @Autowired
private LegFactory legFactory; private LegFactory legFactory;
@Transactional @Transactional
public RouteOrder saveOrder(OrderSaveData orderSaveData) { public RouteOrder saveOrder(OrderSaveData orderSaveData) {
RouteOrder order; RouteOrder order;
@ -142,4 +145,8 @@ public class OrderApplicationService {
Command.of(OrderApprovalCommand.class).data(data).sendToQueue(); Command.of(OrderApprovalCommand.class).data(data).sendToQueue();
} }
@Transactional
public void reloadOrderDetail(SyncLegData syncLegData) {
}
} }

View File

@ -9,6 +9,7 @@ import com.chint.infrastructure.constant.LegConstant;
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 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;
@ -19,7 +20,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@Slf4j
@Data @Data
@Table("leg") @Table("leg")
@NoArgsConstructor @NoArgsConstructor
@ -173,7 +174,8 @@ public class Leg {
// 检查是否已存在此类型的事件 // 检查是否已存在此类型的事件
boolean exists = eventList.stream().anyMatch(e -> e.getEventType().equals(newEventType)); boolean exists = eventList.stream().anyMatch(e -> e.getEventType().equals(newEventType));
if (exists) { if (exists) {
throw new LegEventException("Event of this type already exists."); log.info("Event of this type already exists.");
return this;
} }
// 如果列表为空且新事件不是准备事件抛出异常 // 如果列表为空且新事件不是准备事件抛出异常

View File

@ -2,7 +2,6 @@ package com.chint.domain.aggregates.order;
import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.NotFoundException;
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.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.constant.OrderConstant; import com.chint.infrastructure.constant.OrderConstant;
import lombok.Data; import lombok.Data;
@ -16,6 +15,8 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
@Data @Data
@Table("order_detail") @Table("order_detail")
public class OrderDetail { public class OrderDetail {
@ -93,6 +94,13 @@ public class OrderDetail {
return this; return this;
} }
public OrderEvent getLastEvent() {
return this.orderEventList
.stream()
.max(Comparator.comparingLong(OrderEvent::getOrderEventId))
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
}
public OrderDetail price(String price) { public OrderDetail price(String price) {
this.price = price; this.price = price;
return this; return this;
@ -105,7 +113,7 @@ public class OrderDetail {
case LegConstant.LEG_TYPE_HOTEL -> this.hotelOrderDetail; case LegConstant.LEG_TYPE_HOTEL -> this.hotelOrderDetail;
case LegConstant.LEG_TYPE_TAXI -> this.carOrderDetail; case LegConstant.LEG_TYPE_TAXI -> this.carOrderDetail;
case LegConstant.LEG_TYPE_OTHER -> this.otherOrderDetail; case LegConstant.LEG_TYPE_OTHER -> this.otherOrderDetail;
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND); default -> throw new NotFoundException(NOT_FOUND);
}; };
} }

View File

@ -12,6 +12,8 @@ import com.chint.infrastructure.constant.RouteConstant;
import com.chint.infrastructure.constant.SupplierNameConstant; import com.chint.infrastructure.constant.SupplierNameConstant;
import com.chint.infrastructure.constant.UtilConstant; import com.chint.infrastructure.constant.UtilConstant;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.echo_framework.dispatch.Properties;
import com.chint.infrastructure.echo_framework.dispatch.ResultContainer;
import com.chint.infrastructure.util.BigDecimalCalculator; import com.chint.infrastructure.util.BigDecimalCalculator;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
@ -28,6 +30,8 @@ import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
@Data @Data
@Table("route_order") @Table("route_order")
public class RouteOrder extends BaseEntity { public class RouteOrder extends BaseEntity {
@ -192,6 +196,8 @@ public class RouteOrder extends BaseEntity {
return this; return this;
} }
public RouteOrder reloadStatus(OrderSaveData orderSaveData) { public RouteOrder reloadStatus(OrderSaveData orderSaveData) {
// 重新加载所有Leg的状态 // 重新加载所有Leg的状态
List<Leg> legs = this.getLegItems(); List<Leg> legs = this.getLegItems();
@ -340,13 +346,13 @@ public class RouteOrder extends BaseEntity {
}; };
} }
public void matchOrderWithLeg(OrderDetail orderDetail) { public OrderDetail matchOrderWithLeg(OrderDetail orderDetail) {
if (this.legItems.isEmpty()) { if (this.legItems.isEmpty()) {
return; return orderDetail;
} }
// 定义时间容差例如1天 // 定义时间容差例如1天
long tolerance = Duration.ofDays(1).toMillis(); long tolerance = Duration.ofDays(2).toMillis();
List<Leg> potentialMatches = this.legItems.stream() List<Leg> potentialMatches = this.legItems.stream()
.filter(leg -> leg.getLegType().equals(orderDetail.getProductType()) .filter(leg -> leg.getLegType().equals(orderDetail.getProductType())
@ -363,11 +369,14 @@ public class RouteOrder extends BaseEntity {
// 如果找到最佳匹配项执行相应操作 // 如果找到最佳匹配项执行相应操作
if (bestMatch != null) { if (bestMatch != null) {
Command.of(LegOrderedCommand.class) Properties properties = Command.of(LegOrderedCommand.class)
.legId(bestMatch.getLegId()) .legId(bestMatch.getLegId())
.orderDetailId(orderDetail.getOrderId()) .orderDetailId(orderDetail.getOrderId())
.sendToQueue(); .sendToQueue();
ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL);
return (OrderDetail) byPropertyName.getValue();
} }
return orderDetail;
} }
private double calculateMatchScore(Leg leg, OrderDetail orderDetail, long tolerance) { private double calculateMatchScore(Leg leg, OrderDetail orderDetail, long tolerance) {

View File

@ -0,0 +1,12 @@
package com.chint.domain.aggregates.system;
import lombok.Data;
import org.springframework.data.relational.core.mapping.Table;
@Data
@Table("system_code")
public class SystemCode {
private Long id;
private String systemName;
private String systemCode;
}

View File

@ -14,4 +14,6 @@ public interface OrderDetailRepository {
OrderDetail save(OrderDetail orderDetail); OrderDetail save(OrderDetail orderDetail);
void deleteById(Long id);
} }

View File

@ -0,0 +1,13 @@
package com.chint.domain.repository;
import com.chint.domain.aggregates.system.SystemCode;
public interface SystemCodeRepository {
SystemCode save(SystemCode systemCode);
SystemCode findBySysCode(String sysCode);
SystemCode findById(Long id);
}

View File

@ -0,0 +1,65 @@
package com.chint.domain.service;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.order_search.OrderSearchSelector;
import com.chint.domain.service.supplier.OrderDataAdapterSelector;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.SupplierCallbackData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_CANCEL;
@Service
public class OrderDetailDomainService {
@Autowired
private OrderDetailRepository orderDetailRepository;
@Autowired
private OrderDetailFactory orderDetailFactory;
@Autowired
private RouteRepository routeRepository;
@Autowired
private OrderSearchSelector orderSearchSelector;
@Autowired
private OrderDataAdapterSelector orderDataAdapterSelector;
public void syncOrderDetailStatus(List<OrderLegData> orderLegDataList) {
for (OrderLegData orderLegData : orderLegDataList) {
orderDetailRepository.findByOrderNo(orderLegData.getOutOrderNo()).ifPresent(
it -> {
if (!it.getLastEvent().getEventType().equals(orderLegData.getOrderStatus())) {
it.addOrderEvent(orderDetailFactory.createEvent(orderLegData.getOrderStatus(),
orderLegData.getOriginOrderStatus()));
orderDetailRepository.save(it);
}
}
);
}
}
public void syncOrderDetailStatusByRouteId(Long RouteId) {
RouteOrder routeOrder = routeRepository.queryById(RouteId);
String supplierName = routeOrder.getSupplierName();
List<OrderLegData> orderLegDataList = new ArrayList<>();
List<String> list = routeOrder.getOrderDetails().stream()
.filter(it -> it.getLastEvent().getEventType() != ORDER_EVENT_CANCEL)
.map(OrderDetail::getOrderNo).toList();
for (String orderNo : list) {
SupplierCallbackData supplierCallbackData = orderSearchSelector.of(supplierName).searchOrderDetail(orderNo);
orderDataAdapterSelector.of(supplierName).adapt(supplierCallbackData).ifPresent(orderLegDataList::add);
}
syncOrderDetailStatus(orderLegDataList);
}
}

View File

@ -104,26 +104,25 @@ public class OrderDomainService {
@ListenTo(command = "OrderStatusChangeCommand", order = 0) @ListenTo(command = "OrderStatusChangeCommand", order = 0)
public void orderDetailStatusChange(OrderStatusChangeCommand command) { public void orderDetailStatusChange(OrderStatusChangeCommand command) {
orderDetailRepository.findByOrderNo(command.getOrderNo()).ifPresent(orderDetail -> { OrderDetail orderDetail = command.getOrderDetail();
String outStatus = command.getOutStatus(); String outStatus = command.getOutStatus();
Integer orderEventType = command.getOrderEventType(); Integer orderEventType = command.getOrderEventType();
OrderEvent event = orderDetailFactory.createEvent(orderEventType, OrderEvent event = orderDetailFactory.createEvent(orderEventType,
outStatus); outStatus);
orderDetail.addOrderEvent(event); orderDetail.addOrderEvent(event);
orderDetailRepository.save(orderDetail); orderDetailRepository.save(orderDetail);
if (orderEventType.equals(OrderConstant.ORDER_EVENT_ETA)) { if (orderEventType.equals(OrderConstant.ORDER_EVENT_ETA)) {
//这里如果发现事件的状态为ORDER_EVENT_ETA //这里如果发现事件的状态为ORDER_EVENT_ETA
//需要根据发送审批给bpm //需要根据发送审批给bpm
//根据订单类型获取不同的订单扩展明细 //根据订单类型获取不同的订单扩展明细
orderDetail.getExtensionDataByProductType(); orderDetail.getExtensionDataByProductType();
Command.of(BPMAuditCommand.class) Command.of(BPMAuditCommand.class)
.orderNo(orderDetail.getOrderNo()) .orderNo(orderDetail.getOrderNo())
.productType(orderDetail.getProductType()) .productType(orderDetail.getProductType())
.extensionData(orderDetail.getExtensionDataByProductType()) .extensionData(orderDetail.getExtensionDataByProductType())
.sendToQueue(); .sendToQueue();
} };
});
} }
@ListenTo(command = "BPMAuditCommand", order = 0) @ListenTo(command = "BPMAuditCommand", order = 0)

View File

@ -0,0 +1,23 @@
package com.chint.domain.service;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.SystemCodeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.chint.infrastructure.constant.DataMessageConstant.SYS_CODE_ERROR;
@Service
public class SystemDomainService {
@Autowired
private SystemCodeRepository systemCodeRepository;
public boolean checkSystemCode(String sysCode) {
boolean b = systemCodeRepository.findBySysCode(sysCode) != null;
if(!b){
throw new NotFoundException(SYS_CODE_ERROR);
}
return b;
}
}

View File

@ -28,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.DataMessageConstant.ORDER_STATUS_ERROR;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
@Service @Service
@ -76,10 +78,10 @@ public class LegEventHandler implements LegEventService {
if (routeOrder.getLegItems().isEmpty()) { if (routeOrder.getLegItems().isEmpty()) {
throw new OrderException(CommonMessageConstant.LEG_ERROR); throw new OrderException(CommonMessageConstant.LEG_ERROR);
} }
if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_PREPARE)) { if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo()); approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setAccountCompany(data.getAccountCompany()); // approveOrderNo.setAccountCompany(data.getAccountCompany());
approveOrderNo.setInstructions(data.getInstructions()); approveOrderNo.setInstructions(data.getInstructions());
approveOrderNo.setCreator(data.getCreator()); approveOrderNo.setCreator(data.getCreator());
//这里order所有的leg触发approve事件 //这里order所有的leg触发approve事件
@ -92,8 +94,10 @@ public class LegEventHandler implements LegEventService {
routeOrder.addApprovalEvent(approvalEvent); routeOrder.addApprovalEvent(approvalEvent);
//保存routeOrder的状态 //保存routeOrder的状态
routeRepository.save(routeOrder); routeRepository.save(routeOrder);
} else if (routeOrder.getOrderStatus() > ORDER_STATUS_PREPARE) {
throw new CommandException(ORDER_STATUS_ERROR);
} else { } else {
throw new CommandException("订单未初始化"); throw new CommandException(ORDER_STATUS_ERROR);
} }
} }
@ -105,7 +109,7 @@ public class LegEventHandler implements LegEventService {
if (routeOrder.getOrderStatus() > (RouteConstant.ORDER_STATUS_APPROVAL)) { if (routeOrder.getOrderStatus() > (RouteConstant.ORDER_STATUS_APPROVAL)) {
throw new CommandException("订单已同步"); throw new CommandException("订单已同步");
} }
if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_PREPARE)) { if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
throw new CommandException("订单未提交审批"); throw new CommandException("订单未提交审批");
} }
if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_APPROVAL)) { if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_APPROVAL)) {
@ -158,7 +162,7 @@ public class LegEventHandler implements LegEventService {
// .max(Comparator.comparing(OrderDetail::getCreateTime)) // .max(Comparator.comparing(OrderDetail::getCreateTime))
// .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); // .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
//为订单添加订单已下单事件,这里需要发出额外的命令进行处理 //为订单添加订单已下单事件,这里需要发出额外的命令进行处理
routeOrder.matchOrderWithLeg(orderDetail); orderDetail = routeOrder.matchOrderWithLeg(orderDetail);
} else { } else {
orderDetail = byOrderNo.get(); orderDetail = byOrderNo.get();
} }
@ -167,7 +171,7 @@ public class LegEventHandler implements LegEventService {
@Transactional @Transactional
@Override @Override
public void orderLeg(LegOrderedCommand command) { public ResultContainer orderLeg(LegOrderedCommand command) {
//如果筛选事件可能会是错误需要用户手动添加并修改事件 因此会进行额外出发修改下单事件 //如果筛选事件可能会是错误需要用户手动添加并修改事件 因此会进行额外出发修改下单事件
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
//因为orderDetail已经进行持久化保存 只需要从数据库进行查询 //因为orderDetail已经进行持久化保存 只需要从数据库进行查询
@ -178,6 +182,7 @@ public class LegEventHandler implements LegEventService {
orderDetail.setLegId(leg.getLegId()); orderDetail.setLegId(leg.getLegId());
legRepository.save(leg); legRepository.save(leg);
orderDetailRepository.save(orderDetail); orderDetailRepository.save(orderDetail);
return ResultContainer.of(RESULT_ORDER_DETAIL).value(orderDetail);
} }
@Transactional @Transactional

View File

@ -13,7 +13,7 @@ public interface LegEventService {
void syncLeg(LegSyncCommand command); void syncLeg(LegSyncCommand command);
//下单事件 //下单事件
void orderLeg(LegOrderedCommand command); ResultContainer orderLeg(LegOrderedCommand command);
ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command); ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command);

View File

@ -39,15 +39,14 @@ public class LegEventServiceImpl implements LegEventService {
//下单时间要求回传需要付款的金额以及生成对于的行程订单号如果没有行程订单号根据地点和时间进行匹配 //下单时间要求回传需要付款的金额以及生成对于的行程订单号如果没有行程订单号根据地点和时间进行匹配
@ListenTo(command = "LegOrderedCommand", order = 0) @ListenTo(command = "LegOrderedCommand", order = 0)
@Override @Override
public void orderLeg(LegOrderedCommand command) { public ResultContainer orderLeg(LegOrderedCommand command) {
legEventHandler.orderLeg(command); return legEventHandler.orderLeg(command);
} }
@ListenTo(command = "RouteUpdateOrderCommand", order = 0) @ListenTo(command = "RouteUpdateOrderCommand", order = 0)
@Override @Override
public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) {
legEventHandler.routeUpdateOrder(command); return legEventHandler.routeUpdateOrder(command);
return null;
} }
@Override @Override

View File

@ -0,0 +1,22 @@
package com.chint.domain.service.order_search;
import com.chint.domain.service.supplier.OrderDataAdapterSelector;
import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP;
@Service
public class CTripOrderSearchImpl implements OrderSearchRequest {
@Autowired
private CTripOrderSearchRequest cTripOrderSearchRequest;
@Override
public SupplierCallbackData searchOrderDetail(String orderNo) {
SearchOrderResponse response = cTripOrderSearchRequest.searchOrderResponseByOrderId(orderNo);
return SupplierCallbackData.of(SUPPLIER_C_TRIP).data(response);
}
}

View File

@ -0,0 +1,12 @@
package com.chint.domain.service.order_search;
import com.chint.domain.value_object.SupplierCallbackData;
import org.springframework.stereotype.Component;
@Component
public class LYOrderSearchImpl implements OrderSearchRequest{
@Override
public SupplierCallbackData searchOrderDetail(String orderNo) {
return null;
}
}

View File

@ -0,0 +1,9 @@
package com.chint.domain.service.order_search;
import com.chint.domain.value_object.SupplierCallbackData;
public interface OrderSearchRequest {
SupplierCallbackData searchOrderDetail(String orderNo);
}

View File

@ -0,0 +1,28 @@
package com.chint.domain.service.order_search;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.service.supplier.CTripOrderDataAdapter;
import com.chint.domain.service.supplier.LYOrderDataAdapter;
import com.chint.domain.service.supplier.OrderDataAdapter;
import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.SupplierNameConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class OrderSearchSelector {
@Autowired
private CTripOrderSearchImpl cTripOrderSearch;
@Autowired
private LYOrderSearchImpl lyOrderSearch;
public OrderSearchRequest of(String supplierName) {
// 当找不到匹配的适配器时抛出一个异常
return switch (supplierName) {
case SupplierNameConstant.SUPPLIER_C_TRIP -> cTripOrderSearch;
case SupplierNameConstant.SUPPLIER_L_Y -> lyOrderSearch;
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}
}

View File

@ -1,7 +1,8 @@
package com.chint.domain.service.supplier; package com.chint.domain.service.supplier;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
public interface SupplierService { public interface SupplierService {
void handleSupplierCallback(SupplierCallbackData callbackData); OrderDetail handleSupplierCallback(SupplierCallbackData callbackData);
} }

View File

@ -2,9 +2,11 @@ package com.chint.domain.service.supplier;
import com.chint.application.commands.RouteUpdateOrderCommand; import com.chint.application.commands.RouteUpdateOrderCommand;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.factoriy.order_detail.OrderExtensionCreator; import com.chint.domain.factoriy.order_detail.OrderExtensionCreator;
import com.chint.domain.factoriy.order_detail.OrderExtensionFactory; import com.chint.domain.factoriy.order_detail.OrderExtensionFactory;
import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
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;
@ -13,6 +15,9 @@ import com.chint.infrastructure.echo_framework.dispatch.ResultContainer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
@Service @Service
@ -28,45 +33,43 @@ public class SupplierServiceImpl implements SupplierService {
private OrderDetailRepository orderDetailRepository; private OrderDetailRepository orderDetailRepository;
@Override @Override
public void handleSupplierCallback(SupplierCallbackData callbackData) { public OrderDetail handleSupplierCallback(SupplierCallbackData callbackData) {
String supplierName = callbackData.getSupplierName(); String supplierName = callbackData.getSupplierName();
orderDataAdapterSelector
.of(supplierName)
.adapt(callbackData)
.ifPresent(data -> {
System.out.println(data); Optional<OrderLegData> data = orderDataAdapterSelector.of(supplierName).adapt(callbackData);
//获取使用RouteUpdateOrderCommand命令创建的orderDetail if (data.isPresent()) {
Properties properties = Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue(); //获取使用RouteUpdateOrderCommand命令创建的orderDetail
ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL); Properties properties = Command.of(RouteUpdateOrderCommand.class).data(data.get()).sendToQueue();
OrderDetail orderDetail = (OrderDetail) byPropertyName.getValue(); ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL);
OrderDetail orderDetail = (OrderDetail) byPropertyName.getValue();
Integer productType = data.getProductType(); Integer productType = data.get().getProductType();
OrderExtensionFactory orderExtensionFactory = orderExtensionCreator OrderExtensionFactory orderExtensionFactory = orderExtensionCreator
.of(supplierName); .of(supplierName);
Object callbackDataData = callbackData.getData(); Object callbackDataData = callbackData.getData();
//根据产品的不同类型添加不同的扩展字段 //根据产品的不同类型添加不同的扩展字段
switch (productType) { switch (productType) {
case LegConstant.LEG_TYPE_TRAIN -> orderDetail.addTrainOrderData( case LegConstant.LEG_TYPE_TRAIN -> orderDetail.addTrainOrderData(
orderExtensionFactory.createTrainOrderDetail(callbackDataData) orderExtensionFactory.createTrainOrderDetail(callbackDataData)
); );
case LegConstant.LEG_TYPE_AIRPLANE -> orderDetail.addFlightOrderData( case LegConstant.LEG_TYPE_AIRPLANE -> orderDetail.addFlightOrderData(
orderExtensionFactory.createFlightOrderDetail(callbackDataData) orderExtensionFactory.createFlightOrderDetail(callbackDataData)
); );
case LegConstant.LEG_TYPE_HOTEL -> orderDetail.addHotelOrderData( case LegConstant.LEG_TYPE_HOTEL -> orderDetail.addHotelOrderData(
orderExtensionFactory.createHotelOrderDetail(callbackDataData) orderExtensionFactory.createHotelOrderDetail(callbackDataData)
); );
case LegConstant.LEG_TYPE_TAXI -> orderDetail.addCarOrderData( case LegConstant.LEG_TYPE_TAXI -> orderDetail.addCarOrderData(
orderExtensionFactory.createCarOrderDetail(callbackDataData) orderExtensionFactory.createCarOrderDetail(callbackDataData)
); );
case LegConstant.LEG_TYPE_OTHER -> orderDetail.addOtherOrderData( case LegConstant.LEG_TYPE_OTHER -> orderDetail.addOtherOrderData(
orderExtensionFactory.createOtherOrderDetail(callbackDataData) orderExtensionFactory.createOtherOrderDetail(callbackDataData)
); );
} }
//对orderDetail进行保存
//对orderDetail进行保存 return orderDetailRepository.save(orderDetail);
orderDetailRepository.save(orderDetail); } else {
}); throw new NotFoundException(NOT_FOUND);
}
} }
} }

View File

@ -1,13 +1,20 @@
package com.chint.domain.value_object; package com.chint.domain.value_object;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
public class ApproveLegData { public class ApproveLegData {
@ApiModelProperty("实际财务共享订单号")
private String actualOrderNo; private String actualOrderNo;
@ApiModelProperty("临时财务共享订单号")
private String fakeOrderNo; private String fakeOrderNo;
@ApiModelProperty("入账公司")
private String accountCompany; private String accountCompany;
@ApiModelProperty("系统标识")
private String sysCode; private String sysCode;
@ApiModelProperty("出差说明")
private String instructions; private String instructions;
@ApiModelProperty("财务共享订单创建人")
private String creator; private String creator;
} }

View File

@ -8,4 +8,6 @@ public class DataMessageConstant {
public static final String DATA_DELETION_SUCCESS = "数据删除成功"; public static final String DATA_DELETION_SUCCESS = "数据删除成功";
public static final String DATA_NOT_FOUND = "未找到数据"; public static final String DATA_NOT_FOUND = "未找到数据";
public static final String DATA_INVALID = "数据不合法"; public static final String DATA_INVALID = "数据不合法";
public static final String SYS_CODE_ERROR = "系统标识字段错误";
public static final String ORDER_STATUS_ERROR = "订单状态错误";
} }

View File

@ -36,4 +36,9 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository {
public OrderDetail save(OrderDetail orderDetail) { public OrderDetail save(OrderDetail orderDetail) {
return orderDetailRepository.save(orderDetail); return orderDetailRepository.save(orderDetail);
} }
@Override
public void deleteById(Long id) {
orderDetailRepository.deleteById(id);
}
} }

View File

@ -0,0 +1,32 @@
package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.system.SystemCode;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.SystemCodeRepository;
import com.chint.infrastructure.repository.jdbc.JdbcSystemCodeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
@Repository
public class SystemCodeRepositoryImpl implements SystemCodeRepository {
@Autowired
private JdbcSystemCodeRepository jdbcSystemCodeRepository;
@Override
public SystemCode save(SystemCode systemCode) {
return jdbcSystemCodeRepository.save(systemCode);
}
@Override
public SystemCode findBySysCode(String sysCode) {
return jdbcSystemCodeRepository.findBySystemCode(sysCode);
}
@Override
public SystemCode findById(Long id) {
return jdbcSystemCodeRepository.findById(id).orElseThrow(() -> new NotFoundException(NOT_FOUND));
}
}

View File

@ -0,0 +1,12 @@
package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.system.SystemCode;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface JdbcSystemCodeRepository extends CrudRepository<SystemCode, Long> {
SystemCode findBySystemCode(String systemCode);
}

View File

@ -1,6 +1,7 @@
package com.chint.interfaces.rest.base; package com.chint.interfaces.rest.base;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
@ -14,6 +15,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
@Component @Component
@Slf4j
public class PostRequest { public class PostRequest {
private final Gson gson = new Gson(); private final Gson gson = new Gson();
private final HttpClient client = HttpClients.createDefault(); private final HttpClient client = HttpClients.createDefault();
@ -21,7 +23,7 @@ public class PostRequest {
public <T> T post(String url, Object jsonRequest, Class<T> responseType) { public <T> T post(String url, Object jsonRequest, Class<T> responseType) {
HttpPost post = new HttpPost(url); HttpPost post = new HttpPost(url);
String json = gson.toJson(jsonRequest); String json = gson.toJson(jsonRequest);
System.out.println(json); log.info(json);
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
String responseBody = null; String responseBody = null;
HttpEntity responseEntity = null; HttpEntity responseEntity = null;
@ -40,7 +42,7 @@ public class PostRequest {
HttpPost post = new HttpPost(url); HttpPost post = new HttpPost(url);
post.addHeader(headName, headValue); post.addHeader(headName, headValue);
String json = gson.toJson(jsonRequest); String json = gson.toJson(jsonRequest);
System.out.println(json); log.info(json);
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
String responseBody = null; String responseBody = null;
HttpEntity responseEntity = null; HttpEntity responseEntity = null;

View File

@ -6,6 +6,7 @@ import com.chint.infrastructure.constant.BPMConstant;
import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.SupplierNameConstant; import com.chint.infrastructure.constant.SupplierNameConstant;
import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto; import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;

View File

@ -1,6 +1,7 @@
package com.chint.interfaces.rest.ctrip.in; package com.chint.interfaces.rest.ctrip.in;
import com.chint.application.commands.OrderStatusChangeCommand; import com.chint.application.commands.OrderStatusChangeCommand;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.service.supplier.SupplierService; import com.chint.domain.service.supplier.SupplierService;
import com.chint.domain.value_object.SupplierCallbackData; import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.constant.OrderConstant; import com.chint.infrastructure.constant.OrderConstant;
@ -13,6 +14,7 @@ import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusResponse;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -52,6 +54,7 @@ public class CTripNoteController {
// return new CTripNoteResponse("1", "未收到消息"); // return new CTripNoteResponse("1", "未收到消息");
// } // }
@Transactional
@PostMapping("/status") @PostMapping("/status")
public CTripStatusResponse statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) { public CTripStatusResponse statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) {
String productType = cTripStatusNotification.getProductType(); String productType = cTripStatusNotification.getProductType();
@ -62,45 +65,51 @@ public class CTripNoteController {
return new CTripStatusResponse("1", "sign错误"); return new CTripStatusResponse("1", "sign错误");
} }
if (orderStatus != null && orderId != null) { if (orderStatus != null && orderId != null) {
SupplierCallbackData supplierCallbackData = return handlerData(orderId, orderStatus, productType);
SupplierCallbackData.of(SupplierNameConstant.SUPPLIER_C_TRIP);
SearchOrderResponse response = cTripOrderSearchRequest
.searchOrderResponseByOrderId(orderId);
supplierCallbackData.data(response);
supplierService.handleSupplierCallback(supplierCallbackData);
OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class)
.orderNo(orderId)
.outStatus(orderStatus);
switch (productType) {
case "FlightInternational":
case "FlightDomestic":
command.eventType(mapFlightStatus(orderStatus));
break;
case "HotelMember":
case "HotelContract":
command.eventType(mapHotelStatus(orderStatus));
break;
case "Train":
case "OverseaTrain":
command.eventType(mapTrainStatus(orderStatus));
break;
case "CarPickUpInternational":
case "CarRentalDomestic":
case "CarImmediately":
case "CarPickUpDomesticNew":
case "CarCharterDomestic":
case "BusTicket":
command.eventType(mapCarStatus(orderStatus));
break;
}
command.sendToQueue();
return new CTripStatusResponse("0", "成功收到消息");
} }
return new CTripStatusResponse("1", "未收到消息"); return new CTripStatusResponse("1", "未收到消息");
} }
public CTripStatusResponse handlerData(String orderId, String orderStatus, String productType) {
SupplierCallbackData supplierCallbackData =
SupplierCallbackData.of(SupplierNameConstant.SUPPLIER_C_TRIP);
SearchOrderResponse response = cTripOrderSearchRequest
.searchOrderResponseByOrderId(orderId);
supplierCallbackData.data(response);
OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData);
OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class)
.orderDetail(orderDetail)
.orderNo(orderId)
.outStatus(orderStatus);
switch (productType) {
case "FlightInternational":
case "FlightDomestic":
command.eventType(mapFlightStatus(orderStatus));
break;
case "HotelMember":
case "HotelContract":
command.eventType(mapHotelStatus(orderStatus));
break;
case "Train":
case "OverseaTrain":
command.eventType(mapTrainStatus(orderStatus));
break;
case "CarPickUpInternational":
case "CarRentalDomestic":
case "CarImmediately":
case "CarPickUpDomesticNew":
case "CarCharterDomestic":
case "BusTicket":
command.eventType(mapCarStatus(orderStatus));
break;
}
command.sendToQueue();
return new CTripStatusResponse("0", "成功收到消息");
}
public Integer mapFlightStatus(String status) { public Integer mapFlightStatus(String status) {
return switch (status) { return switch (status) {
case "Submitted" -> OrderConstant.ORDER_EVENT_PREPARE; // "已提交"映射到准备下单 case "Submitted" -> OrderConstant.ORDER_EVENT_PREPARE; // "已提交"映射到准备下单

View File

@ -4,14 +4,20 @@ import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ly.dto.user.EmployeeRequest; import com.chint.interfaces.rest.ly.dto.user.EmployeeRequest;
import com.chint.interfaces.rest.ly.dto.user.EmployeeEntity; import com.chint.interfaces.rest.ly.dto.user.EmployeeEntity;
import com.chint.interfaces.rest.ly.dto.user.PreTravelPolicy;
import com.chint.interfaces.rest.user.UserHttpRequest; import com.chint.interfaces.rest.user.UserHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.chint.interfaces.rest.ly.dto.user.UserResponse; import com.chint.interfaces.rest.ly.dto.user.UserResponse;
import java.util.ArrayList;
import java.util.List;
import static com.chint.infrastructure.constant.LYConstant.L_Y_BASE_URL; import static com.chint.infrastructure.constant.LYConstant.L_Y_BASE_URL;
import static com.chint.infrastructure.constant.LYConstant.L_Y_USER_PATH; import static com.chint.infrastructure.constant.LYConstant.L_Y_USER_PATH;
@Slf4j
@Service @Service
public class LYUserRequest { public class LYUserRequest {
@ -27,7 +33,7 @@ public class LYUserRequest {
private final String userUrl = L_Y_BASE_URL + L_Y_USER_PATH; private final String userUrl = L_Y_BASE_URL + L_Y_USER_PATH;
public boolean saveCurrentUser() { public boolean saveCurrentUser() {
System.out.println("saveCurrentUser"); log.info("saveCurrentUser");
User currentUser = BaseContext.getCurrentUser(); User currentUser = BaseContext.getCurrentUser();
userHttpRequest.loadUserInfo(currentUser); userHttpRequest.loadUserInfo(currentUser);
EmployeeEntity employeeEntity = user2LYEmployee(currentUser); EmployeeEntity employeeEntity = user2LYEmployee(currentUser);
@ -66,7 +72,17 @@ public class LYUserRequest {
employeeEntity.setGender(translateGender(user.getGender())); employeeEntity.setGender(translateGender(user.getGender()));
employeeEntity.setWorkingState(translateWorkStatus(user.getWorkStatus())); employeeEntity.setWorkingState(translateWorkStatus(user.getWorkStatus()));
employeeEntity.setReservationType(0); employeeEntity.setReservationType(0);
employeeEntity.setPositionLevelName(user.getStandardLevel()); String standardLevel = user.getStandardLevel();
employeeEntity.setPositionLevelName(standardLevel);
List<PreTravelPolicy> preTravelPolicyList = List.of(
new PreTravelPolicy(standardLevel,1),
new PreTravelPolicy(standardLevel,2),
new PreTravelPolicy(standardLevel,3),
new PreTravelPolicy(standardLevel,4),
new PreTravelPolicy(standardLevel,5),
new PreTravelPolicy(standardLevel,6)
);
employeeEntity.setPreTravelPolicyList(preTravelPolicyList);
return employeeEntity; return employeeEntity;
} }
} }

View File

@ -32,5 +32,5 @@ public class EmployeeEntity {
private Map<String, String> remarks; private Map<String, String> remarks;
private String baseCity; private String baseCity;
// Getters and setters
} }

View File

@ -1,5 +1,10 @@
package com.chint.interfaces.rest.ly.dto.user; package com.chint.interfaces.rest.ly.dto.user;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class PreTravelPolicy { public class PreTravelPolicy {
private String policyCode; private String policyCode;
private int productTypeId; private int productTypeId;

View File

@ -15,6 +15,7 @@ import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.user.dto.*; import com.chint.interfaces.rest.user.dto.*;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
@ -31,6 +32,8 @@ import static com.chint.infrastructure.constant.RankConstant.STANDARD_LEVEL_THRE
import static com.chint.infrastructure.constant.SFConstant.OPENAI_BASE_URL; import static com.chint.infrastructure.constant.SFConstant.OPENAI_BASE_URL;
import static com.chint.infrastructure.constant.SFConstant.USER_DATA_PATH; import static com.chint.infrastructure.constant.SFConstant.USER_DATA_PATH;
@Slf4j
@Service @Service
public class UserHttpRequestImpl implements UserHttpRequest { public class UserHttpRequestImpl implements UserHttpRequest {
@ -113,7 +116,6 @@ public class UserHttpRequestImpl implements UserHttpRequest {
user.setProfLevel(userData.getCust_profLevel()); user.setProfLevel(userData.getCust_profLevel());
} else { } else {
Optional<UserDataDTO> first; Optional<UserDataDTO> first;
//这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配 //这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配
if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { if (StringCheck.isFirstCharacterChinese(newCompanyCode)) {
first = fromJson.stream() first = fromJson.stream()

View File

@ -1,32 +1,33 @@
server: server:
port: 8081 port: 8081
chint:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
host: rm-cn-jeo3lfy9q0006gso.rwlb.rds.aliyuncs.com
# host: 10.9.56.48
port: 3306
database: itinerary_booking
username: echo
password: R3nd0mP@ssw0rd!
url: https://gxdev03.chint.com/businesstravel/
#chint: #chint:
# datasource: # datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
# host: 10.10.24.44 # host: rm-cn-jeo3lfy9q0006gso.rwlb.rds.aliyuncs.com
# # host: 10.9.56.48 # # host: 10.9.56.48
# port: 6603 # port: 3306
# database: itinerary_booking # database: itinerary_booking
# username: tripbook # username: echo
# password: W@Xgf25d&lRk*L0X# # password: R3nd0mP@ssw0rd!
# url: https://gxdev03.chint.com/businesstravel/ # url: https://gxdev03.chint.com/businesstravel/
chint:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
host: 10.10.24.44
# host: 10.9.56.48
port: 6603
database: itinerary_booking
username: tripbook
password: W@Xgf25d&lRk*L0X#
url: https://gxdev03.chint.com/businesstravel/
logging: logging:
level: level:
org.springframework.jdbc.core.JdbcTemplate: DEBUG org.springframework.jdbc.core.JdbcTemplate: DEBUG
org.springframework.jdbc.core.StatementCreatorUtils: TRACE org.springframework.jdbc.core.StatementCreatorUtils: TRACE
root: info
cTrip: cTrip:

View File

@ -16,6 +16,7 @@ import com.chint.interfaces.rest.ctrip.dto.location.CTripCountry;
import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam; import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.PCResponse; import com.chint.interfaces.rest.ctrip.dto.login.PCResponse;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import com.chint.interfaces.rest.ctrip.in.CTripNoteController;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -50,6 +51,9 @@ public class CTripTest {
@Autowired @Autowired
private SupplierService supplierService; private SupplierService supplierService;
@Autowired
private CTripNoteController cTripNoteController;
private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365");
//@Test //@Test
@ -158,4 +162,10 @@ public class CTripTest {
supplierCallbackData.data(response); supplierCallbackData.data(response);
supplierService.handleSupplierCallback(supplierCallbackData); supplierService.handleSupplierCallback(supplierCallbackData);
} }
@Test
void backData(){
BaseContext.setCurrentUser(user);
cTripNoteController.handlerData("30607415392","Paid","HotelContract");
}
} }

View File

@ -4,9 +4,11 @@ import cn.hutool.extra.pinyin.PinyinUtil;
import com.chint.domain.aggregates.order.Location; import com.chint.domain.aggregates.order.Location;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.Digest;
import com.chint.interfaces.rest.user.UserHttpRequest; import com.chint.interfaces.rest.user.UserHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,6 +18,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@Slf4j
@SpringBootTest @SpringBootTest
class RouteApplicationTests { class RouteApplicationTests {
@ -28,6 +31,8 @@ class RouteApplicationTests {
@Autowired @Autowired
private RouteRepository routeRepository; private RouteRepository routeRepository;
@Autowired
private OrderDetailRepository orderDetailRepository;
private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365");
@ -45,14 +50,18 @@ class RouteApplicationTests {
} }
@Test @Test
void loginSign() { void loginSign() {
String sfno = "210901385"; String sfno = "230615020";
String syscode = "FSSC"; String syscode = "FSSC";
String billcode = "CLSQ240226000004"; String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司"; String companycode = "正泰集团股份有限公司";
String sec = "Superdandan"; String sec = "Superdandan";
String timespan = "1708908662738"; String timespan = "1708908662738";
String s = Digest.md5(sfno + syscode + billcode + companycode + sec + timespan); String s = Digest.md5(sfno + syscode + billcode + companycode + sec + timespan);
System.out.println(s); System.out.println(s);
// log.info("info");
// log.trace("trace");
// log.trace("trace");
// log.trace("trace");
} }
// @Test // @Test
@ -92,4 +101,16 @@ class RouteApplicationTests {
routeRepository.deleteById(19L); routeRepository.deleteById(19L);
routeRepository.deleteById(19L); routeRepository.deleteById(19L);
} }
@Test
void deleteOrderDetail(){
orderDetailRepository.deleteById(15L);
orderDetailRepository.deleteById(18L);
orderDetailRepository.deleteById(19L);
orderDetailRepository.deleteById(20L);
orderDetailRepository.deleteById(23L);
orderDetailRepository.deleteById(26L);
orderDetailRepository.deleteById(28L);
orderDetailRepository.deleteById(31L);
orderDetailRepository.deleteById(33L);
}
} }