This commit is contained in:
2026-08-14 09:04:58 +08:00
parent 863c4f5c13
commit ea13c4ea7c
16 changed files with 74 additions and 69 deletions
@@ -12,6 +12,7 @@ import com.yunhai.bschclassmanage.utils.LogContextHolder;
import com.yunhai.bschclassmanage.utils.RedisConstants;
import com.yunhai.bschclassmanage.utils.RedisUtil;
import com.yunhai.bschclassmanage.utils.UserContext;
import com.yunhai.platform.utils.exception.DException;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.BeanUtils;
@@ -77,7 +78,7 @@ public class BaseYearTermService implements IBaseYearTermService {
@Transactional(rollbackFor = Exception.class)
public void createNowYearTerm(UserContext.UserInfo user,BaseYearTerm entity){
if(getAllYearTerm().stream().anyMatch(s->s.getYear().equals(entity.getYear())))
throw new IllegalArgumentException("创建学年已存在!");
throw new DException("创建学年已存在!");
redisUtil.del(cacheKey);
baseYearTermRepository.save(entity);
{
@@ -112,11 +113,11 @@ public class BaseYearTermService implements IBaseYearTermService {
@Transactional(rollbackFor = Exception.class)
public void updateYearTerm(UserContext.UserInfo user,BaseYearTerm entity){
if (entity.getId() == null) {
throw new IllegalArgumentException("更新时ID不能为空");
throw new DException("更新时ID不能为空");
}
BaseYearTerm existing = baseYearTermRepository.findById(entity.getId())
.orElseThrow(() -> new IllegalArgumentException("学年记录不存在,ID=" + entity.getId()));
.orElseThrow(() -> new DException("学年记录不存在,ID=" + entity.getId()));
BaseYearTerm oldEntity = new BaseYearTerm();
BeanUtils.copyProperties(existing, oldEntity);
@@ -247,7 +248,7 @@ public class BaseYearTermService implements IBaseYearTermService {
public YearTerm getCurrentYearTerm() {
BaseYearTerm nowTerm = getNowYearTerm();
if (nowTerm == null) {
throw new IllegalStateException("当前学年未设置,请先配置学年学期");
throw new DException("当前学年未设置,请先配置学年学期");
}
int year = nowTerm.getYear();
int term = getCurrentTerm(); // 调用下面定义的 getCurrentTerm 方法
@@ -258,7 +259,7 @@ public class BaseYearTermService implements IBaseYearTermService {
public int getCurrentYear() {
BaseYearTerm nowTerm = getNowYearTerm();
if (nowTerm == null) {
throw new IllegalStateException("当前学年未设置");
throw new DException("当前学年未设置");
}
return nowTerm.getYear();
}
@@ -266,7 +267,7 @@ public class BaseYearTermService implements IBaseYearTermService {
public int getCurrentTerm() {
BaseYearTerm nowTerm = getNowYearTerm();
if (nowTerm == null) {
throw new IllegalStateException("当前学年未设置");
throw new DException("当前学年未设置");
}
Date now = new Date();
Date firstStart = nowTerm.getFirstTermStartDate();
@@ -283,6 +284,6 @@ public class BaseYearTermService implements IBaseYearTermService {
return 2;
}
}
throw new IllegalStateException("当前日期不在任何学期区间内,请检查学年学期配置");
throw new DException("当前日期不在任何学期区间内,请检查学年学期配置");
}
}