Browse Source

考场导出接口

wangliang 5 years ago
parent
commit
13be5bdc1b
28 changed files with 773 additions and 111 deletions
  1. 26 3
      themis-backend/src/main/java/com/qmth/themis/backend/api/TBExamInvigilateUserController.java
  2. 1 1
      themis-backend/src/main/java/com/qmth/themis/backend/api/TEExamStudentController.java
  3. 6 0
      themis-backend/src/main/resources/application.properties
  4. 18 0
      themis-business/src/main/java/com/qmth/themis/business/annotation/ExcelNote.java
  5. 1 1
      themis-business/src/main/java/com/qmth/themis/business/constant/SpringContextHolder.java
  6. 4 0
      themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java
  7. 9 0
      themis-business/src/main/java/com/qmth/themis/business/dao/TBExamInvigilateUserMapper.java
  8. 18 0
      themis-business/src/main/java/com/qmth/themis/business/domain/MqConfigDomain.java
  9. 45 0
      themis-business/src/main/java/com/qmth/themis/business/dto/RoomCodeExportDto.java
  10. 10 0
      themis-business/src/main/java/com/qmth/themis/business/entity/TBTaskHistory.java
  11. 11 0
      themis-business/src/main/java/com/qmth/themis/business/service/TBAttachmentService.java
  12. 9 0
      themis-business/src/main/java/com/qmth/themis/business/service/TBExamInvigilateUserService.java
  13. 11 6
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TBAttachmentServiceImpl.java
  14. 12 0
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TBExamInvigilateUserServiceImpl.java
  15. 227 0
      themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportCommon.java
  16. 10 1
      themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportTemplete.java
  17. 6 2
      themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java
  18. 2 1
      themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java
  19. 149 0
      themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeExportTemplete.java
  20. 2 1
      themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java
  21. 1 1
      themis-business/src/main/java/com/qmth/themis/business/util/EhcacheUtil.java
  22. 1 3
      themis-business/src/main/java/com/qmth/themis/business/util/JacksonUtil.java
  23. 42 25
      themis-business/src/main/resources/mapper/TBExamInvigilateUserMapper.xml
  24. 1 1
      themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketSessionConsumer.java
  25. 132 48
      themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketTaskConsumer.java
  26. 1 1
      themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketUserLogConsumer.java
  27. 11 15
      themis-task/src/main/java/com/qmth/themis/task/quartz/MqJob.java
  28. 7 1
      themis-task/src/main/resources/application.properties

+ 26 - 3
themis-backend/src/main/java/com/qmth/themis/backend/api/TBExamInvigilateUserController.java

@@ -30,7 +30,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.util.*;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -141,7 +140,7 @@ public class TBExamInvigilateUserController {
                 throw new BusinessException(ExceptionResultEnum.ATTACHMENT_ERROR);
             } else {
                 //往任务表里插一条数据
-                tbTaskHistory = new TBTaskHistory(TaskTypeEnum.import_exam_student.ordinal(), tbAttachment.getId(), TaskTypeExecEnum.init.ordinal(), "准备开始处理", 0d, tbAttachment.getName(), tbAttachment.getRemark(), tbUser.getId());
+                tbTaskHistory = new TBTaskHistory(TaskTypeEnum.import_invigilate_user.ordinal(), tbAttachment.getId(), TaskTypeExecEnum.init.ordinal(), SystemConstant.IMPORT_INIT, 0d, tbAttachment.getName(), tbAttachment.getRemark(), tbUser.getId());
                 taskHistoryService.save(tbTaskHistory);
                 transMap.put("tbTaskHistory", tbTaskHistory);
             }
@@ -173,6 +172,30 @@ public class TBExamInvigilateUserController {
     @Transactional
     @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0}", response = Result.class)})
     public Result export() {
-        return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
+        TBTaskHistory tbTaskHistory = null;
+        try {
+            int count = tbExamInvigilateUserService.count();
+            if (count > 0) {
+                Map transMap = new HashMap();
+                TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+                //往任务表里插一条数据
+                tbTaskHistory = new TBTaskHistory(TaskTypeEnum.export_invigilate_user.ordinal(), TaskTypeExecEnum.init.ordinal(), SystemConstant.EXPORT_INIT, 0d, tbUser.getId());
+                taskHistoryService.save(tbTaskHistory);
+                transMap.put("tbTaskHistory", tbTaskHistory);
+                transMap.put("createId", tbUser.getId());
+                transMap.put("orgId", tbUser.getOrgId());
+                //mq发送消息start
+                MqDto mqDto = new MqDto(dictionaryConfig.mqConfigDomain().getTaskTopic(), dictionaryConfig.mqConfigDomain().getTaskTopicRoomCodeExportTag(), transMap, MqEnum.TASK_LOG, String.valueOf(tbTaskHistory.getId()), tbUser.getName());
+                mqDtoService.assembleSendOneWayMsg(mqDto);
+                //mq发送消息end
+            } else {
+                return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.EXPORT_NO_DATA));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Map map = new HashMap();
+        map.put(SystemConstant.TASK_ID, tbTaskHistory.getId());
+        return ResultUtil.ok(map);
     }
 }

+ 1 - 1
themis-backend/src/main/java/com/qmth/themis/backend/api/TEExamStudentController.java

@@ -158,7 +158,7 @@ public class TEExamStudentController {
                 throw new BusinessException(ExceptionResultEnum.ATTACHMENT_ERROR);
             } else {
                 //往任务表里插一条数据
-                tbTaskHistory = new TBTaskHistory(TaskTypeEnum.import_exam_student.ordinal(), tbAttachment.getId(), TaskTypeExecEnum.init.ordinal(), "准备开始处理", 0d, tbAttachment.getName(), tbAttachment.getRemark(), tbUser.getId());
+                tbTaskHistory = new TBTaskHistory(TaskTypeEnum.import_exam_student.ordinal(), tbAttachment.getId(), TaskTypeExecEnum.init.ordinal(), SystemConstant.IMPORT_INIT, 0d, tbAttachment.getName(), tbAttachment.getRemark(), tbUser.getId());
                 taskHistoryService.save(tbTaskHistory);
                 transMap.put("tbTaskHistory", tbTaskHistory);
             }

+ 6 - 0
themis-backend/src/main/resources/application.properties

@@ -185,12 +185,18 @@ mq.config.userLogConsumerStudentGroup=${mq.config.userLogConsumerGroup}-${mq.con
 mq.config.taskTopic=${mq.config.server}-topic-task
 mq.config.taskConsumerGroup=${mq.config.server}-group-task
 
+#\u8003\u751F\u5BFC\u5165
 mq.config.taskTopicExamStudentImportTag=examStudentImport
 mq.config.taskConsumerExamStudentImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicExamStudentImportTag}
 
+#\u8003\u573A\u5BFC\u5165
 mq.config.taskTopicRoomCodeImportTag=roomCodeImport
 mq.config.taskConsumerRoomCodeImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeImportTag}
 
+#\u8003\u573A\u5BFC\u51FA
+mq.config.taskTopicRoomCodeExportTag=roomCodeExport
+mq.config.taskConsumerRoomCodeExportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeExportTag}
+
 #dlq\u6B7B\u4FE1\u961F\u5217
 #mq.config.sessionConsumerGroupDlq=${mq.config.sessionConsumerGroup}-dlq
 #mq.config.sessionTopicDlq=%DLQ%${mq.config.sessionConsumerGroup}

+ 18 - 0
themis-business/src/main/java/com/qmth/themis/business/annotation/ExcelNote.java

@@ -0,0 +1,18 @@
+package com.qmth.themis.business.annotation;
+
+import java.lang.annotation.*;
+
+/**
+* @Description: excel导出注释
+* @Param:
+* @return:
+* @Author: wangliang
+* @Date: 2020/7/20
+*/
+@Documented
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelNote {
+
+    String value() default "";
+}

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/constant/SpringContextHolder.java

@@ -18,7 +18,7 @@ public class SpringContextHolder implements ApplicationContextAware {
     /**
      * 上下文对象实例
      */
-    private static ApplicationContext applicationContext;
+    private volatile static ApplicationContext applicationContext;
 
     @Override
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -34,6 +34,9 @@ public class SystemConstant {
      * 系统相关
      */
     public static final String SUCCESS = "{'success':true}";
+    public static final String EXPORT_NO_DATA = "{'noData':'没有数据'}";
+    public static final String IMPORT_INIT = "准备开始处理导入数据";
+    public static final String EXPORT_INIT = "准备开始处理导出数据";
     public static final String RECORDS = "records";
     public static final String USER = "user:";
     public static final String SESSION = "session:";
@@ -60,6 +63,7 @@ public class SystemConstant {
     public static final String DEFAULT_PASSWORD = "yXVUkR45PFz0UfpbDB8/ew==";
     public static final String USER_DIR = "user.dir";
     public static final int MAX_IMPORT_SIZE = 500;
+    public static final int MAX_EXPORT_SIZE = 500;
     /**
      * session过期时间
      */

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TBExamInvigilateUserMapper.java

@@ -2,10 +2,12 @@ package com.qmth.themis.business.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.qmth.themis.business.dto.RoomCodeExportDto;
 import com.qmth.themis.business.entity.TBExamInvigilateUser;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -27,4 +29,11 @@ public interface TBExamInvigilateUserMapper extends BaseMapper<TBExamInvigilateU
      * @return
      */
     public IPage<Map> examInvigilateUserQuery(IPage<Map> iPage, @Param("roomCode") String roomCode, @Param("userId") Long userId);
+
+    /**
+     * 监考员导出
+     *
+     * @return
+     */
+    public List<RoomCodeExportDto> examInvigilateUserExport();
 }

+ 18 - 0
themis-business/src/main/java/com/qmth/themis/business/domain/MqConfigDomain.java

@@ -46,6 +46,24 @@ public class MqConfigDomain {
     private String taskConsumerExamStudentImportGroup;
     private String taskTopicRoomCodeImportTag;
     private String taskConsumerRoomCodeImportGroup;
+    private String taskTopicRoomCodeExportTag;
+    private String taskConsumerRoomCodeExportGroup;
+
+    public String getTaskTopicRoomCodeExportTag() {
+        return taskTopicRoomCodeExportTag;
+    }
+
+    public void setTaskTopicRoomCodeExportTag(String taskTopicRoomCodeExportTag) {
+        this.taskTopicRoomCodeExportTag = taskTopicRoomCodeExportTag;
+    }
+
+    public String getTaskConsumerRoomCodeExportGroup() {
+        return taskConsumerRoomCodeExportGroup;
+    }
+
+    public void setTaskConsumerRoomCodeExportGroup(String taskConsumerRoomCodeExportGroup) {
+        this.taskConsumerRoomCodeExportGroup = taskConsumerRoomCodeExportGroup;
+    }
 
     public String getTaskTopicExamStudentImportTag() {
         return taskTopicExamStudentImportTag;

+ 45 - 0
themis-business/src/main/java/com/qmth/themis/business/dto/RoomCodeExportDto.java

@@ -0,0 +1,45 @@
+package com.qmth.themis.business.dto;
+
+import com.qmth.themis.business.annotation.ExcelNotNull;
+import com.qmth.themis.business.annotation.ExcelNote;
+
+/**
+* @Description: 考场导出 dto
+* @Param:  
+* @return:  
+* @Author: wangliang
+* @Date: 2020/7/20 
+*/ 
+public class RoomCodeExportDto {
+
+    @ExcelNote(value = "考场代码")
+    private String roomCode; //考场代码
+    @ExcelNote(value = "考场名称")
+    private String roomName; //考场名称
+    @ExcelNote(value = "监考老师")
+    private String name;//监考老师
+
+    public String getRoomCode() {
+        return roomCode;
+    }
+
+    public void setRoomCode(String roomCode) {
+        this.roomCode = roomCode;
+    }
+
+    public String getRoomName() {
+        return roomName;
+    }
+
+    public void setRoomName(String roomName) {
+        this.roomName = roomName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 10 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TBTaskHistory.java

@@ -94,6 +94,16 @@ public class TBTaskHistory implements Serializable {
         this.startTime = new Date();
     }
 
+    public TBTaskHistory(Integer type, Integer status, String summary, Double progress, Long createId) {
+        this.id = Constants.idGen.next();
+        this.type = type;
+        this.status = status;
+        this.summary = summary;
+        this.progress = progress;
+        this.createId = createId;
+        this.startTime = new Date();
+    }
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }

+ 11 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TBAttachmentService.java

@@ -31,6 +31,17 @@ public interface TBAttachmentService extends IService<TBAttachment> {
      */
     TBAttachment saveAttachment(MultipartFile file, String md5, String path, Map<String, Object> map, Long orgId, Long userId) throws IOException;
 
+    /**
+     * 保存附件
+     *
+     * @param path
+     * @param map
+     * @param orgId
+     * @param userId
+     * @return
+     * @throws IOException
+     */
+    TBAttachment saveAttachment(String path, Map<String, Object> map, Long orgId, Long userId) throws IOException;
     /**
      * 删除附件
      *

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TBExamInvigilateUserService.java

@@ -2,8 +2,10 @@ package com.qmth.themis.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.dto.RoomCodeExportDto;
 import com.qmth.themis.business.entity.TBExamInvigilateUser;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -24,4 +26,11 @@ public interface TBExamInvigilateUserService extends IService<TBExamInvigilateUs
      * @return
      */
     public IPage<Map> examInvigilateUserQuery(IPage<Map> iPage, String roomCode, Long userId);
+
+    /**
+     * 监考员导出
+     *
+     * @return
+     */
+    public List<RoomCodeExportDto> examInvigilateUserExport();
 }

+ 11 - 6
themis-business/src/main/java/com/qmth/themis/business/service/impl/TBAttachmentServiceImpl.java

@@ -115,13 +115,13 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
                         .add(tbAttachment.getType());
                 ossUtil.ossUpload(map, stringJoiner.toString(), file.getInputStream());
             } else {//上传至服务器
-                File mkdir = new File(stringJoiner.toString());
-                if (!mkdir.exists()) {
-                    mkdir.mkdirs();
+                File finalFile = new File(stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
+                        .add(tbAttachment.getType()).toString());
+                if (!finalFile.exists()) {
+                    finalFile.getParentFile().mkdirs();
+                    finalFile.createNewFile();
                 }
-                stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
-                        .add(tbAttachment.getType());
-                FileUtils.copyInputStreamToFile(file.getInputStream(), new File(stringJoiner.toString()));
+                FileUtils.copyInputStreamToFile(file.getInputStream(), finalFile);
             }
             JSONObject jsonObject = new JSONObject();
             if (oss) {
@@ -146,6 +146,11 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
         return tbAttachment;
     }
 
+    @Override
+    public TBAttachment saveAttachment(String path, Map<String, Object> map, Long orgId, Long userId) throws IOException {
+        return null;
+    }
+
     /**
      * 删除附件
      *

+ 12 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TBExamInvigilateUserServiceImpl.java

@@ -3,11 +3,13 @@ package com.qmth.themis.business.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.dao.TBExamInvigilateUserMapper;
+import com.qmth.themis.business.dto.RoomCodeExportDto;
 import com.qmth.themis.business.entity.TBExamInvigilateUser;
 import com.qmth.themis.business.service.TBExamInvigilateUserService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -35,4 +37,14 @@ public class TBExamInvigilateUserServiceImpl extends ServiceImpl<TBExamInvigilat
     public IPage<Map> examInvigilateUserQuery(IPage<Map> iPage, String roomCode, Long userId) {
         return tbExamInvigilateUserMapper.examInvigilateUserQuery(iPage, roomCode, userId);
     }
+
+    /**
+     * 监考员导出
+     *
+     * @return
+     */
+    @Override
+    public List<RoomCodeExportDto> examInvigilateUserExport() {
+        return tbExamInvigilateUserMapper.examInvigilateUserExport();
+    }
 }

+ 227 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportCommon.java

@@ -0,0 +1,227 @@
+package com.qmth.themis.business.templete;
+
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.qmth.themis.business.config.EnvConfig;
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.TBTaskHistory;
+import com.qmth.themis.business.enums.TaskTypeExecEnum;
+import com.qmth.themis.business.enums.UploadFileEnum;
+import com.qmth.themis.business.service.TBAttachmentService;
+import com.qmth.themis.business.service.TBTaskHistoryService;
+import com.qmth.themis.business.util.OssUtil;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.*;
+
+/**
+ * @Description: 导出任务公用
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/19
+ */
+public class TaskExportCommon {
+    private Map<String, Object> map = null;
+    private Long orgId = null;
+    private Long createId = null;
+    private TBTaskHistoryService tbTaskHistoryService = null;
+    private OssUtil ossUtil = null;
+    private EnvConfig envConfig = null;
+    private Map<String, Object> ossEnv = null;
+    private TBTaskHistory tbTaskHistory = null;
+    private String timeFormat = null;
+    private boolean exception = false;
+    private TBAttachmentService tbAttachmentService = null;
+    private String type = null;
+
+    public TaskExportCommon() {
+
+    }
+
+    public TaskExportCommon(Map<String, Object> map) {
+        this.map = map;
+    }
+
+    /**
+     * 初始化
+     */
+    public void init() {
+        Gson gson = new Gson();
+        if (Objects.nonNull(this.map.get("orgId"))) {
+            this.orgId = Long.parseLong(String.valueOf(this.map.get("orgId")));
+        }
+        this.createId = Long.parseLong(String.valueOf(this.map.get("createId")));
+        this.ossUtil = SpringContextHolder.getBean(OssUtil.class);
+        this.envConfig = SpringContextHolder.getBean(EnvConfig.class);
+        this.ossEnv = this.envConfig.getOssEnv(UploadFileEnum.file.ordinal());
+        this.type = (boolean) this.ossEnv.get("oss") ? SystemConstant.OSS : SystemConstant.LOCAL;
+        Map tbTaskHistoryMap = (Map) this.map.get("tbTaskHistory");
+        tbTaskHistoryMap = SystemConstant.timeTransform(tbTaskHistoryMap);
+        this.tbTaskHistory = gson.fromJson(gson.toJson(tbTaskHistoryMap), TBTaskHistory.class);
+        this.tbTaskHistoryService = SpringContextHolder.getBean(TBTaskHistoryService.class);
+        this.tbAttachmentService = SpringContextHolder.getBean(TBAttachmentService.class);
+        this.timeFormat = "yyyy-MM-dd HH:mm:ss";
+    }
+
+    /**
+     * 创建excel
+     *
+     * @return
+     */
+    public File createExcel() throws IOException {
+        LocalDateTime nowTime = LocalDateTime.now();
+        StringJoiner stringJoiner = new StringJoiner("");
+        String uploadType = String.valueOf(this.ossEnv.get(SystemConstant.UPLOAD_TYPE));
+        stringJoiner.add(uploadType).add(File.separator).add(String.valueOf(nowTime.getYear()))
+                .add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
+                .add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
+        File file = new File(stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
+                .add(".xlsx").toString());
+        if (!file.exists()) {
+            file.getParentFile().mkdirs();
+            file.createNewFile();
+        }
+        return file;
+    }
+
+    /**
+     * 写入txt文件
+     *
+     * @param path
+     * @param txtStr
+     * @throws IOException
+     */
+    public void writeExportResultTxt(String path, String txtStr) throws IOException {
+        FileWriter fileWriter = null;
+        try {
+            path = path.substring(0, path.lastIndexOf(File.separator) + 1);
+            File file = new File(path + String.valueOf(UUID.randomUUID()).replaceAll("-", "") + ".txt");
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+                file.createNewFile();
+            }
+            fileWriter = new FileWriter(file);
+            fileWriter.write(txtStr);
+            JSONObject json = new JSONObject();
+            json.put("path", file.getPath());
+            json.put("type", this.type);
+            if (this.exception) {
+                this.tbTaskHistory.setErrorFilePath(json.toJSONString());
+            } else {
+                this.tbTaskHistory.setResultFilePath(json.toJSONString());
+            }
+            if (Objects.equals(this.type, SystemConstant.OSS)) {
+                this.ossUtil.ossUpload(this.ossEnv, file.getPath(), txtStr);
+                file.delete();
+            }
+            tbTaskHistoryService.updateById(this.tbTaskHistory);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (Objects.nonNull(fileWriter)) {
+                fileWriter.flush();
+                fileWriter.close();
+            }
+        }
+    }
+
+    /**
+     * 换算进度
+     *
+     * @param max
+     * @param min
+     * @param size
+     * @param txtList
+     * @return
+     */
+    public List<String> progress(int max, int min, int size, List<String> txtList) {
+        BigDecimal bigDecimal = new BigDecimal(100);
+        BigDecimal progress = new BigDecimal(Double.valueOf(new BigDecimal(max).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())).setScale(0, BigDecimal.ROUND_HALF_UP);
+        if (progress.intValue() == 100) {
+            this.tbTaskHistory.setStatus(TaskTypeExecEnum.finish.ordinal());
+            this.tbTaskHistory.setSummary("共导出了" + size + "条数据");
+            this.tbTaskHistory.setFinishTime(new Date());
+            txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->数据导出完毕," + this.tbTaskHistory.getSummary());
+        } else {
+            this.tbTaskHistory.setStatus(TaskTypeExecEnum.running.ordinal());
+            this.tbTaskHistory.setSummary("正在导出第" + min + "条至" + max + "条数据");
+            txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->数据导出中," + this.tbTaskHistory.getSummary());
+        }
+        this.tbTaskHistory.setProgress(progress.doubleValue());
+        this.tbTaskHistoryService.updateById(this.tbTaskHistory);
+        return txtList;
+    }
+
+    /**
+     * 异常处理
+     *
+     * @param min
+     * @param y
+     * @param e
+     * @param txtList
+     * @return
+     */
+    public List<String> exception(int min, int y, Exception e, List<String> txtList) {
+        this.exception = true;
+        String exceptionStr = "数据导出到第" + (min + y + 1) + "条时发生异常:" + e.getMessage();
+        txtList.add(DateUtil.format(new Date(), this.timeFormat) + "->" + exceptionStr);
+        this.tbTaskHistory.setSummary(exceptionStr);
+        this.tbTaskHistoryService.updateById(this.tbTaskHistory);
+        return txtList;
+    }
+
+    public void setException(boolean exception) {
+        this.exception = exception;
+    }
+
+    public boolean isException() {
+        return exception;
+    }
+
+    public String getTimeFormat() {
+        return timeFormat;
+    }
+
+    public Map<String, Object> getMap() {
+        return map;
+    }
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public Long getCreateId() {
+        return createId;
+    }
+
+    public TBTaskHistoryService getTbTaskHistoryService() {
+        return tbTaskHistoryService;
+    }
+
+    public OssUtil getOssUtil() {
+        return ossUtil;
+    }
+
+    public EnvConfig getEnvConfig() {
+        return envConfig;
+    }
+
+    public Map<String, Object> getOssEnv() {
+        return ossEnv;
+    }
+
+    public TBTaskHistory getTbTaskHistory() {
+        return tbTaskHistory;
+    }
+
+    public TBAttachmentService getTbAttachmentService() {
+        return tbAttachmentService;
+    }
+}

+ 10 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportTemplete.java

@@ -2,6 +2,9 @@ package com.qmth.themis.business.templete;
 
 import com.qmth.themis.common.util.Result;
 
+import java.io.IOException;
+import java.util.Map;
+
 /**
  * @Description: 导出任务模版
  * @Param:
@@ -11,5 +14,11 @@ import com.qmth.themis.common.util.Result;
  */
 public interface TaskExportTemplete {
 
-    Result exportTask();
+    /**
+     * 导出任务
+     *
+     * @param map
+     * @return
+     */
+    Result exportTask(Map<String, Object> map) throws IOException;
 }

+ 6 - 2
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -18,7 +18,7 @@ import java.math.BigDecimal;
 import java.util.*;
 
 /**
- * @Description: 任务公用
+ * @Description: 导入任务公用
  * @Param:
  * @return:
  * @Author: wangliang
@@ -41,6 +41,10 @@ public class TaskImportCommon {
     private String timeFormat = null;
     private boolean exception = false;
 
+    public TaskImportCommon() {
+
+    }
+
     public TaskImportCommon(Map<String, Object> map) {
         this.map = map;
     }
@@ -105,7 +109,7 @@ public class TaskImportCommon {
         FileWriter fileWriter = null;
         try {
             this.path = this.path.substring(0, this.path.lastIndexOf(File.separator) + 1);
-            File file = new File(this.path + this.tbTaskHistory.getId() + ".txt");
+            File file = new File(this.path + String.valueOf(UUID.randomUUID()).replaceAll("-", "") + ".txt");
             if (!file.exists()) {
                 file.createNewFile();
             }

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -116,13 +116,14 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
                     LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
                     List<Object> examStudentImportDtoList = finalMap.get(i);
                     min = 0;
+                    y = 0;
                     int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentImportDtoList.size();
                     if (max >= size) {
                         max = size;
                     }
                     while (max <= size) {
                         List subList = examStudentImportDtoList.subList(min, max);
-                        for (y = 0; y < subList.size(); y++) {
+                        for (; y < subList.size(); y++) {
                             ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) subList.get(y);
                             Map m = (Map) teExamActivityMap.get(examStudentImportDto.getExamActivityCode());
                             m = SystemConstant.timeTransform(m);

+ 149 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeExportTemplete.java

@@ -0,0 +1,149 @@
+package com.qmth.themis.business.templete.impl;
+
+import cn.hutool.core.date.DateUtil;
+import com.qmth.themis.business.annotation.ExcelNote;
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.dto.RoomCodeExportDto;
+import com.qmth.themis.business.service.TBExamInvigilateUserService;
+import com.qmth.themis.business.templete.TaskExportCommon;
+import com.qmth.themis.business.templete.TaskExportTemplete;
+import com.qmth.themis.business.util.JacksonUtil;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.*;
+
+/**
+ * @Description: 考场导出任务
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/20
+ */
+public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
+    private final static Logger log = LoggerFactory.getLogger(TaskRoomCodeExportTemplete.class);
+
+    /**
+     * 考场导出模版
+     *
+     * @param map
+     * @return
+     */
+    @Override
+    @Transactional
+    public Result exportTask(Map<String, Object> map) throws IOException {
+        log.info("开始导出考场数据");
+        long start = System.currentTimeMillis();
+        TaskExportCommon taskExportCommon = new TaskExportCommon(map);
+        taskExportCommon.init();
+        String timeFormat = taskExportCommon.getTimeFormat();
+        List<String> txtList = new ArrayList();
+        FileOutputStream fos = null;
+        SXSSFWorkbook wb = null;
+        boolean oss = (boolean) taskExportCommon.getOssEnv().get(SystemConstant.OSS);
+        File file = null;
+        int y = 0, min = 0;
+        try {
+            txtList.add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导出的考场数据");
+            TBExamInvigilateUserService tbExamInvigilateUserService = SpringContextHolder.getBean(TBExamInvigilateUserService.class);
+            List<RoomCodeExportDto> roomCodeExportDtoList = tbExamInvigilateUserService.examInvigilateUserExport();
+
+            //创建excel
+            wb = new SXSSFWorkbook();
+            Sheet sheet = wb.createSheet("考场导出");
+            CellStyle style = wb.createCellStyle();
+            style.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
+            style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
+            Row row = sheet.createRow(0);
+            Field[] fields = RoomCodeExportDto.class.getDeclaredFields();
+            //绘制表头
+            for (int i = 0; i < fields.length; i++) {
+                Field field = fields[i];
+                field.setAccessible(true);
+                Cell cell = row.createCell(i);
+                cell.setCellValue(field.getAnnotation(ExcelNote.class).value());
+                cell.setCellStyle(style);
+//                sheet.setColumnWidth(i, 15 * 256);
+            }
+            int cellIndex = 0, max = SystemConstant.MAX_EXPORT_SIZE, size = roomCodeExportDtoList.size();
+            if (max >= size) {
+                max = size;
+            }
+            while (max <= size) {
+                List subList = roomCodeExportDtoList.subList(min, max);
+                //绘制数据
+                for (; y < subList.size(); y++) {
+                    RoomCodeExportDto roomCodeExportDto = roomCodeExportDtoList.get(y);
+                    int firstRow = y + 1;
+                    cellIndex = 0;
+                    Row hssfRow = sheet.createRow(firstRow);
+
+                    Cell cell = hssfRow.createCell(cellIndex);
+                    cell.setCellValue(roomCodeExportDto.getRoomCode());
+                    cell.setCellStyle(style);
+                    cellIndex++;
+
+                    cell = hssfRow.createCell(cellIndex);
+                    cell.setCellValue(roomCodeExportDto.getRoomName());
+                    cell.setCellStyle(style);
+                    cellIndex++;
+
+                    cell = hssfRow.createCell(cellIndex);
+                    cell.setCellValue(roomCodeExportDto.getName());
+                    cell.setCellStyle(style);
+                    cellIndex++;
+                }
+                txtList = taskExportCommon.progress(max, min, size, txtList);
+                if (max == size) {
+                    break;
+                }
+                min = max;
+                max += SystemConstant.MAX_EXPORT_SIZE;
+                if (max >= size) {
+                    max = size;
+                }
+            }
+            file = taskExportCommon.createExcel();
+            //写入excel并上传附件
+            fos = new FileOutputStream(file);
+            wb.write(fos);
+            if (oss) {//上传至oss
+                taskExportCommon.getOssUtil().ossUpload(taskExportCommon.getOssEnv(), file.getPath(), new FileInputStream(file));
+                file.delete();
+            }
+            long end = System.currentTimeMillis();
+            log.info("导出考场数据结束,============耗时============:{}秒", (end - start) / 1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+            txtList = taskExportCommon.exception(min, y, e, txtList);
+            if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        } finally {
+            if (Objects.nonNull(wb)) {
+                wb.dispose();
+            }
+            if (Objects.nonNull(fos)) {
+                fos.flush();
+                fos.close();
+            }
+            //这里写入txt文件
+            taskExportCommon.writeExportResultTxt(file.getPath(), txtList.toString());
+        }
+        return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
+    }
+}

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java

@@ -109,13 +109,14 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
                     LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
                     List<Object> examStudentDtoImportList = finalMap.get(i);
                     min = 0;
+                    y = 0;
                     int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentDtoImportList.size();
                     if (max >= size) {
                         max = size;
                     }
                     while (max <= size) {
                         List subList = examStudentDtoImportList.subList(min, max);
-                        for (y = 0; y < subList.size(); y++) {
+                        for (; y < subList.size(); y++) {
                             RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) subList.get(y);
                             dataVerify(roomCodeImportDto.getTeacher1(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), taskImportCommon.getOrgId(), taskImportCommon.getCreateId());
                             dataVerify(roomCodeImportDto.getTeacher2(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), taskImportCommon.getOrgId(), taskImportCommon.getCreateId());

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/util/EhcacheUtil.java

@@ -24,7 +24,7 @@ public class EhcacheUtil {
 
     private URL url;
     private static CacheManager manager;
-    private static EhcacheUtil ehCache;
+    private volatile static EhcacheUtil ehCache;
 
     private EhcacheUtil(String path) {
         url = getClass().getResource(path);

+ 1 - 3
themis-business/src/main/java/com/qmth/themis/business/util/JacksonUtil.java

@@ -1,10 +1,8 @@
 package com.qmth.themis.business.util;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.qmth.themis.business.entity.TBUser;
 
 import java.util.List;
 import java.util.Objects;
@@ -18,7 +16,7 @@ import java.util.Set;
  * @Date: 2020/7/6
  */
 public class JacksonUtil {
-    private static ObjectMapper objectMapper = null;
+    private volatile static ObjectMapper objectMapper = null;
 
     static {
         getInstance();

+ 42 - 25
themis-business/src/main/resources/mapper/TBExamInvigilateUserMapper.xml

@@ -2,34 +2,51 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.themis.business.dao.TBExamInvigilateUserMapper">
 
+    <sql id="queryCommon">
+        (
+        select
+        tbeiu.room_code as roomCode, tbeiu.room_name as roomName, tbeiu.user_id as userId, (
+        select
+        tbu.name
+        from
+        t_b_user tbu
+        where
+        tbu.id = tbeiu.user_id) as name
+        from
+        t_b_exam_invigilate_user tbeiu
+        <where>
+            <if test="userId != null and userId != ''">
+                and tbeiu.user_id = #{userId}
+            </if>
+            <if test="roomCode != null and roomCode != ''">
+                and tbeiu.room_code like concat('%', #{roomCode}, '%')
+            </if>
+        </where>
+        ) t
+    </sql>
+
     <select id="examInvigilateUserQuery" resultType="java.util.Map">
         select
-            t.roomCode,
-            t.roomName,
-            GROUP_CONCAT(t.userId) as userId,
-            GROUP_CONCAT(t.name) as name
+        t.roomCode,
+        t.roomName,
+        GROUP_CONCAT(t.userId) as userId,
+        GROUP_CONCAT(t.name) as name
+        from
+        <include refid="queryCommon"/>
+        group by
+        t.roomCode,
+        t.roomName
+    </select>
+
+    <select id="examInvigilateUserExport" resultType="com.qmth.themis.business.dto.RoomCodeExportDto">
+        select
+        t.roomCode,
+        t.roomName,
+        GROUP_CONCAT(t.name) as name
         from
-            (
-            select
-                tbeiu.room_code as roomCode, tbeiu.room_name as roomName, tbeiu.user_id as userId, (
-                select
-                    tbu.name
-                from
-                    t_b_user tbu
-                where
-                    tbu.id = tbeiu.user_id) as name
-            from
-                t_b_exam_invigilate_user tbeiu
-            <where>
-                <if test="userId != null and userId != ''">
-                    and tbeiu.user_id = #{userId}
-                </if>
-                <if test="roomCode != null and roomCode != ''">
-                    and tbeiu.room_code like concat('%', #{roomCode}, '%')
-                </if>
-            </where>) t
+        <include refid="queryCommon"/>
         group by
-            t.roomCode,
-            t.roomName
+        t.roomCode,
+        t.roomName
     </select>
 </mapper>

+ 1 - 1
themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketSessionConsumer.java

@@ -73,7 +73,7 @@ public class RocketSessionConsumer implements
                 log.info(":{}-:{} sessionConsumer 重试次数:{}", threadId, threadName, messageExt.getReconsumeTimes());
                 mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
                 log.info(":{}-:{} sessionConsumer 接收到的消息:{}", threadId, threadName, JacksonUtil.parseJson(mqDto));
-                log.info(":{}-:{} sessionConsumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
+//                log.info(":{}-:{} sessionConsumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
                 if (Objects.nonNull(mqDto.getAck()) && mqDto.getAck().intValue() != SystemConstant.STANDARD_ACK_TYPE && Objects.nonNull(redisUtil.getMqTopicList(SystemConstant.SESSION_TOPIC_BUFFER_LIST, mqDto.getId())) && redisUtil.lock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId(), SystemConstant.REDIS_LOCK_MQ_TIME_OUT, TimeUnit.SECONDS)) {
                     log.info(":{}-:{} 更新db", threadId, threadName);
                     tbSessionService.saveSessionInfo(JacksonUtil.readJson(JacksonUtil.parseJson(mqDto.getBody()), TBSession.class), mqDto.getTimestamp());

+ 132 - 48
themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketTaskConsumer.java

@@ -4,8 +4,10 @@ import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TMRocketMessage;
 import com.qmth.themis.business.service.TMRocketMessageService;
+import com.qmth.themis.business.templete.TaskExportTemplete;
 import com.qmth.themis.business.templete.TaskImportTemplete;
 import com.qmth.themis.business.templete.impl.TaskExamStudentImportTemplete;
+import com.qmth.themis.business.templete.impl.TaskRoomCodeExportTemplete;
 import com.qmth.themis.business.templete.impl.TaskRoomCodeImportTemplete;
 import com.qmth.themis.business.threadPool.MyThreadPool;
 import com.qmth.themis.business.util.JacksonUtil;
@@ -42,7 +44,7 @@ import java.util.concurrent.TimeUnit;
  * @Date: 2020/7/2
  */
 @Service
-public class RocketTaskConsumer implements MessageListenerConcurrently {
+public class RocketTaskConsumer {
     private final static Logger log = LoggerFactory.getLogger(RocketTaskConsumer.class);
 
     @Resource
@@ -54,54 +56,61 @@ public class RocketTaskConsumer implements MessageListenerConcurrently {
     @Resource
     MyThreadPool myThreadPool;
 
-    @Override
-    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
-        MqDto mqDto = null;
-        try {
-            long threadId = Thread.currentThread().getId();
-            String threadName = Thread.currentThread().getName();
-            Gson gson = new Gson();
-            for (MessageExt messageExt : msgs) {
-                log.info(":{}-:{} task ExamStudentImport Consumer重试次数:{}", threadId, threadName, messageExt.getReconsumeTimes());
-                mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
-                log.info(":{}-:{} task ExamStudentImport Consumer接收到的消息:{}", threadId, threadName, JacksonUtil.parseJson(mqDto));
-                log.info(":{}-:{} task ExamStudentImport Consumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
-                if (Objects.nonNull(mqDto.getAck()) && mqDto.getAck().intValue() != SystemConstant.STANDARD_ACK_TYPE && Objects.nonNull(redisUtil.getMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId())) && redisUtil.lock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId(), SystemConstant.REDIS_LOCK_MQ_TIME_OUT, TimeUnit.SECONDS)) {
-                    Map<String, Object> map = (Map<String, Object>) mqDto.getBody();
-                    String tag = mqDto.getTag();
-                    myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
-                        TaskImportTemplete taskImportTemplete = null;
-                        if (tag.contains("examStudentImport")) {
-                            taskImportTemplete = new TaskExamStudentImportTemplete();
-                        } else if (tag.contains("roomCodeImport")) {
-                            taskImportTemplete = new TaskRoomCodeImportTemplete();
-                        }
-                        try {
-                            taskImportTemplete.importTask(map);
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                        }
-                    });
-                    mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
-                    mqDto.setBody(JacksonUtil.parseJson(mqDto.getBody()));
-                    TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
-                    tmRocketMessageService.saveOrUpdate(tmRocketMessage);
-                    redisUtil.deleteMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId());
-                    return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
-                } else {
-                    log.info(":{}-:{} 消息ack未确认,重发", threadId, threadName);
-                    return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
+    /**
+     * 导入任务监听
+     */
+    @Service
+    public class ImportTask implements MessageListenerConcurrently {
+
+        @Override
+        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
+            MqDto mqDto = null;
+            try {
+                long threadId = Thread.currentThread().getId();
+                String threadName = Thread.currentThread().getName();
+                Gson gson = new Gson();
+                for (MessageExt messageExt : msgs) {
+                    log.info(":{}-:{} task import Consumer重试次数:{}", threadId, threadName, messageExt.getReconsumeTimes());
+                    mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
+                    log.info(":{}-:{} task import Consumer接收到的消息:{}", threadId, threadName, JacksonUtil.parseJson(mqDto));
+//                    log.info(":{}-:{} task import Consumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
+                    if (Objects.nonNull(mqDto.getAck()) && mqDto.getAck().intValue() != SystemConstant.STANDARD_ACK_TYPE && Objects.nonNull(redisUtil.getMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId())) && redisUtil.lock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId(), SystemConstant.REDIS_LOCK_MQ_TIME_OUT, TimeUnit.SECONDS)) {
+                        Map<String, Object> map = (Map<String, Object>) mqDto.getBody();
+                        String tag = mqDto.getTag();
+                        myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
+                            TaskImportTemplete taskImportTemplete = null;
+                            if (tag.contains("examStudentImport")) {
+                                taskImportTemplete = new TaskExamStudentImportTemplete();
+                            } else if (tag.contains("roomCodeImport")) {
+                                taskImportTemplete = new TaskRoomCodeImportTemplete();
+                            }
+                            try {
+                                taskImportTemplete.importTask(map);
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
+                        });
+                        mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
+                        mqDto.setBody(JacksonUtil.parseJson(mqDto.getBody()));
+                        TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
+                        tmRocketMessageService.saveOrUpdate(tmRocketMessage);
+                        redisUtil.deleteMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId());
+                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
+                    } else {
+                        log.info(":{}-:{} 消息ack未确认,重发", threadId, threadName);
+                        return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
+            } finally {
+                if (Objects.nonNull(mqDto)) {
+                    redisUtil.releaseLock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId());
                 }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
-            return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
-        } finally {
-            if (Objects.nonNull(mqDto)) {
-                redisUtil.releaseLock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId());
-            }
+            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//成功
         }
-        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//成功
     }
 
     /**
@@ -121,7 +130,7 @@ public class RocketTaskConsumer implements MessageListenerConcurrently {
             defaultMQPushConsumer.setConsumeMessageBatchMaxSize(SystemConstant.CONSUME_MESSAGE_BATCH_MAX_SIZE);//每次拉取10条
             defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
             defaultMQPushConsumer.setMaxReconsumeTimes(SystemConstant.MAXRECONSUMETIMES);//最大重试次数
-            defaultMQPushConsumer.registerMessageListener(RocketTaskConsumer.this::consumeMessage);
+            defaultMQPushConsumer.registerMessageListener(new ImportTask()::consumeMessage);
         }
     }
 
@@ -142,7 +151,82 @@ public class RocketTaskConsumer implements MessageListenerConcurrently {
             defaultMQPushConsumer.setConsumeMessageBatchMaxSize(SystemConstant.CONSUME_MESSAGE_BATCH_MAX_SIZE);//每次拉取10条
             defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
             defaultMQPushConsumer.setMaxReconsumeTimes(SystemConstant.MAXRECONSUMETIMES);//最大重试次数
-            defaultMQPushConsumer.registerMessageListener(RocketTaskConsumer.this::consumeMessage);
+            defaultMQPushConsumer.registerMessageListener(new ImportTask()::consumeMessage);
+        }
+    }
+
+    /**
+     * 导出任务
+     */
+    public class exportTask implements MessageListenerConcurrently {
+
+        @Override
+        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
+            MqDto mqDto = null;
+            try {
+                long threadId = Thread.currentThread().getId();
+                String threadName = Thread.currentThread().getName();
+                Gson gson = new Gson();
+                for (MessageExt messageExt : msgs) {
+                    log.info(":{}-:{} task export Consumer重试次数:{}", threadId, threadName, messageExt.getReconsumeTimes());
+                    mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
+                    log.info(":{}-:{} task export Consumer接收到的消息:{}", threadId, threadName, JacksonUtil.parseJson(mqDto));
+//                    log.info(":{}-:{} task ExamStudentImport Consumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
+                    if (Objects.nonNull(mqDto.getAck()) && mqDto.getAck().intValue() != SystemConstant.STANDARD_ACK_TYPE && Objects.nonNull(redisUtil.getMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId())) && redisUtil.lock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId(), SystemConstant.REDIS_LOCK_MQ_TIME_OUT, TimeUnit.SECONDS)) {
+                        Map<String, Object> map = (Map<String, Object>) mqDto.getBody();
+                        String tag = mqDto.getTag();
+                        myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
+                            TaskExportTemplete taskExportTemplete = null;
+                            if (tag.contains("roomCodeExport")) {
+                                taskExportTemplete = new TaskRoomCodeExportTemplete();
+                            }
+                            try {
+                                taskExportTemplete.exportTask(map);
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
+                        });
+                        mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
+                        mqDto.setBody(JacksonUtil.parseJson(mqDto.getBody()));
+                        TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
+                        tmRocketMessageService.saveOrUpdate(tmRocketMessage);
+                        redisUtil.deleteMqTopicList(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST, mqDto.getId());
+                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
+                    } else {
+                        log.info(":{}-:{} 消息ack未确认,重发", threadId, threadName);
+                        return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
+            } finally {
+                if (Objects.nonNull(mqDto)) {
+                    redisUtil.releaseLock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId());
+                }
+            }
+            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//成功
+        }
+    }
+
+    /**
+     * 考场导出
+     */
+    @Service
+    @RocketMQMessageListener(consumerGroup = "${mq.config.taskConsumerRoomCodeExportGroup}", topic = "${mq.config.taskTopic}", selectorType = SelectorType.TAG, selectorExpression = "${mq.config.taskTopicRoomCodeExportTag}")
+    public class taskConsumerRoomCodeExport implements RocketMQListener<Message>, RocketMQPushConsumerLifecycleListener {
+
+        @Override
+        public void onMessage(Message message) {
+            //实现RocketMQPushConsumerLifecycleListener监听器之后,此方法不调用
+        }
+
+        @Override
+        public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
+            defaultMQPushConsumer.setConsumeMessageBatchMaxSize(SystemConstant.CONSUME_MESSAGE_BATCH_MAX_SIZE);//每次拉取10条
+            defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
+            defaultMQPushConsumer.setMaxReconsumeTimes(SystemConstant.MAXRECONSUMETIMES);//最大重试次数
+            defaultMQPushConsumer.registerMessageListener(new exportTask()::consumeMessage);
         }
     }
 }

+ 1 - 1
themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketUserLogConsumer.java

@@ -65,7 +65,7 @@ public class RocketUserLogConsumer implements MessageListenerConcurrently {
 //                MqDto mqDto = (MqDto) toJavaObject(parseObject(new String(messageExt.getBody(), Constants.CHARSET)), MqDto.class);
                 mqDto = JacksonUtil.readJson(new String(messageExt.getBody(), Constants.CHARSET), MqDto.class);
                 log.info(":{}-:{} userLogConsumer接收到的消息:{}", threadId, threadName, JacksonUtil.parseJson(mqDto));
-                log.info(":{}-:{} userLogConsumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
+//                log.info(":{}-:{} userLogConsumer mqDto sequence:{},tag:{}", threadId, threadName, mqDto.getSequence(), mqDto.getTag());
                 if (Objects.nonNull(mqDto.getAck()) && mqDto.getAck().intValue() != SystemConstant.STANDARD_ACK_TYPE && Objects.nonNull(redisUtil.getMqTopicList(SystemConstant.USERLOG_TOPIC_BUFFER_LIST, mqDto.getId())) && redisUtil.lock(SystemConstant.REDIS_LOCK_MQ_PREFIX, mqDto.getId(), SystemConstant.REDIS_LOCK_MQ_TIME_OUT, TimeUnit.SECONDS)) {
                     log.info(":{}-:{} 插入用户轨迹日志", threadId, threadName);
                     teUserLogService.saveUserLogInfo(mqDto.getTimestamp(), mqDto.getObjId(), MqEnum.valueOf(String.valueOf(mqDto.getType())).getId(), SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(), JacksonUtil.parseJson(mqDto));

+ 11 - 15
themis-task/src/main/java/com/qmth/themis/task/quartz/MqJob.java

@@ -31,25 +31,21 @@ public class MqJob extends QuartzJobBean {
     @Resource
     ProducerServer producerServer;
 
-    @Resource
-    MyThreadPool myThreadPool;
-
     @Override
     protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
-        myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
-            log.info("session_topic_job进来了");
-            this.assembleJob(SystemConstant.SESSION_TOPIC_BUFFER_LIST);
-        });
-        myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
-            log.info("userLog_topic_job进来了");
-            this.assembleJob(SystemConstant.USERLOG_TOPIC_BUFFER_LIST);
-        });
-        myThreadPool.arbitratePoolTaskExecutor.execute(() -> {
-            log.info("task_topic_job进来了");
-            this.assembleJob(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST);
-        });
+        log.info("session_topic_job进来了");
+        this.assembleJob(SystemConstant.SESSION_TOPIC_BUFFER_LIST);
+        log.info("userLog_topic_job进来了");
+        this.assembleJob(SystemConstant.USERLOG_TOPIC_BUFFER_LIST);
+        log.info("task_topic_job进来了");
+        this.assembleJob(SystemConstant.TASKLOG_TOPIC_BUFFER_LIST);
     }
 
+    /**
+     * 组装job
+     *
+     * @param redisKey
+     */
     public void assembleJob(String redisKey) {
         Long size = redisUtil.getHashSize(redisKey);
         if (Objects.nonNull(size) && size.longValue() > 0) {

+ 7 - 1
themis-task/src/main/resources/application.properties

@@ -203,8 +203,14 @@ mq.config.userLogConsumerStudentGroup=${mq.config.userLogConsumerGroup}-${mq.con
 mq.config.taskTopic=${mq.config.server}-topic-task
 mq.config.taskConsumerGroup=${mq.config.server}-group-task
 
+#\u8003\u751F\u5BFC\u5165
 mq.config.taskTopicExamStudentImportTag=examStudentImport
 mq.config.taskConsumerExamStudentImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicExamStudentImportTag}
 
+#\u8003\u573A\u5BFC\u5165
 mq.config.taskTopicRoomCodeImportTag=roomCodeImport
-mq.config.taskConsumerRoomCodeImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeImportTag}
+mq.config.taskConsumerRoomCodeImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeImportTag}
+
+#\u8003\u573A\u5BFC\u51FA
+mq.config.taskTopicRoomCodeExportTag=roomCodeExport
+mq.config.taskConsumerRoomCodeExportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeExportTag}