refactor(boss): 优化决策记录处理逻辑
- 添加检查是否存在决策记录的功能 - 实现已存在记录时更新操作 - 实现不存在记录时插入新记录 - 统一决策时间设置逻辑 - 优化异常处理机制 - 修正更新申请状态的注释信息
This commit is contained in:
@@ -57,14 +57,35 @@ public class BossApplicationDecisionServiceImpl extends ServiceImpl<BossApplicat
|
|||||||
|
|
||||||
User loginUser = userService.getLoginUser(request);
|
User loginUser = userService.getLoginUser(request);
|
||||||
|
|
||||||
BossApplicationDecision e = new BossApplicationDecision();
|
// 检查是否已存在决策记录,如果有则更新,否则插入新记录
|
||||||
BeanUtil.copyProperties(addRequest, e);
|
QueryWrapper<BossApplicationDecision> queryWrapper = new QueryWrapper<>();
|
||||||
e.setBossId(loginUser.getId());
|
queryWrapper.eq("application_id", addRequest.getApplicationId());
|
||||||
e.setDecidedAt(new Date()); // 设置决策时间
|
BossApplicationDecision existingDecision = this.getOne(queryWrapper);
|
||||||
|
|
||||||
boolean res = this.save(e);
|
BossApplicationDecision e;
|
||||||
if (!res) {
|
boolean isNew = true;
|
||||||
throw new BusinessException(ErrorCode.OPERATION_ERROR);
|
|
||||||
|
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);
|
||||||
|
e.setBossId(loginUser.getId());
|
||||||
|
e.setDecidedAt(new Date()); // 设置决策时间
|
||||||
|
boolean res = this.save(e);
|
||||||
|
if (!res) {
|
||||||
|
throw new BusinessException(ErrorCode.OPERATION_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新申请状态
|
// 更新申请状态
|
||||||
@@ -72,7 +93,7 @@ public class BossApplicationDecisionServiceImpl extends ServiceImpl<BossApplicat
|
|||||||
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user