feat(wms): 添加钢卷锁定机制并优化操作流程
- 在WmsCoilPendingActionBo中新增lockValue字段用于钢卷锁值控制 - 为insertByBo方法添加事务注解确保数据一致性 - 实现钢卷领料时的锁状态校验和上锁逻辑 - 添加unlockCoil方法在操作完成后自动解锁关联钢卷 - 在deleteBatch、completeAction和cancelAction方法中集成自动解锁功能 - 新增getLockStatusDesc方法提供详细的锁状态描述信息 - 优化合卷操作流程,使用completeAction替代手动更新状态 - 在MaterialCoilService中增强独占状态检查,支持多种锁定类型识别
This commit is contained in:
@@ -128,5 +128,10 @@ public class WmsCoilPendingActionBo extends BaseEntity {
|
||||
private String coilIds;
|
||||
|
||||
private String createBys;
|
||||
|
||||
/**
|
||||
* 钢卷锁值(3=酸扎领料,4=分卷领料,5=合卷领料)
|
||||
*/
|
||||
private Integer lockValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -268,6 +268,7 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
* 新增钢卷待操作
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(WmsCoilPendingActionBo bo) {
|
||||
WmsCoilPendingAction add = BeanUtil.toBean(bo, WmsCoilPendingAction.class);
|
||||
validEntityBeforeSave(add);
|
||||
@@ -276,6 +277,16 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
if (materialCoil.getDataType() == 0) {
|
||||
throw new RuntimeException("该钢卷为历史钢卷不能被操作");
|
||||
}
|
||||
// 加锁前校验锁是否存在:只要不为0说明钢卷已上锁,不能领料插入
|
||||
if (bo.getLockValue() != null) {
|
||||
if (materialCoil.getExclusiveStatus() != null && materialCoil.getExclusiveStatus() != 0) {
|
||||
String lockDesc = getLockStatusDesc(materialCoil.getExclusiveStatus());
|
||||
throw new RuntimeException("该钢卷" + lockDesc + ",不能领料");
|
||||
}
|
||||
// 给钢卷上锁
|
||||
materialCoil.setExclusiveStatus(bo.getLockValue());
|
||||
materialCoilMapper.updateById(materialCoil);
|
||||
}
|
||||
}
|
||||
// 设置默认值
|
||||
if (add.getActionStatus() == null) {
|
||||
@@ -400,6 +411,37 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁钢卷(将exclusiveStatus恢复为0)
|
||||
*/
|
||||
private void unlockCoil(Long actionId) {
|
||||
WmsCoilPendingAction pendingAction = baseMapper.selectById(actionId);
|
||||
if (pendingAction != null && pendingAction.getCoilId() != null) {
|
||||
WmsMaterialCoil coil = materialCoilMapper.selectById(pendingAction.getCoilId());
|
||||
if (coil != null && coil.getExclusiveStatus() != null && coil.getExclusiveStatus() != 0) {
|
||||
coil.setExclusiveStatus(0);
|
||||
materialCoilMapper.updateById(coil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取锁状态描述
|
||||
*/
|
||||
private String getLockStatusDesc(Integer exclusiveStatus) {
|
||||
if (exclusiveStatus == null) {
|
||||
return "状态未知";
|
||||
}
|
||||
switch (exclusiveStatus) {
|
||||
case 1: return "正在单步分卷中";
|
||||
case 2: return "正在退火中";
|
||||
case 3: return "已被酸扎领料锁定";
|
||||
case 4: return "已被分卷领料锁定";
|
||||
case 5: return "已被合卷领料锁定";
|
||||
default: return "已被其他操作锁定(状态码:" + exclusiveStatus + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除钢卷待操作
|
||||
*/
|
||||
@@ -408,6 +450,10 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
if(isValid){
|
||||
// TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
// 删除操作时解锁关联钢卷
|
||||
for (Long id : ids) {
|
||||
unlockCoil(id);
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@@ -433,12 +479,12 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
if (wmsCoilPendingAction == null) {
|
||||
throw new ServiceException("待操作记录不存在");
|
||||
}
|
||||
|
||||
|
||||
// 2. 检查状态:已完成的操作不能再次开始
|
||||
if (wmsCoilPendingAction.getActionStatus() != null && wmsCoilPendingAction.getActionStatus() == 2) {
|
||||
throw new ServiceException("钢卷已被加工, 该操作已完成");
|
||||
}
|
||||
|
||||
|
||||
// 3. 更新状态为处理中,并记录操作人和时间
|
||||
WmsCoilPendingAction updateAction = new WmsCoilPendingAction();
|
||||
updateAction.setActionId(actionId);
|
||||
@@ -450,7 +496,7 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
} catch (Exception e) {
|
||||
// 如果获取登录用户失败,不影响主流程
|
||||
}
|
||||
|
||||
|
||||
return baseMapper.updateById(updateAction) > 0;
|
||||
}
|
||||
|
||||
@@ -465,6 +511,9 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
throw new RuntimeException("待操作记录不存在");
|
||||
}
|
||||
|
||||
// 完成操作时解锁关联钢卷
|
||||
unlockCoil(actionId);
|
||||
|
||||
WmsCoilPendingAction action = new WmsCoilPendingAction();
|
||||
action.setActionId(actionId);
|
||||
action.setActionStatus(2); // 已完成
|
||||
@@ -491,6 +540,8 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
*/
|
||||
@Override
|
||||
public Boolean cancelAction(Long actionId) {
|
||||
// 取消操作时解锁关联钢卷
|
||||
unlockCoil(actionId);
|
||||
WmsCoilPendingAction action = new WmsCoilPendingAction();
|
||||
action.setActionId(actionId);
|
||||
action.setActionStatus(3); // 已取消
|
||||
|
||||
@@ -1659,7 +1659,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
}
|
||||
|
||||
// 如果有关联的操作记录ID,调用完成接口
|
||||
if (bo.getActionId() != null && bo.getActionId() > 0) {
|
||||
if (bo.getActionId() != null && bo.getActionId() > 0 && bo.getHasMergeSplit() != 2) {
|
||||
coilPendingActionService.completeAction(bo.getActionId(), result);
|
||||
}
|
||||
|
||||
@@ -2003,7 +2003,16 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
if (status == 2) {
|
||||
throw new RuntimeException("钢卷正在进行退火操作中,无法执行" + operation + "操作");
|
||||
}
|
||||
throw new RuntimeException("钢卷已被独占,无法执行" + operation + "操作");
|
||||
if (status == 3) {
|
||||
throw new RuntimeException("钢卷已被酸扎领料锁定,无法执行" + operation + "操作");
|
||||
}
|
||||
if (status == 4) {
|
||||
throw new RuntimeException("钢卷已被分卷领料锁定,无法执行" + operation + "操作");
|
||||
}
|
||||
if (status == 5) {
|
||||
throw new RuntimeException("钢卷已被合卷领料锁定,无法执行" + operation + "操作");
|
||||
}
|
||||
throw new RuntimeException("钢卷已被独占(状态码:" + status + "),无法执行" + operation + "操作");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3565,8 +3574,6 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("合卷操作需要提供参与合卷的钢卷列表");
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
// 第一步:先为每个原始钢卷创建待操作记录(状态为处理中)
|
||||
// 收集创建成功的actionId,用于后续更新
|
||||
Map<Long, Long> coilToActionIdMap = new HashMap<>();
|
||||
@@ -3598,6 +3605,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
pendingActionBo.setActionStatus(0); // 处理中
|
||||
pendingActionBo.setSourceType("manual");
|
||||
pendingActionBo.setPriority(0);
|
||||
pendingActionBo.setLockValue(5); // 合卷领料锁
|
||||
coilPendingActionService.insertByBo(pendingActionBo);
|
||||
|
||||
// insertByBo 会自动设置 actionId 到 bo 中
|
||||
@@ -3631,16 +3639,10 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("未找到合卷后的新钢卷ID");
|
||||
}
|
||||
|
||||
// 第三步:更新所有待操作记录状态为已完成,并设置processedCoilIds
|
||||
// 第三步:调用完成接口更新所有待操作记录状态为已完成,并解锁钢卷
|
||||
for (Map.Entry<Long, Long> entry : coilToActionIdMap.entrySet()) {
|
||||
Long actionId = entry.getValue();
|
||||
|
||||
WmsCoilPendingActionBo pendingActionBo = new WmsCoilPendingActionBo();
|
||||
pendingActionBo.setActionId(actionId);
|
||||
pendingActionBo.setActionStatus(2); // 已完成
|
||||
pendingActionBo.setCompleteTime(now);
|
||||
pendingActionBo.setProcessedCoilIds(mergedCoilId.toString());
|
||||
coilPendingActionService.updateByBo(pendingActionBo);
|
||||
coilPendingActionService.completeAction(actionId, mergedCoilId.toString());
|
||||
}
|
||||
|
||||
return mergedCoilId;
|
||||
|
||||
Reference in New Issue
Block a user