diff --git a/src/main/java/com/gaotao/modules/salesReturn/controller/SalesReturnController.java b/src/main/java/com/gaotao/modules/salesReturn/controller/SalesReturnController.java index 707c77d..d21d7d8 100644 --- a/src/main/java/com/gaotao/modules/salesReturn/controller/SalesReturnController.java +++ b/src/main/java/com/gaotao/modules/salesReturn/controller/SalesReturnController.java @@ -84,7 +84,7 @@ public class SalesReturnController extends AbstractController { } /** - * 验证标签是否存在于库存中且状态为出库状态 + * 验证标签(通过存储过程) */ @PostMapping("validateLabelWithSalesReturn") public R validateLabelWithSalesReturn(@RequestBody Map params) { @@ -92,11 +92,26 @@ public class SalesReturnController extends AbstractController { String labelCode = (String) params.get("labelCode"); String site = (String) params.get("site"); String buNo = (String) params.get("buNo"); + String returnNo = (String) params.get("returnNo"); + String operationType = (String) params.get("operationType"); + if (labelCode == null || labelCode.trim().isEmpty()) { return R.error("标签条码不能为空"); } - List> resultList = salesReturnService.validateLabelInInventory(labelCode, site, buNo); - return R.ok().put("data", resultList); + if (returnNo == null || returnNo.trim().isEmpty()) { + return R.error("退货单号不能为空"); + } + if (operationType == null || operationType.trim().isEmpty()) { + operationType = "I"; // 默认为添加 + } + + // 获取当前登录用户 + String userName = getUser().getUsername(); + + // 调用存储过程验证标签 + Map result = salesReturnService.validateLabelWithSalesReturn( + site, buNo, returnNo, labelCode, operationType, userName); + return R.ok().put("data", result); } catch (Exception e) { logger.error("标签验证失败", e); return R.error(e.getMessage()); @@ -104,13 +119,7 @@ public class SalesReturnController extends AbstractController { } /** - * 确认销售退货入库 - * 系统逻辑: - * 1. 更新po_order_roll_no表中的标签状态为"已入库" - * 2. 更改InboundNotificationHead表中的单据状态、入库状态为"已入库" - * 3. 在WMS库存表中插入标签数据,状态为"待入" - * 4. 生成WMS入库记录:Transheader... - * 5. 异步调用ERP接口回传数据 + * 确认销售退货入库(通过存储过程) */ @PostMapping("confirmSalesReturnStorage") public R confirmSalesReturnStorage(@RequestBody Map params) { @@ -119,24 +128,19 @@ public class SalesReturnController extends AbstractController { String locationCode = (String) params.get("locationCode"); String site = (String) params.get("site"); String buNo = (String) params.get("buNo"); - List> labels = (List>) params.get("labels"); + if (returnNo == null || returnNo.trim().isEmpty()) { return R.error("退货单号不能为空"); } if (locationCode == null || locationCode.trim().isEmpty()) { return R.error("库位号不能为空"); } - if (labels == null || labels.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 = salesReturnService.confirmSalesReturnStorage(returnNo, locationCode, labels, site, buNo); + + // 获取当前登录用户 + String userName = getUser().getUsername(); + + boolean success = salesReturnService.confirmSalesReturnStorage( + site, buNo, returnNo, locationCode, userName); if (success) { return R.ok("退货入库成功"); } else { @@ -179,4 +183,35 @@ public class SalesReturnController extends AbstractController { return R.error("获取物料清单失败: " + e.getMessage()); } } + + /** + * 获取已扫描标签列表(从缓存表) + */ + @PostMapping("getScannedLabelList") + 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"); + + 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 = salesReturnService.getScannedLabelList(site, buNo, returnNo); + + 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/salesReturn/dao/SalesReturnMapper.java b/src/main/java/com/gaotao/modules/salesReturn/dao/SalesReturnMapper.java index 706fbd5..8ad50b2 100644 --- a/src/main/java/com/gaotao/modules/salesReturn/dao/SalesReturnMapper.java +++ b/src/main/java/com/gaotao/modules/salesReturn/dao/SalesReturnMapper.java @@ -80,4 +80,15 @@ public interface SalesReturnMapper { @Param("buNo") String buNo); void updateInventoryStockStatus(InventoryStock inventoryStock); + + /** + * 获取已扫描标签列表(从缓存表) + * @param site 站点 + * @param buNo 业务单元 + * @param returnNo 退货单号 + * @return 已扫描标签列表 + */ + List> getScannedLabelList(@Param("site") String site, + @Param("buNo") String buNo, + @Param("returnNo") String returnNo); } diff --git a/src/main/java/com/gaotao/modules/salesReturn/service/SalesReturnService.java b/src/main/java/com/gaotao/modules/salesReturn/service/SalesReturnService.java index 82d10db..e9a4e7e 100644 --- a/src/main/java/com/gaotao/modules/salesReturn/service/SalesReturnService.java +++ b/src/main/java/com/gaotao/modules/salesReturn/service/SalesReturnService.java @@ -27,25 +27,27 @@ public interface SalesReturnService { Map getSalesReturnDetails(String returnNo, String warehouseId, String site, String buNo); /** - * 验证标签是否存在于库存中且状态为出库状态 - * @param labelCode 标签条码 + * 验证标签(通过存储过程) * @param site 站点 - * @return 标签信息列表 + * @param buNo 业务单元 + * @param returnNo 退货单号 + * @param labelCode 标签条码 + * @param operationType 操作类型 I-添加 D-移除 + * @param userName 当前登录人 + * @return 标签信息 */ - List> validateLabelInInventory(String labelCode, String site, String buNo); + Map validateLabelWithSalesReturn(String site, String buNo, String returnNo, String labelCode, String operationType, String userName); /** - * 确认销售退货入库 - * @param returnNo 退货单号 - * @param partNo 物料编码 - * @param warehouseId 仓库ID - * @param locationCode 库位号 - * @param labels 标签列表 + * 确认销售退货入库(通过存储过程) * @param site 站点 * @param buNo 业务单元 + * @param returnNo 退货单号 + * @param locationCode 库位号 + * @param userName 当前登录人 * @return 处理结果 */ - boolean confirmSalesReturnStorage(String returnNo, String locationCode, List> labels, String site, String buNo); + boolean confirmSalesReturnStorage(String site, String buNo, String returnNo, String locationCode, String userName); /** * 获取销售退货物料清单 @@ -55,4 +57,13 @@ public interface SalesReturnService { * @return 物料清单 */ List> getSalesReturnMaterialList(String site, String buNo, String returnNo); + + /** + * 获取已扫描标签列表(从缓存表) + * @param site 站点 + * @param buNo 业务单元 + * @param returnNo 退货单号 + * @return 已扫描标签列表 + */ + List> getScannedLabelList(String site, String buNo, String returnNo); } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/salesReturn/service/impl/SalesReturnServiceImpl.java b/src/main/java/com/gaotao/modules/salesReturn/service/impl/SalesReturnServiceImpl.java index 9fc43a8..18bb582 100644 --- a/src/main/java/com/gaotao/modules/salesReturn/service/impl/SalesReturnServiceImpl.java +++ b/src/main/java/com/gaotao/modules/salesReturn/service/impl/SalesReturnServiceImpl.java @@ -6,6 +6,7 @@ import com.gaotao.modules.salesReturn.dao.SalesReturnMapper; import com.gaotao.modules.salesReturn.service.SalesReturnService; import com.gaotao.modules.inventoryStock.entity.InventoryStock; 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; @@ -53,6 +54,9 @@ public class SalesReturnServiceImpl implements SalesReturnService { @Autowired private ProductionInboundMapper productionInboundMapper; + @Autowired + private ProcedureMapper procedureMapper; + @Override public List> getSalesReturnList(String site, String warehouseId, String searchCode, String status) { SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); @@ -65,93 +69,89 @@ public class SalesReturnServiceImpl implements SalesReturnService { } @Override - public List> validateLabelInInventory(String labelCode, String site, String buNo) { - List> resultList = salesReturnMapper.validateLabelInInventory(labelCode, site, buNo); - if (resultList == null || resultList.isEmpty()) { - throw new RuntimeException("该标签不存在于库存中,无法退货"); - } + public Map validateLabelWithSalesReturn(String site, String buNo, String returnNo, String labelCode, String operationType, String userName) { + logger.info("验证销售退货标签,site: {}, buNo: {}, 退货单号: {}, 标签: {}, 操作类型: {}", + site, buNo, returnNo, labelCode, operationType); - // 对每个记录进行校验 - for (Map result : resultList) { - String statusTb = (String) result.get("statusTb"); - String status = (String) result.get("status"); - if (!"E".equals(statusTb)) { - throw new RuntimeException("该标签状态不允许退货,当前状态: " + status); + try { + // 调用存储过程 GetScanLabelVerification + List params = new ArrayList<>(); + params.add(site); // 参数1: site + params.add(buNo); // 参数2: buNo + params.add(returnNo); // 参数3: 退货单号 + params.add(""); // 参数4: 空字符串 + params.add(""); // 参数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 resultList; } @Override @Transactional(rollbackFor = Exception.class) - public boolean confirmSalesReturnStorage(String returnNo, String locationCode, List> labels, String site, String buNo) { - logger.info("开始确认销售退货入库,退货单号: {}, 库位号: {}, 标签数量: {}", returnNo, locationCode, labels.size()); + public boolean confirmSalesReturnStorage(String site, String buNo, String returnNo, String locationCode, String userName) { + logger.info("开始确认销售退货入库,site: {}, buNo: {}, 退货单号: {}, 库位号: {}", + site, buNo, returnNo, locationCode); + try { - // 1. 验证库位是否存在且可用 - Map locationInfo = productionInboundMapper.validateLocation(locationCode, site); - if (locationInfo == null || locationInfo.isEmpty()) { - throw new RuntimeException("该库位不存在,请检查"); + // 调用存储过程 GetSaveLabelVerification + List params = new ArrayList<>(); + params.add(site); // 参数1: site + params.add(buNo); // 参数2: buNo + params.add(returnNo); // 参数3: 退货单号 + params.add(""); // 参数4: 空字符串 + params.add(""); // 参数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("存储过程调用失败"); } - - String locationStatus = (String) locationInfo.get("status"); - if (!"Y".equals(locationStatus)) { - throw new RuntimeException("该库位已停用,请检查"); - } - - // 根据库位获取实际的仓库ID - String warehouseId = (String) locationInfo.get("warehouseId"); - if (warehouseId == null && warehouseId.trim().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); } - - // 1. 提取标签条码列表 - List labelCodes = labels.stream() - .map(label -> (String) label.get("labelCode")) - .collect(Collectors.toList()); - - // 2. 验证所有标签都存在于库存中且状态为出库状态 - for (Map label : labels) { - String labelCode = (String) label.get("labelCode"); - List> inventoryInfoList = salesReturnMapper.validateLabelInInventory2(labelCode, site, buNo); - if (inventoryInfoList == null || inventoryInfoList.isEmpty()) { - throw new RuntimeException("标签 " + labelCode + " 不存在于库存中"); - } - - // 检查是否有符合条件的记录 - boolean hasValidRecord = false; - for (Map inventoryInfo : inventoryInfoList) { - if ("E".equals(inventoryInfo.get("statusTb"))) { - hasValidRecord = true; - break; - } - } - - if (!hasValidRecord) { - throw new RuntimeException("标签 " + labelCode + " 不符合退货条件"); - } - } - -// // 3. 更新入库单状态为"已入库" -// int updatedHead = headMapper.updateInboundStatus(returnNo, "已入库", site, buNo); -// if (updatedHead == 0) { -// throw new RuntimeException("入库单状态更新失败"); -// } - - // 4. 插入库存数据 - insertInventoryStock(returnNo, warehouseId, locationCode, labels, site, buNo); - - // 4. 生成退货入库事务记录 - generateReturnTransaction(returnNo, warehouseId, locationCode, labels, site, buNo); - - // 6. 异步调用ERP接口(这里可以发送消息到队列) - //asyncCallErpInterface(returnNo, partNo, 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); } } @@ -302,6 +302,25 @@ public class SalesReturnServiceImpl implements SalesReturnService { } } + @Override + public List> getScannedLabelList(String site, String buNo, String returnNo) { + logger.info("获取已扫描标签列表,site: {}, buNo: {}, 退货单号: {}", site, buNo, returnNo); + + try { + List> labelList = salesReturnMapper.getScannedLabelList(site, buNo, returnNo); + + 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/salesReturn/SalesReturnMapper.xml b/src/main/resources/mapper/salesReturn/SalesReturnMapper.xml index 76cebc1..eabae0c 100644 --- a/src/main/resources/mapper/salesReturn/SalesReturnMapper.xml +++ b/src/main/resources/mapper/salesReturn/SalesReturnMapper.xml @@ -155,4 +155,19 @@ #{item} + + +