From ae29cbb6890a8525c667cd54833d2f700a90e1b6 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Sat, 28 Feb 2026 10:16:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(wms):=20=E6=96=B0=E5=A2=9E=E9=92=A2?= =?UTF-8?q?=E5=8D=B7=E9=80=80=E8=B4=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在IWmsMaterialCoilService接口中添加returnCoil方法定义 - 在WmsMaterialCoilController控制器中新增退货接口映射 - 在WmsMaterialCoilServiceImpl实现类中实现完整的退货逻辑 - 实现将原钢卷转为历史数据并创建新钢卷记录的功能 - 实现退货仓查找及仓库状态更新机制 - 实现二维码内容更新以记录退货操作步骤 - 添加退货操作的权限验证和数据校验机制 --- .../controller/WmsMaterialCoilController.java | 19 ++++ .../klp/service/IWmsMaterialCoilService.java | 9 ++ .../impl/WmsMaterialCoilServiceImpl.java | 104 ++++++++++++++++++ 3 files changed, 132 insertions(+) diff --git a/klp-wms/src/main/java/com/klp/controller/WmsMaterialCoilController.java b/klp-wms/src/main/java/com/klp/controller/WmsMaterialCoilController.java index 22737278..f402365a 100644 --- a/klp-wms/src/main/java/com/klp/controller/WmsMaterialCoilController.java +++ b/klp-wms/src/main/java/com/klp/controller/WmsMaterialCoilController.java @@ -422,6 +422,25 @@ public class WmsMaterialCoilController extends BaseController { } } + /** + * 钢卷退货操作 + * 将钢卷退货到退货仓,创建新钢卷记录,将原钢卷设置为历史钢卷 + */ + @Log(title = "钢卷物料表-退货", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PostMapping("/return") + public R returnCoil( + @NotNull(message = "钢卷ID不能为空") + @RequestParam Long coilId) { + + try { + WmsMaterialCoilVo result = iWmsMaterialCoilService.returnCoil(coilId); + return R.ok(result); + } catch (RuntimeException e) { + return R.fail("退货失败:" + e.getMessage()); + } + } + } diff --git a/klp-wms/src/main/java/com/klp/service/IWmsMaterialCoilService.java b/klp-wms/src/main/java/com/klp/service/IWmsMaterialCoilService.java index e21263a1..aa96df9c 100644 --- a/klp-wms/src/main/java/com/klp/service/IWmsMaterialCoilService.java +++ b/klp-wms/src/main/java/com/klp/service/IWmsMaterialCoilService.java @@ -213,5 +213,14 @@ public interface IWmsMaterialCoilService { Map completeSpecialSplit(@NotNull(message = "待操作记录ID不能为空") Long pendingActionId); Map cancelSpecialSplit(@NotNull(message = "待操作记录ID不能为空") Long pendingActionId); + + /** + * 钢卷退货操作 + * 将钢卷退货到退货仓,创建新钢卷记录,将原钢卷设置为历史钢卷 + * + * @param coilId 原钢卷ID + * @return 退货后的新钢卷信息 + */ + WmsMaterialCoilVo returnCoil(@NotNull(message = "钢卷ID不能为空") Long coilId); } diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java index 032e9ee2..9aeaa1dc 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsMaterialCoilServiceImpl.java @@ -3648,7 +3648,111 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService { return result; } + /** + * 钢卷退货操作 + * 将钢卷退货到退货仓,创建新钢卷记录,将原钢卷设置为历史钢卷 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public WmsMaterialCoilVo returnCoil(Long coilId) { + if (coilId == null) { + throw new RuntimeException("钢卷ID不能为空"); + } + validateCoilOperationPermission(coilId, "退货"); + + WmsMaterialCoil oldCoil = baseMapper.selectById(coilId); + if (oldCoil == null) { + throw new RuntimeException("原钢卷不存在"); + } + + if (oldCoil.getDataType() == 0) { + throw new RuntimeException("当前钢卷是历史钢卷"); + } + + WmsWarehouseBo warehouseBo = new WmsWarehouseBo(); + warehouseBo.setWarehouseName("退货仓"); + List warehouseList = warehouseService.queryList(warehouseBo); + if (warehouseList == null || warehouseList.isEmpty()) { + throw new RuntimeException("退货仓不存在,请先配置退货仓"); + } + Long returnWarehouseId = warehouseList.get(0).getWarehouseId(); + + if (oldCoil.getActualWarehouseId() != null) { + updateActualWarehouseEnableStatus(oldCoil.getActualWarehouseId(), null); + } + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(WmsMaterialCoil::getCoilId, oldCoil.getCoilId()) + .set(WmsMaterialCoil::getDataType, 0); + baseMapper.update(null, updateWrapper); + + WmsMaterialCoil newCoil = new WmsMaterialCoil(); + BeanUtils.copyProperties(oldCoil, newCoil); + newCoil.setCoilId(null); + newCoil.setDataType(1); + newCoil.setWarehouseId(returnWarehouseId); + newCoil.setNextWarehouseId(null); + newCoil.setQrcodeRecordId(oldCoil.getQrcodeRecordId()); + newCoil.setParentCoilId(null); + newCoil.setStatus(0); + + validEntityBeforeSave(newCoil); + boolean flag = baseMapper.insert(newCoil) > 0; + + if (flag && oldCoil.getQrcodeRecordId() != null) { + updateQrcodeContentForReturn(oldCoil, newCoil.getCoilId()); + } + + return queryById(newCoil.getCoilId()); + } + + /** + * 更新二维码内容(退货操作) + */ + private void updateQrcodeContentForReturn(WmsMaterialCoil oldCoil, Long newCoilId) { + try { + WmsGenerateRecordVo oldRecord = generateRecordService.queryById(oldCoil.getQrcodeRecordId()); + if (oldRecord == null) { + throw new RuntimeException("二维码记录不存在"); + } + + ObjectMapper objectMapper = new ObjectMapper(); + @SuppressWarnings("unchecked") + Map contentMap = objectMapper.readValue(oldRecord.getContent(), Map.class); + + @SuppressWarnings("unchecked") + List> steps = (List>) contentMap.get("steps"); + if (steps == null) { + steps = new ArrayList<>(); + } + + Map newStep = new HashMap<>(); + newStep.put("step", steps.size() + 1); + newStep.put("action", "退货"); + newStep.put("operation", "退货操作"); + newStep.put("old_current_coil_no", oldCoil.getCurrentCoilNo()); + newStep.put("new_current_coil_no", oldCoil.getCurrentCoilNo()); + newStep.put("old_coil_id", String.valueOf(oldCoil.getCoilId())); + newStep.put("new_coil_id", String.valueOf(newCoilId)); + newStep.put("operator", LoginHelper.getUsername()); + newStep.put("update_time", new java.util.Date()); + + steps.add(newStep); + contentMap.put("steps", steps); + + contentMap.put("current_coil_id", String.valueOf(newCoilId)); + + String newContentJson = objectMapper.writeValueAsString(contentMap); + + WmsGenerateRecordBo updateBo = new WmsGenerateRecordBo(); + updateBo.setRecordId(oldCoil.getQrcodeRecordId()); + updateBo.setContent(newContentJson); + generateRecordService.updateByBo(updateBo); + } catch (JsonProcessingException e) { + throw new RuntimeException("更新二维码内容失败", e); + } + } }