From ec6a0d183832a604a00075a10b9405769e2c25b1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 Jan 2026 16:45:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BF=9D=E5=AD=98=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=A6=E7=BB=86=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=92=8C=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designhub/service/DepartmentService.java | 41 ++++++++++--- .../service/TeamScorePoolService.java | 60 ++++++++++++++----- 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/DepartmentService.java b/backend/src/main/java/com/designhub/service/DepartmentService.java index be8ed4f..1b391b9 100644 --- a/backend/src/main/java/com/designhub/service/DepartmentService.java +++ b/backend/src/main/java/com/designhub/service/DepartmentService.java @@ -28,6 +28,7 @@ import java.util.stream.Collectors; /** * 部门管理Service */ +@Slf4j @Service @RequiredArgsConstructor public class DepartmentService { @@ -210,20 +211,42 @@ public class DepartmentService { existDept.setOverLimitAction(request.getOverLimitAction()); } - departmentMapper.updateById(existDept); + try { + departmentMapper.updateById(existDept); + log.info("更新部门成功: id={}, deptName={}", id, existDept.getDeptName()); + } catch (Exception e) { + log.error("更新部门失败: id={}, error={}", id, e.getMessage(), e); + throw new BusinessException("更新部门失败: " + e.getMessage()); + } // 同步积分池 - teamScorePoolService.upsertPool(existDept.getId(), existDept.getDeptName()); + try { + teamScorePoolService.upsertPool(existDept.getId(), existDept.getDeptName()); + log.info("同步积分池成功: deptId={}, deptName={}", existDept.getId(), existDept.getDeptName()); + } catch (Exception e) { + log.error("同步积分池失败: deptId={}, error={}", existDept.getId(), e.getMessage(), e); + throw new BusinessException("同步积分池失败: " + e.getMessage()); + } + + // 更新积分池限制配置(仅需求部门) if ("demand".equals(existDept.getDeptType()) && (request.getLimitEnabled() != null || request.getLimitPeriod() != null || request.getPeriodLimit() != null || request.getAlertThreshold() != null)) { - teamScorePoolService.updateLimitConfig( - existDept.getId(), - request.getLimitEnabled(), - request.getLimitPeriod(), - request.getPeriodLimit(), - request.getAlertThreshold() - ); + try { + teamScorePoolService.updateLimitConfig( + existDept.getId(), + request.getLimitEnabled(), + request.getLimitPeriod(), + request.getPeriodLimit(), + request.getAlertThreshold() + ); + log.info("更新积分池限制配置成功: deptId={}, limitEnabled={}, limitPeriod={}, periodLimit={}, alertThreshold={}", + existDept.getId(), request.getLimitEnabled(), request.getLimitPeriod(), + request.getPeriodLimit(), request.getAlertThreshold()); + } catch (Exception e) { + log.error("更新积分池限制配置失败: deptId={}, error={}", existDept.getId(), e.getMessage(), e); + throw new BusinessException("更新积分池限制配置失败: " + e.getMessage()); + } } return true; diff --git a/backend/src/main/java/com/designhub/service/TeamScorePoolService.java b/backend/src/main/java/com/designhub/service/TeamScorePoolService.java index 36899bb..a2faba8 100644 --- a/backend/src/main/java/com/designhub/service/TeamScorePoolService.java +++ b/backend/src/main/java/com/designhub/service/TeamScorePoolService.java @@ -7,6 +7,7 @@ import com.designhub.exception.BusinessException; import com.designhub.mapper.DepartmentMapper; import com.designhub.mapper.TeamScorePoolMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -258,23 +259,50 @@ public class TeamScorePoolService { @Transactional(rollbackFor = Exception.class) public void updateLimitConfig(Long deptId, Integer limitEnabled, String limitPeriod, Integer periodLimit, Integer alertThreshold) { - TeamScorePool pool = upsertPool(deptId, null); - if (limitEnabled != null) { - pool.setLimitEnabled(limitEnabled); + try { + log.info("开始更新积分池限制配置: deptId={}, limitEnabled={}, limitPeriod={}, periodLimit={}, alertThreshold={}", + deptId, limitEnabled, limitPeriod, periodLimit, alertThreshold); + + TeamScorePool pool = upsertPool(deptId, null); + if (pool == null) { + throw new BusinessException("积分池不存在且创建失败: deptId=" + deptId); + } + + boolean hasUpdate = false; + if (limitEnabled != null) { + pool.setLimitEnabled(limitEnabled); + hasUpdate = true; + } + if (limitPeriod != null) { + pool.setLimitPeriod(limitPeriod); + hasUpdate = true; + } + if (periodLimit != null) { + pool.setPeriodLimit(periodLimit); + hasUpdate = true; + } + if (alertThreshold != null) { + pool.setAlertThreshold(alertThreshold); + hasUpdate = true; + } + if (pool.getPeriodStartTime() == null) { + pool.setPeriodStartTime(LocalDateTime.now()); + hasUpdate = true; + } + + if (hasUpdate) { + int rows = teamScorePoolMapper.updateById(pool); + log.info("更新积分池限制配置成功: deptId={}, affectedRows={}", deptId, rows); + } else { + log.warn("没有需要更新的积分池限制配置: deptId={}", deptId); + } + } catch (BusinessException e) { + log.error("更新积分池限制配置业务异常: deptId={}, error={}", deptId, e.getMessage()); + throw e; + } catch (Exception e) { + log.error("更新积分池限制配置失败: deptId={}, error={}", deptId, e.getMessage(), e); + throw new BusinessException("更新积分池限制配置失败: " + e.getMessage()); } - if (limitPeriod != null) { - pool.setLimitPeriod(limitPeriod); - } - if (periodLimit != null) { - pool.setPeriodLimit(periodLimit); - } - if (alertThreshold != null) { - pool.setAlertThreshold(alertThreshold); - } - if (pool.getPeriodStartTime() == null) { - pool.setPeriodStartTime(LocalDateTime.now()); - } - teamScorePoolMapper.updateById(pool); } /**