From fd49d392900e98fc6cc9cc7de7753ce2495f8764 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Mon, 3 Nov 2025 13:11:13 +0800 Subject: [PATCH] =?UTF-8?q?2025-11-03=20pda=E8=B0=83=E6=95=B4=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E3=80=81=E6=9F=A5=E8=AF=A2=E3=80=81=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=88=E9=87=87=E8=B4=AD=E9=80=80=E8=B4=A7?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PurchaseReturnController.java | 82 ++++--- .../dao/PurchaseReturnMapper.java | 15 ++ .../service/PurchaseReturnService.java | 43 ++-- .../impl/PurchaseReturnServiceImpl.java | 203 +++++++++++++----- .../purchaseReturn/PurchaseReturnMapper.xml | 17 ++ 5 files changed, 270 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java b/src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java index 4bf24ef..3725835 100644 --- a/src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java +++ b/src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java @@ -89,7 +89,7 @@ public class PurchaseReturnController extends AbstractController { } /** - * 验证标签与采购退货单是否匹配,并检查库存 + * 验证标签(通过存储过程) */ @PostMapping("/validateLabelWithReturn") @ApiOperation("验证标签与退货单匹配") @@ -97,9 +97,11 @@ public class PurchaseReturnController extends AbstractController { try { String labelCode = (String) params.get("labelCode"); String returnNo = (String) params.get("returnNo"); - String warehouseId = (String) params.get("warehouseId"); + String relatedNo = (String) params.get("relatedNo"); + String relatedLineNo = (String) params.get("relatedLineNo"); String site = (String) params.get("site"); String buNo = (String) params.get("buNo"); + String operationType = (String) params.get("operationType"); if (labelCode == null || labelCode.trim().isEmpty()) { return R.error("标签条码不能为空"); @@ -109,8 +111,15 @@ public class PurchaseReturnController extends AbstractController { return R.error("退货单号不能为空"); } + if (operationType == null || operationType.trim().isEmpty()) { + operationType = "I"; // 默认为添加 + } + + // 获取当前登录用户 + String userName = getUser().getUsername(); + Map result = purchaseReturnService.validateLabelWithReturn( - labelCode, returnNo, warehouseId, site, buNo); + site, buNo, returnNo, relatedNo, relatedLineNo, labelCode, operationType, userName); return R.ok().put("data", result); } catch (Exception e) { @@ -120,12 +129,7 @@ public class PurchaseReturnController extends AbstractController { } /** - * 确认采购退货 - * 系统逻辑: - * 1. 更新库存表中的标签状态 - * 2. 更改return_notification_head表中的单据状态为"已退货" - * 3. 生成WMS退货记录:Transheader... - * 4. 异步调用ERP接口回传数据 + * 确认采购退货(通过存储过程) */ @PostMapping("/confirmPurchaseReturn") @ApiOperation("确认采购退货") @@ -134,27 +138,22 @@ public class PurchaseReturnController extends AbstractController { String site = (String) params.get("site"); String buNo = (String) params.get("buNo"); String returnNo = (String) params.get("returnNo"); - String warehouseId = (String) params.get("warehouseId"); - List> labels = (List>) params.get("labels"); + String relatedNo = (String) params.get("relatedNo"); + String relatedLineNo = (String) params.get("relatedLineNo"); + String locationCode = (String) params.get("locationCode"); if (returnNo == null || returnNo.trim().isEmpty()) { return R.error("退货单号不能为空"); } - if (warehouseId == null || warehouseId.trim().isEmpty()) { - return R.error("仓库ID不能为空"); - } - if (labels == null || labels.isEmpty()) { - return R.error("标签列表不能为空"); + if (locationCode == null || locationCode.trim().isEmpty()) { + return R.error("库位号不能为空"); } - // 验证标签数据完整性 - for (Map label : labels) { - String labelCode = (String) label.get("labelCode"); - if (labelCode == null || labelCode.trim().isEmpty()) { - return R.error("标签条码不能为空"); - } - } - boolean success = purchaseReturnService.confirmPurchaseReturn(site, buNo, returnNo, warehouseId, labels); + // 获取当前登录用户 + String userName = getUser().getUsername(); + + boolean success = purchaseReturnService.confirmPurchaseReturn( + site, buNo, returnNo, relatedNo, relatedLineNo, locationCode, userName); if (success) { return R.ok("退货成功"); } else { @@ -239,4 +238,39 @@ public class PurchaseReturnController extends AbstractController { return R.error("获取明细卡片列表失败: " + e.getMessage()); } } + + /** + * 获取已扫描标签列表(从缓存表) + */ + @PostMapping("/getScannedLabelList") + @ApiOperation("获取已扫描标签列表") + public R getScannedLabelList(@RequestBody Map params) { + try { + String site = (String) params.get("site"); + String buNo = (String) params.get("buNo"); + String returnNo = (String) params.get("returnNo"); + String relatedNo = (String) params.get("relatedNo"); + String relatedLineNo = (String) params.get("relatedLineNo"); + + if (site == null || site.trim().isEmpty()) { + return R.error("站点不能为空"); + } + + if (buNo == null || buNo.trim().isEmpty()) { + return R.error("业务单元不能为空"); + } + + if (returnNo == null || returnNo.trim().isEmpty()) { + return R.error("退货单号不能为空"); + } + + List> labelList = purchaseReturnService.getScannedLabelList( + site, buNo, returnNo, relatedNo, relatedLineNo); + + return R.ok().put("data", labelList); + } catch (Exception e) { + logger.error("获取已扫描标签列表失败", e); + return R.error("获取已扫描标签列表失败: " + e.getMessage()); + } + } } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java b/src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java index 9652cd6..7527e04 100644 --- a/src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java +++ b/src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java @@ -116,4 +116,19 @@ public interface PurchaseReturnMapper extends BaseMapper { @Param("warehouseId") String warehouseId, @Param("searchCode") String searchCode, @Param("userName") String userName); + + /** + * 获取已扫描标签列表(从缓存表) + * @param site 站点 + * @param buNo 业务单元 + * @param returnNo 退货单号 + * @param relatedNo 关联单号 + * @param relatedLineNo 关联单行号 + * @return 已扫描标签列表 + */ + List> getScannedLabelList(@Param("site") String site, + @Param("buNo") String buNo, + @Param("returnNo") String returnNo, + @Param("relatedNo") String relatedNo, + @Param("relatedLineNo") String relatedLineNo); } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java b/src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java index c2851fc..7f0f395 100644 --- a/src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java +++ b/src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java @@ -32,32 +32,35 @@ public interface PurchaseReturnService { Map getReturnDetails(String returnNo, String buNo, String warehouseId, String site); /** - * 验证标签与采购退货单是否匹配,并检查库存 - * 从库存表验证标签信息 - * @param labelCode 标签条码 - * @param returnNo 退货单号 - * @param warehouseId 仓库ID + * 验证标签(通过存储过程) * @param site 站点 * @param buNo 业务单元 + * @param returnNo 退货单号 + * @param relatedNo 关联单号 + * @param relatedLineNo 关联单行号 + * @param labelCode 标签条码 + * @param operationType 操作类型 I-添加 D-移除 + * @param userName 当前登录人 * @return 标签信息 */ - Map validateLabelWithReturn(String labelCode, String returnNo, - String warehouseId, String site, String buNo); + Map validateLabelWithReturn(String site, String buNo, String returnNo, + String relatedNo, String relatedLineNo, + String labelCode, String operationType, String userName); /** - * 确认采购退货 - * 1. 更新库存表中的标签状态 - * 2. 更新return_notification_head表状态 - * 3. 生成退货事务记录 + * 确认采购退货(通过存储过程) * @param site 站点 * @param buNo 业务单元 * @param returnNo 退货单号 - * @param warehouseId 仓库ID - * @param labels 标签列表 + * @param relatedNo 关联单号 + * @param relatedLineNo 关联单行号 + * @param locationCode 库位号 + * @param userName 当前登录人 * @return 处理结果 */ boolean confirmPurchaseReturn(String site, String buNo, String returnNo, - String warehouseId, List> labels); + String relatedNo, String relatedLineNo, + String locationCode, String userName); /** * 获取采购退货单物料清单 @@ -82,4 +85,16 @@ public interface PurchaseReturnService { */ List> getReturnDetailCards(String site, String buNo, String returnNo, String warehouseId, String searchCode, String userName); + + /** + * 获取已扫描标签列表(从缓存表) + * @param site 站点 + * @param buNo 业务单元 + * @param returnNo 退货单号 + * @param relatedNo 关联单号 + * @param relatedLineNo 关联单行号 + * @return 已扫描标签列表 + */ + List> getScannedLabelList(String site, String buNo, String returnNo, + String relatedNo, String relatedLineNo); } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java b/src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java index 41e7c99..056a26f 100644 --- a/src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java +++ b/src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java @@ -2,7 +2,7 @@ package com.gaotao.modules.purchaseReturn.service.impl; import com.gaotao.modules.purchaseReturn.dao.PurchaseReturnMapper; import com.gaotao.modules.purchaseReturn.service.PurchaseReturnService; -import com.gaotao.modules.inventoryStock.service.InventoryStockService; +import com.gaotao.modules.schedule.mapper.ProcedureMapper; import com.gaotao.modules.sys.entity.SysUserEntity; import com.gaotao.modules.trans.entity.TransDetail; import com.gaotao.modules.trans.entity.TransDetailDto; @@ -29,9 +29,6 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService { @Autowired private PurchaseReturnMapper purchaseReturnMapper; - @Autowired - private InventoryStockService inventoryStockService; - @Autowired private TransHeaderService transHeaderService; @@ -41,6 +38,9 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService { @Autowired private TransDetailSubService transDetailSubService; + @Autowired + private ProcedureMapper procedureMapper; + @Override public List> getReturnList(String site, String warehouseId, String searchCode, String status) { SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); @@ -53,67 +53,144 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService { } @Override - public Map validateLabelWithReturn(String labelCode, String returnNo, String warehouseId, String site, String buNo) { - Map result = purchaseReturnMapper.validateLabelWithReturn(labelCode, returnNo, warehouseId, site, buNo); - if (result == null || result.isEmpty()) { - throw new RuntimeException("该标签与退货单不符,请检查"); - } - String status = (String) result.get("status"); - if (!"在库".equals(status)) { - throw new RuntimeException("该标签状态不允许退货"); + public Map validateLabelWithReturn(String site, String buNo, String returnNo, + String relatedNo, String relatedLineNo, + String labelCode, String operationType, String userName) { + logger.info("验证采购退货标签,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}, 标签: {}, 操作类型: {}", + site, buNo, returnNo, relatedNo, relatedLineNo, labelCode, operationType); + + try { + // 调用存储过程 GetScanLabelVerification + List params = new ArrayList<>(); + params.add(site); // 参数1: site + params.add(buNo); // 参数2: buNo + params.add(returnNo); // 参数3: 退货单号 + params.add(relatedNo); // 参数4: 关联单号 + params.add(relatedLineNo); // 参数5: 关联单行号 + params.add(""); // 参数6: 空字符串 + params.add(""); // 参数7: 空字符串 + params.add(labelCode); // 参数8: 扫描的标签条码 + params.add(""); // 参数9: 空字符串 + params.add("采购退货"); // 参数10: 采购退货 + params.add(operationType); // 参数11: 操作类型 I或D + params.add(userName); // 参数12: 当前登陆人 + + List> resultList = procedureMapper.getProcedureData("GetScanLabelVerification", params); + + // 判断返回结果 + if (resultList == null || resultList.isEmpty()) { + throw new RuntimeException("存储过程调用失败"); + } + + Map result = resultList.get(0); + String code = String.valueOf(result.get("code")); + + if (!"200".equals(code)) { + String msg = String.valueOf(result.get("message")); + throw new RuntimeException(msg); + } + + logger.info("标签验证成功,标签: {}, 操作类型: {}", labelCode, operationType); + return result; + } catch (Exception e) { + logger.error("标签验证失败,标签: {}, 错误: {}", labelCode, e.getMessage(), e); + throw new RuntimeException(e.getMessage(), e); } - return result; } @Override @Transactional(rollbackFor = Exception.class) - public boolean confirmPurchaseReturn(String site, String buNo, String returnNo, String warehouseId, List> labels) { - logger.info("开始确认采购退货,退货单号: {}, 仓库ID: {}, 标签数量: {}", returnNo, warehouseId, labels.size()); + public boolean confirmPurchaseReturn(String site, String buNo, String returnNo, + String relatedNo, String relatedLineNo, + String locationCode, String userName) { + logger.info("开始确认采购退货,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}, 库位: {}", + site, buNo, returnNo, relatedNo, relatedLineNo, locationCode); + try { - // 1. 更新库存表中的标签状态为"已退货" - List labelCodes = new ArrayList<>(); - for (Map label : labels) { - labelCodes.add((String) label.get("labelCode")); - } - - int updatedLabels = purchaseReturnMapper.updateInventoryStatus(labelCodes, "已退货", site, buNo); - if (updatedLabels != labelCodes.size()) { - throw new RuntimeException("部分标签状态更新失败"); + // 调用存储过程 GetSaveLabelVerification + List params = new ArrayList<>(); + params.add(site); // 参数1: site + params.add(buNo); // 参数2: buNo + params.add(returnNo); // 参数3: 退货单号 + params.add(relatedNo); // 参数4: 关联单号 + params.add(relatedLineNo); // 参数5: 关联单行号 + params.add(""); // 参数6: 空字符串 + params.add(""); // 参数7: 空字符串 + params.add(locationCode); // 参数8: 库位 + params.add("采购退货"); // 参数9: 采购退货 + params.add(userName); // 参数10: 当前登陆人 + + List> resultList = procedureMapper.getProcedureData("GetSaveLabelVerification", params); + + // 判断返回结果 + if (resultList == null || resultList.isEmpty()) { + throw new RuntimeException("存储过程调用失败"); } - - // 2. 检查是否所有标签都已退货,决定是否更新退货单状态 - Map labelStats = purchaseReturnMapper.checkAllLabelsReturned(returnNo, site, buNo); - if (labelStats != null) { - Integer totalLabels = (Integer) labelStats.get("totalLabels"); - Integer returnedLabels = (Integer) labelStats.get("returnedLabels"); - - logger.info("退货单 {} 标签统计: 总标签数={}, 已退货标签数={}", returnNo, totalLabels, returnedLabels); - - // 只有当所有标签都已退货时,才更新退货单状态为"已完成" - if (totalLabels != null && returnedLabels != null && totalLabels.equals(returnedLabels) && totalLabels > 0) { - int updatedHead = purchaseReturnMapper.updateReturnStatus(returnNo, "已完成", site, buNo); - if (updatedHead > 0) { - logger.info("退货单 {} 所有标签已退货,状态更新为已完成", returnNo); - } - } else { - logger.info("退货单 {} 还有标签未退货,保持待退货状态", returnNo); - } + + Map result = resultList.get(0); + String code = String.valueOf(result.get("code")); + + if (!"200".equals(code)) { + String msg = String.valueOf(result.get("message")); + throw new RuntimeException(msg); } - - // 3. 生成退货事务记录 - generateReturnTransaction(returnNo, warehouseId, labels, site, buNo); - - // 4. 异步调用ERP接口(这里可以发送消息到队列) - //asyncCallErpInterface(returnNo, labels); - - logger.info("采购退货确认完成,退货单号: {}", returnNo); + + logger.info("采购退货确认成功,退货单号: {}", returnNo); return true; } catch (Exception e) { - logger.error("采购退货确认失败,退货单号: {}, 错误信息: {}", returnNo, e.getMessage(), e); - throw new RuntimeException("退货确认失败: " + e.getMessage(), e); + logger.error("采购退货确认失败,退货单号: {}, 错误: {}", returnNo, e.getMessage(), e); + throw new RuntimeException(e.getMessage(), e); } } + // 保留原有的实现方法作为注释,以防需要 + // private boolean confirmPurchaseReturnOld(String site, String buNo, String returnNo, String warehouseId, List> labels) { + // logger.info("开始确认采购退货(旧方法),退货单号: {}, 仓库ID: {}, 标签数量: {}", returnNo, warehouseId, labels.size()); + // try { + // // 1. 更新库存表中的标签状态为"已退货" + // List labelCodes = new ArrayList<>(); + // for (Map label : labels) { + // labelCodes.add((String) label.get("labelCode")); + // } + // + // int updatedLabels = purchaseReturnMapper.updateInventoryStatus(labelCodes, "已退货", site, buNo); + // if (updatedLabels != labelCodes.size()) { + // throw new RuntimeException("部分标签状态更新失败"); + // } + // + // // 2. 检查是否所有标签都已退货,决定是否更新退货单状态 + // Map labelStats = purchaseReturnMapper.checkAllLabelsReturned(returnNo, site, buNo); + // if (labelStats != null) { + // Integer totalLabels = (Integer) labelStats.get("totalLabels"); + // Integer returnedLabels = (Integer) labelStats.get("returnedLabels"); + // + // logger.info("退货单 {} 标签统计: 总标签数={}, 已退货标签数={}", returnNo, totalLabels, returnedLabels); + // + // // 只有当所有标签都已退货时,才更新退货单状态为"已完成" + // if (totalLabels != null && returnedLabels != null && totalLabels.equals(returnedLabels) && totalLabels > 0) { + // int updatedHead = purchaseReturnMapper.updateReturnStatus(returnNo, "已完成", site, buNo); + // if (updatedHead > 0) { + // logger.info("退货单 {} 所有标签已退货,状态更新为已完成", returnNo); + // } + // } else { + // logger.info("退货单 {} 还有标签未退货,保持待退货状态", returnNo); + // } + // } + // + // // 3. 生成退货事务记录 + // generateReturnTransaction(returnNo, warehouseId, labels, site, buNo); + // + // // 4. 异步调用ERP接口(这里可以发送消息到队列) + // //asyncCallErpInterface(returnNo, labels); + // + // logger.info("采购退货确认完成,退货单号: {}", returnNo); + // return true; + // } catch (Exception e) { + // logger.error("采购退货确认失败,退货单号: {}, 错误信息: {}", returnNo, e.getMessage(), e); + // throw new RuntimeException("退货确认失败: " + e.getMessage(), e); + // } + // } + @Override public List> getMaterialList(String site, String buNo, String returnNo) { logger.info("获取采购退货物料清单,站点: {}, 业务单元: {}, 退货单号: {}", site, buNo, returnNo); @@ -296,4 +373,26 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService { } } + @Override + public List> getScannedLabelList(String site, String buNo, String returnNo, + String relatedNo, String relatedLineNo) { + logger.info("获取已扫描标签列表,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}", + site, buNo, returnNo, relatedNo, relatedLineNo); + + try { + List> labelList = purchaseReturnMapper.getScannedLabelList( + site, buNo, returnNo, relatedNo, relatedLineNo); + + if (labelList == null) { + labelList = new ArrayList<>(); + } + + logger.info("获取已扫描标签列表成功,共 {} 条记录", labelList.size()); + return labelList; + } catch (Exception e) { + logger.error("获取已扫描标签列表失败,错误: {}", e.getMessage(), e); + throw new RuntimeException("获取已扫描标签列表失败: " + e.getMessage(), e); + } + } + } diff --git a/src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml b/src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml index 7581ab8..0ca655a 100644 --- a/src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml +++ b/src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml @@ -183,4 +183,21 @@ ORDER BY h.required_outbound_date DESC + + +