月报填写--整合导出主页面中英文文件
This commit is contained in:
+4
-2
@@ -183,8 +183,10 @@ public class LawsMonthlyReportWriteEOController extends JeroController<LawsMonth
|
||||
@AutoLog(value = "月报整合导出zip")
|
||||
@ApiOperation(value = "月报整合导出zip", notes = "月报整合导出zip")
|
||||
@RequestMapping(value = "/exportMonthlyReport", method = RequestMethod.GET)
|
||||
public ResponseEntity<byte[]> exportMonthlyReport(LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO) throws IOException {
|
||||
return lawsMonthlyReportWriteEOService.exportMonthlyReport(lawsMonthlyReportWriteEO);
|
||||
public void exportMonthlyReport(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO) throws IOException {
|
||||
lawsMonthlyReportWriteEOService.exportMonthlyReport(response,request,lawsMonthlyReportWriteEO);
|
||||
}
|
||||
|
||||
@ApiOperation(value="带入标准信息--分页", notes="带入标准信息--分页")
|
||||
|
||||
+4
-2
@@ -3,9 +3,9 @@ package com.jero.modules.report.service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.modules.report.entity.LawsMonthlyReportWriteEO;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -77,7 +77,9 @@ public interface ILawsMonthlyReportWriteEOService extends IService<LawsMonthlyRe
|
||||
Integer pageSize,
|
||||
HttpServletRequest req);
|
||||
|
||||
ResponseEntity<byte[]> exportMonthlyReport(LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO);
|
||||
void exportMonthlyReport(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO);
|
||||
|
||||
IPage queryPageDocument(Map<String, Object> parameter);
|
||||
}
|
||||
|
||||
+136
-12
@@ -1,5 +1,7 @@
|
||||
package com.jero.modules.report.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -32,15 +34,19 @@ import com.jero.modules.system.service.impl.SysDictItemServiceImpl;
|
||||
import com.jero.modules.system.util.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -327,7 +333,9 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> exportMonthlyReport(LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO) {
|
||||
public void exportMonthlyReport(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO) {
|
||||
ResponseEntity<byte[]> result = null;
|
||||
//获取数据
|
||||
LambdaQueryWrapper<LawsMonthlyReportWriteEO> wrapper = new LambdaQueryWrapper<>();
|
||||
@@ -353,17 +361,35 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
fileTemp.delete();
|
||||
}
|
||||
fileTemp.mkdirs();
|
||||
createWord(path,lawsMonthlyReportWriteEOS,lawsMonthlyReportTitleTemplateEOS);
|
||||
OutputStream os = null;
|
||||
try {
|
||||
createWord(path,lawsMonthlyReportWriteEOS,lawsMonthlyReportTitleTemplateEOS);
|
||||
ZipUtil.zip(path, path + ".zip");
|
||||
//文件
|
||||
os = response.getOutputStream();
|
||||
FileInputStream fis = new FileInputStream(path + ".zip");
|
||||
os = response.getOutputStream();
|
||||
|
||||
int len = 0;
|
||||
while ((len = fis.read()) != -1) {
|
||||
os.write(len);
|
||||
}
|
||||
os.flush();
|
||||
} catch (Exception e) {
|
||||
|
||||
}finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
File file = new File(uploadpath + "/tempZip");
|
||||
FileUtil.deleteContents(file);
|
||||
File fileTem = new File(uploadpath + "/tempZip.zip");
|
||||
FileUtil.deleteContents(fileTem);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*创建word文件
|
||||
* @param path
|
||||
* @param lawsMonthlyReportWriteEOS 列表数据
|
||||
* @param lawsMonthlyReportTitleTemplateEOS 章节目录
|
||||
@@ -371,32 +397,130 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
private void createWord(String path,
|
||||
List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS){
|
||||
//一级菜单
|
||||
List<String> parentIdList = lawsMonthlyReportTitleTemplateEOS.stream().map(LawsMonthlyReportTitleTemplateEO::getParentId).distinct().collect(Collectors.toList());
|
||||
LambdaQueryWrapper<LawsMonthlyReportTitleTemplateEO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(LawsMonthlyReportTitleTemplateEO::getId,parentIdList).orderByAsc(LawsMonthlyReportTitleTemplateEO::getSort);
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleOneList = lawsMonthlyReportTitleTemplateEOService.list(wrapper);
|
||||
//蔚来汽车法规月报-202004-主页面-CN
|
||||
//NIO Monthly Report on Automobile Regulations-202004-Main Page-EN
|
||||
String memoriesChapterCN = path + File.separator +"蔚来汽车法规月报" + lawsMonthlyReportWriteEOS.get(0).getMonth()+"主页面-CN.docx";
|
||||
String memoriesChapterEN = path + File.separator +"NIO Monthly Report on Automobile Regulations-" + lawsMonthlyReportWriteEOS.get(0).getMonth()+"-Main Page-EN.docx";
|
||||
String titleCN = "蔚来汽车法规月报" + lawsMonthlyReportWriteEOS.get(0).getMonth();
|
||||
String titleEN = "NIO Monthly Report on Automobile Regulations-" + lawsMonthlyReportWriteEOS.get(0).getMonth();
|
||||
|
||||
File wordFile = new File(memoriesChapterCN);
|
||||
File wordFileEn = new File(memoriesChapterEN);
|
||||
if(!wordFile.exists()){
|
||||
try {
|
||||
wordFile.getParentFile().mkdirs();
|
||||
wordFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
log.error("文件《"+memoriesChapterCN+"》创建失败");
|
||||
log.error("文件《"+titleCN+"》创建失败");
|
||||
}
|
||||
}
|
||||
|
||||
try (XWPFDocument document = new XWPFDocument();
|
||||
FileOutputStream out = new FileOutputStream(wordFile)) {
|
||||
WordUtil.exportWord(document, memoriesChapterCN, null, ParagraphAlignment.CENTER, 0, 12, false, true, "Microsoft YaHei UI");
|
||||
|
||||
|
||||
|
||||
try {
|
||||
//主页面中文版
|
||||
XWPFDocument document = new XWPFDocument();
|
||||
FileOutputStream out = new FileOutputStream(wordFile);
|
||||
word(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleCN, document,CutEnum.CN.getValue());
|
||||
document.write(out);
|
||||
//主页面英文版
|
||||
XWPFDocument documentEn = new XWPFDocument();
|
||||
FileOutputStream outCn = new FileOutputStream(wordFileEn);
|
||||
word(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleEN, documentEn,CutEnum.EN.getValue());
|
||||
documentEn.write(outCn);
|
||||
} catch (IOException e) {
|
||||
log.error("文件创建异常,异常信息为:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void word(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleOneList,
|
||||
String titleCN,
|
||||
XWPFDocument document,
|
||||
String cut) {
|
||||
String content = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
content = "主要内容";
|
||||
}else{
|
||||
content = "Content";
|
||||
}
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 12, false, true, "Microsoft YaHei UI");
|
||||
WordUtil.exportWord(document, content, null, ParagraphAlignment.LEFT, 0, 12, false, true, "Microsoft YaHei UI");
|
||||
int oneCount = 1;
|
||||
|
||||
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
|
||||
int twoCount = 1;
|
||||
String oneNumber = intToRoman(oneCount);
|
||||
//一级标题
|
||||
String oneTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
oneTitle = lawsMonthlyReportTitleTemplateEO.getTitleCn();
|
||||
}else{
|
||||
oneTitle = lawsMonthlyReportTitleTemplateEO.getTitleEn();
|
||||
}
|
||||
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT, 0, 12, false, true, "Microsoft YaHei UI");
|
||||
oneCount++;
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleTwoList = lawsMonthlyReportTitleTemplateEOS.stream().filter(e -> e.getParentId().equals(lawsMonthlyReportTitleTemplateEO.getId())).collect(Collectors.toList());
|
||||
|
||||
|
||||
for (LawsMonthlyReportTitleTemplateEO monthlyReportTitleTemplateEO : reportTitleTwoList) {
|
||||
int reportCount = 1;
|
||||
//子标题对应的月报填写的内容
|
||||
List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOList = lawsMonthlyReportWriteEOS.stream().filter(e -> monthlyReportTitleTemplateEO.getId().equals(e.getMemoriesChapter())).collect(Collectors.toList());
|
||||
String twoNumber = intToRoman(twoCount);
|
||||
twoNumber = oneNumber+"."+twoNumber;
|
||||
|
||||
//二级标题
|
||||
String twoTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
twoTitle = monthlyReportTitleTemplateEO.getTitleCn();
|
||||
}else{
|
||||
twoTitle = monthlyReportTitleTemplateEO.getTitleEn();
|
||||
}
|
||||
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT, 2, 12, false, true, "Microsoft YaHei UI");
|
||||
twoCount++;
|
||||
|
||||
for (LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO : lawsMonthlyReportWriteEOList) {
|
||||
//月报内容标题
|
||||
String reportTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
reportTitle = lawsMonthlyReportWriteEO.getTitleCn();
|
||||
}else{
|
||||
reportTitle = lawsMonthlyReportWriteEO.getTitleEn();
|
||||
}
|
||||
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT, 6, 10, false, false, "Microsoft YaHei UI");
|
||||
reportCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字转罗马字
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public String intToRoman(int num) {
|
||||
int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
|
||||
String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
|
||||
StringBuffer ss=new StringBuffer();
|
||||
for (int i=0;i<values.length;i++){
|
||||
while (num>=values[i]){
|
||||
num=num-values[i];
|
||||
ss.append(symbols[i]);
|
||||
}
|
||||
if (num==0){
|
||||
return ss.toString();
|
||||
}
|
||||
}
|
||||
System.out.println(ss);
|
||||
return ss.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage queryPageDocument(Map<String, Object> parameter) {
|
||||
String cut = (String) parameter.get("cut");//中英文切换标识
|
||||
|
||||
Reference in New Issue
Block a user