Browse Source

质检设计值实体表保存修改

lvy 1 month ago
parent
commit
4326381cbf

+ 49 - 19
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -65,6 +65,7 @@ import org.springblade.manager.mapper.*;
 import org.springblade.manager.service.INodeBaseInfoService;
 import org.springblade.manager.service.ITableFileService;
 import org.springblade.manager.service.IWbsTreeContractService;
+import org.springblade.manager.util.DataStructureFormatUtils;
 import org.springblade.manager.utils.CompositeKey;
 import org.springblade.manager.vo.*;
 import org.springblade.system.cache.ParamCache;
@@ -894,32 +895,32 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                     break;
                 }
             }
-
-            if (DataMap != null && DataMap.size() >= 1) {
-                String dataCol = "";
+            String dataCol = "";
+            for (int j = 0; j < dataSize; j++) {
+                if (j == dataSize - 1) {
+                    dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j];
+                } else {
+                    dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j] + "☆";
+                }
+            }
+            boolean flag = isSaveKey201(info, wbsInfo, dataCol);
+            if (!DataMap.isEmpty()) {
                 String updateSql = "update " + wbsInfo.getInitTableName() + " set " + info.getKey() + "=";
-                for (int j = 0; j < dataSize; j++) {
-                    if (j == dataSize - 1) {
-                        dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j];
-                    } else {
-                        dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j] + "☆";
-                    }
+                if (flag) {
+                    updateSql = "update " + wbsInfo.getInitTableName() + " set key_201 = concat(key_201,'$$'," + "'" + info.getKey() + ":" + dataCol + "') where p_key_id= " + wbsTreeContract.getPKeyId() + ";";
+                } else {
+                    updateSql = updateSql + "'" + dataCol + "' where p_key_id=" + wbsTreeContract.getPKeyId() + " ;";
                 }
-                updateSql = updateSql + "'" + dataCol + "' where p_key_id=" + wbsTreeContract.getPKeyId() + " ;";
                 moreData = moreData.stream().skip(excLenght.length).map(com.mixsmart.utils.StringUtils::handleNull).collect(Collectors.toList());
                 addSql.append(updateSql);
             } else {
                 long dataId = SnowFlakeUtil.getId();
                 String insertSql = "insert into " + wbsInfo.getInitTableName() + "(id,p_key_id," + info.getKey() + ") VALUES (" + dataId + "," + wbsTreeContract.getPKeyId() + ",'";
-                String dataCol = "";
-                for (int j = 0; j < dataSize; j++) {
-                    if (j == dataSize - 1) {
-                        dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j];
-                    } else {
-                        dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j] + "☆";
-                    }
+                if (flag) {
+                    insertSql = "insert into " + wbsInfo.getInitTableName() + "(id,p_key_id,key_201) values (" + dataId + "," + wbsTreeContract.getPKeyId() + ",'" + info.getKey() + ":" + dataCol + "');";
+                } else {
+                    insertSql = insertSql + dataCol + "');";
                 }
-                insertSql = insertSql + dataCol + "');";
                 moreData = moreData.stream().skip(excLenght.length).map(com.mixsmart.utils.StringUtils::handleNull).collect(Collectors.toList());
                 addSql.append(insertSql);
             }
@@ -984,7 +985,11 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         dataCol = dataCol + moreData.get(j) + "_^_" + excLenght[j] + "☆";
                     }
                 }
-                insertSql = insertSql + dataCol + "');";
+                if (isSaveKey201(info, wbsInfo, dataCol)) {
+                    insertSql = "insert into " + wbsInfo.getInitTableName() + "(id,p_key_id,key_201) values (" + dataId + "," + wbsTreeContract.getPKeyId() + ",'" + info.getKey() + ":" + dataCol + "');";
+                } else {
+                    insertSql = insertSql + dataCol + "');";
+                }
                 moreData = moreData.stream().skip(excLenght.length).map(com.mixsmart.utils.StringUtils::handleNull).collect(Collectors.toList());
                 addSql.append(insertSql);
             }
@@ -1003,6 +1008,31 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         return false;
     }
 
+    private boolean isSaveKey201(RangeInfo info, WbsTreeContract wbsInfo, String dataCol) {
+        boolean flag = false;
+        try {
+            String[] split = info.getKey().split("_");
+            flag = split.length > 1 && StringUtil.isNumeric(split[1]) && Integer.parseInt(split[1]) > 80;
+            if (!flag) {
+                List<Map<String, Object>> fieldMap = jdbcTemplate.queryForList("select distinct COLUMN_NAME as fieldName, CHARACTER_MAXIMUM_LENGTH as fieldLength from information_schema.COLUMNS where  TABLE_NAME = '" + wbsInfo.getInitTableName() +
+                        "' and COLUMN_NAME in ('" + info.getKey() + "', 'key_201" + "')");
+                if (!fieldMap.isEmpty()) {
+                    Map<String, Object> map1 = fieldMap.stream().filter(map -> map.get("fieldName") != null).collect(Collectors.toMap(map -> map.get("fieldName") + "", map -> map.get("fieldLength")));
+                    Object length = map1.get(info.getKey());
+                    if (length != null && Integer.parseInt(length.toString()) > dataCol.length()) {
+                        flag = true;
+                        if (map1.get("key_201") == null) {
+                            jdbcTemplate.execute("alter table " + wbsInfo.getInitTableName() + " add column key_201 text ");
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return flag;
+    }
+
     @Override
     public void syncCurrentFormToAllContract(WbsTreePrivate wbsTreePrivate) {
         baseMapper.syncCurrentFormToAllContract(wbsTreePrivate);