Просмотр исходного кода

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

xiaof 4 лет назад
Родитель
Сommit
0dfdeb11f5

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

@@ -3,6 +3,7 @@ package com.qmth.distributed.print.business.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.bean.result.TaskListResult;
+import com.qmth.distributed.print.business.entity.SysUser;
 import com.qmth.distributed.print.business.entity.TBTask;
 import com.qmth.distributed.print.business.enums.TaskResultEnum;
 import com.qmth.distributed.print.business.enums.TaskStatusEnum;
@@ -88,7 +89,15 @@ public interface TBTaskService extends IService<TBTask> {
      */
     public Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum, Long printPlanId);
 
-
+    /**
+     * 保存任务
+     *
+     * @param taskTypeEnum
+     * @param printPlanId
+     * @param sysUser
+     * @return
+     */
+    public Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum, Long printPlanId, SysUser sysUser);
 
     /**
      * 查询任务列表

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

@@ -21,11 +21,13 @@ import com.qmth.distributed.print.business.enums.TaskTypeEnum;
 import com.qmth.distributed.print.business.mapper.ExamDetailMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
+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;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -69,6 +71,8 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
 
     @Resource
     TBTaskService tbTaskService;
+    @Resource
+    ConvertUtil convertUtil;
 
     @Resource
     AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
@@ -141,8 +145,6 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
     @Transactional(rollbackFor = Exception.class)
     @Override
     public List<FieldsDto> findExaminationFields(Long schoolId) {
-        // TODO: 2021/4/9 回复schoolId的获取方式
-//        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
         BasicExamRule basicExamRule = basicExamRuleService.list(new QueryWrapper<BasicExamRule>().lambda().eq(BasicExamRule::getSchoolId, schoolId)).get(0);
         if (basicExamRule == null) {
             throw ExceptionResultEnum.ERROR.exception("找不到该学校考务字段信息 + schoolId" + schoolId);
@@ -191,23 +193,23 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         List<String> fieldsNameList = this.findExaminationFields(schoolId).stream().map(FieldsDto::getName).distinct().collect(Collectors.toList());
 
         log.debug("导出Excel开始...");
-        HSSFWorkbook wb = new HSSFWorkbook();
+        XSSFWorkbook wb = new XSSFWorkbook();
         String fileName = "考务数据模板";
         response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME) + DEFALUT_EXT);
         response.setContentType(DEFALUT_CONTENT_TYPE);
-        HSSFSheet sheet = wb.createSheet(cacheService.schoolCache(schoolId).getName() + "考务数据模板");
+        XSSFSheet sheet = wb.createSheet(cacheService.schoolCache(schoolId).getName() + "考务数据模板");
 
-        HSSFFont font = wb.createFont();
+        XSSFFont font = wb.createFont();
         font.setFontHeightInPoints((short) 11);
         font.setFontName("宋体"); //什么字体
 
-        HSSFRow row = sheet.createRow(0);
-        HSSFCellStyle style = wb.createCellStyle();
+        XSSFRow row = sheet.createRow(0);
+        XSSFCellStyle style = wb.createCellStyle();
         style.setAlignment(HorizontalAlignment.CENTER);
         style.setFont(font);
 
         for (int i = 0; i < fieldsNameList.size(); i++) {
-            HSSFCell cell = row.createCell(i);
+            XSSFCell cell = row.createCell(i);
             cell.setCellValue(fieldsNameList.get(i));
             cell.setCellStyle(style);
         }
@@ -365,6 +367,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.setSchoolId(Long.valueOf(String.valueOf(map.get("schoolId"))));
             examDetail.setPrintPlanId(Long.valueOf(String.valueOf(map.get("printPlanId"))));
             examDetail.setPrintPlanName(String.valueOf(map.get("printPlanName")));
@@ -522,21 +525,27 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         // 准备删除的考务-场次表id
         List<Long> examDetailIds = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId, printPlanId))
                 .stream().map(ExamDetail::getId).collect(Collectors.toList());
+        if (examDetailIds.size() == 0){
+            return;
+        }
+        // 删除exam_detail 表数据
+        this.remove(new QueryWrapper<ExamDetail>().lambda().in(ExamDetail::getId, examDetailIds));
 
         // 准备删除的考务-科目表id
         List<Long> examDetailCourseIds = examDetailCourseService.list(new QueryWrapper<ExamDetailCourse>().lambda().in(ExamDetailCourse::getExamDetailId, examDetailIds))
                 .stream().map(ExamDetailCourse::getId).collect(Collectors.toList());
+        if (examDetailCourseIds.size() == 0){
+            return;
+        }
+        // 删除exam_detail_course 表数据
+        examDetailCourseService.remove(new QueryWrapper<ExamDetailCourse>().lambda().in(ExamDetailCourse::getId, examDetailCourseIds));
 
         // 准备删除的考务-考生表id
         List<Long> examStudentIds = examStudentService.list(new QueryWrapper<ExamStudent>().lambda().in(ExamStudent::getExamDetailCourseId, examDetailCourseIds))
                 .stream().map(ExamStudent::getId).collect(Collectors.toList());
-
-        // 删除exam_detail 表数据
-        this.remove(new QueryWrapper<ExamDetail>().lambda().in(ExamDetail::getId, examDetailIds));
-
-        // 删除exam_detail_course 表数据
-        examDetailCourseService.remove(new QueryWrapper<ExamDetailCourse>().lambda().in(ExamDetailCourse::getId, examDetailCourseIds));
-
+        if (examStudentIds.size() == 0){
+            return;
+        }
         // 删除exam_student 表数据
         examStudentService.remove(new QueryWrapper<ExamStudent>().lambda().in(ExamStudent::getId, examStudentIds));
     }

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

@@ -76,6 +76,9 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Autowired
     private ExamCardService examCardService;
 
+    @Autowired
+    private ExamDetailCourseService examDetailCourseService;
+
     @Override
     public List<ExamTask> listByCourseCode(Long schoolId, String code) {
         QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
@@ -96,17 +99,31 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Override
     public List<String> listPaperNumber(String param) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
+        // 查询命题任务中的试卷编号
+        QueryWrapper<ExamTask> queryWrapperExamTask = new QueryWrapper<>();
         List<String> list = new ArrayList<>();
         if (StringUtils.isNotBlank(param)) {
-            queryWrapper.lambda().eq(ExamTask::getSchoolId, schoolId)
+            queryWrapperExamTask.lambda().eq(ExamTask::getSchoolId, schoolId)
                     .and(i -> i.like(ExamTask::getCourseCode, param).or().like(ExamTask::getCourseName, param));
         }
-        List<ExamTask> examTasks = this.list(queryWrapper);
+        List<ExamTask> examTasks = this.list(queryWrapperExamTask);
         if (examTasks != null && examTasks.size() > 0) {
-            list = examTasks.stream().map(m -> m.getPaperNumber()).distinct().collect(Collectors.toList());
+            list = examTasks.stream().map(ExamTask::getPaperNumber).distinct().collect(Collectors.toList());
         }
-        return list;
+
+        // 查询考务-科目中的试卷编号
+        QueryWrapper<ExamDetailCourse> queryWrapperExamDetailCourse = new QueryWrapper<>();
+        List<String> list2 = new ArrayList<>();
+        if (StringUtils.isNotBlank(param)) {
+            queryWrapperExamDetailCourse.lambda().eq(ExamDetailCourse::getSchoolId, schoolId)
+                    .and(i -> i.like(ExamDetailCourse::getCourseCode, param).or().like(ExamDetailCourse::getCourseName, param));
+        }
+        List<ExamDetailCourse> ExamDetailCourses = examDetailCourseService.list(queryWrapperExamDetailCourse);
+        if (ExamDetailCourses != null && ExamDetailCourses.size() > 0) {
+            list2 = ExamDetailCourses.stream().map(ExamDetailCourse::getPaperNumber).distinct().collect(Collectors.toList());
+        }
+        list.addAll(list2);
+        return list.stream().distinct().collect(Collectors.toList());
     }
 
     @Override

+ 33 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBTaskServiceImpl.java

@@ -62,7 +62,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
                 throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
             } else {
                 map = new HashMap<>();
-                TBTask tbTask = saveTaskCommon(basicAttachment, taskTypeEnum, map);
+                TBTask tbTask = saveTaskCommon(basicAttachment, taskTypeEnum, map, null);
                 this.save(tbTask);
             }
         } catch (Exception e) {
@@ -85,7 +85,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
         Map<String, Object> map = null;
         try {
             map = new HashMap<>();
-            TBTask tbTask = saveTaskCommon(null, taskTypeEnum, map);
+            TBTask tbTask = saveTaskCommon(null, taskTypeEnum, map, null);
             this.save(tbTask);
         } catch (Exception e) {
             log.error("请求出错", e);
@@ -109,7 +109,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
                 throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
             } else {
                 map = new HashMap<>();
-                TBTask tbTask = saveTaskCommon(basicAttachment, taskTypeEnum, map);
+                TBTask tbTask = saveTaskCommon(basicAttachment, taskTypeEnum, map, null);
                 tbTask.setPrintPlanId(printPlanId);
                 this.save(tbTask);
             }
@@ -179,7 +179,33 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
     public Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum, Long printPlanId) {
         Map<String, Object> map = new HashMap<>();
         try {
-            TBTask tbTask = saveTaskCommon(null, taskTypeEnum, map);
+            TBTask tbTask = saveTaskCommon(null, taskTypeEnum, map, null);
+            tbTask.setPrintPlanId(printPlanId);
+            this.save(tbTask);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 保存任务
+     *
+     * @param taskTypeEnum
+     * @param printPlanId
+     * @param sysUser
+     * @return
+     */
+    @Override
+    public Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum, Long printPlanId, SysUser sysUser) {
+        Map<String, Object> map = new HashMap<>();
+        try {
+            TBTask tbTask = saveTaskCommon(null, taskTypeEnum, map, sysUser);
             tbTask.setPrintPlanId(printPlanId);
             this.save(tbTask);
         } catch (Exception e) {
@@ -213,10 +239,11 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
      *
      * @param basicAttachment
      * @param taskTypeEnum
+     * @param sysUser
      * @return
      */
-    public TBTask saveTaskCommon(BasicAttachment basicAttachment, TaskTypeEnum taskTypeEnum, Map map) {
-        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+    public TBTask saveTaskCommon(BasicAttachment basicAttachment, TaskTypeEnum taskTypeEnum, Map map, SysUser sysUser) {
+        SysUser requestUser = Objects.nonNull(sysUser) ? sysUser : (SysUser) ServletUtil.getRequestUser();
 
         TBTask tbTask = new TBTask(taskTypeEnum,
                 TaskStatusEnum.INIT,

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

@@ -12,7 +12,6 @@ import com.qmth.distributed.print.common.util.ResultUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.InputStream;
@@ -34,7 +33,6 @@ public class AsyncExaminationImportTemplateService extends AsyncImportTaskTemple
 
     public static final String OBJ_TITLE = "考务数据";
 
-    @Transactional(rollbackFor = Exception.class)
     @Override
     public Result importTask(Map<String, Object> map) throws Exception {
         TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);

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

@@ -505,19 +505,19 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
 
         // TODO: 2021/4/13 调用检验接口 dataList按照schoolId,courseCode,paperNumber归集
-        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"));
-            commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber);
-        }
+//        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"));
+//            commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber);
+//        }
         map.put("dataCount",dataList.size());
         return map;
     }

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

@@ -91,9 +91,9 @@ public class ConvertUtil {
      * @param prefix 生成序列号的前缀
      * @return
      */
-    public String getIncre(String prefix) {
+    public String getIncre(String prefix,String model) {
         //序列号前缀加特定标识,如系统模块名之类的 防止重复
-        String key = "SCM_DAMLL" + prefix;
+        String key = model + "-" + prefix;
         String increResult = null;
         try {
             //如果该key不存在 会自动创建,值为第二个参数delta

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamDetailController.java

@@ -158,7 +158,7 @@ public class ExamDetailController {
         map.put("packageCode",packageCode);
         asyncExaminationExportTemplateService
                 .exportTask(map);
-        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
+//        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
     }
 }