全文对比-导出接口。
This commit is contained in:
+15
@@ -328,4 +328,19 @@ public class SarFileCompareInfoController extends JeroController<SarFileCompareI
|
||||
return Result.error("发起条款对比失败!" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "全文对比-导出")
|
||||
@GetMapping(value = "/exportFullTextCompareXls")
|
||||
public void exportFullTextCompareXls(@ApiParam("导出名") @RequestParam(value = "exportName", required = false) String exportName,
|
||||
@ApiParam("standHisId") @RequestParam(value = "id", required = false) String id,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
this.sarFileCompareInfoService.exportFullTextCompareXls(id,exportName, response, request);
|
||||
}catch (JeroBootException e){
|
||||
throw new JeroBootException(e.getMessage());
|
||||
}catch (Exception e){
|
||||
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.ERROR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.jero.modules.compare.entity;
|
||||
|
||||
public class MarkTextVO {
|
||||
|
||||
private int startIndex;
|
||||
|
||||
private int endIndex;
|
||||
|
||||
public int getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getEndIndex() {
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
public void setEndIndex(int endIndex) {
|
||||
this.endIndex = endIndex;
|
||||
}
|
||||
}
|
||||
+11
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.modules.compare.entity.SarFileCompareDetailVO;
|
||||
import com.jero.modules.compare.entity.SarFileCompareInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -98,4 +100,13 @@ public interface ISarFileCompareInfoService extends IService<SarFileCompareInfo>
|
||||
* @return
|
||||
*/
|
||||
String itemComparison(String leftStandard, String rightStandard, String remark) throws Exception;
|
||||
|
||||
/**
|
||||
* 导出全文对比
|
||||
* @param id
|
||||
* @param exportName
|
||||
* @param response
|
||||
* @param request
|
||||
*/
|
||||
void exportFullTextCompareXls(String id, String exportName, HttpServletResponse response, HttpServletRequest request);
|
||||
}
|
||||
|
||||
+158
@@ -19,7 +19,9 @@ import com.jero.modules.compare.service.ISarItemsCompareHisEOService;
|
||||
import com.jero.modules.compare.utils.CompHanLPUtils;
|
||||
import com.jero.modules.compare.utils.CompareConst;
|
||||
import com.jero.modules.compare.utils.EventEditHistoryHighLightUtil;
|
||||
import com.jero.modules.compare.utils.HtmlTextExcel;
|
||||
import com.jero.modules.document.service.IBussDocumentLibraryEOService;
|
||||
import com.jero.modules.split.common.ReadExcel;
|
||||
import com.jero.modules.split.entity.SarFileSplitInfoEO;
|
||||
import com.jero.modules.split.entity.SarFileSplitItemsEO;
|
||||
import com.jero.modules.split.entity.SarFileSplitItemsValEO;
|
||||
@@ -29,13 +31,26 @@ import com.jero.modules.split.service.IFileSplitItemsEOService;
|
||||
import com.jero.modules.split.service.ISarFileSplitInfoService;
|
||||
import com.jero.modules.split.service.ISarFileSplitItemsValEOService;
|
||||
import com.jero.modules.split.service.ISarFileSplitMenuEOService;
|
||||
import com.jero.modules.sys.entity.LawsEnterpriseStandardLevel;
|
||||
import com.jero.modules.system.util.MyStringUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -498,4 +513,147 @@ public class SarFileCompareInfoServiceImpl extends ServiceImpl<SarFileCompareInf
|
||||
SarFileCompareInfo sfcInfo = addStandCompareHis(leftStandard, rightStandard, remark, CompareTypeEnum.ITEM.getValue());
|
||||
return sfcInfo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportFullTextCompareXls(String id, String exportName, HttpServletResponse response, HttpServletRequest request) {
|
||||
|
||||
OutputStream os = null;
|
||||
OutputStream excelOS = null;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
String fileOriName = "全文比对信息";
|
||||
if (StringUtils.isNotEmpty(exportName)) {
|
||||
fileOriName = exportName;
|
||||
}
|
||||
String[] headers = {"条款号","条款名称","条款内容","备注"};
|
||||
HSSFSheet sheetItemsLeft = workbook.createSheet("旧文档");
|
||||
// 左侧在excel表中添加表头
|
||||
HSSFRow row = sheetItemsLeft.createRow(0);
|
||||
sheetItemsLeft.setColumnWidth(0,20*256);
|
||||
sheetItemsLeft.setColumnWidth(1,30*256);
|
||||
sheetItemsLeft.setColumnWidth(2,100*256);
|
||||
sheetItemsLeft.setColumnWidth(3,80*256);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
HSSFCell cell = row.createCell(i);
|
||||
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
|
||||
cell.setCellValue(text);
|
||||
}
|
||||
|
||||
HSSFSheet sheetItemsRight = workbook.createSheet("新文档");
|
||||
HSSFRow rowRightHeader = sheetItemsRight.createRow(0);
|
||||
sheetItemsRight.setColumnWidth(0,20*256);
|
||||
sheetItemsRight.setColumnWidth(1,30*256);
|
||||
sheetItemsRight.setColumnWidth(2,100*256);
|
||||
sheetItemsRight.setColumnWidth(3,80*256);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
HSSFCell cell = rowRightHeader.createCell(i);
|
||||
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
|
||||
cell.setCellValue(text);
|
||||
}
|
||||
|
||||
// 基础样式
|
||||
HSSFCellStyle cellStyleBase =workbook.createCellStyle();
|
||||
cellStyleBase.setWrapText(true);
|
||||
cellStyleBase.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
HSSFFont fontBase = workbook.createFont();
|
||||
fontBase.setColor(IndexedColors.BLACK.index);
|
||||
// 增加文字样式
|
||||
HSSFFont fontAdd = workbook.createFont();
|
||||
fontAdd.setColor(IndexedColors.LIGHT_BLUE.index);
|
||||
// 删除文字样式
|
||||
HSSFFont fontDel = workbook.createFont();
|
||||
fontDel.setColor(IndexedColors.RED.index);
|
||||
|
||||
SarFileCompareInfo sfcInfo = this.queryById(id);
|
||||
|
||||
List<SarFileCompareItem> itemList = sarFileCompareItemService.queryListByInfoId(id);
|
||||
Map<String, List<SarFileCompareItem>> itemMap = itemList.stream().collect(Collectors.groupingBy(SarFileCompareItem::getLeftOrRight));
|
||||
List<SarFileCompareItem> leftData = itemMap.get(CompareConst.POS_LEFT);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(leftData)) {
|
||||
for (int rowNum = 0; rowNum < leftData.size(); rowNum++) {
|
||||
SarFileCompareItem sarFileCompareItem = leftData.get(rowNum);
|
||||
|
||||
HSSFRow row1 = sheetItemsLeft.createRow(rowNum + 1);
|
||||
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberLeft() + " " +sfcInfo.getTitleLeft());
|
||||
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
||||
row1.getCell(1).setCellStyle(cellStyleBase);
|
||||
|
||||
String itemText = sarFileCompareItem.getItemsText();
|
||||
List<MarkTextVO> addList = new ArrayList<>();
|
||||
List<MarkTextVO> delList = new ArrayList<>();
|
||||
itemText = HtmlTextExcel.changeHtmlToExcel(itemText,addList,delList);
|
||||
HSSFRichTextString ts= new HSSFRichTextString(itemText);
|
||||
if (addList != null && !addList.isEmpty()) {
|
||||
for (MarkTextVO markTextVO : addList) {
|
||||
int stIndex = markTextVO.getStartIndex();
|
||||
int edIndex = markTextVO.getEndIndex();
|
||||
ts.applyFont(stIndex,edIndex,fontAdd);
|
||||
}
|
||||
}
|
||||
if (delList != null && !delList.isEmpty()) {
|
||||
for (MarkTextVO markTextVO : delList) {
|
||||
int stIndex = markTextVO.getStartIndex();
|
||||
int edIndex = markTextVO.getEndIndex();
|
||||
ts.applyFont(stIndex,edIndex,fontDel);
|
||||
}
|
||||
}
|
||||
row1.createCell(2).setCellValue(sarFileCompareItem.getItemsName());
|
||||
row1.createCell(3).setCellValue(ts);
|
||||
row1.getCell(3).setCellStyle(cellStyleBase);
|
||||
row1.createCell(4).setCellValue(sarFileCompareItem.getRemark());
|
||||
}
|
||||
}
|
||||
|
||||
List<SarFileCompareItem> rightData = itemMap.get(CompareConst.POS_RIGHT);
|
||||
if (CollectionUtils.isNotEmpty(rightData)) {
|
||||
for (int rowNum = 0; rowNum < rightData.size(); rowNum++) {
|
||||
SarFileCompareItem sarFileCompareItem = rightData.get(rowNum);
|
||||
|
||||
HSSFRow row1 = sheetItemsRight.createRow(rowNum + 1);
|
||||
row1.createCell(0).setCellValue(sfcInfo.getSerialNumberRight() + " " +sfcInfo.getTitleRight());
|
||||
row1.createCell(1).setCellValue(sarFileCompareItem.getItemsNum());
|
||||
row1.getCell(1).setCellStyle(cellStyleBase);
|
||||
|
||||
String itemText = sarFileCompareItem.getItemsText();
|
||||
List<MarkTextVO> addList = new ArrayList<>();
|
||||
List<MarkTextVO> delList = new ArrayList<>();
|
||||
itemText = HtmlTextExcel.changeHtmlToExcel(itemText,addList,delList);
|
||||
HSSFRichTextString ts= new HSSFRichTextString(itemText);
|
||||
if (addList != null && !addList.isEmpty()) {
|
||||
for (MarkTextVO markTextVO : addList) {
|
||||
int stIndex = markTextVO.getStartIndex();
|
||||
int edIndex = markTextVO.getEndIndex();
|
||||
ts.applyFont(stIndex,edIndex,fontAdd);
|
||||
}
|
||||
}
|
||||
if (delList != null && !delList.isEmpty()) {
|
||||
for (MarkTextVO markTextVO : delList) {
|
||||
int stIndex = markTextVO.getStartIndex();
|
||||
int edIndex = markTextVO.getEndIndex();
|
||||
ts.applyFont(stIndex,edIndex,fontDel);
|
||||
}
|
||||
}
|
||||
row1.createCell(2).setCellValue(sarFileCompareItem.getItemsName());
|
||||
row1.createCell(3).setCellValue(ts);
|
||||
row1.getCell(3).setCellStyle(cellStyleBase);
|
||||
row1.createCell(4).setCellValue(sarFileCompareItem.getRemark());
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\"" + ReadExcel.encodeFileName(fileOriName, request) +"\"");
|
||||
response.setContentType("application/force-download");
|
||||
response.flushBuffer();
|
||||
os = response.getOutputStream();
|
||||
workbook.write(os);
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException("下载文件失败,请重试");
|
||||
} finally {
|
||||
org.apache.poi.util.IOUtils.closeQuietly(os);
|
||||
org.apache.poi.util.IOUtils.closeQuietly(excelOS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class SarItemsCompareHisEOServiceImpl extends ServiceImpl<SarItemsCompare
|
||||
os = response.getOutputStream();
|
||||
workbook.write(os);
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
os.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new JeroBootException("下载文件失败,请重试");
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.jero.modules.compare.utils;
|
||||
|
||||
import com.jero.modules.compare.entity.MarkTextVO;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HtmlTextExcel {
|
||||
|
||||
public static String changeHtmlToExcel (String itemContent, List<MarkTextVO> addList, List<MarkTextVO> delList) {
|
||||
if (StringUtils.isNotEmpty(itemContent)) {
|
||||
itemContent = itemContent.replaceAll("<div>","");
|
||||
itemContent = itemContent.replaceAll("<div class=\"compareBackgroundColor\">","");
|
||||
itemContent = itemContent.replaceAll("</div>","\n");
|
||||
itemContent = itemContent.replaceAll("<p>","");
|
||||
itemContent = itemContent.replaceAll("</p>","\n");
|
||||
//获取所有新增内容的位置
|
||||
String splitContentAdd = itemContent;
|
||||
int addSpiltIndex = 0;
|
||||
int cirIndex = 0;
|
||||
int stLen = "<span class=\"insertClass\">".length();
|
||||
int edLen = "</span>".length();
|
||||
while (splitContentAdd.contains("<span class=\"insertClass\">")) {
|
||||
int addStIndex = splitContentAdd.indexOf("<span class=\"insertClass\">");
|
||||
int addEdIndex = splitContentAdd.indexOf("</span>");
|
||||
if (addStIndex > -1) {
|
||||
MarkTextVO markTextVO = new MarkTextVO();
|
||||
markTextVO.setStartIndex(addSpiltIndex + addStIndex - (cirIndex*(stLen+edLen)));
|
||||
markTextVO.setEndIndex(addSpiltIndex + addEdIndex - (cirIndex*(stLen+edLen)) - stLen);
|
||||
addList.add(markTextVO);
|
||||
addSpiltIndex = addSpiltIndex + addEdIndex + 7;
|
||||
// String replaceStr = splitContentAdd.substring(0,addStIndex);
|
||||
splitContentAdd = splitContentAdd.substring(addEdIndex + 7,splitContentAdd.length());
|
||||
cirIndex++;
|
||||
}
|
||||
}
|
||||
//获取所有删除内容的位置
|
||||
String splitContentDel = itemContent;
|
||||
int delSpiltIndex = 0;
|
||||
int cirIndexDel = 0;
|
||||
int stLenDel = "<span class=\"delClass\">".length();
|
||||
int edLenDel = "</span>".length();
|
||||
while (splitContentDel.contains("<span class=\"delClass\">")) {
|
||||
int delStIndex = splitContentDel.indexOf("<span class=\"delClass\">");
|
||||
int delEdIndex = splitContentDel.indexOf("</span>");
|
||||
if (delStIndex > -1) {
|
||||
MarkTextVO markTextVO = new MarkTextVO();
|
||||
markTextVO.setStartIndex(delSpiltIndex + delStIndex - (cirIndexDel*(stLenDel+edLenDel)));
|
||||
markTextVO.setEndIndex(delSpiltIndex + delEdIndex - (cirIndexDel*(stLenDel+edLenDel)) - stLenDel);
|
||||
delList.add(markTextVO);
|
||||
delSpiltIndex = delSpiltIndex + delEdIndex + 7;
|
||||
// String replaceStr = splitContentDel.substring(0,delStIndex);
|
||||
splitContentDel = splitContentDel.substring(delEdIndex + 7,splitContentDel.length());
|
||||
cirIndexDel++;
|
||||
}
|
||||
}
|
||||
itemContent = itemContent.replaceAll("<span class=\"insertClass\">","");
|
||||
itemContent = itemContent.replaceAll("</span>","");
|
||||
itemContent = itemContent.replaceAll("<span class=\"delClass\">","");
|
||||
itemContent = itemContent.replaceAll("</span>","");
|
||||
}
|
||||
return itemContent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user