This commit is contained in:
CD
2022-09-27 15:28:42 +08:00
parent b07b15952c
commit 5e48545a73
3 changed files with 80 additions and 16 deletions
@@ -165,8 +165,8 @@ public class SarFileCompareItemCommentController extends JeroController<SarFileC
@RequestParam(name = "selectIds", required = true) String selectIds,
@RequestParam(name = "includeComments", required = true) boolean includeComments,
@RequestParam(name = "cut", required = true) String cut,
HttpServletResponse response) {
sarFileCompareItemCommentService.exportResXls(response, infoId, selectIds, includeComments, cut);
HttpServletResponse response,HttpServletRequest request) {
sarFileCompareItemCommentService.exportResXls(request,response, infoId, selectIds, includeComments, cut);
}
}
@@ -67,5 +67,5 @@ public interface ISarFileCompareItemCommentService extends IService<SarFileCompa
SarFileCompareResultVO queryCompareResult(String infoId);
void exportResXls(HttpServletResponse response, String infoId, String selectIds, boolean includeComments, String cut);
void exportResXls(HttpServletRequest request,HttpServletResponse response, String infoId, String selectIds, boolean includeComments, String cut);
}
@@ -11,17 +11,29 @@ 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.system.util.StringUtils;
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.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Description: 文档对比信息条款评论表
@@ -38,6 +50,13 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
@Autowired
private ISarFileCompareItemService SarFileCompareItemServiceImpl;
@Value("${jero.path.upload}")
private String filePath;
@Value("${jero.path.uploadCos}")
private String filePathCos;
@Value("${jero.splitUrl}")
private String splitUrl;
/**
* 保存
@@ -164,7 +183,7 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
@Override
public void exportResXls(HttpServletResponse response, String infoId, String selectIds, boolean includeComments, String cut) {
public void exportResXls(HttpServletRequest request,HttpServletResponse response, String infoId, String selectIds, boolean includeComments, String cut) {
List<SarFileCompareItemComment> list = null;
if (includeComments && StringUtils.isEmpty(selectIds)) {
//只导出全文评论的情况
@@ -180,8 +199,10 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
}
Map<String, SarFileCompareItem> sfcItemMap = SarFileCompareItemServiceImpl.queryMapByInfoId(infoId);
SarFileCompareInfo sarFileCompareInfo = sarFileCompareInfoServiceImpl.queryById(infoId);
OutputStream os = null;
Workbook workbook = new XSSFWorkbook();
Workbook workbook = new HSSFWorkbook();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fileName = "导出对比结果 " + sdf.format(new Date()) + ".xlsx";
@@ -195,15 +216,15 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
sheetName = "Comparing results";
}
Sheet sheet = workbook.createSheet(sheetName);
HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
// 创建头部
String header = "";
if (CutEnum.CN.getValue().equals(cut)) {
header = "条款号,条款名称,条款内容,条款号,条款名称,条款内容,评论";
header = "所选标准,条款号,条款名称,条款内容,所选标准,条款号,条款名称,条款内容,评论";
} else {
header = "Number,Title,Content,Number,Title,Content,Comment";
header = "Selected Standard,Number,Title,Content,Selected Standard,Number,Title,Content,Comment";
}
int[] columnWidth = {5000, 5000, 10000, 5000, 5000, 10000, 10000};
int[] columnWidth = {5000,5000, 5000, 10000, 5000,5000, 5000, 10000, 10000};
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
cellStyle.setAlignment(HorizontalAlignment.LEFT);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
@@ -219,15 +240,39 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
int i = 1;
for (SarFileCompareItemComment itemComment : list) {
Row row = sheet.createRow(i);
row.createCell(0).setCellValue(sarFileCompareInfo == null ? "" : sarFileCompareInfo.getTitleLeft() + " " + sarFileCompareInfo.getFileNameLeft());
row.createCell(4).setCellValue(sarFileCompareInfo == null ? "" : sarFileCompareInfo.getTitleRight() + " " + sarFileCompareInfo.getFileNameRight());
String itemIdLeft = itemComment.getItemsIdLeft();
if (!StringUtils.isEmpty(itemIdLeft)) {
SarFileCompareItem itemLeft = sfcItemMap.get(itemIdLeft);
if (null != itemLeft) {
row.createCell(0).setCellValue(itemLeft.getItemsNum());
row.createCell(1).setCellValue(itemLeft.getItemsName());
row.createCell(1).setCellValue(itemLeft.getItemsNum());
row.createCell(2).setCellValue(itemLeft.getItemsName());
String text = itemLeft.getItemsText();
text = text.replace("<p>", "").replace("</p>", "\r\n");
row.createCell(2).setCellValue(text);
BufferedImage bufferImg = null;
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
addImgdata(text,request.getSession());
String rowdata = "";
String rowDataAndPath = (String) request.getSession().getAttribute("txtAndImg");
for (String s : rowDataAndPath.split("---")) {
if (s.contains(".jpg") || s.contains(".png")) {
File file = new File(filePath + s);
if (file.exists()) {
bufferImg = ImageIO.read(file);
ImageIO.write(bufferImg, "jpg", byteArrayOut);
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 200,(short)3, i, (short) 3, i);
patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
} else {
rowdata = rowdata + s;
}
}
row.createCell(3).setCellValue(rowdata);
row.setRowStyle(cellStyle);
}
}
@@ -235,15 +280,15 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
if (!StringUtils.isEmpty(itemIdRight)) {
SarFileCompareItem itemRight = sfcItemMap.get(itemIdRight);
if (null != itemRight) {
row.createCell(3).setCellValue(itemRight.getItemsNum());
row.createCell(4).setCellValue(itemRight.getItemsName());
row.createCell(5).setCellValue(itemRight.getItemsNum());
row.createCell(6).setCellValue(itemRight.getItemsName());
String text = itemRight.getItemsText();
text = text.replace("<p>", "").replace("</p>", "\r\n");
row.createCell(5).setCellValue(text);
row.createCell(7).setCellValue(text);
row.setRowStyle(cellStyle);
}
}
row.createCell(6).setCellValue(itemComment.getComment());
row.createCell(8).setCellValue(itemComment.getComment());
for (int j = 0; j < 7; j++) {
Cell cell = row.getCell(j);
if (null != cell) {
@@ -280,4 +325,23 @@ public class SarFileCompareItemCommentServiceImpl extends ServiceImpl<SarFileCom
IOUtils.closeQuietly(os);
}
}
/**
* 提取字符串中<img>标签内容中的图片路径,并重新按顺序拼接
* @param text
* @return
*/
private void addImgdata(String text,HttpSession session) {
if (text.contains("<") || text.contains(">")) {
String txtLeft = text.substring(0, text.indexOf("<"));
String txtRight = text.substring(text.indexOf(">") + 1);
String img = text.substring(text.indexOf("<"), text.indexOf(">"));
String path = img.substring(img.lastIndexOf("=") + 1, img.lastIndexOf("\""));
text = txtLeft + "---" + path + "---" + txtRight;
addImgdata(text, session);
} else {
session.setAttribute("txtAndImg", text);
}
}
}