Jelajahi Sumber

3.2.3 同步云阅卷

xiaofei 2 tahun lalu
induk
melakukan
2ab5b2b1b9
41 mengubah file dengan 799 tambahan dan 412 penghapusan
  1. 119 36
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/SyncExamTaskDto.java
  2. 5 17
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/params/SyncDataParam.java
  3. 4 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/PrintPlanResult.java
  4. 4 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamDetailCourse.java
  5. 193 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamTaskSync.java
  6. 11 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TSyncStmmsExam.java
  7. 6 6
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExamTaskSyncStatusEnum.java
  8. 4 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamDetailCourseMapper.java
  9. 0 10
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamPrintPlanMapper.java
  10. 0 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamStudentMapper.java
  11. 13 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamTaskSyncMapper.java
  12. 2 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamDetailCourseService.java
  13. 5 5
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPrintPlanService.java
  14. 2 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamStudentService.java
  15. 15 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskSyncService.java
  16. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TSyncStmmsExamService.java
  17. 115 51
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java
  18. 16 14
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailCourseServiceImpl.java
  19. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java
  20. 3 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperStructureServiceImpl.java
  21. 23 60
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPrintPlanServiceImpl.java
  22. 11 11
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamStudentServiceImpl.java
  23. 2 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskPrintServiceImpl.java
  24. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java
  25. 31 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskSyncServiceImpl.java
  26. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBSyncTaskServiceImpl.java
  27. 2 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TSyncExamLogServiceImpl.java
  28. 5 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TSyncStmmsExamServiceImpl.java
  29. 2 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncCloudMarkingTaskService.java
  30. 23 0
      distributed-print-business/src/main/resources/db/3.2.3更新脚本-增量.sql
  31. 62 27
      distributed-print-business/src/main/resources/mapper/ExamDetailCourseMapper.xml
  32. 1 73
      distributed-print-business/src/main/resources/mapper/ExamPrintPlanMapper.xml
  33. 0 25
      distributed-print-business/src/main/resources/mapper/ExamStudentMapper.xml
  34. 13 33
      distributed-print/src/main/java/com/qmth/distributed/print/api/ExamPrintPlanSyncController.java
  35. 9 3
      distributed-print/src/main/java/com/qmth/distributed/print/api/SysAdminSetController.java
  36. 3 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java
  37. 11 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/SysOrg.java
  38. 9 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CommonCacheService.java
  39. 34 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CommonCacheServiceImpl.java
  40. 27 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java
  41. 10 11
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/CloudMarkingTaskUtils.java

+ 119 - 36
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/SyncExamTaskDto.java

@@ -1,35 +1,70 @@
 package com.qmth.distributed.print.business.bean.dto;
 
 
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.qmth.distributed.print.business.entity.ExamTask;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
-import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
+import cn.hutool.core.date.DateUtil;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Date: 2021/3/29.
  */
-public class SyncExamTaskDto extends ExamTask {
+public class SyncExamTaskDto {
 
+    private Long examTaskId;
+    private String courseCode;
+    private String courseName;
+    private String paperNumber;
     private String paperType;
     private String syncCardType;
+    private String sequence;
+    private Long startTime;
+    private Long endTime;
+    private String examDate;
+    private String examTime;
     private Integer totalSubjects;
+    private Integer thirdRelateId;
+    private ExamTaskSyncStatusEnum syncStatus;
+    private String syncStatusDisplay;
+    private String errorMsg;
+    private List<Map> syncStatusDetailDisplay;
+    private String syncUserName;
+    private String printPlanIds;
 
-    private Integer syncSuccessCount;
+    public Long getExamTaskId() {
+        return examTaskId;
+    }
 
-    private Integer syncFailCount;
+    public void setExamTaskId(Long examTaskId) {
+        this.examTaskId = examTaskId;
+    }
 
-    private Integer syncInitCount;
+    public String getCourseCode() {
+        return courseCode;
+    }
 
-    private String printPlanIds;
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
 
-    private Long thirdRelateId;
+    public String getCourseName() {
+        return courseName;
+    }
 
-    private String syncStatus;
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
 
-    private String syncUserName;
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
 
     public String getPaperType() {
         return paperType;
@@ -47,62 +82,102 @@ public class SyncExamTaskDto extends ExamTask {
         this.syncCardType = syncCardType;
     }
 
-    public Integer getTotalSubjects() {
-        return totalSubjects;
+    public String getSequence() {
+        return sequence;
     }
 
-    public void setTotalSubjects(Integer totalSubjects) {
-        this.totalSubjects = totalSubjects;
+    public void setSequence(String sequence) {
+        this.sequence = sequence;
     }
 
-    public Integer getSyncSuccessCount() {
-        return syncSuccessCount;
+    public Long getStartTime() {
+        return startTime;
     }
 
-    public void setSyncSuccessCount(Integer syncSuccessCount) {
-        this.syncSuccessCount = syncSuccessCount;
+    public void setStartTime(Long startTime) {
+        this.startTime = startTime;
     }
 
-    public Integer getSyncFailCount() {
-        return syncFailCount;
+    public Long getEndTime() {
+        return endTime;
     }
 
-    public void setSyncFailCount(Integer syncFailCount) {
-        this.syncFailCount = syncFailCount;
+    public void setEndTime(Long endTime) {
+        this.endTime = endTime;
     }
 
-    public Integer getSyncInitCount() {
-        return syncInitCount;
+    public String getExamDate() {
+        if (this.startTime != null) {
+            return DateUtil.format(new Date(this.startTime), SystemConstant.DATE_PATTERN);
+        }
+        return "-";
     }
 
-    public void setSyncInitCount(Integer syncInitCount) {
-        this.syncInitCount = syncInitCount;
+    public void setExamDate(String examDate) {
+        this.examDate = examDate;
     }
 
-    public String getPrintPlanIds() {
-        return printPlanIds;
+    public String getExamTime() {
+        if (this.startTime != null && this.endTime != null) {
+            String startTimeTemp = DateUtil.format(new Date(this.startTime), SystemConstant.TIME_PATTERN);
+            String endTimeTemp = DateUtil.format(new Date(this.endTime), SystemConstant.TIME_PATTERN);
+            return startTimeTemp + "-" + endTimeTemp;
+        }
+        return "-";
     }
 
-    public void setPrintPlanIds(String printPlanIds) {
-        this.printPlanIds = printPlanIds;
+    public void setExamTime(String examTime) {
+        this.examTime = examTime;
+    }
+
+    public Integer getTotalSubjects() {
+        return totalSubjects;
     }
 
-    public Long getThirdRelateId() {
+    public void setTotalSubjects(Integer totalSubjects) {
+        this.totalSubjects = totalSubjects;
+    }
+
+    public Integer getThirdRelateId() {
         return thirdRelateId;
     }
 
-    public void setThirdRelateId(Long thirdRelateId) {
+    public void setThirdRelateId(Integer thirdRelateId) {
         this.thirdRelateId = thirdRelateId;
     }
 
-    public String getSyncStatus() {
+    public ExamTaskSyncStatusEnum getSyncStatus() {
         return syncStatus;
     }
 
-    public void setSyncStatus(String syncStatus) {
+    public void setSyncStatus(ExamTaskSyncStatusEnum syncStatus) {
         this.syncStatus = syncStatus;
     }
 
+    public String getSyncStatusDisplay() {
+        return this.syncStatus != null ? syncStatus.getDesc() : "-";
+    }
+
+    public void setSyncStatusDisplay(String syncStatusDisplay) {
+        this.syncStatusDisplay = syncStatusDisplay;
+    }
+
+    public String getErrorMsg() {
+        return errorMsg;
+    }
+
+    public void setErrorMsg(String errorMsg) {
+        this.errorMsg = errorMsg;
+    }
+
+    public List<Map> getSyncStatusDetailDisplay() {
+        return syncStatusDetailDisplay;
+    }
+
+    public void setSyncStatusDetailDisplay(List<Map> syncStatusDetailDisplay) {
+        this.syncStatusDetailDisplay = syncStatusDetailDisplay;
+    }
+
     public String getSyncUserName() {
         return syncUserName;
     }
@@ -110,4 +185,12 @@ public class SyncExamTaskDto extends ExamTask {
     public void setSyncUserName(String syncUserName) {
         this.syncUserName = syncUserName;
     }
+
+    public String getPrintPlanIds() {
+        return printPlanIds;
+    }
+
+    public void setPrintPlanIds(String printPlanIds) {
+        this.printPlanIds = printPlanIds;
+    }
 }

+ 5 - 17
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/params/SyncDataParam.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.bean.params;
 
 import com.alibaba.fastjson.JSONObject;
+import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
 
 import java.util.List;
 
@@ -9,11 +10,6 @@ import java.util.List;
  */
 public class SyncDataParam {
 
-    /**
-     * 印刷计划ID
-     */
-    private Long printPlanId;
-
     /**
      * thirdRelateId、thirdRelateName二选一,若thirdRelateId有值优先用thirdRelateId值
      */
@@ -30,17 +26,9 @@ public class SyncDataParam {
     private Long examTime;
 
     /**
-     * examTaskId集合
+     * 参数
      */
-    private List<JSONObject> list;
-
-    public Long getPrintPlanId() {
-        return printPlanId;
-    }
-
-    public void setPrintPlanId(Long printPlanId) {
-        this.printPlanId = printPlanId;
-    }
+    private List<SyncExamTaskDto> list;
 
     public Long getThirdRelateId() {
         return thirdRelateId;
@@ -66,11 +54,11 @@ public class SyncDataParam {
         this.examTime = examTime;
     }
 
-    public List<JSONObject> getList() {
+    public List<SyncExamTaskDto> getList() {
         return list;
     }
 
-    public void setList(List<JSONObject> list) {
+    public void setList(List<SyncExamTaskDto> list) {
         this.list = list;
     }
 }

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/PrintPlanResult.java

@@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.distributed.print.business.enums.BackupMethodEnum;
 import com.qmth.teachcloud.common.enums.DrawRuleEnum;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -94,7 +94,7 @@ public class PrintPlanResult {
     private String thirdRelateName;
 
     @ApiModelProperty("是否同步成功")
-    private ExamPrintPlanSyncStatusEnum syncStatus;
+    private ExamTaskSyncStatusEnum syncStatus;
 
     @ApiModelProperty("考试id")
     @JsonSerialize(using = ToStringSerializer.class)
@@ -299,11 +299,11 @@ public class PrintPlanResult {
         this.thirdRelateName = thirdRelateName;
     }
 
-    public ExamPrintPlanSyncStatusEnum getSyncStatus() {
+    public ExamTaskSyncStatusEnum getSyncStatus() {
         return syncStatus;
     }
 
-    public void setSyncStatus(ExamPrintPlanSyncStatusEnum syncStatus) {
+    public void setSyncStatus(ExamTaskSyncStatusEnum syncStatus) {
         this.syncStatus = syncStatus;
     }
 

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamDetailCourse.java

@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.teachcloud.common.base.BaseEntity;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -75,7 +75,7 @@ public class ExamDetailCourse extends BaseEntity implements Serializable {
     private Long thirdRelateId;
 
     @TableField("sync_status")
-    private ExamPrintPlanSyncStatusEnum syncStatus;
+    private ExamTaskSyncStatusEnum syncStatus;
 
     @TableField("sync_user_id")
     private Long syncUserId;
@@ -196,11 +196,11 @@ public class ExamDetailCourse extends BaseEntity implements Serializable {
         this.thirdRelateId = thirdRelateId;
     }
 
-    public ExamPrintPlanSyncStatusEnum getSyncStatus() {
+    public ExamTaskSyncStatusEnum getSyncStatus() {
         return syncStatus;
     }
 
-    public void setSyncStatus(ExamPrintPlanSyncStatusEnum syncStatus) {
+    public void setSyncStatus(ExamTaskSyncStatusEnum syncStatus) {
         this.syncStatus = syncStatus;
     }
 

+ 193 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamTaskSync.java

@@ -0,0 +1,193 @@
+package com.qmth.distributed.print.business.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.enums.ExamStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ReviewStatusEnum;
+import com.qmth.teachcloud.common.annotation.EditKey;
+import com.qmth.teachcloud.common.base.BaseEntity;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * 数据同步
+ * </p>
+ *
+ */
+@TableName("exam_task_sync")
+public class ExamTaskSync extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "id")
+    @EditKey
+    private Long id;
+
+    @ApiModelProperty(value = "学校id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableField("school_id")
+    private Long schoolId;
+
+    /**
+     * 课程代码
+     */
+    @TableField("course_code")
+    private String courseCode;
+    /**
+     * 试卷编号
+     */
+    @TableField("paper_number")
+    private String paperNumber;
+
+    /**
+     * 机构代码
+     */
+    @TableField("org_code")
+    private String orgCode;
+
+    /**
+     * 云阅卷考试ID
+     */
+    @TableField("third_relate_id")
+    private Integer thirdRelateId;
+    /**
+     * 同步状态
+     */
+    @TableField("sync_status")
+    private ExamTaskSyncStatusEnum syncStatus;
+    @TableField(value = "error_msg", updateStrategy = FieldStrategy.IGNORED)
+    private String errorMsg;
+    /**
+     * 同步用户ID
+     */
+    @TableField("sync_user_id")
+    private Long syncUserId;
+
+    /**
+     * 同步开始时间
+     */
+    @TableField("sync_start_time")
+    private Long syncStartTime;
+    /**
+     * 同步结束时间
+     */
+    @TableField("sync_end_time")
+    private Long syncEndTime;
+
+    public ExamTaskSync() {
+    }
+
+    public ExamTaskSync(Long schoolId, String courseCode, String paperNumber, String orgCode, Integer thirdRelateId, ExamTaskSyncStatusEnum syncStatus, Long syncUserId, Long syncStartTime, Long syncEndTime) {
+        this.id = SystemConstant.getDbUuid();
+        this.schoolId = schoolId;
+        this.courseCode = courseCode;
+        this.paperNumber = paperNumber;
+        this.orgCode = orgCode;
+        this.thirdRelateId = thirdRelateId;
+        this.syncStatus = syncStatus;
+        this.syncUserId = syncUserId;
+        this.syncStartTime = syncStartTime;
+        this.syncEndTime = syncEndTime;
+    }
+
+    @Override
+    public Long getId() {
+        return id;
+    }
+
+    @Override
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Long schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+
+    public String getOrgCode() {
+        return orgCode;
+    }
+
+    public void setOrgCode(String orgCode) {
+        this.orgCode = orgCode;
+    }
+
+    public Integer getThirdRelateId() {
+        return thirdRelateId;
+    }
+
+    public void setThirdRelateId(Integer thirdRelateId) {
+        this.thirdRelateId = thirdRelateId;
+    }
+
+    public ExamTaskSyncStatusEnum getSyncStatus() {
+        return syncStatus;
+    }
+
+    public void setSyncStatus(ExamTaskSyncStatusEnum syncStatus) {
+        this.syncStatus = syncStatus;
+    }
+
+    public String getErrorMsg() {
+        return errorMsg;
+    }
+
+    public void setErrorMsg(String errorMsg) {
+        this.errorMsg = errorMsg;
+    }
+
+    public Long getSyncUserId() {
+        return syncUserId;
+    }
+
+    public void setSyncUserId(Long syncUserId) {
+        this.syncUserId = syncUserId;
+    }
+
+    public Long getSyncStartTime() {
+        return syncStartTime;
+    }
+
+    public void setSyncStartTime(Long syncStartTime) {
+        this.syncStartTime = syncStartTime;
+    }
+
+    public Long getSyncEndTime() {
+        return syncEndTime;
+    }
+
+    public void setSyncEndTime(Long syncEndTime) {
+        this.syncEndTime = syncEndTime;
+    }
+}

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TSyncStmmsExam.java

@@ -28,6 +28,9 @@ public class TSyncStmmsExam implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long schoolId;
 
+    @ApiModelProperty(value = "机构代码")
+    private String orgCode;
+
     @ApiModelProperty(value = "考试id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Integer examId;
@@ -91,4 +94,12 @@ public class TSyncStmmsExam implements Serializable {
     public void setCreateTime(Long createTime) {
         this.createTime = createTime;
     }
+
+    public String getOrgCode() {
+        return orgCode;
+    }
+
+    public void setOrgCode(String orgCode) {
+        this.orgCode = orgCode;
+    }
 }

+ 6 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExamPrintPlanSyncStatusEnum.java → distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExamTaskSyncStatusEnum.java

@@ -6,16 +6,16 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 考试试卷结构同步状态
+ * 云阅卷同步状态
  */
-public enum ExamPrintPlanSyncStatusEnum {
+public enum ExamTaskSyncStatusEnum {
 
     INIT("未开始"),
-    START("开始同步"),
-    PART_FINISH("部分成功"),
+    STARTING("同步"),
+    FAIL("同步失败"),
     FINISH("同步成功");
 
-    ExamPrintPlanSyncStatusEnum(String desc) {
+    ExamTaskSyncStatusEnum(String desc) {
         this.desc = desc;
     }
 
@@ -30,7 +30,7 @@ public enum ExamPrintPlanSyncStatusEnum {
      */
     public static List<EnumResult> listTypes() {
         List<EnumResult> list = new ArrayList<EnumResult>();
-        for (ExamPrintPlanSyncStatusEnum value : ExamPrintPlanSyncStatusEnum.values()) {
+        for (ExamTaskSyncStatusEnum value : ExamTaskSyncStatusEnum.values()) {
             EnumResult result = new EnumResult();
             result.setName(value.name());
             result.setOrdinal(value.ordinal());

+ 4 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamDetailCourseMapper.java

@@ -1,9 +1,11 @@
 package com.qmth.distributed.print.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
 import com.qmth.distributed.print.business.entity.ExamDetailCourse;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
 import com.qmth.teachcloud.common.entity.BasicCourse;
 import org.apache.ibatis.annotations.Param;
@@ -35,7 +37,7 @@ public interface ExamDetailCourseMapper extends BaseMapper<ExamDetailCourse> {
 
     List<ExamDetailCourse> listByAndCourseCodeAndPaperNumber(@Param("schoolId") Long schoolId,@Param("courseCode") String courseCode,@Param("paperNumber") String paperNumber);
 
-    List<SyncExamTaskDto> listSyncCourseByPrintPlanId(@Param("printPlanIds") List<Long> printPlanIds, @Param("courseName") String courseName);
-
     List<ExamDetailCourseDto> listByPrintPlanIdAndExamTaskId(@Param("printPlanIds") List<Long> printPlanIds, @Param("examTaskId") Long examTaskId);
+
+    List<SyncExamTaskDto> listSyncCourseByPrintPlanId(@Param("ipage") Page<SyncExamTaskDto> ipage, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("orgIds") Set<Long> orgIds, @Param("cardType") SyncCardTypeEnum cardType, @Param("syncStatus") ExamTaskSyncStatusEnum syncStatus, @Param("courseName") String courseName, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
 }

+ 0 - 10
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamPrintPlanMapper.java

@@ -33,16 +33,6 @@ public interface ExamPrintPlanMapper extends BaseMapper<ExamPrintPlan> {
                                              @Param("endTime") Long endTime,
                                              @Param("dpr") DataPermissionRule dpr);
 
-    IPage<PrintPlanResult> findPrintPlanSyncPage(@Param("iPage") Page<PrintPlanResult> iPage,
-                                                 @Param("schoolId") Long schoolId,
-                                                 @Param("semesterId") Long semesterId,
-                                                 @Param("examId") Long examId,
-                                                 @Param("status") String[] status,
-                                                 @Param("printPlanId") Long printPlanId,
-                                                 @Param("startTime") Long startTime,
-                                                 @Param("endTime") Long endTime,
-                                                 @Param("dpr") DataPermissionRule dpr);
-
     List<PrintPlanBrief> list(@Param("schoolId") Long schoolId, @Param("source") String source, @Param("module") String module, @Param("status") String[] status, @Param("dpr") DataPermissionRule dpr);
 
     IPage<ClientPrintTaskDto> listClientPrintTask(Page<ClientPrintTaskDto> page, @Param("schoolId") Long schoolId, @Param("machineCode") String machineCode, @Param("printPlanId") String printPlanId, @Param("status") String status, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("examPlace") String examPlace, @Param("examRoom") String examRoom, @Param("examStartTime") Long examStartTime, @Param("examEndTime") Long examEndTime, @Param("isDownload") Boolean isDownload, @Param("validate") Boolean validate, @Param("orgId") Long orgId, @Param("examDetailStatus") String[] examDetailStatus);

+ 0 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamStudentMapper.java

@@ -34,8 +34,6 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudent> {
      */
     List<ExamStudentCourseDto> queryBySchoolIdAndExamDetailCourseIds(@Param("schoolId") Long schoolId, @Param("examDetailCourseIds") List<Long> examDetailCourseIds);
 
-    List<SyncExamStudentDto> listStudentByPrintPlanIdAndSyncStatus(Long printPlanId);
-
     void insertBatch(@Param("examStudents") List<ExamStudent> examStudents);
 
     /**

+ 13 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamTaskSyncMapper.java

@@ -0,0 +1,13 @@
+package com.qmth.distributed.print.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.distributed.print.business.entity.ExamTaskSync;
+
+/**
+ * <p>
+ * 数据同步 Mapper 接口
+ * </p>
+ */
+public interface ExamTaskSyncMapper extends BaseMapper<ExamTaskSync> {
+
+}

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

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
 import com.qmth.distributed.print.business.entity.ExamDetailCourse;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
 import com.qmth.teachcloud.common.entity.BasicCourse;
 
@@ -35,7 +36,7 @@ public interface ExamDetailCourseService extends IService<ExamDetailCourse> {
 
     List<ExamDetailCourse> listByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber);
 
-    List<SyncExamTaskDto> listSyncCourseByPrintPlanId(List<Long> printPlanIds, SyncCardTypeEnum cardType, String courseName);
+    List<SyncExamTaskDto> listSyncCourseByPrintPlanId(Long semesterId, Long examId, Long orgId, SyncCardTypeEnum cardType, ExamTaskSyncStatusEnum syncStatus, String courseName, Long startTime, Long endTime, Integer pageNumber, Integer pageSize);
 
     List<ExamDetailCourseDto> listByPrintPlanIdAndExamTaskId(List<Long> printPlanIds, Long examTaskId);
 }

+ 5 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPrintPlanService.java

@@ -10,6 +10,7 @@ import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.bean.result.PrintPlanBrief;
 import com.qmth.distributed.print.business.bean.result.PrintPlanResult;
 import com.qmth.distributed.print.business.entity.ExamPrintPlan;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
 import com.qmth.teachcloud.common.entity.SysUser;
@@ -43,8 +44,6 @@ public interface ExamPrintPlanService extends IService<ExamPrintPlan> {
      */
     IPage<PrintPlanResult> printPlanPage(Long schoolId, Long semesterId, Long examId, List<Long> printPlanIdList, PrintPlanStatusEnum status, Long startTime, Long endTime, int pageNumber, int pageSize);
 
-    IPage<PrintPlanResult> printPlanSyncPage(Long schoolId, Long semesterId, Long examId, Long printPlanId, Long startTime, Long endTime, int pageNumber, int pageSize);
-
     /**
      * 印刷计划模糊名称
      *
@@ -106,13 +105,14 @@ public interface ExamPrintPlanService extends IService<ExamPrintPlan> {
 
     /**
      * 根据学校id和试卷编号查询印刷计划
-     * @param schoolId 学校id
+     *
+     * @param schoolId    学校id
      * @param paperNumber 试卷编号
      * @return 印刷计划
      */
-    List<ExamPrintPlan> findByPaperNumber(Long schoolId,String paperNumber);
+    List<ExamPrintPlan> findByPaperNumber(Long schoolId, String paperNumber);
 
     List<ExamPrintPlan> listBySchoolId(Long schoolId);
 
-    List<SyncExamTaskDto> listSyncExamTask(List<Long> printPlanIds, SyncCardTypeEnum cardType, String courseName);
+    List<SyncExamTaskDto> listSyncExamTask(Long semesterId, Long examId, Long orgId, SyncCardTypeEnum cardType, ExamTaskSyncStatusEnum syncStatus, String courseName, Long startTime, Long endTime, Integer pageNumber, Integer pageSize);
 }

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

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentPdfInfoDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
@@ -35,8 +36,6 @@ public interface ExamStudentService extends IService<ExamStudent> {
      */
     List<ExamStudentCourseDto> queryBySchoolIdAndExamDetailCourseIds(Long schoolId, List<Long> examDetailCourseIds);
 
-    List<SyncExamStudentDto> listStudentByPrintPlanIdAndSyncStatus(Long printPlanId);
-
     void insertBatch(List<ExamStudent> examStudents);
 
     List<ExamStudent> listExamStudentBySchoolIdAndClazzId(Long schoolId, String classId);
@@ -47,5 +46,5 @@ public interface ExamStudentService extends IService<ExamStudent> {
 
     List<Map> listStudentScoreSync(Long schoolId, String studentCode, String examNumber, String subjectCode);
 
-    List<SyncExamStudentDto> listStudentByExamDetailCourseId(Long examDetailCourseId);
+    List<SyncExamStudentDto> listStudentByExamDetailCourseId(List<ExamDetailCourseDto> examDetailCourseList);
 }

+ 15 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskSyncService.java

@@ -0,0 +1,15 @@
+package com.qmth.distributed.print.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
+import com.qmth.distributed.print.business.entity.ExamTaskSync;
+
+/**
+ * <p>
+ * 数据同步 服务类
+ * </p>
+ */
+public interface ExamTaskSyncService extends IService<ExamTaskSync> {
+
+    ExamTaskSync getBySchoolIdAndOrgCodeAndPaperNumber(Long schoolId, String orgCode, String paperNumber);
+}

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

@@ -14,5 +14,5 @@ public interface TSyncStmmsExamService extends IService<TSyncStmmsExam> {
 
     List<TSyncStmmsExam> syncExam();
 
-    TSyncStmmsExam getBySchoolIdAndExamId(Long schoolId, Long thirdRelateId);
+    TSyncStmmsExam getBySchoolIdAndExamId(Long schoolId, String orgCode, Long thirdRelateId);
 }

+ 115 - 51
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -7,9 +7,10 @@ import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.CardDetailDto;
 import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
+import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.bean.dto.stmms.GroupDetailDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.PicConfig;
@@ -19,12 +20,14 @@ 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.BasicCollege;
+import com.qmth.teachcloud.common.entity.SysOrg;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.SyncFileTypeEnum;
 import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
+import com.qmth.teachcloud.common.service.SysOrgService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
 import com.qmth.teachcloud.common.sync.CloudMarkingTaskUtils;
 import org.apache.commons.io.IOUtils;
@@ -51,16 +54,16 @@ public class DataSyncServiceImpl implements DataSyncService {
     private final static Logger log = LoggerFactory.getLogger(DataSyncServiceImpl.class);
 
     @Resource
-    private ExamPrintPlanService examPrintPlanService;
+    private ExamTaskSyncService examTaskSyncService;
 
     @Resource
-    private TBSyncTaskService tbSyncTaskService;
+    private TSyncStmmsExamService tSyncStmmsExamService;
 
     @Resource
-    private ExamStudentService examStudentService;
+    private TBSyncTaskService tbSyncTaskService;
 
     @Resource
-    private ExamDetailService examDetailService;
+    private ExamStudentService examStudentService;
 
     @Resource
     private ExamDetailCourseService examDetailCourseService;
@@ -98,7 +101,6 @@ public class DataSyncServiceImpl implements DataSyncService {
     @Async
     @Override
     public void syncExamAndStudentAndCard(Long thirdRelateId, String thirdRelateName, String examTime, TBSyncTask tbSyncTask, SysUser sysUser) {
-        ExamPrintPlanSyncStatusEnum syncStatus;
 
         // 同步初始参数
         TaskResultEnum result = null;
@@ -106,42 +108,67 @@ public class DataSyncServiceImpl implements DataSyncService {
         String errorMessage = null;
         Long schoolId = tbSyncTask.getSchoolId();
         Long objectId = tbSyncTask.getObjectId();
-        List<JSONObject> examTaskIds = JSONObject.parseArray(tbSyncTask.getRemark(), JSONObject.class);
+        JSONObject object = JSONObject.parseObject(tbSyncTask.getRemark());
+        SysOrg sysOrg = object.getObject("sysOrg", SysOrg.class);
+        Integer thirdRelateOrgId = sysOrg.getThirdRelateId();
+        String orgCode = sysOrg.getCode();
+        String orgName = sysOrg.getName();
+        List<SyncExamTaskDto> params = JSONObject.parseArray(object.getString("param"), SyncExamTaskDto.class);
+
+        // 各步骤状态
         try {
             // 同步中
             status = TaskStatusEnum.RUNNING;
             tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, null, null);
 
-            // 同步计划 -> 同步到云阅卷考试
-            thirdRelateId = saveExam(schoolId, objectId, thirdRelateId, thirdRelateName, examTime);
-            syncStatus = ExamPrintPlanSyncStatusEnum.PART_FINISH;
-            // 考试同步成功,才能同步考生和题卡
-            if (Objects.isNull(thirdRelateId)) {
-                throw ExceptionResultEnum.ERROR.exception("无法获取云阅卷考试ID,同步数据失败");
-            }
+            // 同步机构
+            thirdRelateOrgId = saveSchool(schoolId, thirdRelateOrgId, orgCode, orgName);
+            // 同步考试
+            thirdRelateId = saveExam(schoolId, objectId, orgCode, thirdRelateId, thirdRelateName, examTime);
+            //按课程做同步
+            for (SyncExamTaskDto param : params) {
+                Long examTaskId = param.getExamTaskId();
+                ExamTask examTask = examTaskService.getById(examTaskId);
+                ExamTaskSync examTaskSync = examTaskSyncService.getBySchoolIdAndOrgCodeAndPaperNumber(schoolId, orgCode, examTask.getPaperNumber());
+                if (examTaskSync != null && ExamTaskSyncStatusEnum.STARTING.equals(examTaskSync.getSyncStatus())) {
+                    throw ExceptionResultEnum.ERROR.exception("其它任务中该课程正在同步中,请刷新列表查看最新状态");
+                }
+                ExamTaskSyncStatusEnum syncStatus = ExamTaskSyncStatusEnum.STARTING;
+
+                if (examTaskSync == null) {
+                    examTaskSync = new ExamTaskSync(schoolId, examTask.getCourseCode(), examTask.getPaperNumber(), orgCode, thirdRelateOrgId, syncStatus, sysUser.getId(), System.currentTimeMillis(), null);
+                } else {
+                    examTaskSync.setSyncStatus(syncStatus);
+                    examTaskSync.setSyncStartTime(System.currentTimeMillis());
+                    examTaskSync.setSyncUserId(sysUser.getId());
+                    examTaskSync.setErrorMsg(null);
+                }
+                examTaskSyncService.saveOrUpdate(examTaskSync);
+
+                try {
+                    List<Long> printPlanIds = Arrays.asList(param.getPrintPlanIds().split(",")).stream().map(m -> Long.parseLong(m)).collect(Collectors.toList());
+                    List<ExamDetailCourseDto> examDetailCourseList = examDetailCourseService.listByPrintPlanIdAndExamTaskId(printPlanIds, examTaskId);
+                    // 同步考生
+                    List<SyncExamStudentDto> syncExamStudentDtoList = examStudentService.listStudentByExamDetailCourseId(examDetailCourseList);
+
+                    long count = syncExamStudentDtoList.stream().filter(m -> StringUtils.isBlank(m.getPaperType())).count();
+                    if (count > 0) {
+                        throw ExceptionResultEnum.ERROR.exception("部分学生未关联试卷类型,数量[" + count + "]");
+                    }
+                    // 同步考生
+                    saveStudent(schoolId, thirdRelateId, syncExamStudentDtoList);
 
-            for (JSONObject object : examTaskIds) {
-                List<Long> printPlanIds = Arrays.asList(object.getString("printPlanIds").split(",")).stream().map(m -> Long.parseLong(m)).collect(Collectors.toList());
-                Long examTaskId = object.getLong("id");
-                List<ExamDetailCourseDto> examDetailCourseList = examDetailCourseService.listByPrintPlanIdAndExamTaskId(printPlanIds, examTaskId);
-                for (ExamDetailCourseDto examDetailCourseDto : examDetailCourseList) {
-                    try {
-                        // 同步考生
-                        saveStudent(schoolId, thirdRelateId, examDetailCourseDto.getId());
-                        syncStatus = ExamPrintPlanSyncStatusEnum.PART_FINISH;
+                    // 同步题卡
+                    for (ExamDetailCourseDto examDetailCourseDto : examDetailCourseList) {
                         // 同步题卡
-                        cardUpload(schoolId, thirdRelateId, examDetailCourseDto.getExamTaskId(), examDetailCourseDto.getPaperType());
-                        syncStatus = ExamPrintPlanSyncStatusEnum.FINISH;
-                    } catch (Exception e) {
-                        throw new RuntimeException("推送考生信息、题卡信息失败,试卷编号:" + examDetailCourseDto.getPaperNumber() + SystemConstant.COMMA_OF_CHINESE + e.getMessage());
-                    } finally {
-                        UpdateWrapper<ExamDetailCourse> examDetailCourseUpdateWrapper = new UpdateWrapper<>();
-                        examDetailCourseUpdateWrapper.lambda().set(ExamDetailCourse::getThirdRelateId, thirdRelateId)
-                                .set(ExamDetailCourse::getSyncStatus, syncStatus)
-                                .set(ExamDetailCourse::getSyncUserId, sysUser.getId())
-                                .eq(ExamDetailCourse::getId, examDetailCourseDto.getId());
-                        examDetailCourseService.update(examDetailCourseUpdateWrapper);
+                        cardUpload(schoolId, thirdRelateId, examTask, examDetailCourseDto.getPaperType());
                     }
+                } catch (Exception e) {
+                    examTaskSync.setErrorMsg(e.getMessage());
+                    examTaskSync.setSyncStatus(ExamTaskSyncStatusEnum.FAIL);
+                } finally {
+                    examTaskSync.setSyncStatus(ExamTaskSyncStatusEnum.FINISH);
+                    examTaskSyncService.saveOrUpdate(examTaskSync);
                 }
             }
             // 任务结果
@@ -449,25 +476,71 @@ public class DataSyncServiceImpl implements DataSyncService {
         }
     }
 
+    /**
+     * 创建考试
+     *
+     * @param schoolId      学校ID
+     * @param thirdRelateId 学院ID
+     * @param orgCode       学院代码
+     * @param orgName       学院名称
+     */
+    public Integer saveSchool(Long schoolId, Integer thirdRelateId, String orgCode, String orgName) {
+        try {
+            if (Objects.isNull(thirdRelateId)) {
+                thirdRelateId = cloudMarkingTaskUtils.syncSchool(schoolId, orgCode, orgName);
+            }
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+        try {
+            UpdateWrapper<SysOrg> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.lambda().set(SysOrg::getThirdRelateId, thirdRelateId)
+                    .eq(SysOrg::getSchoolId, schoolId)
+                    .eq(SysOrg::getCode, orgCode)
+                    .isNull(SysOrg::getThirdRelateId);
+        } catch (Exception e) {
+            log.error("保存云阅卷机构数据失败。");
+        }
+        return thirdRelateId;
+    }
+
     /**
      * 创建考试
      *
      * @param schoolId        学校ID
-     * @param printPlanId     计划ID
+     * @param objectId        计划ID
+     * @param orgCode         学院代码
      * @param thirdRelateId   云阅卷考试ID
      * @param thirdRelateName 云阅卷考试名称
      * @param examTime        考试时间
      */
-    public Long saveExam(Long schoolId, Long printPlanId, Long thirdRelateId, String thirdRelateName, String examTime) {
+    public Long saveExam(Long schoolId, Long objectId, String orgCode, Long thirdRelateId, String thirdRelateName, String examTime) {
         try {
             if (Objects.isNull(thirdRelateId)) {
-                String code = String.valueOf(printPlanId);
+                String code = String.valueOf(objectId);
                 thirdRelateId = cloudMarkingTaskUtils.syncExam(schoolId, code, thirdRelateName, examTime);
             }
-            return thirdRelateId;
+
         } catch (Exception e) {
             throw ExceptionResultEnum.ERROR.exception(e.getMessage());
         }
+        try {
+            TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(schoolId, orgCode, thirdRelateId);
+            if (tSyncStmmsExam == null) {
+                tSyncStmmsExam = new TSyncStmmsExam();
+                tSyncStmmsExam.setId(SystemConstant.getDbUuid());
+                tSyncStmmsExam.setSchoolId(schoolId);
+                if (StringUtils.isNotBlank(orgCode)) {
+                    tSyncStmmsExam.setOrgCode(orgCode);
+                }
+                tSyncStmmsExam.setExamId(thirdRelateId.intValue());
+                tSyncStmmsExam.setExamName(thirdRelateName);
+                tSyncStmmsExamService.save(tSyncStmmsExam);
+            }
+        } catch (Exception e) {
+            log.error("保存云阅卷考试数据失败。页面上可刷新从云阅卷系统获取考试列表。");
+        }
+        return thirdRelateId;
     }
 
     /**
@@ -476,13 +549,8 @@ public class DataSyncServiceImpl implements DataSyncService {
      * @param schoolId      学校ID
      * @param thirdRelateId 云阅卷考试ID
      */
-    public void saveStudent(Long schoolId, Long thirdRelateId, Long examDetailCourseId) {
-        List<SyncExamStudentDto> examStudents = examStudentService.listStudentByExamDetailCourseId(examDetailCourseId);
-        long count = examStudents.stream().filter(m -> StringUtils.isBlank(m.getPaperType())).count();
-        if (count > 0) {
-            throw ExceptionResultEnum.ERROR.exception("部分学生未关联试卷类型,数量[" + count + "]");
-        }
-        for (SyncExamStudentDto examStudent : examStudents) {
+    public void saveStudent(Long schoolId, Long thirdRelateId, List<SyncExamStudentDto> syncExamStudentDtoList) {
+        for (SyncExamStudentDto examStudent : syncExamStudentDtoList) {
             try {
                 //参数
                 String examId = String.valueOf(thirdRelateId);
@@ -518,15 +586,11 @@ public class DataSyncServiceImpl implements DataSyncService {
      * @param schoolId      学校ID
      * @param thirdRelateId 云阅卷考试ID
      */
-    public void cardUpload(Long schoolId, Long thirdRelateId, Long examTaskId, String paperType) {
-        ExamTask examTask = examTaskService.getById(examTaskId);
-        if (examTask == null) {
-            throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,命题任务ID[%s]数据为空", examTaskId));
-        }
+    public void cardUpload(Long schoolId, Long thirdRelateId, ExamTask examTask, String paperType) {
         ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTask.getId());
         List<JSONObject> paperAttachmentIds = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), JSONObject.class);
         if (paperAttachmentIds.isEmpty()) {
-            throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,通过命题任务ID[%s],查询试卷信息为空", examTask.getId()));
+            throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,试卷编号[%s]未查询到题卡信息", examTask.getPaperNumber()));
         }
 
         if (StringUtils.isBlank(paperType)) {

+ 16 - 14
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailCourseServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
@@ -17,14 +18,15 @@ import com.qmth.distributed.print.business.service.ExamDetailCourseService;
 import com.qmth.distributed.print.business.service.ExamTaskDetailService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicCourse;
+import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
-import org.apache.commons.lang3.StringUtils;
+import com.qmth.teachcloud.common.service.SysOrgService;
+import com.qmth.teachcloud.common.util.ServletUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * <p>
@@ -43,6 +45,9 @@ public class ExamDetailCourseServiceImpl extends ServiceImpl<ExamDetailCourseMap
     @Resource
     private ExamCardService examCardService;
 
+    @Resource
+    private SysOrgService sysOrgService;
+
     @Override
     public List<Map<String, Object>> listByExamDetailId(Long examDetailId) {
         return this.baseMapper.listByExamDetailId(examDetailId, ExamDetailStatusEnum.FINISH.name());
@@ -83,12 +88,16 @@ public class ExamDetailCourseServiceImpl extends ServiceImpl<ExamDetailCourseMap
     }
 
     @Override
-    public List<SyncExamTaskDto> listSyncCourseByPrintPlanId(List<Long> printPlanIds, SyncCardTypeEnum cardType, String courseName) {
-        List<SyncExamTaskDto> examTaskDtos = this.baseMapper.listSyncCourseByPrintPlanId(printPlanIds, courseName);
+    public List<SyncExamTaskDto> listSyncCourseByPrintPlanId(Long semesterId, Long examId, Long orgId, SyncCardTypeEnum cardType, ExamTaskSyncStatusEnum syncStatus, String courseName, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        Page<SyncExamTaskDto> ipage = new Page<>(pageNumber, pageSize);
+        // 查询用户所在机构及以下机构
+        Set<Long> orgIds = sysOrgService.findDeepOrgIdListByUserId(sysUser.getId());
+        List<SyncExamTaskDto> examTaskDtos = this.baseMapper.listSyncCourseByPrintPlanId(ipage, semesterId, examId, orgIds, cardType, syncStatus, courseName, startTime, endTime);
         for (SyncExamTaskDto examTaskDto : examTaskDtos) {
             String paperType = examTaskDto.getPaperType();
             List<String> paperTypes = Arrays.asList(paperType.split(","));
-            ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTaskDto.getId());
+            ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTaskDto.getExamTaskId());
             List<JSONObject> paperAttachments = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), JSONObject.class);
             List<Long> cardIds = paperAttachments.stream().filter(m -> paperTypes.contains(m.getString("name"))).map(m -> m.getLong("cardId")).collect(Collectors.toList());
             QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
@@ -106,16 +115,9 @@ public class ExamDetailCourseServiceImpl extends ServiceImpl<ExamDetailCourseMap
             if (stringSet.size() > 0) {
                 examTaskDto.setSyncCardType(String.join(",", stringSet));
             }
-
-            // 解析同步状态
-            String syncStatus = examTaskDto.getSyncStatus();
-            if (StringUtils.isNotBlank(syncStatus)) {
-                List<String> collect = Stream.of(syncStatus.split(",")).map(m -> ExamPrintPlanSyncStatusEnum.valueOf(m).getDesc()).collect(Collectors.toList());
-                examTaskDto.setSyncStatus(collect.isEmpty() ? "-" : String.join(",", collect));
-            }
         }
-        if(cardType != null){
-            examTaskDtos = examTaskDtos.stream().filter(m->m.getSyncCardType().contains(cardType.getDesc())).collect(Collectors.toList());
+        if (cardType != null) {
+            examTaskDtos = examTaskDtos.stream().filter(m -> m.getSyncCardType().contains(cardType.getDesc())).collect(Collectors.toList());
         }
         return examTaskDtos;
     }

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

@@ -629,7 +629,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
             examDetailCourse.setCourseName(courseName);
             examDetailCourse.setPaperNumber(paperNumber);
             examDetailCourse.setTotalSubjects(totalSubjects);
-            examDetailCourse.setSyncStatus(ExamPrintPlanSyncStatusEnum.INIT);
+            examDetailCourse.setSyncStatus(ExamTaskSyncStatusEnum.INIT);
             examDetailCourse.setCreateId(userId);
             examDetailCourse.setUpdateId(userId);
             examDetailCourseList.add(examDetailCourse);

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

@@ -15,7 +15,7 @@ import com.qmth.distributed.print.business.bean.dto.ExamPaperSubjectiveStructure
 import com.qmth.distributed.print.business.bean.marking.*;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.mapper.ExamPaperStructureMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
@@ -103,7 +103,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, sysUser.getId(), ServletUtil.getRequest().getServletPath());
         Page<ExamPaperStructure> page = new Page<>(pageNumber, pageSize);
-        IPage<ExamPaperStructure> examPaperStructureIPage = this.baseMapper.listByPropositionTeacherId(page, schoolId, semesterId, examId, sysUser.getId(), ExamPrintPlanSyncStatusEnum.FINISH.name(), structureStatusEnums, ready, dpr);
+        IPage<ExamPaperStructure> examPaperStructureIPage = this.baseMapper.listByPropositionTeacherId(page, schoolId, semesterId, examId, sysUser.getId(), ExamTaskSyncStatusEnum.FINISH.name(), structureStatusEnums, ready, dpr);
         examPaperStructureIPage.getRecords().forEach(m -> {
             m.setStatusStr(ExamPaperStructureStatusEnum.INIT.equals(m.getStatus()) ? "未提交" : "已提交");
 
@@ -322,7 +322,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         String[] structureStatusEnums = new String[]{ExamPaperStructureStatusEnum.FINISH.name()};
-        List<ExamPaperStructure> examPaperStructureList = this.baseMapper.listByPropositionTeacherId(schoolId, null, null, sysUser.getId(), ExamPrintPlanSyncStatusEnum.FINISH.name(), structureStatusEnums, ready,null);
+        List<ExamPaperStructure> examPaperStructureList = this.baseMapper.listByPropositionTeacherId(schoolId, null, null, sysUser.getId(), ExamTaskSyncStatusEnum.FINISH.name(), structureStatusEnums, ready,null);
         return CollectionUtils.isEmpty(examPaperStructureList) ? 0 : examPaperStructureList.size();
     }
 

+ 23 - 60
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPrintPlanServiceImpl.java

@@ -15,6 +15,8 @@ import com.qmth.distributed.print.business.bean.result.PrintPlanResult;
 import com.qmth.distributed.print.business.bean.result.TemplatePrintInfoResult;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
+import com.qmth.teachcloud.common.entity.*;
 import com.qmth.teachcloud.common.enums.MessageEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
@@ -23,10 +25,6 @@ import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncCloudMarkingTaskService;
 import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
 import com.qmth.teachcloud.common.contant.SystemConstant;
-import com.qmth.teachcloud.common.entity.BasicAttachment;
-import com.qmth.teachcloud.common.entity.BasicSchool;
-import com.qmth.teachcloud.common.entity.SysOrg;
-import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ClassifyEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.*;
@@ -131,34 +129,6 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
         return page;
     }
 
-    @Transactional(rollbackFor = Exception.class)
-    @Override
-    public IPage<PrintPlanResult> printPlanSyncPage(Long schoolId, Long semesterId, Long examId, Long printPlanId, Long startTime, Long endTime, int pageNumber, int pageSize) {
-        String[] status = {PrintPlanStatusEnum.PRINT_FINISH.name(), PrintPlanStatusEnum.END.name()};
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission();
-        IPage<PrintPlanResult> page = examPrintPlanMapper.findPrintPlanSyncPage(new Page<>(pageNumber, pageSize), schoolId, semesterId, examId, status, printPlanId, startTime, endTime, dpr);
-        List<PrintPlanResult> list = page.getRecords();
-        for (PrintPlanResult printPlanResult : list) {
-            List<SyncExamStudentDto> examStudentDtos = examStudentService.listStudentByPrintPlanIdAndSyncStatus(printPlanResult.getId());
-            printPlanResult.setCanPush(examStudentDtos != null && examStudentDtos.size() > 0);
-
-            double totalSubjects = examDetailService.calculateTotalSubjects(printPlanResult.getId());
-            double totalPackages = examDetailService.calculateTotalPackages(printPlanResult.getId());
-            printPlanResult.setTotalSubjects((int) totalSubjects);
-            printPlanResult.setTotalPackages((int) totalPackages);
-
-            List<Long> printPlanIds = Arrays.asList(new Long[]{printPlanResult.getId()});
-            List<SyncExamTaskDto> syncExamTaskDtos = examDetailCourseService.listSyncCourseByPrintPlanId(printPlanIds, null, null);
-            long successCount = syncExamTaskDtos.stream().mapToInt(m -> m.getSyncSuccessCount()).sum();
-            printPlanResult.setSyncSuccessCount(Math.toIntExact(successCount));
-            long failCount = syncExamTaskDtos.stream().mapToInt(m -> m.getSyncFailCount()).sum();
-            printPlanResult.setSyncFailCount(Math.toIntExact(failCount));
-            long initCount = syncExamTaskDtos.stream().mapToInt(m -> m.getSyncInitCount()).sum();
-            printPlanResult.setSyncInitCount(Math.toIntExact(initCount));
-        }
-        return page;
-    }
-
     @Transactional(rollbackFor = Exception.class)
     @Override
     public List<PrintPlanBrief> printPlanBriefQuery(String source, String module) {
@@ -464,12 +434,16 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
     @Override
     public void syncDataCloud(SyncDataParam syncDataParam) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        List<JSONObject> examTaskIds = syncDataParam.getList();
-        if (CollectionUtils.isEmpty(examTaskIds)) {
-            throw ExceptionResultEnum.ERROR.exception("请选择需要推送的数据");
-        }
 
+        // 是否开启了同步功能
         if (asyncCloudMarkingTaskService.isSync()) {
+            // 是否设置同步规则 todo
+
+            List<SyncExamTaskDto> params = syncDataParam.getList();
+            if (CollectionUtils.isEmpty(params)) {
+                throw ExceptionResultEnum.ERROR.exception("请选择需要推送的数据");
+            }
+
             if (Objects.isNull(syncDataParam.getThirdRelateId())
                     && StringUtils.isBlank(syncDataParam.getThirdRelateName())) {
                 throw ExceptionResultEnum.ERROR.exception("考试ID、考试名称至少选择一个");
@@ -477,28 +451,17 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
                     && Objects.isNull(syncDataParam.getExamTime())) {
                 throw ExceptionResultEnum.ERROR.exception("考试时间必填");
             }
-            String examTime = null;
-            if (syncDataParam.getThirdRelateId() == null) {
-                String time = String.valueOf(System.currentTimeMillis());
-                examTime = DateUtil.format(new Date(syncDataParam.getExamTime()), CloudMarkingTaskUtils.DATE_FORMAT);
-                syncDataParam.setThirdRelateId(cloudMarkingTaskUtils.syncExam(schoolId, time, syncDataParam.getThirdRelateName(), examTime));
-
-                try {
-                    TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(schoolId, syncDataParam.getThirdRelateId());
-                    if (tSyncStmmsExam == null) {
-                        tSyncStmmsExam = new TSyncStmmsExam();
-                        tSyncStmmsExam.setId(SystemConstant.getDbUuid());
-                        tSyncStmmsExam.setSchoolId(schoolId);
-                        tSyncStmmsExam.setExamId(Math.toIntExact(syncDataParam.getThirdRelateId()));
-                        tSyncStmmsExam.setExamName(syncDataParam.getThirdRelateName());
-                        tSyncStmmsExamService.save(tSyncStmmsExam);
-                    }
-                } catch (Exception e) {
-                    log.error("保存云阅卷考试失败");
-                }
-            }
-            Long printPlanId = SystemConstant.getDbUuid();
-            asyncCloudMarkingTaskService.syncExamAndStudentAndCard(schoolId, printPlanId, syncDataParam.getThirdRelateId(), syncDataParam.getThirdRelateName(), examTime, examTaskIds);
+            // 查询科目所属学院是否一致 todo
+
+            Long objectId = SystemConstant.getDbUuid();
+            String examTime = DateUtil.format(new Date(syncDataParam.getExamTime()), CloudMarkingTaskUtils.DATE_FORMAT);
+            // 新增一个参数对象,加入学校信息(学院代码, 学院名称,云阅卷机构ID),加入参数(任务ID集合),加入同步规则参数
+            JSONObject object = new JSONObject();
+            object.put("sysOrg", null);
+            object.put("syncMode", null);
+            // examTaskIds中包含printPlanIds和examTaskId
+            object.put("param", params);
+            asyncCloudMarkingTaskService.syncExamAndStudentAndCard(schoolId, objectId, syncDataParam.getThirdRelateId(), syncDataParam.getThirdRelateName(), examTime, object);
         }
     }
 
@@ -559,8 +522,8 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
     }
 
     @Override
-    public List<SyncExamTaskDto> listSyncExamTask(List<Long> printPlanIds, SyncCardTypeEnum cardType, String courseName) {
-        return examDetailCourseService.listSyncCourseByPrintPlanId(printPlanIds, cardType, courseName);
+    public List<SyncExamTaskDto> listSyncExamTask(Long semesterId, Long examId, Long orgId, SyncCardTypeEnum cardType, ExamTaskSyncStatusEnum syncStatus, String courseName, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) {
+        return examDetailCourseService.listSyncCourseByPrintPlanId(semesterId, examId, orgId, cardType, syncStatus, courseName, startTime, endTime, pageNumber, pageSize);
     }
 
 

+ 11 - 11
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamStudentServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentPdfInfoDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
@@ -20,10 +21,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -82,11 +80,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
         return examStudentMapper.queryBySchoolIdAndExamDetailCourseIds(schoolId, examDetailCourseIds);
     }
 
-    @Override
-    public List<SyncExamStudentDto> listStudentByPrintPlanIdAndSyncStatus(Long printPlanId) {
-        return this.baseMapper.listStudentByPrintPlanIdAndSyncStatus(printPlanId);
-    }
-
     @Override
     public void insertBatch(List<ExamStudent> examStudents) {
         this.baseMapper.insertBatch(examStudents);
@@ -117,7 +110,14 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
     }
 
     @Override
-    public List<SyncExamStudentDto> listStudentByExamDetailCourseId(Long examDetailCourseId) {
-        return this.baseMapper.listStudentByExamDetailCourseId(examDetailCourseId);
+    public List<SyncExamStudentDto> listStudentByExamDetailCourseId(List<ExamDetailCourseDto> examDetailCourseList) {
+        List<SyncExamStudentDto> syncExamStudentDtoList = new ArrayList<>();
+        for (ExamDetailCourseDto examDetailCourseDto : examDetailCourseList) {
+            List<SyncExamStudentDto> syncExamStudentDtos = this.baseMapper.listStudentByExamDetailCourseId(examDetailCourseDto.getId());
+            if(!syncExamStudentDtos.isEmpty()){
+                syncExamStudentDtoList.addAll(syncExamStudentDtos);
+            }
+        }
+        return syncExamStudentDtoList;
     }
 }

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

@@ -13,7 +13,7 @@ import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamDataSourceEnum;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
-import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.mapper.ExamTaskPrintMapper;
 import com.qmth.distributed.print.business.service.*;
@@ -224,7 +224,7 @@ public class ExamTaskPrintServiceImpl extends ServiceImpl<ExamTaskPrintMapper, E
             examDetailCourse.setPaperNumber(examTaskPrint.getPaperNumber());
             examDetailCourse.setClazzId(examTaskPrint.getClassId());
             examDetailCourse.setTotalSubjects(examTaskPrint.getStudentCount());
-            examDetailCourse.setSyncStatus(ExamPrintPlanSyncStatusEnum.INIT);
+            examDetailCourse.setSyncStatus(ExamTaskSyncStatusEnum.INIT);
             examDetailCourse.setCreateId(examTaskPrint.getCreateId());
             examDetailCourseService.save(examDetailCourse);
 

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

@@ -1727,7 +1727,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                         examDetailCourse.setPaperNumber(paperNumber);
                         examDetailCourse.setClazzId(examDetailList.getClassId());
                         examDetailCourse.setTotalSubjects(examDetailList.getStudentCount());
-                        examDetailCourse.setSyncStatus(ExamPrintPlanSyncStatusEnum.INIT);
+                        examDetailCourse.setSyncStatus(ExamTaskSyncStatusEnum.INIT);
                         examDetailCourse.setCreateId(sysUser.getId());
                         examDetailCourseService.save(examDetailCourse);
 

+ 31 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskSyncServiceImpl.java

@@ -0,0 +1,31 @@
+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.qmth.distributed.print.business.bean.dto.SyncExamTaskDto;
+import com.qmth.distributed.print.business.entity.ExamTaskSync;
+import com.qmth.distributed.print.business.mapper.ExamTaskSyncMapper;
+import com.qmth.distributed.print.business.service.ExamTaskSyncService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 数据同步 服务实现类
+ * </p>
+ */
+@Service
+public class ExamTaskSyncServiceImpl extends ServiceImpl<ExamTaskSyncMapper, ExamTaskSync> implements ExamTaskSyncService {
+
+    @Override
+    public ExamTaskSync getBySchoolIdAndOrgCodeAndPaperNumber(Long schoolId, String orgCode, String paperNumber) {
+
+        QueryWrapper<ExamTaskSync> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(ExamTaskSync::getSchoolId, schoolId)
+                .eq(ExamTaskSync::getPaperNumber, paperNumber);
+        if(StringUtils.isNotBlank(orgCode)){
+            queryWrapper.lambda().eq(ExamTaskSync::getOrgCode, orgCode);
+        }
+        return this.getOne(queryWrapper);
+    }
+}

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

@@ -239,7 +239,7 @@ public class TBSyncTaskServiceImpl extends ServiceImpl<TBSyncTaskMapper, TBSyncT
         }
         switch (tbSyncTask.getType()) {
             case EXAM_PUSH:
-                asyncCloudMarkingTaskService.syncExamAndStudentAndCard(tbSyncTask.getSchoolId(), tbSyncTask.getObjectId(), tbSyncTask.getThirdRelateId(), null, null, JSON.parseArray(tbSyncTask.getRemark(), JSONObject.class));
+                asyncCloudMarkingTaskService.syncExamAndStudentAndCard(tbSyncTask.getSchoolId(), tbSyncTask.getObjectId(), tbSyncTask.getThirdRelateId(), null, null, JSON.parseObject(tbSyncTask.getRemark()));
                 break;
             case STRUCTURE_GROUP_PUSH:
                 asyncCloudMarkingTaskService.syncPaperStructureAndGroup(examPaperStructureService.getById(tbSyncTask.getObjectId()));

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

@@ -51,7 +51,7 @@ public class TSyncExamLogServiceImpl extends ServiceImpl<TSyncExamLogMapper, TSy
         for (TSyncExamLog record : examLogResultIPage.getRecords()) {
             TSyncExamLog tSyncExamLog = this.selectBySchoolIdAndSemesterIdAndExamId(schoolId, semesterId, record.getExamId());
             if (tSyncExamLog == null) {
-                TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(schoolId, examId);
+                TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(schoolId, null, examId);
                 if (tSyncStmmsExam != null) {
                     record.setExamName(tSyncStmmsExam.getExamName());
                 }
@@ -99,7 +99,7 @@ public class TSyncExamLogServiceImpl extends ServiceImpl<TSyncExamLogMapper, TSy
             }
         }
 
-        TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(sysUser.getSchoolId(), examId);
+        TSyncStmmsExam tSyncStmmsExam = tSyncStmmsExamService.getBySchoolIdAndExamId(sysUser.getSchoolId(), null, examId);
         String examName = tSyncStmmsExam == null ? null : tSyncStmmsExam.getExamName();
         TSyncExamLog tSyncExamLog = new TSyncExamLog(SystemConstant.getDbUuid(), sysUser.getSchoolId(), examId, semesterId, examName, TaskStatusEnum.INIT, sysUser.getId(), System.currentTimeMillis());
         boolean isSave = this.save(tSyncExamLog);

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

@@ -11,6 +11,7 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.sync.CloudMarkingTaskUtils;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -60,10 +61,13 @@ public class TSyncStmmsExamServiceImpl extends ServiceImpl<TSyncStmmsExamMapper,
     }
 
     @Override
-    public TSyncStmmsExam getBySchoolIdAndExamId(Long schoolId, Long thirdRelateId) {
+    public TSyncStmmsExam getBySchoolIdAndExamId(Long schoolId, String orgCode, Long thirdRelateId) {
         QueryWrapper<TSyncStmmsExam> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(TSyncStmmsExam::getSchoolId, schoolId)
                 .eq(TSyncStmmsExam::getExamId, thirdRelateId);
+        if(StringUtils.isNotBlank(orgCode)){
+            queryWrapper.lambda().eq(TSyncStmmsExam::getOrgCode, orgCode);
+        }
         return this.getOne(queryWrapper);
     }
 }

+ 2 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncCloudMarkingTaskService.java

@@ -53,9 +53,9 @@ public class AsyncCloudMarkingTaskService {
      * @param objectId      同步对象ID(命题任务Id)
      * @param thirdRelateId 云阅卷考试ID
      */
-    public void syncExamAndStudentAndCard(Long schoolId, Long objectId, Long thirdRelateId, String thirdRelateName, String examTime, List<JSONObject> examTaskIds) {
+    public void syncExamAndStudentAndCard(Long schoolId, Long objectId, Long thirdRelateId, String thirdRelateName, String examTime, JSONObject object) {
         if (isSync()) {
-            TBSyncTask tbSyncTask = tbSyncTaskService.saveTask(schoolId, objectId, PushTypeEnum.EXAM_PUSH, JSONObject.toJSONString(examTaskIds));
+            TBSyncTask tbSyncTask = tbSyncTaskService.saveTask(schoolId, objectId, PushTypeEnum.EXAM_PUSH, JSONObject.toJSONString(object));
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
             dataSyncService.syncExamAndStudentAndCard(thirdRelateId, thirdRelateName, examTime, tbSyncTask, sysUser);
         }

+ 23 - 0
distributed-print-business/src/main/resources/db/3.2.3更新脚本-增量.sql

@@ -2,6 +2,29 @@
 INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES ('828', '生成图片', 'ConvertImage', 'LINK', '624', '7', 'AUTH', '829', '1', '0', '1');
 INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('829', '生成图片', '/api/admin/exam/card/convert_image', 'URL', '624', '6', 'AUTH', '1', '1', '1');
 
+ALTER TABLE `sys_org` ADD COLUMN `third_relate_id` INT NULL COMMENT '云阅卷机构ID' AFTER `historic_name`;
+
+CREATE TABLE `exam_task_sync` (
+    `id` BIGINT(20) NOT NULL,
+    `school_id` BIGINT(20) NOT NULL,
+    `course_code` VARCHAR(50) NOT NULL COMMENT '课程代码',
+    `paper_number` VARCHAR(50) NOT NULL COMMENT '试着编号',
+    `org_code` VARCHAR(45) NULL COMMENT '机构代码',
+    `third_relate_id` INT NULL COMMENT '云阅卷考试ID',
+    `sync_status` VARCHAR(45) NULL COMMENT '同步状态',
+    `error_msg` VARCHAR(500) NULL COMMENT '同步失败原因',
+    `sync_user_id` BIGINT(20) NULL COMMENT '同步用户ID',
+    `sync_start_time` BIGINT(20) NULL COMMENT '同步开始时间 ',
+    `sync_end_time` BIGINT(20) NULL COMMENT '同步结束时间'
+    PRIMARY KEY (`id`));
+
+DELETE FROM `sys_privilege` WHERE (`id` = '791');
+UPDATE `sys_privilege` SET `related` = '435,792,793' WHERE (`id` = '394');
+UPDATE `sys_privilege` SET `related` = '435,792,793' WHERE (`id` = '397');
+ALTER TABLE `t_sync_stmms_exam` ADD COLUMN `org_code` VARCHAR(45) NULL COMMENT '机构代码' AFTER `school_id`;
+
+
+
 /*王亮新增*/
 INSERT INTO sys_role
 (id, school_id, org_id, name, enable, `type`, create_id, create_time, update_id, update_time, default_role, source, interpret)

+ 62 - 27
distributed-print-business/src/main/resources/mapper/ExamDetailCourseMapper.xml

@@ -144,36 +144,71 @@
     </select>
     <select id="listSyncCourseByPrintPlanId"
             resultType="com.qmth.distributed.print.business.bean.dto.SyncExamTaskDto">
-        SELECT et.id,
-               b.course_code   courseCode,
-               b.course_name   courseName,
-               b.paper_number  paperNumber,
-               b.paper_type    paperType,
-               et.sequence,
-               sum(b.total_subjects) totalSubjects,
-               sum(case b.sync_status when 'FINISH' then 1 else 0 end) syncSuccessCount,
-               sum(case b.sync_status when 'PART_FINISH' then 1 else 0 end) syncFailCount,
-               sum(case b.sync_status when 'INIT' then 1 else 0 end) syncInitCount,
-               group_concat(distinct c.print_plan_id) printPlanIds,
-               group_concat(distinct b.third_relate_id) thirdRelateId,
-               group_concat(distinct b.sync_status) syncStatus,
-               group_concat(distinct su.real_name) syncUserName
-        FROM exam_detail_course b
-                 LEFT JOIN
-             exam_detail c ON b.exam_detail_id = c.id
-                 LEFT JOIN
-             exam_task et ON b.school_id = et.school_id
-                 and b.paper_number = et.paper_number
-                LEFT JOIN
-            sys_user su ON b.sync_user_id = su.id
-        WHERE c.print_plan_id in
-                <foreach collection="printPlanIds" open="(" close=")" item="printPlanId" separator=",">
-                    #{printPlanId}
-                </foreach>
+        SELECT
+            et.id examTaskId,
+            et.course_code courseCode,
+            et.course_name courseName,
+            et.paper_number paperNumber,
+            t.paper_type paperType,
+            et.sequence,
+            et.start_time startTime,
+            et.end_time endTime,
+            t.total_subjects totalSubjects,
+            t.print_plan_ids printPlanIds,
+            ets.third_relate_id thirdRelateId,
+            ets.sync_status syncStatus,
+            ets.sync_status_detail syncStatusDetail,
+            su.real_name syncUserName
+        FROM
+            (SELECT
+                 b.school_id,
+                 b.paper_number,
+                 b.paper_type,
+                 SUM(b.total_subjects) total_subjects,
+                 group_concat(c.print_plan_id) print_plan_ids
+             FROM
+                 exam_detail_course b
+                     LEFT JOIN exam_detail c ON b.exam_detail_id = c.id
+                     LEFT JOIN exam_print_plan epp ON c.print_plan_id = epp.id
+                     LEFT JOIN basic_exam be ON epp.exam_id = be.id
+            <where>
+                <if test="semesterId != null">
+                    and be.semester_id = #{semesterId}
+                </if>
+                <if test="examId != null">
+                    and be.id = #{examId}
+                </if>
                 <if test="courseName != null and courseName != ''">
                     and b.course_name like concat(#{courseName}, '%')
                 </if>
-                GROUP BY et.id, b.course_code, b.course_name , b.paper_number, b.paper_type, et.sequence
+            </where>
+             GROUP BY b.school_id , b.paper_number , b.paper_type) t
+                LEFT JOIN
+            exam_task et ON t.school_id = et.school_id
+                AND t.paper_number = et.paper_number
+                LEFT JOIN
+            exam_task_sync ets ON et.school_id = ets.school_id
+                AND et.paper_number = ets.paper_number
+                LEFT JOIN
+            sys_user su ON ets.sync_user_id = su.id
+            <where>
+                <if test="orgIds != null">
+                    and et.org_id in
+                    <foreach collection="orgIds" separator="," open="(" close=")" item="orgId">
+                        #{orgId}
+                    </foreach>
+                </if>
+                <if test="syncStatus != null">
+                    and ets.sync_status = #{syncStatus}
+                </if>
+                <if test="startTime != null">
+                    and et.start_time &gt;= #{startTime}
+                </if>
+                <if test="endTime != null">
+                    and et.end_time &lt;= #{endTime}
+                </if>
+            </where>
+        ORDER BY et.course_code , et.sequence
     </select>
     <select id="listByPrintPlanIdAndExamTaskId"
             resultType="com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto">

+ 1 - 73
distributed-print-business/src/main/resources/mapper/ExamPrintPlanMapper.xml

@@ -107,79 +107,7 @@
         </where>
         ORDER BY a.id DESC
     </select>
-    <select id="findPrintPlanSyncPage"
-            resultType="com.qmth.distributed.print.business.bean.result.PrintPlanResult">
-        SELECT
-        a.id,
-        be.semester_id semesterId,
-        be.id examId,
-        a.name,
-        a.exam_start_time AS examStartTime,
-        a.exam_end_time AS examEndTime,
-        a.status,
-        (
-        SELECT
-        COUNT(
-        DISTINCT ( course_code ))
-        FROM
-        exam_detail_course
-        WHERE
-        exam_detail_id IN ( SELECT id FROM exam_detail WHERE print_plan_id = a.id )) AS totalGates,
-        a.print_content AS printContent,
-        a.backup_method AS backupMethod,
-        a.backup_count AS backupCount,
-        a.draw_rule AS drawRule,
-        a.variable_content AS variableContentTemp,
-        a.ordinary_content AS ordinaryContentTemp,
-        a.create_id AS createId,
-        a.create_time AS createTime,
-        b.real_name AS createName,
-        a.third_relate_id thirdRelateId,
-        a.third_relate_name thirdRelateName,
-        a.sync_status syncStatus
-        FROM
-        exam_print_plan a
-        LEFT JOIN
-            basic_exam be on a.exam_id = be.id
-        LEFT JOIN
-        sys_user b on a.create_id = b.id
-        <where>
-            AND a.status IN
-            <foreach collection="status" item="item" index="index" open="(" separator="," close=")">
-                #{item}
-            </foreach>
-            <if test="schoolId != null and schoolId != ''">
-                and a.school_id = #{schoolId}
-            </if>
-            <if test="semesterId!= null and semesterId != ''">
-                and be.semester_id = #{semesterId}
-            </if>
-            <if test="examId!= null and examId != ''">
-                and be.id = #{examId}
-            </if>
-            <if test="printPlanId!= null and printPlanId != ''">
-                and a.id = #{printPlanId}
-            </if>
-            <if test="startTime != null and startTime != ''">
-                and a.create_time >= #{startTime}
-            </if>
-            <if test="endTime != null and endTime != ''">
-                and #{endTime} >= a.create_time
-            </if>
-            <if test="dpr != null">
-                <if test="dpr.requestUserId != null">
-                    AND b.id = #{dpr.requestUserId}
-                </if>
-                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
-                    AND b.org_id IN
-                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-                </if>
-            </if>
-        </where>
-        ORDER BY a.update_time DESC
-    </select>
+
     <select id="list" resultType="com.qmth.distributed.print.business.bean.result.PrintPlanBrief">
         select a.id, a.name, a.status from exam_print_plan a left join sys_user b on a.create_id = b.id
         <where>

+ 0 - 25
distributed-print-business/src/main/resources/mapper/ExamStudentMapper.xml

@@ -110,31 +110,6 @@
         </where>
         order by edc.course_code, 0+ cast(es.site_number as char), es.ticket_number
     </select>
-    <select id="listStudentByPrintPlanIdAndSyncStatus"
-            resultType="com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto">
-        SELECT a.id,
-               b.course_code   courseCode,
-               b.course_name   courseName,
-               b.paper_number  paperNumber,
-               a.student_name  studentName,
-               a.student_code  studentCode,
-               a.ticket_number ticketNumber,
-               a.clazz_name    clazzName,
-               a.extend_fields extendFields,
-               a.paper_type    paperType,
-               c.package_code pachageCode,
-               et.sequence
-        FROM exam_student a
-                 LEFT JOIN
-             exam_detail_course b ON a.exam_detail_course_id = b.id
-                 LEFT JOIN
-             exam_detail c ON b.exam_detail_id = c.id
-                 LEFT JOIN
-             exam_task et ON b.school_id = et.school_id
-                 and b.course_code = et.course_code
-                 and b.paper_number = et.paper_number
-        WHERE c.print_plan_id = #{printPlanId}
-    </select>
     <select id="listStudentByExamDetailCourseId"
             resultType="com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto">
         SELECT a.id,

+ 13 - 33
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamPrintPlanSyncController.java

@@ -3,6 +3,7 @@ package com.qmth.distributed.print.api;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.bean.result.EditResult;
+import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
 import com.qmth.distributed.print.business.service.ExamPrintPlanService;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
@@ -10,7 +11,6 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
-import com.qmth.teachcloud.common.util.ServletUtil;
 import io.swagger.annotations.*;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
-import java.util.List;
 
 /**
  * <p>
@@ -37,43 +36,24 @@ public class ExamPrintPlanSyncController {
     private ExamPrintPlanService examPrintPlanService;
 
     /**
-     * 需要合并的计划查询
+     * 查询需要同步的命题任务
      *
-     * @param printPlanId
-     * @param startTime
-     * @param endTime
-     * @param pageNumber
-     * @param pageSize
-     * @return
-     */
-    @ApiOperation(value = "印刷计划推送管理-查询")
-    @RequestMapping(value = "/list_sync", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
-    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
-    public Result findPrintPlanPage(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
-                                    @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
-                                    @ApiParam(value = "印刷计划ID") @RequestParam(required = false) Long printPlanId,
-                                    @ApiParam(value = "计划创建时间段开始时间") @RequestParam(required = false) Long startTime,
-                                    @ApiParam(value = "计划创建时间段结束时间") @RequestParam(required = false) Long endTime,
-                                    @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
-                                    @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
-        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        return ResultUtil.ok(examPrintPlanService.printPlanSyncPage(schoolId, semesterId, examId, printPlanId, startTime, endTime, pageNumber, pageSize));
-    }
-
-    /**
-     * 查询计划下需要同步的命题任务
-     *
-     * @param printPlanIds 印刷计划ID
      */
     @ApiOperation(value = "印刷计划推送管理-推送数据查询")
-    @RequestMapping(value = "/list_sync_exam_task", method = RequestMethod.POST)
+    @RequestMapping(value = "/list_sync", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
-    public Result listSyncExamTask(@ApiParam(value = "印刷计划ID集合") @RequestParam List<Long> printPlanIds,
+    public Result listSyncExamTask(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
+                                   @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
+                                   @ApiParam(value = "学院ID") @RequestParam(required = false) Long orgId,
                                    @ApiParam(value = "题卡类型") @RequestParam(required = false) SyncCardTypeEnum cardType,
-                                   @ApiParam(value = "课程名称") @RequestParam(required = false) String courseName) {
-        return ResultUtil.ok(examPrintPlanService.listSyncExamTask(printPlanIds, cardType, courseName));
+                                   @ApiParam(value = "推送状态") @RequestParam(required = false) ExamTaskSyncStatusEnum syncStatus,
+                                   @ApiParam(value = "课程名称") @RequestParam(required = false) String courseName,
+                                   @ApiParam(value = "计划创建时间段开始时间") @RequestParam(required = false) Long startTime,
+                                   @ApiParam(value = "计划创建时间段结束时间") @RequestParam(required = false) Long endTime,
+                                   @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                   @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        return ResultUtil.ok(examPrintPlanService.listSyncExamTask(semesterId, examId, orgId, cardType,syncStatus, courseName, startTime, endTime, pageNumber, pageSize));
     }
 
 

+ 9 - 3
distributed-print/src/main/java/com/qmth/distributed/print/api/SysAdminSetController.java

@@ -86,27 +86,33 @@ public class SysAdminSetController {
     @RequestMapping(value = "/sync/select", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
     public Result sysadminSyncSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
+        SysConfig sysConfigCloudMarkSyncMode = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_SYNC_MODE);
         SysConfig sysConfigQuestionHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.QUESTION_HOST_URL);
         SysConfig sysConfigCloudmarkHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_HOST_URL);
         SysConfig sysConfigTeachcloudReportHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.TEACHCLOUD_REPORT_HOST_URL);
 
         List<SysConfigResult> sysConfigResultList = new ArrayList<>();
+        if (Objects.nonNull(sysConfigCloudMarkSyncMode)) {
+            sysConfigResultList.add(new SysConfigResult(sysConfigCloudMarkSyncMode));
+        } else {
+            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.CLOUDMARK_SYNC_MODE, "同步规则", "", 1));
+        }
         if (Objects.nonNull(sysConfigQuestionHostUrl)) {
             sysConfigResultList.add(new SysConfigResult(sysConfigQuestionHostUrl));
         } else {
-            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.QUESTION_HOST_URL, "题库地址", "", 1));
+            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.QUESTION_HOST_URL, "题库地址", "", 2));
         }
 
         if (Objects.nonNull(sysConfigCloudmarkHostUrl)) {
             sysConfigResultList.add(new SysConfigResult(sysConfigCloudmarkHostUrl));
         } else {
-            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.CLOUDMARK_HOST_URL, "云阅卷地址", "", 2));
+            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.CLOUDMARK_HOST_URL, "云阅卷地址", "", 3));
         }
 
         if (Objects.nonNull(sysConfigTeachcloudReportHostUrl)) {
             sysConfigResultList.add(new SysConfigResult(sysConfigTeachcloudReportHostUrl));
         } else {
-            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.TEACHCLOUD_REPORT_HOST_URL, "教研分析地址", "", 3));
+            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.TEACHCLOUD_REPORT_HOST_URL, "教研分析地址", "", 4));
         }
         return ResultUtil.ok(new SysAdminSetResult(schoolId, sysConfigResultList));
     }

+ 3 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -146,6 +146,7 @@ public class SystemConstant {
     public static final String THREAD_POOL_CORE_SIZE = "thread.pool.core.size";
     public static final String CUSTOM_THREAD_POOL_CORE_SIZE = "custom.thread.pool.core.size";
     public static final String SESSION_ACTIVE = "session.active";
+    public static final String CLOUDMARK_SYNC_MODE = "cloudmark.sync.mode";
     public static final String CLOUDMARK_HOST_URL = "cloudmark.host.url";
     public static final String SMS_NORMAL_CODE = "sms.normal.code";
     public static final String CODE_EXPIRED_TIME = "code.expired.time";
@@ -199,6 +200,7 @@ public class SystemConstant {
     public static final String TEMP = "temp";
     public static final String SESSION = "session:";
     public static final String TASK = "task";
+    public static final String ORG_PREFIX = "code";
     public static final String TB_TASK_ID = "tbTaskId";
     public static final String TB_SYNC_TASK = "tbSyncTask";
     public static final String TB_SYNC_TASK_ID = "tbSyncTaskId";
@@ -319,6 +321,7 @@ public class SystemConstant {
     public static final String CUSTOM_ROLE_CACHE = "custom:role:cache";
     public static final String NUMBER_CACHE = "school:number:cache:";
     public static final String ORG_COLLEGE_LEVEL_CACHE = "org:college:level:cache";
+    public static final String ORG_CODE_CACHE = "org:code:cache";
 
     public static final String EXAM_TASK_SEQUENCE_CACHE = "exam:task:sequence:cache";
 

+ 11 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/SysOrg.java

@@ -59,6 +59,9 @@ public class SysOrg extends BaseEntity implements Serializable {
     @ApiModelProperty("历史机构名")
     private String historicName;
 
+    @ApiModelProperty("云阅卷机构ID")
+    private Integer thirdRelateId;
+
     public SysOrg() {
 
     }
@@ -147,4 +150,12 @@ public class SysOrg extends BaseEntity implements Serializable {
     public void setEnable(Boolean enable) {
         this.enable = enable;
     }
+
+    public Integer getThirdRelateId() {
+        return thirdRelateId;
+    }
+
+    public void setThirdRelateId(Integer thirdRelateId) {
+        this.thirdRelateId = thirdRelateId;
+    }
 }

+ 9 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CommonCacheService.java

@@ -523,4 +523,13 @@ public interface CommonCacheService {
      * @return int
      */
     public String updateExamTaskSequence(Long schoolId, String courseCode, String value);
+
+    /**
+     * 查询机构Code
+     *
+     * @param schoolId
+     */
+    public Integer getMaxOrgCode(Long schoolId);
+
+    public Integer setMaxOrgCode(Long schoolId, Integer maxCode);
 }

+ 34 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CommonCacheServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
 
@@ -788,4 +789,37 @@ public class CommonCacheServiceImpl implements CommonCacheService {
     public String updateExamTaskSequence(Long schoolId, String courseCode, String value) {
         return String.valueOf(Integer.valueOf(value) + 1);
     }
+
+    /**
+     * 添加机构code
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.ORG_CODE_CACHE, key = "#p0", unless = "#result == null")
+    public Integer getMaxOrgCode(Long schoolId) {
+        QueryWrapper<SysOrg> orgQueryWrapper = new QueryWrapper<>();
+        orgQueryWrapper.lambda().eq(SysOrg::getSchoolId, schoolId)
+                .eq(SysOrg::getParentId, schoolId)
+                .like(SysOrg::getCode, SystemConstant.ORG_PREFIX);
+        List<SysOrg> sysOrgList = sysOrgService.list(orgQueryWrapper);
+        if (sysOrgList.isEmpty()) {
+            return 0;
+        }
+        Integer maxCode = sysOrgList.stream().map(m -> Integer.parseInt(m.getCode().replace(SystemConstant.ORG_PREFIX, "").trim())).max(Comparator.comparingInt(x -> x)).get();
+        return maxCode;
+    }
+
+    /**
+     * 修改机构code
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.ORG_CODE_CACHE, key = "#p0", condition = "#result != null")
+    public Integer setMaxOrgCode(Long schoolId, Integer maxCode) {
+        return maxCode;
+    }
 }

+ 27 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java

@@ -146,6 +146,24 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
             Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
             org.setSchoolId(schoolId);
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+
+            // 已经推送到云阅卷,不允许修改机构代码
+            if(org.getThirdRelateId() != null && org.getThirdRelateId() > 0){
+                throw ExceptionResultEnum.ERROR.exception("机构已经同步到云阅卷,不支持修改机构代码");
+            }
+
+            // 机构代码不为空,校验唯一性
+            if (StringUtils.isNotBlank(org.getCode())) {
+                QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
+                queryWrapper.lambda().eq(SysOrg::getSchoolId, schoolId)
+                        .eq(SysOrg::getCode, org.getCode());
+                SysOrg codeSysOrg = this.getOne(queryWrapper);
+
+                if(codeSysOrg != null && (org.getId() == null || !org.getId().equals(codeSysOrg.getId()))){
+                    throw ExceptionResultEnum.ERROR.exception("机构代码已存在");
+                }
+            }
+
             if (org.getId() == null) {// 新增
                 org.insertInfo(sysUser.getId());
                 success = this.save(org);
@@ -604,6 +622,15 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         sysOrg.setParentId(parentId);
         sysOrg.setName(orgName);
         sysOrg.setEnable(true);
+
+        SysOrg sysOrgRoot = this.getOne(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId, requestUser.getSchoolId()).eq(SysOrg::getType, OrgTypeEnum.SCHOOL));
+        // 学校下第一级机构,自动生成code
+        if (sysOrgRoot != null && parentId.equals(sysOrgRoot.getId())) {
+            Integer maxOrgCode = commonCacheService.getMaxOrgCode(sysOrg.getSchoolId());
+            Integer currentCode = maxOrgCode + 1;
+            commonCacheService.setMaxOrgCode(sysOrg.getSchoolId(), currentCode);
+            sysOrg.setCode(SystemConstant.ORG_PREFIX + currentCode);
+        }
         this.save(sysOrg);
 
         return sysOrg;

+ 10 - 11
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/CloudMarkingTaskUtils.java

@@ -63,29 +63,28 @@ public class CloudMarkingTaskUtils {
     /**
      * 考试创建/更新接口
      *
-     * @param code     唯一标识
-     * @param name     考试名称
-     * @param examTime 考试时间
-     * @return 考试ID
+     * @param code 学院代码
+     * @param name 学院名称
+     * @return 机构ID
      */
-    public Long syncSchool(Long schoolId, String code, String name, String examTime) {
+    public Integer syncSchool(Long schoolId, String code, String name) {
         SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_HOST_URL);
         Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置云阅卷地址"));
         String hostUrl = sysConfig.getConfigValue();
-        String examSaveUrl = SystemConstant.CLOUD_MARK_SCHOOL_SAVE_API;
-        validUrl(hostUrl, examSaveUrl);
-        String postUrl = hostUrl.concat(examSaveUrl);
+        String schoolSaveUrl = SystemConstant.CLOUD_MARK_SCHOOL_SAVE_API;
+        validUrl(hostUrl, schoolSaveUrl);
+        String postUrl = hostUrl.concat(schoolSaveUrl);
         //参数
         Map<String, Object> map = new HashMap<>();
         map.put("code", validParam(code, null, true, "唯一标识"));
         map.put("name", validParam(name, null, true, "显示名称"));
 
-        String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, examSaveUrl), map, null, null, null);
+        String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, schoolSaveUrl), map, null, null, null);
         JSONObject jsonObject = JSONObject.parseObject(result);
         if (jsonObject.containsKey("id")) {
-            return Long.valueOf(jsonObject.get("id").toString());
+            return Integer.valueOf(jsonObject.get("id").toString());
         } else {
-            throw ExceptionResultEnum.ERROR.exception("学(机构)同步失败");
+            throw ExceptionResultEnum.ERROR.exception("学(机构)同步失败");
         }
     }