This commit is contained in:
2025-10-28 15:26:43 +08:00
parent f446d962ff
commit 99bdfe94d6
2 changed files with 71 additions and 5 deletions

View File

@@ -35,10 +35,6 @@ public class WmsStock extends BaseEntity {
* 物品ID指向原材料或产品主键
*/
private Long itemId;
/**
* 钢卷ID指向wms_material_coil.coil_id
*/
private Long coilId;
/**
* 批次号(可选)
*/

View File

@@ -161,6 +161,8 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setCoilId(add.getCoilId());
// 4. 更新二维码内容中的coilId
updateQrcodeCoilId(qrcodeRecordId, add.getCoilId());
}
return flag;
}
@@ -175,6 +177,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
contentMap.put("enter_coil_no", bo.getEnterCoilNo()); // 入场钢卷号(唯一不变)
contentMap.put("current_coil_no", currentCoilNo); // 当前钢卷号(可变)
contentMap.put("coil_id", null); // 钢卷ID新增时暂时为null插入后更新
// 创建steps数组
List<Map<String, Object>> steps = new ArrayList<>();
@@ -395,6 +398,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
validEntityBeforeSave(newCoil);
baseMapper.insert(newCoil);
newCoils.add(newCoil);
// 更新二维码内容中的coilId
updateQrcodeCoilId(newQrcodeId, newCoil.getCoilId());
}
} else if (isMerge) {
// 合卷将bo作为合卷后的新钢卷newCoils中的对象作为参与合卷的原始钢卷
@@ -428,6 +434,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
validEntityBeforeSave(newCoil);
baseMapper.insert(newCoil);
newCoils.add(newCoil);
// 更新二维码内容中的coilId
updateQrcodeCoilId(mergedQrcodeId, newCoil.getCoilId());
}
return true;
@@ -441,6 +450,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
Map<String, Object> contentMap = new HashMap<>();
contentMap.put("enter_coil_no", oldCoil.getEnterCoilNo());
contentMap.put("current_coil_no", newCoilBo.getCurrentCoilNo());
contentMap.put("coil_id", null); // 钢卷ID分卷时暂时为null插入后更新
// 复制原钢卷的历史steps
List<Map<String, Object>> steps = new ArrayList<>();
@@ -464,6 +474,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
splitStep.put("action", "更新");
splitStep.put("operation", "分卷");
splitStep.put("old_current_coil_no", oldCoil.getCurrentCoilNo());
splitStep.put("old_coil_id", oldCoil.getCoilId());
splitStep.put("new_current_coil_nos", String.join(",", allNewCoilNos));
splitStep.put("child_coils", allNewCoilNos);
steps.add(splitStep);
@@ -507,6 +518,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
contentMap.put("enter_coil_no", enterCoilNo);
contentMap.put("current_coil_no", mergedCoilBo.getCurrentCoilNo());
contentMap.put("coil_id", null); // 钢卷ID合卷时暂时为null插入后更新
// 合并所有参与合卷的原始钢卷的历史steps
List<Map<String, Object>> steps = new ArrayList<>();
@@ -540,16 +552,21 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
mergeStep.put("action", "更新");
mergeStep.put("operation", "合卷");
// 收集参与合卷的原始钢卷号
// 收集参与合卷的原始钢卷号和ID
List<String> originalCoilNos = new ArrayList<>();
List<String> originalCoilIds = new ArrayList<>();
if (originalCoils != null && !originalCoils.isEmpty()) {
for (WmsMaterialCoilBo originalCoilBo : originalCoils) {
if (originalCoilBo.getCurrentCoilNo() != null) {
originalCoilNos.add(originalCoilBo.getCurrentCoilNo());
}
if (originalCoilBo.getCoilId() != null) {
originalCoilIds.add(originalCoilBo.getCoilId().toString());
}
}
}
mergeStep.put("parent_coil_nos", String.join(",", originalCoilNos));
mergeStep.put("parent_coil_ids", String.join(",", originalCoilIds));
mergeStep.put("new_current_coil_no", mergedCoilBo.getCurrentCoilNo());
steps.add(mergeStep);
@@ -571,6 +588,35 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
throw new RuntimeException("生成合卷二维码失败: " + e.getMessage());
}
}
/**
* 更新二维码内容中的coilId
*/
private void updateQrcodeCoilId(Long qrcodeRecordId, Long coilId) {
try {
// 获取二维码记录
WmsGenerateRecordVo record = generateRecordService.queryById(qrcodeRecordId);
if (record == null) {
throw new RuntimeException("二维码记录不存在");
}
// 解析现有content
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> contentMap = objectMapper.readValue(record.getContent(), Map.class);
// 更新coilId
contentMap.put("coil_id", coilId);
// 更新二维码记录
String newContentJson = objectMapper.writeValueAsString(contentMap);
WmsGenerateRecordBo updateBo = new WmsGenerateRecordBo();
updateBo.setRecordId(qrcodeRecordId);
updateBo.setContent(newContentJson);
generateRecordService.updateByBo(updateBo);
} catch (Exception e) {
throw new RuntimeException("更新二维码coilId失败: " + e.getMessage());
}
}
/**
* 更新二维码内容(单个更新)
*/
@@ -602,6 +648,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
newStep.put("action", "更新");
newStep.put("old_current_coil_no", oldCoil.getCurrentCoilNo()); // 原当前钢卷号
newStep.put("new_current_coil_no", bo.getCurrentCoilNo()); // 新当前钢卷号
newStep.put("coil_id", bo.getCoilId()); // 钢卷ID
// 判断操作类型
if (bo.getHasMergeSplit() != null && bo.getHasMergeSplit() == 2) {
@@ -691,6 +738,10 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
extractCoilNo(step, "new_current_coil_nos", coilNos);
extractCoilNo(step, "merged_from", coilNos);
extractCoilNo(step, "parent_coil_nos", coilNos);
// 提取钢卷ID字段
extractCoilId(step, "coil_id", coilNos);
extractCoilId(step, "old_coil_id", coilNos);
extractCoilId(step, "parent_coil_ids", coilNos);
}
}
@@ -757,5 +808,24 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
}
}
/**
* 从step中提取钢卷ID
*/
private void extractCoilId(Map<String, Object> step, String fieldName, Set<String> coilNos) {
Object value = step.get(fieldName);
if (value != null) {
String strValue = value.toString();
if (strValue.contains(",")) {
// 如果是逗号分隔的多个钢卷ID分割后添加
String[] coilArray = strValue.split(",");
for (String coilId : coilArray) {
coilNos.add(coilId.trim());
}
} else {
coilNos.add(strValue.trim());
}
}
}
}