|
@@ -2,21 +2,32 @@ package cn.cslg.report.service.business;
|
|
|
|
|
|
import cn.cslg.report.common.model.dto.invalidReReport.InvalidReasonDTO;
|
|
|
import cn.cslg.report.common.model.dto.invalidReReport.InvalidReasonFieldValueDTO;
|
|
|
+import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
|
import cn.cslg.report.common.model.vo.invalidReReport.ExportInvalidReasonVO;
|
|
|
import cn.cslg.report.common.model.vo.invalidReReport.QueryInvalidReasonVO;
|
|
|
+import cn.cslg.report.common.utils.CacheUtils;
|
|
|
+import cn.cslg.report.common.utils.FileUtils;
|
|
|
+import cn.cslg.report.common.utils.Response;
|
|
|
+import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
|
import cn.cslg.report.common.utils.WordUtil;
|
|
|
+import cn.cslg.report.entity.ReportDocument;
|
|
|
import cn.cslg.report.entity.invalidReReport.InvalidReasonField;
|
|
|
import cn.cslg.report.service.business.InvalidReReport.InvalidReasonFieldService;
|
|
|
import cn.cslg.report.service.business.InvalidReReport.InvalidReasonService;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.config.ConfigureBuilder;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.apache.poi.xwpf.usermodel.*;
|
|
|
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
|
|
+import org.ddr.poi.html.HtmlRenderPolicy;
|
|
|
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -24,6 +35,7 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -39,9 +51,28 @@ import java.util.stream.Collectors;
|
|
|
public class ExportArgumentsScenariosService {
|
|
|
private final InvalidReasonService invalidReasonService;
|
|
|
private final InvalidReasonFieldService invalidReasonFieldService;
|
|
|
-
|
|
|
- public void ExportToExcel(Integer reportId, String filePath) throws IOException {
|
|
|
+ private final FileUtils fileUtils;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
+ public String ExportToWord(Integer reportId) throws IOException {
|
|
|
+ String templeName = IdUtil.simpleUUID() + ".docx";
|
|
|
+ String directoryName = fileUtils.createDirectory();
|
|
|
+ //富文本栏位计数器
|
|
|
+ int nameCount=0;
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
XWPFDocument doc = new XWPFDocument();
|
|
|
+ doc.createStyles();
|
|
|
+ // 获取底层 XML 文档对象模型
|
|
|
+ CTDocument1 ctDocument = doc.getDocument();
|
|
|
+ // 设置页面布局为横向
|
|
|
+ CTBody body = ctDocument.getBody();
|
|
|
+ if (!body.isSetSectPr()) {
|
|
|
+ body.addNewSectPr();
|
|
|
+ CTPageSz pageSize = body.getSectPr().addNewPgSz();
|
|
|
+ pageSize.setOrient(STPageOrientation.LANDSCAPE); // 设置页面布局为横向
|
|
|
+ pageSize.setW(BigInteger.valueOf(16840));
|
|
|
+ pageSize.setH(BigInteger.valueOf(11907));
|
|
|
+ }
|
|
|
//根据报告id查询所有自定义字段
|
|
|
LambdaQueryWrapper<InvalidReasonField> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(InvalidReasonField::getReportId, reportId)
|
|
@@ -53,21 +84,16 @@ public class ExportArgumentsScenariosService {
|
|
|
nameList.add("涉及内容");
|
|
|
nameList.add("相关证据");
|
|
|
nameList.add("陈述意见");
|
|
|
-
|
|
|
List<String> tem = fields.stream().map(InvalidReasonField::getFieldName).collect(Collectors.toList());
|
|
|
nameList.addAll(tem);
|
|
|
//根据报告id查询无效理由
|
|
|
List<QueryInvalidReasonVO> queryInvalidReasonVOS = invalidReasonService.queryInvalidReason(reportId);
|
|
|
//根据无效类型排序,方便合并单元格
|
|
|
queryInvalidReasonVOS.sort(Comparator.comparing(QueryInvalidReasonVO::getInvalidName));
|
|
|
- //设置页脚
|
|
|
-// WordUtil.createDefaultFooter(doc);
|
|
|
- //设置页边距
|
|
|
- WordUtil.setMargin(doc, 1000, 1000, 500, 100);
|
|
|
//设置标题
|
|
|
WordUtil.setParagraph(doc, "标题", "宋体", 16, 10, true, ParagraphAlignment.CENTER);
|
|
|
//设置副标题
|
|
|
- WordUtil.setParagraph(doc, 1 + "到" + 2, "宋体", 10, 10, true, ParagraphAlignment.RIGHT);
|
|
|
+ WordUtil.setParagraph(doc,"生成时间:"+new Date().toString() , "宋体", 10, 10, true, ParagraphAlignment.RIGHT);
|
|
|
int colTotalCount = fields.size() + 5;
|
|
|
//总条数
|
|
|
int dataCount = queryInvalidReasonVOS.size();
|
|
@@ -98,6 +124,8 @@ public class ExportArgumentsScenariosService {
|
|
|
XWPFTableCell cell = row.createCell();
|
|
|
XWPFRun run;
|
|
|
run = WordUtil.setTableCellStyle(cell, ParagraphAlignment.CENTER, "微软雅黑", 9, false);
|
|
|
+ String aa=run.getStyle();
|
|
|
+ System.out.println(aa);
|
|
|
if (j == 0) {
|
|
|
run.setText(String.valueOf(i2));
|
|
|
} else if (j == 1) {
|
|
@@ -108,15 +136,7 @@ public class ExportArgumentsScenariosService {
|
|
|
} else if (name == 2) {
|
|
|
run.setText("不具备创造性");
|
|
|
} else if (name == 3) {
|
|
|
- // 创建一个段落
|
|
|
- XWPFParagraph paragraph = cell.getParagraphs().get(0);
|
|
|
-
|
|
|
- // 创建一个运行
|
|
|
- XWPFRun run1 = paragraph.createRun();
|
|
|
- CTR ctr = run1.getCTR();
|
|
|
- ctr.addNewRPr().addNewB();
|
|
|
- ctr.addNewT().setStringValue("<b>Bold text</b> Normal text");
|
|
|
-// run.setText("<h1>不具备新颖性<h1>");
|
|
|
+ run.setText("不具备新颖性");
|
|
|
}
|
|
|
} else if (j == 2) {
|
|
|
int content = queryInvalidReasonVO.getContent();
|
|
@@ -148,25 +168,53 @@ public class ExportArgumentsScenariosService {
|
|
|
run.setText(stringBuilder.toString());
|
|
|
}
|
|
|
} else if (j == 4) {
|
|
|
- run.setText(queryInvalidReasonVO.getArgumentStr());
|
|
|
+ map1.put("argument"+nameCount,queryInvalidReasonVO.getArgumentStr());
|
|
|
+ run.setText("{{argument"+nameCount+"}}");
|
|
|
+ nameCount=nameCount+1;
|
|
|
} else {
|
|
|
InvalidReasonField field = fields.get(j - 5);
|
|
|
InvalidReasonFieldValueDTO valueDTO = fieldValueDTOS.stream().filter(item -> item.getFieldId().equals(field.getId())).findFirst().orElse(new InvalidReasonFieldValueDTO());
|
|
|
- run.setText(valueDTO.getFieldValue());
|
|
|
+ map1.put(valueDTO.getFieldKey()+nameCount,valueDTO.getFieldValue());
|
|
|
+ run.setText("{{"+valueDTO.getFieldKey()+nameCount+"}}");
|
|
|
+ nameCount=nameCount+1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//记录合并起始位置
|
|
|
- Integer t=1;
|
|
|
- for(int i :map.keySet()){
|
|
|
- int end =t+map.get(i)-1;
|
|
|
- WordUtil.mergeCellsVertically(xTable,1,t,end);
|
|
|
- t= t+map.get(i);
|
|
|
+ Integer t = 1;
|
|
|
+ for (int i : map.keySet()) {
|
|
|
+ int end = t + map.get(i) - 1;
|
|
|
+ WordUtil.mergeCellsVertically(xTable, 1, t, end);
|
|
|
+ t = t + map.get(i);
|
|
|
}
|
|
|
- FileOutputStream os = new FileOutputStream("output.docx");
|
|
|
+ String templePath = fileUtils.getSavePath(directoryName) + templeName;
|
|
|
+ FileOutputStream os = new FileOutputStream(templePath);
|
|
|
doc.write(os);
|
|
|
os.close();
|
|
|
doc.close();
|
|
|
+ HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
|
|
|
+ // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
|
|
|
+ ConfigureBuilder configureBuilder= Configure.builder();
|
|
|
+ for (String key:map1.keySet())
|
|
|
+ {
|
|
|
+ configureBuilder=configureBuilder.bind(key,htmlRenderPolicy);
|
|
|
+ }
|
|
|
+ Configure configure=configureBuilder.build();
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile("D:\\RMS\\output.docx", configure).render(map1);
|
|
|
+ String fileName = IdUtil.simpleUUID() + ".docx";
|
|
|
+ String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
+ template.writeToFile(outPath);
|
|
|
+ template.close();
|
|
|
+ String url = fileUtils.getDirectory2(directoryName) + fileName;
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ ReportDocument reportDocument = new ReportDocument();
|
|
|
+ reportDocument.setReportId(reportId);
|
|
|
+ reportDocument.setFileName(fileName);
|
|
|
+ reportDocument.setFilePath(url);
|
|
|
+ reportDocument.setPersonId(personnelVO.getId());
|
|
|
+ reportDocument.setPersonName(personnelVO.getName());
|
|
|
+ reportDocument.insert();
|
|
|
+ return Response.success(url);
|
|
|
}
|
|
|
|
|
|
|