fix:对比导出问题
This commit is contained in:
+86
-71
@@ -23,8 +23,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
import org.apache.poi.hssf.util.HSSFColor;
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -309,7 +309,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
//超链接样式
|
//超链接样式
|
||||||
CellStyle cellStyleLink =workbook.createCellStyle();
|
CellStyle cellStyleLink =workbook.createCellStyle();
|
||||||
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
|
HSSFFont font = ((HSSFWorkbook) workbook).createFont();
|
||||||
font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
// font.setColor(HSSFColor.HSSFColorPredefined.LIGHT_BLUE.getIndex());
|
||||||
cellStyleLink.setFont(font);
|
cellStyleLink.setFont(font);
|
||||||
cellStyleLink.setWrapText(true);
|
cellStyleLink.setWrapText(true);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
@@ -336,6 +336,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
log.info("-------------- 开始开始拆分左侧图片、文字、表格 :" + text + "-----------------");
|
log.info("-------------- 开始开始拆分左侧图片、文字、表格 :" + text + "-----------------");
|
||||||
rowDataAndPathLeft = getSplitContent(request, text);
|
rowDataAndPathLeft = getSplitContent(request, text);
|
||||||
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPathLeft +"-----------------");
|
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPathLeft +"-----------------");
|
||||||
|
if (rowDataAndPathLeft.startsWith("---")){
|
||||||
|
rowDataAndPathLeft = rowDataAndPathLeft.replaceFirst("---", "");
|
||||||
|
}
|
||||||
leftSplit = rowDataAndPathLeft.split("---");
|
leftSplit = rowDataAndPathLeft.split("---");
|
||||||
if (leftSplit.length > 1) {
|
if (leftSplit.length > 1) {
|
||||||
for (int j = 0; j < leftSplit.length; j++) {
|
for (int j = 0; j < leftSplit.length; j++) {
|
||||||
@@ -379,6 +382,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
log.info("-------------- 开始开始拆分右侧图片、文字、表格 :"+ text +" -----------------");
|
log.info("-------------- 开始开始拆分右侧图片、文字、表格 :"+ text +" -----------------");
|
||||||
rowDataAndPathRight = getSplitContent(request, text);
|
rowDataAndPathRight = getSplitContent(request, text);
|
||||||
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPathRight +" -----------------");
|
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPathRight +" -----------------");
|
||||||
|
if (rowDataAndPathRight.startsWith("---")){
|
||||||
|
rowDataAndPathRight = rowDataAndPathRight.replaceFirst("---", "");
|
||||||
|
}
|
||||||
rightSplit = rowDataAndPathRight.split("---");
|
rightSplit = rowDataAndPathRight.split("---");
|
||||||
if (rightSplit.length > 1) {
|
if (rightSplit.length > 1) {
|
||||||
for (int j = 0; j < rightSplit.length; j++) {
|
for (int j = 0; j < rightSplit.length; j++) {
|
||||||
@@ -409,76 +415,85 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 左、右条款内容
|
Integer leftStart = sarFileCompareExcelMergeCell.getLeftStart();
|
||||||
String leftContent = String.valueOf(row.getCell(3));
|
Integer leftEnd = sarFileCompareExcelMergeCell.getLeftEnd();
|
||||||
String rightContent = String.valueOf(row.getCell(7));
|
if (!Objects.isNull(leftStart) || !Objects.isNull(leftEnd)) {
|
||||||
// 左、右条款名称
|
int rows = Math.max(leftEnd - leftStart, 1);
|
||||||
String leftName = String.valueOf(row.getCell(2));
|
for (int j = 0; j <= rows; j++) {
|
||||||
String rightName = String.valueOf(row.getCell(6));
|
Row row1 = sheet.getRow(j + leftStart);
|
||||||
// 左右条款内容对比
|
// 左、右条款内容
|
||||||
if (StringUtils.isNotBlank(leftContent) && StringUtils.isNotBlank(rightContent)) {
|
String leftContent = String.valueOf(Objects.isNull(row1.getCell(3)) ? "" : row1.getCell(3));
|
||||||
// 获取对比结果
|
String rightContent = String.valueOf(Objects.isNull(row1.getCell(7)) ? "" : row1.getCell(7));
|
||||||
DiffUtils dmp = new DiffUtils();
|
// 左、右条款名称
|
||||||
List<String> htmlDiffStrContent = dmp.getHtmlDiffStr(leftContent, rightContent);
|
String leftName = String.valueOf(row1.getCell(2));
|
||||||
List<String> htmlDiffStrName = dmp.getHtmlDiffStr(leftName, rightName);
|
String rightName = String.valueOf(row1.getCell(6));
|
||||||
|
// 左右条款内容对比
|
||||||
|
if ((StringUtils.isNotBlank(leftContent) || StringUtils.isNotBlank(rightContent))) {
|
||||||
|
// 获取对比结果
|
||||||
|
DiffUtils dmp = new DiffUtils();
|
||||||
|
List<String> htmlDiffStrContent = dmp.getHtmlDiffStr(leftContent, rightContent);
|
||||||
|
List<String> htmlDiffStrName = dmp.getHtmlDiffStr(leftName, rightName);
|
||||||
|
|
||||||
Font redFont = workbook.createFont();
|
Font redFont = workbook.createFont();
|
||||||
redFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
redFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
||||||
Font greenFont = workbook.createFont();
|
Font greenFont = workbook.createFont();
|
||||||
greenFont.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
|
greenFont.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
|
||||||
|
|
||||||
// 获取红色字体标签的所有下标位置
|
// 获取红色字体标签的所有下标位置
|
||||||
String redTag = "<span class=\"delClass\">";
|
String redTag = "<span class=\"delClass\">";
|
||||||
List<String> leftContentRedTagIndex = getTagIndex(htmlDiffStrContent.get(0), redTag);
|
List<String> leftContentRedTagIndex = getTagIndex(htmlDiffStrContent.get(0), redTag);
|
||||||
HSSFRichTextString leftRich = new HSSFRichTextString(
|
HSSFRichTextString leftRich = new HSSFRichTextString(
|
||||||
htmlDiffStrContent.get(0)
|
htmlDiffStrContent.get(0)
|
||||||
.replace(redTag, "")
|
.replace(redTag, "")
|
||||||
.replace("</span>", ""));
|
.replace("</span>", ""));
|
||||||
for (String tagIndex : leftContentRedTagIndex) {
|
for (String tagIndex : leftContentRedTagIndex) {
|
||||||
// 设置单独字体样式
|
// 设置单独字体样式
|
||||||
String[] split = tagIndex.split(",");
|
String[] split = tagIndex.split(",");
|
||||||
leftRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
leftRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||||
row.createCell(3).setCellValue(leftRich);
|
row1.createCell(3).setCellValue(leftRich);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取绿色字体标签的所有下标位置
|
||||||
|
String greenTag = "<span class=\"insertClass\">";
|
||||||
|
List<String> rightContentGreenTagIndex = getTagIndex(htmlDiffStrContent.get(1), greenTag);
|
||||||
|
HSSFRichTextString rightRich = new HSSFRichTextString(
|
||||||
|
htmlDiffStrContent.get(1)
|
||||||
|
.replace(greenTag, "")
|
||||||
|
.replace("</span>", ""));
|
||||||
|
for (String tagIndex : rightContentGreenTagIndex) {
|
||||||
|
// 设置单独字体样式
|
||||||
|
String[] split = tagIndex.split(",");
|
||||||
|
rightRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||||
|
row1.createCell(7).setCellValue(rightRich);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置标题单独字体样式
|
||||||
|
List<String> leftNameRedTagIndex = getTagIndex(htmlDiffStrName.get(0), redTag);
|
||||||
|
HSSFRichTextString leftNameRich = new HSSFRichTextString(
|
||||||
|
htmlDiffStrName.get(0)
|
||||||
|
.replace(redTag, "")
|
||||||
|
.replace("</span>", ""));
|
||||||
|
for (String tagIndex : leftNameRedTagIndex) {
|
||||||
|
// 设置单独字体样式
|
||||||
|
String[] split = tagIndex.split(",");
|
||||||
|
leftNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||||
|
row1.createCell(2).setCellValue(leftNameRich);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> rightNameGreenTagIndex = getTagIndex(htmlDiffStrName.get(1), greenTag);
|
||||||
|
HSSFRichTextString rightNameRich = new HSSFRichTextString(
|
||||||
|
htmlDiffStrName.get(1)
|
||||||
|
.replace(greenTag, "")
|
||||||
|
.replace("</span>", ""));
|
||||||
|
for (String tagIndex : rightNameGreenTagIndex) {
|
||||||
|
// 设置单独字体样式
|
||||||
|
String[] split = tagIndex.split(",");
|
||||||
|
rightNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||||
|
row1.createCell(6).setCellValue(rightNameRich);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取绿色字体标签的所有下标位置
|
|
||||||
String greenTag = "<span class=\"insertClass\">";
|
|
||||||
List<String> rightContentGreenTagIndex = getTagIndex(htmlDiffStrContent.get(1), greenTag);
|
|
||||||
HSSFRichTextString rightRich = new HSSFRichTextString(
|
|
||||||
htmlDiffStrContent.get(1)
|
|
||||||
.replace(greenTag, "")
|
|
||||||
.replace("</span>", ""));
|
|
||||||
for (String tagIndex : rightContentGreenTagIndex) {
|
|
||||||
// 设置单独字体样式
|
|
||||||
String[] split = tagIndex.split(",");
|
|
||||||
rightRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
|
||||||
row.createCell(7).setCellValue(rightRich);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置标题单独字体样式
|
|
||||||
List<String> leftNameRedTagIndex = getTagIndex(htmlDiffStrName.get(0), redTag);
|
|
||||||
HSSFRichTextString leftNameRich = new HSSFRichTextString(
|
|
||||||
htmlDiffStrName.get(0)
|
|
||||||
.replace(redTag, "")
|
|
||||||
.replace("</span>", ""));
|
|
||||||
for (String tagIndex : leftNameRedTagIndex) {
|
|
||||||
// 设置单独字体样式
|
|
||||||
String[] split = tagIndex.split(",");
|
|
||||||
leftNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
|
||||||
row.createCell(2).setCellValue(leftNameRich);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> rightNameGreenTagIndex = getTagIndex(htmlDiffStrName.get(1), greenTag);
|
|
||||||
HSSFRichTextString rightNameRich = new HSSFRichTextString(
|
|
||||||
htmlDiffStrName.get(1)
|
|
||||||
.replace(greenTag, "")
|
|
||||||
.replace("</span>", ""));
|
|
||||||
for (String tagIndex : rightNameGreenTagIndex) {
|
|
||||||
// 设置单独字体样式
|
|
||||||
String[] split = tagIndex.split(",");
|
|
||||||
rightNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
|
||||||
row.createCell(6).setCellValue(rightNameRich);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
row.createCell(8).setCellValue(itemComment.getComment());
|
row.createCell(8).setCellValue(itemComment.getComment());
|
||||||
@@ -643,6 +658,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
tableAssociate(workbook, cellStyleLink, cell, text);
|
tableAssociate(workbook, cellStyleLink, cell, text);
|
||||||
log.info("-------------------------表格处理完毕----------------------------");
|
log.info("-------------------------表格处理完毕----------------------------");
|
||||||
} else {
|
} else {
|
||||||
|
text = text.replace("<p style=\"text-align: center;\">", "");
|
||||||
cell.setCellValue(text);
|
cell.setCellValue(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -719,7 +735,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
textAndImg = left + "---" + table + "---" + right;
|
textAndImg = left + "---" + table + "---" + right;
|
||||||
splitTable(textAndImg, session);
|
splitTable(textAndImg, session);
|
||||||
} else {
|
} else {
|
||||||
session.setAttribute("textAndTableAndImg", textAndImg);
|
session.setAttribute("textAndTableAndImg", textAndImg.replace("------", "---"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +754,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
text = txtLeft + "---" + path + "---" + txtRight;
|
text = txtLeft + "---" + path + "---" + txtRight;
|
||||||
splitImg(text, session);
|
splitImg(text, session);
|
||||||
} else {
|
} else {
|
||||||
session.setAttribute("txtAndImg", text);
|
session.setAttribute("txtAndImg", text.replace("------", "---"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,5 +797,4 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
|||||||
bos.close(); // 后开先关
|
bos.close(); // 后开先关
|
||||||
bis.close(); // 先开后关
|
bis.close(); // 先开后关
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user