|
@@ -0,0 +1,135 @@
|
|
|
|
+package com.qmth.distributed.print.business.service.impl;
|
|
|
|
+
|
|
|
|
+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.CourseDimensionDto;
|
|
|
|
+import com.qmth.distributed.print.business.entity.CourseDimension;
|
|
|
|
+import com.qmth.distributed.print.business.enums.CourseDimensionCodeEnum;
|
|
|
|
+import com.qmth.distributed.print.business.mapper.CourseDimensionMapper;
|
|
|
|
+import com.qmth.distributed.print.business.service.CourseDimensionService;
|
|
|
|
+import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 课程知识点表 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author CaoZixuan
|
|
|
|
+ * @since 2024-02-27
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class CourseDimensionServiceImpl extends ServiceImpl<CourseDimensionMapper, CourseDimension> implements CourseDimensionService {
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void importCourseDimension(SysUser requestUser, MultipartFile file, Long examId, String courseCode)
|
|
|
|
+ throws IOException, NoSuchFieldException {
|
|
|
|
+ List<String> errorMsgList = new ArrayList<>();
|
|
|
|
+ List<CourseDimensionDto> list = new ArrayList<>();
|
|
|
|
+ ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(CourseDimensionDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
|
+ for (int i = 0; i < finalExcelList.size(); i++) {
|
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
|
|
+ List<Object> courseDimensionDtoList = excelMap.get(i);
|
|
|
|
+ // 无数据,跳过
|
|
|
|
+ if (CollectionUtils.isEmpty(courseDimensionDtoList)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ for (int y = 0; y < courseDimensionDtoList.size(); y++) {
|
|
|
|
+
|
|
|
|
+ // 行索引
|
|
|
|
+ Integer rowIndex = y + 1;
|
|
|
|
+ CourseDimensionDto courseDimensionDto = (CourseDimensionDto) courseDimensionDtoList.get(y);
|
|
|
|
+ String excelCourseCode = StringUtils.trimToNull(courseDimensionDto.getCourseCode());
|
|
|
|
+ String excelCourseName = StringUtils.trimToNull(courseDimensionDto.getCourseName());
|
|
|
|
+ String firstDimensionName = StringUtils.trimToNull(courseDimensionDto.getFirstDimensionName());
|
|
|
|
+ String secondDimensionName = StringUtils.trimToNull(courseDimensionDto.getSecondDimensionName());
|
|
|
|
+
|
|
|
|
+ // 本行全部列为空,跳过
|
|
|
|
+ if (StringUtils.isAllBlank(excelCourseCode, excelCourseName, firstDimensionName, secondDimensionName)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (courseCode.equals(excelCourseCode)) {
|
|
|
|
+ errorMsgList.add(String.format("第[%s]行,课程代码异常", rowIndex));
|
|
|
|
+ }
|
|
|
|
+ list.add(courseDimensionDto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return finalExcelList;
|
|
|
|
+ }, 2);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(errorMsgList)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorMsgList));
|
|
|
|
+ } else {
|
|
|
|
+ // 处理要新增的考察点
|
|
|
|
+ // TODO: 2024/2/27
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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;
|
|
|
|
+ }
|
|
|
|
+}
|