diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardTicketInfoController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardTicketInfoController.java index 4f79472..d1ebfad 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardTicketInfoController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/controller/StandardTicketInfoController.java @@ -191,4 +191,11 @@ public class StandardTicketInfoController extends BladeController { public R> operate(OperateVo operate, Query query) { return R.data(standardTicketInfoService.operate(Condition.getPage(query),operate)); } + + @GetMapping("/exportOperateTicket") + @ApiOperation(value = "导出操作票") + @ApiOperationSupport(order = 12) + public void exportOperateTicket(HttpServletResponse response, @RequestParam Long ticketId) throws Exception { + standardTicketInfoService.exportOperateTicket(response,ticketId); + } } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java index 6c98ccd..52a9e55 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java @@ -143,4 +143,11 @@ public interface IStandardTicketInfoService extends BaseService operate(IPage page,OperateVo operate); List exportStandardTicket(StandardTicketInfoDto entity); + + /** + * 导出操作票 + * @param response + * @param ticketId + */ + void exportOperateTicket(HttpServletResponse response, Long ticketId); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java index f3b6699..524c43c 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.ticket.standardTicket.service.impl; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; +import cn.afterturn.easypoi.word.WordExportUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -8,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; import com.hnac.hzims.ticket.allTicket.service.TicketInfoEvaluateService; import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO; @@ -30,6 +32,7 @@ import com.hnac.hzims.ticket.standardTicket.wrapper.StandardTicketInfoWrapper; import com.hnac.hzims.ticket.twoTicket.vo.operation.StandardTicketInfoVo; import com.hnac.hzims.ticket.twoTicket.vo.operation.StandardTicketMeasureVo; import com.hnac.hzims.ticket.twoTicket.vo.ticket.StandardTicketCountQueryVo; +import com.hnac.hzims.ticket.utils.AsposeUtil; import com.hnac.hzims.ticket.utils.ExcelUtil; import com.hnac.hzims.ticket.utils.PdfUtils; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; @@ -39,6 +42,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; 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.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseServiceImpl; @@ -64,6 +68,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; +import java.io.FileOutputStream; +import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; @@ -73,6 +79,7 @@ import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * @author hx @@ -865,4 +872,69 @@ public class StandardTicketInfoServiceImpl extends BaseServiceImpl params = com.hnac.hzims.ticket.utils.ObjectUtils.obj2Map(detail); + params.put("measureMapList",this.convert(detail.getStandardTicketMeasureVOList())); + XWPFDocument xwpfDocument = null; + String fileName = "template/电气操作票.docx"; + try { + xwpfDocument = WordExportUtil.exportWord07(fileName, params); + } catch (Exception e) { + e.printStackTrace(); + } + String wordPath = this.getFileSavePath() + detail.getTitle() +".docx"; + try { + this.exportTicketWord(Lists.newArrayList(xwpfDocument),wordPath); + } catch (IOException e) { + throw new RuntimeException(e); + } + String pdfPath = this.getFileSavePath() + detail.getTitle() +".pdf"; + AsposeUtil.wordToPdf(wordPath,pdfPath); + PdfUtils.readPdf(response,pdfPath); + } + + private void exportTicketWord(List documents, String savePath) throws IOException { + FileOutputStream out = new FileOutputStream(savePath); + try { + for (XWPFDocument document : documents) { + document.write(out); + } + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + out.close(); + } + } + + private String getFileSavePath() { + String os = System.getProperty("os.name").toLowerCase(); + if("linux".equals(os)) { + return pdfSavePath; + } + else { + return "E://template/"; + } + } + + private List convert (List list) { + if(CollectionUtil.isNotEmpty(list)) { + return IntStream.iterate(0, index -> index + 1).limit(list.size() > 25 ? list.size() : 25).mapToObj(index -> { + if(index <= list.size() - 1) { + Map result = com.hnac.hzims.ticket.utils.ObjectUtils.obj2Map(list.get(index)); + result.put("index",index + 1); + result.put("status",TicketConstants.MATTER_FINISH_STATUS == result.get("status") ? "√" : null); + return result; + } + else { + return new HashMap(); + } + }).collect(Collectors.toList()); + } + return IntStream.iterate(0,index -> index + 1).limit(4).mapToObj(index -> new HashMap()).collect(Collectors.toList()); + } } diff --git a/hzims-service/ticket/src/main/resources/template/电气操作票.docx b/hzims-service/ticket/src/main/resources/template/电气操作票.docx index 6ca4036..2a8cc1b 100644 Binary files a/hzims-service/ticket/src/main/resources/template/电气操作票.docx and b/hzims-service/ticket/src/main/resources/template/电气操作票.docx differ