|
@@ -1,29 +1,50 @@
|
|
package org.jeecg.modules.admin_order.service.impl;
|
|
package org.jeecg.modules.admin_order.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.thread.ThreadFactoryBuilder;
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
|
+import cn.hutool.json.JSON;
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.jeecg.modules.admin.entity.AdminPlatform;
|
|
|
|
+import org.jeecg.modules.admin.service.IAdminPlatformService;
|
|
import org.jeecg.modules.admin_aircraft_position.entity.AdminAircraftPosition;
|
|
import org.jeecg.modules.admin_aircraft_position.entity.AdminAircraftPosition;
|
|
import org.jeecg.modules.admin_aircraft_position.service.IAdminAircraftPositionService;
|
|
import org.jeecg.modules.admin_aircraft_position.service.IAdminAircraftPositionService;
|
|
|
|
+import org.jeecg.modules.admin_file_export.entity.AdminFileExport;
|
|
|
|
+import org.jeecg.modules.admin_file_export.service.IAdminFileExportService;
|
|
import org.jeecg.modules.admin_order.entity.AdminOrder;
|
|
import org.jeecg.modules.admin_order.entity.AdminOrder;
|
|
import org.jeecg.modules.admin_order.entity.AdminOrderExamine;
|
|
import org.jeecg.modules.admin_order.entity.AdminOrderExamine;
|
|
|
|
+import org.jeecg.modules.admin_order.entity.AdminOrderExamine2;
|
|
import org.jeecg.modules.admin_order.mapper.AdminOrderExamineMapper;
|
|
import org.jeecg.modules.admin_order.mapper.AdminOrderExamineMapper;
|
|
import org.jeecg.modules.admin_order.mapper.AdminOrderMapper;
|
|
import org.jeecg.modules.admin_order.mapper.AdminOrderMapper;
|
|
import org.jeecg.modules.admin_order.service.IAdminOrderExamineService;
|
|
import org.jeecg.modules.admin_order.service.IAdminOrderExamineService;
|
|
import org.jeecg.modules.admin_order.service.IAdminOrderService;
|
|
import org.jeecg.modules.admin_order.service.IAdminOrderService;
|
|
import org.jeecg.modules.admin_security_check.entity.AdminSecurityCheck;
|
|
import org.jeecg.modules.admin_security_check.entity.AdminSecurityCheck;
|
|
import org.jeecg.modules.admin_security_check.service.IAdminSecurityCheckService;
|
|
import org.jeecg.modules.admin_security_check.service.IAdminSecurityCheckService;
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import org.jeecg.modules.api.AddWatermarkToPDF;
|
|
|
|
+import org.jeecg.modules.api.HtmlToPdf;
|
|
|
|
+import org.jeecg.modules.utils.AirportUtil;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
+import org.thymeleaf.TemplateEngine;
|
|
|
|
+import org.thymeleaf.context.Context;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileWriter;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 订单管理
|
|
* @Description: 订单管理
|
|
@@ -44,6 +65,21 @@ public class AdminOrderServiceImpl extends ServiceImpl<AdminOrderMapper, AdminOr
|
|
@Autowired
|
|
@Autowired
|
|
private IAdminSecurityCheckService adminSecurityCheckService;
|
|
private IAdminSecurityCheckService adminSecurityCheckService;
|
|
|
|
|
|
|
|
+ @Value("${airport.system.host:http://120.79.86.50:9999/airport}")
|
|
|
|
+ private String systemHost;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAdminFileExportService adminFileExportService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAdminOrderExamineService adminOrderExamineService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAdminPlatformService adminPlatformService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TemplateEngine templateEngine;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public void saveMain(AdminOrder adminOrder, List<AdminOrderExamine> adminOrderExamineList) {
|
|
public void saveMain(AdminOrder adminOrder, List<AdminOrderExamine> adminOrderExamineList) {
|
|
@@ -100,8 +136,8 @@ public class AdminOrderServiceImpl extends ServiceImpl<AdminOrderMapper, AdminOr
|
|
adminAircaftQueryWarpper
|
|
adminAircaftQueryWarpper
|
|
//.eq("aircraft_position_num", adminOrder.getAircraftPositionNum())
|
|
//.eq("aircraft_position_num", adminOrder.getAircraftPositionNum())
|
|
.eq("aircraft_num", adminOrder.getAircraftNum())
|
|
.eq("aircraft_num", adminOrder.getAircraftNum())
|
|
- //.eq("drop_time", adminOrder.getDropTime())
|
|
|
|
- //.eq("flight_num", adminOrder.getFlightNum())
|
|
|
|
|
|
+ //.eq("drop_time", adminOrder.getDropTime())
|
|
|
|
+ //.eq("flight_num", adminOrder.getFlightNum())
|
|
;
|
|
;
|
|
AdminAircraftPosition adminAircraftPosition = adminAircraftPositionService.getOne(adminAircaftQueryWarpper);
|
|
AdminAircraftPosition adminAircraftPosition = adminAircraftPositionService.getOne(adminAircaftQueryWarpper);
|
|
if (adminAircraftPosition == null || Strings.isNullOrEmpty(adminAircraftPosition.getAircraftNum())) {
|
|
if (adminAircraftPosition == null || Strings.isNullOrEmpty(adminAircraftPosition.getAircraftNum())) {
|
|
@@ -158,4 +194,247 @@ public class AdminOrderServiceImpl extends ServiceImpl<AdminOrderMapper, AdminOr
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean addExportPdfFilesTask(List<String> orderIdList) {
|
|
|
|
+ String folderName = String.valueOf(DateUtils.getCurrentTimestamp());
|
|
|
|
+
|
|
|
|
+ // 添加导出任务
|
|
|
|
+ AdminFileExport adminFileExport = new AdminFileExport();
|
|
|
|
+ adminFileExport.setName(folderName + ".zip");
|
|
|
|
+ adminFileExport.setExportType("AdminOrderList");
|
|
|
|
+ adminFileExport.setExportStatus("0");
|
|
|
|
+ adminFileExport.setExportParam(JSONUtil.toJsonStr(orderIdList));
|
|
|
|
+ boolean save = adminFileExportService.save(adminFileExport);
|
|
|
|
+ if (save) {
|
|
|
|
+ // 创建线程生成文件
|
|
|
|
+ ThreadUtil.execAsync(() -> {
|
|
|
|
+ // 生成文件
|
|
|
|
+ generateZipFile(adminFileExport);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return save;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean reExportPdfFilesTask(String id) {
|
|
|
|
+ AdminFileExport adminFileExport = adminFileExportService.getById(id);
|
|
|
|
+ if (adminFileExport != null) {
|
|
|
|
+ adminFileExport.setExportStatus("0");
|
|
|
|
+ boolean save = adminFileExportService.saveOrUpdate(adminFileExport);
|
|
|
|
+ if (save) {
|
|
|
|
+ // 创建线程生成文件
|
|
|
|
+ ThreadUtil.execAsync(() -> {
|
|
|
|
+ // 生成文件
|
|
|
|
+ generateZipFile(adminFileExport);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成zip文件
|
|
|
|
+ *
|
|
|
|
+ * @param adminFileExport
|
|
|
|
+ */
|
|
|
|
+ private synchronized void generateZipFile(AdminFileExport adminFileExport) {
|
|
|
|
+ // 文件夹名称
|
|
|
|
+ String folderName = createFolder(adminFileExport);
|
|
|
|
+ // 输出的文件夹
|
|
|
|
+ String outputFolder = AirportUtil.getLocalUploadTempPath() + "/" + folderName;
|
|
|
|
+ File outputFolderFile = new File(outputFolder);
|
|
|
|
+ if (!outputFolderFile.exists()) {
|
|
|
|
+ outputFolderFile.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ // 生成文件
|
|
|
|
+ String exportParam = adminFileExport.getExportParam();
|
|
|
|
+ if (Strings.isNullOrEmpty(exportParam) || "[]".equals(exportParam)) {
|
|
|
|
+ // 参数是空的
|
|
|
|
+ File file1 = new File(AirportUtil.getLocalUploadTempPath() + "/" + adminFileExport.getName());
|
|
|
|
+ if (!file1.exists()) {
|
|
|
|
+ file1.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ adminFileExport.setFileNum(0);
|
|
|
|
+ adminFileExport.setFileSize(0L);
|
|
|
|
+ adminFileExport.setExportStatus("2");
|
|
|
|
+ adminFileExport.setExportDesc("没有选择要导出的订单");
|
|
|
|
+ adminFileExport.setUrl(systemHost + "/sys/common/static/tempFile/" + adminFileExport.getName());
|
|
|
|
+ adminFileExportService.saveOrUpdateNoInfo(adminFileExport);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(exportParam);
|
|
|
|
+ List<String> orderIdList = jsonArray.toList(String.class);
|
|
|
|
+ // 生成zip文件中的内容
|
|
|
|
+ List<String> genFileNameList = generatePdfFileByOrderList(orderIdList, outputFolder);
|
|
|
|
+ // 生成zip文件
|
|
|
|
+ File zip = ZipUtil.zip(outputFolder);
|
|
|
|
+ adminFileExport.setFileNum(genFileNameList.size());
|
|
|
|
+ adminFileExport.setFileSize(zip.length());
|
|
|
|
+ adminFileExport.setUrl(systemHost + "/sys/common/static/tempFile/" + adminFileExport.getName());
|
|
|
|
+ if (orderIdList.size() == genFileNameList.size()) {
|
|
|
|
+ adminFileExport.setExportDesc("已完成导出");
|
|
|
|
+ adminFileExport.setExportStatus("1");
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ if (genFileNameList.size() == 0) {
|
|
|
|
+ adminFileExport.setExportStatus("2");
|
|
|
|
+ } else {
|
|
|
|
+ adminFileExport.setExportStatus("1");
|
|
|
|
+ }
|
|
|
|
+ adminFileExport.setExportDesc("共" + orderIdList.size() + "个订单," + (orderIdList.size() - genFileNameList.size()) + "个未找到数据");
|
|
|
|
+ }
|
|
|
|
+ adminFileExportService.saveOrUpdateNoInfo(adminFileExport);
|
|
|
|
+ // 删除多余文件
|
|
|
|
+ FileUtil.del(outputFolderFile);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据订单列表向指定文件夹中生成pdf文件
|
|
|
|
+ *
|
|
|
|
+ * @param orderIdList
|
|
|
|
+ * @param outputFolder
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<String> generatePdfFileByOrderList(List<String> orderIdList, String outputFolder) {
|
|
|
|
+ if (orderIdList == null || orderIdList.isEmpty()) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ ArrayList<String> genFileNameList = new ArrayList<>();
|
|
|
|
+ for (String orderId : orderIdList) {
|
|
|
|
+ String fileName = generatePdfFile(orderId, outputFolder);
|
|
|
|
+ if (Strings.isNullOrEmpty(fileName)) continue;
|
|
|
|
+ genFileNameList.add(fileName);
|
|
|
|
+ }
|
|
|
|
+ return genFileNameList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String generatePdfFile(String id, String path) {
|
|
|
|
+ String fileName = "";
|
|
|
|
+ String fileNameQ = "";
|
|
|
|
+ String fileNameHtml = "";
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ QueryWrapper<AdminOrderExamine> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("order_id", id);
|
|
|
|
+ List<AdminOrderExamine> list = adminOrderExamineService.list(queryWrapper);
|
|
|
|
+ if (list.size() == 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ AdminOrder byId = this.getById(id);
|
|
|
|
+
|
|
|
|
+ //fileNameQ = id + "_" + System.currentTimeMillis();
|
|
|
|
+ fileNameQ = yyyyMMdd.format(byId.getCreateTime()) + "-" + byId.getAircraftNum();
|
|
|
|
+ fileName = fileNameQ + ".pdf";
|
|
|
|
+ fileNameHtml = fileNameQ + ".html";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String outputFolder = path + "/" + fileName;
|
|
|
|
+ String outputFolderHtml = path + "/" + fileNameHtml;
|
|
|
|
+
|
|
|
|
+ //获取水印
|
|
|
|
+ List<AdminPlatform> adminPlatformList = adminPlatformService.list();
|
|
|
|
+ AdminPlatform adminPlatform = adminPlatformList.get(0);
|
|
|
|
+
|
|
|
|
+ Context context = new Context();
|
|
|
|
+ //订单号
|
|
|
|
+ context.setVariable("OrderNum", byId.getOrderNum());
|
|
|
|
+ //飞机号
|
|
|
|
+ context.setVariable("AircraftNum", byId.getAircraftNum());
|
|
|
|
+ //航班号
|
|
|
|
+ context.setVariable("FlightNum", byId.getFlightNum());
|
|
|
|
+ //落地机位
|
|
|
|
+ context.setVariable("AircraftPositionNum", byId.getAircraftPositionNum());
|
|
|
|
+
|
|
|
|
+// context.setVariable( "sy", "temp/sy.png" );
|
|
|
|
+ //创建时间
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ context.setVariable("Time", sdf.format(byId.getCreateTime()));
|
|
|
|
+// context.setVariable( "order", byId );
|
|
|
|
+ //阶段数据
|
|
|
|
+ List<AdminOrderExamine2> list2 = new ArrayList<>();
|
|
|
|
+ for (AdminOrderExamine main : list) {
|
|
|
|
+ AdminOrderExamine2 vo = new AdminOrderExamine2();
|
|
|
|
+ BeanUtils.copyProperties(main, vo);
|
|
|
|
+ String[] arrPic = main.getPic().split(",");
|
|
|
|
+ String[] arrExamineYes = main.getExamineYes().split(",");
|
|
|
|
+ vo.setPic(arrPic);
|
|
|
|
+ vo.setExamineYes(arrExamineYes);
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ context.setVariable("date", list2);
|
|
|
|
+ context.setVariable("SystemHost", systemHost);
|
|
|
|
+
|
|
|
|
+ String htmlStr = templateEngine.process("template", context);
|
|
|
|
+
|
|
|
|
+// // 创建一个新的HTML文件
|
|
|
|
+ FileWriter writer = new FileWriter(outputFolderHtml);
|
|
|
|
+ // 写入HTML代码
|
|
|
|
+ writer.write(htmlStr);
|
|
|
|
+ // 关闭文件写入器
|
|
|
|
+ writer.close();
|
|
|
|
+ HtmlToPdf.convert(outputFolderHtml, outputFolder);
|
|
|
|
+ // 删除html文件
|
|
|
|
+ File htmlFile = new File(outputFolderHtml);
|
|
|
|
+ if (htmlFile.exists()) {
|
|
|
|
+ htmlFile.delete();
|
|
|
|
+ }
|
|
|
|
+ Date qifeiTime = byId.getQifeiTime();
|
|
|
|
+ if (qifeiTime == null) {
|
|
|
|
+ if ("交接结束".equals(byId.getType())) {
|
|
|
|
+ qifeiTime = byId.getUpdateTime();
|
|
|
|
+ } else {
|
|
|
|
+ qifeiTime = byId.getUpdateTime();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ long after24HoursInMillis = qifeiTime.getTime() + 24 * 60 * 60 * 1000; // 将毫秒数增加 24 小时
|
|
|
|
+ Date after24Hours = new Date(after24HoursInMillis);
|
|
|
|
+ if (after24Hours.before(new Date())) {
|
|
|
|
+ //打印加水印
|
|
|
|
+ AddWatermarkToPDF.convert(fileName, adminPlatform.getSy(),path);
|
|
|
|
+ // 删除旧文件
|
|
|
|
+ File oldFile = new File(outputFolder);
|
|
|
|
+ if (oldFile.exists()) {
|
|
|
|
+ oldFile.delete();
|
|
|
|
+ }
|
|
|
|
+ return "sy_" + fileName;
|
|
|
|
+ } else {
|
|
|
|
+ return fileName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建存放 zip中的文件的文件夹
|
|
|
|
+ * 如果名称为空则补全
|
|
|
|
+ *
|
|
|
|
+ * @param adminFileExport
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String createFolder(AdminFileExport adminFileExport) {
|
|
|
|
+ String name = adminFileExport.getName();
|
|
|
|
+ String folderName;
|
|
|
|
+ if (!Strings.isNullOrEmpty(name)) {
|
|
|
|
+ if (name.contains(".")) {
|
|
|
|
+ String[] split = name.split("\\.");
|
|
|
|
+ folderName = split[0];
|
|
|
|
+ } else {
|
|
|
|
+ folderName = name;
|
|
|
|
+ adminFileExport.setName(folderName + ".zip");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //名字是空的
|
|
|
|
+ folderName = String.valueOf(DateUtils.getCurrentTimestamp());
|
|
|
|
+ adminFileExport.setName(folderName + ".zip");
|
|
|
|
+ }
|
|
|
|
+ return folderName;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|