feat(wms): 新增钢卷退货功能

- 在IWmsMaterialCoilService接口中添加returnCoil方法定义
- 在WmsMaterialCoilController控制器中新增退货接口映射
- 在WmsMaterialCoilServiceImpl实现类中实现完整的退货逻辑
- 实现将原钢卷转为历史数据并创建新钢卷记录的功能
- 实现退货仓查找及仓库状态更新机制
- 实现二维码内容更新以记录退货操作步骤
- 添加退货操作的权限验证和数据校验机制
This commit is contained in:
2026-02-28 10:16:32 +08:00
parent 80b4722eae
commit ae29cbb689
3 changed files with 132 additions and 0 deletions

View File

@@ -422,6 +422,25 @@ public class WmsMaterialCoilController extends BaseController {
}
}
/**
* 钢卷退货操作
* 将钢卷退货到退货仓,创建新钢卷记录,将原钢卷设置为历史钢卷
*/
@Log(title = "钢卷物料表-退货", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PostMapping("/return")
public R<WmsMaterialCoilVo> 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());
}
}
}

View File

@@ -213,5 +213,14 @@ public interface IWmsMaterialCoilService {
Map<String, Object> completeSpecialSplit(@NotNull(message = "待操作记录ID不能为空") Long pendingActionId);
Map<String, Object> cancelSpecialSplit(@NotNull(message = "待操作记录ID不能为空") Long pendingActionId);
/**
* 钢卷退货操作
* 将钢卷退货到退货仓,创建新钢卷记录,将原钢卷设置为历史钢卷
*
* @param coilId 原钢卷ID
* @return 退货后的新钢卷信息
*/
WmsMaterialCoilVo returnCoil(@NotNull(message = "钢卷ID不能为空") Long coilId);
}

View File

@@ -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<WmsWarehouseVo> 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<WmsMaterialCoil> 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<String, Object> contentMap = objectMapper.readValue(oldRecord.getContent(), Map.class);
@SuppressWarnings("unchecked")
List<Map<String, Object>> steps = (List<Map<String, Object>>) contentMap.get("steps");
if (steps == null) {
steps = new ArrayList<>();
}
Map<String, Object> 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);
}
}
}