commit
eb9908d993
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.renchao</groupId>
|
||||
<artifactId>Drools</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web容器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- 规则引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-spring</artifactId>
|
||||
<version>7.6.0.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,11 @@
|
||||
package com.renchao;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.renchao.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Order {
|
||||
|
||||
/**
|
||||
* 订单原价金额
|
||||
*/
|
||||
private int price;
|
||||
|
||||
/**
|
||||
*下单人
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
*积分
|
||||
*/
|
||||
private int score;
|
||||
|
||||
/**
|
||||
* 下单日期
|
||||
*/
|
||||
private Date bookingDate;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.renchao.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
private String name;
|
||||
private Integer level;
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.renchao.config;
|
||||
|
||||
|
||||
import org.kie.api.KieBase;
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.builder.*;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.internal.io.ResourceFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* <p> 规则引擎自动配置类 </p>
|
||||
*/
|
||||
@Configuration
|
||||
public class DroolsAutoConfiguration {
|
||||
|
||||
private static final String RULES_PATH = "rules/";
|
||||
|
||||
private KieServices getKieServices() {
|
||||
return KieServices.Factory.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieFileSystem.class)
|
||||
public KieFileSystem kieFileSystem() throws IOException {
|
||||
KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
|
||||
for (Resource file : getRuleFiles()) {
|
||||
kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
|
||||
}
|
||||
return kieFileSystem;
|
||||
}
|
||||
|
||||
private Resource[] getRuleFiles() throws IOException {
|
||||
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
|
||||
return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieContainer.class)
|
||||
public KieContainer kieContainer() throws IOException {
|
||||
final KieRepository kieRepository = getKieServices().getRepository();
|
||||
|
||||
kieRepository.addKieModule(() -> kieRepository.getDefaultReleaseId());
|
||||
|
||||
KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
|
||||
kieBuilder.buildAll();
|
||||
|
||||
KieContainer kieContainer = getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
|
||||
|
||||
return kieContainer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieBase.class)
|
||||
public KieBase kieBase() throws IOException {
|
||||
return kieContainer().getKieBase();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package rules
|
||||
|
||||
import com.renchao.bean.Order
|
||||
|
||||
rule "zero"
|
||||
no-loop true
|
||||
lock-on-active true
|
||||
salience 1
|
||||
when
|
||||
$s : Order(price <= 100)
|
||||
then
|
||||
$s.setScore(0);
|
||||
update($s);
|
||||
end
|
||||
|
||||
rule "add100"
|
||||
no-loop true
|
||||
lock-on-active true
|
||||
salience 1
|
||||
when
|
||||
$s : Order(price > 100 && price <= 500)
|
||||
then
|
||||
$s.setScore(100);
|
||||
update($s);
|
||||
end
|
||||
|
||||
rule "add500"
|
||||
no-loop true
|
||||
lock-on-active true
|
||||
salience 1
|
||||
when
|
||||
$s : Order(price > 500 && price <= 1000)
|
||||
then
|
||||
$s.setScore(500);
|
||||
update($s);
|
||||
end
|
||||
|
||||
rule "add1000"
|
||||
no-loop true
|
||||
lock-on-active true
|
||||
salience 1
|
||||
when
|
||||
$s : Order(price > 1000)
|
||||
then
|
||||
$s.setScore(1000);
|
||||
update($s);
|
||||
end
|
@ -0,0 +1,96 @@
|
||||
package com.renchao;
|
||||
|
||||
import com.renchao.bean.Order;
|
||||
import com.renchao.bean.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 需求
|
||||
* 计算额外积分金额 规则如下: 订单原价金额
|
||||
* 100以下, 不加分
|
||||
* 100-500 加100分
|
||||
* 500-1000 加500分
|
||||
* 1000 以上 加1000分
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class DroolsOrderTests {
|
||||
@Resource
|
||||
private KieContainer kieContainer;
|
||||
|
||||
|
||||
@Test
|
||||
public void droolsOrderTest() throws Exception {
|
||||
KieSession kieSession = kieContainer.newKieSession();
|
||||
List<Order> orderList = getInitData();
|
||||
for (Order order: orderList) {
|
||||
// 1-规则引擎处理逻辑
|
||||
kieSession.insert(order);
|
||||
kieSession.fireAllRules();
|
||||
// 2-执行完规则后, 执行相关的逻辑
|
||||
addScore(order);
|
||||
}
|
||||
kieSession.dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void addScore(Order o){
|
||||
System.out.println("用户" + o.getUser().getName() + "享受额外增加积分: " + o.getScore());
|
||||
}
|
||||
|
||||
private static List<Order> getInitData() throws Exception {
|
||||
List<Order> orderList = new ArrayList<>();
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
{
|
||||
Order order = new Order();
|
||||
order.setPrice(80);
|
||||
order.setBookingDate(df.parse("2015-07-01"));
|
||||
User user = new User();
|
||||
user.setLevel(1);
|
||||
user.setName("Name1");
|
||||
order.setUser(user);
|
||||
order.setScore(111);
|
||||
orderList.add(order);
|
||||
}
|
||||
{
|
||||
Order order = new Order();
|
||||
order.setPrice(200);
|
||||
order.setBookingDate(df.parse("2015-07-02"));
|
||||
User user = new User();
|
||||
user.setLevel(2);
|
||||
user.setName("Name2");
|
||||
order.setUser(user);
|
||||
orderList.add(order);
|
||||
}
|
||||
{
|
||||
Order order = new Order();
|
||||
order.setPrice(800);
|
||||
order.setBookingDate(df.parse("2015-07-03"));
|
||||
User user = new User();
|
||||
user.setLevel(3);
|
||||
user.setName("Name3");
|
||||
order.setUser(user);
|
||||
orderList.add(order);
|
||||
}
|
||||
{
|
||||
Order order = new Order();
|
||||
order.setPrice(1500);
|
||||
order.setBookingDate(df.parse("2015-07-04"));
|
||||
User user = new User();
|
||||
user.setLevel(4);
|
||||
user.setName("Name4");
|
||||
order.setUser(user);
|
||||
orderList.add(order);
|
||||
}
|
||||
return orderList;
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
<?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>MyMaven</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>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- EasyExcel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
<!--常用工具库-->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>29.0-jre</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.14.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.26</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- drools规则引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-compiler</artifactId>
|
||||
<version>7.6.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>5.3.20</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.5.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>6.0.9.Final</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.poi</groupId>-->
|
||||
<!-- <artifactId>poi</artifactId>-->
|
||||
<!-- <version>4.1.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.poi</groupId>-->
|
||||
<!-- <artifactId>poi-ooxml</artifactId>-->
|
||||
<!-- <version>4.1.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>1.36</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess -->
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.36</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,42 @@
|
||||
package com.renchao.chemical;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DangerChemicalInfo {
|
||||
@ExcelProperty(value = "序号")
|
||||
private String number;
|
||||
|
||||
@ExcelProperty(value = "日期")
|
||||
private String date;
|
||||
|
||||
@ExcelProperty(value = "样品名称及型号")
|
||||
private String nameAndModel;
|
||||
|
||||
@ExcelProperty(value = "进口国别/地区")
|
||||
private String country;
|
||||
|
||||
@ExcelProperty(value = "进口收货人/消费使用单位")
|
||||
private String receiver;
|
||||
|
||||
@ExcelProperty(value = "生产商/发货人")
|
||||
private String consignor;
|
||||
|
||||
@ExcelProperty(value = "成分/组分")
|
||||
private String composition;
|
||||
|
||||
@ExcelProperty(value = "危险特性")
|
||||
private String hazardousProperties;
|
||||
|
||||
@ExcelProperty(value = "危险类别")
|
||||
private String hazardCategory;
|
||||
|
||||
@ExcelProperty(value = "联合国编号")
|
||||
private String unNumber;
|
||||
|
||||
@ExcelProperty(value = "建议包装类别")
|
||||
private String packingCategory;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.renchao.drools;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*/
|
||||
@Data
|
||||
public class Order {
|
||||
private Double originalPrice; // 订单原始价格,即优惠前的价格
|
||||
private Double realPrice; // 订单真实价格,即优惠后的价格
|
||||
private List<String> stringList = new ArrayList<>();
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.renchao.jmh;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2014, Oracle America, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Oracle nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
public class JMHSample_01_HelloWorld {
|
||||
|
||||
/**
|
||||
* This is our first benchmark method.
|
||||
*
|
||||
* JMH works as follows: users annotate the methods with @Benchmark, and
|
||||
* then JMH produces the generated code to run this particular benchmark as
|
||||
* reliably as possible. In general one might think about @Benchmark methods
|
||||
* as the benchmark "payload", the things we want to measure. The
|
||||
* surrounding infrastructure is provided by the harness itself.
|
||||
*
|
||||
* Read the Javadoc for @Benchmark annotation for complete semantics and
|
||||
* restrictions. At this point we only note that the methods names are
|
||||
* non-essential, and it only matters that the methods are marked with
|
||||
* @Benchmark. You can have multiple benchmark methods within the same
|
||||
* class.
|
||||
*
|
||||
* Note: if the benchmark method never finishes, then JMH run never finishes
|
||||
* as well. If you throw an exception from the method body the JMH run ends
|
||||
* abruptly for this benchmark and JMH will run the next benchmark down the
|
||||
* list.
|
||||
*
|
||||
* Although this benchmark measures "nothing" it is a good showcase for the
|
||||
* overheads the infrastructure bear on the code you measure in the method.
|
||||
* There are no magical infrastructures which incur no overhead, and it is
|
||||
* important to know what are the infra overheads you are dealing with. You
|
||||
* might find this thought unfolded in future examples by having the
|
||||
* "baseline" measurements to compare against.
|
||||
*/
|
||||
|
||||
@Benchmark
|
||||
public void wellHelloThere() {
|
||||
// this method was intentionally left blank.
|
||||
}
|
||||
|
||||
/**
|
||||
* ============================== HOW TO RUN THIS TEST: ====================================
|
||||
*
|
||||
* You are expected to see the run with large number of iterations, and
|
||||
* very large throughput numbers. You can see that as the estimate of the
|
||||
* harness overheads per method call. In most of our measurements, it is
|
||||
* down to several cycles per call.
|
||||
*
|
||||
* a) Via command-line:
|
||||
* $ mvn clean install
|
||||
* $ java -jar target/benchmarks.jar JMHSample_01
|
||||
*
|
||||
* JMH generates self-contained JARs, bundling JMH together with it.
|
||||
* The runtime options for the JMH are available with "-h":
|
||||
* $ java -jar target/benchmarks.jar -h
|
||||
*
|
||||
* b) Via the Java API:
|
||||
* (see the JMH homepage for possible caveats when running from IDE:
|
||||
* http://openjdk.java.net/projects/code-tools/jmh/)
|
||||
*/
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(JMHSample_01_HelloWorld.class.getSimpleName())
|
||||
.forks(1)
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.renchao.spring;
|
||||
|
||||
import com.renchao.spring.bean.Anonymous;
|
||||
import com.renchao.spring.bean.TestController;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
||||
public class AnnotationUtilsTest {
|
||||
public static void main(String[] args) {
|
||||
Anonymous annotation = AnnotationUtils.findAnnotation(TestController.class, Anonymous.class);
|
||||
System.out.println(annotation);
|
||||
System.out.println(AnnotatedElementUtils.isAnnotated(TestController.class, Anonymous.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.renchao.spring.bean;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 匿名访问不鉴权注解
|
||||
*
|
||||
* @author admin
|
||||
*/
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Anonymous
|
||||
{
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.renchao.spring.bean;
|
||||
|
||||
@Anonymous
|
||||
public class BaseController {
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.renchao.spring.bean;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Anonymous
|
||||
public class TestController extends BaseController {
|
||||
|
||||
@RequestMapping({"/cc","dd"})
|
||||
@Anonymous
|
||||
public String testF() {
|
||||
return "testFeign.test01()";
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class DateDemo {
|
||||
public static void main(String[] args) throws JsonProcessingException {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
SimpleModule simpleModule = new SimpleModule()
|
||||
// .addSerializer(Long.class, ToStringSerializer.instance)
|
||||
.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
builder.modules(simpleModule);
|
||||
ObjectMapper build = builder.build();
|
||||
String str = "{\"id\":22,\"name\":\"aaa\",\"age\":55}";
|
||||
Bean bean1 = build.readValue(str, Bean.class);
|
||||
|
||||
|
||||
Bean bean = new Bean();
|
||||
bean.setId(22L);
|
||||
bean.setName("aaa");
|
||||
String s = build.writeValueAsString(bean);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Bean {
|
||||
@NotBlank(message = "aabb")
|
||||
private String name;
|
||||
@NotNull(message = "唯一标识不能为空")
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "cc")
|
||||
private String age;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
Bean bean = new Bean();
|
||||
Validator validator = Validation.byProvider(HibernateValidator.class)
|
||||
.configure().failFast(false).buildValidatorFactory().getValidator();
|
||||
Set<ConstraintViolation<Bean>> validate = validator.validate(bean);
|
||||
for (ConstraintViolation<Bean> violation : validate) {
|
||||
System.out.println(violation.getLeafBean());
|
||||
System.out.println(violation.getMessage());
|
||||
System.out.println(violation.getMessageTemplate());
|
||||
System.out.println(violation.getPropertyPath());
|
||||
System.out.println("======================");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DemoData {
|
||||
public static void main(String[] args) {
|
||||
String filePath = "C:/Users/RENCHAO/Desktop/资料/easyexcel-user1.xls";
|
||||
List<UserEntity> list = EasyExcel.read(filePath).head(UserEntity.class).sheet().doReadSync();
|
||||
System.out.println(list);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
String str = "[{\"component\":\"聚酯树脂\",\"content\":\"48%\"},{\"component\":\"乙酸乙酯\",\"content\":\"52%\"}]";
|
||||
// String str = "ssss";
|
||||
|
||||
System.out.println(JSON.isValid(str));
|
||||
List<Map<String, String>> list = JSON.parseObject(str, new TypeReference<List<Map<String, String>>>() {});
|
||||
for (Map<String, String> map : list) {
|
||||
System.out.println(map.get("component") + "::" + map.get("content"));
|
||||
}
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
strings.add("cc");
|
||||
strings.add("dd");
|
||||
System.out.println(String.join("||", strings));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
import org.openjdk.jmh.runner.options.TimeValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
//@BenchmarkMode(Mode.AverageTime)
|
||||
//@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
//@State(Scope.Thread)
|
||||
public class JMHTest {
|
||||
/**
|
||||
* 测试数据
|
||||
*/
|
||||
private final static String DATA = "大白有点菜";
|
||||
|
||||
// private List<String> arrayList = new ArrayList<>();
|
||||
// private List<String> linkedList = new LinkedList<>();
|
||||
|
||||
// /**
|
||||
// * 初始化 ArrayList 和 LinkedList
|
||||
// */
|
||||
// @Setup(Level.Iteration)
|
||||
// public void setUp()
|
||||
// {
|
||||
// this.arrayList = new ArrayList<>();
|
||||
// this.linkedList = new LinkedList<>();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * ArrayList的add方法
|
||||
// * @return
|
||||
// */
|
||||
// @Benchmark
|
||||
// public List<String> arrayListAdd() {
|
||||
// this.arrayList.add(DATA);
|
||||
// return arrayList;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * LinkedList的add方法
|
||||
// * @return
|
||||
// */
|
||||
// @Benchmark
|
||||
// public List<String> linkedListAdd() {
|
||||
// this.linkedList.add(DATA);
|
||||
// return this.linkedList;
|
||||
// }
|
||||
|
||||
@Benchmark
|
||||
public int Test() {
|
||||
int i = 5;
|
||||
int k = i * 8;
|
||||
return k;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
final Options opts = new OptionsBuilder()
|
||||
.include(JMHTest.class.getSimpleName())
|
||||
.forks(1)
|
||||
// .output("Benchmark1.log")
|
||||
.build();
|
||||
new Runner(opts).run();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
public class JMHTest2 {
|
||||
/**
|
||||
* Most of the time, you need to maintain some state while the benchmark is
|
||||
* running. Since JMH is heavily used to build concurrent benchmarks, we
|
||||
* opted for an explicit notion of state-bearing objects.
|
||||
*
|
||||
* Below are two state objects. Their class names are not essential, it
|
||||
* matters they are marked with @State. These objects will be instantiated
|
||||
* on demand, and reused during the entire benchmark trial.
|
||||
*
|
||||
* The important property is that state is always instantiated by one of
|
||||
* those benchmark threads which will then have the access to that state.
|
||||
* That means you can initialize the fields as if you do that in worker
|
||||
* threads (ThreadLocals are yours, etc).
|
||||
*/
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public static class BenchmarkState {
|
||||
volatile double x = Math.PI;
|
||||
}
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class ThreadState {
|
||||
volatile double x = Math.PI;
|
||||
}
|
||||
|
||||
/*
|
||||
* Benchmark methods can reference the states, and JMH will inject the
|
||||
* appropriate states while calling these methods. You can have no states at
|
||||
* all, or have only one state, or have multiple states referenced. This
|
||||
* makes building multi-threaded benchmark a breeze.
|
||||
*
|
||||
* For this exercise, we have two methods.
|
||||
*/
|
||||
|
||||
@Benchmark
|
||||
public void measureUnshared(ThreadState state) {
|
||||
// All benchmark threads will call in this method.
|
||||
//
|
||||
// However, since ThreadState is the Scope.Thread, each thread
|
||||
// will have it's own copy of the state, and this benchmark
|
||||
// will measure unshared case.
|
||||
state.x++;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void measureShared(BenchmarkState state) {
|
||||
// All benchmark threads will call in this method.
|
||||
//
|
||||
// Since BenchmarkState is the Scope.Benchmark, all threads
|
||||
// will share the state instance, and we will end up measuring
|
||||
// shared case.
|
||||
state.x++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ============================== HOW TO RUN THIS TEST: ====================================
|
||||
*
|
||||
* You are expected to see the drastic difference in shared and unshared cases,
|
||||
* because you either contend for single memory location, or not. This effect
|
||||
* is more articulated on large machines.
|
||||
*
|
||||
* You can run this test:
|
||||
*
|
||||
* a) Via the command line:
|
||||
* $ mvn clean install
|
||||
* $ java -jar target/benchmarks.jar JMHSample_03 -t 4 -f 1
|
||||
* (we requested 4 threads, single fork; there are also other options, see -h)
|
||||
*
|
||||
* b) Via the Java API:
|
||||
* (see the JMH homepage for possible caveats when running from IDE:
|
||||
* http://openjdk.java.net/projects/code-tools/jmh/)
|
||||
*/
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(JMHTest2.class.getSimpleName())
|
||||
.threads(4)
|
||||
.forks(1)
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.renchao.utils.RsaUtil;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MyTest {
|
||||
private static final Pattern pattern = Pattern.compile("[+/]");
|
||||
public static void main(String[] args) throws JsonProcessingException {
|
||||
String str = "ee, tt,,cc ";
|
||||
List<String> split = StrUtil.split(str, ",", true, true);
|
||||
split.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
String str = "I:X,II:X.Y,III:X.Y.Z";
|
||||
String[] split = str.split(",");
|
||||
HashMap<String, List<String>> map = new HashMap<>();
|
||||
for (String s : split) {
|
||||
String[] m = s.split(":");
|
||||
map.put(m[0], CharSequenceUtil.split(m[1], "."));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void test03() throws IOException {
|
||||
String str = "任超";
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] bytes1 = str.getBytes(StandardCharsets.ISO_8859_1);
|
||||
|
||||
System.out.println(new String(bytes,StandardCharsets.UTF_8));
|
||||
System.out.println(new String(bytes1,StandardCharsets.ISO_8859_1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test04() {
|
||||
String str = "2bce7d71-d60b-4858-a852-15380eba6c84";
|
||||
String s = RsaUtil.decryptStr(str);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test05() {
|
||||
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDG03gR1w6i3E6h6+N9F2///BnRrkzPc7RT4qZKKl2b/rolym0EYl3QZTsIV5oQngT93TLtld7EK5svdwUabX6kzqd8yDDChZXS/E7/FrufN6Hwf9S3O3ZzkhEyd45HmRHV4aNRFsS/NviEZx83D6FR94l0SPnomvPkVqM8UnafnQIDAQAB";
|
||||
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMbTeBHXDqLcTqHr430Xb//8GdGuTM9ztFPipkoqXZv+uiXKbQRiXdBlOwhXmhCeBP3dMu2V3sQrmy93BRptfqTOp3zIMMKFldL8Tv8Wu583ofB/1Lc7dnOSETJ3jkeZEdXho1EWxL82+IRnHzcPoVH3iXRI+eia8+RWozxSdp+dAgMBAAECgYAJjtfqT6LR/HJBQXQ9qrdFIIrjNBRYMrE8CRzCWvgGDEBJmcoU2F+3KW6lj4SGAPqvc4dDuZ0sZAZBSWDy7MmWL+Zz2z44sulxsOsb3DJqIyBSAr5D6mhrRmu7MJA5AGgDHo/2gn+9Cji2JQBHBFe18BzJdr2tIM4uAYTVB6EW8QJBAPCrnHohSDtgLSmHrbORP/cIS8OOF/M3PsYfHZ3cpdrKk2zs1rXAHJq80GlmhSQx8tezx6wt63Cph0reiHbOMRkCQQDTfYqahFR0NTFFfTBfSJKQEqoiRYMnOrjkkOOgFv6cBwYd16pnqTfNISSYkBsOcDO09qiMILW96MoJONCV458lAkEAmMrqueK9X+zMX0xjK9hwOp5Ks2lXrTKKqO+CNwGpTkFD3WhzW8oOnvJ2giPzLSqE2QqrHpW8nrcSTKcBDiQTqQJABORmjGR7P6TrWtwmfk3Ddim4XcqV2hZ1qHPhkBZ4FUvkTFRs0LENZWVa31yWA6N8zrbV90fabGYyJjx2NsFpMQJARtRflzJjWc/49nzu+om41bz9Ngg07/S8Rxe8AlZbSlCxggmp/KUBcoVgNJCa5qGsX2AvTOCXaHngp+YLtHHPBQ==";
|
||||
|
||||
RSA rsa = new RSA(privateKey,publicKey);
|
||||
|
||||
//获得私钥
|
||||
System.out.println("获得私钥:" + rsa.getPrivateKey());
|
||||
System.out.println("获得私钥:" + rsa.getPrivateKeyBase64());
|
||||
//获得公钥
|
||||
System.out.println("获得公钥:" + rsa.getPublicKey());
|
||||
System.out.println("获得公钥:" + rsa.getPublicKeyBase64());
|
||||
|
||||
//公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
System.out.println("加密后的串:" + rsa.encryptBase64("我是一段测试aaaa",KeyType.PublicKey));
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
System.out.println("公钥加密,私钥解密:" + new String(decrypt));
|
||||
|
||||
//Junit单元测试
|
||||
//Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
//私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
System.out.println("加密后的串:" + rsa.encryptBase64("url=/checkInInfo/reviewResult&token=2bce7d71-d60b-4858-a852-15380eba6c84×tamp=1574821902392",KeyType.PrivateKey));
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
System.out.println("私钥加密,公钥解密:" + new String(decrypt2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test06() {
|
||||
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDG03gR1w6i3E6h6+N9F2///BnRrkzPc7RT4qZKKl2b/rolym0EYl3QZTsIV5oQngT93TLtld7EK5svdwUabX6kzqd8yDDChZXS/E7/FrufN6Hwf9S3O3ZzkhEyd45HmRHV4aNRFsS/NviEZx83D6FR94l0SPnomvPkVqM8UnafnQIDAQAB";
|
||||
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMbTeBHXDqLcTqHr430Xb//8GdGuTM9ztFPipkoqXZv+uiXKbQRiXdBlOwhXmhCeBP3dMu2V3sQrmy93BRptfqTOp3zIMMKFldL8Tv8Wu583ofB/1Lc7dnOSETJ3jkeZEdXho1EWxL82+IRnHzcPoVH3iXRI+eia8+RWozxSdp+dAgMBAAECgYAJjtfqT6LR/HJBQXQ9qrdFIIrjNBRYMrE8CRzCWvgGDEBJmcoU2F+3KW6lj4SGAPqvc4dDuZ0sZAZBSWDy7MmWL+Zz2z44sulxsOsb3DJqIyBSAr5D6mhrRmu7MJA5AGgDHo/2gn+9Cji2JQBHBFe18BzJdr2tIM4uAYTVB6EW8QJBAPCrnHohSDtgLSmHrbORP/cIS8OOF/M3PsYfHZ3cpdrKk2zs1rXAHJq80GlmhSQx8tezx6wt63Cph0reiHbOMRkCQQDTfYqahFR0NTFFfTBfSJKQEqoiRYMnOrjkkOOgFv6cBwYd16pnqTfNISSYkBsOcDO09qiMILW96MoJONCV458lAkEAmMrqueK9X+zMX0xjK9hwOp5Ks2lXrTKKqO+CNwGpTkFD3WhzW8oOnvJ2giPzLSqE2QqrHpW8nrcSTKcBDiQTqQJABORmjGR7P6TrWtwmfk3Ddim4XcqV2hZ1qHPhkBZ4FUvkTFRs0LENZWVa31yWA6N8zrbV90fabGYyJjx2NsFpMQJARtRflzJjWc/49nzu+om41bz9Ngg07/S8Rxe8AlZbSlCxggmp/KUBcoVgNJCa5qGsX2AvTOCXaHngp+YLtHHPBQ==";
|
||||
|
||||
RSA rsa = new RSA(null,publicKey);
|
||||
|
||||
String str = "mlVdU379GcmXAFJvtdJ5rhoLrTOg89/efKmQvCtcYnEFUdZYuivURy0T62S0jN+KCKJ70LpfX7uoBMitBixAK8sUNq9YF9GF4GmnhSJHHklsgEujz+ULwPIG3kbhYpjKCl0RQXwdjyz0htNgLn6MR6M7JQ2fAbtR6nDL1Z2W8Ig=";
|
||||
|
||||
String decrypt = rsa.decryptStr(str, KeyType.PublicKey);
|
||||
System.out.println(decrypt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私钥加密
|
||||
*/
|
||||
@Test
|
||||
public void test07() throws UnsupportedEncodingException {
|
||||
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDG03gR1w6i3E6h6+N9F2///BnRrkzPc7RT4qZKKl2b/rolym0EYl3QZTsIV5oQngT93TLtld7EK5svdwUabX6kzqd8yDDChZXS/E7/FrufN6Hwf9S3O3ZzkhEyd45HmRHV4aNRFsS/NviEZx83D6FR94l0SPnomvPkVqM8UnafnQIDAQAB";
|
||||
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMbTeBHXDqLcTqHr430Xb//8GdGuTM9ztFPipkoqXZv+uiXKbQRiXdBlOwhXmhCeBP3dMu2V3sQrmy93BRptfqTOp3zIMMKFldL8Tv8Wu583ofB/1Lc7dnOSETJ3jkeZEdXho1EWxL82+IRnHzcPoVH3iXRI+eia8+RWozxSdp+dAgMBAAECgYAJjtfqT6LR/HJBQXQ9qrdFIIrjNBRYMrE8CRzCWvgGDEBJmcoU2F+3KW6lj4SGAPqvc4dDuZ0sZAZBSWDy7MmWL+Zz2z44sulxsOsb3DJqIyBSAr5D6mhrRmu7MJA5AGgDHo/2gn+9Cji2JQBHBFe18BzJdr2tIM4uAYTVB6EW8QJBAPCrnHohSDtgLSmHrbORP/cIS8OOF/M3PsYfHZ3cpdrKk2zs1rXAHJq80GlmhSQx8tezx6wt63Cph0reiHbOMRkCQQDTfYqahFR0NTFFfTBfSJKQEqoiRYMnOrjkkOOgFv6cBwYd16pnqTfNISSYkBsOcDO09qiMILW96MoJONCV458lAkEAmMrqueK9X+zMX0xjK9hwOp5Ks2lXrTKKqO+CNwGpTkFD3WhzW8oOnvJ2giPzLSqE2QqrHpW8nrcSTKcBDiQTqQJABORmjGR7P6TrWtwmfk3Ddim4XcqV2hZ1qHPhkBZ4FUvkTFRs0LENZWVa31yWA6N8zrbV90fabGYyJjx2NsFpMQJARtRflzJjWc/49nzu+om41bz9Ngg07/S8Rxe8AlZbSlCxggmp/KUBcoVgNJCa5qGsX2AvTOCXaHngp+YLtHHPBQ==";
|
||||
|
||||
RSA rsa = new RSA(privateKey,null);
|
||||
|
||||
String str = "url=/checkInInfo/reviewResult&token=5bce7d71-d60b-4858-a852-15380eba6c84×tamp=1681440129945";
|
||||
|
||||
String base64 = rsa.encryptBase64(str, KeyType.PrivateKey);
|
||||
System.out.println(base64);
|
||||
System.out.println(URLEncoder.encode(base64,"UTF-8"));
|
||||
System.out.println("==========PublicKey解密=============");
|
||||
|
||||
RSA rsa2 = new RSA(null, publicKey);
|
||||
try {
|
||||
System.out.println(rsa2.decryptStr(base64 + "ss", KeyType.PublicKey));
|
||||
} catch (CryptoException e) {
|
||||
System.out.println("发生异常===================" + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("聚酯树脂");
|
||||
list.add("聚酯树脂33");
|
||||
list.add("4,4'-(1-甲基亚乙基)双苯酚与(氯甲基)环氧乙烷的聚合物(平均分子量≤700)");
|
||||
System.out.println(JSONUtil.toJsonStr(list));
|
||||
System.out.println(this.getClass().getResource("/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test00() throws IOException {
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("template/declarationInformationExport.docx");
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
byte[] byteArray = outputStream.toByteArray();
|
||||
long l = System.currentTimeMillis();
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
// InputStream inputStream2 = getClass().getClassLoader().getResourceAsStream("template/declarationInformationExport.docx");
|
||||
// InputStream inputStream2 = new FileInputStream("C:\\Users\\RENCHAO\\IdeaProjects\\Test\\MyMaven\\src\\main\\resources\\template\\declarationInformationExport.docx");
|
||||
InputStream inputStream2 = new ByteArrayInputStream(byteArray);
|
||||
byte[] bytes = new byte[1024 * 1024];
|
||||
inputStream2.read(bytes);
|
||||
}
|
||||
System.out.println(System.currentTimeMillis() - l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test08() {
|
||||
System.out.println(new Date());
|
||||
System.out.println(Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()));
|
||||
System.out.println(TimeZone.getDefault());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.renchao.test;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserEntity {
|
||||
@ExcelProperty(value = "姓名")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty(value = "年龄")
|
||||
private int age;
|
||||
|
||||
@ExcelProperty(value = "操作时间")
|
||||
private Date time;
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<UserEntity> dataList = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
UserEntity userEntity = new UserEntity();
|
||||
userEntity.setName("张三" + i);
|
||||
userEntity.setAge(20 + i);
|
||||
userEntity.setTime(new Date(System.currentTimeMillis() + i));
|
||||
dataList.add(userEntity);
|
||||
}
|
||||
EasyExcel.write("C:/Users/RENCHAO/Desktop/资料/easyexcel-user1.xls", UserEntity.class).sheet("用户信息").doWrite(dataList);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,123 @@
|
||||
package com.renchao.test;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
public class ValidationUtil {
|
||||
/**
|
||||
* 开启快速结束模式 failFast (true)
|
||||
*/
|
||||
private static final Validator validator = Validation.byProvider(HibernateValidator.class).configure().failFast(false).buildValidatorFactory().getValidator();
|
||||
/**
|
||||
* 校验对象
|
||||
*
|
||||
* @param t bean
|
||||
* @param groups 校验组
|
||||
* @return ValidResult
|
||||
*/
|
||||
public static <T> ValidResult validateBean(T t,Class<?>...groups) {
|
||||
ValidResult result = new ValidResult();
|
||||
Set<ConstraintViolation<T>> violationSet = validator.validate(t,groups);
|
||||
boolean hasError = violationSet != null && violationSet.size() > 0;
|
||||
result.setHasErrors(hasError);
|
||||
if (hasError) {
|
||||
for (ConstraintViolation<T> violation : violationSet) {
|
||||
result.addError(violation.getPropertyPath().toString(), violation.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 校验bean的某一个属性
|
||||
*
|
||||
* @param obj bean
|
||||
* @param propertyName 属性名称
|
||||
* @return ValidResult
|
||||
*/
|
||||
public static <T> ValidResult validateProperty(T obj, String propertyName) {
|
||||
ValidResult result = new ValidResult();
|
||||
Set<ConstraintViolation<T>> violationSet = validator.validateProperty(obj, propertyName);
|
||||
boolean hasError = violationSet != null && violationSet.size() > 0;
|
||||
result.setHasErrors(hasError);
|
||||
if (hasError) {
|
||||
for (ConstraintViolation<T> violation : violationSet) {
|
||||
result.addError(propertyName, violation.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 校验结果类
|
||||
*/
|
||||
@Data
|
||||
static class ValidResult {
|
||||
|
||||
/**
|
||||
* 是否有错误
|
||||
*/
|
||||
private boolean hasErrors;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private List<ErrorMessage> errors;
|
||||
|
||||
public ValidResult() {
|
||||
this.errors = new ArrayList<>();
|
||||
}
|
||||
public boolean hasErrors() {
|
||||
return hasErrors;
|
||||
}
|
||||
|
||||
public void setHasErrors(boolean hasErrors) {
|
||||
this.hasErrors = hasErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有验证信息
|
||||
* @return 集合形式
|
||||
*/
|
||||
public List<ErrorMessage> getAllErrors() {
|
||||
return errors;
|
||||
}
|
||||
/**
|
||||
* 获取所有验证信息
|
||||
* @return 字符串形式
|
||||
*/
|
||||
public String getErrors(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (ErrorMessage error : errors) {
|
||||
sb.append(error.getPropertyPath()).append(":").append(error.getMessage()).append(" \n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void addError(String propertyName, String message) {
|
||||
this.errors.add(new ErrorMessage(propertyName, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
static class ErrorMessage {
|
||||
|
||||
private String propertyPath;
|
||||
|
||||
private String message;
|
||||
|
||||
public ErrorMessage() {
|
||||
}
|
||||
|
||||
public ErrorMessage(String propertyPath, String message) {
|
||||
this.propertyPath = propertyPath;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.renchao.utils;
|
||||
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
|
||||
public class RsaUtil {
|
||||
|
||||
private static final RSA PUB_RSA = new RSA(null, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMdrstRnZe65DiLQtGUuA33JKdwf4P4oBSd0itbUYmn/8N4Z9kVKap/yLZhXU8JRoI7yJLizR0iszlllbrRor+HBhB56NaHnZ1zTshELII/QXLCbqfevVDOcfvMs5OGa7pThxn3r08H7RCdko9xVWYDZvf3xJzrGe9Zj//zbe5ywIDAQAB");
|
||||
|
||||
|
||||
public static String decryptStr(String content) {
|
||||
return PUB_RSA.decryptStr(content, KeyType.PublicKey);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
ss
|
@ -0,0 +1 @@
|
||||
ss
|
@ -0,0 +1,70 @@
|
||||
package com.renchao;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
public class RSADemo {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// 生成密钥对
|
||||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
||||
keyPairGenerator.initialize(2048);
|
||||
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
||||
PublicKey publicKey = keyPair.getPublic();
|
||||
System.out.println(publicKey.getFormat());
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
|
||||
// 加密消息
|
||||
String message = "Hello RSA";
|
||||
Cipher cipher = Cipher.getInstance("RSA");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] encryptedMessage = cipher.doFinal(message.getBytes());
|
||||
System.out.println("Encrypted message: " + Base64.getEncoder().encodeToString(encryptedMessage));
|
||||
|
||||
// 解密密文
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] decryptedMessage = cipher.doFinal(encryptedMessage);
|
||||
System.out.println("Decrypted message: " + new String(decryptedMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() throws Exception {
|
||||
// String publicKeyStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDG03gR1w6i3E6h6+N9F2///BnRrkzPc7RT4qZKKl2b/rolym0EYl3QZTsIV5oQngT93TLtld7EK5svdwUabX6kzqd8yDDChZXS/E7/FrufN6Hwf9S3O3ZzkhEyd45HmRHV4aNRFsS/NviEZx83D6FR94l0SPnomvPkVqM8UnafnQIDAQAB";
|
||||
String publicKeyStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCUAPS4EiEkyKAay4dRY7hWuyTSewj3X1g9NXj6832Eup0VE+xxGfsDiU5xlZBenFcLT8nn88q3mYit5DowuwxTCmem2TIAfkxdAnZ4vm7ndVbugQTu3TDB5R7LIGRjNF62lfwzYc7ywJFHVH/7dVfh4/uaijjQeDhznlBxM57NgwIDAQAB";
|
||||
String privateKeyStr = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMbTeBHXDqLcTqHr430Xb//8GdGuTM9ztFPipkoqXZv+uiXKbQRiXdBlOwhXmhCeBP3dMu2V3sQrmy93BRptfqTOp3zIMMKFldL8Tv8Wu583ofB/1Lc7dnOSETJ3jkeZEdXho1EWxL82+IRnHzcPoVH3iXRI+eia8+RWozxSdp+dAgMBAAECgYAJjtfqT6LR/HJBQXQ9qrdFIIrjNBRYMrE8CRzCWvgGDEBJmcoU2F+3KW6lj4SGAPqvc4dDuZ0sZAZBSWDy7MmWL+Zz2z44sulxsOsb3DJqIyBSAr5D6mhrRmu7MJA5AGgDHo/2gn+9Cji2JQBHBFe18BzJdr2tIM4uAYTVB6EW8QJBAPCrnHohSDtgLSmHrbORP/cIS8OOF/M3PsYfHZ3cpdrKk2zs1rXAHJq80GlmhSQx8tezx6wt63Cph0reiHbOMRkCQQDTfYqahFR0NTFFfTBfSJKQEqoiRYMnOrjkkOOgFv6cBwYd16pnqTfNISSYkBsOcDO09qiMILW96MoJONCV458lAkEAmMrqueK9X+zMX0xjK9hwOp5Ks2lXrTKKqO+CNwGpTkFD3WhzW8oOnvJ2giPzLSqE2QqrHpW8nrcSTKcBDiQTqQJABORmjGR7P6TrWtwmfk3Ddim4XcqV2hZ1qHPhkBZ4FUvkTFRs0LENZWVa31yWA6N8zrbV90fabGYyJjx2NsFpMQJARtRflzJjWc/49nzu+om41bz9Ngg07/S8Rxe8AlZbSlCxggmp/KUBcoVgNJCa5qGsX2AvTOCXaHngp+YLtHHPBQ==";
|
||||
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
Cipher rsa = Cipher.getInstance("RSA");
|
||||
// 加密 Hello
|
||||
KeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKeyStr));
|
||||
PublicKey publicKey = keyFactory.generatePublic(keySpec);
|
||||
System.out.println(publicKey);
|
||||
System.out.println(System.currentTimeMillis());
|
||||
rsa.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
String str = "Admin1234," + System.currentTimeMillis();
|
||||
byte[] bytes = rsa.doFinal(str.getBytes(StandardCharsets.UTF_8));
|
||||
String s = Base64.getEncoder().encodeToString(bytes);
|
||||
System.out.println(s);
|
||||
|
||||
|
||||
// 解密
|
||||
// KeySpec keySpec2 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyStr));
|
||||
// PrivateKey privateKey = keyFactory.generatePrivate(keySpec2);
|
||||
// rsa.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
// byte[] bytes1 = rsa.doFinal(Base64.getDecoder().decode(s));
|
||||
// System.out.println("解密后:" + new String(bytes1, StandardCharsets.UTF_8));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.renchao;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StringFormatDemo {
|
||||
public static void main(String[] args) {
|
||||
String format = String.format("aaa%s,bbb%s,ccc%s", "111", 222, "333");
|
||||
System.out.println(format);
|
||||
|
||||
String s = String.format("%s/%s/%s/%s.pdf", "c:", "a", "b", UUID.randomUUID());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
StringFormatDemo demo = new StringFormatDemo();
|
||||
String t = demo.t();
|
||||
System.out.println(t);
|
||||
}
|
||||
|
||||
|
||||
public String t() {
|
||||
try {
|
||||
// int i =4 / 0;
|
||||
return "try";
|
||||
} catch (Exception e) {
|
||||
return "catch";
|
||||
} finally {
|
||||
// return "finally";
|
||||
System.out.println("ccc");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.renchao;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class ZonedDateTimeDemo {
|
||||
|
||||
@Test
|
||||
public void test09() throws InterruptedException {
|
||||
// long timestamp = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
||||
// System.out.println(timestamp);
|
||||
//// Thread.sleep(5000);
|
||||
// System.out.println(System.currentTimeMillis() - timestamp);
|
||||
// System.out.println(30<<1<<2);
|
||||
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.of(2023, 4, 13, 12, 57, 0, 0, ZoneId.systemDefault());
|
||||
long l = zonedDateTime.toInstant().toEpochMilli();
|
||||
System.out.println(l);
|
||||
System.out.println(System.currentTimeMillis());
|
||||
|
||||
System.out.println((System.currentTimeMillis() - 1681365120000L) /1000/60);
|
||||
System.out.println(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?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>
|
@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?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>
|
@ -0,0 +1,30 @@
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.jiuyv.agile.data.controller;
|
||||
|
||||
import com.jiuyv.agile.data.api.AgileApi;
|
||||
|
||||
|
||||
public interface ts extends AgileApi {
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.jiuyv.agile.data.database;
|
||||
|
||||
public interface DataSourceFactory {
|
||||
|
||||
/**
|
||||
* 创建数据源实例
|
||||
*
|
||||
* @param property
|
||||
* @return
|
||||
*/
|
||||
DbQuery createDbQuery(DbQueryProperty property);
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue