From cd4ceecf989ef80e1414eff8e76c2400dca85f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Thu, 10 Sep 2026 20:17:05 +0800 Subject: [PATCH] =?UTF-8?q?OMS=E8=B0=83=E6=95=B4=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessDocumentOrderAdjustService.java | 55 ++++++++++++++++++- .../entity/BusinessDocumentOrder.java | 32 +++++++++++ .../service/OmsAddressMultiService.java | 18 +++++- 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/mhd_oms/src/main/java/com/mhd/oms/application/service/businessDocumentOrder/BusinessDocumentOrderAdjustService.java b/mhd_oms/src/main/java/com/mhd/oms/application/service/businessDocumentOrder/BusinessDocumentOrderAdjustService.java index 68de46eed..26aa5a696 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/application/service/businessDocumentOrder/BusinessDocumentOrderAdjustService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/application/service/businessDocumentOrder/BusinessDocumentOrderAdjustService.java @@ -20,6 +20,7 @@ import com.mhd.oms.domain.businessOrderAccount.BusinessOrderAccount; import com.mhd.oms.domain.businessOrderAccount.repository.mapper.BusinessOrderAccountMapper; import com.mhd.oms.domain.executeOrder.entity.ExecuteOrder; import com.mhd.oms.domain.executeOrder.repository.mapper.ExecuteOrderMapper; +import com.mhd.oms.interfaces.dto.businessDocumentAddressMulti.BusinessDocumentAddressMultiDTO; import com.mhd.oms.interfaces.dto.businessDocumentOrderAdjust.BusinessDocumentOrderAdjustAuditDTO; import com.mhd.oms.interfaces.dto.businessDocumentOrderAdjust.BusinessDocumentOrderAdjustDTO; import com.mhd.oms.interfaces.dto.businessDocumentOrderAdjust.BusinessDocumentOrderAdjustQueryDTO; @@ -137,12 +138,20 @@ public class BusinessDocumentOrderAdjustService { .eq(BusinessOrderAccount::getOrderId, dbOrder.getId()) .eq(BusinessOrderAccount::getIsDelete, 0)); - // 2. 调整后的费用明细(前端);为 null 则视为保持库中不变 + // 2. 调整后的费用明细(前端);为 null 则视为保持库中不变。 + // 兼容前端两种传法:顶层 feeDetailList,或整单回传 order.businessOrderAccountList List newFeeList = dto.getFeeDetailList(); + if ((newFeeList == null || newFeeList.isEmpty()) && front.getBusinessOrderAccountList() != null) { + newFeeList = front.getBusinessOrderAccountList(); + } // 3. 生成"调整后"业务单对象:DB原值 + 前端可编辑字段覆盖(忽略null) BusinessDocumentOrder afterOrder = buildAfterOrder(dbOrder, front); + // 3.1 地址兼容:前端把地址放在 shipment/receipt 或 loadingAddressList/unloadAddressList, + // 映射到 loading*/unload* 扁平字段(与下单主流程 BusinessDocumentOrderDomainService 一致口径) + applyAddressMapping(afterOrder, front); + // 4. 若提供了费用明细,则 deliveryFreight(合计)=明细 amount 之和,并联动到 afterOrder boolean hasFeeDetail = newFeeList != null && !newFeeList.isEmpty(); if (hasFeeDetail) { @@ -400,6 +409,50 @@ public class BusinessDocumentOrderAdjustService { return after; } + /** + * 地址兼容映射:前端整单回传时地址在 shipment/receipt 或 loadingAddressList/unloadAddressList, + * 这里统一映射到 business_document_order 的 loading 与 unload 系列扁平字段。 + * 口径与 BusinessDocumentOrderDomainService 下单主流程保持一致: + * 装货取第一条地址,卸货取最后一条地址。 + */ + private void applyAddressMapping(BusinessDocumentOrder after, BusinessDocumentOrder front) { + BusinessDocumentAddressMultiDTO loading = null; + BusinessDocumentAddressMultiDTO unloading = null; + + // 优先取 shipment/receipt 单对象,其次取 loadingAddressList/unloadAddressList 集合 + if (front.getShipment() != null) { + loading = front.getShipment(); + } else if (front.getLoadingAddressList() != null && !front.getLoadingAddressList().isEmpty()) { + loading = front.getLoadingAddressList().get(0); + } + if (front.getReceipt() != null) { + unloading = front.getReceipt(); + } else if (front.getUnloadAddressList() != null && !front.getUnloadAddressList().isEmpty()) { + unloading = front.getUnloadAddressList().get(front.getUnloadAddressList().size() - 1); + } + + if (loading != null) { + after.setLoadingAreaId(loading.getAreaCode()); + after.setLoadingName(loading.getAreaName() != null ? loading.getAreaName() : loading.getAreaCode()); + after.setLoadingAddress(loading.getAddress()); + after.setLoadingLongitude(loading.getLongitude()); + after.setLoadingLatitude(loading.getLatitude()); + after.setFreighterName(loading.getContactName()); + after.setLoadingPhone(loading.getContactPhone()); + after.setLoadingDate(loading.getLayDate()); + } + if (unloading != null) { + after.setUnloadAreaId(unloading.getAreaCode()); + after.setUnloadName(unloading.getAreaName() != null ? unloading.getAreaName() : unloading.getAreaCode()); + after.setUnloadAddress(unloading.getAddress()); + after.setUnloadLongitude(unloading.getLongitude()); + after.setUnloadLatitude(unloading.getLatitude()); + after.setDischargerName(unloading.getContactName()); + after.setUnloadPhone(unloading.getContactPhone()); + after.setUnloadingData(unloading.getLayDate()); + } + } + private BusinessDocumentOrderAdjust buildAdjust(BusinessDocumentOrder dbOrder, LoginUser u, Date now, boolean amountChanged, String reason) { BusinessDocumentOrderAdjust adjust = new BusinessDocumentOrderAdjust(); diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/businessDocumentOrder/entity/BusinessDocumentOrder.java b/mhd_oms/src/main/java/com/mhd/oms/domain/businessDocumentOrder/entity/BusinessDocumentOrder.java index 29f15fe9c..f24f19291 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/domain/businessDocumentOrder/entity/BusinessDocumentOrder.java +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/businessDocumentOrder/entity/BusinessDocumentOrder.java @@ -8,6 +8,7 @@ import com.mhd.common.core.web.domain.BaseVOEntity; import java.math.BigDecimal; import lombok.Data; import java.util.Date; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.format.annotation.DateTimeFormat; @@ -825,4 +826,35 @@ public class BusinessDocumentOrder extends BaseVOEntity{ @ApiModelProperty("车次") @Excel(name = "车次") private String shuttleNo; + + /** + * 前端整单回传时携带的费用明细(business_order_account),非表字段,仅用于「订单调整」入参接收。 + * 与顶层 feeDetailList 二选一,后端在 adjust() 中做回退兼容。 + */ + @com.baomidou.mybatisplus.annotation.TableField(exist = false) + private List businessOrderAccountList; + + /** + * 前端整单回传时的装货地址(单个),非表字段,仅用于「订单调整」入参接收与映射到 loading* 扁平字段。 + */ + @com.baomidou.mybatisplus.annotation.TableField(exist = false) + private com.mhd.oms.interfaces.dto.businessDocumentAddressMulti.BusinessDocumentAddressMultiDTO shipment; + + /** + * 前端整单回传时的卸货地址(单个),非表字段,仅用于「订单调整」入参接收与映射到 unload* 扁平字段。 + */ + @com.baomidou.mybatisplus.annotation.TableField(exist = false) + private com.mhd.oms.interfaces.dto.businessDocumentAddressMulti.BusinessDocumentAddressMultiDTO receipt; + + /** + * 前端整单回传时的装货地址集合,非表字段,仅用于「订单调整」入参接收与映射。 + */ + @com.baomidou.mybatisplus.annotation.TableField(exist = false) + private List loadingAddressList; + + /** + * 前端整单回传时的卸货地址集合,非表字段,仅用于「订单调整」入参接收与映射。 + */ + @com.baomidou.mybatisplus.annotation.TableField(exist = false) + private List unloadAddressList; } diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/reservationOrder/service/OmsAddressMultiService.java b/mhd_oms/src/main/java/com/mhd/oms/domain/reservationOrder/service/OmsAddressMultiService.java index 3ddce8ecd..70652f315 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/domain/reservationOrder/service/OmsAddressMultiService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/reservationOrder/service/OmsAddressMultiService.java @@ -610,6 +610,12 @@ public class OmsAddressMultiService implements IOmsAddressMultiService { List tmsOrderAccountList = tmsOrderAddDTO.getTmsOrderAccountList(); if (ObjectUtil.isNotNull(tmsOrderAccountList) && tmsOrderAccountList.size() > 0) { for (OmsOrderAccount tmsOrderAccount : tmsOrderAccountList) { + // 防御:account_id 为空或<=0 时跳过(避免唯一约束撞库 + 插入脏数据) + if (tmsOrderAccount.getAccountId() == null || tmsOrderAccount.getAccountId() <= 0) { + log.warn("订单费用科目 accountId 为空,已跳过该条, orderId={}, subjectName={}", + resevationOrder.getId(), tmsOrderAccount.getSubjectName()); + continue; + } tmsOrderAccount.setIsDelete(0); tmsOrderAccount.setOrderId(String.valueOf(resevationOrder.getId())); tmsOrderAccount.setCreateBy(String.valueOf(userPo.getUserId())); @@ -1116,14 +1122,20 @@ public class OmsAddressMultiService implements IOmsAddressMultiService { if (ObjectUtil.isNotNull(tmsOrderAccountList) && tmsOrderAccountList.size() > 0) { // 先删除旧的费用科目信息 tmsOrderAccountMapper.delete(new LambdaQueryWrapper().eq(OmsOrderAccount::getOrderId, String.valueOf(resevationOrder.getId()))); - + // 插入新的费用科目信息 for (OmsOrderAccount tmsOrderAccount : tmsOrderAccountList) { + // 防御:account_id 为空或<=0 时跳过 + if (tmsOrderAccount.getAccountId() == null || tmsOrderAccount.getAccountId() <= 0) { + log.warn("订单费用科目 accountId 为空,已跳过该条, orderId={}, subjectName={}", + resevationOrder.getId(), tmsOrderAccount.getSubjectName()); + continue; + } tmsOrderAccount.setIsDelete(0); tmsOrderAccount.setOrderId(String.valueOf(resevationOrder.getId())); tmsOrderAccount.setCreateBy(String.valueOf(userPo.getUserId())); tmsOrderAccount.setCreateTime(new Date()); - + // 设置组织信息 if (tmsOrderAddDTO.getOrganizationId() != null) { tmsOrderAccount.setOrganizationId(tmsOrderAddDTO.getOrganizationId()); @@ -1134,7 +1146,7 @@ public class OmsAddressMultiService implements IOmsAddressMultiService { if (tmsOrderAddDTO.getTopOrganizationId() != null) { tmsOrderAccount.setTopOrganizationId(tmsOrderAddDTO.getTopOrganizationId()); } - + tmsOrderAccountMapper.insert(tmsOrderAccount); } }