From b77287a3aead8d6d907f7aa2c8dabe1f668880ca Mon Sep 17 00:00:00 2001 From: lulz1 Date: Sun, 4 Feb 2024 16:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E4=BC=B0=E7=AE=97=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BB=A3=E7=A0=81=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chint/application/dtos/LocationParam.java | 1 + .../out/SupplierLoginController.java | 6 +++++ .../chint/domain/aggregates/order/Leg.java | 10 +++++++- .../domain/aggregates/order/RouteOrder.java | 14 +++++++++++ .../amount_estimate/AmountEstimate.java | 9 +++++++ .../amount_estimate/CTripEstimate.java | 18 +++++++++++++ .../amount_estimate/EstimateAdapter.java | 25 +++++++++++++++++++ .../service/amount_estimate/LYEstimate.java | 20 +++++++++++++++ .../leg_event/LegEventServiceImpl.java | 3 +-- .../repository/LocationRepositoryImpl.java | 4 +++ 10 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/chint/domain/service/amount_estimate/AmountEstimate.java create mode 100644 src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java create mode 100644 src/main/java/com/chint/domain/service/amount_estimate/EstimateAdapter.java create mode 100644 src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java diff --git a/src/main/java/com/chint/application/dtos/LocationParam.java b/src/main/java/com/chint/application/dtos/LocationParam.java index 646f28de..fcf99ad9 100644 --- a/src/main/java/com/chint/application/dtos/LocationParam.java +++ b/src/main/java/com/chint/application/dtos/LocationParam.java @@ -7,4 +7,5 @@ import lombok.Data; public class LocationParam extends BaseQuery { private Long level; private Long parentLocationId; + private String cityName; } diff --git a/src/main/java/com/chint/application/out/SupplierLoginController.java b/src/main/java/com/chint/application/out/SupplierLoginController.java index 1653738b..750fbec2 100644 --- a/src/main/java/com/chint/application/out/SupplierLoginController.java +++ b/src/main/java/com/chint/application/out/SupplierLoginController.java @@ -17,4 +17,10 @@ public class SupplierLoginController { public Result lyLogin() { return Result.Success(SUCCESS); } + + @PostMapping("/CTrip/login") + public Result cTripLogin() { + return Result.Success(SUCCESS); + } + } diff --git a/src/main/java/com/chint/domain/aggregates/order/Leg.java b/src/main/java/com/chint/domain/aggregates/order/Leg.java index 555e3997..f066dc81 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -2,6 +2,7 @@ package com.chint.domain.aggregates.order; import com.chint.domain.exceptions.LegEventException; +import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; import lombok.Data; import lombok.NoArgsConstructor; @@ -55,7 +56,7 @@ public class Leg { @Transient private String legStatusName; - @MappedCollection(idColumn = "leg_id",keyColumn = "leg_key") + @MappedCollection(idColumn = "leg_id", keyColumn = "leg_key") private List eventList; public Leg(Long legId) { @@ -66,6 +67,13 @@ public class Leg { return new Leg(legId); } + public Leg queryEstimateAmount(EstimateAdapter estimateAdapter, String supplierName) { + if (this.legStatus >= (LEG_STATUS_NOT_ORDERED)) { + this.estimateAmount = estimateAdapter.of(supplierName).amountEstimate(this); + } + return this; + } + public Leg reloadStatus() { if (eventList == null) { this.legStatus = LEG_STATUS_PREPARE; 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 df501a39..50ea3bf1 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -3,6 +3,7 @@ package com.chint.domain.aggregates.order; import com.chint.domain.aggregates.base.BaseEntity; import com.chint.domain.factoriy.leg.LegFactory; +import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.OrderSaveData; import com.chint.infrastructure.util.BigDecimalCalculator; @@ -50,6 +51,8 @@ public class RouteOrder extends BaseEntity { @Transient private String orderStatusName; + private String supplierName; + @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") public List legItems; @@ -77,6 +80,17 @@ public class RouteOrder extends BaseEntity { .collect(Collectors.toList()); } + public RouteOrder queryEstimateAmount(EstimateAdapter estimateAdapter) { + if (this.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) { + this.estimateAmount = estimateAdapter + .of(this.supplierName) + .amountEstimate(this); + this.getLegItems() + .forEach(leg -> leg.queryEstimateAmount(estimateAdapter, this.supplierName)); + } + return this; + } + public RouteOrder reloadStatus() { this.getLegItems().forEach(Leg::reloadStatus); this.estimateAmount = this.getLegItems() diff --git a/src/main/java/com/chint/domain/service/amount_estimate/AmountEstimate.java b/src/main/java/com/chint/domain/service/amount_estimate/AmountEstimate.java new file mode 100644 index 00000000..ee258dd4 --- /dev/null +++ b/src/main/java/com/chint/domain/service/amount_estimate/AmountEstimate.java @@ -0,0 +1,9 @@ +package com.chint.domain.service.amount_estimate; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.RouteOrder; + +public interface AmountEstimate { + String amountEstimate(Leg leg); + String amountEstimate(RouteOrder routeOrder); +} diff --git a/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java b/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java new file mode 100644 index 00000000..89e20371 --- /dev/null +++ b/src/main/java/com/chint/domain/service/amount_estimate/CTripEstimate.java @@ -0,0 +1,18 @@ +package com.chint.domain.service.amount_estimate; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.RouteOrder; +import org.springframework.stereotype.Component; + +@Component +public class CTripEstimate implements AmountEstimate { + @Override + public String amountEstimate(Leg leg) { + return null; + } + + @Override + public String amountEstimate(RouteOrder routeOrder) { + return null; + } +} diff --git a/src/main/java/com/chint/domain/service/amount_estimate/EstimateAdapter.java b/src/main/java/com/chint/domain/service/amount_estimate/EstimateAdapter.java new file mode 100644 index 00000000..69b8c2de --- /dev/null +++ b/src/main/java/com/chint/domain/service/amount_estimate/EstimateAdapter.java @@ -0,0 +1,25 @@ +package com.chint.domain.service.amount_estimate; + +import com.chint.domain.exceptions.NotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import static com.chint.infrastructure.constant.Constant.*; + +@Component +public class EstimateAdapter { + + @Autowired + private CTripEstimate cTripEstimate; + + @Autowired + private LYEstimate lyEstimate; + + public AmountEstimate of(String supplierName) { + return switch (supplierName) { + case SUPPLIER_C_TRIP -> cTripEstimate; + case SUPPLIER_L_Y -> lyEstimate; + default -> throw new NotFoundException(NOT_FOUND); + }; + } +} diff --git a/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java b/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java new file mode 100644 index 00000000..64f0a666 --- /dev/null +++ b/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java @@ -0,0 +1,20 @@ +package com.chint.domain.service.amount_estimate; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.RouteOrder; +import org.springframework.stereotype.Component; + +@Component +public class LYEstimate implements AmountEstimate { + @Override + public String amountEstimate(Leg leg) { + return null; + } + + @Override + public String amountEstimate(RouteOrder routeOrder) { + return null; + } + + +} diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java index 1f9c6bf3..d59f0d64 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java @@ -72,13 +72,12 @@ public class LegEventServiceImpl implements LegEventService { SyncLegData data = command.getData(); RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId()); String supplierName = data.getSupplierName(); - + routeOrder.setSupplierName(supplierName); //这里order所有的leg触发approve事件 routeOrder.getLegItems().forEach(leg -> leg.getEventList().add( legEventFactory.creatLegEvent(command.getLegEventType()) )); syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus()); - //保存routeOrder的状态 routeRepository.save(routeOrder); } diff --git a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java index 1e122213..00ef1f48 100644 --- a/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LocationRepositoryImpl.java @@ -26,6 +26,10 @@ public class LocationRepositoryImpl implements LocationRepository { locationParam.getPageNum() - 1, locationParam.getPageSize() ); + if(locationParam.getCityName() != null){ + Page res = jdbcLocationRepository.findAllByLocationPathContaining(locationParam.getCityName(), pageResult); + return PageResult.totalPageNum(res.getTotalElements(), res.toList()); + } if (locationParam.getLevel() != null) { Page res = jdbcLocationRepository.findAllByLevel(locationParam.getLevel(), pageResult); return PageResult.totalPageNum(res.getTotalElements(), res.toList());