方法名称优化

This commit is contained in:
CD
2022-10-10 10:21:57 +08:00
parent 1ec0784eb6
commit 62a87236aa
@@ -288,9 +288,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) { if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i); row2 = sheet.createRow(j + i);
} }
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3); handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, leftSplit[j], 3);
} else { } else {
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3); handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, leftSplit[j], 3);
} }
} }
} }
@@ -322,9 +322,9 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (ObjectUtils.isEmpty(row2)) { if (ObjectUtils.isEmpty(row2)) {
row2 = sheet.createRow(j + i); row2 = sheet.createRow(j + i);
} }
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7); handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row2, i, j, rightSplit[j], 7);
} else { } else {
imgToExcel(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7); handleSpecificData(workbook, dir, patriarch, cellStyleLink, byteArrayOut, row, i, j, rightSplit[j], 7);
} }
} }
} }
@@ -401,7 +401,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} }
/** /**
* 将图片添加到excel指定单元格中 * 处理图片跟表格类型的数据
* @param workbook * @param workbook
* @param dir * @param dir
* @param patriarch * @param patriarch
@@ -414,7 +414,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
* @param cellNum * @param cellNum
* @throws IOException * @throws IOException
*/ */
private void imgToExcel(Workbook workbook, String dir, HSSFPatriarch patriarch, CellStyle cellStyleLink, ByteArrayOutputStream byteArrayOut, Row row, int i, int j, String text, int 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")) { if (text.contains("/upFiles")) {
row.setHeight((short) 3000); //设置行高 row.setHeight((short) 3000); //设置行高
//先将图片下载到本地 //先将图片下载到本地
@@ -439,7 +439,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} else { } else {
Cell cell = row.createCell(cellNum); Cell cell = row.createCell(cellNum);
if (text.contains("<table")) { if (text.contains("<table")) {
tableAssociations(workbook, cellStyleLink, cell, text); tableAssociate(workbook, cellStyleLink, cell, text);
} else { } else {
cell.setCellValue(text); cell.setCellValue(text);
} }
@@ -453,7 +453,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
* @param cell * @param cell
* @param tableHtml * @param tableHtml
*/ */
private void tableAssociations(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) { private void tableAssociate(Workbook workbook, CellStyle cellStyleLink, Cell cell, String tableHtml) {
cell.setCellValue("点击查看详情"); cell.setCellValue("点击查看详情");
//新开sheet生成表格 //新开sheet生成表格
if (org.apache.commons.lang.StringUtils.isNotEmpty(tableHtml) && tableHtml.indexOf("<tbody>") < 0) { if (org.apache.commons.lang.StringUtils.isNotEmpty(tableHtml) && tableHtml.indexOf("<tbody>") < 0) {
@@ -487,7 +487,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
private String getSplitContent(HttpServletRequest request, String text) { private String getSplitContent(HttpServletRequest request, String text) {
text = text.replace("<p>", "").replace("</p>", "\r\n"); text = text.replace("<p>", "").replace("</p>", "\r\n");
//分割图片 //分割图片
addImgdata(text, request.getSession()); splitImg(text, request.getSession());
//分割表格 //分割表格
String txtAndImg = (String) request.getSession().getAttribute("txtAndImg"); String txtAndImg = (String) request.getSession().getAttribute("txtAndImg");
txtAndImg = txtAndImg.replaceAll("table", "replaceTable"); txtAndImg = txtAndImg.replaceAll("table", "replaceTable");
@@ -514,18 +514,19 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
} }
/** /**
* 提取字符串中<img>标签内容中的图片路径,并重新按顺序拼接 * 分割图片
* @param text * @param text
* @param session
* @return * @return
*/ */
private void addImgdata(String text,HttpSession session) { private void splitImg(String text,HttpSession session) {
if (text.contains("<img")) { if (text.contains("<img")) {
String txtLeft = text.substring(0, text.indexOf("<img")); String txtLeft = text.substring(0, text.indexOf("<img"));
String txtRight = text.substring(text.indexOf("g\">") + 3); String txtRight = text.substring(text.indexOf("g\">") + 3);
String img = text.substring(text.indexOf("<img"), text.indexOf("g\">")); String img = text.substring(text.indexOf("<img"), text.indexOf("g\">"));
String path = img.substring(img.lastIndexOf("=") + 1)+"g"; String path = img.substring(img.lastIndexOf("=") + 1)+"g";
text = txtLeft + "---" + path + "---" + txtRight; text = txtLeft + "---" + path + "---" + txtRight;
addImgdata(text, session); splitImg(text, session);
} else { } else {
session.setAttribute("txtAndImg", text); session.setAttribute("txtAndImg", text);
} }