diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/TestPOIController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/TestPOIController.java index 369d6ce..be87b38 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/TestPOIController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/TestPOIController.java @@ -35,6 +35,7 @@ import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.*; +import java.util.regex.Pattern; @RestController @RequestMapping @@ -52,6 +53,8 @@ public class TestPOIController { private RedisCache redisCache; @Autowired private SendMailRecordMapper sendMailRecordMapper; + @Autowired + private ICaseApplicationService caseApplicationService; @GetMapping("/test") public AjaxResult createDocument(@RequestBody CaseApplication caseApplication) { @@ -92,10 +95,10 @@ public class TestPOIController { datas.put("resName", affiliate.getName()); datas.put("resAddress", affiliate.getResidenAffili()); String responSex = affiliate.getResponSex(); - if (responSex.equals("0")){ - datas.put("resSex","男"); - }else{ - datas.put("resSex","女"); + if (responSex.equals("0")) { + datas.put("resSex", "男"); + } else { + datas.put("resSex", "女"); } Date responBirth = affiliate.getResponBirth(); if (responBirth != null) { @@ -244,12 +247,37 @@ public class TestPOIController { } datas.put("claims", caseApplication1.getArbitratClaims()); datas.put("request", caseApplication1.getRequestRule()); - //申请人证据材料 - datas.put("appEvidenceMaterial", null); - //被申请人证据材料 - - PictureRenderData pictureRenderData = WordUtil.rebuildImageContent(100, 100, null, "D:\\develop\\Snipaste_2023-10-27_09-59-23.jpg"); - datas.put("resEvidenceMaterial", "证据详情可查询附件"); + CaseApplication caseApplication2 = caseApplicationService.selectCaseApplication(caseApplication); + List caseAttachList1 = caseApplication2.getCaseAttachList(); + if (caseAttachList1 != null && caseAttachList1.size() > 0) { + for (CaseAttach caseAttach : caseAttachList1) { + if (caseAttach.getAnnexType() == 6) { //被申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String prefix = "/profile"; + int startIndex = annexName.indexOf(prefix); + startIndex += prefix.length(); + String annexPath = "/uploadPath" + annexName.substring(startIndex); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + datas.put("resEvidenceMaterial", pictureRenderData); + } + } else if (caseAttach.getAnnexType() == 2) { //申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String annexPath = "/home/ruoyi"+caseAttach.getAnnexPath(); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + //申请人证据材料 + datas.put("appEvidenceMaterial", pictureRenderData); + } + } + } + } datas.put("applicaCrossOpin", caseApplication1.getApplicaCrossOpin()); if (arbitrateRecord1 != null) { datas.put("factDetermi", arbitrateRecord1.getFactDetermi()); @@ -261,10 +289,10 @@ public class TestPOIController { datas.put("year", year); String month = String.format("%02d", now.getMonthValue()); String day = String.format("%02d", now.getDayOfMonth()); - //String modalFilePath = "/data/arbitrate-document/template/新裁决书模板.docx"; - String modalFilePath = "D:/develop/新裁决书模板.docx"; - //String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day; - String saveFolderPath = "D:/data/" + year + "/" + month + "/" + day; + String modalFilePath = "/data/arbitrate-document/template/新裁决书模板.docx"; + // String modalFilePath = "D:/develop/新裁决书模板.docx"; + String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day; + // String saveFolderPath = "D:/data/" + year + "/" + month + "/" + day; String fileName = UUID.randomUUID().toString().replace("-", "") + ".docx"; String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName; String resultFilePath = saveFolderPath + "/" + fileName; @@ -311,11 +339,13 @@ public class TestPOIController { caseApplication1.setCaseStatus(CaseApplicationConstants.VERPRIF_ARBITRATION); caseApplicationMapper.submitCaseApplication(caseApplication1); return AjaxResult.success("裁决书已生成"); - } catch (IOException e) { - return AjaxResult.error(e + "请检查文件路径是否有误"); - } + } catch(IOException e) + { + return AjaxResult.error(e + "请检查文件路径是否有误"); } +} + public String getNewEquipmentNo() { Object awardNum = redisCache.getCacheObject("awardNum"); if (awardNum == null) { @@ -343,30 +373,22 @@ public class TestPOIController { } public static void main(String[] args) throws Exception { - // 创建一个新的Word文档 - XWPFDocument document = new XWPFDocument(); + Map datas = new HashMap() { + { + //本地图片 + put("resEvidenceMaterial", new PictureRenderData(100, 120, "D:\\develop\\Snipaste_2023-10-27_09-59-23.jpg")); + //网路图片 + // put("urlPicture", new PictureRenderData(100, 100, ".png", BytePictureUtils.getUrlByteArray("https://avatars3.githubusercontent.com/u/1394854?v=3&s=40"))); + } + }; - // 创建一个段落 - XWPFParagraph paragraph = document.createParagraph(); - - // 创建一个文本区域 - XWPFRun run = paragraph.createRun(); - - // 加载图片文件 - File imageFile = new File("D:\\develop\\Snipaste_2023-10-27_09-59-23.jpg"); - FileInputStream fis = new FileInputStream(imageFile); - - // 将图片插入到文档中 - run.addPicture(fis, Document.PICTURE_TYPE_JPEG, "image.jpg", Units.toEMU(100), Units.toEMU(100)); - - // 关闭输入流 - fis.close(); - - // 保存文档 - String filePath= "D:\\develop\\"+UUID.randomUUID()+"document.docx"; - FileOutputStream fos = new FileOutputStream(filePath); - document.write(fos); - fos.close(); - } + XWPFTemplate template = XWPFTemplate.compile("D:\\develop\\新裁决书模板.docx") + .render(datas); + FileOutputStream out = new FileOutputStream("D:\\develop\\out_picture.docx"); + template.write(out); + out.flush(); + out.close(); + template.close(); } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java index 5cddab0..236fee7 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java @@ -146,7 +146,7 @@ public class WordUtil { public static PictureRenderData rebuildImageContent(Integer with, Integer height, String imageUrl, String relatedPath) { PictureRenderData pictureRenderData = null; if (!StringUtils.isBlank(imageUrl)) { - // pictureRenderData = Pictures.of(imageUrl).size(with, height).create(); + //pictureRenderData = Pictures.of(imageUrl).size(with, height).create(); //Pictures.PictureBuilder pictureBuilder = Pictures.of("https://res.wx.qq.com/a/wx_fed/weixin_portal/res/static/img/1EtCRvm.png"); } else if (!StringUtils.isBlank(relatedPath)) { pictureRenderData = Pictures.ofLocal(relatedPath).size(with, height).create(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java index 3ac266d..3e371b6 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.wisdomarbitrate.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.deepoove.poi.data.PictureRenderData; import com.ruoyi.common.constant.CaseApplicationConstants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; @@ -36,6 +37,7 @@ import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.*; +import java.util.regex.Pattern; import static com.ruoyi.common.utils.SecurityUtils.getUsername; @@ -254,10 +256,34 @@ public class AdjudicationServiceImpl implements IAdjudicationService { } datas.put("claims", caseApplication1.getArbitratClaims()); datas.put("request", caseApplication1.getRequestRule()); - //申请人证据材料 - datas.put("appEvidenceMaterial", null); - //被申请人证据材料 - datas.put("resEvidenceMaterial","(详见附件列表)"); + CaseApplication caseApplication2 = caseApplicationService.selectCaseApplication(caseApplication); + List caseAttachList1 = caseApplication2.getCaseAttachList(); + if (caseAttachList1 != null && caseAttachList1.size() > 0) { + for (CaseAttach caseAttach : caseAttachList1) { + if (caseAttach.getAnnexType() == 6) { //被申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String annexPath = "/home/ruoyi"+caseAttach.getAnnexPath(); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + datas.put("resEvidenceMaterial", pictureRenderData); + } + } else if (caseAttach.getAnnexType() == 2) { //申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String annexPath = "/home/ruoyi"+caseAttach.getAnnexPath(); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + //申请人证据材料 + datas.put("appEvidenceMaterial", pictureRenderData); + } + } + } + } datas.put("applicaCrossOpin", caseApplication1.getApplicaCrossOpin()); if (arbitrateRecord1 != null) { datas.put("factDetermi", arbitrateRecord1.getFactDetermi()); @@ -804,10 +830,34 @@ public class AdjudicationServiceImpl implements IAdjudicationService { } datas.put("claims", caseApplication1.getArbitratClaims()); datas.put("request", caseApplication1.getRequestRule()); - //申请人证据材料 - datas.put("appEvidenceMaterial", null); - //被申请人证据材料 - datas.put("resEvidenceMaterial","(详见附件列表)"); + CaseApplication caseApplication2 = caseApplicationService.selectCaseApplication(caseApplication); + List caseAttachList1 = caseApplication2.getCaseAttachList(); + if (caseAttachList1 != null && caseAttachList1.size() > 0) { + for (CaseAttach caseAttach : caseAttachList1) { + if (caseAttach.getAnnexType() == 6) { //被申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String annexPath = "/home/ruoyi"+caseAttach.getAnnexPath(); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + datas.put("resEvidenceMaterial", pictureRenderData); + } + } else if (caseAttach.getAnnexType() == 2) { //申请人证据材料 + String annexName = caseAttach.getAnnexName(); + boolean isImageFile = Pattern.matches(".*\\.(jpg|png|gif|bmp)$", annexName); + if (isImageFile) { + String annexPath = "/home/ruoyi"+caseAttach.getAnnexPath(); + System.out.println("路径是===========" + annexPath); + PictureRenderData pictureRenderData = WordUtil + .rebuildImageContent(100, 100, null, annexPath); + //申请人证据材料 + datas.put("appEvidenceMaterial", pictureRenderData); + } + } + } + } datas.put("applicaCrossOpin", caseApplication1.getApplicaCrossOpin()); if (arbitrateRecord1 != null) { datas.put("factDetermi", arbitrateRecord1.getFactDetermi());