|
@@ -36,6 +36,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -282,6 +283,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) {
|
|
|
if (StringUtils.isEmpty(initTableName)) {
|
|
|
return R.fail("未获取到initTableName对应实体表名称,操作失败");
|
|
@@ -303,6 +305,19 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
wbsFormElementList.forEach(obj -> obj.setStatus(1));
|
|
|
boolean b = this.updateBatchById(wbsFormElementList);
|
|
|
|
|
|
+ //字段级字段长度缓存
|
|
|
+ Map<String, Integer> lengthMap = new HashMap<>();
|
|
|
+
|
|
|
+ //查询当前表的所有字段级字段长度
|
|
|
+ List<Map<String, Object>> filedLengths = baseMapper.selectFiledLength(initTableName);
|
|
|
+ for (Map<String, Object> filedLength : filedLengths) {
|
|
|
+ BigInteger length = (BigInteger) filedLength.get("length");
|
|
|
+ if (length == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ lengthMap.put(filedLength.get("key").toString(), length.intValue());
|
|
|
+ }
|
|
|
+
|
|
|
//修改实体表信息
|
|
|
if (b) {
|
|
|
String fId = "";
|
|
@@ -321,16 +336,16 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
|
|
|
if (eType.equals("bigint") && (eLength > 255 || eLength < 10)) {
|
|
|
this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
- return R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-255之间");
|
|
|
+ return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-255之间");
|
|
|
} else if (eType.equals("varchar") && (eLength > 3000 || eLength < 10)) {
|
|
|
this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
- return R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-3000之间");
|
|
|
+ return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-3000之间");
|
|
|
} else if (eType.equals("decimal") && (eLength > 65 || eLength < 10)) {
|
|
|
this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
- return R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为10-65之间");
|
|
|
+ return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为10-65之间");
|
|
|
} else if (eType.equals("datetime") && (eLength > 400 || eLength < 0)) {
|
|
|
this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
- return R.fail(eKey+"元素名称:"+eName+"请输入正确长度,该类型范围为0-400之间");
|
|
|
+ return R.fail(eKey + "元素名称:" + eName + "请输入正确长度,该类型范围为0-400之间");
|
|
|
}
|
|
|
|
|
|
//设置默认长度
|
|
@@ -346,7 +361,39 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
int row1 = wbsTreeMapper.isThereAField(initTableName, eKey);
|
|
|
if (row1 > 0) {
|
|
|
try {
|
|
|
- baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
|
|
|
+ //1、查询当前表当前字段
|
|
|
+
|
|
|
+ //字段配置的长度
|
|
|
+ Integer filedLength = lengthMap.get(eKey);
|
|
|
+ if(filedLength == null){
|
|
|
+ throw new RuntimeException("字段不存在");
|
|
|
+ }
|
|
|
+ //获取当前字段数据的最长数据长度
|
|
|
+ Integer maxLength = baseMapper.selectFiledDataMaxLength(initTableName, eKey);
|
|
|
+ //初始长度
|
|
|
+ int initLength = 250;
|
|
|
+ //当前字段数据长度为null
|
|
|
+ if (maxLength == null) {
|
|
|
+ //设置初始长度
|
|
|
+ baseMapper.updateFiledType(initTableName, eKey, "varchar", initLength);
|
|
|
+ wbsFormElement.setELength(initLength);
|
|
|
+ baseMapper.updateById(wbsFormElement);
|
|
|
+ } else {
|
|
|
+ //动态扩容 每次根据最大数据长度扩容100
|
|
|
+ int newLength = maxLength + 100;
|
|
|
+ //如果字段的长度与扩容后的值一致则不去修改字段
|
|
|
+ if (filedLength == newLength) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //如果数据的最大长度 +100 都大于字段配置的长度 则重新设置字段的长度
|
|
|
+ if (filedLength >= newLength) {
|
|
|
+ baseMapper.updateFiledType(initTableName, eKey, "varchar", newLength);
|
|
|
+ wbsFormElement.setELength(newLength);
|
|
|
+ baseMapper.updateById(wbsFormElement);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
throw new RuntimeException("字段长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
|