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
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(WmsMaterialCoilBo bo) {
if (bo.getCoilId() == null) {
throw new RuntimeException("钢卷ID不能为空");
}
// 判断是否批量更新
if (bo.getNewCoils() != null && !bo.getNewCoils().isEmpty()) {
// 批量更新逻辑(分卷/合卷)
return updateByBatch(bo);
} else {
// 单个更新逻辑
// 单个更新逻辑需要coilId
if (bo.getCoilId() == null) {
throw new RuntimeException("钢卷ID不能为空");
}
return updateBySingle(bo);
}
}
@@ -330,32 +329,40 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
* 批量更新(分卷/合卷)
*/
private Boolean updateByBatch(WmsMaterialCoilBo bo) {
// 查询原钢卷
WmsMaterialCoil oldCoil = baseMapper.selectById(bo.getCoilId());
if (oldCoil == null) {
throw new RuntimeException("原钢卷不存在");
// 查询原钢卷(分卷时需要,合卷时可能不需要)
WmsMaterialCoil oldCoil = null;
if (bo.getCoilId() != null) {
oldCoil = baseMapper.selectById(bo.getCoilId());
if (oldCoil == null) {
throw new RuntimeException("原钢卷不存在");
}
}
// 判断是分卷还是合卷
boolean isSplit = false;
boolean isMerge = false;
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
if (newCoilBo.getHasMergeSplit() != null) {
if (newCoilBo.getHasMergeSplit() == 1) {
// 检查bo本身是否为合卷
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;
break;
} else if (newCoilBo.getHasMergeSplit() == 2) {
isMerge = true;
break;
}
}
}
// 1. 将原数据更新为历史数据data_type=0
LambdaUpdateWrapper<WmsMaterialCoil> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(WmsMaterialCoil::getCoilId, bo.getCoilId())
.set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据
baseMapper.update(null, updateWrapper);
// 注意合卷时bo的coilId可能为空因为bo是合卷后的新钢卷
if (bo.getCoilId() != null) {
LambdaUpdateWrapper<WmsMaterialCoil> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(WmsMaterialCoil::getCoilId, bo.getCoilId())
.set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据
baseMapper.update(null, updateWrapper);
}
// 2. 插入多条新的当前数据data_type=1
List<WmsMaterialCoil> newCoils = new ArrayList<>();
@@ -367,7 +374,14 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
if (isSplit) {
// 分卷:为每个子钢卷生成独立的二维码
// 分卷:将bo作为被分卷的原始对象newCoils中的对象作为分卷后产生的新钢卷
if (oldCoil == null) {
throw new RuntimeException("分卷操作需要原钢卷信息");
}
// 1. 将原始钢卷更新为历史数据(已在上面完成)
// 2. 为每个分卷后的子钢卷生成独立的二维码并插入数据库
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
WmsMaterialCoil newCoil = BeanUtil.toBean(newCoilBo, WmsMaterialCoil.class);
newCoil.setCoilId(null);
@@ -383,20 +397,37 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
newCoils.add(newCoil);
}
} else if (isMerge) {
// 合卷:合并多个二维码信息为一个
Long mergedQrcodeId = generateQrcodeForMerge(oldCoil, bo.getNewCoils());
for (WmsMaterialCoilBo newCoilBo : bo.getNewCoils()) {
WmsMaterialCoil newCoil = BeanUtil.toBean(newCoilBo, WmsMaterialCoil.class);
newCoil.setCoilId(null);
newCoil.setDataType(1);
newCoil.setEnterCoilNo(oldCoil.getEnterCoilNo());
newCoil.setQrcodeRecordId(mergedQrcodeId); // 所有合卷后的钢卷共享一个二维码
validEntityBeforeSave(newCoil);
baseMapper.insert(newCoil);
newCoils.add(newCoil);
// 合卷:将bo作为合卷后的新钢卷newCoils中的对象作为参与合卷的原始钢卷
// 1. 将参与合卷的原始钢卷更新为历史数据
for (WmsMaterialCoilBo originalCoilBo : bo.getNewCoils()) {
if (originalCoilBo.getCoilId() != null) {
LambdaUpdateWrapper<WmsMaterialCoil> originalUpdateWrapper = new LambdaUpdateWrapper<>();
originalUpdateWrapper.eq(WmsMaterialCoil::getCoilId, originalCoilBo.getCoilId())
.set(WmsMaterialCoil::getDataType, 0); // 设置为历史数据
baseMapper.update(null, originalUpdateWrapper);
}
}
// 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;
@@ -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 {
if (newCoils.isEmpty()) {
if (mergedCoilBo == null) {
throw new RuntimeException("合卷后的钢卷数据不能为空");
}
WmsMaterialCoilBo mergedCoilBo = newCoils.get(0);
Map<String, Object> contentMap = new HashMap<>();
contentMap.put("enter_coil_no", oldCoil.getEnterCoilNo());
contentMap.put("current_coil_no", mergedCoilBo.getCurrentCoilNo());
// 合并所有父钢卷的历史steps
List<Map<String, Object>> steps = new ArrayList<>();
// 如果有父钢卷号,获取它们的二维码信息并合并
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);
}
}
}
// 获取enterCoilNo优先使用mergedCoilBo的如果没有则从原始钢卷中获取
String enterCoilNo = mergedCoilBo.getEnterCoilNo();
if (enterCoilNo == null && originalCoils != null && !originalCoils.isEmpty()) {
WmsMaterialCoil firstOriginalCoil = baseMapper.selectById(originalCoils.get(0).getCoilId());
if (firstOriginalCoil != null) {
enterCoilNo = firstOriginalCoil.getEnterCoilNo();
}
}
contentMap.put("enter_coil_no", enterCoilNo);
contentMap.put("current_coil_no", mergedCoilBo.getCurrentCoilNo());
// 添加原钢卷的历史
if (oldCoil.getQrcodeRecordId() != null) {
WmsGenerateRecordVo oldRecord = generateRecordService.queryById(oldCoil.getQrcodeRecordId());
if (oldRecord != null) {
ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked")
Map<String, Object> oldContentMap = objectMapper.readValue(oldRecord.getContent(), Map.class);
@SuppressWarnings("unchecked")
List<Map<String, Object>> oldSteps = (List<Map<String, Object>>) oldContentMap.get("steps");
if (oldSteps != null) {
steps.addAll(oldSteps);
// 合并所有参与合卷的原始钢卷的历史steps
List<Map<String, Object>> steps = new ArrayList<>();
// 从参与合卷的原始钢卷中获取二维码信息并合并
if (originalCoils != null && !originalCoils.isEmpty()) {
for (WmsMaterialCoilBo originalCoilBo : originalCoils) {
if (originalCoilBo.getCoilId() != null) {
// 查询原始钢卷的二维码信息
WmsMaterialCoil originalCoil = baseMapper.selectById(originalCoilBo.getCoilId());
if (originalCoil != null && originalCoil.getQrcodeRecordId() != null) {
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("action", "更新");
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());
steps.add(mergeStep);
@@ -531,7 +560,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
WmsGenerateRecordBo recordBo = new WmsGenerateRecordBo();
recordBo.setContent(contentJson);
recordBo.setSerialNumber(oldCoil.getEnterCoilNo() + "-" + mergedCoilBo.getCurrentCoilNo());
recordBo.setSerialNumber(enterCoilNo + "-" + mergedCoilBo.getCurrentCoilNo());
recordBo.setQrcodeType(0L);
recordBo.setIsEnabled(0L);
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_by varchar(50) null comment '更新人',
constraint fk_stock_warehouse
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)
foreign key (warehouse_id) references wms_warehouse (warehouse_id)
)
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
on wms_stock (warehouse_id);