init
This commit is contained in:
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# maven #
|
||||
target
|
||||
|
||||
logs
|
||||
|
||||
# windows #
|
||||
Thumbs.db
|
||||
|
||||
# Mac #
|
||||
.DS_Store
|
||||
|
||||
# eclipse #
|
||||
.settings
|
||||
.project
|
||||
.classpath
|
||||
.log
|
||||
*.class
|
||||
|
||||
# idea #
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
/target
|
||||
397
pom.xml
Normal file
397
pom.xml
Normal file
@@ -0,0 +1,397 @@
|
||||
<?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>3.0.1.RELEASE</version>
|
||||
|
||||
<properties>
|
||||
<bladex.project.id>zyp-admin-api</bladex.project.id>
|
||||
<bladex.project.version>3.0.1.RELEASE</bladex.project.version>
|
||||
|
||||
<java.version>1.8</java.version>
|
||||
<maven.plugin.version>3.8.1</maven.plugin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<spring.boot.version>2.7.1</spring.boot.version>
|
||||
<spring.platform.version>Cairo-SR8</spring.platform.version>
|
||||
<thumbnail.version>0.4.13</thumbnail.version>
|
||||
<shardingsphere.version>5.2.1</shardingsphere.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<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.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spring.platform</groupId>
|
||||
<artifactId>platform-bom</artifactId>
|
||||
<version>${spring.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- Blade -->
|
||||
<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>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-http</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-api-crypto</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-datascope</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-tenant</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-develop</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-swagger</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-excel</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-social</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-auto</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-test</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- 报表 -->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-report</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<!-- 验证码 -->
|
||||
<dependency>
|
||||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
</dependency>
|
||||
<!-- Mybatis-Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Oss-->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-oss</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</dependency>
|
||||
<!--Sms-->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-sms</artifactId>
|
||||
<version>${bladex.project.version}</version>
|
||||
</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>
|
||||
<!--腾讯COS-->
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
</dependency>
|
||||
<!--腾讯SMS-->
|
||||
<dependency>
|
||||
<groupId>com.github.qcloudsms</groupId>
|
||||
<artifactId>qcloudsms</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>
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- mapstruct -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.5.3.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.3.Final</version>
|
||||
</dependency>
|
||||
<!-- elasticsearch -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
<!-- json-api -->
|
||||
<dependency>
|
||||
<groupId>jakarta.json</groupId>
|
||||
<artifactId>jakarta.json-api</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
<!-- 图片压缩 -->
|
||||
<dependency>
|
||||
<groupId>com.sonsure</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>${thumbnail.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dynamic-datasource -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- sharding-jdbc -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||
<version>${shardingsphere.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-easysdk</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.wechatpay-apiv3</groupId>
|
||||
<artifactId>wechatpay-java</artifactId>
|
||||
<version>0.2.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fadada.api</groupId>
|
||||
<artifactId>fasc-openapi-java-sdk</artifactId>
|
||||
<version>5.2.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-reload4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>snack3</artifactId>
|
||||
<version>3.2.72</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>1.5.30</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.xuxueli/xxl-job-core -->
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.11</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
<version>4.0.2.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-mqtt</artifactId>
|
||||
<version>5.0.6.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel-core</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.hutool</groupId>-->
|
||||
<!-- <artifactId>hutool-all</artifactId>-->
|
||||
<!-- <version>5.8.8</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fly</groupId>
|
||||
<artifactId>fly-tool-jsonParse</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>cloudauth20190307</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</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>${spring.boot.version}</version>
|
||||
<configuration>
|
||||
<finalName>${project.build.finalName}</finalName>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</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>
|
||||
<url>https://maven.aliyun.com/repository/public/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>aliyun-plugin</id>
|
||||
<url>https://maven.aliyun.com/repository/public/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
||||
25
src/main/java/org/springblade/Application.java
Normal file
25
src/main/java/org/springblade/Application.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package org.springblade;
|
||||
|
||||
import org.springblade.common.constant.CommonConstant;
|
||||
import org.springblade.core.launch.BladeApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* 启动器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
//@EnableScheduling
|
||||
@EnableAsync
|
||||
@EnableCaching
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BladeApplication.run(CommonConstant.APPLICATION_NAME, Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
61
src/main/java/org/springblade/common/cache/CacheNames.java
vendored
Normal file
61
src/main/java/org/springblade/common/cache/CacheNames.java
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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 USER_FAIL_KEY = "blade:user::blade:fail:";
|
||||
|
||||
}
|
||||
116
src/main/java/org/springblade/common/cache/DictBizCache.java
vendored
Normal file
116
src/main/java/org/springblade/common/cache/DictBizCache.java
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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));
|
||||
}
|
||||
|
||||
}
|
||||
143
src/main/java/org/springblade/common/cache/DictCache.java
vendored
Normal file
143
src/main/java/org/springblade/common/cache/DictCache.java
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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);
|
||||
}
|
||||
|
||||
}
|
||||
62
src/main/java/org/springblade/common/cache/ParamCache.java
vendored
Normal file
62
src/main/java/org/springblade/common/cache/ParamCache.java
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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));
|
||||
}
|
||||
|
||||
}
|
||||
56
src/main/java/org/springblade/common/cache/RegionCache.java
vendored
Normal file
56
src/main/java/org/springblade/common/cache/RegionCache.java
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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 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));
|
||||
}
|
||||
|
||||
}
|
||||
317
src/main/java/org/springblade/common/cache/SysCache.java
vendored
Normal file
317
src/main/java/org/springblade/common/cache/SysCache.java
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
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.entity.*;
|
||||
import org.springblade.modules.system.service.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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, () -> tenantService.getById(id), Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @return Tenant
|
||||
*/
|
||||
public static Tenant getTenant(String tenantId) {
|
||||
return CacheUtil.get(SYS_CACHE, TENANT_TENANT_ID, tenantId, () -> tenantService.getByTenantId(tenantId), 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);
|
||||
}
|
||||
|
||||
}
|
||||
77
src/main/java/org/springblade/common/cache/UserCache.java
vendored
Normal file
77
src/main/java/org/springblade/common/cache/UserCache.java
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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,169 @@
|
||||
package org.springblade.common.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 异步线程池配置(不同业务之间线程池隔离)
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AsyncConfiguration {
|
||||
private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
private static final int MAX_POOL_SIZE = CORE_POOL_SIZE * 2;
|
||||
private static final int QUEUE_CAPACITY = 500;
|
||||
private static final int KEEP_ALIVE_SECONDS = 60;
|
||||
private static final int AWAIT_TERMINATION_SECONDS = 60;
|
||||
|
||||
@Bean("common")
|
||||
public AsyncTaskExecutor commonAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("common-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("spuAsyncExecutor")
|
||||
public AsyncTaskExecutor spuAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("SPU-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("skuAsyncExecutor")
|
||||
public AsyncTaskExecutor skuAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("SKU-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@Bean("ossAsyncExecutor")
|
||||
public AsyncTaskExecutor ossAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("OSS-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("categoryAsyncExecutor")
|
||||
public AsyncTaskExecutor categoryAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("CATE-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@Bean("jsonParseAsyncExecutor")
|
||||
public AsyncTaskExecutor jsonParseAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
//核心线程数 cpuNum:线程池创建时候初始化的线程数
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
//缓冲队列500:用来缓冲执行任务的队列
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
//允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
|
||||
executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
|
||||
// CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
|
||||
//当提交的任务个数大于QueueCapacity,就需要设置该参数,但spring提供的都不太满足业务场景,可以自定义一个,也可以注意不要超过QueueCapacity即可
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//调度器shutdown被调用时等待当前被调度的任务完成
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//等待时长
|
||||
executor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
|
||||
//线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
|
||||
executor.setThreadNamePrefix("CATE-Async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.config;
|
||||
|
||||
|
||||
import org.springblade.core.secure.registry.SecureRegistry;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Blade配置
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class BladeConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 安全框架配置
|
||||
*/
|
||||
@Bean
|
||||
public SecureRegistry secureRegistry() {
|
||||
SecureRegistry secureRegistry = new SecureRegistry();
|
||||
secureRegistry.setEnabled(true);
|
||||
secureRegistry.excludePathPatterns("/blade-auth/**");
|
||||
secureRegistry.excludePathPatterns("/`blade-system/menu/routes`");
|
||||
secureRegistry.excludePathPatterns("/blade-system/menu/auth-routes");
|
||||
secureRegistry.excludePathPatterns("/blade-system/menu/top-menu");
|
||||
secureRegistry.excludePathPatterns("/blade-system/tenant/info");
|
||||
secureRegistry.excludePathPatterns("/blade-system/test/**");
|
||||
secureRegistry.excludePathPatterns("/doc.html");
|
||||
secureRegistry.excludePathPatterns("/js/**");
|
||||
secureRegistry.excludePathPatterns("/webjars/**");
|
||||
secureRegistry.excludePathPatterns("/swagger-resources/**");
|
||||
secureRegistry.excludePathPatterns("/druid/**");
|
||||
secureRegistry.excludePathPatterns("/erp/oauth/**");
|
||||
secureRegistry.excludePathPatterns("/erp/syncUser/vip");
|
||||
secureRegistry.excludePathPatterns("/fresh/mqtt/sub");
|
||||
secureRegistry.excludePathPatterns("/fresh/mqtt/sendTopic");
|
||||
secureRegistry.excludePathPatterns("/sync/order/**");
|
||||
secureRegistry.excludePathPatterns("/sync/base/**");
|
||||
secureRegistry.excludePathPatterns("/version/current-version");
|
||||
secureRegistry.excludePathPatterns("/version/current-terminal-version");
|
||||
secureRegistry.excludePathPatterns("/owner-static/city-list");
|
||||
secureRegistry.excludePathPatterns("/wiwibao/callback/**");
|
||||
return secureRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/cors/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedHeaders("*")
|
||||
.allowedMethods("*")
|
||||
.maxAge(3600)
|
||||
.allowCredentials(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
|
||||
package org.springblade.common.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.listener.ApiLogListener;
|
||||
import org.springblade.common.listener.ErrorLogListener;
|
||||
import org.springblade.common.listener.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,43 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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,45 @@
|
||||
package org.springblade.common.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* @author ganwu
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfiguration {
|
||||
@Bean("redisServiceTemplate")
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
//由于源码autoConfig中是<Object, Object>,开发中一般直接使用<String,Object>
|
||||
RedisTemplate<String, Object> template = new RedisTemplate();
|
||||
template.setConnectionFactory(factory);
|
||||
|
||||
//Json序列化配置
|
||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
|
||||
//String的序列化
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
|
||||
//key采用string的序列化
|
||||
template.setKeySerializer(stringRedisSerializer);
|
||||
//hash的key采用string的序列化
|
||||
template.setHashKeySerializer(stringRedisSerializer);
|
||||
//value序列化采用jackson
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
//hash的value序列化方式采用jackson
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.swagger.EnableSwagger;
|
||||
import org.springblade.core.swagger.SwaggerProperties;
|
||||
import org.springblade.core.swagger.SwaggerUtil;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.RequestHandler;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Swagger配置类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableSwagger
|
||||
@AllArgsConstructor
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
/**
|
||||
* 引入swagger配置类
|
||||
*/
|
||||
private final SwaggerProperties swaggerProperties;
|
||||
|
||||
/**
|
||||
* 引入Knife4j扩展类
|
||||
*/
|
||||
private final OpenApiExtensionResolver openApiExtensionResolver;
|
||||
|
||||
// @Bean
|
||||
// public Docket authDocket() {
|
||||
// return docket("授权模块", Collections.singletonList(AppConstant.BASE_PACKAGES + ".modules.auth"));
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public Docket sysDocket() {
|
||||
// return docket("系统模块",
|
||||
// Arrays.asList(AppConstant.BASE_PACKAGES + ".modules.system", AppConstant.BASE_PACKAGES + ".modules.resource"));
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public Docket flowDocket() {
|
||||
// return docket("工作流模块", Collections.singletonList(AppConstant.BASE_PACKAGES + ".flow"));
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public Docket sysErp() {
|
||||
// return docket("生鲜客户端模块",
|
||||
// Arrays.asList(AppConstant.BASE_PACKAGES + ".modules.erp.controller"));
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public Docket restDocket() {
|
||||
// return docket("全部模块",
|
||||
// RequestHandlerSelectors.withClassAnnotation(Api.class),PathSelectors.any());
|
||||
// }
|
||||
|
||||
// private Docket docket(String groupName, List<String> basePackages) {
|
||||
// return docket(groupName, SwaggerUtil.basePackages(basePackages), PathSelectors.any());
|
||||
// }
|
||||
|
||||
// private Docket docket(String groupName, Predicate<RequestHandler> handler, Predicate<String> predicate) {
|
||||
// return new Docket(DocumentationType.SWAGGER_2)
|
||||
// .groupName(groupName)
|
||||
// .apiInfo(apiInfo())
|
||||
// .ignoredParameterTypes(BladeUser.class)
|
||||
// .select()
|
||||
// .apis(handler)
|
||||
// .paths(predicate)
|
||||
// .build().securityContexts(securityContexts()).securitySchemes(securitySchemas())
|
||||
// .extensions(openApiExtensionResolver.buildExtensions(groupName));
|
||||
// }
|
||||
|
||||
private List<SecurityContext> securityContexts() {
|
||||
return Collections.singletonList(SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex("^.*$"))
|
||||
.build());
|
||||
}
|
||||
|
||||
List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverywhere");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
return Lists.newArrayList(new SecurityReference(SwaggerUtil.clientInfo().getName(), authorizationScopes),
|
||||
new SecurityReference(SwaggerUtil.bladeAuth().getName(), authorizationScopes),
|
||||
new SecurityReference(SwaggerUtil.bladeTenant().getName(), authorizationScopes));
|
||||
}
|
||||
|
||||
private List<SecurityScheme> securitySchemas() {
|
||||
return Lists.newArrayList(SwaggerUtil.clientInfo(), SwaggerUtil.bladeAuth(), SwaggerUtil.bladeTenant());
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.license(swaggerProperties.getLicense())
|
||||
.licenseUrl(swaggerProperties.getLicenseUrl())
|
||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
||||
.contact(
|
||||
new Contact
|
||||
(
|
||||
swaggerProperties.getContact().getName(),
|
||||
swaggerProperties.getContact().getUrl(),
|
||||
swaggerProperties.getContact().getEmail()
|
||||
)
|
||||
)
|
||||
.version(swaggerProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.springblade.common.config;
|
||||
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class XxlJobConfig {
|
||||
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||
|
||||
@Value("${xxl.job.admin.addresses}")
|
||||
private String adminAddresses;
|
||||
|
||||
@Value("${xxl.job.accessToken}")
|
||||
private String accessToken;
|
||||
|
||||
@Value("${xxl.job.executor.appname}")
|
||||
private String appname;
|
||||
|
||||
@Value("${xxl.job.executor.address}")
|
||||
private String address;
|
||||
|
||||
@Value("${xxl.job.executor.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${xxl.job.executor.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${xxl.job.executor.logpath}")
|
||||
private String logPath;
|
||||
|
||||
@Value("${xxl.job.executor.logretentiondays}")
|
||||
private int logRetentionDays;
|
||||
|
||||
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||
xxlJobSpringExecutor.setAppname(appname);
|
||||
xxlJobSpringExecutor.setAddress(address);
|
||||
xxlJobSpringExecutor.setIp(ip);
|
||||
xxlJobSpringExecutor.setPort(port);
|
||||
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||
xxlJobSpringExecutor.setLogPath(logPath);
|
||||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||
return xxlJobSpringExecutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
|
||||
*
|
||||
* 1、引入依赖:
|
||||
* <dependency>
|
||||
* <groupId>org.springframework.cloud</groupId>
|
||||
* <artifactId>spring-cloud-commons</artifactId>
|
||||
* <version>${version}</version>
|
||||
* </dependency>
|
||||
*
|
||||
* 2、配置文件,或者容器启动变量
|
||||
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
|
||||
*
|
||||
* 3、获取IP
|
||||
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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;
|
||||
|
||||
/**
|
||||
* 高德地图获取经纬度-用户key
|
||||
*/
|
||||
String ADDRESS_USER_KEY = "f33d1181359ec73e9f1e8ee7b8cef2a2";
|
||||
|
||||
|
||||
/**
|
||||
* 顶级父节点id
|
||||
*/
|
||||
String AI_AREA_ROOT = "2000001";
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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) {
|
||||
switch (profile) {
|
||||
case (AppConstant.PROD_CODE):
|
||||
return SENTINEL_PROD_ADDR;
|
||||
case (AppConstant.TEST_CODE):
|
||||
return SENTINEL_TEST_ADDR;
|
||||
default:
|
||||
return SENTINEL_DEV_ADDR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态获取elk地址
|
||||
*
|
||||
* @param profile 环境变量
|
||||
* @return addr
|
||||
*/
|
||||
static String elkAddr(String profile) {
|
||||
switch (profile) {
|
||||
case (AppConstant.PROD_CODE):
|
||||
return ELK_PROD_ADDR;
|
||||
case (AppConstant.TEST_CODE):
|
||||
return ELK_TEST_ADDR;
|
||||
default:
|
||||
return ELK_DEV_ADDR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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"
|
||||
);
|
||||
|
||||
}
|
||||
50
src/main/java/org/springblade/common/entity/EsQuery.java
Normal file
50
src/main/java/org/springblade/common/entity/EsQuery.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package org.springblade.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ganwu
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class EsQuery {
|
||||
/**
|
||||
* 模糊查询条件
|
||||
*/
|
||||
private List<MatchQuery> wildCard;
|
||||
/**
|
||||
* 查询条件
|
||||
*/
|
||||
private List<MatchQuery> match;
|
||||
|
||||
/**
|
||||
* 范围查询
|
||||
*/
|
||||
private GepPointQuery geoPoint;
|
||||
|
||||
/**
|
||||
* in查询条件
|
||||
*/
|
||||
private List<MatchQuery> terms;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String sortFiled;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private SortOrder sortOrder;
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private Integer current;
|
||||
/**
|
||||
* 条数
|
||||
*/
|
||||
private Integer size;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.springblade.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
|
||||
/**
|
||||
* 范围查询
|
||||
*
|
||||
* @author ganwu
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class GepPointQuery {
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 经纬度
|
||||
*/
|
||||
private GeoPoint geoPoint;
|
||||
/**
|
||||
* 距离单位
|
||||
*/
|
||||
private DistanceUnit unit;
|
||||
/**
|
||||
* 半径
|
||||
*/
|
||||
private Double initRadius;
|
||||
}
|
||||
23
src/main/java/org/springblade/common/entity/MatchQuery.java
Normal file
23
src/main/java/org/springblade/common/entity/MatchQuery.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.springblade.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 范围查询
|
||||
*
|
||||
* @author ganwu
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MatchQuery {
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
}
|
||||
39
src/main/java/org/springblade/common/enums/DictBizEnum.java
Normal file
39
src/main/java/org/springblade/common/enums/DictBizEnum.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 业务字典枚举类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DictBizEnum {
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
TEST("test"),
|
||||
;
|
||||
|
||||
final String name;
|
||||
|
||||
}
|
||||
95
src/main/java/org/springblade/common/enums/DictEnum.java
Normal file
95
src/main/java/org/springblade/common/enums/DictEnum.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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,66 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.filter;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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 RuntimeException("演示环境暂时无法操作!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
|
||||
package org.springblade.common.listener;
|
||||
|
||||
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,57 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.listener;
|
||||
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.common.listener;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
52
src/main/java/org/springblade/common/utils/AESUtils.java
Normal file
52
src/main/java/org/springblade/common/utils/AESUtils.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AESUtils {
|
||||
|
||||
|
||||
/**
|
||||
* AES加密字符串
|
||||
*
|
||||
* @param content 需要被加密的字符串
|
||||
* @param aesKey 加密需要的密码
|
||||
* @return 密文
|
||||
*/
|
||||
public static String encrypt(String content, String aesKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(aesKey.getBytes(StandardCharsets.UTF_8), "AES"));
|
||||
byte[] bytes = cipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
|
||||
String encode = new BASE64Encoder().encode(bytes);
|
||||
return encode.replaceAll(System.getProperty("line.separator"), "");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密AES加密过的字符串
|
||||
*
|
||||
* @param content AES加密过过的内容
|
||||
* @param aesKey 加密时的密码
|
||||
* @return 明文
|
||||
*/
|
||||
public static String decrypt(String content, String aesKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(aesKey.getBytes(StandardCharsets.UTF_8), "AES"));
|
||||
byte[] bytes = new BASE64Decoder().decodeBuffer(content);
|
||||
bytes = cipher.doFinal(bytes);
|
||||
return new String(bytes, "utf-8");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
303
src/main/java/org/springblade/common/utils/DateUtil.java
Normal file
303
src/main/java/org/springblade/common/utils/DateUtil.java
Normal file
@@ -0,0 +1,303 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
|
||||
import io.jsonwebtoken.lang.Assert;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DateUtil {
|
||||
|
||||
private static final SimpleDateFormat SIMPLE_DAY = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
/**
|
||||
* 校验开始时间和结束时间是否其中一个为空<br>
|
||||
* 并且比较时间范围
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
*/
|
||||
public static void VerificationTime(Date startTime, Date endTime) {
|
||||
// if (startTime == null && endTime == null) return;
|
||||
// if (startTime == null || endTime == null)
|
||||
// throw new FlyException(ResultCode.NOT_NULL_TIME.code(), ResultCode.NOT_NULL_TIME.msg());
|
||||
// if (endTime.before(startTime))
|
||||
// throw new FlyException(ResultCode.WRONG_TIME.code(), ResultCode.WRONG_TIME.msg());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算天数
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 结束时间
|
||||
*/
|
||||
public static Integer getDaySub(Date beginDate, Date endDate) {
|
||||
try {
|
||||
Date start = SIMPLE_DAY.parse(SIMPLE_DAY.format(beginDate));
|
||||
Date end = SIMPLE_DAY.parse(SIMPLE_DAY.format(endDate));
|
||||
return Math.toIntExact((end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000));
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Date geFirstDayOfThisMonth() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月最后一天
|
||||
*/
|
||||
public static Date geLastDayOfThisMonth() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.roll(Calendar.DAY_OF_MONTH, -1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public static Date getThirtyMinuteLate() {
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.add(Calendar.MINUTE, 30);
|
||||
return now.getTime();
|
||||
}
|
||||
|
||||
public static Date getMinutesLate(Date date, int minutes) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.MINUTE, minutes);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getDaysLate(Date date, int days) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.DATE, days);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getYearsLate(Date date, int years) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.YEAR, years);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static boolean isExpireDays(Date date, int i) {
|
||||
Calendar createDate = Calendar.getInstance();
|
||||
createDate.setTime(date);
|
||||
createDate.add(Calendar.DATE, i);
|
||||
return createDate.before(new Date());
|
||||
}
|
||||
|
||||
|
||||
public static Integer getPersonAgeFromIdCard(String pensonnelIdCard) {
|
||||
|
||||
//截取身份证中出行人出生日期中的年、月、日
|
||||
Integer personYear = Integer.parseInt(pensonnelIdCard.substring(6, 10));
|
||||
Integer personMonth = Integer.parseInt(pensonnelIdCard.substring(10, 12));
|
||||
Integer personDay = Integer.parseInt(pensonnelIdCard.substring(12, 14));
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// 得到当前时间的年、月、日
|
||||
Integer yearNow = cal.get(Calendar.YEAR);
|
||||
Integer monthNow = cal.get(Calendar.MONTH) + 1;
|
||||
Integer dayNow = cal.get(Calendar.DATE);
|
||||
|
||||
// 用当前年月日减去生日年月日
|
||||
Integer yearMinus = yearNow - personYear;
|
||||
Integer monthMinus = monthNow - personMonth;
|
||||
Integer dayMinus = dayNow - personDay;
|
||||
|
||||
Integer age = yearMinus; //先大致赋值
|
||||
|
||||
if (yearMinus == 0) { //出生年份为当前年份
|
||||
age = 0;
|
||||
} else { //出生年份大于当前年份
|
||||
if (monthMinus < 0) {//出生月份小于当前月份时,还没满周岁
|
||||
age = age - 1;
|
||||
}
|
||||
if (monthMinus == 0) {//当前月份为出生月份时,判断日期
|
||||
if (dayMinus < 0) {//出生日期小于当前月份时,没满周岁
|
||||
age = age - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
public static Date getToday() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getYesterday() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getTomorrow() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getSpecifyDay(int day) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, day);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前时间 + 分钟数
|
||||
*
|
||||
* @param minute
|
||||
* @return 当前时间 + 分钟数
|
||||
*/
|
||||
public static Date getSpecifyMinute(int minute) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
System.out.println(calendar.getTime());
|
||||
calendar.add(Calendar.MINUTE, minute);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定日期后x天的日期
|
||||
*
|
||||
* @param start 日期
|
||||
* @param day 天数
|
||||
* @return
|
||||
*/
|
||||
public static Date getSpecifyDay(Date start, int day) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(start);
|
||||
calendar.add(Calendar.DATE, day);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Integer getTimeHour() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public static Date getTodayHour(String end) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(end));
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Integer getTimeStampSec() {
|
||||
return Integer.valueOf(String.valueOf(Instant.now().getEpochSecond()));
|
||||
}
|
||||
|
||||
public static Date getDayOfMonth(Integer month) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.DAY_OF_MONTH, month);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date convertFromString(String dateString, String format) {
|
||||
SimpleDateFormat ft = new SimpleDateFormat(format);
|
||||
try {
|
||||
return ft.parse(dateString);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Date convertFromString(String dateString) {
|
||||
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
return ft.parse(dateString);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertFromDate(Date date, String format) {
|
||||
SimpleDateFormat ft = new SimpleDateFormat(format);
|
||||
return ft.format(date);
|
||||
}
|
||||
|
||||
public static Date convertLocalDateTimeToDate(LocalDateTime localDateTime) {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime zdt = localDateTime.atZone(zoneId);
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
|
||||
public static Date getBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.SECOND, 59);
|
||||
calendar.set(Calendar.MINUTE, 59);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||
calendar.set(Calendar.MILLISECOND, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static List<String> getDayList(String start, String end) {
|
||||
List<String> result = new ArrayList<>();
|
||||
result.add(start);
|
||||
Date startDay = convertFromString(start, "yyyy-MM-dd");
|
||||
Date endDay = convertFromString(end, "yyyy-MM-dd");
|
||||
Integer sub = getDaySub(startDay, endDay);
|
||||
Assert.isTrue(sub <= 31, "查询日期间隔不能大于31天减法");
|
||||
if (sub > 0) {
|
||||
for (int i = 1; i <= sub; i++) {
|
||||
result.add(convertFromDate(getDaysLate(startDay, i), "yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
80
src/main/java/org/springblade/common/utils/ImageUtil.java
Normal file
80
src/main/java/org/springblade/common/utils/ImageUtil.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
public class ImageUtil {
|
||||
|
||||
/**
|
||||
* 添加字体的属性设置
|
||||
*/
|
||||
private static Font YaHei_35 = new Font("微软雅黑", Font.BOLD, 35);
|
||||
private static Font YaHei_40 = new Font("微软雅黑", Font.BOLD, 40);
|
||||
private static Font YaHei_20 = new Font("微软雅黑", Font.PLAIN, 20);
|
||||
private static Font SiYuanHeiTi_22 = new Font("思源黑体", Font.BOLD, 22);
|
||||
private static Font SiYuanHeiTi_20 = new Font("思源黑体", Font.BOLD, 20);
|
||||
private static Color BLACK_COLOR = new Color(2, 1, 1);
|
||||
|
||||
/**
|
||||
* 生成图片
|
||||
*
|
||||
* @param image 图片
|
||||
* @param file 文件
|
||||
*/
|
||||
public static void getFile(Image image, File file) {
|
||||
ImgUtil.write(image, file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取纯色图片
|
||||
*
|
||||
* @param width 宽
|
||||
* @param height 高
|
||||
* @param color 颜色
|
||||
* @return java.awt.image.BufferedImage
|
||||
*/
|
||||
public static BufferedImage getSolidImage(int width, int height, Color color) {
|
||||
BufferedImage image = new BufferedImage(width, height, 1);
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(color);
|
||||
g.fillRect(0, 0, width, height);
|
||||
g.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 图片转base64
|
||||
*
|
||||
* @param image
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
public static String getBase64(BufferedImage image, String fileType) {
|
||||
ByteArrayOutputStream bass = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(image, fileType, bass);
|
||||
return Base64.getEncoder().encodeToString(bass.toByteArray());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (bass != null) {
|
||||
try {
|
||||
bass.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
src/main/java/org/springblade/common/utils/StringPool.java
Normal file
72
src/main/java/org/springblade/common/utils/StringPool.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
/**
|
||||
* 静态 String 池
|
||||
*
|
||||
* @author L.cm
|
||||
*/
|
||||
public interface StringPool {
|
||||
|
||||
String AMPERSAND = "&";
|
||||
String AND = "and";
|
||||
String AT = "@";
|
||||
String ASTERISK = "*";
|
||||
String STAR = ASTERISK;
|
||||
String SLASH = "/";
|
||||
String BACK_SLASH = "\\";
|
||||
String DOUBLE_SLASH = "#//";
|
||||
String COLON = ":";
|
||||
String COMMA = ",";
|
||||
String DASH = "-";
|
||||
String DOLLAR = "$";
|
||||
String DOT = ".";
|
||||
String EMPTY = "";
|
||||
String EMPTY_JSON = "{}";
|
||||
String EQUALS = "=";
|
||||
String FALSE = "false";
|
||||
String HASH = "#";
|
||||
String HAT = "^";
|
||||
String LEFT_BRACE = "{";
|
||||
String LEFT_BRACKET = "(";
|
||||
String LEFT_CHEV = "<";
|
||||
|
||||
String NEWLINE = "\n";
|
||||
String N = "n";
|
||||
String NO = "no";
|
||||
String NULL = "null";
|
||||
String OFF = "off";
|
||||
String ON = "on";
|
||||
String PERCENT = "%";
|
||||
String PIPE = "|";
|
||||
String PLUS = "+";
|
||||
String QUESTION_MARK = "?";
|
||||
String EXCLAMATION_MARK = "!";
|
||||
String QUOTE = "\"";
|
||||
String RETURN = "\r";
|
||||
String TAB = "\t";
|
||||
String RIGHT_BRACE = "}";
|
||||
String RIGHT_BRACKET = ")";
|
||||
String RIGHT_CHEV = ">";
|
||||
String SEMICOLON = ";";
|
||||
String SINGLE_QUOTE = "'";
|
||||
String BACKTICK = "`";
|
||||
String SPACE = " ";
|
||||
String TILDA = "~";
|
||||
String LEFT_SQ_BRACKET = "[";
|
||||
String RIGHT_SQ_BRACKET = "]";
|
||||
String TRUE = "true";
|
||||
String UNDERSCORE = "_";
|
||||
String UTF_8 = "UTF-8";
|
||||
String GBK = "GBK";
|
||||
String ISO_8859_1 = "ISO-8859-1";
|
||||
String Y = "y";
|
||||
String YES = "yes";
|
||||
String ONE = "1";
|
||||
String ZERO = "0";
|
||||
String MINUS_ONE = "-1";
|
||||
String DOLLAR_LEFT_BRACE = "${";
|
||||
String UNKNOWN = "unknown";
|
||||
String GET = "GET";
|
||||
String POST = "POST";
|
||||
|
||||
}
|
||||
20
src/main/java/org/springblade/common/utils/XmlUtil.java
Normal file
20
src/main/java/org/springblade/common/utils/XmlUtil.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.StringReader;
|
||||
|
||||
public class XmlUtil {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T parseBean(String xml, Class<T> clazz) {
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(clazz);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (T) unmarshaller.unmarshal(new StringReader(xml));
|
||||
} catch (JAXBException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.endpoint;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.social.props.SocialProperties;
|
||||
import org.springblade.core.social.utils.SocialUtil;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 第三方登陆端点
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_AUTH_NAME)
|
||||
@ConditionalOnProperty(value = "social.enabled", havingValue = "true")
|
||||
@Api(value = "第三方登陆", tags = "第三方登陆端点")
|
||||
public class BladeSocialEndpoint {
|
||||
|
||||
private final SocialProperties socialProperties;
|
||||
|
||||
/**
|
||||
* 授权完毕跳转
|
||||
*/
|
||||
@ApiOperation(value = "授权完毕跳转")
|
||||
@RequestMapping("/oauth/render/{source}")
|
||||
public void renderAuth(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
|
||||
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
|
||||
response.sendRedirect(authorizeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取认证信息
|
||||
*/
|
||||
@ApiOperation(value = "获取认证信息")
|
||||
@RequestMapping("/oauth/callback/{source}")
|
||||
public Object login(@PathVariable("source") String source, AuthCallback callback) {
|
||||
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||
return authRequest.login(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销授权
|
||||
*/
|
||||
@ApiOperation(value = "撤销授权")
|
||||
@RequestMapping("/oauth/revoke/{source}/{token}")
|
||||
public Object revokeAuth(@PathVariable("source") String source, @PathVariable("token") String token) {
|
||||
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||
return authRequest.revoke(AuthToken.builder().accessToken(token).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 续期accessToken
|
||||
*/
|
||||
@ApiOperation(value = "续期令牌")
|
||||
@RequestMapping("/oauth/refresh/{source}")
|
||||
public Object refreshAuth(@PathVariable("source") String source, String token) {
|
||||
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||
return authRequest.refresh(AuthToken.builder().refreshToken(token).build());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.endpoint;
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.jwt.JwtUtil;
|
||||
import org.springblade.core.jwt.props.JwtProperties;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.launch.constant.TokenConstant;
|
||||
import org.springblade.core.log.annotation.ApiLog;
|
||||
import org.springblade.core.redis.cache.BladeRedis;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springblade.modules.auth.provider.ITokenGranter;
|
||||
import org.springblade.modules.auth.provider.TokenGranterBuilder;
|
||||
import org.springblade.modules.auth.provider.TokenParameter;
|
||||
import org.springblade.modules.auth.utils.TokenUtil;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.*;
|
||||
|
||||
/**
|
||||
* 令牌端点
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@ApiSort(1)
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_AUTH_NAME)
|
||||
@Api(value = "用户授权认证", tags = "授权接口")
|
||||
public class BladeTokenEndPoint {
|
||||
|
||||
private final BladeRedis bladeRedis;
|
||||
|
||||
private final JwtProperties jwtProperties;
|
||||
|
||||
@ApiLog("登录用户验证")
|
||||
@PostMapping("/oauth/token")
|
||||
@ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password")
|
||||
public Kv token(@ApiParam(value = "租户ID", required = true) @RequestParam String tenantId,
|
||||
@ApiParam(value = "账号", required = true) @RequestParam(required = false) String username,
|
||||
@ApiParam(value = "密码", required = true) @RequestParam(required = false) String password,
|
||||
@ApiIgnore @RequestHeader(name = TokenUtil.DEPT_HEADER_KEY, required = false) String deptId,
|
||||
@ApiIgnore @RequestHeader(name = TokenUtil.ROLE_HEADER_KEY, required = false) String roleId) {
|
||||
return getToken(tenantId, username, password, deptId, roleId);
|
||||
}
|
||||
|
||||
public static Kv getToken(String tenantId, String username, String password, String deptId, String roleId) {
|
||||
Kv authInfo = Kv.create();
|
||||
|
||||
String grantType = WebUtil.getRequest().getParameter("grant_type");
|
||||
String refreshToken = WebUtil.getRequest().getParameter("refresh_token");
|
||||
|
||||
String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.DEFAULT_USER_TYPE);
|
||||
|
||||
TokenParameter tokenParameter = new TokenParameter();
|
||||
tokenParameter.getArgs().set("tenantId", tenantId)
|
||||
.set("username", username)
|
||||
.set("password", password)
|
||||
.set("grantType", grantType)
|
||||
.set("refreshToken", refreshToken)
|
||||
.set("userType", userType)
|
||||
.set("deptId", deptId).set("roleId", roleId);
|
||||
|
||||
ITokenGranter granter = TokenGranterBuilder.getGranter(grantType);
|
||||
UserInfo userInfo = granter.grant(tokenParameter);
|
||||
|
||||
if (userInfo == null || userInfo.getUser() == null) {
|
||||
return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户名或密码不正确");
|
||||
}
|
||||
|
||||
if (Func.isEmpty(userInfo.getRoles())) {
|
||||
return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "未获得用户的角色信息");
|
||||
}
|
||||
|
||||
return TokenUtil.createAuthInfo(userInfo);
|
||||
}
|
||||
|
||||
@ApiLog("骑手用户验证")
|
||||
@PostMapping("/oauth/riderToken")
|
||||
@ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password")
|
||||
public R riderToken(@ApiParam(value = "租户ID", required = true) @RequestParam String tenantId,
|
||||
@ApiParam(value = "账号", required = true) @RequestParam(required = false) String username,
|
||||
@ApiParam(value = "密码", required = true) @RequestParam(required = false) String password,
|
||||
@ApiIgnore @RequestHeader(name = TokenUtil.DEPT_HEADER_KEY, required = false) String deptId,
|
||||
@ApiIgnore @RequestHeader(name = TokenUtil.ROLE_HEADER_KEY, required = false) String roleId) {
|
||||
|
||||
Kv kv = getToken(tenantId, username, password, deptId, roleId);
|
||||
if (kv.get("error_code") != null) {
|
||||
return R.fail(kv.get("error_description").toString());
|
||||
} else {
|
||||
return R.data(kv);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/oauth/logout")
|
||||
@ApiOperation(value = "退出登录")
|
||||
public Kv logout() {
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
if (user != null && jwtProperties.getState()) {
|
||||
String token = JwtUtil.getToken(WebUtil.getRequest().getHeader(TokenConstant.HEADER));
|
||||
JwtUtil.removeAccessToken(user.getTenantId(), String.valueOf(user.getUserId()), token);
|
||||
}
|
||||
return Kv.create().set("success", "true").set("msg", "success");
|
||||
}
|
||||
|
||||
@GetMapping("/oauth/captcha")
|
||||
@ApiOperation(value = "获取验证码")
|
||||
public Kv captcha() {
|
||||
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
|
||||
String verCode = specCaptcha.text().toLowerCase();
|
||||
String key = UUID.randomUUID().toString();
|
||||
// 存入redis并设置过期时间为30分钟
|
||||
bladeRedis.setEx(CacheNames.CAPTCHA_KEY + key, verCode, Duration.ofMinutes(30));
|
||||
// 将key和base64返回给前端
|
||||
return Kv.create().set("key", key).set("image", specCaptcha.toBase64());
|
||||
}
|
||||
|
||||
@GetMapping("/oauth/clear-cache")
|
||||
@ApiOperation(value = "清除缓存")
|
||||
public Kv clearCache() {
|
||||
CacheUtil.clear(BIZ_CACHE);
|
||||
CacheUtil.clear(USER_CACHE);
|
||||
CacheUtil.clear(DICT_CACHE);
|
||||
CacheUtil.clear(FLOW_CACHE);
|
||||
CacheUtil.clear(SYS_CACHE);
|
||||
CacheUtil.clear(PARAM_CACHE);
|
||||
CacheUtil.clear(RESOURCE_CACHE);
|
||||
CacheUtil.clear(MENU_CACHE);
|
||||
CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
|
||||
CacheUtil.clear(MENU_CACHE, Boolean.FALSE);
|
||||
CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
|
||||
CacheUtil.clear(PARAM_CACHE, Boolean.FALSE);
|
||||
return Kv.create().set("success", "true").set("msg", "success");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用户类型枚举
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UserEnum {
|
||||
|
||||
/**
|
||||
* web
|
||||
*/
|
||||
WEB("web", 1),
|
||||
|
||||
/**
|
||||
* app
|
||||
*/
|
||||
APP("app", 2),
|
||||
|
||||
/**
|
||||
* other
|
||||
*/
|
||||
OTHER("other", 3),
|
||||
;
|
||||
|
||||
final String name;
|
||||
final int category;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.granter;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.common.cache.ParamCache;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.redis.cache.BladeRedis;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springblade.modules.auth.enums.UserEnum;
|
||||
import org.springblade.modules.auth.provider.ITokenGranter;
|
||||
import org.springblade.modules.auth.provider.TokenParameter;
|
||||
import org.springblade.modules.auth.utils.TokenUtil;
|
||||
import org.springblade.modules.system.entity.Tenant;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
import org.springblade.modules.system.service.IRoleService;
|
||||
import org.springblade.modules.system.service.ITenantService;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 验证码TokenGranter
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class CaptchaTokenGranter implements ITokenGranter {
|
||||
|
||||
public static final String GRANT_TYPE = "captcha";
|
||||
public static final Integer FAIL_COUNT = 5;
|
||||
public static final String FAIL_COUNT_VALUE = "account.failCount";
|
||||
|
||||
private final IUserService userService;
|
||||
private final IRoleService roleService;
|
||||
private final ITenantService tenantService;
|
||||
private final BladeRedis bladeRedis;
|
||||
|
||||
@Override
|
||||
public UserInfo grant(TokenParameter tokenParameter) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
|
||||
// 获取用户绑定ID
|
||||
String headerDept = request.getHeader(TokenUtil.DEPT_HEADER_KEY);
|
||||
String headerRole = request.getHeader(TokenUtil.ROLE_HEADER_KEY);
|
||||
// 获取验证码信息
|
||||
String key = request.getHeader(TokenUtil.CAPTCHA_HEADER_KEY);
|
||||
String code = request.getHeader(TokenUtil.CAPTCHA_HEADER_CODE);
|
||||
// 获取验证码
|
||||
String redisCode = bladeRedis.get(CacheNames.CAPTCHA_KEY + key);
|
||||
// 判断验证码
|
||||
if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) {
|
||||
throw new ServiceException(TokenUtil.CAPTCHA_NOT_CORRECT);
|
||||
}
|
||||
|
||||
String tenantId = tokenParameter.getArgs().getStr("tenantId");
|
||||
String username = tokenParameter.getArgs().getStr("username");
|
||||
String password = tokenParameter.getArgs().getStr("password");
|
||||
|
||||
// 判断登录是否锁定
|
||||
int cnt = Func.toInt(bladeRedis.get(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username)), 0);
|
||||
// int cnt = -1;
|
||||
int failCount = Func.toInt(ParamCache.getValue(FAIL_COUNT_VALUE), FAIL_COUNT);
|
||||
if (cnt >= failCount) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_TOO_MANY_FAILS);
|
||||
}
|
||||
|
||||
UserInfo userInfo = null;
|
||||
if (Func.isNoneBlank(username, password)) {
|
||||
// 获取租户信息
|
||||
Tenant tenant = tenantService.getByTenantId(tenantId);
|
||||
if (TokenUtil.judgeTenant(tenant)) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
|
||||
}
|
||||
// 获取用户类型
|
||||
String userType = tokenParameter.getArgs().getStr("userType");
|
||||
// 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
|
||||
if (userType.equals(UserEnum.WEB.getName())) {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.WEB);
|
||||
} else if (userType.equals(UserEnum.APP.getName())) {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.APP);
|
||||
} else {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.OTHER);
|
||||
}
|
||||
}
|
||||
if (userInfo == null || userInfo.getUser() == null) {
|
||||
// 增加错误锁定次数
|
||||
bladeRedis.setEx(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username), cnt + 1, Duration.ofMinutes(30));
|
||||
} else {
|
||||
// 成功则清除登录错误次数
|
||||
bladeRedis.del(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username));
|
||||
}
|
||||
// 多部门情况下指定单部门
|
||||
if (Func.isNotEmpty(headerDept) && userInfo != null && userInfo.getUser().getDeptId().contains(headerDept)) {
|
||||
userInfo.getUser().setDeptId(headerDept);
|
||||
}
|
||||
// 多角色情况下指定单角色
|
||||
if (Func.isNotEmpty(headerRole) && userInfo != null && userInfo.getUser().getRoleId().contains(headerRole)) {
|
||||
List<String> roleResult = roleService.getRoleAliases(headerRole);
|
||||
userInfo.setRoles(roleResult);
|
||||
userInfo.getUser().setRoleId(headerRole);
|
||||
}
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.granter;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.common.cache.ParamCache;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.redis.cache.BladeRedis;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springblade.modules.auth.enums.UserEnum;
|
||||
import org.springblade.modules.auth.provider.ITokenGranter;
|
||||
import org.springblade.modules.auth.provider.TokenParameter;
|
||||
import org.springblade.modules.auth.utils.TokenUtil;
|
||||
import org.springblade.modules.system.entity.Tenant;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
import org.springblade.modules.system.service.IRoleService;
|
||||
import org.springblade.modules.system.service.ITenantService;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PasswordTokenGranter
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PasswordTokenGranter implements ITokenGranter {
|
||||
|
||||
public static final String GRANT_TYPE = "password";
|
||||
public static final Integer FAIL_COUNT = 5;
|
||||
public static final String FAIL_COUNT_VALUE = "account.failCount";
|
||||
|
||||
private final IUserService userService;
|
||||
private final IRoleService roleService;
|
||||
private final ITenantService tenantService;
|
||||
private final BladeRedis bladeRedis;
|
||||
|
||||
@Override
|
||||
public UserInfo grant(TokenParameter tokenParameter) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
// 获取用户绑定ID
|
||||
String headerDept = request.getHeader(TokenUtil.DEPT_HEADER_KEY);
|
||||
String headerRole = request.getHeader(TokenUtil.ROLE_HEADER_KEY);
|
||||
|
||||
// 获取用户信息
|
||||
String tenantId = tokenParameter.getArgs().getStr("tenantId");
|
||||
String username = tokenParameter.getArgs().getStr("username");
|
||||
String password = tokenParameter.getArgs().getStr("password");
|
||||
|
||||
// 判断登录是否锁定
|
||||
int cnt = Func.toInt(bladeRedis.get(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username)), 0);
|
||||
int failCount = Func.toInt(ParamCache.getValue(FAIL_COUNT_VALUE), FAIL_COUNT);
|
||||
// int cnt = -1;
|
||||
if (cnt >= failCount) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_TOO_MANY_FAILS);
|
||||
}
|
||||
|
||||
UserInfo userInfo = null;
|
||||
if (Func.isNoneBlank(username, password)) {
|
||||
// 获取租户信息
|
||||
Tenant tenant = tenantService.getByTenantId(tenantId);
|
||||
if (TokenUtil.judgeTenant(tenant)) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
|
||||
}
|
||||
// 获取用户类型
|
||||
String userType = tokenParameter.getArgs().getStr("userType");
|
||||
// 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
|
||||
if (userType.equals(UserEnum.WEB.getName())) {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.WEB);
|
||||
} else if (userType.equals(UserEnum.APP.getName())) {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.APP);
|
||||
} else {
|
||||
userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.OTHER);
|
||||
}
|
||||
}
|
||||
if (userInfo == null || userInfo.getUser() == null) {
|
||||
// 增加错误锁定次数
|
||||
bladeRedis.setEx(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username), cnt + 1, Duration.ofMinutes(30));
|
||||
} else {
|
||||
// 成功则清除登录错误次数
|
||||
bladeRedis.del(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username));
|
||||
}
|
||||
// 多部门情况下指定单部门
|
||||
if (Func.isNotEmpty(headerDept) && userInfo != null && userInfo.getUser().getDeptId().contains(headerDept)) {
|
||||
userInfo.getUser().setDeptId(headerDept);
|
||||
}
|
||||
// 多角色情况下指定单角色
|
||||
if (Func.isNotEmpty(headerRole) && userInfo != null && userInfo.getUser().getRoleId().contains(headerRole)) {
|
||||
List<String> roleAliases = roleService.getRoleAliases(headerRole);
|
||||
userInfo.setRoles(roleAliases);
|
||||
userInfo.getUser().setRoleId(headerRole);
|
||||
}
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.granter;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.jwt.JwtUtil;
|
||||
import org.springblade.core.jwt.props.JwtProperties;
|
||||
import org.springblade.core.launch.constant.TokenConstant;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.modules.auth.provider.ITokenGranter;
|
||||
import org.springblade.modules.auth.provider.TokenParameter;
|
||||
import org.springblade.modules.auth.utils.TokenUtil;
|
||||
import org.springblade.modules.system.entity.Tenant;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
import org.springblade.modules.system.service.IRoleService;
|
||||
import org.springblade.modules.system.service.ITenantService;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RefreshTokenGranter
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class RefreshTokenGranter implements ITokenGranter {
|
||||
|
||||
public static final String GRANT_TYPE = "refresh_token";
|
||||
|
||||
private final IUserService userService;
|
||||
private final IRoleService roleService;
|
||||
private final ITenantService tenantService;
|
||||
private final JwtProperties jwtProperties;
|
||||
|
||||
@Override
|
||||
public UserInfo grant(TokenParameter tokenParameter) {
|
||||
String tenantId = tokenParameter.getArgs().getStr("tenantId");
|
||||
String grantType = tokenParameter.getArgs().getStr("grantType");
|
||||
String refreshToken = tokenParameter.getArgs().getStr("refreshToken");
|
||||
String deptId = tokenParameter.getArgs().getStr("deptId");
|
||||
String roleId = tokenParameter.getArgs().getStr("roleId");
|
||||
UserInfo userInfo = null;
|
||||
if (Func.isNoneBlank(grantType, refreshToken) && grantType.equals(TokenConstant.REFRESH_TOKEN)) {
|
||||
// 判断令牌合法性
|
||||
if (!judgeRefreshToken(grantType, refreshToken)) {
|
||||
throw new ServiceException(TokenUtil.TOKEN_NOT_PERMISSION);
|
||||
}
|
||||
Claims claims = AuthUtil.parseJWT(refreshToken);
|
||||
if (claims != null) {
|
||||
String tokenType = Func.toStr(claims.get(TokenConstant.TOKEN_TYPE));
|
||||
if (tokenType.equals(TokenConstant.REFRESH_TOKEN)) {
|
||||
// 获取租户信息
|
||||
Tenant tenant = tenantService.getByTenantId(tenantId);
|
||||
if (TokenUtil.judgeTenant(tenant)) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
|
||||
}
|
||||
// 获取用户信息
|
||||
userInfo = userService.userInfo(Func.toLong(claims.get(TokenConstant.USER_ID)));
|
||||
// 设置多部门信息
|
||||
if (Func.isNotEmpty(deptId) && userInfo.getUser().getDeptId().contains(deptId)) {
|
||||
userInfo.getUser().setDeptId(deptId);
|
||||
}
|
||||
// 设置多角色信息
|
||||
if (Func.isNotEmpty(roleId) && userInfo.getUser().getRoleId().contains(roleId)) {
|
||||
userInfo.getUser().setRoleId(roleId);
|
||||
List<String> roleAliases = roleService.getRoleAliases(roleId);
|
||||
userInfo.setRoles(roleAliases);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验refreshToken合法性
|
||||
*
|
||||
* @param grantType 认证类型
|
||||
* @param refreshToken refreshToken
|
||||
*/
|
||||
private boolean judgeRefreshToken(String grantType, String refreshToken) {
|
||||
if (jwtProperties.getState() && jwtProperties.getSingle()) {
|
||||
Claims claims = JwtUtil.parseJWT(refreshToken);
|
||||
String tenantId = String.valueOf(claims.get("tenant_id"));
|
||||
String userId = String.valueOf(claims.get("user_id"));
|
||||
String token = JwtUtil.getRefreshToken(tenantId, userId, refreshToken);
|
||||
return StringUtil.equalsIgnoreCase(token, refreshToken);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.granter;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
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.log.exception.ServiceException;
|
||||
import org.springblade.core.social.props.SocialProperties;
|
||||
import org.springblade.core.social.utils.SocialUtil;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springblade.modules.auth.provider.ITokenGranter;
|
||||
import org.springblade.modules.auth.provider.TokenParameter;
|
||||
import org.springblade.modules.auth.utils.TokenUtil;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
import org.springblade.modules.system.entity.UserOauth;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* SocialTokenGranter
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class SocialTokenGranter implements ITokenGranter {
|
||||
|
||||
public static final String GRANT_TYPE = "social";
|
||||
|
||||
private static final Integer AUTH_SUCCESS_CODE = 2000;
|
||||
|
||||
private final IUserService userService;
|
||||
private final SocialProperties socialProperties;
|
||||
|
||||
@Override
|
||||
public UserInfo grant(TokenParameter tokenParameter) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
String tenantId = Func.toStr(request.getHeader(TokenUtil.TENANT_HEADER_KEY), TokenUtil.DEFAULT_TENANT_ID);
|
||||
// 开放平台来源
|
||||
String sourceParameter = request.getParameter("source");
|
||||
// 匹配是否有别名定义
|
||||
String source = socialProperties.getAlias().getOrDefault(sourceParameter, sourceParameter);
|
||||
// 开放平台授权码
|
||||
String code = request.getParameter("code");
|
||||
// 开放平台状态吗
|
||||
String state = request.getParameter("state");
|
||||
|
||||
// 获取开放平台授权数据
|
||||
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
|
||||
AuthCallback authCallback = new AuthCallback();
|
||||
authCallback.setCode(code);
|
||||
authCallback.setState(state);
|
||||
AuthResponse authResponse = authRequest.login(authCallback);
|
||||
AuthUser authUser;
|
||||
if (authResponse.getCode() == AUTH_SUCCESS_CODE) {
|
||||
authUser = (AuthUser) authResponse.getData();
|
||||
} else {
|
||||
throw new ServiceException("social grant failure, auth response is not success");
|
||||
}
|
||||
|
||||
// 组装数据
|
||||
UserOauth userOauth = Objects.requireNonNull(BeanUtil.copy(authUser, UserOauth.class));
|
||||
userOauth.setSource(authUser.getSource());
|
||||
userOauth.setTenantId(tenantId);
|
||||
userOauth.setUuid(authUser.getUuid());
|
||||
// 返回UserInfo
|
||||
return userService.userInfo(userOauth);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.provider;
|
||||
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
|
||||
/**
|
||||
* 授权认证统一接口.
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface ITokenGranter {
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param tokenParameter 授权参数
|
||||
* @return UserInfo
|
||||
*/
|
||||
UserInfo grant(TokenParameter tokenParameter);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.provider;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.secure.exception.SecureException;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.modules.auth.granter.CaptchaTokenGranter;
|
||||
import org.springblade.modules.auth.granter.PasswordTokenGranter;
|
||||
import org.springblade.modules.auth.granter.RefreshTokenGranter;
|
||||
import org.springblade.modules.auth.granter.SocialTokenGranter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* TokenGranterBuilder
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TokenGranterBuilder {
|
||||
|
||||
/**
|
||||
* TokenGranter缓存池
|
||||
*/
|
||||
private static final Map<String, ITokenGranter> GRANTER_POOL = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
GRANTER_POOL.put(PasswordTokenGranter.GRANT_TYPE, SpringUtil.getBean(PasswordTokenGranter.class));
|
||||
GRANTER_POOL.put(CaptchaTokenGranter.GRANT_TYPE, SpringUtil.getBean(CaptchaTokenGranter.class));
|
||||
GRANTER_POOL.put(RefreshTokenGranter.GRANT_TYPE, SpringUtil.getBean(RefreshTokenGranter.class));
|
||||
GRANTER_POOL.put(SocialTokenGranter.GRANT_TYPE, SpringUtil.getBean(SocialTokenGranter.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取TokenGranter
|
||||
*
|
||||
* @param grantType 授权类型
|
||||
* @return ITokenGranter
|
||||
*/
|
||||
public static ITokenGranter getGranter(String grantType) {
|
||||
ITokenGranter tokenGranter = GRANTER_POOL.get(Func.toStr(grantType, PasswordTokenGranter.GRANT_TYPE));
|
||||
if (tokenGranter == null) {
|
||||
throw new SecureException("no grantType was found");
|
||||
} else {
|
||||
return GRANTER_POOL.get(Func.toStr(grantType, PasswordTokenGranter.GRANT_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.provider;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
|
||||
/**
|
||||
* TokenParameter
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
public class TokenParameter {
|
||||
|
||||
private Kv args = Kv.create();
|
||||
|
||||
}
|
||||
169
src/main/java/org/springblade/modules/auth/utils/TokenUtil.java
Normal file
169
src/main/java/org/springblade/modules/auth/utils/TokenUtil.java
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.auth.utils;
|
||||
|
||||
import org.springblade.common.constant.TenantConstant;
|
||||
import org.springblade.core.launch.constant.TokenConstant;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.secure.TokenInfo;
|
||||
import org.springblade.core.secure.utils.SecureUtil;
|
||||
import org.springblade.core.tenant.BladeTenantProperties;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
import org.springblade.core.tool.utils.*;
|
||||
import org.springblade.modules.system.entity.Tenant;
|
||||
import org.springblade.modules.system.entity.User;
|
||||
import org.springblade.modules.system.entity.UserInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 认证工具类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class TokenUtil {
|
||||
|
||||
public final static String DEPT_HEADER_KEY = "Dept-Id";
|
||||
public final static String ROLE_HEADER_KEY = "Role-Id";
|
||||
public final static String CAPTCHA_HEADER_KEY = "Captcha-Key";
|
||||
public final static String CAPTCHA_HEADER_CODE = "Captcha-Code";
|
||||
public final static String CAPTCHA_NOT_CORRECT = "验证码不正确";
|
||||
public final static String TENANT_HEADER_KEY = "Tenant-Id";
|
||||
public final static String DEFAULT_TENANT_ID = "000000";
|
||||
public final static String USER_TYPE_HEADER_KEY = "User-Type";
|
||||
public final static String DEFAULT_USER_TYPE = "web";
|
||||
public final static String TOKEN_NOT_PERMISSION = "令牌授权已过期";
|
||||
public final static String USER_NOT_FOUND = "用户名或密码错误";
|
||||
public final static String USER_HAS_NO_ROLE = "未获得用户的角色信息";
|
||||
public final static String USER_HAS_NO_TENANT = "未获得用户的租户信息";
|
||||
public final static String USER_HAS_NO_TENANT_PERMISSION = "租户授权已过期,请联系管理员";
|
||||
public final static String USER_HAS_TOO_MANY_FAILS = "登录错误次数过多,请稍后再试";
|
||||
public final static String HEADER_KEY = "Authorization";
|
||||
public final static String HEADER_PREFIX = "Basic ";
|
||||
public final static String DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png";
|
||||
|
||||
private static BladeTenantProperties tenantProperties;
|
||||
|
||||
/**
|
||||
* 获取租户配置
|
||||
*
|
||||
* @return tenantProperties
|
||||
*/
|
||||
private static BladeTenantProperties getTenantProperties() {
|
||||
if (tenantProperties == null) {
|
||||
tenantProperties = SpringUtil.getBean(BladeTenantProperties.class);
|
||||
}
|
||||
return tenantProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建认证token
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
* @return token
|
||||
*/
|
||||
public static Kv createAuthInfo(UserInfo userInfo) {
|
||||
Kv authInfo = Kv.create();
|
||||
User user = userInfo.getUser();
|
||||
//设置jwt参数
|
||||
Map<String, Object> param = new HashMap<>(16);
|
||||
param.put(TokenConstant.TOKEN_TYPE, TokenConstant.ACCESS_TOKEN);
|
||||
param.put(TokenConstant.TENANT_ID, user.getTenantId());
|
||||
param.put(TokenConstant.USER_ID, Func.toStr(user.getId()));
|
||||
param.put(TokenConstant.DEPT_ID, user.getDeptId());
|
||||
param.put(TokenConstant.POST_ID, user.getPostId());
|
||||
param.put(TokenConstant.ROLE_ID, user.getRoleId());
|
||||
param.put(TokenConstant.OAUTH_ID, userInfo.getOauthId());
|
||||
param.put(TokenConstant.ACCOUNT, user.getAccount());
|
||||
param.put(TokenConstant.USER_NAME, user.getAccount());
|
||||
param.put(TokenConstant.NICK_NAME, user.getRealName());
|
||||
param.put(TokenConstant.ROLE_NAME, Func.join(userInfo.getRoles()));
|
||||
param.put(TokenConstant.DETAIL, userInfo.getDetail());
|
||||
|
||||
//拼装accessToken
|
||||
try {
|
||||
TokenInfo accessToken = SecureUtil.createJWT(param, "audience", "issuser", TokenConstant.ACCESS_TOKEN);
|
||||
//返回accessToken
|
||||
return authInfo.set(TokenConstant.TENANT_ID, user.getTenantId())
|
||||
.set(TokenConstant.USER_ID, Func.toStr(user.getId()))
|
||||
.set(TokenConstant.DEPT_ID, user.getDeptId())
|
||||
.set(TokenConstant.POST_ID, user.getPostId())
|
||||
.set(TokenConstant.ROLE_ID, user.getRoleId())
|
||||
.set(TokenConstant.OAUTH_ID, userInfo.getOauthId())
|
||||
.set(TokenConstant.ACCOUNT, user.getAccount())
|
||||
.set(TokenConstant.USER_NAME, user.getAccount())
|
||||
.set(TokenConstant.NICK_NAME, user.getRealName())
|
||||
.set(TokenConstant.ROLE_NAME, Func.join(userInfo.getRoles()))
|
||||
.set(TokenConstant.AVATAR, Func.toStr(user.getAvatar(), TokenConstant.DEFAULT_AVATAR))
|
||||
.set(TokenConstant.ACCESS_TOKEN, accessToken.getToken())
|
||||
.set(TokenConstant.REFRESH_TOKEN, createRefreshToken(userInfo).getToken())
|
||||
.set(TokenConstant.TOKEN_TYPE, TokenConstant.BEARER)
|
||||
.set(TokenConstant.EXPIRES_IN, accessToken.getExpire())
|
||||
.set(TokenConstant.DETAIL, userInfo.getDetail())
|
||||
.set(TokenConstant.LICENSE, TokenConstant.LICENSE_NAME);
|
||||
} catch (Exception ex) {
|
||||
return authInfo.set("error_code", HttpServletResponse.SC_UNAUTHORIZED).set("error_description", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建refreshToken
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
* @return refreshToken
|
||||
*/
|
||||
private static TokenInfo createRefreshToken(UserInfo userInfo) {
|
||||
User user = userInfo.getUser();
|
||||
Map<String, Object> param = new HashMap<>(16);
|
||||
param.put(TokenConstant.TOKEN_TYPE, TokenConstant.REFRESH_TOKEN);
|
||||
param.put(TokenConstant.USER_ID, Func.toStr(user.getId()));
|
||||
param.put(TokenConstant.DEPT_ID, Func.toStr(user.getDeptId()));
|
||||
param.put(TokenConstant.ROLE_ID, Func.toStr(user.getRoleId()));
|
||||
return SecureUtil.createJWT(param, "audience", "issuser", TokenConstant.REFRESH_TOKEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断租户权限
|
||||
*
|
||||
* @param tenant 租户信息
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean judgeTenant(Tenant tenant) {
|
||||
if (tenant == null) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT);
|
||||
}
|
||||
if (StringUtil.equalsIgnoreCase(tenant.getTenantId(), BladeConstant.ADMIN_TENANT_ID)) {
|
||||
return false;
|
||||
}
|
||||
Date expireTime = tenant.getExpireTime();
|
||||
if (getTenantProperties().getLicense()) {
|
||||
String licenseKey = tenant.getLicenseKey();
|
||||
String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY);
|
||||
expireTime = JsonUtil.parse(decrypt, Tenant.class).getExpireTime();
|
||||
}
|
||||
if (expireTime != null && expireTime.before(DateUtil.now())) {
|
||||
throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springblade.modules.blacklist.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName("user_blacklist")
|
||||
@ApiModel(value = "UserBlacklist对象", description = "用户黑名单表")
|
||||
public class UserBlacklist extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("手机号")
|
||||
@TableField("phone")
|
||||
private Long phone;
|
||||
|
||||
@ApiModelProperty("名字")
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
@TableField("remarks")
|
||||
private String remarks;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.springblade.modules.blacklist.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.modules.blacklist.entity.UserBlacklist;
|
||||
|
||||
public interface UserBlacklistMapper extends BaseMapper<UserBlacklist> {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?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.blacklist.mapper.UserBlacklistMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.springblade.modules.blacklist.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.blacklist.entity.UserBlacklist;
|
||||
|
||||
public interface UserBlacklistService extends BaseService<UserBlacklist> {
|
||||
IPage<UserBlacklist> selectUserBlacklistPage(IPage<UserBlacklist> page, UserBlacklist entity);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.modules.blacklist.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.modules.blacklist.entity.UserBlacklist;
|
||||
import org.springblade.modules.blacklist.mapper.UserBlacklistMapper;
|
||||
import org.springblade.modules.blacklist.service.UserBlacklistService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserBlacklistServiceImpl extends BaseServiceImpl<UserBlacklistMapper, UserBlacklist> implements UserBlacklistService {
|
||||
@Override
|
||||
public IPage<UserBlacklist> selectUserBlacklistPage(IPage<UserBlacklist> page, UserBlacklist entity) {
|
||||
LambdaQueryWrapper<UserBlacklist> wrapper = new LambdaQueryWrapper<>();
|
||||
if (!Objects.isNull(entity.getPhone())) {
|
||||
wrapper.eq(UserBlacklist::getPhone, entity.getPhone());
|
||||
}
|
||||
wrapper.orderByDesc(UserBlacklist::getId);
|
||||
return page(page, wrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package org.springblade.modules.desk.controller;
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@ApiIgnore
|
||||
@RestController
|
||||
@RequestMapping(AppConstant.APPLICATION_DESK_NAME)
|
||||
@AllArgsConstructor
|
||||
@Api(value = "首页", tags = "首页")
|
||||
public class DashBoardController {
|
||||
|
||||
/**
|
||||
* 活跃用户
|
||||
*/
|
||||
@GetMapping("/dashboard/activities")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "活跃用户", notes = "活跃用户")
|
||||
public R activities() {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
|
||||
Map<String, Object> map1 = new HashMap<>(16);
|
||||
map1.put("id", "trend-1");
|
||||
map1.put("updatedAt", "2019-01-01");
|
||||
map1.put("user", Kv.create().set("name", "曲丽丽").set("avatar", "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"));
|
||||
map1.put("group", Kv.create().set("name", "高逼格设计天团").set("link", "http://github.com/"));
|
||||
map1.put("project", Kv.create().set("name", "六月迭代").set("link", "http://github.com/"));
|
||||
map1.put("template", "在 @{group} 新建项目 @{project}");
|
||||
list.add(map1);
|
||||
|
||||
Map<String, Object> map2 = new HashMap<>(16);
|
||||
map2.put("id", "trend-2");
|
||||
map2.put("updatedAt", "2019-01-01");
|
||||
map2.put("user", Kv.create().set("name", "付小小").set("avatar", "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"));
|
||||
map2.put("group", Kv.create().set("name", "高逼格设计天团").set("link", "http://github.com/"));
|
||||
map2.put("project", Kv.create().set("name", "七月月迭代").set("link", "http://github.com/"));
|
||||
map2.put("template", "在 @{group} 新建项目 @{project}");
|
||||
list.add(map2);
|
||||
|
||||
return R.data(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/dashboard/info")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "用户信息", notes = "用户信息")
|
||||
public R info() {
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
map.put("id", "trend-1");
|
||||
map.put("updatedAt", "2019-01-01");
|
||||
map.put("user", Kv.create().set("name", "曲丽丽").set("avatar", "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"));
|
||||
map.put("group", Kv.create().set("name", "高逼格设计天团").set("link", "http://github.com/"));
|
||||
map.put("project", Kv.create().set("name", "六月迭代").set("link", "http://github.com/"));
|
||||
map.put("template", "在 @{group} 新建项目 @{project}");
|
||||
return R.data(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名信息
|
||||
*/
|
||||
@PostMapping("/dashboard/sign")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@ApiOperation(value = "签名信息", notes = "签名信息")
|
||||
public R sign() {
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
map.put("user", Kv.create().set("name", "曲丽丽").set("avatar", "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"));
|
||||
return R.data(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息
|
||||
*/
|
||||
@GetMapping("/notice/notices")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "消息", notes = "消息")
|
||||
public R notices() {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
Map<String, String> map1 = new HashMap<>(16);
|
||||
map1.put("logo", "https://spring.io/img/homepage/icon-spring-framework.svg");
|
||||
map1.put("title", "SpringBoot");
|
||||
map1.put("description", "现在的web项目几乎都会用到spring框架,而要使用spring难免需要配置大量的xml配置文件,而 springboot的出现解 决了这一问题,一个项目甚至不用部署到服务器上直接开跑,真像springboot所说:“just run”。");
|
||||
map1.put("member", "Chill");
|
||||
map1.put("href", "http://spring.io/projects/spring-boot");
|
||||
list.add(map1);
|
||||
|
||||
Map<String, String> map2 = new HashMap<>(16);
|
||||
map2.put("logo", "https://spring.io/img/homepage/icon-spring-cloud.svg");
|
||||
map2.put("title", "SpringCloud");
|
||||
map2.put("description", "SpringCloud是基于SpringBoot的一整套实现微服务的框架。他提供了微服务开发所需的配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分布式会话和集群状态管理等组件。");
|
||||
map2.put("member", "Chill");
|
||||
map2.put("href", "http://spring.io/projects/spring-cloud");
|
||||
list.add(map2);
|
||||
|
||||
Map<String, String> map3 = new HashMap<>(16);
|
||||
map3.put("logo", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1546359961068&di=05ff9406e6675ca9a58a525a7e7950b9&imgtype=jpg&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D575314515%2C4268715674%26fm%3D214%26gp%3D0.jpg");
|
||||
map3.put("title", "Mybatis");
|
||||
map3.put("description", "MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。");
|
||||
map3.put("member", "Chill");
|
||||
map3.put("href", "http://www.mybatis.org/mybatis-3/getting-started.html");
|
||||
list.add(map3);
|
||||
|
||||
Map<String, String> map4 = new HashMap<>(16);
|
||||
map4.put("logo", "https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png");
|
||||
map4.put("title", "React");
|
||||
map4.put("description", "React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设Instagram 的网站。做出来以后,发现这套东西很好用,就在2013年5月开源了。");
|
||||
map4.put("member", "Chill");
|
||||
map4.put("href", "https://reactjs.org/");
|
||||
list.add(map4);
|
||||
|
||||
Map<String, String> map5 = new HashMap<>(16);
|
||||
map5.put("logo", "https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png");
|
||||
map5.put("title", "Ant Design");
|
||||
map5.put("description", "蚂蚁金服体验技术部经过大量的项目实践和总结,沉淀出设计语言 Ant Design,这可不单纯只是设计原则、控件规范和视觉尺寸,还配套有前端代码实现方案。也就是说采用Ant Design后,UI设计和前端界面研发可同步完成,效率大大提升。");
|
||||
map5.put("member", "Chill");
|
||||
map5.put("href", "https://ant.design/docs/spec/introduce-cn");
|
||||
list.add(map5);
|
||||
|
||||
Map<String, String> map6 = new HashMap<>(16);
|
||||
map6.put("logo", "https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png");
|
||||
map6.put("title", "Ant Design Pro");
|
||||
map6.put("description", "Ant Design Pro 是一个企业级开箱即用的中后台前端/设计解决方案。符合阿里追求的'敏捷的前端+强大的中台'的思想。");
|
||||
map6.put("member", "Chill");
|
||||
map6.put("href", "https://pro.ant.design");
|
||||
list.add(map6);
|
||||
|
||||
return R.data(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的消息
|
||||
*/
|
||||
@GetMapping("/notice/my-notices")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "消息", notes = "消息")
|
||||
public R myNotices() {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
Map<String, String> map1 = new HashMap<>(16);
|
||||
map1.put("id", "000000001");
|
||||
map1.put("avatar", "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png");
|
||||
map1.put("title", "你收到了 14 份新周报");
|
||||
map1.put("datetime", "2018-08-09");
|
||||
map1.put("type", "notification");
|
||||
list.add(map1);
|
||||
|
||||
Map<String, String> map2 = new HashMap<>(16);
|
||||
map2.put("id", "000000002");
|
||||
map2.put("avatar", "https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png");
|
||||
map2.put("title", "你推荐的 曲妮妮 已通过第三轮面试");
|
||||
map2.put("datetime", "2018-08-08");
|
||||
map2.put("type", "notification");
|
||||
list.add(map2);
|
||||
|
||||
|
||||
Map<String, String> map3 = new HashMap<>(16);
|
||||
map3.put("id", "000000003");
|
||||
map3.put("avatar", "https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg");
|
||||
map3.put("title", "曲丽丽 评论了你");
|
||||
map3.put("description", "描述信息描述信息描述信息");
|
||||
map3.put("datetime", "2018-08-07");
|
||||
map3.put("type", "message");
|
||||
map3.put("clickClose", "true");
|
||||
list.add(map3);
|
||||
|
||||
|
||||
Map<String, String> map4 = new HashMap<>(16);
|
||||
map4.put("id", "000000004");
|
||||
map4.put("avatar", "https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg");
|
||||
map4.put("title", "朱偏右 回复了你");
|
||||
map4.put("description", "这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像");
|
||||
map4.put("type", "message");
|
||||
map4.put("datetime", "2018-08-07");
|
||||
map4.put("clickClose", "true");
|
||||
list.add(map4);
|
||||
|
||||
|
||||
Map<String, String> map5 = new HashMap<>(16);
|
||||
map5.put("id", "000000005");
|
||||
map5.put("title", "任务名称");
|
||||
map5.put("description", "任务需要在 2018-01-12 20:00 前启动");
|
||||
map5.put("extra", "未开始");
|
||||
map5.put("status", "todo");
|
||||
map5.put("type", "event");
|
||||
list.add(map5);
|
||||
|
||||
return R.data(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.*;
|
||||
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.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.constant.RoleConstant;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.develop.support.BladeCodeGenerator;
|
||||
import org.springblade.modules.develop.entity.Code;
|
||||
import org.springblade.modules.develop.entity.Datasource;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
import org.springblade.modules.develop.entity.ModelPrototype;
|
||||
import org.springblade.modules.develop.service.ICodeService;
|
||||
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 springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@ApiIgnore
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/code")
|
||||
@Api(value = "代码生成", tags = "代码生成")
|
||||
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
|
||||
public class CodeController extends BladeController {
|
||||
|
||||
private final ICodeService codeService;
|
||||
private final IDatasourceService datasourceService;
|
||||
private final IModelService modelService;
|
||||
private final IModelPrototypeService modelPrototypeService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入code")
|
||||
public R<Code> detail(Code code) {
|
||||
Code detail = codeService.getOne(Condition.getQueryWrapper(code));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "codeName", value = "模块名", paramType = "query", dataType = "string"),
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "query", dataType = "string"),
|
||||
@ApiImplicitParam(name = "modelName", value = "实体名", paramType = "query", dataType = "string")
|
||||
})
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入code")
|
||||
public R<IPage<Code>> list(@ApiIgnore @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)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入code")
|
||||
public R submit(@Valid @RequestBody Code code) {
|
||||
return R.status(codeService.submit(code));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(codeService.removeByIds(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*/
|
||||
@PostMapping("/copy")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "复制", notes = "传入id")
|
||||
public R copy(@ApiParam(value = "主键", 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)
|
||||
@ApiOperation(value = "代码生成", notes = "传入ids")
|
||||
public R genCode(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
Collection<Code> codes = codeService.listByIds(Func.toLongList(ids));
|
||||
codes.forEach(code -> {
|
||||
BladeCodeGenerator generator = new BladeCodeGenerator();
|
||||
// 设置基础模型
|
||||
Model model = modelService.getById(code.getModelId());
|
||||
generator.setModelCode(model.getModelCode());
|
||||
generator.setModelClass(model.getModelClass());
|
||||
// 设置模型集合
|
||||
List<ModelPrototype> prototypes = modelPrototypeService.prototypeList(model.getId());
|
||||
generator.setModel(JsonUtil.readMap(JsonUtil.toJson(model)));
|
||||
generator.setPrototypes(JsonUtil.readListMap(JsonUtil.toJson(prototypes)));
|
||||
if (StringUtil.isNotBlank(code.getSubModelId())) {
|
||||
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)));
|
||||
}
|
||||
// 设置数据源
|
||||
Datasource datasource = datasourceService.getById(model.getDatasourceId());
|
||||
generator.setDriverName(datasource.getDriverClass());
|
||||
generator.setUrl(datasource.getUrl());
|
||||
generator.setUsername(datasource.getUsername());
|
||||
generator.setPassword(datasource.getPassword());
|
||||
// 设置基础配置
|
||||
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(code.getTemplateType());
|
||||
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);
|
||||
// 启动代码生成
|
||||
generator.run();
|
||||
});
|
||||
return R.success("代码生成成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.controller;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
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.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.modules.develop.entity.Datasource;
|
||||
import org.springblade.modules.develop.service.IDatasourceService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据源配置表 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/datasource")
|
||||
@Api(value = "数据源配置表", tags = "数据源配置表接口")
|
||||
public class DatasourceController extends BladeController {
|
||||
|
||||
private final IDatasourceService datasourceService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入datasource")
|
||||
public R<Datasource> detail(Datasource datasource) {
|
||||
Datasource detail = datasourceService.getOne(Condition.getQueryWrapper(datasource));
|
||||
detail.setUsername(DesensitizedUtil.password(detail.getUsername()));
|
||||
detail.setPassword(DesensitizedUtil.password(detail.getPassword()));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页 数据源配置表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入datasource")
|
||||
public R<IPage<Datasource>> list(Datasource datasource, Query query) {
|
||||
IPage<Datasource> pages = datasourceService.page(Condition.getPage(query), Condition.getQueryWrapper(datasource));
|
||||
pages.getRecords().forEach(data -> {
|
||||
data.setUsername(DesensitizedUtil.password(data.getUsername()));
|
||||
data.setPassword(DesensitizedUtil.password(data.getPassword()));
|
||||
});
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增 数据源配置表
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "新增", notes = "传入datasource")
|
||||
public R save(@Valid @RequestBody Datasource datasource) {
|
||||
return R.status(datasourceService.save(datasource));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 数据源配置表
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "修改", notes = "传入datasource")
|
||||
public R update(@Valid @RequestBody Datasource datasource) {
|
||||
return R.status(datasourceService.updateById(datasource));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改 数据源配置表
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入datasource")
|
||||
public R submit(@Valid @RequestBody Datasource datasource) {
|
||||
datasource.setUrl(datasource.getUrl().replace("&", "&"));
|
||||
return R.status(datasourceService.saveOrUpdate(datasource));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除 数据源配置表
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(datasourceService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据源列表
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@ApiOperation(value = "下拉数据源", notes = "查询列表")
|
||||
public R<List<Datasource>> select() {
|
||||
List<Datasource> list = datasourceService.list();
|
||||
return R.data(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.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 com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
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.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.entity.Datasource;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
import org.springblade.modules.develop.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 javax.validation.Valid;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据模型表 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/model")
|
||||
@Api(value = "数据模型表", tags = "数据模型表接口")
|
||||
public class ModelController extends BladeController {
|
||||
|
||||
private final IModelService modelService;
|
||||
private final IModelPrototypeService modelPrototypeService;
|
||||
private final IDatasourceService datasourceService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入model")
|
||||
public R<Model> detail(Model model) {
|
||||
Model detail = modelService.getOne(Condition.getQueryWrapper(model));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页 数据模型表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入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)
|
||||
@ApiOperation(value = "新增", notes = "传入model")
|
||||
public R save(@Valid @RequestBody Model model) {
|
||||
return R.status(modelService.save(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 数据模型表
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "修改", notes = "传入model")
|
||||
public R update(@Valid @RequestBody Model model) {
|
||||
return R.status(modelService.updateById(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改 数据模型表
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入model")
|
||||
public R submit(@Valid @RequestBody Model model) {
|
||||
return R.status(modelService.saveOrUpdate(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 数据模型表
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(modelService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型列表
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "模型列表", notes = "模型列表")
|
||||
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)
|
||||
@ApiOperation(value = "物理表列表", notes = "传入datasourceId")
|
||||
public R<List<TableInfo>> tableList(Long datasourceId) {
|
||||
Datasource datasource = datasourceService.getById(datasourceId);
|
||||
ConfigBuilder config = getConfigBuilder(datasource);
|
||||
List<TableInfo> tableInfoList = config.getTableInfoList().stream()
|
||||
.filter(tableInfo -> !StringUtil.startsWithIgnoreCase(tableInfo.getName(), "ACT_"))
|
||||
.map(tableInfo -> tableInfo.setComment(tableInfo.getName() + StringPool.COLON + tableInfo.getComment()))
|
||||
.collect(Collectors.toList());
|
||||
return R.data(tableInfoList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物理表信息
|
||||
*/
|
||||
@GetMapping("/table-info")
|
||||
@ApiOperationSupport(order = 9)
|
||||
@ApiOperation(value = "物理表信息", notes = "传入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 = getTableInfo(tableName, datasourceId);
|
||||
return R.data(tableInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字段信息
|
||||
*/
|
||||
@GetMapping("/model-prototype")
|
||||
@ApiOperationSupport(order = 10)
|
||||
@ApiOperation(value = "物理表字段信息", notes = "传入modelId与datasourceId")
|
||||
public R modelPrototype(Long modelId, Long datasourceId) {
|
||||
List<ModelPrototype> modelPrototypeList = modelPrototypeService.list(Wrappers.<ModelPrototype>query().lambda().eq(ModelPrototype::getModelId, modelId));
|
||||
if (modelPrototypeList.size() > 0) {
|
||||
return R.data(modelPrototypeList);
|
||||
}
|
||||
Model model = modelService.getById(modelId);
|
||||
String tableName = model.getModelTable();
|
||||
TableInfo tableInfo = getTableInfo(tableName, datasourceId);
|
||||
if (tableInfo != null) {
|
||||
return R.data(tableInfo.getFields());
|
||||
} else {
|
||||
return R.fail("未获得相关表信息");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表信息
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param datasourceId 数据源主键
|
||||
*/
|
||||
private TableInfo getTableInfo(String tableName, Long datasourceId) {
|
||||
Datasource datasource = datasourceService.getById(datasourceId);
|
||||
ConfigBuilder config = getConfigBuilder(datasource);
|
||||
List<TableInfo> tableInfoList = config.getTableInfoList();
|
||||
TableInfo tableInfo = null;
|
||||
Iterator<TableInfo> iterator = tableInfoList.stream().filter(table -> table.getName().equals(tableName)).collect(Collectors.toList()).iterator();
|
||||
if (iterator.hasNext()) {
|
||||
tableInfo = iterator.next();
|
||||
tableInfo.setEntityName(tableInfo.getEntityName().replace(StringUtil.firstCharToUpper(tableName.split(StringPool.UNDERSCORE)[0]), StringPool.EMPTY));
|
||||
}
|
||||
return tableInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表配置信息
|
||||
*
|
||||
* @param datasource 数据源信息
|
||||
*/
|
||||
private ConfigBuilder getConfigBuilder(Datasource datasource) {
|
||||
StrategyConfig strategyConfig = new 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,137 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
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.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.modules.develop.entity.ModelPrototype;
|
||||
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据原型表 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(AppConstant.APPLICATION_DEVELOP_NAME + "/model-prototype")
|
||||
@Api(value = "数据原型表", tags = "数据原型表接口")
|
||||
public class ModelPrototypeController extends BladeController {
|
||||
|
||||
private final IModelPrototypeService modelPrototypeService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入modelPrototype")
|
||||
public R<ModelPrototype> detail(ModelPrototype modelPrototype) {
|
||||
ModelPrototype detail = modelPrototypeService.getOne(Condition.getQueryWrapper(modelPrototype));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页 数据原型表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入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)
|
||||
@ApiOperation(value = "新增", notes = "传入modelPrototype")
|
||||
public R save(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||
return R.status(modelPrototypeService.save(modelPrototype));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 数据原型表
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "修改", notes = "传入modelPrototype")
|
||||
public R update(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||
return R.status(modelPrototypeService.updateById(modelPrototype));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改 数据原型表
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入modelPrototype")
|
||||
public R submit(@Valid @RequestBody ModelPrototype modelPrototype) {
|
||||
return R.status(modelPrototypeService.saveOrUpdate(modelPrototype));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增或修改 数据原型表
|
||||
*/
|
||||
@PostMapping("/submit-list")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "批量新增或修改", notes = "传入modelPrototype集合")
|
||||
public R submitList(@Valid @RequestBody List<ModelPrototype> modelPrototypes) {
|
||||
return R.status(modelPrototypeService.submitList(modelPrototypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 数据原型表
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(modelPrototypeService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据原型列表
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
@ApiOperationSupport(order = 9)
|
||||
@ApiOperation(value = "数据原型列表", notes = "数据原型列表")
|
||||
public R<List<ModelPrototype>> select(@ApiParam(value = "数据模型Id", required = true) @RequestParam Long modelId) {
|
||||
List<ModelPrototype> list = modelPrototypeService.list(Wrappers.<ModelPrototype>query().lambda().eq(ModelPrototype::getModelId, modelId));
|
||||
list.forEach(prototype -> prototype.setComment(prototype.getJdbcName() + StringPool.COLON + StringPool.SPACE + prototype.getComment()));
|
||||
return R.data(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
import org.springblade.modules.develop.entity.ModelPrototype;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代码模型DTO
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ModelDTO extends Model {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 代码建模原型
|
||||
*/
|
||||
private List<ModelPrototype> prototypes;
|
||||
|
||||
}
|
||||
180
src/main/java/org/springblade/modules/develop/entity/Code.java
Normal file
180
src/main/java/org/springblade/modules/develop/entity/Code.java
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.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.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_code")
|
||||
@ApiModel(value = "Code对象", description = "Code对象")
|
||||
public class Code implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
@ApiModelProperty(value = "主键")
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 数据模型主键
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
@ApiModelProperty(value = "数据模型主键")
|
||||
private Long modelId;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
@ApiModelProperty(value = "服务名称")
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
@ApiModelProperty(value = "模块名称")
|
||||
private String codeName;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
@ApiModelProperty(value = "表名")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 实体名
|
||||
*/
|
||||
@ApiModelProperty(value = "表前缀")
|
||||
private String tablePrefix;
|
||||
|
||||
/**
|
||||
* 主键名
|
||||
*/
|
||||
@ApiModelProperty(value = "主键名")
|
||||
private String pkName;
|
||||
|
||||
/**
|
||||
* 后端包名
|
||||
*/
|
||||
@ApiModelProperty(value = "后端包名")
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 模版类型
|
||||
*/
|
||||
@ApiModelProperty(value = "模版类型")
|
||||
private String templateType;
|
||||
|
||||
/**
|
||||
* 作者信息
|
||||
*/
|
||||
@ApiModelProperty(value = "作者信息")
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 子表模型主键
|
||||
*/
|
||||
@ApiModelProperty(value = "子表模型主键")
|
||||
private String subModelId;
|
||||
|
||||
/**
|
||||
* 子表绑定外键
|
||||
*/
|
||||
@ApiModelProperty(value = "子表绑定外键")
|
||||
private String subFkId;
|
||||
|
||||
/**
|
||||
* 树主键字段
|
||||
*/
|
||||
@ApiModelProperty(value = "树主键字段")
|
||||
private String treeId;
|
||||
|
||||
/**
|
||||
* 树父主键字段
|
||||
*/
|
||||
@ApiModelProperty(value = "树父主键字段")
|
||||
private String treePid;
|
||||
|
||||
/**
|
||||
* 树名称字段
|
||||
*/
|
||||
@ApiModelProperty(value = "树名称字段")
|
||||
private String treeName;
|
||||
|
||||
/**
|
||||
* 基础业务模式
|
||||
*/
|
||||
@ApiModelProperty(value = "基础业务模式")
|
||||
private Integer baseMode;
|
||||
|
||||
/**
|
||||
* 包装器模式
|
||||
*/
|
||||
@ApiModelProperty(value = "包装器模式")
|
||||
private Integer wrapMode;
|
||||
|
||||
/**
|
||||
* 远程调用模式
|
||||
*/
|
||||
@ApiModelProperty(value = "远程调用模式")
|
||||
private Integer feignMode;
|
||||
|
||||
/**
|
||||
* 代码风格
|
||||
*/
|
||||
@ApiModelProperty(value = "代码风格")
|
||||
private String codeStyle;
|
||||
|
||||
/**
|
||||
* 后端路径
|
||||
*/
|
||||
@ApiModelProperty(value = "后端路径")
|
||||
private String apiPath;
|
||||
|
||||
/**
|
||||
* 前端路径
|
||||
*/
|
||||
@ApiModelProperty(value = "前端路径")
|
||||
private String webPath;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@TableLogic
|
||||
@ApiModelProperty(value = "是否已删除")
|
||||
private Integer isDeleted;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据源配置表实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_datasource")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "Datasource对象", description = "数据源配置表")
|
||||
public class Datasource extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
/**
|
||||
* 驱动类
|
||||
*/
|
||||
@ApiModelProperty(value = "驱动类")
|
||||
private String driverClass;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
@ApiModelProperty(value = "连接地址")
|
||||
private String url;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ApiModelProperty(value = "密码")
|
||||
private String password;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.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.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据模型表实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_model")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "Model对象", description = "数据模型表")
|
||||
public class Model extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 数据源主键
|
||||
*/
|
||||
@ApiModelProperty(value = "数据源主键")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long datasourceId;
|
||||
/**
|
||||
* 模型名称
|
||||
*/
|
||||
@ApiModelProperty(value = "模型名称")
|
||||
private String modelName;
|
||||
/**
|
||||
* 模型编号
|
||||
*/
|
||||
@ApiModelProperty(value = "模型编号")
|
||||
private String modelCode;
|
||||
/**
|
||||
* 物理表名
|
||||
*/
|
||||
@ApiModelProperty(value = "物理表名")
|
||||
private String modelTable;
|
||||
/**
|
||||
* 模型类名
|
||||
*/
|
||||
@ApiModelProperty(value = "模型类名")
|
||||
private String modelClass;
|
||||
/**
|
||||
* 模型备注
|
||||
*/
|
||||
@ApiModelProperty(value = "模型备注")
|
||||
private String modelRemark;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.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.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据原型表实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_model_prototype")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "ModelPrototype对象", description = "数据原型表")
|
||||
public class ModelPrototype extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 模型主键
|
||||
*/
|
||||
@ApiModelProperty(value = "模型主键")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long modelId;
|
||||
/**
|
||||
* 物理列名
|
||||
*/
|
||||
@ApiModelProperty(value = "物理列名")
|
||||
private String jdbcName;
|
||||
/**
|
||||
* 物理类型
|
||||
*/
|
||||
@ApiModelProperty(value = "物理类型")
|
||||
private String jdbcType;
|
||||
/**
|
||||
* 实体列名
|
||||
*/
|
||||
@ApiModelProperty(value = "实体列名")
|
||||
private String propertyName;
|
||||
/**
|
||||
* 实体类型
|
||||
*/
|
||||
@ApiModelProperty(value = "实体类型")
|
||||
private String propertyType;
|
||||
/**
|
||||
* 实体类型引用
|
||||
*/
|
||||
@ApiModelProperty(value = "实体类型引用")
|
||||
private String propertyEntity;
|
||||
/**
|
||||
* 注释说明
|
||||
*/
|
||||
@ApiModelProperty(value = "注释说明")
|
||||
private String comment;
|
||||
/**
|
||||
* 列表显示
|
||||
*/
|
||||
@ApiModelProperty(value = "列表显示")
|
||||
private Integer isList;
|
||||
/**
|
||||
* 表单显示
|
||||
*/
|
||||
@ApiModelProperty(value = "表单显示")
|
||||
private Integer isForm;
|
||||
/**
|
||||
* 独占一行
|
||||
*/
|
||||
@ApiModelProperty(value = "独占一行")
|
||||
private Integer isRow;
|
||||
/**
|
||||
* 组件类型
|
||||
*/
|
||||
@ApiModelProperty(value = "组件类型")
|
||||
private String componentType;
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@ApiModelProperty(value = "字典编码")
|
||||
private String dictCode;
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@ApiModelProperty(value = "是否必填")
|
||||
private Integer isRequired;
|
||||
/**
|
||||
* 查询配置
|
||||
*/
|
||||
@ApiModelProperty(value = "查询配置")
|
||||
private Integer isQuery;
|
||||
/**
|
||||
* 查询类型
|
||||
*/
|
||||
@ApiModelProperty(value = "查询类型")
|
||||
private String queryType;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.modules.develop.entity.Code;
|
||||
|
||||
/**
|
||||
* Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface CodeMapper extends BaseMapper<Code> {
|
||||
|
||||
}
|
||||
@@ -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.CodeMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="codeResultMap" type="org.springblade.modules.develop.entity.Code">
|
||||
<id column="id" property="id" />
|
||||
<result column="datasource_id" property="datasourceId" />
|
||||
<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,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.modules.develop.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.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,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
|
||||
/**
|
||||
* 数据模型表 Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface ModelMapper extends BaseMapper<Model> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.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,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.modules.develop.entity.ModelPrototype;
|
||||
|
||||
/**
|
||||
* 数据原型表 Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface ModelPrototypeMapper extends BaseMapper<ModelPrototype> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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.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="comment" property="comment" />
|
||||
<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,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springblade.modules.develop.entity.Code;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface ICodeService extends IService<Code> {
|
||||
|
||||
/**
|
||||
* 提交
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
boolean submit(Code code);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service;
|
||||
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.develop.entity.Datasource;
|
||||
|
||||
/**
|
||||
* 数据源配置表 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface IDatasourceService extends BaseService<Datasource> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service;
|
||||
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.develop.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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service;
|
||||
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
|
||||
/**
|
||||
* 数据模型表 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface IModelService extends BaseService<Model> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.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.entity.Code;
|
||||
import org.springblade.modules.develop.mapper.CodeMapper;
|
||||
import org.springblade.modules.develop.service.ICodeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@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,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service.impl;
|
||||
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.modules.develop.entity.Datasource;
|
||||
import org.springblade.modules.develop.mapper.DatasourceMapper;
|
||||
import org.springblade.modules.develop.service.IDatasourceService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据源配置表 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class DatasourceServiceImpl extends BaseServiceImpl<DatasourceMapper, Datasource> implements IDatasourceService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.modules.develop.entity.ModelPrototype;
|
||||
import org.springblade.modules.develop.mapper.ModelPrototypeMapper;
|
||||
import org.springblade.modules.develop.service.IModelPrototypeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据原型表 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class ModelPrototypeServiceImpl extends BaseServiceImpl<ModelPrototypeMapper, ModelPrototype> implements IModelPrototypeService {
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package org.springblade.modules.develop.service.impl;
|
||||
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.modules.develop.entity.Model;
|
||||
import org.springblade.modules.develop.mapper.ModelMapper;
|
||||
import org.springblade.modules.develop.service.IModelService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据模型表 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class ModelServiceImpl extends BaseServiceImpl<ModelMapper, Model> implements IModelService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package org.springblade.modules.log.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
import org.springblade.modules.log.service.ILogPaymentCallbackService;
|
||||
import org.springblade.modules.log.vo.LogPaymentCallbackVO;
|
||||
import org.springblade.modules.log.wrapper.LogPaymentCallbackWrapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 控制器
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/log/paymentCallback")
|
||||
@Api(value = "支付回调回调日志", tags = "支付回调回调日志接口")
|
||||
public class LogPaymentCallbackController extends BladeController {
|
||||
|
||||
private final ILogPaymentCallbackService paymentCallbackService;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入paymentCallback")
|
||||
public R<LogPaymentCallbackVO> detail(LogPaymentCallback paymentCallback) {
|
||||
LogPaymentCallback detail = paymentCallbackService.getOne(Condition.getQueryWrapper(paymentCallback));
|
||||
return R.data(LogPaymentCallbackWrapper.build().entityVO(detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入paymentCallback")
|
||||
public R<IPage<LogPaymentCallbackVO>> list(LogPaymentCallback paymentCallback, Query query) {
|
||||
IPage<LogPaymentCallback> pages = paymentCallbackService.page(Condition.getPage(query), Condition.getQueryWrapper(paymentCallback));
|
||||
return R.data(LogPaymentCallbackWrapper.build().pageVO(pages));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@ApiOperation(value = "分页", notes = "传入paymentCallback")
|
||||
public R<IPage<LogPaymentCallbackVO>> page(LogPaymentCallbackVO paymentCallback, Query query) {
|
||||
IPage<LogPaymentCallbackVO> pages = paymentCallbackService.selectPaymentCallbackPage(Condition.getPage(query), paymentCallback);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "新增", notes = "传入paymentCallback")
|
||||
public R save(@Valid @RequestBody LogPaymentCallback paymentCallback) {
|
||||
return R.status(paymentCallbackService.save(paymentCallback));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "修改", notes = "传入paymentCallback")
|
||||
public R update(@Valid @RequestBody LogPaymentCallback paymentCallback) {
|
||||
return R.status(paymentCallbackService.updateById(paymentCallback));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入paymentCallback")
|
||||
public R submit(@Valid @RequestBody LogPaymentCallback paymentCallback) {
|
||||
return R.status(paymentCallbackService.saveOrUpdate(paymentCallback));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(paymentCallbackService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springblade.modules.log.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 数据传输对象实体类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LogPaymentCallbackDTO extends LogPaymentCallback {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.springblade.modules.log.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 实体类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
@Data
|
||||
@TableName("log_payment_callback")
|
||||
@ApiModel(value = "PaymentCallback对象", description = "支付回调回调日志")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LogPaymentCallback extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@ApiModelProperty(value = "类型")
|
||||
private Integer type;
|
||||
/**
|
||||
* 回调内容
|
||||
*/
|
||||
@ApiModelProperty(value = "回调内容")
|
||||
private String data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springblade.modules.log.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
import org.springblade.modules.log.vo.LogPaymentCallbackVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 Mapper 接口
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
public interface LogPaymentCallbackMapper extends BaseMapper<LogPaymentCallback> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page
|
||||
* @param paymentCallback
|
||||
* @return
|
||||
*/
|
||||
List<LogPaymentCallbackVO> selectPaymentCallbackPage(IPage<LogPaymentCallbackVO> page, LogPaymentCallbackVO paymentCallback);
|
||||
|
||||
|
||||
}
|
||||
@@ -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.log.mapper.LogPaymentCallbackMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="paymentCallbackResultMap" type="org.springblade.modules.log.entity.LogPaymentCallback">
|
||||
<result column="id" property="id" />
|
||||
<result column="type" property="type" />
|
||||
<result column="data" property="data" />
|
||||
<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" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectPaymentCallbackPage" resultMap="paymentCallbackResultMap">
|
||||
select *
|
||||
from log_payment_callback
|
||||
where is_deleted = 0
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springblade.modules.log.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
import org.springblade.modules.log.vo.LogPaymentCallbackVO;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 服务类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
public interface ILogPaymentCallbackService extends BaseService<LogPaymentCallback> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page
|
||||
* @param paymentCallback
|
||||
* @return
|
||||
*/
|
||||
IPage<LogPaymentCallbackVO> selectPaymentCallbackPage(IPage<LogPaymentCallbackVO> page, LogPaymentCallbackVO paymentCallback);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.modules.log.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
import org.springblade.modules.log.mapper.LogPaymentCallbackMapper;
|
||||
import org.springblade.modules.log.service.ILogPaymentCallbackService;
|
||||
import org.springblade.modules.log.vo.LogPaymentCallbackVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 服务实现类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
@Service
|
||||
public class LogPaymentCallbackServiceImpl extends BaseServiceImpl<LogPaymentCallbackMapper, LogPaymentCallback> implements ILogPaymentCallbackService {
|
||||
|
||||
@Override
|
||||
public IPage<LogPaymentCallbackVO> selectPaymentCallbackPage(IPage<LogPaymentCallbackVO> page, LogPaymentCallbackVO paymentCallback) {
|
||||
return page.setRecords(baseMapper.selectPaymentCallbackPage(page, paymentCallback));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springblade.modules.log.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 视图实体类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LogPaymentCallbackVO extends LogPaymentCallback {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.springblade.modules.log.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.modules.log.entity.LogPaymentCallback;
|
||||
import org.springblade.modules.log.vo.LogPaymentCallbackVO;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 支付回调回调日志 包装类,返回视图层所需的字段
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-11-30
|
||||
*/
|
||||
public class LogPaymentCallbackWrapper extends BaseEntityWrapper<LogPaymentCallback, LogPaymentCallbackVO> {
|
||||
|
||||
public static LogPaymentCallbackWrapper build() {
|
||||
return new LogPaymentCallbackWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogPaymentCallbackVO entityVO(LogPaymentCallback paymentCallback) {
|
||||
LogPaymentCallbackVO paymentCallbackVO = Objects.requireNonNull(BeanUtil.copy(paymentCallback, LogPaymentCallbackVO.class));
|
||||
|
||||
//User createUser = UserCache.getUser(paymentCallback.getCreateUser());
|
||||
//User updateUser = UserCache.getUser(paymentCallback.getUpdateUser());
|
||||
//paymentCallbackVO.setCreateUserName(createUser.getName());
|
||||
//paymentCallbackVO.setUpdateUserName(updateUser.getName());
|
||||
|
||||
return paymentCallbackVO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.springblade.modules.payment.api;
|
||||
|
||||
|
||||
import org.springblade.modules.payment.dto.QueryDto;
|
||||
import org.springblade.modules.payment.dto.RefundDto;
|
||||
import org.springblade.modules.payment.dto.RefundRecordDTO;
|
||||
import org.springblade.modules.payment.dto.RefundTotalDto;
|
||||
import org.springblade.modules.payment.entity.PaymentRecord;
|
||||
import org.springblade.modules.payment.response.QueryResult;
|
||||
import org.springblade.modules.payment.response.RefundResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付接口
|
||||
*/
|
||||
public interface PaymentFacade {
|
||||
|
||||
QueryResult query(QueryDto dto) throws Exception;
|
||||
|
||||
/**
|
||||
* 退款字段含义
|
||||
* 组合支付 refund_amount(现金) refund_point(抵扣券) refund_token(消费金)
|
||||
* 现金支付 refund_amount(现金) refund_point(无) refund_token(无)
|
||||
* 纯消费金 refund_amount(消费金) refund_point(无) refund_token(无)
|
||||
* 纯抵扣券 refund_amount(抵扣券) refund_point(无) refund_token(无)
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
RefundResult refund(RefundDto dto) throws Exception;
|
||||
|
||||
/**
|
||||
* 退款记录查询
|
||||
*
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
Map<Long, List<RefundRecordDTO>> queryRefund(List<Long> orderId);
|
||||
|
||||
/**
|
||||
* 订单退款查询
|
||||
*
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
RefundTotalDto selectRefundAmount(Long orderId);
|
||||
|
||||
|
||||
PaymentRecord queryRecord(QueryDto dto);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package org.springblade.modules.payment.api.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.modules.payment.api.PaymentFacade;
|
||||
import org.springblade.modules.payment.dto.QueryDto;
|
||||
import org.springblade.modules.payment.dto.RefundDto;
|
||||
import org.springblade.modules.payment.dto.RefundRecordDTO;
|
||||
import org.springblade.modules.payment.dto.RefundTotalDto;
|
||||
import org.springblade.modules.payment.entity.PaymentRecord;
|
||||
import org.springblade.modules.payment.entity.RefundRecord;
|
||||
import org.springblade.modules.payment.enums.PaymentStatusEnum;
|
||||
import org.springblade.modules.payment.response.QueryResult;
|
||||
import org.springblade.modules.payment.response.RefundResult;
|
||||
import org.springblade.modules.payment.service.AliPayment;
|
||||
import org.springblade.modules.payment.service.PaymentRecordService;
|
||||
import org.springblade.modules.payment.service.RefundRecordService;
|
||||
import org.springblade.modules.payment.service.WechatPayment;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class PaymentFacadeImpl implements PaymentFacade {
|
||||
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
private final PaymentRecordService recordService;
|
||||
|
||||
private final AliPayment aliPaymentService;
|
||||
|
||||
private final WechatPayment wechatPaymentService;
|
||||
|
||||
private final RefundRecordService refundRecordService;
|
||||
|
||||
@Override
|
||||
public QueryResult query(QueryDto dto) throws Exception {
|
||||
|
||||
PaymentRecord record = recordService.getOne(Wrappers.<PaymentRecord>lambdaQuery()
|
||||
.eq(PaymentRecord::getOrderId, dto.getOrderId())
|
||||
.eq(PaymentRecord::getOrderType, dto.getOrderType().getCode())
|
||||
.eq(PaymentRecord::getPaymentType, dto.getPaymentType().getType())
|
||||
);
|
||||
|
||||
Assert.notNull(record, "支付记录不存在");
|
||||
|
||||
return new QueryResult().setStatus(record.getPaymentStatus()).setContent(record.getRemark());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefundResult refund(RefundDto dto) throws Exception {
|
||||
PaymentRecord record = null;
|
||||
if (dto.getPaymentId() != null) {
|
||||
record = recordService.getById(dto.getPaymentId());
|
||||
} else if (dto.getOrderId() != null) {
|
||||
record = recordService.getOne(Wrappers.lambdaQuery(PaymentRecord.class)
|
||||
.eq(PaymentRecord::getOrderId, dto.getOrderId())
|
||||
.eq(PaymentRecord::getPaymentType, dto.getPaymentType().getType())
|
||||
.eq(PaymentRecord::getOrderType, dto.getOrderType().getCode())
|
||||
.eq(PaymentRecord::getPaymentStatus, PaymentStatusEnum.PAY.getCode())
|
||||
.orderByDesc(PaymentRecord::getId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
Assert.notNull(record, "未找到符合条件的支付记录");
|
||||
Assert.isTrue(dto.getAmount().compareTo(record.getTotalAmount()) < 1, "退款金额大于支付金额");
|
||||
Assert.isTrue(Objects.equals(dto.getOrderType().getCode(), record.getOrderType()), "订单类型错误");
|
||||
Assert.isTrue(Objects.equals(dto.getPaymentType().getType(), record.getPaymentType()), "退款方式错误");
|
||||
RefundRecord refundRecord = new RefundRecord()
|
||||
.setRefundAmount(dto.getAmount())
|
||||
.setRefundPoint(dto.getPoint())
|
||||
.setRefundToken(dto.getToken())
|
||||
.setPaymentRecordId(record.getId())
|
||||
.setOrderId(record.getOrderId())
|
||||
.setOrderType(record.getOrderType())
|
||||
.setPaymentType(record.getPaymentType())
|
||||
.setRefundStatus(1);
|
||||
refundRecordService.save(refundRecord);
|
||||
String refundNo = StringPool.EMPTY;
|
||||
switch (dto.getPaymentType()) {
|
||||
case ALI:
|
||||
refundNo = aliPaymentService.refundPartial(dto.getAmount(), String.valueOf(record.getId()), String.valueOf(refundRecord.getId()));
|
||||
if (StrUtil.isNotEmpty(refundNo)) {
|
||||
refundRecord.setRefundStatus(2);
|
||||
backUserSkipAds(record.getTotalAmount(), refundRecord.getRefundAmount(), record.getOrderId(), dto);
|
||||
}
|
||||
break;
|
||||
case WECHAT:
|
||||
refundNo = wechatPaymentService.refundPartial(dto.getTotalAmount(), dto.getAmount(), String.valueOf(record.getId()), String.valueOf(refundRecord.getId()));
|
||||
if (StrUtil.isNotEmpty(refundNo)) {
|
||||
refundRecord.setRefundStatus(2);
|
||||
backUserSkipAds(record.getTotalAmount(), refundRecord.getRefundAmount(), record.getOrderId(), dto);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("退款类型错误");
|
||||
}
|
||||
log.info("退款凭证:{}", refundNo);
|
||||
refundRecordService.updateById(refundRecord.setRefundNo(refundNo));
|
||||
return new RefundResult().setStatus(refundRecord.getRefundStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, List<RefundRecordDTO>> queryRefund(List<Long> orderId) {
|
||||
return refundRecordService.selectRefundByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefundTotalDto selectRefundAmount(Long orderId) {
|
||||
return refundRecordService.selectRefundAmount(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付记录
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PaymentRecord queryRecord(QueryDto dto) {
|
||||
return recordService.getOne(Wrappers.<PaymentRecord>lambdaQuery()
|
||||
.eq(PaymentRecord::getOrderId, dto.getOrderId())
|
||||
.eq(PaymentRecord::getOrderType, dto.getOrderType().getCode())
|
||||
.eq(PaymentRecord::getPaymentType, dto.getPaymentType().getType())
|
||||
.eq(dto.getPaymentStatus() != null, PaymentRecord::getPaymentStatus, dto.getPaymentStatus())
|
||||
.orderByDesc(PaymentRecord::getId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 消费金 token 退款
|
||||
*
|
||||
* @param dto
|
||||
* @param record
|
||||
*/
|
||||
private void virtualRefund(RefundDto dto, PaymentRecord record) {
|
||||
if (dto.getPoint() != null) {
|
||||
if (dto.getPoint().compareTo(BigDecimal.ZERO) > 0) {
|
||||
Assert.isTrue(record.getActualPoint().compareTo(dto.getPoint()) >= 0, "使用贡值退款金额大于实际扣除金额");
|
||||
if (record.getActualPoint().compareTo(dto.getPoint()) >= 0) {
|
||||
record.setActualPoint(record.getActualPoint().subtract(dto.getPoint()));
|
||||
recordService.updateById(record);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (record.getActualPoint().compareTo(BigDecimal.ZERO) > 0) {
|
||||
record.setActualPoint(BigDecimal.ZERO);
|
||||
recordService.updateById(record);
|
||||
}
|
||||
}
|
||||
if (dto.getToken() != null) {
|
||||
if (dto.getToken().compareTo(BigDecimal.ZERO) > 0) {
|
||||
Assert.isTrue(record.getActualToken().compareTo(dto.getPoint()) >= 0, "消费金退款金额大于实际扣除金额");
|
||||
record.setActualToken(record.getActualToken().subtract(dto.getPoint()));
|
||||
recordService.updateById(record);
|
||||
}
|
||||
} else {
|
||||
if (record.getActualToken().compareTo(BigDecimal.ZERO) > 0) {
|
||||
record.setActualToken(BigDecimal.ZERO);
|
||||
recordService.updateById(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款推送(回收30天权益)
|
||||
*
|
||||
* @param totalAmount
|
||||
* @param refundAmount
|
||||
* @param orderId
|
||||
* @param dto
|
||||
*/
|
||||
private void backUserSkipAds(BigDecimal totalAmount, BigDecimal refundAmount, Long orderId, RefundDto dto) {
|
||||
if (totalAmount.compareTo(refundAmount) > 0) {
|
||||
refundAmount = refundAmount.add(refundRecordService.refundAmount(orderId));
|
||||
}
|
||||
if (totalAmount.compareTo(refundAmount) == 0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.modules.payment.client;
|
||||
|
||||
import com.dtflys.forest.annotation.JSONBody;
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
import com.dtflys.forest.annotation.Var;
|
||||
import org.springblade.modules.payment.request.allinpay.QueryOrderRequest;
|
||||
import org.springblade.modules.payment.request.allinpay.RefundOrderRequest;
|
||||
import org.springblade.modules.payment.response.allinpay.Response;
|
||||
|
||||
public interface AllInPayClient {
|
||||
|
||||
@Post("{baseUrl}/api/pay/unifiedOrder")
|
||||
Response<String> unifiedOrder(@Var("baseUrl") String baseUrl, String request);
|
||||
|
||||
@Post("{baseUrl}/api/pay/queryPayway")
|
||||
Response<String> queryPayway(@Var("baseUrl") String baseUrl, String request);
|
||||
|
||||
@Post("{baseUrl}/api/pay/queryPayList")
|
||||
Response<String> queryPayList(@Var("baseUrl") String baseUrl, String request);
|
||||
|
||||
@Post("{baseUrl}/api/pay/query")
|
||||
Response<String> query(@Var("baseUrl") String baseUrl, @JSONBody QueryOrderRequest request);
|
||||
|
||||
@Post("{baseUrl}/api/refund/refundOrder")
|
||||
Response<String> refundOrder(@Var("baseUrl") String baseUrl, @JSONBody RefundOrderRequest request);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.springblade.modules.payment.client;
|
||||
|
||||
import com.dtflys.forest.annotation.Body;
|
||||
import com.dtflys.forest.annotation.Header;
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
|
||||
public interface WxMicroPayClient {
|
||||
|
||||
@Post("https://api.mch.weixin.qq.com/pay/micropay")
|
||||
@Header("Content-Type:application/xml")
|
||||
String prepay(@Body String request);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springblade.modules.payment.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "allinpay")
|
||||
public class AllInPayConfiguration {
|
||||
|
||||
private String host;
|
||||
|
||||
private String merchantsNo;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String privateKey;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String refundUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springblade.modules.payment.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "wechatpay")
|
||||
public class WechatPayConfiguration {
|
||||
|
||||
private String mchId;
|
||||
|
||||
private String mchKey;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String privateKey;
|
||||
|
||||
private String apiKey;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.springblade.modules.payment.constant;
|
||||
|
||||
public class PaymentConstant {
|
||||
public static final String ALI_PREFIX = "ali-";
|
||||
public static final String MEMBER_ALI_PREFIX = "mem-ali-";
|
||||
public static final String WECHAT_PREFIX = "wx-";
|
||||
public static final String MEMBER_WECHAT_PREFIX = "mem-wx-";
|
||||
public static final String ALIPAY = "1";
|
||||
public static final String WECHAT = "2";
|
||||
public static final String ALIPAY_P = "5";
|
||||
public static final String WECHAT_P = "6";
|
||||
//支付状态 1-待支付 2-已支付 3已关闭 4退款中 5已退款 等待
|
||||
public static final Integer PAYMENT_STATUS_AWAIT = 1;
|
||||
public static final Integer PAYMENT_STATUS_PAY = 2;
|
||||
public static final Integer PAYMENT_STATUS_CLOSE = 3;
|
||||
public static final Integer PAYMENT_STATUS_REFUND_DOING = 4;
|
||||
public static final Integer PAYMENT_STATUS_REFUND_END = 5;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.springblade.modules.payment.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.modules.payment.entity.PaymentRecord;
|
||||
import org.springblade.modules.payment.service.PaymentRecordService;
|
||||
import org.springblade.modules.payment.vo.PaymentRecordVO;
|
||||
import org.springblade.modules.payment.wrapper.PaymentRecordWrapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 支付记录 控制器
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-12-19
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/payment/record")
|
||||
@Api(value = "支付记录", tags = "支付记录接口")
|
||||
public class PaymentRecordController extends BladeController {
|
||||
|
||||
private final PaymentRecordService recordService;
|
||||
|
||||
/**
|
||||
* 支付记录 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入record")
|
||||
public R<PaymentRecordVO> detail(PaymentRecord record) {
|
||||
PaymentRecord detail = recordService.getOne(Condition.getQueryWrapper(record));
|
||||
return R.data(PaymentRecordWrapper.build().entityVO(detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入record")
|
||||
public R<IPage<PaymentRecordVO>> list(PaymentRecord record, Query query) {
|
||||
IPage<PaymentRecord> pages = recordService.page(Condition.getPage(query), Condition.getQueryWrapper(record));
|
||||
return R.data(PaymentRecordWrapper.build().pageVO(pages));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@ApiOperation(value = "分页", notes = "传入record")
|
||||
public R<IPage<PaymentRecordVO>> page(PaymentRecordVO record, Query query) {
|
||||
IPage<PaymentRecordVO> pages = recordService.selectRecordPage(Condition.getPage(query), record);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperation(value = "新增", notes = "传入record")
|
||||
public R save(@Valid @RequestBody PaymentRecord record) {
|
||||
return R.status(recordService.save(record));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperation(value = "修改", notes = "传入record")
|
||||
public R update(@Valid @RequestBody PaymentRecord record) {
|
||||
return R.status(recordService.updateById(record));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "新增或修改", notes = "传入record")
|
||||
public R submit(@Valid @RequestBody PaymentRecord record) {
|
||||
return R.status(recordService.saveOrUpdate(record));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付记录 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(recordService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.springblade.modules.payment.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springblade.modules.payment.enums.BizTypeEnum;
|
||||
import org.springblade.modules.payment.enums.PaymentTypeEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class APPPayDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PaymentTypeEnum paymentType;
|
||||
|
||||
private BizTypeEnum orderType;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Date expireTime;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springblade.modules.payment.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.modules.payment.entity.PaymentRecord;
|
||||
|
||||
/**
|
||||
* 支付记录 数据传输对象实体类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-12-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PaymentRecordDTO extends PaymentRecord {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springblade.modules.payment.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springblade.modules.payment.enums.BizTypeEnum;
|
||||
import org.springblade.modules.payment.enums.PaymentTypeEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class QueryDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PaymentTypeEnum paymentType;
|
||||
|
||||
private BizTypeEnum orderType;
|
||||
|
||||
private Long orderId;
|
||||
private Integer paymentStatus;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springblade.modules.payment.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springblade.modules.payment.enums.BizTypeEnum;
|
||||
import org.springblade.modules.payment.enums.PaymentTypeEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class RefundDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PaymentTypeEnum paymentType;
|
||||
|
||||
private BizTypeEnum orderType;
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private Long paymentId;
|
||||
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
private BigDecimal amount;
|
||||
private BigDecimal token;
|
||||
private BigDecimal point;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long refundId;
|
||||
|
||||
private String outTradeNo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.springblade.modules.payment.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 退款记录 数据传输对象实体类
|
||||
*
|
||||
* @author RayL
|
||||
* @since 2023-12-26
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class RefundRecordDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
private Integer paymentType;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
private Integer refundStatus;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款抵扣券
|
||||
*/
|
||||
private BigDecimal refundPoint;
|
||||
|
||||
/**
|
||||
* 退款消费金
|
||||
*/
|
||||
private BigDecimal refundToken;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user