|
@@ -1,10 +1,20 @@
|
|
|
package com.qmth.teachcloud.report.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.itextpdf.text.pdf.PdfReader;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.entity.BasicAttachment;
|
|
|
+import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
+import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
|
+import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
|
import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
+import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import com.qmth.teachcloud.report.business.bean.result.*;
|
|
|
import com.qmth.teachcloud.report.business.entity.*;
|
|
@@ -12,18 +22,24 @@ import com.qmth.teachcloud.report.business.enums.*;
|
|
|
import com.qmth.teachcloud.report.business.service.*;
|
|
|
import com.qmth.teachcloud.report.business.utils.AnalyzeScopeUtil;
|
|
|
import com.qmth.teachcloud.report.business.utils.MathUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -74,12 +90,21 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
@Resource
|
|
|
TAExamCourseTeacherCollegeDifficultService taExamCourseTeacherCollegeDifficultService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FileStoreUtil fileStoreUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DictionaryConfig dictionaryConfig;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
/**
|
|
|
* 学院学科报表查询科目信息
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
+ * @param collegeId collegeId
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -129,9 +154,9 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 学院学科报表科目描述
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
+ * @param collegeId collegeId
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -234,10 +259,10 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 开课学院分数段
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
- * @param filter filter
|
|
|
+ * @param collegeId collegeId
|
|
|
+ * @param filter filter
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -327,10 +352,10 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 学院学科报表查询维度
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
- * @param teacherId teacherId
|
|
|
+ * @param collegeId collegeId
|
|
|
+ * @param teacherId teacherId
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -353,11 +378,8 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
dimensionInfoDatasource = tbDimensionService.findDimensionByTeacherCollegeInfo(examId, courseCode, teacherId, collegeId);
|
|
|
teacherLookSelf = true;
|
|
|
}
|
|
|
-// if (dimensionInfoDatasource.size() < 1) {
|
|
|
-// throw ExceptionResultEnum.DATA_ERROR.exception();
|
|
|
-// }
|
|
|
List<ModuleDimensionResult> dimensionAnalyzeList = new ArrayList<>();
|
|
|
- if (dimensionInfoDatasource != null && dimensionInfoDatasource.size() > 0){
|
|
|
+ if (dimensionInfoDatasource != null && dimensionInfoDatasource.size() > 0) {
|
|
|
Set<String> moduleSet = dimensionInfoDatasource.stream().map(CourseDimensionResult::getModule).collect(Collectors.toSet()); // 考查模块集合
|
|
|
for (String module : moduleSet) {
|
|
|
List<CourseDimensionResult> dimensionInfoList = dimensionInfoDatasource
|
|
@@ -380,13 +402,13 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
String schScoreRate = null;
|
|
|
String colScoreRate = null;
|
|
|
String teaScoreRate = null;
|
|
|
- if (deanLookCollege){
|
|
|
+ if (deanLookCollege) {
|
|
|
schScoreRate = String.valueOf(referenceScoreRate);
|
|
|
colScoreRate = String.valueOf(myScoreRate);
|
|
|
- }else if (deanLookTeacher){
|
|
|
+ } else if (deanLookTeacher) {
|
|
|
schScoreRate = String.valueOf(referenceScoreRate);
|
|
|
teaScoreRate = String.valueOf(myScoreRate);
|
|
|
- }else if (teacherLookSelf){
|
|
|
+ } else if (teacherLookSelf) {
|
|
|
colScoreRate = String.valueOf(referenceScoreRate);
|
|
|
teaScoreRate = String.valueOf(myScoreRate);
|
|
|
}
|
|
@@ -401,10 +423,10 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 查找题目相关
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
- * @param teacherId teacherId
|
|
|
+ * @param collegeId collegeId
|
|
|
+ * @param teacherId teacherId
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -422,7 +444,7 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
answerDetailDatasource = taExamCourseTeacherCollegeDifficultService.findValidAnswerDetail(examId, courseCode, teacherId, collegeId);
|
|
|
}
|
|
|
List<PaperTypeResult> questionInfoList = new ArrayList<>();
|
|
|
- if (answerDetailDatasource != null && answerDetailDatasource.size() > 0){
|
|
|
+ if (answerDetailDatasource != null && answerDetailDatasource.size() > 0) {
|
|
|
Set<String> paperTypeList = answerDetailDatasource.stream().map(CellResult::getPaperType).collect(Collectors.toSet());
|
|
|
for (String paperType : paperTypeList) {
|
|
|
questionInfoList.add(new PaperTypeResult(paperType, answerDetailDatasource.stream().filter(e -> Objects.equals(paperType, e.getPaperType())).collect(Collectors.toList())));
|
|
@@ -434,9 +456,9 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 查找老师信息
|
|
|
*
|
|
|
- * @param examId examId
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param collegeId collegeId
|
|
|
+ * @param collegeId collegeId
|
|
|
* @return return
|
|
|
*/
|
|
|
@Override
|
|
@@ -509,7 +531,7 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
for (String dimensionCode : knowledgeDimensionSort) {
|
|
|
String dimensionName;
|
|
|
List<String> nameTwoList = dimensionDataSource.stream()
|
|
|
- .filter(e -> dimensionCode.equals(e.getCodeSecond()))
|
|
|
+ .filter(e -> dimensionCode.equals(e.getCodeSecond()) && "知识".equals(e.getDimensionType()))
|
|
|
.map(TBDimension::getNameSecond).collect(Collectors.toList());
|
|
|
if (nameTwoList.size() < 1) {
|
|
|
List<String> tmpList = dimensionDataSource.stream()
|
|
@@ -533,7 +555,7 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
.map(TBDimension::getNameSecond).collect(Collectors.toList());
|
|
|
if (nameTwoList.size() < 1) {
|
|
|
List<String> tmpList = dimensionDataSource.stream()
|
|
|
- .filter(e -> dimensionCode.equals(e.getCodePrimary()))
|
|
|
+ .filter(e -> dimensionCode.equals(e.getCodePrimary()) && "能力".equals(e.getDimensionType()))
|
|
|
.map(TBDimension::getNamePrimary).collect(Collectors.toList());
|
|
|
if (tmpList.size() == 0) {
|
|
|
continue;
|
|
@@ -552,10 +574,10 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 取总体平均分
|
|
|
*
|
|
|
- * @param schoolId schoolId
|
|
|
+ * @param schoolId schoolId
|
|
|
* @param courseCode courseCode
|
|
|
- * @param examId examId
|
|
|
- * @param filter filter
|
|
|
+ * @param examId examId
|
|
|
+ * @param filter filter
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
@@ -573,9 +595,7 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
}
|
|
|
if (filter) {
|
|
|
QueryWrapper<TBExamCourse> tbExamCourseQueryWrapper = new QueryWrapper<>();
|
|
|
- if (Objects.nonNull(schoolId)) {
|
|
|
- tbExamCourseQueryWrapper.lambda().eq(TBExamCourse::getSchoolId, schoolId);
|
|
|
- }
|
|
|
+ tbExamCourseQueryWrapper.lambda().eq(TBExamCourse::getSchoolId, schoolId);
|
|
|
if (Objects.nonNull(examId)) {
|
|
|
tbExamCourseQueryWrapper.lambda().eq(TBExamCourse::getExamId, examId);
|
|
|
}
|
|
@@ -616,8 +636,8 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
/**
|
|
|
* 获取开课课程考试课程总览
|
|
|
*
|
|
|
- * @param semester semester
|
|
|
- * @param examId examId
|
|
|
+ * @param semester semester
|
|
|
+ * @param examId examId
|
|
|
* @param courseCode courseCode
|
|
|
* @return return
|
|
|
*/
|
|
@@ -638,4 +658,123 @@ public class ReportCommonServiceImpl implements ReportCommonService {
|
|
|
teachCourseSurveyResult.setInspectCollegeNames(taExamCourse.getInspectCollegeNames());
|
|
|
return teachCourseSurveyResult;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public BasicAttachment saveAttachment(MultipartFile file, String md5, UploadFileEnum type) {
|
|
|
+ return saveAttachmentCommon(file, md5, type, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件公用
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param md5
|
|
|
+ * @param type
|
|
|
+ * @param objId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BasicAttachment saveAttachmentCommon(MultipartFile file, String md5, UploadFileEnum type, Long objId) {
|
|
|
+ if (Objects.isNull(type)) {
|
|
|
+ throw ExceptionResultEnum.ATTACHMENT_TYPE_EMPTY.exception();
|
|
|
+ }
|
|
|
+ BasicAttachment basicAttachment = null;
|
|
|
+ try {
|
|
|
+ // TODO: 2022/4/14 临时测试生成user
|
|
|
+// SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ SysUser requestUser = new SysUser();
|
|
|
+ requestUser.setId(1L);
|
|
|
+
|
|
|
+
|
|
|
+ int temp = file.getOriginalFilename().lastIndexOf(".");
|
|
|
+ String fileName = file.getOriginalFilename().substring(0, temp);
|
|
|
+ String format = file.getOriginalFilename().substring(temp, file.getOriginalFilename().length());
|
|
|
+ List<String> attachmentTypeList = dictionaryConfig.sysDomain().getAttachmentType();
|
|
|
+ if (Objects.nonNull(format)) {
|
|
|
+ long count = attachmentTypeList.stream().filter(s -> format.equalsIgnoreCase(s)).count();
|
|
|
+ if (count == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文件格式只能为" + attachmentTypeList.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int attachmentLength = dictionaryConfig.sysDomain().getAttachmentLength().intValue();
|
|
|
+ if (Objects.nonNull(fileName) && fileName.length() > attachmentLength) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文件名长度不能超过" + attachmentLength + "个字符");
|
|
|
+ }
|
|
|
+ long size = file.getSize();
|
|
|
+ BigDecimal b = new BigDecimal(size);
|
|
|
+ BigDecimal num = new BigDecimal(1024);
|
|
|
+ b = b.divide(num, 2, BigDecimal.ROUND_HALF_UP).divide(num, 2, BigDecimal.ROUND_HALF_UP)
|
|
|
+ .setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ double attachmentSize = dictionaryConfig.sysDomain().getAttachmentSize().doubleValue();
|
|
|
+ if (b.doubleValue() > attachmentSize) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文件大小不能超过" + attachmentSize + "MB");
|
|
|
+ }
|
|
|
+ log.info("fileName:{}", fileName);
|
|
|
+ log.info("format:{}", format);
|
|
|
+ log.info("size:{}", b);
|
|
|
+ log.info("getOriginalFilename:{}", file.getOriginalFilename());
|
|
|
+ String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
+ log.info("fileMd5:{}", fileMd5);
|
|
|
+ log.info("md5:{}", md5);
|
|
|
+ if (!Objects.equals(fileMd5, md5)) {
|
|
|
+ throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
+ }
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ if (!oss) {
|
|
|
+ stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
+ }
|
|
|
+ stringJoiner.add(type.getTitle()).add(File.separator);
|
|
|
+// else if (type == UploadFileEnum.PAPER) {//试卷需要单独
|
|
|
+// stringJoiner.add(type.getTitle()).add(File.separator);
|
|
|
+// } else if (type == UploadFileEnum.UPLOAD) {
|
|
|
+// stringJoiner.add(type.getTitle()).add(File.separator);
|
|
|
+// }
|
|
|
+ stringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(format);
|
|
|
+ if (oss) {//上传至oss\
|
|
|
+ String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
+ fileStoreUtil.ossUpload(dirName, file.getInputStream(), md5, type.getFssType());
|
|
|
+
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirName);
|
|
|
+ } else {//上传至服务器
|
|
|
+ File finalFile = new File(stringJoiner.toString());
|
|
|
+ if (!finalFile.exists()) {
|
|
|
+ finalFile.getParentFile().mkdirs();
|
|
|
+ finalFile.createNewFile();
|
|
|
+ }
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), finalFile);
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
|
|
|
+ }
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, type);
|
|
|
+
|
|
|
+ basicAttachment = new BasicAttachment(jsonObject.toJSONString(), fileName, format, b, fileMd5, requestUser.getId(), objId);
|
|
|
+ basicAttachmentService.save(basicAttachment);
|
|
|
+
|
|
|
+ // pdf需要读取总页数
|
|
|
+ Integer pages = 0;
|
|
|
+ if (".pdf".equals(format)) {
|
|
|
+ PdfReader pdfReader = new PdfReader(file.getBytes());
|
|
|
+ pages = pdfReader.getNumberOfPages();
|
|
|
+ }
|
|
|
+ basicAttachment.setPages(pages);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ basicAttachmentService.deleteAttachment(basicAttachment);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return basicAttachment;
|
|
|
+ }
|
|
|
}
|