Browse Source

增加读取配置文件

wangliang 4 năm trước cách đây
mục cha
commit
31c3d0c65b

+ 5 - 2
themis-backend/src/main/java/com/qmth/themis/backend/api/SysController.java

@@ -3,8 +3,8 @@ package com.qmth.themis.backend.api;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.backend.constant.BackendConstant;
 import com.qmth.themis.backend.util.ServletUtil;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TBAttachment;
 import com.qmth.themis.business.entity.TBPrivilege;
@@ -59,6 +59,9 @@ public class SysController {
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    SystemConfig systemConfig;
+
     @ApiOperation(value = "菜单查询接口")
     @RequestMapping(value = "/getMenu", method = RequestMethod.GET)
     @ApiResponses({@ApiResponse(code = 200, message = "菜单信息", response = TBPrivilege.class)})
@@ -102,7 +105,7 @@ public class SysController {
         if (Objects.isNull(file) || Objects.equals(file, "")) {
             throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
         }
-        Map<String, Object> mapParameter = BackendConstant.getAttachmentEnv(type);
+        Map<String, Object> mapParameter = systemConfig.getOssEnv(type);
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         TBAttachment tbAttachment = tbAttachmentService.saveAttachment(file, ServletUtil.getRequestMd5(), ServletUtil.getRequestPath(), mapParameter, tbUser.getOrgId(), tbUser.getId());
         if (Objects.isNull(tbAttachment)) {

+ 5 - 2
themis-backend/src/main/java/com/qmth/themis/backend/api/TBExamInvigilateUserController.java

@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.backend.constant.BackendConstant;
 import com.qmth.themis.backend.util.ServletUtil;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.FieldUniqueEnum;
@@ -59,6 +59,9 @@ public class TBExamInvigilateUserController {
     @Resource
     TBAttachmentService tbAttachmentService;
 
+    @Resource
+    SystemConfig systemConfig;
+
     @ApiOperation(value = "监考员查询接口")
     @RequestMapping(value = "/query", method = RequestMethod.GET)
     @ApiResponses({@ApiResponse(code = 200, message = "监考员信息", response = TEExamStudent.class)})
@@ -129,7 +132,7 @@ public class TBExamInvigilateUserController {
         if (Objects.isNull(file) || Objects.equals(file, "")) {
             throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
         }
-        Map<String, Object> mapParameter = BackendConstant.getAttachmentEnv(type);
+        Map<String, Object> mapParameter = systemConfig.getOssEnv(type);
         TBAttachment tbAttachment = null;
         TBTaskHistory tbTaskHistory = null;
         Map transMap = new HashMap();

+ 29 - 41
themis-backend/src/main/java/com/qmth/themis/backend/api/TEExamPaperController.java

@@ -1,31 +1,11 @@
 package com.qmth.themis.backend.api;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import javax.annotation.Resource;
-
-import org.springframework.dao.DuplicateKeyException;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.backend.constant.BackendConstant;
 import com.qmth.themis.backend.util.ServletUtil;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.entity.TBAttachment;
-import com.qmth.themis.business.entity.TBTaskHistory;
-import com.qmth.themis.business.entity.TBUser;
-import com.qmth.themis.business.entity.TEExam;
-import com.qmth.themis.business.entity.TEExamPaper;
+import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.FieldUniqueEnum;
 import com.qmth.themis.business.enums.MqEnum;
 import com.qmth.themis.business.enums.TaskTypeEnum;
@@ -42,12 +22,17 @@ import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.mq.dto.MqDto;
 import com.qmth.themis.mq.service.MqDtoService;
+import io.swagger.annotations.*;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * @Description: 考试试卷 前端控制器
@@ -63,22 +48,25 @@ public class TEExamPaperController {
 
     @Resource
     TEExamPaperService teExamPaperService;
-    
+
     @Resource
     TBTaskHistoryService taskHistoryService;
-    
+
     @Resource
     TEExamService teExamService;
-    
+
     @Resource
     TBAttachmentService tbAttachmentService;
-    
+
     @Resource
     MqDtoService mqDtoService;
 
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    SystemConfig systemConfig;
+
     @ApiOperation(value = "考试试卷查询接口")
     @RequestMapping(value = "/query", method = RequestMethod.GET)
     @ApiResponses({@ApiResponse(code = 200, message = "考试科目信息", response = TEExamPaper.class)})
@@ -92,7 +80,7 @@ public class TEExamPaperController {
         QueryWrapper<TEExamPaper> teExamPaperQueryWrapper = new QueryWrapper<>();
         teExamPaperQueryWrapper.lambda().eq(TEExamPaper::getExamId, examId).eq(TEExamPaper::getCourseCode, courseCode);
         List<TEExamPaper> teExamPaperList = teExamPaperService.list(teExamPaperQueryWrapper);
-        Map<String,List<TEExamPaper>> map = new HashMap<String,List<TEExamPaper>>();
+        Map<String, List<TEExamPaper>> map = new HashMap<String, List<TEExamPaper>>();
         map.put(SystemConstant.RECORDS, teExamPaperList);
         return ResultUtil.ok(map);
     }
@@ -136,20 +124,20 @@ public class TEExamPaperController {
     @Transactional
     @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0}", response = Result.class)})
     public Result importData(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file
-    		, @ApiParam(value = "批次ID", required = true) @RequestParam Long examId
-    		, @ApiParam(value = "客观题乱序", required = false) @RequestParam Boolean objectiveShuffle
-    		, @ApiParam(value = "选项乱序", required = false) @RequestParam Boolean optionShuffle
-    		, @ApiParam(value = "音频播放次数", required = false) @RequestParam Integer audioPlayTime) {
-    	if (file==null) {
+            , @ApiParam(value = "批次ID", required = true) @RequestParam Long examId
+            , @ApiParam(value = "客观题乱序", required = false) @RequestParam Boolean objectiveShuffle
+            , @ApiParam(value = "选项乱序", required = false) @RequestParam Boolean optionShuffle
+            , @ApiParam(value = "音频播放次数", required = false) @RequestParam Integer audioPlayTime) {
+        if (file == null) {
             throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
         }
-        if (examId==null) {
+        if (examId == null) {
             throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
         }
-        Map<String, Object> mapParameter = BackendConstant.getAttachmentEnv(3);
+        Map<String, Object> mapParameter = systemConfig.getOssEnv(3);
         TBAttachment tbAttachment = null;
         TBTaskHistory tbTaskHistory = null;
-        Map<String,Object> transMap = new HashMap<String,Object>();
+        Map<String, Object> transMap = new HashMap<String, Object>();
         try {
             TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
             tbAttachment = tbAttachmentService.saveAttachment(file, ServletUtil.getRequestMd5(), ServletUtil.getRequestPath(), mapParameter, tbUser.getOrgId(), tbUser.getId());
@@ -186,7 +174,7 @@ public class TEExamPaperController {
                 throw new RuntimeException(e);
             }
         }
-        Map<String,Long> map = new HashMap<String,Long>();
+        Map<String, Long> map = new HashMap<String, Long>();
         map.put(SystemConstant.TASK_ID, tbTaskHistory.getId());
         return ResultUtil.ok(map);
     }

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

@@ -4,17 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.backend.constant.BackendConstant;
 import com.qmth.themis.backend.util.ServletUtil;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.MqEnum;
 import com.qmth.themis.business.enums.TaskTypeEnum;
 import com.qmth.themis.business.enums.TaskTypeExecEnum;
 import com.qmth.themis.business.service.*;
-import com.qmth.themis.business.threadPool.MyThreadPool;
 import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
@@ -72,6 +71,9 @@ public class TEExamStudentController {
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    SystemConfig systemConfig;
+
     @ApiOperation(value = "考生查询接口")
     @RequestMapping(value = "/query", method = RequestMethod.GET)
     @ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TEExamStudent.class)})
@@ -147,7 +149,7 @@ public class TEExamStudentController {
         if (Objects.isNull(examId) || Objects.equals(examId, "")) {
             throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
         }
-        Map<String, Object> mapParameter = BackendConstant.getAttachmentEnv(type);
+        Map<String, Object> mapParameter = systemConfig.getOssEnv(type);
         TBAttachment tbAttachment = null;
         TBTaskHistory tbTaskHistory = null;
         Map transMap = new HashMap();

+ 0 - 50
themis-backend/src/main/java/com/qmth/themis/backend/constant/BackendConstant.java

@@ -1,50 +0,0 @@
-package com.qmth.themis.backend.constant;
-
-import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.business.constant.SpringContextHolder;
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.enums.UploadFileEnum;
-import com.qmth.themis.common.enums.ExceptionResultEnum;
-import com.qmth.themis.common.exception.BusinessException;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * @Description: 后台系统常量
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2020/7/15
- */
-public class BackendConstant {
-
-    /**
-     * 获取系统上传环境
-     *
-     * @param type
-     * @return
-     */
-    public static Map<String, Object> getAttachmentEnv(Integer type) {
-        if (Objects.isNull(type) || Objects.equals(type, "")) {
-            throw new BusinessException(ExceptionResultEnum.ATTACHMENT_TYPE_IS_NULL);
-        }
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        Map<String, Object> mapParameter = new HashMap<>();
-        mapParameter.put(SystemConstant.END_POINT, dictionaryConfig.aliYunOssDomain().getEndpoint());
-        mapParameter.put(SystemConstant.ACCESS_KEY_ID, dictionaryConfig.aliYunOssDomain().getAccessKeyId());
-        mapParameter.put(SystemConstant.ACCESS_KEY_SECRET, dictionaryConfig.aliYunOssDomain().getAccessKeySecret());
-        mapParameter.put(SystemConstant.BUCKET, dictionaryConfig.aliYunOssDomain().getBucket());
-        mapParameter.put(SystemConstant.OSS, dictionaryConfig.sysDomain().isOss());
-        mapParameter.put(SystemConstant.ATTACHMENT_TYPE, dictionaryConfig.sysDomain().getAttachmentType());
-        String uploadType = UploadFileEnum.convertToName(type);
-        mapParameter.put(SystemConstant.UPLOAD_TYPE, uploadType);
-        return mapParameter;
-    }
-    
-    public static String getTempDir() {
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        return dictionaryConfig.sysDomain().getTempDataDir();
-    }
-}

+ 0 - 62
themis-business/src/main/java/com/qmth/themis/business/config/EnvConfig.java

@@ -1,62 +0,0 @@
-package com.qmth.themis.business.config;
-
-import org.springframework.stereotype.Component;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-/**
- * @Description: 获取环境
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2020/7/18
- */
-@Component
-public class EnvConfig {
-    String backendProject = "backend",
-            taskProject = "task",
-            examProject = "exam",
-            backendPath = "com.qmth.themis.backend.constant.BackendConstant",
-            taskPath = "com.qmth.themis.task.constant.TaskConstant",
-            examPath = "com.qmth.themis.exam.constant.ExamConstant",
-            methodName = "getAttachmentEnv";
-
-    /**
-     * 获取oss环境
-     *
-     * @param type
-     * @return
-     */
-    public Map<String, Object> getOssEnv(Integer type) {
-        try {
-            String path = this.getClass().getResource(File.separator).getPath();
-            Class clazz = null;
-            try {
-                if (path.contains(backendProject)) {
-                    clazz = Class.forName(backendPath);
-                } else if (path.contains(taskProject)) {
-                    clazz = Class.forName(taskPath);
-                } else if (path.contains(examProject)) {
-                    clazz = Class.forName(examPath);
-                }
-            } catch (ClassNotFoundException e) {
-                e.printStackTrace();
-            }
-            Object o = clazz.newInstance();
-            Method method = clazz.getDeclaredMethod(methodName, Integer.class);
-            return (Map<String, Object>) method.invoke(o, type);
-        } catch (NoSuchMethodException e) {
-            e.printStackTrace();
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-        } catch (InvocationTargetException e) {
-            e.printStackTrace();
-        } catch (InstantiationException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-}

+ 0 - 49
themis-business/src/main/java/com/qmth/themis/business/config/SysConfig.java

@@ -1,49 +0,0 @@
-package com.qmth.themis.business.config;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.springframework.stereotype.Component;
-
-/**
- * @Description: 
- * @Author: xiatian
- * @Date: 2020-07-21
- */
-@Component
-public class SysConfig {
-
-    public String getTempDir() {
-    	String backendProject = "backend",
-    			taskProject = "task",
-    			backendPath = "com.qmth.themis.backend.constant.BackendConstant",
-    			taskPath = "com.qmth.themis.task.constant.TaskConstant",
-    			methodName = "getTempDir";
-        try {
-            String path = this.getClass().getResource(File.separator).getPath();
-            Class clazz = null;
-            try {
-                if (path.contains(backendProject)) {
-                    clazz = Class.forName(backendPath);
-                } else if (path.contains(taskProject)) {
-                    clazz = Class.forName(taskPath);
-                }
-            } catch (ClassNotFoundException e) {
-                e.printStackTrace();
-            }
-            Object o = clazz.newInstance();
-            Method method = clazz.getDeclaredMethod(methodName);
-            return (String) method.invoke(o);
-        } catch (NoSuchMethodException e) {
-            e.printStackTrace();
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-        } catch (InvocationTargetException e) {
-            e.printStackTrace();
-        } catch (InstantiationException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-}

+ 81 - 0
themis-business/src/main/java/com/qmth/themis/business/config/SystemConfig.java

@@ -0,0 +1,81 @@
+package com.qmth.themis.business.config;
+
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.enums.UploadFileEnum;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @Description: 读取系统配置文件
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/22
+ */
+@Component
+public class SystemConfig {
+    private Properties props = null;
+
+    public SystemConfig() {
+        try {
+            Resource resource = new ClassPathResource("/application.properties");
+            props = PropertiesLoaderUtils.loadProperties(resource);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取属性
+     *
+     * @param key
+     * @return
+     */
+    public String getProperty(String key) {
+        return Objects.isNull(props) ? null : props.getProperty(key);
+    }
+
+    /**
+     * 获取属性
+     *
+     * @param key
+     * @param defaultValue
+     * @return
+     */
+    public String getProperty(String key, String defaultValue) {
+        return Objects.isNull(props) ? null : props.getProperty(key, defaultValue);
+    }
+
+    /**
+     * 获取properyies属性
+     *
+     * @return
+     */
+    public Properties getProperties() {
+        return props;
+    }
+
+    /**
+     * 获取oss环境
+     *
+     * @param type
+     * @return
+     */
+    public Map<String, Object> getOssEnv(Integer type) {
+        Map<String, Object> mapParameter = new HashMap<>();
+        mapParameter.put(SystemConstant.END_POINT, props.getProperty("aliyun.oss.endpoint"));
+        mapParameter.put(SystemConstant.ACCESS_KEY_ID, props.getProperty("aliyun.oss.accessKeyId"));
+        mapParameter.put(SystemConstant.ACCESS_KEY_SECRET, props.getProperty("aliyun.oss.accessKeySecret"));
+        mapParameter.put(SystemConstant.BUCKET, props.getProperty("aliyun.oss.bucket"));
+        mapParameter.put(SystemConstant.OSS, Boolean.valueOf(props.getProperty("sys.config.oss")));
+        mapParameter.put(SystemConstant.ATTACHMENT_TYPE, Arrays.asList(props.getProperty("sys.config.attachmentType").split(",")));
+        String uploadType = UploadFileEnum.convertToName(type);
+        mapParameter.put(SystemConstant.UPLOAD_TYPE, uploadType);
+        return mapParameter;
+    }
+}

+ 3 - 8
themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportCommon.java

@@ -3,7 +3,7 @@ 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.config.SystemConfig;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TBTaskHistory;
@@ -34,7 +34,6 @@ public class TaskExportCommon {
     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;
@@ -54,14 +53,14 @@ public class TaskExportCommon {
      * 初始化
      */
     public void init() {
+        SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
         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.ossEnv = systemConfig.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);
@@ -238,10 +237,6 @@ public class TaskExportCommon {
         return ossUtil;
     }
 
-    public EnvConfig getEnvConfig() {
-        return envConfig;
-    }
-
     public Map<String, Object> getOssEnv() {
         return ossEnv;
     }

+ 3 - 8
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -3,7 +3,7 @@ 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.config.SystemConfig;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TBTaskHistory;
@@ -35,7 +35,6 @@ public class TaskImportCommon {
     private String path = null;
     private Integer uploadType = null;
     private OssUtil ossUtil = null;
-    private EnvConfig envConfig = null;
     private Map<String, Object> ossEnv = null;
     private TBTaskHistory tbTaskHistory = null;
     private String timeFormat = null;
@@ -53,6 +52,7 @@ public class TaskImportCommon {
      * 初始化
      */
     public void init() {
+        SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
         Gson gson = new Gson();
         if (Objects.nonNull(this.map.get("mode"))) {
             this.mode = Integer.parseInt(String.valueOf(this.map.get("mode")));
@@ -69,8 +69,7 @@ public class TaskImportCommon {
         this.path = String.valueOf(remarkJs.get("path"));
         this.uploadType = Integer.parseInt(String.valueOf(remarkJs.get("uploadType")));
         this.ossUtil = SpringContextHolder.getBean(OssUtil.class);
-        this.envConfig = SpringContextHolder.getBean(EnvConfig.class);
-        this.ossEnv = this.envConfig.getOssEnv(this.uploadType);
+        this.ossEnv = systemConfig.getOssEnv(this.uploadType);
         Map tbTaskHistoryMap = (Map) this.map.get("tbTaskHistory");
         tbTaskHistoryMap = SystemConstant.timeTransform(tbTaskHistoryMap);
         this.tbTaskHistory = gson.fromJson(gson.toJson(tbTaskHistoryMap), TBTaskHistory.class);
@@ -236,10 +235,6 @@ public class TaskImportCommon {
         return ossUtil;
     }
 
-    public EnvConfig getEnvConfig() {
-        return envConfig;
-    }
-
     public Map<String, Object> getOssEnv() {
         return ossEnv;
     }

+ 342 - 351
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamPaperImportTemplete.java

@@ -1,25 +1,9 @@
 package com.qmth.themis.business.templete.impl;
 
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.qmth.themis.business.config.EnvConfig;
-import com.qmth.themis.business.config.SysConfig;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TEExam;
@@ -37,8 +21,15 @@ import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.FileUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import cn.hutool.core.date.DateUtil;
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * @Description: 试卷导入
@@ -47,352 +38,352 @@ import cn.hutool.core.date.DateUtil;
  */
 @Service("taskExamPaperImportTemplete")
 public class TaskExamPaperImportTemplete implements TaskImportTemplete {
-	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
-	@Resource
-	TEExamService teExamService;
-	@Resource
-	SysConfig sysConfig;
-	@Resource
-	TEExamCourseService teExamCourseService;
-	@Resource
-	TEExamPaperService teExamPaperService;
+    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+    @Resource
+    TEExamService teExamService;
+    @Resource
+    SystemConfig systemConfig;
+    @Resource
+    TEExamCourseService teExamCourseService;
+    @Resource
+    TEExamPaperService teExamPaperService;
+
+    @Override
+    @Transactional
+    public Result importTask(Map<String, Object> map) throws IOException {
+        long start = System.currentTimeMillis();
+        TaskImportCommon taskImportCommon = new TaskImportCommon(map);
+        taskImportCommon.init();
+        StringBuilder result = new StringBuilder();
+        String timeFormat = taskImportCommon.getTimeFormat();
+        addResult(result, DateUtil.format(new Date(), timeFormat) + "处理开始");
+        File file = null;
+        try {
+            file = taskImportCommon.getUploadFile();
+            dispose(file, map, result);
+        } catch (Exception e) {
+            addResult(result, "处理出错 " + e.getMessage());
+            throw e;
+        } finally {
+            if (file != null) {
+                file.delete();
+            }
+            addResult(result, DateUtil.format(new Date(), timeFormat) + "处理结束");
+            long end = System.currentTimeMillis();
+            addResult(result, "耗时(秒):" + ((end - start) / 1000));
+            taskImportCommon.writeImportResultTxt(result.toString());
+        }
+        return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
+    }
 
-	@Override
-	@Transactional
-	public Result importTask(Map<String, Object> map) throws IOException {
-		long start = System.currentTimeMillis();
-		TaskImportCommon taskImportCommon = new TaskImportCommon(map);
-		taskImportCommon.init();
-		StringBuilder result = new StringBuilder();
-		String timeFormat = taskImportCommon.getTimeFormat();
-		addResult(result, DateUtil.format(new Date(), timeFormat) + "处理开始");
-		File file = null;
-		try {
-			file = taskImportCommon.getUploadFile();
-			dispose(file, map, result);
-		} catch (Exception e) {
-			addResult(result, "处理出错 " + e.getMessage());
-			throw e;
-		} finally {
-			if (file != null) {
-				file.delete();
-			}
-			addResult(result, DateUtil.format(new Date(), timeFormat) + "处理结束");
-			long end = System.currentTimeMillis();
-			addResult(result, "耗时(秒):" + ((end - start) / 1000));
-			taskImportCommon.writeImportResultTxt(result.toString());
-		}
-		return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
-	}
+    private void dispose(File file, Map<String, Object> map, StringBuilder result) throws IOException {
+        Long examId = (Long) map.get("examId");
 
-	private void dispose(File file, Map<String, Object> map, StringBuilder result) throws IOException {
-		Long examId = (Long) map.get("examId");
+        TEExam teExam = teExamService.getById(examId);
+        if (Objects.isNull(teExam)) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_NO);
+        }
 
-		TEExam teExam = teExamService.getById(examId);
-		if (Objects.isNull(teExam)) {
-			throw new BusinessException(ExceptionResultEnum.EXAM_NO);
-		}
+        String tempDir = systemConfig.getProperty("sys.config.tempDataDir");
+        String dir = tempDir + "/" + uuid() + "/";
+        File dfile = new File(dir);
+        try {
+            dfile.mkdirs();
+            FileUtil.unZip(dfile, file);
+            if (!hasErr(dir, examId, dfile, result)) {
+                for (File courseDir : dfile.listFiles()) {
+                    if (courseDir.isDirectory()) {
+                        disposeCourseDir(dir, teExam, courseDir, map);
+                    }
+                }
+            }
+        } finally {
+            FileUtil.deleteFolder(dir);
+        }
+    }
 
-		String tempDir = sysConfig.getTempDir();
-		String dir = tempDir + "/" + uuid() + "/";
-		File dfile = new File(dir);
-		try {
-			dfile.mkdirs();
-			FileUtil.unZip(dfile, file);
-			if (!hasErr(dir, examId, dfile, result)) {
-				for (File courseDir : dfile.listFiles()) {
-					if (courseDir.isDirectory()) {
-						disposeCourseDir(dir, teExam, courseDir, map);
-					}
-				}
-			}
-		} finally {
-			FileUtil.deleteFolder(dir);
-		}
-	}
+    private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
+        String courseCode = courseDir.getName();
+        TEExamCourse course = teExamCourseService.findByCode(courseCode);
+        if (course == null) {
+            throw new BusinessException("科目编码不存在 " + courseCode);
+        }
+        File[] childs = courseDir.listFiles();
+        for (File paperDir : childs) {
+            if (paperDir.isDirectory()) {
+                disposePaperDir(rootDir, teExam, course, paperDir, map);
+            }
+        }
+        Boolean objectiveShuffle = (Boolean) map.get("objectiveShuffle");
+        Boolean optionShuffle = (Boolean) map.get("optionShuffle");
+        Integer audioPlayTime = (Integer) map.get("audioPlayTime");
+        if (objectiveShuffle != null) {
+            course.setObjectiveShuffle(objectiveShuffle ? 1 : 0);
+        }
+        if (optionShuffle != null) {
+            course.setOptionShuffle(optionShuffle ? 1 : 0);
+        }
+        if (audioPlayTime != null) {
+            course.setAudioPlayTime(audioPlayTime);
+        }
+        if (objectiveShuffle != null || optionShuffle != null || audioPlayTime != null) {
+            teExamCourseService.save(course);
+        }
+    }
 
-	private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
-		String courseCode = courseDir.getName();
-		TEExamCourse course = teExamCourseService.findByCode(courseCode);
-		if (course == null) {
-			throw new BusinessException("科目编码不存在 " + courseCode);
-		}
-		File[] childs = courseDir.listFiles();
-		for (File paperDir : childs) {
-			if (paperDir.isDirectory()) {
-				disposePaperDir(rootDir, teExam, course, paperDir, map);
-			}
-		}
-		Boolean objectiveShuffle = (Boolean) map.get("objectiveShuffle");
-		Boolean optionShuffle = (Boolean) map.get("optionShuffle");
-		Integer audioPlayTime = (Integer) map.get("audioPlayTime");
-		if(objectiveShuffle!=null) {
-			course.setObjectiveShuffle(objectiveShuffle?1:0);
-		}
-		if(optionShuffle!=null) {
-			course.setOptionShuffle(optionShuffle?1:0);
-		}
-		if(audioPlayTime!=null) {
-			course.setAudioPlayTime(audioPlayTime);
-		}
-		if(objectiveShuffle!=null||optionShuffle!=null||audioPlayTime!=null) {
-			teExamCourseService.save(course);
-		}
-	}
+    private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
+                                 Map<String, Object> map) {
+        String paperCode = paperDir.getName();
+        File[] childs = paperDir.listFiles();
 
-	private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
-			Map<String, Object> map) {
-		String paperCode = paperDir.getName();
-		File[] childs = paperDir.listFiles();
+        File paperFile = null;
+        File answerFile = null;
+        File attachmentDir = null;
+        for (File cfile : childs) {
+            if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
+                paperFile = cfile;
+            }
+            if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
+                answerFile = cfile;
+            }
+            if ("attachment".equals(cfile.getName()) && cfile.isDirectory()) {
+                if (cfile.listFiles() != null && cfile.listFiles().length != 0) {
+                    attachmentDir = cfile;
+                }
+            }
+        }
+        TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(teExam.getId(),
+                course.getCourseCode(), paperCode);
+        if (paper == null) {
+            paper = new TEExamPaper();
+            Long createId = (Long) map.get("createId");
+            JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
+            paper.setName(paperJson.getString("name"));
+            paper.setTotalScore(paperJson.getDouble("totalScore"));
+            paper.setDecryptSecret(RandomStringUtils.randomAlphanumeric(16));
+            paper.setEncryptMode(0);
+            paper.setExamId(teExam.getId());
+            paper.setCode(paperCode);
+            paper.setHasAudio(paperJson.getInteger("hasAudio"));
+            paper.setCreateId(createId);
+            paper.setCourseCode(course.getCourseCode());
+            paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
+        }
+        disposePaper(rootDir, paper, paperFile, attachmentDir);
+        disposeStruct(rootDir, paper, paperFile);
+        disposeAnswer(rootDir, paper, answerFile);
 
-		File paperFile = null;
-		File answerFile = null;
-		File attachmentDir = null;
-		for (File cfile : childs) {
-			if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
-				paperFile = cfile;
-			}
-			if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
-				answerFile = cfile;
-			}
-			if ("attachment".equals(cfile.getName()) && cfile.isDirectory()) {
-				if (cfile.listFiles() != null && cfile.listFiles().length != 0) {
-					attachmentDir = cfile;
-				}
-			}
-		}
-		TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(teExam.getId(),
-				course.getCourseCode(), paperCode);
-		if (paper == null) {
-			paper = new TEExamPaper();
-			Long createId = (Long) map.get("createId");
-			JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
-			paper.setName(paperJson.getString("name"));
-			paper.setTotalScore(paperJson.getDouble("totalScore"));
-			paper.setDecryptSecret(RandomStringUtils.randomAlphanumeric(16));
-			paper.setEncryptMode(0);
-			paper.setExamId(teExam.getId());
-			paper.setCode(paperCode);
-			paper.setHasAudio(paperJson.getInteger("hasAudio"));
-			paper.setCreateId(createId);
-			paper.setCourseCode(course.getCourseCode());
-			paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
-		}
-		disposePaper(rootDir, paper, paperFile, attachmentDir);
-		disposeStruct(rootDir, paper, paperFile);
-		disposeAnswer(rootDir, paper, answerFile);
-		
-		teExamPaperService.save(paper);
-	}
+        teExamPaperService.save(paper);
+    }
 
-	private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
-		if (paperFile == null) {
-			return;
-		}
-		File zip = new File(rootDir + uuid() + ".zip");
-		List<File> files = new ArrayList<File>();
-		files.add(paperFile);
-		if (attachmentDir != null) {
-			files.add(attachmentDir);
-		}
-		FileUtil.doZip(zip, files);
-		File encryptZip = new File(rootDir + uuid() + ".zip");
-		FileUtil.encryptFile(zip, encryptZip, paper.getDecryptSecret(), paper.getDecryptVector());
-		String filePath = sdf.format(new Date()) + "/" + uuid() + ".zip";
-		paper.setPaperPath(filePath);
-		EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
-		OssUtil.ossUpload(env.getOssEnv(3), filePath, encryptZip);
-	}
+    private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
+        if (paperFile == null) {
+            return;
+        }
+        File zip = new File(rootDir + uuid() + ".zip");
+        List<File> files = new ArrayList<File>();
+        files.add(paperFile);
+        if (attachmentDir != null) {
+            files.add(attachmentDir);
+        }
+        FileUtil.doZip(zip, files);
+        File encryptZip = new File(rootDir + uuid() + ".zip");
+        FileUtil.encryptFile(zip, encryptZip, paper.getDecryptSecret(), paper.getDecryptVector());
+        String filePath = sdf.format(new Date()) + "/" + uuid() + ".zip";
+        paper.setPaperPath(filePath);
+        SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
+        OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, encryptZip);
+    }
 
-	private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) {
-		if (paperFile == null) {
-			return;
-		}
-		JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
-		JSONArray details = paperJson.getJSONArray("details");
-		for (int i = 0; i < details.size(); i++) {
-			JSONArray questions = details.getJSONObject(i).getJSONArray("questions");
-			for (int j = 0; j < questions.size(); j++) {
-				JSONObject question = questions.getJSONObject(j);
-				question.remove("body");
-				if (question.getInteger("structType").intValue() == 6) {
-					JSONArray subQuestions = question.getJSONArray("subQuestions");
-					for (int k = 0; k < subQuestions.size(); k++) {
-						JSONObject subquestion = subQuestions.getJSONObject(k);
-						subquestion.remove("body");
-					}
-				}
-			}
-		}
+    private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) {
+        if (paperFile == null) {
+            return;
+        }
+        JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
+        JSONArray details = paperJson.getJSONArray("details");
+        for (int i = 0; i < details.size(); i++) {
+            JSONArray questions = details.getJSONObject(i).getJSONArray("questions");
+            for (int j = 0; j < questions.size(); j++) {
+                JSONObject question = questions.getJSONObject(j);
+                question.remove("body");
+                if (question.getInteger("structType").intValue() == 6) {
+                    JSONArray subQuestions = question.getJSONArray("subQuestions");
+                    for (int k = 0; k < subQuestions.size(); k++) {
+                        JSONObject subquestion = subQuestions.getJSONObject(k);
+                        subquestion.remove("body");
+                    }
+                }
+            }
+        }
 
-		File file = new File(rootDir + uuid() + ".json");
-		FileUtil.saveAsFile(file.getAbsolutePath(), paperJson.toJSONString());
-		String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
-		paper.setStructPath(filePath);
-		EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
-		OssUtil.ossUpload(env.getOssEnv(3), filePath, file);
-	}
+        File file = new File(rootDir + uuid() + ".json");
+        FileUtil.saveAsFile(file.getAbsolutePath(), paperJson.toJSONString());
+        String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
+        paper.setStructPath(filePath);
+        SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
+        OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, file);
+    }
 
-	private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile) {
-		if (answerFile == null) {
-			return;
-		}
-		File encryptFile = new File(rootDir + uuid() + ".json");
-		FileUtil.encryptFile(answerFile, encryptFile, paper.getDecryptSecret(), paper.getDecryptVector());
-		String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
-		paper.setAnswerPath(filePath);
-		EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
-		OssUtil.ossUpload(env.getOssEnv(3), filePath, encryptFile);
-	}
+    private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile) {
+        if (answerFile == null) {
+            return;
+        }
+        File encryptFile = new File(rootDir + uuid() + ".json");
+        FileUtil.encryptFile(answerFile, encryptFile, paper.getDecryptSecret(), paper.getDecryptVector());
+        String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
+        paper.setAnswerPath(filePath);
+        SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
+        OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, encryptFile);
+    }
 
-	private void addResult(StringBuilder result, String msg) {
-		result.append(msg).append("\r\n");
-	}
+    private void addResult(StringBuilder result, String msg) {
+        result.append(msg).append("\r\n");
+    }
 
-	private boolean hasErr(String rootDir, Long examId, File dfile, StringBuilder result) {
-		boolean hasErr = false;
-		for (File courseDir : dfile.listFiles()) {// 校验每一个科目
-			if (courseDir.isDirectory()) {
-				String courseCode = courseDir.getName();
-				TEExamCourse course = teExamCourseService.findByCode(courseCode);
-				if (course == null) {
-					addResult(result, "科目编码不存在 " + courseCode);
-					hasErr = true;
-					continue;
-				}
-				File[] childs = courseDir.listFiles();
-				if (childs == null || childs.length == 0) {
-					addResult(result, "科目 " + courseCode + " 没有需要导入的文件");
-					hasErr = true;
-					continue;
-				}
-				for (File paperDir : childs) {// 校验每一套试卷
-					if (paperDir.isDirectory()) {
-						String paperCode = paperDir.getName();
-						File[] paperDirChilds = paperDir.listFiles();
-						if (paperDirChilds == null || paperDirChilds.length == 0) {
-							addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有需要导入的文件");
-							hasErr = true;
-							continue;
-						}
-						try {
-							// 校验答案
-							checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
-						} catch (Exception e) {
-							addResult(result, e.getMessage());
-							hasErr = true;
-							continue;
-						}
-					}
-				}
-			}
-		}
-		return hasErr;
-	}
+    private boolean hasErr(String rootDir, Long examId, File dfile, StringBuilder result) {
+        boolean hasErr = false;
+        for (File courseDir : dfile.listFiles()) {// 校验每一个科目
+            if (courseDir.isDirectory()) {
+                String courseCode = courseDir.getName();
+                TEExamCourse course = teExamCourseService.findByCode(courseCode);
+                if (course == null) {
+                    addResult(result, "科目编码不存在 " + courseCode);
+                    hasErr = true;
+                    continue;
+                }
+                File[] childs = courseDir.listFiles();
+                if (childs == null || childs.length == 0) {
+                    addResult(result, "科目 " + courseCode + " 没有需要导入的文件");
+                    hasErr = true;
+                    continue;
+                }
+                for (File paperDir : childs) {// 校验每一套试卷
+                    if (paperDir.isDirectory()) {
+                        String paperCode = paperDir.getName();
+                        File[] paperDirChilds = paperDir.listFiles();
+                        if (paperDirChilds == null || paperDirChilds.length == 0) {
+                            addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有需要导入的文件");
+                            hasErr = true;
+                            continue;
+                        }
+                        try {
+                            // 校验答案
+                            checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
+                        } catch (Exception e) {
+                            addResult(result, e.getMessage());
+                            hasErr = true;
+                            continue;
+                        }
+                    }
+                }
+            }
+        }
+        return hasErr;
+    }
 
-	private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
-			String paperCode) {
-		File paperFile = null;
-		File answerFile = null;
-		for (File cfile : paperDirChilds) {// 校验试卷下的答案
-			if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
-				paperFile = cfile;
-			}
-			if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
-				answerFile = cfile;
-			}
-		}
-		if (answerFile != null) {
-			if (paperFile == null) {// 没有试卷信息,不能先导入答案
-				TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode,
-						paperCode);
-				if (paper == null) {
-					throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
-				}
-				String structPath = paper.getStructPath();
-				EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
-				String url = OssUtil.getUrlForPrivateBucket(env.getOssEnv(3), structPath);
-				String name = structPath.substring(structPath.lastIndexOf("/") + 1);
-				File structFile = new File(rootDir + name);
-				try {
-					FileUtil.saveUrlAsFile(url, structFile);
-					compareAnswerAndPaper(courseCode, paperCode, answerFile, structFile);
-				} finally {
-					if (structFile.exists()) {
-						structFile.delete();
-					}
-				}
-			} else {
-				compareAnswerAndPaper(courseCode, paperCode, answerFile, paperFile);
-			}
-		}
-	}
+    private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
+                                 String paperCode) {
+        File paperFile = null;
+        File answerFile = null;
+        for (File cfile : paperDirChilds) {// 校验试卷下的答案
+            if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
+                paperFile = cfile;
+            }
+            if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
+                answerFile = cfile;
+            }
+        }
+        if (answerFile != null) {
+            if (paperFile == null) {// 没有试卷信息,不能先导入答案
+                TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode,
+                        paperCode);
+                if (paper == null) {
+                    throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
+                }
+                String structPath = paper.getStructPath();
+                SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
+                String url = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), structPath);
+                String name = structPath.substring(structPath.lastIndexOf("/") + 1);
+                File structFile = new File(rootDir + name);
+                try {
+                    FileUtil.saveUrlAsFile(url, structFile);
+                    compareAnswerAndPaper(courseCode, paperCode, answerFile, structFile);
+                } finally {
+                    if (structFile.exists()) {
+                        structFile.delete();
+                    }
+                }
+            } else {
+                compareAnswerAndPaper(courseCode, paperCode, answerFile, paperFile);
+            }
+        }
+    }
 
-	private void compareAnswerAndPaper(String courseCode, String paperCode, File answerFile, File structFile) {
-		JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
-		JSONArray answerdetails = answerJson.getJSONArray("details");
-		JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
-		JSONArray structdetails = structJson.getJSONArray("details");
-		if (answerdetails.size() != structdetails.size()) {
-			throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷大题数量不一致");
-		}
-		for (int i = 0; i < answerdetails.size(); i++) {
-			JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
-			JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
-			if (answerdetailquestions.size() != structdetailquestions.size()) {
-				throw new BusinessException(
-						"科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1) + "大题的小题数量不一致");
-			}
-			for (int j = 0; j < answerdetailquestions.size(); j++) {
-				JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
-				JSONObject structquestion = structdetailquestions.getJSONObject(j);
-				if (structquestion.getInteger("structType").intValue() == 1
-						|| structquestion.getInteger("structType").intValue() == 2) {
-					JSONArray answer = answerquestion.getJSONArray("answer");
-					if (answer == null || answer.size() == 0) {
-						throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
-								+ "大题第" + (j + 1) + "小题没有答案");
-					}
-				}
-				if (structquestion.getInteger("structType").intValue() == 3) {
-					Boolean answer = answerquestion.getBoolean("answer");
-					if (answer == null) {
-						throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
-								+ "大题第" + (j + 1) + "小题没有答案");
-					}
-				}
-				if (structquestion.getInteger("structType").intValue() == 6) {
-					JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
-					JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
-					if (answersubQuestions.size() != structsubQuestions.size()) {
-						throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
-								+ "大题第" + (j + 1) + "小题子题数量不一致");
-					}
-					for (int k = 0; k < answersubQuestions.size(); k++) {
-						JSONObject answersubquestion = answerdetailquestions.getJSONObject(k);
-						JSONObject structsubquestion = structdetailquestions.getJSONObject(k);
-						if (structsubquestion.getInteger("structType").intValue() == 1
-								|| structsubquestion.getInteger("structType").intValue() == 2) {
-							JSONArray answer = answersubquestion.getJSONArray("answer");
-							if (answer == null || answer.size() == 0) {
-								throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
-										+ (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
-							}
-						}
-						if (structsubquestion.getInteger("structType").intValue() == 3) {
-							Boolean answer = answersubquestion.getBoolean("answer");
-							if (answer == null) {
-								throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
-										+ (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
-							}
-						}
-					}
-				}
-			}
-		}
-	}
+    private void compareAnswerAndPaper(String courseCode, String paperCode, File answerFile, File structFile) {
+        JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
+        JSONArray answerdetails = answerJson.getJSONArray("details");
+        JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
+        JSONArray structdetails = structJson.getJSONArray("details");
+        if (answerdetails.size() != structdetails.size()) {
+            throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷大题数量不一致");
+        }
+        for (int i = 0; i < answerdetails.size(); i++) {
+            JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
+            JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
+            if (answerdetailquestions.size() != structdetailquestions.size()) {
+                throw new BusinessException(
+                        "科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1) + "大题的小题数量不一致");
+            }
+            for (int j = 0; j < answerdetailquestions.size(); j++) {
+                JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
+                JSONObject structquestion = structdetailquestions.getJSONObject(j);
+                if (structquestion.getInteger("structType").intValue() == 1
+                        || structquestion.getInteger("structType").intValue() == 2) {
+                    JSONArray answer = answerquestion.getJSONArray("answer");
+                    if (answer == null || answer.size() == 0) {
+                        throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
+                                + "大题第" + (j + 1) + "小题没有答案");
+                    }
+                }
+                if (structquestion.getInteger("structType").intValue() == 3) {
+                    Boolean answer = answerquestion.getBoolean("answer");
+                    if (answer == null) {
+                        throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
+                                + "大题第" + (j + 1) + "小题没有答案");
+                    }
+                }
+                if (structquestion.getInteger("structType").intValue() == 6) {
+                    JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
+                    JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
+                    if (answersubQuestions.size() != structsubQuestions.size()) {
+                        throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
+                                + "大题第" + (j + 1) + "小题子题数量不一致");
+                    }
+                    for (int k = 0; k < answersubQuestions.size(); k++) {
+                        JSONObject answersubquestion = answerdetailquestions.getJSONObject(k);
+                        JSONObject structsubquestion = structdetailquestions.getJSONObject(k);
+                        if (structsubquestion.getInteger("structType").intValue() == 1
+                                || structsubquestion.getInteger("structType").intValue() == 2) {
+                            JSONArray answer = answersubquestion.getJSONArray("answer");
+                            if (answer == null || answer.size() == 0) {
+                                throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
+                                        + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
+                            }
+                        }
+                        if (structsubquestion.getInteger("structType").intValue() == 3) {
+                            Boolean answer = answersubquestion.getBoolean("answer");
+                            if (answer == null) {
+                                throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
+                                        + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
 
-	private String uuid() {
-		return UUID.randomUUID().toString().replaceAll("-", "");
-	}
+    private String uuid() {
+        return UUID.randomUUID().toString().replaceAll("-", "");
+    }
 }

+ 0 - 45
themis-exam/src/main/java/com/qmth/themis/exam/constant/ExamConstant.java

@@ -1,45 +0,0 @@
-package com.qmth.themis.exam.constant;
-
-import com.qmth.themis.business.constant.SpringContextHolder;
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.enums.UploadFileEnum;
-import com.qmth.themis.common.enums.ExceptionResultEnum;
-import com.qmth.themis.common.exception.BusinessException;
-import com.qmth.themis.exam.config.DictionaryConfig;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * @Description: 后台系统常量
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2020/7/15
- */
-public class ExamConstant {
-
-    /**
-     * 获取系统上传环境
-     *
-     * @param type
-     * @return
-     */
-    public static Map<String, Object> getAttachmentEnv(Integer type) {
-        if (Objects.isNull(type) || Objects.equals(type, "")) {
-            throw new BusinessException(ExceptionResultEnum.ATTACHMENT_TYPE_IS_NULL);
-        }
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        Map<String, Object> mapParameter = new HashMap<>();
-        mapParameter.put(SystemConstant.END_POINT, dictionaryConfig.aliYunOssDomain().getEndpoint());
-        mapParameter.put(SystemConstant.ACCESS_KEY_ID, dictionaryConfig.aliYunOssDomain().getAccessKeyId());
-        mapParameter.put(SystemConstant.ACCESS_KEY_SECRET, dictionaryConfig.aliYunOssDomain().getAccessKeySecret());
-        mapParameter.put(SystemConstant.BUCKET, dictionaryConfig.aliYunOssDomain().getBucket());
-        mapParameter.put(SystemConstant.OSS, dictionaryConfig.sysDomain().isOss());
-        mapParameter.put(SystemConstant.ATTACHMENT_TYPE, dictionaryConfig.sysDomain().getAttachmentType());
-        String uploadType = UploadFileEnum.convertToName(type);
-        mapParameter.put(SystemConstant.UPLOAD_TYPE, uploadType);
-        return mapParameter;
-    }
-}

+ 0 - 50
themis-task/src/main/java/com/qmth/themis/task/constant/TaskConstant.java

@@ -1,50 +0,0 @@
-package com.qmth.themis.task.constant;
-
-import com.qmth.themis.business.constant.SpringContextHolder;
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.enums.UploadFileEnum;
-import com.qmth.themis.common.enums.ExceptionResultEnum;
-import com.qmth.themis.common.exception.BusinessException;
-import com.qmth.themis.task.config.DictionaryConfig;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * @Description: 后台系统常量
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2020/7/15
- */
-public class TaskConstant {
-
-    /**
-     * 获取系统上传环境
-     *
-     * @param type
-     * @return
-     */
-    public static Map<String, Object> getAttachmentEnv(Integer type) {
-        if (Objects.isNull(type) || Objects.equals(type, "")) {
-            throw new BusinessException(ExceptionResultEnum.ATTACHMENT_TYPE_IS_NULL);
-        }
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        Map<String, Object> mapParameter = new HashMap<>();
-        mapParameter.put(SystemConstant.END_POINT, dictionaryConfig.aliYunOssDomain().getEndpoint());
-        mapParameter.put(SystemConstant.ACCESS_KEY_ID, dictionaryConfig.aliYunOssDomain().getAccessKeyId());
-        mapParameter.put(SystemConstant.ACCESS_KEY_SECRET, dictionaryConfig.aliYunOssDomain().getAccessKeySecret());
-        mapParameter.put(SystemConstant.BUCKET, dictionaryConfig.aliYunOssDomain().getBucket());
-        mapParameter.put(SystemConstant.OSS, dictionaryConfig.sysDomain().isOss());
-        mapParameter.put(SystemConstant.ATTACHMENT_TYPE, dictionaryConfig.sysDomain().getAttachmentType());
-        String uploadType = UploadFileEnum.convertToName(type);
-        mapParameter.put(SystemConstant.UPLOAD_TYPE, uploadType);
-        return mapParameter;
-    }
-    
-    public static String getTempDir() {
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        return dictionaryConfig.sysDomain().getTempDataDir();
-    }
-}