diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index bd5aab51..be7c8b1a 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -115,6 +115,18 @@ public class OrderOutController { return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); } + @ApiOperation("查询行程规划订单自定义字段") + @PostMapping("/query/custom/fields") + public Result> queryLeg(@RequestBody OrderQueryData queryData) { + RouteOrder routeOrder = routeRepository + .findByActualOrderNoAndSysCode(queryData.getActualOrderNo(), queryData.getSysCode()); + List approveCustomFieldList = routeOrder.getRouteCustomExtensionFieldList() + .stream() + .map(ApproveCustomField::of) + .toList(); + return Result.Success(SUCCESS, approveCustomFieldList); + } + @ApiOperation("查询能够同步的行程节点") @PostMapping("/query/legs") @@ -123,7 +135,7 @@ public class OrderOutController { List legResList = legDomainService .queryLegsCanSync(routeOrder, queryData.getSupplierName()).stream().map(LegRes::copyFrom).toList(); legResList.forEach(it -> it.setUserName(userRepository.findByUserEmployeeNo(routeOrder.getUserId()).getName())); - legDomainService.getSupplierName(legResList,routeOrder); + legDomainService.getSupplierName(legResList, routeOrder); return Result.Success(SUCCESS, legResList); } diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteCustomExtensionField.java b/src/main/java/com/chint/domain/aggregates/order/RouteCustomExtensionField.java index 8aa3ab50..80b899f8 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteCustomExtensionField.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteCustomExtensionField.java @@ -20,4 +20,15 @@ public class RouteCustomExtensionField implements Serializable { private Long routeOrderKey; private String fieldName; private String fieldValue; + private String extension; + + private RouteCustomExtensionField(String fieldName, String fieldValue, String extension) { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + this.extension = extension; + } + + public static RouteCustomExtensionField of(String fieldName, String fieldValue, String extension) { + return new RouteCustomExtensionField(fieldName, fieldValue, extension); + } } diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java index bbe4ea2b..958b559f 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -6,6 +6,7 @@ import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.supplier.SupplierConstantUtil; +import com.chint.domain.value_object.ApproveCustomField; import com.chint.domain.value_object.ApproveRouteData; import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.OrderSaveData; @@ -162,6 +163,22 @@ public class RouteOrder implements Serializable { parseAndSetTime(data.getStartTime(), true); parseAndSetTime(data.getEndTime(), false); + List approveCustomFieldList = data.getApproveCustomFieldList(); + if (approveCustomFieldList != null && !approveCustomFieldList.isEmpty()) { + if (this.getRouteCustomExtensionFieldList() == null) { + this.routeCustomExtensionFieldList = new ArrayList<>(); + } + for (ApproveCustomField approveCustomField : approveCustomFieldList) { + String fieldName = approveCustomField.getFieldName(); + String fieldValue = approveCustomField.getFieldValue(); + Optional first = this.routeCustomExtensionFieldList + .stream() + .filter(it -> it.getFieldName().equals(fieldName)) + .findFirst(); + first.ifPresentOrElse(it -> it.setFieldValue(fieldValue), + () -> this.routeCustomExtensionFieldList.add(RouteCustomExtensionField.of(fieldName, fieldValue, null))); + } + } return this; } diff --git a/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java b/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java new file mode 100644 index 00000000..3c19e607 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java @@ -0,0 +1,23 @@ +package com.chint.domain.aggregates.supplier; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.MappedCollection; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +@Data +@Table("supplier") +public class Supplier implements Serializable { + @Serial + private static final long serialVersionUID = 987635285619453614L; + @Id + private Long id; + private String name; + private String cnName; + @MappedCollection(idColumn = "supplier_id", keyColumn = "supplier_key") + private List supplierProductList; +} diff --git a/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java new file mode 100644 index 00000000..b1902dd4 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java @@ -0,0 +1,23 @@ +package com.chint.domain.aggregates.supplier; + + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Table("supplier_product") +public class SupplierProduct implements Serializable { + @Serial + private static final long serialVersionUID = 1296764923629924614L; + @Id + private Long id; + private Long supplierId; + private Long supplierKey; + private Integer productType; + private Integer ifCanOrder; + private String ifCanCancelRule; +} diff --git a/src/main/java/com/chint/domain/repository/SupplierRepository.java b/src/main/java/com/chint/domain/repository/SupplierRepository.java new file mode 100644 index 00000000..0b6c1577 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/SupplierRepository.java @@ -0,0 +1,11 @@ +package com.chint.domain.repository; + +import com.chint.domain.aggregates.supplier.Supplier; + +import java.util.Optional; + +public interface SupplierRepository { + Supplier save(Supplier supplier); + Optional findById(Long id); + Optional findBySupplierName(String supplierName); +} diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 522a0d14..3aafe189 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -2,17 +2,17 @@ package com.chint.domain.service; import com.chint.application.dtos.response.LegRes; import com.chint.domain.aggregates.order.*; +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.supplier.SupplierProduct; import com.chint.domain.exceptions.LegEventException; import com.chint.domain.factoriy.leg_event.LegEventFactory; -import com.chint.domain.repository.LegRepository; -import com.chint.domain.repository.LocationRepository; -import com.chint.domain.repository.OrderDetailRepository; -import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.LegConstant.*; @@ -41,6 +41,13 @@ public class LegDomainService { @Autowired private OrderDomainService orderDomainService; + @Autowired + private SupplierRepository supplierRepository; + + @Autowired + private SupplierDomainService supplierDomainService; + + public Leg legCheckOrder(Leg leg) { List orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); orderDetailList.forEach(OrderDetail::reloadStatus); @@ -161,9 +168,8 @@ public class LegDomainService { List legItems = routeOrder.getLegItems(); legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); -// if (supplierName.equals("CTrip")) { -// legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_TRAIN)).toList(); -// } + //通过查看供应商的商品类型,来进行同步 + legItems = supplierDomainService.ifCanSync(legItems, supplierName); List alreadySyncLegs = routeOrder.getRouteRequestList() .stream() diff --git a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java index 218d27be..48a103b5 100644 --- a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -1,12 +1,15 @@ package com.chint.domain.service; import com.chint.domain.aggregates.order.*; +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.supplier.SupplierProduct; import com.chint.domain.exceptions.CommandException; import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRequestRepository; +import com.chint.domain.repository.SupplierRepository; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.value_object.SyncLegData; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +47,12 @@ public class RouteRequestDomainService { @Autowired private LegEventFactory legEventFactory; + @Autowired + private SupplierRepository supplierRepository; + + @Autowired + private SupplierDomainService supplierDomainService; + // //这里增加一个判断 ,如果这个订单的行程为空,那么就返回给用户提示 // if (legItems == null || legItems.isEmpty()) { @@ -98,6 +107,7 @@ public class RouteRequestDomainService { return routeRequest; } + public void cancelRouteRequest(SyncLegData syncLegData) { Long routeId = syncLegData.getRouteId(); RouteOrder routeOrder = routeRepository.queryById(routeId); @@ -123,20 +133,26 @@ public class RouteRequestDomainService { .map(RouteRequestLeg::getLeg) .toList(); - Map> collect = legs - .stream() - .collect(Collectors.partitioningBy(leg -> { - Integer legStatus = leg.reloadStatus().getLegStatus(); - return (legStatus.equals(LEG_STATUS_ORDERED) || legStatus.equals(LEG_STATUS_PAYED) || legStatus.equals(LEG_STATUS_FINISH)) - && leg.getLegType().equals(LEG_TYPE_AIRPLANE); - })); - List orderedLegs = collect.get(true); - if (!orderedLegs.isEmpty()) { - it.reloadGenerateRequestLegs(orderedLegs); - syncAdapter.of(it.getSupplier()).syncRouteRequest(it); - it.addEvent(RouteRequestEvent.sync(it.getSupplier())); - List notOrderLegs = collect.get(false); - notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); + Optional supplierOptional = supplierRepository.findBySupplierName(it.getSupplier()); + Map> collect; + if (supplierOptional.isPresent()) { + collect = legs + .stream() + .collect(Collectors.partitioningBy(leg -> supplierDomainService.ifCanCancel(leg,it.getSupplier()))); + List orderedLegs = collect.get(false); + if (!orderedLegs.isEmpty()) { + it.reloadGenerateRequestLegs(orderedLegs); + syncAdapter.of(it.getSupplier()).syncRouteRequest(it); + it.addEvent(RouteRequestEvent.sync(it.getSupplier())); + List notOrderLegs = collect.get(true); + notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); + } else { + it.addEvent(RouteRequestEvent.cancel(it.getSupplier())); + getLegInfoFromRouteOrder(it, routeOrder); + syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); + it.getRouteRequestLegList() + .forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); + } } else { it.addEvent(RouteRequestEvent.cancel(it.getSupplier())); getLegInfoFromRouteOrder(it, routeOrder); @@ -144,6 +160,29 @@ public class RouteRequestDomainService { it.getRouteRequestLegList() .forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); } + +// Map> collect = legs +// .stream() +// .collect(Collectors.partitioningBy(leg -> { +// Integer legStatus = leg.reloadStatus().getLegStatus(); +// return (legStatus.equals(LEG_STATUS_ORDERED) || legStatus.equals(LEG_STATUS_PAYED) || legStatus.equals(LEG_STATUS_FINISH)) +// && leg.getLegType().equals(LEG_TYPE_AIRPLANE); +// })); + +// List orderedLegs = collect.get(true); +// if (!orderedLegs.isEmpty()) { +// it.reloadGenerateRequestLegs(orderedLegs); +// syncAdapter.of(it.getSupplier()).syncRouteRequest(it); +// it.addEvent(RouteRequestEvent.sync(it.getSupplier())); +// List notOrderLegs = collect.get(false); +// notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); +// } else { +// it.addEvent(RouteRequestEvent.cancel(it.getSupplier())); +// getLegInfoFromRouteOrder(it, routeOrder); +// syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); +// it.getRouteRequestLegList() +// .forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); +// } }); routeRepository.save(routeOrder); } @@ -164,7 +203,6 @@ public class RouteRequestDomainService { return optionalRouteRequest .orElseGet(() -> routeOrderFactory.createRequestWithLeg(routeOrder, legIds, supplier)).reloadStatus(); } - } //获取目前已经同步到供应商的差旅申请单 diff --git a/src/main/java/com/chint/domain/service/SupplierDomainService.java b/src/main/java/com/chint/domain/service/SupplierDomainService.java new file mode 100644 index 00000000..d62e8e39 --- /dev/null +++ b/src/main/java/com/chint/domain/service/SupplierDomainService.java @@ -0,0 +1,54 @@ +package com.chint.domain.service; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.supplier.SupplierProduct; +import com.chint.domain.repository.SupplierRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class SupplierDomainService { + + @Autowired + private SupplierRepository supplierRepository; + + public boolean ifCanCancel(Leg leg, String supplierName) { + Optional supplierOptional = supplierRepository.findBySupplierName(supplierName); + if (supplierOptional.isPresent()) { + Supplier supplier = supplierOptional.get(); + List supplierProductList = supplier.getSupplierProductList(); + for (SupplierProduct product : supplierProductList) { + if (product.getProductType().equals(leg.getLegType())) { + String ifCanCancelRule = product.getIfCanCancelRule(); + String[] split = ifCanCancelRule.split(","); + for (String status : split) { + if (status.equals(String.valueOf(leg.getLegStatus()))) { + return true; + } + } + } + } + } + return false; + } + + public List ifCanSync(List legs, String supplierName) { + Optional supplierOptional = supplierRepository.findBySupplierName(supplierName); + if (supplierOptional.isPresent()) { + Supplier supplier = supplierOptional.get(); + List productTypes = supplier + .getSupplierProductList() + .stream() + .filter(it->it.getIfCanOrder().equals(1)) + .map(SupplierProduct::getProductType) + .toList(); + return legs.stream().filter(it -> productTypes.contains(it.getLegType())).toList(); + } else { + return legs; + } + } +} diff --git a/src/main/java/com/chint/domain/value_object/ApproveCustomField.java b/src/main/java/com/chint/domain/value_object/ApproveCustomField.java new file mode 100644 index 00000000..003b59fa --- /dev/null +++ b/src/main/java/com/chint/domain/value_object/ApproveCustomField.java @@ -0,0 +1,18 @@ +package com.chint.domain.value_object; + +import cn.hutool.core.bean.BeanUtil; +import com.chint.domain.aggregates.order.RouteCustomExtensionField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class ApproveCustomField { + @ApiModelProperty("自定义字段名") + private String fieldName; + @ApiModelProperty("自定义字段值") + private String fieldValue; + + public static ApproveCustomField of(RouteCustomExtensionField routeCustomExtensionField) { + return BeanUtil.copyProperties(routeCustomExtensionField, ApproveCustomField.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/domain/value_object/ApproveRouteData.java b/src/main/java/com/chint/domain/value_object/ApproveRouteData.java index 087d4083..e00d95c5 100644 --- a/src/main/java/com/chint/domain/value_object/ApproveRouteData.java +++ b/src/main/java/com/chint/domain/value_object/ApproveRouteData.java @@ -31,13 +31,9 @@ public class ApproveRouteData { private String startTime; @ApiModelProperty("结束时间") private String endTime; - @ApiModelProperty("结束时间") + @ApiModelProperty("自定义字段") private List approveCustomFieldList; - @Data - private static class ApproveCustomField{ - private String fieldName; - private String fieldValue; - } + } diff --git a/src/main/java/com/chint/domain/value_object/OrderQueryData.java b/src/main/java/com/chint/domain/value_object/OrderQueryData.java index 955351ee..7007fdb5 100644 --- a/src/main/java/com/chint/domain/value_object/OrderQueryData.java +++ b/src/main/java/com/chint/domain/value_object/OrderQueryData.java @@ -13,6 +13,7 @@ public class OrderQueryData extends BaseQuery { @ApiModelProperty("需要同步的行程规划单ID") private Long routeId; private String billcode; + private String actualOrderNo; private String sysCode; private List approvalStatusCodes; private List legTypes; diff --git a/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java new file mode 100644 index 00000000..d4ad2887 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java @@ -0,0 +1,33 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.repository.SupplierRepository; +import com.chint.infrastructure.repository.jdbc.JdbcSupplierRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public class SupplierRepositoryImpl implements SupplierRepository { + + @Autowired + private JdbcSupplierRepository jdbcSupplierRepository; + + @Override + public Supplier save(Supplier supplier) { + return jdbcSupplierRepository.save(supplier); + } + + @Override + public Optional findById(Long id) { + return jdbcSupplierRepository.findById(id); + } + +// @Cacheable(value = "supplier", key = "#supplierName") + @Override + public Optional findBySupplierName(String supplierName) { + return jdbcSupplierRepository.findByName(supplierName); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java new file mode 100644 index 00000000..bef19dc9 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java @@ -0,0 +1,13 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.system.SupplierCallBackLog; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface JdbcSupplierRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index c9231cfd..e759624c 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -265,7 +265,7 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "200529132"; + String sfno = "240412063"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; @@ -280,7 +280,7 @@ class RouteApplicationTests { @Test void loginSignProd() { - String sfno = "200529132"; + String sfno = "240412063"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司";