deason 5 سال پیش
والد
کامیت
f5874163bb

+ 151 - 0
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/SysProperty.java

@@ -0,0 +1,151 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-11-30 15:17:49.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.common;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * 系统配置信息
+ *
+ * @author: fengdesheng
+ * @since: 2018/11/30
+ */
+@Component
+public class SysProperty implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Value("${$upyun.site.1.domain}")
+    protected String domain;
+
+    @Value("${$upyun.site.1.bucketName}")
+    protected String bucketName;
+
+    @Value("${$upyun.site.1.userName}")
+    protected String userName;
+
+    @Value("${$upyun.site.1.password}")
+    protected String password;
+
+    @Value("${$upyun.site.1.uploadUrl}")
+    private String uploadUrl;
+
+    /**
+     * 配置文件环境
+     */
+    @Value("${spring.profiles.active}")
+    private String profile;
+
+    /**
+     * 文件存放目录
+     */
+    @Value("${examcloud.web.sys.dataDir}")
+    private String dir;
+
+    /**
+     * 文件存放临时目录
+     */
+    @Value("${examcloud.web.sys.tempDataDir}")
+    private String tempDir;
+
+    /**
+     * 题库访问地址前缀
+     */
+    @Value("${$question.url.prefix}")
+    private String questionUrlPrefix;
+
+    public String getDomain() {
+        if (domain != null) {
+            return domain.trim();
+        }
+        return "";
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+    public String getBucketName() {
+        if (bucketName != null) {
+            return bucketName.trim();
+        }
+        return "";
+    }
+
+    public void setBucketName(String bucketName) {
+        this.bucketName = bucketName;
+    }
+
+    public String getUserName() {
+        if (userName != null) {
+            return userName.trim();
+        }
+        return "";
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        if (password != null) {
+            return password.trim();
+        }
+        return "";
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getUploadUrl() {
+        if (uploadUrl != null) {
+            return uploadUrl.trim();
+        }
+        return "";
+    }
+
+    public void setUploadUrl(String uploadUrl) {
+        this.uploadUrl = uploadUrl;
+    }
+
+    public String getProfile() {
+        return profile;
+    }
+
+    public void setProfile(String profile) {
+        this.profile = profile;
+    }
+
+    public String getDir() {
+        return dir;
+    }
+
+    public void setDir(String dir) {
+        this.dir = dir;
+    }
+
+    public String getTempDir() {
+        return tempDir;
+    }
+
+    public void setTempDir(String tempDir) {
+        this.tempDir = tempDir;
+    }
+
+    public String getQuestionUrlPrefix() {
+        return questionUrlPrefix;
+    }
+
+    public void setQuestionUrlPrefix(String questionUrlPrefix) {
+        this.questionUrlPrefix = questionUrlPrefix;
+    }
+
+}

+ 0 - 64
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/upyun/SystemProperty.java

@@ -1,64 +0,0 @@
-/*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-11-30 15:17:49.
- * *************************************************
- */
-
-package cn.com.qmth.examcloud.core.print.common.upyun;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import java.io.Serializable;
-
-/**
- * 系统配置信息
- *
- * @author: fengdesheng
- * @since: 2018/11/30
- */
-@Component
-public class SystemProperty implements Serializable {
-    private static final long serialVersionUID = 1L;
-    /**
-     * 配置文件环境
-     */
-    @Value("${spring.profiles.active}")
-    private String profile;
-    /**
-     * 文件存放目录
-     */
-    @Value("${examcloud.web.sys.dataDir}")
-    private String dir;
-    /**
-     * 文件存放临时目录
-     */
-    @Value("${examcloud.web.sys.tempDataDir}")
-    private String tempDir;
-
-    public String getDir() {
-        return dir;
-    }
-
-    public void setDir(String dir) {
-        this.dir = dir;
-    }
-
-    public String getTempDir() {
-        return tempDir;
-    }
-
-    public void setTempDir(String tempDir) {
-        this.tempDir = tempDir;
-    }
-
-    public String getProfile() {
-        return profile;
-    }
-
-    public void setProfile(String profile) {
-        this.profile = profile;
-    }
-
-}

+ 11 - 16
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/upyun/UpYunClient.java

@@ -8,10 +8,10 @@
 package cn.com.qmth.examcloud.core.print.common.upyun;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.core.print.common.SysProperty;
 import cn.com.qmth.examcloud.core.print.common.utils.Check;
 import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
 import main.java.com.UpYun;
-import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,9 +30,7 @@ import static cn.com.qmth.examcloud.core.print.common.Constants.SYS_CODE_500;
 public class UpYunClient {
     private static final Logger log = LoggerFactory.getLogger(UpYunClient.class);
     @Autowired
-    private UpYunProperty upYunProperty;
-    @Autowired
-    private SystemProperty systemProperty;
+    private SysProperty sysProperty;
 
     public String upload(File file) {
         Check.isEmpty(file, "上传的文件不能为空!");
@@ -42,11 +40,11 @@ public class UpYunClient {
 
         try {
             final String newFileName = FileUtils.newFileName(file.getName());
-            final String newFilePath = upYunProperty.getUploadUrl() + FileUtils.dateDir() + newFileName;
+            final String newFilePath = sysProperty.getUploadUrl() + FileUtils.dateDir() + newFileName;
             this.getInstance().writeFile(newFilePath, file, true);
 
             //成功后,返回文件访问地址
-            return upYunProperty.getFileUrl() + newFilePath;
+            return this.getUrlPrefix() + newFilePath;
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             throw new StatusException(SYS_CODE_500, "上传文件异常!");
@@ -59,11 +57,11 @@ public class UpYunClient {
 
         try {
             final String newFileName = FileUtils.newFileName(originalFilename);
-            final String newFilePath = upYunProperty.getUploadUrl() + FileUtils.dateDir() + newFileName;
+            final String newFilePath = sysProperty.getUploadUrl() + FileUtils.dateDir() + newFileName;
             this.getInstance().writeFile(newFilePath, bytes, true);
 
             //成功后,返回文件访问地址
-            return upYunProperty.getFileUrl() + newFilePath;
+            return this.getUrlPrefix() + newFilePath;
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             throw new StatusException(SYS_CODE_500, "上传文件异常!");
@@ -73,7 +71,7 @@ public class UpYunClient {
     public File download(String filePath) {
         try {
             //final String rootDir = Constants.rootFileDir();
-            final String rootDir = systemProperty.getTempDir();
+            final String rootDir = sysProperty.getTempDir();
             FileUtils.makeDirs(rootDir);
             final String newFilePath = rootDir + "/" + FileUtils.newFileName(filePath);
             File file = new File(newFilePath);
@@ -86,21 +84,18 @@ public class UpYunClient {
     }
 
     public UpYun getInstance() {
-        UpYun upyun = new UpYun(upYunProperty.getBucketName(), upYunProperty.getUserName(), upYunProperty.getPassword());
+        UpYun upyun = new UpYun(sysProperty.getBucketName(), sysProperty.getUserName(), sysProperty.getPassword());
         upyun.setDebug(true);
         upyun.setApiDomain(UpYun.ED_AUTO);
         return upyun;
     }
 
     public String getUrlPrefix() {
-        if (StringUtils.isNotBlank(upYunProperty.getFileUrl())) {
-            return upYunProperty.getFileUrl();
-        }
-        return "";
+        return sysProperty.getDomain();
     }
 
-    public UpYunProperty getProperty() {
-        return upYunProperty;
+    public SysProperty getProperty() {
+        return sysProperty;
     }
 
 }

+ 0 - 90
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/upyun/UpYunProperty.java

@@ -1,90 +0,0 @@
-/*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-11-01 16:59:28.
- * *************************************************
- */
-
-package cn.com.qmth.examcloud.core.print.common.upyun;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import java.io.Serializable;
-
-/**
- * 又拍云配置信息
- *
- * @author: fengdesheng
- * @since: 2018/11/1
- */
-@Component
-public class UpYunProperty implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Value("${$upyun.site.1.userName}")
-    private String userName;//账号
-
-    @Value("${$upyun.site.1.password}")
-    private String password;//密码
-
-    @Value("${$upyun.site.1.bucketName}")
-    private String bucketName;//存储空间名称
-
-    @Value("${$upyun.site.1.bucketUrl}")
-    private String bucketUrl;//存储空间访问前缀
-
-    @Value("${$upyun.site.1.fileUrl}")
-    private String fileUrl;//文件访问地址前缀
-
-    @Value("${$upyun.site.1.uploadUrl}")
-    private String uploadUrl;//文件存放目录
-
-    public String getUserName() {
-        return userName;
-    }
-
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
-    public String getBucketName() {
-        return bucketName;
-    }
-
-    public void setBucketName(String bucketName) {
-        this.bucketName = bucketName;
-    }
-
-    public String getBucketUrl() {
-        return bucketUrl;
-    }
-
-    public void setBucketUrl(String bucketUrl) {
-        this.bucketUrl = bucketUrl;
-    }
-
-    public String getFileUrl() {
-        return fileUrl;
-    }
-
-    public void setFileUrl(String fileUrl) {
-        this.fileUrl = fileUrl;
-    }
-
-    public String getUploadUrl() {
-        return uploadUrl;
-    }
-
-    public void setUploadUrl(String uploadUrl) {
-        this.uploadUrl = uploadUrl;
-    }
-
-}

+ 8 - 12
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -8,9 +8,9 @@
 package cn.com.qmth.examcloud.core.print.service.impl;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.core.print.common.SysProperty;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
-import cn.com.qmth.examcloud.core.print.common.upyun.SystemProperty;
 import cn.com.qmth.examcloud.core.print.common.upyun.UpYunClient;
 import cn.com.qmth.examcloud.core.print.common.utils.*;
 import cn.com.qmth.examcloud.core.print.entity.*;
@@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -56,13 +55,10 @@ public class CoursePaperServiceImpl implements CoursePaperService {
     @Autowired
     private ExamQuestionStructureService examQuestionStructureService;
     @Autowired
-    private SystemProperty systemProperty;
+    private SysProperty sysProperty;
     @Autowired
     private UpYunClient upYunClient;
 
-    @Value("${$question.url.prefix}")
-    private String QUESTION_URL_PREFIX;//题库访问地址前缀
-
     @Override
     public List<CoursePaperLessInfo> getCoursePaperList(CoursePaperQuery query) {
         Check.isNull(query, "查询参数不能为空!");
@@ -114,8 +110,8 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
         //试卷页面地址和答案页面地址
         //String title = urlParamEncode(coursePaper.getPaperName());
-        final String paperHtmlUrl = QUESTION_URL_PREFIX.concat("/api/ecs_ques/paper/pdf/").concat(coursePaper.getPaperId());
-        final String answerHtmlUrl = QUESTION_URL_PREFIX.concat("/api/ecs_ques/paper/answer/pdf/").concat(coursePaper.getPaperId());
+        final String paperHtmlUrl = sysProperty.getQuestionUrlPrefix().concat("/api/ecs_ques/paper/pdf/").concat(coursePaper.getPaperId());
+        final String answerHtmlUrl = sysProperty.getQuestionUrlPrefix().concat("/api/ecs_ques/paper/answer/pdf/").concat(coursePaper.getPaperId());
 
         CoursePaper oldCoursePaper = coursePaperRepository.findByExamIdAndPaperId(coursePaper.getExamId(), coursePaper.getPaperId());
         if (oldCoursePaper != null) {
@@ -155,7 +151,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
             //将试卷和答案页面转换为PDF文件
             //final String rootDir = Constants.rootFileDir();
-            final String rootDir = systemProperty.getTempDir();
+            final String rootDir = sysProperty.getTempDir();
             final String paperPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
             final String answerPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
             FileUtils.makeDirs(rootDir);
@@ -168,13 +164,13 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
             final String title = String.format("?examName=%s", this.urlParamEncode(printingProject.getExamName()));
 
-            boolean paperResult = ElectronUtils.toPdf(systemProperty.getProfile(), systemProperty.getDir(), coursePaper.getPaperHtmlUrl() + title, paperPdfPath);
+            boolean paperResult = ElectronUtils.toPdf(sysProperty.getProfile(), sysProperty.getDir(), coursePaper.getPaperHtmlUrl() + title, paperPdfPath);
             if (!paperResult) {
                 log.warn(String.format("试卷页面转换PDF文件失败!paperId = %s", coursePaper.getPaperId()));
                 continue;
             }
 
-            boolean answerResult = ElectronUtils.toPdf(systemProperty.getProfile(), systemProperty.getDir(), coursePaper.getAnswerHtmlUrl() + title, answerPdfPath);
+            boolean answerResult = ElectronUtils.toPdf(sysProperty.getProfile(), sysProperty.getDir(), coursePaper.getAnswerHtmlUrl() + title, answerPdfPath);
             if (!answerResult) {
                 log.warn(String.format("答案页面转换PDF文件失败!paperId = %s", coursePaper.getPaperId()));
                 continue;
@@ -478,7 +474,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
         //文件存放目录
         //final String targetDir = Constants.rootFileDir() + "/" + FileUtils.randomUUID();
-        final String targetDir = systemProperty.getTempDir() + "/" + FileUtils.randomUUID();
+        final String targetDir = sysProperty.getTempDir() + "/" + FileUtils.randomUUID();
         FileUtils.makeDirs(targetDir);
 
         //优先处理试卷或答案文件(需要网络下载)

+ 4 - 4
examcloud-core-print-starter/src/main/java/cn/com/qmth/examcloud/core/print/controller/IndexController.java

@@ -7,7 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.controller;
 
-import cn.com.qmth.examcloud.core.print.common.upyun.SystemProperty;
+import cn.com.qmth.examcloud.core.print.common.SysProperty;
 import cn.com.qmth.examcloud.core.print.common.utils.ElectronUtils;
 import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
@@ -33,7 +33,7 @@ public class IndexController {
     @Autowired
     private PrintingProjectService printingProjectService;
     @Autowired
-    private SystemProperty systemProperty;
+    private SysProperty sysProperty;
 
     @Naked
     @ResponseBody
@@ -48,12 +48,12 @@ public class IndexController {
     @ResponseBody
     @RequestMapping(value = "/test", method = RequestMethod.GET)
     public void demo() {
-        final String rootDir = systemProperty.getTempDir();
+        final String rootDir = sysProperty.getTempDir();
         FileUtils.makeDirs(rootDir);
 
         String targetUrl = "https://www.baidu.com";
         String pdfPath = rootDir + "/test.pdf";
-        ElectronUtils.toPdf(systemProperty.getProfile(), systemProperty.getDir(), targetUrl, pdfPath);
+        ElectronUtils.toPdf(sysProperty.getProfile(), sysProperty.getDir(), targetUrl, pdfPath);
     }
 
 }