caozixuan 4 роки тому
батько
коміт
eaf890a4af

+ 53 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/params/SerialNumberParams.java

@@ -0,0 +1,53 @@
+package com.qmth.distributed.print.business.bean.params;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: redis生成序列号参数类
+ * @Author: CaoZixuan
+ * @Date: 2021-04-19
+ */
+public class SerialNumberParams {
+
+    @ApiModelProperty(value = "序列号所属模块")
+    private String model;
+
+    @ApiModelProperty(value = "序列号前缀(序列号模块加前缀作为key)")
+    private String prefix;
+
+    @ApiModelProperty(value = "补齐位数")
+    private int digit;
+
+    public SerialNumberParams(String model, String prefix, int digit) {
+        this.model = model;
+        this.prefix = prefix;
+        this.digit = digit;
+    }
+
+    public SerialNumberParams() {
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    public int getDigit() {
+        return digit;
+    }
+
+    public void setDigit(int digit) {
+        this.digit = digit;
+    }
+}

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

@@ -6,6 +6,7 @@ import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
 import com.qmth.distributed.print.business.bean.dto.FieldsDto;
 import com.qmth.distributed.print.business.bean.dto.PrintTaskDto;
 import com.qmth.distributed.print.business.bean.dto.PrintTaskTotalDto;
+import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.bean.result.ExaminationDetailResult;
 import com.qmth.distributed.print.business.bean.result.ExaminationResult;
 import com.qmth.distributed.print.business.bean.result.SummarizedDataResult;
@@ -131,8 +132,9 @@ public interface ExamDetailService extends IService<ExamDetail> {
      * 根据考务数据Excel数据处理考务-场次表
      * @param dataList Excel处理后的数据
      * @param userId 当前用户id
+     * @param serialNumberParams 序列号生成参数
      */
-    void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId);
+    void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams);
 
     /**
      * 根据考务数据Excel数据处理考务-科目表

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

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.distributed.print.business.bean.dto.*;
+import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.bean.result.ExaminationDetailResult;
 import com.qmth.distributed.print.business.bean.result.ExaminationResult;
 import com.qmth.distributed.print.business.bean.result.SummarizedDataResult;
@@ -342,7 +343,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId) {
+    public void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams) {
         List<Map<String, Object>> examDetailKeyList = dataList.stream().flatMap(e -> {
             Map<String, Object> map = new HashMap<>();
             map.put("schoolId", e.get("schoolId"));
@@ -374,7 +375,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
             System.out.println("totalSubjects" + totalSubjects);
             ExamDetail examDetail = new ExamDetail();
             examDetail.setId(SystemConstant.getDbUuid());
-            examDetail.setPackageCode(convertUtil.getIncre("x", "packageCode"));
+            examDetail.setPackageCode(convertUtil.getIncre(serialNumberParams.getPrefix(),serialNumberParams.getModel(),serialNumberParams.getDigit()));
             examDetail.setSchoolId(Long.valueOf(String.valueOf(map.get("schoolId"))));
             examDetail.setPrintPlanId(Long.valueOf(String.valueOf(map.get("printPlanId"))));
             examDetail.setPrintPlanName(String.valueOf(map.get("printPlanName")));

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

@@ -8,6 +8,7 @@ import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
 import com.qmth.distributed.print.business.bean.dto.FieldsDto;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
+import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
@@ -26,6 +27,8 @@ import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -92,6 +95,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     CreatePdfUtil createPdfUtil;
 
+    @Resource
+    RedisTemplate<String, Object> redisTemplate;
+
     /**
      * 创建pdf逻辑
      *
@@ -317,7 +323,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return map;
     }
 
-    @Transactional(rollbackFor = Exception.class)
+    @Transactional
     @Override
     public Map<String, Object> executeImportExaminationLogic(Map<String, Object> map) throws Exception {
         TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
@@ -474,29 +480,41 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
         // 删除印刷计划下的考务数据
         examDetailService.deleteExaminationData(printPlanId);
-        // 组装exam_detail数据
-        examDetailService.disposeExamDetailByExaminationExcel(dataList, userId);
-        // 组装exam_detail_course数据
-        examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
-        // 组装exam_student数据
-        examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
-
-        List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
-            Map<String, Object> tmp = new HashMap<>();
-            tmp.put("schoolId", e.get("schoolId"));
-            tmp.put("courseCode", e.get("courseCode"));
-            tmp.put("paperNumber", e.get("paperNumber"));
-            return Stream.of(tmp);
-        }).distinct().collect(Collectors.toList());
-        for (Map<String, Object> stringObjectMap : checkList) {
-            Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
-            String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
-            String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
-            SysUser user = (SysUser) map.get(SystemConstant.USER);
-            user.setSchoolId(schoolId);
-            commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
+
+
+        SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-","p",6);
+        String key = serialNumberParams.getModel() + serialNumberParams.getPrefix();
+        RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
+        Long value = counter.get();
+        try {
+            // 组装exam_detail数据
+            examDetailService.disposeExamDetailByExaminationExcel(dataList, userId , serialNumberParams);
+            // 组装exam_detail_course数据
+            examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
+            // 组装exam_student数据
+            examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
+
+            List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
+                Map<String, Object> tmp = new HashMap<>();
+                tmp.put("schoolId", e.get("schoolId"));
+                tmp.put("courseCode", e.get("courseCode"));
+                tmp.put("paperNumber", e.get("paperNumber"));
+                return Stream.of(tmp);
+            }).distinct().collect(Collectors.toList());
+            for (Map<String, Object> stringObjectMap : checkList) {
+                Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
+                String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
+                String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
+                SysUser user = (SysUser) map.get(SystemConstant.USER);
+                user.setSchoolId(schoolId);
+                commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
+            }
+            map.put("dataCount", dataList.size());
+        }catch (Exception e){
+            redisTemplate.opsForValue().set(key,value);
+            throw new RuntimeException(e);
         }
-        map.put("dataCount", dataList.size());
+
         return map;
     }
 }

+ 13 - 9
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ConvertUtil.java

@@ -131,23 +131,27 @@ public class ConvertUtil {
 
 
     /**
-     * 获取递增的序列号
-     *
-     * @param prefix 生成序列号的前缀
-     * @return
+     * 获取递增序列号
+     * @param prefix 前缀
+     * @param model 模块
+     * @param digit 补齐位数
+     * @return 序列号
      */
-    public String getIncre(String prefix,String model) {
-        final String STR_FORMAT = "000000";
+    public String getIncre(String prefix,String model,int digit) {
+        StringBuilder temp = new StringBuilder();
+        for (int i = 0;i < digit;i ++){
+            temp.append("0");
+        }
         //序列号前缀加特定标识,如系统模块名之类的 防止重复
-        String key = model + "-" + prefix;
+        String key = model + prefix;
         String increResult = "";
         try {
             //如果该key不存在 会自动创建,值为第二个参数delta
             //最终调用的还是jedis的incrBy(byte[] key, long value)方法
             RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
-            Long increment = counter.getAndIncrement();
+            Long increment = counter.incrementAndGet();
             //不足补位
-            DecimalFormat df = new DecimalFormat(STR_FORMAT);
+            DecimalFormat df = new DecimalFormat(temp.toString());
             increResult = prefix + df.format(increment);
         } catch (Exception e) {
             // TODO: 2021/4/16