diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalH3BPMMethod.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalH3BPMMethod.java new file mode 100644 index 00000000..9b5b7996 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalH3BPMMethod.java @@ -0,0 +1,169 @@ +package com.chint.domain.aggregates.approval.platform; + +import com.chint.domain.aggregates.order.*; +import com.chint.domain.aggregates.user.User; +import com.chint.domain.repository.LegRepository; +import com.chint.domain.repository.LocationRepository; +import com.chint.domain.repository.UserRepository; +import com.chint.domain.service.supplier.SupplierConstantUtil; +import com.chint.infrastructure.constant.BPMConstant; +import com.chint.infrastructure.util.DaysUtil; +import com.chint.infrastructure.util.Json; +import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.bpm.dot.BPMBaseResponse; +import com.chint.interfaces.rest.bpm.dto.BPMBaseRequest; +import com.chint.interfaces.rest.bpm.dto.BPMResponse; +import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto; +import com.chint.interfaces.rest.ctrip.CTripEstimateRequest; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; + +import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_HOTEL; +import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO; + +@Slf4j +@Component +public class ApprovalH3BPMMethod { + + @Autowired + private PostRequest postRequest; + + @Autowired + private LocationRepository locationRepository; + + @Autowired + private CTripEstimateRequest cTripEstimateRequest; + + @Autowired + private UserRepository userRepository; + @Autowired + private LegRepository legRepository; + + + /** + * H3BPM + */ + public BPMResponse H3BPMSubmitWorkflow(String url, String workflowCode, Object entityObject, String employeeNo) { + BPMBaseRequest bpmRequest = new BPMBaseRequest(); + String entityParamValues = Json.gson().toJson(entityObject); + bpmRequest.setWorkflowCode(workflowCode) + .setUserCode(employeeNo)//sf号 + .setFinishStart(true)//true:会自动流转到下一审批点,false:停在手工填写节点 + .setEntityParamValues(entityParamValues); + BPMBaseResponse bpmBaseResponse = postRequest.post(url, bpmRequest, BPMBaseResponse.class); + log.info("response = " + bpmBaseResponse); + return bpmBaseResponse.getD(); + } + + public ExceedStandardDto creatAuditParamByCar(OrderDetail orderDetail) { + CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail(); + ExceedStandardDto exceedStandardDto = new ExceedStandardDto(); + String supplierName = orderDetail.getSupplierName(); + exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_CAR) + .setOrderSource(SupplierConstantUtil.etaSupplierName(supplierName)) + .setOrderNo(carOrderDetail.getOrderNo()) + .setExcessAmount(BigDecimal.valueOf(Double.parseDouble(carOrderDetail.getOrderAmount()))) + .setReason(carOrderDetail.getOverStandardReason()); + return exceedStandardDto; + } + + public ExceedStandardDto creatAuditParamByTrain(OrderDetail orderDetail) { + TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail(); + ExceedStandardDto exceedStandardDto = new ExceedStandardDto(); + String supplierName = SupplierConstantUtil.etaSupplierName(orderDetail.getSupplierName()); + exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_TRAIN) + .setSeatingStandard(trainOrderDetail.getSeatName()) + .setOrderSource(supplierName) + .setOrderNo(trainOrderDetail.getOrderNo()) + .setExcessAmount(BigDecimal.valueOf(Double.parseDouble(trainOrderDetail.getOrderAmount()))) + .setReason(trainOrderDetail.getOverStandardReason()); + return exceedStandardDto; + } + + public ExceedStandardDto creatAuditParamByHotel(OrderDetail orderDetail, RouteOrder routeOrder) { + HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail(); + ExceedStandardDto exceedStandardDto = new ExceedStandardDto(); + Long legId = orderDetail.getLegId(); + // 差旅标准金额 + BigDecimal standardPrice = new BigDecimal("0"); + + // 定义用于计算标准价格的函数 + Function calculateStandardPrice = leg -> { + String standardTotalPrice = leg.getEstimateAmount() == null ? "0" : leg.getEstimateAmount(); + BigDecimal bigStandardPrice = new BigDecimal(standardTotalPrice); + int days = DaysUtil.calculateNightsBetweenDates(LocalDate.from(leg.getStartTime()), LocalDate.from(leg.getEndTime())); + return days > 0 ? bigStandardPrice.divide(new BigDecimal(days), 3, RoundingMode.HALF_UP) : bigStandardPrice; + }; + + // 当 legId 为 null 时的处理逻辑 + Supplier handleNullLegId = () -> { + Optional optById = locationRepository.findOptById(orderDetail.getOriginId()); + return optById.map(location -> { + Long cityId = location.getCityId(); + if (cityId != null) { + String maxPrice = cTripEstimateRequest.hotelMaxPrice(cityId, routeOrder.getUserId(), routeOrder.getStandardLevel()); + return maxPrice != null ? new BigDecimal(maxPrice) : new BigDecimal(KEEP_TWO_DECIMAL_ZERO); + } else { + return new BigDecimal(KEEP_TWO_DECIMAL_ZERO); + } + }).orElse(new BigDecimal(KEEP_TWO_DECIMAL_ZERO)); + }; + BigDecimal standardPriceFromQuery = handleNullLegId.get(); + if (orderDetail.getPrice() != null && orderDetail.getProductType().equals(LEG_TYPE_HOTEL)) { + standardPrice = !standardPriceFromQuery.equals(new BigDecimal(KEEP_TWO_DECIMAL_ZERO)) ? standardPriceFromQuery : + calculateStandardPrice.apply(legRepository.findByLegId(legId)); + } + + // 金额计算 + BigDecimal bigTotalPrice = new BigDecimal(orderDetail.getPrice() == null ? "0" : orderDetail.getPrice()); // 获取酒店需要支付的总价格 + int actualDays = DaysUtil.calculateNightsBetweenDates(LocalDate.from(orderDetail.getStartTime()), LocalDate.from(orderDetail.getEndTime())); + BigDecimal result = bigTotalPrice.subtract(standardPrice.multiply(BigDecimal.valueOf(actualDays))); + BigDecimal divide = actualDays > 0 ? result.divide(new BigDecimal(actualDays), 3, RoundingMode.HALF_UP) : result; + + // 超标总金额 + String supplierName = SupplierConstantUtil.etaSupplierName(orderDetail.getSupplierName()); + exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_HOTEL) + .setHotelStandard(String.valueOf(standardPrice)) // 差旅标准 + .setHouseLayout(hotelOrderDetail.getRoomTypeName()) + .setHotelName(hotelOrderDetail.getHotelName()) + .setOrderSource(supplierName) + .setOrderNo(hotelOrderDetail.getOrderNo()) + .setExcessAmount(result) // 超标金额 + .setReason(hotelOrderDetail.getOverStandardReason()) + .setOccupant(hotelOrderDetail.getBookingName()) // 入住人 + .setDays(Integer.valueOf(hotelOrderDetail.getNightCount())) // 入住天数 + .setExcessAmountDay(divide); // 超标金额(元/天) + + if (StringUtils.isBlank(exceedStandardDto.getOccupant())) { + String employeeNo = orderDetail.getEmployeeNo(); // 用户id + User user = userRepository.findByUserEmployeeNo(employeeNo); + if (user != null) { + exceedStandardDto.setOccupant(user.getName()); // 入住人 + } + } + return exceedStandardDto; + } + + public ExceedStandardDto creatAuditParamByFlight(OrderDetail orderDetail) { + FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail(); + ExceedStandardDto exceedStandardDto = new ExceedStandardDto(); + String supplierName = SupplierConstantUtil.etaSupplierName(orderDetail.getSupplierName()); + exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_FLIGHT) + .setCabinClass(flightOrderDetail.getSeatPointName()) + .setOrderSource(supplierName) + .setOrderNo(flightOrderDetail.getOrderNo()) + .setExcessAmount(BigDecimal.valueOf(Double.parseDouble(flightOrderDetail.getOrderAmount()))) + .setReason(flightOrderDetail.getOverStandardReason()); + return exceedStandardDto; + } + +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java index 6455bc53..d0b690c2 100644 --- a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java @@ -10,6 +10,9 @@ import java.io.Serial; import java.io.Serializable; import java.util.List; import java.util.Optional; +import java.util.function.Function; + +import static com.chint.domain.aggregates.approval.platform.ApprovalPlatformInfo.ApprovalPlatformPathType.*; @Data @Table("approval_platform_info") @@ -26,37 +29,61 @@ public class ApprovalPlatformInfo implements Serializable { private String platformDescription; private String platformExtension; + @MappedCollection(idColumn = "approval_platform_info_id", keyColumn = "approval_platform_info_key") private List approvalPlatformPathList; public Optional expenseUrl() { - return getUrlByType("EXPENSE"); + return getUrlByType(EXPENSE); } - public Optional changeUrl() { - return getUrlByType("CHANGE"); + return getUrlByType(CHANGE); } - - public Optional addUrl() { - return getUrlByType("ADD"); + return getUrlByType(ADD); } - public Optional refundOrderUrl() { - return getUrlByType("REFUND_ORDER"); + return getUrlByType(REFUND_ORDER); } - public Optional changeOrderUrl() { - return getUrlByType("CHANGE_ORDER"); + return getUrlByType(CHANGE_ORDER); } - public Optional getUrlByType(String type) { + public Optional expenseExtension() { + return getExtensionByType(EXPENSE); + } + public Optional changeExtension() { + return getExtensionByType(CHANGE); + } + public Optional addExtension() { + return getExtensionByType(ADD); + } + public Optional refundOrderExtension() { + return getExtensionByType(REFUND_ORDER); + } + public Optional changeOrderExtension() { + return getExtensionByType(CHANGE_ORDER); + } + + private Optional getPropertyByType(ApprovalPlatformPathType type, Function mapper) { if (approvalPlatformPathList == null || approvalPlatformPathList.isEmpty()) { return Optional.empty(); } return approvalPlatformPathList.stream() - .filter(it -> it.getApproval_platform_type().equals(type)) - .map(it -> this.platformBaseUrl + it.getApproval_platform_path()) + .filter(it -> it.getApproval_platform_type().equals(type.name())) + .map(mapper) .findFirst(); } + + public Optional getUrlByType(ApprovalPlatformPathType type) { + return getPropertyByType(type, it -> this.platformBaseUrl + it.getApproval_platform_path()); + } + + public Optional getExtensionByType(ApprovalPlatformPathType type) { + return getPropertyByType(type, ApprovalPlatformPath::getExtension); + } + + public enum ApprovalPlatformPathType { + EXPENSE, CHANGE, ADD, REFUND_ORDER, CHANGE_ORDER + } } diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformJT.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformJT.java new file mode 100644 index 00000000..d01de6db --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformJT.java @@ -0,0 +1,114 @@ +package com.chint.domain.aggregates.approval.platform; + +import com.chint.domain.aggregates.approval.ApprovalData; +import com.chint.domain.aggregates.approval.ApprovalResultData; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.repository.ApprovalPlatformInfoRepository; +import com.chint.domain.repository.SupplierRepository; +import com.chint.infrastructure.util.DelayDispatch; +import com.chint.infrastructure.util.Json; +import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto; +import jakarta.annotation.PostConstruct; +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +@Component +public class ApprovalPlatformJT implements ApprovalPlatform { + + @Autowired + private SupplierRepository supplierRepository; + + @Autowired + private ApprovalPlatformInfoRepository approvalPlatformInfoRepository; + + private ApprovalPlatformInfo approvalPlatformInfo; + + @Autowired + private ApprovalH3BPMMethod approvalH3BPMMethod; + + @Autowired + private PostRequest postRequest; + + public static final String platformMark = "JT"; + + @PostConstruct + void init() { + approvalPlatformInfoRepository.findByPlatformMark(platformMark) + .ifPresent(approvalPlatformInfo -> this.approvalPlatformInfo = approvalPlatformInfo); + } + + @Override + public void submitApproval(ApprovalData approvalData) { + + } + + @Override + public String getApprovalPlatformName() { + return ""; + } + + @Override + public void submitLegAddApproval(ApprovalData approvalData) { + + } + + @Override + public void submitLegChangeApproval(ApprovalData approvalData) { + + } + + @Override + public void submitOrderExpenseApproval(ApprovalData approvalData) { + Optional expenseUrlOpt = approvalPlatformInfo.expenseUrl(); + if (expenseUrlOpt.isEmpty()) { + return; + } + Optional expenseExtensionOpt = approvalPlatformInfo.expenseExtension(); + if (expenseExtensionOpt.isEmpty()) { + return; + } + RouteOrder routeOrder = approvalData.getRouteOrder(); + ExceedStandardDto exceedStandardDto = approvalH3BPMMethod + .creatAuditParamByHotel(approvalData.getOrderDetail(), routeOrder); + String json = Json.gson().toJson(exceedStandardDto); + String url = expenseUrlOpt.get(); + String extension = expenseExtensionOpt.get(); + DelayDispatch.attemptToSend( + () -> approvalH3BPMMethod.H3BPMSubmitWorkflow(url, extension, json, routeOrder.getUserId()).getSuccess(), 0 + ); + } + + @Override + public void submitOrderChangeApproval(ApprovalData approvalData) { + + } + + @Override + public void submitOrderRefundApproval(ApprovalData approvalData) { + + } + + @Override + public void submitLegAddOrChangeApproval(ApprovalData approvalData) { + + } + + @Override + public void receiveApprovalResultCustom(ApprovalResultData resultData) { + + } + + @Data + @Accessors(chain = true) + public static class ExpenseParam { + private String workflowCode;//流程编码 + private String userCode;//发起人SF号 + private Boolean finishStart;//是否结果填单节点 + private String EntityParamValues;//数据 + } +} diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderBaseRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderBaseRecord.java index 5c71875d..e580f080 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderBaseRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderBaseRecord.java @@ -10,4 +10,5 @@ public class OrderBaseRecord { private LocalDateTime updateDataTime; private String ticketClerk; // 票务员 private String belongDepart; + private Long routeId; } diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java index aeb509e5..16df3528 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java @@ -12,7 +12,7 @@ import org.springframework.data.relational.core.mapping.Table; @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) -public class OrderTrainRecord extends OrderBaseRecord{ +public class OrderTrainRecord extends OrderBaseRecord { @Id private Long id; private Long orderDetailId; @@ -21,7 +21,7 @@ public class OrderTrainRecord extends OrderBaseRecord{ private String detailId; // 结算明细唯一标识 private String accountCompanyId; // 核算企业code private String accountCompanyName; // 核算企业名称 -// private String ticketClerk; // 票务员 + // private String ticketClerk; // 票务员 private String accountPeriod; // 账期号 private String billNo; // 账单号 private String orderNo; // 订单号 @@ -74,15 +74,17 @@ public class OrderTrainRecord extends OrderBaseRecord{ private String yxId; // 影像比对ID private String orderStatus;//订单状态 private String receiptsNumOrigin;//原差旅申请单单号 -// private String belongDepart; //归属部门 + // private String belongDepart; //归属部门 private String settleOrderFlag; + public OrderTrainRecord loadBelongDeport(String belongDeport ) { // 行程信息 this.setBelongDepart(belongDeport); return this; } + // 加载基础订单信息 public OrderTrainRecord loadBasicOrderInfo(Long id, String orderNo, String orderStatus, String createTime) { this.setId(id); diff --git a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java index 24a4fad7..a9e17995 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java @@ -177,6 +177,10 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact orderCarRecord.setRunTime("0"); } + if (routeOrder.isPresent()) { + RouteOrder routeOrderEntity = routeOrder.get(); + orderCarRecord.setRouteId(routeOrderEntity.getRouteId()); + } orderDetail.ifPresentOrElse(orderCarRecord::loadComplianceInfo, orderCarRecord::loadComplianceInfoNot); return orderCarRecord; diff --git a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java index 2561cab4..0d9d65d6 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java @@ -871,6 +871,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac if (approveOrderNo != null) { orderCarRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); } + orderCarRecord.setRouteId(routeOrder.getRouteId()); } return orderCarRecord; } @@ -1071,8 +1072,8 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac if (approveOrderNo != null) { orderFlightRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); } + orderFlightRecord.setRouteId(routeOrder.getRouteId()); } - return orderFlightRecord; } @@ -1280,6 +1281,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac if (approveOrderNo != null) { orderHotelRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); } + orderHotelRecord.setRouteId(routeOrder.getRouteId()); } return orderHotelRecord; } diff --git a/src/main/java/com/chint/domain/factoriy/order_record/LyOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/LyOrderRecordExtensionFactory.java index 89da9745..434d5253 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/LyOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/LyOrderRecordExtensionFactory.java @@ -96,6 +96,11 @@ public class LyOrderRecordExtensionFactory implements OrderRecordExtensionFactor if (orderCarRecordData instanceof LyOrderCarRecord lyOrderCarRecord) { createCarOrder(orderCarRecord, lyOrderCarRecord, routeOrder); } + + if (routeOrder.isPresent()) { + RouteOrder routeOrderEntity = routeOrder.get(); + orderCarRecord.setRouteId(routeOrderEntity.getRouteId()); + } return orderCarRecord; } @@ -105,6 +110,11 @@ public class LyOrderRecordExtensionFactory implements OrderRecordExtensionFactor if (orderTrainRecordData instanceof LyOrderTrainRecord lyOrderTrainRecord) { createTrainOrder(orderTrainRecord, lyOrderTrainRecord, routeOrder); } + + if (routeOrder.isPresent()) { + RouteOrder routeOrderEntity = routeOrder.get(); + orderTrainRecord.setRouteId(routeOrderEntity.getRouteId()); + } return orderTrainRecord; } @@ -114,6 +124,11 @@ public class LyOrderRecordExtensionFactory implements OrderRecordExtensionFactor if (orderFlightRecordData instanceof LyOrderFlightRecord lyOrderFlightRecord) { createFlightOrder(orderFlightRecord, lyOrderFlightRecord, routeOrder); } + + if (routeOrder.isPresent()) { + RouteOrder routeOrderEntity = routeOrder.get(); + orderFlightRecord.setRouteId(routeOrderEntity.getRouteId()); + } return orderFlightRecord; } @@ -123,6 +138,11 @@ public class LyOrderRecordExtensionFactory implements OrderRecordExtensionFactor if (orderHotelRecordData instanceof LyOrderHotelRecord lyOrderHotelRecord) { createHotelOrder(orderHotelRecord, lyOrderHotelRecord, routeOrder); } + + if (routeOrder.isPresent()) { + RouteOrder routeOrderEntity = routeOrder.get(); + orderHotelRecord.setRouteId(routeOrderEntity.getRouteId()); + } return orderHotelRecord; } diff --git a/src/main/java/com/chint/domain/service/SupplierDomainService.java b/src/main/java/com/chint/domain/service/SupplierDomainService.java index e7b4363f..cfcdded9 100644 --- a/src/main/java/com/chint/domain/service/SupplierDomainService.java +++ b/src/main/java/com/chint/domain/service/SupplierDomainService.java @@ -23,6 +23,14 @@ public class SupplierDomainService { @Autowired private SupplierCallBackLogRepository supplierCallBackLogRepository; + + public String translateSupplierCNName(String supplier) { + return supplierRepository + .findBySupplierName(supplier) + .map(Supplier::getCnName) + .orElse(""); + } + public boolean ifCanCancel(Leg leg, String supplierName) { Optional supplierOptional = supplierRepository.findBySupplierName(supplierName); if (supplierOptional.isPresent()) { @@ -60,7 +68,6 @@ public class SupplierDomainService { } - @ListenTo(command = "SupplierCallBackErrorCommand", order = 0) public void supplierCallBackError(SupplierCallBackErrorCommand command) { SupplierCallBackLog supplierCallBackLog = SupplierCallBackLog diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierConstantUtil.java b/src/main/java/com/chint/domain/service/supplier/SupplierConstantUtil.java index e0e5f37c..790079ad 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierConstantUtil.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierConstantUtil.java @@ -1,17 +1,43 @@ package com.chint.domain.service.supplier; -import com.chint.infrastructure.constant.SupplierNameConstant; +import com.chint.domain.repository.SupplierRepository; +import com.chint.domain.service.SupplierDomainService; +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; -import static com.chint.infrastructure.constant.SupplierNameConstant.*; +import java.util.HashMap; +import java.util.Map; +@Slf4j +@Component public class SupplierConstantUtil { + @Autowired + private SupplierRepository supplierRepository; + + @Autowired + private SupplierDomainService supplierDomainService; + + private static final Map supplierCnNameMap = new HashMap<>(); + + @PostConstruct + public void init() { + supplierRepository.findAll() + .forEach(supplier -> supplierCnNameMap.put(supplier.getName(), supplier.getCnName())); + log.info(supplierCnNameMap.toString()); + } + public static String translateOrderSupplierName(String supplier) { - return switch (supplier) { - case SUPPLIER_L_Y -> SUPPLIER_L_Y_CN_NAME; - case SUPPLIER_C_TRIP -> SUPPLIER_C_TRIP_CN_NAME; - case SUPPLIER_AMAP -> SUPPLIER_AMAP_CN_NAME; - default -> "未知供应商"; - }; + return supplierCnNameMap.getOrDefault(supplier, ""); + } + + public static String etaSupplierName(String supplier) { + return translateOrderSupplierName(supplier) + "商旅"; + } + + public static String orderSupplierName(String supplier) { + return translateOrderSupplierName(supplier) + "预定"; } } diff --git a/src/main/java/com/chint/infrastructure/constant/SQLConstant.java b/src/main/java/com/chint/infrastructure/constant/SQLConstant.java new file mode 100644 index 00000000..f41f5e67 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/constant/SQLConstant.java @@ -0,0 +1,75 @@ +package com.chint.infrastructure.constant; + +import org.intellij.lang.annotations.Language; + +public class SQLConstant { + + @Language("sql") + public static final String OrderFlightRecordExtensionSQL = """ + select r1.* from order_flight_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + limit :offset , :size + """; + + @Language("sql") + public static final String OrderFlightRecordExtensionCOUNTSQL = """ + select count(*) from order_flight_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + """; + + + @Language("sql") + public static final String OrderHotelRecordExtensionSQL = """ + select r1.* from order_hotel_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + limit :offset , :size + """; + + @Language("sql") + public static final String OrderHotelRecordExtensionCOUNTSQL = """ + select count(*) from order_hotel_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + """; + + @Language("sql") + public static final String OrderTrainRecordExtensionSQL = """ + select r1.* from order_train_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + limit :offset , :size + """; + + @Language("sql") + public static final String OrderTrainRecordExtensionCOUNTSQL = """ + select count(*) from order_train_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + """; + + @Language("sql") + public static final String OrderCarRecordExtensionSQL = """ + select r1.* from order_car_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + limit :offset , :size + """; + + @Language("sql") + public static final String OrderCarRecordExtensionCOUNTSQL = """ + select count(*) from order_car_record r1 + left join route_custom_extension_field r3 on r1.route_id = r3.route_id + where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod + order by r1.create_time desc + """; +} diff --git a/src/main/java/com/chint/infrastructure/repository/UserNameRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/UserNameRepositoryImpl.java index 73cb2dc9..954a7598 100644 --- a/src/main/java/com/chint/infrastructure/repository/UserNameRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/UserNameRepositoryImpl.java @@ -15,7 +15,7 @@ public class UserNameRepositoryImpl implements UserNameRepository { @Autowired private JdbcUserNameRepository jdbcUserNameRepository; - @Cacheable(value = "user::name", key = "#employeeNo") + @Cacheable(value = "User::name", key = "#employeeNo") @Override public Optional findByEmployeeNo(String employeeNo) { return jdbcUserNameRepository.findByEmployeeNo(employeeNo); diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderCarRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderCarRecordRepository.java index c01add49..152ad234 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderCarRecordRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderCarRecordRepository.java @@ -12,6 +12,9 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import static com.chint.infrastructure.constant.SQLConstant.OrderCarRecordExtensionCOUNTSQL; +import static com.chint.infrastructure.constant.SQLConstant.OrderCarRecordExtensionSQL; + @Repository public interface JdbcOrderCarRecordRepository extends CrudRepository { @@ -32,24 +35,9 @@ public interface JdbcOrderCarRecordRepository extends CrudRepository findByAccountPeriod(String accountPeriod); - @Query(""" - select r1.* from order_car_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - limit :offset , :size - """) + @Query(OrderCarRecordExtensionSQL) List queryRecordByCustomFiled(String fieldName, String fieldValue, String accountPeriod, Integer offset, Integer size); - @Query(""" - select count(*) from order_car_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - """) + @Query(OrderCarRecordExtensionCOUNTSQL) Integer countRecordByCustomFiled(String fieldName, Object fieldValue, String accountPeriod); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderFlightRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderFlightRecordRepository.java index 64c931fb..03f33a5a 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderFlightRecordRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderFlightRecordRepository.java @@ -12,6 +12,8 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import static com.chint.infrastructure.constant.SQLConstant.*; + @Repository public interface JdbcOrderFlightRecordRepository extends CrudRepository { Optional findByDetailId(String detailId); @@ -30,24 +32,9 @@ public interface JdbcOrderFlightRecordRepository extends CrudRepository findByDetailIdIn(Collection detailId); List findByAccountPeriod(String accountPeriod); - @Query(""" - select r1.* from order_flight_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - limit :offset , :size - """) + @Query(OrderFlightRecordExtensionSQL) List queryRecordByCustomFiled(String fieldName, String fieldValue, String accountPeriod, Integer offset, Integer size); - @Query(""" - select count(*) from order_flight_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - """) + @Query(OrderFlightRecordExtensionCOUNTSQL) Integer countRecordByCustomFiled(String fieldName, Object fieldValue, String accountPeriod); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderHotelRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderHotelRecordRepository.java index d4e138d5..5f725201 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderHotelRecordRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderHotelRecordRepository.java @@ -12,6 +12,9 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import static com.chint.infrastructure.constant.SQLConstant.OrderHotelRecordExtensionCOUNTSQL; +import static com.chint.infrastructure.constant.SQLConstant.OrderHotelRecordExtensionSQL; + @Repository public interface JdbcOrderHotelRecordRepository extends CrudRepository { @@ -31,25 +34,10 @@ public interface JdbcOrderHotelRecordRepository extends CrudRepository findByDetailIdIn(Collection detailId); List findByAccountPeriod(String accountPeriod); - @Query(""" - select r1.* from order_hotel_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - limit :offset , :size - """) + @Query(OrderHotelRecordExtensionSQL) List queryRecordByCustomFiled(String fieldName, String fieldValue, String accountPeriod, Integer offset, Integer size); - @Query(""" - select count(*) from order_hotel_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - """) + @Query(OrderHotelRecordExtensionCOUNTSQL) Integer countRecordByCustomFiled(String fieldName, Object fieldValue, String accountPeriod); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderTrainRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderTrainRecordRepository.java index 89b14674..81868098 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderTrainRecordRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderTrainRecordRepository.java @@ -12,6 +12,9 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import static com.chint.infrastructure.constant.SQLConstant.OrderTrainRecordExtensionCOUNTSQL; +import static com.chint.infrastructure.constant.SQLConstant.OrderTrainRecordExtensionSQL; + @Repository public interface JdbcOrderTrainRecordRepository extends CrudRepository { Optional findByDetailId(String detailId); @@ -30,24 +33,9 @@ public interface JdbcOrderTrainRecordRepository extends CrudRepository findByDetailIdIn(Collection detailId); List findByAccountPeriod(String accountPeriod); - @Query(""" - select r1.* from order_train_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - limit :offset , :size - """) + @Query(OrderTrainRecordExtensionSQL) List queryRecordByCustomFiled(String fieldName, String fieldValue, String accountPeriod, Integer offset, Integer size); - @Query(""" - select count(*) from order_train_record r1 - left join order_detail o1 on r1.order_detail_id = o1.order_id - left join route_order r2 on o1.route_id = r2.route_id - left join route_custom_extension_field r3 on r2.route_id = r3.route_id - where r3.field_name = :fieldName and r3.field_value = :fieldValue and account_period = :accountPeriod - order by r1.create_time desc - """) + @Query(OrderTrainRecordExtensionCOUNTSQL) Integer countRecordByCustomFiled(String fieldName, Object fieldValue, String accountPeriod); } diff --git a/src/test/java/com/chint/CacheTest.java b/src/test/java/com/chint/CacheTest.java index e7df3fa5..7a7b3e51 100644 --- a/src/test/java/com/chint/CacheTest.java +++ b/src/test/java/com/chint/CacheTest.java @@ -6,13 +6,15 @@ import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserRepository; import com.chint.infrastructure.cache.RouteCacheManage; import com.chint.infrastructure.cache.RouteCacheService; -import com.chint.interfaces.rest.ctrip.CTripLocationHttpRequest; +import com.chint.infrastructure.repository.cache.CacheSystemOrganizationRepository; import com.google.gson.Gson; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cache.support.NullValue; import org.springframework.data.redis.core.RedisTemplate; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -31,8 +33,18 @@ public class CacheTest { @Autowired private UserRepository userRepository; + @Autowired + private CacheSystemOrganizationRepository cacheSystemOrganizationRepository; + private Gson gson = new Gson(); + @Test + public void nullTest(){ + List list = new ArrayList<>(); + list.add((Long) NullValue.INSTANCE); + cacheSystemOrganizationRepository.getFromCacheByIdIn( list ); + } + // @Test public void getAllRouteOrderById(){ List keys = List.of("RouteOrders::900","RouteOrders::918"); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index f2bf28f1..7e116cc0 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -314,9 +314,9 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "220222190"; + String sfno = "220506072"; String syscode = "FSSC"; - String billcode = "CLSQ240225000101"; + String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; String timespan = "1708908662738"; String s = Digest.md5(sfno + syscode + billcode + companycode + LOGIN_SECRET_KEY + timespan); @@ -325,7 +325,7 @@ class RouteApplicationTests { @Test void loginSignProd() { - String sfno = "240522018"; + String sfno = "240102037"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; @@ -336,6 +336,8 @@ class RouteApplicationTests { } + + @Test void deleteRouteOrder2() { routeRepository.deleteById(50519L); @@ -344,18 +346,10 @@ class RouteApplicationTests { @Test void testPushBatch() throws UnsupportedEncodingException { - List billcodeList = List.of("CLS24070100346", - "CLS24070100358", - "CLS24070100472", - "CLS24070100474", - "CLS24063000266"); + List billcodeList = List.of("CLS24070300047"); List sfnoList = List.of( - "220524027", - "220506052", - "180605050", - "220621032", - "220630159" + "220208019" ); System.out.println(billcodeList.size());