|
@@ -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(), "连接打印机超时");
|