|
@@ -310,25 +310,10 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
//修改之前的值
|
|
|
String fId1 = wbsFormElementList.get(0).getFId();
|
|
|
List<WbsFormElement> beforeUpdateWbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda().eq(WbsFormElement::getFId, fId1));
|
|
|
+ Map<Long, Integer> eLengthMap = beforeUpdateWbsFormElements.stream().collect(Collectors.toMap(WbsFormElement::getId, WbsFormElement::getELength, (v1, v2) -> v1 > v2 ? v1 : v2));
|
|
|
//修改元素基础信息
|
|
|
wbsFormElementList.forEach(obj -> obj.setStatus(1));
|
|
|
boolean b = this.updateBatchById(wbsFormElementList);
|
|
|
-
|
|
|
-
|
|
|
- //当前设置的字段总长度
|
|
|
- Integer nowTotalLength = 0;
|
|
|
- for (WbsFormElement wbsFormElement : wbsFormElementList) {
|
|
|
- // + 10 预留字段长度,用来保存在excel中的位置信息,比如:xx_^_12_12, 不适合一个字段存储多个位置
|
|
|
- nowTotalLength += wbsFormElement.getELength() + 10;
|
|
|
- }
|
|
|
- //当前表总字段长度
|
|
|
- int sumLength = baseMapper.selectSumColumnLength(jdbcTemplate.queryForObject("SELECT DATABASE()", String.class), initTableName);
|
|
|
- if (nowTotalLength > MYSQL_MAX_COLUMN_LENGTH) {
|
|
|
- //修改元素字段长度
|
|
|
- throw new ServiceException("无法添加字段,可用长度:" + (MYSQL_MAX_COLUMN_LENGTH - sumLength));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
//修改实体表信息
|
|
|
if (b) {
|
|
|
String fId = "";
|
|
@@ -367,21 +352,18 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
// } else if (eLength >= 0 && eLength <= 65) {
|
|
|
// eLength = DEFAULT_ELEMENT_LENGTH_NUMBER;
|
|
|
// }
|
|
|
-
|
|
|
- //判断是否存在该Key字段
|
|
|
- int row1 = wbsTreeMapper.isThereAField(initTableName, eKey);
|
|
|
- if (row1 > 0) {
|
|
|
- try {
|
|
|
- // + 10 预留字段长度,用来保存在excel中的位置信息,比如:xx_^_12_12, 不适合一个字段存储多个位置
|
|
|
- baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength + 10);
|
|
|
- } catch (Exception e) {
|
|
|
- // 数据库字段长度大于修改长度,则忽略
|
|
|
- if (e.getMessage().contains("Data truncated for column '" + eKey + "' at row 1")) {
|
|
|
- continue;
|
|
|
+ Integer length = eLengthMap.get(wbsFormElement.getId());
|
|
|
+ if (length == null || !length.equals(eLength)) {
|
|
|
+ //判断是否存在该Key字段
|
|
|
+ int row1 = wbsTreeMapper.isThereAField(initTableName, eKey);
|
|
|
+ if (row1 > 0) {
|
|
|
+ try {
|
|
|
+ baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
+ return R.fail(eName + "长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
|
|
|
}
|
|
|
- e.printStackTrace();
|
|
|
- this.updateBatchById(beforeUpdateWbsFormElements);
|
|
|
- throw new RuntimeException("字段长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
|
|
|
}
|
|
|
}
|
|
|
}
|