diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java index 5aa103d..3f6f410 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/controller/TicketMatterGroupController.java @@ -108,8 +108,8 @@ public class TicketMatterGroupController extends BladeController { @ApiImplicitParam(name = "type", value = "模板类型:2为工作票;1为操作票") }) @ApiOperation(value = "预览") - public void preview(@RequestParam("id") Long id, @RequestParam("type") String type , HttpServletResponse response) throws Exception { - service.preview(id, type, response); + public void preview(@RequestParam("id") Long id , HttpServletResponse response) throws Exception { + service.preview(id, response); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java index da7a6c6..d724793 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/ITicketMatterGroupService.java @@ -64,4 +64,6 @@ public interface ITicketMatterGroupService extends BaseService param = new HashMap(); + if(TicketConstants.WordFileNameEnum.FIRST_WORK.getType().equals(type)) { + fileName = "template/电气第一种工作票模版.docx"; + param.put("matterLibraryListOne", this.convert(detail.getMatterLibraryListOne())); + param.put("matterLibraryListTwo", this.convert(detail.getMatterLibraryListTwo())); + param.put("matterLibraryListThree", this.convert(detail.getMatterLibraryListThree())); + } + else if(TicketConstants.WordFileNameEnum.SECOND_WORK.getType().equals(type)) { + fileName = "template/电气第二种工作票模版.docx"; + param.put("matterLibraryListSeven", this.convert(detail.getMatterLibraryListOne())); + } + else if(TicketConstants.WordFileNameEnum.MECHANICAL_WORK.getType().equals(type)) { + fileName = "template/水力机械工作票模版.docx"; + param.put("matterLibraryListEight", this.convert(detail.getMatterLibraryListOne())); + param.put("matterLibraryListNine", this.convert(detail.getMatterLibraryListTwo())); + param.put("matterLibraryListTen", this.convert(detail.getMatterLibraryListThree())); + } + else if(TicketConstants.WordFileNameEnum.SWITCH_OFF.getType().equals(type)) { + fileName = "template/电气操作票.docx"; + param.put("measureMapList", this.convert(detail.getMatterLibraryListOne())); + } + else { + return; + } + XWPFDocument xwpfDocument = null; + try { + xwpfDocument = WordExportUtil.exportWord07(fileName, param); + } catch (Exception e) { + e.printStackTrace(); + } + String wordPath = this.getFileSavePath() + detail.getName() +".docx"; + try { + this.exportTicketWord(Lists.newArrayList(xwpfDocument),wordPath); + } catch (IOException e) { + throw new RuntimeException(e); + } + String pdfPath = this.getFileSavePath() + detail.getName() +".pdf"; + AsposeUtil.wordToPdf(wordPath,pdfPath); + PdfUtils.readPdf(response,pdfPath); + } + + private List convert(List param) { + if(CollectionUtil.isNotEmpty(param)) { + return IntStream.iterate(0,index -> index + 1).limit(param.size() > 4 ? param.size() : 4).mapToObj(index -> { + if(index <= param.size() - 1) { + Map result = ObjectUtils.obj2Map(param.get(index)); + result.put("index",index + 1); + result.put("measure",result.get("safetyMeasure")); + result.put("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()); + } + + 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/"; + } + } } diff --git a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx index 03fcd4e..e19e428 100644 Binary files a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx and b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气操作票.docx b/hzims-service/ticket/src/main/resources/template/电气操作票.docx index 836b2db..6ca4036 100644 Binary files a/hzims-service/ticket/src/main/resources/template/电气操作票.docx and b/hzims-service/ticket/src/main/resources/template/电气操作票.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx index a4ca429..adf483f 100644 Binary files a/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx and b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx differ