|
@@ -1,6 +1,5 @@
|
|
|
package com.qmth.teachcloud.common.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -8,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
+import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.teachcloud.common.base.BaseEntity;
|
|
|
import com.qmth.teachcloud.common.bean.dto.BasicCourseExportDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
@@ -27,12 +28,13 @@ import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
import com.qmth.teachcloud.common.util.JdbcErrorUtil;
|
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
import org.springframework.jdbc.BadSqlGrammarException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -151,30 +153,34 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Long saveBasicCourse(BasicCourseParams basicCourseParams, SysUser sysUser) {
|
|
|
- List<BasicCourseParams> basicCourseParamsList = new ArrayList<>();
|
|
|
- basicCourseParamsList.add(basicCourseParams);
|
|
|
- BasicCourse editBasicCourse = this.editEntityHelp(basicCourseParamsList, sysUser).get(0);
|
|
|
- try {
|
|
|
- this.saveOrUpdate(editBasicCourse);
|
|
|
- // 同步更新命题任务中的课程名称
|
|
|
- this.baseMapper.updateCourseNameFormExamTask(sysUser.getSchoolId(), editBasicCourse.getCode(),
|
|
|
- editBasicCourse.getName());
|
|
|
- // 以下表中course_name要也同步更新
|
|
|
-// client_status,exam_card,exam_detail_course,exam_paper_structure,exam_task,exam_task_print
|
|
|
-// mark_document,mark_group,mark_paper,mark_paper_package,mark_student,mark_task,
|
|
|
-// t_b_sync_task,t_b_task,t_c_final_score,t_c_paper_struct,t_c_statistics,t_c_usual_score,t_r_basic_info
|
|
|
- } catch (Exception e) {
|
|
|
- if (e instanceof DataIntegrityViolationException || e instanceof BadSqlGrammarException) {
|
|
|
- String content = JdbcErrorUtil.parseErrorMsg(e.getMessage());
|
|
|
- throw ExceptionResultEnum.SQL_ERROR.exception(content);
|
|
|
- } else if (e instanceof ApiException) {
|
|
|
- ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
|
+ public Long saveBasicCourse(BasicCourseParams basicCourseParams) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ SysOrg sysOrg = sysOrgService.getById(basicCourseParams.getTeachingRoomId());
|
|
|
+ if (sysOrg == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("开课学院[" + sysOrg.getName() + "]在组织架构中不存在");
|
|
|
+ }
|
|
|
+ BasicCourse basicCourse = this.getByTeachRoomIdAndCode(basicCourseParams.getTeachingRoomId(), basicCourseParams.getCourseCode());
|
|
|
+ if (basicCourseParams.getId() == null) {
|
|
|
+ // 校验课程代码和开课学院
|
|
|
+ if (basicCourse != null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("开课学院[" + sysOrg.getName() + "]下已存在课程代码[" + basicCourseParams.getCourseCode() + "]的课程");
|
|
|
} else {
|
|
|
- ResultUtil.error(e.getMessage());
|
|
|
+ basicCourse = new BasicCourse(sysUser.getSchoolId(), basicCourseParams.getTeachingRoomId(), basicCourseParams.getCourseCode(), basicCourseParams.getCourseCode());
|
|
|
+ basicCourse.insertInfo(sysUser.getId());
|
|
|
+ this.save(basicCourse);
|
|
|
+ return basicCourse.getId();
|
|
|
}
|
|
|
+ } else {
|
|
|
+ if(basicCourse != null && !basicCourse.getId().equals(basicCourseParams.getId())){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("开课学院[" + sysOrg.getName() + "]下已存在课程代码[" + basicCourseParams.getCourseCode() + "]的课程");
|
|
|
+ }
|
|
|
+ BasicCourse editBasicCourse = this.getById(basicCourseParams.getId());
|
|
|
+ editBasicCourse.setName(basicCourseParams.getCourseName());
|
|
|
+ editBasicCourse.setTeachingRoomId(basicCourseParams.getTeachingRoomId());
|
|
|
+ editBasicCourse.updateInfo(sysUser.getId());
|
|
|
+ this.updateById(editBasicCourse);
|
|
|
+ return editBasicCourse.getId();
|
|
|
}
|
|
|
- return editBasicCourse.getId();
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -253,168 +259,6 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
|
return idList.size() > 0 ? this.removeBasicCourseBatch(idList) : true;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<BasicCourseParams> executeImportBasicCourseLogic(MultipartFile file) throws IOException, NoSuchFieldException {
|
|
|
- Map<Integer, List<String>> errorMap = new HashMap<>();
|
|
|
- InputStream inputStream = file.getInputStream();
|
|
|
- List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicCourseImportDto.class, DescribeImportDto.class),
|
|
|
- (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
- Map<String, BasicCourseImportDto> courseDtoMap = new HashMap<>();
|
|
|
- for (int i = 0; i < finalExcelList.size(); i++) {
|
|
|
- LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
|
- List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
|
- List<BasicCourseImportDto> duplicateData = new ArrayList<>();
|
|
|
- for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
|
- BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(
|
|
|
- y);
|
|
|
- basicCourseImportDto.setRowIndex(y + 1);
|
|
|
- String courseName = basicCourseImportDto.getCourseName();
|
|
|
- String courseCode = basicCourseImportDto.getCourseCode();
|
|
|
- String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- } else {
|
|
|
- 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);
|
|
|
- }
|
|
|
- duplicateData.add(basicCourseImportDto);
|
|
|
- } else {
|
|
|
- courseDtoMap.put(courseCode, basicCourseImportDto);
|
|
|
- }
|
|
|
- }
|
|
|
- if (Objects.nonNull(courseCode) && (!courseCode.matches(SystemConstant.REGULAR_EXPRESSION_OF_CODE)
|
|
|
- || courseCode.length() < 3 || courseCode.length() > 30)) {
|
|
|
- this.updateErrorInfoMap(errorMap, y + 1, "课程编码[" + courseCode + "]不符合输入规范");
|
|
|
- }
|
|
|
- }
|
|
|
- // 删除重复的(需要累加的)excel数据
|
|
|
- basicCourseImportDtoList.removeAll(duplicateData);
|
|
|
- }
|
|
|
- return finalExcelList;
|
|
|
- }, 2);
|
|
|
- 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)
|
|
|
- @Override
|
|
|
- public List<BasicCourseParams> executeBasicCourseImportLogic(List<LinkedMultiValueMap<Integer, Object>> finalList,
|
|
|
- Map<Integer, List<String>> errorMap) {
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- Long schoolId = sysUser.getSchoolId();
|
|
|
- List<BasicCourseParams> addBasicCourseParamsList = new ArrayList<>();
|
|
|
- for (int i = 0; i < finalList.size(); i++) {
|
|
|
- LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
- List<Object> basicCourseImportDtoList = excelMap.get(i);
|
|
|
- for (int y = 0; y < Objects.requireNonNull(basicCourseImportDtoList).size(); y++) {
|
|
|
- BasicCourseImportDto basicCourseImportDto = (BasicCourseImportDto) basicCourseImportDtoList.get(y);
|
|
|
- String courseName = basicCourseImportDto.getCourseName();
|
|
|
- String courseCode = basicCourseImportDto.getCourseCode();
|
|
|
- String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
|
-
|
|
|
- // 原始excel中的行索引
|
|
|
- Integer rowIndex = basicCourseImportDto.getRowIndex();
|
|
|
-
|
|
|
- SysOrg sysOrg = sysOrgService.getOne(
|
|
|
- new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId, schoolId).eq(SysOrg::getEnable, true).eq(SysOrg::getName, teachingRoomName));
|
|
|
- if (Objects.isNull(sysOrg)) {
|
|
|
- this.updateErrorInfoMap(errorMap, rowIndex, "输入的开课学院[" + teachingRoomName + "]不存在");
|
|
|
- continue;
|
|
|
- }
|
|
|
- Long teachingRoomId = sysOrg.getId();
|
|
|
-
|
|
|
- BasicCourseParams basicCourseParams = new BasicCourseParams();
|
|
|
- basicCourseParams.setCourseCode(courseCode);
|
|
|
- basicCourseParams.setCourseName(courseName);
|
|
|
- basicCourseParams.setTeachingRoomId(teachingRoomId);
|
|
|
- BasicCourse old = this.getOne(
|
|
|
- new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId).eq(BasicCourse::getEnable, true).eq(BasicCourse::getCode, courseCode));
|
|
|
- if (Objects.nonNull(old)) {
|
|
|
- basicCourseParams.setId(old.getId());
|
|
|
- }
|
|
|
- addBasicCourseParamsList.add(basicCourseParams);
|
|
|
- }
|
|
|
- // 解析异常
|
|
|
- this.analyzeException(errorMap);
|
|
|
-
|
|
|
- List<BasicCourse> editBasicCourse = this.editEntityHelp(addBasicCourseParamsList, sysUser);
|
|
|
- try {
|
|
|
- this.saveOrUpdateBatch(editBasicCourse);
|
|
|
-
|
|
|
- // 同步更新命题任务中的课程名称
|
|
|
- for (BasicCourse basicCourse : editBasicCourse) {
|
|
|
- this.baseMapper.updateCourseNameFormExamTask(sysUser.getSchoolId(), basicCourse.getCode(),
|
|
|
- basicCourse.getName());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- if (e instanceof DataIntegrityViolationException || e instanceof BadSqlGrammarException) {
|
|
|
- String content = JdbcErrorUtil.parseErrorMsg(e.getMessage());
|
|
|
- throw ExceptionResultEnum.SQL_ERROR.exception(content);
|
|
|
- } else if (e instanceof ApiException) {
|
|
|
- ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
|
- } else {
|
|
|
- ResultUtil.error(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return addBasicCourseParamsList;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Long getOrgIdBySchoolIdAndCourseCode(Long schoolId, String courseCode) {
|
|
|
if (Objects.isNull(schoolId)) {
|
|
@@ -469,7 +313,7 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
|
List<String> occupiedCourseCodeList = this.baseMapper.findOccupiedCourseCode(examId, requestUser.getId());
|
|
|
LambdaQueryWrapper<BasicCourse> lambda = new QueryWrapper<BasicCourse>().lambda();
|
|
|
lambda.in(BasicCourse::getTeachingRoomId, orgIdSet).orderByAsc(BasicCourse::getOrgId);
|
|
|
- if(StringUtils.isNotBlank(courseName)){
|
|
|
+ if (StringUtils.isNotBlank(courseName)) {
|
|
|
lambda.like(BasicCourse::getName, courseName);
|
|
|
}
|
|
|
result = this.list(lambda).stream().filter(e -> !occupiedCourseCodeList.contains(e.getCode())).flatMap(e -> {
|
|
@@ -493,86 +337,69 @@ public class BasicCourseServiceImpl extends ServiceImpl<BasicCourseMapper, Basic
|
|
|
return this.getOne(queryWrapper);
|
|
|
}
|
|
|
|
|
|
- private List<BasicCourse> editEntityHelp(List<BasicCourseParams> basicCourseParamsList, SysUser sysUser) {
|
|
|
- Long schoolId = sysUser.getSchoolId();
|
|
|
- List<BasicCourse> basicCourseList = new ArrayList<>();
|
|
|
- for (BasicCourseParams basicCourseParams : basicCourseParamsList) {
|
|
|
- Long id = basicCourseParams.getId();
|
|
|
- String courseName = basicCourseParams.getCourseName();
|
|
|
- // 校验课程编号
|
|
|
- String courseCode = basicCourseParams.getCourseCode();
|
|
|
- BasicCourse checkCode = this.getOne(
|
|
|
- new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getCode, courseCode).eq(BasicCourse::getSchoolId, schoolId).eq(BasicCourse::getEnable, true));
|
|
|
- if (Objects.nonNull(checkCode)) {
|
|
|
- if (!checkCode.getId().equals(id)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("课程编码[" + courseCode + "]重复");
|
|
|
- }
|
|
|
- }
|
|
|
- // 校验教研室id
|
|
|
- Long teachingRoomId = basicCourseParams.getTeachingRoomId();
|
|
|
- // if (Objects.isNull(sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
|
|
|
- // .eq(SysOrg::getId, teachingRoomId)
|
|
|
- // .eq(SysOrg::getEnable, true)
|
|
|
- // .eq(SysOrg::getType, OrgTypeEnum.TEACHING_ROOM)))) {
|
|
|
- // throw ExceptionResultEnum.ERROR.exception("所选教研室不存在");
|
|
|
- // }
|
|
|
- // 校验班级
|
|
|
-
|
|
|
- //基础数据组装
|
|
|
- Long orgId;
|
|
|
- BasicCourse basicCourse = new BasicCourse();
|
|
|
- basicCourse.setName(courseName);
|
|
|
- basicCourse.setCode(courseCode);
|
|
|
- basicCourse.setTeachingRoomId(teachingRoomId);
|
|
|
- basicCourse.setSchoolId(schoolId);
|
|
|
|
|
|
- if (!SystemConstant.longNotNull(id)) {
|
|
|
- // 没有id -》新增
|
|
|
- id = SystemConstant.getDbUuid();
|
|
|
- basicCourse.setId(id);
|
|
|
- basicCourse.setCreateId(sysUser.getId());
|
|
|
- basicCourse.setEnable(true);
|
|
|
- // 生成简码
|
|
|
- String shortCode = createShortCode(schoolId);
|
|
|
- basicCourse.setShortCode(shortCode);
|
|
|
- orgId = sysUser.getOrgId();
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void importBasicCourse(MultipartFile file) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ try {
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+ ExcelReader excelReader;
|
|
|
+ if (SystemConstant.XLS.equals(extension)) {
|
|
|
+ excelReader = ExcelReader.create(ExcelType.XLS, inputStream, 1);
|
|
|
+ } else if (SystemConstant.XLSX.equals(extension)) {
|
|
|
+ excelReader = ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
} else {
|
|
|
- // 有id -》 更新
|
|
|
- BasicCourse old = this.getById(id);
|
|
|
- if (Objects.isNull(old) || old.getEnable().equals(false)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("课程主键不存在或被禁用");
|
|
|
- }
|
|
|
- orgId = old.getOrgId();
|
|
|
- basicCourse.setId(id);
|
|
|
- basicCourse.setUpdateId(sysUser.getId());
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只能导入后缀为.xls或.xlsx文件");
|
|
|
}
|
|
|
- basicCourseParams.setId(basicCourse.getId());
|
|
|
- basicCourse.setOrgId(orgId);
|
|
|
|
|
|
- basicCourseList.add(basicCourse);
|
|
|
+ List<BasicCourseImportDto> courseImportDtoList = excelReader.getObjectList(BasicCourseImportDto.class);
|
|
|
+ if (CollectionUtils.isEmpty(courseImportDtoList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未读取到有效数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (BasicCourseImportDto basicCourseImportDto : courseImportDtoList) {
|
|
|
+ String courseName = basicCourseImportDto.getCourseName();
|
|
|
+ String courseCode = basicCourseImportDto.getCourseCode();
|
|
|
+ String teachingRoomName = basicCourseImportDto.getTeachingRoomName();
|
|
|
+ if (StringUtils.isBlank(courseName) || StringUtils.isBlank(courseCode) || StringUtils.isBlank(teachingRoomName)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程名称、课程代码、开课学院不能为空");
|
|
|
+ }
|
|
|
+ // 去空格
|
|
|
+ courseName = StringUtils.deleteWhitespace(courseName);
|
|
|
+ courseCode = StringUtils.deleteWhitespace(courseCode);
|
|
|
+ teachingRoomName = StringUtils.deleteWhitespace(teachingRoomName);
|
|
|
+ // 校验开课学院
|
|
|
+ List<SysOrg> sysOrgList = sysOrgService.getSecondOrg(sysUser.getSchoolId(), teachingRoomName);
|
|
|
+ if (CollectionUtils.isEmpty(sysOrgList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("开课学院[" + teachingRoomName + "]在学院层级不存在");
|
|
|
+ }
|
|
|
+ SysOrg sysOrg = sysOrgList.get(0);
|
|
|
+ // 校验课程代码和开课学院
|
|
|
+ BasicCourse basicCourse = this.getByTeachRoomIdAndCode(sysOrg.getId(), courseCode);
|
|
|
+ if (basicCourse != null) {
|
|
|
+ basicCourse.setName(courseName);
|
|
|
+ basicCourse.setUpdateId(sysUser.getId());
|
|
|
+ basicCourse.setUpdateTime(System.currentTimeMillis());
|
|
|
+ basicCourse.setEnable(true);
|
|
|
+ } else {
|
|
|
+ basicCourse = new BasicCourse(sysUser.getSchoolId(), sysOrg.getId(), courseCode, courseName);
|
|
|
+ basicCourse.insertInfo(sysUser.getId());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(basicCourse);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("导入失败:" + e.getMessage());
|
|
|
}
|
|
|
- return basicCourseList;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 生成考试简码
|
|
|
- *
|
|
|
- * @param schoolId 学校ID
|
|
|
- */
|
|
|
- private String createShortCode(Long schoolId) {
|
|
|
+ @Override
|
|
|
+ public BasicCourse getByTeachRoomIdAndCode(Long teachRoomId, String courseCode) {
|
|
|
QueryWrapper<BasicCourse> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.lambda().eq(BasicCourse::getSchoolId, schoolId);
|
|
|
- List<BasicCourse> basicCourses = this.baseMapper.selectList(queryWrapper);
|
|
|
- if (basicCourses.isEmpty()) {
|
|
|
- return "001";
|
|
|
- } else {
|
|
|
- Optional<BasicCourse> max = basicCourses.stream().filter(m -> StringUtils.isNotBlank(m.getShortCode())).max(Comparator.comparing(BasicCourse::getShortCode));
|
|
|
- if (!max.isPresent()) {
|
|
|
- return "001";
|
|
|
- }
|
|
|
- String maxShortCode = max.get().getShortCode();
|
|
|
- int shortCode = StringUtils.isBlank(maxShortCode) ? 0 : Integer.parseInt(maxShortCode);
|
|
|
- return String.format("%03d", shortCode + 1);
|
|
|
- }
|
|
|
+ queryWrapper.lambda().eq(BasicCourse::getTeachingRoomId, teachRoomId)
|
|
|
+ .eq(BasicCourse::getCode, courseCode);
|
|
|
+ return this.getOne(queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
}
|