feat: 院校硕士研究生信息后台导入导出

This commit is contained in:
zhouwentao 2025-12-12 11:29:21 +08:00
parent 04bfc661c0
commit 1a9d4e87a2
1 changed files with 64 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.modules.yx.dto.YxSchoolDTO;
import org.jeecg.modules.yx.entity.*;
import org.jeecg.modules.yx.service.IYxSchoolGraduateDegreeService;
@ -174,19 +175,49 @@ public class YxSchoolGraduateDegreeController extends JeecgController<YxSchoolGr
return Result.error("文件数据过多请分批次1000条上传。");
}
Set<String> schoolNameSet = list.stream().map(YxSchoolGraduateDegree::getSchoolName).collect(Collectors.toSet());
List<YxSchool> yxSchoolList = yxSchoolService.list(new LambdaQueryWrapper<YxSchool>().select(YxSchool::getId).select(YxSchool::getSchoolName).in(YxSchool::getSchoolName, schoolNameSet));
List<YxSchool> yxSchoolList = yxSchoolService.list(new LambdaQueryWrapper<YxSchool>().select(YxSchool::getId, YxSchool::getSchoolName).in(YxSchool::getSchoolName, schoolNameSet));
Map<String, String> schoolNameIdMap = yxSchoolList.stream().collect(Collectors.toMap(YxSchool::getSchoolName, YxSchool::getId));
List<YxSchoolGraduateDegree> yxSchoolGraduateDegreeList = yxSchoolGraduateDegreeService.list(new LambdaQueryWrapper<YxSchoolGraduateDegree>().in(YxSchoolGraduateDegree::getSchoolName, schoolNameSet));
String schoolId = null;
String schoolName = null;
String year = null;
for (YxSchoolGraduateDegree yxSchoolGraduateDegree : list) {
schoolName = yxSchoolGraduateDegree.getSchoolName();
year = yxSchoolGraduateDegree.getYear();
schoolId = schoolNameIdMap.get(schoolId);
List<YxSchoolGraduateDegree> existingList = yxSchoolGraduateDegreeService.list(new LambdaQueryWrapper<YxSchoolGraduateDegree>().in(YxSchoolGraduateDegree::getSchoolName, schoolNameSet));
yxSchoolGraduateDegree.setSchoolId(schoolId);
// 构建已有数据的唯一键Map用于快速查找
Map<String, YxSchoolGraduateDegree> existingMap = existingList.stream().collect(Collectors.toMap(
this::buildUniqueKey,
item -> item,
(existing, replacement) -> existing
));
List<YxSchoolGraduateDegree> toInsertList = new ArrayList<>();
List<YxSchoolGraduateDegree> toUpdateList = new ArrayList<>();
for (YxSchoolGraduateDegree item : list) {
index++;
// 设置schoolId
String schoolId = schoolNameIdMap.get(item.getSchoolName());
AssertUtils.notNull(schoolId, String.format("第%s行未找到院校信息", index));
item.setSchoolId(schoolId);
// 根据唯一键判断是新增还是更新
String uniqueKey = buildUniqueKey(item);
YxSchoolGraduateDegree existingItem = existingMap.get(uniqueKey);
if (existingItem != null) {
// 已存在设置id进行更新
item.setId(existingItem.getId());
toUpdateList.add(item);
} else {
toInsertList.add(item);
}
}
// 批量新增
if (!toInsertList.isEmpty()) {
yxSchoolGraduateDegreeService.saveBatch(toInsertList, 100);
}
// 批量更新
if (!toUpdateList.isEmpty()) {
yxSchoolGraduateDegreeService.updateBatchById(toUpdateList, 100);
}
return Result.OK("导入成功!新增" + toInsertList.size() + "条,更新" + toUpdateList.size() + "");
}catch (Exception e){
System.out.println("索引:"+index);
String msg = e.getMessage();
@ -297,4 +328,27 @@ public class YxSchoolGraduateDegreeController extends JeecgController<YxSchoolGr
return Result.ok("文件导入成功!");
}
/**
* 构建唯一键年份+门类代码+门类名称+学科代码+学科领域+学位性质+专业编码+专业名称+研究方向+院校编码+院校名称
*/
private String buildUniqueKey(YxSchoolGraduateDegree item) {
return String.join("_",
nullToEmpty(item.getYear()),
nullToEmpty(item.getCategoryCode()),
nullToEmpty(item.getCategoryName()),
nullToEmpty(item.getSubjectCode()),
nullToEmpty(item.getDisciplineField()),
nullToEmpty(item.getDegreeNature()),
nullToEmpty(item.getMajorCode()),
nullToEmpty(item.getMajorName()),
nullToEmpty(item.getResearchDirection()),
nullToEmpty(item.getSchoolMasterCode()),
nullToEmpty(item.getSchoolName())
);
}
private String nullToEmpty(String str) {
return str == null ? "" : str;
}
}