|
@@ -1,6 +1,6 @@
|
|
package com.qmth.teachcloud.common.service.impl;
|
|
package com.qmth.teachcloud.common.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -26,7 +26,6 @@ import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
-import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -245,95 +244,131 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<BasicCourseParams> executeImportBasicCourseLogic(MultipartFile file) throws IOException, NoSuchFieldException {
|
|
public List<BasicCourseParams> executeImportBasicCourseLogic(MultipartFile file) throws IOException, NoSuchFieldException {
|
|
|
|
+ Map<Integer,List<String>> errorMap = new HashMap<>();
|
|
InputStream inputStream = file.getInputStream();
|
|
InputStream inputStream = file.getInputStream();
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicCourseImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicCourseImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
- List<ExcelError> excelErrorTemp = new ArrayList<>();
|
|
|
|
Map<String, BasicCourseImportDto> courseDtoMap = new HashMap<>();
|
|
Map<String, BasicCourseImportDto> courseDtoMap = new HashMap<>();
|
|
for (int i = 0; i < finalExcelList.size(); i++) {
|
|
for (int i = 0; i < finalExcelList.size(); i++) {
|
|
LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
- assert basicCourseImportDtoList != null;
|
|
|
|
- if (basicCourseImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
List<BasicCourseImportDto> duplicateData = new ArrayList<>();
|
|
List<BasicCourseImportDto> duplicateData = new ArrayList<>();
|
|
for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(y);
|
|
BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(y);
|
|
|
|
+ basicCourseImportDto.setRowIndex(y + 1);
|
|
String courseName = basicCourseImportDto.getCourseName();
|
|
String courseName = basicCourseImportDto.getCourseName();
|
|
String courseCode = basicCourseImportDto.getCourseCode();
|
|
String courseCode = basicCourseImportDto.getCourseCode();
|
|
String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
String clazz = basicCourseImportDto.getClazz();
|
|
String clazz = basicCourseImportDto.getClazz();
|
|
String name = basicCourseImportDto.getName();
|
|
String name = basicCourseImportDto.getName();
|
|
String code = basicCourseImportDto.getCode();
|
|
String code = basicCourseImportDto.getCode();
|
|
-
|
|
|
|
- if (courseDtoMap.containsKey(courseCode)) {
|
|
|
|
- BasicCourseImportDto primaryCell = courseDtoMap.get(courseCode);
|
|
|
|
- String primaryName = primaryCell.getCourseName();
|
|
|
|
- String primaryTeachingRoomName = primaryCell.getTeachingRoomName();
|
|
|
|
- if (!Objects.equals(primaryName, courseName)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("【课程编号】 : " + courseCode + ",存在不同的【课程名称】");
|
|
|
|
- }
|
|
|
|
- if (!Objects.equals(primaryTeachingRoomName, teachingRoomName)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("【课程编号】 : " + courseCode + ",存在不同的【所属教研室】");
|
|
|
|
|
|
+ String emptyCheckError = ExcelUtil.checkExcelField(basicCourseImportDto);
|
|
|
|
+ if (SystemConstant.strNotNull(emptyCheckError)) {
|
|
|
|
+ if (errorMap.containsKey(y + 1)) {
|
|
|
|
+ errorMap.get(y + 1).add(emptyCheckError);
|
|
|
|
+ } else {
|
|
|
|
+ List<String> errorInfo = new ArrayList<>();
|
|
|
|
+ errorInfo.add(emptyCheckError);
|
|
|
|
+ errorMap.put(y + 1, errorInfo);
|
|
}
|
|
}
|
|
- String primaryClazz = primaryCell.getClazz();
|
|
|
|
- if (SystemConstant.strNotNull(clazz)) {
|
|
|
|
- primaryClazz = primaryClazz + SystemConstant.COMMA + clazz;
|
|
|
|
- primaryCell.setClazz(primaryClazz);
|
|
|
|
- }
|
|
|
|
- duplicateData.add(basicCourseImportDto);
|
|
|
|
} else {
|
|
} else {
|
|
- courseDtoMap.put(courseCode, basicCourseImportDto);
|
|
|
|
|
|
+ if (courseDtoMap.containsKey(courseCode)) {
|
|
|
|
+ BasicCourseImportDto primaryCell = courseDtoMap.get(courseCode);
|
|
|
|
+ String primaryName = primaryCell.getCourseName();
|
|
|
|
+ String primaryTeachingRoomName = primaryCell.getTeachingRoomName();
|
|
|
|
+ if (!Objects.equals(primaryName, courseName)) {
|
|
|
|
+ String cellException = "【课程编号】 : " + courseCode + ",存在不同的【课程名称】";
|
|
|
|
+ this.updateErrorInfoMap(errorMap, y + 1, cellException);
|
|
|
|
+ }
|
|
|
|
+ if (!Objects.equals(primaryTeachingRoomName, teachingRoomName)) {
|
|
|
|
+ String cellException = "【课程编号】 : " + courseCode + ",存在不同的【所属教研室】";
|
|
|
|
+ this.updateErrorInfoMap(errorMap, y + 1, cellException);
|
|
|
|
+ }
|
|
|
|
+ String primaryClazz = primaryCell.getClazz();
|
|
|
|
+ if (SystemConstant.strNotNull(clazz)) {
|
|
|
|
+ primaryClazz = primaryClazz + SystemConstant.COMMA + clazz;
|
|
|
|
+ primaryCell.setClazz(primaryClazz);
|
|
|
|
+ }
|
|
|
|
+ duplicateData.add(basicCourseImportDto);
|
|
|
|
+ } else {
|
|
|
|
+ courseDtoMap.put(courseCode, basicCourseImportDto);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- excelErrorTemp.addAll(ExcelUtil.checkExcelField(basicCourseImportDto, y, i));
|
|
|
|
if (Objects.nonNull(courseCode) && !courseCode.matches(SystemConstant.REGULAR_EXPRESSION_OF_CODE)) {
|
|
if (Objects.nonNull(courseCode) && !courseCode.matches(SystemConstant.REGULAR_EXPRESSION_OF_CODE)) {
|
|
- excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程编号]不符合输入规范"));
|
|
|
|
- }
|
|
|
|
- if ((Objects.nonNull(name) && !Objects.equals(name.trim(), "")) && (Objects.isNull(code) || Objects.equals(code.trim(), ""))) {
|
|
|
|
- excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[工号]不能为空"));
|
|
|
|
- }
|
|
|
|
- if ((Objects.nonNull(code) && !Objects.equals(code.trim(), "")) && (Objects.isNull(name) || Objects.equals(name.trim(), ""))) {
|
|
|
|
- excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[姓名]不能为空"));
|
|
|
|
|
|
+ this.updateErrorInfoMap(errorMap, y + 1, "[课程编号]不符合输入规范");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 删除重复的(需要累加的)excel数据
|
|
// 删除重复的(需要累加的)excel数据
|
|
basicCourseImportDtoList.removeAll(duplicateData);
|
|
basicCourseImportDtoList.removeAll(duplicateData);
|
|
}
|
|
}
|
|
- if (excelErrorTemp.size() > 0) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(excelErrorTemp));
|
|
|
|
- }
|
|
|
|
return finalExcelList;
|
|
return finalExcelList;
|
|
},2);
|
|
},2);
|
|
- return this.executeBasicCourseImportLogic(finalList);
|
|
|
|
|
|
+ return this.executeBasicCourseImportLogic(finalList,errorMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateErrorInfoMap(Map<Integer,List<String>> errorMap,Integer key,String exception) {
|
|
|
|
+ if (errorMap.containsKey(key)) {
|
|
|
|
+ errorMap.get(key).add(exception);
|
|
|
|
+ } else {
|
|
|
|
+ List<String> errorInfo = new ArrayList<>();
|
|
|
|
+ errorInfo.add(exception);
|
|
|
|
+ errorMap.put(key, errorInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 解析异常信息
|
|
|
|
+ *
|
|
|
|
+ * @param exceptionMap 异常信息
|
|
|
|
+ */
|
|
|
|
+ private void analyzeException(Map<Integer, List<String>> exceptionMap) {
|
|
|
|
+ System.out.println(JSON.toJSONString(exceptionMap));
|
|
|
|
+ StringBuilder exception = new StringBuilder();
|
|
|
|
+ for (Integer rowIndex : exceptionMap.keySet()) {
|
|
|
|
+ String rowInfo;
|
|
|
|
+ if (rowIndex > 0) {
|
|
|
|
+ rowInfo = "excel中第【" + rowIndex + "】行 : ";
|
|
|
|
+ } else {
|
|
|
|
+ rowInfo = "excel中存在异常:";
|
|
|
|
+ }
|
|
|
|
+ List<String> exceptionList = exceptionMap.get(rowIndex);
|
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(exceptionList)) {
|
|
|
|
+ for (String e : exceptionList) {
|
|
|
|
+ String cell = rowInfo + e + "\n";
|
|
|
|
+ exception.append(cell);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println(exception);
|
|
|
|
+ if (exception.length() > 0) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(exception.toString());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
- public List<BasicCourseParams> executeBasicCourseImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList) {
|
|
|
|
|
|
+ public List<BasicCourseParams> executeBasicCourseImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList,Map<Integer,List<String>> errorMap) {
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
Long schoolId = sysUser.getSchoolId();
|
|
Long schoolId = sysUser.getSchoolId();
|
|
List<BasicCourseParams> addBasicCourseParamsList = new ArrayList<>();
|
|
List<BasicCourseParams> addBasicCourseParamsList = new ArrayList<>();
|
|
for (int i = 0; i < finalList.size(); i++) {
|
|
for (int i = 0; i < finalList.size(); i++) {
|
|
LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
- assert basicCourseImportDtoList != null;
|
|
|
|
- if (basicCourseImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(y);
|
|
BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(y);
|
|
String courseName = basicCourseImportDto.getCourseName();
|
|
String courseName = basicCourseImportDto.getCourseName();
|
|
String courseCode = basicCourseImportDto.getCourseCode();
|
|
String courseCode = basicCourseImportDto.getCourseCode();
|
|
String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
String clazz = basicCourseImportDto.getClazz();
|
|
String clazz = basicCourseImportDto.getClazz();
|
|
|
|
+ // 原始excel中的行索引
|
|
|
|
+ Integer rowIndex = basicCourseImportDto.getRowIndex();
|
|
|
|
|
|
SysOrg sysOrg = sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
|
|
SysOrg sysOrg = sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
|
|
.eq(SysOrg::getSchoolId, schoolId)
|
|
.eq(SysOrg::getSchoolId, schoolId)
|
|
.eq(SysOrg::getEnable, true)
|
|
.eq(SysOrg::getEnable, true)
|
|
.eq(SysOrg::getName, teachingRoomName));
|
|
.eq(SysOrg::getName, teachingRoomName));
|
|
if (Objects.isNull(sysOrg)) {
|
|
if (Objects.isNull(sysOrg)) {
|
|
- throw ExceptionResultEnum.ERROR.exception("输入的开课学院【" + teachingRoomName + "】不存在");
|
|
|
|
|
|
+ this.updateErrorInfoMap(errorMap,rowIndex,"输入的开课学院【" + teachingRoomName + "】不存在");
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
Long teachingRoomId = sysOrg.getId();
|
|
Long teachingRoomId = sysOrg.getId();
|
|
LinkedHashSet<Long> clazzIdSet = new LinkedHashSet<>(), teachIdSet = new LinkedHashSet<>();
|
|
LinkedHashSet<Long> clazzIdSet = new LinkedHashSet<>(), teachIdSet = new LinkedHashSet<>();
|
|
@@ -345,7 +380,8 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
.eq(BasicClazz::getSchoolId, schoolId)
|
|
.eq(BasicClazz::getSchoolId, schoolId)
|
|
.eq(BasicClazz::getClazzName, clzName));
|
|
.eq(BasicClazz::getClazzName, clzName));
|
|
if (Objects.isNull(basicClazz)) {
|
|
if (Objects.isNull(basicClazz)) {
|
|
- throw ExceptionResultEnum.ERROR.exception("所选择【班级】" + clzName + "不存在");
|
|
|
|
|
|
+ this.updateErrorInfoMap(errorMap,rowIndex,"所选择【班级】" + clzName + "不存在");
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
clazzIdSet.add(basicClazz.getId());
|
|
clazzIdSet.add(basicClazz.getId());
|
|
}
|
|
}
|
|
@@ -357,7 +393,8 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
codeList = basicCourseImportDto.getCode().split(SystemConstant.COMMA);
|
|
codeList = basicCourseImportDto.getCode().split(SystemConstant.COMMA);
|
|
}
|
|
}
|
|
if (Objects.nonNull(codeList) && codeList.length != nameList.length) {
|
|
if (Objects.nonNull(codeList) && codeList.length != nameList.length) {
|
|
- throw ExceptionResultEnum.ERROR.exception("姓名和工号长度不匹配");
|
|
|
|
|
|
+ this.updateErrorInfoMap(errorMap, rowIndex, "姓名和工号长度不匹配");
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
for (int k = 0; k < nameList.length; k++) {
|
|
for (int k = 0; k < nameList.length; k++) {
|
|
String name = nameList[k].trim();
|
|
String name = nameList[k].trim();
|
|
@@ -367,12 +404,16 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
.eq(SysUser::getSchoolId, schoolId)
|
|
.eq(SysUser::getSchoolId, schoolId)
|
|
.eq(SysUser::getRealName, name)
|
|
.eq(SysUser::getRealName, name)
|
|
.eq(SysUser::getCode, code));
|
|
.eq(SysUser::getCode, code));
|
|
- Optional.ofNullable(sysUserDb).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("【姓名】" + name + ",【工号】" + code + "不存在"));
|
|
|
|
|
|
+ if (Objects.isNull(sysUserDb)) {
|
|
|
|
+ this.updateErrorInfoMap(errorMap, rowIndex, "【姓名】" + name + ",【工号】" + code + "不存在");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
List<SysRole> sysRoleList = sysUserRoleService.listRoleByUserId(sysUserDb.getId());
|
|
List<SysRole> sysRoleList = sysUserRoleService.listRoleByUserId(sysUserDb.getId());
|
|
sysRoleList = sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.SCHOOL_TEACHER).collect(Collectors.toList());
|
|
sysRoleList = sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.SCHOOL_TEACHER).collect(Collectors.toList());
|
|
if (CollectionUtils.isEmpty(sysRoleList)) {
|
|
if (CollectionUtils.isEmpty(sysRoleList)) {
|
|
- throw ExceptionResultEnum.ERROR.exception("【姓名】" + name + ",【工号】" + code + "没有老师角色");
|
|
|
|
|
|
+ this.updateErrorInfoMap(errorMap, rowIndex, "【姓名】" + name + ",【工号】" + code + "没有老师角色");
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
teachIdSet.add(sysUserDb.getId());
|
|
teachIdSet.add(sysUserDb.getId());
|
|
}
|
|
}
|
|
@@ -393,6 +434,9 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
}
|
|
}
|
|
addBasicCourseParamsList.add(basicCourseParams);
|
|
addBasicCourseParamsList.add(basicCourseParams);
|
|
}
|
|
}
|
|
|
|
+ // 解析异常
|
|
|
|
+ this.analyzeException(errorMap);
|
|
|
|
+
|
|
List<BasicCourse> editBasicCourse = this.editEntityHelp(addBasicCourseParamsList, sysUser);
|
|
List<BasicCourse> editBasicCourse = this.editEntityHelp(addBasicCourseParamsList, sysUser);
|
|
try {
|
|
try {
|
|
this.saveOrUpdateBatch(editBasicCourse);
|
|
this.saveOrUpdateBatch(editBasicCourse);
|