parent
8c0766f197
commit
26172f3340
@ -0,0 +1,49 @@
|
||||
<?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>org.example</groupId>
|
||||
<artifactId>SentinelDemo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-core</artifactId>
|
||||
<version>1.8.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-transport-simple-http</artifactId>
|
||||
<version>1.8.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-annotation-aspectj</artifactId>
|
||||
<version>1.8.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-extension</artifactId>
|
||||
<version>1.8.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.5.14</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,16 @@
|
||||
package com.renchao.web.config;
|
||||
|
||||
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author ren_chao
|
||||
*/
|
||||
@Configuration
|
||||
public class SentinelConfig {
|
||||
@Bean
|
||||
public SentinelResourceAspect sentinelResourceAspect() {
|
||||
return new SentinelResourceAspect();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8088
|
||||
@ -0,0 +1,33 @@
|
||||
package com.renchao;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CollectorsExample {
|
||||
public static void main(String[] args) {
|
||||
List<String> words = Arrays.asList("apple", "banana", "apple", "orange", "banana");
|
||||
|
||||
// 不提供合并函数,会抛出 IllegalStateException 异常
|
||||
try {
|
||||
Map<String, Integer> wordLengthMap = words.stream()
|
||||
.collect(Collectors.toMap(
|
||||
word -> word, // 键映射函数
|
||||
String::length // 值映射函数
|
||||
));
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("IllegalStateException caught: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 提供合并函数,解决相同键冲突
|
||||
Map<String, Integer> wordLengthMap = words.stream()
|
||||
.collect(Collectors.toMap(
|
||||
word -> word, // 键映射函数
|
||||
String::length, // 值映射函数
|
||||
(existing, replacement) -> existing // 合并函数,保留已有值
|
||||
));
|
||||
|
||||
System.out.println(wordLengthMap);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>agile-data</artifactId>
|
||||
<groupId>com.jiuyv.sptcc.agile</groupId>
|
||||
<version>0.1.13-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>agile-data-api</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jiuyv.sptcc.agile</groupId>
|
||||
<artifactId>agile-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,179 +0,0 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.7</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.jiuyv.sptcc.agile</groupId>
|
||||
<artifactId>agile-data</artifactId>
|
||||
<version>0.1.13-SNAPSHOT</version>
|
||||
<name>agile-data</name>
|
||||
<description>agile-data</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<maven.clean.version>3.1.0</maven.clean.version>
|
||||
<maven.resource.version>3.1.0</maven.resource.version>
|
||||
<spring-cloud.version>2021.0.2</spring-cloud.version>
|
||||
<commons.lang.veriosn>3.3</commons.lang.veriosn>
|
||||
<hibernate.validator.version>6.2.3.Final</hibernate.validator.version>
|
||||
<openfeign.version>3.1.0</openfeign.version>
|
||||
<mybatis.version>1.3.0</mybatis.version>
|
||||
<agile.service.api>0.1.13-SNAPSHOT</agile.service.api>
|
||||
<agile-common>0.1.13</agile-common>
|
||||
<pageHelper.version>1.4.6</pageHelper.version>
|
||||
<caffeine.version>2.8.5</caffeine.version>
|
||||
<jsch.version>0.1.55</jsch.version>
|
||||
<aspose.version>20.3</aspose.version>
|
||||
<okhttp3.version>3.14.9</okhttp3.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jiuyv.sptcc.agile</groupId>
|
||||
<artifactId>agile-data-api</artifactId>
|
||||
<version>${agile.service.api}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jiuyv.sptcc.agile</groupId>
|
||||
<artifactId>agile-common</artifactId>
|
||||
<version>${agile-common}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<modules>
|
||||
<module>agile-data-api</module>
|
||||
<module>agile-data-service</module>
|
||||
</modules>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:http://172.16.12.10/svn/sptcc_agile_etl/src/agile-date-service/src/trunk/agile-dataservice</connection>
|
||||
<developerConnection>scm:svn:http://172.16.12.10/svn/sptcc_agile_etl/src/agile-date-service/src/trunk/agile-dataservice</developerConnection>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus-releases</id>
|
||||
<name>Internal Releases</name>
|
||||
<url>http://172.16.12.11:8082/repository/maven-releases/</url>
|
||||
</repository>
|
||||
|
||||
<snapshotRepository>
|
||||
<id>nexus-snapshots</id>
|
||||
<name>Internal Snapshots</name>
|
||||
<url>http://172.16.12.11:8082/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jiuyv</id>
|
||||
<name>jiuyv</name>
|
||||
<url>http://172.16.12.11:8082/repository/maven-public/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jboss</id>
|
||||
<name>jboss</name>
|
||||
<url>http://repository.jboss.org/maven2/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>geotools</id>
|
||||
<name>geotools</name>
|
||||
<url>http://maven.geotools.fr/repository/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jahia</id>
|
||||
<name>jahia</name>
|
||||
<url>http://maven.jahia.org/maven2/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vars</id>
|
||||
<name>vars</name>
|
||||
<url>http://vars.sourceforge.net/maven2/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>jiuyv</id>
|
||||
<name>jiuyv Plugin Repository</name>
|
||||
<url>http://172.16.12.11:8082/repository/maven-public/</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>central</id>
|
||||
<name>Maven Plugin Repository</name>
|
||||
<url>http://repo1.maven.org/maven2/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<!-- <skipTests>true</skipTests> <!–默认关掉单元测试 –>-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@ -1,40 +0,0 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>agile-data</artifactId>
|
||||
<groupId>com.jiuyv</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>agile-data-api</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,29 +0,0 @@
|
||||
package com.jiuyv.agile.data.api;
|
||||
|
||||
import com.jiuyv.agile.data.web.R;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* 敏捷API
|
||||
*
|
||||
* @author yulei
|
||||
*/
|
||||
public interface AgileApi {
|
||||
|
||||
/**
|
||||
* 发布接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/dataApis/{id}/release")
|
||||
public R<Object> releaseDataApi(@PathVariable Long id);
|
||||
|
||||
/**
|
||||
* 注销接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/dataApis/{id}/cancel")
|
||||
public R<Object> cancelDataApi(@PathVariable Long id);
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.enums;
|
||||
|
||||
public enum AlgorithmCrypto {
|
||||
|
||||
BASE64("1", "BASE64加密"),
|
||||
MD5("2", "MD5加密"),
|
||||
SHA_1("3", "SHA_1加密"),
|
||||
SHA_256("4", "SHA_256加密"),
|
||||
AES("5", "AES加密"),
|
||||
DES("6", "DES加密");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
AlgorithmCrypto(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static AlgorithmCrypto getAlgorithmCrypto(String algorithmCrypt) {
|
||||
for (AlgorithmCrypto type : AlgorithmCrypto.values()) {
|
||||
if (type.key.equals(algorithmCrypt)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return BASE64;
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.enums;
|
||||
|
||||
public enum CipherType {
|
||||
|
||||
REGEX("1", "正则替换"),
|
||||
ALGORITHM("2", "加密算法");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
CipherType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static CipherType getCipherType(String cipherType) {
|
||||
for (CipherType type : CipherType.values()) {
|
||||
if (type.key.equals(cipherType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return REGEX;
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.enums;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public enum ParamType {
|
||||
|
||||
String("1", "字符串"),
|
||||
Integer("2", "整型"),
|
||||
Float("3", "浮点型"),
|
||||
Date("4", "时间"),
|
||||
List("5", "集合");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
ParamType(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static Object parse(ParamType paramType, Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
switch (paramType) {
|
||||
case String:
|
||||
try {
|
||||
return (java.lang.String)obj;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("参数值[" + obj + "]不是" + String.getVal() + "数据类型]");
|
||||
}
|
||||
case Float:
|
||||
try {
|
||||
return new BigDecimal(obj.toString()).doubleValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("参数值[" + obj + "]不是" + Float.getVal() + "数据类型]");
|
||||
}
|
||||
case Integer:
|
||||
try {
|
||||
return (java.lang.Integer)obj;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("参数值[" + obj + "]不是" + Integer.getVal() + "数据类型]");
|
||||
}
|
||||
case List:
|
||||
try {
|
||||
return (java.util.List<?>)obj;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("参数值[" + obj + "]不是" + List.getVal() + "数据类型]");
|
||||
}
|
||||
case Date:
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
return sdf.parse(obj.toString());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return sdf.parse(obj.toString());
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("参数值[" + obj + "]不是" + Date.getVal() + "数据类型]");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ParamType getParamType(String paramType) {
|
||||
for (ParamType type : ParamType.values()) {
|
||||
if (type.key.equals(paramType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return String;
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.enums;
|
||||
|
||||
public enum RegexCrypto {
|
||||
|
||||
CHINESE_NAME("1", "中文姓名"),
|
||||
ID_CARD("2", "身份证号"),
|
||||
FIXED_PHONE("3", "固定电话"),
|
||||
MOBILE_PHONE("4", "手机号码"),
|
||||
ADDRESS("5", "地址"),
|
||||
EMAIL("6", "电子邮箱"),
|
||||
BANK_CARD("7", "银行卡号"),
|
||||
CNAPS_CODE("8", "公司开户银行联号");
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String val;
|
||||
|
||||
RegexCrypto(String key, String val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public static RegexCrypto getRegexCrypto(String regexCrypt) {
|
||||
for (RegexCrypto type : RegexCrypto.values()) {
|
||||
if (type.key.equals(regexCrypt)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return CHINESE_NAME;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.enums;
|
||||
|
||||
public enum WhereType {
|
||||
|
||||
EQUALS("1", "=", "等于"),
|
||||
NOT_EQUALS("2", "!=", "不等于"),
|
||||
LIKE("3", "LIKE", "全模糊查询"),
|
||||
LIKE_LEFT("4", "LIKE", "左模糊查询"),
|
||||
LIKE_RIGHT("5", "LIKE", "右模糊查询"),
|
||||
GREATER_THAN("6", ">", "大于"),
|
||||
GREATER_THAN_EQUALS("7", ">=", "大于等于"),
|
||||
LESS_THAN("8", "<", "小于"),
|
||||
LESS_THAN_EQUALS("9", "<=", "小于等于"),
|
||||
NULL("10", "IS NULL", "是否为空"),
|
||||
NOT_NULL("11", "IS NOT NULL", "是否不为空"),
|
||||
IN("12", "IN", "IN");
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String key;
|
||||
|
||||
private final String desc;
|
||||
|
||||
WhereType(String type, String key, String desc) {
|
||||
this.type = type;
|
||||
this.key = key;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static WhereType getWhereType(String whereType) {
|
||||
for (WhereType type : WhereType.values()) {
|
||||
if (type.type.equals(whereType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return EQUALS;
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据API脱敏信息表 查询实体
|
||||
* </p>
|
||||
*/
|
||||
public class ApiMaskQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String maskName;
|
||||
|
||||
private Long apiId;
|
||||
|
||||
public String getMaskName() {
|
||||
return maskName;
|
||||
}
|
||||
|
||||
public void setMaskName(String maskName) {
|
||||
this.maskName = maskName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ApiMaskQuery that = (ApiMaskQuery) o;
|
||||
return maskName.equals(that.maskName) && apiId.equals(that.apiId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(maskName, apiId);
|
||||
}
|
||||
|
||||
public Long getApiId() {
|
||||
return apiId;
|
||||
}
|
||||
|
||||
public void setApiId(Long apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class BaseQueryParams implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// 关键字
|
||||
private String keyword;
|
||||
// 当前页码
|
||||
private Integer pageNum = 1;
|
||||
// 分页条数
|
||||
private Integer pageSize = 20;
|
||||
// 排序
|
||||
private List<OrderItem> orderList;
|
||||
// 数据权限
|
||||
private String dataScope;
|
||||
|
||||
public class OrderItem{
|
||||
private String column;
|
||||
private boolean asc;
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public boolean isAsc() {
|
||||
return asc;
|
||||
}
|
||||
|
||||
public void setAsc(boolean asc) {
|
||||
this.asc = asc;
|
||||
}
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public List<OrderItem> getOrderList() {
|
||||
return orderList;
|
||||
}
|
||||
|
||||
public void setOrderList(List<OrderItem> orderList) {
|
||||
this.orderList = orderList;
|
||||
}
|
||||
|
||||
public String getDataScope() {
|
||||
return dataScope;
|
||||
}
|
||||
|
||||
public void setDataScope(String dataScope) {
|
||||
this.dataScope = dataScope;
|
||||
}
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据源连接信息Model
|
||||
*/
|
||||
public class DbSchema implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*/
|
||||
@NotBlank(message = "主机不能为空")
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
@NotNull(message = "端口不能为空")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据库
|
||||
*/
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* 服务名
|
||||
*/
|
||||
private String sid;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 执行配置信息Model
|
||||
*/
|
||||
public class ExecuteConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
@NotBlank(message = "数据源不能为空")
|
||||
private Long sourceId;
|
||||
|
||||
/**
|
||||
* 配置方式
|
||||
*/
|
||||
@NotNull(message = "配置方式不能为空")
|
||||
private String configType;
|
||||
|
||||
/**
|
||||
* 数据库表主键
|
||||
*/
|
||||
private Long tableId;
|
||||
|
||||
/**
|
||||
* 数据库表
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表字段列表
|
||||
*/
|
||||
@Valid
|
||||
private List<FieldParam> fieldParams;
|
||||
|
||||
/**
|
||||
* 解析SQL
|
||||
*/
|
||||
private String sqlText;
|
||||
|
||||
public Long getSourceId() {
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public void setSourceId(Long sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
public String getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public void setConfigType(String configType) {
|
||||
this.configType = configType;
|
||||
}
|
||||
|
||||
public Long getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public void setTableId(Long tableId) {
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<FieldParam> getFieldParams() {
|
||||
return fieldParams;
|
||||
}
|
||||
|
||||
public void setFieldParams(List<FieldParam> fieldParams) {
|
||||
this.fieldParams = fieldParams;
|
||||
}
|
||||
|
||||
public String getSqlText() {
|
||||
return sqlText;
|
||||
}
|
||||
|
||||
public void setSqlText(String sqlText) {
|
||||
this.sqlText = sqlText;
|
||||
}
|
||||
}
|
||||
@ -1,167 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 字段信息Model
|
||||
*/
|
||||
public class FieldParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 列名
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 数据长度
|
||||
*/
|
||||
private Integer dataLength;
|
||||
|
||||
/**
|
||||
* 数据精度
|
||||
*/
|
||||
private Integer dataPrecision;
|
||||
|
||||
/**
|
||||
* 数据小数位
|
||||
*/
|
||||
private Integer dataScale;
|
||||
|
||||
/**
|
||||
* 是否主键
|
||||
*/
|
||||
private String columnKey;
|
||||
|
||||
/**
|
||||
* 是否允许为空
|
||||
*/
|
||||
private String columnNullable;
|
||||
|
||||
/**
|
||||
* 列的序号
|
||||
*/
|
||||
private Integer columnPosition;
|
||||
|
||||
/**
|
||||
* 列默认值
|
||||
*/
|
||||
private String dataDefault;
|
||||
|
||||
/**
|
||||
* 列注释
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/**
|
||||
* 作为请求参数
|
||||
*/
|
||||
private String reqable;
|
||||
|
||||
/**
|
||||
* 作为返回参数
|
||||
*/
|
||||
private String resable;
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public Integer getDataLength() {
|
||||
return dataLength;
|
||||
}
|
||||
|
||||
public void setDataLength(Integer dataLength) {
|
||||
this.dataLength = dataLength;
|
||||
}
|
||||
|
||||
public Integer getDataPrecision() {
|
||||
return dataPrecision;
|
||||
}
|
||||
|
||||
public void setDataPrecision(Integer dataPrecision) {
|
||||
this.dataPrecision = dataPrecision;
|
||||
}
|
||||
|
||||
public Integer getDataScale() {
|
||||
return dataScale;
|
||||
}
|
||||
|
||||
public void setDataScale(Integer dataScale) {
|
||||
this.dataScale = dataScale;
|
||||
}
|
||||
|
||||
public String getColumnKey() {
|
||||
return columnKey;
|
||||
}
|
||||
|
||||
public void setColumnKey(String columnKey) {
|
||||
this.columnKey = columnKey;
|
||||
}
|
||||
|
||||
public String getColumnNullable() {
|
||||
return columnNullable;
|
||||
}
|
||||
|
||||
public void setColumnNullable(String columnNullable) {
|
||||
this.columnNullable = columnNullable;
|
||||
}
|
||||
|
||||
public Integer getColumnPosition() {
|
||||
return columnPosition;
|
||||
}
|
||||
|
||||
public void setColumnPosition(Integer columnPosition) {
|
||||
this.columnPosition = columnPosition;
|
||||
}
|
||||
|
||||
public String getDataDefault() {
|
||||
return dataDefault;
|
||||
}
|
||||
|
||||
public void setDataDefault(String dataDefault) {
|
||||
this.dataDefault = dataDefault;
|
||||
}
|
||||
|
||||
public String getColumnComment() {
|
||||
return columnComment;
|
||||
}
|
||||
|
||||
public void setColumnComment(String columnComment) {
|
||||
this.columnComment = columnComment;
|
||||
}
|
||||
|
||||
public String getReqable() {
|
||||
return reqable;
|
||||
}
|
||||
|
||||
public void setReqable(String reqable) {
|
||||
this.reqable = reqable;
|
||||
}
|
||||
|
||||
public String getResable() {
|
||||
return resable;
|
||||
}
|
||||
|
||||
public void setResable(String resable) {
|
||||
this.resable = resable;
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 字段信息Model
|
||||
*/
|
||||
public class FieldRule implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
@NotBlank(message = "字段名称不能为空")
|
||||
private String fieldName;
|
||||
/**
|
||||
* 脱敏类型
|
||||
*/
|
||||
@NotNull(message = "脱敏类型不能为空")
|
||||
private String cipherType;
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@NotNull(message = "规则类型不能为空")
|
||||
private String cryptType;
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void setFieldName(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public String getCipherType() {
|
||||
return cipherType;
|
||||
}
|
||||
|
||||
public void setCipherType(String cipherType) {
|
||||
this.cipherType = cipherType;
|
||||
}
|
||||
|
||||
public String getCryptType() {
|
||||
return cryptType;
|
||||
}
|
||||
|
||||
public void setCryptType(String cryptType) {
|
||||
this.cryptType = cryptType;
|
||||
}
|
||||
}
|
||||
@ -1,111 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 请求参数信息Model
|
||||
*/
|
||||
public class ReqParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 参数名称
|
||||
*/
|
||||
@NotBlank(message = "参数名称不能为空")
|
||||
private String paramName;
|
||||
|
||||
/**
|
||||
* 是否为空
|
||||
*/
|
||||
@NotNull(message = "是否为空不能为空")
|
||||
private String nullable;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@NotBlank(message = "描述不能为空")
|
||||
private String paramComment;
|
||||
|
||||
/**
|
||||
* 操作符
|
||||
*/
|
||||
@NotNull(message = "操作符不能为空")
|
||||
private String whereType;
|
||||
|
||||
/**
|
||||
* 参数类型
|
||||
*/
|
||||
@NotNull(message = "参数类型不能为空")
|
||||
private String paramType;
|
||||
|
||||
/**
|
||||
* 示例值
|
||||
*/
|
||||
@NotBlank(message = "示例值不能为空")
|
||||
private String exampleValue;
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
@NotBlank(message = "默认值不能为空")
|
||||
private String defaultValue;
|
||||
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
|
||||
public void setParamName(String paramName) {
|
||||
this.paramName = paramName;
|
||||
}
|
||||
|
||||
public String getNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
public void setNullable(String nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
|
||||
public String getParamComment() {
|
||||
return paramComment;
|
||||
}
|
||||
|
||||
public void setParamComment(String paramComment) {
|
||||
this.paramComment = paramComment;
|
||||
}
|
||||
|
||||
public String getWhereType() {
|
||||
return whereType;
|
||||
}
|
||||
|
||||
public void setWhereType(String whereType) {
|
||||
this.whereType = whereType;
|
||||
}
|
||||
|
||||
public String getParamType() {
|
||||
return paramType;
|
||||
}
|
||||
|
||||
public void setParamType(String paramType) {
|
||||
this.paramType = paramType;
|
||||
}
|
||||
|
||||
public String getExampleValue() {
|
||||
return exampleValue;
|
||||
}
|
||||
|
||||
public void setExampleValue(String exampleValue) {
|
||||
this.exampleValue = exampleValue;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* API请求参数
|
||||
*
|
||||
* @author yulei
|
||||
*/
|
||||
public class ReqVo implements Serializable {
|
||||
|
||||
|
||||
/** 报文内容 */
|
||||
private String body;
|
||||
|
||||
/** 签名 */
|
||||
private String sign;
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.response;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 返回参数信息Model
|
||||
*/
|
||||
public class ResParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
@NotBlank(message = "字段名称不能为空")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@NotBlank(message = "描述不能为空")
|
||||
private String fieldComment;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
@NotNull(message = "数据类型不能为空")
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 示例值
|
||||
*/
|
||||
@NotBlank(message = "示例值不能为空")
|
||||
private String exampleValue;
|
||||
|
||||
/**
|
||||
* 字段别名
|
||||
*/
|
||||
private String fieldAliasName;
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void setFieldName(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public String getFieldComment() {
|
||||
return fieldComment;
|
||||
}
|
||||
|
||||
public void setFieldComment(String fieldComment) {
|
||||
this.fieldComment = fieldComment;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getExampleValue() {
|
||||
return exampleValue;
|
||||
}
|
||||
|
||||
public void setExampleValue(String exampleValue) {
|
||||
this.exampleValue = exampleValue;
|
||||
}
|
||||
|
||||
public String getFieldAliasName() {
|
||||
return fieldAliasName;
|
||||
}
|
||||
|
||||
public void setFieldAliasName(String fieldAliasName) {
|
||||
this.fieldAliasName = fieldAliasName;
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
package com.jiuyv.agile.data.dto.response;
|
||||
|
||||
import com.jiuyv.agile.data.web.ResultCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* API返回参数
|
||||
*
|
||||
* @author yulei
|
||||
*/
|
||||
public class RespVo implements Serializable {
|
||||
|
||||
/** 返回码*/
|
||||
private Integer respCode;
|
||||
|
||||
/** 返回说明 */
|
||||
private String respDesc;
|
||||
|
||||
public RespVo() {
|
||||
}
|
||||
|
||||
public RespVo(Integer code, String message) {
|
||||
this.respCode = code;
|
||||
this.respDesc = message;
|
||||
}
|
||||
|
||||
public static RespVo ok(){
|
||||
return new RespVo(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
|
||||
}
|
||||
|
||||
public Integer getRespCode() {
|
||||
return respCode;
|
||||
}
|
||||
|
||||
public void setRespCode(Integer respCode) {
|
||||
this.respCode = respCode;
|
||||
}
|
||||
|
||||
public String getRespDesc() {
|
||||
return respDesc;
|
||||
}
|
||||
|
||||
public void setRespDesc(String respDesc) {
|
||||
this.respDesc = respDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RespVo{" +
|
||||
"respCode='" + respCode + '\'' +
|
||||
", respDesc='" + respDesc + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.jiuyv.agile.data.web;
|
||||
|
||||
/**
|
||||
* @ClassName : IErrorCode
|
||||
* @Description : 常用API返回对接接口
|
||||
* @Author : sky
|
||||
* @Date: 2023-06-06 16:33
|
||||
*/
|
||||
public interface IErrorCode {
|
||||
|
||||
/**
|
||||
* 返回码
|
||||
*/
|
||||
Integer getCode();
|
||||
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
String getMessage();
|
||||
}
|
||||
@ -1,107 +0,0 @@
|
||||
package com.jiuyv.agile.data.web;
|
||||
|
||||
|
||||
import com.jiuyv.agile.data.web.constant.HttpStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 响应信息主体
|
||||
*
|
||||
* @author admin
|
||||
*/
|
||||
public class R<T> implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 成功 */
|
||||
public static final int SUCCESS = HttpStatus.SUCCESS;
|
||||
|
||||
/** 失败 */
|
||||
public static final int FAIL = HttpStatus.ERROR;
|
||||
|
||||
private int code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <T> R<T> ok()
|
||||
{
|
||||
return restResult(null, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
public static <T> R<T> ok(T data)
|
||||
{
|
||||
return restResult(data, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
public static <T> R<T> ok(T data, String msg)
|
||||
{
|
||||
return restResult(data, SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail()
|
||||
{
|
||||
return restResult(null, FAIL, "操作失败");
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(String msg)
|
||||
{
|
||||
return restResult(null, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(T data)
|
||||
{
|
||||
return restResult(data, FAIL, "操作失败");
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(T data, String msg)
|
||||
{
|
||||
return restResult(data, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(int code, String msg)
|
||||
{
|
||||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
private static <T> R<T> restResult(T data, int code, String msg)
|
||||
{
|
||||
R<T> apiResult = new R<>();
|
||||
apiResult.setCode(code);
|
||||
apiResult.setData(data);
|
||||
apiResult.setMsg(msg);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code)
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg()
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg)
|
||||
{
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package com.jiuyv.agile.data.web;
|
||||
|
||||
/**
|
||||
* 常用API返回对象
|
||||
* Created by macro on 2019/4/19.
|
||||
*/
|
||||
public enum ResultCode implements IErrorCode {
|
||||
/** success : 成功. */
|
||||
SUCCESS(200, "操作成功"),
|
||||
ACCEPTED(202, "请求已经被接受"),
|
||||
NO_CONTENT(204, "操作已经执行成功,但是没有返回数据"),
|
||||
MOVED_PERM(301, "资源已被移除"),
|
||||
|
||||
SEE_OTHER(303, "重定向"),
|
||||
NOT_MODIFIED(304, "资源没有被修改"),
|
||||
BAD_REQUEST(400, "参数列表错误(缺少,格式不匹配)"),
|
||||
UNAUTHORIZED(401, "未授权"),
|
||||
FORBIDDEN(403, "访问受限,授权过期"),
|
||||
NOT_FOUND(404, "资源,服务未找到"),
|
||||
BAD_METHOD(405, "不允许的http方法"),
|
||||
CONFLICT(409, "资源冲突,或者资源被锁"),
|
||||
ERROR(500, "系统内部错误"),
|
||||
NOT_IMPLEMENTED(501, "接口未实现"),
|
||||
//PROCESS("process", "订单处理中,请稍后查询"),
|
||||
//FAILED("failed", "操作失败"),
|
||||
//VALIDATE_FAILED("input_not_valid", "输入不合法"),
|
||||
//REPEAT_SUBMIT("duplicate_req_id", "请勿重复提交"),
|
||||
//AUTHORIZATION_LIMIT("authorization limit", "权限限制"),
|
||||
//UNAUTHORIZED("401", "暂未登录或token已经过期"),
|
||||
//
|
||||
//ILLEGALLY("illegally request", "不合法请求"),
|
||||
///** input_not_valid : 输入不合法. */
|
||||
//INPUT_NOT_VALID("input_not_valid", "输入不合法"),
|
||||
///** duplicate_req_id : 重复请求. */
|
||||
//DUPLICATE_REQ_ID("duplicate_req_id","重复请求"),
|
||||
///** duplicate_order : 订单重复. */
|
||||
//DUPLICATE_ORDER("duplicate_order","订单重复"),
|
||||
//
|
||||
///** product_limit : 商品限购 */
|
||||
//SYS_ERROR("sys_error","系统异常"),
|
||||
///** business_error : 调用返回非成功 */
|
||||
//BUSINESS_ERROR("business_error","调用返回非成功"),
|
||||
///** sql_lock_exception : 乐观锁异常*/
|
||||
//SQL_EXCEPTION("sql_lock_exception","乐观锁异常"),
|
||||
//
|
||||
///** file_not_exist,请输入正确的权益号 */
|
||||
//FILE_NOT_EXIST("file_not_exist","文件不存在"),
|
||||
///** file_no_data,文件内容为空 */
|
||||
//FILE_NO_DATA("file_no_data","文件内容为空");
|
||||
;
|
||||
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
private ResultCode(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>agile-data</artifactId>
|
||||
<groupId>com.jiuyv</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>agile-data-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jiuyv</groupId>
|
||||
<artifactId>agile-data-api</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional> <!-- 表示依赖不会传递 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Mybatis-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- postgresql连接 -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -1,30 +0,0 @@
|
||||
package com.jiuyv.agile.data;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @author yulei
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class AgileDataApplication {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AgileDataApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AgileDataApplication.class, args);
|
||||
LOGGER.info("(♥◠‿◠)ノ゙ 模块启动成功゙ \n"+
|
||||
" ___ ___ ___ \n"+
|
||||
" |\\ \\ |\\ \\ / /| \n"+
|
||||
" \\ \\ \\ \\ \\ \\/ / / \n"+
|
||||
" __ \\ \\ \\ \\ \\ / / \n"+
|
||||
" |\\ \\\\_\\ \\ \\/ / / \n"+
|
||||
" \\ \\________\\ __/ / / \n"+
|
||||
" \\|________| |\\___/ / \n"+
|
||||
" \\|___|/ \n"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,211 +0,0 @@
|
||||
package com.jiuyv.agile.data.common.constants;
|
||||
|
||||
public class DataConstant {
|
||||
|
||||
/**
|
||||
* Oauth2安全相关常量
|
||||
*/
|
||||
public enum Security {
|
||||
//请求头TOKEN名称
|
||||
TOKENHEADER("gatewayToken"),
|
||||
//请求头TOKEN值
|
||||
TOKENVALUE("datax:gateway:123456"),
|
||||
//OAUTH2请求头
|
||||
AUTHORIZATION("Authorization"),
|
||||
//OAUTH2令牌类型
|
||||
TOKENTYPE("bearer "),
|
||||
//security授权角色前缀
|
||||
ROLEPREFIX("ROLE_");
|
||||
|
||||
Security(String val){
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String val;
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的是否
|
||||
*/
|
||||
public enum TrueOrFalse {
|
||||
FALSE("0",false),
|
||||
TRUE("1",true);
|
||||
|
||||
TrueOrFalse(String key, boolean val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final boolean val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public boolean getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户认证返回额外信息
|
||||
*/
|
||||
public enum UserAdditionalInfo {
|
||||
LICENSE("license", "datax"),
|
||||
USER("user", "用户"),
|
||||
USERID("user_id", "用户ID"),
|
||||
USERNAME("username", "用户名"),
|
||||
NICKNAME("nickname", "用户昵称"),
|
||||
DEPT("user_dept", "用户部门"),
|
||||
ROLE("user_role", "用户角色"),
|
||||
POST("user_post", "用户岗位");
|
||||
|
||||
UserAdditionalInfo(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的启用禁用状态
|
||||
*/
|
||||
public enum EnableState {
|
||||
DISABLE("0","禁用"),
|
||||
ENABLE("1","启用");
|
||||
|
||||
EnableState(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程审核状态
|
||||
*/
|
||||
public enum AuditState{
|
||||
WAIT("1","待提交"),
|
||||
BACK("2", "已退回"),
|
||||
AUDIT("3","审核中"),
|
||||
AGREE("4","通过"),
|
||||
REJECT("5","不通过"),
|
||||
CANCEL("6", "已撤销");
|
||||
|
||||
AuditState(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单类型
|
||||
*/
|
||||
public enum MenuType{
|
||||
MODULE("0","模块"),
|
||||
MENU("1","菜单"),
|
||||
BUTTON("2","按钮");
|
||||
|
||||
MenuType(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据范围
|
||||
*/
|
||||
public enum DataScope{
|
||||
ALL("1","全部数据权限"),
|
||||
CUSTOM("2","自定义数据权限"),
|
||||
DEPT("3","本部门数据权限"),
|
||||
DEPTANDCHILD("4","本部门及以下数据权限"),
|
||||
SELF("5","仅本人数据权限");
|
||||
DataScope(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Api状态
|
||||
*/
|
||||
public enum ApiState{
|
||||
WAIT("1","待发布"),
|
||||
RELEASE("2","已发布"),
|
||||
CANCEL("3","已下线");
|
||||
ApiState(String key, String val){
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final String val;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package com.jiuyv.agile.data.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jiuyv.agile.data.handler.MappingHandlerMapping;
|
||||
import com.jiuyv.agile.data.handler.RequestHandler;
|
||||
import com.jiuyv.agile.data.handler.RequestInterceptor;
|
||||
import com.jiuyv.agile.data.service.impl.ApiMappingEngine;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
@Configuration
|
||||
public class ApiMappingConfig {
|
||||
|
||||
@Bean
|
||||
public MappingHandlerMapping mappingHandlerMapping(RequestMappingHandlerMapping requestMappingHandlerMapping,
|
||||
ApiMappingEngine apiMappingEngine,
|
||||
ObjectMapper objectMapper) {
|
||||
MappingHandlerMapping mappingHandlerMapping = new MappingHandlerMapping();
|
||||
mappingHandlerMapping.setHandler(requestHandler(apiMappingEngine, objectMapper));
|
||||
mappingHandlerMapping.setRequestMappingHandlerMapping(requestMappingHandlerMapping);
|
||||
return mappingHandlerMapping;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RequestHandler requestHandler(ApiMappingEngine apiMappingEngine, ObjectMapper objectMapper) {
|
||||
RequestHandler handler = new RequestHandler();
|
||||
handler.setApiMappingEngine(apiMappingEngine);
|
||||
handler.setObjectMapper(objectMapper);
|
||||
handler.setRequestInterceptor(new RequestInterceptor());
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package com.jiuyv.agile.data.controller;
|
||||
|
||||
import com.jiuyv.agile.data.service.AgileApiService;
|
||||
import com.jiuyv.agile.data.web.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 敏捷API控制
|
||||
*
|
||||
* @author yulei
|
||||
*/
|
||||
@RestController
|
||||
public class AgileApiController {
|
||||
|
||||
@Autowired
|
||||
private AgileApiService agileApiService;
|
||||
|
||||
/**
|
||||
* 发布接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/dataApis/{id}/release")
|
||||
public R<Object> releaseDataApi(@PathVariable Long id){
|
||||
agileApiService.releaseDataApi(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销接口
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/dataApis/{id}/cancel")
|
||||
public R<Object> cancelDataApi(@PathVariable Long id){
|
||||
agileApiService.cancelDataApi(id);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.jiuyv.agile.data.controller;
|
||||
|
||||
import com.jiuyv.agile.data.api.AgileApi;
|
||||
|
||||
|
||||
public interface ts extends AgileApi {
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package com.jiuyv.agile.data.controller;
|
||||
|
||||
import com.jiuyv.agile.data.api.AgileApi;
|
||||
import com.jiuyv.agile.data.service.AgileApiService;
|
||||
import com.jiuyv.agile.data.web.R;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class tt implements AgileApi {
|
||||
/**
|
||||
* 发布接口
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<Object> releaseDataApi(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销接口
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<Object> cancelDataApi(Long id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
public interface DataSourceFactory {
|
||||
|
||||
/**
|
||||
* 创建数据源实例
|
||||
*
|
||||
* @param property
|
||||
* @return
|
||||
*/
|
||||
DbQuery createDbQuery(DbQueryProperty property);
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
public class DbColumn {
|
||||
|
||||
/**
|
||||
* 列名
|
||||
*/
|
||||
private String colName;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 数据长度
|
||||
*/
|
||||
private String dataLength;
|
||||
|
||||
/**
|
||||
* 数据精度
|
||||
*/
|
||||
private String dataPrecision;
|
||||
|
||||
/**
|
||||
* 数据小数位
|
||||
*/
|
||||
private String dataScale;
|
||||
|
||||
/**
|
||||
* 是否主键
|
||||
*/
|
||||
private Boolean colKey;
|
||||
|
||||
/**
|
||||
* 是否允许为空
|
||||
*/
|
||||
private Boolean nullable;
|
||||
|
||||
/**
|
||||
* 列的序号
|
||||
*/
|
||||
private Integer colPosition;
|
||||
|
||||
/**
|
||||
* 列默认值
|
||||
*/
|
||||
private String dataDefault;
|
||||
|
||||
/**
|
||||
* 列注释
|
||||
*/
|
||||
private String colComment;
|
||||
|
||||
public String getColName() {
|
||||
return colName;
|
||||
}
|
||||
|
||||
public void setColName(String colName) {
|
||||
this.colName = colName;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getDataLength() {
|
||||
return dataLength;
|
||||
}
|
||||
|
||||
public void setDataLength(String dataLength) {
|
||||
this.dataLength = dataLength;
|
||||
}
|
||||
|
||||
public String getDataPrecision() {
|
||||
return dataPrecision;
|
||||
}
|
||||
|
||||
public void setDataPrecision(String dataPrecision) {
|
||||
this.dataPrecision = dataPrecision;
|
||||
}
|
||||
|
||||
public String getDataScale() {
|
||||
return dataScale;
|
||||
}
|
||||
|
||||
public void setDataScale(String dataScale) {
|
||||
this.dataScale = dataScale;
|
||||
}
|
||||
|
||||
public Boolean getColKey() {
|
||||
return colKey;
|
||||
}
|
||||
|
||||
public void setColKey(Boolean colKey) {
|
||||
this.colKey = colKey;
|
||||
}
|
||||
|
||||
public Boolean getNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
public void setNullable(Boolean nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
|
||||
public Integer getColPosition() {
|
||||
return colPosition;
|
||||
}
|
||||
|
||||
public void setColPosition(Integer colPosition) {
|
||||
this.colPosition = colPosition;
|
||||
}
|
||||
|
||||
public String getDataDefault() {
|
||||
return dataDefault;
|
||||
}
|
||||
|
||||
public void setDataDefault(String dataDefault) {
|
||||
this.dataDefault = dataDefault;
|
||||
}
|
||||
|
||||
public String getColComment() {
|
||||
return colComment;
|
||||
}
|
||||
|
||||
public void setColComment(String colComment) {
|
||||
this.colComment = colComment;
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* 表数据查询接口
|
||||
*/
|
||||
public interface DbDialect {
|
||||
|
||||
RowMapper<DbTable> tableMapper();
|
||||
|
||||
RowMapper<DbColumn> columnMapper();
|
||||
|
||||
/**
|
||||
* 获取指定表的所有列
|
||||
*
|
||||
* @param dbName
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
String columns(String dbName, String tableName);
|
||||
|
||||
/**
|
||||
* 获取数据库下的 所有表
|
||||
*
|
||||
* @param dbName
|
||||
* @return
|
||||
*/
|
||||
String tables(String dbName);
|
||||
|
||||
/**
|
||||
* 构建 分页 sql
|
||||
*
|
||||
* @param sql
|
||||
* @param offset
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
String buildPaginationSql(String sql, long offset, long count);
|
||||
|
||||
/**
|
||||
* 包装 count sql
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
String count(String sql);
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class DbMD5Util {
|
||||
|
||||
private static final char[] HEX_CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*/
|
||||
public static String encrypt(String value){
|
||||
return encrypt(value.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*/
|
||||
public static String encrypt(byte[] value){
|
||||
try {
|
||||
byte[] bytes = MessageDigest.getInstance("MD5").digest(value);
|
||||
char[] chars = new char[32];
|
||||
for (int i = 0; i < chars.length; i = i + 2) {
|
||||
byte b = bytes[i / 2];
|
||||
chars[i] = HEX_CHARS[(b >>> 0x4) & 0xf];
|
||||
chars[i + 1] = HEX_CHARS[b & 0xf];
|
||||
}
|
||||
return new String(chars);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("md5 encrypt error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 表数据查询接口
|
||||
*/
|
||||
public interface DbQuery {
|
||||
|
||||
/**
|
||||
* 获取数据库连接
|
||||
*/
|
||||
Connection getConnection();
|
||||
|
||||
/**
|
||||
* 检测连通性
|
||||
*/
|
||||
boolean valid();
|
||||
|
||||
/**
|
||||
* 关闭数据源
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* 获取指定表 具有的所有字段列表
|
||||
* @param dbName
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<DbColumn> getTableColumns(String dbName, String tableName);
|
||||
|
||||
/**
|
||||
* 获取指定数据库下 所有的表信息
|
||||
*
|
||||
* @param dbName
|
||||
* @return
|
||||
*/
|
||||
List<DbTable> getTables(String dbName);
|
||||
|
||||
/**
|
||||
* 获取总数
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
int count(String sql);
|
||||
|
||||
/**
|
||||
* 获取总数带查询参数
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
int count(String sql, Object[] args);
|
||||
|
||||
/**
|
||||
* 获取总数带查询参数 NamedParameterJdbcTemplate
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
int count(String sql, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 查询结果列表
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> queryList(String sql);
|
||||
|
||||
/**
|
||||
* 查询结果列表带查询参数
|
||||
*
|
||||
* @param sql
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> queryList(String sql, Object[] args);
|
||||
|
||||
/**
|
||||
* 查询结果分页
|
||||
*
|
||||
* @param sql
|
||||
* @param offset
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
PageResult<Map<String, Object>> queryByPage(String sql, long offset, long size);
|
||||
|
||||
/**
|
||||
* 查询结果分页带查询参数
|
||||
* @param sql
|
||||
* @param args
|
||||
* @param offset
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
PageResult<Map<String, Object>> queryByPage(String sql, Object[] args, long offset, long size);
|
||||
|
||||
/**
|
||||
* 查询结果分页带查询参数 NamedParameterJdbcTemplate
|
||||
* @param sql
|
||||
* @param params
|
||||
* @param offset
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
PageResult<Map<String, Object>> queryByPage(String sql, Map<String, Object> params, long offset, long size);
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
//@AllArgsConstructor
|
||||
public class DbQueryProperty implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String dbType;
|
||||
private String host;
|
||||
private String username;
|
||||
private String password;
|
||||
private Integer port;
|
||||
private String dbName;
|
||||
private String sid;
|
||||
|
||||
/**
|
||||
* 参数合法性校验
|
||||
*/
|
||||
public void viald() {
|
||||
if (StringUtils.isEmpty(dbType) || StringUtils.isEmpty(host) ||
|
||||
StringUtils.isEmpty(username) || StringUtils.isEmpty(password) ||
|
||||
StringUtils.isEmpty(port)) {
|
||||
throw new RuntimeException("参数不完整");
|
||||
}
|
||||
if (DbType.OTHER.getDb().equals(dbType)) {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
}
|
||||
|
||||
public DbQueryProperty(String dbType, String host, String username, String password, Integer port, String dbName, String sid) {
|
||||
this.dbType = dbType;
|
||||
this.host = host;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.port = port;
|
||||
this.dbName = dbName;
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
public class DbTable {
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getTableComment() {
|
||||
return tableComment;
|
||||
}
|
||||
|
||||
public void setTableComment(String tableComment) {
|
||||
this.tableComment = tableComment;
|
||||
}
|
||||
}
|
||||
@ -1,87 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
public enum DbType {
|
||||
|
||||
/**
|
||||
* MYSQL
|
||||
*/
|
||||
MYSQL("1", "MySql数据库", "jdbc:mysql://${host}:${port}/${dbName}?serverTimezone=GMT%2B8&characterEncoding=UTF-8&useUnicode=true&useSSL=false"),
|
||||
/**
|
||||
* MARIADB
|
||||
*/
|
||||
MARIADB("2", "MariaDB数据库", "jdbc:mariadb://${host}:${port}/${dbName}"),
|
||||
/**
|
||||
* ORACLE
|
||||
*/
|
||||
ORACLE("3", "Oracle11g及以下数据库", "jdbc:oracle:thin:@${host}:${port}:${sid}"),
|
||||
/**
|
||||
* oracle12c new pagination
|
||||
*/
|
||||
ORACLE_12C("4", "Oracle12c+数据库", "jdbc:oracle:thin:@${host}:${port}:${sid}"),
|
||||
/**
|
||||
* POSTGRESQL
|
||||
*/
|
||||
POSTGRE_SQL("5", "PostgreSql数据库", "jdbc:postgresql://${host}:${port}/${dbName}"),
|
||||
/**
|
||||
* SQLSERVER2005
|
||||
*/
|
||||
SQL_SERVER2008("6", "SQLServer2008及以下数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"),
|
||||
/**
|
||||
* SQLSERVER
|
||||
*/
|
||||
SQL_SERVER("7", "SQLServer2012+数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"),
|
||||
/**
|
||||
* UNKONWN DB
|
||||
*/
|
||||
OTHER("8", "其他数据库", "");
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private final String db;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* url
|
||||
*/
|
||||
private final String url;
|
||||
|
||||
public String getDb() {
|
||||
return this.db;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
DbType(String db, String desc, String url) {
|
||||
this.db = db;
|
||||
this.desc = desc;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库类型
|
||||
*
|
||||
* @param dbType 数据库类型字符串
|
||||
*/
|
||||
public static DbType getDbType(String dbType) {
|
||||
for (DbType type : DbType.values()) {
|
||||
if (type.db.equals(dbType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return OTHER;
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
import com.jiuyv.agile.data.database.dialect.DialectRegistry;
|
||||
|
||||
/**
|
||||
* 方言工厂类
|
||||
*/
|
||||
public class DialectFactory {
|
||||
|
||||
private static final DialectRegistry DIALECT_REGISTRY = new DialectRegistry();
|
||||
|
||||
public static DbDialect getDialect(DbType dbType) {
|
||||
return DIALECT_REGISTRY.getDialect(dbType);
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
//@Accessors(chain = true)
|
||||
public class PageResult<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
private Integer total;
|
||||
private List<T> data;
|
||||
|
||||
public PageResult(Integer total, List<T> data) {
|
||||
this.total = total;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<T> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<T> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@ -1,123 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.cache;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class DefaultSqlCache extends LinkedHashMap<String, DefaultSqlCache.ExpireNode<Object>> implements SqlCache {
|
||||
|
||||
private int capacity;
|
||||
|
||||
private long expire;
|
||||
|
||||
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
public DefaultSqlCache(int capacity, long expire) {
|
||||
super((int) Math.ceil(capacity / 0.75) + 1, 0.75f, true);
|
||||
// 容量
|
||||
this.capacity = capacity;
|
||||
// 固定过期时间
|
||||
this.expire = expire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, Object value, long ttl) {
|
||||
long expireTime = Long.MAX_VALUE;
|
||||
if (ttl >= 0) {
|
||||
expireTime = System.currentTimeMillis() + (ttl == 0 ? this.expire : ttl);
|
||||
}
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
// 封装成过期时间节点
|
||||
put(key, new ExpireNode<>(expireTime, value));
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
lock.readLock().lock();
|
||||
ExpireNode<Object> expireNode;
|
||||
try {
|
||||
expireNode = super.get(key);
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
if (expireNode == null) {
|
||||
return null;
|
||||
}
|
||||
// 惰性删除过期的
|
||||
if (this.expire > -1L && expireNode.expire < System.currentTimeMillis()) {
|
||||
try {
|
||||
lock.writeLock().lock();
|
||||
super.remove(key);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return expireNode.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String key) {
|
||||
try {
|
||||
lock.writeLock().lock();
|
||||
Iterator<Map.Entry<String, ExpireNode<Object>>> iterator = super.entrySet().iterator();
|
||||
// 清除key的缓存
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, ExpireNode<Object>> entry = iterator.next();
|
||||
if (entry.getKey().equals(key)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, ExpireNode<Object>> eldest) {
|
||||
if (this.expire > -1L && size() > capacity) {
|
||||
clean();
|
||||
}
|
||||
// lru淘汰
|
||||
return size() > this.capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理已过期的数据
|
||||
*/
|
||||
private void clean() {
|
||||
try {
|
||||
lock.writeLock().lock();
|
||||
Iterator<Map.Entry<String, ExpireNode<Object>>> iterator = super.entrySet().iterator();
|
||||
long now = System.currentTimeMillis();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, ExpireNode<Object>> next = iterator.next();
|
||||
// 判断是否过期
|
||||
if (next.getValue().expire < now) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 过期时间节点
|
||||
*/
|
||||
static class ExpireNode<V> {
|
||||
long expire;
|
||||
Object value;
|
||||
public ExpireNode(long expire, Object value) {
|
||||
this.expire = expire;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.cache;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbMD5Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* SQL缓存接口
|
||||
*/
|
||||
public interface SqlCache {
|
||||
|
||||
/**
|
||||
* 计算key
|
||||
*/
|
||||
default String buildSqlCacheKey(String sql, Object[] args) {
|
||||
return DbMD5Util.encrypt(sql + ":" + Arrays.toString(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* 存入缓存
|
||||
* @param key key
|
||||
* @param value 值
|
||||
*/
|
||||
void put(String key, Object value, long ttl);
|
||||
|
||||
/**
|
||||
* 获取缓存
|
||||
* @param key key
|
||||
* @return
|
||||
*/
|
||||
<T> T get(String key);
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param key key
|
||||
*/
|
||||
void delete(String key);
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.datasource;
|
||||
|
||||
import com.jiuyv.agile.data.database.*;
|
||||
import com.jiuyv.agile.data.database.query.AbstractDbQueryFactory;
|
||||
import com.jiuyv.agile.data.database.query.CacheDbQueryFactoryBean;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public abstract class AbstractDataSourceFactory implements DataSourceFactory {
|
||||
|
||||
@Override
|
||||
public DbQuery createDbQuery(DbQueryProperty property) {
|
||||
property.viald();
|
||||
DbType dbType = DbType.getDbType(property.getDbType());
|
||||
DataSource dataSource = createDataSource(property);
|
||||
DbQuery dbQuery = createDbQuery(dataSource, dbType);
|
||||
return dbQuery;
|
||||
}
|
||||
|
||||
public DbQuery createDbQuery(DataSource dataSource, DbType dbType) {
|
||||
DbDialect dbDialect = DialectFactory.getDialect(dbType);
|
||||
if(dbDialect == null){
|
||||
throw new RuntimeException("该数据库类型正在开发中");
|
||||
}
|
||||
AbstractDbQueryFactory dbQuery = new CacheDbQueryFactoryBean();
|
||||
dbQuery.setDataSource(dataSource);
|
||||
dbQuery.setJdbcTemplate(new JdbcTemplate(dataSource));
|
||||
dbQuery.setDbDialect(dbDialect);
|
||||
return dbQuery;
|
||||
}
|
||||
|
||||
public DataSource createDataSource(DbQueryProperty property) {
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setJdbcUrl(trainToJdbcUrl(property));
|
||||
dataSource.setUsername(property.getUsername());
|
||||
dataSource.setPassword(property.getPassword());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
protected String trainToJdbcUrl(DbQueryProperty property) {
|
||||
String url = DbType.getDbType(property.getDbType()).getUrl();
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
throw new RuntimeException("无效数据库类型!");
|
||||
}
|
||||
url = url.replace("${host}", property.getHost());
|
||||
url = url.replace("${port}", String.valueOf(property.getPort()));
|
||||
if (DbType.ORACLE.getDb().equals(property.getDbType()) || DbType.ORACLE_12C.getDb().equals(property.getDbType())) {
|
||||
url = url.replace("${sid}", property.getSid());
|
||||
} else {
|
||||
url = url.replace("${dbName}", property.getDbName());
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.datasource;
|
||||
|
||||
|
||||
import com.jiuyv.agile.data.database.DbQueryProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
public class CacheDataSourceFactoryBean extends AbstractDataSourceFactory {
|
||||
|
||||
/**
|
||||
* 数据源缓存
|
||||
*/
|
||||
private static Map<String, DataSource> dataSourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public DataSource createDataSource(DbQueryProperty property) {
|
||||
String key = property.getHost() + ":" + property.getPort() + ":" + property.getUsername() + ":" + property.getDbName();
|
||||
String s = compress(key);
|
||||
DataSource dataSource = dataSourceMap.get(s);
|
||||
if (null == dataSource) {
|
||||
synchronized (CacheDataSourceFactoryBean.class) {
|
||||
dataSource = super.createDataSource(property);
|
||||
dataSourceMap.put(s, dataSource);
|
||||
}
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
// 压缩
|
||||
public static String compress(String str) {
|
||||
if (str == null || str.length() == 0) {
|
||||
return str;
|
||||
}
|
||||
MessageDigest md = null;
|
||||
try {
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (md != null) {
|
||||
md.update(str.getBytes());
|
||||
byte[] b = md.digest();
|
||||
int i;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (byte value : b) {
|
||||
i = value;
|
||||
if (i < 0)
|
||||
i += 256;
|
||||
if (i < 16)
|
||||
buf.append("0");
|
||||
buf.append(Integer.toHexString(i));
|
||||
}
|
||||
str = buf.toString().substring(8, 24).toUpperCase();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.datasource;
|
||||
|
||||
public class DefaultDataSourceFactoryBean extends AbstractDataSourceFactory{
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbDialect;
|
||||
|
||||
/**
|
||||
* 方言抽象类
|
||||
*/
|
||||
public abstract class AbstractDbDialect implements DbDialect {
|
||||
|
||||
@Override
|
||||
public String columns(String dbName, String tableName) {
|
||||
return "select column_name AS COLNAME, ordinal_position AS COLPOSITION, column_default AS DATADEFAULT, is_nullable AS NULLABLE, data_type AS DATATYPE, " +
|
||||
"character_maximum_length AS DATALENGTH, numeric_precision AS DATAPRECISION, numeric_scale AS DATASCALE, column_key AS COLKEY, column_comment AS COLCOMMENT " +
|
||||
"from information_schema.columns where table_schema = '" + dbName + "' and table_name = '" + tableName + "' order by ordinal_position ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tables(String dbName) {
|
||||
return "SELECT table_name AS TABLENAME, table_comment AS TABLECOMMENT FROM information_schema.tables where table_schema = '" + dbName + "' ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String originalSql, long offset, long count) {
|
||||
// 获取 分页实际条数
|
||||
StringBuilder sqlBuilder = new StringBuilder(originalSql);
|
||||
sqlBuilder.append(" LIMIT ").append(offset).append(" , ").append(count);
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String count(String sql) {
|
||||
return "SELECT COUNT(*) FROM ( " + sql + " ) TEMP";
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbDialect;
|
||||
import com.jiuyv.agile.data.database.DbType;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DialectRegistry {
|
||||
|
||||
private final Map<DbType, DbDialect> dialect_enum_map = new EnumMap<>(DbType.class);
|
||||
|
||||
public DialectRegistry() {
|
||||
dialect_enum_map.put(DbType.MARIADB, new MariaDBDialect());
|
||||
dialect_enum_map.put(DbType.MYSQL, new MySqlDialect());
|
||||
dialect_enum_map.put(DbType.ORACLE_12C, new Oracle12cDialect());
|
||||
dialect_enum_map.put(DbType.ORACLE, new OracleDialect());
|
||||
dialect_enum_map.put(DbType.POSTGRE_SQL, new PostgreDialect());
|
||||
dialect_enum_map.put(DbType.SQL_SERVER2008, new SQLServer2008Dialect());
|
||||
dialect_enum_map.put(DbType.SQL_SERVER, new SQLServerDialect());
|
||||
dialect_enum_map.put(DbType.OTHER, new UnknownDialect());
|
||||
}
|
||||
|
||||
public DbDialect getDialect(DbType dbType) {
|
||||
return dialect_enum_map.get(dbType);
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
/**
|
||||
* MariaDB 数据库方言
|
||||
*/
|
||||
public class MariaDBDialect extends MySqlDialect {
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbColumn;
|
||||
import com.jiuyv.agile.data.database.DbTable;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* MySql 数据库方言
|
||||
*/
|
||||
public class MySqlDialect extends AbstractDbDialect {
|
||||
|
||||
@Override
|
||||
public RowMapper<DbColumn> columnMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbColumn entity = new DbColumn();
|
||||
entity.setColName(rs.getString("COLNAME"));
|
||||
entity.setDataType(rs.getString("DATATYPE"));
|
||||
entity.setDataLength(rs.getString("DATALENGTH"));
|
||||
entity.setDataPrecision(rs.getString("DATAPRECISION"));
|
||||
entity.setDataScale(rs.getString("DATASCALE"));
|
||||
entity.setColKey("PRI".equals(rs.getString("COLKEY")) ? true : false);
|
||||
entity.setNullable("YES".equals(rs.getString("NULLABLE")) ? true : false);
|
||||
entity.setColPosition(rs.getInt("COLPOSITION"));
|
||||
entity.setDataDefault(rs.getString("DATADEFAULT"));
|
||||
entity.setColComment(rs.getString("COLCOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbTable> tableMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbTable entity = new DbTable();
|
||||
entity.setTableName(rs.getString("TABLENAME"));
|
||||
entity.setTableComment(rs.getString("TABLECOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
/**
|
||||
* ORACLE Oracle12c+数据库方言
|
||||
*/
|
||||
public class Oracle12cDialect extends OracleDialect {
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String originalSql, long offset, long count) {
|
||||
StringBuilder sqlBuilder = new StringBuilder(originalSql);
|
||||
sqlBuilder.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ").append(count).append(" ROWS ONLY ");
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbColumn;
|
||||
import com.jiuyv.agile.data.database.DbTable;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* Oracle Oracle11g及以下数据库方言
|
||||
*/
|
||||
public class OracleDialect extends AbstractDbDialect {
|
||||
|
||||
@Override
|
||||
public String columns(String dbName, String tableName) {
|
||||
return "select columns.column_name AS colName, columns.data_type AS DATATYPE, columns.data_length AS DATALENGTH, columns.data_precision AS DATAPRECISION, " +
|
||||
"columns.data_scale AS DATASCALE, columns.nullable AS NULLABLE, columns.column_id AS COLPOSITION, columns.data_default AS DATADEFAULT, comments.comments AS COLCOMMENT," +
|
||||
"case when t.column_name is null then 0 else 1 end as COLKEY " +
|
||||
"from sys.user_tab_columns columns LEFT JOIN sys.user_col_comments comments ON columns.table_name = comments.table_name AND columns.column_name = comments.column_name " +
|
||||
"left join ( " +
|
||||
"select col.column_name as column_name, con.table_name as table_name from user_constraints con, user_cons_columns col " +
|
||||
"where con.constraint_name = col.constraint_name and con.constraint_type = 'P' " +
|
||||
") t on t.table_name = columns.table_name and columns.column_name = t.column_name " +
|
||||
"where columns.table_name = UPPER('" + tableName + "') order by columns.column_id ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tables(String dbName) {
|
||||
return "select tables.table_name AS TABLENAME, comments.comments AS TABLECOMMENT from sys.user_tables tables " +
|
||||
"LEFT JOIN sys.user_tab_comments comments ON tables.table_name = comments.table_name ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String originalSql, long offset, long count) {
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
sqlBuilder.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
|
||||
sqlBuilder.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + count) : count);
|
||||
sqlBuilder.append(") WHERE ROW_ID > ").append(offset);
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbColumn> columnMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbColumn entity = new DbColumn();
|
||||
entity.setColName(rs.getString("COLNAME"));
|
||||
entity.setDataType(rs.getString("DATATYPE"));
|
||||
entity.setDataLength(rs.getString("DATALENGTH"));
|
||||
entity.setDataPrecision(rs.getString("DATAPRECISION"));
|
||||
entity.setDataScale(rs.getString("DATASCALE"));
|
||||
entity.setColKey("1".equals(rs.getString("COLKEY")) ? true : false);
|
||||
entity.setNullable("Y".equals(rs.getString("NULLABLE")) ? true : false);
|
||||
entity.setColPosition(rs.getInt("COLPOSITION"));
|
||||
entity.setDataDefault(rs.getString("DATADEFAULT"));
|
||||
entity.setColComment(rs.getString("COLCOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbTable> tableMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbTable entity = new DbTable();
|
||||
entity.setTableName(rs.getString("TABLENAME"));
|
||||
entity.setTableComment(rs.getString("TABLECOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbColumn;
|
||||
import com.jiuyv.agile.data.database.DbTable;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* Postgre 数据库方言
|
||||
*/
|
||||
public class PostgreDialect extends AbstractDbDialect {
|
||||
|
||||
@Override
|
||||
public String columns(String dbName, String tableName) {
|
||||
return "select col.column_name AS COLNAME, col.ordinal_position AS COLPOSITION, col.column_default AS DATADEFAULT, col.is_nullable AS NULLABLE, col.udt_name AS DATATYPE, " +
|
||||
"col.character_maximum_length AS DATALENGTH, col.numeric_precision AS DATAPRECISION, col.numeric_scale AS DATASCALE, des.description AS COLCOMMENT, " +
|
||||
"case when t.colname is null then 0 else 1 end as COLKEY " +
|
||||
"from information_schema.columns col left join pg_description des on col.table_name::regclass = des.objoid and col.ordinal_position = des.objsubid " +
|
||||
"left join ( " +
|
||||
"select pg_attribute.attname as colname from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid " +
|
||||
"inner join pg_attribute on pg_attribute.attrelid = pg_class.oid and pg_attribute.attnum = any(pg_constraint.conkey) " +
|
||||
"where pg_class.relname = '" + tableName + "' and pg_constraint.contype = 'p' " +
|
||||
") t on t.colname = col.column_name " +
|
||||
"where col.table_catalog = '" + dbName + "' and col.table_schema = 'public' and col.table_name = '" + tableName + "' order by col.ordinal_position ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tables(String dbName) {
|
||||
return "select relname AS TABLENAME, cast(obj_description(relfilenode, 'pg_class') as varchar) AS TABLECOMMENT from pg_class " +
|
||||
"where relname in (select tablename from pg_tables where schemaname = 'public' and position('_2' in tablename) = 0) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String originalSql, long offset, long count) {
|
||||
StringBuilder sqlBuilder = new StringBuilder(originalSql);
|
||||
sqlBuilder.append(" LIMIT ").append(count).append(" offset ").append(offset);
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbColumn> columnMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbColumn entity = new DbColumn();
|
||||
entity.setColName(rs.getString("COLNAME"));
|
||||
entity.setDataType(rs.getString("DATATYPE"));
|
||||
entity.setDataLength(rs.getString("DATALENGTH"));
|
||||
entity.setDataPrecision(rs.getString("DATAPRECISION"));
|
||||
entity.setDataScale(rs.getString("DATASCALE"));
|
||||
entity.setColKey("1".equals(rs.getString("COLKEY")) ? true : false);
|
||||
entity.setNullable("YES".equals(rs.getString("NULLABLE")) ? true : false);
|
||||
entity.setColPosition(rs.getInt("COLPOSITION"));
|
||||
entity.setDataDefault(rs.getString("DATADEFAULT"));
|
||||
entity.setColComment(rs.getString("COLCOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbTable> tableMapper() {
|
||||
return (ResultSet rs, int rowNum) -> {
|
||||
DbTable entity = new DbTable();
|
||||
entity.setTableName(rs.getString("TABLENAME"));
|
||||
entity.setTableComment(rs.getString("TABLECOMMENT"));
|
||||
return entity;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
/**
|
||||
* SQLServer 数据库方言
|
||||
*/
|
||||
public class SQLServerDialect extends SQLServer2008Dialect {
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String originalSql, long offset, long count) {
|
||||
StringBuilder sqlBuilder = new StringBuilder(originalSql);
|
||||
sqlBuilder.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ").append(count).append(" ROWS ONLY ");
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.dialect;
|
||||
|
||||
import com.jiuyv.agile.data.database.DbColumn;
|
||||
import com.jiuyv.agile.data.database.DbTable;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* 未知 数据库方言
|
||||
*/
|
||||
public class UnknownDialect extends AbstractDbDialect {
|
||||
|
||||
@Override
|
||||
public String columns(String dbName, String tableName) {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tables(String dbName) {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildPaginationSql(String sql, long offset, long count) {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String count(String sql) {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbColumn> columnMapper() {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowMapper<DbTable> tableMapper() {
|
||||
throw new RuntimeException("不支持的数据库类型");
|
||||
}
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.query;
|
||||
|
||||
import com.jiuyv.agile.data.database.*;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractDbQueryFactory implements DbQuery {
|
||||
|
||||
protected DataSource dataSource;
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
protected DbDialect dbDialect;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库连接出错");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
return conn.isValid(0);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("检测连通性出错");
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("关闭数据库连接出错");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (dataSource instanceof HikariDataSource) {
|
||||
((HikariDataSource) dataSource).close();
|
||||
} else {
|
||||
throw new RuntimeException("不合法数据源类型");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbColumn> getTableColumns(String dbName, String tableName) {
|
||||
String sql = dbDialect.columns(dbName, tableName);
|
||||
return jdbcTemplate.query(sql, dbDialect.columnMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbTable> getTables(String dbName) {
|
||||
String sql = dbDialect.tables(dbName);
|
||||
return jdbcTemplate.query(sql, dbDialect.tableMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql) {
|
||||
return jdbcTemplate.queryForObject(dbDialect.count(sql), Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql, Object[] args) {
|
||||
return jdbcTemplate.queryForObject(dbDialect.count(sql), args, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql, Map<String, Object> params) {
|
||||
NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
|
||||
return namedJdbcTemplate.queryForObject(dbDialect.count(sql), params, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> queryList(String sql) {
|
||||
return jdbcTemplate.queryForList(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> queryList(String sql, Object[] args) {
|
||||
return jdbcTemplate.queryForList(sql, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, long offset, long size) {
|
||||
int total = count(sql);
|
||||
String pageSql = dbDialect.buildPaginationSql(sql, offset, size);
|
||||
List<Map<String, Object>> records = jdbcTemplate.queryForList(pageSql);
|
||||
return new PageResult<>(total, records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, Object[] args, long offset, long size) {
|
||||
int total = count(sql, args);
|
||||
String pageSql = dbDialect.buildPaginationSql(sql, offset, size);
|
||||
List<Map<String, Object>> records = jdbcTemplate.queryForList(pageSql, args);
|
||||
return new PageResult<>(total, records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, Map<String, Object> params, long offset, long size) {
|
||||
int total = count(sql, params);
|
||||
String pageSql = dbDialect.buildPaginationSql(sql, offset, size);
|
||||
NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
|
||||
List<Map<String, Object>> records = namedJdbcTemplate.queryForList(pageSql, params);
|
||||
return new PageResult<>(total, records);
|
||||
}
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setDbDialect(DbDialect dbDialect) {
|
||||
this.dbDialect = dbDialect;
|
||||
}
|
||||
}
|
||||
@ -1,105 +0,0 @@
|
||||
package com.jiuyv.agile.data.database.query;
|
||||
|
||||
|
||||
import com.jiuyv.agile.data.database.DbColumn;
|
||||
import com.jiuyv.agile.data.database.DbTable;
|
||||
import com.jiuyv.agile.data.database.PageResult;
|
||||
import com.jiuyv.agile.data.database.cache.DefaultSqlCache;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CacheDbQueryFactoryBean extends AbstractDbQueryFactory {
|
||||
|
||||
/**
|
||||
* 默认缓存5分钟
|
||||
*/
|
||||
private static long DEFAULT_EXPIRE = 5 * 60 * 1000;
|
||||
private static DefaultSqlCache sqlCache = new DefaultSqlCache(100, DEFAULT_EXPIRE);
|
||||
|
||||
private <T> T putCacheValue(String key, T value, long ttl) {
|
||||
sqlCache.put(key, value, ttl);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbColumn> getTableColumns(String dbName, String tableName) {
|
||||
Object[] args = new Object[]{dbName, tableName};
|
||||
Optional<Object> o = Optional.ofNullable(sqlCache.get(sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":getTableColumns", args)));
|
||||
return super.getTableColumns(dbName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbTable> getTables(String dbName) {
|
||||
Object[] args = new Object[]{dbName};
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":getTables", args);
|
||||
return (List<DbTable>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.getTables(dbName), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql) {
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, null);
|
||||
return (int) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.count(sql), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql, Object[] args) {
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, args);
|
||||
return (int) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.count(sql, args), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(String sql, Map<String, Object> params) {
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, params.values().toArray());
|
||||
return (int) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.count(sql, params), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> queryList(String sql) {
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, null);
|
||||
return (List<Map<String, Object>>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.queryList(sql), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> queryList(String sql, Object[] args) {
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, args);
|
||||
return (List<Map<String, Object>>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.queryList(sql, args), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, long offset, long size) {
|
||||
Object[] args = new Object[]{offset, size};
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, args);
|
||||
return (PageResult<Map<String, Object>>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.queryByPage(sql, offset, size), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, Object[] args, long offset, long size) {
|
||||
Object[] objects = Arrays.copyOf(args, args.length + 2);
|
||||
objects[args.length] = offset;
|
||||
objects[args.length + 1] = size;
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, objects);
|
||||
return (PageResult<Map<String, Object>>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.queryByPage(sql, args, offset, size), DEFAULT_EXPIRE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryByPage(String sql, Map<String, Object> params, long offset, long size) {
|
||||
Object[] args = params.values().toArray();
|
||||
Object[] objects = Arrays.copyOf(args, args.length + 2);
|
||||
objects[args.length] = offset;
|
||||
objects[args.length + 1] = size;
|
||||
String cacheKey = sqlCache.buildSqlCacheKey(super.dataSource.toString() + ":" + sql, objects);
|
||||
return (PageResult<Map<String, Object>>) Optional.ofNullable(sqlCache.get(cacheKey))
|
||||
.orElse(putCacheValue(cacheKey, super.queryByPage(sql, params, offset, size), DEFAULT_EXPIRE));
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory;
|
||||
|
||||
import com.jiuyv.agile.data.factory.crypto.Crypto;
|
||||
|
||||
public abstract class AbstractFactory {
|
||||
|
||||
public abstract Crypto getCrypto(String type);
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory;
|
||||
|
||||
import com.jiuyv.agile.data.dto.enums.AlgorithmCrypto;
|
||||
import com.jiuyv.agile.data.factory.crypto.AlgorithmRegistry;
|
||||
import com.jiuyv.agile.data.factory.crypto.Crypto;
|
||||
|
||||
public class AlgorithmFactory extends AbstractFactory {
|
||||
|
||||
private static final AlgorithmRegistry ALGORITHM_REGISTRY = new AlgorithmRegistry();
|
||||
|
||||
@Override
|
||||
public Crypto getCrypto(String type) {
|
||||
AlgorithmCrypto crypto = AlgorithmCrypto.getAlgorithmCrypto(type);
|
||||
return ALGORITHM_REGISTRY.getAlgorithm(crypto);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory;
|
||||
|
||||
import com.jiuyv.agile.data.dto.enums.CipherType;
|
||||
|
||||
public class FactoryProducer {
|
||||
|
||||
public static AbstractFactory getFactory(String type){
|
||||
CipherType cipherType = CipherType.getCipherType(type);
|
||||
switch (cipherType) {
|
||||
case REGEX:
|
||||
return new RegexFactory();
|
||||
case ALGORITHM:
|
||||
return new AlgorithmFactory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory;
|
||||
|
||||
import com.jiuyv.agile.data.dto.enums.RegexCrypto;
|
||||
import com.jiuyv.agile.data.factory.crypto.Crypto;
|
||||
import com.jiuyv.agile.data.factory.crypto.RegexRegistry;
|
||||
|
||||
public class RegexFactory extends AbstractFactory {
|
||||
|
||||
private static final RegexRegistry REGEX_REGISTRY = new RegexRegistry();
|
||||
|
||||
@Override
|
||||
public Crypto getCrypto(String type) {
|
||||
RegexCrypto crypto = RegexCrypto.getRegexCrypto(type);
|
||||
return REGEX_REGISTRY.getRegex(crypto);
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory.crypto;
|
||||
|
||||
import com.jiuyv.agile.data.dto.enums.AlgorithmCrypto;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AlgorithmRegistry {
|
||||
|
||||
private final Map<AlgorithmCrypto, Crypto> algorithm_enum_map = new EnumMap<>(AlgorithmCrypto.class);
|
||||
|
||||
public AlgorithmRegistry() {
|
||||
algorithm_enum_map.put(AlgorithmCrypto.BASE64, new BASE64Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.AES, new AESCrypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.DES, new DESCrypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.MD5, new MD5Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.SHA_1, new SHA1Crypto());
|
||||
algorithm_enum_map.put(AlgorithmCrypto.SHA_256, new SHA256Crypto());
|
||||
}
|
||||
|
||||
public Crypto getAlgorithm(AlgorithmCrypto crypto) {
|
||||
return algorithm_enum_map.get(crypto);
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class BASE64Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] encode = Base64.getEncoder().encode(content.getBytes(CHARSET_UTF8));
|
||||
return new String(encode, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] decode = Base64.getDecoder().decode(content.getBytes(CHARSET_UTF8));
|
||||
return new String(decode, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory.crypto;
|
||||
|
||||
public interface Crypto {
|
||||
|
||||
/**
|
||||
* 字符编码
|
||||
*/
|
||||
String CHARSET_UTF8 = "UTF-8";
|
||||
/**
|
||||
* 密码盐
|
||||
*/
|
||||
String SLAT = "DATAX:20200101";
|
||||
|
||||
String encrypt(String content);
|
||||
|
||||
String decrypt(String content);
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
public class DESCrypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("DES");
|
||||
kGen.init(56, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
|
||||
Cipher cipher = Cipher.getInstance("DES");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
byte[] DES_encrypt = cipher.doFinal(content.getBytes(CHARSET_UTF8));
|
||||
return Base64.getEncoder().encodeToString(DES_encrypt);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KeyGenerator kGen = KeyGenerator.getInstance("DES");
|
||||
kGen.init(56, new SecureRandom(SLAT.getBytes(CHARSET_UTF8)));
|
||||
SecretKey secretKey = kGen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
|
||||
Cipher cipher = Cipher.getInstance("DES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||
byte[] DES_decrypt = cipher.doFinal(Base64.getDecoder().decode(content));
|
||||
return new String(DES_decrypt, CHARSET_UTF8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.jiuyv.agile.data.factory.crypto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
public class MD5Crypto implements Crypto {
|
||||
|
||||
@Override
|
||||
public String encrypt(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(content.getBytes(CHARSET_UTF8));
|
||||
md5.update(SLAT.getBytes(CHARSET_UTF8));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (md5 != null) {
|
||||
return Base64.getEncoder().encodeToString(md5.digest());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decrypt(String content) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue