修复bug
This commit is contained in:
@@ -44,10 +44,10 @@ public final class OrderRequests {
|
||||
LocalDate expectedShipDate,
|
||||
@Schema(description = "Customer remark / 客户备注", example = "Notify before pickup / 提货前联系", maxLength = 1000)
|
||||
@Size(max = 1000) String customerRemark,
|
||||
@Schema(description = "Sender information / 发货方信息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull @Valid Party sender,
|
||||
@Schema(description = "Receiver information / 收货方信息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull @Valid Party receiver,
|
||||
@Schema(description = "Sender information; required when pickupMethod is PICKUP / 发货方信息,取货方式为 PICKUP 时必填")
|
||||
@Valid Party sender,
|
||||
@Schema(description = "Receiver information; required for PRIVATE destination / 收货方信息,私人地址目的地时必填")
|
||||
@Valid Party receiver,
|
||||
@Schema(description = "Cargo lines / 货物明细", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty @Valid List<Cargo> cargoes,
|
||||
@NotBlank @Pattern(regexp = "SELF_EXPRESS|PICKUP|SELF_TRUCK") String pickupMethod,
|
||||
|
||||
@@ -145,6 +145,12 @@ public class OrderApplicationService {
|
||||
}
|
||||
|
||||
private void validatePrototypeFields(OrderRequests.SaveRequest request) {
|
||||
if ("PICKUP".equals(request.pickupMethod()) && request.sender() == null) {
|
||||
throw new BizException("上门提货时必须填写发货信息");
|
||||
}
|
||||
if ("PRIVATE".equals(request.destinationType()) && request.receiver() == null) {
|
||||
throw new BizException("私人地址必须填写收货信息");
|
||||
}
|
||||
if ("FBA".equals(request.destinationType())) {
|
||||
if (!StringUtils.hasText(request.amazonWarehouseCode()) || !StringUtils.hasText(request.shipmentId())
|
||||
|| !StringUtils.hasText(request.referenceId())) {
|
||||
@@ -168,6 +174,13 @@ public class OrderApplicationService {
|
||||
}
|
||||
var cargoes = repository.findCargo(tenantId, order.getId());
|
||||
if (cargoes == null || cargoes.isEmpty()) throw new BizException("At least one cargo line is required");
|
||||
var parties = repository.findParties(tenantId, order.getId());
|
||||
if ("PICKUP".equals(order.getPickupMethod()) && !hasParty(parties, "SENDER")) {
|
||||
throw new BizException("上门提货时必须填写发货信息");
|
||||
}
|
||||
if ("PRIVATE".equals(order.getDestinationType()) && !hasParty(parties, "RECEIVER")) {
|
||||
throw new BizException("私人地址必须填写收货信息");
|
||||
}
|
||||
if ("FBA".equals(order.getDestinationType())) {
|
||||
if (!StringUtils.hasText(order.getAmazonWarehouseCode()) || !StringUtils.hasText(order.getShipmentId())
|
||||
|| !StringUtils.hasText(order.getReferenceId())) {
|
||||
@@ -181,6 +194,11 @@ public class OrderApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasParty(List<OrderPartyEntity> parties, String partyType) {
|
||||
return parties != null && parties.stream()
|
||||
.anyMatch(party -> party != null && partyType.equals(party.getPartyType()));
|
||||
}
|
||||
|
||||
private OrderEntity require(long tenantId, long id) {
|
||||
OrderEntity order = repository.findOwned(tenantId, id);
|
||||
if (order == null) throw new BizException(com.baiyue.common.core.api.ResultCode.NOT_FOUND, "Order not found");
|
||||
@@ -272,7 +290,8 @@ public class OrderApplicationService {
|
||||
};
|
||||
}
|
||||
private void apply(OrderEntity order, OrderRequests.SaveRequest request, OrderMasterDataGuard.Snapshots snapshots) {
|
||||
order.setCustomerId(snapshots.partner().id()); order.setCustomerName(snapshots.partner().partnerName());
|
||||
order.setCustomerId(snapshots.partner() == null ? null : snapshots.partner().id());
|
||||
order.setCustomerName(snapshots.partner() == null ? request.customerName() : snapshots.partner().partnerName());
|
||||
order.setTransportMode(request.transportMode()); order.setTradeTerm(request.tradeTerm());
|
||||
order.setDestinationCountryCode(snapshots.destination() == null ? request.destinationCountryCode()
|
||||
: snapshots.destination().warehouse().countryCode());
|
||||
@@ -324,8 +343,8 @@ public class OrderApplicationService {
|
||||
item.setProductUsage(cargo.usage()); item.setModel(cargo.model()); item.setBrand(cargo.brand());
|
||||
item.setCreatedBy(userId); item.setUpdatedBy(userId); repository.insertCargo(item);
|
||||
}
|
||||
saveParty(tenantId, userId, orderId, "SENDER", request.sender());
|
||||
saveParty(tenantId, userId, orderId, "RECEIVER", request.receiver());
|
||||
if (request.sender() != null) saveParty(tenantId, userId, orderId, "SENDER", request.sender());
|
||||
if (request.receiver() != null) saveParty(tenantId, userId, orderId, "RECEIVER", request.receiver());
|
||||
}
|
||||
private void saveParty(long tenantId, long userId, long orderId, String type, OrderRequests.Party party) {
|
||||
OrderPartyEntity item = new OrderPartyEntity();
|
||||
|
||||
@@ -28,9 +28,8 @@ public class OrderMasterDataGuard {
|
||||
this.warehouses=warehouses; this.partners=partners; this.token=token;
|
||||
}
|
||||
public Snapshots validate(long tenantId, OrderRequests.SaveRequest request) {
|
||||
if (request.customerId() == null) throw new BizException(ResultCode.VALIDATION_FAILED, "必须选择往来单位");
|
||||
try {
|
||||
var partner=loadPartner(tenantId,request.customerId());
|
||||
PartnerClient.Partner partner=request.customerId()==null ? null : loadPartner(tenantId,request.customerId());
|
||||
var receiving=loadWarehouse(request.receivingWarehouseId(),"收货仓库");
|
||||
requireWarehouseType(receiving, "DOMESTIC", "收货仓库");
|
||||
if (receiving.addresses()==null || receiving.addresses().stream().noneMatch(Objects::nonNull))
|
||||
@@ -62,8 +61,7 @@ public class OrderMasterDataGuard {
|
||||
public void validatePersisted(long tenantId, Long partnerId, Long receivingWarehouseId,
|
||||
Long destinationWarehouseId, String destinationType) {
|
||||
try {
|
||||
if (partnerId==null) throw new BizException(ResultCode.NOT_FOUND,"往来单位已停用或不可用");
|
||||
loadPartner(tenantId,partnerId);
|
||||
if (partnerId!=null) loadPartner(tenantId,partnerId);
|
||||
if (receivingWarehouseId==null) throw new BizException(ResultCode.NOT_FOUND,"收货仓库已停用或不可用");
|
||||
WarehouseClient.Detail receiving=loadWarehouse(receivingWarehouseId,"收货仓库");
|
||||
requireWarehouseType(receiving,"DOMESTIC","收货仓库");
|
||||
|
||||
Reference in New Issue
Block a user