价格估算接口代码初始化

This commit is contained in:
lulz1 2024-02-04 16:15:55 +08:00
parent 0ad7ffe1b0
commit b77287a3ae
10 changed files with 107 additions and 3 deletions

View File

@ -7,4 +7,5 @@ import lombok.Data;
public class LocationParam extends BaseQuery { public class LocationParam extends BaseQuery {
private Long level; private Long level;
private Long parentLocationId; private Long parentLocationId;
private String cityName;
} }

View File

@ -17,4 +17,10 @@ public class SupplierLoginController {
public Result<String> lyLogin() { public Result<String> lyLogin() {
return Result.Success(SUCCESS); return Result.Success(SUCCESS);
} }
@PostMapping("/CTrip/login")
public Result<String> cTripLogin() {
return Result.Success(SUCCESS);
}
} }

View File

@ -2,6 +2,7 @@ package com.chint.domain.aggregates.order;
import com.chint.domain.exceptions.LegEventException; import com.chint.domain.exceptions.LegEventException;
import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.LegData;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -55,7 +56,7 @@ public class Leg {
@Transient @Transient
private String legStatusName; private String legStatusName;
@MappedCollection(idColumn = "leg_id",keyColumn = "leg_key") @MappedCollection(idColumn = "leg_id", keyColumn = "leg_key")
private List<LegEvent> eventList; private List<LegEvent> eventList;
public Leg(Long legId) { public Leg(Long legId) {
@ -66,6 +67,13 @@ public class Leg {
return new Leg(legId); 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() { public Leg reloadStatus() {
if (eventList == null) { if (eventList == null) {
this.legStatus = LEG_STATUS_PREPARE; this.legStatus = LEG_STATUS_PREPARE;

View File

@ -3,6 +3,7 @@ package com.chint.domain.aggregates.order;
import com.chint.domain.aggregates.base.BaseEntity; import com.chint.domain.aggregates.base.BaseEntity;
import com.chint.domain.factoriy.leg.LegFactory; 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.LegData;
import com.chint.domain.value_object.OrderSaveData; import com.chint.domain.value_object.OrderSaveData;
import com.chint.infrastructure.util.BigDecimalCalculator; import com.chint.infrastructure.util.BigDecimalCalculator;
@ -50,6 +51,8 @@ public class RouteOrder extends BaseEntity {
@Transient @Transient
private String orderStatusName; private String orderStatusName;
private String supplierName;
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
public List<Leg> legItems; public List<Leg> legItems;
@ -77,6 +80,17 @@ public class RouteOrder extends BaseEntity {
.collect(Collectors.toList()); .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() { public RouteOrder reloadStatus() {
this.getLegItems().forEach(Leg::reloadStatus); this.getLegItems().forEach(Leg::reloadStatus);
this.estimateAmount = this.getLegItems() this.estimateAmount = this.getLegItems()

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
};
}
}

View File

@ -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;
}
}

View File

@ -72,13 +72,12 @@ public class LegEventServiceImpl implements LegEventService {
SyncLegData data = command.getData(); SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId()); RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId());
String supplierName = data.getSupplierName(); String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件 //这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add( routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType()) legEventFactory.creatLegEvent(command.getLegEventType())
)); ));
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus()); syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus());
//保存routeOrder的状态 //保存routeOrder的状态
routeRepository.save(routeOrder); routeRepository.save(routeOrder);
} }

View File

@ -26,6 +26,10 @@ public class LocationRepositoryImpl implements LocationRepository {
locationParam.getPageNum() - 1, locationParam.getPageNum() - 1,
locationParam.getPageSize() locationParam.getPageSize()
); );
if(locationParam.getCityName() != null){
Page<Location> res = jdbcLocationRepository.findAllByLocationPathContaining(locationParam.getCityName(), pageResult);
return PageResult.totalPageNum(res.getTotalElements(), res.toList());
}
if (locationParam.getLevel() != null) { if (locationParam.getLevel() != null) {
Page<Location> res = jdbcLocationRepository.findAllByLevel(locationParam.getLevel(), pageResult); Page<Location> res = jdbcLocationRepository.findAllByLevel(locationParam.getLevel(), pageResult);
return PageResult.totalPageNum(res.getTotalElements(), res.toList()); return PageResult.totalPageNum(res.getTotalElements(), res.toList());