|
@@ -3,15 +3,12 @@ package org.springblade.manager.service.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import jodd.util.ArraysUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
@@ -27,7 +24,6 @@ import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
-import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
|
import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.manager.dto.RangeInfo;
|
|
@@ -40,17 +36,18 @@ import org.springblade.manager.mapper.ContractInfoMapper;
|
|
|
import org.springblade.manager.mapper.WbsTreeContractMapper;
|
|
|
import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
|
import org.springblade.manager.service.IWbsTreeContractService;
|
|
|
-import org.springblade.manager.utils.DiffListUtil;
|
|
|
import org.springblade.manager.vo.*;
|
|
|
import org.springblade.system.cache.ParamCache;
|
|
|
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.regex.Matcher;
|
|
@@ -565,6 +562,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.eq(WbsTreeContract::getWbsId, node.getWbsId()).eq(WbsTreeContract::getWbsType, node.getWbsType())
|
|
|
.eq(WbsTreeContract::getStatus, 1));
|
|
|
|
|
|
+ Map<Long, WbsTreeContract> tabMaps = tabs.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, Function.identity()));
|
|
|
+
|
|
|
//初始化表
|
|
|
List<WbsTreeContract> sgTab = tabs.stream().filter(f -> "1,2,3".contains(f.getTableOwner())).collect(Collectors.toList());
|
|
|
List<WbsTreeContract> jlTab = tabs.stream().filter(f -> "4,5,6".contains(f.getTableOwner())).collect(Collectors.toList());
|
|
@@ -648,6 +647,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Set<String> filedNames = new HashSet<>();
|
|
|
//数据处理
|
|
|
for (Map.Entry<String, List<InsertDataVO>> oneTabData : maps.entrySet()) {
|
|
|
String initTabName = oneTabData.getKey();
|
|
@@ -657,11 +657,11 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
//一张实体表中,多组数据,复制表共用同一张实体表,只是pKeyId不同
|
|
|
Map<String, List<InsertDataVO>> oneTab = dataValue.stream().collect(Collectors.groupingBy(InsertDataVO::getPKeyId));
|
|
|
-
|
|
|
for (Map.Entry<String, List<InsertDataVO>> tab : oneTab.entrySet()) {
|
|
|
String tabPKeyId = tab.getKey();
|
|
|
List<InsertDataVO> tabData = tab.getValue();
|
|
|
StringBuilder dataSql = new StringBuilder();
|
|
|
+ Set<String> exKeys = new LinkedHashSet<>();
|
|
|
List<String> keys = new LinkedList<>();
|
|
|
List<String> values = new LinkedList<>();
|
|
|
for (InsertDataVO vo : tabData) {
|
|
@@ -674,8 +674,31 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
String data = vo.getData();
|
|
|
values.add(data);
|
|
|
}
|
|
|
+ if (ObjectUtil.isNotEmpty(vo.getDataLength()) && vo.getDataLength() > 250 && vo.getDataLength() <= 500) {
|
|
|
+ //如果字段长度不够,那么扩容
|
|
|
+ exKeys.add(vo.getKey() + "---" + vo.getDataLength());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(vo.getDataLength()) && vo.getDataLength() > 500) {
|
|
|
+ //如果超过500字符长度,那么直接异常提示
|
|
|
+ filedNames.add(vo.getName());
|
|
|
+ }
|
|
|
}
|
|
|
if (keys.size() > 0 && values.size() > 0 && keys.size() == values.size()) {
|
|
|
+ //alter SQL(扩容字段长度)
|
|
|
+ StringBuilder exStrBuilder = new StringBuilder();
|
|
|
+ if (exKeys.size() > 0) {
|
|
|
+ for (String exKey : exKeys) {
|
|
|
+ String[] split = exKey.split("---");
|
|
|
+ String key = split[0];
|
|
|
+ int length = Integer.parseInt(split[1]) + 10; //字段长度+10
|
|
|
+ String alterSql = "ALTER TABLE " + initTabName + " MODIFY " + key + " VARCHAR(" + length + ");";
|
|
|
+ exStrBuilder.append(alterSql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(exStrBuilder)) {
|
|
|
+ dataSql.append(exStrBuilder);
|
|
|
+ }
|
|
|
+
|
|
|
//delete SQL(删除旧数据,去重)
|
|
|
String delSql = "delete from " + initTabName + " where p_key_id = " + tabPKeyId + ";";
|
|
|
//insert SQL(新增)
|
|
@@ -695,6 +718,40 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //超过500字符长度,直接返回异常
|
|
|
+ if (filedNames.size() > 0) {
|
|
|
+ //存储结果的Map
|
|
|
+ Map<String, List<String>> resultMap = new HashMap<>();
|
|
|
+ for (String str : filedNames) {
|
|
|
+ String[] split = str.split("tabId:");
|
|
|
+ String filedName = split[0];
|
|
|
+ String tabId = split[1];
|
|
|
+ WbsTreeContract tab = tabMaps.get(Long.parseLong(tabId));
|
|
|
+ if (tab != null) {
|
|
|
+ String tableName = tab.getNodeName();
|
|
|
+ if (!resultMap.containsKey(tableName)) {
|
|
|
+ //如果该表名不存在于Map中,则新建一个列表
|
|
|
+ resultMap.put(tableName, new ArrayList<>());
|
|
|
+ }
|
|
|
+ //将字段名加入该表对应的列表中
|
|
|
+ resultMap.get(tableName).add(filedName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (resultMap.size() > 0) {
|
|
|
+ List<String> errorList = new ArrayList<>();
|
|
|
+ //遍历Map,拼接错误信息
|
|
|
+ for (String tableName : resultMap.keySet()) {
|
|
|
+ List<String> fields = resultMap.get(tableName);
|
|
|
+ if (fields.size() > 0) {
|
|
|
+ errorList.add("表:【" + tableName + "】中字段:" + StringUtils.join(fields, "、"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (errorList.size() > 0) {
|
|
|
+ throw new ServiceException("【" + StringUtils.join(errorList, "、") + "】填报的数据过长,同步失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//入库
|
|
|
if (resultSQLS.size() > 0) {
|
|
|
List<List<String>> partition = Lists.partition(resultSQLS, 10);
|
|
@@ -781,19 +838,32 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//下拉框
|
|
|
td = doc.select("el-select[keyname~=" + findIndex + ".*]");
|
|
|
}
|
|
|
+ if (td.size() == 0) {
|
|
|
+ //测站点
|
|
|
+ td = doc.select("hc-form-select-search[keyname~=" + findIndex + ".*]");
|
|
|
+ }
|
|
|
String placeholderValue = "";
|
|
|
+ String inputType = "";
|
|
|
if (td.size() >= 1) {
|
|
|
for (Element element : td) {
|
|
|
placeholderValue = element.attr("placeholderxx");
|
|
|
+ inputType = element.attr("type");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //警告,空串跳过
|
|
|
+ //警告,空串跳过(根据placeholder、type匹配关联)
|
|
|
if (!placeholderValue.contains("警告") && StringUtils.isNotEmpty(placeholderValue)) {
|
|
|
if (StringUtils.isNotEmpty(htmlStringJL)) {
|
|
|
Document docJL = Jsoup.parse(htmlStringJL);
|
|
|
Elements tdJL = docJL.select("el-input[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
+
|
|
|
+ //特殊处理
|
|
|
+ if (placeholderValue.equals("测站点") && StringUtils.isNotEmpty(inputType)) {
|
|
|
+ tdJL = docJL.select("hc-form-select-search[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*][type~=" + this.escapeRegex(inputType) + ".*]");
|
|
|
+ } /*else if (placeholderValue.equals("日期:")) {
|
|
|
+ tdJL = docJL.select("el-date-picker[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*][type~=" + this.escapeRegex(inputType) + ".*]");
|
|
|
+ }*/
|
|
|
+
|
|
|
if (tdJL.size() == 0) {
|
|
|
//日期格式
|
|
|
tdJL = docJL.select("el-date-picker[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
@@ -814,6 +884,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//下拉框
|
|
|
tdJL = docJL.select("el-select[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
}
|
|
|
+ if (tdJL.size() == 0) {
|
|
|
+ //测站点
|
|
|
+ tdJL = docJL.select("hc-form-select-search[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
+ }
|
|
|
if (tdJL.size() >= 1) {
|
|
|
for (Element element : tdJL) {
|
|
|
String keyname = element.attr("keyname");
|
|
@@ -873,19 +947,33 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//下拉框
|
|
|
td = doc.select("el-select[keyname~=" + findIndex + ".*]");
|
|
|
}
|
|
|
+ if (td.size() == 0) {
|
|
|
+ //测站点
|
|
|
+ td = doc.select("hc-form-select-search[keyname~=" + findIndex + ".*]");
|
|
|
+ }
|
|
|
String placeholderValue = "";
|
|
|
+ String inputType = "";
|
|
|
if (td.size() >= 1) {
|
|
|
for (Element element : td) {
|
|
|
placeholderValue = element.attr("placeholderxx");
|
|
|
+ inputType = element.attr("type");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //警告,空串跳过
|
|
|
+ //警告,空串跳过(根据placeholder、type匹配关联)
|
|
|
if (!placeholderValue.contains("警告") && StringUtils.isNotEmpty(placeholderValue)) {
|
|
|
if (StringUtils.isNotEmpty(htmlStringJL)) {
|
|
|
Document docJL = Jsoup.parse(htmlStringJL);
|
|
|
Elements tdJL = docJL.select("el-input[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
+
|
|
|
+ //特殊处理
|
|
|
+ if (placeholderValue.equals("测站点") && StringUtils.isNotEmpty(inputType)) {
|
|
|
+ tdJL = docJL.select("hc-form-select-search[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*][type~=" + this.escapeRegex(inputType) + ".*]");
|
|
|
+ } /*else if (placeholderValue.equals("日期:")) {
|
|
|
+ tdJL = docJL.select("el-date-picker[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*][type~=" + this.escapeRegex(inputType) + ".*]");
|
|
|
+ }*/
|
|
|
+
|
|
|
if (tdJL.size() == 0) {
|
|
|
//日期格式
|
|
|
tdJL = docJL.select("el-date-picker[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
@@ -906,6 +994,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//下拉框
|
|
|
tdJL = docJL.select("el-select[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
}
|
|
|
+ if (tdJL.size() == 0) {
|
|
|
+ //测站点
|
|
|
+ tdJL = docJL.select("hc-form-select-search[placeholderxx~=" + this.escapeRegex(placeholderValue) + ".*]");
|
|
|
+ }
|
|
|
if (tdJL.size() >= 1) {
|
|
|
for (Element element : tdJL) {
|
|
|
String keyname = element.attr("keyname");
|
|
@@ -915,7 +1007,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
if (keyJL.length() > 3) { //排除key=key的时候,也就是找不到key值,正常为key_X
|
|
|
String keyJLIndex = keynameJL[1];
|
|
|
if (keyJLIndex.equals(index)) { //位置相同才复制
|
|
|
- values.add(data + "_^_" + keyJLIndex + "---" + keyJL);
|
|
|
+ values.add(data + "_^_" + keyJLIndex + "---" + keyJL + "---" + placeholderValue + "tabId:" + pKeyId);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -929,10 +1021,12 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
Set<String> dataResult = new HashSet<>();
|
|
|
Set<String> keyResult = new HashSet<>();
|
|
|
+ Set<String> nameResult = new HashSet<>();
|
|
|
for (String v : values) {
|
|
|
String[] split1 = v.split("---");
|
|
|
dataResult.add(split1[0]);
|
|
|
keyResult.add(split1[1]);
|
|
|
+ nameResult.add(split1[2]);
|
|
|
}
|
|
|
if (dataResult.size() > 0 && keyResult.size() > 0) {
|
|
|
InsertDataVO vo = new InsertDataVO();
|
|
@@ -940,6 +1034,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
vo.setInitTabName(initTabNameJL);
|
|
|
vo.setKey(keyResult.stream().findAny().orElse(null));
|
|
|
vo.setData(StringUtils.join(dataResult, "☆"));
|
|
|
+ vo.setDataLength(vo.getData().length());
|
|
|
+ vo.setName(nameResult.stream().findAny().orElse(null));
|
|
|
resultData.add(vo);
|
|
|
}
|
|
|
}
|