月报整合导出(临时)
This commit is contained in:
+12
@@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -22,6 +23,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -172,4 +174,14 @@ public class LawsMonthlyReportWriteEOController extends JeroController<LawsMonth
|
||||
return super.importExcel(request, response, LawsMonthlyReportWriteEO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 月报整合导出zip
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -187,4 +187,8 @@ public class LawsMonthlyReportWriteEO implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private String cut;
|
||||
|
||||
//导出
|
||||
@TableField(exist = false)
|
||||
private String ids;
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -3,6 +3,7 @@ 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 java.util.List;
|
||||
@@ -74,4 +75,6 @@ public interface ILawsMonthlyReportWriteEOService extends IService<LawsMonthlyRe
|
||||
Integer pageNo,
|
||||
Integer pageSize,
|
||||
HttpServletRequest req);
|
||||
|
||||
ResponseEntity<byte[]> exportMonthlyReport(LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO);
|
||||
}
|
||||
|
||||
+83
@@ -18,13 +18,21 @@ import com.jero.modules.report.service.ILawsMonthlyReportTitleTemplateEOService;
|
||||
import com.jero.modules.report.service.ILawsMonthlyReportWriteEOService;
|
||||
import com.jero.modules.report.service.INewOpinionTemplateEOService;
|
||||
import com.jero.modules.report.service.INewStandardTemplateEOService;
|
||||
import com.jero.modules.report.util.WordUtil;
|
||||
import com.jero.modules.system.entity.SysCategory;
|
||||
import com.jero.modules.system.service.impl.SysCategoryServiceImpl;
|
||||
import com.jero.modules.system.util.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
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 java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -48,6 +56,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
private ILawsMonthlyReportTitleTemplateEOService lawsMonthlyReportTitleTemplateEOService;
|
||||
@Autowired
|
||||
private SysCategoryServiceImpl sysCategoryService;
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
@@ -298,4 +308,77 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> exportMonthlyReport(LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO) {
|
||||
ResponseEntity<byte[]> result = null;
|
||||
//获取数据
|
||||
LambdaQueryWrapper<LawsMonthlyReportWriteEO> wrapper = new LambdaQueryWrapper<>();
|
||||
if(StringUtils.isNotBlank(lawsMonthlyReportWriteEO.getMonth())){
|
||||
wrapper.eq(LawsMonthlyReportWriteEO::getMonth,lawsMonthlyReportWriteEO.getMonth());
|
||||
}
|
||||
if(StringUtils.isNotBlank(lawsMonthlyReportWriteEO.getIds())){
|
||||
wrapper.in(LawsMonthlyReportWriteEO::getId,StringUtils.join(lawsMonthlyReportWriteEO.getIds(),""));
|
||||
}
|
||||
List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS = this.list(wrapper);
|
||||
//月报填写列表所有的章节目录
|
||||
List<String> memoriesChapterList = lawsMonthlyReportWriteEOS.stream()
|
||||
.map(LawsMonthlyReportWriteEO::getMemoriesChapter).distinct().collect(Collectors.toList());
|
||||
|
||||
//所有的章节目录
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS = lawsMonthlyReportTitleTemplateEOService.list();
|
||||
lawsMonthlyReportTitleTemplateEOS = lawsMonthlyReportTitleTemplateEOS.stream()
|
||||
.filter(e -> memoriesChapterList.contains(e.getId())).collect(Collectors.toList());
|
||||
|
||||
String path = uploadpath + "/tempZip";
|
||||
File fileTemp = new File(path);
|
||||
if (fileTemp.exists()) {
|
||||
fileTemp.delete();
|
||||
}
|
||||
fileTemp.mkdirs();
|
||||
createWord(path,lawsMonthlyReportWriteEOS,lawsMonthlyReportTitleTemplateEOS);
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @param lawsMonthlyReportWriteEOS 列表数据
|
||||
* @param lawsMonthlyReportTitleTemplateEOS 章节目录
|
||||
*/
|
||||
private void createWord(String path,
|
||||
List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS){
|
||||
//蔚来汽车法规月报-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";
|
||||
|
||||
File wordFile = new File(memoriesChapterCN);
|
||||
if(!wordFile.exists()){
|
||||
try {
|
||||
wordFile.getParentFile().mkdirs();
|
||||
wordFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
log.error("文件《"+memoriesChapterCN+"》创建失败");
|
||||
}
|
||||
}
|
||||
|
||||
try (XWPFDocument document = new XWPFDocument();
|
||||
FileOutputStream out = new FileOutputStream(wordFile)) {
|
||||
WordUtil.exportWord(document, memoriesChapterCN, null, ParagraphAlignment.CENTER, 0, 12, false, true, "Microsoft YaHei UI");
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("文件创建异常,异常信息为:" + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.jero.modules.report.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
|
||||
public class WordUtil {
|
||||
/**
|
||||
* 导出工具示例
|
||||
*
|
||||
* @param document POI文件类
|
||||
* @param text 输出文本
|
||||
* @param textColor 字体颜色
|
||||
* @param align 字体位置,默认居左
|
||||
* @param spaceNum 预留空格数,默认不留空格
|
||||
* @param fontSize 字体大小,默认11
|
||||
* @param isNewline 是否换行,换行后文本失效
|
||||
* @param isBold 是否加粗,默认不加粗
|
||||
* @param fontFamily 字体,默认宋体
|
||||
*/
|
||||
public static void exportWord(XWPFDocument document,
|
||||
String text,
|
||||
String textColor,
|
||||
ParagraphAlignment align,
|
||||
Integer spaceNum,
|
||||
Integer fontSize,
|
||||
Boolean isNewline,
|
||||
Boolean isBold,
|
||||
String fontFamily) {
|
||||
|
||||
document.createParagraph();
|
||||
|
||||
//添加标题
|
||||
XWPFParagraph titleParagraph = document.createParagraph();
|
||||
//设置段落左对齐
|
||||
if (align == null) {
|
||||
titleParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
} else {
|
||||
titleParagraph.setAlignment(align);
|
||||
}
|
||||
|
||||
XWPFRun titleParagraphRun = titleParagraph.createRun();
|
||||
if (isNewline) {
|
||||
titleParagraphRun.setText("\r");
|
||||
} else {
|
||||
//封装文字内容
|
||||
StringBuilder newText = new StringBuilder();
|
||||
for (int i = 0; i < spaceNum; i++) {
|
||||
newText.append(" ");
|
||||
}
|
||||
newText.append(text);
|
||||
titleParagraphRun.setText(newText.toString());
|
||||
|
||||
//设置颜色
|
||||
if (StringUtils.isNotEmpty(textColor)) {
|
||||
titleParagraphRun.setColor(textColor);
|
||||
} else {
|
||||
titleParagraphRun.setColor("000000");
|
||||
}
|
||||
//设置文字大小
|
||||
if (ObjectUtil.isNotEmpty(fontSize)) {
|
||||
titleParagraphRun.setFontSize(fontSize);
|
||||
} else {
|
||||
titleParagraphRun.setFontSize(11);
|
||||
}
|
||||
|
||||
//设置加粗
|
||||
if (ObjectUtil.isNotEmpty(isBold)) {
|
||||
titleParagraphRun.setBold(isBold);
|
||||
} else {
|
||||
titleParagraphRun.setBold(false);
|
||||
}
|
||||
|
||||
//设置字体样式
|
||||
if (StringUtils.isNotEmpty(fontFamily)) {
|
||||
titleParagraphRun.setFontFamily(fontFamily);
|
||||
} else {
|
||||
titleParagraphRun.setFontFamily("宋体");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user