|
@@ -1,10 +1,11 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.CourseDimensionImportDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.CourseDimensionMd5Dto;
|
|
|
import com.qmth.distributed.print.business.entity.CourseDimension;
|
|
|
import com.qmth.distributed.print.business.entity.TeachCourse;
|
|
|
import com.qmth.distributed.print.business.enums.CourseDimensionCodeEnum;
|
|
@@ -21,6 +22,7 @@ import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.kit.TikuUtils;
|
|
|
import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -34,6 +36,7 @@ import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -183,15 +186,14 @@ public class CourseDimensionServiceImpl extends ServiceImpl<CourseDimensionMappe
|
|
|
}
|
|
|
Long semesterId = SystemConstant.convertIdToLong(basicExam.getSemesterId());
|
|
|
|
|
|
- if (this.count(new QueryWrapper<CourseDimension>().lambda().eq(CourseDimension::getTeachCourseId, teachCourseId)
|
|
|
- .ne(CourseDimension::getSource, CourseDimensionSourceEnum.UNION_QUESTION)) == 0) {
|
|
|
+ List<CourseDimension> courseDimensionList = this.list(
|
|
|
+ new QueryWrapper<CourseDimension>().lambda().eq(CourseDimension::getTeachCourseId, teachCourseId));
|
|
|
+
|
|
|
+ if (courseDimensionList.stream().noneMatch(e -> CourseDimensionSourceEnum.IMPORT.equals(e.getSource()))) {
|
|
|
// 表里没有导入的知识点记录,从题库获取
|
|
|
List<TikuCourseProperty> tikuDimensionList = tikuUtils.listCourseProperty(teachCourse.getSchoolId(),
|
|
|
courseCode);
|
|
|
if (CollectionUtils.isNotEmpty(tikuDimensionList)) {
|
|
|
- // 删除课程设置
|
|
|
- teachCourseService.clearCourseSetting(teachCourseId, CourseSettingTypeEnum.COURSE_DIMENSION);
|
|
|
-
|
|
|
CourseDimension temp = new CourseDimension();
|
|
|
temp.setTeachCourseId(teachCourseId);
|
|
|
temp.setSchoolId(schoolId);
|
|
@@ -237,65 +239,37 @@ public class CourseDimensionServiceImpl extends ServiceImpl<CourseDimensionMappe
|
|
|
willAddList.add(willAddSecond);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(willAddList)) {
|
|
|
- this.saveBatch(willAddList);
|
|
|
+ String dbMd5 = this.buildCourseDimensionMd5(courseDimensionList.stream().filter(e -> CourseDimensionSourceEnum.UNION_QUESTION.equals(e.getSource()))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ String willAddMd5 = this.buildCourseDimensionMd5(willAddList);
|
|
|
+ if (!willAddMd5.equals(dbMd5)) {
|
|
|
+ // 如果题库知识点和之前的题库知识点不一致,删除原先的并新增
|
|
|
+ teachCourseService.clearCourseSetting(teachCourseId, CourseSettingTypeEnum.COURSE_DIMENSION);
|
|
|
+ this.saveBatch(willAddList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String autoCreateDimensionCode(Long examId, String courseCode, Long parentId) {
|
|
|
- // 一级属性
|
|
|
- boolean isPrimaryProperty = parentId == null || parentId == 0;
|
|
|
- int primaryPropertyNumber;
|
|
|
- int secondaryPropertyNumber;
|
|
|
- String code;
|
|
|
- List<CourseDimension> sameLevelPropertyList = this.list(
|
|
|
- new QueryWrapper<CourseDimension>().lambda().eq(CourseDimension::getExamId, examId).eq(CourseDimension::getCourseCode, courseCode).eq(CourseDimension::getParentId, parentId)
|
|
|
- .orderByDesc(CourseDimension::getNumber));
|
|
|
- if (sameLevelPropertyList.size() > 0) {
|
|
|
- // 当前级别属性已经有值
|
|
|
- if (isPrimaryProperty) {
|
|
|
- // 一级属性
|
|
|
- primaryPropertyNumber = sameLevelPropertyList.get(0).getNumber() + 1;
|
|
|
- code = CourseDimensionCodeEnum.getCodeByIndex(primaryPropertyNumber);
|
|
|
- if (code == null || code.length() == 0) {
|
|
|
- CourseDimensionCodeEnum[] questionPropertyCodeEnums = CourseDimensionCodeEnum.values();
|
|
|
- Set<String> alreadyUsedCodeSet = sameLevelPropertyList.stream().map(CourseDimension::getCode).collect(Collectors.toSet());
|
|
|
- // 最大编号已经超过属性编号枚举,则查询是否有,没有使用过的编号
|
|
|
- Set<String> canUseCodeSet = Arrays.stream(questionPropertyCodeEnums)
|
|
|
- .filter(e -> !alreadyUsedCodeSet.contains(e.getCode()))
|
|
|
- .sorted(Comparator.comparing(CourseDimensionCodeEnum::getIndex))
|
|
|
- .map(CourseDimensionCodeEnum::getCode).collect(Collectors.toSet());
|
|
|
- if (canUseCodeSet.size() == 0) {
|
|
|
- throw new StatusException("课程属性一级结构编号已经用完");
|
|
|
- }
|
|
|
- code = canUseCodeSet.iterator().next();
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 二级属性
|
|
|
- CourseDimension primaryProperty = this.getById(parentId);
|
|
|
- if (Objects.isNull(primaryProperty)) {
|
|
|
- throw new StatusException("未找到对应的一级属性");
|
|
|
- }
|
|
|
- secondaryPropertyNumber = sameLevelPropertyList.get(0).getNumber() + 1;
|
|
|
- code = primaryProperty.getCode() + secondaryPropertyNumber;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 当前级别还未建立属性
|
|
|
- if (isPrimaryProperty) {
|
|
|
- // 一级属性
|
|
|
- code = CourseDimensionCodeEnum.A.getCode();
|
|
|
- } else {
|
|
|
- // 二级属性
|
|
|
- CourseDimension primaryProperty = this.getById(parentId);
|
|
|
- if (Objects.isNull(primaryProperty)) {
|
|
|
- throw new StatusException("未找到对应的一级属性");
|
|
|
- }
|
|
|
- code = primaryProperty.getCode() + 1;
|
|
|
- }
|
|
|
- }
|
|
|
- return code;
|
|
|
+ /**
|
|
|
+ * 构建知识点md5
|
|
|
+ *
|
|
|
+ * @param courseDimensionList 课程知识点集合
|
|
|
+ * @return MD5
|
|
|
+ */
|
|
|
+ private String buildCourseDimensionMd5(List<CourseDimension> courseDimensionList) {
|
|
|
+ List<CourseDimensionMd5Dto> md5List = courseDimensionList.stream().flatMap(e -> {
|
|
|
+ CourseDimensionMd5Dto dto = new CourseDimensionMd5Dto();
|
|
|
+ dto.setCode(e.getCode());
|
|
|
+ dto.setName(e.getName());
|
|
|
+ dto.setNumber(e.getNumber());
|
|
|
+ dto.setParentId(e.getParentId());
|
|
|
+ dto.setSource(e.getSource());
|
|
|
+ return Stream.of(dto);
|
|
|
+ }).sorted(Comparator.comparing(CourseDimensionMd5Dto::getCode)).collect(Collectors.toList());
|
|
|
+ return DigestUtils.md5Hex(JSON.toJSONString(md5List));
|
|
|
}
|
|
|
}
|