Merge branch 'develop_migration' into 'develop_master'
feat: There is no way the, contrast See merge request LiuChao/foton-slrs-system-rest!254
This commit is contained in:
+2276
File diff suppressed because it is too large
Load Diff
+209
@@ -0,0 +1,209 @@
|
||||
package com.adc.da.slrs.standardSplit.EventUtils;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: super_liu
|
||||
* @date: 2021年11月28日 12:28
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文本差异高亮算法
|
||||
*
|
||||
* @Author : cron
|
||||
* @Date: 2020-01-15
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class EventEditHistoryHighLightUtil {
|
||||
|
||||
/**
|
||||
* 传入2个字符串进行相比高亮显示
|
||||
* eg:
|
||||
* 原数据一:王五张三
|
||||
* 原数据二:张三李四
|
||||
* <span style='color:red'>王五</span>张三
|
||||
* 张三<span style='color:red'>李四</span>
|
||||
*/
|
||||
|
||||
public static String[] getHighLightDifferentOld(String a, String b) {
|
||||
String[] temp = getDiff(a, b);
|
||||
String[] result = {getHighLight(a, temp[0]), getHighLight(b, temp[1])};
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getHighLight(String source, String temp) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
char[] sourceChars = source.toCharArray();
|
||||
char[] tempChars = temp.toCharArray();
|
||||
boolean flag = false;
|
||||
for (int i = 0; i < sourceChars.length; i++) {
|
||||
if (tempChars[i] != ' ') {
|
||||
if (i == 0) {
|
||||
sb.append("<span style='color:red'>").append(sourceChars[i]);
|
||||
} else if (flag) {
|
||||
sb.append(sourceChars[i]);
|
||||
} else {
|
||||
sb.append("<span style='color:red'>").append(sourceChars[i]);
|
||||
}
|
||||
flag = true;
|
||||
if (i == sourceChars.length - 1) {
|
||||
sb.append("</span>");
|
||||
}
|
||||
} else if (flag) {
|
||||
sb.append("</span>").append(sourceChars[i]);
|
||||
flag = false;
|
||||
} else {
|
||||
sb.append(sourceChars[i]);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] getDiff(String a, String b) {
|
||||
String[] result = null;
|
||||
//选取长度较小的字符串用来穷举子串
|
||||
if (a.length() < b.length()) {
|
||||
result = getDiff(a, b, 0, a.length());
|
||||
} else {
|
||||
result = getDiff(b, a, 0, b.length());
|
||||
result = new String[]{result[1], result[0]};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将a的指定部分与b进行比较生成比对结果
|
||||
*/
|
||||
private static String[] getDiff(String a, String b, int start, int end) {
|
||||
String[] result = new String[]{a, b};
|
||||
int len = result[0].length();
|
||||
while (len > 0) {
|
||||
for (int i = start; i < end - len + 1; i++) {
|
||||
String sub = result[0].substring(i, i + len);
|
||||
int idx = -1;
|
||||
if ((idx = result[1].indexOf(sub)) != -1) {
|
||||
result[0] = setEmpty(result[0], i, i + len);
|
||||
result[1] = setEmpty(result[1], idx, idx + len);
|
||||
if (i > 0) {
|
||||
//递归获取空白区域左边差异
|
||||
result = getDiff(result[0], result[1], 0, i);
|
||||
}
|
||||
if (i + len < end) {
|
||||
//递归获取空白区域右边差异
|
||||
result = getDiff(result[0], result[1], i + len, end);
|
||||
}
|
||||
len = 0;//退出while循环
|
||||
break;
|
||||
}
|
||||
}
|
||||
len = len / 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串s指定的区域设置成空格
|
||||
*/
|
||||
public static String setEmpty(String s, int start, int end) {
|
||||
char[] array = s.toCharArray();
|
||||
for (int i = start; i < end; i++) {
|
||||
array[i] = ' ';
|
||||
}
|
||||
return new String(array);
|
||||
}
|
||||
|
||||
//--------------new -------------------------
|
||||
|
||||
public static String[] getHighLightDifferent(String altbe, String altaf) {
|
||||
//字符串1 altbe 字符串2 altaf
|
||||
List<Integer> beList = rememberSpacing(altbe);
|
||||
List<Integer> afList = rememberSpacing(altaf);
|
||||
altbe = altbe.replace(" ", "");
|
||||
altaf = altaf.replace(" ", "");
|
||||
LinkedList<DiffMatchPatch.Diff> t = new DiffMatchPatch().diff_main(altbe, altaf);
|
||||
StringBuffer s1 = new StringBuffer();
|
||||
StringBuffer s2 = new StringBuffer();
|
||||
Integer indexBe = 0;
|
||||
Integer indexAf = 0;
|
||||
for (DiffMatchPatch.Diff diff : t) {
|
||||
StringBuffer diffTextBe = new StringBuffer(diff.text);
|
||||
StringBuffer diffTextAf = new StringBuffer(diff.text);
|
||||
if ("EQUAL".equalsIgnoreCase(diff.operation.toString())) {
|
||||
addSpacing(beList, indexBe, diffTextBe);
|
||||
addSpacing(afList, indexAf, diffTextAf);
|
||||
s1.append(diffTextBe);
|
||||
s2.append(diffTextAf);
|
||||
indexBe += diffTextBe.length();
|
||||
indexAf += diffTextAf.length();
|
||||
}
|
||||
indexBe = appendString2("DELETE", diff, s1, s2, beList, indexBe);
|
||||
indexAf = appendString2("INSERT", diff, s2, s1, afList, indexAf);
|
||||
}
|
||||
String[] result = new String[2];
|
||||
result[0] = s1.toString();
|
||||
result[1] = s2.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
// public static void appendString(String type, Diff diff, StringBuffer sbOne, StringBuffer sbTwo) {
|
||||
// if (type.equals(diff.operation.toString())) {
|
||||
// if (" ".equals(diff.text)) {
|
||||
// sbOne.append(" ");
|
||||
// sbTwo.append(" ");
|
||||
// } else {
|
||||
// sbOne.append("<em class='f-required'>").append(diff.text).append("</em>");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private static List<Integer> rememberSpacing(String str) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (' ' == str.charAt(i)) {
|
||||
list.add(i);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void addSpacing(List<Integer> list, Integer index, StringBuffer str) {
|
||||
for (Integer o : list) {
|
||||
if (o >= index && o < index + str.length()) {
|
||||
str.insert(o - index, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer appendString2(String type, DiffMatchPatch.Diff diff, StringBuffer sbOne,
|
||||
StringBuffer sbTwo, List<Integer> list, Integer i) {
|
||||
Integer result = i;
|
||||
if (type.equals(diff.operation.toString())) {
|
||||
StringBuffer sb = new StringBuffer(diff.text);
|
||||
for (Integer o : list) {
|
||||
if (o >= i && o < i + sb.length()) {
|
||||
sb.insert(o - i, ' ');
|
||||
}
|
||||
}
|
||||
sbOne.append("<span style='color:red;'>").append(sb).append("</span>");
|
||||
result = i + sb.length();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String a = "测试测试测试仅关注界面和功能,数据准确性在暂不测试";
|
||||
String b = "提交留言数据仅关注界面和功能,数据准确性在暂不测试";
|
||||
String[] anb = getHighLightDifferent(a, b);
|
||||
System.out.println(Arrays.toString(anb));
|
||||
|
||||
// String altbe = "提交留言数据仅关注界面和 功能,数据准确性在暂不测试";
|
||||
// String altaf = "提交留言数据仅关注界面和功能,数据准确性在暂不测试提交 留言数据仅关注界面和功能,数据准确性在暂不测试";
|
||||
// String[] highLightDifferentNew = getHighLightDifferent(altbe, altaf);
|
||||
// System.out.println(Arrays.toString(highLightDifferentNew));
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -124,8 +124,8 @@ public class SarStandCompareHisEOController extends BaseController<SarStandCompa
|
||||
|
||||
@ApiOperation(value = "条款比对")
|
||||
@PostMapping("/clauseComparison")
|
||||
public ResponseMessage<Map<String,Object>> clauseComparison(String oldItemId, String newItemId, String standHisId) throws Exception {
|
||||
Map<String,Object> resultMap = sarStandCompareHisEOService.clauseComparison(oldItemId,newItemId,standHisId);
|
||||
public ResponseMessage<Map<String,Object>> clauseComparison(String oldItemId, String newItemId, String standHisId,String flag) throws Exception {
|
||||
Map<String,Object> resultMap = sarStandCompareHisEOService.clauseComparisonEvent(oldItemId,newItemId,standHisId,flag);
|
||||
return Result.success(resultMap);
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -21,5 +21,7 @@ public interface SarStandCompareHisEOService {
|
||||
|
||||
Map<String,Object> clauseComparison(String oldItemId, String newItemId, String standHisId);
|
||||
|
||||
Map<String,Object> clauseComparisonEvent(String oldItemId, String newItemId, String standHisId,String flag);
|
||||
|
||||
Map<String,Object> fullTextComparison(String leftStandard, String rightStandard,String id) throws Exception;
|
||||
}
|
||||
|
||||
+134
@@ -1,6 +1,7 @@
|
||||
package com.adc.da.slrs.standardSplit.service.impl;
|
||||
|
||||
import com.adc.da.person.service.IPersonCollectEOService;
|
||||
import com.adc.da.slrs.standardSplit.EventUtils.EventEditHistoryHighLightUtil;
|
||||
import com.adc.da.slrs.standardSplit.dao.SarStandAttrDetailsEODao;
|
||||
import com.adc.da.slrs.standardSplit.dao.SarStandCompareHisEODao;
|
||||
import com.adc.da.slrs.standardSplit.entity.*;
|
||||
@@ -14,6 +15,7 @@ import com.adc.da.utils.treetool.TreeNode;
|
||||
import com.adc.da.utils.util.CompHanLPUtils;
|
||||
import com.adc.da.utils.util.DiffUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -112,6 +114,138 @@ public class SarStandCompareHisEOServiceImpl implements SarStandCompareHisEOServ
|
||||
return sarStandCompareHisEODao.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> clauseComparisonEvent(String oldItemId, String newItemId, String standHisId, String flag) {
|
||||
Map<String,Object> resultMap = new HashMap<String, Object>();
|
||||
String oldTxt = "";
|
||||
SarFileSplitItemsValEOPage oldPage = new SarFileSplitItemsValEOPage();
|
||||
oldPage.setItemId(oldItemId);
|
||||
oldPage.setType("TEXT");
|
||||
oldPage.setOrderBy("DISPLAY_SEQ,ID");
|
||||
List<SarFileSplitItemsValEO> oldList = sarFileSplitItemsValEOService.queryByList(oldPage);
|
||||
if(oldList!=null && !oldList.isEmpty()){
|
||||
for(int i = 1;i<=oldList.size();i++){
|
||||
if(i==oldList.size()) {
|
||||
oldTxt += oldList.get(i-1).getItemContent();
|
||||
}else{
|
||||
oldTxt += oldList.get(i-1).getItemContent() + "i#2\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
String newTxt = "";
|
||||
SarFileSplitItemsValEOPage newPage = new SarFileSplitItemsValEOPage();
|
||||
newPage.setItemId(newItemId);
|
||||
newPage.setType("TEXT");
|
||||
newPage.setOrderBy("DISPLAY_SEQ,ID");
|
||||
List<SarFileSplitItemsValEO> newList = sarFileSplitItemsValEOService.queryByList(newPage);
|
||||
if(newList!=null && !newList.isEmpty()){
|
||||
for(int i = 1;i<=newList.size();i++){
|
||||
if(i==newList.size()) {
|
||||
newTxt += newList.get(i-1).getItemContent();
|
||||
}else{
|
||||
newTxt += newList.get(i-1).getItemContent() + "i#2\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
String similarityDegree="";
|
||||
double similarity = 100.00;
|
||||
if(!StringUtils.isNotBlank(oldTxt.trim()) && !StringUtils.isNotBlank(newTxt.trim())){
|
||||
similarityDegree = "100.00";
|
||||
}else if(StringUtils.isNotBlank(oldTxt.trim()) && StringUtils.isNotBlank(newTxt.trim())){
|
||||
similarity = CompHanLPUtils.findSimilarity(oldTxt.trim(), newTxt.trim());
|
||||
NumberFormat nf = java.text.NumberFormat.getPercentInstance();
|
||||
//nf.setMaximumIntegerDigits(2);//小数点前保留几位
|
||||
nf.setMinimumFractionDigits(2);// 小数点后保留几位
|
||||
similarityDegree = nf.format(similarity);
|
||||
}else{
|
||||
similarity = 0.00;
|
||||
similarityDegree = "0.00";
|
||||
}
|
||||
resultMap.put("similarityDegree",similarityDegree);
|
||||
List<String> leftString = new ArrayList<>();
|
||||
List<String> rightString = new ArrayList<>();
|
||||
if(similarity >= 0.6){
|
||||
// DiffUtils diffUtils = new DiffUtils();
|
||||
// List<String> htmlDiffStr = diffUtils.getHtmlDiffStr(oldTxt.trim(), newTxt.trim());
|
||||
// List<String> stringList1 = Arrays.asList(htmlDiffStr.get(0).split("<br/>"));
|
||||
// for(String left : stringList1){
|
||||
// StringBuilder stringBuilder = new StringBuilder(left);
|
||||
// stringBuilder.append("</br>");
|
||||
// leftString.add(stringBuilder.toString());
|
||||
// }
|
||||
// List<String> stringList2 = Arrays.asList(htmlDiffStr.get(1).split("<br/>"));
|
||||
// for(String right : stringList2){
|
||||
// StringBuilder stringBuilder = new StringBuilder(right);
|
||||
// stringBuilder.append("</br>");
|
||||
// rightString.add(stringBuilder.toString());
|
||||
// }
|
||||
String[] anb = EventEditHistoryHighLightUtil.getHighLightDifferent(oldTxt.trim(), newTxt.trim());
|
||||
if(StringUtils.isNotBlank(flag) && flag.equals("2")){
|
||||
anb[0] = anb[0].replaceAll("red;", "#000000;background-color: red;").replaceAll("i#2\n", "<br/>");
|
||||
anb[1] = anb[1].replaceAll("red;", "#000000;background-color: rgb(51, 145, 206);").replaceAll("i#2\n", "<br/>");
|
||||
}else {
|
||||
anb[0] = anb[0].replaceAll("red;", "#000000;background-color: rgb(51, 145, 206);").replaceAll("i#2\n", "<br/>");
|
||||
anb[1] = anb[1].replaceAll("red;", "#000000;background-color: red;").replaceAll("i#2\n", "<br/>");
|
||||
}
|
||||
resultMap.put("leftString",anb[0]);
|
||||
resultMap.put("rightString",anb[1]);
|
||||
}else{
|
||||
String oldTxtTemp = oldTxt.replace("i#2\n", "<br/>");
|
||||
List<String> stringList1 = Arrays.asList(oldTxtTemp.split("<br/>"));
|
||||
for(String left : stringList1){
|
||||
StringBuilder stringBuilder = new StringBuilder(left);
|
||||
stringBuilder.append("</div>");
|
||||
stringBuilder.insert(0,"<div>");
|
||||
leftString.add(stringBuilder.toString());
|
||||
}
|
||||
resultMap.put("leftString",leftString);
|
||||
String newTxtTemp = newTxt.replace("i#2\n", "<br/>");
|
||||
List<String> stringList2 = Arrays.asList(newTxtTemp.split("<br/>"));
|
||||
for(String right : stringList2){
|
||||
StringBuilder stringBuilder = new StringBuilder(right);
|
||||
stringBuilder.append("</div>");
|
||||
stringBuilder.insert(0,"<div>");
|
||||
rightString.add(stringBuilder.toString());
|
||||
}
|
||||
resultMap.put("rightString",rightString);
|
||||
}
|
||||
//往条款比对历史表中添加数据
|
||||
if(standHisId != null && !standHisId.isEmpty()){
|
||||
SarFileSplitItemsEO leftEo = sarFileSplitItemsEOService.selectByPrimaryKey(oldItemId);
|
||||
SarFileSplitItemsEO rightEo = sarFileSplitItemsEOService.selectByPrimaryKey(newItemId);
|
||||
String leftItemsText = "";
|
||||
if(leftString != null && !leftString.isEmpty()){
|
||||
for(String left : leftString){
|
||||
leftItemsText += left;
|
||||
}
|
||||
}
|
||||
String rightItemsText = "";
|
||||
if(rightString != null && !rightString.isEmpty()){
|
||||
for(String right : rightString){
|
||||
rightItemsText += right;
|
||||
}
|
||||
}
|
||||
SarItemsCompareHisEO sarItemsCompareHisEO = new SarItemsCompareHisEO();
|
||||
sarItemsCompareHisEO.setId(UUIDUtils.randomUUID20());
|
||||
sarItemsCompareHisEO.setOldItemsId(leftEo.getId());
|
||||
sarItemsCompareHisEO.setOldItemsName(leftEo.getItemsName());
|
||||
sarItemsCompareHisEO.setOldItemsNum(leftEo.getItemsNum());
|
||||
sarItemsCompareHisEO.setOldItemsText(leftItemsText);
|
||||
sarItemsCompareHisEO.setNewItemsId(rightEo.getId());
|
||||
sarItemsCompareHisEO.setNewItemsName(rightEo.getItemsName());
|
||||
sarItemsCompareHisEO.setNewItemsNum(rightEo.getItemsNum());
|
||||
sarItemsCompareHisEO.setNewItemsText(rightItemsText);
|
||||
sarItemsCompareHisEO.setStandHisId(standHisId);
|
||||
sarItemsCompareHisEO.setSimilarityDegree(similarityDegree);
|
||||
sarItemsCompareHisEO.setCreateUser(LoginUserUtil.getUserId());
|
||||
sarItemsCompareHisEO.setModifyUser(LoginUserUtil.getUserId());
|
||||
sarItemsCompareHisEO.setModifyTime(new Date());
|
||||
sarItemsCompareHisEO.setCreateTime(new Date());
|
||||
sarItemsCompareHisEOService.insertSelective(sarItemsCompareHisEO);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> clauseComparison(String oldItemId, String newItemId, String standHisId) {
|
||||
Map<String,Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
Reference in New Issue
Block a user