fix(oa):优化项目进度步骤更新逻辑
- 增加 trackId 空值校验,避免无效更新 - 使用 selectById 替代 selectOne 提高查询效率 - 完善首次修改结束时间的判断逻辑 - 明确设置原始结束时间字段- 增强异常处理,提升代码健壮性
This commit is contained in:
@@ -122,16 +122,29 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(OaProjectScheduleStepBo bo) {
|
||||
|
||||
// 除了做更新还需要编辑文件权限将涉及到的所有文件 都涉及到userId
|
||||
// 1. 转换实体并校验
|
||||
OaProjectScheduleStep update = BeanUtil.toBean(bo, OaProjectScheduleStep.class);
|
||||
validEntityBeforeSave(update);
|
||||
//查询end_time结束时间是不是空 如果是空则证明是第一次修改需要给end_time赋值也就是新的结束时间原来结束时间不变
|
||||
OaProjectScheduleStep oaProjectScheduleStep = baseMapper.selectOne(new LambdaQueryWrapper<OaProjectScheduleStep>().eq(OaProjectScheduleStep::getTrackId, update.getTrackId()));
|
||||
if (oaProjectScheduleStep.getEndTime() == null) {
|
||||
|
||||
// 2. 查询原数据(先判断 trackId 是否存在)
|
||||
Long trackId = update.getTrackId();
|
||||
if (trackId == null) {
|
||||
throw new IllegalArgumentException("更新主键 trackId 不能为空");
|
||||
}
|
||||
OaProjectScheduleStep original = baseMapper.selectById(trackId); // 推荐用 selectById 更简洁
|
||||
if (original == null) {
|
||||
// 处理查询不到的情况(例如抛异常或返回失败)
|
||||
throw new RuntimeException("未找到 ID 为 " + trackId + " 的项目进度步骤记录");
|
||||
}
|
||||
|
||||
// 3. 处理结束时间逻辑(此时 original 一定非 null,可安全调用方法)
|
||||
if (original.getEndTime() == null) {
|
||||
// 首次修改:设置结束时间和原始结束时间
|
||||
update.setEndTime(bo.getEndTime());
|
||||
update.setOriginalEndTime(bo.getEndTime());
|
||||
}
|
||||
|
||||
// 4. 执行更新
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user