Procházet zdrojové kódy

新增同步题库试卷结构功能

wangliang před 1 rokem
rodič
revize
a7fa4d76b3

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCFinalScoreService.java

@@ -85,7 +85,7 @@ public interface TCFinalScoreService extends IService<TCFinalScore> {
      * @return
      * @throws IOException
      */
-    public Map<String, String> finalScoreExcelSync(Long examId, String courseCode, String paperNumber) throws IOException;
+    public Map<String, String> finalScoreSync(Long examId, String courseCode, String paperNumber) throws IOException;
 
     /**
      * 根据考试id/课程编码/试卷编码删除数据

+ 2 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCPaperStructService.java

@@ -40,7 +40,7 @@ public interface TCPaperStructService extends IService<TCPaperStruct> {
     public Map<String, String> paperStructExcelImport(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException;
 
     /**
-     * 同步试卷蓝图结构
+     * 同步试卷结构
      *
      * @param examId
      * @param courseCode
@@ -48,7 +48,7 @@ public interface TCPaperStructService extends IService<TCPaperStruct> {
      * @return
      * @throws IOException
      */
-    public Map<String, String> paperStructDimensionSync(Long examId, String courseCode, String paperNumber) throws IOException;
+    public Map<String, String> paperStructSync(Long examId, String courseCode, String paperNumber) throws IOException;
 
     /**
      * 根据考试id/科目编辑/试卷编码查询数据

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCFinalScoreServiceImpl.java

@@ -259,7 +259,7 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
      */
     @Override
     @Transactional
-    public Map<String, String> finalScoreExcelSync(Long examId, String courseCode, String paperNumber) throws IOException {
+    public Map<String, String> finalScoreSync(Long examId, String courseCode, String paperNumber) throws IOException {
         Map<String, String> messageMap = new LinkedHashMap<>();
         try {
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();

+ 58 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCPaperStructServiceImpl.java

@@ -6,12 +6,11 @@ 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.distributed.print.business.bean.excel.PaperStructDto;
+import com.qmth.distributed.print.business.bean.result.CourseWeightResult;
+import com.qmth.distributed.print.business.bean.result.report.PaperStructDimensionResult;
 import com.qmth.distributed.print.business.entity.TCPaperStruct;
 import com.qmth.distributed.print.business.mapper.TCPaperStructMapper;
-import com.qmth.distributed.print.business.service.PrintCommonService;
-import com.qmth.distributed.print.business.service.TCFinalScoreService;
-import com.qmth.distributed.print.business.service.TCPaperStructService;
-import com.qmth.distributed.print.business.service.TRBasicInfoService;
+import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -24,6 +23,7 @@ import com.qmth.teachcloud.mark.entity.MarkPaper;
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -60,6 +60,9 @@ public class TCPaperStructServiceImpl extends ServiceImpl<TCPaperStructMapper, T
     @Resource
     RedisUtil redisUtil;
 
+    @Resource
+    CourseTargetService courseTargetService;
+
     /**
      * 根据考试id/课程编码/试卷编码查询数据库数据
      *
@@ -181,7 +184,7 @@ public class TCPaperStructServiceImpl extends ServiceImpl<TCPaperStructMapper, T
     }
 
     /**
-     * 同步试卷蓝图结构
+     * 同步试卷结构
      *
      * @param examId
      * @param courseCode
@@ -191,8 +194,56 @@ public class TCPaperStructServiceImpl extends ServiceImpl<TCPaperStructMapper, T
      */
     @Override
     @Transactional
-    public Map<String, String> paperStructDimensionSync(Long examId, String courseCode, String paperNumber) throws IOException {
-        return null;
+    public Map<String, String> paperStructSync(Long examId, String courseCode, String paperNumber) throws IOException {
+        Map<String, String> messageMap = new LinkedHashMap<>();
+        try {
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            StringJoiner errorData = new StringJoiner("");
+            StringJoiner successData = new StringJoiner("");
+            List<PaperStructDimensionResult> paperStructDimensionResultList = courseTargetService.findTikuPaperStruct(examId, paperNumber);
+            if (!CollectionUtils.isEmpty(paperStructDimensionResultList)) {
+                for (PaperStructDimensionResult paperStructDimensionResult : paperStructDimensionResultList) {
+                    Objects.requireNonNull(paperStructDimensionResult.getMainNumber(), "大题号为空");
+                    Objects.requireNonNull(paperStructDimensionResult.getSubNumber(), "小题号为空");
+                    if (!CollectionUtils.isEmpty(paperStructDimensionResult.getTargetList()) && paperStructDimensionResult.getTargetList().size() > 1) {
+                        throw ExceptionResultEnum.ERROR.exception("一个题只能属于一个目标");
+                    }
+                }
+                successData.add("共同步").add(paperStructDimensionResultList.size() + "").add("条数据");
+                TCPaperStruct tcPaperStructDb = tcPaperStructService.getOne(new QueryWrapper<TCPaperStruct>().lambda().eq(TCPaperStruct::getExamId, examId).eq(TCPaperStruct::getCourseCode, courseCode).eq(TCPaperStruct::getPaperNumber, paperNumber));
+                TCPaperStruct tcPaperStruct = null;
+                if (Objects.nonNull(tcPaperStructDb) && Objects.nonNull(tcPaperStructDb.getPaperStructDimension())) {
+                    tcPaperStruct = new TCPaperStruct();
+                    BeanUtils.copyProperties(tcPaperStructDb, tcPaperStruct);
+                    tcPaperStruct.setPaperStructDimension(JacksonUtil.parseJson(paperStructDimensionResultList));
+
+                    if (!tcPaperStruct.equals(tcPaperStructDb)) {
+                        trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
+                    }
+                    tcPaperStruct.updateInfo(sysUser.getId());
+                } else {
+                    MarkPaper markPaper = printCommonService.getMarkPaper(examId, paperNumber);
+                    CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(examId, courseCode);
+                    tcPaperStruct = new TCPaperStruct(examId, courseCode, markPaper.getCourseName(), paperNumber, JacksonUtil.parseJson(paperStructDimensionResultList), sysUser.getId(), courseWeightResult.getDimensionSign());
+                    trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
+                }
+                tcPaperStructService.saveOrUpdate(tcPaperStruct);
+            }
+            messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
+            messageMap.put(SystemConstant.EXCEL_ERROR, errorData.length() > 0 ? errorData.toString() : "无");
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return messageMap;
     }
 
     /**

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TCFinalScoreController.java

@@ -142,7 +142,7 @@ public class TCFinalScoreController {
         String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
         Map<String, String> map = null;
         try {
-            map = tcFinalScoreService.finalScoreExcelSync(examId, courseCode, paperNumber);
+            map = tcFinalScoreService.finalScoreSync(examId, courseCode, paperNumber);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {

+ 5 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/TCPaperStructController.java

@@ -10,8 +10,8 @@ import com.qmth.distributed.print.business.bean.result.CourseWeightResult;
 import com.qmth.distributed.print.business.bean.result.EditResult;
 import com.qmth.distributed.print.business.bean.result.report.PaperStructDimensionResult;
 import com.qmth.distributed.print.business.entity.TCPaperStruct;
+import com.qmth.distributed.print.business.service.CourseTargetService;
 import com.qmth.distributed.print.business.service.PrintCommonService;
-import com.qmth.distributed.print.business.service.TCFinalScoreService;
 import com.qmth.distributed.print.business.service.TCPaperStructService;
 import com.qmth.distributed.print.business.service.TRBasicInfoService;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
@@ -72,6 +72,9 @@ public class TCPaperStructController {
     @Resource
     RedisUtil redisUtil;
 
+    @Resource
+    CourseTargetService courseTargetService;
+
     @ApiOperation(value = "导入试卷结构")
     @RequestMapping(value = "/final_score/paper_struct/import", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
@@ -109,7 +112,7 @@ public class TCPaperStructController {
         String lockKey = SystemConstant.REDIS_PAPER_STRUCT_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
         Map<String, String> map = null;
         try {
-//            map = tcFinalScoreService.finalScoreExcelSync(examId, courseCode, paperNumber);
+            map = tcPaperStructService.paperStructSync(examId, courseCode, paperNumber);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {