deason 6 năm trước cách đây
mục cha
commit
f1c5700409

+ 103 - 0
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/utils/ElectronUtils.java

@@ -0,0 +1,103 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-11-28 16:17:55.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.common.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/11/28
+ */
+public class ElectronUtils {
+    private static final Logger log = LoggerFactory.getLogger(ElectronUtils.class);
+    private static final String WIN_PREFIX = "cmd /c ";
+
+    /**
+     * 将URL响应内容转为PDF文件
+     */
+    public static boolean toPdf(String url, String path) {
+        if (StringUtils.isBlank(url) || StringUtils.isBlank(path)) {
+            return false;
+        }
+
+        String cmd = String.format("electron-pdf %s %s -p A3 -l true -e view-ready", url, path);
+        if (isWindows()) {
+            cmd = WIN_PREFIX + cmd;
+        }
+
+        return executeCommand(cmd);
+    }
+
+    /**
+     * 执行命令
+     */
+    private static boolean executeCommand(String cmd) {
+        Process process;
+
+        try {
+            process = Runtime.getRuntime().exec(cmd);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            return false;
+        }
+
+        String charsetName = "UTF-8";
+        if (isWindows()) {
+            charsetName = "GBK";
+        }
+
+        try (BufferedReader out = new BufferedReader(new InputStreamReader(process.getInputStream(), charsetName));
+             BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream(), charsetName));) {
+
+            String outStr;
+            while ((outStr = out.readLine()) != null) {
+                log.debug(outStr);
+            }
+
+            String errStr;
+            while ((errStr = err.readLine()) != null) {
+                log.debug("err:" + errStr);
+            }
+
+            int exitCode = process.waitFor();
+            if (exitCode == 0) {
+                log.debug("Execute Command Success.");
+                return true;
+            }
+
+            log.warn("Execute Command Error. exitCode:" + exitCode);
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+        } catch (InterruptedException e) {
+            log.error(e.getMessage(), e);
+        } finally {
+            if (process != null) {
+                process.destroy();
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 判断是否为Windows系统
+     */
+    private static boolean isWindows() {
+        String os = System.getProperty("os.name").toLowerCase();
+        if (os.contains("windows") || os.startsWith("win")) {
+            return true;
+        }
+        return false;
+    }
+
+}

+ 33 - 24
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/StatisticServiceImpl.java

@@ -17,10 +17,11 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamPaperTypeRelation;
 import cn.com.qmth.examcloud.examwork.api.request.CountExamStudentReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCoursePaperTypeListReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamOrgListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamStudentPropertyValueListReq;
 import cn.com.qmth.examcloud.examwork.api.response.CountExamStudentResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamCoursePaperTypeListResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamOrgListResp;
-import com.google.common.collect.Lists;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentPropertyValueListResp;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -126,31 +127,18 @@ public class StatisticServiceImpl implements StatisticService {
 
     @Override
     public List<String> findExamPackageCodes(Long orgId, Long examId) {
-        //todo
-        return Lists.newArrayList("abc");
+        GetExamStudentPropertyValueListReq req = new GetExamStudentPropertyValueListReq();
+        req.setExamId(examId);
+        req.setPropertyName("ext1");//试卷袋编号字段
+        return this.findExamStudentProperties(req);
     }
 
     @Override
     public List<String> findExamSites(Long examId) {
-        List<String> sites = new ArrayList<>();
-        GetExamOrgListReq req = new GetExamOrgListReq();
+        GetExamStudentPropertyValueListReq req = new GetExamStudentPropertyValueListReq();
         req.setExamId(examId);
-        Long start = 0L;
-        while (true) {
-            req.setStart(start);
-            GetExamOrgListResp resp = examCloudService.getExamOrgList(req);
-            List<Long> list = resp.getOrgIdList();
-            if (list == null || list.isEmpty()) {
-                break;
-            }
-            //sites.addAll(list);
-            if (start.equals(resp.getNext())) {
-                break;
-            } else {
-                start = resp.getNext();
-            }
-        }
-        return sites;
+        req.setPropertyName("examSite");//考点字段
+        return this.findExamStudentProperties(req);
     }
 
     @Override
@@ -187,7 +175,7 @@ public class StatisticServiceImpl implements StatisticService {
     public int countExamTotalStudentByPackageCode(Long examId, String packageCode) {
         CountExamStudentReq req = new CountExamStudentReq();
         req.setExamId(examId);
-        //todo
+        req.setExt1(packageCode);//试卷袋编号
         return this.countExamTotalStudent(req);
     }
 
@@ -195,7 +183,7 @@ public class StatisticServiceImpl implements StatisticService {
     public int countExamTotalStudentByLearnCenter(Long examId, Long learnCenterId) {
         CountExamStudentReq req = new CountExamStudentReq();
         req.setExamId(examId);
-        req.setOrgId(learnCenterId);
+        req.setOrgId(learnCenterId);//学习中心
         return this.countExamTotalStudent(req);
     }
 
@@ -203,7 +191,7 @@ public class StatisticServiceImpl implements StatisticService {
     public int countExamTotalStudentBySite(Long examId, String site) {
         CountExamStudentReq req = new CountExamStudentReq();
         req.setExamId(examId);
-        req.setExamSite(site);
+        req.setExamSite(site);//考点
         return this.countExamTotalStudent(req);
     }
 
@@ -212,4 +200,25 @@ public class StatisticServiceImpl implements StatisticService {
         return resp.getCount().intValue();
     }
 
+    private List<String> findExamStudentProperties(GetExamStudentPropertyValueListReq req) {
+        List<String> properties = new ArrayList<>();
+        String start = "";
+        while (true) {
+            req.setStart(start);
+            GetExamStudentPropertyValueListResp resp = examCloudService.getExamStudentPropertyValueList(req);
+            List<String> list = resp.getValueList();
+            if (list == null || list.isEmpty()) {
+                break;
+            }
+            properties.addAll(list);
+            String last = list.get(list.size() - 1);
+            if (start.equals(last)) {
+                break;
+            } else {
+                start = last;
+            }
+        }
+        return properties;
+    }
+
 }