修改0108

This commit is contained in:
2026-01-08 17:22:13 +08:00
parent e0b88a84f0
commit 24c7c2997a
5 changed files with 57 additions and 36 deletions

View File

@@ -148,11 +148,10 @@ public class DeliveryOrderController extends BaseController {
* 从智慧实物系统拉取待配送出库单据列表 * 从智慧实物系统拉取待配送出库单据列表
*/ */
@GetMapping("/wisdom/rk/list") @GetMapping("/wisdom/rk/list")
public AjaxResult listRkFromWisdom() { public AjaxResult listRkFromWisdom(String billNoCk) {
List<DeliveryBillVO> list = deliveryOrderService.listWisdomRkForDelivery(); List<DeliveryBillVO> list = deliveryOrderService.listWisdomRkForDelivery(billNoCk);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
// ======================== 统计接口 ======================== // ======================== 统计接口 ========================
/** 总览统计 */ /** 总览统计 */

View File

@@ -26,11 +26,11 @@ public class DeliveryOrder extends BaseEntity {
private String orderNo; private String orderNo;
/** rk_info主键ID */ /** rk_info主键ID */
@Excel(name = "rk_info主键ID") // @Excel(name = "rk_info主键ID")
private Long rkInfoId; private Long rkInfoId;
/** 制单人用户ID */ /** 制单人用户ID */
@Excel(name = "制单人ID") // @Excel(name = "制单人ID")
private Long makerId; private Long makerId;
/** 制单人用户名(不入库,用于返回给前端) */ /** 制单人用户名(不入库,用于返回给前端) */
@@ -45,39 +45,39 @@ public class DeliveryOrder extends BaseEntity {
private String receiveProblem; private String receiveProblem;
/** 出库单据号 */ /** 出库单据号 */
@Excel(name = "出库单据号") // @Excel(name = "出库单据号")
private String billNoCk; private String billNoCk;
/** 项目描述 */ /** 项目描述 */
@Excel(name = "项目描述") // @Excel(name = "项目描述")
private String xmMs; private String xmMs;
/** 项目号 */ /** 项目号 */
@Excel(name = "项目号") // @Excel(name = "项目号")
private String xmNo; private String xmNo;
/** 物料号 */ /** 物料号 */
@Excel(name = "物料号") // @Excel(name = "物料号")
private String wlNo; private String wlNo;
/** 物料描述 */ /** 物料描述 */
@Excel(name = "物料描述") // @Excel(name = "物料描述")
private String wlMs; private String wlMs;
/** 实际入库数量 */ /** 实际入库数量 */
@Excel(name = "实际入库数量") // @Excel(name = "实际入库数量")
private BigDecimal realQty; private BigDecimal realQty;
/** 计量单位 */ /** 计量单位 */
@Excel(name = "计量单位") // @Excel(name = "计量单位")
private String dw; private String dw;
/** SAP订单编号 */ /** SAP订单编号 */
@Excel(name = "SAP订单编号") // @Excel(name = "SAP订单编号")
private String sapNo; private String sapNo;
/** 供应商名称 */ /** 供应商名称 */
@Excel(name = "供应商名称") // @Excel(name = "供应商名称")
private String gysMc; private String gysMc;
/** 起始地点名称 */ /** 起始地点名称 */

View File

@@ -37,8 +37,8 @@ public interface IDeliveryOrderService {
/** 详情:按单号查行 */ /** 详情:按单号查行 */
List<DeliveryOrderDetailVO> listByOrderNo(String orderNo); List<DeliveryOrderDetailVO> listByOrderNo(String orderNo);
/** 从智慧实物系统查询待配送出库单据 */ /** 从智慧实物系统查询待配送出库单据(可按出库单号 billNoCk 过滤) */
List<DeliveryBillVO> listWisdomRkForDelivery(); List<DeliveryBillVO> listWisdomRkForDelivery(String billNoCk);
// ======================== 统计 ======================== // ======================== 统计 ========================

View File

@@ -140,13 +140,19 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int executeBind(DeliveryExecuteBindDTO dto) { public int executeBind(DeliveryExecuteBindDTO dto) {
// 0) 基础校验
if (dto == null || StringUtils.isBlank(dto.getOrderNo())) {
throw new ServiceException("订单号不能为空");
}
// 1) 校验订单存在(一个单号多行) // 1) 校验订单存在(一个单号多行)
List<DeliveryOrder> existList = deliveryOrderMapper.selectDeliveryOrderByOrderNo(dto.getOrderNo()); List<DeliveryOrder> existList = deliveryOrderMapper.selectDeliveryOrderByOrderNo(dto.getOrderNo());
if (existList == null || existList.isEmpty()) { if (existList == null || existList.isEmpty()) {
throw new ServiceException("配送单不存在:" + dto.getOrderNo()); throw new ServiceException("配送单不存在:" + dto.getOrderNo());
} }
// ====== 从配送单中拿到所有 rk_info_id 列表 ====== // ====== 从配送单中拿到所有 rk_info_id 列表(允许为空:手工配送单场景) ======
List<Long> rkInfoIdList = existList.stream() List<Long> rkInfoIdList = existList.stream()
.map(DeliveryOrder::getRkInfoId) .map(DeliveryOrder::getRkInfoId)
.filter(Objects::nonNull) .filter(Objects::nonNull)
@@ -154,9 +160,10 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
.collect(Collectors.toList()); .collect(Collectors.toList());
if (rkInfoIdList.isEmpty()) { if (rkInfoIdList.isEmpty()) {
throw new ServiceException("配送单未绑定 rk_info_id无法回写库存状态"); // 手工创建的配送单可能没有绑定 rk_info_id允许为空后续只跳过 WMS 回写
log.warn("配送单未绑定 rk_info_id将跳过 WMS 库存状态回写。orderNo={}", dto.getOrderNo());
} }
// ==================================================== // ======================================================================
if (dto.getAttachments() == null || dto.getAttachments().isEmpty()) { if (dto.getAttachments() == null || dto.getAttachments().isEmpty()) {
throw new ServiceException("附件列表不能为空"); throw new ServiceException("附件列表不能为空");
@@ -164,8 +171,8 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
// 2) 批量插入附件(只传 URL // 2) 批量插入附件(只传 URL
List<DeliveryAttachment> list = new ArrayList<>(); List<DeliveryAttachment> list = new ArrayList<>();
String username = getUsername(); String username = getUsername();
for (DeliveryAttachItemDTO it : dto.getAttachments()) { for (DeliveryAttachItemDTO it : dto.getAttachments()) {
if (it == null) { if (it == null) {
continue; continue;
@@ -187,6 +194,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
a.setCreateTime(DateUtils.getNowDate()); a.setCreateTime(DateUtils.getNowDate());
list.add(a); list.add(a);
} }
if (list.isEmpty()) { if (list.isEmpty()) {
throw new ServiceException("有效附件条目为空"); throw new ServiceException("有效附件条目为空");
} }
@@ -197,6 +205,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
patch.setOrderNo(dto.getOrderNo()); patch.setOrderNo(dto.getOrderNo());
String scene = dto.getScene() == null ? "" : dto.getScene().toUpperCase(Locale.ROOT); String scene = dto.getScene() == null ? "" : dto.getScene().toUpperCase(Locale.ROOT);
if ("ORIGIN".equals(scene)) { if ("ORIGIN".equals(scene)) {
// 起点:司机信息 + 起点经纬度 + 状态=2起运/配送中) // 起点:司机信息 + 起点经纬度 + 状态=2起运/配送中)
if (dto.getDriverName() != null) patch.setDriverName(dto.getDriverName()); if (dto.getDriverName() != null) patch.setDriverName(dto.getDriverName());
@@ -205,6 +214,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
if (dto.getLng() != null) patch.setOriginLng(BigDecimal.valueOf(dto.getLng())); if (dto.getLng() != null) patch.setOriginLng(BigDecimal.valueOf(dto.getLng()));
if (dto.getLat() != null) patch.setOriginLat(BigDecimal.valueOf(dto.getLat())); if (dto.getLat() != null) patch.setOriginLat(BigDecimal.valueOf(dto.getLat()));
patch.setOrderStatus("2"); patch.setOrderStatus("2");
} else if ("DEST".equals(scene)) { } else if ("DEST".equals(scene)) {
// 终点:终点经纬度 + 费用 + 状态=3已完成 // 终点:终点经纬度 + 费用 + 状态=3已完成
if (dto.getLng() != null) patch.setDestLng(BigDecimal.valueOf(dto.getLng())); if (dto.getLng() != null) patch.setDestLng(BigDecimal.valueOf(dto.getLng()));
@@ -216,6 +226,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
} }
patch.setActualFee(dto.getActualFee()); patch.setActualFee(dto.getActualFee());
} }
if (dto.getTollFee() != null) { if (dto.getTollFee() != null) {
if (dto.getTollFee().compareTo(BigDecimal.ZERO) < 0) { if (dto.getTollFee().compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("高速费用不能为负数"); throw new ServiceException("高速费用不能为负数");
@@ -241,18 +252,26 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
} }
patch.setOrderStatus("3"); // 已完成 patch.setOrderStatus("3"); // 已完成
} else {
// scene 既不是 ORIGIN 也不是 DEST不强制报错避免影响“仅绑定附件”的场景
// 如果你希望严格校验,可以改为 throw new ServiceException("scene 不合法");
log.warn("executeBind 未识别的 scene={}将仅绑定附件并更新已有字段如有。orderNo={}", scene, dto.getOrderNo());
} }
deliveryOrderMapper.updateDeliveryOrder(patch); deliveryOrderMapper.updateDeliveryOrder(patch);
// 4) ⭐ 如果是 DEST 场景,远程调用 WMS把这些 rk_info 记录的 is_delivery 改成 3 // 4) ⭐ 仅当 DEST 场景且存在 rk_info_id 绑定时,才远程调用 WMS 回写 is_delivery=3
if ("DEST".equals(scene)) { if ("DEST".equals(scene)) {
// 这里已经不再按 billNoCk 整单更新,而是按 rk_info_id 列表更新 if (rkInfoIdList != null && !rkInfoIdList.isEmpty()) {
boolean ok = updateWmsIsDeliveryByIds(rkInfoIdList, 3); boolean ok = updateWmsIsDeliveryByIds(rkInfoIdList, 3);
if (!ok) { if (!ok) {
// 让整个事务回滚,附件 + 配送单状态都撤回 // 让整个事务回滚,附件 + 配送单状态都撤回
throw new ServiceException("回写 WMS 配送状态失败rk_info_id 列表:" + rkInfoIdList); throw new ServiceException("回写 WMS 配送状态失败rk_info_id 列表:" + rkInfoIdList);
}
} else {
// 手工配送单:不回写 WMS
log.info("DEST 场景下配送单无 rk_info_id 绑定,跳过 WMS 回写。orderNo={}", dto.getOrderNo());
} }
} }
@@ -263,7 +282,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
* 远程调用智慧实物管理系统,按 rk_info 主键ID列表更新 is_delivery 状态 * 远程调用智慧实物管理系统,按 rk_info 主键ID列表更新 is_delivery 状态
* 约定请求体结构: * 约定请求体结构:
* { * {
* "rkInfoIdList": [1, 2, 3], * "ids": [1, 2, 3],
* "isDelivery": 3 * "isDelivery": 3
* } * }
*/ */

View File

@@ -395,7 +395,7 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
* @return List<RkInfo> * @return List<RkInfo>
*/ */
@Override @Override
public List<DeliveryBillVO> listWisdomRkForDelivery() { public List<DeliveryBillVO> listWisdomRkForDelivery(String billNoCk) {
// 1. 远程接口地址 // 1. 远程接口地址
String url = wisdomBaseUrl + "/wisdom/stock/delivery/list"; String url = wisdomBaseUrl + "/wisdom/stock/delivery/list";
@@ -406,7 +406,10 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
param.append("&isChuku=1"); // 已出库 param.append("&isChuku=1"); // 已出库
param.append("&isDelivery=1"); // 需要配送 param.append("&isDelivery=1"); // 需要配送
// 2. 调用智慧实物系统 if (StringUtils.isNotBlank(billNoCk)) {
param.append("&billNoCk=").append(billNoCk);
}
// 3. 调用智慧实物系统
String respJson = HttpUtils.sendGet(url, param.toString()); String respJson = HttpUtils.sendGet(url, param.toString());
if (StringUtils.isEmpty(respJson)) { if (StringUtils.isEmpty(respJson)) {
throw new ServiceException("调用智慧实物接口失败:返回结果为空"); throw new ServiceException("调用智慧实物接口失败:返回结果为空");
@@ -428,10 +431,10 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
return new ArrayList<>(); return new ArrayList<>();
} }
// 3. 反序列化为一对多结构DeliveryBillVO(detailList 中是 RkInfo) // 4. 反序列化为一对多结构DeliveryBillVO(detailList 中是 RkInfo)
List<DeliveryBillVO> list = data.toJavaList(DeliveryBillVO.class); List<DeliveryBillVO> list = data.toJavaList(DeliveryBillVO.class);
// 4. 收集所有 wlNo // 5. 收集所有 wlNo
Set<String> wlNoSet = list.stream() Set<String> wlNoSet = list.stream()
.filter(bill -> bill.getDetailList() != null && !bill.getDetailList().isEmpty()) .filter(bill -> bill.getDetailList() != null && !bill.getDetailList().isEmpty())
.flatMap(bill -> bill.getDetailList().stream()) .flatMap(bill -> bill.getDetailList().stream())
@@ -443,22 +446,21 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
return list; return list;
} }
// 5. 一次性查询本地 delivery_mtd // 6. 一次性查询本地 delivery_mtd
List<Mtd> mtdList = mtdMapper.selectByWlNos(new ArrayList<>(wlNoSet)); List<Mtd> mtdList = mtdMapper.selectByWlNos(new ArrayList<>(wlNoSet));
if (mtdList == null || mtdList.isEmpty()) { if (mtdList == null || mtdList.isEmpty()) {
// 本地没有维护重量体积,也直接返回原始数据
return list; return list;
} }
// 6. 转为 Map<wlNo, Mtd> // 7. 转为 Map<wlNo, Mtd>
Map<String, Mtd> mtdMap = mtdList.stream() Map<String, Mtd> mtdMap = mtdList.stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
Mtd::getWlNo, Mtd::getWlNo,
m -> m, m -> m,
(a, b) -> a // 同 wlNo 只保留一个 (a, b) -> a
)); ));
// 7. 回填到每一条 RkInfo 上 // 8. 回填到每一条 RkInfo 上
for (DeliveryBillVO bill : list) { for (DeliveryBillVO bill : list) {
if (bill.getDetailList() == null) { if (bill.getDetailList() == null) {
continue; continue;
@@ -477,6 +479,7 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
return list; return list;
} }
// ======================== 统计 ======================== // ======================== 统计 ========================
@Override @Override