Kaynağa Gözat

Merge branch 'dev_v2.2.0' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev_v2.2.0

xiaof 3 yıl önce
ebeveyn
işleme
d21b66b347
15 değiştirilmiş dosya ile 322 ekleme ve 150 silme
  1. 33 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ApprovalForm/BasicInfo.java
  2. 21 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ApprovalForm/ExamRoomInfo.java
  3. 12 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCStatistics.java
  4. 12 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCStatisticsTemp.java
  5. 2 29
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCStatisticsService.java
  6. 4 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ActivitiServiceImpl.java
  7. 26 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java
  8. 126 104
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCStatisticsServiceImpl.java
  9. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  10. 17 12
      distributed-print-business/src/main/resources/mapper/TCStatisticsMapper.xml
  11. 2 0
      distributed-print-business/src/main/resources/mapper/TCStatisticsTempMapper.xml
  12. 8 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicCampusService.java
  13. 7 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysOrgService.java
  14. 21 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicCampusServiceImpl.java
  15. 30 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java

+ 33 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ApprovalForm/BasicInfo.java

@@ -10,6 +10,12 @@ import io.swagger.annotations.ApiModelProperty;
  * @Date: 2021-09-06
  */
 public class BasicInfo {
+    @ApiModelProperty(value = "学院id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long collegeId;
+
+    @ApiModelProperty(value = "学院名称")
+    private String collegeName;
 
     @ApiModelProperty(value = "教研室id")
     @JsonSerialize(using = ToStringSerializer.class)
@@ -33,6 +39,25 @@ public class BasicInfo {
     @ApiModelProperty(value = "拟卷老师")
     private String teacherName;
 
+    @ApiModelProperty(value = "课程名称")
+    private String courseName;
+
+    public Long getCollegeId() {
+        return collegeId;
+    }
+
+    public void setCollegeId(Long collegeId) {
+        this.collegeId = collegeId;
+    }
+
+    public String getCollegeName() {
+        return collegeName;
+    }
+
+    public void setCollegeName(String collegeName) {
+        this.collegeName = collegeName;
+    }
+
     public Long getTeachingRoomId() {
         return teachingRoomId;
     }
@@ -88,4 +113,12 @@ public class BasicInfo {
     public void setTeacherName(String teacherName) {
         this.teacherName = teacherName;
     }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
 }

+ 21 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ApprovalForm/ExamRoomInfo.java

@@ -8,6 +8,11 @@ import io.swagger.annotations.ApiModelProperty;
  * @Date: 2021-09-06
  */
 public class ExamRoomInfo {
+    @ApiModelProperty(value = "卷袋编号")
+    private String packageCode;
+
+    @ApiModelProperty(value = "校区名称")
+    private String campusNames;
 
     @ApiModelProperty(value = "使用班级(考场)")
     private String clazzNames;
@@ -18,6 +23,22 @@ public class ExamRoomInfo {
     @ApiModelProperty(value = "总印份数(人数 + 备用)")
     private String printCount;
 
+    public String getPackageCode() {
+        return packageCode;
+    }
+
+    public void setPackageCode(String packageCode) {
+        this.packageCode = packageCode;
+    }
+
+    public String getCampusNames() {
+        return campusNames;
+    }
+
+    public void setCampusNames(String campusNames) {
+        this.campusNames = campusNames;
+    }
+
     public String getClazzNames() {
         return clazzNames;
     }

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCStatistics.java

@@ -76,6 +76,10 @@ public class TCStatistics extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "完成状态,FINISH:已完成,UN_FINISH:未完成")
     private StatisticsStatusEnum status;
 
+    @ApiModelProperty(name = "命题明细id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    Long examDetailId;
+
     public TCStatistics() {
 
     }
@@ -144,6 +148,14 @@ public class TCStatistics extends BaseEntity implements Serializable {
         updateInfo(userId);
     }
 
+    public Long getExamDetailId() {
+        return examDetailId;
+    }
+
+    public void setExamDetailId(Long examDetailId) {
+        this.examDetailId = examDetailId;
+    }
+
     public Integer getPrintSum() {
         return printSum;
     }

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCStatisticsTemp.java

@@ -73,6 +73,10 @@ public class TCStatisticsTemp extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "数据来源")
     DataSourceEnum dataSource;
 
+    @ApiModelProperty(name = "命题明细id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    Long examDetailId;
+
     public TCStatisticsTemp() {
 
     }
@@ -142,6 +146,14 @@ public class TCStatisticsTemp extends BaseEntity implements Serializable {
         updateInfo(userId);
     }
 
+    public Long getExamDetailId() {
+        return examDetailId;
+    }
+
+    public void setExamDetailId(Long examDetailId) {
+        this.examDetailId = examDetailId;
+    }
+
     public DataSourceEnum getDataSource() {
         return dataSource;
     }

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

@@ -45,26 +45,6 @@ public interface TCStatisticsService extends IService<TCStatistics> {
                                        Long schoolId,
                                        Long userId);
 
-    /**
-     * 根据batchNo统计信息
-     *
-     * @param schoolId
-     * @param batchNo
-     * @param orgIds
-     * @return
-     */
-    public List<TCStatisticsDto> findByBatchNoCount(Long schoolId, String batchNo, Set<Long> orgIds);
-
-    /**
-     * 根据batchNo统计信息
-     *
-     * @param schoolId
-     * @param batchNo
-     * @param orgIds
-     * @return
-     */
-    public List<TCStatisticsDto> findByBatchNoCountJoin(Long schoolId, String batchNo, Set<Long> orgIds);
-
     /**
      * 导入关联数据
      *
@@ -76,18 +56,11 @@ public interface TCStatisticsService extends IService<TCStatistics> {
     /**
      * 删除导入数据
      *
+     * @param userId
      * @param courseSet
      * @param setCollections
      */
-    public void removeImportData(Set<String> courseSet, Set<Long>... setCollections);
-
-    /**
-     * 刷新关联数据
-     *
-     * @param sysUser
-     * @param batchNoSet
-     */
-    public void freshenJoinData(SysUser sysUser, Set<String> batchNoSet);
+    public void removeImportData(Long userId, Set<String> courseSet, Set<Long>... setCollections);
 
     /**
      * 刷新数据

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

@@ -708,11 +708,11 @@ public class ActivitiServiceImpl implements ActivitiService {
         if (Objects.isNull(task.getAssignee())) {
             Task taskUser = taskService.createTaskQuery().taskId(task.getId()).taskAssignee(String.valueOf(userId)).singleResult();
             if (Objects.isNull(taskUser)) {
-                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
+                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
             }
         } else {
             if (!Objects.equals(task.getAssignee(), String.valueOf(userId))) {
-                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
+                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
             }
         }
     }
@@ -728,11 +728,11 @@ public class ActivitiServiceImpl implements ActivitiService {
         if (Objects.isNull(task.getAssignee())) {
             Task taskUser = taskService.createTaskQuery().taskId(task.getId()).taskCandidateUser(String.valueOf(userId)).singleResult();
             if (Objects.isNull(taskUser)) {
-                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
+                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
             }
         } else {
             if (!Objects.equals(task.getAssignee(), String.valueOf(userId))) {
-                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
+                throw ExceptionResultEnum.ERROR.exception("不能提交他人的任务或者该任务已被审核,请刷新再试");
             }
         }
         if (Objects.isNull(map.get(SystemConstant.APPROVE_OPERATION))) {

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

@@ -160,6 +160,9 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Resource
     ExamTaskService examTaskService;
 
+    @Resource
+    BasicCampusService basicCampusService;
+
     @Override
     public List<ExamTask> listByCourseCode(Long schoolId, String code) {
         QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
@@ -1722,6 +1725,18 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             throw ExceptionResultEnum.ERROR.exception("找不到教研室");
         }
         String teachingRoomName = teachingRoom.getName();
+
+        // 查询教研室所在学院
+        List<SysOrg> collegeList = sysOrgService.findParentsByOrgId(teachingRoom.getId())
+                .stream()
+                .filter(e -> OrgTypeEnum.COLLEGE.equals(e.getType()))
+                .collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(collegeList)){
+            throw ExceptionResultEnum.ERROR.exception("找不到学院");
+        }
+        SysOrg college = collegeList.get(0);
+
+
         // 流程id
         Long flowId = examTask.getFlowId();
 
@@ -1778,6 +1793,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         // ---- 组装Dto
         ExamTaskApprovalFormDto examTaskApprovalFormDto = new ExamTaskApprovalFormDto();
         BasicInfo basicInfo = new BasicInfo();
+        basicInfo.setCollegeId(college.getId());
+        basicInfo.setCollegeName(college.getName());
         basicInfo.setTeachingRoomId(teachingRoomId);
         basicInfo.setTeachingRoomName(teachingRoomName);
         basicInfo.setPaperName(paperName);
@@ -1785,6 +1802,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         basicInfo.setTeacherName(examTask.getTeacherName());
         basicInfo.setExamStartTime(examObjectDto.getExamStartTime());
         basicInfo.setExamEndTime(examObjectDto.getExamEndTime());
+        basicInfo.setCourseName(examTask.getCourseName());
 
 
         examTaskApprovalFormDto.setBasicInfo(basicInfo);
@@ -1909,6 +1927,12 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 List<ExamPackageDetail> examPackageDetailCell = examPackageDetailDatasource.stream()
                         .filter(e -> examDetailId.equals(e.getExamDetailId()))
                         .collect(Collectors.toList());
+                List<String> packageCodeList = examPackageDetailCell.stream().map(ExamPackageDetail::getPackageCode).distinct().collect(Collectors.toList());
+                String packageCode = "";
+                if (packageCodeList.size() > 0){
+                    packageCode = packageCodeList.get(0);
+                }
+
 
                 List<BackupMethodEnum> backupMethodEnums = examPackageDetailCell.stream().map(ExamPackageDetail::getBackupMethod).distinct().collect(Collectors.toList());
                 if (backupMethodEnums.size() != 1 && backupMethodEnums.get(0) != BackupMethodEnum.ROOM) {
@@ -1951,7 +1975,9 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
 
                     // 组装examRoom
                     ExamRoomInfo examRoomInfo = new ExamRoomInfo();
+                    examRoomInfo.setPackageCode(packageCode);
                     examRoomInfo.setClazzNames(classNames);
+                    examRoomInfo.setCampusNames(basicCampusService.findCampusNamesByClazzIdList(clazzIds,","));
                     examRoomInfo.setStudentCount(studentCount);
                     examRoomInfo.setPrintCount(printCount);
                     examRoomInfoList.add(examRoomInfo);

+ 126 - 104
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCStatisticsServiceImpl.java

@@ -68,32 +68,6 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
         return tcStatisticsMapper.list(iPage, collegeId, teachingRoomId, Objects.nonNull(status) ? status.name() : null, courseName, teacherName, schoolId, userId);
     }
 
-    /**
-     * 根据batchNo统计信息
-     *
-     * @param schoolId
-     * @param batchNo
-     * @param orgIds
-     * @return
-     */
-    @Override
-    public List<TCStatisticsDto> findByBatchNoCount(Long schoolId, String batchNo, Set<Long> orgIds) {
-        return tcStatisticsMapper.findByBatchNoCount(schoolId, batchNo, orgIds);
-    }
-
-    /**
-     * 根据batchNo统计信息
-     *
-     * @param schoolId
-     * @param batchNo
-     * @param orgIds
-     * @return
-     */
-    @Override
-    public List<TCStatisticsDto> findByBatchNoCountJoin(Long schoolId, String batchNo, Set<Long> orgIds) {
-        return tcStatisticsMapper.findByBatchNoCountJoin(schoolId, batchNo, orgIds);
-    }
-
     /**
      * 导入关联数据
      *
@@ -106,30 +80,10 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
         List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNo(sysUser.getSchoolId(), batchNo);
         if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
             batchNo = SystemConstant.getUuid();
-            Set<Long> collegeIdSet = new HashSet<>();
-            for (TCStatisticsTemp t : tcStatisticsTempList) {
-                collegeIdSet.add(t.getCollegeId());
-                t.insertInfo(sysUser.getId());
-                t.setBatchNo(batchNo);
-            }
-            tcStatisticsTempService.saveBatch(tcStatisticsTempList);
-
-            Set<Long> orgIds = new HashSet<>();
-            for (Long l : collegeIdSet) {
-                List<SysOrg> sysOrgList = sysOrgService.findByConnectByRootOrgId(l);
-                Set<Long> orgTempIds = sysOrgList.stream().map(s -> s.getId()).collect(Collectors.toSet());
-                orgIds.addAll(orgTempIds);
-            }
+            Set<Long> orgIds = this.joinDataGetOrgIds(sysUser, batchNo, tcStatisticsTempList);
             List<TCStatisticsDto> tcStatisticsDtoList = this.findByBatchNoCount(sysUser.getSchoolId(), batchNo, orgIds);
             if (Objects.nonNull(tcStatisticsDtoList) && tcStatisticsDtoList.size() > 0) {
-                Gson gson = new Gson();
-                List<TCStatistics> tcStatisticsList = gson.fromJson(JacksonUtil.parseJson(tcStatisticsDtoList), new TypeToken<List<TCStatistics>>() {
-                }.getType());
-                for (TCStatistics t : tcStatisticsList) {
-                    t.insertInfo(sysUser.getId());
-                }
-                TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
-                tcStatisticsService.saveBatch(tcStatisticsList);
+                this.saveJoinData(sysUser, tcStatisticsDtoList);
             }
         }
     }
@@ -137,78 +91,31 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
     /**
      * 删除导入数据
      *
+     * @param userId
      * @param courseSet
      * @param setCollections
      */
     @Override
     @Transactional
-    public void removeImportData(Set<String> courseSet, Set<Long>... setCollections) {
+    public void removeImportData(Long userId, Set<String> courseSet, Set<Long>... setCollections) {
         TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
         QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
         tcStatisticsQueryWrapper.lambda().in(TCStatistics::getCollegeId, setCollections[0])
                 .in(TCStatistics::getTeachingRoomId, setCollections[1])
                 .in(TCStatistics::getCourseCode, courseSet)
-                .in(TCStatistics::getClazzId, setCollections[2]);
+                .in(TCStatistics::getClazzId, setCollections[2])
+                .eq(TCStatistics::getCreateId, userId);
         tcStatisticsService.remove(tcStatisticsQueryWrapper);
 
         QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
         tcStatisticsTempQueryWrapper.lambda().in(TCStatisticsTemp::getCollegeId, setCollections[0])
                 .in(TCStatisticsTemp::getTeachingRoomId, setCollections[1])
                 .in(TCStatisticsTemp::getCourseCode, courseSet)
-                .in(TCStatisticsTemp::getClazzId, setCollections[2]);
+                .in(TCStatisticsTemp::getClazzId, setCollections[2])
+                .eq(TCStatisticsTemp::getCreateId, userId);
         tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
     }
 
-    /**
-     * 刷新关联数据
-     *
-     * @param sysUser
-     * @param batchNoSet
-     */
-    @Override
-    @Transactional
-    public void freshenJoinData(SysUser sysUser, Set<String> batchNoSet) {
-        TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
-        for (String batchNo : batchNoSet) {
-            List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNoJoin(sysUser.getSchoolId(), batchNo);
-            if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
-                QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
-                tcStatisticsTempQueryWrapper.lambda().eq(TCStatisticsTemp::getBatchNo, batchNo);
-                tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
-
-                String batchNoNew = SystemConstant.getUuid();
-                Set<Long> collegeIdSet = new HashSet<>();
-                for (TCStatisticsTemp t : tcStatisticsTempList) {
-                    collegeIdSet.add(t.getCollegeId());
-                    t.insertInfo(sysUser.getId());
-                    t.setBatchNo(batchNoNew);
-                }
-                tcStatisticsTempService.saveBatch(tcStatisticsTempList);
-
-                Set<Long> orgIds = new HashSet<>();
-                for (Long l : collegeIdSet) {
-                    List<SysOrg> sysOrgList = sysOrgService.findByConnectByRootOrgId(l);
-                    Set<Long> orgTempIds = sysOrgList.stream().map(s -> s.getId()).collect(Collectors.toSet());
-                    orgIds.addAll(orgTempIds);
-                }
-                List<TCStatisticsDto> tcStatisticsDtoList = this.findByBatchNoCountJoin(sysUser.getSchoolId(), batchNoNew, orgIds);
-                if (Objects.nonNull(tcStatisticsDtoList) && tcStatisticsDtoList.size() > 0) {
-                    QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
-                    tcStatisticsQueryWrapper.lambda().eq(TCStatistics::getBatchNo, batchNo);
-                    tcStatisticsService.remove(tcStatisticsQueryWrapper);
-
-                    Gson gson = new Gson();
-                    List<TCStatistics> tcStatisticsList = gson.fromJson(JacksonUtil.parseJson(tcStatisticsDtoList), new TypeToken<List<TCStatistics>>() {
-                    }.getType());
-                    for (TCStatistics t : tcStatisticsList) {
-                        t.insertInfo(sysUser.getId());
-                    }
-                    tcStatisticsService.saveBatch(tcStatisticsList);
-                }
-            }
-        }
-    }
-
     /**
      * 刷新数据
      *
@@ -217,11 +124,10 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
     @Override
     @Transactional
     public Result freshenData() {
-        TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
         tcStatisticsQueryWrapper.select(" DISTINCT batch_no ").eq("create_id", sysUser.getId());
-        List<TCStatistics> tcStatisticsList = tcStatisticsService.list(tcStatisticsQueryWrapper);
+        List<TCStatistics> tcStatisticsList = this.list(tcStatisticsQueryWrapper);
         if (Objects.nonNull(tcStatisticsList) && tcStatisticsList.size() > 0) {
             Set<String> batchNoSet = tcStatisticsList.stream().map(s -> s.getBatchNo()).collect(Collectors.toSet());
             boolean lock = redisUtil.lock(SystemConstant.REDIS_LOCK_BATCH_NO_PREFIX + Math.abs(batchNoSet.toString().hashCode()), SystemConstant.REDIS_LOCK_BATCH_NO_TIME_OUT);
@@ -229,7 +135,7 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
                 throw ExceptionResultEnum.ERROR.exception("正在刷新数据,请稍候再试!");
             }
             try {
-                tcStatisticsService.freshenJoinData(sysUser, batchNoSet);
+                this.freshenJoinData(sysUser, batchNoSet);
             } catch (Exception e) {
                 log.error("请求出错", e);
                 if (e instanceof ApiException) {
@@ -257,4 +163,120 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
         tcStatisticsService.removeByIds(ids);
         return ResultUtil.ok(true);
     }
+
+    /**
+     * 关联数据获取orgIds
+     *
+     * @param sysUser
+     * @param batchNo
+     * @param tcStatisticsTempList
+     * @return
+     */
+    private Set<Long> joinDataGetOrgIds(SysUser sysUser, String batchNo, List<TCStatisticsTemp> tcStatisticsTempList) {
+        Set<Long> collegeIdSet = new HashSet<>();
+        for (TCStatisticsTemp t : tcStatisticsTempList) {
+            collegeIdSet.add(t.getCollegeId());
+            t.insertInfo(sysUser.getId());
+            t.setBatchNo(batchNo);
+        }
+        tcStatisticsTempService.saveBatch(tcStatisticsTempList);
+
+        Set<Long> orgIds = new HashSet<>();
+        for (Long l : collegeIdSet) {
+            List<SysOrg> sysOrgList = sysOrgService.findByConnectByRootOrgId(l);
+            Set<Long> orgTempIds = sysOrgList.stream().map(s -> s.getId()).collect(Collectors.toSet());
+            orgIds.addAll(orgTempIds);
+        }
+        return orgIds;
+    }
+
+    /**
+     * 保存正式统计数据
+     *
+     * @param sysUser
+     * @param tcStatisticsDtoList
+     */
+    private void saveJoinData(SysUser sysUser, List<TCStatisticsDto> tcStatisticsDtoList) {
+        //进行过滤
+        Map<String, TCStatisticsDto> map = new LinkedHashMap<>();
+        for (TCStatisticsDto t : tcStatisticsDtoList) {
+            String key = t.getCollegeId() + ":" +
+                    t.getTeachingRoomId() + ":" +
+                    t.getCourseCode() + ":" +
+                    t.getPaperNumber() + ":" +
+                    t.getPrintPlanId() + ":" +
+                    t.getClazzId();
+            if (!map.containsKey(key)) {
+                map.computeIfAbsent(key, v -> t);
+            } else {
+                TCStatisticsDto temp = map.get(key);
+                if (t.getPrintSum().intValue() > temp.getPrintSum().intValue()) {
+                    map.put(key, t);
+                } else if (t.getPrintSum().intValue() == temp.getPrintSum().intValue()) {
+                    temp.setExamDetailId(null);
+                    temp.setStatus(StatisticsStatusEnum.UN_JOIN);
+                }
+            }
+        }
+        Gson gson = new Gson();
+        List<TCStatistics> tcStatisticsList = gson.fromJson(JacksonUtil.parseJson(map.values()), new TypeToken<List<TCStatistics>>() {
+        }.getType());
+        for (TCStatistics t : tcStatisticsList) {
+            t.insertInfo(sysUser.getId());
+        }
+        TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
+        tcStatisticsService.saveBatch(tcStatisticsList);
+    }
+
+    /**
+     * 刷新关联数据
+     *
+     * @param sysUser
+     * @param batchNoSet
+     */
+    public void freshenJoinData(SysUser sysUser, Set<String> batchNoSet) {
+        TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
+        for (String batchNo : batchNoSet) {
+            List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNoJoin(sysUser.getSchoolId(), batchNo);
+            if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
+                QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
+                tcStatisticsTempQueryWrapper.lambda().eq(TCStatisticsTemp::getBatchNo, batchNo);
+                tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
+
+                String batchNoNew = SystemConstant.getUuid();
+                Set<Long> orgIds = this.joinDataGetOrgIds(sysUser, batchNoNew, tcStatisticsTempList);
+                List<TCStatisticsDto> tcStatisticsDtoList = this.findByBatchNoCountJoin(sysUser.getSchoolId(), batchNoNew, orgIds);
+                if (Objects.nonNull(tcStatisticsDtoList) && tcStatisticsDtoList.size() > 0) {
+                    QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
+                    tcStatisticsQueryWrapper.lambda().eq(TCStatistics::getBatchNo, batchNo);
+                    tcStatisticsService.remove(tcStatisticsQueryWrapper);
+                    this.saveJoinData(sysUser, tcStatisticsDtoList);
+                }
+            }
+        }
+    }
+
+    /**
+     * 根据batchNo统计信息
+     *
+     * @param schoolId
+     * @param batchNo
+     * @param orgIds
+     * @return
+     */
+    public List<TCStatisticsDto> findByBatchNoCount(Long schoolId, String batchNo, Set<Long> orgIds) {
+        return tcStatisticsMapper.findByBatchNoCount(schoolId, batchNo, orgIds);
+    }
+
+    /**
+     * 根据batchNo统计信息
+     *
+     * @param schoolId
+     * @param batchNo
+     * @param orgIds
+     * @return
+     */
+    public List<TCStatisticsDto> findByBatchNoCountJoin(Long schoolId, String batchNo, Set<Long> orgIds) {
+        return tcStatisticsMapper.findByBatchNoCountJoin(schoolId, batchNo, orgIds);
+    }
 }

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

@@ -1383,7 +1383,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(errors));
             }
             //加入删除
-            tcStatisticsService.removeImportData(courseSet, collegeIdSet, teachingRoomIdSet, ClazzIdSet);
+            tcStatisticsService.removeImportData(sysUser.getId(), courseSet, collegeIdSet, teachingRoomIdSet, ClazzIdSet);
             tcStatisticsTempService.saveBatch(tcStatisticsImportTempList);
             map.put("dataCount", tcStatisticsImportTempList.size());
             tcStatisticsService.importJoinData(sysUser, batchNo);

+ 17 - 12
distributed-print-business/src/main/resources/mapper/TCStatisticsMapper.xml

@@ -58,15 +58,16 @@
         and es.clazz_id = tcs.clazz_id
         and es.school_id = #{schoolId}),0) as examStudentCount,
         case
-        when epp.status is null then 'UN_JOIN'
-        when epp.status = 'PRINT_FINISH'
-        or epp.status = 'END' then 'FINISH'
+        when ed.status is null then 'UN_JOIN'
+        when ed.status = 'FINISH' then 'FINISH'
         else 'UN_FINISH'
         end status
         from
         t_c_statistics tcs
         left join exam_print_plan epp on
         epp.id = tcs.print_plan_id
+        left join exam_detail ed on
+        ed.id = tcs.exam_detail_id and ed.print_plan_id = epp.id
         where 1 = 1
             and IF(epp.id is null, true,
         <if test="schoolId != null and schoolId != ''">
@@ -115,6 +116,7 @@
                 when sum(t.examStudentCount) = 0 then 0
                 else sum(t.examStudentCount) + (t.drawCount * t.backupCount)
             end printSum,
+            t.examDetailId,
             GROUP_CONCAT(distinct t.examDetailCourseId) as examDetailCourseIds,
             GROUP_CONCAT(distinct t.examTaskDetailId) as examTaskDetailIds
         from
@@ -136,6 +138,7 @@
                 etd.id as examTaskDetailId,
                 epp.id as printPlanId,
                 epp.name as printPlanName,
+                ed.id as examDetailId,
                 IFNULL(etd.draw_count, 0) as drawCount,
                 IFNULL((
                 select
@@ -147,10 +150,9 @@
                     and es.clazz_id = tcst.clazz_id
                     and es.school_id = #{schoolId}),0) as examStudentCount,
                 IFNULL(epp.backup_count, 0) as backupCount,
-                    case
-                        when epp.status is null then 'UN_JOIN'
-                        when epp.status = 'PRINT_FINISH'
-                    or epp.status = 'END' then 'FINISH'
+                case
+                    when ed.status is null then 'UN_JOIN'
+                    when ed.status = 'FINISH' then 'FINISH'
                     else 'UN_FINISH'
                 end status
             from
@@ -200,7 +202,8 @@
             t.printPlanName,
             t.status,
             t.drawCount,
-            t.batchNo
+            t.batchNo,
+            t.examDetailId
         order by
             t.printPlanId,
             t.clazzId
@@ -226,6 +229,7 @@
         when sum(t.examStudentCount) = 0 then 0
         else sum(t.examStudentCount) + (t.drawCount * t.backupCount)
         end printSum,
+        t.examDetailId,
         GROUP_CONCAT(distinct t.examDetailCourseId) as examDetailCourseIds,
         GROUP_CONCAT(distinct t.examTaskDetailId) as examTaskDetailIds
         from
@@ -247,6 +251,7 @@
         etd.id as examTaskDetailId,
         epp.id as printPlanId,
         epp.name as printPlanName,
+        ed.id as examDetailId,
         IFNULL(etd.draw_count, 0) as drawCount,
         IFNULL((
         select
@@ -259,9 +264,8 @@
         and es.school_id = #{schoolId}),0) as examStudentCount,
         IFNULL(epp.backup_count, 0) as backupCount,
         case
-        when epp.status is null then 'UN_JOIN'
-        when epp.status = 'PRINT_FINISH'
-        or epp.status = 'END' then 'FINISH'
+        when ed.status is null then 'UN_JOIN'
+        when ed.status = 'FINISH' then 'FINISH'
         else 'UN_FINISH'
         end status
         from
@@ -311,7 +315,8 @@
         t.printPlanName,
         t.status,
         t.drawCount,
-        t.batchNo
+        t.batchNo,
+        t.examDetailId
         order by
         t.printPlanId,
         t.clazzId

+ 2 - 0
distributed-print-business/src/main/resources/mapper/TCStatisticsTempMapper.xml

@@ -17,6 +17,7 @@
         epp.id as printPlanId,
         edc.id as examDetailCourseId,
         etd.id as examTaskDetailId,
+        ed.id as examDetailId,
         'JOIN' as dataSource
         from
         t_c_statistics_temp tcst
@@ -61,6 +62,7 @@
         epp.id as printPlanId,
         edc.id as examDetailCourseId,
         etd.id as examTaskDetailId,
+        ed.id as examDetailId,
         'JOIN' as dataSource
         from
         t_c_statistics_temp tcst

+ 8 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicCampusService.java

@@ -38,4 +38,12 @@ public interface BasicCampusService extends IService<BasicCampus> {
     Boolean removeBasicCampusById(Long id);
 
     Long getPrintHouseIdBySchoolIdAndCampusName(Long schoolId, String campusName);
+
+    /**
+     * 根据班级id集合查找对应的校区
+     * @param clazzIdList  班级id集合
+     * @param separator 校区连接符
+     * @return 连接符连好的校区
+     */
+    String findCampusNamesByClazzIdList(List<Long> clazzIdList,String separator);
 }

+ 7 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysOrgService.java

@@ -94,4 +94,11 @@ public interface SysOrgService extends IService<SysOrg> {
      * @return 符合条件的机构
      */
     List<SysOrg> findDeepByOrgIdAndType(OrgTypeEnum orgTypeEnum,Long orgId,boolean auth);
+
+    /**
+     * 根据机构id查询他的父亲们
+     * @param orgId 机构id
+     * @return 父亲们
+     */
+    List<SysOrg> findParentsByOrgId(Long orgId);
 }

+ 21 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicCampusServiceImpl.java

@@ -16,10 +16,12 @@ import com.qmth.teachcloud.common.service.BasicClazzService;
 import com.qmth.teachcloud.common.util.ServletUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -119,4 +121,23 @@ public class BasicCampusServiceImpl extends ServiceImpl<BasicCampusMapper, Basic
         }
         return basicCampus.getPrintHouseId();
     }
+
+    @Override
+    public String findCampusNamesByClazzIdList(List<Long> clazzIdList, String separator) {
+        String campusNames = "";
+        Long schoolId = SystemConstant.convertIdToLong(ServletUtil.getRequestHeaderSchoolId().toString());
+        List<Long> campusId = basicClazzService.list(new QueryWrapper<BasicClazz>().lambda()
+                .in(BasicClazz::getId,clazzIdList))
+                .stream()
+                .map(BasicClazz::getCampusId)
+                .distinct()
+                .collect(Collectors.toList());
+        if (!CollectionUtils.isEmpty(campusId)){
+            List<BasicCampus> basicCampusList = this.list(new QueryWrapper<BasicCampus>().lambda()
+                    .eq(BasicCampus::getSchoolId,schoolId)
+                    .in(BasicCampus::getId,campusId));
+            campusNames = basicCampusList.stream().map(BasicCampus::getCampusName).distinct().collect(Collectors.joining(separator));
+        }
+        return campusNames;
+    }
 }

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

@@ -19,6 +19,7 @@ import com.qmth.teachcloud.common.mapper.SysOrgMapper;
 import com.qmth.teachcloud.common.service.*;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -321,4 +322,33 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         }
         return this.list(queryWrapper);
     }
+
+    @Override
+    public List<SysOrg> findParentsByOrgId(Long orgId) {
+        SysOrg sysOrg = this.getById(orgId);
+        Long parentId = sysOrg.getParentId();
+        return this.findTopDFS(null,parentId);
+    }
+
+    /**
+     * 根据子机构id深度优先搜索其父机构们
+     * @param sysOrgList 目标父机构们
+     * @param orgId 子机构id
+     * @return 父亲们
+     */
+    private List<SysOrg> findTopDFS(List<SysOrg> sysOrgList,Long orgId){
+        if (CollectionUtils.isEmpty(sysOrgList)){
+            sysOrgList = new ArrayList<>();
+        }
+        SysOrg sysOrg = this.getById(orgId);
+        if (Objects.isNull(sysOrg)){
+            throw ExceptionResultEnum.ERROR.exception("找不到机构");
+        }
+        sysOrgList.add(sysOrg);
+        Long parentId = sysOrg.getParentId();
+        if (SystemConstant.longNotNull(parentId)){
+            this.findTopDFS(sysOrgList,parentId);
+        }
+        return sysOrgList;
+    }
 }