加log 晚上看哪报错

This commit is contained in:
CD
2022-10-19 14:40:06 +08:00
parent c53f98a8b8
commit d4a9dfa76e
@@ -15,6 +15,7 @@ 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.*;
@@ -44,6 +45,7 @@ import java.util.*;
* @Version: V1.0
*/
@Service
@Slf4j
public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCompareItemCommentMapper, SarFileCompareItemComment> implements ISarFileCompareItemCommentService {
@Autowired
@@ -243,14 +245,16 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
OutputStream os = null;
Workbook workbook = new HSSFWorkbook();
log.info("-------------- workbook创建成功 -----------------");
//在本地创建图片文件夹
log.info("-------------- 在本地创建图片文件夹 -----------------");
String dir = filePath + File.separator + UUID.randomUUID().toString().replace("-", "");
File dirFile = new File(dir);
if (dirFile.exists()){
dirFile.delete();
}
dirFile.mkdirs();
log.info("-------------- 文件夹创建成功:"+ dirFile.getAbsolutePath() +" -----------------");
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fileName = "导出对比结果 " + sdf.format(new Date()) + ".xlsx";
@@ -308,7 +312,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
row.createCell(1).setCellValue(itemLeft.getItemsNum());
row.createCell(2).setCellValue(itemLeft.getItemsName());
String text = itemLeft.getItemsText();
log.info("-------------- 开始开始拆分左侧图片、文字、表格 :" + text + "-----------------");
String rowDataAndPath = getSplitContent(request, text);
log.info("-------------- 左侧图片、文字、表格 拆分成功 :"+ rowDataAndPath +"-----------------");
leftSplit = rowDataAndPath.split("---");
if (leftSplit.length > 1) {
for (int j = 0; j < leftSplit.length; j++) {
@@ -319,9 +325,13 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
} else {
log.info("-------------- 开始开始处理左侧图片、表格 -----------------");
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
log.info("-------------- 左侧图片、表格 处理成功 -----------------");
}
}
}
@@ -342,7 +352,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
row.createCell(5).setCellValue(itemRight.getItemsNum());
row.createCell(6).setCellValue(itemRight.getItemsName());
String text = itemRight.getItemsText();
log.info("-------------- 开始开始拆分右侧图片、文字、表格 :"+ text +" -----------------");
String rowDataAndPath = getSplitContent(request, text);
log.info("-------------- 右侧图片、文字、表格 拆分成功 :"+ rowDataAndPath +" -----------------");
rightSplit = rowDataAndPath.split("---");
if (rightSplit.length > 1) {
for (int j = 0; j < rightSplit.length; j++) {
@@ -353,9 +365,13 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i);
}
log.info("-------------- 开始处理右侧图片、表格 -----------------");
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7);
log.info("-------------- 右侧图片、表格 处理成功 -----------------");
} else {
log.info("-------------- 开始处理右侧图片、表格 -----------------");
handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7);
log.info("-------------- 右侧图片、表格 处理成功 -----------------");
}
}
}
@@ -392,12 +408,15 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
row.getCell(1).setCellStyle(cellStyle);
}
if (ObjectUtils.isNotEmpty(mergeCells)) {
log.info("-------------- 开始处理需要合并的单元格 -----------------");
Set<SarFileCompareExcelMergeCell> mergeCellSet = new HashSet<>(mergeCells);
for (SarFileCompareExcelMergeCell mergeCell : mergeCellSet) {
Integer leftCount = mergeCell.getLeftEnd() - mergeCell.getLeftStart() + 1;
Integer rightCount = mergeCell.getRightEnd() - mergeCell.getRightStart() + 1;
Integer start = leftCount - rightCount >= 0 ? mergeCell.getLeftStart() : mergeCell.getRightStart();
log.info("-------------- 合并开始行数:" + start + " -----------------");
Integer end = leftCount - rightCount >= 0 ? mergeCell.getLeftEnd() : mergeCell.getRightEnd();
log.info("-------------- 合并结束行数: " + end + " -----------------");
//合并
CellRangeAddress region0 = new CellRangeAddress(start, end, 0, 0);
sheet.addMergedRegion(region0);
@@ -414,6 +433,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
CellRangeAddress region7 = new CellRangeAddress(start, end, 8, 8);
sheet.addMergedRegion(region7);
}
log.info("-------------- 单元格合并成功 -----------------");
}
@@ -449,6 +469,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (text.contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高
//先将图片下载到本地
log.info("-------------------------将图片下载到本地文件夹中----------------------------");
String fileLastName = text.substring(text.lastIndexOf("/") + 1);
if (CosBootUtil.doesObjectExist(text)) {
try (InputStream in = CosBootUtil.download(text)) {
@@ -459,18 +480,22 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
}
File file = new File(dir + File.separator + fileLastName);
log.info("-------------------------图片下载成功:"+ file.getAbsolutePath() +"----------------------------");
if (file.exists()) {
log.info("-------------------------将图片插入excel指定单元格中----------------------------");
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));
log.info("-------------------------将图片插入成功----------------------------");
}
} else {
Cell cell = row.createCell(cellNum);
if (text.contains("<table")) {
log.info("-------------------------开始处理表格----------------------------");
tableAssociate(workbook, cellStyleLink, cell, text);
log.info("-------------------------表格处理完毕----------------------------");
} else {
cell.setCellValue(text);
}
@@ -487,6 +512,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
private void tableAssociate(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) {
cell.setCellValue("点击查看详情");
//新开sheet生成表格
log.info("-------------------------开始生成表格----------------------------");
if (org.apache.commons.lang.StringUtils.isNotEmpty(tableHtml) && tableHtml.indexOf("<tbody>") < 0) {
if (tableHtml.indexOf("<thead>") < 0) {
tableHtml = tableHtml.replaceFirst("<tr>", "<tbody><tr>");
@@ -500,13 +526,16 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
tableHtml = tableHtml.replaceAll("<[\\s]*?br[^>]*?>|<[\\s]*?\\/[\\s]*?br[\\s]*?>", cnt);
String tableSheetName = "表格" + System.currentTimeMillis();
ConvertHtml2Excel.table2Excel(tableHtml, (HSSFWorkbook) workbook, tableSheetName);
log.info("-------------------------表格生产完毕----------------------------");
//添加超链接
log.info("-------------------------开始添加超链接---------------------------");
CreationHelper createHelper = workbook.getCreationHelper();
Hyperlink hyperlink1 = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
String tableName = "#\'" + tableSheetName + "\'!A1";
hyperlink1.setAddress(tableName);
cell.setHyperlink(hyperlink1);// 链接
cell.setCellStyle(cellStyleLink);
log.info("-------------------------超链接添加完毕---------------------------");
}
/**
@@ -518,11 +547,15 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
private String getSplitContent(HttpServletRequest request, String text) {
text = text.replace("<p>", "").replace("</p>", "\r\n");
//分割图片
log.info("-------------------------开始分割文字与图片---------------------------");
splitImg(text, request.getSession());
log.info("-------------------------文字与图片分割完毕---------------------------");
//分割表格
log.info("-------------------------从剩余文字中开始分割表格---------------------------");
String txtAndImg = (String) request.getSession().getAttribute("txtAndImg");
txtAndImg = txtAndImg.replaceAll("table", "replaceTable");
splitTable(txtAndImg, request.getSession());
log.info("-------------------------表格分割完毕---------------------------");
return (String) request.getSession().getAttribute("textAndTableAndImg");
}