Browse Source

# 第一种工作票预览

zhongwei
haungxing 1 year ago
parent
commit
491b133c5f
  1. BIN
      hzims-service/ticket/lib/aspose-words-15.8.0-jdk16.jar
  2. 7
      hzims-service/ticket/pom.xml
  3. 13
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java
  4. 7
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/IFirstWorkTicketService.java
  5. 97
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java
  6. 49
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/AsposeUtil.java
  7. 0
      hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx

BIN
hzims-service/ticket/lib/aspose-words-15.8.0-jdk16.jar

Binary file not shown.

7
hzims-service/ticket/pom.xml

@ -102,6 +102,13 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.8.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aspose-words-15.8.0-jdk16.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>

13
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; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; 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.twoTicket.service.IFirstWorkTicketService;
import com.hnac.hzims.ticket.workTicket.dto.TicketAccessTaskDto; import com.hnac.hzims.ticket.workTicket.dto.TicketAccessTaskDto;
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; 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.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; 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.springblade.flow.core.vo.ComleteTask;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.time.YearMonth; import java.time.YearMonth;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author hx * @author hx
@ -110,4 +116,11 @@ public class FirstWorkTicketController extends BladeController {
public void preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) { public void preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) {
firstWorkTicketService.preview(ticketType,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);
}
} }

7
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.core.tool.utils.CollectionUtil;
import org.springblade.flow.core.vo.ComleteTask; import org.springblade.flow.core.vo.ComleteTask;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -75,6 +76,12 @@ public interface IFirstWorkTicketService extends ITwoTicketService<WorkTicketInf
void preview(String ticketType, Long ticketId); void preview(String ticketType, Long ticketId);
/** /**
* 根据票据ID预览工作票
* @param ticketId 票据ID
*/
void preview(HttpServletResponse response,Long ticketId);
/**
* 评价 * 评价
* @param isPass 是否合格 * @param isPass 是否合格
* @param ticketId 票据ID * @param ticketId 票据ID

97
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java

@ -1,12 +1,14 @@
package com.hnac.hzims.ticket.twoTicket.service.impl; package com.hnac.hzims.ticket.twoTicket.service.impl;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.hnac.hzims.message.entity.config.PushConfigEntity; import com.hnac.hzims.message.entity.config.PushConfigEntity;
import com.hnac.hzims.message.fegin.IMessageConfigClient; import com.hnac.hzims.message.fegin.IMessageConfigClient;
import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO; import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO;
@ -21,6 +23,7 @@ import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO;
import com.hnac.hzims.ticket.constants.TicketConstants; import com.hnac.hzims.ticket.constants.TicketConstants;
import com.hnac.hzims.ticket.constants.WorkTicketConstants; import com.hnac.hzims.ticket.constants.WorkTicketConstants;
import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService; import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService;
import com.hnac.hzims.ticket.utils.AsposeUtil;
import com.hnac.hzims.ticket.utils.ExcelUtil; import com.hnac.hzims.ticket.utils.ExcelUtil;
import com.hnac.hzims.ticket.utils.PdfUtils; import com.hnac.hzims.ticket.utils.PdfUtils;
import com.hnac.hzims.ticket.workTicket.dto.*; import com.hnac.hzims.ticket.workTicket.dto.*;
@ -34,6 +37,7 @@ import com.hnac.hzims.ticket.workTicket.wrapper.WorkTicketInfoWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
@ -52,6 +56,10 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -267,6 +275,95 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl<WorkTicketInfoMa
} }
@Override @Override
public void preview(HttpServletResponse response,Long ticketId) {
Map measure = new HashMap(3) {{
put("index",1);
put("safetyMeasure","暗室逢灯你根本就发给你开始的那数据打你电话");
put("status","√");
}};
Map<String,Object> 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) { public R evaluation(Integer isPass, Long ticketId, String reason) {
return null; return null;
} }

49
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);
}
}
}

0
hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx

Loading…
Cancel
Save