update 多条款时对后面的属性合并去重

This commit is contained in:
lijiarao
2024-09-02 18:24:38 +08:00
parent 6c3ca8f745
commit 5cb3a447b7
@@ -1711,8 +1711,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
Map map = validateImportDatas(list,categoryList,dictItemList,fieldList,filepath,cut);
long b = System.currentTimeMillis();
log.error("================校验耗时:" + (b - a) + "ms");
boolean isOk = (boolean) map.get("result");
if (!isOk) {
boolean isOk = (boolean) map.get("result"); if (!isOk) {
//验证没有通过
String message = (String) map.get("message");
return Result.error(message);
@@ -1736,6 +1735,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
String[] translationArr = importDto.get("translation").toString().split("\n");
int j = translationArr.length;
List<SarFileSplitItemsValEO> addItemValList = new ArrayList<>();
List<Map<String, Object>> itemList = new ArrayList<>();
if (addItemsEOList != null && !addItemsEOList.isEmpty()) {
Map<String, Object> oldItems = addItemsEOList.get(addItemsEOList.size()-1);
if (itemNum > 0 && importDto.get("item_num").equals(oldItems.get("item_num"))
@@ -1746,6 +1746,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if(!Objects.isNull(oldItems.get("itemValEOList"))){
addItemValList = (List<SarFileSplitItemsValEO>) oldItems.get("itemValEOList");
}
if(!Objects.isNull(oldItems.get("itemList"))){
itemList = (List<Map<String, Object>>) oldItems.get("itemList");
}
String itemContent = oldItems.get("item_content").toString() + importDto.get("item_content").toString();
oldItems.put("item_content", itemContent);
if (valArr != null && valArr.length > 0) {
@@ -1772,31 +1775,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if (nowfilelist != null && !nowfilelist.isEmpty()) {
String url = nowfilelist.get(0).getPath();
MultipartFile multipartFile = createMfileByPath(url);
String state = "0";
// String fileSuffix = url.substring(url.lastIndexOf("."));
// String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
// if (fileTypeStr.contains(fileSuffix)) {
// state = "1";
// }
// OSSFile oSSFile = ossFileService.uploadLocalForSplit(multipartFile, "",state,null);
// if(oSSFile!=null){
// oSSFile = ossFileService.getById(oSSFile.getId());
isText = false;
//// BASE64Encoder base64Encoder = new BASE64Encoder();
//// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
// String path = oSSFile.getUrl();
//// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
//// String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
// valEO.setType("IMG");
//// valEO.setItemContent(imgCon);
// valEO.setItemContent(path);
//
// String imageName = UUIDUtils.randomUUID10() + multipartFile.getName();
// String filepathandname = uploadCospath + "/" + imageName;
try {
// String paths = splitUrl+imageName;
// MinioUtil.uploadByte(bytev, filepathandname);
imgCheck(multipartFile);
String upload = ObsBootUtil.upload(multipartFile, "temp");
OSSFile ossFile = new OSSFile();
@@ -1833,9 +1813,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
}
}
addItemValList.add(valEO);
itemList.add(importDto);
}
}
oldItems.put("itemValEOList", addItemValList);
oldItems.put("itemList", itemList);
}else {
if(ObjectUtil.isNotEmpty(importDto.get("item_content"))) {
if (valArr != null && valArr.length > 0) {
@@ -1862,31 +1844,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if (nowfilelist != null && !nowfilelist.isEmpty()) {
String url = nowfilelist.get(0).getPath();
MultipartFile multipartFile = createMfileByPath(url);
String state = "0";
// String fileSuffix = url.substring(url.lastIndexOf("."));
// String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
// if (fileTypeStr.contains(fileSuffix)) {
// state = "1";
// }
// OSSFile oSSFile = ossFileService.uploadLocalOfCos(multipartFile, "", state,null);
// OSSFile oSSFile = ossFileService.uploadLocalForSplit(multipartFile, "",state,null);
// oSSFile = ossFileService.getById(oSSFile.getId());
// if (oSSFile != null) {
// oSSFile = ossFileService.getById(oSSFile.getId());
isText = false;
//// BASE64Encoder base64Encoder = new BASE64Encoder();
//// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
// String path = oSSFile.getUrl();
//// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
//// String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
// valEO.setType("IMG");
//// valEO.setItemContent(imgCon);
// valEO.setItemContent(path);
// }
try {
// String paths = splitUrl+imageName;
// MinioUtil.uploadByte(bytev, filepathandname);
imgCheck(multipartFile);
String upload = ObsBootUtil.upload(multipartFile, "temp");
OSSFile ossFile = new OSSFile();
@@ -1922,9 +1881,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
}
}
addItemValList.add(valEO);
itemList.add(importDto);
}
}
importDto.put("itemValEOList", addItemValList);
importDto.put("itemList", itemList);
}
addItemsEOList.add(importDto);
}
@@ -1954,25 +1915,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if (nowfilelist != null && !nowfilelist.isEmpty()) {
String url = nowfilelist.get(0).getPath();
MultipartFile multipartFile = createMfileByPath(url);
String state = "0";
// OSSFile oSSFile = ossFileService.uploadLocalOfCos(multipartFile, "", state,null);
// OSSFile oSSFile = ossFileService.uploadLocalForSplit(multipartFile, "",state,null);
//// oSSFile = ossFileService.getById(oSSFile.getId());
// if (oSSFile != null) {
isText = false;
//// BASE64Encoder base64Encoder = new BASE64Encoder();
//// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
// String path = oSSFile.getUrl();
//// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
//// String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
// valEO.setType("IMG");
//// valEO.setItemContent(imgCon);
// valEO.setItemContent(path);
// }
try {
// String paths = splitUrl+imageName;
// MinioUtil.uploadByte(bytev, filepathandname);
imgCheck(multipartFile);
String upload = ObsBootUtil.upload(multipartFile, "temp");
OSSFile ossFile = new OSSFile();
@@ -2008,9 +1952,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
}
}
addItemValList.add(valEO);
itemList.add(importDto);
}
}
importDto.put("itemValEOList", addItemValList);
importDto.put("itemList", itemList);
}
addItemsEOList.add(importDto);
}
@@ -2033,39 +1979,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
//当导入节点没有子节点时获取当前节点的序号
treeListDisplay = targetMenuEO.getDisplaySeq();
}
// if(!"总目录".equals(targetMenuEO.getName())){
// String regex = "^[0-9]{0}([0-9]|[.])+$"; //TODO 待优化数字和点必须交替
// if(!targetMenuEO.getName().matches(regex)){
// throw new AdcDaBaseException("所选目录命名不规范");
// }
// String[] str = targetMenuEO.getName().split(".");
// if(str.length == 0){
// levelNum = 2;
// }else {
// levelNum = str.length + 1;
// }
// }else{
// levelNum = 1;
// }
}
//获取导入数据的所有一级节点
int finalLevelNum = levelNum;
/*List<SarFileSplitItemsEO> itemNumList = new ArrayList<>();
for(SarFileSplitItemsEO sarFileSplitItemsEO : addItemsEOList){
String[] str = sarFileSplitItemsEO.getItemsNum().split(".");
if(str.length == finalLevelNum){
itemNumList.add(sarFileSplitItemsEO);
}
}*/
// 2022-03-31 注释
// List<SarFileSplitItemsEO> itemNumList = addItemsEOList.stream()
// .filter(e->e.getItemsNum().split("\\.").length == finalLevelNum || e.getItemsNum().contains("附录"))
// .collect(Collectors.toList());
//构造目录树
HashMap<String, String> menuAndItemMap = new HashMap<>();
// if(CollectionUtils.isNotEmpty(itemNumList)) {
List<SarFileSplitMenuTreeNode> treeList = new ArrayList<>();
List<Map<String, Object>> itemsEOList = new ArrayList<>(addItemsEOList);
if (splitStandardClass.contains(sarFileSplitInfoEO.getStandardClass())){
@@ -2078,9 +1994,6 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
for (SarFileSplitMenuTreeNode treeNode : treeList) {
menuAndItemMap.put(treeNode.getItemId(), treeNode.getId());
}
// }else{
// throw new AdcDaBaseException("导入目录命名不规范");
// }
//添加条款
long aa = System.currentTimeMillis();
List<SarFileSplitItemsValEO> addItemValList = new ArrayList<>();
@@ -2145,20 +2058,6 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
List<SarFileSplitMenu> sarFileSplitMenuList = new ArrayList<>();
for (SarFileSplitMenuTreeNode treeNode : treeList) {
//创建菜单
// SarFileSplitMenuEO sarFileSplitMenuEO = new SarFileSplitMenuEO();
// sarFileSplitMenuEO.setId(treeNode.getId());
// sarFileSplitMenuEO.setInfoId(infoId);
// sarFileSplitMenuEO.setName(treeNode.getName());
// sarFileSplitMenuEO.setItemName(treeNode.getItemName());
// sarFileSplitMenuEO.setPId(treeNode.getParentId());
// sarFileSplitMenuEO.setDisplaySeq(treeNode.getOrderNum());
// sarFileSplitMenuEO.setCreationUser(userId);
// sarFileSplitMenuEO.setModifyUser(userId);
// sarFileSplitMenuEO.setValidFlag(0);
// sarFileSplitMenuEO.setCreationTime(new Date());
// sarFileSplitMenuEO.setModifyTime(new Date());
// sarFileSplitMenuEOMapper.insertSelective(sarFileSplitMenuEO);
if (existStandard && treeNode.getItemId().equals(LawsDocumentSplit.get(0).getId())){
continue;
}
@@ -2571,35 +2470,6 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
} catch (Exception e) {
templateError();
}
// for (int i = 0; i < cellLength; i++) {
// if (rowTitle != null) {
// Cell cell = rowTitle.getCell(i);
// if(ObjectUtil.isNotNull(cell)){
// //设置单元格类型
// cell.setCellType(CellType.STRING);
// String cellValue = cell.getStringCellValue().substring(cell.getStringCellValue().indexOf("*")+1);
// if(!cellValue.equals(titles[i])){
// if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
// throw new JeroBootException("请导入正确模板!");
// } else {
// throw new JeroBootException("Please import the correct template");
// }
// }
// } else{
// if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
// throw new JeroBootException("请导入正确模板!");
// } else {
// throw new JeroBootException("Please import the correct template");
// }
// }
// }else{
// if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
// throw new JeroBootException("请导入正确模板!");
// } else {
// throw new JeroBootException("Please import the correct template");
// }
// }
// }
Row rowDescription= sheet.getRow(1);
if (rowDescription != null) {
Cell cell = rowDescription.getCell(0);
@@ -2639,19 +2509,17 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if (y == 0){
// 条文号精度丢失问题
try {
String stringCellValue = cell.getStringCellValue();
if (StringUtils.isNotBlank(stringCellValue)){
double numericCellValue = cell.getNumericCellValue();
BigDecimal bigDecimal = BigDecimal.valueOf(numericCellValue);
double numericCellValue = cell.getNumericCellValue();
BigDecimal bigDecimal = BigDecimal.valueOf(numericCellValue);
if (bigDecimal.compareTo(BigDecimal.ZERO)==0){
cell.setCellValue("");
}else {
String str = String.valueOf(bigDecimal);
if (str.endsWith(".0")){
str = str.substring(0, str.length() - 2);
}
cell.setCellValue(str);
}else {
cell.setCellValue("");
}
} catch (Exception e) {
}
}
@@ -2669,8 +2537,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cellValue = df.format(d);
}else {
String stringCellValue = cell.getStringCellValue();
cellValue = stringCellValue;
cellValue = cell.getStringCellValue();
}
}
//
@@ -3471,6 +3338,36 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
}
}
}
private final String[] NEED_MERGE = new String[]{
"change_description",
"regulatory_notes",
"part_name",
"key_controller",
"applicable_components",
"responsible_department",
"responsible_module",
"related_department",
"related_module",
"applications",
"power_type",
"domain_area",
"configuration_requirements",
"new_cer_implement_date",
"new_production_implementation",
"registration_date",
"enterprise_standard",
"technical_specification_design_guide",
"drawing_template",
"technical_agreement_template",
"verification_report_template_checklist",
"dvp_template",
"dfema",
"key_technology_decomposition_table",
"other_documents_templates",
"investigation_stage",
"p3",
"p5",
"remarkss"};
private void createItemsInfo(Map<String, Object> sarFileSplitItemsEO, String menuId, String infoId, List<SarFileSplitItemsValEO> addItemValList, List<LawsDocumentSplit> lawsDocumentSplit, List<LawsTag> fieldListSelect){
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
@@ -3492,6 +3389,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
//添加val表数据
List<SarFileSplitItemsValEO> getValList = (List<SarFileSplitItemsValEO>) sarFileSplitItemsEO.get("itemValEOList");
List<Map<String, Object>> getItemListList = (List<Map<String, Object>>) sarFileSplitItemsEO.get("itemList");
String itemConditions = "";
String itemConditionsTranslation = "";
int ind = 1;
@@ -3540,9 +3438,44 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
sarFileSplitItemsEO.put("item_content", itemConditions);
sarFileSplitItemsEO.put("translation", itemConditionsTranslation);
}
if (CollectionUtil.isNotEmpty(getItemListList) && getItemListList.size() > 1) {
Map<String, Object> map = new HashMap<>();
for (String s : NEED_MERGE) {
map.put(s,"");
}
for (Map<String, Object> stringObjectMap : getItemListList) {
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
String key = entry.getKey();
if (map.containsKey(key)) {
String value = (String) entry.getValue();
if (StringUtils.isBlank(value)) {
continue;
}
String str = map.get(key).toString();
if (StringUtils.isBlank(str)) {
map.put(key,value);
}else {
map.put(key,str+","+value);
}
}
}
}
//去重
for (Map.Entry<String, Object> entry : map.entrySet()) {
String value = (String) entry.getValue();
if (StringUtils.isBlank(value)) {
continue;
}
List<String> strings = Arrays.asList(value.split(","));
Set<String> sets = new HashSet<>(strings);
entry.setValue(String.join(",",sets));
}
sarFileSplitItemsEO.putAll(map);
}
String id = (String)sarFileSplitItemsEO.get("id");
sarFileSplitItemsEO.remove("id");
sarFileSplitItemsEO.remove("itemValEOList");
sarFileSplitItemsEO.remove("itemList");
sarFileSplitItemsEO = filterMap(sarFileSplitItemsEO);
Map<String, Object> finalSarFileSplitItemsEO = sarFileSplitItemsEO;
sarFileSplitItemsEO.forEach((k, v) -> {
@@ -3565,8 +3498,10 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
List<SarFileSplitMenuTreeNode> treeNodeList = new ArrayList<>();
String regex = "^[0-9]{0}([0-9]|[.])+$"; //TODO 待优化数字和点必须交替
String parentId = "";
for (Map<String, Object> itemEO : addItemsEOList) {
String itemNum = itemEO.get("item_num").toString();
String itemTitle = itemEO.get("item_title").toString();
// if(itemNum.matches(regex) || itemNum.contains("附录")) { // TODO 解除条款号格式限制
SarFileSplitMenuTreeNode treeNode = new SarFileSplitMenuTreeNode();
treeNode.setId(UUIDUtils.randomUUID20());
@@ -3576,6 +3511,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if(itemNum.contains(".")) {
String parentName = itemNum.substring(0, itemNum.lastIndexOf("."));
treeNode.setParentName(parentName);
List<SarFileSplitMenuTreeNode> p = treeNodeList.stream().filter(e -> e.getName().equals(parentName)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(p)) {
//其他节点
@@ -3587,12 +3523,17 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
}else{
treeNode.setParentId(menuId);
}
}else{
}
else if (StringUtils.isBlank(itemTitle)){
treeNode.setParentId(parentId);
}
else{
treeNode.setParentId(menuId);
parentId = treeNode.getId();
}
++treeListDisplay;
treeNode.setOrderNum(treeListDisplay);
treeNode.setItemName(itemEO.get("item_title").toString());
treeNode.setItemName(itemTitle);
treeNode.setItemId(itemEO.get("id").toString());
treeNodeList.add(treeNode);
// }
@@ -3634,24 +3575,13 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
*/
private List<SarFileSplitMenuTreeNode> buildTree2(List<Map<String, Object>> addItemsEOList, Long treeListDisplay, String menuId){
// 过滤出 非正常编号的数据
// String regexs = "^[0-9]{0}([0-9]|[.])+$";
// List<Map<String, Object>> otherList =
// addItemsEOList.stream()
// .filter(v -> !String.valueOf(v.get("item_num")).matches(regexs))
// .collect(Collectors.toList());
// 排序
// addItemsEOList.removeAll(otherList);
// addItemsEOList.sort(new DirectoryComparator());
// addItemsEOList.addAll(otherList);
List<SarFileSplitMenuTreeNode> treeNodeList = new ArrayList<>();
List<String> dotList = new ArrayList<>();
String regex = "^[0-9]{0}([0-9]|[.])+$"; //TODO 待优化数字和点必须交替
String parentId = "";
for (Map<String, Object> itemEO : addItemsEOList) {
String itemNum = itemEO.get("item_num").toString();
String itemTitle = itemEO.get("item_title").toString();
// if(itemNum.matches(regex) || itemNum.contains("附录")) { // TODO 解除条款号格式限制
SarFileSplitMenuTreeNode treeNode = new SarFileSplitMenuTreeNode();
treeNode.setId(UUIDUtils.randomUUID20());
@@ -3674,15 +3604,21 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
//一级节点
treeNode.setParentId(menuId);
}
}else{
}
else if (StringUtils.isBlank(itemTitle)){
treeNode.setParentId(parentId);
}
else{
treeNode.setParentId(menuId);
parentId = treeNode.getId();
}
// }else{
// treeNode.setParentId(menuId);
// }
++treeListDisplay;
treeNode.setOrderNum(treeListDisplay);
treeNode.setItemName(itemEO.get("item_title").toString());
treeNode.setItemName(itemTitle);
treeNode.setItemId(itemEO.get("id").toString());
treeNodeList.add(treeNode);
// }