Преглед изворни кода

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

xiaof пре 3 година
родитељ
комит
5f5c87169c

+ 17 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCStatisticsService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.bean.dto.TCStatisticsDto;
 import com.qmth.distributed.print.business.entity.TCStatistics;
 import com.qmth.distributed.print.business.enums.StatisticsStatusEnum;
+import com.qmth.teachcloud.common.entity.SysUser;
 
 import java.util.List;
 import java.util.Map;
@@ -51,4 +52,20 @@ public interface TCStatisticsService extends IService<TCStatistics> {
      * @return
      */
     public List<TCStatisticsDto> findByBatchNoCount(Long schoolId, String batchNo, Set<Long> orgIds);
+
+    /**
+     * 导入关联数据
+     *
+     * @param sysUser
+     * @param batchNo
+     */
+    public void importJoinData(SysUser sysUser, String batchNo);
+
+    /**
+     * 删除导入数据
+     *
+     * @param courseSet
+     * @param setCollections
+     */
+    public void removeImportData(Set<String> courseSet, Set<Long>... setCollections);
 }

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

@@ -1,19 +1,31 @@
 package com.qmth.distributed.print.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
 import com.qmth.distributed.print.business.bean.dto.TCStatisticsDto;
 import com.qmth.distributed.print.business.entity.TCStatistics;
+import com.qmth.distributed.print.business.entity.TCStatisticsTemp;
 import com.qmth.distributed.print.business.enums.StatisticsStatusEnum;
 import com.qmth.distributed.print.business.mapper.TCStatisticsMapper;
+import com.qmth.distributed.print.business.mapper.TCStatisticsTempMapper;
 import com.qmth.distributed.print.business.service.TCStatisticsService;
+import com.qmth.distributed.print.business.service.TCStatisticsTempService;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.SysOrg;
+import com.qmth.teachcloud.common.entity.SysUser;
+import com.qmth.teachcloud.common.service.SysOrgService;
+import com.qmth.teachcloud.common.util.JacksonUtil;
+import org.springframework.boot.SpringApplication;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -29,6 +41,12 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
     @Resource
     TCStatisticsMapper tcStatisticsMapper;
 
+    @Resource
+    TCStatisticsTempService tcStatisticsTempService;
+
+    @Resource
+    SysOrgService sysOrgService;
+
     /**
      * 查找印刷计划信息
      *
@@ -59,4 +77,69 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
     public List<TCStatisticsDto> findByBatchNoCount(Long schoolId, String batchNo, Set<Long> orgIds) {
         return tcStatisticsMapper.findByBatchNoCount(schoolId, batchNo, orgIds);
     }
+
+    /**
+     * 导入关联数据
+     *
+     * @param sysUser
+     * @param batchNo
+     */
+    @Override
+    @Transactional
+    public void importJoinData(SysUser sysUser, String batchNo) {
+        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);
+            }
+            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);
+            }
+        }
+    }
+
+    /**
+     * 删除导入数据
+     *
+     * @param courseSet
+     * @param setCollections
+     */
+    @Override
+    @Transactional
+    public void removeImportData(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]);
+        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]);
+        tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
+    }
 }

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

@@ -1382,50 +1382,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 List<String> errors = excelErrorTemp.stream().map(m -> m.getExcelErrorType()).collect(Collectors.toList());
                 throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(errors));
             }
-            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);
-            }
             //加入删除
-            QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
-            tcStatisticsQueryWrapper.lambda().in(TCStatistics::getCollegeId, collegeIdSet)
-                    .in(TCStatistics::getTeachingRoomId, teachingRoomIdSet)
-                    .in(TCStatistics::getCourseCode, courseSet)
-                    .in(TCStatistics::getClazzId, ClazzIdSet);
-            tcStatisticsService.remove(tcStatisticsQueryWrapper);
-
-            QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
-            tcStatisticsTempQueryWrapper.lambda().in(TCStatisticsTemp::getCollegeId, collegeIdSet)
-                    .in(TCStatisticsTemp::getTeachingRoomId, teachingRoomIdSet)
-                    .in(TCStatisticsTemp::getCourseCode, courseSet)
-                    .in(TCStatisticsTemp::getClazzId, ClazzIdSet);
-            tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
-
+            tcStatisticsService.removeImportData(courseSet, collegeIdSet, teachingRoomIdSet, ClazzIdSet);
             tcStatisticsTempService.saveBatch(tcStatisticsImportTempList);
             map.put("dataCount", tcStatisticsImportTempList.size());
-
-            List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNo(sysUser.getSchoolId(), batchNo);
-            if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
-                batchNo = SystemConstant.getUuid();
-                for (TCStatisticsTemp t : tcStatisticsTempList) {
-                    t.insertInfo(sysUser.getId());
-                    t.setBatchNo(batchNo);
-                }
-                tcStatisticsTempService.saveBatch(tcStatisticsTempList);
-
-                List<TCStatisticsDto> tcStatisticsDtoList = tcStatisticsService.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.saveBatch(tcStatisticsList);
-                }
-            }
+            tcStatisticsService.importJoinData(sysUser, batchNo);
             return finalExcelList;
         });
         return map;