This commit is contained in:
2025-10-28 14:56:46 +08:00
parent 3be57b3f67
commit f8afe8d0e7
2 changed files with 109 additions and 89 deletions

View File

@@ -253,16 +253,15 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(WmsMaterialCoilBo bo) { public Boolean updateByBo(WmsMaterialCoilBo bo) {
if (bo.getCoilId() == null) {
throw new RuntimeException("钢卷ID不能为空");
}
// 判断是否批量更新 // 判断是否批量更新
if (bo.getNewCoils() != null && !bo.getNewCoils().isEmpty()) { if (bo.getNewCoils() != null && !bo.getNewCoils().isEmpty()) {
// 批量更新逻辑(分卷/合卷) // 批量更新逻辑(分卷/合卷)
return updateByBatch(bo); return updateByBatch(bo);
} else { } else {
// 单个更新逻辑 // 单个更新逻辑需要coilId
if (bo.getCoilId() == null) {
throw new RuntimeException("钢卷ID不能为空");
}
return updateBySingle(bo); return updateBySingle(bo);
} }
} }
@@ -330,32 +329,40 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
* 批量更新(分卷/合卷) * 批量更新(分卷/合卷)
*/ */
private Boolean updateByBatch(WmsMaterialCoilBo bo) { private Boolean updateByBatch(WmsMaterialCoilBo bo) {
// 查询原钢卷 // 查询原钢卷(分卷时需要,合卷时可能不需要)
WmsMaterialCoil oldCoil = baseMapper.selectById(bo.getCoilId()); WmsMaterialCoil oldCoil = null;
if (oldCoil == null) { if (bo.getCoilId() != null) {
throw new RuntimeException("原钢卷不存在"); oldCoil = baseMapper.selectById(bo.getCoilId());
if (oldCoil == null) {
throw new RuntimeException("原钢卷不存在");
}
} }
// 判断是分卷还是合卷 // 判断是分卷还是合卷
boolean isSplit = false; boolean isSplit = false;
boolean isMerge = false; boolean isMerge = false;
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
if (newCoilBo.getHasMergeSplit() != null) { // 检查bo本身是否为合卷
if (newCoilBo.getHasMergeSplit() == 1) { if (bo.getHasMergeSplit() != null && bo.getHasMergeSplit() == 2) {
isMerge = true;
} else if (bo.getNewCoils() != null && !bo.getNewCoils().isEmpty()) {
// 检查newCoils中是否有分卷
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
if (newCoilBo.getHasMergeSplit() != null && newCoilBo.getHasMergeSplit() == 1) {
isSplit = true; isSplit = true;
break; break;
} else if (newCoilBo.getHasMergeSplit() == 2) {
isMerge = true;
break;
} }
} }
} }
// 1. 将原数据更新为历史数据data_type=0 // 1. 将原数据更新为历史数据data_type=0
LambdaUpdateWrapper<WmsMaterialCoil> updateWrapper = new LambdaUpdateWrapper<>(); // 注意合卷时bo的coilId可能为空因为bo是合卷后的新钢卷
updateWrapper.eq(WmsMaterialCoil::getCoilId, bo.getCoilId()) if (bo.getCoilId() != null) {
.set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据 LambdaUpdateWrapper<WmsMaterialCoil> updateWrapper = new LambdaUpdateWrapper<>();
baseMapper.update(null, updateWrapper); updateWrapper.eq(WmsMaterialCoil::getCoilId, bo.getCoilId())
.set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据
baseMapper.update(null, updateWrapper);
}
// 2. 插入多条新的当前数据data_type=1 // 2. 插入多条新的当前数据data_type=1
List<WmsMaterialCoil> newCoils = new ArrayList<>(); List<WmsMaterialCoil> newCoils = new ArrayList<>();
@@ -367,7 +374,14 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
} }
if (isSplit) { if (isSplit) {
// 分卷:为每个子钢卷生成独立的二维码 // 分卷:将bo作为被分卷的原始对象newCoils中的对象作为分卷后产生的新钢卷
if (oldCoil == null) {
throw new RuntimeException("分卷操作需要原钢卷信息");
}
// 1. 将原始钢卷更新为历史数据(已在上面完成)
// 2. 为每个分卷后的子钢卷生成独立的二维码并插入数据库
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) { for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
WmsMaterialCoil newCoil = BeanUtil.toBean(newCoilBo, WmsMaterialCoil.class); WmsMaterialCoil newCoil = BeanUtil.toBean(newCoilBo, WmsMaterialCoil.class);
newCoil.setCoilId(null); newCoil.setCoilId(null);
@@ -383,20 +397,37 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
newCoils.add(newCoil); newCoils.add(newCoil);
} }
} else if (isMerge) { } else if (isMerge) {
// 合卷:合并多个二维码信息为一个 // 合卷:将bo作为合卷后的新钢卷newCoils中的对象作为参与合卷的原始钢卷
Long mergedQrcodeId = generateQrcodeForMerge(oldCoil, bo.getNewCoils()); // 1. 将参与合卷的原始钢卷更新为历史数据
for (WmsMaterialCoilBo originalCoilBo : bo.getNewCoils()) {
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) { if (originalCoilBo.getCoilId() != null) {
WmsMaterialCoil newCoil = BeanUtil.toBean(newCoilBo, WmsMaterialCoil.class); LambdaUpdateWrapper<WmsMaterialCoil> originalUpdateWrapper = new LambdaUpdateWrapper<>();
newCoil.setCoilId(null); originalUpdateWrapper.eq(WmsMaterialCoil::getCoilId, originalCoilBo.getCoilId())
newCoil.setDataType(1); .set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据
newCoil.setEnterCoilNo(oldCoil.getEnterCoilNo()); baseMapper.update(null, originalUpdateWrapper);
newCoil.setQrcodeRecordId(mergedQrcodeId); // 所有合卷后的钢卷共享一个二维码 }
validEntityBeforeSave(newCoil);
baseMapper.insert(newCoil);
newCoils.add(newCoil);
} }
// 2. 生成合卷后的新钢卷二维码
Long mergedQrcodeId = generateQrcodeForMerge(bo, bo.getNewCoils());
// 3. 插入合卷后的新钢卷
WmsMaterialCoil newCoil = BeanUtil.toBean(bo, WmsMaterialCoil.class);
newCoil.setCoilId(null);
newCoil.setDataType(1);
// 合卷后的钢卷使用自己的enterCoilNo如果没有则从参与合卷的原始钢卷中获取
if (newCoil.getEnterCoilNo() == null && !bo.getNewCoils().isEmpty()) {
// 从第一个参与合卷的原始钢卷获取enterCoilNo
WmsMaterialCoil firstOriginalCoil = baseMapper.selectById(bo.getNewCoils().get(0).getCoilId());
if (firstOriginalCoil != null) {
newCoil.setEnterCoilNo(firstOriginalCoil.getEnterCoilNo());
}
}
newCoil.setQrcodeRecordId(mergedQrcodeId);
validEntityBeforeSave(newCoil);
baseMapper.insert(newCoil);
newCoils.add(newCoil);
} }
return true; return true;
@@ -459,58 +490,46 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
/** /**
* 为合卷生成新二维码(合并多个父钢卷的二维码信息) * 为合卷生成新二维码(合并多个父钢卷的二维码信息)
*/ */
private Long generateQrcodeForMerge(WmsMaterialCoil oldCoil, List<WmsMaterialCoilBo> newCoils) { private Long generateQrcodeForMerge(WmsMaterialCoilBo mergedCoilBo, List<WmsMaterialCoilBo> originalCoils) {
try { try {
if (newCoils.isEmpty()) { if (mergedCoilBo == null) {
throw new RuntimeException("合卷后的钢卷数据不能为空"); throw new RuntimeException("合卷后的钢卷数据不能为空");
} }
WmsMaterialCoilBo mergedCoilBo = newCoils.get(0);
Map<String, Object> contentMap = new HashMap<>(); Map<String, Object> contentMap = new HashMap<>();
contentMap.put("enter_coil_no", oldCoil.getEnterCoilNo()); // 获取enterCoilNo优先使用mergedCoilBo的如果没有则从原始钢卷中获取
contentMap.put("current_coil_no", mergedCoilBo.getCurrentCoilNo()); String enterCoilNo = mergedCoilBo.getEnterCoilNo();
if (enterCoilNo == null && originalCoils != null && !originalCoils.isEmpty()) {
// 合并所有父钢卷的历史steps WmsMaterialCoil firstOriginalCoil = baseMapper.selectById(originalCoils.get(0).getCoilId());
List<Map<String, Object>> steps = new ArrayList<>(); if (firstOriginalCoil != null) {
enterCoilNo = firstOriginalCoil.getEnterCoilNo();
// 如果有父钢卷号,获取它们的二维码信息并合并
if (mergedCoilBo.getParentCoilNos() != null && !mergedCoilBo.getParentCoilNos().trim().isEmpty()) {
String[] parentCoilNos = mergedCoilBo.getParentCoilNos().split(",");
for (String parentCoilNo : parentCoilNos) {
// 查找父钢卷
LambdaQueryWrapper<WmsMaterialCoil> parentLqw = Wrappers.lambdaQuery();
parentLqw.eq(WmsMaterialCoil::getCurrentCoilNo, parentCoilNo.trim())
.eq(WmsMaterialCoil::getDataType, 1);
List<WmsMaterialCoil> parentCoils = baseMapper.selectList(parentLqw);
if (!parentCoils.isEmpty() && parentCoils.get(0).getQrcodeRecordId() != null) {
WmsGenerateRecordVo parentQr = generateRecordService.queryById(parentCoils.get(0).getQrcodeRecordId());
if (parentQr != null) {
ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked")
Map<String, Object> parentContentMap = objectMapper.readValue(parentQr.getContent(), Map.class);
@SuppressWarnings("unchecked")
List<Map<String, Object>> parentSteps = (List<Map<String, Object>>) parentContentMap.get("steps");
if (parentSteps != null) {
steps.addAll(parentSteps);
}
}
}
} }
} }
contentMap.put("enter_coil_no", enterCoilNo);
contentMap.put("current_coil_no", mergedCoilBo.getCurrentCoilNo());
// 添加原钢卷的历史 // 合并所有参与合卷的原始钢卷的历史steps
if (oldCoil.getQrcodeRecordId() != null) { List<Map<String, Object>> steps = new ArrayList<>();
WmsGenerateRecordVo oldRecord = generateRecordService.queryById(oldCoil.getQrcodeRecordId());
if (oldRecord != null) { // 从参与合卷的原始钢卷中获取二维码信息并合并
ObjectMapper objectMapper = new ObjectMapper(); if (originalCoils != null && !originalCoils.isEmpty()) {
@SuppressWarnings("unchecked") for (WmsMaterialCoilBo originalCoilBo : originalCoils) {
Map<String, Object> oldContentMap = objectMapper.readValue(oldRecord.getContent(), Map.class); if (originalCoilBo.getCoilId() != null) {
@SuppressWarnings("unchecked") // 查询原始钢卷的二维码信息
List<Map<String, Object>> oldSteps = (List<Map<String, Object>>) oldContentMap.get("steps"); WmsMaterialCoil originalCoil = baseMapper.selectById(originalCoilBo.getCoilId());
if (oldSteps != null) { if (originalCoil != null && originalCoil.getQrcodeRecordId() != null) {
steps.addAll(oldSteps); WmsGenerateRecordVo originalQr = generateRecordService.queryById(originalCoil.getQrcodeRecordId());
if (originalQr != null) {
ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked")
Map<String, Object> originalContentMap = objectMapper.readValue(originalQr.getContent(), Map.class);
@SuppressWarnings("unchecked")
List<Map<String, Object>> originalSteps = (List<Map<String, Object>>) originalContentMap.get("steps");
if (originalSteps != null) {
steps.addAll(originalSteps);
}
}
}
} }
} }
} }
@@ -520,7 +539,17 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
mergeStep.put("step", steps.size() + 1); mergeStep.put("step", steps.size() + 1);
mergeStep.put("action", "更新"); mergeStep.put("action", "更新");
mergeStep.put("operation", "合卷"); mergeStep.put("operation", "合卷");
mergeStep.put("parent_coil_nos", mergedCoilBo.getParentCoilNos());
// 收集参与合卷的原始钢卷号
List<String> originalCoilNos = new ArrayList<>();
if (originalCoils != null && !originalCoils.isEmpty()) {
for (WmsMaterialCoilBo originalCoilBo : originalCoils) {
if (originalCoilBo.getCurrentCoilNo() != null) {
originalCoilNos.add(originalCoilBo.getCurrentCoilNo());
}
}
}
mergeStep.put("parent_coil_nos", String.join(",", originalCoilNos));
mergeStep.put("new_current_coil_no", mergedCoilBo.getCurrentCoilNo()); mergeStep.put("new_current_coil_no", mergedCoilBo.getCurrentCoilNo());
steps.add(mergeStep); steps.add(mergeStep);
@@ -531,7 +560,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
WmsGenerateRecordBo recordBo = new WmsGenerateRecordBo(); WmsGenerateRecordBo recordBo = new WmsGenerateRecordBo();
recordBo.setContent(contentJson); recordBo.setContent(contentJson);
recordBo.setSerialNumber(oldCoil.getEnterCoilNo() + "-" + mergedCoilBo.getCurrentCoilNo()); recordBo.setSerialNumber(enterCoilNo + "-" + mergedCoilBo.getCurrentCoilNo());
recordBo.setQrcodeType(0L); recordBo.setQrcodeType(0L);
recordBo.setIsEnabled(0L); recordBo.setIsEnabled(0L);
recordBo.setSize(200L); recordBo.setSize(200L);

View File

@@ -16,19 +16,10 @@ create table wms_stock
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
update_by varchar(50) null comment '更新人', update_by varchar(50) null comment '更新人',
constraint fk_stock_warehouse constraint fk_stock_warehouse
foreign key (warehouse_id) references wms_warehouse (warehouse_id), foreign key (warehouse_id) references wms_warehouse (warehouse_id)
constraint fk_stock_raw_material
foreign key (raw_material_id) references wms_raw_material (raw_material_id),
constraint fk_stock_coil
foreign key (coil_id) references wms_material_coil (coil_id)
) )
comment '库存表:原材料-钢卷-库区的存放关系' charset = utf8mb4; comment '库存表:原材料-钢卷-库区的存放关系' charset = utf8mb4;
create index idx_stock_raw_material
on wms_stock (raw_material_id);
create index idx_stock_coil
on wms_stock (coil_id);
create index idx_stock_warehouse create index idx_stock_warehouse
on wms_stock (warehouse_id); on wms_stock (warehouse_id);