文档生成 11.21

master
zhc077 1 day ago
parent f5d6506490
commit 8c06e4e8cf
  1. 1
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 17
      jeecg-boot/jeecg-module-demo/pom.xml
  3. 14
      jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/controller/ProjectController.java
  4. 6
      jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/dto/ProjectDto.java
  5. 14
      jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/IProject4WordService.java
  6. 45
      jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java
  7. 144
      jeecg-boot/jeecg-module-demo/src/main/test/java/org/jeecg/test/word/WordExportUtil_test.java
  8. 4
      jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
  9. 34
      jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/word/WordExportUtil_test.java
  10. 2
      jeecg-boot/pom.xml

@ -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生成

@ -20,6 +20,23 @@
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-biz</artifactId>
</dependency>
<!-- easypoi -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
</project>

@ -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<Project, IProjectService>
@Autowired
private IProjectLogService iProjectLogService;
@Autowired
IProject4WordService iProject4WordService;
/**
* 分页列表查询
*
@ -809,4 +814,13 @@ public class ProjectController extends JeecgController<Project, IProjectService>
return super.importExcel(request, response, Project.class);
}
@ApiOperation(value = "生成项目书word文件", notes = "生成项目书word文件")
@GetMapping(value = "/createXiangmushuWord")
// @PermissionData(pageComponent = "projectApplication/productAudit/project4AuditList")
public Result<Object> list4LiXiang(Project project){
iProject4WordService.createXiangMuShu4Word(project);
return Result.OK("创建成功");
}
}

@ -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;
/**

@ -13,5 +13,17 @@ import org.jeecg.modules.demo.project.service.impl.Project4WordServiceImpl;
*/
public interface IProject4WordService extends IService<Project> {
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);
}

@ -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<ProjectMapper, Project>
@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<ProjectMapper, Project>
}
dto.setSqdw(departExtDto);
List<ProjectMember> projectMemberList = iProjectMemberService.list(new LambdaQueryWrapper<ProjectMember>().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<ProjectMapper, Project>
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<String, Object> 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;
}
}

@ -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<String, Object> map = BeanUtil.beanToMap(project);
// Map<String, Object> map = new HashMap<String, Object>();
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<File> 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<XWPFDocument> 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<XWPFPictureData> allPictures = append.getAllPictures();
// 记录图片合并前及合并后的ID
Map<String, String> map = new HashMap<String, String>();
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<String, String> 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<String, String> set : map.entrySet()) {
addPart = addPart.replace(set.getKey(), set.getValue());
}
}
//将两个文档的xml内容进行拼接
CTBody makeBody = CTBody.Factory.parse(prefix + mainPart + addPart + sufix);
src.set(makeBody);
}
}

@ -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:

@ -41,20 +41,38 @@ public class WordExportUtil_test {
@Autowired
private IProject4WordService iProject4WordService;
@Test
public void test1() {
Object info4Word = iProject4WordService.createXiangMuShu4Word(null);
Map<String, Object> map = BeanUtil.beanToMap(info4Word);
/*System.out.println("map = " + JSON.toJSONString(map));
List<Map<String, Object>> 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<String, Object> map = BeanUtil.beanToMap(info4Word);
// List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
System.out.println("map = " + JSON.toJSONString(map));
List<Map<String, Object>> 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<File> 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);

@ -472,6 +472,8 @@
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>doc</nonFilteredFileExtension>
<nonFilteredFileExtension>docx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>

Loading…
Cancel
Save