Browse Source

成绩管理1对多

wangliang 8 months ago
parent
commit
2669551389

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

@@ -9,10 +9,12 @@ import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.core.rateLimit.annotation.RateLimit;
 import com.qmth.distributed.print.business.bean.excel.ExcelField;
 import com.qmth.distributed.print.business.bean.result.EditResult;
+import com.qmth.distributed.print.business.service.BasicExamStudentService;
 import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicCourse;
+import com.qmth.teachcloud.common.entity.BasicExamStudent;
 import com.qmth.teachcloud.common.entity.MarkQuestion;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -23,6 +25,7 @@ import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.mark.entity.MarkPaper;
 import com.qmth.teachcloud.mark.service.MarkPaperService;
 import com.qmth.teachcloud.mark.service.MarkQuestionService;
+import com.qmth.teachcloud.obe.been.dto.ExamParamDto;
 import com.qmth.teachcloud.obe.been.dto.TCFinalScoreDto;
 import com.qmth.teachcloud.obe.been.excel.PaperStructDto;
 import com.qmth.teachcloud.obe.been.result.report.PaperStructDimensionResult;
@@ -89,6 +92,9 @@ public class TCFinalScoreController {
     @Resource
     BasicCourseService basicCourseService;
 
+    @Resource
+    BasicExamStudentService basicExamStudentService;
+
     @ApiOperation(value = "导入期末成绩-模板下载")
     @RequestMapping(value = "/final_score/template_download", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
@@ -181,7 +187,17 @@ public class TCFinalScoreController {
                                             @ApiParam(value = "科目编码") @RequestParam(required = false) Long courseId) {
         BasicCourse basicCourse = basicCourseService.getById(courseId);
         Objects.requireNonNull(basicCourse, "未找到课程信息");
-        return ResultUtil.ok(markPaperService.list(new QueryWrapper<MarkPaper>().lambda().eq(MarkPaper::getExamId, examId).eq(MarkPaper::getCourseId, basicCourse.getId()).eq(MarkPaper::getStatus, MarkPaperStatus.FINISH)));
+        Set<ExamParamDto> examParamDtoList = new LinkedHashSet<>();
+        List<MarkPaper> markPaperList = markPaperService.list(new QueryWrapper<MarkPaper>().lambda().eq(MarkPaper::getExamId, examId).eq(MarkPaper::getCourseId, basicCourse.getId()).eq(MarkPaper::getStatus, MarkPaperStatus.FINISH));
+        if (CollectionUtils.isEmpty(markPaperList)) {
+            List<BasicExamStudent> basicExamStudentList = basicExamStudentService.list(new QueryWrapper<BasicExamStudent>().select(" distinct exam_id as examId,paper_number as paperNumber").lambda().eq(BasicExamStudent::getExamId, examId).eq(BasicExamStudent::getCourseId, basicCourse.getId()));
+            if (!CollectionUtils.isEmpty(basicExamStudentList)) {
+                basicExamStudentList.stream().peek(s -> examParamDtoList.add(new ExamParamDto(s.getExamId(), s.getPaperNumber()))).collect(Collectors.toList());
+            }
+        } else {
+            markPaperList.stream().peek(s -> examParamDtoList.add(new ExamParamDto(s.getExamId(), s.getPaperNumber()))).collect(Collectors.toList());
+        }
+        return ResultUtil.ok(examParamDtoList);
     }
 
     @ApiOperation(value = "同步期末成绩")

+ 3 - 0
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkStudentServiceImpl.java

@@ -1860,6 +1860,9 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public List<MarkStudentScoreVo> listMarkStudentScoreList(Long examId, String paperNumber) {
         MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
+        if (Objects.isNull(markPaper)) {
+            return null;
+        }
         if (!MarkPaperStatus.FINISH.equals(markPaper.getStatus())) {
             throw ExceptionResultEnum.ERROR.exception("科目未结束评卷,不能同步考生成绩");
         }

+ 67 - 0
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/been/dto/ExamParamDto.java

@@ -0,0 +1,67 @@
+package com.qmth.teachcloud.obe.been.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * @Description: 考试参数dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2024/10/23
+ */
+public class ExamParamDto implements Serializable {
+
+    @ApiModelProperty(value = "考试id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long examId;
+
+    @ApiModelProperty(value = "试卷编码")
+    private String paperNumber;
+
+    public ExamParamDto() {
+
+    }
+
+    public ExamParamDto(Long examId, String paperNumber) {
+        this.paperNumber = paperNumber;
+        this.examId = examId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        ExamParamDto that = (ExamParamDto) o;
+        return Objects.equals(examId, that.examId) && Objects.equals(paperNumber, that.paperNumber);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(examId, paperNumber);
+    }
+}

+ 17 - 0
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/entity/TCFinalScore.java

@@ -4,6 +4,8 @@ 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.base.BaseEntity;
+import com.qmth.teachcloud.common.entity.BasicCourse;
+import com.qmth.teachcloud.common.entity.BasicExamStudent;
 import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -103,6 +105,21 @@ public class TCFinalScore extends BaseEntity implements Serializable {
         this.teachClassName = markStudentScoreVo.getTeachClassName();
     }
 
+    public TCFinalScore(BasicExamStudent basicExamStudent, BasicCourse basicCourse, SourceEnum source, Long userId, Long cultureProgramId, Long courseId) {
+        insertInfo(Objects.nonNull(basicExamStudent.getTeacherId()) ? basicExamStudent.getTeacherId() : userId);
+        this.examId = basicExamStudent.getExamId();
+        this.courseCode = basicCourse.getCode();
+        this.courseName = basicCourse.getName();
+        this.paperNumber = basicExamStudent.getPaperNumber();
+        this.name = basicExamStudent.getStudentName();
+        this.studentCode = basicExamStudent.getStudentCode();
+        this.source = source;
+        this.enable = true;
+        this.cultureProgramId = cultureProgramId;
+        this.courseId = courseId;
+        this.teachClassName = basicExamStudent.getTeachClassName();
+    }
+
     public void updateInfo(TCFinalScore tcFinalScore, Long userId) {
         this.name = tcFinalScore.getName();
         this.score = tcFinalScore.getScore();

+ 2 - 1
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/entity/TCPaperStruct.java

@@ -101,7 +101,7 @@ public class TCPaperStruct extends BaseEntity implements Serializable {
         updateInfo(userId);
     }
 
-    public TCPaperStruct(Long cultureProgramId, Long courseId, String courseCode, String courseName, String paperNumber, String paperStruct, Long userId) {
+    public TCPaperStruct(Long cultureProgramId, Long courseId, String courseCode, String courseName, String paperNumber, String paperStruct, Long userId, Long examId) {
         insertInfo(userId);
         this.cultureProgramId = cultureProgramId;
         this.courseId = courseId;
@@ -110,6 +110,7 @@ public class TCPaperStruct extends BaseEntity implements Serializable {
         this.paperNumber = paperNumber;
         this.paperStruct = paperStruct;
         this.enable = true;
+        this.examId = examId;
     }
 
     public Long getCultureProgramId() {

+ 17 - 0
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/entity/TCUsualScore.java

@@ -4,6 +4,8 @@ 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.base.BaseEntity;
+import com.qmth.teachcloud.common.entity.BasicCourse;
+import com.qmth.teachcloud.common.entity.BasicExamStudent;
 import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -97,6 +99,21 @@ public class TCUsualScore extends BaseEntity implements Serializable {
         this.teachClassName = markStudentScoreVo.getTeachClassName();
     }
 
+    public TCUsualScore(BasicExamStudent basicExamStudent, BasicCourse basicCourse, SourceEnum source, Long userId, Long cultureProgramId, Long courseId) {
+        insertInfo(Objects.nonNull(basicExamStudent.getTeacherId()) ? basicExamStudent.getTeacherId() : userId);
+        this.examId = basicExamStudent.getExamId();
+        this.courseCode = basicCourse.getCode();
+        this.courseName = basicCourse.getName();
+        this.paperNumber = basicExamStudent.getPaperNumber();
+        this.name = basicExamStudent.getStudentName();
+        this.studentCode = basicExamStudent.getStudentCode();
+        this.source = source;
+        this.enable = true;
+        this.cultureProgramId = cultureProgramId;
+        this.courseId = courseId;
+        this.teachClassName = basicExamStudent.getTeachClassName();
+    }
+
     public void updateInfo(TCUsualScore tcUsualScore, Long userId) {
         updateInfo(userId);
         this.name = tcUsualScore.getName();

+ 52 - 30
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/service/impl/TCFinalScoreServiceImpl.java

@@ -8,11 +8,13 @@ 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.enums.SourceEnum;
+import com.qmth.distributed.print.business.service.BasicExamStudentService;
 import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.teachcloud.common.base.BaseEntity;
 import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicCourse;
+import com.qmth.teachcloud.common.entity.BasicExamStudent;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
@@ -96,6 +98,9 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     @Resource
     private BasicRoleDataPermissionService basicRoleDataPermissionService;
 
+    @Resource
+    BasicExamStudentService basicExamStudentService;
+
     /**
      * 导入期末成绩excel
      *
@@ -350,13 +355,18 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     public Map<String, String> finalScoreSync(Long examId, Long courseId, String paperNumber, Long cultureProgramId) {
         Map<String, String> messageMap = new LinkedHashMap<>();
         try {
+            BasicCourse basicCourse = basicCourseService.getById(courseId);
+            Objects.requireNonNull(basicCourse, "未找到基础课程信息");
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
             StringJoiner errorData = new StringJoiner("");
             StringJoiner successData = new StringJoiner("");
             List<MarkStudentScoreVo> markStudentScoreVoList = markStudentService.listMarkStudentScoreList(examId, paperNumber);
+            //不为空则从markPaper里同步基础数据,否则从basicExamStudent同步
+            List<TCFinalScore> tcFinalScoreList = null;
+            List<TCUsualScore> tcUsualScoreList = null;
             if (!CollectionUtils.isEmpty(markStudentScoreVoList)) {
-                List<TCFinalScore> tcFinalScoreList = new ArrayList<>(markStudentScoreVoList.size());
-                List<TCUsualScore> tcUsualScoreList = new ArrayList<>(markStudentScoreVoList.size());
+                tcFinalScoreList = new ArrayList<>(markStudentScoreVoList.size());
+                tcUsualScoreList = new ArrayList<>(markStudentScoreVoList.size());
                 List<PaperStructDimensionResult> paperStructDimensionResultList = new ArrayList<>(markStudentScoreVoList.size());
                 for (int i = 0; i < markStudentScoreVoList.size(); i++) {
                     MarkStudentScoreVo markStudentScoreVo = markStudentScoreVoList.get(i);
@@ -379,42 +389,54 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
                                         SourceEnum.SYNC, sysUser.getId(), cultureProgramId, courseId));
                     }
                 }
-                if (!CollectionUtils.isEmpty(tcFinalScoreList) && !CollectionUtils.isEmpty(
-                        paperStructDimensionResultList)) {
-                    successData.add("共同步").add(tcFinalScoreList.size() + "").add("条数据");
-                    List<TCFinalScore> tcFinalScoreDbSourceList = tcFinalScoreService.queryFinalScore(cultureProgramId,
-                            courseId, paperNumber, examId, null);
-                    List<TCUsualScore> tcUsualScoreDbSourceList = tcUsualScoreService.queryUsualScore(cultureProgramId,
-                            courseId, paperNumber, examId, null);
-                    log.info("tcFinalScoreDbSourceList:{}", JacksonUtil.parseJson(tcFinalScoreDbSourceList));
-                    log.info("tcFinalScoreList:{}", JacksonUtil.parseJson(tcFinalScoreList));
-                    if (CollectionUtils.isEmpty(tcFinalScoreDbSourceList) || !CollectionUtils.isEqualCollection(
-                            tcFinalScoreDbSourceList, tcFinalScoreList)) {
-                        tcFinalScoreService.removeByIds(
-                                tcFinalScoreDbSourceList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
-                        tcFinalScoreService.saveBatch(tcFinalScoreList);
-                        trBasicInfoService.clearReportData(cultureProgramId, courseId, paperNumber, examId, true);
-                    }
-                    if (CollectionUtils.isEmpty(tcUsualScoreDbSourceList) || !CollectionUtils.isEqualCollection(
-                            tcUsualScoreDbSourceList, tcUsualScoreList)) {
-                        tcUsualScoreService.removeByIds(
-                                tcUsualScoreDbSourceList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
-                        tcUsualScoreService.saveBatch(tcUsualScoreList);
-                    }
+                if (!CollectionUtils.isEmpty(paperStructDimensionResultList)) {
                     TCPaperStruct tcPaperStruct = tcPaperStructService.queryPaperStruct(cultureProgramId, courseId, paperNumber, examId);
                     if (Objects.nonNull(tcPaperStruct)) {
                         tcPaperStructService.removeById(tcPaperStruct.getId());
                     }
-                    BasicCourse basicCourse = basicCourseService.getById(courseId);
-                    Objects.requireNonNull(basicCourse, "未找到基础课程信息");
-
                     paperStructDimensionResultList = SDFrame.read(paperStructDimensionResultList).sortDesc(Sorter.sortDescBy(PaperStructDimensionResult::getMainNumber).sortDesc(PaperStructDimensionResult::getMainNumber)).toLists();
                     tcPaperStruct = new TCPaperStruct(cultureProgramId, courseId, basicCourse.getCode(), basicCourse.getName(), paperNumber, JacksonUtil.parseJson(paperStructDimensionResultList),
-                            sysUser.getId());
-                    tcPaperStruct.setExamId(examId);
-
+                            sysUser.getId(), examId);
                     tcPaperStructService.saveOrUpdate(tcPaperStruct);
                 }
+            } else {
+                List<BasicExamStudent> basicExamStudentList = basicExamStudentService.list(new QueryWrapper<BasicExamStudent>().lambda().eq(BasicExamStudent::getExamId, examId).eq(BasicExamStudent::getCourseId, courseId).eq(BasicExamStudent::getPaperNumber, paperNumber));
+                if (!CollectionUtils.isEmpty(basicExamStudentList)) {
+                    tcFinalScoreList = new ArrayList<>(basicExamStudentList.size());
+                    tcUsualScoreList = new ArrayList<>(basicExamStudentList.size());
+                    for (BasicExamStudent basicExamStudent : basicExamStudentList) {
+                        tcFinalScoreList.add(
+                                new TCFinalScore(basicExamStudent, basicCourse,
+                                        SourceEnum.SYNC, sysUser.getId(), cultureProgramId, courseId));
+                        tcUsualScoreList.add(
+                                new TCUsualScore(basicExamStudent, basicCourse,
+                                        SourceEnum.SYNC, sysUser.getId(), cultureProgramId, courseId));
+                    }
+                }
+                TCPaperStruct tcPaperStruct = tcPaperStructService.queryPaperStruct(cultureProgramId, courseId, paperNumber, examId);
+                if (Objects.nonNull(tcPaperStruct)) {
+                    tcPaperStructService.removeById(tcPaperStruct.getId());
+                }
+            }
+            if (!CollectionUtils.isEmpty(tcFinalScoreList) && !CollectionUtils.isEmpty(tcUsualScoreList)) {
+                successData.add("共同步").add(tcFinalScoreList.size() + "").add("条数据");
+                List<TCFinalScore> tcFinalScoreDbSourceList = tcFinalScoreService.queryFinalScore(cultureProgramId,
+                        courseId, paperNumber, examId, null);
+                List<TCUsualScore> tcUsualScoreDbSourceList = tcUsualScoreService.queryUsualScore(cultureProgramId,
+                        courseId, paperNumber, examId, null);
+                if (CollectionUtils.isEmpty(tcFinalScoreDbSourceList) || !CollectionUtils.isEqualCollection(
+                        tcFinalScoreDbSourceList, tcFinalScoreList)) {
+                    tcFinalScoreService.removeByIds(
+                            tcFinalScoreDbSourceList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
+                    tcFinalScoreService.saveBatch(tcFinalScoreList);
+                    trBasicInfoService.clearReportData(cultureProgramId, courseId, paperNumber, examId, true);
+                }
+                if (CollectionUtils.isEmpty(tcUsualScoreDbSourceList) || !CollectionUtils.isEqualCollection(
+                        tcUsualScoreDbSourceList, tcUsualScoreList)) {
+                    tcUsualScoreService.removeByIds(
+                            tcUsualScoreDbSourceList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
+                    tcUsualScoreService.saveBatch(tcUsualScoreList);
+                }
             }
             messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
             messageMap.put(SystemConstant.EXCEL_ERROR, errorData.length() > 0 ? errorData.toString() : "无");