init code
This commit is contained in:
21
.editorconfig
Normal file
21
.editorconfig
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# 空格替代Tab缩进在各种编辑工具下效果一致
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.java]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.{json,yml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
insert_final_newline = false
|
||||||
|
trim_trailing_whitespace = false
|
||||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM registry.cn-hangzhou.aliyuncs.com/bladex-repo/alpine-java:openjdk17_cn_slim
|
||||||
|
|
||||||
|
LABEL maintainer="yamasaki8499@gmail.com"
|
||||||
|
|
||||||
|
RUN mkdir -p /blade
|
||||||
|
|
||||||
|
WORKDIR /blade
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
COPY ./target/blade-api.jar ./app.jar
|
||||||
|
|
||||||
|
ENTRYPOINT ["java", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
|
||||||
|
|
||||||
|
CMD ["--spring.profiles.active=prod"]
|
||||||
372
pom.xml
Normal file
372
pom.xml
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
<?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.springblade</groupId>
|
||||||
|
<artifactId>BladeX-Boot</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>4.6.0.RELEASE</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<bladex.project.id>blade-api</bladex.project.id>
|
||||||
|
<bladex.project.version>4.6.0.RELEASE</bladex.project.version>
|
||||||
|
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<maven.plugin.version>3.11.0</maven.plugin.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
|
<!-- Docker仓库服务配置 -->
|
||||||
|
<docker.registry.url>192.168.0.188</docker.registry.url>
|
||||||
|
<docker.username>admin</docker.username>
|
||||||
|
<docker.password>admin12345</docker.password>
|
||||||
|
<docker.namespace>blade</docker.namespace>
|
||||||
|
<docker.fabric.version>0.42.0</docker.fabric.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Blade -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade.platform</groupId>
|
||||||
|
<artifactId>blade-bom</artifactId>
|
||||||
|
<version>${bladex.project.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-boot</artifactId>
|
||||||
|
<version>${bladex.project.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-cloud</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- ↓ BladeX依赖库 ↓ -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-boot</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-oauth2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 多租户字段隔离模式 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-tenant</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 多租户数据库隔离模式则引入此配置 -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-tenant-dynamic</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!-- 集成sharding功能则引入此配置 -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-sharding</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-http</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-api-crypto</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-data-record</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-data-scope</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-develop</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-swagger</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-excel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-social</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-ui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- 报表 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-report</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 验证码 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.whvcse</groupId>
|
||||||
|
<artifactId>easy-captcha</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis-Plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--Oss-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-oss</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--Sms-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-sms</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--Aws S3-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-s3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--MinIO-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--Alioss-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--AliSms-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--华为云Obs-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.huaweicloud</groupId>
|
||||||
|
<artifactId>esdk-obs-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--腾讯COS-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qcloud</groupId>
|
||||||
|
<artifactId>cos_api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--腾讯SMS-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
|
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--QiNiu-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qiniu</groupId>
|
||||||
|
<artifactId>qiniu-java-sdk</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--YunPian-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yunpian.sdk</groupId>
|
||||||
|
<artifactId>yunpian-java-sdk</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- literule -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-starter-literule</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Oracle -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.oracle.database.jdbc</groupId>
|
||||||
|
<artifactId>ojdbc17</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!-- PostgreSql -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!-- SqlServer -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.microsoft.sqlserver</groupId>
|
||||||
|
<artifactId>mssql-jdbc</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!-- DaMeng -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.dameng</groupId>
|
||||||
|
<artifactId>DmJdbcDriver18</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!--YashanDB-->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.yashandb.jdbc</groupId>
|
||||||
|
<artifactId>yasdb-jdbc</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!--KingbaseES-->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>cn.com.kingbase</groupId>
|
||||||
|
<artifactId>kingbase8</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
<!-- 任务调度 -->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springblade</groupId>-->
|
||||||
|
<!-- <artifactId>blade-starter-powerjob</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- 工作流 -->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springblade</groupId>-->
|
||||||
|
<!-- <artifactId>blade-starter-flowable</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- auto -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-auto</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- ↑ BladeX依赖库 ↑ -->
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>${bladex.project.id}</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.xml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>3.2.10</version>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<excludes>
|
||||||
|
<!-- 打包的 jar 中排除 lombok -->
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.fabric8</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
<version>${docker.fabric.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<authConfig>
|
||||||
|
<username>${docker.username}</username>
|
||||||
|
<password>${docker.password}</password>
|
||||||
|
</authConfig>
|
||||||
|
<registry>${docker.registry.url}</registry>
|
||||||
|
<images>
|
||||||
|
<image>
|
||||||
|
<name>${docker.namespace}/${project.build.finalName}:${project.version}</name>
|
||||||
|
<alias>${project.name}</alias>
|
||||||
|
<build>
|
||||||
|
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
|
||||||
|
</build>
|
||||||
|
</image>
|
||||||
|
</images>
|
||||||
|
<buildArgs>
|
||||||
|
<JAR_FILE>${basedir}/target/${project.build.finalName}.jar</JAR_FILE>
|
||||||
|
</buildArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>aliyun-repos</id>
|
||||||
|
<name>Aliyun Public Repository</name>
|
||||||
|
<url>https://maven.aliyun.com/repository/public</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>bladex</id>
|
||||||
|
<name>BladeX Release Repository</name>
|
||||||
|
<url>https://center.javablade.com/api/packages/blade/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>aliyun-plugin</id>
|
||||||
|
<name>Aliyun Public Plugin</name>
|
||||||
|
<url>https://maven.aliyun.com/repository/public</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>bladex</id>
|
||||||
|
<name>BladeX Release Repository</name>
|
||||||
|
<url>https://center.javablade.com/api/packages/blade/maven</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>bladex</id>
|
||||||
|
<name>BladeX Snapshot Repository</name>
|
||||||
|
<url>https://center.javablade.com/api/packages/blade/maven</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
</project>
|
||||||
49
src/main/java/org/springblade/Application.java
Normal file
49
src/main/java/org/springblade/Application.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade;
|
||||||
|
|
||||||
|
import org.springblade.common.constant.CommonConstant;
|
||||||
|
import org.springblade.core.launch.BladeApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@EnableScheduling
|
||||||
|
@EnableRedisHttpSession
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
BladeApplication.run(CommonConstant.APPLICATION_NAME, Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
75
src/main/java/org/springblade/common/cache/CacheNames.java
vendored
Normal file
75
src/main/java/org/springblade/common/cache/CacheNames.java
vendored
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存名
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface CacheNames {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回拼接后的key
|
||||||
|
*
|
||||||
|
* @param cacheKey 缓存key
|
||||||
|
* @param cacheKeyValue 缓存key值
|
||||||
|
* @return tenantKey
|
||||||
|
*/
|
||||||
|
static String cacheKey(String cacheKey, String cacheKeyValue) {
|
||||||
|
return cacheKey.concat(cacheKeyValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回租户格式的key
|
||||||
|
*
|
||||||
|
* @param tenantId 租户编号
|
||||||
|
* @param cacheKey 缓存key
|
||||||
|
* @param cacheKeyValue 缓存key值
|
||||||
|
* @return tenantKey
|
||||||
|
*/
|
||||||
|
static String tenantKey(String tenantId, String cacheKey, String cacheKeyValue) {
|
||||||
|
return tenantId.concat(StringPool.COLON).concat(cacheKey).concat(cacheKeyValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码key
|
||||||
|
*/
|
||||||
|
String CAPTCHA_KEY = "blade:auth::blade:captcha:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号失败key
|
||||||
|
*/
|
||||||
|
String ACCOUNT_FAIL_KEY = "blade:lock::account:fail:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP失败key
|
||||||
|
*/
|
||||||
|
String IP_FAIL_KEY = "blade:lock::ip:fail:";
|
||||||
|
|
||||||
|
}
|
||||||
125
src/main/java/org/springblade/common/cache/DictBizCache.java
vendored
Normal file
125
src/main/java/org/springblade/common/cache/DictBizCache.java
vendored
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.common.enums.DictBizEnum;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.modules.system.pojo.entity.DictBiz;
|
||||||
|
import org.springblade.modules.system.service.IDictBizService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务字典缓存工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class DictBizCache {
|
||||||
|
|
||||||
|
private static final String DICT_ID = "dictBiz:id";
|
||||||
|
private static final String DICT_VALUE = "dictBiz:value";
|
||||||
|
private static final String DICT_LIST = "dictBiz:list";
|
||||||
|
|
||||||
|
private static final IDictBizService dictService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
dictService = SpringUtil.getBean(IDictBizService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典实体
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return DictBiz
|
||||||
|
*/
|
||||||
|
public static DictBiz getById(Long id) {
|
||||||
|
String keyPrefix = DICT_ID.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||||
|
return CacheUtil.get(DICT_CACHE, keyPrefix, id, () -> dictService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号枚举
|
||||||
|
* @param dictKey Integer型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(DictBizEnum code, Integer dictKey) {
|
||||||
|
return getValue(code.getName(), dictKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @param dictKey Integer型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(String code, Integer dictKey) {
|
||||||
|
String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||||
|
return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号枚举
|
||||||
|
* @param dictKey String型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(DictBizEnum code, String dictKey) {
|
||||||
|
return getValue(code.getName(), dictKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @param dictKey String型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(String code, String dictKey) {
|
||||||
|
String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||||
|
return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典集合
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @return List<DictBiz>
|
||||||
|
*/
|
||||||
|
public static List<DictBiz> getList(String code) {
|
||||||
|
String keyPrefix = DICT_LIST.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||||
|
return CacheUtil.get(DICT_CACHE, keyPrefix, code, () -> dictService.getList(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
152
src/main/java/org/springblade/common/cache/DictCache.java
vendored
Normal file
152
src/main/java/org/springblade/common/cache/DictCache.java
vendored
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.common.enums.DictEnum;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.modules.system.pojo.entity.Dict;
|
||||||
|
import org.springblade.modules.system.service.IDictService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典缓存工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class DictCache {
|
||||||
|
|
||||||
|
private static final String DICT_ID = "dict:id:";
|
||||||
|
private static final String DICT_KEY = "dict:key:";
|
||||||
|
private static final String DICT_VALUE = "dict:value:";
|
||||||
|
private static final String DICT_LIST = "dict:list:";
|
||||||
|
|
||||||
|
private static final Boolean TENANT_MODE = Boolean.FALSE;
|
||||||
|
|
||||||
|
private static final IDictService dictService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
dictService = SpringUtil.getBean(IDictService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典实体
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return Dict
|
||||||
|
*/
|
||||||
|
public static Dict getById(Long id) {
|
||||||
|
return CacheUtil.get(DICT_CACHE, DICT_ID, id, () -> dictService.getById(id), TENANT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号枚举
|
||||||
|
* @param dictValue 字典值
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getKey(DictEnum code, String dictValue) {
|
||||||
|
return getKey(code.getName(), dictValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典键
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @param dictValue 字典值
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getKey(String code, String dictValue) {
|
||||||
|
return CacheUtil.get(DICT_CACHE, DICT_KEY + code + StringPool.COLON, dictValue, () -> {
|
||||||
|
List<Dict> list = getList(code);
|
||||||
|
Optional<String> key = list.stream().filter(
|
||||||
|
dict -> dict.getDictValue().equalsIgnoreCase(dictValue)
|
||||||
|
).map(Dict::getDictKey).findFirst();
|
||||||
|
return key.orElse(StringPool.EMPTY);
|
||||||
|
}, TENANT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号枚举
|
||||||
|
* @param dictKey Integer型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(DictEnum code, Integer dictKey) {
|
||||||
|
return getValue(code.getName(), dictKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @param dictKey Integer型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(String code, Integer dictKey) {
|
||||||
|
return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)), TENANT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号枚举
|
||||||
|
* @param dictKey String型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(DictEnum code, String dictKey) {
|
||||||
|
return getValue(code.getName(), dictKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典值
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @param dictKey String型字典键
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(String code, String dictKey) {
|
||||||
|
return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey), TENANT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典集合
|
||||||
|
*
|
||||||
|
* @param code 字典编号
|
||||||
|
* @return List<Dict>
|
||||||
|
*/
|
||||||
|
public static List<Dict> getList(String code) {
|
||||||
|
return CacheUtil.get(DICT_CACHE, DICT_LIST, code, () -> dictService.getList(code), TENANT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
71
src/main/java/org/springblade/common/cache/ParamCache.java
vendored
Normal file
71
src/main/java/org/springblade/common/cache/ParamCache.java
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.modules.system.pojo.entity.Param;
|
||||||
|
import org.springblade.modules.system.service.IParamService;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.PARAM_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数缓存工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class ParamCache {
|
||||||
|
|
||||||
|
private static final String PARAM_ID = "param:id:";
|
||||||
|
private static final String PARAM_VALUE = "param:value:";
|
||||||
|
|
||||||
|
private static final IParamService paramService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
paramService = SpringUtil.getBean(IParamService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数实体
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return Param
|
||||||
|
*/
|
||||||
|
public static Param getById(Long id) {
|
||||||
|
return CacheUtil.get(PARAM_CACHE, PARAM_ID, id, () -> paramService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数配置
|
||||||
|
*
|
||||||
|
* @param paramKey 参数值
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getValue(String paramKey) {
|
||||||
|
return CacheUtil.get(PARAM_CACHE, PARAM_VALUE, paramKey, () -> paramService.getValue(paramKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
src/main/java/org/springblade/common/cache/RegionCache.java
vendored
Normal file
66
src/main/java/org/springblade/common/cache/RegionCache.java
vendored
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.modules.system.pojo.entity.Region;
|
||||||
|
import org.springblade.modules.system.service.IRegionService;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行政区划缓存工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class RegionCache {
|
||||||
|
public static final String MAIN_CODE = "00";
|
||||||
|
public static final int PROVINCE_LEVEL = 1;
|
||||||
|
public static final int CITY_LEVEL = 2;
|
||||||
|
public static final int DISTRICT_LEVEL = 3;
|
||||||
|
public static final int TOWN_LEVEL = 4;
|
||||||
|
public static final int VILLAGE_LEVEL = 5;
|
||||||
|
|
||||||
|
private static final String REGION_CODE = "region:code:";
|
||||||
|
|
||||||
|
private static final IRegionService regionService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
regionService = SpringUtil.getBean(IRegionService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取行政区划实体
|
||||||
|
*
|
||||||
|
* @param code 区划编号
|
||||||
|
* @return Param
|
||||||
|
*/
|
||||||
|
public static Region getByCode(String code) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, REGION_CODE, code, () -> regionService.getById(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
334
src/main/java/org/springblade/common/cache/SysCache.java
vendored
Normal file
334
src/main/java/org/springblade/common/cache/SysCache.java
vendored
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.mp.enums.StatusType;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.modules.system.pojo.entity.*;
|
||||||
|
import org.springblade.modules.system.service.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统缓存
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class SysCache {
|
||||||
|
private static final String MENU_ID = "menu:id:";
|
||||||
|
private static final String DEPT_ID = "dept:id:";
|
||||||
|
private static final String DEPT_NAME = "dept:name:";
|
||||||
|
private static final String DEPT_NAME_FUZZY = "dept:nameFuzzy:";
|
||||||
|
private static final String DEPT_NAME_ID = "deptName:id:";
|
||||||
|
private static final String DEPT_NAMES_ID = "deptNames:id:";
|
||||||
|
private static final String DEPT_CHILD_ID = "deptChild:id:";
|
||||||
|
private static final String DEPT_CHILDIDS_ID = "deptChildIds:id:";
|
||||||
|
private static final String POST_ID = "post:id:";
|
||||||
|
private static final String POST_NAME = "post:name:";
|
||||||
|
private static final String POST_NAME_FUZZY = "post:nameFuzzy:";
|
||||||
|
private static final String POST_NAME_ID = "postName:id:";
|
||||||
|
private static final String POST_NAMES_ID = "postNames:id:";
|
||||||
|
private static final String ROLE_ID = "role:id:";
|
||||||
|
private static final String ROLE_NAME = "role:name:";
|
||||||
|
private static final String ROLE_NAME_ID = "roleName:id:";
|
||||||
|
private static final String ROLE_NAMES_ID = "roleNames:id:";
|
||||||
|
private static final String ROLE_ALIAS_ID = "roleAlias:id:";
|
||||||
|
private static final String ROLE_ALIASES_ID = "roleAliases:id:";
|
||||||
|
public static final String TENANT_ID = "tenant:id:";
|
||||||
|
public static final String TENANT_TENANT_ID = "tenant:tenantId:";
|
||||||
|
public static final String TENANT_PACKAGE_ID = "tenant:packageId:";
|
||||||
|
|
||||||
|
private static final IMenuService menuService;
|
||||||
|
private static final IDeptService deptService;
|
||||||
|
private static final IPostService postService;
|
||||||
|
private static final IRoleService roleService;
|
||||||
|
private static final ITenantService tenantService;
|
||||||
|
private static final ITenantPackageService tenantPackageService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
menuService = SpringUtil.getBean(IMenuService.class);
|
||||||
|
deptService = SpringUtil.getBean(IDeptService.class);
|
||||||
|
postService = SpringUtil.getBean(IPostService.class);
|
||||||
|
roleService = SpringUtil.getBean(IRoleService.class);
|
||||||
|
tenantService = SpringUtil.getBean(ITenantService.class);
|
||||||
|
tenantPackageService = SpringUtil.getBean(ITenantPackageService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 菜单
|
||||||
|
*/
|
||||||
|
public static Menu getMenu(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, MENU_ID, id, () -> menuService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 部门
|
||||||
|
*/
|
||||||
|
public static Dept getDept(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_ID, id, () -> deptService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门id
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param deptNames 部门名
|
||||||
|
* @return 部门id
|
||||||
|
*/
|
||||||
|
public static String getDeptIds(String tenantId, String deptNames) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_NAME, tenantId + StringPool.DASH + deptNames, () -> deptService.getDeptIds(tenantId, deptNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门id
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param deptNames 部门名模糊查询
|
||||||
|
* @return 部门id
|
||||||
|
*/
|
||||||
|
public static String getDeptIdsByFuzzy(String tenantId, String deptNames) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_NAME_FUZZY, tenantId + StringPool.DASH + deptNames, () -> deptService.getDeptIdsByFuzzy(tenantId, deptNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门名
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 部门名
|
||||||
|
*/
|
||||||
|
public static String getDeptName(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_NAME_ID, id, () -> deptService.getById(id).getDeptName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门名集合
|
||||||
|
*
|
||||||
|
* @param deptIds 主键集合
|
||||||
|
* @return 部门名
|
||||||
|
*/
|
||||||
|
public static List<String> getDeptNames(String deptIds) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_NAMES_ID, deptIds, () -> deptService.getDeptNames(deptIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子部门集合
|
||||||
|
*
|
||||||
|
* @param deptId 主键
|
||||||
|
* @return 子部门
|
||||||
|
*/
|
||||||
|
public static List<Dept> getDeptChild(Long deptId) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, DEPT_CHILD_ID, deptId, () -> deptService.getDeptChild(deptId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子部门ID集合
|
||||||
|
*
|
||||||
|
* @param deptId 主键
|
||||||
|
* @return 子部门ID
|
||||||
|
*/
|
||||||
|
public static List<Long> getDeptChildIds(Long deptId) {
|
||||||
|
if (deptId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<Long> deptIdList = CacheUtil.get(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, List.class);
|
||||||
|
if (deptIdList == null) {
|
||||||
|
deptIdList = new ArrayList<>();
|
||||||
|
List<Dept> deptChild = getDeptChild(deptId);
|
||||||
|
if (deptChild != null) {
|
||||||
|
List<Long> collect = deptChild.stream().map(Dept::getId).collect(Collectors.toList());
|
||||||
|
deptIdList.addAll(collect);
|
||||||
|
}
|
||||||
|
deptIdList.add(deptId);
|
||||||
|
CacheUtil.put(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, deptIdList);
|
||||||
|
}
|
||||||
|
return deptIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Post getPost(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, POST_ID, id, () -> postService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位id
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param postNames 岗位名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getPostIds(String tenantId, String postNames) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, POST_NAME, tenantId + StringPool.DASH + postNames, () -> postService.getPostIds(tenantId, postNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位id
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param postNames 岗位名模糊查询
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getPostIdsByFuzzy(String tenantId, String postNames) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, POST_NAME_FUZZY, tenantId + StringPool.DASH + postNames, () -> postService.getPostIdsByFuzzy(tenantId, postNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位名
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 岗位名
|
||||||
|
*/
|
||||||
|
public static String getPostName(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, POST_NAME_ID, id, () -> postService.getById(id).getPostName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位名集合
|
||||||
|
*
|
||||||
|
* @param postIds 主键集合
|
||||||
|
* @return 岗位名
|
||||||
|
*/
|
||||||
|
public static List<String> getPostNames(String postIds) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, POST_NAMES_ID, postIds, () -> postService.getPostNames(postIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return Role
|
||||||
|
*/
|
||||||
|
public static Role getRole(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_ID, id, () -> roleService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色id
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param roleNames 角色名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getRoleIds(String tenantId, String roleNames) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_NAME, tenantId + StringPool.DASH + roleNames, () -> roleService.getRoleIds(tenantId, roleNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色名
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 角色名
|
||||||
|
*/
|
||||||
|
public static String getRoleName(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_NAME_ID, id, () -> roleService.getById(id).getRoleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色名集合
|
||||||
|
*
|
||||||
|
* @param roleIds 主键集合
|
||||||
|
* @return 角色名
|
||||||
|
*/
|
||||||
|
public static List<String> getRoleNames(String roleIds) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_NAMES_ID, roleIds, () -> roleService.getRoleNames(roleIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色别名
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 角色别名
|
||||||
|
*/
|
||||||
|
public static String getRoleAlias(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_ALIAS_ID, id, () -> roleService.getById(id).getRoleAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色别名集合
|
||||||
|
*
|
||||||
|
* @param roleIds 主键集合
|
||||||
|
* @return 角色别名
|
||||||
|
*/
|
||||||
|
public static List<String> getRoleAliases(String roleIds) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, ROLE_ALIASES_ID, roleIds, () -> roleService.getRoleAliases(roleIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return Tenant
|
||||||
|
*/
|
||||||
|
public static Tenant getTenant(Long id) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, TENANT_ID, id, () -> Optional.ofNullable(tenantService.getById(id))
|
||||||
|
.filter(tenant -> tenant.getStatus() != null)
|
||||||
|
.filter(tenant -> tenant.getStatus() == StatusType.ACTIVE.getType())
|
||||||
|
.orElse(null), Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return Tenant
|
||||||
|
*/
|
||||||
|
public static Tenant getTenant(String tenantId) {
|
||||||
|
return CacheUtil.get(SYS_CACHE, TENANT_TENANT_ID, tenantId, () -> Optional.ofNullable(tenantService.getByTenantId(tenantId))
|
||||||
|
.filter(tenant -> tenant.getStatus() != null)
|
||||||
|
.filter(tenant -> tenant.getStatus() == StatusType.ACTIVE.getType())
|
||||||
|
.orElse(null), Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户产品包
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return Tenant
|
||||||
|
*/
|
||||||
|
public static TenantPackage getTenantPackage(String tenantId) {
|
||||||
|
Tenant tenant = getTenant(tenantId);
|
||||||
|
return CacheUtil.get(SYS_CACHE, TENANT_PACKAGE_ID, tenantId, () -> tenantPackageService.getById(tenant.getPackageId()), Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
86
src/main/java/org/springblade/common/cache/UserCache.java
vendored
Normal file
86
src/main/java/org/springblade/common/cache/UserCache.java
vendored
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.cache;
|
||||||
|
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.SpringUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.modules.system.pojo.entity.User;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
|
||||||
|
import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统缓存
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class UserCache {
|
||||||
|
private static final String USER_CACHE_ID = "user:id:";
|
||||||
|
private static final String USER_CACHE_ACCOUNT = "user:account:";
|
||||||
|
|
||||||
|
private static final IUserService userService;
|
||||||
|
|
||||||
|
static {
|
||||||
|
userService = SpringUtil.getBean(IUserService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据任务用户id获取用户信息
|
||||||
|
*
|
||||||
|
* @param taskUserId 任务用户id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static User getUserByTaskUser(String taskUserId) {
|
||||||
|
Long userId = Func.toLong(StringUtil.removePrefix(taskUserId, TASK_USR_PREFIX));
|
||||||
|
return getUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static User getUser(Long userId) {
|
||||||
|
return CacheUtil.get(USER_CACHE, USER_CACHE_ID, userId, () -> userService.getById(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static User getUser(String tenantId, String account) {
|
||||||
|
return CacheUtil.get(USER_CACHE, USER_CACHE_ACCOUNT, tenantId + StringPool.DASH + account, () -> userService.userByAccount(tenantId, account));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.oauth2.endpoint.OAuth2SocialEndpoint;
|
||||||
|
import org.springblade.core.oauth2.endpoint.OAuth2TokenEndPoint;
|
||||||
|
import org.springblade.core.secure.provider.HttpMethod;
|
||||||
|
import org.springblade.core.secure.registry.SecureRegistry;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.modules.auth.endpoint.Oauth2SmsEndpoint;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blade配置
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
public class BladeConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全框架配置
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SecureRegistry secureRegistry() {
|
||||||
|
return new SecureRegistry()
|
||||||
|
// 开启认证配置
|
||||||
|
.enabled()
|
||||||
|
// 令牌严格模式配置
|
||||||
|
.strictTokenEnabled()
|
||||||
|
// 请求头严格模式配置
|
||||||
|
.strictHeaderEnabled()
|
||||||
|
// 认证放行配置
|
||||||
|
.skipUrls(
|
||||||
|
"/blade-auth/**",
|
||||||
|
"/blade-system/tenant/info",
|
||||||
|
"/blade-flow/process/resource-view",
|
||||||
|
"/blade-flow/process/diagram-view",
|
||||||
|
"/blade-flow/manager/check-upload",
|
||||||
|
"/doc.html",
|
||||||
|
"/swagger-ui.html",
|
||||||
|
"/static/**",
|
||||||
|
"/webjars/**",
|
||||||
|
"/swagger-resources/**",
|
||||||
|
"/druid/**"
|
||||||
|
)
|
||||||
|
// 认证鉴权配置
|
||||||
|
.authEnabled()
|
||||||
|
.addAuthPattern(HttpMethod.ALL, "/blade-chat/message/**", "hasAuth()")
|
||||||
|
.addAuthPattern(HttpMethod.POST, "/blade-desk/dashboard/upload", "hasTimeAuth(9, 17)")
|
||||||
|
.addAuthPattern(HttpMethod.POST, "/blade-desk/dashboard/submit", "hasAnyRole('administrator', 'admin', 'user')")
|
||||||
|
// 基础认证配置
|
||||||
|
.basicEnabled()
|
||||||
|
.addBasicPattern(HttpMethod.POST, "/blade-desk/dashboard/info", "blade", "blade")
|
||||||
|
// 签名认证配置
|
||||||
|
.signDisabled()
|
||||||
|
.addSignPattern(HttpMethod.POST, "/blade-desk/dashboard/sign", "sha1");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跨域配置
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/cors/**")
|
||||||
|
.allowedOriginPatterns("*")
|
||||||
|
.allowedHeaders("*")
|
||||||
|
.allowedMethods("*")
|
||||||
|
.maxAge(3600)
|
||||||
|
.allowCredentials(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给OAuth2服务端添加前缀
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void configurePathMatch(PathMatchConfigurer configurer) {
|
||||||
|
configurer.addPathPrefix(StringPool.SLASH + AppConstant.APPLICATION_AUTH_NAME,
|
||||||
|
c -> c.isAnnotationPresent(RestController.class) && (
|
||||||
|
OAuth2TokenEndPoint.class.equals(c) || OAuth2SocialEndpoint.class.equals(c) || Oauth2SmsEndpoint.class.equals(c))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.common.handler.BladePermissionHandler;
|
||||||
|
import org.springblade.common.handler.BladeRecordHandler;
|
||||||
|
import org.springblade.common.handler.BladeScopeModelHandler;
|
||||||
|
import org.springblade.core.datarecord.processor.DataRecordHandler;
|
||||||
|
import org.springblade.core.datascope.handler.ScopeModelHandler;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blade处理器自动配置
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladeHandlerConfiguration {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataRecordHandler dataRecordHandler() {
|
||||||
|
return new BladeRecordHandler(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ScopeModelHandler scopeModelHandler() {
|
||||||
|
return new BladeScopeModelHandler(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BladePermissionHandler permissionHandler() {
|
||||||
|
return new BladePermissionHandler(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.common.event.ApiLogListener;
|
||||||
|
import org.springblade.common.event.ErrorLogListener;
|
||||||
|
import org.springblade.common.event.UsualLogListener;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.launch.server.ServerInfo;
|
||||||
|
import org.springblade.modules.system.service.ILogService;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志工具自动配置
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladeLogConfiguration {
|
||||||
|
|
||||||
|
private final ILogService logService;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private final BladeProperties bladeProperties;
|
||||||
|
|
||||||
|
@Bean(name = "apiLogListener")
|
||||||
|
public ApiLogListener apiLogListener() {
|
||||||
|
return new ApiLogListener(logService, serverInfo, bladeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "errorEventListener")
|
||||||
|
public ErrorLogListener errorEventListener() {
|
||||||
|
return new ErrorLogListener(logService, serverInfo, bladeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "usualEventListener")
|
||||||
|
public UsualLogListener usualEventListener() {
|
||||||
|
return new UsualLogListener(logService, serverInfo, bladeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
import org.springblade.common.filter.PreviewFilter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 演示配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty(value = "blade.preview.enabled", havingValue = "true")
|
||||||
|
public class BladePreviewConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 演示模式配置
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public PreviewFilter previewFilter() {
|
||||||
|
return new PreviewFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
import org.springblade.core.report.datasource.ReportDataSource;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty(value = "report.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
|
public class BladeReportConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义报表可选数据源
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ReportDataSource reportDataSource(DataSource dataSource) {
|
||||||
|
return new ReportDataSource(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swagger配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ConditionalOnProperty(value = "swagger.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
|
public class SwaggerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi authApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("授权模块")
|
||||||
|
.packagesToScan(AppConstant.BASE_PACKAGES + ".core.oauth2", AppConstant.BASE_PACKAGES + ".modules.auth")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi sysApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("系统模块")
|
||||||
|
.packagesToScan(AppConstant.BASE_PACKAGES + ".modules.system", AppConstant.BASE_PACKAGES + ".modules.resource")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi flowApi() {
|
||||||
|
// 创建并返回GroupedOpenApi对象
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("工作流模块")
|
||||||
|
.packagesToScan(AppConstant.BASE_PACKAGES + ".flow")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.constant;
|
||||||
|
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用常量
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface CommonConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app name
|
||||||
|
*/
|
||||||
|
String APPLICATION_NAME = AppConstant.APPLICATION_NAME_PREFIX + "api";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sword 系统名
|
||||||
|
*/
|
||||||
|
String SWORD_NAME = "sword";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saber 系统名
|
||||||
|
*/
|
||||||
|
String SABER_NAME = "saber";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顶级父节点id
|
||||||
|
*/
|
||||||
|
Long TOP_PARENT_ID = 0L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顶级父节点名称
|
||||||
|
*/
|
||||||
|
String TOP_PARENT_NAME = "顶级";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未封存状态值
|
||||||
|
*/
|
||||||
|
Integer NOT_SEALED_ID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认密码
|
||||||
|
*/
|
||||||
|
String DEFAULT_PASSWORD = "123456";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认密码参数值
|
||||||
|
*/
|
||||||
|
String DEFAULT_PARAM_PASSWORD = "account.initPassword";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认排序字段
|
||||||
|
*/
|
||||||
|
String SORT_FIELD = "sort";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限类型
|
||||||
|
*/
|
||||||
|
Integer DATA_SCOPE_CATEGORY = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口权限类型
|
||||||
|
*/
|
||||||
|
Integer API_SCOPE_CATEGORY = 2;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典常量.
|
||||||
|
*
|
||||||
|
* @author zhuangqian
|
||||||
|
*/
|
||||||
|
public interface DictConstant {
|
||||||
|
|
||||||
|
String SEX_CODE = "sex";
|
||||||
|
|
||||||
|
String NOTICE_CODE = "notice";
|
||||||
|
|
||||||
|
String MENU_CATEGORY_CODE = "menu_category";
|
||||||
|
|
||||||
|
String BUTTON_FUNC_CODE = "button_func";
|
||||||
|
|
||||||
|
String YES_NO_CODE = "yes_no";
|
||||||
|
|
||||||
|
String FLOW_CATEGORY_CODE = "flow_category";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.constant;
|
||||||
|
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动常量
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface LauncherConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sentinel dev 地址
|
||||||
|
*/
|
||||||
|
String SENTINEL_DEV_ADDR = "127.0.0.1:8858";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sentinel prod 地址
|
||||||
|
*/
|
||||||
|
String SENTINEL_PROD_ADDR = "10.211.55.5:8858";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sentinel test 地址
|
||||||
|
*/
|
||||||
|
String SENTINEL_TEST_ADDR = "172.30.0.58:8858";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* elk dev 地址
|
||||||
|
*/
|
||||||
|
String ELK_DEV_ADDR = "127.0.0.1:9000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* elk prod 地址
|
||||||
|
*/
|
||||||
|
String ELK_PROD_ADDR = "172.30.0.58:9000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* elk test 地址
|
||||||
|
*/
|
||||||
|
String ELK_TEST_ADDR = "172.30.0.58:9000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态获取sentinel地址
|
||||||
|
*
|
||||||
|
* @param profile 环境变量
|
||||||
|
* @return addr
|
||||||
|
*/
|
||||||
|
static String sentinelAddr(String profile) {
|
||||||
|
return switch (profile) {
|
||||||
|
case (AppConstant.PROD_CODE) -> SENTINEL_PROD_ADDR;
|
||||||
|
case (AppConstant.TEST_CODE) -> SENTINEL_TEST_ADDR;
|
||||||
|
default -> SENTINEL_DEV_ADDR;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态获取elk地址
|
||||||
|
*
|
||||||
|
* @param profile 环境变量
|
||||||
|
* @return addr
|
||||||
|
*/
|
||||||
|
static String elkAddr(String profile) {
|
||||||
|
return switch (profile) {
|
||||||
|
case (AppConstant.PROD_CODE) -> ELK_PROD_ADDR;
|
||||||
|
case (AppConstant.TEST_CODE) -> ELK_TEST_ADDR;
|
||||||
|
default -> ELK_DEV_ADDR;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.constant;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户常量
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface TenantConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认密码KEY
|
||||||
|
*/
|
||||||
|
String PASSWORD_KEY = "tenant.default.password";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认账号额度KEY
|
||||||
|
*/
|
||||||
|
String ACCOUNT_NUMBER_KEY = "tenant.default.accountNumber";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认菜单集合KEY
|
||||||
|
*/
|
||||||
|
String ACCOUNT_MENU_CODE_KEY = "tenant.default.menuCode";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认密码
|
||||||
|
*/
|
||||||
|
String DEFAULT_PASSWORD = "123456";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户授权码默认16位密钥
|
||||||
|
*/
|
||||||
|
String DES_KEY = "0000000000000000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认账号额度
|
||||||
|
*/
|
||||||
|
Integer DEFAULT_ACCOUNT_NUMBER = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户默认菜单集合
|
||||||
|
*/
|
||||||
|
List<String> MENU_CODES = Arrays.asList(
|
||||||
|
"desk", "flow", "work", "monitor", "resource", "role", "user", "dept", "dictbiz", "topmenu"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
48
src/main/java/org/springblade/common/enums/DictBizEnum.java
Normal file
48
src/main/java/org/springblade/common/enums/DictBizEnum.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务字典枚举类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum DictBizEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试
|
||||||
|
*/
|
||||||
|
TEST("test"),
|
||||||
|
;
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
}
|
||||||
104
src/main/java/org/springblade/common/enums/DictEnum.java
Normal file
104
src/main/java/org/springblade/common/enums/DictEnum.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统字典枚举类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum DictEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
SEX("sex"),
|
||||||
|
/**
|
||||||
|
* 通知类型
|
||||||
|
*/
|
||||||
|
NOTICE("notice"),
|
||||||
|
/**
|
||||||
|
* 菜单类型
|
||||||
|
*/
|
||||||
|
MENU_CATEGORY("menu_category"),
|
||||||
|
/**
|
||||||
|
* 按钮功能
|
||||||
|
*/
|
||||||
|
BUTTON_FUNC("button_func"),
|
||||||
|
/**
|
||||||
|
* 是否
|
||||||
|
*/
|
||||||
|
YES_NO("yes_no"),
|
||||||
|
/**
|
||||||
|
* 流程类型
|
||||||
|
*/
|
||||||
|
FLOW("flow"),
|
||||||
|
/**
|
||||||
|
* 机构类型
|
||||||
|
*/
|
||||||
|
ORG_CATEGORY("org_category"),
|
||||||
|
/**
|
||||||
|
* 数据权限
|
||||||
|
*/
|
||||||
|
DATA_SCOPE_TYPE("data_scope_type"),
|
||||||
|
/**
|
||||||
|
* 接口权限
|
||||||
|
*/
|
||||||
|
API_SCOPE_TYPE("api_scope_type"),
|
||||||
|
/**
|
||||||
|
* 权限类型
|
||||||
|
*/
|
||||||
|
SCOPE_CATEGORY("scope_category"),
|
||||||
|
/**
|
||||||
|
* 对象存储类型
|
||||||
|
*/
|
||||||
|
OSS("oss"),
|
||||||
|
/**
|
||||||
|
* 短信服务类型
|
||||||
|
*/
|
||||||
|
SMS("sms"),
|
||||||
|
/**
|
||||||
|
* 岗位类型
|
||||||
|
*/
|
||||||
|
POST_CATEGORY("post_category"),
|
||||||
|
/**
|
||||||
|
* 行政区划
|
||||||
|
*/
|
||||||
|
REGION("region"),
|
||||||
|
/**
|
||||||
|
* 用户平台
|
||||||
|
*/
|
||||||
|
USER_TYPE("user_type"),
|
||||||
|
;
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springblade.common.event;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.launch.server.ServerInfo;
|
||||||
|
import org.springblade.core.log.constant.EventConstant;
|
||||||
|
import org.springblade.core.log.event.ApiLogEvent;
|
||||||
|
import org.springblade.core.log.model.LogApi;
|
||||||
|
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||||
|
import org.springblade.modules.system.service.ILogService;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步监听日志事件
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiLogListener {
|
||||||
|
|
||||||
|
private final ILogService logService;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private final BladeProperties bladeProperties;
|
||||||
|
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Order
|
||||||
|
@EventListener(ApiLogEvent.class)
|
||||||
|
public void saveApiLog(ApiLogEvent event) {
|
||||||
|
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||||
|
LogApi logApi = (LogApi) source.get(EventConstant.EVENT_LOG);
|
||||||
|
LogAbstractUtil.addOtherInfoToLog(logApi, bladeProperties, serverInfo);
|
||||||
|
logService.saveApiLog(logApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.event;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.launch.server.ServerInfo;
|
||||||
|
import org.springblade.core.log.constant.EventConstant;
|
||||||
|
import org.springblade.core.log.event.ErrorLogEvent;
|
||||||
|
import org.springblade.core.log.model.LogError;
|
||||||
|
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||||
|
import org.springblade.modules.system.service.ILogService;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步监听错误日志事件
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ErrorLogListener {
|
||||||
|
|
||||||
|
private final ILogService logService;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private final BladeProperties bladeProperties;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Order
|
||||||
|
@EventListener(ErrorLogEvent.class)
|
||||||
|
public void saveErrorLog(ErrorLogEvent event) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||||
|
LogError logError = (LogError) source.get(EventConstant.EVENT_LOG);
|
||||||
|
LogAbstractUtil.addOtherInfoToLog(logError, bladeProperties, serverInfo);
|
||||||
|
logService.saveErrorLog(logError);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 可以根据需要进行更多的异常处理,例如发送警报等
|
||||||
|
log.error("保存错误日志时发生异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.event;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.launch.server.ServerInfo;
|
||||||
|
import org.springblade.core.log.constant.EventConstant;
|
||||||
|
import org.springblade.core.log.event.UsualLogEvent;
|
||||||
|
import org.springblade.core.log.model.LogUsual;
|
||||||
|
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||||
|
import org.springblade.modules.system.service.ILogService;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步监听日志事件
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UsualLogListener {
|
||||||
|
|
||||||
|
private final ILogService logService;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private final BladeProperties bladeProperties;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Order
|
||||||
|
@EventListener(UsualLogEvent.class)
|
||||||
|
public void saveUsualLog(UsualLogEvent event) {
|
||||||
|
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||||
|
LogUsual logUsual = (LogUsual) source.get(EventConstant.EVENT_LOG);
|
||||||
|
LogAbstractUtil.addOtherInfoToLog(logUsual, bladeProperties, serverInfo);
|
||||||
|
logService.saveUsualLog(logUsual);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.filter;
|
||||||
|
|
||||||
|
import jakarta.servlet.*;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 演示过滤器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class PreviewFilter implements Filter {
|
||||||
|
|
||||||
|
private static final List<String> KEYS = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
KEYS.add("notice");
|
||||||
|
KEYS.add("process");
|
||||||
|
KEYS.add("work");
|
||||||
|
KEYS.add("token");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||||
|
|
||||||
|
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||||
|
String path = httpServletRequest.getServletPath();
|
||||||
|
String method = httpServletRequest.getMethod();
|
||||||
|
|
||||||
|
String get = "GET";
|
||||||
|
if (method.equals(get) || KEYS.stream().anyMatch(path::contains)) {
|
||||||
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("演示环境暂时无法操作!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package org.springblade.common.handler;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.secure.BladeUser;
|
||||||
|
import org.springblade.core.secure.handler.IPermissionHandler;
|
||||||
|
import org.springblade.core.secure.provider.PermissionMenu;
|
||||||
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||||
|
import static org.springblade.core.secure.constant.PermissionConstant.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认授权校验类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||||
|
//@Master
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladePermissionHandler implements IPermissionHandler {
|
||||||
|
|
||||||
|
private static final String SCOPE_CACHE_ROLE = "apiScope:role:";
|
||||||
|
|
||||||
|
private static final String SCOPE_CACHE_CODE = "apiScope:code:";
|
||||||
|
|
||||||
|
private static final String SCOPE_CACHE_MENU = "apiScope:menu:";
|
||||||
|
|
||||||
|
private static final String SCOPE_CACHE_ALL_MENU = "apiScope:allMenu:permission";
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean permissionAll() {
|
||||||
|
HttpServletRequest request = WebUtil.getRequest();
|
||||||
|
BladeUser user = AuthUtil.getUser();
|
||||||
|
if (request == null || user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String uri = request.getRequestURI();
|
||||||
|
List<String> paths = permissionPath(user.getRoleId());
|
||||||
|
if (paths.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return paths.stream().anyMatch(uri::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String permission) {
|
||||||
|
HttpServletRequest request = WebUtil.getRequest();
|
||||||
|
BladeUser user = AuthUtil.getUser();
|
||||||
|
if (request == null || user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<String> codes = permissionCode(permission, user.getRoleId());
|
||||||
|
return !codes.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMenu(String permission) {
|
||||||
|
HttpServletRequest request = WebUtil.getRequest();
|
||||||
|
BladeUser user = AuthUtil.getUser();
|
||||||
|
if (request == null || user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (AuthUtil.isAdministrator()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
List<String> codes = permissionMenu(permission, user.getRoleId());
|
||||||
|
return !codes.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取接口权限地址
|
||||||
|
*
|
||||||
|
* @param roleId 角色id
|
||||||
|
* @return permissions
|
||||||
|
*/
|
||||||
|
private List<String> permissionPath(String roleId) {
|
||||||
|
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_ROLE, roleId, List.class, Boolean.FALSE);
|
||||||
|
if (permissions == null) {
|
||||||
|
List<Long> roleIds = Func.toLongList(roleId);
|
||||||
|
permissions = jdbcTemplate.queryForList(permissionAllStatement(roleIds.size()), String.class, roleIds.toArray());
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_ROLE, roleId, permissions, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取接口权限信息
|
||||||
|
*
|
||||||
|
* @param permission 权限编号
|
||||||
|
* @param roleId 角色id
|
||||||
|
* @return permissions
|
||||||
|
*/
|
||||||
|
private List<String> permissionCode(String permission, String roleId) {
|
||||||
|
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CODE, permission + StringPool.COLON + roleId, List.class, Boolean.FALSE);
|
||||||
|
if (permissions == null) {
|
||||||
|
List<Object> args = new ArrayList<>(Collections.singletonList(permission));
|
||||||
|
List<Long> roleIds = Func.toLongList(roleId);
|
||||||
|
args.addAll(roleIds);
|
||||||
|
permissions = jdbcTemplate.queryForList(permissionCodeStatement(roleIds.size()), String.class, args.toArray());
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CODE, permission + StringPool.COLON + roleId, permissions, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单权限信息
|
||||||
|
*
|
||||||
|
* @param permission 菜单编号
|
||||||
|
* @param roleId 角色id
|
||||||
|
* @return permissions
|
||||||
|
*/
|
||||||
|
private List<String> permissionMenu(String permission, String roleId) {
|
||||||
|
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_MENU, permission + StringPool.COLON + roleId, List.class, Boolean.FALSE);
|
||||||
|
if (permissions == null) {
|
||||||
|
// 获取所有菜单
|
||||||
|
List<PermissionMenu> allMenus = permissionAllMenu();
|
||||||
|
// 获取角色菜单
|
||||||
|
List<Long> roleIds = Func.toLongList(roleId);
|
||||||
|
List<PermissionMenu> roleIdMenus = jdbcTemplate.query(permissionMenuStatement(roleIds.size()), new BeanPropertyRowMapper<>(PermissionMenu.class), roleIds.toArray());
|
||||||
|
// 反向递归角色菜单所有父级
|
||||||
|
List<PermissionMenu> routes = new LinkedList<>(roleIdMenus);
|
||||||
|
roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
|
||||||
|
// 获取匹配的菜单权限值
|
||||||
|
permissions = routes.stream().map(PermissionMenu::getCode).filter(code -> Func.equals(code, permission)).collect(Collectors.toList());
|
||||||
|
// 写入缓存值
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_MENU, permission + StringPool.COLON + roleId, permissions, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有菜单权限信息
|
||||||
|
*/
|
||||||
|
private List<PermissionMenu> permissionAllMenu() {
|
||||||
|
List<PermissionMenu> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_ALL_MENU, StringPool.EMPTY, List.class, Boolean.FALSE);
|
||||||
|
if (permissions == null) {
|
||||||
|
permissions = jdbcTemplate.query(permissionAllMenuStatement(), new BeanPropertyRowMapper<>(PermissionMenu.class));
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_ALL_MENU, StringPool.EMPTY, permissions, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归获取菜单父级
|
||||||
|
*
|
||||||
|
* @param allMenus 所有菜单合集
|
||||||
|
* @param routes 角色分配的菜单合集
|
||||||
|
* @param roleMenu 当前菜单
|
||||||
|
*/
|
||||||
|
private void recursion(List<PermissionMenu> allMenus, List<PermissionMenu> routes, PermissionMenu roleMenu) {
|
||||||
|
Optional<PermissionMenu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
|
||||||
|
if (menu.isPresent() && !routes.contains(menu.get())) {
|
||||||
|
routes.add(menu.get());
|
||||||
|
recursion(allMenus, routes, menu.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.handler;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.core.datarecord.annotation.DataRecord;
|
||||||
|
import org.springblade.core.datarecord.annotation.DataRecordLevel;
|
||||||
|
import org.springblade.core.datarecord.model.DataRecordInfo;
|
||||||
|
import org.springblade.core.datarecord.processor.DataRecordHandler;
|
||||||
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import static org.springblade.core.datarecord.constant.DataRecordConstant.RECORD_INSERT_SQL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志数据审计处理器
|
||||||
|
* <p>
|
||||||
|
* 将数据审计输出到日志
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||||
|
//@Master
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BladeRecordHandler implements DataRecordHandler {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(DataRecordInfo recordInfo, DataRecord dataRecord) {
|
||||||
|
// 获取格式化的记录信息
|
||||||
|
String recordMessage = formatRecordInfo(recordInfo);
|
||||||
|
// 获取数据审计级别
|
||||||
|
DataRecordLevel level = dataRecord.level();
|
||||||
|
|
||||||
|
// 数据审计入库处理
|
||||||
|
int affectedRows = saveRecordData(recordInfo, level.name(), recordMessage);
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
// 根据配置的日志级别输出
|
||||||
|
switch (level) {
|
||||||
|
case DEBUG:
|
||||||
|
log.debug("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||||
|
break;
|
||||||
|
case INFO:
|
||||||
|
log.info("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||||
|
break;
|
||||||
|
case WARN:
|
||||||
|
log.warn("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||||
|
break;
|
||||||
|
case ERROR:
|
||||||
|
log.error("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果入库失败,记录错误日志
|
||||||
|
log.error("数据审计[{}] 保存入库失败", recordInfo.getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化记录信息
|
||||||
|
*
|
||||||
|
* @param recordInfo 记录信息
|
||||||
|
* @return 格式化后的字符串
|
||||||
|
*/
|
||||||
|
private String formatRecordInfo(DataRecordInfo recordInfo) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
// 添加模块信息
|
||||||
|
sb.append("\n").append("[表名]: ").append(recordInfo.getTableName()).append("\n");
|
||||||
|
sb.append("[操作]: ").append(recordInfo.getOperation()).append("\n");
|
||||||
|
if (recordInfo.getPrimaryKeyValue() != null) {
|
||||||
|
sb.append("[主键]: ").append(recordInfo.getPrimaryKeyValue()).append("\n");
|
||||||
|
}
|
||||||
|
// 添加用户信息
|
||||||
|
if (recordInfo.getUserName() != null) {
|
||||||
|
sb.append("[用户]: ").append(recordInfo.getUserName()).append("\n");
|
||||||
|
}
|
||||||
|
// 添加IP信息
|
||||||
|
if (recordInfo.getRemoteIp() != null) {
|
||||||
|
sb.append("[IP]: ").append(recordInfo.getRemoteIp()).append("\n");
|
||||||
|
}
|
||||||
|
// 添加请求URI
|
||||||
|
if (recordInfo.getRequestUri() != null) {
|
||||||
|
sb.append("[URI]: ").append(recordInfo.getRequestUri()).append("\n");
|
||||||
|
}
|
||||||
|
if (recordInfo.getChangedFields() != null && !recordInfo.getChangedFields().isEmpty()) {
|
||||||
|
sb.append("[变更]: ").append(recordInfo.getChangedFields()).append("\n");
|
||||||
|
}
|
||||||
|
if (recordInfo.getCost() != null) {
|
||||||
|
sb.append("[耗时]: ").append(recordInfo.getCost()).append("ms").append("\n");
|
||||||
|
}
|
||||||
|
// 如果需要详细信息,添加变更详情
|
||||||
|
if (recordInfo.getChangeData() != null && !recordInfo.getChangeData().isEmpty()) {
|
||||||
|
sb.append("[详情]: {");
|
||||||
|
recordInfo.getChangeData().forEach((field, change) -> sb.append(change.getChangeDescription()).append(", "));
|
||||||
|
if (sb.toString().endsWith(", ")) {
|
||||||
|
sb.setLength(sb.length() - 2);
|
||||||
|
}
|
||||||
|
sb.append("}");
|
||||||
|
}
|
||||||
|
return sb.append("\n").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用 JdbcTemplate 保存数据审计记录
|
||||||
|
*
|
||||||
|
* @param recordInfo 记录信息
|
||||||
|
* @param recordLevel 记录级别
|
||||||
|
* @param recordMessage 记录消息
|
||||||
|
* @return 影响的行数
|
||||||
|
*/
|
||||||
|
private int saveRecordData(DataRecordInfo recordInfo, String recordLevel, String recordMessage) {
|
||||||
|
return jdbcTemplate.update(RECORD_INSERT_SQL,
|
||||||
|
// 主键
|
||||||
|
recordInfo.getRecordId(),
|
||||||
|
// 基础服务信息
|
||||||
|
recordInfo.getServiceId(),
|
||||||
|
recordInfo.getServerHost(),
|
||||||
|
recordInfo.getServerIp(),
|
||||||
|
recordInfo.getEnv(),
|
||||||
|
// 审计级别
|
||||||
|
recordLevel,
|
||||||
|
// 请求信息
|
||||||
|
recordInfo.getMethod(),
|
||||||
|
recordInfo.getRequestUri(),
|
||||||
|
recordInfo.getUserAgent(),
|
||||||
|
recordInfo.getRemoteIp(),
|
||||||
|
// 操作信息
|
||||||
|
recordInfo.getOperation(),
|
||||||
|
recordInfo.getTableName(),
|
||||||
|
// 数据转换:将 Map 转换为 JSON 字符串
|
||||||
|
JsonUtil.toJson(recordInfo.getOldData()),
|
||||||
|
JsonUtil.toJson(recordInfo.getNewData()),
|
||||||
|
// 审计消息
|
||||||
|
recordMessage,
|
||||||
|
// 审计结果
|
||||||
|
recordInfo.getRecordResult(),
|
||||||
|
// 记录耗时
|
||||||
|
Func.toStr(recordInfo.getCost()),
|
||||||
|
// 记录时间
|
||||||
|
recordInfo.getRecordTime(),
|
||||||
|
// 记录人
|
||||||
|
Func.toLong(recordInfo.getUserId()),
|
||||||
|
// 业务状态:默认为正常状态
|
||||||
|
BladeConstant.DB_STATUS_NORMAL,
|
||||||
|
// 逻辑删除状态:默认为未删除状态
|
||||||
|
BladeConstant.DB_NOT_DELETED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.handler;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.datascope.constant.DataScopeConstant;
|
||||||
|
import org.springblade.core.datascope.handler.ScopeModelHandler;
|
||||||
|
import org.springblade.core.datascope.model.DataScopeModel;
|
||||||
|
import org.springblade.core.tool.utils.CollectionUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladeScopeModelHandler
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||||
|
//@Master
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BladeScopeModelHandler implements ScopeModelHandler {
|
||||||
|
|
||||||
|
private static final String SCOPE_CACHE_CODE = "dataScope:code:";
|
||||||
|
private static final String SCOPE_CACHE_CLASS = "dataScope:class:";
|
||||||
|
private static final String DEPT_CACHE_ANCESTORS = "dept:ancestors:";
|
||||||
|
private static final DataScopeModel SEARCHED_DATA_SCOPE_MODEL = new DataScopeModel(Boolean.TRUE);
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据权限
|
||||||
|
*
|
||||||
|
* @param mapperId 数据权限mapperId
|
||||||
|
* @param roleId 用户角色集合
|
||||||
|
* @return DataScopeModel
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DataScopeModel getDataScopeByMapper(String mapperId, String roleId) {
|
||||||
|
List<Object> args = new ArrayList<>(Collections.singletonList(mapperId));
|
||||||
|
List<Long> roleIds = Func.toLongList(roleId);
|
||||||
|
args.addAll(roleIds);
|
||||||
|
// 增加searched字段防止未配置的参数重复读库导致缓存击穿
|
||||||
|
// 后续若有新增配置则会清空缓存重新加载
|
||||||
|
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, DataScopeModel.class, Boolean.FALSE);
|
||||||
|
if (dataScope == null || !dataScope.getSearched()) {
|
||||||
|
List<DataScopeModel> list = jdbcTemplate.query(DataScopeConstant.dataByMapper(roleIds.size()), new BeanPropertyRowMapper<>(DataScopeModel.class), args.toArray());
|
||||||
|
if (CollectionUtil.isNotEmpty(list)) {
|
||||||
|
dataScope = list.iterator().next();
|
||||||
|
dataScope.setSearched(Boolean.TRUE);
|
||||||
|
} else {
|
||||||
|
dataScope = SEARCHED_DATA_SCOPE_MODEL;
|
||||||
|
}
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, dataScope, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据权限
|
||||||
|
*
|
||||||
|
* @param code 数据权限资源编号
|
||||||
|
* @return DataScopeModel
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DataScopeModel getDataScopeByCode(String code) {
|
||||||
|
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CODE, code, DataScopeModel.class, Boolean.FALSE);
|
||||||
|
// 增加searched字段防止未配置的参数重复读库导致缓存击穿
|
||||||
|
// 后续若有新增配置则会清空缓存重新加载
|
||||||
|
if (dataScope == null || !dataScope.getSearched()) {
|
||||||
|
List<DataScopeModel> list = jdbcTemplate.query(DataScopeConstant.DATA_BY_CODE, new BeanPropertyRowMapper<>(DataScopeModel.class), code);
|
||||||
|
if (CollectionUtil.isNotEmpty(list)) {
|
||||||
|
dataScope = list.iterator().next();
|
||||||
|
dataScope.setSearched(Boolean.TRUE);
|
||||||
|
} else {
|
||||||
|
dataScope = SEARCHED_DATA_SCOPE_MODEL;
|
||||||
|
}
|
||||||
|
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CODE, code, dataScope, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门子级
|
||||||
|
*
|
||||||
|
* @param deptId 部门id
|
||||||
|
* @return deptIds
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Long> getDeptAncestors(Long deptId) {
|
||||||
|
List ancestors = CacheUtil.get(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, List.class);
|
||||||
|
if (CollectionUtil.isEmpty(ancestors)) {
|
||||||
|
ancestors = jdbcTemplate.queryForList(DataScopeConstant.DATA_BY_DEPT, Long.class, deptId);
|
||||||
|
CacheUtil.put(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, ancestors);
|
||||||
|
}
|
||||||
|
return ancestors;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.launch;
|
||||||
|
|
||||||
|
import org.springblade.common.constant.LauncherConstant;
|
||||||
|
import org.springblade.core.auto.service.AutoService;
|
||||||
|
import org.springblade.core.launch.service.LauncherService;
|
||||||
|
import org.springblade.core.launch.utils.PropsUtil;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动参数拓展
|
||||||
|
*
|
||||||
|
* @author smallchil
|
||||||
|
*/
|
||||||
|
@AutoService(LauncherService.class)
|
||||||
|
public class LauncherServiceImpl implements LauncherService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile));
|
||||||
|
PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
|
||||||
|
// 开启elk日志
|
||||||
|
//PropsUtil.setProperty(props, "blade.log.elk.destination", LauncherConstant.elkAddr(profile));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/main/java/org/springblade/common/utils/CommonUtil.java
Normal file
35
src/main/java/org/springblade/common/utils/CommonUtil.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class CommonUtil {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package org.springblade.modules.auth.config;
|
||||||
|
|
||||||
|
import org.springblade.core.jwt.props.JwtProperties;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.oauth2.config.OAuth2AutoConfiguration;
|
||||||
|
import org.springblade.core.oauth2.handler.AuthorizationHandler;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.handler.TokenHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.tenant.BladeTenantProperties;
|
||||||
|
import org.springblade.modules.auth.handler.BladeAuthorizationHandler;
|
||||||
|
import org.springblade.modules.auth.handler.BladeLockHandler;
|
||||||
|
import org.springblade.modules.auth.handler.BladePasswordHandler;
|
||||||
|
import org.springblade.modules.auth.handler.BladeTokenHandler;
|
||||||
|
import org.springblade.modules.auth.service.BladeClientDetailService;
|
||||||
|
import org.springblade.modules.auth.service.BladeUserDetailService;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladeAuthConfiguration
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AutoConfigureBefore(OAuth2AutoConfiguration.class)
|
||||||
|
public class BladeAuthConfiguration {
|
||||||
|
@Bean
|
||||||
|
public AuthorizationHandler authorizationHandler(BladeProperties bladeProperties,
|
||||||
|
BladeTenantProperties tenantProperties,
|
||||||
|
OAuth2Properties oAuth2Properties,
|
||||||
|
BladeLockHandler lockHandler) {
|
||||||
|
return new BladeAuthorizationHandler(bladeProperties, tenantProperties, oAuth2Properties, lockHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BladeLockHandler lockHandler(BladeRedis bladeRedis) {
|
||||||
|
return new BladeLockHandler(bladeRedis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordHandler passwordHandler(OAuth2Properties properties) {
|
||||||
|
return new BladePasswordHandler(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TokenHandler tokenHandler(JwtProperties jwtProperties) {
|
||||||
|
return new BladeTokenHandler(jwtProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OAuth2ClientService oAuth2ClientService(JdbcTemplate jdbcTemplate) {
|
||||||
|
return new BladeClientDetailService(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OAuth2UserService oAuth2UserService(IUserService userService) {
|
||||||
|
return new BladeUserDetailService(userService);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.springblade.modules.auth.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AuthorizationConstant
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface BladeAuthConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启注册参数key
|
||||||
|
*/
|
||||||
|
String REGISTER_USER_VALUE = "account.registerUser";
|
||||||
|
/**
|
||||||
|
* 账号锁定错误次数参数key
|
||||||
|
*/
|
||||||
|
String FAIL_COUNT_VALUE = "account.failCount";
|
||||||
|
/**
|
||||||
|
* 账号锁定默认错误次数
|
||||||
|
*/
|
||||||
|
Integer FAIL_COUNT = 5;
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.endpoint;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.sms.model.SmsCode;
|
||||||
|
import org.springblade.core.sms.model.SmsData;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.SM2Util;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.modules.resource.builder.SmsBuilder;
|
||||||
|
import org.springblade.modules.resource.utils.SmsUtil;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springblade.core.oauth2.constant.OAuth2TokenConstant.USER_PHONE_NOT_FOUND;
|
||||||
|
import static org.springblade.modules.resource.utils.SmsUtil.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oauth2SmsEndpoint
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "用户短信认证", description = "4 - OAuth2短信认证端点")
|
||||||
|
public class Oauth2SmsEndpoint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信服务构建类
|
||||||
|
*/
|
||||||
|
private final SmsBuilder smsBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务类
|
||||||
|
*/
|
||||||
|
private final OAuth2UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth2配置类
|
||||||
|
*/
|
||||||
|
private final OAuth2Properties properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码发送
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @param phone 手机号
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/oauth/sms/send-validate")
|
||||||
|
public R sendValidate(@RequestParam String tenantId, @RequestParam String phone) {
|
||||||
|
// 校验手机加密认证,防止恶意发送验证码
|
||||||
|
String decryptedPhone = SM2Util.decrypt(phone, properties.getPublicKey(), properties.getPrivateKey());
|
||||||
|
if (StringUtil.isBlank(decryptedPhone)) {
|
||||||
|
return R.fail(USER_PHONE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
// 校验手机是否已注册,防止恶意发送验证码
|
||||||
|
OAuth2Request request = OAuth2Request.create();
|
||||||
|
request.setTenantId(tenantId);
|
||||||
|
OAuth2User oAuth2User = userService.loadByPhone(decryptedPhone, request);
|
||||||
|
if (oAuth2User == null) {
|
||||||
|
return R.fail(USER_PHONE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
// 用户存在则发送验证码
|
||||||
|
Map<String, String> params = SmsUtil.getValidateParams();
|
||||||
|
SmsCode smsCode = smsBuilder.template(tenantId, StringPool.EMPTY).sendValidate(new SmsData(params).setKey(PARAM_KEY), decryptedPhone);
|
||||||
|
return smsCode.isSuccess() ? R.data(smsCode, SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
|
import org.springblade.core.oauth2.constant.OAuth2TokenConstant;
|
||||||
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
|
import org.springblade.core.oauth2.granter.PasswordTokenGranter;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CaptchaTokenGranter
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class CaptchaTokenGranter extends PasswordTokenGranter {
|
||||||
|
|
||||||
|
private final BladeRedis bladeRedis;
|
||||||
|
|
||||||
|
public CaptchaTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, BladeRedis bladeRedis) {
|
||||||
|
super(clientService, userService, passwordHandler);
|
||||||
|
this.bladeRedis = bladeRedis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String type() {
|
||||||
|
return CAPTCHA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User user(OAuth2Request request) {
|
||||||
|
// 获取验证码信息
|
||||||
|
String key = request.getCaptchaKey();
|
||||||
|
String code = request.getCaptchaCode();
|
||||||
|
// 获取验证码
|
||||||
|
String redisCode = bladeRedis.getAndDel(OAuth2TokenConstant.CAPTCHA_CACHE_KEY + key);
|
||||||
|
// 判断验证码
|
||||||
|
if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) {
|
||||||
|
throw new UserInvalidException(OAuth2TokenConstant.CAPTCHA_NOT_CORRECT);
|
||||||
|
}
|
||||||
|
return super.user(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springblade.common.cache.ParamCache;
|
||||||
|
import org.springblade.core.launch.constant.TokenConstant;
|
||||||
|
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||||
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
|
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Token;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2Client;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.SM2Util;
|
||||||
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
|
import org.springblade.modules.system.pojo.entity.User;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.REGISTER_USER_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RegisterTokenGranter
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RegisterTokenGranter extends AbstractTokenGranter {
|
||||||
|
|
||||||
|
private final IUserService service;
|
||||||
|
private final OAuth2Properties properties;
|
||||||
|
|
||||||
|
public RegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, OAuth2Properties properties) {
|
||||||
|
super(clientService, userService, passwordHandler);
|
||||||
|
this.service = service;
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String type() {
|
||||||
|
return REGISTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User user(OAuth2Request request) {
|
||||||
|
// 校验注册功能是否开启
|
||||||
|
Boolean registerOpen = Func.toBoolean(ParamCache.getValue(REGISTER_USER_VALUE), false);
|
||||||
|
if (!registerOpen) {
|
||||||
|
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户注册信息
|
||||||
|
User user = new User();
|
||||||
|
user.setUserType(UserType.of(request.getUserType()).getCategory());
|
||||||
|
user.setTenantId(request.getTenantId());
|
||||||
|
user.setAccount(request.getUsername());
|
||||||
|
user.setPassword(SM2Util.decrypt(request.getPassword(), properties.getPublicKey(), properties.getPrivateKey()));
|
||||||
|
user.setName(request.getName());
|
||||||
|
user.setRealName(request.getName());
|
||||||
|
user.setPhone(request.getPhone());
|
||||||
|
user.setEmail(request.getEmail());
|
||||||
|
|
||||||
|
if (UserType.KIOSK.getCategory()!=user.getUserType()){
|
||||||
|
// 校验用户格式
|
||||||
|
validateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行用户注册
|
||||||
|
if (service.registerUser(user)) {
|
||||||
|
// 构建oauth2所需用户信息
|
||||||
|
return convertOAuth2UserDetail(user, client(request));
|
||||||
|
}
|
||||||
|
throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2Token token(OAuth2User user, OAuth2Request request) {
|
||||||
|
// 移除注册后返回的令牌与刷新令牌,防止外部攻击采用注册接口获取令牌并调用低权接口
|
||||||
|
// 注意:
|
||||||
|
// 1. 框架已默认开启严格模式,blade.secure.strict-token=true,不移除令牌则不受影响,注册令牌会被框架校验并拒绝
|
||||||
|
// 2. 若自行关闭严格模式,blade.secure.strict-token=false,必须将令牌移除,否则注册获取令牌后可调用低权接口
|
||||||
|
OAuth2Token token = super.token(user, request);
|
||||||
|
token.getArgs().remove(TokenConstant.ACCESS_TOKEN);
|
||||||
|
token.getArgs().remove(TokenConstant.REFRESH_TOKEN);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateUser(User user) {
|
||||||
|
Predicate<String> isNameValid = name -> name.matches("^([\\u4e00-\\u9fa5]{2,20}|[a-zA-Z]{2,10})$");
|
||||||
|
Predicate<String> isUsernameValid = username -> username.matches("^(?=.*[a-zA-Z])[a-zA-Z0-9_\\-@]{3,20}$");
|
||||||
|
Predicate<String> isPasswordValid = password -> password.matches("^(?=.*[0-9])(?=.*[a-zA-Z])[\\w@-]{6,20}$");
|
||||||
|
Predicate<String> isPhoneValid = phone -> phone.matches("^1[3-9]\\d{9}$");
|
||||||
|
Predicate<String> isEmailValid = email -> email.matches("^[A-Za-z0-9+_.-]+@(.+)$");
|
||||||
|
if (!isNameValid.test(user.getName())) {
|
||||||
|
throw new UserInvalidException("用户姓名长度必须在2-10之间,且仅能设置纯中文或纯英文");
|
||||||
|
}
|
||||||
|
if (!isUsernameValid.test(user.getAccount())) {
|
||||||
|
throw new UserInvalidException("用户账号长度必须在3-20之间,且需要包含英文,可额外携带数字、下划线、横杠、@");
|
||||||
|
}
|
||||||
|
if (!isPasswordValid.test(user.getPassword())) {
|
||||||
|
throw new UserInvalidException("用户密码长度必须在6-20之间,且需要包含英文与数字,可额外携带下划线、横杠、@");
|
||||||
|
}
|
||||||
|
if (!isPhoneValid.test(user.getPhone())) {
|
||||||
|
throw new UserInvalidException("手机号格式不正确");
|
||||||
|
}
|
||||||
|
if (!isEmailValid.test(user.getEmail())) {
|
||||||
|
throw new UserInvalidException("邮箱格式不正确");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private OAuth2UserDetail convertOAuth2UserDetail(User user, OAuth2Client client) {
|
||||||
|
OAuth2UserDetail userDetail = new OAuth2UserDetail();
|
||||||
|
userDetail.setUserId(String.valueOf(user.getId()));
|
||||||
|
userDetail.setTenantId(user.getTenantId());
|
||||||
|
userDetail.setName(user.getName());
|
||||||
|
userDetail.setRealName(user.getName());
|
||||||
|
userDetail.setAccount(user.getAccount());
|
||||||
|
userDetail.setPassword(user.getPassword());
|
||||||
|
userDetail.setPhone(user.getPhone());
|
||||||
|
userDetail.setEmail(user.getEmail());
|
||||||
|
userDetail.setAuthorities(Collections.singletonList(REGISTER));
|
||||||
|
userDetail.setClient(client);
|
||||||
|
return userDetail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springblade.core.oauth2.constant.OAuth2TokenConstant;
|
||||||
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
|
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.sms.model.SmsCode;
|
||||||
|
import org.springblade.core.tool.utils.SM2Util;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
|
import org.springblade.modules.resource.builder.SmsBuilder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmsTokenGranter
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SmsTokenGranter extends AbstractTokenGranter {
|
||||||
|
|
||||||
|
private final OAuth2UserService userService;
|
||||||
|
private final SmsBuilder smsBuilder;
|
||||||
|
private final OAuth2Properties properties;
|
||||||
|
|
||||||
|
public SmsTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, SmsBuilder smsBuilder, OAuth2Properties properties) {
|
||||||
|
super(clientService, userService, passwordHandler);
|
||||||
|
this.userService = userService;
|
||||||
|
this.smsBuilder = smsBuilder;
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String type() {
|
||||||
|
return SMS_CODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User user(OAuth2Request request) {
|
||||||
|
// 获取基础信息
|
||||||
|
String tenantId = request.getTenantId();
|
||||||
|
SmsCode smsCode = buildSmsCode();
|
||||||
|
// 校验手机加密认证
|
||||||
|
String decryptedPhone = SM2Util.decrypt(smsCode.getPhone(), properties.getPublicKey(), properties.getPrivateKey());
|
||||||
|
if (StringUtil.isBlank(decryptedPhone)) {
|
||||||
|
throw new UserInvalidException(OAuth2TokenConstant.USER_PHONE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
// 获取短信验证信息
|
||||||
|
boolean temp = smsBuilder.template(tenantId, StringPool.EMPTY).validateMessage(smsCode.setPhone(decryptedPhone));
|
||||||
|
if (!temp) {
|
||||||
|
throw new UserInvalidException(OAuth2TokenConstant.CAPTCHA_NOT_CORRECT);
|
||||||
|
}
|
||||||
|
// 获取用户信息
|
||||||
|
OAuth2User user = userService.loadByPhone(decryptedPhone, request);
|
||||||
|
// 校验用户信息
|
||||||
|
if (!userService.validateUser(user)) {
|
||||||
|
throw new UserInvalidException(OAuth2TokenConstant.TOKEN_NOT_CORRECT);
|
||||||
|
}
|
||||||
|
// 设置客户端信息
|
||||||
|
user.setClient(client(request));
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SmsCode buildSmsCode() {
|
||||||
|
HttpServletRequest request = WebUtil.getRequest();
|
||||||
|
return new SmsCode().setId(request.getParameter("id"))
|
||||||
|
.setPhone(request.getParameter("phone"))
|
||||||
|
.setValue(request.getParameter("value"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
|
import me.zhyd.oauth.model.AuthCallback;
|
||||||
|
import me.zhyd.oauth.model.AuthResponse;
|
||||||
|
import me.zhyd.oauth.model.AuthUser;
|
||||||
|
import me.zhyd.oauth.request.AuthRequest;
|
||||||
|
import org.springblade.core.oauth2.exception.OAuth2ErrorCode;
|
||||||
|
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.oauth2.utils.OAuth2ExceptionUtil;
|
||||||
|
import org.springblade.core.social.props.SocialProperties;
|
||||||
|
import org.springblade.core.social.utils.SocialUtil;
|
||||||
|
import org.springblade.core.tool.utils.BeanUtil;
|
||||||
|
import org.springblade.modules.auth.utils.TokenUtil;
|
||||||
|
import org.springblade.modules.system.pojo.entity.UserInfo;
|
||||||
|
import org.springblade.modules.system.pojo.entity.UserOauth;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SocialTokenGranter
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SocialTokenGranter extends AbstractTokenGranter {
|
||||||
|
|
||||||
|
|
||||||
|
private static final Integer AUTH_SUCCESS_CODE = 2000;
|
||||||
|
|
||||||
|
private final IUserService userService;
|
||||||
|
private final SocialProperties socialProperties;
|
||||||
|
|
||||||
|
|
||||||
|
public SocialTokenGranter(OAuth2ClientService clientService, OAuth2UserService oAuth2UserService, PasswordHandler passwordHandler, IUserService userService, SocialProperties socialProperties) {
|
||||||
|
super(clientService, oAuth2UserService, passwordHandler);
|
||||||
|
this.userService = userService;
|
||||||
|
this.socialProperties = socialProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String type() {
|
||||||
|
return SOCIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User user(OAuth2Request request) {
|
||||||
|
String tenantId = request.getTenantId();
|
||||||
|
// 开放平台来源
|
||||||
|
String sourceParameter = request.getSource();
|
||||||
|
// 匹配是否有别名定义
|
||||||
|
String source = socialProperties.getAlias().getOrDefault(sourceParameter, sourceParameter);
|
||||||
|
// 开放平台授权码
|
||||||
|
String code = request.getCode();
|
||||||
|
// 开放平台状态吗
|
||||||
|
String state = request.getState();
|
||||||
|
|
||||||
|
// 获取开放平台授权数据
|
||||||
|
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||||
|
AuthCallback authCallback = new AuthCallback();
|
||||||
|
authCallback.setCode(code);
|
||||||
|
authCallback.setState(state);
|
||||||
|
AuthResponse<?> authResponse = authRequest.login(authCallback);
|
||||||
|
AuthUser authUser = null;
|
||||||
|
if (authResponse.getCode() == AUTH_SUCCESS_CODE) {
|
||||||
|
authUser = (AuthUser) authResponse.getData();
|
||||||
|
} else {
|
||||||
|
OAuth2ExceptionUtil.throwFromCode(OAuth2ErrorCode.INVALID_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组装数据
|
||||||
|
UserOauth userOauth = Objects.requireNonNull(BeanUtil.copyProperties(authUser, UserOauth.class));
|
||||||
|
userOauth.setSource(authUser.getSource());
|
||||||
|
userOauth.setTenantId(tenantId);
|
||||||
|
userOauth.setUuid(authUser.getUuid());
|
||||||
|
UserInfo userInfo = userService.userInfo(userOauth);
|
||||||
|
|
||||||
|
// 设置Oauth2用户信息
|
||||||
|
OAuth2User user = TokenUtil.convertUser(userInfo, request);
|
||||||
|
// 设置客户端信息
|
||||||
|
user.setClient(client(request));
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.handler;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.common.cache.SysCache;
|
||||||
|
import org.springblade.common.constant.TenantConstant;
|
||||||
|
import org.springblade.core.launch.props.BladeProperties;
|
||||||
|
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||||
|
import org.springblade.core.oauth2.handler.AbstractAuthorizationHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Validation;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.tenant.BladeTenantProperties;
|
||||||
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
|
import org.springblade.core.tool.utils.*;
|
||||||
|
import org.springblade.modules.system.pojo.entity.Tenant;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证处理器
|
||||||
|
* 统一处理认证前校验、认证成功/失败回调等逻辑
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BladeAuthorizationHandler extends AbstractAuthorizationHandler {
|
||||||
|
|
||||||
|
private final BladeProperties bladeProperties;
|
||||||
|
private final BladeTenantProperties tenantProperties;
|
||||||
|
private final OAuth2Properties oAuth2Properties;
|
||||||
|
private final BladeLockHandler lockHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义弱密码列表
|
||||||
|
*/
|
||||||
|
private static final List<String> WEAK_PASSWORDS = List.of("admin", "administrator", "hr", "manager", "boss");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证前校验
|
||||||
|
*
|
||||||
|
* @param request 请求信息
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OAuth2Validation preValidation(OAuth2Request request) {
|
||||||
|
if (request.isPassword() || request.isCaptchaCode()) {
|
||||||
|
// 生产环境弱密码校验
|
||||||
|
if (bladeProperties.isProd() && isWeakPassword(request.getPassword())) {
|
||||||
|
return buildValidationFailure(ExceptionCode.INVALID_USER_PASSWORD);
|
||||||
|
}
|
||||||
|
// 判断账号是否锁定
|
||||||
|
OAuth2Validation accountValidation = lockHandler.validateAccountLock(request.getTenantId(), request.getUsername());
|
||||||
|
if (!accountValidation.isSuccess()) {
|
||||||
|
return accountValidation;
|
||||||
|
}
|
||||||
|
// 判断IP是否锁定
|
||||||
|
OAuth2Validation ipValidation = lockHandler.validateIpLock(request.getTenantId());
|
||||||
|
if (!ipValidation.isSuccess()) {
|
||||||
|
return ipValidation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.preValidation(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证前失败回调
|
||||||
|
*
|
||||||
|
* @param validation 失败信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void preFailure(OAuth2Request request, OAuth2Validation validation) {
|
||||||
|
// 处理认证失败,增加错误次数
|
||||||
|
lockHandler.handleAuthFailure(request.getTenantId(), request.getUsername());
|
||||||
|
|
||||||
|
log.error("用户:{},认证失败,失败原因:{}", request.getUsername(), validation.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证校验
|
||||||
|
*
|
||||||
|
* @param user 用户信息
|
||||||
|
* @param request 请求信息
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OAuth2Validation authValidation(OAuth2User user, OAuth2Request request) {
|
||||||
|
// 密码模式、刷新token模式、验证码模式需要校验租户状态
|
||||||
|
if (request.isPassword() || request.isRefreshToken() || request.isCaptchaCode()) {
|
||||||
|
// 租户校验
|
||||||
|
OAuth2Validation tenantValidation = validateTenant(user.getTenantId());
|
||||||
|
if (!tenantValidation.isSuccess()) {
|
||||||
|
return tenantValidation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.authValidation(user, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证成功回调
|
||||||
|
*
|
||||||
|
* @param user 用户信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void authSuccessful(OAuth2User user, OAuth2Request request) {
|
||||||
|
// 处理认证成功,清空错误次数
|
||||||
|
lockHandler.handleAuthSuccess(user.getTenantId(), user.getAccount());
|
||||||
|
|
||||||
|
log.info("用户:{},认证成功", user.getAccount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证失败回调
|
||||||
|
*
|
||||||
|
* @param user 用户信息
|
||||||
|
* @param validation 失败信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void authFailure(OAuth2User user, OAuth2Request request, OAuth2Validation validation) {
|
||||||
|
// 自定义认证失败回调
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为弱密码
|
||||||
|
*
|
||||||
|
* @param rawPassword 加密密码
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private boolean isWeakPassword(String rawPassword) {
|
||||||
|
// 获取公钥
|
||||||
|
String publicKey = oAuth2Properties.getPublicKey();
|
||||||
|
// 获取私钥
|
||||||
|
String privateKey = oAuth2Properties.getPrivateKey();
|
||||||
|
// 解密密码
|
||||||
|
String decryptPassword = SM2Util.decrypt(rawPassword, publicKey, privateKey);
|
||||||
|
return WEAK_PASSWORDS.stream()
|
||||||
|
.anyMatch(weakPass -> weakPass.equalsIgnoreCase(decryptPassword));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户授权校验
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return OAuth2Validation
|
||||||
|
*/
|
||||||
|
private OAuth2Validation validateTenant(String tenantId) {
|
||||||
|
// 租户校验
|
||||||
|
Tenant tenant = SysCache.getTenant(tenantId);
|
||||||
|
if (tenant == null) {
|
||||||
|
return buildValidationFailure(ExceptionCode.USER_TENANT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
// 租户授权时间校验
|
||||||
|
Date expireTime = tenant.getExpireTime();
|
||||||
|
if (tenantProperties.getLicense()) {
|
||||||
|
String licenseKey = tenant.getLicenseKey();
|
||||||
|
String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY);
|
||||||
|
Tenant license = JsonUtil.parse(decrypt, Tenant.class);
|
||||||
|
if (license == null || !license.getId().equals(tenant.getId())) {
|
||||||
|
return buildValidationFailure(ExceptionCode.UNAUTHORIZED_USER_TENANT);
|
||||||
|
}
|
||||||
|
expireTime = license.getExpireTime();
|
||||||
|
}
|
||||||
|
if (expireTime != null && expireTime.before(DateUtil.now())) {
|
||||||
|
return buildValidationFailure(ExceptionCode.UNAUTHORIZED_USER_TENANT);
|
||||||
|
}
|
||||||
|
return new OAuth2Validation();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.handler;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.common.cache.CacheNames;
|
||||||
|
import org.springblade.common.cache.ParamCache;
|
||||||
|
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Validation;
|
||||||
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.FAIL_COUNT;
|
||||||
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.FAIL_COUNT_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败锁定处理器
|
||||||
|
* 统一管理账号锁定和IP锁定逻辑
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BladeLockHandler {
|
||||||
|
|
||||||
|
private final BladeRedis bladeRedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 锁定时长(分钟)
|
||||||
|
*/
|
||||||
|
private static final int LOCK_DURATION_MINUTES = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验账号是否锁定
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
* @return OAuth2Validation
|
||||||
|
*/
|
||||||
|
public OAuth2Validation validateAccountLock(String tenantId, String account) {
|
||||||
|
int cnt = getAccountFailCount(tenantId, account);
|
||||||
|
int failCount = getFailCountThreshold();
|
||||||
|
if (cnt >= failCount) {
|
||||||
|
log.error("用户:{},已锁定,请求ip:{}", account, WebUtil.getIP());
|
||||||
|
return buildValidationFailure();
|
||||||
|
}
|
||||||
|
return new OAuth2Validation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验IP是否锁定
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return OAuth2Validation
|
||||||
|
*/
|
||||||
|
public OAuth2Validation validateIpLock(String tenantId) {
|
||||||
|
String clientIp = WebUtil.getIP();
|
||||||
|
int cnt = getIpFailCount(tenantId, clientIp);
|
||||||
|
int failCount = getFailCountThreshold();
|
||||||
|
if (cnt >= failCount) {
|
||||||
|
log.error("IP:{},已锁定", clientIp);
|
||||||
|
return buildValidationFailure();
|
||||||
|
}
|
||||||
|
return new OAuth2Validation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加账号错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
*/
|
||||||
|
public void addAccountFailCount(String tenantId, String account) {
|
||||||
|
if (Func.hasEmpty(tenantId, account)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int count = getAccountFailCount(tenantId, account);
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.ACCOUNT_FAIL_KEY, account);
|
||||||
|
bladeRedis.setEx(cacheKey, count + 1, Duration.ofMinutes(LOCK_DURATION_MINUTES));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加IP错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
*/
|
||||||
|
public void addIpFailCount(String tenantId) {
|
||||||
|
String clientIp = WebUtil.getIP();
|
||||||
|
if (Func.hasEmpty(tenantId, clientIp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int count = getIpFailCount(tenantId, clientIp);
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.IP_FAIL_KEY, clientIp);
|
||||||
|
bladeRedis.setEx(cacheKey, count + 1, Duration.ofMinutes(LOCK_DURATION_MINUTES));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空账号错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
*/
|
||||||
|
public void clearAccountFailCount(String tenantId, String account) {
|
||||||
|
if (Func.hasEmpty(tenantId, account)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.ACCOUNT_FAIL_KEY, account);
|
||||||
|
bladeRedis.del(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空IP错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
*/
|
||||||
|
public void clearIpFailCount(String tenantId) {
|
||||||
|
String clientIp = WebUtil.getIP();
|
||||||
|
if (Func.hasEmpty(tenantId, clientIp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.IP_FAIL_KEY, clientIp);
|
||||||
|
bladeRedis.del(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理认证失败
|
||||||
|
* 同时增加账号和IP错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
*/
|
||||||
|
public void handleAuthFailure(String tenantId, String account) {
|
||||||
|
addAccountFailCount(tenantId, account);
|
||||||
|
addIpFailCount(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理认证成功
|
||||||
|
* 同时清空账号和IP错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
*/
|
||||||
|
public void handleAuthSuccess(String tenantId, String account) {
|
||||||
|
clearAccountFailCount(tenantId, account);
|
||||||
|
clearIpFailCount(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取账号错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param account 账号
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private int getAccountFailCount(String tenantId, String account) {
|
||||||
|
if (Func.hasEmpty(tenantId, account)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.ACCOUNT_FAIL_KEY, account);
|
||||||
|
return Func.toInt(bladeRedis.get(cacheKey), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取IP错误次数
|
||||||
|
*
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @param clientIp 客户端IP
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private int getIpFailCount(String tenantId, String clientIp) {
|
||||||
|
if (Func.hasEmpty(tenantId, clientIp)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String cacheKey = CacheNames.tenantKey(tenantId, CacheNames.IP_FAIL_KEY, clientIp);
|
||||||
|
return Func.toInt(bladeRedis.get(cacheKey), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取失败次数阈值
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private int getFailCountThreshold() {
|
||||||
|
return Func.toInt(ParamCache.getValue(FAIL_COUNT_VALUE), FAIL_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建校验失败结果
|
||||||
|
*
|
||||||
|
* @return OAuth2Validation
|
||||||
|
*/
|
||||||
|
private OAuth2Validation buildValidationFailure() {
|
||||||
|
OAuth2Validation validation = new OAuth2Validation();
|
||||||
|
validation.setSuccess(false);
|
||||||
|
validation.setCode(ExceptionCode.USER_TOO_MANY_FAILS.getCode());
|
||||||
|
validation.setMessage(ExceptionCode.USER_TOO_MANY_FAILS.getMessage());
|
||||||
|
return validation;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.handler;
|
||||||
|
|
||||||
|
import org.springblade.core.oauth2.handler.OAuth2PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladePasswordHandler
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
public class BladePasswordHandler extends OAuth2PasswordHandler {
|
||||||
|
|
||||||
|
public BladePasswordHandler(OAuth2Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断密码是否匹配
|
||||||
|
*
|
||||||
|
* @param rawPassword 请求时提交的原密码
|
||||||
|
* @param encodedPassword 数据库加密后的密码
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean matches(String rawPassword, String encodedPassword) {
|
||||||
|
return super.matches(rawPassword, encodedPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密密码规则
|
||||||
|
*
|
||||||
|
* @param rawPassword 密码
|
||||||
|
* @return 加密后的密码
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String encode(String rawPassword) {
|
||||||
|
return super.encode(rawPassword);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.springblade.modules.auth.handler;
|
||||||
|
|
||||||
|
import org.springblade.core.jwt.props.JwtProperties;
|
||||||
|
import org.springblade.core.launch.constant.TokenConstant;
|
||||||
|
import org.springblade.core.oauth2.handler.OAuth2TokenHandler;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Token;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.tool.support.Kv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladeTokenHandler
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
public class BladeTokenHandler extends OAuth2TokenHandler {
|
||||||
|
|
||||||
|
public BladeTokenHandler(JwtProperties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2Token enhance(OAuth2User user, OAuth2Token token, OAuth2Request request) {
|
||||||
|
// 父类令牌状态配置
|
||||||
|
OAuth2Token enhanceToken = super.enhance(user, token, request);
|
||||||
|
|
||||||
|
// 令牌统一处理,增加或删减字段
|
||||||
|
Kv args = enhanceToken.getArgs();
|
||||||
|
args.set(TokenConstant.USER_NAME, user.getAccount());
|
||||||
|
|
||||||
|
// 返回令牌
|
||||||
|
return enhanceToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.provider;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户类型枚举
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum UserType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* web
|
||||||
|
*/
|
||||||
|
WEB("web", 1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app
|
||||||
|
*/
|
||||||
|
APP("app", 2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* other
|
||||||
|
*/
|
||||||
|
OTHER("other", 3),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kiosk
|
||||||
|
*/
|
||||||
|
KIOSK("kiosk", 4),
|
||||||
|
;
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final int category;
|
||||||
|
|
||||||
|
public static UserType of(String name) {
|
||||||
|
return Arrays.stream(UserType.values())
|
||||||
|
.filter(userEnum -> userEnum.getName().equalsIgnoreCase(name != null ? name : "web"))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(UserType.WEB); // 在没有找到匹配项时返回默认值
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package org.springblade.modules.auth.service;
|
||||||
|
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2Client;
|
||||||
|
import org.springblade.core.oauth2.service.impl.OAuth2ClientDetailService;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladeClientDetailService
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class BladeClientDetailService extends OAuth2ClientDetailService {
|
||||||
|
public BladeClientDetailService(JdbcTemplate jdbcTemplate) {
|
||||||
|
super(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2Client loadByClientId(String clientId) {
|
||||||
|
return super.loadByClientId(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2Client loadByClientId(String clientId, OAuth2Request request) {
|
||||||
|
return super.loadByClientId(clientId, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateClient(OAuth2Client client, String clientId, String clientSecret) {
|
||||||
|
return super.validateClient(client, clientId, clientSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateGranter(OAuth2Client client, String grantType) {
|
||||||
|
return super.validateGranter(client, grantType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package org.springblade.modules.auth.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
|
import org.springblade.modules.auth.utils.TokenUtil;
|
||||||
|
import org.springblade.modules.system.pojo.entity.UserInfo;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BladeUserDetailService
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BladeUserDetailService implements OAuth2UserService {
|
||||||
|
private final IUserService userService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User loadByUserId(String userId, OAuth2Request request) {
|
||||||
|
// 获取用户参数
|
||||||
|
String userType = Optional.ofNullable(request.getUserType())
|
||||||
|
.filter(s -> !StringUtil.isBlank(s))
|
||||||
|
.orElse(UserType.WEB.getName());
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
UserInfo userInfo = userService.userInfo(Func.toLong(userId), UserType.of(userType));
|
||||||
|
|
||||||
|
// 构建oauth2用户信息
|
||||||
|
return TokenUtil.convertUser(userInfo, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User loadByUsername(String username, OAuth2Request request) {
|
||||||
|
// 获取用户参数
|
||||||
|
String userType = Optional.ofNullable(request.getUserType())
|
||||||
|
.filter(s -> !StringUtil.isBlank(s))
|
||||||
|
.orElse(UserType.WEB.getName());
|
||||||
|
String tenantId = request.getTenantId();
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
UserInfo userInfo = userService.userInfo(tenantId, username, UserType.of(userType));
|
||||||
|
|
||||||
|
// 构建oauth2用户信息
|
||||||
|
return TokenUtil.convertUser(userInfo, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User loadByPhone(String phone, OAuth2Request request) {
|
||||||
|
// 获取用户参数
|
||||||
|
String userType = Optional.ofNullable(request.getUserType())
|
||||||
|
.filter(s -> !StringUtil.isBlank(s))
|
||||||
|
.orElse(UserType.WEB.getName());
|
||||||
|
String tenantId = request.getTenantId();
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
UserInfo userInfo = userService.userInfoByPhone(tenantId, phone, UserType.of(userType));
|
||||||
|
|
||||||
|
// 构建oauth2用户信息
|
||||||
|
return TokenUtil.convertUser(userInfo, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateUser(OAuth2User user) {
|
||||||
|
return Optional.ofNullable(user)
|
||||||
|
.filter(u -> u.getUserId() != null && !u.getUserId().isEmpty()) // 检查userId不为空
|
||||||
|
.filter(u -> u.getAuthorities() != null && !u.getAuthorities().isEmpty()) // 检查authorities不为空
|
||||||
|
.isPresent(); // 如果上述条件都满足,则返回true,否则返回false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.utils;
|
||||||
|
|
||||||
|
import org.springblade.common.cache.SysCache;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.system.pojo.entity.User;
|
||||||
|
import org.springblade.modules.system.pojo.entity.UserInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证工具类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class TokenUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户转换为OAuth2标准用户
|
||||||
|
*
|
||||||
|
* @param userInfo 用户信息
|
||||||
|
* @param request 请求信息
|
||||||
|
* @return OAuth2User
|
||||||
|
*/
|
||||||
|
public static OAuth2User convertUser(UserInfo userInfo, OAuth2Request request) {
|
||||||
|
// 为空则返回null
|
||||||
|
if (userInfo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
User user = userInfo.getUser();
|
||||||
|
String userDept = request.getUserDept();
|
||||||
|
String userRole = request.getUserRole();
|
||||||
|
// 单独指定部门
|
||||||
|
if (Func.isNotEmpty(userDept) && user.getDeptId().contains(userDept)) {
|
||||||
|
user.setDeptId(userDept);
|
||||||
|
}
|
||||||
|
// 单独指定角色
|
||||||
|
if (Func.isNotEmpty(userRole) && user.getRoleId().contains(userRole)) {
|
||||||
|
user.setRoleId(userRole);
|
||||||
|
userInfo.setRoles(SysCache.getRoleAliases(userRole));
|
||||||
|
}
|
||||||
|
// 构建oauth2所需用户信息
|
||||||
|
OAuth2UserDetail userDetail = new OAuth2UserDetail();
|
||||||
|
userDetail.setUserId(String.valueOf(user.getId()));
|
||||||
|
userDetail.setOauthId(userInfo.getOauthId());
|
||||||
|
userDetail.setTenantId(user.getTenantId());
|
||||||
|
userDetail.setName(user.getName());
|
||||||
|
userDetail.setRealName(user.getRealName());
|
||||||
|
userDetail.setAccount(user.getAccount());
|
||||||
|
userDetail.setPassword(user.getPassword());
|
||||||
|
userDetail.setDeptId(user.getDeptId());
|
||||||
|
userDetail.setPostId(user.getPostId());
|
||||||
|
userDetail.setRoleId(user.getRoleId());
|
||||||
|
userDetail.setRoleName(Func.join(userInfo.getRoles()));
|
||||||
|
userDetail.setAvatar(user.getAvatar());
|
||||||
|
userDetail.setAuthorities(userInfo.getRoles());
|
||||||
|
userDetail.setDetail(userInfo.getDetail());
|
||||||
|
return userDetail;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.PreAuth;
|
||||||
|
import org.springblade.core.tenant.annotation.TenantDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.xss.annotation.XssIgnore;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||||
|
import org.springblade.modules.desk.service.INoticeService;
|
||||||
|
import org.springblade.modules.desk.wrapper.NoticeWrapper;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@TenantDS
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@PreAuth(menu = "notice")
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DESK_NAME + "/notice")
|
||||||
|
@Tag(name = "用户博客", description = "博客接口")
|
||||||
|
public class NoticeController extends BladeController {
|
||||||
|
|
||||||
|
private final INoticeService noticeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入notice")
|
||||||
|
public R<NoticeVO> detail(Notice notice) {
|
||||||
|
Notice detail = noticeService.getOne(Condition.getQueryWrapper(notice));
|
||||||
|
return R.data(NoticeWrapper.build().entityVO(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||||
|
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||||
|
})
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入notice")
|
||||||
|
public R<IPage<NoticeVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> notice, Query query) {
|
||||||
|
NoticeWrapper.build().noticeQuery(notice);
|
||||||
|
IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
|
||||||
|
return R.data(NoticeWrapper.build().pageVO(pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多表联合查询自定义分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||||
|
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||||
|
})
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "分页", description = "传入notice")
|
||||||
|
public R<IPage<NoticeVO>> page(@Parameter(hidden = true) NoticeVO notice, Query query) {
|
||||||
|
IPage<NoticeVO> pages = noticeService.selectNoticePage(Condition.getPage(query), notice);
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入notice")
|
||||||
|
public R save(@RequestBody Notice notice) {
|
||||||
|
return R.status(noticeService.save(notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入notice")
|
||||||
|
public R update(@RequestBody Notice notice) {
|
||||||
|
return R.status(noticeService.updateById(notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改
|
||||||
|
*/
|
||||||
|
@XssIgnore
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入notice")
|
||||||
|
public R submit(@RequestBody Notice notice) {
|
||||||
|
return R.status(noticeService.saveOrUpdate(notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入notice")
|
||||||
|
public R remove(@Parameter(description = "主键集合") @RequestParam String ids) {
|
||||||
|
boolean temp = noticeService.deleteLogic(Func.toLongList(ids));
|
||||||
|
return R.status(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前N条数据
|
||||||
|
*
|
||||||
|
* @param number 数量
|
||||||
|
* @return List<Notice>
|
||||||
|
*/
|
||||||
|
List<Notice> topList(Integer number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页
|
||||||
|
*
|
||||||
|
* @param page 分页
|
||||||
|
* @param notice 实体
|
||||||
|
* @return List<NoticeVO>
|
||||||
|
*/
|
||||||
|
List<NoticeVO> selectNoticePage(IPage page, NoticeVO notice);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.desk.mapper.NoticeMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="noticeResultMap" type="org.springblade.modules.desk.pojo.entity.Notice">
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="release_time" property="releaseTime"/>
|
||||||
|
<result column="title" property="title"/>
|
||||||
|
<result column="content" property="content"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="noticeVOResultMap" type="org.springblade.modules.desk.pojo.vo.NoticeVO">
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="release_time" property="releaseTime"/>
|
||||||
|
<result column="title" property="title"/>
|
||||||
|
<result column="content" property="content"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="topList" resultMap="noticeResultMap">
|
||||||
|
select * from blade_notice limit #{number}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectNoticePage" resultMap="noticeVOResultMap">
|
||||||
|
SELECT
|
||||||
|
n.*,
|
||||||
|
d.dict_value AS categoryName
|
||||||
|
FROM
|
||||||
|
blade_notice n
|
||||||
|
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
|
||||||
|
WHERE
|
||||||
|
n.is_deleted = 0 and n.tenant_id = #{notice.tenantId}
|
||||||
|
<if test="notice.title!=null">
|
||||||
|
and n.title like concat(concat('%', #{notice.title}), '%')
|
||||||
|
</if>
|
||||||
|
<if test="notice.category!=null">
|
||||||
|
and n.category = #{notice.category}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.pojo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.core.datarecord.annotation.DataRecord;
|
||||||
|
import org.springblade.core.datarecord.annotation.DataRecordLevel;
|
||||||
|
import org.springblade.core.datarecord.annotation.FieldRecord;
|
||||||
|
import org.springblade.core.tenant.mp.TenantEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("blade_notice")
|
||||||
|
@DataRecord(
|
||||||
|
module = "工作台",
|
||||||
|
operation = "通知公告",
|
||||||
|
ignoreFields = {"status"},
|
||||||
|
level = DataRecordLevel.INFO,
|
||||||
|
condition = "#oldData.Category > 1"
|
||||||
|
)
|
||||||
|
@Schema(description = "公告实体类")
|
||||||
|
public class Notice extends TenantEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
@Schema(description = "标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知类型
|
||||||
|
*/
|
||||||
|
@FieldRecord(
|
||||||
|
description = "通知类型",
|
||||||
|
condition = "#newValue > 1"
|
||||||
|
)
|
||||||
|
@Schema(description = "通知类型")
|
||||||
|
private Integer category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布日期
|
||||||
|
*/
|
||||||
|
@Schema(description = "发布日期")
|
||||||
|
private Date releaseTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
@Schema(description = "内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.springblade.modules.desk.pojo.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知公告视图类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Schema(description = "公告实体VO")
|
||||||
|
public class NoticeVO extends Notice {
|
||||||
|
|
||||||
|
@Schema(description = "通知类型名")
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
@Schema(description = "租户编号")
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.springblade.core.mp.base.BaseService;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface INoticeService extends BaseService<Notice> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页
|
||||||
|
* @param page
|
||||||
|
* @param notice
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
import org.springblade.modules.desk.mapper.NoticeMapper;
|
||||||
|
import org.springblade.modules.desk.service.INoticeService;
|
||||||
|
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice) {
|
||||||
|
// 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入
|
||||||
|
notice.setTenantId(AuthUtil.getTenantId());
|
||||||
|
return page.setRecords(baseMapper.selectNoticePage(page, notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.desk.wrapper;
|
||||||
|
|
||||||
|
import org.springblade.common.cache.DictCache;
|
||||||
|
import org.springblade.common.enums.DictEnum;
|
||||||
|
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||||
|
import org.springblade.core.tool.utils.BeanUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.desk.pojo.entity.Notice;
|
||||||
|
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notice包装类,返回视图层所需的字段
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class NoticeWrapper extends BaseEntityWrapper<Notice, NoticeVO> {
|
||||||
|
|
||||||
|
public static NoticeWrapper build() {
|
||||||
|
return new NoticeWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NoticeVO entityVO(Notice notice) {
|
||||||
|
NoticeVO noticeVO = Objects.requireNonNull(BeanUtil.copyProperties(notice, NoticeVO.class));
|
||||||
|
String dictValue = DictCache.getValue(DictEnum.NOTICE, noticeVO.getCategory());
|
||||||
|
noticeVO.setCategoryName(dictValue);
|
||||||
|
return noticeVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询条件处理
|
||||||
|
*/
|
||||||
|
public void noticeQuery(Map<String, Object> notice) {
|
||||||
|
// 此场景仅在 pg数据库 map类型传参的情况下需要处理,entity传参已经包含数据类型,则无需关心
|
||||||
|
// 针对 pg数据库 int类型字段查询需要强转的处理示例
|
||||||
|
String searchKey = "category";
|
||||||
|
if (Func.isNotEmpty(notice.get(searchKey))) {
|
||||||
|
// 数据库字段为int类型,设置"="查询,具体查询参数请见 @org.springblade.core.mp.support.SqlKeyword
|
||||||
|
notice.put(searchKey.concat("_equal"), Func.toInt(notice.get(searchKey)));
|
||||||
|
// 默认"like"查询,pg数据库 场景会报错,所以将其删除
|
||||||
|
notice.remove(searchKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdministrator;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.develop.pojo.dto.GeneratorDTO;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Code;
|
||||||
|
import org.springblade.modules.develop.service.ICodeService;
|
||||||
|
import org.springblade.modules.develop.service.IGenerateService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@Hidden
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdministrator
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/code")
|
||||||
|
@Tag(name = "代码生成", description = "代码生成")
|
||||||
|
public class CodeController extends BladeController {
|
||||||
|
|
||||||
|
private final ICodeService codeService;
|
||||||
|
private final IGenerateService generateService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入code")
|
||||||
|
public R<Code> detail(Code code) {
|
||||||
|
Code detail = codeService.getOne(Condition.getQueryWrapper(code));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "codeName", description = "模块名", in = ParameterIn.QUERY, schema = @Schema(type = "string")),
|
||||||
|
@Parameter(name = "tableName", description = "表名", in = ParameterIn.QUERY, schema = @Schema(type = "string")),
|
||||||
|
@Parameter(name = "modelName", description = "实体名", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||||
|
})
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入code")
|
||||||
|
public R<IPage<Code>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> code, Query query) {
|
||||||
|
IPage<Code> pages = codeService.page(Condition.getPage(query), Condition.getQueryWrapper(code, Code.class));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入code")
|
||||||
|
public R submit(@Valid @RequestBody Code code) {
|
||||||
|
return R.status(codeService.submit(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(codeService.removeByIds(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制
|
||||||
|
*/
|
||||||
|
@PostMapping("/copy")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "复制", description = "传入id")
|
||||||
|
public R copy(@Parameter(description = "主键", required = true) @RequestParam Long id) {
|
||||||
|
Code code = codeService.getById(id);
|
||||||
|
code.setId(null);
|
||||||
|
code.setCodeName(code.getCodeName() + "-copy");
|
||||||
|
return R.status(codeService.save(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成
|
||||||
|
*/
|
||||||
|
@PostMapping("/gen-code")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "代码生成", description = "传入ids")
|
||||||
|
public R genCode(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(generateService.code(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成
|
||||||
|
*/
|
||||||
|
@PostMapping("/gen-code-fast")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "代码快速生成", description = "传入配置集合")
|
||||||
|
public R genCodeFast(@Parameter(description = "主键集合", required = true) @RequestBody GeneratorDTO dto) {
|
||||||
|
return R.status(generateService.codeFast(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdministrator;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.xss.annotation.XssIgnore;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.CodeSetting;
|
||||||
|
import org.springblade.modules.develop.service.ICodeSettingService;
|
||||||
|
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 控制器
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdministrator
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/code-setting")
|
||||||
|
@Tag(name = "代码生成器配置表", description = "代码生成器配置表接口")
|
||||||
|
public class CodeSettingController extends BladeController {
|
||||||
|
|
||||||
|
private final ICodeSettingService codeSettingService;
|
||||||
|
private final IModelPrototypeService modelPrototypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入codeSetting")
|
||||||
|
public R<CodeSetting> detail(CodeSetting codeSetting) {
|
||||||
|
CodeSetting detail = codeSettingService.getOne(Condition.getQueryWrapper(codeSetting));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入codeSetting")
|
||||||
|
public R<IPage<CodeSetting>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> codeSetting, Query query) {
|
||||||
|
IPage<CodeSetting> pages = codeSettingService.page(Condition.getPage(query), Condition.getQueryWrapper(codeSetting, CodeSetting.class).orderByDesc("id"));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "新增", description = "传入codeSetting")
|
||||||
|
public R save(@Valid @RequestBody CodeSetting codeSetting) {
|
||||||
|
return R.status(codeSettingService.save(codeSetting));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "修改", description = "传入codeSetting")
|
||||||
|
public R update(@Valid @RequestBody CodeSetting codeSetting) {
|
||||||
|
return R.status(codeSettingService.updateById(codeSetting));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 新增或修改
|
||||||
|
*/
|
||||||
|
@XssIgnore
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入codeSetting")
|
||||||
|
public R submit(@Valid @RequestBody CodeSetting codeSetting) {
|
||||||
|
boolean temp = codeSettingService.saveOrUpdate(codeSetting);
|
||||||
|
if (temp) {
|
||||||
|
return R.data(codeSetting);
|
||||||
|
} else {
|
||||||
|
return R.status(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(codeSettingService.removeByIds(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 启用
|
||||||
|
*/
|
||||||
|
@PostMapping("/enable")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "配置启用", description = "传入id")
|
||||||
|
public R enable(@Parameter(description = "主键", required = true) @RequestParam Long id) {
|
||||||
|
return R.status(codeSettingService.enable(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 启用详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/enable-detail")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "详情", description = "传入codeSetting")
|
||||||
|
public R<CodeSetting> enableDetail() {
|
||||||
|
CodeSetting detail = codeSettingService.getOne(Wrappers.<CodeSetting>lambdaQuery().eq(CodeSetting::getStatus, BladeConstant.DB_STATUS_2).eq(CodeSetting::getIsDeleted, BladeConstant.DB_NOT_DELETED));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单设计器选择
|
||||||
|
*/
|
||||||
|
@GetMapping("/table-form")
|
||||||
|
@ApiOperationSupport(order = 9)
|
||||||
|
@Operation(summary = "表单设计器选择", description = "tableName")
|
||||||
|
public R<List<CodeSetting>> formSelect(String tableName) {
|
||||||
|
return R.data(codeSettingService.list(Wrappers.<CodeSetting>lambdaQuery().eq(CodeSetting::getCode, tableName).eq(CodeSetting::getCategory, 2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字段信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/table-prototype")
|
||||||
|
@ApiOperationSupport(order = 10)
|
||||||
|
@Operation(summary = "物理表字段信息", description = "传入tableName与datasourceId")
|
||||||
|
public R tablePrototype(String tableName, Long datasourceId) {
|
||||||
|
TableInfo tableInfo = modelPrototypeService.getTableInfo(tableName, datasourceId);
|
||||||
|
if (tableInfo != null) {
|
||||||
|
return R.data(tableInfo.getFields());
|
||||||
|
} else {
|
||||||
|
return R.fail("未获得相关表信息");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdministrator;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.core.xss.annotation.XssIgnore;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
import org.springblade.modules.develop.service.IDatasourceService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置表 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdministrator
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/datasource")
|
||||||
|
@Tag(name = "数据源配置表", description = "数据源配置表接口")
|
||||||
|
public class DatasourceController extends BladeController {
|
||||||
|
|
||||||
|
private final IDatasourceService datasourceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入datasource")
|
||||||
|
public R<Datasource> detail(Datasource datasource) {
|
||||||
|
Datasource detail = datasourceService.getOne(Condition.getQueryWrapper(datasource));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页 数据源配置表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入datasource")
|
||||||
|
public R<IPage<Datasource>> list(Datasource datasource, Query query) {
|
||||||
|
IPage<Datasource> pages = datasourceService.page(Condition.getPage(query), Condition.getQueryWrapper(datasource));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 数据源配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入datasource")
|
||||||
|
public R save(@Valid @RequestBody Datasource datasource) {
|
||||||
|
return R.status(datasourceService.save(datasource));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 数据源配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入datasource")
|
||||||
|
public R update(@Valid @RequestBody Datasource datasource) {
|
||||||
|
return R.status(datasourceService.updateById(datasource));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改 数据源配置表
|
||||||
|
*/
|
||||||
|
@XssIgnore
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入datasource")
|
||||||
|
public R submit(@Valid @RequestBody Datasource datasource) {
|
||||||
|
if (StringUtil.isNotBlank(datasource.getUrl())) {
|
||||||
|
datasource.setUrl(datasource.getUrl().replace("&", "&"));
|
||||||
|
}
|
||||||
|
return R.status(datasourceService.saveOrUpdate(datasource));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 数据源配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(datasourceService.deleteLogic(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/select")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "下拉数据源", description = "查询列表")
|
||||||
|
public R<List<Datasource>> select() {
|
||||||
|
List<Datasource> list = datasourceService.list();
|
||||||
|
return R.data(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdministrator;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Model;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
import org.springblade.modules.develop.service.IDatasourceService;
|
||||||
|
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||||
|
import org.springblade.modules.develop.service.IModelService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型表 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdministrator
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/model")
|
||||||
|
@Tag(name = "数据模型表", description = "数据模型表接口")
|
||||||
|
public class ModelController extends BladeController {
|
||||||
|
|
||||||
|
private final IModelService modelService;
|
||||||
|
private final IModelPrototypeService modelPrototypeService;
|
||||||
|
private final IDatasourceService datasourceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入model")
|
||||||
|
public R<Model> detail(Model model) {
|
||||||
|
Model detail = modelService.getOne(Condition.getQueryWrapper(model));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页 数据模型表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入model")
|
||||||
|
public R<IPage<Model>> list(Model model, Query query) {
|
||||||
|
IPage<Model> pages = modelService.page(Condition.getPage(query), Condition.getQueryWrapper(model));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 数据模型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "新增", description = "传入model")
|
||||||
|
public R save(@Valid @RequestBody Model model) {
|
||||||
|
return R.status(modelService.save(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 数据模型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "修改", description = "传入model")
|
||||||
|
public R update(@Valid @RequestBody Model model) {
|
||||||
|
return R.status(modelService.updateById(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改 数据模型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入model")
|
||||||
|
public R submit(@Valid @RequestBody Model model) {
|
||||||
|
boolean temp = modelService.saveOrUpdate(model);
|
||||||
|
if (temp) {
|
||||||
|
return R.data(model);
|
||||||
|
} else {
|
||||||
|
return R.status(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 数据模型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(modelService.delete(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/select")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "模型列表", description = "模型列表")
|
||||||
|
public R<List<Model>> select() {
|
||||||
|
List<Model> list = modelService.list();
|
||||||
|
list.forEach(model -> model.setModelName(model.getModelTable() + StringPool.COLON + StringPool.SPACE + model.getModelName()));
|
||||||
|
return R.data(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取物理表列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/table-list")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "物理表列表", description = "传入datasourceId")
|
||||||
|
public R<List<TableInfo>> tableList(Long datasourceId) {
|
||||||
|
Datasource datasource = datasourceService.getById(datasourceId);
|
||||||
|
ConfigBuilder config = modelPrototypeService.getConfigBuilder(datasource);
|
||||||
|
List<TableInfo> tableInfoList = config.getTableInfoList().stream()
|
||||||
|
.filter(tableInfo -> !StringUtil.startsWithIgnoreCase(tableInfo.getName(), "ACT_") && !StringUtil.startsWithIgnoreCase(tableInfo.getName(), "FLW_"))
|
||||||
|
.map(tableInfo -> tableInfo.setComment(tableInfo.getName() + StringPool.COLON + tableInfo.getComment()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return R.data(tableInfoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取物理表信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/table-info")
|
||||||
|
@ApiOperationSupport(order = 9)
|
||||||
|
@Operation(summary = "物理表信息", description = "传入model信息")
|
||||||
|
public R<TableInfo> tableInfo(Long modelId, String tableName, Long datasourceId) {
|
||||||
|
if (StringUtil.isBlank(tableName)) {
|
||||||
|
Model model = modelService.getById(modelId);
|
||||||
|
tableName = model.getModelTable();
|
||||||
|
}
|
||||||
|
TableInfo tableInfo = modelPrototypeService.getTableInfo(tableName, datasourceId);
|
||||||
|
return R.data(tableInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字段信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/model-prototype")
|
||||||
|
@ApiOperationSupport(order = 10)
|
||||||
|
@Operation(summary = "物理表字段信息", description = "传入modelId与datasourceId")
|
||||||
|
public R modelPrototype(Long modelId, Long datasourceId) {
|
||||||
|
List<ModelPrototype> modelPrototypeList = modelPrototypeService.list(Wrappers.<ModelPrototype>query().lambda().eq(ModelPrototype::getModelId, modelId));
|
||||||
|
if (!modelPrototypeList.isEmpty()) {
|
||||||
|
return R.data(modelPrototypeList);
|
||||||
|
}
|
||||||
|
Model model = modelService.getById(modelId);
|
||||||
|
String tableName = model.getModelTable();
|
||||||
|
TableInfo tableInfo = modelPrototypeService.getTableInfo(tableName, datasourceId);
|
||||||
|
if (tableInfo != null) {
|
||||||
|
return R.data(tableInfo.getFields());
|
||||||
|
} else {
|
||||||
|
return R.fail("未获得相关表信息");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdministrator;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型表 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdministrator
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/model-prototype")
|
||||||
|
@Tag(name = "数据原型表", description = "数据原型表接口")
|
||||||
|
public class ModelPrototypeController extends BladeController {
|
||||||
|
|
||||||
|
private final IModelPrototypeService modelPrototypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入modelPrototype")
|
||||||
|
public R<ModelPrototype> detail(ModelPrototype modelPrototype) {
|
||||||
|
ModelPrototype detail = modelPrototypeService.getOne(Condition.getQueryWrapper(modelPrototype));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页 数据原型表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入modelPrototype")
|
||||||
|
public R<IPage<ModelPrototype>> list(ModelPrototype modelPrototype, Query query) {
|
||||||
|
IPage<ModelPrototype> pages = modelPrototypeService.page(Condition.getPage(query), Condition.getQueryWrapper(modelPrototype));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 数据原型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入modelPrototype")
|
||||||
|
public R save(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||||
|
return R.status(modelPrototypeService.save(modelPrototype));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 数据原型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入modelPrototype")
|
||||||
|
public R update(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||||
|
return R.status(modelPrototypeService.updateById(modelPrototype));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改 数据原型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入modelPrototype")
|
||||||
|
public R submit(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||||
|
return R.status(modelPrototypeService.saveOrUpdate(modelPrototype));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增或修改 数据原型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit-list")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "批量新增或修改", description = "传入modelPrototype集合")
|
||||||
|
public R submitList(@Valid @RequestBody List<ModelPrototype> modelPrototypes) {
|
||||||
|
return R.status(modelPrototypeService.submitList(modelPrototypes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 数据原型表
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(modelPrototypeService.deleteLogic(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/select")
|
||||||
|
@ApiOperationSupport(order = 9)
|
||||||
|
@Operation(summary = "数据原型列表", description = "数据原型列表")
|
||||||
|
public R<List<ModelPrototype>> select(@Parameter(description = "数据模型Id", required = true) @RequestParam Long modelId) {
|
||||||
|
List<ModelPrototype> list = modelPrototypeService.list(Wrappers.<ModelPrototype>query().lambda().eq(ModelPrototype::getModelId, modelId));
|
||||||
|
list.forEach(prototype -> prototype.setJdbcComment(prototype.getJdbcName() + StringPool.COLON + StringPool.SPACE + prototype.getJdbcComment()));
|
||||||
|
return R.data(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface CodeMapper extends BaseMapper<Code> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.develop.mapper.CodeMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="codeResultMap" type="org.springblade.modules.develop.pojo.entity.Code">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="model_id" property="modelId"/>
|
||||||
|
<result column="menu_id" property="menuId"/>
|
||||||
|
<result column="service_name" property="serviceName"/>
|
||||||
|
<result column="code_name" property="codeName"/>
|
||||||
|
<result column="table_name" property="tableName"/>
|
||||||
|
<result column="pk_name" property="pkName"/>
|
||||||
|
<result column="base_mode" property="baseMode"/>
|
||||||
|
<result column="wrap_mode" property="wrapMode"/>
|
||||||
|
<result column="table_prefix" property="tablePrefix"/>
|
||||||
|
<result column="package_name" property="packageName"/>
|
||||||
|
<result column="api_path" property="apiPath"/>
|
||||||
|
<result column="web_path" property="webPath"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.CodeSetting;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
public interface CodeSettingMapper extends BaseMapper<CodeSetting> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.develop.mapper.CodeSettingMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="codeSettingResultMap" type="org.springblade.modules.develop.pojo.entity.CodeSetting">
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="name" property="name"/>
|
||||||
|
<result column="code" property="code"/>
|
||||||
|
<result column="category" property="category"/>
|
||||||
|
<result column="settings" property="settings"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置表 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface DatasourceMapper extends BaseMapper<Datasource> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.develop.mapper.DatasourceMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="datasourceResultMap" type="org.springblade.modules.develop.pojo.entity.Datasource">
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_dept" property="createDept"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="driver_class" property="driverClass"/>
|
||||||
|
<result column="url" property="url"/>
|
||||||
|
<result column="username" property="username"/>
|
||||||
|
<result column="password" property="password"/>
|
||||||
|
<result column="remark" property="remark"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型表 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface ModelMapper extends BaseMapper<Model> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.develop.mapper.ModelMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="modelResultMap" type="org.springblade.modules.develop.pojo.entity.Model">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="datasource_id" property="datasourceId"/>
|
||||||
|
<result column="model_name" property="modelName"/>
|
||||||
|
<result column="model_code" property="modelCode"/>
|
||||||
|
<result column="model_table" property="modelTable"/>
|
||||||
|
<result column="model_class" property="modelClass"/>
|
||||||
|
<result column="model_remark" property="modelRemark"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectModelPage" resultMap="modelResultMap">
|
||||||
|
select * from blade_model where is_deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型表 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface ModelPrototypeMapper extends BaseMapper<ModelPrototype> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.develop.mapper.ModelPrototypeMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="modelPrototypeResultMap" type="org.springblade.modules.develop.pojo.entity.ModelPrototype">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="jdbc_name" property="jdbcName"/>
|
||||||
|
<result column="jdbc_type" property="jdbcType"/>
|
||||||
|
<result column="jdbc_comment" property="jdbcComment"/>
|
||||||
|
<result column="property_type" property="propertyType"/>
|
||||||
|
<result column="property_entity" property="propertyEntity"/>
|
||||||
|
<result column="property_name" property="propertyName"/>
|
||||||
|
<result column="is_form" property="isForm"/>
|
||||||
|
<result column="is_row" property="isRow"/>
|
||||||
|
<result column="component_type" property="componentType"/>
|
||||||
|
<result column="dict_code" property="dictCode"/>
|
||||||
|
<result column="is_required" property="isRequired"/>
|
||||||
|
<result column="is_list" property="isList"/>
|
||||||
|
<result column="is_query" property="isQuery"/>
|
||||||
|
<result column="query_type" property="queryType"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectModelPrototypePage" resultMap="modelPrototypeResultMap">
|
||||||
|
select * from blade_model_prototype where is_deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成DTO
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GeneratorDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上级菜单主键
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "上级菜单主键")
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源主键
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源主键")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long datasourceId;
|
||||||
|
/**
|
||||||
|
* 模型编号
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型编号")
|
||||||
|
private String modelCode;
|
||||||
|
/**
|
||||||
|
* 物理表名
|
||||||
|
*/
|
||||||
|
@Schema(description = "物理表名")
|
||||||
|
private String modelTable;
|
||||||
|
/**
|
||||||
|
* 表单设计
|
||||||
|
*/
|
||||||
|
@Schema(description = "表单设计")
|
||||||
|
private String modelForm;
|
||||||
|
/**
|
||||||
|
* 模型类名
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型类名")
|
||||||
|
private String modelClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "服务名称")
|
||||||
|
private String serviceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "模块名称")
|
||||||
|
private String codeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
@Schema(description = "表名")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体名
|
||||||
|
*/
|
||||||
|
@Schema(description = "表前缀")
|
||||||
|
private String tablePrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键名
|
||||||
|
*/
|
||||||
|
@Schema(description = "主键名")
|
||||||
|
private String pkName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端包名
|
||||||
|
*/
|
||||||
|
@Schema(description = "后端包名")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础业务模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "基础业务模式")
|
||||||
|
private Integer baseMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包装器模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "包装器模式")
|
||||||
|
private Integer wrapMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程调用模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "远程调用模式")
|
||||||
|
private Integer feignMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码风格
|
||||||
|
*/
|
||||||
|
@Schema(description = "代码风格")
|
||||||
|
private String codeStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端路径
|
||||||
|
*/
|
||||||
|
@Schema(description = "后端路径")
|
||||||
|
private String apiPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前端路径
|
||||||
|
*/
|
||||||
|
@Schema(description = "前端路径")
|
||||||
|
private String webPath;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Model;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码模型DTO
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ModelDTO extends Model {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码建模原型
|
||||||
|
*/
|
||||||
|
private List<ModelPrototype> prototypes;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("blade_code")
|
||||||
|
@Schema(description = "Code对象")
|
||||||
|
public class Code implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "主键")
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型主键
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "数据模型主键")
|
||||||
|
private Long modelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上级菜单主键
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "上级菜单主键")
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "服务名称")
|
||||||
|
private String serviceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "模块名称")
|
||||||
|
private String codeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
@Schema(description = "表名")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体名
|
||||||
|
*/
|
||||||
|
@Schema(description = "表前缀")
|
||||||
|
private String tablePrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键名
|
||||||
|
*/
|
||||||
|
@Schema(description = "主键名")
|
||||||
|
private String pkName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端包名
|
||||||
|
*/
|
||||||
|
@Schema(description = "后端包名")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模版类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "模版类型")
|
||||||
|
private String templateType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者信息
|
||||||
|
*/
|
||||||
|
@Schema(description = "作者信息")
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子表模型主键
|
||||||
|
*/
|
||||||
|
@Schema(description = "子表模型主键")
|
||||||
|
private String subModelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子表绑定外键
|
||||||
|
*/
|
||||||
|
@Schema(description = "子表绑定外键")
|
||||||
|
private String subFkId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树主键字段
|
||||||
|
*/
|
||||||
|
@Schema(description = "树主键字段")
|
||||||
|
private String treeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树父主键字段
|
||||||
|
*/
|
||||||
|
@Schema(description = "树父主键字段")
|
||||||
|
private String treePid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树名称字段
|
||||||
|
*/
|
||||||
|
@Schema(description = "树名称字段")
|
||||||
|
private String treeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础业务模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "基础业务模式")
|
||||||
|
private Integer baseMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包装器模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "包装器模式")
|
||||||
|
private Integer wrapMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程调用模式
|
||||||
|
*/
|
||||||
|
@Schema(description = "远程调用模式")
|
||||||
|
private Integer feignMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码风格
|
||||||
|
*/
|
||||||
|
@Schema(description = "代码风格")
|
||||||
|
private String codeStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端路径
|
||||||
|
*/
|
||||||
|
@Schema(description = "后端路径")
|
||||||
|
private String apiPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前端路径
|
||||||
|
*/
|
||||||
|
@Schema(description = "前端路径")
|
||||||
|
private String webPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已删除
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
@Schema(description = "是否已删除")
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 实体类
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("blade_code_setting")
|
||||||
|
@Schema(description = "CodeSetting对象")
|
||||||
|
public class CodeSetting implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "主键")
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 编号
|
||||||
|
*/
|
||||||
|
@Schema(description = "编号")
|
||||||
|
private String code;
|
||||||
|
/**
|
||||||
|
* 分类[1:默认配置 2:表单设计]
|
||||||
|
*/
|
||||||
|
@Schema(description = "业务状态", hidden = true)
|
||||||
|
private Integer category;
|
||||||
|
/**
|
||||||
|
* 配置项
|
||||||
|
*/
|
||||||
|
@Schema(description = "配置项")
|
||||||
|
private String settings;
|
||||||
|
/**
|
||||||
|
* 状态[1:正常]
|
||||||
|
*/
|
||||||
|
@Schema(description = "业务状态", hidden = true)
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 是否已删除
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否已删除")
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.core.mp.base.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置表实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("blade_datasource")
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Schema(description = "数据源配置表")
|
||||||
|
public class Datasource extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源类型")
|
||||||
|
private Integer category;
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 驱动类
|
||||||
|
*/
|
||||||
|
@Schema(description = "驱动类")
|
||||||
|
private String driverClass;
|
||||||
|
/**
|
||||||
|
* 连接地址
|
||||||
|
*/
|
||||||
|
@Schema(description = "连接地址")
|
||||||
|
private String url;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@Schema(description = "用户名")
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@Schema(description = "密码")
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* 分库分表配置
|
||||||
|
*/
|
||||||
|
@Schema(description = "分库分表配置")
|
||||||
|
private String shardingConfig;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.core.mp.base.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型表实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("blade_model")
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Schema(description = "数据模型表")
|
||||||
|
public class Model extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源主键
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源主键")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long datasourceId;
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型名称")
|
||||||
|
private String modelName;
|
||||||
|
/**
|
||||||
|
* 模型编号
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型编号")
|
||||||
|
private String modelCode;
|
||||||
|
/**
|
||||||
|
* 物理表名
|
||||||
|
*/
|
||||||
|
@Schema(description = "物理表名")
|
||||||
|
private String modelTable;
|
||||||
|
/**
|
||||||
|
* 模型类名
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型类名")
|
||||||
|
private String modelClass;
|
||||||
|
/**
|
||||||
|
* 模型备注
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型备注")
|
||||||
|
private String modelRemark;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.pojo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springblade.core.mp.base.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型表实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("blade_model_prototype")
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Schema(description = "数据原型表")
|
||||||
|
public class ModelPrototype extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型主键
|
||||||
|
*/
|
||||||
|
@Schema(description = "模型主键")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long modelId;
|
||||||
|
/**
|
||||||
|
* 物理列名
|
||||||
|
*/
|
||||||
|
@Schema(description = "物理列名")
|
||||||
|
private String jdbcName;
|
||||||
|
/**
|
||||||
|
* 物理类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "物理类型")
|
||||||
|
private String jdbcType;
|
||||||
|
/**
|
||||||
|
* 注释说明
|
||||||
|
*/
|
||||||
|
@Schema(description = "注释说明")
|
||||||
|
private String jdbcComment;
|
||||||
|
/**
|
||||||
|
* 实体列名
|
||||||
|
*/
|
||||||
|
@Schema(description = "实体列名")
|
||||||
|
private String propertyName;
|
||||||
|
/**
|
||||||
|
* 实体类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "实体类型")
|
||||||
|
private String propertyType;
|
||||||
|
/**
|
||||||
|
* 实体类型引用
|
||||||
|
*/
|
||||||
|
@Schema(description = "实体类型引用")
|
||||||
|
private String propertyEntity;
|
||||||
|
/**
|
||||||
|
* 列表显示
|
||||||
|
*/
|
||||||
|
@Schema(description = "列表显示")
|
||||||
|
private Integer isList;
|
||||||
|
/**
|
||||||
|
* 表单显示
|
||||||
|
*/
|
||||||
|
@Schema(description = "表单显示")
|
||||||
|
private Integer isForm;
|
||||||
|
/**
|
||||||
|
* 独占一行
|
||||||
|
*/
|
||||||
|
@Schema(description = "独占一行")
|
||||||
|
private Integer isRow;
|
||||||
|
/**
|
||||||
|
* 组件类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "组件类型")
|
||||||
|
private String componentType;
|
||||||
|
/**
|
||||||
|
* 字典编码
|
||||||
|
*/
|
||||||
|
@Schema(description = "字典编码")
|
||||||
|
private String dictCode;
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否必填")
|
||||||
|
private Integer isRequired;
|
||||||
|
/**
|
||||||
|
* 查询配置
|
||||||
|
*/
|
||||||
|
@Schema(description = "查询配置")
|
||||||
|
private Integer isQuery;
|
||||||
|
/**
|
||||||
|
* 查询类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "查询类型")
|
||||||
|
private String queryType;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface ICodeService extends IService<Code> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交
|
||||||
|
*
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean submit(Code code);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.CodeSetting;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 服务类
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
public interface ICodeSettingService extends IService<CodeSetting> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动配置
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean enable(Long id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseService;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置表 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface IDatasourceService extends BaseService<Datasource> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springblade.modules.develop.pojo.dto.GeneratorDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface IGenerateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成代码
|
||||||
|
*
|
||||||
|
* @param ids 主键集合
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean code(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 快速生成代码
|
||||||
|
*
|
||||||
|
* @param dto 配置参数
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean codeFast(GeneratorDTO dto);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import org.springblade.core.mp.base.BaseService;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型表 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface IModelPrototypeService extends BaseService<ModelPrototype> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量提交
|
||||||
|
*
|
||||||
|
* @param modelPrototypes 原型集合
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean submitList(List<ModelPrototype> modelPrototypes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原型列表
|
||||||
|
*
|
||||||
|
* @param modelId 模型ID
|
||||||
|
* @return List<ModelPrototype>
|
||||||
|
*/
|
||||||
|
List<ModelPrototype> prototypeList(Long modelId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表信息
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param datasourceId 数据源主键
|
||||||
|
*/
|
||||||
|
TableInfo getTableInfo(String tableName, Long datasourceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表配置信息
|
||||||
|
*
|
||||||
|
* @param datasource 数据源信息
|
||||||
|
*/
|
||||||
|
default ConfigBuilder getConfigBuilder(Datasource datasource) {
|
||||||
|
return getConfigBuilder(datasource, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表配置信息
|
||||||
|
*
|
||||||
|
* @param datasource 数据源信息
|
||||||
|
* @param tableName 表名
|
||||||
|
*/
|
||||||
|
ConfigBuilder getConfigBuilder(Datasource datasource, String tableName);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service;
|
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseService;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型表 服务类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface IModelService extends BaseService<Model> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除模型
|
||||||
|
*
|
||||||
|
* @param ids 主键集合
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean delete(List<Long> ids);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Code;
|
||||||
|
import org.springblade.modules.develop.mapper.CodeMapper;
|
||||||
|
import org.springblade.modules.develop.service.ICodeService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
public class CodeServiceImpl extends ServiceImpl<CodeMapper, Code> implements ICodeService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean submit(Code code) {
|
||||||
|
code.setIsDeleted(BladeConstant.DB_NOT_DELETED);
|
||||||
|
return saveOrUpdate(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
|
import org.springblade.modules.develop.mapper.CodeSettingMapper;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.CodeSetting;
|
||||||
|
import org.springblade.modules.develop.service.ICodeSettingService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器配置表 服务实现类
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
public class CodeSettingServiceImpl extends ServiceImpl<CodeSettingMapper, CodeSetting> implements ICodeSettingService {
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean enable(Long id) {
|
||||||
|
// 先禁用
|
||||||
|
boolean temp1 = this.update(Wrappers.<CodeSetting>update().lambda().set(CodeSetting::getStatus, BladeConstant.DB_STATUS_1));
|
||||||
|
// 在启用
|
||||||
|
boolean temp2 = this.update(Wrappers.<CodeSetting>update().lambda().set(CodeSetting::getStatus, BladeConstant.DB_STATUS_2).eq(CodeSetting::getId, id));
|
||||||
|
return temp1 && temp2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
import org.springblade.modules.develop.mapper.DatasourceMapper;
|
||||||
|
import org.springblade.modules.develop.service.IDatasourceService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置表 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
public class DatasourceServiceImpl extends BaseServiceImpl<DatasourceMapper, Datasource> implements IDatasourceService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableField;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
|
import org.springblade.core.tool.utils.BeanUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.develop.constant.DevelopConstant;
|
||||||
|
import org.springblade.develop.support.BladeCodeGenerator;
|
||||||
|
import org.springblade.modules.develop.pojo.dto.GeneratorDTO;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.*;
|
||||||
|
import org.springblade.modules.develop.service.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GenerateServiceImpl implements IGenerateService {
|
||||||
|
|
||||||
|
private final ICodeService codeService;
|
||||||
|
private final ICodeSettingService codeSettingService;
|
||||||
|
private final IDatasourceService datasourceService;
|
||||||
|
private final IModelService modelService;
|
||||||
|
private final IModelPrototypeService modelPrototypeService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean code(List<Long> ids) {
|
||||||
|
Collection<Code> codes = codeService.listByIds(ids);
|
||||||
|
codes.forEach(code -> {
|
||||||
|
// 创建代码生成器
|
||||||
|
BladeCodeGenerator generator = new BladeCodeGenerator();
|
||||||
|
// 设置菜单数据
|
||||||
|
this.generateMenu(generator, code);
|
||||||
|
// 设置配置信息
|
||||||
|
this.generateTemplate(generator, code);
|
||||||
|
// 设置基础模型
|
||||||
|
Model model = modelService.getById(code.getModelId());
|
||||||
|
this.generateModel(generator, code, model);
|
||||||
|
// 设置数据源
|
||||||
|
this.generateDatasource(generator, model);
|
||||||
|
// 启动代码生成
|
||||||
|
generator.run();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean codeFast(GeneratorDTO dto) {
|
||||||
|
// 创建代码生成器
|
||||||
|
BladeCodeGenerator generator = new BladeCodeGenerator();
|
||||||
|
Code code = Objects.requireNonNull(BeanUtil.copyProperties(dto, Code.class));
|
||||||
|
Model model = Objects.requireNonNull(BeanUtil.copyProperties(dto, Model.class));
|
||||||
|
String modelForm = dto.getModelForm();
|
||||||
|
// 设置菜单数据
|
||||||
|
this.generateMenu(generator, code);
|
||||||
|
// 设置配置信息
|
||||||
|
this.generateForm(generator, modelForm);
|
||||||
|
this.generateTemplate(generator, code);
|
||||||
|
this.generateModel(generator, code, model);
|
||||||
|
// 设置数据源
|
||||||
|
this.generateDatasource(generator, model);
|
||||||
|
// 启动代码生成
|
||||||
|
generator.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateMenu(BladeCodeGenerator generator, Code code) {
|
||||||
|
// 设置上级菜单id
|
||||||
|
generator.setMenuId(String.valueOf(code.getMenuId()));
|
||||||
|
// 设置是否生成菜单sql
|
||||||
|
generator.setHasMenuSql(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateForm(BladeCodeGenerator generator, String modelForm) {
|
||||||
|
if (StringUtil.isNotBlank(modelForm)) {
|
||||||
|
CodeSetting codeSetting = codeSettingService.getById(Func.toLong(modelForm));
|
||||||
|
if (codeSetting != null) {
|
||||||
|
generator.setModelFormOption(codeSetting.getSettings());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateTemplate(BladeCodeGenerator generator, Code code) {// 设置基础配置
|
||||||
|
generator.setCodeStyle(code.getCodeStyle());
|
||||||
|
generator.setCodeName(code.getCodeName());
|
||||||
|
generator.setServiceName(code.getServiceName());
|
||||||
|
generator.setPackageName(code.getPackageName());
|
||||||
|
generator.setPackageDir(code.getApiPath());
|
||||||
|
generator.setPackageWebDir(code.getWebPath());
|
||||||
|
generator.setTablePrefix(Func.toStrArray(code.getTablePrefix()));
|
||||||
|
generator.setIncludeTables(Func.toStrArray(code.getTableName()));
|
||||||
|
// 设置模版信息
|
||||||
|
generator.setTemplateType(Func.toStr(code.getTemplateType(), DevelopConstant.TEMPLATE_CRUD));
|
||||||
|
generator.setAuthor(code.getAuthor());
|
||||||
|
generator.setSubModelId(code.getSubModelId());
|
||||||
|
generator.setSubFkId(code.getSubFkId());
|
||||||
|
generator.setTreeId(code.getTreeId());
|
||||||
|
generator.setTreePid(code.getTreePid());
|
||||||
|
generator.setTreeName(code.getTreeName());
|
||||||
|
// 设置是否继承基础业务字段
|
||||||
|
generator.setHasSuperEntity(code.getBaseMode() == 2);
|
||||||
|
// 设置是否开启包装器模式
|
||||||
|
generator.setHasWrapper(code.getWrapMode() == 2);
|
||||||
|
// 设置是否开启远程调用模式
|
||||||
|
generator.setHasFeign(code.getFeignMode() == 2);
|
||||||
|
// 设置控制器服务名前缀
|
||||||
|
generator.setHasServiceName(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateModel(BladeCodeGenerator generator, Code code, Model model) {
|
||||||
|
generator.setModelCode(model.getModelCode());
|
||||||
|
generator.setModelClass(model.getModelClass());
|
||||||
|
generator.setModel(JsonUtil.readMap(JsonUtil.toJson(model)));
|
||||||
|
|
||||||
|
// 设置模型集合
|
||||||
|
if (Func.isNotEmpty(model.getId())) {
|
||||||
|
List<ModelPrototype> prototypes = modelPrototypeService.prototypeList(model.getId());
|
||||||
|
generator.setPrototypes(JsonUtil.readListMap(JsonUtil.toJson(prototypes)));
|
||||||
|
if (StringUtil.isNotBlank(code.getSubModelId()) && StringUtil.equals(code.getTemplateType(), DevelopConstant.TEMPLATE_SUB)) {
|
||||||
|
Model subModel = modelService.getById(Func.toLong(code.getSubModelId()));
|
||||||
|
List<ModelPrototype> subPrototypes = modelPrototypeService.prototypeList(subModel.getId());
|
||||||
|
generator.setSubModel(JsonUtil.readMap(JsonUtil.toJson(subModel)));
|
||||||
|
generator.setSubPrototypes(JsonUtil.readListMap(JsonUtil.toJson(subPrototypes)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TableInfo tableInfo = modelPrototypeService.getTableInfo(model.getModelTable(), model.getDatasourceId());
|
||||||
|
List<TableField> fields = tableInfo.getFields();
|
||||||
|
List<ModelPrototype> prototypes = convertPrototypes(fields);
|
||||||
|
generator.setPrototypes(JsonUtil.readListMap(JsonUtil.toJson(prototypes)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateDatasource(BladeCodeGenerator generator, Model model) {
|
||||||
|
Datasource datasource = datasourceService.getById(model.getDatasourceId());
|
||||||
|
generator.setDriverName(datasource.getDriverClass());
|
||||||
|
generator.setUrl(datasource.getUrl());
|
||||||
|
generator.setUsername(datasource.getUsername());
|
||||||
|
generator.setPassword(datasource.getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 TableField 列表转换为 ModelPrototype 列表
|
||||||
|
*
|
||||||
|
* @param tableFields 输入的 TableField 列表
|
||||||
|
* @return 转换后的 ModelPrototype 列表
|
||||||
|
*/
|
||||||
|
public static List<ModelPrototype> convertPrototypes(List<TableField> tableFields) {
|
||||||
|
return tableFields.stream().map(tableField -> {
|
||||||
|
ModelPrototype prototype = new ModelPrototype();
|
||||||
|
prototype.setJdbcName(tableField.getName());
|
||||||
|
if (tableField.getColumnType() != null) {
|
||||||
|
prototype.setJdbcType(tableField.getColumnType().getType());
|
||||||
|
prototype.setPropertyType(tableField.getColumnType().getType());
|
||||||
|
}
|
||||||
|
prototype.setJdbcComment(tableField.getComment());
|
||||||
|
prototype.setPropertyName(tableField.getPropertyName());
|
||||||
|
prototype.setComponentType("input");
|
||||||
|
return prototype;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Datasource;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
import org.springblade.modules.develop.mapper.ModelPrototypeMapper;
|
||||||
|
import org.springblade.modules.develop.service.IDatasourceService;
|
||||||
|
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据原型表 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ModelPrototypeServiceImpl extends BaseServiceImpl<ModelPrototypeMapper, ModelPrototype> implements IModelPrototypeService {
|
||||||
|
|
||||||
|
private final IDatasourceService datasourceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean submitList(List<ModelPrototype> modelPrototypes) {
|
||||||
|
modelPrototypes.forEach(modelPrototype -> {
|
||||||
|
if (modelPrototype.getId() == null) {
|
||||||
|
this.save(modelPrototype);
|
||||||
|
} else {
|
||||||
|
this.updateById(modelPrototype);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModelPrototype> prototypeList(Long modelId) {
|
||||||
|
return this.list(Wrappers.<ModelPrototype>lambdaQuery().eq(ModelPrototype::getModelId, modelId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableInfo getTableInfo(String tableName, Long datasourceId) {
|
||||||
|
Datasource datasource = datasourceService.getById(datasourceId);
|
||||||
|
ConfigBuilder config = getConfigBuilder(datasource, tableName);
|
||||||
|
List<TableInfo> tableInfoList = config.getTableInfoList();
|
||||||
|
TableInfo tableInfo = null;
|
||||||
|
Iterator<TableInfo> iterator = tableInfoList.stream().filter(table -> table.getName().equals(tableName)).toList().iterator();
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
tableInfo = iterator.next();
|
||||||
|
if (tableName.contains(StringPool.UNDERSCORE)) {
|
||||||
|
String entityPrefix = StringUtil.firstCharToUpper(tableName.split(StringPool.UNDERSCORE)[0]);
|
||||||
|
String entityName = StringUtil.removePrefix(tableInfo.getEntityName(), entityPrefix);
|
||||||
|
tableInfo.setEntityName(entityName);
|
||||||
|
} else {
|
||||||
|
tableInfo.setEntityName(StringUtil.firstCharToUpper(tableName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tableInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigBuilder getConfigBuilder(Datasource datasource, String tableName) {
|
||||||
|
StrategyConfig.Builder builder = new StrategyConfig.Builder();
|
||||||
|
//表前缀过滤,目前官方仅支持一个前缀,可自行修改为sys_或tb_或其他业务表前缀
|
||||||
|
//builder.likeTable(new LikeTable("blade_", SqlLike.RIGHT));
|
||||||
|
if (StringUtil.isNotBlank(tableName)) {
|
||||||
|
builder.addInclude(tableName);
|
||||||
|
}
|
||||||
|
StrategyConfig strategyConfig = builder.entityBuilder()
|
||||||
|
.naming(NamingStrategy.underline_to_camel)
|
||||||
|
.columnNaming(NamingStrategy.underline_to_camel).build();
|
||||||
|
DataSourceConfig datasourceConfig = new DataSourceConfig.Builder(
|
||||||
|
datasource.getUrl(), datasource.getUsername(), datasource.getPassword()
|
||||||
|
).build();
|
||||||
|
return new ConfigBuilder(null, datasourceConfig, strategyConfig, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.develop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Code;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.Model;
|
||||||
|
import org.springblade.modules.develop.pojo.entity.ModelPrototype;
|
||||||
|
import org.springblade.modules.develop.mapper.ModelMapper;
|
||||||
|
import org.springblade.modules.develop.service.ICodeService;
|
||||||
|
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||||
|
import org.springblade.modules.develop.service.IModelService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型表 服务实现类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
//@Master
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ModelServiceImpl extends BaseServiceImpl<ModelMapper, Model> implements IModelService {
|
||||||
|
|
||||||
|
private final IModelPrototypeService modelPrototypeService;
|
||||||
|
private final ICodeService codeService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean delete(List<Long> ids) {
|
||||||
|
boolean modelTemp = this.deleteLogic(ids);
|
||||||
|
if (modelTemp) {
|
||||||
|
if (modelPrototypeService.count(Wrappers.<ModelPrototype>lambdaQuery().in(ModelPrototype::getModelId, ids)) > 0) {
|
||||||
|
boolean prototypeTemp = modelPrototypeService.remove(Wrappers.<ModelPrototype>lambdaQuery().in(ModelPrototype::getModelId, ids));
|
||||||
|
if (!prototypeTemp) {
|
||||||
|
throw new ServiceException("删除数据模型成功,关联数据原型删除失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (codeService.count(Wrappers.<Code>lambdaQuery().in(Code::getModelId, ids)) > 0) {
|
||||||
|
boolean codeTemp = codeService.remove(Wrappers.<Code>lambdaQuery().in(Code::getModelId, ids));
|
||||||
|
if (!codeTemp) {
|
||||||
|
throw new ServiceException("删除数据模型成功,关联代码生成配置删除失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.builder;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.literule.engine.RuleEngineExecutor;
|
||||||
|
import org.springblade.core.literule.provider.LiteRuleResponse;
|
||||||
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
|
import org.springblade.core.oss.OssTemplate;
|
||||||
|
import org.springblade.core.oss.enums.OssEnum;
|
||||||
|
import org.springblade.core.oss.enums.OssStatusEnum;
|
||||||
|
import org.springblade.core.oss.props.OssProperties;
|
||||||
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Oss;
|
||||||
|
import org.springblade.modules.resource.rule.context.OssContext;
|
||||||
|
import org.springblade.modules.resource.service.IOssService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
|
||||||
|
import static org.springblade.modules.resource.rule.constant.OssRuleConstant.OSS_CHAIN_ID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oss云存储统一构建类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class OssBuilder {
|
||||||
|
|
||||||
|
public static final String OSS_CODE = "oss:code:";
|
||||||
|
public static final String OSS_PARAM_KEY = "code";
|
||||||
|
|
||||||
|
private final OssProperties ossProperties;
|
||||||
|
private final IOssService ossService;
|
||||||
|
private final RuleEngineExecutor ruleExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OssTemplate配置缓存池
|
||||||
|
*/
|
||||||
|
private final Map<String, OssTemplate> templatePool = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* oss配置缓存池
|
||||||
|
*/
|
||||||
|
private final Map<String, Oss> ossPool = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @return OssTemplate
|
||||||
|
*/
|
||||||
|
public OssTemplate template() {
|
||||||
|
return template(StringPool.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @param code 资源编号
|
||||||
|
* @return OssTemplate
|
||||||
|
*/
|
||||||
|
public OssTemplate template(String code) {
|
||||||
|
String tenantId = AuthUtil.getTenantId();
|
||||||
|
return template(tenantId, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @param code 资源编号
|
||||||
|
* @return OssTemplate
|
||||||
|
*/
|
||||||
|
public OssTemplate template(String tenantId, String code) {
|
||||||
|
Oss oss = getOss(tenantId, code);
|
||||||
|
|
||||||
|
OssContext ossContext = new OssContext();
|
||||||
|
ossContext.setOss(oss);
|
||||||
|
ossContext.setOssProperties(ossProperties);
|
||||||
|
ossContext.setOssPool(ossPool);
|
||||||
|
ossContext.setTemplatePool(templatePool);
|
||||||
|
|
||||||
|
LiteRuleResponse<OssContext> resp = ruleExecutor.execute(OSS_CHAIN_ID, tenantId, ossContext);
|
||||||
|
if (resp.isSuccess()) {
|
||||||
|
OssContext contextBean = resp.getContext();
|
||||||
|
return contextBean.getOssTemplate();
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("未获取到对应的对象存储配置");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对象存储实体
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @return Oss
|
||||||
|
*/
|
||||||
|
public Oss getOss(String tenantId, String code) {
|
||||||
|
String key = tenantId;
|
||||||
|
LambdaQueryWrapper<Oss> lqw = Wrappers.<Oss>query().lambda().eq(Oss::getTenantId, tenantId);
|
||||||
|
// 获取传参的资源编号并查询,若有则返回,若没有则调启用的配置
|
||||||
|
String ossCode = StringUtil.isBlank(code) ? WebUtil.getParameter(OSS_PARAM_KEY) : code;
|
||||||
|
if (StringUtil.isNotBlank(ossCode)) {
|
||||||
|
key = key.concat(StringPool.DASH).concat(ossCode);
|
||||||
|
lqw.eq(Oss::getOssCode, ossCode);
|
||||||
|
} else {
|
||||||
|
lqw.eq(Oss::getStatus, OssStatusEnum.ENABLE.getNum());
|
||||||
|
}
|
||||||
|
Oss oss = CacheUtil.get(RESOURCE_CACHE, OSS_CODE, key, () -> {
|
||||||
|
Oss o = ossService.getOne(lqw);
|
||||||
|
// 若为空则调用默认配置
|
||||||
|
if (o == null || o.getId() == null) {
|
||||||
|
Oss defaultOss = new Oss();
|
||||||
|
defaultOss.setId(0L);
|
||||||
|
defaultOss.setCategory(OssEnum.of(ossProperties.getName()).getCategory());
|
||||||
|
defaultOss.setEndpoint(ossProperties.getEndpoint());
|
||||||
|
defaultOss.setTransformEndpoint(ossProperties.getTransformEndpoint());
|
||||||
|
defaultOss.setBucketName(ossProperties.getBucketName());
|
||||||
|
defaultOss.setAccessKey(ossProperties.getAccessKey());
|
||||||
|
defaultOss.setSecretKey(ossProperties.getSecretKey());
|
||||||
|
return defaultOss;
|
||||||
|
} else {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (oss == null || oss.getId() == null) {
|
||||||
|
throw new ServiceException("未获取到对应的对象存储配置");
|
||||||
|
} else {
|
||||||
|
return oss;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.builder;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.literule.engine.RuleEngineExecutor;
|
||||||
|
import org.springblade.core.literule.provider.LiteRuleResponse;
|
||||||
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
|
import org.springblade.core.sms.SmsTemplate;
|
||||||
|
import org.springblade.core.sms.enums.SmsEnum;
|
||||||
|
import org.springblade.core.sms.enums.SmsStatusEnum;
|
||||||
|
import org.springblade.core.sms.props.SmsProperties;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Sms;
|
||||||
|
import org.springblade.modules.resource.rule.context.SmsContext;
|
||||||
|
import org.springblade.modules.resource.service.ISmsService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
|
||||||
|
import static org.springblade.modules.resource.rule.constant.SmsRuleConstant.SMS_CHAIN_ID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sms短信服务统一构建类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SmsBuilder {
|
||||||
|
|
||||||
|
public static final String SMS_CODE = "sms:code:";
|
||||||
|
public static final String SMS_PARAM_KEY = "code";
|
||||||
|
|
||||||
|
private final SmsProperties smsProperties;
|
||||||
|
private final ISmsService smsService;
|
||||||
|
private final BladeRedis bladeRedis;
|
||||||
|
private final RuleEngineExecutor ruleExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmsTemplate配置缓存池
|
||||||
|
*/
|
||||||
|
private final Map<String, SmsTemplate> templatePool = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sms配置缓存池
|
||||||
|
*/
|
||||||
|
private final Map<String, Sms> smsPool = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @return SmsTemplate
|
||||||
|
*/
|
||||||
|
public SmsTemplate template() {
|
||||||
|
return template(StringPool.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @param code 资源编号
|
||||||
|
* @return SmsTemplate
|
||||||
|
*/
|
||||||
|
public SmsTemplate template(String code) {
|
||||||
|
String tenantId = AuthUtil.getTenantId();
|
||||||
|
return template(tenantId, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取template
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @param code 资源编号
|
||||||
|
* @return SmsTemplate
|
||||||
|
*/
|
||||||
|
public SmsTemplate template(String tenantId, String code) {
|
||||||
|
Sms sms = getSms(tenantId, code);
|
||||||
|
|
||||||
|
SmsContext smsContext = new SmsContext();
|
||||||
|
smsContext.setSms(sms);
|
||||||
|
smsContext.setSmsProperties(smsProperties);
|
||||||
|
smsContext.setSmsPool(smsPool);
|
||||||
|
smsContext.setTemplatePool(templatePool);
|
||||||
|
smsContext.setBladeRedis(bladeRedis);
|
||||||
|
|
||||||
|
LiteRuleResponse<SmsContext> resp = ruleExecutor.execute(SMS_CHAIN_ID, tenantId, smsContext);
|
||||||
|
if (resp.isSuccess()) {
|
||||||
|
SmsContext contextBean = resp.getContext();
|
||||||
|
return contextBean.getSmsTemplate();
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("未获取到对应的短信配置");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取短信实体
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @return Sms
|
||||||
|
*/
|
||||||
|
public Sms getSms(String tenantId, String code) {
|
||||||
|
String key = tenantId;
|
||||||
|
LambdaQueryWrapper<Sms> lqw = Wrappers.<Sms>query().lambda().eq(Sms::getTenantId, tenantId);
|
||||||
|
// 获取传参的资源编号并查询,若有则返回,若没有则调启用的配置
|
||||||
|
String smsCode = StringUtil.isBlank(code) ? WebUtil.getParameter(SMS_PARAM_KEY) : code;
|
||||||
|
if (StringUtil.isNotBlank(smsCode)) {
|
||||||
|
key = key.concat(StringPool.DASH).concat(smsCode);
|
||||||
|
lqw.eq(Sms::getSmsCode, smsCode);
|
||||||
|
} else {
|
||||||
|
lqw.eq(Sms::getStatus, SmsStatusEnum.ENABLE.getNum());
|
||||||
|
}
|
||||||
|
Sms sms = CacheUtil.get(RESOURCE_CACHE, SMS_CODE, key, () -> {
|
||||||
|
Sms s = smsService.getOne(lqw);
|
||||||
|
// 若为空则调用默认配置
|
||||||
|
if (s == null || s.getId() == null) {
|
||||||
|
Sms defaultSms = new Sms();
|
||||||
|
defaultSms.setId(0L);
|
||||||
|
defaultSms.setTemplateId(smsProperties.getTemplateId());
|
||||||
|
defaultSms.setRegionId(smsProperties.getRegionId());
|
||||||
|
defaultSms.setCategory(SmsEnum.of(smsProperties.getName()).getCategory());
|
||||||
|
defaultSms.setAccessKey(smsProperties.getAccessKey());
|
||||||
|
defaultSms.setSecretKey(smsProperties.getSecretKey());
|
||||||
|
defaultSms.setSignName(smsProperties.getSignName());
|
||||||
|
return defaultSms;
|
||||||
|
} else {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (sms == null || sms.getId() == null) {
|
||||||
|
throw new ServiceException("未获取到对应的短信配置");
|
||||||
|
} else {
|
||||||
|
return sms;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.literule.engine.RuleEngineExecutor;
|
||||||
|
import org.springblade.core.oss.props.OssProperties;
|
||||||
|
import org.springblade.modules.resource.builder.OssBuilder;
|
||||||
|
import org.springblade.modules.resource.service.IOssService;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oss配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladeOssConfiguration {
|
||||||
|
|
||||||
|
private final OssProperties ossProperties;
|
||||||
|
|
||||||
|
private final IOssService ossService;
|
||||||
|
|
||||||
|
private final RuleEngineExecutor ruleExecutor;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OssBuilder ossBuilder() {
|
||||||
|
return new OssBuilder(ossProperties, ossService, ruleExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.literule.engine.RuleEngineExecutor;
|
||||||
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.sms.props.SmsProperties;
|
||||||
|
import org.springblade.modules.resource.builder.SmsBuilder;
|
||||||
|
import org.springblade.modules.resource.service.ISmsService;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sms配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladeSmsConfiguration {
|
||||||
|
|
||||||
|
private final SmsProperties smsProperties;
|
||||||
|
|
||||||
|
private final ISmsService smsService;
|
||||||
|
|
||||||
|
private final BladeRedis bladeRedis;
|
||||||
|
|
||||||
|
private final RuleEngineExecutor ruleExecutor;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SmsBuilder smsBuilder() {
|
||||||
|
return new SmsBuilder(smsProperties, smsService, bladeRedis, ruleExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdmin;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Attach;
|
||||||
|
import org.springblade.modules.resource.pojo.vo.AttachVO;
|
||||||
|
import org.springblade.modules.resource.service.IAttachService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件表 控制器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdmin
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/attach")
|
||||||
|
@Tag(name = "附件", description = "附件")
|
||||||
|
public class AttachController extends BladeController {
|
||||||
|
|
||||||
|
private final IAttachService attachService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入attach")
|
||||||
|
public R<Attach> detail(Attach attach) {
|
||||||
|
Attach detail = attachService.getOne(Condition.getQueryWrapper(attach));
|
||||||
|
return R.data(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页 附件表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入attach")
|
||||||
|
public R<IPage<Attach>> list(Attach attach, Query query) {
|
||||||
|
IPage<Attach> pages = attachService.page(Condition.getPage(query), Condition.getQueryWrapper(attach));
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页 附件表
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "分页", description = "传入attach")
|
||||||
|
public R<IPage<AttachVO>> page(AttachVO attach, Query query) {
|
||||||
|
IPage<AttachVO> pages = attachService.selectAttachPage(Condition.getPage(query), attach);
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 附件表
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入attach")
|
||||||
|
public R save(@Valid @RequestBody Attach attach) {
|
||||||
|
return R.status(attachService.save(attach));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 附件表
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入attach")
|
||||||
|
public R update(@Valid @RequestBody Attach attach) {
|
||||||
|
return R.status(attachService.updateById(attach));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改 附件表
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入attach")
|
||||||
|
public R submit(@Valid @RequestBody Attach attach) {
|
||||||
|
return R.status(attachService.saveOrUpdate(attach));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 附件表
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
return R.status(attachService.deleteLogic(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdmin;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Oss;
|
||||||
|
import org.springblade.modules.resource.pojo.vo.OssVO;
|
||||||
|
import org.springblade.modules.resource.service.IOssService;
|
||||||
|
import org.springblade.modules.resource.wrapper.OssWrapper;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@Hidden
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdmin
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/oss")
|
||||||
|
@Tag(name = "对象存储接口", description = "对象存储接口")
|
||||||
|
public class OssController extends BladeController {
|
||||||
|
|
||||||
|
private final IOssService ossService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入oss")
|
||||||
|
public R<OssVO> detail(Oss oss) {
|
||||||
|
Oss detail = ossService.getOne(Condition.getQueryWrapper(oss));
|
||||||
|
return R.data(OssWrapper.build().entityVO(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入oss")
|
||||||
|
public R<IPage<OssVO>> list(Oss oss, Query query) {
|
||||||
|
IPage<Oss> pages = ossService.page(Condition.getPage(query), Condition.getQueryWrapper(oss));
|
||||||
|
return R.data(OssWrapper.build().pageVO(pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "分页", description = "传入oss")
|
||||||
|
public R<IPage<OssVO>> page(OssVO oss, Query query) {
|
||||||
|
IPage<OssVO> pages = ossService.selectOssPage(Condition.getPage(query), oss);
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入oss")
|
||||||
|
public R save(@Valid @RequestBody Oss oss) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(ossService.save(oss));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入oss")
|
||||||
|
public R update(@Valid @RequestBody Oss oss) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(ossService.updateById(oss));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入oss")
|
||||||
|
public R submit(@Valid @RequestBody Oss oss) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(ossService.submit(oss));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(ossService.deleteLogic(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用
|
||||||
|
*/
|
||||||
|
@PostMapping("/enable")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "配置启用", description = "传入id")
|
||||||
|
public R enable(@Parameter(description = "主键", required = true) @RequestParam Long id) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(ossService.enable(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springblade.core.boot.ctrl.BladeController;
|
||||||
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.mp.support.Condition;
|
||||||
|
import org.springblade.core.mp.support.Query;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdmin;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Sms;
|
||||||
|
import org.springblade.modules.resource.pojo.vo.SmsVO;
|
||||||
|
import org.springblade.modules.resource.service.ISmsService;
|
||||||
|
import org.springblade.modules.resource.wrapper.SmsWrapper;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信配置表 控制器
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@Hidden
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@IsAdmin
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/sms")
|
||||||
|
@Tag(name = "短信配置表", description = "短信配置表接口")
|
||||||
|
public class SmsController extends BladeController {
|
||||||
|
|
||||||
|
private final ISmsService smsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
@ApiOperationSupport(order = 1)
|
||||||
|
@Operation(summary = "详情", description = "传入sms")
|
||||||
|
public R<SmsVO> detail(Sms sms) {
|
||||||
|
Sms detail = smsService.getOne(Condition.getQueryWrapper(sms));
|
||||||
|
return R.data(SmsWrapper.build().entityVO(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页 短信配置表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperationSupport(order = 2)
|
||||||
|
@Operation(summary = "分页", description = "传入sms")
|
||||||
|
public R<IPage<SmsVO>> list(Sms sms, Query query) {
|
||||||
|
IPage<Sms> pages = smsService.page(Condition.getPage(query), Condition.getQueryWrapper(sms));
|
||||||
|
return R.data(SmsWrapper.build().pageVO(pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页 短信配置表
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
@Operation(summary = "分页", description = "传入sms")
|
||||||
|
public R<IPage<SmsVO>> page(SmsVO sms, Query query) {
|
||||||
|
IPage<SmsVO> pages = smsService.selectSmsPage(Condition.getPage(query), sms);
|
||||||
|
return R.data(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增 短信配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperationSupport(order = 4)
|
||||||
|
@Operation(summary = "新增", description = "传入sms")
|
||||||
|
public R save(@Valid @RequestBody Sms sms) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(smsService.save(sms));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 短信配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "修改", description = "传入sms")
|
||||||
|
public R update(@Valid @RequestBody Sms sms) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(smsService.updateById(sms));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改 短信配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@Operation(summary = "新增或修改", description = "传入sms")
|
||||||
|
public R submit(@Valid @RequestBody Sms sms) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(smsService.submit(sms));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 短信配置表
|
||||||
|
*/
|
||||||
|
@PostMapping("/remove")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||||
|
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(smsService.deleteLogic(Func.toLongList(ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用
|
||||||
|
*/
|
||||||
|
@PostMapping("/enable")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
@Operation(summary = "配置启用", description = "传入id")
|
||||||
|
public R enable(@Parameter(description = "主键", required = true) @RequestParam Long id) {
|
||||||
|
CacheUtil.clear(RESOURCE_CACHE);
|
||||||
|
return R.status(smsService.enable(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.endpoint;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.oss.model.BladeFile;
|
||||||
|
import org.springblade.core.oss.model.OssFile;
|
||||||
|
import org.springblade.core.secure.annotation.IsAdmin;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.utils.FileUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.resource.builder.OssBuilder;
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Attach;
|
||||||
|
import org.springblade.modules.resource.service.IAttachService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储端点
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "对象存储端点", description = "对象存储端点")
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/oss/endpoint")
|
||||||
|
public class OssEndpoint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储构建类
|
||||||
|
*/
|
||||||
|
private final OssBuilder ossBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件表服务
|
||||||
|
*/
|
||||||
|
private final IAttachService attachService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建存储桶
|
||||||
|
*
|
||||||
|
* @param bucketName 存储桶名称
|
||||||
|
* @return Bucket
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@IsAdmin
|
||||||
|
@PostMapping("/make-bucket")
|
||||||
|
public R makeBucket(@RequestParam String bucketName) {
|
||||||
|
ossBuilder.template().makeBucket(bucketName);
|
||||||
|
return R.success("创建成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建存储桶
|
||||||
|
*
|
||||||
|
* @param bucketName 存储桶名称
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@IsAdmin
|
||||||
|
@PostMapping("/remove-bucket")
|
||||||
|
public R removeBucket(@RequestParam String bucketName) {
|
||||||
|
ossBuilder.template().removeBucket(bucketName);
|
||||||
|
return R.success("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拷贝文件
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @param destBucketName 目标存储桶名称
|
||||||
|
* @param destFileName 目标存储桶对象名称
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/copy-file")
|
||||||
|
public R copyFile(@RequestParam String fileName, @RequestParam String destBucketName, String destFileName) {
|
||||||
|
ossBuilder.template().copyFile(fileName, destBucketName, destFileName);
|
||||||
|
return R.success("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件信息
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @return InputStream
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@GetMapping("/stat-file")
|
||||||
|
public R<OssFile> statFile(@RequestParam String fileName) {
|
||||||
|
return R.data(ossBuilder.template().statFile(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件相对路径
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@GetMapping("/file-path")
|
||||||
|
public R<String> filePath(@RequestParam String fileName) {
|
||||||
|
return R.data(ossBuilder.template().filePath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件外链
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@GetMapping("/file-link")
|
||||||
|
public R<String> fileLink(@RequestParam String fileName) {
|
||||||
|
return R.data(ossBuilder.template().fileLink(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return ObjectStat
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/put-file")
|
||||||
|
public R<BladeFile> putFile(@RequestParam MultipartFile file) {
|
||||||
|
BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
|
||||||
|
return R.data(bladeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @param file 文件
|
||||||
|
* @return ObjectStat
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/put-file-by-name")
|
||||||
|
public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) {
|
||||||
|
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
|
||||||
|
return R.data(bladeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件并保存至附件表
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return ObjectStat
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/put-file-attach")
|
||||||
|
public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) {
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
|
||||||
|
Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
|
||||||
|
bladeFile.setAttachId(attachId);
|
||||||
|
return R.data(bladeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件并保存至附件表
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @param file 文件
|
||||||
|
* @return ObjectStat
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/put-file-attach-by-name")
|
||||||
|
public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) {
|
||||||
|
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
|
||||||
|
Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
|
||||||
|
bladeFile.setAttachId(attachId);
|
||||||
|
return R.data(bladeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建附件表
|
||||||
|
*
|
||||||
|
* @param fileName 文件名
|
||||||
|
* @param fileSize 文件大小
|
||||||
|
* @param bladeFile 对象存储文件
|
||||||
|
* @return attachId
|
||||||
|
*/
|
||||||
|
private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile) {
|
||||||
|
String fileExtension = FileUtil.getFileExtension(fileName);
|
||||||
|
Attach attach = new Attach();
|
||||||
|
attach.setDomainUrl(bladeFile.getDomain());
|
||||||
|
attach.setLink(bladeFile.getLink());
|
||||||
|
attach.setName(bladeFile.getName());
|
||||||
|
attach.setOriginalName(bladeFile.getOriginalName());
|
||||||
|
attach.setAttachSize(fileSize);
|
||||||
|
attach.setExtension(fileExtension);
|
||||||
|
attachService.save(attach);
|
||||||
|
return attach.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
*
|
||||||
|
* @param fileName 存储桶对象名称
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@IsAdmin
|
||||||
|
@PostMapping("/remove-file")
|
||||||
|
public R removeFile(@RequestParam String fileName) {
|
||||||
|
ossBuilder.template().removeFile(fileName);
|
||||||
|
return R.success("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除文件
|
||||||
|
*
|
||||||
|
* @param fileNames 存储桶对象名称集合
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@IsAdmin
|
||||||
|
@PostMapping("/remove-files")
|
||||||
|
public R removeFiles(@RequestParam String fileNames) {
|
||||||
|
ossBuilder.template().removeFiles(Func.toStrList(fileNames));
|
||||||
|
return R.success("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.endpoint;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
|
import org.springblade.core.sms.model.SmsCode;
|
||||||
|
import org.springblade.core.sms.model.SmsData;
|
||||||
|
import org.springblade.core.sms.model.SmsResponse;
|
||||||
|
import org.springblade.core.tenant.annotation.NonDS;
|
||||||
|
import org.springblade.core.tool.api.R;
|
||||||
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
|
import org.springblade.core.tool.utils.Func;
|
||||||
|
import org.springblade.modules.resource.builder.SmsBuilder;
|
||||||
|
import org.springblade.modules.resource.utils.SmsUtil;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springblade.modules.resource.utils.SmsUtil.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信服务端点
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@NonDS
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/sms/endpoint")
|
||||||
|
@Tag(name = "短信服务端点", description = "短信服务端点")
|
||||||
|
public class SmsEndpoint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信服务构建类
|
||||||
|
*/
|
||||||
|
private final SmsBuilder smsBuilder;
|
||||||
|
|
||||||
|
//================================= 短信服务校验 =================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码发送
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/send-validate")
|
||||||
|
public R sendValidate(@RequestParam String phone) {
|
||||||
|
Map<String, String> params = SmsUtil.getValidateParams();
|
||||||
|
SmsCode smsCode = smsBuilder.template().sendValidate(new SmsData(params).setKey(PARAM_KEY), phone);
|
||||||
|
return smsCode.isSuccess() ? R.data(smsCode, SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验短信
|
||||||
|
*
|
||||||
|
* @param smsCode 短信校验信息
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/validate-message")
|
||||||
|
public R validateMessage(SmsCode smsCode) {
|
||||||
|
boolean validate = smsBuilder.template().validateMessage(smsCode);
|
||||||
|
return validate ? R.success(VALIDATE_SUCCESS) : R.fail(VALIDATE_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//========== 通用短信自定义发送(支持自定义params参数传递, 推荐用于测试, 不推荐用于生产环境) ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送信息
|
||||||
|
*
|
||||||
|
* @param code 资源编号
|
||||||
|
* @param params 自定义短信参数
|
||||||
|
* @param phones 手机号集合
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/send-message")
|
||||||
|
public R sendMessage(@RequestParam String code, @RequestParam String params, @RequestParam String phones) {
|
||||||
|
SmsData smsData = new SmsData(JsonUtil.readMap(params, String.class, String.class));
|
||||||
|
return send(code, smsData, phones);
|
||||||
|
}
|
||||||
|
|
||||||
|
//========== 指定短信服务发送(可根据各种场景自定拓展定制, 损失灵活性增加安全性, 推荐用于生产环境) ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信通知
|
||||||
|
*
|
||||||
|
* @param phones 手机号集合
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/send-notice")
|
||||||
|
public R sendNotice(@RequestParam String phones) {
|
||||||
|
Map<String, String> params = new HashMap<>(3);
|
||||||
|
params.put("title", "通知标题");
|
||||||
|
params.put("content", "通知内容");
|
||||||
|
params.put("date", "通知时间");
|
||||||
|
SmsData smsData = new SmsData(params);
|
||||||
|
return send(smsData, phones);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单通知
|
||||||
|
*
|
||||||
|
* @param phones 手机号集合
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/send-order")
|
||||||
|
public R sendOrder(@RequestParam String phones) {
|
||||||
|
Map<String, String> params = new HashMap<>(3);
|
||||||
|
params.put("orderNo", "订单编号");
|
||||||
|
params.put("packageNo", "快递单号");
|
||||||
|
params.put("user", "收件人");
|
||||||
|
SmsData smsData = new SmsData(params);
|
||||||
|
return send(smsData, phones);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会议通知
|
||||||
|
*
|
||||||
|
* @param phones 手机号集合
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("/send-meeting")
|
||||||
|
public R sendMeeting(@RequestParam String phones) {
|
||||||
|
Map<String, String> params = new HashMap<>(2);
|
||||||
|
params.put("roomId", "会议室");
|
||||||
|
params.put("topic", "会议主题");
|
||||||
|
params.put("date", "会议时间");
|
||||||
|
SmsData smsData = new SmsData(params);
|
||||||
|
return send(smsData, phones);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================= 通用短信发送接口 =================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用短信发送接口
|
||||||
|
*
|
||||||
|
* @param smsData 短信内容
|
||||||
|
* @param phones 手机号列表
|
||||||
|
* @return 是否发送成功
|
||||||
|
*/
|
||||||
|
private R send(SmsData smsData, String phones) {
|
||||||
|
SmsResponse response = smsBuilder.template().sendMessage(smsData, Func.toStrList(phones));
|
||||||
|
return response.isSuccess() ? R.success(SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用短信发送接口
|
||||||
|
*
|
||||||
|
* @param code 资源编号
|
||||||
|
* @param smsData 短信内容
|
||||||
|
* @param phones 手机号列表
|
||||||
|
* @return 是否发送成功
|
||||||
|
*/
|
||||||
|
private R send(String code, SmsData smsData, String phones) {
|
||||||
|
SmsResponse response = smsBuilder.template(code).sendMessage(smsData, Func.toStrList(phones));
|
||||||
|
return response.isSuccess() ? R.success(SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.resource.mapper;
|
||||||
|
|
||||||
|
import org.springblade.modules.resource.pojo.entity.Attach;
|
||||||
|
import org.springblade.modules.resource.pojo.vo.AttachVO;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件表 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface AttachMapper extends BaseMapper<Attach> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义分页
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
|
* @param attach
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<AttachVO> selectAttachPage(IPage page, AttachVO attach);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.springblade.modules.resource.mapper.AttachMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="attachResultMap" type="org.springblade.modules.resource.pojo.entity.Attach">
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="create_user" property="createUser"/>
|
||||||
|
<result column="create_dept" property="createDept"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_user" property="updateUser"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="status" property="status"/>
|
||||||
|
<result column="is_deleted" property="isDeleted"/>
|
||||||
|
<result column="link" property="link"/>
|
||||||
|
<result column="domain_url" property="domainUrl"/>
|
||||||
|
<result column="name" property="name"/>
|
||||||
|
<result column="original_name" property="originalName"/>
|
||||||
|
<result column="extension" property="extension"/>
|
||||||
|
<result column="attach_size" property="attachSize"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectAttachPage" resultMap="attachResultMap">
|
||||||
|
select * from blade_attach where is_deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user