Преглед изворни кода

修改打印任务的执行方式

zhoupeng пре 1 година
родитељ
комит
01f862d2c3

+ 3 - 2
industry-admin/src/views/report/runConfig/timeConfig.vue

@@ -6,7 +6,8 @@
                 <el-form-item label="报表名称" prop="reportTableName">
                     <el-input placeholder="请输入报表名称" v-model="reportForm.reportTableName" maxlength="20"></el-input>
                 </el-form-item>
-                <el-radio-group v-model="radioByCron" v-if="reportForm.reportTableType == 1">
+                <el-radio-group v-model="radioByCron"
+                    v-if="reportForm.reportTableType == 1 || reportForm.reportTableType == 5">
                     <el-form-item label="分钟">
                         <el-radio :label="2">
                             <span style="margin-right: 10px">每</span>
@@ -230,7 +231,7 @@ export default {
         },
         /** 提交报表配置 */
         saveReportConfig() {
-            if (this.reportForm.reportTableType == 1) {
+            if (this.reportForm.reportTableType == 1 || this.reportForm.reportTableType == 5) {
                 this.reportForm.cron = this.generateCron()
                 if (!this.reportForm.cron) {
                     this.$message({

+ 21 - 11
industry-system/industry-da/src/main/java/com/example/opc_da/task/AsyncTask.java

@@ -21,8 +21,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.RequestParam;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
+import javax.validation.constraints.NotNull;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -76,20 +75,20 @@ public class AsyncTask {
     }
 
     /**
-     * 通过主报表,生成子报表,生成子报表的时候不生成reportTableData
+     * 通过主报表,生成子报表。
      *
      * @param mainReportId 主报表id
      * @param chReportId   子报表id
      * @param chReportType 子报表类型
-     * @param sum          当前数量
+     * @param isPrint      方法是否打印
      */
-    public void addHaveKeyChReport(String mainReportId, String chReportId, Integer chReportType, String chReportData, Integer sum) {
+    public void addHaveKeyChReport(String mainReportId, String chReportId, Integer chReportType, String chReportData, @NotNull Boolean isPrint) {
         Date date = new Date();
         ReportTable mainReportTable = reportTableDao.getReportTableById(mainReportId);
         ReportTable chReportTable = new ReportTable(chReportId,
                 chReportType, mainReportTable.getTableTemplateId(), mainReportTable.getUserId(),
                 mainReportTable.getReportTableName() + "_" + DateUtil.dateChangeStr(date, "yyyyMMddHHmmss"),
-                chReportData, sum, mainReportTable.getVersion(), new Date()
+                chReportData, null, mainReportTable.getVersion(), new Date()
         );
         reportTableDao.addHaveKeyReport(chReportTable);
         //添加新的子报表的日志和用户组(使用异步节约时间)
@@ -100,6 +99,14 @@ public class AsyncTask {
         if (Blank.isNotEmpty(userGroupList)) {
             reportTableDao.addTableUserGroup(chReportId, userGroupList);
         }
+        //是否执行打印
+        if (isPrint) {
+            Integer isRunPrint = mainReportTable.getIsRunPrint();
+            if (isRunPrint != null && isRunPrint == 1) {
+                //执行打印服务
+                runPrint(chReportId, mainReportTable.getPrintIp(), mainReportTable.getPrintConfigId());
+            }
+        }
     }
 
     /**
@@ -129,16 +136,19 @@ public class AsyncTask {
      * @param printConfigId 打印配置id
      */
     public void runPrint(@RequestParam String reportTableId, @RequestParam String printIp, @RequestParam Integer printConfigId) {
-        log.info("异步打印开始执行,执行时间为:{}", DateUtil.dateChangeStrYmdhmss(new Date()));
-        log.info("打印的报表id为{},请求的打印机ip为{}", reportTableId, printIp);
+        log.info("打印开始执行,时间为{},打印的报表id为{},请求的打印机ip为{}", DateUtil.dateChangeStrYmdhmss(new Date()), reportTableId, printIp);
 
         //获取打印机配置
         PrintConfig printConfig = printDao.getPrintConfigById(printConfigId);
         //生成报表请求地址
-        String url = "http://localhost:8084/cy-sheet-ss/index.html?id=" + reportTableId;
+        String url = "http://localhost:8081/reportSheet/report-history.html?id=" + reportTableId;
+        url += "&printType=task&serverUrl=http://localhost:8081&clientIP=" + printIp;
+        url += "&printConfig=" + JSONObject.toJSONString(printConfig);
+//        String url = "http://localhost:8084/cy-sheet-ss/index.html?id=" + reportTableId;
         try {
-            HttpUtil.post("http://" + printIp + ":8084" + printUrl + "?excelUrl=" + URLEncoder.encode(url, "UTF-8") + "&printConfig=" + JSONObject.toJSONString(printConfig), new HashMap<>());
-        } catch (UnsupportedEncodingException e) {
+//            HttpUtil.post("http://" + printIp + ":8084" + printUrl + "?excelUrl=" + URLEncoder.encode(url, "UTF-8") + "&printConfig=" + JSONObject.toJSONString(printConfig), new HashMap<>());
+            HttpUtil.get(url, new HashMap<>());
+        } catch (Exception e) {
             String message = e.getMessage();
             if (message.contains("Connection timed out: connect")) {
                 throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "连接打印机超时");

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/task/AutoTableQuartzTask.java

@@ -35,7 +35,7 @@ public class AutoTableQuartzTask extends QuartzJobBean {
         asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.AUTOMATIC_GENERATE_REPORT,
                 ReportTableValidateFactory.getReportTableValidate(
                         reportTable.getReportTableType()
-                ).getData(newReportTable).getReportTableData(), null);
+                ).getData(newReportTable).getReportTableData(), true);
         log.info("自动报表,{},执行结束,时间为{}", reportTable, DateUtil.dateChangeStrYmdhmss(new Date()));
     }
 }

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/task/AutoTableTimerTask.java

@@ -32,7 +32,7 @@ public class AutoTableTimerTask extends PeriodTimerTask {
         asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.AUTOMATIC_GENERATE_REPORT,
                 ReportTableValidateFactory.getReportTableValidate(
                         reportTable.getReportTableType()
-                ).getData(newReportTable).getReportTableData(), null);
+                ).getData(newReportTable).getReportTableData(), true);
         log.info("自动报表,{},执行结束,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
     }
 }