fix(wms/coil): 修复待操作记录开始操作时的状态校验问题
1. 在开始操作前增加待操作记录存在性检查,若记录不存在则抛出异常 2. 增加状态校验逻辑,防止对已完成(状态为2)的记录再次开始操作 3. 重构代码结构,将直接更新改为先查询后更新,确保状态变更的准确性 4. 添加事务注解保证操作原子性
This commit is contained in:
@@ -402,18 +402,32 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
* 开始处理操作
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean startProcess(Long actionId) {
|
||||
WmsCoilPendingAction action = new WmsCoilPendingAction();
|
||||
action.setActionId(actionId);
|
||||
action.setActionStatus(1); // 处理中
|
||||
action.setProcessTime(new Date());
|
||||
// 1. 查询待操作记录
|
||||
WmsCoilPendingAction wmsCoilPendingAction = baseMapper.selectById(actionId);
|
||||
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);
|
||||
updateAction.setActionStatus(1); // 处理中
|
||||
updateAction.setProcessTime(new Date());
|
||||
try {
|
||||
action.setOperatorId(LoginHelper.getUserId());
|
||||
action.setOperatorName(LoginHelper.getUsername());
|
||||
updateAction.setOperatorId(LoginHelper.getUserId());
|
||||
updateAction.setOperatorName(LoginHelper.getUsername());
|
||||
} catch (Exception e) {
|
||||
// 如果获取登录用户失败,不影响主流程
|
||||
}
|
||||
return baseMapper.updateById(action) > 0;
|
||||
|
||||
return baseMapper.updateById(updateAction) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user