From 8c06e4e8cf233aed526b0a91ce87432c953f3a8b Mon Sep 17 00:00:00 2001 From: zhc077 <565291854@qq.com> Date: Thu, 21 Nov 2024 18:00:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=94=9F=E6=88=90=2011.21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/shiro/ShiroConfig.java | 1 + jeecg-boot/jeecg-module-demo/pom.xml | 17 +++ .../project/controller/ProjectController.java | 14 ++ .../modules/demo/project/dto/ProjectDto.java | 6 - .../project/service/IProject4WordService.java | 14 +- .../service/impl/Project4WordServiceImpl.java | 45 +++++- .../jeecg/test/word/WordExportUtil_test.java | 144 ------------------ .../src/main/resources/application-dev.yml | 4 +- .../modules/word/WordExportUtil_test.java | 34 ++++- jeecg-boot/pom.xml | 10 +- 10 files changed, 117 insertions(+), 172 deletions(-) delete mode 100644 jeecg-boot/jeecg-module-demo/src/main/test/java/org/jeecg/test/word/WordExportUtil_test.java diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java index 37da5a6..330c07c 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java @@ -192,6 +192,7 @@ public class ShiroConfig { filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync4FaRen", "anon");//法人注册时,选择部门列表 filterChainDefinitionMap.put("/sys/sysDepart/getDepartList4Quxian", "anon");//法人注册时,获取区县级别部门列表 + filterChainDefinitionMap.put("/project/project/createXiangmushuWord", "anon");//测试word生成 diff --git a/jeecg-boot/jeecg-module-demo/pom.xml b/jeecg-boot/jeecg-module-demo/pom.xml index 86b18a2..424cb05 100644 --- a/jeecg-boot/jeecg-module-demo/pom.xml +++ b/jeecg-boot/jeecg-module-demo/pom.xml @@ -20,6 +20,23 @@ org.jeecgframework.boot jeecg-system-biz + + + + cn.afterturn + easypoi-base + 4.3.0 + + + cn.afterturn + easypoi-web + 4.3.0 + + + cn.afterturn + easypoi-annotation + 4.3.0 + diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java index c117481..97fe1bc 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java @@ -28,6 +28,7 @@ import org.jeecg.modules.demo.project.dto.DepartExtDto; import org.jeecg.modules.demo.project.dto.DepartExtDto2; import org.jeecg.modules.demo.project.dto.ProjectShenBaoDto; import org.jeecg.modules.demo.project.entity.Project; +import org.jeecg.modules.demo.project.service.IProject4WordService; import org.jeecg.modules.demo.project.service.IProjectService; import org.jeecg.modules.demo.projectLog.entity.ProjectLog; import org.jeecg.modules.demo.projectLog.service.IProjectLogService; @@ -88,6 +89,10 @@ public class ProjectController extends JeecgController @Autowired private IProjectLogService iProjectLogService; + @Autowired + IProject4WordService iProject4WordService; + + /** * 分页列表查询 * @@ -809,4 +814,13 @@ public class ProjectController extends JeecgController return super.importExcel(request, response, Project.class); } + @ApiOperation(value = "生成项目书word文件", notes = "生成项目书word文件") + @GetMapping(value = "/createXiangmushuWord") +// @PermissionData(pageComponent = "projectApplication/productAudit/project4AuditList") + public Result list4LiXiang(Project project){ + iProject4WordService.createXiangMuShu4Word(project); + return Result.OK("创建成功"); + } + + } diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/dto/ProjectDto.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/dto/ProjectDto.java index d438b01..9acdc96 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/dto/ProjectDto.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/dto/ProjectDto.java @@ -178,37 +178,31 @@ public class ProjectDto implements Serializable { /** * 就业人数 */ - @Excel(name = "就业人数", width = 15) @ApiModelProperty(value = "就业人数") private String employmentFigure; /** * 年销售收入 */ - @Excel(name = "年销售收入", width = 15) @ApiModelProperty(value = "年销售收入") private BigDecimal annualSalesRevenue; /** * 年出口创汇 */ - @Excel(name = "年出口创汇", width = 15) @ApiModelProperty(value = "年出口创汇") private BigDecimal annualExportEarnings; /** * 年纳税总额 */ - @Excel(name = "年纳税总额", width = 15) @ApiModelProperty(value = "年纳税总额") private BigDecimal totalAnnualTaxPayment; /** * 年净利润 */ - @Excel(name = "年净利润", width = 15) @ApiModelProperty(value = "年净利润") private BigDecimal annualProfit; /** * 申请专利数 */ - @Excel(name = "申请专利数", width = 15) @ApiModelProperty(value = "申请专利数") private String applyPatentNumber; /** diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/IProject4WordService.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/IProject4WordService.java index b97de63..f8e7655 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/IProject4WordService.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/IProject4WordService.java @@ -13,5 +13,17 @@ import org.jeecg.modules.demo.project.service.impl.Project4WordServiceImpl; */ public interface IProject4WordService extends IService { - Object getInfo4Word(Project project); + /** + * @description: 生成项目书文件 + * 1、根据baseInfoModel.doc,生成项目基本信息word文件 + * 2、在其后拼接申报人上传的项目书正文docx 文件 + * 3、再在其后拼接yiJiangModel.doc 文件 + * 4、生成新的项目书文件 + * + * @param: [project] + * @return: java.lang.Object + * @author: z.h.c + * @date: 24/11/21 10:22 + */ + Object createXiangMuShu4Word(Project project); } diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java index dfbab65..6abff96 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java @@ -1,10 +1,13 @@ package org.jeecg.modules.demo.project.service.impl; +import cn.afterturn.easypoi.word.WordExportUtil; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.demo.departext.dto.DepartExtDto; @@ -25,18 +28,18 @@ import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysDepartService; import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.service.impl.SysBaseApiImpl; -import org.jeecgframework.poi.excel.ExcelExportUtil; -import org.jeecgframework.poi.excel.entity.TemplateExportParams; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.List; +import java.util.Map; /** * @Description: 项目表 @@ -68,8 +71,8 @@ public class Project4WordServiceImpl extends ServiceImpl @Autowired private IProjectMemberService iProjectMemberService; - @Override - public Object getInfo4Word(Project obj) { + + ProjectDto getData4Xiangmushu(Project req) { Project project = this.getById("1849284130146025473"); if (ObjectUtils.isEmpty(project)) return null; @@ -205,7 +208,7 @@ public class Project4WordServiceImpl extends ServiceImpl } dto.setSqdw(departExtDto); List projectMemberList = iProjectMemberService.list(new LambdaQueryWrapper().eq(ProjectMember::getProjectId, project.getId())); - if(ObjectUtil.isNotEmpty(projectMemberList)){ + if (ObjectUtil.isNotEmpty(projectMemberList)) { projectMemberList.stream().forEach(pm -> { pm.setZy(pm.getCurrentPerfession()); if (!ObjectUtils.isEmpty(pm.getPolitical())) { @@ -233,4 +236,30 @@ public class Project4WordServiceImpl extends ServiceImpl dto.setPms(projectMemberList); return dto; } + + @Autowired + private ResourceLoader resourceLoader; + + @Value("${jeecg.path.model4word}") + private String model4wordPath; + + @Override + public Object createXiangMuShu4Word(Project obj) { + ProjectDto dto = getData4Xiangmushu(obj); + Map map = BeanUtil.beanToMap(dto); + System.out.println("map = " + JSON.toJSONString(map)); + try { + File file = new File(model4wordPath + File.separator); + String modelFilePath = file.getPath() + File.separator + "model2.doc"; + log.info("the model path:{}",modelFilePath); + XWPFDocument doc = WordExportUtil.exportWord07(modelFilePath, map); + FileOutputStream fos = new FileOutputStream("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\test1121v13.docx"); +// FileOutputStream fos2 = new FileOutputStream("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\test1121v7.docx"); + doc.write(fos); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return dto; + } } diff --git a/jeecg-boot/jeecg-module-demo/src/main/test/java/org/jeecg/test/word/WordExportUtil_test.java b/jeecg-boot/jeecg-module-demo/src/main/test/java/org/jeecg/test/word/WordExportUtil_test.java deleted file mode 100644 index 97ce19d..0000000 --- a/jeecg-boot/jeecg-module-demo/src/main/test/java/org/jeecg/test/word/WordExportUtil_test.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.jeecg.test.word; - -import cn.hutool.core.bean.BeanUtil; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.xwpf.usermodel.BreakType; -import org.apache.poi.xwpf.usermodel.Document; -import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.poi.xwpf.usermodel.XWPFPictureData; -import org.apache.xmlbeans.XmlOptions; -import org.jeecg.modules.demo.project.entity.Project; -import org.jeecg.modules.demo.project.service.IProjectService; -import org.jeecgframework.poi.word.WordExportUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.*; - -/** - * @Description: TODO - * @Author: Z.H.C - * @CreateTime: 2024-11-18 15:33 - * @Version: 1.0 - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class WordExportUtil_test { - - @Autowired - private IProjectService iProjectService; - - /** - * 简单导出没有图片和Excel - */ - @Test - public void SimpleWordExport() { - Project project = iProjectService.getById("1857246264504631297"); - Map map = BeanUtil.beanToMap(project); -// Map map = new HashMap(); - map.put("department", "Easypoi"); - map.put("person", "JueYue"); - map.put("time", new Date()); - map.put("me", "JueYue"); - map.put("date", "2015-01-03"); - System.out.println("map = " + map.values()); - try { - //jeecg-boot/jeecg-boot-base-core/src/main/resources/templates/email/work/test1118.docx - XWPFDocument doc = WordExportUtil.exportWord07("src/main/resources/templates/email/work/test1118.docx", map); - FileOutputStream fos = new FileOutputStream("D:/1.docx"); - doc.write(fos); - fos.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void test2() { - File newFile = new File("C:\\Users\\YX\\Desktop\\testword\\合并2.docx"); - List srcfile = new ArrayList<>(); - - File file1 = new File("C:\\Users\\YX\\Desktop\\testword\\1.docx"); - File file2 = new File("C:\\Users\\YX\\Desktop\\testword\\2.docx"); - File file3 = new File("C:\\Users\\YX\\Desktop\\testword\\3.docx"); - srcfile.add(file1); - srcfile.add(file2); - srcfile.add(file3); - try { - OutputStream dest = new FileOutputStream(newFile); - ArrayList documentList = new ArrayList<>(); - XWPFDocument doc = null; - for (int i = 0; i < srcfile.size(); i++) { - FileInputStream in = new FileInputStream(srcfile.get(i).getPath()); - OPCPackage open = OPCPackage.open(in); - XWPFDocument document = new XWPFDocument(open); - documentList.add(document); - } - for (int i = 0; i < documentList.size(); i++) { - doc = documentList.get(0); - if (i == 0) {//首页直接分页,不再插入首页文档内容 - documentList.get(i).createParagraph().createRun().addBreak(BreakType.PAGE); -// appendBody(doc,documentList.get(i)); - } else if (i == documentList.size() - 1) {//尾页不再分页,直接插入最后文档内容 - appendBody(doc, documentList.get(i)); - } else { - documentList.get(i).createParagraph().createRun().addBreak(BreakType.PAGE); - appendBody(doc, documentList.get(i)); - } - } - doc.write(dest); - dest.close(); - - System.out.println("*****合成成功********"); - - // Runtime.getRuntime().exec("cmd /c start winword C:/Users/gouwe/合并.docx");//直接调用cmd打开合成文档 - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void appendBody(XWPFDocument src, XWPFDocument append) throws Exception { - CTBody src1Body = src.getDocument().getBody(); - CTBody src2Body = append.getDocument().getBody(); - - List allPictures = append.getAllPictures(); - // 记录图片合并前及合并后的ID - Map map = new HashMap(); - for (XWPFPictureData picture : allPictures) { - String before = append.getRelationId(picture); - //将原文档中的图片加入到目标文档中 - String after = src.addPictureData(picture.getData(), Document.PICTURE_TYPE_PNG); - map.put(before, after); - } - appendBody(src1Body, src2Body, map); - } - - private static void appendBody(CTBody src, CTBody append, Map map) throws Exception { - XmlOptions optionsOuter = new XmlOptions(); - optionsOuter.setSaveOuter(); - String appendString = append.xmlText(optionsOuter); - - String srcString = src.xmlText(); - String prefix = srcString.substring(0, srcString.indexOf(">") + 1); - String mainPart = srcString.substring(srcString.indexOf(">") + 1, srcString.lastIndexOf("<")); - String sufix = srcString.substring(srcString.lastIndexOf("<")); - String addPart = appendString.substring(appendString.indexOf(">") + 1, appendString.lastIndexOf("<")); - if (map != null && !map.isEmpty()) { - //对xml字符串中图片ID进行替换 - for (Map.Entry set : map.entrySet()) { - addPart = addPart.replace(set.getKey(), set.getValue()); - } - } - //将两个文档的xml内容进行拼接 - CTBody makeBody = CTBody.Factory.parse(prefix + mainPart + addPart + sufix); - src.set(makeBody); - } -} diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml index c987698..0fca6fc 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml @@ -190,7 +190,7 @@ mybatis-plus: table-underline: true configuration: # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 返回类型为Map,显示null对应的字段 call-setters-on-nulls: true #jeecg专用配置 @@ -216,6 +216,8 @@ jeecg: path: #文件上传根目录 设置 upload: /opt/upFiles + # 申报书模板文件 add by 11.21 + model4word: D:/model4word #webapp文件路径 webapp: /opt/webapp shiro: diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/word/WordExportUtil_test.java b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/word/WordExportUtil_test.java index 968fbc0..7d191f0 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/word/WordExportUtil_test.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/word/WordExportUtil_test.java @@ -41,20 +41,38 @@ public class WordExportUtil_test { @Autowired private IProject4WordService iProject4WordService; + @Test + public void test1() { + Object info4Word = iProject4WordService.createXiangMuShu4Word(null); + Map map = BeanUtil.beanToMap(info4Word); + /*System.out.println("map = " + JSON.toJSONString(map)); + List> edu = new ArrayList<>(); + + try { +// XWPFDocument doc = WordExportUtil.exportWord07("C:\\Users\\YX\\Desktop\\testword\\model2.doc", map); + XWPFDocument doc = WordExportUtil.exportWord07("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\page1Model.doc", map); + FileOutputStream fos = new FileOutputStream( "C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\test1121v1.docx"); + doc.write(fos); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + }*/ + } + /** * 简单导出没有图片和Excel */ @Test public void SimpleWordExport() { - Object info4Word = iProject4WordService.getInfo4Word(null); + Object info4Word = iProject4WordService.createXiangMuShu4Word(null); Map map = BeanUtil.beanToMap(info4Word); -// List> listMap = new ArrayList>(); System.out.println("map = " + JSON.toJSONString(map)); List> edu = new ArrayList<>(); try { - XWPFDocument doc = WordExportUtil.exportWord07("C:\\Users\\YX\\Desktop\\testword\\model.docx", map); - FileOutputStream fos = new FileOutputStream("C:\\Users\\YX\\Desktop\\testword\\test1120.docx"); +// XWPFDocument doc = WordExportUtil.exportWord07("C:\\Users\\YX\\Desktop\\testword\\model2.doc", map); + XWPFDocument doc = WordExportUtil.exportWord07("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\page1Model.doc", map); + FileOutputStream fos = new FileOutputStream( "C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\test1121v1.docx"); doc.write(fos); fos.close(); } catch (Exception e) { @@ -64,12 +82,12 @@ public class WordExportUtil_test { @Test public void test2() { - File newFile = new File("C:\\Users\\YX\\Desktop\\testword\\合并2.docx"); + File newFile = new File("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\合并1121.docx"); List srcfile = new ArrayList<>(); - File file1 = new File("C:\\Users\\YX\\Desktop\\testword\\1.docx"); - File file2 = new File("C:\\Users\\YX\\Desktop\\testword\\2.docx"); - File file3 = new File("C:\\Users\\YX\\Desktop\\testword\\3.docx"); + File file1 = new File("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\test1121v1.docx"); + File file2 = new File("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\正文V15.docx"); + File file3 = new File("C:\\Users\\YX\\Desktop\\testword\\xiangmushu\\yiJianModel.doc"); srcfile.add(file1); srcfile.add(file2); srcfile.add(file3); diff --git a/jeecg-boot/pom.xml b/jeecg-boot/pom.xml index fe4d116..33897fa 100644 --- a/jeecg-boot/pom.xml +++ b/jeecg-boot/pom.xml @@ -19,7 +19,7 @@ http://guojusoft.com http://www.jeecg.com/vip - + org.springframework.boot spring-boot-starter-parent @@ -53,7 +53,7 @@ 9.0.0 8.1.1.49 - + 3.5.3.2 4.1.3 @@ -472,6 +472,8 @@ eot ttf svg + doc + docx @@ -504,7 +506,7 @@ http://maven.jeecg.com:8090/nexus/content/repositories/snapshots/ - + @@ -586,4 +588,4 @@ - \ No newline at end of file +