mj-li 2 months ago
commit
3b3c620551
100 changed files with 6753 additions and 0 deletions
  1. 84 0
      .gitignore
  2. 97 0
      pom.xml
  3. 20 0
      xx-api-wrap/pom.xml
  4. 50 0
      xx-config-activemq/pom.xml
  5. 77 0
      xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/config/ActiveMQConfig.java
  6. 26 0
      xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/constant/ActiveMQWayEnum.java
  7. 25 0
      xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/model/ActiveMQQueueDetail.java
  8. 14 0
      xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/service/ActiveMQProducer.java
  9. 138 0
      xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/utils/ActiveMQSendUtils.java
  10. 27 0
      xx-config-elasticsearch/pom.xml
  11. 77 0
      xx-config-framework/pom.xml
  12. 204 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/common/config/ProjectConfig.java
  13. 28 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/BizFilterConfig.java
  14. 18 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/HstsHeaderInterceptor.java
  15. 63 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/SqlFilter.java
  16. 50 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/ResponseAdvice.java
  17. 70 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/SecurityFilterConfig.java
  18. 24 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/bean/RsaPubPriKeyModel.java
  19. 27 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/config/SecurityConfig.java
  20. 72 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/config/SecurityFilter.java
  21. 84 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/handle/SecurityBodyDecodeHandle.java
  22. 88 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/helper/SecurityCheckManager.java
  23. 92 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/intercepter/HttpRequestUtil.java
  24. 97 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/intercepter/WebHttpServletRequestWrapper.java
  25. 34 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/service/RsaKeyService.java
  26. 70 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/service/impl/RsaKeyServiceImpl.java
  27. 54 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/CacheKeys.java
  28. 23 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/RegexUtils.java
  29. 310 0
      xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/SecurityUtils.java
  30. 31 0
      xx-config-kafka/pom.xml
  31. 449 0
      xx-config-kafka/src/main/java/com/xxh/cloud/framework/mq/kafka/KafkaProducerUtils.java
  32. 46 0
      xx-config-mybatisplus/pom.xml
  33. 67 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/DynamicTableNameHandler.java
  34. 65 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/MyMetaObjectHandler.java
  35. 47 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/MybatisPlusConfig.java
  36. 60 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/entity/BaseEntity.java
  37. 68 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/page/PageConverter.java
  38. 59 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/AESEncryptHandler.java
  39. 192 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/EncryptionQueryWrapper.java
  40. 200 0
      xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/EncryptionUpdateWrapper.java
  41. 30 0
      xx-config-script/pom.xml
  42. 9 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLAlterDTO.java
  43. 23 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLClearDataDTO.java
  44. 53 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLCreateDTO.java
  45. 105 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLCreatePropertyDTO.java
  46. 21 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLDropDTO.java
  47. 23 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateDeleteByIdDTO.java
  48. 24 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateDeleteByWhereDTO.java
  49. 30 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateGetByIdDTO.java
  50. 42 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateGetOneDTO.java
  51. 42 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateListDTO.java
  52. 47 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateQueryDTO.java
  53. 32 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateSaveBatchDTO.java
  54. 24 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateSaveDTO.java
  55. 32 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateUpdateByIdDTO.java
  56. 28 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateUpdateByWhereDTO.java
  57. 39 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/vos/TableEntityPropertyVO.java
  58. 25 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/vos/TableEntityVO.java
  59. 48 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/constant/enums/TableColumnBaseEnum.java
  60. 44 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/constant/enums/TableDataTypeEnum.java
  61. 56 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/mapper/DbSqlDDLMapper.java
  62. 34 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/mapper/DbSqlOperateMapper.java
  63. 45 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableDDLApiService.java
  64. 49 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableOperateApiService.java
  65. 38 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableSchemaApiService.java
  66. 149 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableDDLApiServiceImpl.java
  67. 181 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableOperateApiServiceImpl.java
  68. 63 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableSchemaApiServiceImpl.java
  69. 46 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/DBSqlOpFactory.java
  70. 36 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/bean/XXDataSourceConfigBO.java
  71. 28 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBDeleteOpApi.java
  72. 43 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBInsertOpApi.java
  73. 53 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBSelectOpApi.java
  74. 15 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBUpdateOpApi.java
  75. 44 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DbSqlDDLApi.java
  76. 34 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBDeleteOpService.java
  77. 90 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBInsertOpService.java
  78. 136 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBSelectOpService.java
  79. 17 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBUpdateOpService.java
  80. 69 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DbSqlDDLService.java
  81. 28 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/test/DBSqlTest.java
  82. 14 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/test/TestBean1.java
  83. 69 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DBWriteUtils.java
  84. 203 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DbSQLExecuteUtils.java
  85. 57 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DemoOne.java
  86. 99 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/XXDataSourceUtils.java
  87. 35 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/error/DBErrorEnum.java
  88. 226 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/SqlDDLUtils.java
  89. 23 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/DataTypeConvertFactory.java
  90. 17 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/ITypeConvert.java
  91. 52 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/MySQLTypeConvert.java
  92. 66 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/DeleteSqlWrapper.java
  93. 8 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/ISqlWrapper.java
  94. 115 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/InsertBatchSqlWrapper.java
  95. 78 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/InsertSqlWrapper.java
  96. 221 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/QuerySqlWrapper.java
  97. 81 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/UpdateSqlWrapper.java
  98. 15 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/GroupByBean.java
  99. 39 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/InsertBean.java
  100. 33 0
      xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/InsertColumnBean.java

+ 84 - 0
.gitignore

@@ -0,0 +1,84 @@
+# maven output files
+/target/
+*/target/
+**/target/
+
+# virtual machine crash logs
+hs_err_pid*
+/bin/
+/build/
+*/bin/
+*/gen/
+*/out/
+
+# Java class files
+*.class
+
+# Files for the Dalvik VM
+*.dex
+
+#Built application files
+*.apk
+*.ap_
+proguard/
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+# *.jar
+*.war
+*.ear
+
+# Eclipse Project files
+.classpath
+*/.classpath
+**/.classpath
+.project
+*/.project
+**/.project
+.factorypath
+*/.factorypath
+**/.factorypath
+.settings/
+/.settings/
+*/.settings/
+**/.settings/
+*/.apt_generated/
+**/.apt_generated/
+*/.apt_generated_tests/
+**/.apt_generated_tests/
+
+# IntelliJ IDEA Project files
+.idea
+*.iml
+*/*.iml
+**/*.iml
+*.ipr
+*.iws
+out
+*/.DS_Store
+**/.DS_Store
+.DS_Store
+Thumbs.db
+/.idea/
+*/.idea/
+**/.idea/
+.idea/
+
+#gradle wrapper
+gradle/
+/.gradle/
+# Gradle files
+.gradle/
+build/
+*/build/
+**/build/
+gradlew
+gradlew.bat
+
+# Log Files
+*.log
+
+# VSCode
+.vscode

+ 97 - 0
pom.xml

@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.xxh.cloud</groupId>
+	<artifactId>xx-framework-java</artifactId>
+	<packaging>pom</packaging>
+	<version>1.0.0</version>
+
+
+	<properties>
+		<java.version>1.8</java.version>
+		<maven.compiler.source>8</maven.compiler.source>
+		<maven.compiler.target>8</maven.compiler.target>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>com.xxh.cloud</groupId>
+				<artifactId>xx-framework-dependencies</artifactId>
+				<version>1.0.0</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-aop</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-validation</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-context-support</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-all</artifactId>
+		</dependency>
+
+	</dependencies>
+
+	<modules>
+		<module>xx-framework-dependencies</module>
+		<module>xx-config-web</module>
+		<module>xx-framework-core</module>
+        <module>xx-config-framework</module>
+        <module>xx-config-elasticsearch</module>
+		<module>xx-config-mybatisplus</module>
+		<module>xx-config-kafka</module>
+        <module>xx-config-script</module>
+        <module>xx-config-activemq</module>
+        <module>xx-api-wrap</module>
+    </modules>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.6.1</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>

+ 20 - 0
xx-api-wrap/pom.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.xxh.cloud</groupId>
+        <artifactId>xx-framework-java</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>xx-api-wrap</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+</project>

+ 50 - 0
xx-config-activemq/pom.xml

@@ -0,0 +1,50 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>xx-config-activemq</artifactId>
+    <packaging>jar</packaging>
+
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!--ActiveMq-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-activemq</artifactId>
+        </dependency>
+
+        <!--消息队列连接池-->
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-pool</artifactId>
+            <version>5.16.7</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.xxh.cloud</groupId>
+            <artifactId>xx-framework-core</artifactId>
+        </dependency>
+
+
+<!--        <dependency>-->
+<!--            <groupId>org.apache.activemq</groupId>-->
+<!--            <artifactId>activemq-all</artifactId>-->
+<!--            <version>5.16.7</version>-->
+<!--        </dependency>-->
+
+
+
+    </dependencies>
+
+
+</project>

+ 77 - 0
xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/config/ActiveMQConfig.java

@@ -0,0 +1,77 @@
+package com.xxh.cloud.framework.activemq.config;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQSession;
+import org.apache.activemq.RedeliveryPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
+import org.springframework.jms.config.JmsListenerContainerFactory;
+import org.springframework.jms.config.SimpleJmsListenerContainerFactory;
+import org.springframework.jms.core.JmsMessagingTemplate;
+
+@Configuration
+@ConditionalOnProperty(value ="spring.activemq.enabled", havingValue = "true")
+public class ActiveMQConfig {
+
+
+
+    private Logger logger = LoggerFactory.getLogger(ActiveMQConfig.class);
+
+    @Value("${spring.activemq.broker-url}")
+    private String brokerUrl;
+
+    @Value("${spring.activemq.user}")
+    private String username;
+
+    @Value("${spring.activemq.password}")
+    private String password;
+
+    @Bean
+    public ActiveMQConnectionFactory connectionFactory() {
+        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, brokerUrl);
+        // 设置重发机制
+        RedeliveryPolicy policy = new RedeliveryPolicy();
+        policy.setUseExponentialBackOff(Boolean.TRUE);
+        policy.setMaximumRedeliveries(5);                // 消息处理失败重新处理次数
+        policy.setInitialRedeliveryDelay(5000L);         // 重发时间间隔
+        policy.setBackOffMultiplier(2);       //第一次失败后重新发送之前等待500毫秒,第二次失败再等待500 * 2毫秒,这里的2就是value
+        policy.setMaximumRedeliveryDelay(5000L); //设置重发最大拖延时间-1 表示没有拖延只有UseExponentialBackOff(true)为true时生效
+        activeMQConnectionFactory.setRedeliveryPolicy(policy);
+        return activeMQConnectionFactory;
+    }
+
+
+
+    @Bean
+    public JmsMessagingTemplate jmsMessageTemplate(){
+        return new JmsMessagingTemplate(connectionFactory());
+    }
+
+
+    @Bean("queueListener")
+    public JmsListenerContainerFactory<?> queueJmsListenerContainerFactory(ActiveMQConnectionFactory givenConnectionFactory) {
+        SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
+        // 关闭事务
+        factory.setSessionTransacted(false);
+        // 手动确认消息
+        factory.setSessionAcknowledgeMode(ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
+        factory.setPubSubDomain(false);
+        factory.setConnectionFactory(givenConnectionFactory);
+        return factory;
+    }
+
+    @Bean("topicListener")
+    public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ActiveMQConnectionFactory givenConnectionFactory){
+        //设置为发布订阅模式, 默认情况下使用生产消费者方式
+        DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
+        bean.setPubSubDomain(true);
+        bean.setConnectionFactory(givenConnectionFactory);
+        return bean;
+    }
+
+}

+ 26 - 0
xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/constant/ActiveMQWayEnum.java

@@ -0,0 +1,26 @@
+package com.xxh.cloud.framework.activemq.constant;
+
+public enum ActiveMQWayEnum {
+
+    MQ_SW_Queue("queue","队列"),
+
+    MQ_SW_Topic("topic","广播"),
+
+    ;
+
+    private String code;
+    private String msg;
+
+    private ActiveMQWayEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+    public String getCode() {
+        return code;
+    }
+    public String getMsg() {
+        return msg;
+    }
+
+
+}

+ 25 - 0
xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/model/ActiveMQQueueDetail.java

@@ -0,0 +1,25 @@
+package com.xxh.cloud.framework.activemq.model;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+public class ActiveMQQueueDetail {
+
+    @ApiModelProperty(value = "队列的名称")
+    private String queueName;
+
+    @ApiModelProperty(value = "队列中剩余的消息数")
+    private int queueSize;
+
+    @ApiModelProperty(value = "消费者数")
+    private int consumerCount;
+
+    @ApiModelProperty(value = "出队列的数量")
+    private int dequeueCount;
+    
+}

+ 14 - 0
xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/service/ActiveMQProducer.java

@@ -0,0 +1,14 @@
+package com.xxh.cloud.framework.activemq.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.core.JmsMessagingTemplate;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ActiveMQProducer {
+
+    @Autowired
+    private JmsMessagingTemplate jmsMessagingTemplate;
+
+
+}

+ 138 - 0
xx-config-activemq/src/main/java/com/xxh/cloud/framework/activemq/utils/ActiveMQSendUtils.java

@@ -0,0 +1,138 @@
+package com.xxh.cloud.framework.activemq.utils;
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.activemq.constant.ActiveMQWayEnum;
+import com.xxh.cloud.framework.activemq.model.ActiveMQQueueDetail;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.utils.SpringContextUtils;
+import org.apache.activemq.ScheduledMessage;
+import org.apache.activemq.broker.jmx.BrokerViewMBean;
+import org.apache.activemq.broker.jmx.QueueViewMBean;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.jms.core.JmsMessagingTemplate;
+import org.springframework.jms.core.JmsTemplate;
+
+import javax.jms.Destination;
+import javax.jms.Queue;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ActiveMQSendUtils {
+
+
+
+    /**
+     *
+     * */
+    public static void send(ActiveMQWayEnum way, String channelName, String message, Integer delay){
+        if(way==null || StrUtil.isEmpty(channelName) || StrUtil.isEmpty(message) || delay==null){
+            return;
+        }
+        JmsMessagingTemplate jmsMessagingTemplate= SpringContextUtils.getBean(JmsMessagingTemplate.class);
+        if(jmsMessagingTemplate==null){
+            return;
+        }
+        if (ActiveMQWayEnum.MQ_SW_Queue==way) {
+            Queue queue = new ActiveMQQueue(channelName);
+            ActiveMQSendUtils.sendMessageDelay(jmsMessagingTemplate,queue, message, delay);
+        } else if (ActiveMQWayEnum.MQ_SW_Topic==way) {
+            Topic topic = new ActiveMQTopic(channelName);
+            ActiveMQSendUtils.sendMessageDelay(jmsMessagingTemplate,topic, message, delay);
+        } else {
+            throw new BusinessException("MQ队列类型错误");
+        }
+    }
+
+
+
+    /**
+     *
+     * */
+    public static void send(ActiveMQWayEnum way,String channelName,String message){
+        if(way==null || StrUtil.isEmpty(channelName) || StrUtil.isEmpty(message)){
+            return;
+        }
+        JmsMessagingTemplate jmsMessagingTemplate= SpringContextUtils.getBean(JmsMessagingTemplate.class);
+        if(jmsMessagingTemplate==null){
+            return;
+        }
+        if (ActiveMQWayEnum.MQ_SW_Queue==way) {
+            Queue queue = new ActiveMQQueue(channelName);
+            ActiveMQSendUtils.sendMessage(jmsMessagingTemplate,queue, message);
+        } else if (ActiveMQWayEnum.MQ_SW_Topic==way) {
+            Topic topic = new ActiveMQTopic(channelName);
+            ActiveMQSendUtils.sendMessage(jmsMessagingTemplate,topic, message);
+        } else {
+            throw new BusinessException("MQ队列类型错误");
+        }
+    }
+
+
+    // 发送消息,destination是发送到的队列,message是待发送的消息
+    private static void sendMessage(JmsMessagingTemplate jmsMessagingTemplate, Destination destination, String content){
+        jmsMessagingTemplate.convertAndSend(destination, content);
+    }
+
+    // 发送延迟消息,destination是发送到的队列,message是待发送的消息
+    private static void sendMessageDelay(JmsMessagingTemplate jmsMessagingTemplate,Destination destination, String content, Integer delay){
+        JmsTemplate jmsTemplate = jmsMessagingTemplate.getJmsTemplate();
+        assert jmsTemplate != null;
+        jmsTemplate.send(destination, session -> {
+            TextMessage message = session.createTextMessage(content);
+            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay * 1000);
+            return message;
+        });
+    }
+
+    /** jmx监控队列,需要修改配置文件activemq.xml并重启activemq
+     *  broker节点增加useJmx=”true”,修改managementContext添加connectorPort
+     *  例:
+     *  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" useJmx="true">
+     *  <managementContext>
+     *            <managementContext createConnector="true" connectorPort="11099"/>
+     * </managementContext>
+     *
+     * **/
+    public static List<ActiveMQQueueDetail> queueDetail(String host){
+        String url = StrUtil.format("service:jmx:rmi:///jndi/rmi://{}:11099/jmxrmi", host);
+        String broker = "org.apache.activemq:brokerName=localhost,type=Broker";
+        List<ActiveMQQueueDetail> details = new ArrayList<>();
+        try {
+            JMXServiceURL urls = new JMXServiceURL(url);
+            JMXConnector connector = JMXConnectorFactory.connect(urls, null);
+            connector.connect();
+            MBeanServerConnection conn = connector.getMBeanServerConnection();
+            ObjectName name = new ObjectName(broker);
+            BrokerViewMBean mBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(conn, name, BrokerViewMBean.class, true);
+            for (ObjectName na : mBean.getQueues()) {
+                //获取点对点的队列       mBean.getTopics() 获取订阅模式的队列
+                QueueViewMBean queueBean = (QueueViewMBean)
+                        MBeanServerInvocationHandler.newProxyInstance(conn, na, QueueViewMBean.class, true);
+                details.add(new ActiveMQQueueDetail(queueBean.getName(),
+                        (int)queueBean.getQueueSize(), (int)queueBean.getConsumerCount(),
+                        (int)queueBean.getDequeueCount()));
+            }
+            return details;
+        } catch (Exception e) {
+            throw new BusinessException("MQ队列类型错误");
+        }
+    }
+
+    public static void main(String[] args) throws UnsupportedEncodingException {
+//        List<ActiveMQQueueDetail> details = queueDetail("127.0.0.1");
+//        System.out.println(JSONObject.toJSONString(details));
+    }
+
+}

+ 27 - 0
xx-config-elasticsearch/pom.xml

@@ -0,0 +1,27 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <artifactId>xx-config-elasticsearch</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>org.dromara.easy-es</groupId>
+            <artifactId>easy-es-boot-starter</artifactId>
+        </dependency>
+
+    </dependencies>
+
+
+</project>

+ 77 - 0
xx-config-framework/pom.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <artifactId>xx-config-framework</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>com.xxh.cloud</groupId>
+            <artifactId>xx-framework-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context-support</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
+
+
+
+<!--        <dependency>-->
+<!--            <groupId>mysql</groupId>-->
+<!--            <artifactId>mysql-connector-java</artifactId>-->
+<!--        </dependency>-->
+
+<!--        <dependency>-->
+<!--            <groupId>com.baomidou</groupId>-->
+<!--            <artifactId>mybatis-plus-boot-starter</artifactId>-->
+<!--        </dependency>-->
+
+
+
+<!--        <dependency>-->
+<!--            <groupId>cn.dev33</groupId>-->
+<!--            <artifactId>sa-token-spring-boot-starter</artifactId>-->
+<!--        </dependency>-->
+
+    </dependencies>
+</project>

+ 204 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/common/config/ProjectConfig.java

@@ -0,0 +1,204 @@
+package com.xxh.cloud.framework.common.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.constant.DataScopeMode;
+import com.xxh.cloud.framework.common.constant.UserRegLoginMode;
+import com.xxh.cloud.framework.common.utils.XXEnumUtil;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * 业务系统配置
+ * */
+@Deprecated
+@Component
+public class ProjectConfig {
+
+    //============================运营端===========================================
+    /**
+     *  运营端员工用户注册方式
+     * */
+    @Value("${project.config.sysUser.reg:userNamePassword}")
+    public String sysUserRegMode= UserRegLoginMode.UserNamePassword.getCode();
+
+    /**
+     *  运营端员工用户登录方式
+     * */
+    @Value("${project.config.sysUser.login:userNamePassword}")
+    public String sysUserLoginMode= UserRegLoginMode.UserNamePassword.getCode();
+
+
+    /**
+     *  运营端员工是否管理
+     * */
+
+    //============================机构端===========================================
+
+    /**
+     * 机构端员工用户注册方式 (管理端)
+     * */
+    @Value("${project.config.comUser.mgr.reg:userNamePassword}")
+    public String comUserMgrRegMode=UserRegLoginMode.UserNamePassword.getCode();
+
+
+    /**
+     * 机构端员工用户注册方式 (用户端)
+     * */
+    @Value("${project.config.comUser.app.reg:userNamePassword}")
+    public String comUserAppRegMode=UserRegLoginMode.UserNamePassword.getCode();
+
+    /**
+     *  机构端员工用户登录方式
+     * */
+    @Value("${project.config.comUser.login:none}")
+    public String comUserLoginMode= UserRegLoginMode.NoneLoginRegAdd.getCode();
+
+    /**
+     * 机构端员工用户数据隔离方式(机构数据隔离、租户数据隔离)
+     * */
+    @Value("${project.config.comUser.data:tenant}")
+    public String comUserDataScopeMode= DataScopeMode.TenantDataScope.getCode();
+
+
+
+    //===============================客户端==========================================
+
+    /**
+     * 客户用户注册方式(管理端)
+     * */
+    @Value("${project.config.custUser.mgr.reg:mobileVcode}")
+    public String custUserMgrRegMode=UserRegLoginMode.MobileVcode.getCode();
+
+    /**
+     * 客户用户注册方式 (用户端)
+     * */
+    @Value("${project.config.custUser.app.reg:userNamePassword}")
+    public String custUserAppRegMode=UserRegLoginMode.UserNamePassword.getCode();
+
+    /**
+     *  客户用户用户登录方式
+     * */
+    @Value("${project.config.custUser.login:none}")
+    public String custUserLoginMode= UserRegLoginMode.NoneLoginRegAdd.getCode();
+
+
+    /**
+     * 客户用户数据隔离方式(机构数据隔离、租户数据隔离)
+     * 机构数据隔离:注册和登录时机构编号不能为空
+     * 租户数据隔离:注册和登录时不需要机构编号
+     * */
+    @Value("${project.config.custUser.data:tenant}")
+    public String custUserDataScopeMode= DataScopeMode.TenantDataScope.getCode();
+
+
+
+
+
+    //====================================机构:运营端 获取方法============================================
+
+    /**
+     * 运营端员工用户注册方式
+     * */
+    public UserRegLoginMode getSysUserRegModeEnum(){
+        UserRegLoginMode data= XXEnumUtil.getEnum(UserRegLoginMode.class,this.sysUserRegMode);
+        return data==null?UserRegLoginMode.UserNamePassword:data;
+    }
+
+
+    /**
+     * 运营端员工用户登录方式
+     * */
+    public UserRegLoginMode getSysUserLoginModeEnum(){
+        UserRegLoginMode data= XXEnumUtil.getEnum(UserRegLoginMode.class,this.sysUserLoginMode);
+        return data==null?UserRegLoginMode.UserNamePassword:data;
+    }
+
+
+
+    /**
+     * 检验 : 运营端员工用户注册方式
+     * */
+    public boolean checkSysUserRegMode(UserRegLoginMode regLoginMode){
+        UserRegLoginMode urlm= this.getSysUserRegModeEnum();
+        return  regLoginMode==urlm?true:false;
+    }
+
+    /**
+     * 检验 : 运营端员工用户登录方式
+     * */
+    public boolean checkSysUserLoginModeEnum(UserRegLoginMode regLoginMode){
+        UserRegLoginMode urlm=this.getSysUserLoginModeEnum();
+        return  regLoginMode==urlm?true:false;
+    }
+
+    //=====================================机构:客户端 获取方法===========================================
+
+    /**
+     * 机构端员工用户(管理端)新增方式
+     * */
+    public UserRegLoginMode getComUserMgrRegModeEnum(){
+        UserRegLoginMode data=XXEnumUtil.getEnum(UserRegLoginMode.class,this.comUserMgrRegMode);
+        return data==null?UserRegLoginMode.UserNamePassword:data;
+    }
+
+    /**
+     * 机构端员工用户(自己)注册方式
+     * */
+    public UserRegLoginMode getComUserAppRegModeEnum(){
+        UserRegLoginMode data=XXEnumUtil.getEnum(UserRegLoginMode.class,this.comUserAppRegMode);
+        return data==null?UserRegLoginMode.UserNamePassword:data;
+    }
+
+
+    /**
+     * 机构端员工用户登录方式
+     * */
+    public UserRegLoginMode getComUserLoginModeEnum(){
+        UserRegLoginMode data=XXEnumUtil.getEnum(UserRegLoginMode.class,this.comUserLoginMode);
+        return data==null?UserRegLoginMode.UserNamePassword:data;
+    }
+
+    /**
+     * 机构端员工用户数据隔离方式(机构数据隔离、租户数据隔离)
+     * */
+    public DataScopeMode getComUserDataScopeModeEnum(){
+        DataScopeMode data=XXEnumUtil.getEnum(DataScopeMode.class,this.comUserDataScopeMode);
+        return data==null?DataScopeMode.TenantDataScope:data;
+    }
+
+    /**
+     * 检验 :机构端员工用户(管理端)新增方式
+     * */
+    public boolean checkComUserMgrRegMode(UserRegLoginMode regLoginMode){
+        UserRegLoginMode urlm=this.getComUserMgrRegModeEnum();
+        return  regLoginMode==urlm?true:false;
+    }
+
+    /**
+     * 检验 :机构端员工用户(自己)注册方式
+     * */
+    public boolean checkComUserAppRegMode(UserRegLoginMode regLoginMode){
+        UserRegLoginMode urlm=this.getComUserAppRegModeEnum();
+        return  regLoginMode==urlm?true:false;
+    }
+
+
+    /**
+     * 检验 :机构端员工用户登录方式
+     * */
+    public boolean checkComUserLoginMode(UserRegLoginMode regLoginMode){
+        UserRegLoginMode urlm=this.getComUserLoginModeEnum();
+        return  regLoginMode==urlm?true:false;
+    }
+
+
+
+    //================================================================================
+
+
+
+
+
+}

+ 28 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/BizFilterConfig.java

@@ -0,0 +1,28 @@
+package com.xxh.cloud.framework.filter;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.servlet.DispatcherType;
+
+
+@Configuration
+@ConditionalOnProperty(value ="biz.filter.enabled", havingValue = "true")
+public class BizFilterConfig {
+
+
+    @Bean
+    public FilterRegistrationBean sqlFilterRegistration() {
+        //System.out.println("+++++++++++++++++++++++sqlFilter  SQL");
+        FilterRegistrationBean registration = new FilterRegistrationBean();
+        registration.setDispatcherTypes(DispatcherType.REQUEST);
+        registration.setFilter(new SqlFilter());
+        registration.addUrlPatterns("/*");
+        registration.setName("sqlFilter");
+        registration.setOrder(2);
+        return registration;
+    }
+
+}

+ 18 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/HstsHeaderInterceptor.java

@@ -0,0 +1,18 @@
+package com.xxh.cloud.framework.filter;
+
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class HstsHeaderInterceptor  extends HandlerInterceptorAdapter {
+
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        response.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
+        return true;
+    }
+
+
+}

+ 63 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/filter/SqlFilter.java

@@ -0,0 +1,63 @@
+package com.xxh.cloud.framework.filter;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.xxh.cloud.framework.common.entity.Result;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.xss.SqlFilterUtils;
+import com.xxh.cloud.framework.security.intercepter.WebHttpServletRequestWrapper;
+import org.springframework.http.HttpMethod;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class SqlFilter implements Filter {
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        //System.out.println("----------执行SqlFilter");
+
+        HttpServletResponse httpResponse=(HttpServletResponse) response;
+        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+
+        String contentType = httpServletRequest.getContentType();
+        String method = httpServletRequest.getMethod();
+
+
+        if(!HttpMethod.POST.name().toUpperCase().equals(method.toUpperCase())){
+            chain.doFilter(request, response);
+            return;
+        }
+
+        if(contentType.indexOf("json")<0){
+            chain.doFilter(request, response);
+            return;
+        }
+
+        WebHttpServletRequestWrapper requestWrapper = null;
+
+        try {
+            requestWrapper = new WebHttpServletRequestWrapper(httpServletRequest);
+            String bodyContent = requestWrapper.getBodyContent();
+            SqlFilterUtils.sqlInject(bodyContent);
+            requestWrapper.setBodyContent(bodyContent);
+        }catch (Exception e){
+            e.printStackTrace();
+            //httpResponse.setStatus(401);
+            httpResponse.setStatus(200);
+            httpResponse.setContentType("application/json;charset=UTF-8");
+            httpResponse.setCharacterEncoding("utf-8");
+            Result<String> result = new Result<String>().error(BusinessBaseErrorEnum.INVALID_SYMBOL);
+            httpResponse.getWriter().write(JSONObject.toJSONString(result));
+            return;
+        }
+
+        if (requestWrapper == null) {
+            chain.doFilter(request, response);
+        } else {
+            chain.doFilter(requestWrapper, response);
+        }
+
+
+    }
+}

+ 50 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/ResponseAdvice.java

@@ -0,0 +1,50 @@
+package com.xxh.cloud.framework.security;
+
+/**
+ * @Author: limj
+ * @Date: 2023/11/29
+ */
+
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.xxh.cloud.framework.common.entity.Result;
+import com.xxh.cloud.framework.security.utils.SecurityUtils;
+import lombok.SneakyThrows;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.MethodParameter;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
+
+/**
+ * 拦截controller返回值,封装后统一返回格式
+ */
+@Log4j2
+@RestControllerAdvice
+public class ResponseAdvice implements ResponseBodyAdvice<Object> {
+
+//    @Autowired
+//    private ObjectMapper objectMapper;
+
+    @Override
+    public boolean supports(MethodParameter returnType, Class converterType) {
+        return true;
+    }
+
+    @SneakyThrows
+    @Override
+    public Object beforeBodyWrite(Object o, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
+        //如果Controller返回String的话,SpringBoot不会帮我们自动封装而直接返回,因此我们需要手动转换成json。
+        if (o instanceof Result) {
+            Result result = (Result) o;
+            result.setData(SecurityUtils.encryptBaseResultData(result.getData()));
+            return result;
+        } else {
+            return o;
+        }
+    }
+}
+

+ 70 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/SecurityFilterConfig.java

@@ -0,0 +1,70 @@
+package com.xxh.cloud.framework.security;
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.redis.RedisUtils;
+import com.xxh.cloud.framework.filter.HstsHeaderInterceptor;
+import com.xxh.cloud.framework.security.config.SecurityConfig;
+import com.xxh.cloud.framework.security.config.SecurityFilter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.cglib.transform.impl.AddInitTransformer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@ConditionalOnProperty(value = "saas.security.filter.enabled", havingValue = "true")
+public class SecurityFilterConfig implements WebMvcConfigurer {
+
+    @Autowired
+    private RedisUtils redisUtils;
+
+    @Autowired
+    private SecurityConfig securityConfig;
+
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        System.out.println("--------------注册拦截器  HstsHeaderInterceptor ");
+        registry.addInterceptor(new HstsHeaderInterceptor()).addPathPatterns("/**");
+    }
+
+
+
+    @Bean
+    public FilterRegistrationBean filter(){
+        System.out.println("----------------WebMvcConfig (FilterRegistration): 过滤器 2-------------------------");
+        System.out.println(StrUtil.format("SecurityFilter : url={} , notUrl={}",securityConfig.getFilterUrl() ,securityConfig.getNotFilterUrl()));
+
+        FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean();
+        filterRegistrationBean.setFilter(new SecurityFilter(redisUtils));
+
+        if(StrUtil.isEmpty(securityConfig.getFilterUrl())){
+            filterRegistrationBean.addUrlPatterns("/*");
+        }else {
+            String[] urls= securityConfig.getFilterUrl().split(";");
+            filterRegistrationBean.addUrlPatterns(urls);
+        }
+
+        if(StrUtil.isNotEmpty(securityConfig.getNotFilterUrl())){
+//            Map<String, Object> paramMap = new HashMap<>();
+//            paramMap.put("notUrls", projectConfig.getNotFilterUrl());
+//            filterRegistrationBean.setInitParameters(paramMap);
+            filterRegistrationBean.addInitParameter("notUrls",securityConfig.getNotFilterUrl());
+        }
+
+        filterRegistrationBean.setName("saas_security_filter");
+        filterRegistrationBean.setOrder(1);
+        return filterRegistrationBean;
+    }
+
+
+
+
+
+
+
+
+}

+ 24 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/bean/RsaPubPriKeyModel.java

@@ -0,0 +1,24 @@
+package com.xxh.cloud.framework.security.bean;
+
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+public class RsaPubPriKeyModel {
+
+    private String reqPubKey;
+
+    private String reqPriKey;
+
+    private String respPubKey;
+
+    private String respPriKey;
+
+    private String version;
+
+
+
+
+}

+ 27 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/config/SecurityConfig.java

@@ -0,0 +1,27 @@
+package com.xxh.cloud.framework.security.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+@Getter
+@Setter
+public class SecurityConfig {
+
+	/**是否开启拦截器*/
+	@Value("${saas.security.filter.enabled:false}")
+	private boolean isFilterEnabled=false;
+
+	/**拦截器URL(多个用分号隔开)*/
+	@Value("${saas.security.filter.filterUrl:/*}")
+	private String filterUrl;
+
+	/**不拦截器URL(多个用分号隔开)*/
+	@Value("${saas.security.filter.notFilterUrl:#{null}}")
+	private String notFilterUrl;
+
+	@Value("${project.config.appVersion:1.0.0}")
+	private String appVersion;
+}

+ 72 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/config/SecurityFilter.java

@@ -0,0 +1,72 @@
+package com.xxh.cloud.framework.security.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson2.JSONObject;
+import com.xxh.cloud.framework.common.entity.Result;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.redis.RedisUtils;
+import com.xxh.cloud.framework.security.helper.SecurityCheckManager;
+import com.xxh.cloud.framework.security.intercepter.WebHttpServletRequestWrapper;
+import lombok.extern.log4j.Log4j2;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 安全拦截器()
+ * */
+@Log4j2
+public class SecurityFilter implements Filter {
+
+    private RedisUtils redisUtils;
+
+    private List<String> noFilterUrls;
+
+    public SecurityFilter(RedisUtils redisUtils) {
+        this.redisUtils=redisUtils;
+    }
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        System.out.println("+++++++++++++++++ 安全拦截器 init");
+        String notUrls= filterConfig.getInitParameter("notUrls");
+        System.out.println("not urls = "+notUrls);
+        if(StrUtil.isNotEmpty(notUrls)){
+            noFilterUrls=new ArrayList<>(Arrays.asList( notUrls.split(";")));
+        }
+    }
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        System.out.println("+++++++++++++++++ 安全拦截器 doFilter");
+        WebHttpServletRequestWrapper requestWrapper = null;
+
+        HttpServletResponse httpResponse=(HttpServletResponse) response;
+        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+        try {
+            requestWrapper = SecurityCheckManager.getWebHttpServletRequestWrapper(httpServletRequest,redisUtils,noFilterUrls);
+        }catch (Exception e){
+            e.printStackTrace();
+//          httpResponse.setStatus(401);
+            httpResponse.setStatus(200);
+            httpResponse.setContentType("application/json;charset=UTF-8");
+            httpResponse.setCharacterEncoding("utf-8");
+            Result<String> result = new Result<String>().error(BusinessBaseErrorEnum.SIGN_ERROR);
+            httpResponse.getWriter().write(JSONObject.toJSONString(result));
+            return;
+        }
+
+
+        if (requestWrapper == null) {
+            chain.doFilter(request, response);
+        } else {
+            chain.doFilter(requestWrapper, response);
+        }
+    }
+
+
+}

+ 84 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/handle/SecurityBodyDecodeHandle.java

@@ -0,0 +1,84 @@
+package com.xxh.cloud.framework.security.handle;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.asymmetric.KeyType;
+import com.alibaba.fastjson2.JSONObject;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.redis.RedisUtils;
+import com.xxh.cloud.framework.security.bean.RsaPubPriKeyModel;
+import com.xxh.cloud.framework.security.utils.CacheKeys;
+import com.xxh.cloud.framework.security.utils.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * 内容加解密
+ * */
+public class SecurityBodyDecodeHandle {
+
+    public String process(RedisUtils redisUtils, String token, String bodyContent){
+
+        System.out.println("+++++ SecurityBodyDecodeHandle,参数解密");
+        JSONObject jsonObject= JSONObject.parseObject(bodyContent);
+        String k= jsonObject.getString("k");
+        String d= jsonObject.getString("t");
+        String v= jsonObject.getString("v");
+        if(StrUtil.isEmpty(k) || StrUtil.isEmpty(v)){
+            throw new BusinessException(BusinessBaseErrorEnum.SIGN_ERROR);
+        }
+        System.out.println(StrUtil.format("key = {},data = {}",k,d));
+        String reqPriKey= this.get_Req_Pri_Key(redisUtils, token);
+        String key=this.decrypt_Key_RSA(reqPriKey,k);
+        String data;
+        if(StrUtil.isEmpty(d)){
+            data= "{}";
+        }else {
+            data= this.decrypt_data_AES(key,d);
+        }
+        this.checkRepeat(key);
+        return data;
+    }
+
+
+    /**RSA私钥*/
+    private String get_Req_Pri_Key(RedisUtils redisUtils, String token) {
+        String key= CacheKeys.getRsaKey(token,true);
+        RsaPubPriKeyModel model= (RsaPubPriKeyModel) redisUtils.get(key);
+        if(model==null){
+            throw new BusinessException(BusinessBaseErrorEnum.SIGN_Config_Error);
+        }
+        if(StrUtil.isEmpty(model.getReqPriKey())){
+            throw new BusinessException(BusinessBaseErrorEnum.SIGN_Config_Error);
+        }
+        return model.getReqPriKey();
+    }
+
+    /**RSA解密key*/
+    private String decrypt_Key_RSA(String key,String content){
+        try {
+            return SecurityUtils.rsaDecode2Base64(KeyType.PrivateKey,key,content);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new BusinessException(BusinessBaseErrorEnum.SIGN_ERROR);
+        }
+    }
+
+    /**AES解密内容*/
+    private String decrypt_data_AES(String key,String content){
+        try {
+            return SecurityUtils.aesDecryptStr(key,content);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new BusinessException(BusinessBaseErrorEnum.SIGN_ERROR);
+        }
+    }
+
+
+    /**重复提交验证*/
+    private void checkRepeat(String key){
+        //todo:待实现
+
+    }
+
+
+}

+ 88 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/helper/SecurityCheckManager.java

@@ -0,0 +1,88 @@
+package com.xxh.cloud.framework.security.helper;
+
+import cn.hutool.core.collection.CollUtil;
+import com.xxh.cloud.framework.common.constant.YN;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.redis.RedisUtils;
+import com.xxh.cloud.framework.security.handle.SecurityBodyDecodeHandle;
+import com.xxh.cloud.framework.security.intercepter.WebHttpServletRequestWrapper;
+import com.xxh.cloud.framework.security.utils.RegexUtils;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.List;
+
+@Log4j2
+public class SecurityCheckManager {
+
+    @Autowired
+    private RedisUtils redisUtils;
+
+    /**
+     * 是否需要拦截 (true 需要拦截 ;false不需要拦截)
+     * */
+    public static boolean checkIsFilter(List<String> notFilterUrls,String servletPath){
+        if(CollUtil.isEmpty(notFilterUrls)){
+            return true;
+        }
+        for(String notFilterUrl:notFilterUrls){
+            if(notFilterUrl.indexOf("*")>=0){
+                if(RegexUtils.isAuthc(servletPath.trim(),notFilterUrl.trim())){
+                    return false;
+                }
+            }else if(servletPath.trim().equals(notFilterUrl.trim())){
+                return false;
+            }
+        }
+        return true;
+    }
+
+
+    /**
+     *
+     * */
+    public static WebHttpServletRequestWrapper getWebHttpServletRequestWrapper(
+            HttpServletRequest httpServletRequest, RedisUtils redisUtils, List<String> notFilterUrls){
+        String method = httpServletRequest.getMethod();
+        String contentType = httpServletRequest.getContentType();
+        String servletPath =  httpServletRequest.getServletPath();
+        String token = httpServletRequest.getHeader("token");
+
+        boolean isFilter=checkIsFilter(notFilterUrls,servletPath);
+        System.out.println("+++++ isFilter = "+isFilter);
+        if(isFilter){ //需要拦截True
+            if(!HttpMethod.POST.name().toUpperCase().equals(method.toUpperCase())){
+                throw new BusinessException(BusinessBaseErrorEnum.SIGN_Config_Error);
+            }
+            if(contentType.indexOf("json")<0){
+                throw new BusinessException(BusinessBaseErrorEnum.SIGN_Config_Error);
+            }
+
+            WebHttpServletRequestWrapper  requestWrapper = null;
+            try {
+                requestWrapper = new WebHttpServletRequestWrapper(httpServletRequest);
+                String bodyContent = requestWrapper.getBodyContent();
+                SecurityBodyDecodeHandle handle=new SecurityBodyDecodeHandle();
+                String data= handle.process(redisUtils, token,bodyContent);
+                requestWrapper.setBodyContent(data);
+                requestWrapper.putHeader("sign_flag", YN.YES.getCode());
+            } catch (IOException e) {
+                e.printStackTrace();
+                throw new BusinessException(BusinessBaseErrorEnum.SIGN_ERROR);
+            }
+
+            return requestWrapper;
+        }
+
+
+        return null;
+
+    }
+
+
+
+}

+ 92 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/intercepter/HttpRequestUtil.java

@@ -0,0 +1,92 @@
+package com.xxh.cloud.framework.security.intercepter;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+public class HttpRequestUtil {
+
+	public static String getBodyContent(HttpServletRequest request) throws IOException {
+        StringBuilder sb = new StringBuilder();
+        try  {
+            InputStream inputStream = request.getInputStream();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                sb.append(line);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return sb.toString();
+    }
+
+
+
+    public static String getPostData(HttpServletRequest request) {
+        StringBuilder data = new StringBuilder();
+        String line;
+        BufferedReader reader;
+        try {
+            reader = request.getReader();
+            while (null != (line = reader.readLine())) {
+                data.append(line);
+            }
+        } catch (IOException e) {
+            return null;
+        }
+        return data.toString();
+    }
+
+
+//
+//    public static String getBodyString(HttpServletRequest request) throws IOException {
+//        StringBuilder sb = new StringBuilder();
+//        InputStream inputStream = null;
+//        BufferedReader reader = null;
+//        try {
+//            inputStream = request.getInputStream();
+//            reader = new BufferedReader(
+//                    new InputStreamReader(inputStream, Charset.forName("UTF-8")));
+//
+//            char[] bodyCharBuffer = new char[1024];
+//            int len = 0;
+//            while ((len = reader.read(bodyCharBuffer)) != -1) {
+//                sb.append(new String(bodyCharBuffer, 0, len));
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            if (inputStream != null) {
+//                try {
+//                    inputStream.close();
+//                } catch (IOException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//            if (reader != null) {
+//                try {
+//                    reader.close();
+//                } catch (IOException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//        }
+//        return sb.toString();
+//    }
+
+
+
+
+
+
+
+
+
+
+
+	
+}

+ 97 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/intercepter/WebHttpServletRequestWrapper.java

@@ -0,0 +1,97 @@
+package com.xxh.cloud.framework.security.intercepter;
+
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.util.*;
+
+public class WebHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+	//
+	private  byte[] body;
+
+	//
+	private String content;
+
+	//
+	private final Map<String, String> customHeaders;
+	
+
+    public WebHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
+        super(request);
+        this.customHeaders = new HashMap<String, String>();
+        this.content= HttpRequestUtil.getBodyContent(request);
+        this.body = this.content.getBytes(Charset.forName("UTF-8"));
+    }
+    
+    
+    public void putHeader(String name, String value){
+        this.customHeaders.put(name, value);
+    }
+
+    @Override
+    public String getHeader(String name) {
+        String headerValue = customHeaders.get(name);
+        if (headerValue != null){
+            return headerValue;
+        }
+        return ((HttpServletRequest) getRequest()).getHeader(name);
+    }
+
+    @Override
+    public Enumeration<String> getHeaderNames() {
+        Set<String> set = new HashSet<String>(customHeaders.keySet());
+        @SuppressWarnings("unchecked")
+        Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
+        while (e.hasMoreElements()) {
+            String n = e.nextElement();
+            set.add(n);
+        }
+        return Collections.enumeration(set);
+    }
+
+    /***/
+    public String getBodyContent() {
+        return this.content;
+    }
+
+    /***/
+    public void setBodyContent(String content){
+        this.content=content;
+        this.body = this.content.getBytes(Charset.forName("UTF-8"));
+    }
+    
+    @Override
+    public BufferedReader getReader() throws IOException {
+        return new BufferedReader(new InputStreamReader(getInputStream()));
+    }
+ 
+    @Override
+    public ServletInputStream getInputStream() throws IOException {
+        final ByteArrayInputStream bais = new ByteArrayInputStream(this.body);
+        return new ServletInputStream() {
+            @Override
+            public int read() throws IOException {
+                return bais.read();
+            }
+            @Override
+            public boolean isFinished() {
+                return false;
+            }
+            @Override
+            public boolean isReady() {
+                return false;
+            }
+            @Override
+            public void setReadListener(ReadListener readListener) {
+            }
+        };
+    }
+	
+}

+ 34 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/service/RsaKeyService.java

@@ -0,0 +1,34 @@
+package com.xxh.cloud.framework.security.service;
+
+public interface RsaKeyService {
+
+
+
+    /**
+     * 数据是否要加密
+     * */
+    public boolean isRespDataEncode();
+
+
+    /**
+     * 应用服务端版本号
+     * */
+    public String getApplicationVersion();
+
+
+    /**
+     * RSA pub key
+     * */
+    public String getRespRSAPubKey();
+
+    /**
+     *RSA pri key
+     * */
+    public String getRespRSAPriKey();
+
+
+
+
+
+
+}

+ 70 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/service/impl/RsaKeyServiceImpl.java

@@ -0,0 +1,70 @@
+package com.xxh.cloud.framework.security.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.constant.YN;
+import com.xxh.cloud.framework.common.redis.RedisUtils;
+import com.xxh.cloud.framework.common.utils.HttpContextUtils;
+import com.xxh.cloud.framework.security.bean.RsaPubPriKeyModel;
+import com.xxh.cloud.framework.security.config.SecurityConfig;
+import com.xxh.cloud.framework.security.service.RsaKeyService;
+import com.xxh.cloud.framework.security.utils.CacheKeys;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+@Service
+public class RsaKeyServiceImpl implements RsaKeyService {
+
+
+    @Autowired
+    private RedisUtils redisUtils;
+
+    @Autowired
+    private SecurityConfig securityConfig;
+
+    @Override
+    public boolean isRespDataEncode() {
+        if(securityConfig.isFilterEnabled()){
+            String signFlag = HttpContextUtils.getRequest().getHeader("sign_flag");
+            System.out.println("++++++ 是否需求签名 SIGN_FLAG = "+signFlag);
+            if(StrUtil.isNotEmpty(signFlag) && YN.YES.getCode().equals(signFlag)){
+                return true;
+            }else {
+                return false;
+            }
+        }else {
+            return false;
+        }
+    }
+
+    @Override
+    public String getApplicationVersion() {
+        return securityConfig.getAppVersion();
+    }
+
+    @Override
+    public String getRespRSAPubKey() {
+        RsaPubPriKeyModel entity=this.getRsaKeyByCache();
+        return entity==null?null:entity.getRespPubKey();
+    }
+
+    @Override
+    public String getRespRSAPriKey() {
+        RsaPubPriKeyModel entity=this.getRsaKeyByCache();
+        return entity==null?null:entity.getRespPriKey();
+    }
+
+    private RsaPubPriKeyModel getRsaKeyByCache(){
+        String cacheKey= CacheKeys.getRsaKey();
+        String token = HttpContextUtils.getRequest().getHeader("token");
+        if (StringUtils.hasText(token)) {
+            cacheKey= CacheKeys.getRsaKey(token,true);
+        }
+        RsaPubPriKeyModel data= (RsaPubPriKeyModel) redisUtils.get(cacheKey);
+        return data;
+    }
+
+
+
+
+}

+ 54 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/CacheKeys.java

@@ -0,0 +1,54 @@
+package com.xxh.cloud.framework.security.utils;
+
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.digest.DigestUtil;
+
+public class CacheKeys {
+
+    public static String getUserToken() {
+        return StrUtil.format("AUK_{}", IdUtil.getSnowflake(1, 1).nextIdStr());
+    }
+
+    public static String getUserIdCacheKey(String id) {
+        return "UTK_" + id;
+    }
+
+
+    public static String RsaPubPriKey="RSA:K:PP";
+
+
+    /**
+     *  RSA Key
+     *  @param tonken
+     *  @param  isUserKey :是否每个用户一个证书
+     * */
+    public static String getRsaKey(String tonken,boolean isUserKey){
+        if(!isUserKey){
+            return CacheKeys.RsaPubPriKey;
+        }
+        if(StrUtil.isEmpty(tonken)){
+            return CacheKeys.RsaPubPriKey;
+        }
+        String md5Str= DigestUtil.md5Hex(tonken);
+        return StrUtil.format("RSA:K:{}",md5Str.toUpperCase());
+    }
+
+
+    /**
+     * RSA Key (全局统一证书)
+     * */
+    public static String getRsaKey(){
+        return getRsaKey(null,false);
+    }
+
+    /**
+     * RSA Key (一人一证)
+     * */
+    public static String getRsaKey(String tonken){
+        return getRsaKey(tonken,true);
+    }
+
+
+
+}

+ 23 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/RegexUtils.java

@@ -0,0 +1,23 @@
+package com.xxh.cloud.framework.security.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class RegexUtils {
+
+	public static boolean isAuthc(String val,String regex) {
+		if(val.trim().equals(regex.trim())) {
+			return true;
+		}
+		String p_str1=regex.replaceAll("\\*\\*", "#B#");
+		String p_str2=p_str1.replaceAll("\\*", "#A#");
+		String p_str3=p_str2.replaceAll("#B#", ".*");
+		String p_str4=p_str3.replaceAll("#A#", ".[^/]*");
+//		System.out.println(p_str4);
+        Pattern pattern = Pattern.compile(p_str4);  
+        Matcher matcher = pattern.matcher(val);  
+		return  matcher.matches();
+	}
+	
+	
+}

+ 310 - 0
xx-config-framework/src/main/java/com/xxh/cloud/framework/security/utils/SecurityUtils.java

@@ -0,0 +1,310 @@
+package com.xxh.cloud.framework.security.utils;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.core.util.HexUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.asymmetric.KeyType;
+import cn.hutool.crypto.asymmetric.RSA;
+import cn.hutool.crypto.symmetric.AES;
+import cn.hutool.crypto.symmetric.DES;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.utils.SpringContextUtils;
+import com.xxh.cloud.framework.security.bean.RsaPubPriKeyModel;
+import com.xxh.cloud.framework.security.service.RsaKeyService;
+
+import java.security.KeyPair;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SecurityUtils {
+
+
+    /**获取 RSA Key服务Bean*/
+    private static RsaKeyService getRsaKeyService(){
+        try {
+            RsaKeyService rsaKeyService= SpringContextUtils.getBean(RsaKeyService.class);
+            if(rsaKeyService==null){
+                throw  new BusinessException(BusinessBaseErrorEnum.INTERNAL_SERVER_ERROR,"Response生成器配置错误");
+            }
+            return  rsaKeyService;
+        }catch (Exception e){
+            e.printStackTrace();
+            throw  new BusinessException(BusinessBaseErrorEnum.INTERNAL_SERVER_ERROR,"Response生成器配置错误");
+        }
+    }
+
+
+
+    /**
+     * BaseResult 数据加密
+     * */
+    public static  Object encryptBaseResultData(Object entity){
+        if(entity==null){
+            return null;
+        }
+        RsaKeyService rsaKeyService= SecurityUtils.getRsaKeyService();
+        if(rsaKeyService.isRespDataEncode()){ //加密
+            String rsaRespPupKey= rsaKeyService.getRespRSAPubKey();
+            if(StrUtil.isEmpty(rsaRespPupKey)){
+                throw  new BusinessException(BusinessBaseErrorEnum.INTERNAL_SERVER_ERROR,"Response生成器配置错误");
+            }
+            String version= rsaKeyService.getApplicationVersion();
+            Map<String,String> data=SecurityUtils.encryptResponseData(KeyType.PublicKey, rsaRespPupKey,entity,version);
+            return data;
+        }else {
+            return entity;
+        }
+
+    }
+
+
+    /**
+     * BaseResult 数据加密
+     * */
+    public static Map<String,String> encryptResponseData(KeyType keyType, String key, Object entity, String version){
+        Map<String,String> data=new HashMap<>();
+        if(entity==null){
+            data.put("k","");
+            data.put("t","");
+            data.put("v",version);
+            return data;
+        }
+        String content= JSONObject.toJSONString(entity);
+        String aseKey=SecurityUtils.getAesKey16();
+        data.put("k",SecurityUtils.rsaEncode2Base64(keyType,key,aseKey));
+        data.put("t",SecurityUtils.aesEncryptBase64(aseKey,content));
+        data.put("v",version);
+        return data;
+    }
+
+
+
+    //=======================================DES
+    /**
+     * DES Key 32
+     * */
+    public static String getDesKey32(){
+
+        return RandomUtil.randomString(32);
+
+    }
+
+    /**
+     * DES Key 24
+     * */
+    public static String getDesKey24(){
+        return RandomUtil.randomString(24);
+    }
+
+    /**
+     * DES 加密 (返回 base64)
+     * */
+    public static String desEncryptBase64(String key ,String content){
+        DES des = SecureUtil.des(key.getBytes());
+        return des.encryptBase64(content);
+    }
+
+    /**
+     * DES 解密 (输入 base64, hex16)
+     * */
+    public static String desDecryptStr(String key ,String content){
+        DES des = SecureUtil.des(key.getBytes());
+        return des.decryptStr(content);
+    }
+
+
+
+    //=======================================AES
+
+    /**
+     * AES Key 32
+     * */
+    public static String getAesKey32(){
+        return RandomUtil.randomString(32);
+    }
+
+    /**
+     * AES Key 16
+     * */
+    public static String getAesKey16(){
+        return RandomUtil.randomString(16);
+    }
+
+
+    /**
+     * AES 加密 (base 64)
+     * */
+    public static String aesEncryptBase64(String key ,String content){
+        AES aes =  SecureUtil.aes(key.getBytes());
+        return aes.encryptBase64(content,  CharsetUtil.CHARSET_UTF_8);
+    }
+
+
+    /**
+     * AES 解密 (输入 base64, hex16)
+     * */
+    public static String aesDecryptStr(String key ,String content){
+        AES aes =  SecureUtil.aes(key.getBytes());
+        return  aes.decryptStr(content, CharsetUtil.CHARSET_UTF_8);
+    }
+
+    //=======================================RSA
+    /**
+     * RSA 加密(返回字节数组)
+     * */
+    public static byte[] rsaEncode2Byte(KeyType keyType, String key, String content){
+        if(StrUtil.isEmpty(content)){
+            return null;
+        }
+        RSA rsa =null;
+        if(KeyType.PublicKey==keyType){
+            rsa = new RSA(null,key);
+        }
+        if(KeyType.PrivateKey==keyType){
+            rsa = new RSA(key,null);
+        }
+
+        byte[] encrypt = rsa.encrypt(StrUtil.bytes(content, CharsetUtil.CHARSET_UTF_8), keyType);
+        return encrypt;
+    }
+
+    /**
+     * RSA 加密 (加密内容base64)
+     * */
+    public static String  rsaEncode2Base64(KeyType keyType, String key, String content){
+        byte[] encrypt =rsaEncode2Byte(keyType,key,content);
+        String data= Base64.encode(encrypt);
+        return data;
+    }
+
+
+    /**
+     * RSA 解密 (内容字节数组)
+     * */
+    public static String rsaDecode2Byte(KeyType keyType, String key, byte[] content){
+        if(content.length<=0){
+            return null;
+        }
+        RSA rsa =null;
+        if(KeyType.PublicKey==keyType){
+            rsa = new RSA(null,key);
+        }
+        if(KeyType.PrivateKey==keyType){
+            rsa = new RSA(key,null);
+        }
+
+        byte[] decrypt = rsa.decrypt(content, keyType);
+        return StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8);
+    }
+
+    /**
+     * RSA 解密 (内容:字符串【base64】)
+     * */
+    public static String rsaDecode2Base64(KeyType keyType, String key, String content){
+        if(StrUtil.isEmpty(content)){
+            return content;
+        }
+        byte[] encrypt = Base64.decode(content);
+        return rsaDecode2Byte(keyType,key,encrypt);
+    }
+
+
+
+    /**
+     * 生成RSA公钥和私钥
+     * */
+    public static RsaPubPriKeyModel generateRSAKey(String version){
+        RsaPubPriKeyModel  data=new RsaPubPriKeyModel();
+        data.setVersion(version);
+
+        Map<String,String> reqKeyMap=  SecurityUtils.generateRSAKeyPairBy64();
+        data.setReqPubKey(reqKeyMap.get("Public"));
+        data.setReqPriKey(reqKeyMap.get("Private"));
+
+        Map<String,String> respKeyMap=  SecurityUtils.generateRSAKeyPairBy64();
+        data.setRespPubKey(respKeyMap.get("Public"));
+        data.setRespPriKey(respKeyMap.get("Private"));
+
+
+        return data;
+
+    }
+
+    /**
+     * 生成RSA公钥和私钥(base64)
+     * */
+    public static Map<String,String> generateRSAKeyPairBy64(){
+        KeyPair pair = SecureUtil.generateKeyPair("RSA");
+        Map<String,String> data=new HashMap<>();
+        data.put("Private", Base64.encode(pair.getPrivate().getEncoded()));
+        data.put("Public", Base64.encode(pair.getPublic().getEncoded()));
+        return data;
+    }
+
+
+    /**
+     * 生成RSA公钥和私钥(hex 16 16进制)
+     * */
+    public static Map<String,String> generateRSAKeyPairByHex16(){
+        KeyPair pair = SecureUtil.generateKeyPair("RSA");
+        Map<String,String> data=new HashMap<>();
+        data.put("Private", HexUtil.encodeHexStr(pair.getPrivate().getEncoded()));
+        data.put("Public", HexUtil.encodeHexStr(pair.getPublic().getEncoded()));
+        return data;
+    }
+
+
+
+
+
+
+
+
+    public static void main(String[] args) {
+        
+        // 请求数据公钥私钥
+        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSod8xMv9qW/zkUVZJC3hGJf8eosEzKCjatUAU4kgv1iwL+wsPkqxNSZC5FGILrLBAvlFjNwtPKxa+XFSXJdD89VGLzYfDl8FHqGW1rr3cM2TLGRlmAhRQz4hz/Ng2HIhyrgP+fToLvn2/36RfvGvXMmLOIQQuzYdLk9FqsOmSCwIDAQAB";
+        String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJKh3zEy/2pb/ORRVkkLeEYl/x6iwTMoKNq1QBTiSC/WLAv7Cw+SrE1JkLkUYgussEC+UWM3C08rFr5cVJcl0Pz1UYvNh8OXwUeoZbWuvdwzZMsZGWYCFFDPiHP82DYciHKuA/59Ogu+fb/fpF+8a9cyYs4hBC7Nh0uT0Wqw6ZILAgMBAAECgYAbA6uE+upHhA8BWWLWLkDIW7O2xzFk5V8xe/cEYfP+rCyNQID3K4SG8KizEGhH0lbedrGz3647taqJA6Wp+xOXXzGce5wvTAJcOlzjneRwIRp+Mpq1WXKNmMULfKF1H+O7ftOxqtjuH4gzsD/TE7OzhlgHFcbVX4LLy6iY4qwToQJBANZbGDz+i7lp+R6dP3RvXK3eLcMFVLBp/BNA9IA9+vMtPKRwKqPJPeO+dci6pEiL5jGxlPp6dhBLR1YI4TWYM4kCQQCvHpLVbiT+fc4/S7+oLWEVmvvgYoSoYtBRiCkSZl/wz+F4Os8A8xg5LThaxYhScWhUc7SYnA8GwuwPjarJBq/zAkA/LmiNieW7SA4ixOywMCbcJLHOWuLkgMjJEAtBRYOTa9EFEv6ueiGg4EGtYb4MmBfIq/QihDgKg3XKWSGwf2UpAkBBY2IibaFEoYccnVUwH9mrbpZ0P3UXRuZQO05Sv4U9bvHaqeLXkO3Pk7ICOtXfKtdxCU862LLHrIrmd9h4fZW/AkBFU87MVeJvr1pYdxnpL2D9PvL8VX8DPbYhGUl79YIYA6B+uNZ98llZlN6/NFqBuvJHj4wnWrVyuXeIOTFoEYCa";
+    
+        // 响应数据公钥私钥
+        // String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOT0Fz9b7JnlR8OnKQQE8rKfX0vBgje8n+eHfuTxB+gXQBgQANlkOdA9VcsNCdEBH9bF6jgAR96k5wa37cViB+ySyyulZfyZaLfFGdiGyPTHDxQ5GvKDCbBe1FZm4cVFleJej7iMt3GNctdMz4IMVQ67m8/6KvfdI2FCi6jyPWiQIDAQAB";
+        // String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI5PQXP1vsmeVHw6cpBATysp9fS8GCN7yf54d+5PEH6BdAGBAA2WQ50D1Vyw0J0QEf1sXqOABH3qTnBrftxWIH7JLLK6Vl/Jlot8UZ2IbI9McPFDka8oMJsF7UVmbhxUWV4l6PuIy3cY1y10zPggxVDrubz/oq990jYUKLqPI9aJAgMBAAECgYA5kkSndeZ+SGhjbX3Fb87XZn1TSfj1+fFo2jGinifNFe/pX9e2p3CpB9D8U6fBsquke3/54yNuESk0f7htyQYRyMKThGYB35M66ETlnT2D3G9tlgRWn0Qk4mvd5hqSFoI5KyhtmHreOvtP3Qc4Cgp9pQGnz1m2BDBuTN7cbC8SEQJBANtHXvZJc3j8YxOWvsyRLevNDG6GGWK7qDl32c8fJmIYNQ+MGeNHnkulQpDlIA+2dtyvBrA3iOhqkuv/nNM2Ei0CQQCmJCnXXclWJL2X9SSZx+xcfElGidONSs9Mj/1Qc2iu+w3TZ6Pj0/tZ0vwaXNc71khNU9YJ4h1EUnUxcCjWcDtNAkBx5aN8t/BDwozP6vgWF77LgUlYy0y6TRD3MLqw69QrFbnR5oq31EZzslZeHrVFlBgvTrZhp6b0Wg8QiEf0KVzNAkBqjUDkZbrNa4zImyjZE3YMLo2UFqq9sB/Y+3O7l/ioWEyaq5pZcEeAaSbUBXzoXFpMdZsNBZ49hiCxDzyxopL1AkBmehzquNV7R4VONj6bMlnhiwWirrPuWpRN2LBIiDbktOkvCUTn7GToNmcmpgth+x9eaX4mITarw453Uhx6QBF2";
+        
+        // 需要加密的数据
+        Map<String, Object> dataMap = new HashMap<>();
+        dataMap.put("userName", "liulaoban");
+        dataMap.put("password", "abc123.com");
+        dataMap.put("captchaVerification", "ICc8a6daf4890149db9791d7e373b6858e");
+        dataMap.put("wordVCode", "1111");
+
+        // 加密
+        Map<String,String> data = SecurityUtils.encryptResponseData(KeyType.PublicKey, publicKey, dataMap, "1");
+        String encryptData = JSON.toJSONString(data);
+        System.out.println("加密data:" + encryptData);
+
+        System.out.println("------");
+
+        // 解密
+        String k = SecurityUtils.rsaDecode2Base64(KeyType.PrivateKey, privateKey, data.get("k"));
+        System.out.println("解密key === " + k);
+        String d = SecurityUtils.aesDecryptStr(k, data.get("t"));
+        System.out.println("解密data === " + d);
+    }
+
+    // 生成非对称加密公钥私钥
+    private void generateKeyPair() {
+        // 生成非对称加密公钥私钥
+        KeyPair kp = SecureUtil.generateKeyPair("rsa");
+        System.out.println("公钥:" + Base64.encode(kp.getPublic().getEncoded()));
+        System.out.println("-----");
+        System.out.println("私钥:" + Base64.encode(kp.getPrivate().getEncoded()));
+    }
+
+}

+ 31 - 0
xx-config-kafka/pom.xml

@@ -0,0 +1,31 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>xx-config-kafka</artifactId>
+    <packaging>jar</packaging>
+
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.kafka</groupId>
+            <artifactId>spring-kafka</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.fastjson2</groupId>
+            <artifactId>fastjson2</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>

+ 449 - 0
xx-config-kafka/src/main/java/com/xxh/cloud/framework/mq/kafka/KafkaProducerUtils.java

@@ -0,0 +1,449 @@
+package com.xxh.cloud.framework.mq.kafka;
+
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.util.ArrayUtil;
+import com.alibaba.fastjson2.JSON;
+import lombok.extern.log4j.Log4j2;
+import org.apache.kafka.clients.admin.*;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.KafkaFuture;
+import org.apache.kafka.common.TopicPartitionInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.support.SendResult;
+import org.springframework.stereotype.Component;
+import org.springframework.util.concurrent.ListenableFuture;
+import org.springframework.util.concurrent.ListenableFutureCallback;
+
+import javax.annotation.PostConstruct;
+import java.util.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * https://blog.csdn.net/cold___play/article/details/132398946?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-2-132398946-blog-125011879.235%5Ev38%5Epc_relevant_anti_vip_base&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-2-132398946-blog-125011879.235%5Ev38%5Epc_relevant_anti_vip_base&utm_relevant_index=4
+ *
+ * https://masiyi.blog.csdn.net/article/details/121856703?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-16-121856703-blog-127277614.235%5Ev38%5Epc_relevant_anti_vip_base&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-16-121856703-blog-127277614.235%5Ev38%5Epc_relevant_anti_vip_base&utm_relevant_index=22
+ *
+ *
+ * */
+@Log4j2
+@Component
+public class KafkaProducerUtils {
+
+    private static final String PUSH_MSG_LOG = "准备发送消息为:{}";
+
+
+    @Autowired
+    private KafkaTemplate<String,Object> kafkaTemplate;
+
+
+    @Value("${spring.kafka.bootstrap-servers}")
+    private String springKafkaBootstrapServers;
+
+    private AdminClient adminClient;
+
+
+    private String toJSONString(Object obj){
+        return JSON.toJSONString(obj);
+    }
+
+
+    /**
+     * 初始化AdminClient
+     * '@PostConstruct该注解被用来修饰一个非静态的void()方法。
+     * 被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。
+     * PostConstruct在构造函数之后执行,init()方法之前执行。
+     */
+    @PostConstruct
+    private void initAdminClient() {
+        System.out.println(" +++++++ Kafka Init AdminClient");
+        log.debug(" +++++++ Kafka Init AdminClient");
+        Map<String, Object> props = new HashMap<>();
+        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, springKafkaBootstrapServers);
+        adminClient = KafkaAdminClient.create(props);
+    }
+
+    /**
+     * 获取全部topic
+     */
+    public List<String> getAllTopic() {
+        try {
+            return adminClient.listTopics().listings().get().stream().map(TopicListing::name).collect(Collectors.toList());
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        return ListUtil.empty();
+    }
+
+
+
+    /**
+     * 如果没有topic,则创建一个
+     * @param topicName :
+     * @param partitionNum : 分区
+     * @param replicaNum : 副本
+     * @return org.apache.kafka.clients.admin.CreateTopicsResult
+     */
+    public Boolean createTopic(String topicName, int partitionNum, int replicaNum){
+        KafkaFuture<Set<String>> topics = adminClient.listTopics().names();
+        try {
+            if (topics.get().contains(topicName)) {
+                return true;
+            }
+            System.out.println("++++++++++++ 创建主题 ++++++++++++++");
+            NewTopic newTopic = new NewTopic(topicName, partitionNum, (short) replicaNum);
+            adminClient.createTopics(Collections.singleton(newTopic));
+            return true;
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+            Thread.currentThread().interrupt();
+            return false;
+        }
+    }
+
+
+    /**
+     * 新增topic,支持批量
+     */
+    public void createTopic(Collection<NewTopic> newTopics) {
+        adminClient.createTopics(newTopics);
+    }
+
+
+
+    /**
+     * 获取指定topic的信息
+     */
+    public String getTopicInfo(String topic) {
+        Collection<String> topics = Collections.singleton(topic);
+        return getTopicInfo(topics);
+    }
+
+    /**
+     * 获取指定topic的信息
+     */
+    public String getTopicInfo(Collection<String> topics) {
+        AtomicReference<String> info = new AtomicReference<>("");
+        try {
+            adminClient.describeTopics(topics).all().get().forEach((topic, description) -> {
+                for (TopicPartitionInfo partition : description.partitions()) {
+                    info.set(info + partition.toString() + "\n");
+                }
+            });
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        return info.get();
+    }
+
+
+
+
+    /**
+     *
+     * */
+    public Boolean deleteTopic(String topicName){
+        KafkaFuture<Set<String>> topics = adminClient.listTopics().names();
+        try {
+            if (!topics.get().contains(topicName)) {
+                return true;
+            }
+            adminClient.deleteTopics(Collections.singleton(topicName));
+            return true;
+        }catch(Exception e) {
+            e.printStackTrace();
+            Thread.currentThread().interrupt();
+            return false;
+        }
+    }
+
+
+    /**
+     * 传入topic名称,json格式字符串的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param jsonStr : 消息json字符串
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, String jsonStr) {
+        createTopic(topicName, 5, 1);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future= kafkaTemplate.send(new ProducerRecord<>(topicName,jsonStr));
+        return dealSendResult(future);
+    }
+
+
+
+    /**
+     * 传入topic名称,json格式字符串数组的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param jsonStrs : 消息json字符串数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, String[] jsonStrs) {
+        createTopic(topicName, 5, 1);
+        int msgLength = jsonStrs.length;
+        Boolean[] success = new Boolean[msgLength];
+        for (int i = 0; i < msgLength; i++) {
+            String jsonStr = jsonStrs[i];
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                    jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+
+
+    /**
+     * 传入topic名称,消息对象,生产者进行发送
+     * @param topicName : topic名称
+     * @param obj : 消息对象
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, Object obj) {
+        createTopic(topicName, 5, 1);
+        String jsonStr = toJSONString(obj);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                jsonStr));
+
+        return dealSendResult(future);
+    }
+
+
+    /**
+     * 传入topic名称,消息对象数组,生产者进行发送
+     * @param topicName : topic名称
+     * @param list : 消息对象数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, List<Object> list) {
+        createTopic(topicName, 5, 1);
+        Boolean[] success = new Boolean[list.size()];
+        for (int i = 0; i < list.size(); i++) {
+            Object obj = list.get(i);
+            String jsonStr = toJSONString(obj);
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                    jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+
+
+    /**
+     * 传入topic名称,json格式字符串的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param key : 消息key
+     * @param jsonStr : 消息json字符串
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, String key, String jsonStr) {
+        createTopic(topicName, 5, 1);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                key, jsonStr));
+
+        return dealSendResult(future);
+    }
+
+    /**
+     * 传入topic名称,json格式字符串数组的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param key : 消息key
+     * @param jsonStrs : 消息json字符串数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, String key, String[] jsonStrs) {
+        createTopic(topicName, 5, 1);
+        int msgLength = jsonStrs.length;
+        Boolean[] success = new Boolean[msgLength];
+        for (int i = 0; i < msgLength; i++) {
+            String jsonStr = jsonStrs[i];
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                    key, jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+    /**
+     * 传入topic名称,消息对象,生产者进行发送
+     * @param topicName : topic名称
+     * @param key : 消息key
+     * @param obj : 消息对象
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, String key, Object obj) {
+        createTopic(topicName, 5, 1);
+        String jsonStr = toJSONString(obj);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                key, jsonStr));
+
+        return dealSendResult(future);
+    }
+
+    /**
+     * 传入topic名称,消息对象数组,生产者进行发送
+     * @param topicName : topic名称
+     * @param key : 消息key
+     * @param list : 消息对象数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, String key, List<Object> list) {
+        createTopic(topicName, 5, 1);
+        Boolean[] success = new Boolean[list.size()];
+        for (int i = 0; i < list.size(); i++) {
+            Object obj = list.get(i);
+            String jsonStr = toJSONString(obj);
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                    key, jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+
+
+    /**
+     * 传入topic名称,json格式字符串的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param partition : 消息发送分区
+     * @param key : 消息key
+     * @param jsonStr : 消息json字符串
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, int partition, String key, String jsonStr) {
+        createTopic(topicName, 5, 1);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                partition, key, jsonStr));
+
+        return dealSendResult(future);
+    }
+
+
+    /**
+     * 传入topic名称,json格式字符串数组的消息,生产者进行发送
+     * @param topicName : topic名称
+     * @param partition : 消息发送分区
+     * @param key : 消息key
+     * @param jsonStrs : 消息json字符串数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, int partition, String key, String[] jsonStrs) {
+        createTopic(topicName, 5, 1);
+        int msgLength = jsonStrs.length;
+        Boolean[] success = new Boolean[msgLength];
+        for (int i = 0; i < msgLength; i++) {
+            String jsonStr = jsonStrs[i];
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                    partition, key, jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+    /**
+     * 传入topic名称,消息对象,生产者进行发送
+     * @param topicName : topic名称
+     * @param partition : 消息发送分区
+     * @param key : 消息key
+     * @param obj : 消息对象
+     * @return boolean : 推送是否成功
+     */
+    public boolean sendMessage(String topicName, int partition, String key, Object obj) {
+        createTopic(topicName, 5, 1);
+        String jsonStr = toJSONString(obj);
+        log.info(PUSH_MSG_LOG, jsonStr);
+        //发送消息
+        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(topicName,
+                partition, key, jsonStr));
+
+        return dealSendResult(future);
+    }
+
+    /**
+     * 传入topic名称,消息对象数组,生产者进行发送
+     * @param topicName : topic名称
+     * @param partition : 消息发送分区
+     * @param key : 消息key
+     * @param list : 消息对象数组
+     * @return boolean : 推送是否成功
+     */
+    public Boolean[] sendMessage(String topicName, int partition, String key, List<Object> list) {
+        createTopic(topicName, 5, 1);
+        Boolean[] success = new Boolean[list.size()];
+        for (int i = 0; i < list.size(); i++) {
+            Object obj = list.get(i);
+            String jsonStr = toJSONString(obj);
+            log.info(PUSH_MSG_LOG, jsonStr);
+            //发送消息
+            ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(new ProducerRecord<>(
+                    topicName, partition, key, jsonStr));
+            success[i] = dealSendResult(future);
+        }
+        return success;
+    }
+
+
+
+    /**
+     * 处理消息推送结果
+     * kafkaTemplate提供了一个回调方法addCallback,
+     * 我们可以在回调方法中监控消息是否发送成功 或 失败时做补偿处理
+     * @param future :
+     * @return boolean
+     */
+    private boolean dealSendResult(ListenableFuture<SendResult<String, Object>> future) {
+        final boolean[] success={false};
+
+        future.addCallback(new ListenableFutureCallback<SendResult<String, Object>>() {
+            @Override
+            public void onFailure(Throwable throwable) {
+                //发送失败的处理
+                log.info("生产者 发送消息失败 exMessage:{}", throwable.getMessage());
+                success[0] = false;
+            }
+            @Override
+            public void onSuccess(SendResult<String, Object> result) {
+                //成功的处理
+                log.info("生产者 发送消息成功, topic:{}, partition:{}, offset:{}",
+                        result.getRecordMetadata().topic(),
+                        result.getRecordMetadata().partition(),
+                        result.getRecordMetadata().offset());
+                success[0] = true;
+            }
+        });
+        return success[0];
+    }
+
+
+
+
+
+
+
+
+
+}

+ 46 - 0
xx-config-mybatisplus/pom.xml

@@ -0,0 +1,46 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <artifactId>xx-config-mybatisplus</artifactId>
+
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>com.xxh.cloud</groupId>
+            <artifactId>xx-framework-core</artifactId>
+        </dependency>
+
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+        </dependency>
+
+
+
+    </dependencies>
+
+
+</project>

+ 67 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/DynamicTableNameHandler.java

@@ -0,0 +1,67 @@
+package com.xxh.cloud.framework.common.mybatisplus.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class DynamicTableNameHandler implements TableNameHandler {
+
+
+
+    private static  final  ThreadLocal<String> TableNameSuffix=new ThreadLocal<>();
+
+    private List<String> tableNames;
+
+    public DynamicTableNameHandler(){
+
+    }
+
+    public DynamicTableNameHandler(String ... tableNames){
+        this.tableNames= Arrays.asList(tableNames);
+    }
+
+
+    public static void setTableNameSuffix(String ym){
+        TableNameSuffix.set(ym);
+    }
+
+
+    public static String getTableNameSuffix(){
+        return TableNameSuffix.get();
+    }
+
+
+    public static void removeTableNameSuffix(){
+        TableNameSuffix.remove();
+    }
+
+    @Override
+    public String dynamicTableName(String sql, String tableName) {
+
+//        System.out.println("***************TableNameHandler2**************");
+//        System.out.println("------------SQL");
+//        System.out.println(sql);
+//
+//        System.out.println("------------tableName");
+//        System.out.println(tableName);
+
+        if(this.tableNames.contains(tableName)){
+            String suffix=TableNameSuffix.get();
+            if(StrUtil.isEmpty(suffix)){
+                return tableName;
+            }else {
+                TableNameSuffix.remove();
+                return tableName+"_"+suffix;
+            }
+        }else {
+            return tableName;
+        }
+
+    }
+
+
+
+
+}

+ 65 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/MyMetaObjectHandler.java

@@ -0,0 +1,65 @@
+package com.xxh.cloud.framework.common.mybatisplus.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.xxh.cloud.framework.common.user.LoginUser;
+import com.xxh.cloud.framework.common.user.AuthContextUtils;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Component
+public class MyMetaObjectHandler implements MetaObjectHandler {
+
+
+    private final static String CREATE_DATE = "createDate";
+    private final static String CREATOR = "creator";
+
+    private final static String UPDATE_DATE = "updateDate";
+
+    private final static String UPDATER = "updater";
+
+    private final static String DEPT_ID = "deptId";
+
+
+
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        LoginUser user= AuthContextUtils.getCurrentLoginUser();
+        Date date = new Date();
+
+        if(user!=null){
+            //创建者
+            this.strictInsertFill(metaObject, CREATOR, String.class, user.getId());
+            //创建者所属部门
+            //this.strictInsertFill(metaObject, DEPT_ID, String.class, user.getDeptId());
+            //更新者
+            this.strictInsertFill(metaObject, UPDATER, String.class, user.getId());
+        } else {
+            this.strictInsertFill(metaObject, CREATOR, String.class, "sys");
+            this.strictInsertFill(metaObject, UPDATER, String.class, "sys");
+        }
+
+        //创建时间
+        this.strictInsertFill(metaObject, CREATE_DATE, Date.class, date);
+        //更新时间
+        this.strictInsertFill(metaObject, UPDATE_DATE, Date.class, date);
+
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        LoginUser user= AuthContextUtils.getCurrentLoginUser();
+        Date date = new Date();
+        //更新者
+        if(user!=null){
+            this.strictInsertFill(metaObject, UPDATER, String.class, user.getId());
+        }else {
+            this.strictInsertFill(metaObject, UPDATER, String.class, "sys");
+        }
+        //更新时间
+        this.strictInsertFill(metaObject, UPDATE_DATE, Date.class, date);
+    }
+
+
+}

+ 47 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/config/MybatisPlusConfig.java

@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.xxh.cloud.framework.common.mybatisplus.config;
+
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * mybatis-plus配置
+ */
+@Configuration
+public class MybatisPlusConfig {
+
+    /**
+     * 配置分页等
+     */
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+
+        //todo:动态名称
+        DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor=new DynamicTableNameInnerInterceptor();
+        dynamicTableNameInnerInterceptor.setTableNameHandler(new DynamicTableNameHandler(
+                "r_data_label_rule_call_log", "r_data_label_rule_exe_log","r_data_label_rule_exe_success_info"));
+        mybatisPlusInterceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor);
+
+        // 分页插件
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        // 乐观锁
+        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+        // 防止全表更新与删除
+        mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+        return mybatisPlusInterceptor;
+    }
+
+}

+ 60 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/entity/BaseEntity.java

@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.xxh.cloud.framework.common.mybatisplus.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * mybatisplus
+ * 基础实体类,所有实体都需要继承
+ */
+@Data
+public abstract class BaseEntity implements Serializable {
+
+
+
+    /**
+     * 创建者
+     */
+    @ApiModelProperty(value = "创建者" )
+    @TableField(fill = FieldFill.INSERT)
+    private String creator;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createDate;
+
+    /**
+     * 更新者
+     */
+    @ApiModelProperty(value = "更新者")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String updater;
+
+    /**
+     * 更新时间
+     */
+    @ApiModelProperty(value = "更新时间")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateDate;
+
+
+
+
+}

+ 68 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/page/PageConverter.java

@@ -0,0 +1,68 @@
+package com.xxh.cloud.framework.common.mybatisplus.page;
+
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.xxh.cloud.framework.common.page.PageData;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * mybatisplus
+ * */
+public abstract class PageConverter <R,T> {
+
+
+    public abstract T converter(R entity);
+
+    public PageData<T> getPageData(IPage<R> page){
+        if(page==null){
+            return null;
+        }
+        return this.getPageData(page.getRecords(),page.getTotal(),page.getSize(),page.getPages());
+    }
+
+    public  PageData<T> getPageData(List<R> list, long total, long size,long pages){
+        List<T> targetList = this.sourceToTarget(list);
+        return new PageData<T>(targetList, total, size, pages);
+    }
+
+    public  List<T> sourceToTarget(Collection<R> sourceList){
+        if(sourceList == null){
+            return null;
+        }
+        List<T> targetList = new ArrayList<>();
+        if(CollUtil.isEmpty(sourceList)){
+            return targetList;
+        }
+        for(R source : sourceList){
+             T targetObject = this.converter(source);
+             targetList.add(targetObject);
+        }
+        return targetList;
+    }
+
+
+//    public static void main(String[] args) {
+//        List<PageOneBean> oneList=new ArrayList<>();
+//        oneList.add(new PageOneBean("1"));
+//        oneList.add(new PageOneBean("2"));
+//
+//        PageData<PageTwoBean> data=
+//        new PageConverter<PageOneBean, PageTwoBean>() {
+//            @Override
+//            public PageTwoBean converter(PageOneBean entity) {
+//                return new PageTwoBean(entity.getId());
+//            }
+//        }.getPageData(oneList,2);
+//
+//
+//        System.out.println(JSON.toJSONString(data));
+//
+//    }
+
+
+
+}

+ 59 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/AESEncryptHandler.java

@@ -0,0 +1,59 @@
+package com.xxh.cloud.framework.common.mybatisplus.typehandle;
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.utils.AESUtils;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+
+import java.sql.*;
+
+/**
+ *
+ * */
+@MappedTypes({String.class})
+@MappedJdbcTypes({JdbcType.VARCHAR})
+public class AESEncryptHandler extends BaseTypeHandler<String> {
+
+    // TODO DEMO AES 16位密钥
+    public final static String key = "mybatisplus88888";
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
+        if (StrUtil.isEmpty(parameter)) {
+            ps.setNull(i, Types.VARCHAR);
+        } else {
+            ps.setString(i, AESUtils.encryptBase64(parameter, key));
+        }
+    }
+
+    @Override
+    public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        return decrypt(rs.getString(columnName), rs.wasNull());
+    }
+
+
+    @Override
+    public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        return decrypt(cs.getString(columnIndex), cs.wasNull());
+    }
+
+    @Override
+    public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        return decrypt(rs.getString(columnIndex), rs.wasNull());
+    }
+
+    //字段解密
+    private String decrypt(String rs, boolean rs1) {
+        String columnValue = rs;
+        if (rs1) {
+            return null;
+        }
+        try {
+            return AESUtils.decryptBase64(columnValue, key);
+        } catch (Exception e) {
+            return columnValue;
+        }
+    }
+}

+ 192 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/EncryptionQueryWrapper.java

@@ -0,0 +1,192 @@
+package com.xxh.cloud.framework.common.mybatisplus.typehandle;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.utils.AESUtils;
+import org.springframework.util.StringUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class EncryptionQueryWrapper<T> extends QueryWrapper<T> {
+
+    // TODO DEMO AES 16位密钥
+    public final static String key = "mybatisplus88888";
+
+    //实体类
+    private Class<T> clazz;
+
+    public EncryptionQueryWrapper(Class<T> clazz) {
+        this.clazz = clazz;
+    }
+
+    public EncryptionQueryWrapper<T> eq(boolean condition, String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionQueryWrapper<T>) super.eq(condition, column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.eq(condition, column, val);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> eq(String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionQueryWrapper<T>) super.eq(column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.eq(column, val);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> ne(boolean condition, String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionQueryWrapper<T>) super.ne(condition, column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.ne(condition, column, val);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> ne(String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionQueryWrapper<T>) super.ne(column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.ne(column, val);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> in(boolean condition, String column, String values) {
+        if (encryptionFlg(column) && StringUtils.hasText(values)) {
+            return (EncryptionQueryWrapper<T>) super.in(condition, column, AESUtils.encryptBase64(values, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.in(condition, column, values);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> in(boolean condition, String column, Collection<String> coll) {
+        if (encryptionFlg(column)) {
+            Set<String> values = new HashSet<>();
+            coll.forEach(value->{
+                values.add(AESUtils.encryptBase64(value, key));
+            });
+            return (EncryptionQueryWrapper<T>) super.in(condition, column, values);
+        } else {
+            return (EncryptionQueryWrapper<T>) super.in(condition, column, coll);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> notIn(boolean condition, String column, String values) {
+        if (encryptionFlg(column) && StringUtils.hasText(values)) {
+            return (EncryptionQueryWrapper<T>) super.notIn(condition, column, AESUtils.encryptBase64(values, key));
+        } else {
+            return (EncryptionQueryWrapper<T>) super.notIn(condition, column, values);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> notIn(boolean condition, String column, Collection<String> coll) {
+        if (encryptionFlg(column)) {
+            Set<String> values = new HashSet<>();
+            coll.forEach(value->{
+                values.add(AESUtils.encryptBase64(value, key));
+            });
+            return (EncryptionQueryWrapper<T>) super.notIn(condition, column, values);
+        } else {
+            return (EncryptionQueryWrapper<T>) super.notIn(condition, column, coll);
+        }
+    }
+
+    public EncryptionQueryWrapper<T> like(boolean condition, String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.like(condition, column, val);
+    }
+
+    public EncryptionQueryWrapper<T> like(String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.like(column, val);
+    }
+
+    public EncryptionQueryWrapper<T> ge(boolean condition, String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.ge(condition, column, val);
+    }
+
+    public EncryptionQueryWrapper<T> ge(String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.ge(column, val);
+    }
+
+    public EncryptionQueryWrapper<T> le(boolean condition, String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.le(condition, column, val);
+    }
+
+    public EncryptionQueryWrapper<T> le(String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.le(column, val);
+    }
+
+    public EncryptionQueryWrapper<T> gt(boolean condition, String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.gt(condition, column, val);
+    }
+
+    public EncryptionQueryWrapper<T> gt(String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.gt(column, val);
+    }
+
+    public EncryptionQueryWrapper<T> lt(boolean condition, String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.lt(condition, column, val);
+    }
+
+    public EncryptionQueryWrapper<T> lt(String column, String val) {
+        return (EncryptionQueryWrapper<T>) super.lt(column, val);
+    }
+
+    private Boolean encryptionFlg(String column) {
+        boolean flg = false;
+        try {
+            Field[] fields = clazz.getDeclaredFields();
+            for(Field field : fields) {
+                if (!field.getName().equals(under2camel(column))) {
+                    continue;
+                }
+                Annotation[] annotations = field.getAnnotations();
+                for(Annotation annotation : annotations) {
+                    InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
+                    Field value = invocationHandler.getClass().getDeclaredField("memberValues");
+                    value.setAccessible(true);
+                    Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
+                    if (annotation.annotationType().equals(TableField.class) &&
+                            memberValues.containsKey("value") && memberValues.containsKey("typeHandler") &&
+                            memberValues.get("typeHandler").equals(AESEncryptHandler.class)) {
+                        flg = true;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new BusinessException(e.getMessage());
+        }
+        return flg;
+    }
+
+    /**
+     * 功能:下划线命名转驼峰命名
+     * 将下划线替换为空格,将字符串根据空格分割成数组,再将每个单词首字母大写
+     */
+    private static String under2camel(String s) {
+        String separator = "_";
+        StringBuilder under= new StringBuilder();
+        s = s.toLowerCase().replace(separator, " ");
+        String[] sarr =s.split(" ");
+        for (int i = 0; i < sarr.length; i++) {
+            String value = sarr[i];
+            if (i == 0) {
+                under.append(value);
+            } else {
+                String w = value.substring(0, 1).toUpperCase() + value.substring(1);
+                under.append(w);
+            }
+        }
+        return under.toString();
+    }
+}

+ 200 - 0
xx-config-mybatisplus/src/main/java/com/xxh/cloud/framework/common/mybatisplus/typehandle/EncryptionUpdateWrapper.java

@@ -0,0 +1,200 @@
+package com.xxh.cloud.framework.common.mybatisplus.typehandle;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.utils.AESUtils;
+import org.springframework.util.StringUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * mybatis-加密
+ */
+public class EncryptionUpdateWrapper<T> extends UpdateWrapper<T> {
+
+    // TODO DEMO AES 16位密钥
+    public final static String key = "mybatisplus88888";
+
+    //实体类
+    private Class<T> clazz;
+
+    public EncryptionUpdateWrapper(Class<T> clazz) {
+        this.clazz = clazz;
+    }
+
+    public EncryptionUpdateWrapper<T> set(boolean condition, String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionUpdateWrapper<T>) super.set(condition, column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.set(condition, column, val);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> eq(boolean condition, String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionUpdateWrapper<T>) super.eq(condition, column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.eq(condition, column, val);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> eq(String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionUpdateWrapper<T>) super.eq(column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.eq(column, val);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> ne(boolean condition, String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionUpdateWrapper<T>) super.ne(condition, column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.ne(condition, column, val);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> ne(String column, String val) {
+        if (encryptionFlg(column) && StringUtils.hasText(val)) {
+            return (EncryptionUpdateWrapper<T>) super.ne(column, AESUtils.encryptBase64(val, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.ne(column, val);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> in(boolean condition, String column, String values) {
+        if (encryptionFlg(column) && StringUtils.hasText(values)) {
+            return (EncryptionUpdateWrapper<T>) super.in(condition, column, AESUtils.encryptBase64(values, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.in(condition, column, values);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> in(boolean condition, String column, Collection<String> coll) {
+        if (encryptionFlg(column)) {
+            Set<String> values = new HashSet<>();
+            coll.forEach(value->{
+                values.add(AESUtils.encryptBase64(value, key));
+            });
+            return (EncryptionUpdateWrapper<T>) super.in(condition, column, values);
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.in(condition, column, coll);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> notIn(boolean condition, String column, String values) {
+        if (encryptionFlg(column) && StringUtils.hasText(values)) {
+            return (EncryptionUpdateWrapper<T>) super.notIn(condition, column, AESUtils.encryptBase64(values, key));
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.notIn(condition, column, values);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> notIn(boolean condition, String column, Collection<String> coll) {
+        if (encryptionFlg(column)) {
+            Set<String> values = new HashSet<>();
+            coll.forEach(value->{
+                values.add(AESUtils.encryptBase64(value, key));
+            });
+            return (EncryptionUpdateWrapper<T>) super.notIn(condition, column, values);
+        } else {
+            return (EncryptionUpdateWrapper<T>) super.notIn(condition, column, coll);
+        }
+    }
+
+    public EncryptionUpdateWrapper<T> like(boolean condition, String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.like(condition, column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> like(String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.like(column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> ge(boolean condition, String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.ge(condition, column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> ge(String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.ge(column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> le(boolean condition, String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.le(condition, column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> le(String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.le(column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> gt(boolean condition, String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.gt(condition, column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> gt(String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.gt(column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> lt(boolean condition, String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.lt(condition, column, val);
+    }
+
+    public EncryptionUpdateWrapper<T> lt(String column, String val) {
+        return (EncryptionUpdateWrapper<T>) super.lt(column, val);
+    }
+
+    private Boolean encryptionFlg(String column) {
+        boolean flg = false;
+        try {
+            Field[] fields = clazz.getDeclaredFields();
+            for(Field field : fields) {
+                if (!field.getName().equals(under2camel(column))) {
+                    continue;
+                }
+                Annotation[] annotations = field.getAnnotations();
+                for(Annotation annotation : annotations) {
+                    InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
+                    Field value = invocationHandler.getClass().getDeclaredField("memberValues");
+                    value.setAccessible(true);
+                    Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
+                    if (annotation.annotationType().equals(TableField.class) &&
+                            memberValues.containsKey("value") && memberValues.containsKey("typeHandler") &&
+                            memberValues.get("typeHandler").equals(AESEncryptHandler.class)) {
+                        flg = true;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new BusinessException(e.getMessage());
+        }
+        return flg;
+    }
+
+    /**
+     * 功能:下划线命名转驼峰命名
+     * 将下划线替换为空格,将字符串根据空格分割成数组,再将每个单词首字母大写
+     */
+    private static String under2camel(String s) {
+        String separator = "_";
+        StringBuilder under= new StringBuilder();
+        s = s.toLowerCase().replace(separator, " ");
+        String[] sarr =s.split(" ");
+        for (int i = 0; i < sarr.length; i++) {
+            String value = sarr[i];
+            if (i == 0) {
+                under.append(value);
+            } else {
+                String w = value.substring(0, 1).toUpperCase() + value.substring(1);
+                under.append(w);
+            }
+        }
+        return under.toString();
+    }
+}

+ 30 - 0
xx-config-script/pom.xml

@@ -0,0 +1,30 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>xx-framework-java</artifactId>
+        <groupId>com.xxh.cloud</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>xx-config-script</artifactId>
+    <packaging>jar</packaging>
+
+
+
+    <dependencies>
+        <dependency>
+            <groupId>com.xxh.cloud</groupId>
+            <artifactId>xx-config-framework</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.xxh.cloud</groupId>
+            <artifactId>xx-config-mybatisplus</artifactId>
+        </dependency>
+
+    </dependencies>
+
+
+
+</project>

+ 9 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLAlterDTO.java

@@ -0,0 +1,9 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class EntityDDLAlterDTO extends EntityDDLCreateDTO{
+}

+ 23 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLClearDataDTO.java

@@ -0,0 +1,23 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+
+@Getter
+@Setter
+public class EntityDDLClearDataDTO {
+
+    @ApiModelProperty(value = "数据源分类",required = true)
+    @NotEmpty(message = "数据源分类不能为空")
+    private String dataSourceType;
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+
+}

+ 53 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLCreateDTO.java

@@ -0,0 +1,53 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityDDLCreateDTO {
+
+    @ApiModelProperty(value = "数据源分类",required = true)
+    @NotEmpty(message = "数据源分类不能为空")
+    private String dataSourceType;
+
+
+    @ApiModelProperty(value = "库编号",required = true)
+    @NotEmpty(message = "库编号不能为空")
+    private String database;
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表名称",required = true)
+    @NotEmpty(message = "表名称不能为空")
+    private String tableName;
+
+
+    @ApiModelProperty(value = "属性列表",required = true)
+    @NotNull(message = "属性列表不能为空")
+    private List<EntityDDLCreatePropertyDTO> props;
+
+
+    public void addProp(EntityDDLCreatePropertyDTO item){
+        if(this.props==null){
+            this.props=new ArrayList<>();
+        }
+        if(item!=null){
+            this.props.add(item);
+        }
+    }
+
+
+
+
+
+}

+ 105 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLCreatePropertyDTO.java

@@ -0,0 +1,105 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.common.constant.YN;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableDataTypeEnum;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableColumnBaseEnum;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class EntityDDLCreatePropertyDTO {
+
+    /**
+     *  字段名称
+     * */
+    private String name;
+
+    /**
+     * 字段编号
+     * */
+    private String code;
+
+    /**
+     * 字段数据类型
+     * */
+    private String dataType;
+
+
+    /**
+     * 字段数据类型长度
+     * */
+    private int dataTypeSize;
+
+    /**
+     *  是否主健
+     * */
+    private String priKey;
+
+    /**
+     * 隐藏 -del
+     * */
+    private String hidden;
+
+
+    public EntityDDLCreatePropertyDTO(String code, String name, TableDataTypeEnum dataType, int dataTypeSize, YN priKey){
+            this.code=code;
+            this.name=name;
+            this.dataType=dataType.getCode();
+            this.dataTypeSize=dataTypeSize;
+            this.priKey=priKey.getCode();
+    }
+
+    public EntityDDLCreatePropertyDTO(String code, String name, TableDataTypeEnum dataType, int dataTypeSize){
+        this.code=code;
+        this.name=name;
+        this.dataType=dataType.getCode();
+        this.dataTypeSize=dataTypeSize;
+        this.priKey=YN.NO.getCode();
+    }
+
+    public EntityDDLCreatePropertyDTO(String code, String name, TableDataTypeEnum dataType){
+        this.code=code;
+        this.name=name;
+        this.dataType=dataType.getCode();
+        this.dataTypeSize=0;
+        this.priKey=YN.NO.getCode();
+    }
+
+    public EntityDDLCreatePropertyDTO(String code, String name, String dataType){
+        this.code=code;
+        this.name=name;
+        this.dataType=dataType;
+        this.dataTypeSize=0;
+        this.priKey=YN.NO.getCode();
+    }
+
+    /**
+     * 基础定义
+     * */
+    public EntityDDLCreatePropertyDTO(TableColumnBaseEnum tableColumnBaseEnum){
+        this.code= tableColumnBaseEnum.getCode();
+        this.name= tableColumnBaseEnum.getName();
+        this.dataType= tableColumnBaseEnum.getType().getCode();
+        this.dataTypeSize=0;
+        this.priKey=YN.NO.getCode();
+    }
+
+    /**
+     * 基础定义
+     * */
+    public EntityDDLCreatePropertyDTO(TableColumnBaseEnum tableColumnBaseEnum, int dataTypeSize, YN priKey){
+        this.code= tableColumnBaseEnum.getCode();
+        this.name= tableColumnBaseEnum.getName();
+        this.dataType= tableColumnBaseEnum.getType().getCode();
+        this.dataTypeSize=dataTypeSize;
+        this.priKey=priKey.getCode();
+    }
+
+    public EntityDDLCreatePropertyDTO(){
+
+    }
+
+
+
+}

+ 21 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityDDLDropDTO.java

@@ -0,0 +1,21 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+
+@Getter
+@Setter
+public class EntityDDLDropDTO {
+
+    @ApiModelProperty(value = "数据源分类",required = true)
+    @NotEmpty(message = "数据源分类不能为空")
+    private String dataSourceType;
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+}

+ 23 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateDeleteByIdDTO.java

@@ -0,0 +1,23 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+
+@Getter
+@Setter
+public class EntityOperateDeleteByIdDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+
+    @ApiModelProperty(value = "表数据ID",required = true)
+    @NotEmpty(message = "表数据ID不能为空")
+    private String id;
+
+
+}

+ 24 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateDeleteByWhereDTO.java

@@ -0,0 +1,24 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereAndOrBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateDeleteByWhereDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+
+    @ApiModelProperty(value = "删除条件")
+    private List<WhereAndOrBean> where;
+
+
+}

+ 30 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateGetByIdDTO.java

@@ -0,0 +1,30 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.SelectBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateGetByIdDTO {
+
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<SelectBean> select;
+
+
+    @ApiModelProperty(value = "表数据ID",required = true)
+    @NotEmpty(message = "表数据ID不能为空")
+    private String id;
+}

+ 42 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateGetOneDTO.java

@@ -0,0 +1,42 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.*;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateGetOneDTO {
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<SelectBean> select;
+
+    @ApiModelProperty(value = "关联")
+    private List<JoinBean> join;
+
+    @ApiModelProperty(value = "条件")
+    private List<WhereAndOrBean> where;
+
+    @ApiModelProperty(value = "分组")
+    private List<GroupByBean> groupBy;
+
+    @ApiModelProperty(value = "分组后条件")
+    private List<WhereAndOrBean> having;
+
+    @ApiModelProperty(value = "排序")
+    private List<OrderByBean> orderBy;
+
+
+
+}

+ 42 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateListDTO.java

@@ -0,0 +1,42 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.*;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateListDTO {
+
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<SelectBean> select;
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+
+
+
+    private List<JoinBean> join;
+
+    private List<WhereAndOrBean> where;
+
+    private List<GroupByBean> groupBy;
+
+    private List<WhereAndOrBean> having;
+
+    private List<OrderByBean> orderBy;
+
+    private int limit;
+
+
+}

+ 47 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateQueryDTO.java

@@ -0,0 +1,47 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.*;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateQueryDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<SelectBean> select;
+
+
+    @ApiModelProperty(value = "关联")
+    private List<JoinBean> join;
+
+    @ApiModelProperty(value = "条件")
+    private List<WhereAndOrBean> where;
+
+    @ApiModelProperty(value = "分组")
+    private List<GroupByBean> groupBy;
+
+    @ApiModelProperty(value = "分组后条件")
+    private List<WhereAndOrBean> having;
+
+    @ApiModelProperty(value = "排序")
+    private List<OrderByBean> orderBy;
+
+    @ApiModelProperty(value = "页码", example = "1")
+    private int page = 1;
+
+    @ApiModelProperty(value = "每页记录数", example = "10")
+    private int rows = 10;
+
+
+}

+ 32 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateSaveBatchDTO.java

@@ -0,0 +1,32 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.InsertColumnBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+import java.util.Map;
+
+@Getter
+@Setter
+public class EntityOperateSaveBatchDTO {
+
+
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<InsertColumnBean> insert;
+
+    @ApiModelProperty(value = "新增数据",required = true)
+    @NotNull(message = "新增数据不能为空")
+    private List<Map<String,String>> data;
+
+
+}

+ 24 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateSaveDTO.java

@@ -0,0 +1,24 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.InsertBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateSaveDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<InsertBean> insert;
+
+}

+ 32 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateUpdateByIdDTO.java

@@ -0,0 +1,32 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.UpdateBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateUpdateByIdDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<UpdateBean> updates;
+
+    @ApiModelProperty(value = "数据ID",required = true)
+    @NotEmpty(message = "数据ID不能为空")
+    private String id;
+
+
+
+
+
+}

+ 28 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/dto/EntityOperateUpdateByWhereDTO.java

@@ -0,0 +1,28 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.dto;
+
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.UpdateBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereAndOrBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class EntityOperateUpdateByWhereDTO {
+
+    @ApiModelProperty(value = "表编号",required = true)
+    @NotEmpty(message = "表编号不能为空")
+    private String tableCode;
+
+    @ApiModelProperty(value = "表字段",required = true)
+    @NotNull(message = "表字段不能为空")
+    private List<UpdateBean> updates;
+
+    @ApiModelProperty(value = "更新条件")
+    private List<WhereAndOrBean> where;
+
+}

+ 39 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/vos/TableEntityPropertyVO.java

@@ -0,0 +1,39 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.vos;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class TableEntityPropertyVO {
+
+    //字段编号
+    private String code;
+
+    //字段名称
+    private String name;
+
+    //字段类型
+    private String type;
+
+    //字段全类型
+    private String typeFull;
+
+    //字段类型长度
+    private Integer typeSize;
+
+    //是否可为空
+    private String isNull;
+
+    //是否主键
+    private String isPri;
+
+    //表名
+    private String tableName;
+
+
+    //实体类型
+    private String entityDataType;
+
+
+}

+ 25 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/bean/vos/TableEntityVO.java

@@ -0,0 +1,25 @@
+package com.xxh.cloud.framework.script.modules.biz.bean.vos;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class TableEntityVO {
+
+
+    //表编号
+    private String code;
+
+    //表名称
+    private String name;
+
+
+    //
+    private List<TableEntityPropertyVO> props;
+
+
+
+}

+ 48 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/constant/enums/TableColumnBaseEnum.java

@@ -0,0 +1,48 @@
+package com.xxh.cloud.framework.script.modules.biz.constant.enums;
+
+public enum TableColumnBaseEnum {
+
+    ID("id","id", TableDataTypeEnum.MT_String,true),
+
+    ObjectId("object_id","对象ID", TableDataTypeEnum.MT_String,false),
+
+    ObjectType("object_type","对象分类", TableDataTypeEnum.MT_String,false),
+
+    ProjectCode("project_code","项目编号", TableDataTypeEnum.MT_String,false),
+    VersionCode("version_code","版本号", TableDataTypeEnum.MT_String,false),
+    Creator("creator","创建者", TableDataTypeEnum.MT_String,false),
+    CreateDate("create_date","创建时间", TableDataTypeEnum.MT_DateTime,false),
+    Updater("updater","更新者", TableDataTypeEnum.MT_String,false),
+    UpdateDate("update_date","更新时间", TableDataTypeEnum.MT_DateTime,false),
+
+
+    ;
+    private String code;
+    private String name;
+
+    private TableDataTypeEnum type;
+
+    private boolean priKey;
+
+    private TableColumnBaseEnum(String code, String name, TableDataTypeEnum type, boolean priKey) {
+        this.code = code;
+        this.name = name;
+        this.type=type;
+        this.priKey=priKey;
+    }
+
+    public String getCode() {
+        return code;
+    }
+    public String getName() {
+        return name;
+    }
+    public boolean getPriKey() {
+        return priKey;
+    }
+    public TableDataTypeEnum getType() {
+        return type;
+    }
+
+
+}

+ 44 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/constant/enums/TableDataTypeEnum.java

@@ -0,0 +1,44 @@
+package com.xxh.cloud.framework.script.modules.biz.constant.enums;
+
+
+/**
+ * 标准数据:数据类型
+ * */
+public enum TableDataTypeEnum {
+
+
+    MT_Dict("dict","字典码表"),
+
+    MT_Standard("standard","标准数据"),
+
+    MT_Int("i","整数"),
+
+    MT_Decimal("d","数字"),
+
+    MT_String("s","字符串"),
+
+    MT_Text("t","文本"),
+
+    MT_DateTime("dt","日期"),
+
+
+
+    ;
+
+    private String code;
+    private String msg;
+    private TableDataTypeEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+    public String getCode() {
+        return code;
+    }
+    public String getMsg() {
+        return msg;
+    }
+
+
+
+
+}

+ 56 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/mapper/DbSqlDDLMapper.java

@@ -0,0 +1,56 @@
+package com.xxh.cloud.framework.script.modules.biz.mapper;
+
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
+
+public interface DbSqlDDLMapper {
+
+
+    /**新建表*/
+    @Update("${paramSQL}")
+    public void createTable(@Param("paramSQL") String sql);
+
+    /**修改表*/
+    @Update("${paramSQL}")
+    public void alterTable(@Param("paramSQL") String sql);
+
+
+    /**删除表*/
+    @Update("${paramSQL}")
+    public void dropTable(@Param("paramSQL") String sql);
+
+
+    /**清空表数据*/
+    @Update("${paramSQL}")
+    public void truncateTableData(@Param("paramSQL") String sql);
+
+
+    /**查询表信息列表*/
+    @Select("${paramSQL}")
+    public List<TableEntityVO> entityList(@Param("paramSQL") String sql);
+
+
+    /**查询字段属性列表*/
+    @Select("${paramSQL}")
+    public List<TableEntityPropertyVO> entityPropList(@Param("paramSQL") String sql);
+
+
+    /**判断表是否存在*/
+    @Select("${paramSQL}")
+    public TableEntityVO getEntityObj(@Param("paramSQL") String sql);
+
+
+    /**获取表数据数量*/
+    @Select("select count(1) as num from ${tableName}")
+    public int entityDataNum(@Param("tableName") String tableName);
+
+//    @Update("${paramSQL}")
+//    public void tableDDL(@Param("paramSQL") String sql);
+
+
+}

+ 34 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/mapper/DbSqlOperateMapper.java

@@ -0,0 +1,34 @@
+package com.xxh.cloud.framework.script.modules.biz.mapper;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * SQL 操作脚本
+ * */
+public interface DbSqlOperateMapper {
+
+
+    @Insert("${paramSQL}")
+    public void dynamicsInsert(@Param("paramSQL") String sql);
+
+    @Update("${paramSQL}")
+    public void dynamicsUpdate(@Param("paramSQL") String sql);
+
+
+    @Delete("${paramSQL}")
+    public void dynamicsDelete(@Param("paramSQL") String sql);
+
+
+    @Select("${paramSQL}")
+    public List<Map<String,Object>> selectList(@Param("paramSQL") String sql);
+
+    @Select("${paramSQL}")
+    public IPage<Map<String,Object>> selectPage(IPage<Map<String,Object>> page, @Param("paramSQL") String sql);
+
+
+
+}

+ 45 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableDDLApiService.java

@@ -0,0 +1,45 @@
+package com.xxh.cloud.framework.script.modules.biz.service;
+
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.EntityDDLAlterDTO;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.EntityDDLClearDataDTO;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.EntityDDLCreateDTO;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.EntityDDLDropDTO;
+
+/**
+ * data definition language:数据定义语言
+ * */
+public interface DbTableDDLApiService {
+
+
+    /**
+     * 创建
+     * */
+    public void create(EntityDDLCreateDTO params);
+
+    /**
+     * 新增和修改
+     * */
+    public void alter(EntityDDLAlterDTO params);
+
+    /**
+     * 删除
+     * */
+    public void drop(EntityDDLDropDTO params);
+
+    /**
+     * 清空数据
+     * */
+    public void clearData(EntityDDLClearDataDTO params);
+
+
+
+
+//
+//    /**
+//     *
+//     * */
+//    public List<TableEntityPropertyVO> getTableColumns(DataSourceTypeEnum dataSourceType, String database, String tableCode);
+
+
+
+}

+ 49 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableOperateApiService.java

@@ -0,0 +1,49 @@
+package com.xxh.cloud.framework.script.modules.biz.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.*;
+
+import java.util.List;
+import java.util.Map;
+
+public interface DbTableOperateApiService {
+
+    /**查询*/
+    public IPage<Map<String,Object>> query(EntityOperateQueryDTO params);
+
+    /**列表*/
+    public List<Map<String,Object>> list(EntityOperateListDTO params);
+
+
+    /**获取*/
+    public Map<String,Object> getById(EntityOperateGetByIdDTO params);
+
+    /**获取*/
+    public Map<String,Object> getOne(EntityOperateGetOneDTO params);
+
+
+    /**新增*/
+    public void save(EntityOperateSaveDTO params);
+
+    /**批量新增*/
+    public void saveBatch(EntityOperateSaveBatchDTO params);
+
+    /**修改*/
+    public void updateById(EntityOperateUpdateByIdDTO params);
+
+    /**批量修改*/
+    public void updateByWhere(EntityOperateUpdateByWhereDTO params);
+
+
+    /**删除*/
+    public void deleteById(EntityOperateDeleteByIdDTO params);
+
+
+    /**批量删除*/
+    public void deleteByWhere(EntityOperateDeleteByWhereDTO params);
+
+
+
+
+
+}

+ 38 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/DbTableSchemaApiService.java

@@ -0,0 +1,38 @@
+package com.xxh.cloud.framework.script.modules.biz.service;
+
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+
+import java.util.List;
+
+/**
+ *
+ * */
+public interface DbTableSchemaApiService {
+
+    /**
+     * 获取表定义列表
+     * */
+    public List<TableEntityVO> getTableList(DataSourceTypeEnum dataSourceType, String database);
+
+    /**
+     * 获取表定义列表
+     * */
+    public List<TableEntityVO> getTableLikeList(DataSourceTypeEnum dataSourceType, String database,String likeTableCode);
+
+    /**
+     * 获取表定义信息
+     * */
+    public TableEntityVO getTableInfo(DataSourceTypeEnum dataSourceType, String database, String tableCode);
+
+    /**
+     * 获取表列表定义列表
+     * */
+    public List<TableEntityPropertyVO> getTableColumns(DataSourceTypeEnum dataSourceType, String database, String tableCode);
+
+
+
+
+
+}

+ 149 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableDDLApiServiceImpl.java

@@ -0,0 +1,149 @@
+package com.xxh.cloud.framework.script.modules.biz.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
+import com.xxh.cloud.framework.common.utils.XXEnumUtil;
+import com.xxh.cloud.framework.common.validator.ValidatorUtils;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.*;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableColumnBaseEnum;
+import com.xxh.cloud.framework.script.modules.biz.mapper.DbSqlDDLMapper;
+import com.xxh.cloud.framework.script.modules.biz.service.DbTableDDLApiService;
+import com.xxh.cloud.framework.script.modules.biz.service.DbTableSchemaApiService;
+import com.xxh.cloud.framework.script.modules.sql.ddl.SqlDDLUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class DbTableDDLApiServiceImpl implements DbTableDDLApiService {
+
+
+    @Autowired
+    private DbSqlDDLMapper dbSqlDDLMapper;
+
+    @Autowired
+    private DbTableSchemaApiService dbTableSchemaApiService;
+
+    @Override
+    public void create(EntityDDLCreateDTO params) {
+        ValidatorUtils.validateEntity(params);
+        DataSourceTypeEnum dataSourceType= XXEnumUtil.getEnum(DataSourceTypeEnum.class,params.getDataSourceType());
+        this.create(dataSourceType,params);
+    }
+
+    @Override
+    public void alter(EntityDDLAlterDTO params) {
+        DataSourceTypeEnum dataSourceType= XXEnumUtil.getEnum(DataSourceTypeEnum.class,params.getDataSourceType());
+        boolean isExist= this.isExist(dataSourceType,params.getDatabase(),params.getTableCode());
+        if(isExist){
+            this.alter(dataSourceType,params);
+        }else{
+            this.create(dataSourceType,params);
+        }
+    }
+
+
+    @Override
+    public void drop(EntityDDLDropDTO params) {
+        ValidatorUtils.validateEntity(params);
+        String sql= SqlDDLUtils.dropTableSQL(params.getTableCode());
+        dbSqlDDLMapper.dropTable(sql);
+    }
+
+    @Override
+    public void clearData(EntityDDLClearDataDTO params) {
+        ValidatorUtils.validateEntity(params);
+        String sql= SqlDDLUtils.truncateTableDataSQL(params.getTableCode());
+        dbSqlDDLMapper.truncateTableData(sql);
+    }
+
+
+    //=============================================
+
+    /**
+     * 判断实体表是否存在
+     * */
+    private boolean isExist(DataSourceTypeEnum dataSourceType,String database,String tableCode){
+        String sql= SqlDDLUtils.getTabel2DBSQL(dataSourceType,database,tableCode);
+        TableEntityVO entityModel= dbSqlDDLMapper.getEntityObj(sql);
+        return entityModel==null?false:true;
+    }
+
+    /**
+     * 获取实体表的数据数量
+     * */
+    private int getDataNum(DataSourceTypeEnum dataSourceType,String tableCode){
+        return dbSqlDDLMapper.entityDataNum(tableCode);
+    }
+
+
+    /**
+     *  获取实体表字段列表
+     * */
+    private Map<String, TableEntityPropertyVO> getColumnMap(DataSourceTypeEnum dataSourceType, String database, String tableCode) {
+        Map<String, TableEntityPropertyVO> data=new HashMap<>();
+        String sql= SqlDDLUtils.getColumn2TableSQL(dataSourceType,database,tableCode);
+        List<TableEntityPropertyVO> list= dbSqlDDLMapper.entityPropList(sql);
+        if(CollUtil.isEmpty(list)){
+            return data;
+        }
+        list.forEach(item->{
+            data.put(item.getCode(),item);
+        });
+        return data;
+    }
+
+
+
+
+
+    /**
+     * 创建实体定义
+     * */
+    private void create(DataSourceTypeEnum dataSourceType,EntityDDLCreateDTO params){
+        String sql= SqlDDLUtils.createTableSQL(dataSourceType,
+                params.getTableCode(),
+                params.getTableName(),
+                params.getProps());
+        dbSqlDDLMapper.createTable(sql);
+    }
+
+
+    /**
+     * 修改实体定义
+     * */
+    private void alter(DataSourceTypeEnum dataSourceType,EntityDDLCreateDTO params){
+        int num = this.getDataNum(dataSourceType,params.getTableCode());
+        if(num<=0){
+            String sql= SqlDDLUtils.dropTableSQL(params.getTableCode());
+            dbSqlDDLMapper.dropTable(sql);
+            this.create(dataSourceType,params);
+            return ;
+        }
+
+        Map<String, TableColumnBaseEnum> tableBaseMap= XXEnumUtil.getEnumMap(TableColumnBaseEnum.class);
+
+        Map<String, TableEntityPropertyVO> tablePropMap= this.getColumnMap(dataSourceType,params.getDatabase(),params.getTableCode());
+
+        for(EntityDDLCreatePropertyDTO entityProp:params.getProps()){
+            TableColumnBaseEnum  tableBaseEnum= tableBaseMap.get(entityProp.getCode());
+            if(tableBaseEnum==null){
+                TableEntityPropertyVO tabProp= tablePropMap.get(entityProp.getCode());
+                String sql= SqlDDLUtils.alterTableSQL(dataSourceType,params.getTableCode(),entityProp,tabProp);
+                if(StrUtil.isNotEmpty(sql)){
+                    System.out.println("修改SQL +++++++++++++ "+sql);
+                    dbSqlDDLMapper.alterTable(sql);
+                }
+            }
+        }
+    }
+
+
+
+}

+ 181 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableOperateApiServiceImpl.java

@@ -0,0 +1,181 @@
+package com.xxh.cloud.framework.script.modules.biz.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xxh.cloud.framework.common.validator.ValidatorUtils;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.*;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableColumnBaseEnum;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableDataTypeEnum;
+import com.xxh.cloud.framework.script.modules.biz.mapper.DbSqlOperateMapper;
+import com.xxh.cloud.framework.script.modules.biz.service.DbTableOperateApiService;
+import com.xxh.cloud.framework.script.modules.sql.operate.*;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereAndOrBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereItemBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.constant.ConditionOp;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Log4j2
+@Service
+public class DbTableOperateApiServiceImpl implements DbTableOperateApiService {
+
+
+    @Autowired
+    private DbSqlOperateMapper dbSqlOperateMapper;
+
+    @Override
+    public IPage<Map<String, Object>> query(EntityOperateQueryDTO params) {
+        ValidatorUtils.validateEntity(params);
+        QuerySqlWrapper sqlWrapper=new QuerySqlWrapper();
+        sqlWrapper.select(params.getSelect());
+        sqlWrapper.from(params.getTableCode());
+        sqlWrapper.join(params.getJoin());
+        sqlWrapper.where(params.getWhere());
+        sqlWrapper.groupBy(params.getGroupBy());
+        sqlWrapper.orderBy(params.getOrderBy());
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ query sql  -> "+sql);
+        IPage<Map<String,Object>> data = dbSqlOperateMapper.selectPage(new Page<>(params.getPage(), params.getRows()),sql);
+        return data;
+    }
+
+    @Override
+    public List<Map<String, Object>> list(EntityOperateListDTO params) {
+        ValidatorUtils.validateEntity(params);
+        QuerySqlWrapper sqlWrapper=new QuerySqlWrapper();
+        sqlWrapper.select(params.getSelect());
+        sqlWrapper.from(params.getTableCode());
+        sqlWrapper.join(params.getJoin());
+        sqlWrapper.where(params.getWhere());
+        sqlWrapper.groupBy(params.getGroupBy());
+        sqlWrapper.orderBy(params.getOrderBy());
+        if(params.getLimit()<=0 || params.getLimit()>=2000){
+            sqlWrapper.limit(2000);
+        }else {
+            sqlWrapper.limit(params.getLimit());
+        }
+
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ list sql  -> "+sql);
+        List<Map<String,Object>> data= dbSqlOperateMapper.selectList(sql);
+        return data;
+    }
+
+    @Override
+    public Map<String,Object> getById(EntityOperateGetByIdDTO params) {
+        ValidatorUtils.validateEntity(params);
+        QuerySqlWrapper sqlWrapper=new QuerySqlWrapper();
+        sqlWrapper.select(params.getSelect());
+        sqlWrapper.from(params.getTableCode());
+        sqlWrapper.where(new WhereAndOrBean(new WhereItemBean(params.getTableCode(),"id", TableDataTypeEnum.MT_String, ConditionOp.EQ,params.getId())));
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ getById sql  -> "+sql);
+        List<Map<String,Object>> list= dbSqlOperateMapper.selectList(sql);
+        if(CollUtil.isEmpty(list)){
+            return null;
+        }
+        return list.get(0);
+    }
+
+    @Override
+    public Map<String, Object> getOne(EntityOperateGetOneDTO params) {
+        ValidatorUtils.validateEntity(params);
+        QuerySqlWrapper sqlWrapper=new QuerySqlWrapper();
+        sqlWrapper.select(params.getSelect());
+        sqlWrapper.from(params.getTableCode());
+        sqlWrapper.join(params.getJoin());
+        sqlWrapper.where(params.getWhere());
+        sqlWrapper.groupBy(params.getGroupBy());
+        sqlWrapper.orderBy(params.getOrderBy());
+        sqlWrapper.limit(1);
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ getOne sql  -> "+sql);
+        List<Map<String,Object>> list= dbSqlOperateMapper.selectList(sql);
+        if(CollUtil.isEmpty(list)){
+            return null;
+        }
+        return list.get(0);
+    }
+
+
+    @Override
+    public void save(EntityOperateSaveDTO params) {
+        ValidatorUtils.validateEntity(params);
+        InsertSqlWrapper sqlWrapper=new InsertSqlWrapper();
+        sqlWrapper.tableName(params.getTableCode());
+        sqlWrapper.insert(params.getInsert());
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ save sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsInsert(sql);
+    }
+
+    @Override
+    public void saveBatch(EntityOperateSaveBatchDTO params) {
+        ValidatorUtils.validateEntity(params);
+        InsertBatchSqlWrapper sqlWrapper=new InsertBatchSqlWrapper();
+        sqlWrapper.tableName(params.getTableCode());
+        sqlWrapper.insertCol(params.getInsert());
+        sqlWrapper.insertVal(params.getData());
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ saveBatch sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsInsert(sql);
+    }
+
+    @Override
+    public void updateById(EntityOperateUpdateByIdDTO params) {
+        ValidatorUtils.validateEntity(params);
+        UpdateSqlWrapper sqlWrapper=new UpdateSqlWrapper();
+        sqlWrapper.update(params.getTableCode());
+        sqlWrapper.Set(params.getUpdates());
+        sqlWrapper.where(new WhereAndOrBean(new WhereItemBean(params.getTableCode(),
+                TableColumnBaseEnum.ID.getCode(),TableColumnBaseEnum.ID.getType(), ConditionOp.EQ,params.getId())));
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ updateById sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsUpdate(sql);
+
+    }
+
+    @Override
+    public void updateByWhere(EntityOperateUpdateByWhereDTO params) {
+        ValidatorUtils.validateEntity(params);
+        UpdateSqlWrapper sqlWrapper=new UpdateSqlWrapper();
+        sqlWrapper.update(params.getTableCode());
+        sqlWrapper.Set(params.getUpdates());
+        sqlWrapper.where(params.getWhere());
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ updateByWhere sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsUpdate(sql);
+    }
+
+
+    @Override
+    public void deleteById(EntityOperateDeleteByIdDTO params) {
+        ValidatorUtils.validateEntity(params);
+        DeleteSqlWrapper sqlWrapper=new DeleteSqlWrapper();
+        sqlWrapper.delete(params.getTableCode());
+        sqlWrapper.where(new WhereAndOrBean(
+                new WhereItemBean(params.getTableCode(),"id", TableDataTypeEnum.MT_String, ConditionOp.EQ,params.getId())
+        ));
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ deleteById sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsDelete(sql);
+    }
+
+    @Override
+    public void deleteByWhere(EntityOperateDeleteByWhereDTO params) {
+        ValidatorUtils.validateEntity(params);
+        DeleteSqlWrapper sqlWrapper=new DeleteSqlWrapper();
+        sqlWrapper.delete(params.getTableCode());
+        sqlWrapper.where(params.getWhere());
+        String sql= sqlWrapper.getSqlSegment();
+        log.debug("++++++ deleteByWhere sql  -> "+sql);
+        dbSqlOperateMapper.dynamicsDelete(sql);
+    }
+
+
+}

+ 63 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/biz/service/impl/DbTableSchemaApiServiceImpl.java

@@ -0,0 +1,63 @@
+package com.xxh.cloud.framework.script.modules.biz.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+import com.xxh.cloud.framework.script.modules.biz.mapper.DbSqlDDLMapper;
+import com.xxh.cloud.framework.script.modules.biz.service.DbTableSchemaApiService;
+import com.xxh.cloud.framework.script.modules.sql.ddl.SqlDDLUtils;
+import com.xxh.cloud.framework.script.modules.sql.ddl.convert.DataTypeConvertFactory;
+import com.xxh.cloud.framework.script.modules.sql.ddl.convert.ITypeConvert;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class DbTableSchemaApiServiceImpl implements DbTableSchemaApiService {
+
+
+    @Autowired
+    private DbSqlDDLMapper dbSqlDDLMapper;
+
+    @Override
+    public List<TableEntityVO> getTableList(DataSourceTypeEnum dataSourceType, String database) {
+        String sql= SqlDDLUtils.getTabel2DBSQL(dataSourceType,database);
+        List<TableEntityVO> list = dbSqlDDLMapper.entityList(sql);
+        return list;
+    }
+
+    @Override
+    public List<TableEntityVO> getTableLikeList(DataSourceTypeEnum dataSourceType, String database, String likeTableCode) {
+        String sql= SqlDDLUtils.getTabel2DBLikeSQL(dataSourceType,database,likeTableCode);
+        System.out.println(" +++++ " + sql);
+        List<TableEntityVO> list = dbSqlDDLMapper.entityList(sql);
+        return list;
+    }
+
+    @Override
+    public TableEntityVO getTableInfo(DataSourceTypeEnum dataSourceType, String database, String tableCode) {
+        String sql= SqlDDLUtils.getTabel2DBSQL(dataSourceType,database,tableCode);
+        TableEntityVO entityModel= dbSqlDDLMapper.getEntityObj(sql);
+        return entityModel;
+    }
+
+    @Override
+    public List<TableEntityPropertyVO> getTableColumns(DataSourceTypeEnum dataSourceType, String database, String tableCode) {
+        String sql= SqlDDLUtils.getColumn2TableSQL(dataSourceType,database,tableCode);
+        List<TableEntityPropertyVO> list= dbSqlDDLMapper.entityPropList(sql);
+
+        if(CollUtil.isNotEmpty(list)){
+            ITypeConvert convert= DataTypeConvertFactory.getConvertTypeFactory(dataSourceType);
+            for(TableEntityPropertyVO propertyVO:list){
+                propertyVO.setEntityDataType(convert.getEntityDataType(propertyVO.getType()));
+            }
+        }
+        return list;
+    }
+
+
+
+
+}

+ 46 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/DBSqlOpFactory.java

@@ -0,0 +1,46 @@
+package com.xxh.cloud.framework.script.modules.db;
+
+import com.xxh.cloud.framework.script.modules.db.service.DBDeleteOpApi;
+import com.xxh.cloud.framework.script.modules.db.service.DBInsertOpApi;
+import com.xxh.cloud.framework.script.modules.db.service.DBSelectOpApi;
+import com.xxh.cloud.framework.script.modules.db.service.DBUpdateOpApi;
+import com.xxh.cloud.framework.script.modules.db.service.impl.DBDeleteOpService;
+import com.xxh.cloud.framework.script.modules.db.service.impl.DBInsertOpService;
+import com.xxh.cloud.framework.script.modules.db.service.impl.DBSelectOpService;
+import com.xxh.cloud.framework.script.modules.db.service.impl.DBUpdateOpService;
+
+public class DBSqlOpFactory {
+
+
+    private static DBSelectOpService DBSelectOp=new DBSelectOpService();
+
+    private static DBInsertOpService DBInsertOp=new DBInsertOpService();
+
+    private static DBUpdateOpApi DBUpdateOp=new DBUpdateOpService();
+
+    private static DBDeleteOpApi DBDeleteOp=new DBDeleteOpService();
+
+
+
+    public static DBSelectOpApi getSelect(){
+        return DBSelectOp;
+    }
+
+    public static DBInsertOpApi getInsert(){
+        return DBInsertOp;
+    }
+
+    public static DBUpdateOpApi getUpdate(){
+        return DBUpdateOp;
+    }
+
+    public static  DBDeleteOpApi getDelete(){
+        return DBDeleteOp;
+    }
+
+
+
+
+
+
+}

+ 36 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/bean/XXDataSourceConfigBO.java

@@ -0,0 +1,36 @@
+package com.xxh.cloud.framework.script.modules.db.bean;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class XXDataSourceConfigBO {
+
+    /**
+     *
+     * */
+    private String type;
+
+    /**
+     *
+     * */
+    private String driverClassName;
+
+    /**
+     *
+     * */
+    private String userName;
+
+    /**
+     *
+     * */
+    private String passWord;
+
+    /**
+     *
+     * */
+    private String urlParams;
+
+
+}

+ 28 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBDeleteOpApi.java

@@ -0,0 +1,28 @@
+package com.xxh.cloud.framework.script.modules.db.service;
+
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+
+public interface DBDeleteOpApi {
+
+
+
+
+    /**
+     *
+     * */
+    public int delete(Connection connection, String sql);
+
+    /**
+     *
+     * */
+    public int delete(Connection connection,String sql, Map<String, Object> paramMap);
+
+    /**
+     *
+     * */
+    public void deleteBatch(Connection connection, List<String> sqlList);
+
+
+}

+ 43 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBInsertOpApi.java

@@ -0,0 +1,43 @@
+package com.xxh.cloud.framework.script.modules.db.service;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+
+public interface DBInsertOpApi {
+
+
+
+    /**
+     * INSERT INTO tableName (id ,name) VALUES ('1','1');
+     * */
+    public int insert(Connection connection, String sql);
+
+    public int insert(DataSource dataSource, String sql);
+
+    /**
+     * INSERT INTO tableName (id ,name) VALUES (:id,:name);
+     * */
+    public int insert(Connection connection,String sql, Map<String, Object> paramMap);
+
+    public int insert(DataSource dataSource,String sql, Map<String, Object> paramMap);
+
+    /**
+     * INSERT INTO tableName (id ,name) VALUES (?,?);
+     * */
+    public int[] insertBatch(Connection connection, String sql, List<Object[]> paramsBatch);
+
+    public int[] insertBatch(DataSource dataSource, String sql, List<Object[]> paramsBatch);
+
+    /**
+     * INSERT INTO tableName (id ,name) VALUES ('1','1');
+     * */
+    public int[] executeBatch(Connection connection, List<String> sqls);
+
+
+    public int[] executeBatch(DataSource dataSource, List<String> sqls);
+
+
+
+}

+ 53 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBSelectOpApi.java

@@ -0,0 +1,53 @@
+package com.xxh.cloud.framework.script.modules.db.service;
+
+import cn.hutool.core.lang.Dict;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+
+public interface DBSelectOpApi {
+
+
+
+//    @Insert("${paramSQL}")
+//    public void dynamicsInsert(@Param("paramSQL") String sql);
+//
+//    @Update("${paramSQL}")
+//    public void dynamicsUpdate(@Param("paramSQL") String sql);
+//
+//
+//    @Delete("${paramSQL}")
+//    public void dynamicsDelete(@Param("paramSQL") String sql);
+//
+//
+//    @Select("${paramSQL}")
+//    public List<Map<String,Object>> selectList(@Param("paramSQL") String sql);
+//
+//    @Select("${paramSQL}")
+//    public IPage<Map<String,Object>> selectPage(IPage<Map<String,Object>> page, @Param("paramSQL") String sql);
+
+
+
+
+    /**
+     * select
+     * */
+    public List<Map<String,Object>> selectList(DataSource dataSource, String sql);
+
+    public List<Dict>  selectListDict(DataSource dataSource,String sql);
+
+    public <T> List<T>  selectListBean(DataSource dataSource, String sql,Class<T> beanType);
+
+    public List<Map<String,Object>> selectList(Connection connection,String sql);
+
+    public List<Dict>  selectListDict(Connection connection,String sql);
+
+    public <T> List<T>  selectListBean(Connection connection, String sql,Class<T> beanType);
+
+
+
+
+
+}

+ 15 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DBUpdateOpApi.java

@@ -0,0 +1,15 @@
+package com.xxh.cloud.framework.script.modules.db.service;
+
+import java.sql.Connection;
+
+public interface DBUpdateOpApi {
+
+
+
+    /**
+     *
+     * */
+    public int update(Connection connection, String sql);
+
+
+}

+ 44 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/DbSqlDDLApi.java

@@ -0,0 +1,44 @@
+package com.xxh.cloud.framework.script.modules.db.service;
+
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+
+import java.sql.Connection;
+import java.util.List;
+
+public interface DbSqlDDLApi {
+
+
+
+    /**新建表*/
+    public void createTable(Connection connection , String sql);
+
+    /**修改表*/
+    public void alterTable(Connection connection ,String sql);
+
+
+    /**删除表*/
+    public void dropTable(Connection connection ,String sql);
+
+
+    /**清空表数据*/
+    public void truncateTableData(Connection connection ,String sql);
+
+
+    /**查询表信息列表*/
+    public List<TableEntityVO> entityList(Connection connection ,String sql);
+
+
+    /**查询字段属性列表*/
+    public List<TableEntityPropertyVO> entityPropList(Connection connection ,String sql);
+
+
+    /**判断表是否存在*/
+    public TableEntityVO getEntityObj(Connection connection ,String sql);
+
+
+    /**获取表数据数量*/
+    public int entityDataNum(Connection connection ,String tableName);
+
+
+}

+ 34 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBDeleteOpService.java

@@ -0,0 +1,34 @@
+package com.xxh.cloud.framework.script.modules.db.service.impl;
+
+import com.xxh.cloud.framework.script.modules.db.service.DBDeleteOpApi;
+import com.xxh.cloud.framework.script.modules.db.util.DbSQLExecuteUtils;
+
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+
+public class DBDeleteOpService implements DBDeleteOpApi {
+
+
+    /**
+     *
+     * */
+    @Override
+    public int delete(Connection connection, String sql) {
+
+        return DbSQLExecuteUtils.execute(connection,sql);
+    }
+
+    @Override
+    public int delete(Connection connection, String sql, Map<String, Object> paramMap) {
+        return DbSQLExecuteUtils.execute(connection,sql,paramMap);
+    }
+
+    @Override
+    public void deleteBatch(Connection connection, List<String> sqlList) {
+        DbSQLExecuteUtils.executeBatch(connection,sqlList);
+    }
+
+
+
+}

+ 90 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBInsertOpService.java

@@ -0,0 +1,90 @@
+package com.xxh.cloud.framework.script.modules.db.service.impl;
+
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.db.service.DBInsertOpApi;
+import com.xxh.cloud.framework.script.modules.db.util.DbSQLExecuteUtils;
+import com.xxh.cloud.framework.script.modules.error.DBErrorEnum;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+
+public class DBInsertOpService implements DBInsertOpApi {
+
+
+    /**
+     *
+     * */
+    @Override
+    public int insert(Connection connection, String sql) {
+        return  DbSQLExecuteUtils.execute(connection,sql);
+    }
+
+    @Override
+    public int insert(DataSource dataSource, String sql) {
+        Connection connection=null;
+        try {
+            connection = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+
+        return insert(connection,sql);
+    }
+
+    @Override
+    public int insert(Connection connection, String sql, Map<String, Object> paramMap) {
+        return  DbSQLExecuteUtils.execute(connection,sql,paramMap);
+    }
+
+    @Override
+    public int insert(DataSource dataSource, String sql, Map<String, Object> paramMap) {
+        Connection connection=null;
+        try {
+            connection = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return insert(connection,sql,paramMap);
+    }
+
+    @Override
+    public int[] insertBatch(Connection connection, String sql, List<Object[]> paramsBatch) {
+        return DbSQLExecuteUtils.executeBatch(connection,sql,paramsBatch);
+    }
+
+    @Override
+    public int[] insertBatch(DataSource dataSource, String sql, List<Object[]> paramsBatch) {
+        Connection connection=null;
+        try {
+            connection = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return insertBatch(connection,sql,paramsBatch);
+    }
+
+    @Override
+    public int[] executeBatch(Connection connection, List<String> sqls) {
+        return DbSQLExecuteUtils.executeBatch(connection,sqls);
+    }
+
+    @Override
+    public int[] executeBatch(DataSource dataSource, List<String> sqls) {
+        Connection connection=null;
+        try {
+            connection = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return executeBatch(connection,sqls);
+    }
+
+
+}

+ 136 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBSelectOpService.java

@@ -0,0 +1,136 @@
+package com.xxh.cloud.framework.script.modules.db.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Dict;
+import cn.hutool.db.Entity;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.db.service.DBSelectOpApi;
+import com.xxh.cloud.framework.script.modules.db.util.DbSQLExecuteUtils;
+import com.xxh.cloud.framework.script.modules.error.DBErrorEnum;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DBSelectOpService implements DBSelectOpApi {
+
+
+
+//    String sql="INSERT INTO hs_form_config_info(id ,name) VALUES (?,?)";
+//    List<Object[]> paramsBatch=new ArrayList<>();
+//    List<Object> list1 = new ArrayList<>();
+//        list1.add("100");
+//        list1.add("AAAA");
+//        paramsBatch.add( Convert.toStrArray(list1));
+//
+//    List<Object> list2 = new ArrayList<>();
+//        list2.add("200");
+//        list2.add(null);
+//        paramsBatch.add(Convert.toStrArray(list2));
+//        DbSQLExecuteUtils.executeBatch(conn,sql,paramsBatch);
+
+
+
+
+
+
+
+
+
+    /**
+     * select:
+     * */
+    @Override
+    public List<Map<String, Object>> selectList(DataSource dataSource, String sql) {
+        Connection conn=null;
+        try {
+            conn = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return this.selectList(conn,sql);
+    }
+
+    @Override
+    public List<Dict> selectListDict(DataSource dataSource, String sql) {
+        Connection conn=null;
+        try {
+            conn = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return this.selectListDict(conn,sql);
+    }
+
+
+
+    @Override
+    public List<Map<String, Object>> selectList(Connection connection, String sql) {
+        List<Map<String, Object>> data=new ArrayList<>();
+        List<Entity> list= DbSQLExecuteUtils.queryList(connection,sql);
+        if(CollUtil.isEmpty(list)){
+            return data;
+        }
+        for (Entity entity:list) {
+            Map<String, Object> dataItem=new HashMap<>();
+            for (String key:entity.keySet()){
+                dataItem.put(key,entity.get(key));
+            }
+            data.add(dataItem);
+        }
+        return data;
+    }
+
+    @Override
+    public List<Dict> selectListDict(Connection connection, String sql) {
+        List<Dict> data=new ArrayList<>();
+        List<Entity> list= DbSQLExecuteUtils.queryList(connection,sql);
+        if(CollUtil.isEmpty(list)){
+            return data;
+        }
+        for (Entity entity:list) {
+            Dict dataItem= Dict.create();
+            for (String key:entity.keySet()){
+                dataItem.put(key,entity.get(key));
+            }
+            data.add(dataItem);
+        }
+
+        return data;
+    }
+
+
+    @Override
+    public <T> List<T> selectListBean(DataSource dataSource, String sql, Class<T> beanType) {
+        Connection conn=null;
+        try {
+            conn = dataSource.getConnection();
+        }catch (SQLException e){
+            e.printStackTrace();
+            throw new BusinessException(DBErrorEnum.DB_Connection,"获取数据库连接错误");
+        }
+        return this.selectListBean(conn,sql,beanType);
+    }
+
+
+    @Override
+    public <T> List<T> selectListBean(Connection connection, String sql,Class<T> beanType) {
+        List<T> data = DbSQLExecuteUtils.queryListBean(connection,sql,beanType);
+        return data;
+    }
+
+
+
+
+
+
+
+
+
+}

+ 17 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DBUpdateOpService.java

@@ -0,0 +1,17 @@
+package com.xxh.cloud.framework.script.modules.db.service.impl;
+
+import com.xxh.cloud.framework.script.modules.db.service.DBUpdateOpApi;
+import com.xxh.cloud.framework.script.modules.db.util.DbSQLExecuteUtils;
+
+import java.sql.Connection;
+
+public class DBUpdateOpService implements DBUpdateOpApi {
+
+
+    @Override
+    public int update(Connection connection, String sql) {
+        return DbSQLExecuteUtils.execute(connection,sql);
+    }
+
+
+}

+ 69 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/service/impl/DbSqlDDLService.java

@@ -0,0 +1,69 @@
+package com.xxh.cloud.framework.script.modules.db.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.db.DbUtil;
+import cn.hutool.db.Entity;
+import cn.hutool.db.handler.EntityListHandler;
+import cn.hutool.db.sql.SqlExecutor;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityVO;
+import com.xxh.cloud.framework.script.modules.db.service.DbSqlDDLApi;
+import com.xxh.cloud.framework.script.modules.db.util.DbSQLExecuteUtils;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+public class DbSqlDDLService implements DbSqlDDLApi {
+
+
+
+
+
+
+    @Override
+    public void createTable(Connection connection , String sql) {
+        DbSQLExecuteUtils.execute(connection,sql);
+    }
+
+    @Override
+    public void alterTable(Connection connection, String sql) {
+
+    }
+
+    @Override
+    public void dropTable(Connection connection, String sql) {
+
+    }
+
+    @Override
+    public void truncateTableData(Connection connection, String sql) {
+
+    }
+
+    @Override
+    public List<TableEntityVO> entityList(Connection connection, String sql) {
+        return null;
+    }
+
+    @Override
+    public List<TableEntityPropertyVO> entityPropList(Connection connection, String sql) {
+        return null;
+    }
+
+    @Override
+    public TableEntityVO getEntityObj(Connection connection, String sql) {
+        return null;
+    }
+
+    @Override
+    public int entityDataNum(Connection connection, String tableName) {
+        //@Select("select count(1) as num from ${tableName}")
+        return 0;
+    }
+
+
+
+
+
+}

+ 28 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/test/DBSqlTest.java

@@ -0,0 +1,28 @@
+package com.xxh.cloud.framework.script.modules.db.test;
+
+import com.alibaba.fastjson2.JSON;
+import com.xxh.cloud.framework.script.modules.db.DBSqlOpFactory;
+import com.xxh.cloud.framework.script.modules.db.service.DBSelectOpApi;
+import com.xxh.cloud.framework.script.modules.db.util.XXDataSourceUtils;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+public class DBSqlTest {
+
+    public static void main(String[] args) throws SQLException {
+
+        DataSource ds= XXDataSourceUtils.getDruidDataSource();
+        Connection conn = ds.getConnection();
+        DBSelectOpApi api=  DBSqlOpFactory.getSelect();
+
+//        List<Map<String,Object>> list= api.selectList(conn,"SELECT * FROM hs_form_config_info");
+//        System.out.println(JSON.toJSONString(list));
+
+        List<TestBean1> list= api.selectListBean(conn,"SELECT id as tid FROM hs_form_config_info",TestBean1.class);
+        System.out.println(JSON.toJSONString(list));
+    }
+
+}

+ 14 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/test/TestBean1.java

@@ -0,0 +1,14 @@
+package com.xxh.cloud.framework.script.modules.db.test;
+
+public class TestBean1 {
+
+    private String tid;
+
+    public String getTid() {
+        return tid;
+    }
+
+    public void setTid(String tid) {
+        this.tid = tid;
+    }
+}

+ 69 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DBWriteUtils.java

@@ -0,0 +1,69 @@
+package com.xxh.cloud.framework.script.modules.db.util;
+
+import com.xxh.cloud.framework.common.utils.StrJoinSplitUtils;
+import com.xxh.cloud.framework.common.write.bean.HwdsWriteDBConfigBean;
+import com.xxh.cloud.framework.common.write2.DorisWriteUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class DBWriteUtils {
+
+
+
+
+    public static void batchWriteVoid(DataSource dataSource, List<Map<String, Object>> data){
+//        String tableName =writeDBConfig.getTable();
+//        List<String> fieldNames = StrJoinSplitUtils.split2List(writeDBConfig.getColumn());
+        String sqlInsert = DBWriteUtils.getInsertSQL(null,null);
+        System.out.println(sqlInsert);
+//
+//        try (Connection connection = dataSource.getConnection(); PreparedStatement ps = connection.prepareStatement(sqlInsert); ) {
+//            connection.setAutoCommit(false);
+//            for (Map<String,Object> recordValue : data) {
+//                for (int j = 0; j < fieldNames.size(); j++) {
+//                    ps.setObject(j + 1, recordValue.get(fieldNames.get(j)));
+//                }
+//                ps.addBatch();
+//            }
+//            ps.executeBatch();
+//            ps.clearBatch();
+//            connection.commit();
+//        } catch (SQLException se) {
+//            throw new RuntimeException(se);
+//        }
+//
+
+    }
+
+
+
+
+
+    /**
+     * insert sql
+     * */
+    public static String getInsertSQL(String tableName, List<String> fieldNames){
+        String sqlInsert = String.format("INSERT INTO %s ( %s ) VALUES ( %s )", tableName,
+                StringUtils.join(fieldNames, ","),
+                StringUtils.join(Collections.nCopies(fieldNames.size(), "?"), ","));
+        return sqlInsert;
+    }
+
+
+    public static void main(String[] args) {
+        List<String> fieldNames=new ArrayList<>();
+        fieldNames.add("id");
+        fieldNames.add("name");
+
+        System.out.println(DBWriteUtils.getInsertSQL("test",fieldNames));
+    }
+
+}

+ 203 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DbSQLExecuteUtils.java

@@ -0,0 +1,203 @@
+package com.xxh.cloud.framework.script.modules.db.util;
+
+import cn.hutool.core.convert.Convert;
+import cn.hutool.db.DbUtil;
+import cn.hutool.db.Entity;
+import cn.hutool.db.handler.BeanListHandler;
+import cn.hutool.db.handler.EntityListHandler;
+import cn.hutool.db.sql.SqlExecutor;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.error.DBErrorEnum;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DbSQLExecuteUtils {
+
+
+    /**
+     *  执行SQL
+     * */
+    public static int execute(Connection conn, String sql){
+        try {
+            int count = SqlExecutor.execute(conn,sql);
+            return count;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+    /**
+     * 执行带参数的SQL
+     * @param sql: 参数标记符号 ( :  @  ? )
+     * */
+    public static int execute(Connection conn, String sql, Map<String, Object> paramMap){
+        try {
+            int count = SqlExecutor.execute(conn,sql,paramMap);
+            return count;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+
+    /**
+     * INSERT INTO tb (id ,name) VALUES (?,?)
+     * */
+    public static int[] executeBatch(Connection conn, String sql, List<Object[]> paramsBatch){
+        try {
+            int[] counts =SqlExecutor.executeBatch(conn,sql,paramsBatch);
+            return counts;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+
+    /**
+     *
+     * */
+    public static int[] executeBatch(Connection conn, List<String> sqlList){
+        try {
+            int[] counts =SqlExecutor.executeBatch(conn,sqlList);
+            return counts;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+
+
+    /**
+     * 查询
+     * */
+    public static List<Entity> queryList(Connection conn, String sql){
+        try {
+            List<Entity> data= SqlExecutor.query(conn,sql,new EntityListHandler());
+            return data;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+    /**
+     * 查询
+     * */
+    public static <T> List<T> queryListBean(Connection conn, String sql,Class<T> beanType){
+        try {
+            List<T> data= SqlExecutor.query(conn,sql,new BeanListHandler<T>(beanType));
+            return data;
+        } catch (SQLException e) {
+            throw new BusinessException(DBErrorEnum.DB_ExecuteSQL,e.getMessage());
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+
+    /**
+     * 查询
+     * select * from table_demo where id = :id
+     * select * from table_demo where id = @id
+     * select * from table_demo where id = ?id
+     * */
+    public static List<Entity> queryList(Connection conn, String sql,Map<String, Object> paramMap){
+        try {
+            List<Entity> data= SqlExecutor.query(conn,sql,new EntityListHandler(),paramMap);
+            return data;
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }finally{
+            DbUtil.close(conn);
+        }
+    }
+
+
+
+
+
+
+    public static void main(String[] args) throws SQLException {
+        DataSource ds= XXDataSourceUtils.getDruidDataSource();
+        Connection conn = ds.getConnection();
+
+//        String createTableSQL="CREATE TABLE hs_form_config_info(" +
+//                "    `id` VARCHAR(24) NOT NULL   COMMENT 'id' , " +
+//                "    `name` VARCHAR(64) NOT NULL   COMMENT '名称' ," +
+//                "    PRIMARY KEY (id) " +
+//                ")  COMMENT = '表单配置表'; ";
+//        int num= DbSQLExecuteUtils.execute(conn,createTableSQL);
+//        System.out.println(num);
+
+//        String insertSQL="INSERT INTO hs_form_config_info(id ,name) VALUES('1','anros')";
+//        int num= DbSQLExecuteUtils.execute(conn,insertSQL);
+//        System.out.println(num);
+
+//        String querySQL="select * from hs_form_config_info";
+//        List<Entity> data= DbSQLExecuteUtils.queryList(conn,querySQL);
+//        System.out.println(data.size());
+
+
+//        String sql="select * from hs_form_config_info where id=?id and name=@name";
+//        Map<String, Object> paramMap=new HashMap<>();
+//        paramMap.put("name","anros");
+//        paramMap.put("id","");
+//
+//        NamedSql namedSql = new NamedSql(sql, paramMap);
+//        System.out.println(namedSql.getSql());
+//
+//        for (int i = 0; i < namedSql.getParams().length; i++) {
+//            System.out.println(namedSql.getParams()[i]);
+//        }
+
+
+
+        String sql="INSERT INTO hs_form_config_info(id ,name) VALUES (?,?)";
+        List<Object[]> paramsBatch=new ArrayList<>();
+        List<Object> list1 = new ArrayList<>();
+        list1.add("100");
+        list1.add("AAAA");
+        paramsBatch.add( Convert.toStrArray(list1));
+
+        List<Object> list2 = new ArrayList<>();
+        list2.add("200");
+        list2.add(null);
+        paramsBatch.add(Convert.toStrArray(list2));
+        DbSQLExecuteUtils.executeBatch(conn,sql,paramsBatch);
+
+
+
+//        PageResultHandler
+
+//        String sql="";
+//
+//        try {
+//            List<Entity> data= SqlExecutor.query(conn,sql,new EntityListHandler());
+//
+////            SqlExecutor.query(conn,sql,new PageResultHandler());
+//
+//        } catch (SQLException e) {
+//            throw new RuntimeException(e);
+//        }finally{
+//            DbUtil.close(conn);
+//        }
+
+
+
+    }
+
+}

+ 57 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/DemoOne.java

@@ -0,0 +1,57 @@
+package com.xxh.cloud.framework.script.modules.db.util;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.db.DbUtil;
+import cn.hutool.db.Entity;
+import cn.hutool.db.handler.EntityListHandler;
+import cn.hutool.db.sql.SqlExecutor;
+import com.alibaba.druid.pool.DruidDataSource;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+public class DemoOne {
+
+
+    public static void main(String[] args) {
+
+    }
+
+
+    public static void t(){
+        DruidDataSource dataSource= XXDataSourceUtils.getDruidDataSource();
+
+
+    }
+
+
+    public static void t2(DataSource ds){
+
+        Connection conn = null;
+        try {
+            conn = ds.getConnection();
+            // 执行非查询语句,返回影响的行数
+            int count = SqlExecutor.execute(conn, "UPDATE tb set field1 = ? where id = ?", 0, 0);
+            System.out.println(StrUtil.format("影响行数:{}",count));
+
+            // 执行非查询语句,返回自增的键,如果有多个自增键,只返回第一个
+            Long generatedKey = SqlExecutor.executeForGeneratedKey(conn, "UPDATE s set field1 = ? where id = ?", 0, 0);
+            System.out.println(StrUtil.format("主键:{}", generatedKey));
+
+            /* 执行查询语句,返回实体列表,一个Entity对象表示一行的数据,Entity对象是一个继承自HashMap的对象,存储的key为字段名,value为字段值 */
+            List<Entity> entityList = SqlExecutor.query(conn, "select * from tb where param1 = ?", new EntityListHandler(), "值");
+        } catch (SQLException e) {
+           e.printStackTrace();
+        } finally {
+            DbUtil.close(conn);
+        }
+
+
+
+    }
+
+
+
+}

+ 99 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/db/util/XXDataSourceUtils.java

@@ -0,0 +1,99 @@
+package com.xxh.cloud.framework.script.modules.db.util;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.xxh.cloud.framework.script.modules.db.bean.XXDataSourceConfigBO;
+import com.zaxxer.hikari.HikariDataSource;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+public class XXDataSourceUtils {
+
+
+    private static Map<String,DataSource> DSMap=new HashMap<>();
+
+
+    public static void removeByKey(String key){
+        DSMap.remove(key);
+    }
+
+    public static void removeAll(){
+        DSMap.clear();
+    }
+
+    public static DataSource get(String key){
+        return DSMap.get(key);
+    }
+
+    public static void add(String key,DataSource dataSource){
+        DSMap.put(key,dataSource);
+    }
+
+
+    public static DataSource getDruidDataSource(XXDataSourceConfigBO config){
+        DruidDataSource dataSource=new DruidDataSource();
+        dataSource.setDriverClassName(config.getDriverClassName());
+        dataSource.setUrl(config.getUrlParams());
+        dataSource.setUsername(config.getUserName());
+        dataSource.setPassword(config.getPassWord());
+        return dataSource;
+    }
+
+
+    public static DataSource getHikariDataSource(XXDataSourceConfigBO config){
+        HikariDataSource dataSource=new HikariDataSource();
+        //todo:
+        return dataSource;
+    }
+
+
+
+
+
+
+    public static DruidDataSource getDruidDataSource(){
+        DruidDataSource dataSource=new DruidDataSource();
+        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
+        dataSource.setUrl("jdbc:mysql://47.114.206.46:3306/awa_data_dev_24");
+        dataSource.setUsername("awa_dev");
+        dataSource.setPassword("xxAWA@24");
+        return dataSource;
+    }
+
+
+//    public static HikariDataSource getHikariDataSource(){
+//        HikariDataSource dataSource=new HikariDataSource();
+//
+////        ds.addDataSourceProperty("remarksReporting", true);
+////        ds.addDataSourceProperty("useInformationSchema", true);
+//
+//        dataSource.setPoolName("The_Source_DB_Connection");
+//        dataSource.setJdbcUrl("");
+//        dataSource.setDriverClassName("");
+//        dataSource.setUsername("");
+//        dataSource.setPassword("");
+//
+////        if (properties.getDriverClassName().contains("oracle")) {
+////            System.getProperties().setProperty("oracle.jdbc.J2EE13Compliant", "true");
+////        }
+////        ProductTypeEnum sourceProductType = properties.getSourceProductType();
+//
+//        dataSource.setConnectionTestQuery("testsql");
+//        dataSource.setMaximumPoolSize(2);
+//        dataSource.setMinimumIdle(5);
+//        dataSource.setMaxLifetime(2);
+//        dataSource.setConnectionTimeout(2);
+//        dataSource.setIdleTimeout(60000);
+//
+//        return dataSource;
+//    }
+
+
+
+
+
+
+
+
+}

+ 35 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/error/DBErrorEnum.java

@@ -0,0 +1,35 @@
+package com.xxh.cloud.framework.script.modules.error;
+
+import com.xxh.cloud.framework.common.exception.IErrorCodeEnum;
+
+public enum DBErrorEnum implements IErrorCodeEnum {
+
+
+    DB_Connection(11000,"获取数据库连接错误"),
+
+    DB_ExecuteSQL(11001,"执行SQL语句错误"),
+
+
+    ;
+    private int code;
+    private String msg;
+
+    private DBErrorEnum() {
+
+    }
+
+    DBErrorEnum(int code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    @Override
+    public int getCode() {
+        return code;
+    }
+
+    @Override
+    public String getMsg() {
+        return msg;
+    }
+}

+ 226 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/SqlDDLUtils.java

@@ -0,0 +1,226 @@
+package com.xxh.cloud.framework.script.modules.sql.ddl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
+import com.xxh.cloud.framework.common.constant.YN;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.common.utils.StrSqlUtils;
+import com.xxh.cloud.framework.script.modules.biz.bean.dto.EntityDDLCreatePropertyDTO;
+import com.xxh.cloud.framework.script.modules.biz.bean.vos.TableEntityPropertyVO;
+import com.xxh.cloud.framework.script.modules.sql.ddl.convert.DataTypeConvertFactory;
+import com.xxh.cloud.framework.script.modules.sql.ddl.convert.ITypeConvert;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SqlDDLUtils {
+
+
+    //======================================表
+
+    /**获取库的表列表*/
+    public static String getTabel2DBSQL(DataSourceTypeEnum dataSourceType, String dbName){
+        return SqlDDLUtils.getTabel2DBSQL(dataSourceType.getCode(),dbName);
+    }
+
+    /**获取库的表列表*/
+    public static String getTabel2DBSQL(String dataSourceType, String dbName){
+        if(DataSourceTypeEnum.MySQL.getCode().equals(dataSourceType)){
+            return StrUtil.format("SELECT TABLE_NAME as code ,TABLE_COMMENT as name " +
+                    "FROM information_schema.tables where TABLE_COMMENT ='{}'",dbName);
+        }
+        //todo: error
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+    /**
+     * 表列表
+     * */
+    public static String getTabel2DBLikeSQL(DataSourceTypeEnum dataSourceType, String dbName,String tableName){
+        return SqlDDLUtils.getTabel2DBLikeSQL(dataSourceType.getCode(),dbName,tableName);
+    }
+
+    /**
+     * 表列表
+     * */
+    public static String getTabel2DBLikeSQL(String dataSourceType, String dbName,String tableName){
+        if(DataSourceTypeEnum.MySQL.getCode().equals(dataSourceType)){
+            if(StrUtil.isEmpty(tableName)){
+                return StrUtil.format("SELECT TABLE_NAME as code " +
+                        " ,TABLE_COMMENT as name FROM information_schema.tables " +
+                        "where TABLE_SCHEMA ='{}'",dbName);
+            }else {
+                return StrUtil.format("SELECT TABLE_NAME as code " +
+                        " ,TABLE_COMMENT as name FROM information_schema.tables " +
+                        "where TABLE_SCHEMA ='{}' and  TABLE_NAME like '%{}%' ",dbName,tableName);
+            }
+        }
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+
+    /**根据表名 : 获取库的表列表*/
+    public static String getTabel2DBSQL(DataSourceTypeEnum dataSourceType, String dbName,String tableName){
+        return SqlDDLUtils.getTabel2DBSQL(dataSourceType.getCode(),dbName,tableName);
+    }
+
+    /**根据表名 : 获取库的表列表*/
+    public static String getTabel2DBSQL(String dataSourceType, String dbName,String tableName){
+        if(DataSourceTypeEnum.MySQL.getCode().equals(dataSourceType)){
+            return StrUtil.format("SELECT TABLE_NAME as code " +
+                    " ,TABLE_COMMENT as name FROM information_schema.tables " +
+                    "where TABLE_SCHEMA ='{}' and  TABLE_NAME='{}' ",dbName,tableName);
+        }
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+
+    //======================================表字段
+
+    /**获取表的列列表*/
+    public static String getColumn2TableSQL(DataSourceTypeEnum typeEnum, String dbName,String tableName){
+        return SqlDDLUtils.getColumn2TableSQL(typeEnum.getCode(),dbName,tableName);
+    }
+
+    /**获取表的列列表*/
+    public static String getColumn2TableSQL(String dataSourceType, String dbName,String tableName){
+        if(DataSourceTypeEnum.MySQL.getCode().equals(dataSourceType)){
+//            return StrUtil.format("select column_name as code, " +
+//                    "column_comment as name,column_type as typeFull," +
+//                    "data_type as type,character_maximum_length as typeSize, " +
+//                    "is_nullable as isNull ,column_key as isPri,table_name as tableName  " +
+//                    "from information_schema.columns " +
+//                    "where table_schema ='{}' and table_name = '{}'",dbName,tableName);
+
+           return StrUtil.format("select COLUMN_NAME  as code,  COLUMN_COMMENT   as name,COLUMN_TYPE  as typeFull," +
+                    " DATA_TYPE as type,   CHARACTER_MAXIMUM_LENGTH  as typeSize, IS_NULLABLE  as isNull , " +
+                    " COLUMN_KEY  as isPri,TABLE_NAME  as tableName from information_schema.columns" +
+                    " where TABLE_SCHEMA ='{}' and TABLE_NAME = '{}'",dbName,tableName);
+        }
+
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+
+    /**获取表的列列表*/
+    public static String getColumn2TableSQL(DataSourceTypeEnum dataSourceType, String dbName, Set<String> tableNames){
+        return  SqlDDLUtils.getColumn2TableSQL(dataSourceType.getCode(),dbName,tableNames);
+    }
+
+    /**获取表的列列表*/
+    public static String getColumn2TableSQL(String dataSourceType, String dbName, Set<String> tableNames){
+        if(DataSourceTypeEnum.MySQL.getCode().equals(dataSourceType)){
+            return StrUtil.format("select column_name as code, " +
+                    "column_comment as name,column_type as typeFull," +
+                    "data_type as type,character_maximum_length as typeSize, " +
+                    "is_nullable as isNull ,column_key as isPri,table_name as tableName " +
+                    "from information_schema.columns " +
+                    "where table_schema ='{}' and table_name in {}",dbName, StrSqlUtils.in(tableNames));
+
+        }
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+
+    //======================================create table
+
+    /**生成建表语句*/
+    public static String createTableSQL(DataSourceTypeEnum dataSourceType,
+                                        String tableCode,
+                                        String tableName,
+                                        List<EntityDDLCreatePropertyDTO> props){
+        ITypeConvert dbTypeConvert= DataTypeConvertFactory.getConvertTypeFactory(dataSourceType);
+
+        Set<String> priKeys=new HashSet<>();
+        StringBuilder sqlBody=new StringBuilder();
+        for(EntityDDLCreatePropertyDTO prop:props){
+            sqlBody.append(SqlDDLUtils.getColumnSQL(dbTypeConvert,prop,priKeys));
+        }
+
+        sqlBody.append(SqlDDLUtils.getCommonColumnSQL(dbTypeConvert,priKeys));
+
+
+        String _sqlBody;
+        if(sqlBody.toString().trim().endsWith(",")){
+            int endIdx= sqlBody.toString().lastIndexOf(",");
+            _sqlBody=sqlBody.toString().substring(0,endIdx);
+        }else{
+            _sqlBody=sqlBody.toString();
+        }
+
+        return StrUtil.format("CREATE TABLE {} ( {} ) COMMENT = '{}';",tableCode,_sqlBody,tableName);
+    }
+
+    private static String getColumnSQL(ITypeConvert typeConvert, EntityDDLCreatePropertyDTO prop, Set<String> priKeys){
+        String dbType= typeConvert.getDataType(prop.getDataType(),prop.getDataTypeSize());
+        String name;
+        if(StrUtil.isNotEmpty(prop.getName())){
+            name=prop.getName();
+        }else{
+            name=prop.getCode();
+        }
+        if(StrUtil.isNotEmpty(prop.getPriKey()) && YN.YES.getCode().equals(prop.getPriKey())){
+            priKeys.add(prop.getCode());
+            return StrUtil.format(" {} {} NOT NULL   COMMENT '{}' , ",prop.getCode(),dbType,name);
+        }else {
+            return StrUtil.format(" {} {}  COMMENT '{}' , ",prop.getCode(),dbType,name);
+        }
+    }
+
+    private static String getCommonColumnSQL(ITypeConvert typeConvert,Set<String> priKeys){
+        StringBuilder sql=new StringBuilder();
+        if(priKeys.size()>0){
+            if(StrUtil.isNotEmpty(sql.toString())){
+                sql.append(" , ");
+            }
+            sql.append(StrUtil.format("  PRIMARY KEY ({})", CollUtil.join(priKeys,",")));
+        }
+
+        return sql.toString();
+    }
+
+
+    //======================================alter table
+
+    public static String alterTableSQL(DataSourceTypeEnum dataSourceType,
+                                       String tableName,
+                                       EntityDDLCreatePropertyDTO modelProp,
+                                       TableEntityPropertyVO tableProp){
+
+        ITypeConvert typeConvert=DataTypeConvertFactory.getConvertTypeFactory(dataSourceType);
+
+        if(tableProp==null){
+            return StrUtil.format("ALTER TABLE {} ADD COLUMN {} {}  COMMENT '{}';",
+                    tableName,
+                    modelProp.getCode(),
+                    typeConvert.getDataType(modelProp.getDataType(),modelProp.getDataTypeSize()),
+                    modelProp.getName()
+            );
+        }else{
+            return StrUtil.format("ALTER TABLE {} CHANGE {}  {} {}  COMMENT '{}';",
+                    tableName,
+                    tableProp.getCode(),
+                    modelProp.getCode(),
+                    typeConvert.getDataType(modelProp.getDataType(),modelProp.getDataTypeSize()),
+                    modelProp.getName()
+
+            );
+        }
+    }
+
+    //======================================drop table
+
+    public static String dropTableSQL(String tableCode){
+        return StrUtil.format("drop table if exists {};",tableCode);
+    }
+
+
+    public static String truncateTableDataSQL(String tableCode){
+        return StrUtil.format("truncate table {};",tableCode);
+    }
+
+
+}

+ 23 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/DataTypeConvertFactory.java

@@ -0,0 +1,23 @@
+package com.xxh.cloud.framework.script.modules.sql.ddl.convert;
+
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+
+public class DataTypeConvertFactory {
+
+    public static  ITypeConvert getConvertTypeFactory(DataSourceTypeEnum dataSourceType){
+        if(DataSourceTypeEnum.MySQL == dataSourceType){
+            return new MySQLTypeConvert();
+        }
+        throw new BusinessException(BusinessBaseErrorEnum.DataSource_Config_ERROR);
+    }
+
+
+
+
+
+
+
+
+}

+ 17 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/ITypeConvert.java

@@ -0,0 +1,17 @@
+package com.xxh.cloud.framework.script.modules.sql.ddl.convert;
+
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableDataTypeEnum;
+
+public interface ITypeConvert {
+
+    /**
+     *  获取DB数据类型,根据实体数据类型
+     * */
+    public String getDataType(String dataType,int dataTypeSize);
+
+    /**
+     *  获取实体数据类型,根据DB数据类型
+     * */
+    public String getEntityDataType(String dbDataType);
+
+}

+ 52 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/ddl/convert/MySQLTypeConvert.java

@@ -0,0 +1,52 @@
+package com.xxh.cloud.framework.script.modules.sql.ddl.convert;
+
+
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableDataTypeEnum;
+
+public class MySQLTypeConvert implements ITypeConvert {
+    @Override
+    public String getDataType(String dataType, int dataTypeSize) {
+        if(TableDataTypeEnum.MT_Int.getCode().equals(dataType)){
+            return "INT";
+        }else if(TableDataTypeEnum.MT_Decimal.getCode().equals(dataType)){
+            return "DECIMAL(11,4) ";
+        }else if(TableDataTypeEnum.MT_DateTime.getCode().equals(dataType)){
+            return "DATETIME";
+        }else if(TableDataTypeEnum.MT_Dict.getCode().equals(dataType)){
+            return "VARCHAR(64)";
+        }else if(TableDataTypeEnum.MT_String.getCode().equals(dataType)){
+            return "VARCHAR(256)";
+        }else if(TableDataTypeEnum.MT_Text.getCode().equals(dataType)){
+            return "VARCHAR(1024)";
+        }
+        return "VARCHAR(64)";
+    }
+
+
+
+    @Override
+    public String getEntityDataType(String dbDataType) {
+        if(StrUtil.isEmpty(dbDataType)){
+            return null;
+        }
+        if("varchar".equals(dbDataType.toLowerCase())){
+            return TableDataTypeEnum.MT_String.getCode();
+        }else if("datetime".equals(dbDataType.toLowerCase())){
+            return TableDataTypeEnum.MT_DateTime.getCode();
+        }else if("date".equals(dbDataType.toLowerCase())){
+            return TableDataTypeEnum.MT_DateTime.getCode();
+        }else if("int".equals(dbDataType.toLowerCase())){
+            return TableDataTypeEnum.MT_Int.getCode();
+        }
+
+
+
+        return TableDataTypeEnum.MT_String.getCode();
+    }
+
+    public static void main(String[] args) {
+        String s="AbC";
+        System.out.println(s.toLowerCase());
+    }
+}

+ 66 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/DeleteSqlWrapper.java

@@ -0,0 +1,66 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereAndOrBean;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DeleteSqlWrapper implements ISqlWrapper{
+
+
+    private String tableName;
+    private List<WhereAndOrBean> wheres;
+
+
+
+    public DeleteSqlWrapper delete(String tableName){
+        this.tableName=tableName;
+        return this;
+    }
+
+    public DeleteSqlWrapper where(List<WhereAndOrBean> wheres){
+        this.wheres=wheres;
+        return this;
+    }
+
+    public DeleteSqlWrapper where(WhereAndOrBean whereBean){
+        if(this.wheres==null){
+            this.wheres=new ArrayList<>();
+        }
+        if(whereBean!=null){
+            this.wheres.add(whereBean);
+        }
+        return this;
+    }
+
+
+
+
+
+    private void check() throws BusinessException {
+        if(StrUtil.isEmpty(this.tableName)){
+//            throw new BusinessException(BaseReturnEnum.PARAM_NULL.getCode(),"");
+        }
+        if(CollUtil.isEmpty(this.wheres)){
+//            throw new BusinessException(BaseReturnEnum.PARAM_NULL.getCode(),"");
+        }
+
+    }
+
+
+
+
+    @Override
+    public String getSqlSegment() {
+        this.check();
+        StringBuilder sql=new StringBuilder();
+        sql.append("delete from ").append(this.tableName);
+//        sql.append(" where ").append(new WhereWrapper(this.wheres).getSqlSegment());
+        return sql.toString();
+    }
+
+
+}

+ 8 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/ISqlWrapper.java

@@ -0,0 +1,8 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+public interface ISqlWrapper {
+
+    public String getSqlSegment();
+
+
+}

+ 115 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/InsertBatchSqlWrapper.java

@@ -0,0 +1,115 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.InsertColumnBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.script.SqlConvertByType;
+
+import java.util.List;
+import java.util.Map;
+
+public class InsertBatchSqlWrapper implements ISqlWrapper{
+
+    private List<InsertColumnBean> insertCol;
+
+    private String tableName;
+
+    private List<Map<String,String>> insertVal;
+
+    public InsertBatchSqlWrapper tableName(String tableName){
+        this.tableName=tableName;
+        return this;
+    }
+
+    public InsertBatchSqlWrapper insertCol(List<InsertColumnBean> insertCol){
+        this.insertCol=insertCol;
+        return this;
+    }
+
+    public InsertBatchSqlWrapper insertVal(List<Map<String,String>> insertVal){
+        this.insertVal=insertVal;
+        return this;
+    }
+
+
+
+    private void check() throws BusinessException {
+        if(StrUtil.isEmpty(this.tableName)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:表名不能为空");
+        }
+        if(CollUtil.isEmpty(this.insertCol)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:insert字段不能为空");
+        }
+        if(CollUtil.isEmpty(this.insertVal)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:insert值不能为空");
+        }
+        if(this.insertVal.size()>1000){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:批量新增数据最大1000条");
+        }
+    }
+
+
+    @Override
+    public String getSqlSegment() {
+        this.check();
+        boolean isOne=true;
+        StringBuilder cols=new StringBuilder();
+        for(InsertColumnBean entity:this.insertCol){
+            if(isOne){
+                isOne=false;
+            }else {
+                cols.append(" , ");
+            }
+            cols.append(entity.getP());
+        }
+
+        StringBuilder sql=new StringBuilder();
+        sql.append("INSERT INTO ").append(this.tableName);
+        sql.append(" ( ").append(cols.toString()).append(" ) ");
+        sql.append(" VALUES ");
+
+        boolean isValOne=true;
+        for(Map<String,String> val:this.insertVal){
+            String _val=this.getSqlOneVal(val);
+            if(StrUtil.isNotEmpty(_val)){
+                if(isValOne){
+                    isValOne=false;
+                }else {
+                    sql.append(" , ");
+                }
+                sql.append(_val);
+            }
+        }
+        return  sql.toString();
+    }
+
+
+    private String getSqlOneVal(Map<String,String> val){
+        boolean isValAllNull=false;
+        boolean isOne=true;
+        StringBuilder vals=new StringBuilder();
+        vals.append("(");
+        for(InsertColumnBean entity:this.insertCol){
+            if(isOne){
+                isOne=false;
+            }else {
+                vals.append(" , ");
+            }
+
+            String v=val.get(entity.getP());
+            if(StrUtil.isNotEmpty(v)){
+                isValAllNull=true;
+                vals.append(SqlConvertByType.convert(entity.getT(),v));
+            }else {
+                vals.append("null");
+            }
+
+        }
+        vals.append(")");
+
+        return isValAllNull?vals.toString():null;
+    }
+
+}

+ 78 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/InsertSqlWrapper.java

@@ -0,0 +1,78 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.InsertBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.script.SqlConvertByType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class InsertSqlWrapper implements ISqlWrapper{
+
+
+
+    private List<InsertBean> insert;
+    private String tableName;
+
+    public InsertSqlWrapper tableName(String tableName){
+        this.tableName=tableName;
+        return this;
+    }
+
+    public InsertSqlWrapper insert(List<InsertBean> insert){
+        this.insert=insert;
+        return this;
+    }
+
+    public InsertSqlWrapper insert(InsertBean insertBean){
+        if(this.insert==null){
+            this.insert=new ArrayList<>();
+        }
+        if(insertBean!=null){
+            this.insert.add(insertBean);
+        }
+        return this;
+    }
+
+
+    private void check() throws BusinessException {
+        if(StrUtil.isEmpty(this.tableName)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:表名不能为空");
+        }
+        if(CollUtil.isEmpty(this.insert)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"SQL错误:insert字段和值不能为空");
+        }
+    }
+
+
+    @Override
+    public String getSqlSegment(){
+        this.check();
+        boolean isOne=true;
+        StringBuilder cols=new StringBuilder();
+        StringBuilder vals=new StringBuilder();
+        for(InsertBean entity:this.insert){
+            if(StrUtil.isNotEmpty(entity.getV())){
+                if(isOne){
+                    isOne=false;
+                }else {
+                    cols.append(" , ");
+                    vals.append(" , ");
+                }
+                cols.append(entity.getP());
+                vals.append(SqlConvertByType.convert(entity.getT(),entity.getV()));
+            }
+        }
+        StringBuilder sql=new StringBuilder();
+        sql.append("INSERT INTO ").append(this.tableName);
+        sql.append(" ( ").append(cols.toString()).append(" ) ");
+        sql.append(" VALUES ( ").append(vals.toString()).append(" ); ");
+        return  sql.toString();
+    }
+
+
+
+}

+ 221 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/QuerySqlWrapper.java

@@ -0,0 +1,221 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.*;
+import com.xxh.cloud.framework.script.modules.sql.operate.script.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class QuerySqlWrapper implements ISqlWrapper{
+
+
+    private List<SelectBean> select;
+
+    private String from;
+
+    private List<JoinBean> join;
+
+    private List<WhereAndOrBean> where;
+
+    private List<GroupByBean> groupBy;
+
+    private List<WhereAndOrBean> having;
+
+    private List<OrderByBean> orderBy;
+
+    private int limit=0;
+
+    public QuerySqlWrapper select(SelectBean selectBean){
+        if(this.select==null){
+            this.select=new ArrayList<>();
+        }
+        if(selectBean!=null){
+            this.select.add(selectBean);
+        }
+        return this;
+    }
+
+    public QuerySqlWrapper select(List<SelectBean> selectBeans){
+        if(CollUtil.isEmpty(selectBeans)){
+            return this;
+        }
+        this.select=selectBeans;
+        return this;
+    }
+
+
+    public QuerySqlWrapper from(String tableName){
+        this.from=tableName;
+        return this;
+    }
+
+    public QuerySqlWrapper join(JoinBean joinBean){
+        if(this.join==null){
+            this.join=new ArrayList<>();
+        }
+        if(joinBean!=null){
+            this.join.add(joinBean);
+        }
+        return this;
+    }
+
+    public QuerySqlWrapper join(List<JoinBean> joins){
+        if(CollUtil.isEmpty(joins)){
+            return this;
+        }
+        this.join=joins;
+        return this;
+    }
+
+
+    //todo:
+//    public QuerySqlWrapper where_and(List<WhereItemBean> whereBeans){
+//        return  this;
+//    }
+
+
+
+
+    public QuerySqlWrapper where(WhereAndOrBean whereBean){
+        if(this.where==null){
+            this.where=new ArrayList<>();
+        }
+        if(whereBean!=null){
+            this.where.add(whereBean);
+        }
+        return this;
+    }
+
+    public QuerySqlWrapper where(List<WhereAndOrBean> whereBeans){
+        if(CollUtil.isEmpty(whereBeans)){
+            return this;
+        }
+        this.where=whereBeans;
+        return  this;
+    }
+
+
+
+    public QuerySqlWrapper groupBy(GroupByBean groupByBean){
+        if(this.groupBy==null){
+            this.groupBy=new ArrayList<>();
+        }
+        if(groupByBean!=null){
+            this.groupBy.add(groupByBean);
+        }
+        return this;
+    }
+
+
+    public QuerySqlWrapper groupBy(List<GroupByBean> groupByBeans){
+        if(CollUtil.isEmpty(groupByBeans)){
+            return this;
+        }
+        this.groupBy=groupByBeans;
+        return this;
+    }
+
+
+    public QuerySqlWrapper having(WhereAndOrBean havingBean){
+        if(this.having==null){
+            this.having=new ArrayList<>();
+        }
+        if(havingBean!=null){
+            this.having.add(havingBean);
+        }
+        return this;
+    }
+
+    public QuerySqlWrapper having(List<WhereAndOrBean> havingBeans){
+        if(CollUtil.isEmpty(havingBeans)){
+            return this;
+        }
+        this.having=havingBeans;
+        return this;
+    }
+
+
+
+    public QuerySqlWrapper orderBy(OrderByBean orderByBean){
+        if(this.orderBy==null){
+            this.orderBy=new ArrayList<>();
+        }
+        if(orderByBean!=null){
+            this.orderBy.add(orderByBean);
+        }
+        return this;
+    }
+
+    public QuerySqlWrapper orderBy(List<OrderByBean> orderByBeans) {
+        if(CollUtil.isEmpty(orderByBeans)){
+            return this;
+        }
+        this.orderBy=orderByBeans;
+        return this;
+    }
+
+    public QuerySqlWrapper limit(int limit){
+        if(limit>0){
+            this.limit=limit;
+            return this;
+        }else {
+            return  this;
+        }
+    }
+
+    private void check() throws BusinessException {
+//        if(CollUtil.isEmpty(this.select)){
+//            throw new LowCodeException(BaseReturnEnum.PARAM_NULL.getCode(),"");
+//        }
+//        if(StrUtil.isEmpty(this.from)){
+//            throw new LowCodeException(BaseReturnEnum.PARAM_NULL.getCode(),"");
+//        }
+    }
+
+
+
+
+    @Override
+    public String getSqlSegment(){
+        this.check();
+
+        StringBuilder sql=new StringBuilder();
+        sql.append(" select ");
+        sql.append(new SelectWrapper(this.select).getSqlSegment());
+        sql.append(" from ");
+        sql.append(this.from).append(" as ").append(this.from);
+
+        if(CollUtil.isNotEmpty(this.join)){
+            sql.append(new JoinWrapper(this.join).getSqlSegment());
+        }
+
+        if(CollUtil.isNotEmpty(this.where)){
+            String whereSQL=new WhereWrapper(this.where).getSqlSegment();
+            if(StrUtil.isNotEmpty(whereSQL)){
+                sql.append(" where ").append(whereSQL);
+            }
+        }
+
+        if(CollUtil.isNotEmpty(this.groupBy)){
+            sql.append(new GroupByWrapper(this.groupBy).getSqlSegment());
+        }
+
+        if(CollUtil.isNotEmpty(this.having)){
+            sql.append(new HavingWrapper(this.having).getSqlSegment());
+        }
+
+        if(CollUtil.isNotEmpty(this.orderBy)){
+            sql.append(new OrderByWrapper(this.orderBy).getSqlSegment());
+        }
+
+        if(this.limit>0){
+            sql.append( " LIMIT "+this.limit);
+        }
+        return sql.toString();
+    }
+
+
+}

+ 81 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/UpdateSqlWrapper.java

@@ -0,0 +1,81 @@
+package com.xxh.cloud.framework.script.modules.sql.operate;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
+import com.xxh.cloud.framework.common.exception.BusinessException;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.UpdateBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.bean.WhereAndOrBean;
+import com.xxh.cloud.framework.script.modules.sql.operate.script.SqlConvertByType;
+import com.xxh.cloud.framework.script.modules.sql.operate.script.WhereWrapper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UpdateSqlWrapper implements ISqlWrapper{
+
+    private String tableName;
+    private List<UpdateBean> updates;
+    private List<WhereAndOrBean> wheres;
+
+
+
+    public UpdateSqlWrapper update(String tableName){
+        this.tableName=tableName;
+        return this;
+    }
+
+    public UpdateSqlWrapper Set(List<UpdateBean> updates){
+        this.updates=updates;
+        return this;
+    }
+
+    public UpdateSqlWrapper where(List<WhereAndOrBean> wheres){
+        this.wheres=wheres;
+        return this;
+    }
+
+    public UpdateSqlWrapper where(WhereAndOrBean where){
+        if(this.wheres==null){
+            this.wheres=new ArrayList<>();
+        }
+        if(where!=null){
+            this.wheres.add(where);
+        }
+        return this;
+    }
+
+    private void check() throws BusinessException {
+        if(StrUtil.isEmpty(this.tableName)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"表名不能为空");
+        }
+        if(CollUtil.isEmpty(this.updates)){
+            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"更新字段不能为空");
+        }
+//        if(CollUtil.isEmpty(this.wheres)){
+//            throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"");
+//        }
+
+    }
+
+    @Override
+    public String getSqlSegment(){
+        this.check();
+        StringBuilder sql=new StringBuilder();
+        sql.append(" Update ").append(this.tableName).append(" set ");
+        boolean isOne=true;
+        for(UpdateBean entity:this.updates){
+            if(isOne){
+                isOne=false;
+            }else{
+                sql.append(" , ");
+            }
+            sql.append(entity.getP()).append(" = ").append(SqlConvertByType.convert(entity.getT(),entity.getV()));
+        }
+        if(CollUtil.isNotEmpty(this.wheres)){
+            sql.append(" where ").append(new WhereWrapper(this.wheres).getSqlSegment());
+        }
+        return  sql.toString();
+    }
+
+}

+ 15 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/GroupByBean.java

@@ -0,0 +1,15 @@
+package com.xxh.cloud.framework.script.modules.sql.operate.bean;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class GroupByBean {
+
+    //数据模型
+    private String d;
+
+    //数据模型属性
+    private String p;
+}

+ 39 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/InsertBean.java

@@ -0,0 +1,39 @@
+package com.xxh.cloud.framework.script.modules.sql.operate.bean;
+
+import com.xxh.cloud.framework.script.modules.biz.constant.enums.TableDataTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class InsertBean {
+
+    @ApiModelProperty(value = "数据模型属性")
+    private String p;
+
+    @ApiModelProperty(value = "数据模型属性数据类型")
+    private String t;
+
+    @ApiModelProperty(value = "值")
+    private String v;
+
+
+    public InsertBean(String p, TableDataTypeEnum t, String v){
+        this.p=p;
+        this.t=t.getCode();
+        this.v=v;
+    }
+
+    public InsertBean(String p,String t,String v){
+        this.p=p;
+        this.t=t;
+        this.v=v;
+    }
+
+    public InsertBean(){
+
+    }
+
+
+}

+ 33 - 0
xx-config-script/src/main/java/com/xxh/cloud/framework/script/modules/sql/operate/bean/InsertColumnBean.java

@@ -0,0 +1,33 @@
+package com.xxh.cloud.framework.script.modules.sql.operate.bean;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class InsertColumnBean {
+
+
+    @ApiModelProperty(value = "数据模型属性")
+    private String p;
+
+    @ApiModelProperty(value = "数据模型属性数据类型(DataModelPropertyDtEnum)")
+    private String t;
+
+//    public InsertColumnBean(String p, DataTypeEnum t){
+//        this.p=p;
+//        this.t=t.getCode();
+//    }
+
+    public InsertColumnBean(String p,String t){
+        this.p=p;
+        this.t=t;
+    }
+
+    public InsertColumnBean(){
+
+    }
+
+
+}

Some files were not shown because too many files changed in this diff