|
@@ -62,6 +62,8 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
public static final Integer DEFAULT_ELEMENT_LENGTH_DATE = 50;
|
|
|
//实体表字段默认长度
|
|
|
private static final String ELEMENT_LENGTH_ENTITY = "200";
|
|
|
+ //数据库动态表总字段最大长度
|
|
|
+ private static final Integer MYSQL_MAX_COLUMN_LENGTH = 17453;
|
|
|
|
|
|
@Override
|
|
|
public IPage<WbsFormElementVO> selectWbsFormElementPage(IPage<WbsFormElementVO> page, WbsFormElementVO wbsFormElement) {
|
|
@@ -141,23 +143,29 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
|
|
|
@Override
|
|
|
public WbsFormElement saveAndSyn(WbsFormElement wbsFormElement, String tableName) {
|
|
|
- try {
|
|
|
|
|
|
- String isExitSql = "select * from information_schema.TABLES where TABLE_NAME='" + tableName + "'";
|
|
|
- List<Map<String, Object>> tabList = jdbcTemplate.queryForList(isExitSql);
|
|
|
- if (tabList.size() <= 0) {
|
|
|
- throw new ServiceException("未获取到对应的实体表名称initTableName");
|
|
|
- }
|
|
|
+ String isExitSql = "select * from information_schema.TABLES where TABLE_NAME='" + tableName + "'";
|
|
|
+ List<Map<String, Object>> tabList = jdbcTemplate.queryForList(isExitSql);
|
|
|
+ if (tabList.size() <= 0) {
|
|
|
+ throw new ServiceException("未获取到对应的实体表名称initTableName");
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- //获取实体表主库信息
|
|
|
- TableInfo tableInfo = tableInfoMapper.selectById(wbsFormElement.getFId());
|
|
|
- if (tableInfo == null) {
|
|
|
- throw new ServiceException("没有找到主库信息,确认fid是否正确");
|
|
|
- } else {
|
|
|
- tableName = tableInfo.getTabEnName();
|
|
|
- }
|
|
|
+ //获取实体表主库信息
|
|
|
+ TableInfo tableInfo = tableInfoMapper.selectById(wbsFormElement.getFId());
|
|
|
+ if (tableInfo == null) {
|
|
|
+ throw new ServiceException("没有找到主库信息,确认fid是否正确");
|
|
|
+ } else {
|
|
|
+ tableName = tableInfo.getTabEnName();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ //当前表总字段长度
|
|
|
+ int sumLength = baseMapper.selectSumColumnLength(jdbcTemplate.queryForObject("SELECT DATABASE()",String.class), tableName);
|
|
|
+ if (sumLength + wbsFormElement.getELength() > MYSQL_MAX_COLUMN_LENGTH) {
|
|
|
+ throw new ServiceException("无法添加字段,可用长度:" + (MYSQL_MAX_COLUMN_LENGTH - sumLength));
|
|
|
+ }
|
|
|
+ try {
|
|
|
// 删除 元素和实体表不匹配的字段
|
|
|
//baseMapper.deleteElementByfId2();
|
|
|
|
|
@@ -308,6 +316,18 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
//字段级字段长度缓存
|
|
|
Map<String, Integer> lengthMap = new HashMap<>();
|
|
|
|
|
|
+ //当前设置的字段总长度
|
|
|
+ Integer nowTotalLength = 0;
|
|
|
+ for (WbsFormElement wbsFormElement : wbsFormElementList) {
|
|
|
+ nowTotalLength += wbsFormElement.getELength();
|
|
|
+ }
|
|
|
+ //当前表总字段长度
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
//查询当前表的所有字段级字段长度
|
|
|
List<Map<String, Object>> filedLengths = baseMapper.selectFiledLength(initTableName);
|
|
|
for (Map<String, Object> filedLength : filedLengths) {
|
|
@@ -365,7 +385,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
|
|
|
//字段配置的长度
|
|
|
Integer filedLength = lengthMap.get(eKey);
|
|
|
- if(filedLength == null){
|
|
|
+ if (filedLength == null) {
|
|
|
throw new RuntimeException("字段不存在");
|
|
|
}
|
|
|
//获取当前字段数据的最长数据长度
|
|
@@ -965,4 +985,11 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改当前表所有字段的长度
|
|
|
+ * 1、字段数量超过80 表数据超过500条 把数据长度为0的旧字段长度改为50
|
|
|
+ * 超过:新字段的默认长度改为150,并且
|
|
|
+ */
|
|
|
+
|
|
|
}
|