Merge remote-tracking branch 'origin/dev_third_stage' into dev_third_stage

This commit is contained in:
高嵩
2022-10-10 15:01:24 +08:00
41 changed files with 1107 additions and 372 deletions
@@ -11,11 +11,12 @@ import com.jero.modules.compare.mapper.SarFileCompareItemCommentMapper;
import com.jero.modules.compare.service.ISarFileCompareInfoService;
import com.jero.modules.compare.service.ISarFileCompareItemCommentService;
import com.jero.modules.compare.service.ISarFileCompareItemService;
import com.jero.modules.compare.utils.ConvertHtml2Excel;
import com.jero.modules.system.util.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -255,6 +256,12 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
sheet.setColumnWidth(i, columnWidth[i]);
}
}
//超链接样式
CellStyle cellStyleLink =workbook.createCellStyle();
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
font.setColor(HSSFColor.LIGHT_BLUE.index);
cellStyleLink.setFont(font);
cellStyleLink.setWrapText(true);
int i = 1;
//记录需要合并的单元格
List<SarFileCompareExcelMergeCell> mergeCells = new ArrayList<>();
@@ -272,69 +279,20 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
row.createCell(1).setCellValue(itemLeft.getItemsNum());
row.createCell(2).setCellValue(itemLeft.getItemsName());
String text = itemLeft.getItemsText();
text = text.replace("<p>", "").replace("</p>", "\r\n");
addImgdata(text,request.getSession());
String rowDataAndPath = (String) request.getSession().getAttribute("txtAndImg");
String rowDataAndPath = getSplitContent(request, text);
leftSplit = rowDataAndPath.split("---");
if (leftSplit.length > 1) {
for (int j = 0; j < leftSplit.length; j++) {
if (ObjectUtils.isNotEmpty(leftSplit[j])) {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
BufferedImage bufferImg = null;
if (j > 0) {
Row row2 = sheet.getRow(j + i);
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
if (leftSplit[j].contains("/upFiles")) {
row2.setHeight((short) 3000); //设置行高
//先将图片下载到本地
String fileLastName = leftSplit[j].substring(leftSplit[j].lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(leftSplit[j])) {
try (InputStream in = CosBootUtil.download(leftSplit[j])) {
copyFile2(in, dir + File.separator + fileLastName);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
File file = new File(dir + File.separator + fileLastName);
if (file.exists()) {
bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
row2.createCell(3).setCellValue(leftSplit[j]);
}
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
} else {
if (leftSplit[j].contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高
//先将图片下载到本地
String fileLastName = leftSplit[j].substring(leftSplit[j].lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(leftSplit[j])) {
try (InputStream in = CosBootUtil.download(leftSplit[j])) {
copyFile2(in, dir + File.separator + fileLastName);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
File file = new File(dir + File.separator + fileLastName);
if (file.exists()) {
bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 3, j + i, (short) 3, j + i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
row.createCell(3).setCellValue(leftSplit[j]);
}
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
}
}
}
@@ -346,7 +304,6 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} else {
row.createCell(3).setCellValue(rowDataAndPath);
}
row.setRowStyle(cellStyle);
}
}
String itemIdRight = itemComment.getItemsIdRight();
@@ -356,69 +313,20 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
row.createCell(5).setCellValue(itemRight.getItemsNum());
row.createCell(6).setCellValue(itemRight.getItemsName());
String text = itemRight.getItemsText();
text = text.replace("<p>", "").replace("</p>", "\r\n");
addImgdata(text,request.getSession());
String rowDataAndPath = (String) request.getSession().getAttribute("txtAndImg");
String rowDataAndPath = getSplitContent(request, text);
rightSplit = rowDataAndPath.split("---");
if (rightSplit.length > 1) {
for (int j = 0; j < rightSplit.length; j++) {
if (ObjectUtils.isNotEmpty(rightSplit[j])) {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
BufferedImage bufferImg = null;
if (j > 0) {
Row row2 = sheet.getRow(j + i);
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
if (rightSplit[j].contains("/upFiles")) {
row2.setHeight((short) 3000); //设置行高
//先将图片下载到本地
String fileLastName = rightSplit[j].substring(rightSplit[j].lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(rightSplit[j])) {
try (InputStream in = CosBootUtil.download(rightSplit[j])) {
copyFile2(in, dir + File.separator + fileLastName);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
File file = new File(dir + File.separator + fileLastName);
if (file.exists()) {
bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 7, j + i, (short) 7, j + i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
row2.createCell(7).setCellValue(rightSplit[j]);
}
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7);
} else {
if (rightSplit[j].contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高
//先将图片下载到本地
String fileLastName = rightSplit[j].substring(rightSplit[j].lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(rightSplit[j])) {
try (InputStream in = CosBootUtil.download(rightSplit[j])) {
copyFile2(in, dir + File.separator + fileLastName);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
File file = new File(dir + File.separator + fileLastName);
if (file.exists()) {
bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) 7, j + i, (short) 7, j + i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
row.createCell(7).setCellValue(rightSplit[j]);
}
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7);
}
}
}
@@ -428,11 +336,11 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} else {
row.createCell(7).setCellValue(rowDataAndPath);
}
row.setRowStyle(cellStyle);
}
}
row.createCell(8).setCellValue(itemComment.getComment());
for (int j = 0; j < 7; j++) {
row.setRowStyle(cellStyle);
for (int j = 0; j < 9; j++) {
Cell cell = row.getCell(j);
if (null != cell) {
cell.setCellStyle(cellStyle);
@@ -495,18 +403,132 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
/**
* 提取字符串中<img>标签内容中的图片路径,并重新按顺序拼接
* 处理图片跟表格类型的数据
* @param workbook
* @param dir
* @param patriarch
* @param cellStyleLink
* @param byteArrayOut
* @param row
* @param i
* @param j
* @param text
* @param cellNum
* @throws IOException
*/
private void handleSpecificData(Workbook workbook, String dir, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int cellNum) throws IOException {
if (text.contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高
//先将图片下载到本地
String fileLastName = text.substring(text.lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(text)) {
try (InputStream in = CosBootUtil.download(text)) {
copyFile2(in, dir + File.separator + fileLastName);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
File file = new File(dir + File.separator + fileLastName);
if (file.exists()) {
BufferedImage bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200, (short) cellNum, j + i, (short) cellNum, j + i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
Cell cell = row.createCell(cellNum);
if (text.contains("<table")) {
tableAssociate(workbook, cellStyleLink, cell, text);
} else {
cell.setCellValue(text);
}
}
}
/**
* 当前excel中新开sheet生成表格,并在指定单元格用超链接关联
* @param workbook
* @param cellStyleLink
* @param cell
* @param tableHtml
*/
private void tableAssociate(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) {
cell.setCellValue("点击查看详情");
//新开sheet生成表格
if (org.apache.commons.lang.StringUtils.isNotEmpty(tableHtml) && tableHtml.indexOf("<tbody>") < 0) {
if (tableHtml.indexOf("<thead>") < 0) {
tableHtml = tableHtml.replaceFirst("<tr>", "<tbody><tr>");
tableHtml = tableHtml.replaceFirst("</table>", "</tbody></table>");
} else {
tableHtml = tableHtml.replaceFirst("</thead>", "</thead><tbody>");
tableHtml = tableHtml.replaceFirst("</table>", "</tbody></table>");
}
}
String cnt = "\n";
tableHtml = tableHtml.replaceAll("<[\\s]*?br[^>]*?>|<[\\s]*?\\/[\\s]*?br[\\s]*?>", cnt);
String tableSheetName = "表格" + System.currentTimeMillis();
ConvertHtml2Excel.table2Excel(tableHtml, (HSSFWorkbook) workbook, tableSheetName);
//添加超链接
CreationHelper createHelper = workbook.getCreationHelper();
Hyperlink hyperlink1 = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
String tableName = "#\'" + tableSheetName + "\'!A1";
hyperlink1.setAddress(tableName);
cell.setHyperlink(hyperlink1);// 链接
cell.setCellStyle(cellStyleLink);
}
/**
* 获取文字、图片、表格分割后的内容
* @param request
* @param text
* @return
*/
private void addImgdata(String text,HttpSession session) {
private String getSplitContent(HttpServletRequest request, String text) {
text = text.replace("<p>", "").replace("</p>", "\r\n");
//分割图片
splitImg(text, request.getSession());
//分割表格
String txtAndImg = (String) request.getSession().getAttribute("txtAndImg");
txtAndImg = txtAndImg.replaceAll("table", "replaceTable");
splitTable(txtAndImg, request.getSession());
return (String) request.getSession().getAttribute("textAndTableAndImg");
}
/**
* 分割表格
* @param textAndImg
* @param session
*/
private void splitTable(String textAndImg,HttpSession session) {
if (textAndImg.contains("<replaceTable")) {
String left = textAndImg.substring(0, textAndImg.indexOf("<replaceTable"));
String right = textAndImg.substring(textAndImg.indexOf("/replaceTable>") + 14);
String table = textAndImg.substring(textAndImg.indexOf("<replaceTable"), textAndImg.indexOf("/replaceTable>")+14);
table = table.replaceAll("replaceTable", "table");
textAndImg = left + "---" + table + "---" + right;
splitTable(textAndImg, session);
} else {
session.setAttribute("textAndTableAndImg", textAndImg);
}
}
/**
* 分割图片
* @param text
* @param session
* @return
*/
private void splitImg(String text,HttpSession session) {
if (text.contains("<img")) {
String txtLeft = text.substring(0, text.indexOf("<img"));
String txtRight = text.substring(text.indexOf("g\">") + 3);
String img = text.substring(text.indexOf("<img"), text.indexOf("g\">"));
String path = img.substring(img.lastIndexOf("=") + 1)+"g";
text = txtLeft + "---" + path + "---" + txtRight;
addImgdata(text, session);
splitImg(text, session);
} else {
session.setAttribute("txtAndImg", text);
}
@@ -0,0 +1,231 @@
package com.jero.modules.compare.utils;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFCellUtil;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/****
* html转excel
* @author user
*
*/
public class ConvertHtml2Excel {
/**
* html表格转excel
*
* @param tableHtml 如
* <table>
* ..
* </table>
* @return
*/
public static void table2Excel(String tableHtml, HSSFWorkbook wb,String tableSheetName) {
HSSFSheet sheet = wb.createSheet(tableSheetName);
List<CrossRangeCellMeta> crossRowEleMetaLs = new ArrayList<CrossRangeCellMeta>();
int rowIndex = 0;
try {
Document data = DocumentHelper.parseText(tableHtml);
// 生成表头
Element thead = data.getRootElement().element("thead");
HSSFCellStyle titleStyle = getTitleStyle(wb);
int ls=0;//列数
if (thead != null) {
List<Element> trLs = thead.elements("tr");
for (Element trEle : trLs) {
HSSFRow row = sheet.createRow(rowIndex);
List<Element> thLs = trEle.elements("th");
ls=thLs.size();
makeRowCell(thLs, rowIndex, row, 0, titleStyle, crossRowEleMetaLs);
rowIndex++;
}
}
// 生成表体
Element tbody = data.getRootElement().element("tbody");
HSSFCellStyle contentStyle = getContentStyle(wb);
if (tbody != null) {
List<Element> trLs = tbody.elements("tr");
for (Element trEle : trLs) {
HSSFRow row = sheet.createRow(rowIndex);
List<Element> thLs = trEle.elements("th");
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, titleStyle, crossRowEleMetaLs);
List<Element> tdLs = trEle.elements("td");
makeRowCell(tdLs, rowIndex, row, cellIndex, contentStyle, crossRowEleMetaLs);
rowIndex++;
}
}
// 合并表头
for (CrossRangeCellMeta crcm : crossRowEleMetaLs) {
sheet.addMergedRegion(new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()));
setRegionStyle(sheet, new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()),contentStyle);
}
for(int i=0;i<ls;i++){
sheet.autoSizeColumn(i, true);//设置列宽
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
/**
* 生产行内容
*
* @return 最后一列的cell index
*/
/**
* @param tdLs th或者td集合
* @param rowIndex 行号
* @param row POI行对象
* @param startCellIndex
* @param cellStyle 样式
* @param crossRowEleMetaLs 跨行元数据集合
* @return
*/
private static int makeRowCell(List<Element> tdLs, int rowIndex, HSSFRow row, int startCellIndex, HSSFCellStyle cellStyle,
List<CrossRangeCellMeta> crossRowEleMetaLs) {
int i = startCellIndex;
for (int eleIndex = 0; eleIndex < tdLs.size(); i++, eleIndex++) {
int captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
while (captureCellSize > 0) {
for (int j = 0; j < captureCellSize; j++) {// 当前行跨列处理(补单元格)
row.createCell(i);
i++;
}
captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
}
Element thEle = tdLs.get(eleIndex);
String val = thEle.getTextTrim();
if (StringUtils.isBlank(val)) {
Element e = thEle.element("a");
if (e != null) {
val = e.getTextTrim();
}
}
HSSFCell c = row.createCell(i);
if (NumberUtils.isNumber(val)) {
c.setCellValue(Double.parseDouble(val));
c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
} else {
c.setCellValue(val);
}
int rowSpan = NumberUtils.toInt(thEle.attributeValue("rowspan"), 1);
int colSpan = NumberUtils.toInt(thEle.attributeValue("colspan"), 1);
c.setCellStyle(cellStyle);
if (rowSpan > 1 || colSpan > 1) { // 存在跨行或跨列
crossRowEleMetaLs.add(new CrossRangeCellMeta(rowIndex, i, rowSpan, colSpan));
}
if (colSpan > 1) {// 当前行跨列处理(补单元格)
for (int j = 1; j < colSpan; j++) {
i++;
row.createCell(i);
}
}
}
return i;
}
/**
* 设置合并单元格的边框样式
*
* @param sheet
* @param region
* @param cs
*/
public static void setRegionStyle(HSSFSheet sheet, CellRangeAddress region, HSSFCellStyle cs) {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
HSSFRow row = HSSFCellUtil.getRow(i, sheet);
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
HSSFCell cell = HSSFCellUtil.getCell(row, (short) j);
cell.setCellStyle(cs);
}
}
}
/**
* 获得因rowSpan占据的单元格
*
* @param rowIndex 行号
* @param colIndex 列号
* @param crossRowEleMetaLs 跨行列元数据
* @return 当前行在某列需要占据单元格
*/
private static int getCaptureCellSize(int rowIndex, int colIndex, List<CrossRangeCellMeta> crossRowEleMetaLs) {
int captureCellSize = 0;
for (CrossRangeCellMeta crossRangeCellMeta : crossRowEleMetaLs) {
if (crossRangeCellMeta.getFirstRow() < rowIndex && crossRangeCellMeta.getLastRow() >= rowIndex) {
if (crossRangeCellMeta.getFirstCol() <= colIndex && crossRangeCellMeta.getLastCol() >= colIndex) {
captureCellSize = crossRangeCellMeta.getLastCol() - colIndex + 1;
}
}
}
return captureCellSize;
}
/**
* 获得标题样式
*
* @param workbook
* @return
*/
private static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
short titlebackgroundcolor = HSSFColor.GREY_25_PERCENT.index;
short fontSize = 12;
String fontName = "宋体";
HSSFCellStyle style = workbook.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(titlebackgroundcolor);// 背景色
HSSFFont font = workbook.createFont();
font.setFontName(fontName);
font.setFontHeightInPoints(fontSize);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style.setFont(font);
return style;
}
/**
* 获得内容样式
*
* @param wb
* @return
*/
private static HSSFCellStyle getContentStyle(HSSFWorkbook wb) {
short fontSize = 12;
String fontName = "宋体";
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom((short) 1);
style.setBorderTop((short) 1);
style.setBorderLeft((short) 1);
style.setBorderRight((short) 1);
HSSFFont font = wb.createFont();
font.setFontName(fontName);
font.setFontHeightInPoints(fontSize);
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
return style;
}
}
@@ -0,0 +1,37 @@
package com.jero.modules.compare.utils;
public class CrossRangeCellMeta {
public CrossRangeCellMeta(int firstRowIndex, int firstColIndex, int rowSpan, int colSpan) {
super();
this.firstRowIndex = firstRowIndex;
this.firstColIndex = firstColIndex;
this.rowSpan = rowSpan;
this.colSpan = colSpan;
}
private int firstRowIndex;
private int firstColIndex;
private int rowSpan;// 跨越行数
private int colSpan;// 跨越列数
public int getFirstRow() {
return firstRowIndex;
}
public int getLastRow() {
return firstRowIndex + rowSpan - 1;
}
public int getFirstCol() {
return firstColIndex;
}
public int getLastCol() {
return firstColIndex + colSpan - 1;
}
public int getColSpan(){
return colSpan;
}
}
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.base.controller.JeroController;
import com.jero.modules.extRepo.entity.ERFTreeDataVO;
import com.jero.modules.extRepo.entity.ExtRepoData;
@@ -66,11 +67,20 @@ public class ExtRepoFolderController extends JeroController<ExtRepoFolder, IExtR
public Result<?> add(@Validated @RequestBody ExtRepoFolder extRepoFolder, HttpSession session) {
Result<ExtRepoFolder> result = new Result();
session.setAttribute("haveSuperiorManageAuth", false);
extRepoFolderService.haveSuperiorManageAuth(extRepoFolder.getSupFolder(),session);
if (ObjectUtils.isNotEmpty(session.getAttribute("haveSuperiorManageAuth"))&&(Boolean) session.getAttribute("haveSuperiorManageAuth")) {
ExtRepoFolder folder = extRepoFolderService.queryById(extRepoFolder.getSupFolder());
extRepoFolderService.haveSuperiorManageAuth(folder.getSupFolder(),session);
//上层是否有权限
boolean boo = (Boolean)session.getAttribute("haveSuperiorManageAuth");
if (boo||extRepoFolderService.haveManageAuth(extRepoFolder.getSupFolder())) {
if (!extRepoFolder.isAddSub()) {
//增加同级文件夹
ExtRepoFolder folder = extRepoFolderService.queryById(extRepoFolder.getSupFolder());
if (!boo) {
if (CutEnum.CN.getValue().equals(extRepoFolder.getCut())) {
throw new JeroBootException("无法创建同级文件夹!请联系管理员!");
} else {
throw new JeroBootException("Unable to create a sibling folder ! Please Contact your administrator !");
}
}
extRepoFolder.setSupFolder(folder.getSupFolder());
}
extRepoFolderService.add(extRepoFolder);
@@ -752,20 +752,15 @@ public class LawsTechnologyEvaluationEOServiceImpl extends ServiceImpl<LawsTechn
countError++;
}
if(StringUtils.isEmpty(itemName)){
if(StringUtils.equals(cut,CutEnum.CN.getValue())){
errorMsg += "条款名称不能为空;";
}else if (StringUtils.equals(cut,CutEnum.EN.getValue())){
errorMsg += "Item Name cannot be empty;";
if(StringUtils.isNotEmpty(itemName)){
if(itemName.length() > 100){
if(StringUtils.equals(cut,CutEnum.CN.getValue())){
errorMsg += "条款名称长度不能超过100;";
}else if (StringUtils.equals(cut,CutEnum.EN.getValue())){
errorMsg += "Item Name length of the cannot exceed 100;";
}
countError++;
}
countError++;
}else if(itemName.length() > 100){
if(StringUtils.equals(cut,CutEnum.CN.getValue())){
errorMsg += "条款名称长度不能超过100;";
}else if (StringUtils.equals(cut,CutEnum.EN.getValue())){
errorMsg += "Item Name length of the cannot exceed 100;";
}
countError++;
}
if(StringUtils.isEmpty(itemContent)){
@@ -884,8 +884,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
titleCN = "\r\n\r\n" + titleCN + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
false, false, "Blue Sky Noto Regular",null,null,flag);
WordUtil.exportWord(document, moth+"\r\n", null, ParagraphAlignment.CENTER, 0, 12,
false, true, "Blue Sky Noto Regular",null,null,flag);
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
false, false, "Blue Sky Noto Regular",null,null,flag);
//添加下一页
document.createParagraph().createRun().addBreak(BreakType.PAGE);
}
@@ -900,8 +900,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
titleCN = "\r\n\r\n" + titleCN + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
false, false, "Blue Sky Noto Regular",null,null,flag);
WordUtil.exportWord(document, moth+"\r\n", null, ParagraphAlignment.CENTER, 0, 12,
false, true, "Blue Sky Noto Regular",null,null,flag);
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
false, false, "Blue Sky Noto Regular",null,null,flag);
//添加下一页
document.createParagraph().createRun().addBreak(BreakType.PAGE);
}
@@ -266,12 +266,15 @@ public class WordUtil {
picture.getCTPicture().getBlipFill().getBlip().setEmbed(blipID);
run.addTab();
is.close();
run.setText(" "+month);
run.setFontSize(11);
run.setFontFamily("Blue Sky Noto Regular");
}
//页眉第二个段落展示日期------------------------------------------------------------
XWPFParagraph paragraph = header.createParagraph();//创建新的段落
paragraph.setAlignment(ParagraphAlignment.RIGHT);//段落文本的对齐方式
// paragraph.setAlignment(ParagraphAlignment.RIGHT);//段落文本的对齐方式
XWPFRun run = paragraph.createRun();
run.setText(month);
// run.setText(month);
//页脚(三个段落分别展示3个内容)-----------------------------------------------------
XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
@@ -280,11 +283,15 @@ public class WordUtil {
paragraph.setAlignment(ParagraphAlignment.CENTER);
run = paragraph.createRun();
run.setText("NIO Internal");
run.setFontSize(11);
run.setFontFamily("Blue Sky Standard Regular");
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
run = paragraph.createRun();
run.setText("NIO.com");
run.setFontSize(11);
run.setFontFamily("Blue Sky Noto Regular");
//生成页码---------------------------------------------------------------------
paragraph = footer.createParagraph();
@@ -317,8 +324,8 @@ public class WordUtil {
pageMar.setTop(BigInteger.valueOf(1440)); //页眉高度
pageMar.setBottom(BigInteger.valueOf(1440));//页脚高度
pageMar.setHeader(BigInteger.valueOf(500)); //页眉上边框到顶部的距离
pageMar.setFooter(BigInteger.valueOf(800)); //页脚下边框到底部的距离
pageMar.setHeader(BigInteger.valueOf(720)); //页眉上边框到顶部的距离
pageMar.setFooter(BigInteger.valueOf(720)); //页脚下边框到底部的距离
}
/**
@@ -3754,7 +3754,26 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
@Override
public int insertForeach(List<SarFileSplitItemsEO> messageList) {
return dao.insertForeach(messageList);
// 解决一次批量插入太多 PacketTooBigException 异常
int total = messageList.size();
int count = 0;
int pageSum = 1;
if(total > 100) {
pageSum = total / 100; // 总页数
if ((total % 100) > 0) {
pageSum += 1;
}
}
List<SarFileSplitItemsEO> subList = new ArrayList<>();
for(int i = 0; i < pageSum; i++) {
int j = i*100+100;
if (i == pageSum -1) {
j = total;
}
subList = messageList.subList(i*100, j);
count += dao.insertForeach(subList);
}
return count;
}
/**
@@ -1784,7 +1784,7 @@ public class FileSplitPdfService {
if(StringUtils.isNotBlank(preName)) {
List<String> nowStartList = fileSpiltService.getNewNowStart(preName);
List<String> subList1 = startDigitList.subList(preNameNum, startDigitList.size()-1);
List<String> subList1 = startDigitList.subList(preNameNum, startDigitList.size());
// 后文有一级以下的标题
for (int i = nowStartList.size() - 1; i >= 1; i--) {
int index1 = subList1.indexOf(nowStartList.get(i));
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@@ -79,8 +80,26 @@ public class SarFileSplitItemsValEOServiceImpl extends ServiceImpl<SarFileSplitI
@Override
public int insertForeach(List<SarFileSplitItemsValEO> itemValList) {
return dao.insertForeach(itemValList);
// 解决一次批量插入太多 PacketTooBigException 异常
int total = itemValList.size();
int count = 0;
int pageSum = 1;
if(total > 100) {
pageSum = total / 100; // 总页数
if ((total % 100) > 0) {
pageSum += 1;
}
}
List<SarFileSplitItemsValEO> subList = new ArrayList<>();
for(int i = 0; i < pageSum; i++) {
int j = i*100+100;
if (i == pageSum -1) {
j = total;
}
subList = itemValList.subList(i*100, j);
count += dao.insertForeach(subList);
}
return count;
}
}