Browse Source

day_11.20

andy 1 year ago
parent
commit
d06cb38da0

+ 19 - 34
pom.xml

@@ -5,7 +5,7 @@
 	<parent>
 		<groupId>org.springframework.boot</groupId>
 		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>3.1.4</version>
+		<version>3.1.5</version>
 		<relativePath/> <!-- lookup parent from repository -->
 	</parent>
 	<groupId>com.scbfkj</groupId>
@@ -15,18 +15,9 @@
 	<description>uni</description>
 	<properties>
 		<java.version>17</java.version>
-		<graalvm.version>23.1.1</graalvm.version>
+		<graalvm.version>23.0.1</graalvm.version>
 	</properties>
 	<dependencies>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-actuator</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-web</artifactId>
-		</dependency>
-
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-devtools</artifactId>
@@ -64,7 +55,7 @@
 		<dependency>
 			<groupId>com.rabbitmq</groupId>
 			<artifactId>amqp-client</artifactId>
-			<version>5.16.0</version>
+			<version>5.18.0</version>
 		</dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
@@ -75,29 +66,10 @@
 			<artifactId>commons-net</artifactId>
 			<version>3.9.0</version>
 		</dependency>
-		<!--
-        The polyglot dependency is always required for Java embeddings.
-        It contains the polyglot embedding APIs to include any polyglot language. -->
-		<dependency>
-			<groupId>org.graalvm.polyglot</groupId>
-			<artifactId>polyglot</artifactId>
-			<version>${graalvm.version}</version>
-		</dependency>
-		<!--
-        Choose here which languages should be used.
-        Available languages in the polyglot group are:
-            js, ruby, python, wasm, llvm, llvm-native, java
-
-        Switch to community licenses by adding a `-community` suffix to the artefact id (e.g. `js-communtiy`).
-        Switch to native isolate versions of languages by adding a `-isolate` suffix. (`js-isolate`).
-
-        Any dependency in the org.graalvm.polyglot group is intended for use by polyglot embeddings.
-        -->
 		<dependency>
-			<groupId>org.graalvm.polyglot</groupId>
+			<groupId>org.graalvm.js</groupId>
 			<artifactId>js</artifactId>
 			<version>${graalvm.version}</version>
-			<type>pom</type>
 		</dependency>
 		<dependency>
 			<groupId>com.zaxxer</groupId>
@@ -120,6 +92,11 @@
 			<groupId>com.jayway.jsonpath</groupId>
 			<artifactId>json-path</artifactId>
 		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
@@ -127,12 +104,20 @@
 		<dependency>
 			<groupId>com.google.guava</groupId>
 			<artifactId>guava</artifactId>
-			<version>31.1-jre</version>
+			<version>32.0.0-jre</version>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.activemq</groupId>
 			<artifactId>activemq-client</artifactId>
-			<version>5.18.2</version>
+			<version>5.18.3</version>
+		</dependency>
+		<dependency>
+			<groupId>org.flywaydb</groupId>
+			<artifactId>flyway-core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.flywaydb</groupId>
+			<artifactId>flyway-mysql</artifactId>
 		</dependency>
 
 	</dependencies>

+ 14 - 10
src/main/java/com/scbfkj/uni/api/LogAop.java

@@ -31,7 +31,7 @@ import java.util.stream.Stream;
 @Aspect
 public class LogAop {
 
-    private static final Logger logger= LoggerFactory.getLogger(LogAop.class);
+    private static final Logger logger = LoggerFactory.getLogger(LogAop.class);
 
 
     @Resource
@@ -62,12 +62,12 @@ public class LogAop {
         String message = null;
 
 
-        if(Config.debug){
-            logger.info("请求参数:{}",DataFormatUtil.toString(args));
-            logger.info("请求路径:{}",uri);
-            logger.info("请求session:{}",RequestUtil.getSessionId());
-            logger.info("请求ip:{}",RequestUtil.getIpAddr());
-            logger.info("请求appToken:{}",RequestUtil.getAppToken());
+        if (Config.debug) {
+            logger.info("请求参数:{}", DataFormatUtil.toString(args));
+            logger.info("请求路径:{}", uri);
+            logger.info("请求session:{}", RequestUtil.getSessionId());
+            logger.info("请求ip:{}", RequestUtil.getIpAddr());
+            logger.info("请求appToken:{}", RequestUtil.getAppToken());
         }
 
         try {
@@ -158,8 +158,8 @@ public class LogAop {
             }
             returnData = joinPoint.proceed(args);
 
-            if(Config.debug){
-                logger.info("返回值:{}",DataFormatUtil.toString(returnData));
+            if (Config.debug) {
+                logger.info("返回值:{}", DataFormatUtil.toString(returnData));
             }
             return ((ResponseEntity<Map<String, Object>>) returnData);
         } catch (Throwable e) {
@@ -180,7 +180,11 @@ public class LogAop {
                 try {
                     put("applicationid", RequestUtil.getAppId());
                 } catch (Exception e) {
-                    System.out.println(UniReturnUtil.getMessage(e));
+                    if (Config.debug) {
+                        e.printStackTrace();
+                    } else {
+                        System.out.println(UniReturnUtil.getMessage(e));
+                    }
                 }
             }});
         }

+ 10 - 11
src/main/java/com/scbfkj/uni/process/DataBase.java

@@ -24,10 +24,11 @@ public class DataBase {
 //        缓存数据 connectionStr + sql
 
         String key = "%s;%s;%s".formatted(connectionStr, sql, DataFormatUtil.toString(argsList));
+        String effectivedurationColumnName = "effectiveduration";
         if (cacheDatas.containsKey(key)) {
             Map<String, Object> cacheData = cacheDatas.get(key);
 
-            Object effectiveduration = cacheData.get("effectiveduration");
+            Object effectiveduration = cacheData.get(effectivedurationColumnName);
             if (Objects.isNull(effectiveduration) || ((LocalDateTime) effectiveduration).isBefore(LocalDateTime.now())) {
                 cacheDatas.remove(key);
             } else {
@@ -56,10 +57,10 @@ public class DataBase {
             cacheConfigList = query(Config.centerConnectionStr, querySql, Collections.singletonList(new Object[]{1}));
         }
         cacheConfigList.stream().filter(it -> Objects.equals(it.get("querysql"), sql) && Objects.equals(it.get("connectset"), connectionStr)).findFirst().ifPresent(it -> {
-            Object o = it.get("effectiveduration");
+            Object o = it.get(effectivedurationColumnName);
             LocalDateTime localDateTime = LocalDateTime.now().plusSeconds(Long.parseLong(o.toString()));
             cacheDatas.put(key, new HashMap<>() {{
-                put("effectiveduration", localDateTime);
+                put(effectivedurationColumnName, localDateTime);
                 put("data", result);
             }});
         });
@@ -128,13 +129,14 @@ public class DataBase {
         String filterLineWhereStr = null;
         for (Object f : filterLines) {
             Map<String, Object> it = ((Map<String, Object>) f);
+            Object comparator = it.get("comparator");
             filterLineWhereStr = " %s %s %s %s %s %s %s %s ".formatted(
                     filterLineWhereStr,
                     it.getOrDefault("left", ""),
                     it.get("column"),
-                    it.get("comparator"),
-                    Objects.equals(it.get("comparator"), " is null ") ? "" : "?",
-                    !Objects.equals(it.get("comparator"), " is null ") ? " " : it.get("value"),
+                    comparator,
+                    Objects.equals(comparator, " is null ") ? "" : "?",
+                    !Objects.equals(comparator, " is null ") ? " " : it.get("value"),
                     it.getOrDefault("right", ""),
                     it.getOrDefault("connector", "")
             );
@@ -183,7 +185,7 @@ public class DataBase {
     }
 
 
-    private static HikariPool getDataSourcePool(String connectionStr) throws Exception {
+    public static HikariPool getDataSourcePool(String connectionStr) throws Exception {
         if (dataSourcePools.containsKey(connectionStr)) {
             return dataSourcePools.get(connectionStr);
         }
@@ -194,10 +196,7 @@ public class DataBase {
         JsonNode password = jsonNode.get("password");
         JsonNode driverClassName = jsonNode.get("driverClassName");
         HikariPool dataSourcePool = createDataSourcePool(jdbcUrl.asText(), Objects.isNull(username) ? null : username.asText(), Objects.isNull(password) ? null : password.asText(), Objects.isNull(driverClassName) ? null : driverClassName.asText(), connectionStr);
-        JsonNode enableCache = jsonNode.get("enableCache");
-        if (Objects.isNull(enableCache) || enableCache.asBoolean()) {
-            dataSourcePools.put(connectionStr, dataSourcePool);
-        }
+        dataSourcePools.put(connectionStr, dataSourcePool);
         return dataSourcePool;
     }
 

+ 151 - 0
src/main/java/com/scbfkj/uni/process/Web.java

@@ -1,4 +1,155 @@
 package com.scbfkj.uni.process;
 
+import com.scbfkj.uni.library.DataFormatUtil;
+import com.scbfkj.uni.library.UniReturnUtil;
+import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
+import org.apache.commons.pool2.KeyedObjectPool;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestTemplate;
+
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
 public class Web {
+
+    private KeyedObjectPool<String, Web> webPool = new GenericKeyedObjectPool<>(new BaseKeyedPooledObjectFactory<String, Web>() {
+        @Override
+        public Web create(String s) throws Exception {
+            return new Web();
+        }
+
+        @Override
+        public PooledObject<Web> wrap(Web web) {
+            return new DefaultPooledObject<>(web);
+        }
+    });
+
+
+    private RestTemplate restTemplate; //webapi请求对象
+
+
+    private String webapiURL;
+
+    private HttpHeaders webApiHeader;
+    private String webapiMethod;
+
+    private Map<String, Object> baseHeader = new HashMap<>();
+
+    /**
+     * webapi 执行入口函数
+     */
+    public Map<String, Object> exec(Object header, String method, Object defaultBody, String connectConfig) throws Exception {
+        Web web = null;
+        try {
+            web = webPool.borrowObject(connectConfig);
+            return web.execWebApi(header, method, defaultBody, connectConfig);
+
+        } finally {
+            if (web != null) {
+                webPool.returnObject(connectConfig, web);
+            }
+        }
+    }
+    public Map<String, Object> execWebApi(Object header, String method, Object defaultBody, String connectConfig) {
+        Map<String, Object> connectConfigMaps = (Map<String, Object>) DataFormatUtil.toMap(connectConfig);
+        Map<String, Object> restTemplateResult = initWebApiParams(connectConfigMaps); // 通过连接配置 获取restTemplate
+
+        if (!"0".equals(restTemplateResult.get("code"))) {
+            return UniReturnUtil.fail(restTemplateResult.get("message").toString());
+        }
+        if (header instanceof Map) {
+            Map<String, Object> temeMap = (Map) header;
+            if (!temeMap.isEmpty()) {
+                temeMap.putAll(baseHeader);
+                webApiHeader.clear();
+                for (String key : temeMap.keySet()) {
+                    webApiHeader.add(key, temeMap.get(key).toString());
+                }
+            }
+        }
+        if (StringUtils.hasLength(method)) webapiMethod = method.toLowerCase();
+        try {
+            List<Map<String, Object>> returnList = new ArrayList<>();
+            if (defaultBody instanceof List<?> tempList) {
+                for (Object o : tempList) {
+                    returnList.add(sendWebApiRequest(o));
+                }
+            } else {
+                returnList.add(sendWebApiRequest(defaultBody));
+            }
+            return (defaultBody instanceof List<?>) ? UniReturnUtil.success(returnList) : returnList.get(0);
+        } catch (Exception e) {
+            return UniReturnUtil.fail("restTemplate执行异常" + UniReturnUtil.getMessage(e));
+        }
+    }
+
+    private Map<String, Object> sendWebApiRequest(Object defaultBody) {
+        try {
+            HttpEntity<Object> request = new HttpEntity<>(defaultBody, webApiHeader);
+            String responseEntity = null;
+            switch (webapiMethod) {
+                case "get" -> responseEntity = restTemplate.getForObject(webapiURL, String.class, request);
+                case "put" -> restTemplate.put(webapiURL, request);
+                case "delete" -> restTemplate.delete(webapiURL, request);
+                default -> responseEntity = restTemplate.postForObject(webapiURL, request, String.class);
+            }
+            if (responseEntity == null && (webapiMethod.equals("put") || webapiMethod.equals("delete"))) {
+                return UniReturnUtil.success(null);
+            }
+            if (Objects.nonNull(responseEntity)) {
+                return UniReturnUtil.success(responseEntity);
+            } else {
+                return UniReturnUtil.fail("webapi发送请求失败 : " + responseEntity);
+            }
+        } catch (Exception e) {
+            return UniReturnUtil.fail("发送请求失败 : ".concat(UniReturnUtil.getMessage(e)));
+        }
+    }
+
+    private Map<String, Object> initWebApiParams(Map<String, Object> connectConfig) {
+        try {
+            String configStr = DataFormatUtil.toString(connectConfig);
+
+            if (restTemplate == null) {
+                if (Objects.isNull(connectConfig)) {
+                    return UniReturnUtil.fail("webapi请求配置参数为空");
+                }
+                webapiURL = Objects.nonNull(connectConfig.get("url")) ? connectConfig.get("url").toString() : null;
+                if (Objects.isNull(webapiURL)) {
+                    return UniReturnUtil.fail("webapi请求地址为空");
+                }
+                Object tempHeaders = connectConfig.get("headers"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+                webApiHeader = new HttpHeaders();
+                if (Objects.isNull(tempHeaders)) {
+                    webApiHeader.setContentType(MediaType.APPLICATION_JSON);
+                }
+                if (tempHeaders instanceof Map) {
+                    baseHeader = (Map) tempHeaders;
+                    if (!baseHeader.isEmpty()) {
+                        for (String key : baseHeader.keySet()) {
+                            webApiHeader.add(key, baseHeader.get(key).toString());
+                        }
+                    }
+                }
+                Object webMethod = connectConfig.get("method"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+                if (Objects.nonNull(webMethod)) {
+                    webapiMethod = webMethod.toString().toLowerCase();
+                } else {
+                    webapiMethod = "post";
+                }
+                restTemplate = new RestTemplate();
+                restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
+            }
+        } catch (Exception e) {
+            return UniReturnUtil.fail(UniReturnUtil.getMessage(e));
+        }
+        return UniReturnUtil.success(null);
+    }
 }

+ 28 - 1
src/main/java/com/scbfkj/uni/service/LoggerService.java

@@ -118,7 +118,21 @@ public class LoggerService {
                             errorFileNames.add(matcher.group());
                         }
                         return Stream.empty();
+                    } finally {
+
+                        HikariPool hikariPool = DataBase.dataSourcePools.remove(connectionStr);
+                        if (Objects.nonNull(hikariPool)) {
+                            try {
+                                hikariPool.shutdown();
+                            } catch (InterruptedException e) {
+                                if (Config.debug) {
+                                    e.printStackTrace();
+                                }
+                            }
+                        }
                     }
+
+
                 })
 //                分组
                 .collect(Collectors.groupingBy((log) -> log.get("target").toString()))
@@ -177,20 +191,33 @@ public class LoggerService {
                 errorFileNames.stream().filter(Objects::nonNull).noneMatch(errorFileName ->
                         errorFileName.contains(f.getName()))
         ).forEach(f -> {
+            String connectionStr = connection.formatted(dir + f.getName());
             try {
-                String connectionStr = connection.formatted(dir + f.getName());
                 DataBase.exec(connectionStr, "delete  from logs");
                 HikariPool hikariPool = DataBase.dataSourcePools.remove(connectionStr);
                 if (Objects.nonNull(hikariPool))
                     hikariPool.shutdown();
 //                删除文件一直不成功 怀疑是数据库连接导致文件被使用导致一直删除不成功
                 f.delete();
+                fileNames.remove(Long.parseLong(f.getName().substring(0,f.getName().indexOf(".sqlite"))));
             } catch (Exception e) {
                 if (Config.debug) {
                     e.printStackTrace();
                 } else {
                     System.out.println(UniReturnUtil.getMessage(e));
                 }
+            } finally {
+
+                HikariPool hikariPool = DataBase.dataSourcePools.remove(connectionStr);
+                if (Objects.nonNull(hikariPool)) {
+                    try {
+                        hikariPool.shutdown();
+                    } catch (InterruptedException e) {
+                        if (Config.debug) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
             }
         });
     }

+ 44 - 24
src/main/java/com/scbfkj/uni/service/SecurityService.java

@@ -12,6 +12,7 @@ import org.springframework.web.context.request.RequestContextHolder;
 import java.security.SecureRandom;
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.regex.Pattern;
 
 import static com.scbfkj.uni.library.DataAliasGetUtil.getValue;
 import static org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST;
@@ -275,17 +276,17 @@ public class SecurityService {
         } else {
             Object multilogin = application.get("multilogin");
             if (Objects.equals(DataFormatUtil.toString(multilogin), "1")) {
-                Optional<Map<String, Object>> log = userLoginLogList.stream().filter(it -> it.get("sessionid").equals(sessionId) ).findAny();
+                Optional<Map<String, Object>> log = userLoginLogList.stream().filter(it -> it.get("sessionid").equals(sessionId)).findAny();
                 if (log.isEmpty()) {
                     DataBase.updateBatch(Config.securityConnectionStr, insert, new ArrayList<>() {{
                         add(new Object[]{userId, ip, sessionId, LocalDateTime.now(), null, LocalDateTime.now(), LocalDateTime.now(), appToken, appId});
                     }});
-                }else{
+                } else {
                     Map<String, Object> map = log.get();
-                    if(Objects.isNull(map.get("apptoken"))){
+                    if (Objects.isNull(map.get("apptoken"))) {
 
                         DataBase.updateBatch(Config.securityConnectionStr, "update  userloginlog set apptoken = ? where loginid = ?", new ArrayList<>() {{
-                            add(new Object[]{appToken,map.get("loginid")});
+                            add(new Object[]{appToken, map.get("loginid")});
                         }});
                     }
                 }
@@ -343,7 +344,6 @@ public class SecurityService {
         data.put("usertoken", userToken);
 
         return UniReturnUtil.success(data);
-
     }
 
     public Map<String, Object> checkUserToken(String userToken) throws Exception {
@@ -394,8 +394,6 @@ public class SecurityService {
         DataBase.updateBatch(Config.securityConnectionStr, delete, new ArrayList<>() {{
             add(new Object[]{userIdObj});
         }});
-
-
         return UniReturnUtil.success("成功");
     }
 
@@ -403,24 +401,46 @@ public class SecurityService {
     //获取用户权限
 
     public Map<String, Object> permission() throws Exception {
-
         String userId = RequestUtil.getUserId();
-        String query = """
-                                select userpermissionsid,
-                       t1.userid,
-                       t3.*,
-                       t1.serviceid,
-                       insetcolumnlist,
-                       updatecolumnlist,
-                       selectcolumnlist,
-                       filterset
-                from pageconfiguration t3,
-                     userpermissions t1
-                where t3.pageconfigurationid = t1.pageconfigurationid
-                  and t1.userid = ?""";
-        List<Map<String, Object>> permission = DataBase.query(Config.securityConnectionStr, query, new ArrayList<>() {{
-            add(new Object[]{userId});
-        }});
+        Map<String, Object> userInfo = RequestUtil.getUserInfo();
+        Object usergroupid = userInfo.get("usergroupid");
+        List<Map<String, Object>> permission;
+        if (Objects.equals("0", usergroupid)) {
+            String query = """
+                    select
+                           null as userpermissionsid,
+                           null as userid,
+                           t.*,
+                           null as serviceid,
+                           null as insetcolumnlist,
+                           null as updatecolumnlist,
+                           null as selectcolumnlist,
+                           null as filterset
+                    from
+                        pageconfiguration t
+                    where 1 = ?""";
+            permission = DataBase.query(Config.securityConnectionStr, query, new ArrayList<>() {{
+                add(new Object[]{1});
+            }});
+        } else {
+            String query = """
+                                    select userpermissionsid,
+                           t1.userid,
+                           t3.*,
+                           t1.serviceid,
+                           insetcolumnlist,
+                           updatecolumnlist,
+                           selectcolumnlist,
+                           filterset
+                    from pageconfiguration t3,
+                         userpermissions t1
+                    where t3.pageconfigurationid = t1.pageconfigurationid
+                      and t1.userid = ?""";
+
+            permission = DataBase.query(Config.securityConnectionStr, query, new ArrayList<>() {{
+                add(new Object[]{userId});
+            }});
+        }
         return UniReturnUtil.success(permission);
     }
 

+ 25 - 11
src/main/java/com/scbfkj/uni/system/SystemInit.java

@@ -5,17 +5,20 @@ import com.scbfkj.uni.process.DataBase;
 import com.scbfkj.uni.service.ControlService;
 import com.scbfkj.uni.service.LoggerService;
 import jakarta.annotation.PostConstruct;
-import org.apache.kafka.common.utils.ByteBufferInputStream;
+import org.flywaydb.core.Flyway;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 import org.springframework.util.ResourceUtils;
 
-import java.io.*;
-import java.nio.ByteBuffer;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.net.URL;
 import java.time.LocalDateTime;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Objects;
 import java.util.Scanner;
 
 
@@ -45,6 +48,7 @@ public class SystemInit {
         Config.debug = debug;
         Config.centerConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(centerConfig);
         Config.securityConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(securityConfig);
+        migrateDB();
 
 //        日志配置初始化
         Config.targets.addAll(DataBase.query(Config.centerConnectionStr, "select * from systeminfo where 1=?", Collections.singletonList(new Object[]{1})));
@@ -57,8 +61,6 @@ public class SystemInit {
         LoggerService.log(LoggerService.LogType.SYSTEM, new HashMap<>() {{
             put("occurrencetime", LocalDateTime.now());
         }});
-
-
     }
 
     private void initializeSystemEnvironment() throws Exception {
@@ -107,7 +109,8 @@ public class SystemInit {
      * 清理远程数据配置
      */
     private void cleanRemoteConfig() throws Exception {
-        File file = ResourceUtils.getFile("classpath:sql");
+        URL url = ResourceUtils.getURL("classpath:sql");
+        File file = new File(url.getPath());
         removeRemoteData();
         if (file.exists()) {
             if (!file.isFile()) {
@@ -132,16 +135,27 @@ public class SystemInit {
 
     public static String readFileToString(File file) {
         StringBuilder content = new StringBuilder();
-        try {
-            Scanner scanner = new Scanner(file);
+        try (Scanner scanner = new Scanner(file)) {
             while (scanner.hasNextLine()) {
                 content.append(scanner.nextLine());
             }
-            scanner.close();
         } catch (FileNotFoundException e) {
-            e.printStackTrace();
+            if (Config.debug) {
+                e.printStackTrace();
+            }
         }
         return content.toString();
     }
 
+    /**
+     * 迁移数据,数据库管理
+     *
+     * @throws Exception
+     */
+    private void migrateDB() throws Exception {
+        Flyway systemSetFlyway = Flyway.configure().dataSource(DataBase.getDataSourcePool(Config.centerConnectionStr).getUnwrappedDataSource()).locations("db/systemset").baselineOnMigrate(true).load();
+        systemSetFlyway.migrate();
+        Flyway uniAuthFlyway = Flyway.configure().dataSource(DataBase.getDataSourcePool(Config.securityConnectionStr).getUnwrappedDataSource()).locations("db/uniauth").baselineOnMigrate(true).load();
+        uniAuthFlyway.migrate();
+    }
 }

+ 10 - 0
src/main/resources/db/systemset/V1_1__create_system_info_table.sql

@@ -0,0 +1,10 @@
+create table if not exists systeminfo
+(
+    systemid       int auto_increment
+        primary key,
+    keyname        tinytext null,
+    datasourceid   int      null,
+    expression     tinytext null,
+    systemdescribe tinytext null
+);
+

+ 16 - 0
src/main/resources/db/systemset/V1_2__create_service_info_table.sql

@@ -0,0 +1,16 @@
+create table if not exists  serviceinfo
+(
+    serviceid            int auto_increment comment '主键'
+        primary key,
+    servicename          tinytext null comment '名称',
+    servicetype          int      null comment '服务类型',
+    containercode        tinytext null comment '运行实例编号',
+    tasktype             int      null comment '定时类型',
+    cronexpress          tinytext null comment '定时器表达式',
+    urilist              tinytext null comment '对外暴露URI列表',
+    nullresultparameters tinytext null comment '空结果请求参数',
+    autonotification     tinytext null comment '成功后自动通知数据源配置(空代表无需通知,非空记录数据源编号)',
+    loopcount            int      null,
+    frequency            int      null comment '频率'
+);
+

+ 13 - 0
src/main/resources/db/systemset/V1_3__create_container_table.sql

@@ -0,0 +1,13 @@
+create table if not exists  container
+(
+    containerid       int auto_increment
+        primary key,
+    containercode     tinytext null,
+    containername     tinytext null,
+    containerdescribe tinytext null,
+    requesturi        tinytext null,
+    containervesion   tinytext null,
+    runstate          tinytext null,
+    lasttime          datetime null
+);
+

+ 8 - 0
src/main/resources/db/systemset/V1_4__create_datasource_table.sql

@@ -0,0 +1,8 @@
+create table if not exists  datasource
+(
+    datasourceid       int auto_increment
+        primary key,
+    datasourcedescribe tinytext null,
+    connectset         tinytext null,
+    datasourcetype     tinytext null
+);

+ 9 - 0
src/main/resources/db/systemset/V1_5__create_key_alias_table.sql

@@ -0,0 +1,9 @@
+create table if not exists  keyalias
+(
+    aliasid       int auto_increment
+        primary key,
+    keyname       tinytext null,
+    aliasname     tinytext null,
+    aliasdescribe tinytext null
+);
+

+ 12 - 0
src/main/resources/db/systemset/V1_6__create_data_cache_table.sql

@@ -0,0 +1,12 @@
+create table  if not exists datacache
+(
+    datacacheid       int auto_increment
+        primary key,
+    connectset        text null comment '连接字符串',
+    querysql          text null comment '查询语句',
+    querytable        text null comment '查询表名',
+    effectiveduration int  null comment '缓存时长(秒)',
+    datacachedescribe text null comment '描述'
+)
+comment '二级缓存配置';
+

+ 13 - 0
src/main/resources/db/systemset/V1_7__create_service_state_table.sql

@@ -0,0 +1,13 @@
+create table if not exists  servicestate
+(
+    servicestateid int auto_increment
+        primary key,
+    serviceid      int      null,
+    containerid    int      null,
+    containercode  tinytext null,
+    starttime      datetime null,
+    stoptime       datetime null,
+    runstate       tinytext null,
+    lasttime       datetime null
+);
+

+ 14 - 0
src/main/resources/db/systemset/V1_8__create_algorithm_library_table.sql

@@ -0,0 +1,14 @@
+create table  if not exists algorithmlibrary
+(
+    algorithmlibraryid  int auto_increment comment '算法编号'
+        primary key,
+    serviceid           int      null comment '服务编号',
+    algorithmtype       int      null comment '算法类型',
+    computingexpression tinytext null comment '计算表达式',
+    parameterset        tinytext null comment '参数列表',
+    preconditions       tinytext null comment '前置计算条件',
+    executionnumber     int      null comment '事件编号',
+    datasourceid        int      null comment '数据源编号',
+    preparameterset     tinytext null comment '前置条件参数'
+);
+

+ 8 - 0
src/main/resources/db/systemset/V1_9__create_service_type_table.sql

@@ -0,0 +1,8 @@
+create table if not exists servicetype
+(
+    servicetypeid       int auto_increment
+        primary key,
+    servicetypename     tinytext null,
+    servicetypedescribe text     null
+);
+

+ 0 - 223
src/main/resources/schema/V1__init.sql

@@ -1,223 +0,0 @@
-create table apiinfo
-(
-    apiid       int auto_increment comment '自增长主键'
-        primary key,
-    apiname     varchar(255) null comment 'api名称',
-    apitype     varchar(255) null comment '类型(外部api、内部方法、服务)',
-    requestpath varchar(255) null comment '请求路径',
-    routepath   varchar(255) null comment '转发路径(外部api完整路径、带类名的内部方法名、服务编号)'
-);
-
-create table appconnectlog
-(
-    connid      int auto_increment comment '自增主键'
-        primary key,
-    appid       varchar(16) null comment '应用编码',
-    requesttime datetime    null comment '连接时间',
-    requestip   varchar(32) null comment '请求ip',
-    apptoken    varchar(64) null comment 'app连接token',
-    expiretime  datetime    null comment 'token过期时间',
-    lasttime    datetime    null comment '最后活跃时间'
-);
-
-create table application
-(
-    applicationid         int auto_increment comment '自增主键'
-        primary key,
-    appid                 varchar(16)  null comment '应用编码',
-    appsecret             varchar(32)  null comment '应用密钥',
-    appname               varchar(64)  null comment '应用名称',
-    appengname            varchar(128) null comment '应用英文名称',
-    appdescribe           varchar(256) null comment '应用描述',
-    applogo               varchar(256) null comment '应用图标',
-    smalllogo             varchar(256) null comment '应用小图标',
-    backgroundimage       varchar(256) null comment '背景图',
-    apptokeneffective     int          null comment '应用令牌有效时长(分钟,从连接起)',
-    securitycoderule      varchar(128) null comment '验证码规则',
-    securitycodeeffective int          null comment '验证码有效时长(秒)',
-    multilogin            int          null comment '是否允许多机登录',
-    passwordrule          varchar(128) null comment '密码规则',
-    passwordeffective     int          null comment '密码过期时长'
-);
-
-create table applicationpermissions
-(
-    applicationpermissionsid int auto_increment comment '自增长主键应用api权限编号'
-        primary key,
-    appid                    int          null comment 'app编号',
-    apiid                    int          null comment 'api编号',
-    columnlist               varchar(200) null comment '列权限',
-    filterset                varchar(200) null comment '行权限'
-);
-
-create table breakerrule
-(
-    breakerruleid        int auto_increment comment '自增长主键熔断策略编号'
-        primary key,
-    breakerrulename      varchar(50)   null comment '策略名',
-    duration             int           null comment '单位时间(秒)',
-    limitvalue           int           null comment '流量上限',
-    averageerrorrate     decimal(5, 2) null comment '平均错误率',
-    errorcount           int           null comment '错误次数',
-    averageexecutiontime int           null comment '平均执行时长',
-    returnmessage        varchar(100)  null comment '超限熔断返回提示'
-);
-
-create table container
-(
-    containerid       int auto_increment comment '自增长主键容器编号'
-        primary key,
-    containercode     varchar(50)  null comment '运行实例编号',
-    containername     varchar(50)  null comment '名称',
-    containerdescribe varchar(200) null comment '用途说明',
-    requesturi        varchar(200) null comment '访问路径',
-    containervesion   varchar(50)  null comment '版本号',
-    runstate          varchar(20)  null comment '当前状态',
-    lasttime          datetime     null comment '最后活跃时间'
-);
-
-create table datasource
-(
-    datasourceid       int auto_increment comment '自增长主键'
-        primary key,
-    datasourcedescribe varchar(200) null comment '数据源说明',
-    connectset         varchar(200) null comment '连接字符串'
-);
-
-create table pageconfiguration
-(
-    pageconfigurationid int auto_increment comment '自增长主键界面配置编号'
-        primary key,
-    pagetype            varchar(50)  null comment '类型(模块、页面、按钮、表格)',
-    superiorid          int          null comment '页面配置上级编号',
-    pagename            varchar(50)  null comment '名称',
-    pagecode            varchar(50)  null comment '界面控件编码',
-    pagedescribe        varchar(200) null comment '描述',
-    serviceid           int          null comment '绑定服务编号'
-);
-
-create table ratelimitrule
-(
-    ratelimitingid   int auto_increment comment '自增长主键限流策略编号'
-        primary key,
-    ratelimitingname varchar(50)  null comment '策略名',
-    duration         int          null comment '单位时间(秒)',
-    limitvalue       int          null comment '流量上限',
-    returnmessage    varchar(100) null comment '超限保护返回提示',
-    apiid            varchar(100) null comment 'api编号'
-);
-
-create table servicestate
-(
-    servicestateid int auto_increment comment '自增长主键'
-        primary key,
-    serviceid      int         null comment '服务编号',
-    containerid    int         null comment '容器编号',
-    containercode  varchar(50) null comment '运行实例编号',
-    starttime      datetime    null comment '启动时间',
-    stoptime       datetime    null comment '停止时间',
-    runstate       varchar(20) null comment '当前状态',
-    lasttime       datetime    null comment '最后活跃时间'
-);
-
-create table tableconfiguration
-(
-    tableconfigurationid int auto_increment comment '自增长主键表格配置编号'
-        primary key,
-    pagecode             varchar(50)  null,
-    columnname           varchar(50)  null comment '列名',
-    columncode           varchar(50)  null comment '列标识',
-    groupname            varchar(50)  null comment '上级分组名称',
-    columndescribe       varchar(200) null comment '列描述',
-    datatype             varchar(50)  null comment '数据类型',
-    datalength           int          null comment '数据长度',
-    isdisplay            int          null comment '是否显示',
-    displaynumber        int          null comment '显示顺序',
-    displaywidth         int          null comment '显示宽度',
-    enablesort           int          null comment '启用排序',
-    enablefilter         int          null comment '启用过滤',
-    enablegroup          int          null comment '启用分组',
-    enablecount          int          null comment '启用计算',
-    isfiltercolumn       int          null comment '是否为过滤列',
-    isprimarykey         int          null comment '是否为主键',
-    defaultparameters    varchar(200) null comment '默认查询参数'
-);
-
-create table tempsecuritycode
-(
-    codeid       int auto_increment comment '自增主键'
-        primary key,
-    appid        varchar(16) null comment '应用编码',
-    requestip    varchar(32) null comment '请求ip',
-    sessionid    varchar(64) null comment '连接sessionid',
-    securitycode varchar(8)  null comment '验证码',
-    expiretime   datetime    null comment '过期时间'
-);
-
-create table usergroup
-(
-    usergroupid       int auto_increment comment '自增长主键用户组编号'
-        primary key,
-    superiorid        int          null comment '上级用户组编号',
-    usergroupname     varchar(50)  null comment '名称',
-    usergroupdescribe varchar(200) null comment '描述'
-);
-
-create table usergrouppermissions
-(
-    userpermissionsid   int auto_increment comment '自增长主键用户组权限编号'
-        primary key,
-    usergroupid         int          null comment '用户组编号',
-    pageconfigurationid int          null comment '页面配置编号',
-    serviceid           int          null comment '服务编号',
-    insertcolumnlist    varchar(200) null comment '列权限插入列表',
-    updatecolumnlist    varchar(200) null comment '列权限更新列表',
-    selectcolumnlist    varchar(200) null comment '列权限查询列表',
-    filterset           varchar(200) null comment '行权限过滤条件'
-);
-
-create table userinfo
-(
-    userid                    int auto_increment comment '自增长主键用户编号'
-        primary key,
-    usergroupid               int          null comment '用户组编号',
-    username                  varchar(50)  null comment '用户名',
-    account                   varchar(50)  null comment '账号',
-    userpassword              varchar(50)  null comment '密码',
-    userdescribe              varchar(200) null comment '描述',
-    isenable                  int          null comment '是否启用账号',
-    secondarypassword         varchar(50)  null comment '二级安全密码',
-    lastestchangepasswordtime datetime     null comment '最后修改密码时间'
-);
-
-create table userloginlog
-(
-    loginid       int auto_increment comment '自增长主键登录编号'
-        primary key,
-    userid        int          null,
-    requestip     varchar(50)  null comment '请求地址',
-    sessionid     varchar(50)  null comment '请求编号',
-    logintime     datetime     null comment '登录时间',
-    usertoken     varchar(100) null comment '用户令牌',
-    lasttime      datetime     null comment '最后活跃时间',
-    lastheartbeat datetime     null comment '最后心跳时间',
-    logouttime    datetime     null comment '登出时间',
-    apptoken      varchar(128) null comment '连接令牌',
-    isexpires     int          null comment '是否过期',
-    appid         varchar(16)  null comment 'app编号',
-    expirestime   datetime     null comment '过期时间'
-);
-
-create table userpermissions
-(
-    userpermissionsid   int auto_increment comment '自增长主键用户权限编号'
-        primary key,
-    userid              int          null comment '用户编号',
-    pageconfigurationid int          null comment '页面配置编号',
-    serviceid           int          null comment '服务编号',
-    insertcolumnlist    varchar(200) null comment '列权限插入列表',
-    updatecolumnlist    varchar(200) null comment '列权限更新列表',
-    selectcolumnlist    varchar(200) null comment '列权限查询列表',
-    filterset           varchar(200) null comment '行权限过滤条件'
-);
-

+ 54 - 0
src/main/resources/sql/init.sql

@@ -0,0 +1,54 @@
+delete from serviceinfo where serviceid <= 18;
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,nullresultparameters, autonotification, loopcount, frequency)
+VALUES (1, 'application', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (2, 'pageconfiguration', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (3, 'tableconfiguration', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (4, 'usergroup', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (5, 'userinfo', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (6, 'usergrouppermissions', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (7, 'userpermissions', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (8, 'apiinfo', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (9, 'applicationpermissions', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (10, 'ratelimitrule', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (11, 'container', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (12, 'datasource', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (13, 'servicetype', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (14, 'serviceinfo', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (15, 'algorithmlibrary', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (16, 'systeminfo', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (17, 'keyalias', 1, 'dev', null, null, null, null, null, null, null);
+INSERT INTO serviceinfo (serviceid, servicename, servicetype, containercode, tasktype, cronexpress, urilist,
+                         nullresultparameters, autonotification, loopcount, frequency)
+VALUES (18, 'datacache', 1, 'dev', null, null, null, null, null, null, null);

+ 1 - 1
src/test/java/com/scbfkj/uni/ControllerBaseTest.java

@@ -11,7 +11,7 @@ import org.springframework.web.context.WebApplicationContext;
 
 @SpringBootTest
 @ActiveProfiles("dev")
-public class ControllerBaseTest {
+public abstract class ControllerBaseTest {
 
 
     protected MockMvc mockMvc;

+ 4 - 4
src/test/java/com/scbfkj/uni/process/DataBaseTest.java

@@ -96,22 +96,22 @@ class DataBaseTest {
     }
 
     @Test
-    public void testWhereStr() throws Exception {
+    void testWhereStr() throws Exception {
         Map<String, Object> exec = exec(connectionStr, "select * from %s where 《whereStr》".formatted(tableName), insert, "0", filterColumns, filterLines);
         System.out.println(DataFormatUtil.toString(exec));
     }
     @Test
-    public void testBookTitleSymbol() throws Exception {
+    void testBookTitleSymbol() throws Exception {
         Map<String, Object> exec = exec(connectionStr, "select * from %s where id=《id》".formatted(tableName), insert, "0", filterColumns, filterLines);
         System.out.println(DataFormatUtil.toString(exec));
     }
     @Test
-    public void testBookTitleSymbol2() throws Exception {
+    void testBookTitleSymbol2() throws Exception {
         Map<String, Object> exec = exec(connectionStr, "select * from %s where id=《id》".formatted(tableName), insert.stream().map(it-> ((Map<String,Object>) it.get("filter"))).toList(), "0", filterColumns, filterLines);
         System.out.println(DataFormatUtil.toString(exec));
     }
     @Test
-    public void testFilter() throws Exception {
+    void testFilter() throws Exception {
         Map<String, Object> exec = exec(connectionStr, "select * from %s where 《whereStr》".formatted(tableName), List.of(new HashMap<>(){{
             put("filter",new ArrayList<Map<String,Object>>(){{
                 add(new HashMap<>(){{