Kaynağa Gözat

Merge branch 'lihb' of http://219.151.181.73:3000/zhuwei/bladex into test-merge

lvy 2 ay önce
ebeveyn
işleme
7fe197d28c

+ 1 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/dto/TrialFileSubmitDTO.java

@@ -1,6 +1,7 @@
 package org.springblade.business.dto;
 
 import io.swagger.annotations.ApiModelProperty;
+import io.swagger.models.auth.In;
 import lombok.Data;
 
 import java.io.Serializable;

+ 9 - 4
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -1895,11 +1895,16 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
 
                     //自检pdf
                     List<TrialSelfInspectionRecord> trialSelfInspectionRecords = baseMapper.selectList(Wrappers.<TrialSelfInspectionRecord>lambdaQuery()
-                            .select(TrialSelfInspectionRecord::getPdfUrl)
+                            .select(TrialSelfInspectionRecord::getPdfUrl,TrialSelfInspectionRecord::getContractId,TrialSelfInspectionRecord::getId,TrialSelfInspectionRecord::getType)
                             .in(TrialSelfInspectionRecord::getId, Func.toLongList(dto.getIds())));
-                    List<String> pdfURLs = trialSelfInspectionRecords.stream().map(TrialSelfInspectionRecord::getPdfUrl).collect(Collectors.toList());
-                    pdfList.addAll(pdfURLs);
-
+                    if(trialSelfInspectionRecords.size()>0){
+                        for (TrialSelfInspectionRecord record : trialSelfInspectionRecords) {
+                            String pdf = this.getMergePdfToTrialNew(record.getContractId(), record.getId(), record.getType());
+                            pdfList.add(pdf);
+                        }
+                    }
+//                    List<String> pdfURLs = trialSelfInspectionRecords.stream().map(TrialSelfInspectionRecord::getPdfUrl).collect(Collectors.toList());
+//                    pdfList.addAll(pdfURLs);
                     //------第三方、外委------
                 } else if (dto.getType().equals(2) || dto.getType().equals(3)) {
                     if (informationQuery.getPdfTrialUrl() != null) {

+ 7 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.java

@@ -77,4 +77,11 @@ public interface WbsFormElementMapper extends BaseMapper<WbsFormElement> {
      * @return
      */
     Integer selectFiledDataMaxLength(@Param("tableName") String initTableName,@Param("key") String eKey);
+
+    /**
+     * 统计当前表所有字段长度
+     * @param initTableName
+     * @return
+     */
+    int selectSumColumnLength(@Param("database") String database,@Param("tableName") String initTableName);
 }

+ 12 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.xml

@@ -167,10 +167,20 @@
         SELECT data_type FROM information_schema.columns WHERE table_name=#{initTableName} AND column_name = #{eKey}
     </select>
     <select id="selectFiledLength" resultType="java.util.Map">
-        select column_name `key`,character_octet_length length from INFORMATION_SCHEMA.COLUMNS  where table_name = #{initTableName}
+        select column_name `key`,character_maximum_length length from INFORMATION_SCHEMA.COLUMNS  where table_name = #{initTableName}
     </select>
     <select id="selectFiledDataMaxLength" resultType="java.lang.Integer">
-        select MAX(LENGTH(${key})) from ${tableName}
+        select IFNULL(MAX(CHAR_LENGTH(${key})),0) from ${tableName}
+    </select>
+    <select id="selectSumColumnLength" resultType="java.lang.Integer">
+        SELECT
+            SUM( CHARACTER_MAXIMUM_LENGTH )
+        FROM
+            information_schema.COLUMNS
+        WHERE
+            TABLE_SCHEMA = #{database}
+            AND TABLE_NAME = #{tableName}
+            AND DATA_TYPE = 'varchar'
     </select>
 
 </mapper>

+ 123 - 56
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsFormElementServiceImpl.java

@@ -62,6 +62,8 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     public static final Integer DEFAULT_ELEMENT_LENGTH_DATE = 100;
     //实体表字段默认长度
     private static final String ELEMENT_LENGTH_ENTITY = "200";
+    //数据库动态表总字段最大长度
+    private static final Integer MYSQL_MAX_COLUMN_LENGTH = 16328;
 
     @Override
     public IPage<WbsFormElementVO> selectWbsFormElementPage(IPage<WbsFormElementVO> page, WbsFormElementVO wbsFormElement) {
@@ -140,24 +142,32 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     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) {
+            updateTableFieldLength(tableName);
+            throw new ServiceException("无法添加字段,可用长度:" + (MYSQL_MAX_COLUMN_LENGTH - sumLength) + ",已自动调整其他字段长度,请重新添加");
+        }
+        try {
             // 删除 元素和实体表不匹配的字段
             //baseMapper.deleteElementByfId2();
 
@@ -193,6 +203,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                     throw new ServiceException("请输入正确的长度,范围为10-1000");
                 } else {
                     //新增
+                    wbsFormElement.setELength(DEFAULT_ELEMENT_LENGTH_VARCHAR);
                     baseMapper.insert(wbsFormElement);
 
                     //同步
@@ -209,6 +220,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                     throw new ServiceException("请输入正确的长度,范围为10-255");
                 } else {
                     //新增
+                    wbsFormElement.setELength(DEFAULT_ELEMENT_LENGTH_VARCHAR);
                     baseMapper.insert(wbsFormElement);
 
                     //同步
@@ -240,6 +252,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                     throw new ServiceException("请输入正确的长度,范围为0-100");
                 } else {
                     //新增
+                    wbsFormElement.setELength(DEFAULT_ELEMENT_LENGTH_VARCHAR);
                     baseMapper.insert(wbsFormElement);
 
                     //同步
@@ -305,19 +318,20 @@ 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());
+        //当前设置的字段总长度
+        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));
         }
 
+
         //修改实体表信息
         if (b) {
             String fId = "";
@@ -361,40 +375,9 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                 int row1 = wbsTreeMapper.isThereAField(initTableName, eKey);
                 if (row1 > 0) {
                     try {
-                        //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);
-                        }
+                        baseMapper.updateFiledType(initTableName, eKey, "varchar", eLength);
                     } catch (Exception e) {
+                        e.printStackTrace();
                         this.updateBatchById(beforeUpdateWbsFormElements);
                         throw new RuntimeException("字段长度范围超出总最大限制,请尝试缩小当前字段长度或其他字段长度");
                     }
@@ -965,4 +948,88 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         }
     }
 
+
+    /**
+     * 修改当前表所有字段的长度 (只用于字段缩减)
+     * 1、字段数量超过80 表数据超过500条 把数据长度为0的旧字段长度改为50
+     * 超过:新字段的默认长度改为150,并且
+     */
+    public void updateTableFieldLength(String tableName) {
+        TableInfo tableInfo = tableInfoMapper.selectOne(Wrappers.<TableInfo>lambdaQuery()
+                .eq(TableInfo::getTabEnName, tableName)
+                .last("limit 1"));
+
+        List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>lambdaQuery()
+                .eq(WbsFormElement::getFId, tableInfo.getId()));
+        //元素是否存在
+        if (CollectionUtil.isEmpty(wbsFormElements)) {
+            return;
+        }
+        //字段级字段长度缓存
+        Map<String, Integer> lengthMap = new HashMap<>();
+        //查询当前表的所有字段级字段长度
+        List<Map<String, Object>> filedLengths = baseMapper.selectFiledLength(tableName);
+        //表是否存在
+        if (CollectionUtil.isEmpty(filedLengths)) {
+            return;
+        }
+        for (Map<String, Object> filedLength : filedLengths) {
+            BigInteger length = (BigInteger) filedLength.get("length");
+            if (length == null) {
+                continue;
+            }
+            //记录字段与字段长度
+            lengthMap.put(filedLength.get("key").toString(), length.intValue());
+        }
+
+        //这张表是否拥有数据超过500条
+        Integer count = jdbcTemplate.queryForObject("select count(0) from " + tableName, Integer.class);
+
+
+        for (WbsFormElement wbsFormElement : wbsFormElements) {
+
+            String eKey = wbsFormElement.getEKey();
+            //字段不存在
+            if (lengthMap.get(eKey) == null) {
+                continue;
+            }
+            Integer dataLength = baseMapper.selectFiledDataMaxLength(tableName, eKey);
+
+            if (wbsFormElements.size() > 80 && count > 500) {
+                //数据长度
+                dataLength = dataLength == 0 ? 50 : lengthMap.get(eKey) + 100;
+                //如果当前需要设置的长度大于当前字段长度,则跳过
+                if (dataLength > wbsFormElement.getELength()) {
+                    continue;
+                }
+            } else if (wbsFormElements.size() > 80 && count < 500) {
+                //数据长度
+                dataLength = dataLength == 0 ? 100 : lengthMap.get(eKey) + 100;
+                //如果当前需要设置的长度大于当前字段长度,则跳过
+                if (dataLength > wbsFormElement.getELength()) {
+                    continue;
+                }
+            } else if (wbsFormElements.size() < 80 && count > 500) {
+                //数据长度
+                dataLength = dataLength == 0 ? 200 : lengthMap.get(eKey) + 100;
+                //如果当前需要设置的长度大于当前字段长度,则跳过
+                if (dataLength > wbsFormElement.getELength()) {
+                    continue;
+                }
+            } else {
+                //数据长度
+                dataLength = dataLength == 0 ? 200 : lengthMap.get(eKey) + 100;
+                //如果当前需要设置的长度大于当前字段长度,则跳过
+                if (dataLength > wbsFormElement.getELength()) {
+                    continue;
+                }
+                if (dataLength < 200) {
+                    dataLength = 200;
+                }
+            }
+            baseMapper.updateFiledType(tableName, eKey, "varchar", dataLength);
+            wbsFormElement.setELength(dataLength);
+            baseMapper.updateById(wbsFormElement);
+        }
+    }
 }

+ 15 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java

@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
 import org.apache.commons.lang.ObjectUtils;
 import org.springblade.business.entity.InformationQuery;
 import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.log.publisher.ErrorLogPublisher;
@@ -23,7 +24,11 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.rmi.ServerException;
 import java.util.*;
 import java.util.function.Function;
@@ -180,6 +185,7 @@ public class WbsSynchronousServiceImpl {
      * @param wbsTreeSynchronousRecord
      */
     public void insertPrivateNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) throws IOException {
+        String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
         String type = wbsTreeSynchronousRecord.getType();
@@ -403,6 +409,15 @@ public class WbsSynchronousServiceImpl {
                                 String[] split = templateNode.getHtmlUrl().split("/");
                                 String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
                                 File file_in = ResourceUtil.getFile(templateNode.getHtmlUrl());
+                                InputStream fileInputStream;
+                                if (!file_in.exists()) {
+                                    String path = sys_file_net_url + templateNode.getHtmlUrl().replaceAll("//", "/").replaceAll(file_path, "");
+                                    fileInputStream = CommonUtil.getOSSInputStream(path);
+
+                                    file_in.createNewFile();
+                                    Files.copy(fileInputStream, file_in.toPath(), StandardCopyOption.REPLACE_EXISTING);
+                                }
+
                                 if (!file_in.exists() || file_in.length() == 0) {
                                     //如果本地服务器上没有
                                     throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");

+ 3 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/WbsElementUtil.java

@@ -62,7 +62,7 @@ public class WbsElementUtil {
                 case 5:  //数值
                 case 3:  //小数
                 case 4:  //日期
-                    return "50";
+                    return "100";
                 default:
                     return "0";
             }
@@ -79,7 +79,7 @@ public class WbsElementUtil {
                 case "bigint":
                 case "decimal":
                 case "datetime":
-                    return 50;
+                    return 100;
                 default:
                     return 0;
             }
@@ -99,7 +99,7 @@ public class WbsElementUtil {
                 case "数值":
                 case "小数":
                 case "日期":
-                    return 50;
+                    return 100;
                 default:
                     return 0;
             }