refactor(boss): 优化决策记录处理逻辑

- 添加检查是否存在决策记录的功能
- 实现已存在记录时更新操作
- 实现不存在记录时插入新记录
- 统一决策时间设置逻辑
- 优化异常处理机制
- 修正更新申请状态的注释信息
This commit is contained in:
2026-01-10 22:13:12 +08:00
parent c48df65d18
commit d4e0e651cb

View File

@@ -57,22 +57,43 @@ public class BossApplicationDecisionServiceImpl extends ServiceImpl<BossApplicat
User loginUser = userService.getLoginUser(request); User loginUser = userService.getLoginUser(request);
BossApplicationDecision e = new BossApplicationDecision(); // 检查是否已存在决策记录,如果有则更新,否则插入新记录
QueryWrapper<BossApplicationDecision> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("application_id", addRequest.getApplicationId());
BossApplicationDecision existingDecision = this.getOne(queryWrapper);
BossApplicationDecision e;
boolean isNew = true;
if (existingDecision != null) {
// 更新现有记录
e = existingDecision;
isNew = false;
BeanUtil.copyProperties(addRequest, e);
e.setBossId(loginUser.getId());
e.setDecidedAt(new Date()); // 更新决策时间
boolean res = this.updateById(e);
if (!res) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
}
} else {
// 插入新记录
e = new BossApplicationDecision();
BeanUtil.copyProperties(addRequest, e); BeanUtil.copyProperties(addRequest, e);
e.setBossId(loginUser.getId()); e.setBossId(loginUser.getId());
e.setDecidedAt(new Date()); // 设置决策时间 e.setDecidedAt(new Date()); // 设置决策时间
boolean res = this.save(e); boolean res = this.save(e);
if (!res) { if (!res) {
throw new BusinessException(ErrorCode.OPERATION_ERROR); throw new BusinessException(ErrorCode.OPERATION_ERROR);
} }
}
// 更新申请状态 // 更新申请状态
try { try {
applicationService.updateApplicationStatus(addRequest.getApplicationId(), addRequest.getDecision()); applicationService.updateApplicationStatus(addRequest.getApplicationId(), addRequest.getDecision());
} catch (Exception ex) { } catch (Exception ex) {
log.error("更新申请状态失败", ex); log.error("更新申请状态失败", ex);
// 不抛出异常,因为决策已经创建成功 // 不抛出异常,因为决策已经处理成功
} }
return e.getId(); return e.getId();