Ver Fonte

加入同步考生

wangliang há 1 ano atrás
pai
commit
2b1dd30e1d

+ 17 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCFinalScore.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.distributed.print.business.enums.SourceEnum;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -92,6 +93,22 @@ public class TCFinalScore implements Serializable {
         this.createTime = System.currentTimeMillis();
     }
 
+    public TCFinalScore(MarkStudentScoreVo markStudentScoreVo, String scoreDetail, SourceEnum source, Long userId) {
+        this.id = SystemConstant.getDbUuid();
+        this.examId = markStudentScoreVo.getExamId();
+        this.courseCode = markStudentScoreVo.getCourseCode();
+        this.courseName = markStudentScoreVo.getCourseName();
+        this.paperNumber = markStudentScoreVo.getPaperNumber();
+        this.name = markStudentScoreVo.getStudentName();
+        this.studentCode = markStudentScoreVo.getStudentCode();
+        this.score = markStudentScoreVo.getTotalScore();
+        this.scoreDetail = scoreDetail;
+        this.source = source;
+        this.enable = true;
+        this.createId = userId;
+        this.createTime = System.currentTimeMillis();
+    }
+
     public void updateInfo(TCFinalScore tcFinalScore, Long userId) {
         this.name = tcFinalScore.getName();
         this.score = tcFinalScore.getScore();

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

@@ -75,4 +75,15 @@ public interface TCFinalScoreService extends IService<TCFinalScore> {
      * @return
      */
     public List<FinalScoreResult> examStudentOverview(Long examId, String courseCode, String paperNumber);
+
+    /**
+     * 同步期末成绩
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     * @return
+     * @throws IOException
+     */
+    public Map<String, String> finalScoreExcelSync(Long examId, String courseCode, String paperNumber) throws IOException;
 }

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

@@ -23,7 +23,11 @@ import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
 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.mark.bean.archivescore.MarkStudentScoreVo;
+import com.qmth.teachcloud.mark.dto.mark.ScoreItem;
 import com.qmth.teachcloud.mark.entity.MarkPaper;
+import com.qmth.teachcloud.mark.service.MarkPaperService;
+import com.qmth.teachcloud.mark.service.MarkStudentService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.dao.DuplicateKeyException;
@@ -54,6 +58,12 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     @Resource
     TCFinalScoreService tcFinalScoreService;
 
+    @Resource
+    MarkPaperService markPaperService;
+
+    @Resource
+    MarkStudentService markStudentService;
+
     /**
      * 导入期末成绩excel
      *
@@ -69,10 +79,9 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     public Map<String, String> finalScoreExcelImport(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException {
         log.debug("导入Excel开始...");
         long start = System.currentTimeMillis();
-        MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
-
         Map<String, String> messageMap = new LinkedHashMap<>();
         try {
+            MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
             StringJoiner errorData = new StringJoiner("");
             StringJoiner successData = new StringJoiner("");
 
@@ -126,13 +135,10 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
             }
             if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
                 successData.add("共导入" + tcFinalScoreList.size() + "条数据");
-
-                QueryWrapper<TCFinalScore> tcScoreEndExamQueryWrapper = new QueryWrapper<>();
-                tcScoreEndExamQueryWrapper.lambda().eq(TCFinalScore::getExamId, examId)
+                tcFinalScoreService.remove(new QueryWrapper<TCFinalScore>().lambda().eq(TCFinalScore::getExamId, examId)
                         .eq(TCFinalScore::getCourseCode, courseCode)
                         .eq(TCFinalScore::getCourseName, markPaper.getCourseName())
-                        .eq(TCFinalScore::getPaperNumber, paperNumber);
-                tcFinalScoreService.remove(tcScoreEndExamQueryWrapper);
+                        .eq(TCFinalScore::getPaperNumber, paperNumber));
                 tcFinalScoreService.saveBatch(tcFinalScoreList);
             }
             messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
@@ -209,4 +215,66 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     public List<FinalScoreResult> examStudentOverview(Long examId, String courseCode, String paperNumber) {
         return this.baseMapper.examStudentOverview(examId, courseCode, paperNumber);
     }
+
+    /**
+     * 同步期末成绩
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     * @return
+     * @throws IOException
+     */
+    @Override
+    @Transactional
+    public Map<String, String> finalScoreExcelSync(Long examId, String courseCode, String paperNumber) throws IOException {
+        Map<String, String> messageMap = new LinkedHashMap<>();
+        try {
+            MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
+            Objects.requireNonNull(markPaper, "未找到科目信息");
+
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            StringJoiner errorData = new StringJoiner("");
+            StringJoiner successData = new StringJoiner("");
+            List<MarkStudentScoreVo> markStudentScoreVoList = markStudentService.listMarkStudentScoreList(examId, paperNumber);
+            if (!CollectionUtils.isEmpty(markStudentScoreVoList)) {
+                List<TCFinalScore> tcFinalScoreList = new ArrayList<>(markStudentScoreVoList.size());
+                for (MarkStudentScoreVo markStudentScoreVo : markStudentScoreVoList) {
+                    if (!CollectionUtils.isEmpty(markStudentScoreVo.getTotalScoreList())) {
+                        JSONArray jsonArray = new JSONArray();
+                        for (ScoreItem scoreItem : markStudentScoreVo.getTotalScoreList()) {
+                            JSONObject jsonObject = new JSONObject();
+                            String name = scoreItem.getMainNumber() + "-" + scoreItem.getSubNumber();
+                            jsonObject.put("name", name);
+                            jsonObject.put("score", scoreItem.getScore());
+                            jsonArray.add(jsonObject);
+                        }
+                        tcFinalScoreList.add(new TCFinalScore(markStudentScoreVo, jsonArray.toJSONString(), SourceEnum.SYNC, sysUser.getId()));
+                    }
+                }
+                if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
+                    successData.add("共同步" + tcFinalScoreList.size() + "条数据");
+                    tcFinalScoreService.remove(new QueryWrapper<TCFinalScore>().lambda().eq(TCFinalScore::getExamId, examId)
+                            .eq(TCFinalScore::getCourseCode, courseCode)
+                            .eq(TCFinalScore::getCourseName, markPaper.getCourseName())
+                            .eq(TCFinalScore::getPaperNumber, paperNumber));
+                    tcFinalScoreService.saveBatch(tcFinalScoreList);
+                }
+            }
+            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;
+    }
 }

+ 3 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCUsualScoreServiceImpl.java

@@ -66,10 +66,9 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
     public Map<String, String> usualScoreExcelImport(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException {
         log.debug("导入Excel开始...");
         long start = System.currentTimeMillis();
-        MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
-
         Map<String, String> messageMap = new LinkedHashMap<>();
         try {
+            MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
             StringJoiner errorData = new StringJoiner("");
             StringJoiner successData = new StringJoiner("");
 
@@ -119,13 +118,10 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
             }
             if (!CollectionUtils.isEmpty(tcUsualScoreList)) {
                 successData.add("共导入" + tcUsualScoreList.size() + "条数据");
-
-                QueryWrapper<TCUsualScore> tcScoreNormalQueryWrapper = new QueryWrapper<>();
-                tcScoreNormalQueryWrapper.lambda().eq(TCUsualScore::getExamId, examId)
+                tcUsualScoreService.remove(new QueryWrapper<TCUsualScore>().lambda().eq(TCUsualScore::getExamId, examId)
                         .eq(TCUsualScore::getCourseCode, courseCode)
                         .eq(TCUsualScore::getCourseName, markPaper.getCourseName())
-                        .eq(TCUsualScore::getPaperNumber, paperNumber);
-                tcUsualScoreService.remove(tcScoreNormalQueryWrapper);
+                        .eq(TCUsualScore::getPaperNumber, paperNumber));
                 tcUsualScoreService.saveBatch(tcUsualScoreList);
             }
             messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TRBasicInfoServiceImpl.java

@@ -12,16 +12,14 @@ import com.qmth.distributed.print.business.bean.result.report.PaperStructResult;
 import com.qmth.distributed.print.business.entity.TCPaperStruct;
 import com.qmth.distributed.print.business.entity.TRBasicInfo;
 import com.qmth.distributed.print.business.mapper.TRBasicInfoMapper;
-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.TRExamStudentService;
+import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.entity.BasicSemester;
 import com.qmth.teachcloud.common.service.BasicSemesterService;
 import com.qmth.teachcloud.common.util.GsonUtil;
 import com.qmth.teachcloud.common.util.JacksonUtil;
 import com.qmth.teachcloud.mark.bean.archivescore.ScoreRangeVo;
 import com.qmth.teachcloud.mark.entity.MarkPaper;
+import com.qmth.teachcloud.mark.service.MarkStudentService;
 import com.qmth.teachcloud.mark.utils.Calculator;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -60,6 +58,9 @@ public class TRBasicInfoServiceImpl extends ServiceImpl<TRBasicInfoMapper, TRBas
     @Resource
     TRExamStudentService trExamStudentService;
 
+    @Resource
+    CourseWeightService courseWeightService;
+
     /**
      * 获取课程目标考核分布-分数图
      *

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

@@ -134,6 +134,7 @@ public class TCFinalScoreController {
     @ApiOperation(value = "同步期末成绩")
     @RequestMapping(value = "/final_score/sync", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
+    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.PUSH)
     public Object finalScoreSync(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                  @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                  @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
@@ -142,8 +143,9 @@ public class TCFinalScoreController {
         if (!lock) {
             throw ExceptionResultEnum.ERROR.exception("正在导入数据,请稍候再试!");
         }
+        Map<String, String> map = null;
         try {
-            //TODO 待肖飞补充同步接口
+            map = tcFinalScoreService.finalScoreExcelSync(examId, courseCode, paperNumber);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {
@@ -154,7 +156,7 @@ public class TCFinalScoreController {
         } finally {
             redisUtil.releaseLock(lockKey);
         }
-        return ResultUtil.ok(true);
+        return ResultUtil.ok(map);
     }
 
     @ApiOperation(value = "期末成绩列表")

+ 0 - 3
distributed-print/src/main/java/com/qmth/distributed/print/api/TRBasicInfoController.java

@@ -75,9 +75,6 @@ public class TRBasicInfoController {
     @Resource
     TRExamStudentService trExamStudentService;
 
-    @Resource
-    TCFinalScoreService tcFinalScoreService;
-
     @ApiOperation(value = "报告管理列表")
     @RequestMapping(value = "/report/list", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)