caozixuan 4 年之前
父節點
當前提交
e088c3e5b4

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

@@ -76,6 +76,9 @@ public class PrintPlanResult {
     @ApiModelProperty(value = "创建时间")
     private Long createTime;
 
+    @ApiModelProperty(value = "创建人名字")
+    private String createName;
+
     public Long getId() {
         return id;
     }
@@ -219,4 +222,12 @@ public class PrintPlanResult {
     public void setCreateTime(Long createTime) {
         this.createTime = createTime;
     }
+
+    public String getCreateName() {
+        return createName;
+    }
+
+    public void setCreateName(String createName) {
+        this.createName = createName;
+    }
 }

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

@@ -2,7 +2,6 @@ package com.qmth.distributed.print.business.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -23,7 +22,6 @@ import com.qmth.distributed.print.business.util.ConvertUtil;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
-import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.xssf.usermodel.*;
 import org.slf4j.Logger;
@@ -89,11 +87,11 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
     public double calculateTotalPackages(Long printPlanId) {
         double result = 0;
         List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId, printPlanId));
-        for (ExamDetail examDetail : examDetailList) {
-            double count = examDetailCourseService.calculatePackagesByDetailId(examDetail.getId());
-            result = result + count;
-        }
-        return result;
+//        for (ExamDetail examDetail : examDetailList) {
+//            double count = examDetailCourseService.calculatePackagesByDetailId(examDetail.getId());
+//            result = result + count;
+//        }
+        return examDetailList.size();
     }
 
     @Override
@@ -269,17 +267,14 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         IPage<ExaminationResult> page = this.findExaminationBriefPage(schoolId, printPlanId, courseCode, paperNumber, examPlace, examRoom, packageCode, SystemConstant.PAGE_NUMBER, SystemConstant.PAGE_SIZE);
         List<ExaminationResult> list = page.getRecords();
         int totalSubjects = 0;
-        int packageCount = 0;
         for (ExaminationResult examinationResult : list) {
             int subjects = examinationResult.getTotalSubjects();
-            int packages = examinationResult.getCourseNameCode().split("、").length;
             totalSubjects = totalSubjects + subjects;
-            packageCount = packageCount + packages;
         }
         SummarizedDataResult summarizedDataResult = new SummarizedDataResult();
         summarizedDataResult.setSchoolId(schoolId);
         summarizedDataResult.setTotalSubjects(totalSubjects);
-        summarizedDataResult.setPackageCount(packageCount);
+        summarizedDataResult.setPackageCount(list.size());
         return summarizedDataResult;
     }
 
@@ -379,7 +374,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("p-","packageCode"));
+            examDetail.setPackageCode(convertUtil.getIncre("x","packageCode"));
             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")));

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

@@ -231,9 +231,8 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
         if (!PrintPlanStatusEnum.NEW.equals(examPrintPlan.getStatus())){
             throw ExceptionResultEnum.ERROR.exception("只有'新建'状态的项目计划可以被删除 status = " + examPrintPlan.getStatus());
         }
-        this.removeById(id);
         examDetailService.deleteExaminationData(id);
-        return true;
+        return this.removeById(id);
     }
 
     /**

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

@@ -16,7 +16,9 @@ import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.apache.catalina.core.ApplicationContext;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -52,7 +54,8 @@ public class ExamTaskDetailServiceImpl extends ServiceImpl<ExamTaskDetailMapper,
     private CommonService commonService;
 
     @Resource
-    AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
+    @Lazy
+    private AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
 
     @Resource
     TBTaskService tbTaskService;

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

@@ -22,10 +22,7 @@ import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -411,33 +408,28 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 String code = fieldsDto.getCode();
                 int index = fieldsDto.getIndex();
                 String level = fieldsDto.getLevel();
+
+                Cell cell = row.getCell(index);
+                String cellValue = String.valueOf(ExcelUtil.convert(cell));
+
                 if ("学号".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    studentCode = row.getCell(index).getStringCellValue();
+                    studentCode = cellValue;
                 } else if ("姓名".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    studentName = row.getCell(index).getStringCellValue();
+                    studentName = cellValue;
                 } else if ("课程代码".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    courseCode = row.getCell(index).getStringCellValue();
+                    courseCode = cellValue;
                 } else if ("课程名称".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    courseName = row.getCell(index).getStringCellValue();
+                    courseName = cellValue;
                 } else if ("考点".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    examPlace = row.getCell(index).getStringCellValue();
+                    examPlace = cellValue;
                 } else if ("考场".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    examRoom = row.getCell(index).getStringCellValue();
+                    examRoom = cellValue;
                 } else if ("考试日期".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    examDate = row.getCell(index).getStringCellValue();
+                    examDate = cellValue;
                 } else if ("考试时间".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    examTime = row.getCell(index).getStringCellValue();
+                    examTime = cellValue;
                 } else if ("试卷编号".equals(name)) {
-                    row.getCell(index).setCellType(CellType.STRING);
-                    paperNumber = row.getCell(index).getStringCellValue();
+                    paperNumber = cellValue;
                 } else {
                     if ("primary".equals(level)) {
                         throw ExceptionResultEnum.ERROR.exception("有数据库不需要的必选字段 : " + name);
@@ -449,7 +441,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         secondaryField.setCode(code);
                         secondaryField.setName(name);
                         secondaryField.setEnable(true);
-                        secondaryField.setValue(row.getCell(index).getStringCellValue());
+                        secondaryField.setValue(cellValue);
                         secondaryFieldList.add(secondaryField);
                     }
                 }

+ 65 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ConvertUtil.java

@@ -1,16 +1,19 @@
 package com.qmth.distributed.print.business.util;
 
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.*;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Description: 转换工具类
@@ -134,20 +137,75 @@ public class ConvertUtil {
      * @return
      */
     public String getIncre(String prefix,String model) {
+        final String STR_FORMAT = "000000";
         //序列号前缀加特定标识,如系统模块名之类的 防止重复
         String key = model + "-" + prefix;
-        String increResult = null;
+        String increResult = "";
         try {
             //如果该key不存在 会自动创建,值为第二个参数delta
             //最终调用的还是jedis的incrBy(byte[] key, long value)方法
-            Long increNum = redisTemplate.opsForValue().increment(key, 1);
+            RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
+            Long increment = counter.getAndIncrement();
             //不足补位
-            increResult = prefix + String.format("%1$06d", increNum);
+            DecimalFormat df = new DecimalFormat(STR_FORMAT);
+            increResult = prefix + df.format(increment);
         } catch (Exception e) {
+            // TODO: 2021/4/16  
             System.out.println("获取序列号失败");
             /*这里可以根据需求手动生成一个不重复的单号,
              * */
         }
         return increResult;
     }
+
+    /**
+     * 解析excel单元格类型
+     * @param cell 单元格
+     * @return 转换成字符串后的值
+     */
+    public static String analyzeExcelCellValue(Cell cell){
+        String cellValue;
+        CellType cellType = cell.getCellTypeEnum();
+        switch (cellType) {
+            case NUMERIC:
+                if (HSSFDateUtil.isCellDateFormatted(cell)) {
+                    SimpleDateFormat sdf;
+                    // 验证short值
+                    if (cell.getCellStyle().getDataFormat() == 14) {
+                        sdf = new SimpleDateFormat("yyyy/MM/dd");
+                    } else if (cell.getCellStyle().getDataFormat() == 21) {
+                        sdf = new SimpleDateFormat("HH:mm:ss");
+                    } else if (cell.getCellStyle().getDataFormat() == 22) {
+                        sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+                    } else {
+                        throw new RuntimeException("日期格式错误!!!");
+                    }
+                    Date date = cell.getDateCellValue();
+                    cellValue = sdf.format(date);
+                } else {//处理数值格式
+                    cell.setCellType(CellType.STRING);
+                    cellValue = String.valueOf(cell.getRichStringCellValue().getString());
+                }
+                break;
+            case STRING:
+                cellValue = String.valueOf(cell.getStringCellValue());
+                break;
+            case BOOLEAN:
+                cellValue = String.valueOf(cell.getBooleanCellValue());
+                break;
+            case FORMULA:
+                cellValue = String.valueOf(cell.getCellFormula());
+                break;
+            case BLANK:
+                cellValue = null;
+                break;
+            case ERROR:
+                cellValue = "非法字符";
+                break;
+            default:
+                cellValue = "未知类型";
+                break;
+        }
+        return cellValue;
+    }
 }

+ 22 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ExcelUtil.java

@@ -6,7 +6,9 @@ import com.qmth.distributed.print.business.util.excel.ExcelError;
 import com.qmth.distributed.print.business.util.excel.ExcelWriter;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -23,6 +25,7 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -210,10 +213,27 @@ public class ExcelUtil {
      * @param cell
      * @return
      */
-    private static Object convert(Cell cell) {
+    public static Object convert(Cell cell) {
         switch (cell.getCellTypeEnum()) {
             case NUMERIC:
-                return cell.getNumericCellValue();
+                if (HSSFDateUtil.isCellDateFormatted(cell)) {
+                    SimpleDateFormat sdf;
+                    // 验证short值
+                    if (cell.getCellStyle().getDataFormat() == 14) {
+                        sdf = new SimpleDateFormat("yyyy/MM/dd");
+                    } else if (cell.getCellStyle().getDataFormat() == 21) {
+                        sdf = new SimpleDateFormat("HH:mm:ss");
+                    } else if (cell.getCellStyle().getDataFormat() == 22) {
+                        sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+                    } else {
+                        throw new RuntimeException("日期格式错误!!!");
+                    }
+                    Date date = cell.getDateCellValue();
+                    return sdf.format(date);
+                } else {//处理数值格式
+                    cell.setCellType(CellType.STRING);
+                    return String.valueOf(cell.getRichStringCellValue().getString());
+                }
             case STRING:
                 return cell.getStringCellValue();
             case FORMULA:

+ 3 - 2
distributed-print-business/src/main/resources/mapper/ExamPrintPlanMapper.xml

@@ -43,7 +43,7 @@
                 FROM
                 exam_detail_course
             WHERE
-            exam_detail_id IN ( SELECT id FROM exam_detail WHERE print_plan_id = 1 )) AS totalGates,
+            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,
@@ -51,7 +51,8 @@
             a.variable_content AS variableContentTemp,
             a.ordinary_content AS ordinaryContentTemp,
             a.create_id AS createId,
-            a.create_time AS createTime
+            a.create_time AS createTime,
+            b.real_name AS createName
         FROM
             exam_print_plan a
                 LEFT JOIN