修复保存部门失败问题:添加详细错误处理和日志记录
This commit is contained in:
parent
e40cf047fa
commit
ec6a0d1838
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user