refactor: 根包由 com.bestsch.bschclassmanage 重命名为 com.yunhai.bschclassmanage

- git mv src/main/java/com/bestsch/bschclassmanage -> src/main/java/com/yunhai/bschclassmanage
- 255 个 Java 文件的 package/import 同步替换为 com.yunhai.bschclassmanage
- pom.xml 项目 groupId 设为 com.yunhai(与外部依赖 com.bestsch:bsch-* 无关,未改动)
- IDE 缓存 workspace.xml 路径同步更新(外部依赖坐标 com.bestsch:bsch-* 保持不动)
This commit is contained in:
Allen
2026-08-12 17:21:22 +08:00
parent 66cd0f1515
commit dc217ca7a9
258 changed files with 1082 additions and 1067 deletions
@@ -0,0 +1,211 @@
package com.yunhai.bschclassmanage.service.impl;
import com.yunhai.bschclassmanage.Repository.SchBinSchsystemRepository;
import com.yunhai.bschclassmanage.entity.BaseSchsystem;
import com.yunhai.bschclassmanage.entity.SchBinSchsystem;
import com.yunhai.bschclassmanage.enums.AcademicStage;
import com.yunhai.bschclassmanage.enums.SchType;
import com.yunhai.bschclassmanage.model.entityField.EntityFieldNames;
import com.yunhai.bschclassmanage.model.vo.AcademicStageSchsystemVO;
import com.yunhai.bschclassmanage.model.vo.SchSystemVO;
import com.yunhai.bschclassmanage.model.vo.SelectIntVO;
import com.yunhai.bschclassmanage.service.IBaseSchsystemGradeService;
import com.yunhai.bschclassmanage.service.IBaseSchsystemService;
import com.yunhai.bschclassmanage.service.ISchBinSchsystemService;
import com.yunhai.bschclassmanage.utils.RedisConstants;
import com.yunhai.bschclassmanage.utils.RedisUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.criteria.Predicate;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class SchBinSchsystemService implements ISchBinSchsystemService {
@Autowired
private SchBinSchsystemRepository schBinSchsystemRepository;
@Autowired
private IBaseSchsystemService baseSchsystemService;
@Autowired
private RedisUtil redisUtil;
public List<SchBinSchsystem> getSchBinSchsystemList(Integer schId){
Specification specification = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(root.get(EntityFieldNames.schId),schId));
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
};
return schBinSchsystemRepository.findAll(specification);
}
public List<Integer> getSchIds(){
return schBinSchsystemRepository.findAll().stream().map(s->s.getSchId()).distinct().collect(Collectors.toList());
}
public List<Integer> getSchBinSchsystemIds(Integer schId){
return getSchBinSchsystemList(schId).stream().map(s->s.getSchSystemId()).collect(Collectors.toList());
}
/**
* 获取学校关联的学段与学制映射(一个学段仅对应一个学制)
* @param schId 学校ID
* @return Map<学段ID, 学制ID>
*/
public Map<Integer, Integer> getAcademicStageToSchsystemMap(Integer schId) {
List<Integer> schsystemIds = getSchBinSchsystemIds(schId);
return baseSchsystemService.getSchsystemList().stream()
.filter(s -> schsystemIds.contains(s.getId()))
.collect(Collectors.toMap(
BaseSchsystem::getAcademicStage, // key: 学段ID
BaseSchsystem::getId, // value: 学制ID
(existing, replacement) -> existing // 若有重复,保留第一个(理论上不会发生)
));
}
public List<AcademicStageSchsystemVO> getAcademicStageSchsystemList(Integer schId) {
List<AcademicStage> academicStageEnumList = AcademicStage.list();
List<BaseSchsystem> baseSchSystemList = baseSchsystemService.getSchsystemList();
Set<Integer> checkedIdSet = new HashSet<>(getSchBinSchsystemIds(schId));
Map<Integer, List<BaseSchsystem>> groupByStage = baseSchSystemList.stream()
.filter(s -> s.getAcademicStage() != null)
.collect(Collectors.groupingBy(BaseSchsystem::getAcademicStage));
return academicStageEnumList.stream()
.map(stageEnum -> {
List<BaseSchsystem> stageSystems = groupByStage.getOrDefault(stageEnum.getKey(), Collections.emptyList());
List<SchSystemVO> schSystemVOList = stageSystems.stream()
.map(sys -> SchSystemVO.builder()
.id(sys.getId())
.name(sys.getName())
.checked(checkedIdSet.contains(sys.getId()))
.build())
.collect(Collectors.toList());
return AcademicStageSchsystemVO.builder()
.academicStageId(stageEnum.getKey())
.academicStageName(stageEnum.getValue())
.academicStageList(schSystemVOList)
.build();
})
.collect(Collectors.toList());
}
@Transactional(rollbackFor = Exception.class)
public void saveSchBinSchsystem(SchBinSchsystem entity, Integer[] schsystemIds) {
Integer schId=entity.getSchId();
List<SchBinSchsystem> existingList = getSchBinSchsystemList(schId);
if (!existingList.isEmpty()) {
schBinSchsystemRepository.deleteAll(existingList);
}
List<SchBinSchsystem> newList = new ArrayList<>(schsystemIds.length);
for (Integer systemId : schsystemIds) {
if (systemId == null) {
continue;
}
SchBinSchsystem newEntity = new SchBinSchsystem(); // ← 每次 new 一个新对象
// 如果需要复制 entity 的其他属性
BeanUtils.copyProperties(entity, newEntity);
newEntity.setSchSystemId(systemId);
newList.add(newEntity);
}
if (!newList.isEmpty()) {
schBinSchsystemRepository.saveAll(newList);
}
String cacheKey = RedisConstants.SCHOOL_GRAGE+"_"+schId;
redisUtil.del(cacheKey);
}
//获取学校类型
public Integer getSchType(Integer schId) {
Set<Integer> schsystemIds = getSchBinSchsystemList(schId)
.stream()
.map(s -> s.getSchSystemId())
.collect(Collectors.toSet());
Set<Integer> typeIds = baseSchsystemService.getSchsystemList()
.stream()
.filter(s -> schsystemIds.contains(s.getId()))
.map(s -> s.getType())
.collect(Collectors.toSet());
// 校验:类型必须唯一
if (typeIds.isEmpty()) {
throw new IllegalArgumentException("该学校未绑定任何学制,请先绑定");
}
if (typeIds.size() > 1) {
throw new IllegalArgumentException("该学校绑定了多种学制类型(" + typeIds + "),数据异常,请检查");
}
// 此时 typeIds 仅有一个元素,直接获取
Integer typeId = typeIds.iterator().next();
if(typeId.equals(SchType.VOCATIONALEDUCATION.getKey())&&schsystemIds.size()>1){
throw new IllegalArgumentException("该学校只能选择单个学制,请重新选择学制!");
}
// 从枚举中匹配该 typeId
return SchType.list().stream()
.filter(s -> s.getKey().equals(typeId))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("未找到对应的学制类型,typeId=" + typeId))
.getKey();
}
public List<SelectIntVO> selectSchBinSchsystem(Integer schId) {
// 1. 获取学校绑定的学制 ID 集合
List<SchBinSchsystem> binList = getSchBinSchsystemList(schId);
if (binList == null || binList.isEmpty()) {
return Collections.emptyList();
}
Set<Integer> schsystemIds = binList.stream()
.map(SchBinSchsystem::getSchSystemId)
.collect(Collectors.toSet());
// 2. 获取全部学制并过滤出绑定的
List<BaseSchsystem> allSystems = baseSchsystemService.getSchsystemList();
if (allSystems == null || allSystems.isEmpty()) {
return Collections.emptyList();
}
// 3. 转换为 SchSystemVO 列表,checked 固定为 true
return allSystems.stream()
.filter(s -> schsystemIds.contains(s.getId()))
.map(s -> {
SelectIntVO vo = new SelectIntVO();
vo.setId(s.getId());
vo.setName(s.getName());
return vo;
})
.collect(Collectors.toList());
}
public Map<Integer, String> getSchBinSchsystemMap(Integer schId) {
List<SelectIntVO> list= selectSchBinSchsystem(schId);
return list.stream()
.collect(Collectors.toMap(
SelectIntVO::getId, // key
SelectIntVO::getName, // value
(oldVal, newVal) -> oldVal // 若key冲突,保留旧值(理论上不会冲突)
));
}
}