修改0108
This commit is contained in:
@@ -148,11 +148,10 @@ public class DeliveryOrderController extends BaseController {
|
||||
* 从智慧实物系统拉取待配送出库单据列表
|
||||
*/
|
||||
@GetMapping("/wisdom/rk/list")
|
||||
public AjaxResult listRkFromWisdom() {
|
||||
List<DeliveryBillVO> list = deliveryOrderService.listWisdomRkForDelivery();
|
||||
public AjaxResult listRkFromWisdom(String billNoCk) {
|
||||
List<DeliveryBillVO> list = deliveryOrderService.listWisdomRkForDelivery(billNoCk);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
// ======================== 统计接口 ========================
|
||||
|
||||
/** 总览统计 */
|
||||
|
||||
@@ -26,11 +26,11 @@ public class DeliveryOrder extends BaseEntity {
|
||||
private String orderNo;
|
||||
|
||||
/** rk_info主键ID */
|
||||
@Excel(name = "rk_info主键ID")
|
||||
// @Excel(name = "rk_info主键ID")
|
||||
private Long rkInfoId;
|
||||
|
||||
/** 制单人用户ID */
|
||||
@Excel(name = "制单人ID")
|
||||
// @Excel(name = "制单人ID")
|
||||
private Long makerId;
|
||||
|
||||
/** 制单人用户名(不入库,用于返回给前端) */
|
||||
@@ -45,39 +45,39 @@ public class DeliveryOrder extends BaseEntity {
|
||||
private String receiveProblem;
|
||||
|
||||
/** 出库单据号 */
|
||||
@Excel(name = "出库单据号")
|
||||
// @Excel(name = "出库单据号")
|
||||
private String billNoCk;
|
||||
|
||||
/** 项目描述 */
|
||||
@Excel(name = "项目描述")
|
||||
// @Excel(name = "项目描述")
|
||||
private String xmMs;
|
||||
|
||||
/** 项目号 */
|
||||
@Excel(name = "项目号")
|
||||
// @Excel(name = "项目号")
|
||||
private String xmNo;
|
||||
|
||||
/** 物料号 */
|
||||
@Excel(name = "物料号")
|
||||
// @Excel(name = "物料号")
|
||||
private String wlNo;
|
||||
|
||||
/** 物料描述 */
|
||||
@Excel(name = "物料描述")
|
||||
// @Excel(name = "物料描述")
|
||||
private String wlMs;
|
||||
|
||||
/** 实际入库数量 */
|
||||
@Excel(name = "实际入库数量")
|
||||
// @Excel(name = "实际入库数量")
|
||||
private BigDecimal realQty;
|
||||
|
||||
/** 计量单位 */
|
||||
@Excel(name = "计量单位")
|
||||
// @Excel(name = "计量单位")
|
||||
private String dw;
|
||||
|
||||
/** SAP订单编号 */
|
||||
@Excel(name = "SAP订单编号")
|
||||
// @Excel(name = "SAP订单编号")
|
||||
private String sapNo;
|
||||
|
||||
/** 供应商名称 */
|
||||
@Excel(name = "供应商名称")
|
||||
// @Excel(name = "供应商名称")
|
||||
private String gysMc;
|
||||
|
||||
/** 起始地点名称 */
|
||||
|
||||
@@ -37,8 +37,8 @@ public interface IDeliveryOrderService {
|
||||
/** 详情:按单号查行 */
|
||||
List<DeliveryOrderDetailVO> listByOrderNo(String orderNo);
|
||||
|
||||
/** 从智慧实物系统查询待配送出库单据 */
|
||||
List<DeliveryBillVO> listWisdomRkForDelivery();
|
||||
/** 从智慧实物系统查询待配送出库单据(可按出库单号 billNoCk 过滤) */
|
||||
List<DeliveryBillVO> listWisdomRkForDelivery(String billNoCk);
|
||||
|
||||
// ======================== 统计 ========================
|
||||
|
||||
|
||||
@@ -140,13 +140,19 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int executeBind(DeliveryExecuteBindDTO dto) {
|
||||
|
||||
// 0) 基础校验
|
||||
if (dto == null || StringUtils.isBlank(dto.getOrderNo())) {
|
||||
throw new ServiceException("订单号不能为空");
|
||||
}
|
||||
|
||||
// 1) 校验订单存在(一个单号多行)
|
||||
List<DeliveryOrder> existList = deliveryOrderMapper.selectDeliveryOrderByOrderNo(dto.getOrderNo());
|
||||
if (existList == null || existList.isEmpty()) {
|
||||
throw new ServiceException("配送单不存在:" + dto.getOrderNo());
|
||||
}
|
||||
|
||||
// ====== 从配送单中拿到所有 rk_info_id 列表 ======
|
||||
// ====== 从配送单中拿到所有 rk_info_id 列表(允许为空:手工配送单场景) ======
|
||||
List<Long> rkInfoIdList = existList.stream()
|
||||
.map(DeliveryOrder::getRkInfoId)
|
||||
.filter(Objects::nonNull)
|
||||
@@ -154,9 +160,10 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
.collect(Collectors.toList());
|
||||
|
||||
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()) {
|
||||
throw new ServiceException("附件列表不能为空");
|
||||
@@ -164,8 +171,8 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
|
||||
// 2) 批量插入附件(只传 URL)
|
||||
List<DeliveryAttachment> list = new ArrayList<>();
|
||||
|
||||
String username = getUsername();
|
||||
|
||||
for (DeliveryAttachItemDTO it : dto.getAttachments()) {
|
||||
if (it == null) {
|
||||
continue;
|
||||
@@ -187,6 +194,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
a.setCreateTime(DateUtils.getNowDate());
|
||||
list.add(a);
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
throw new ServiceException("有效附件条目为空");
|
||||
}
|
||||
@@ -197,6 +205,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
patch.setOrderNo(dto.getOrderNo());
|
||||
|
||||
String scene = dto.getScene() == null ? "" : dto.getScene().toUpperCase(Locale.ROOT);
|
||||
|
||||
if ("ORIGIN".equals(scene)) {
|
||||
// 起点:司机信息 + 起点经纬度 + 状态=2(起运/配送中)
|
||||
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.getLat() != null) patch.setOriginLat(BigDecimal.valueOf(dto.getLat()));
|
||||
patch.setOrderStatus("2");
|
||||
|
||||
} else if ("DEST".equals(scene)) {
|
||||
// 终点:终点经纬度 + 费用 + 状态=3(已完成)
|
||||
if (dto.getLng() != null) patch.setDestLng(BigDecimal.valueOf(dto.getLng()));
|
||||
@@ -216,6 +226,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
}
|
||||
patch.setActualFee(dto.getActualFee());
|
||||
}
|
||||
|
||||
if (dto.getTollFee() != null) {
|
||||
if (dto.getTollFee().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new ServiceException("高速费用不能为负数");
|
||||
@@ -241,19 +252,27 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
}
|
||||
|
||||
patch.setOrderStatus("3"); // 已完成
|
||||
} else {
|
||||
// scene 既不是 ORIGIN 也不是 DEST:不强制报错,避免影响“仅绑定附件”的场景
|
||||
// 如果你希望严格校验,可以改为 throw new ServiceException("scene 不合法");
|
||||
log.warn("executeBind 未识别的 scene={},将仅绑定附件并更新已有字段(如有)。orderNo={}", scene, dto.getOrderNo());
|
||||
}
|
||||
|
||||
deliveryOrderMapper.updateDeliveryOrder(patch);
|
||||
|
||||
// 4) ⭐ 如果是 DEST 场景,远程调用 WMS,把这些 rk_info 记录的 is_delivery 改成 3
|
||||
// 4) ⭐ 仅当 DEST 场景且存在 rk_info_id 绑定时,才远程调用 WMS 回写 is_delivery=3
|
||||
if ("DEST".equals(scene)) {
|
||||
|
||||
// 这里已经不再按 billNoCk 整单更新,而是按 rk_info_id 列表更新
|
||||
if (rkInfoIdList != null && !rkInfoIdList.isEmpty()) {
|
||||
boolean ok = updateWmsIsDeliveryByIds(rkInfoIdList, 3);
|
||||
if (!ok) {
|
||||
// 让整个事务回滚,附件 + 配送单状态都撤回
|
||||
throw new ServiceException("回写 WMS 配送状态失败,rk_info_id 列表:" + rkInfoIdList);
|
||||
}
|
||||
} else {
|
||||
// 手工配送单:不回写 WMS
|
||||
log.info("DEST 场景下配送单无 rk_info_id 绑定,跳过 WMS 回写。orderNo={}", dto.getOrderNo());
|
||||
}
|
||||
}
|
||||
|
||||
return list.size();
|
||||
@@ -263,7 +282,7 @@ public class DeliveryAttachmentServiceImpl implements IDeliveryAttachmentService
|
||||
* 远程调用智慧实物管理系统,按 rk_info 主键ID列表更新 is_delivery 状态
|
||||
* 约定请求体结构:
|
||||
* {
|
||||
* "rkInfoIdList": [1, 2, 3],
|
||||
* "ids": [1, 2, 3],
|
||||
* "isDelivery": 3
|
||||
* }
|
||||
*/
|
||||
|
||||
@@ -395,7 +395,7 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
|
||||
* @return List<RkInfo>
|
||||
*/
|
||||
@Override
|
||||
public List<DeliveryBillVO> listWisdomRkForDelivery() {
|
||||
public List<DeliveryBillVO> listWisdomRkForDelivery(String billNoCk) {
|
||||
|
||||
// 1. 远程接口地址
|
||||
String url = wisdomBaseUrl + "/wisdom/stock/delivery/list";
|
||||
@@ -406,7 +406,10 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
|
||||
param.append("&isChuku=1"); // 已出库
|
||||
param.append("&isDelivery=1"); // 需要配送
|
||||
|
||||
// 2. 调用智慧实物系统
|
||||
if (StringUtils.isNotBlank(billNoCk)) {
|
||||
param.append("&billNoCk=").append(billNoCk);
|
||||
}
|
||||
// 3. 调用智慧实物系统
|
||||
String respJson = HttpUtils.sendGet(url, param.toString());
|
||||
if (StringUtils.isEmpty(respJson)) {
|
||||
throw new ServiceException("调用智慧实物接口失败:返回结果为空");
|
||||
@@ -428,10 +431,10 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 3. 反序列化为一对多结构:DeliveryBillVO(detailList 中是 RkInfo)
|
||||
// 4. 反序列化为一对多结构:DeliveryBillVO(detailList 中是 RkInfo)
|
||||
List<DeliveryBillVO> list = data.toJavaList(DeliveryBillVO.class);
|
||||
|
||||
// 4. 收集所有 wlNo
|
||||
// 5. 收集所有 wlNo
|
||||
Set<String> wlNoSet = list.stream()
|
||||
.filter(bill -> bill.getDetailList() != null && !bill.getDetailList().isEmpty())
|
||||
.flatMap(bill -> bill.getDetailList().stream())
|
||||
@@ -443,22 +446,21 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
|
||||
return list;
|
||||
}
|
||||
|
||||
// 5. 一次性查询本地 delivery_mtd
|
||||
// 6. 一次性查询本地 delivery_mtd
|
||||
List<Mtd> mtdList = mtdMapper.selectByWlNos(new ArrayList<>(wlNoSet));
|
||||
if (mtdList == null || mtdList.isEmpty()) {
|
||||
// 本地没有维护重量体积,也直接返回原始数据
|
||||
return list;
|
||||
}
|
||||
|
||||
// 6. 转为 Map<wlNo, Mtd>
|
||||
// 7. 转为 Map<wlNo, Mtd>
|
||||
Map<String, Mtd> mtdMap = mtdList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
Mtd::getWlNo,
|
||||
m -> m,
|
||||
(a, b) -> a // 同 wlNo 只保留一个
|
||||
(a, b) -> a
|
||||
));
|
||||
|
||||
// 7. 回填到每一条 RkInfo 上
|
||||
// 8. 回填到每一条 RkInfo 上
|
||||
for (DeliveryBillVO bill : list) {
|
||||
if (bill.getDetailList() == null) {
|
||||
continue;
|
||||
@@ -477,6 +479,7 @@ public class DeliveryOrderServiceImpl implements IDeliveryOrderService
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
// ======================== 统计 ========================
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user