fix(新旧拆分单对比): 导出对比报告单独设置某些文字颜色
This commit is contained in:
+108
-14
@@ -15,16 +15,15 @@ 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.compare.utils.DiffUtils;
|
||||
import com.jero.modules.system.util.MyStringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||
import org.apache.poi.hssf.usermodel.HSSFFont;
|
||||
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
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.util.CellRangeAddress;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -324,17 +323,20 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
row.createCell(0).setCellValue(sarFileCompareInfo == null ? "" : sarFileCompareInfo.getTitleLeft() + " " + sarFileCompareInfo.getFileNameLeft());
|
||||
row.createCell(4).setCellValue(sarFileCompareInfo == null ? "" : sarFileCompareInfo.getTitleRight() + " " + sarFileCompareInfo.getFileNameRight());
|
||||
String itemIdLeft = itemComment.getItemsIdLeft();
|
||||
String rowDataAndPathLeft = "";
|
||||
String rowDataAndPathRight = "";
|
||||
SarFileCompareItem itemLeft = new SarFileCompareItem();
|
||||
if (!MyStringUtils.isEmpty(itemIdLeft)) {
|
||||
SarFileCompareItem itemLeft = sfcItemMap.get(itemIdLeft);
|
||||
itemLeft = sfcItemMap.get(itemIdLeft);
|
||||
if (null != itemLeft) {
|
||||
row.createCell(1).setCellValue(itemLeft.getItemsNum());
|
||||
row.createCell(2).setCellValue(itemLeft.getItemsName());
|
||||
String text = itemLeft.getItemsText();
|
||||
if (MyStringUtils.isNotEmpty(text)){
|
||||
log.info("-------------- 开始开始拆分左侧图片、文字、表格 :" + text + "-----------------");
|
||||
String rowDataAndPath = getSplitContent(request, text);
|
||||
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPath +"-----------------");
|
||||
leftSplit = rowDataAndPath.split("---");
|
||||
rowDataAndPathLeft = getSplitContent(request, text);
|
||||
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPathLeft +"-----------------");
|
||||
leftSplit = rowDataAndPathLeft.split("---");
|
||||
if (leftSplit.length > 1) {
|
||||
for (int j = 0; j < leftSplit.length; j++) {
|
||||
if (ObjectUtils.isNotEmpty(leftSplit[j])) {
|
||||
@@ -360,23 +362,24 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
sarFileCompareExcelMergeCell.setRightEnd(0);
|
||||
mergeCells.add(sarFileCompareExcelMergeCell);
|
||||
} else {
|
||||
row.createCell(3).setCellValue(rowDataAndPath);
|
||||
row.createCell(3).setCellValue(rowDataAndPathLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String itemIdRight = itemComment.getItemsIdRight();
|
||||
SarFileCompareItem itemRight = new SarFileCompareItem();
|
||||
if (!MyStringUtils.isEmpty(itemIdRight)) {
|
||||
SarFileCompareItem itemRight = sfcItemMap.get(itemIdRight);
|
||||
itemRight = sfcItemMap.get(itemIdRight);
|
||||
if (null != itemRight) {
|
||||
row.createCell(5).setCellValue(itemRight.getItemsNum());
|
||||
row.createCell(6).setCellValue(itemRight.getItemsName());
|
||||
String text = itemRight.getItemsText();
|
||||
if (MyStringUtils.isNotEmpty(text)) {
|
||||
log.info("-------------- 开始开始拆分右侧图片、文字、表格 :"+ text +" -----------------");
|
||||
String rowDataAndPath = getSplitContent(request, text);
|
||||
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPath +" -----------------");
|
||||
rightSplit = rowDataAndPath.split("---");
|
||||
rowDataAndPathRight = getSplitContent(request, text);
|
||||
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPathRight +" -----------------");
|
||||
rightSplit = rowDataAndPathRight.split("---");
|
||||
if (rightSplit.length > 1) {
|
||||
for (int j = 0; j < rightSplit.length; j++) {
|
||||
if (ObjectUtils.isNotEmpty(rightSplit[j])) {
|
||||
@@ -400,11 +403,78 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
sarFileCompareExcelMergeCell.setRightEnd(i + rightSplit.length - 1);
|
||||
mergeCells.add(sarFileCompareExcelMergeCell);
|
||||
} else {
|
||||
row.createCell(7).setCellValue(rowDataAndPath);
|
||||
row.createCell(7).setCellValue(rowDataAndPathRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 左右条款内容对比
|
||||
if (StringUtils.isNotBlank(itemIdLeft) && StringUtils.isNotBlank(itemIdRight)) {
|
||||
// 获取对比结果
|
||||
DiffUtils dmp = new DiffUtils();
|
||||
List<String> htmlDiffStrContent = dmp.getHtmlDiffStr(rowDataAndPathLeft, rowDataAndPathRight);
|
||||
List<String> htmlDiffStrName = dmp.getHtmlDiffStr(itemLeft.getItemsName(), itemRight.getItemsName());
|
||||
|
||||
Font redFont = workbook.createFont();
|
||||
redFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
||||
Font greenFont = workbook.createFont();
|
||||
greenFont.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
|
||||
|
||||
// 获取红色字体标签的所有下标位置
|
||||
String redTag = "<span class=\"delClass\">";
|
||||
List<String> leftContentRedTagIndex = getTagIndex(htmlDiffStrContent.get(0), redTag);
|
||||
HSSFRichTextString leftRich = new HSSFRichTextString(
|
||||
htmlDiffStrContent.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : leftContentRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
leftRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), redFont);
|
||||
row.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);
|
||||
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(leftRich);
|
||||
}
|
||||
|
||||
List<String> rightNameRedTagIndex = getTagIndex(htmlDiffStrName.get(1), greenTag);
|
||||
HSSFRichTextString rightNameRich = new HSSFRichTextString(
|
||||
htmlDiffStrName.get(0)
|
||||
.replace(redTag, "")
|
||||
.replace("</span>", ""));
|
||||
for (String tagIndex : rightNameRedTagIndex) {
|
||||
// 设置单独字体样式
|
||||
String[] split = tagIndex.split(",");
|
||||
rightNameRich.applyFont(Integer.parseInt(split[0]), Integer.parseInt(split[1]), greenFont);
|
||||
row.createCell(6).setCellValue(leftRich);
|
||||
}
|
||||
}
|
||||
|
||||
row.createCell(8).setCellValue(itemComment.getComment());
|
||||
row.setRowStyle(cellStyle);
|
||||
for (int j = 0; j < 9; j++) {
|
||||
@@ -485,6 +555,30 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getTagIndex(String str, String tag) {
|
||||
List<String> indexList = new ArrayList<>();
|
||||
int index = 0;
|
||||
int i = 0;
|
||||
while ((index = str.indexOf(tag, index)) != -1) {
|
||||
int tmp = i * tag.length();
|
||||
indexList.add(String.valueOf(index - tmp));
|
||||
// 移动到下一个可能的起始位置
|
||||
index += tag.length();
|
||||
++i;
|
||||
}
|
||||
index = 0;
|
||||
i = 0;
|
||||
str = str.replaceAll(tag, "");
|
||||
while ((index = str.indexOf("</span>", index)) != -1) {
|
||||
int tmp = i * "</span>".length();
|
||||
indexList.set(i, (Integer.parseInt(indexList.get(i)) - tmp) + "," + (index - tmp));
|
||||
// 移动到下一个可能的起始位置
|
||||
index += "</span>".length();
|
||||
++i;
|
||||
}
|
||||
return indexList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理图片跟表格类型的数据
|
||||
* @param workbook
|
||||
|
||||
+1
@@ -201,6 +201,7 @@ public class LawsEnterpriseStandard implements Serializable {
|
||||
* 标准推进人
|
||||
*/
|
||||
@ApiModelProperty(value = "标准推进人")
|
||||
@TableField(exist = false)
|
||||
private String standardPromoter;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user