diff --git a/hzims-service/ticket/lib/aspose-words-15.8.0-jdk16.jar b/hzims-service/ticket/lib/aspose-words-15.8.0-jdk16.jar new file mode 100644 index 0000000..c0e699f Binary files /dev/null and b/hzims-service/ticket/lib/aspose-words-15.8.0-jdk16.jar differ diff --git a/hzims-service/ticket/pom.xml b/hzims-service/ticket/pom.xml index 40afd83..5bf9e3d 100644 --- a/hzims-service/ticket/pom.xml +++ b/hzims-service/ticket/pom.xml @@ -102,6 +102,13 @@ + + com.aspose + aspose-words + 15.8.0 + system + ${project.basedir}/lib/aspose-words-15.8.0-jdk16.jar + org.springblade diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java index a9a142c..17d49c9 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java @@ -1,8 +1,10 @@ package com.hnac.hzims.ticket.twoTicket.controller; +import cn.afterturn.easypoi.word.WordExportUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.google.common.collect.Lists; import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService; import com.hnac.hzims.ticket.workTicket.dto.TicketAccessTaskDto; import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; @@ -12,6 +14,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -19,7 +22,10 @@ import org.springblade.core.tool.api.R; import org.springblade.flow.core.vo.ComleteTask; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; import java.time.YearMonth; +import java.util.HashMap; +import java.util.Map; /** * @author hx @@ -110,4 +116,11 @@ public class FirstWorkTicketController extends BladeController { public void preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) { firstWorkTicketService.preview(ticketType,ticketId); } + + @GetMapping("/exportFirstTicket") + @ApiOperation(value = "导出第一种工作票") + @ApiOperationSupport(order = 12) + public void exportFirstTicket(HttpServletResponse response,@RequestParam Long ticketId) throws Exception { + firstWorkTicketService.preview(response,ticketId); + } } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/IFirstWorkTicketService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/IFirstWorkTicketService.java index 0044a93..f6bc5ec 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/IFirstWorkTicketService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/IFirstWorkTicketService.java @@ -11,6 +11,7 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.flow.core.vo.ComleteTask; +import javax.servlet.http.HttpServletResponse; import java.time.LocalDateTime; import java.time.YearMonth; import java.time.format.DateTimeFormatter; @@ -75,6 +76,12 @@ public interface IFirstWorkTicketService extends ITwoTicketService params = new HashMap(){{ + put("projectName","海南三亚一级站"); + put("code","GY-D2-2311--004"); + put("principalName","杨汪洋"); + put("classGroupName","白班"); + put("classGroupMembersName","吴先强,唐钰,彭晨洋,黄兴,肖璐"); + put("totalPerson","5"); + put("addressEquName","#1变压器出线-三洪奇"); + put("workContent","#29电池舱第四簇高压箱"); + put("ps_year","2023"); + put("ps_month","11"); + put("ps_day","11"); + put("ps_hour","16"); + put("ps_minuter","45"); + put("pe_year","2023"); + put("pe_month","11"); + put("pe_day","12"); + put("pe_hour","11"); + put("pe_minuter","13"); + put("matterLibraryListOne", Lists.newArrayList(measure,measure,measure,measure,measure,measure,measure,measure)); + put("signerName","杨汪洋"); + put("s_year","2023"); + put("s_month","11"); + put("s_day","12"); + put("s_hour","11"); + put("s_minuter","13"); + put("jobReceiver","杨汪洋"); + put("r_year","2023"); + put("r_month","11"); + put("r_day","12"); + put("r_hour","11"); + put("r_minuter","13"); + put("l_year","2023"); + put("l_month","11"); + put("l_day","12"); + put("l_hour","11"); + put("l_minuter","13"); + put("licensorName","杨汪洋"); + put("principalName1","杨汪洋"); + }}; + try { + response.setHeader("content-disposition", "attachment;filename=" + new String("电气第一种工作票模版新.docx".getBytes(), "ISO8859-1")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + XWPFDocument xwpfDocument = null; + try { + xwpfDocument = WordExportUtil.exportWord07("template/电气第一种工作票模版新.docx", params); + } catch (Exception e) { + throw new RuntimeException(e); + } + try { + xwpfDocument.write(response.getOutputStream()); + } catch (IOException e) { + throw new RuntimeException(e); + } + String wordPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".docx"; + String pdfPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".pdf"; + // String pdfPath = pdfSavePath + "/" + params.get("code") + "_" + params.get("addressEquName") +".pdf"; + FileOutputStream outputStream = null; + try { + outputStream = new FileOutputStream(wordPath); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + try { + xwpfDocument.write(outputStream); + } + catch(Exception e) { + e.printStackTrace(); + } + finally { + try { + outputStream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + AsposeUtil.wordToPdf(wordPath,pdfPath); + } + + @Override public R evaluation(Integer isPass, Long ticketId, String reason) { return null; } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/AsposeUtil.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/AsposeUtil.java new file mode 100644 index 0000000..1291c48 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/AsposeUtil.java @@ -0,0 +1,49 @@ +package com.hnac.hzims.ticket.utils; + +import cn.hutool.system.SystemUtil; +import com.aspose.words.Document; +import com.aspose.words.FontSettings; +import com.aspose.words.License; +import com.aspose.words.SaveFormat; +import lombok.SneakyThrows; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; + +public class AsposeUtil { + /** + * 加载license 用于破解 不生成水印 + * + * @author LCheng + * @date 2020/12/25 13:51 + */ + @SneakyThrows + private static void getLicense() { + try (InputStream is = AsposeUtil.class.getClassLoader().getResourceAsStream("License.xml")) { + License license = new License(); + license.setLicense(is); + } + } + + /** + * word转pdf + * + * @param wordPath word文件保存的路径 + * @param pdfPath 转换后pdf文件保存的路径 + * @author LCheng + * @date 2020/12/25 13:51 + */ + @SneakyThrows + public static void wordToPdf(String wordPath, String pdfPath) { + getLicense(); + File file = new File(pdfPath); + try (FileOutputStream os = new FileOutputStream(file)) { + if(SystemUtil.getOsInfo().isLinux()) { + FontSettings.setFontsFolder("/usr/share/fonts/chinese", true); + } + Document doc = new Document(wordPath); + doc.save(os, SaveFormat.PDF); + } + } +} diff --git a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx new file mode 100644 index 0000000..e69de29