commit
19aadc06c0
917 changed files with 357058 additions and 0 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
HELP.md |
||||
target/ |
||||
!.mvn/wrapper/maven-wrapper.jar |
||||
!**/src/main/**/target/ |
||||
!**/src/test/**/target/ |
||||
|
||||
### STS ### |
||||
.apt_generated |
||||
.classpath |
||||
.factorypath |
||||
.project |
||||
.settings |
||||
.springBeans |
||||
.sts4-cache |
||||
|
||||
### IntelliJ IDEA ### |
||||
.idea |
||||
*.iws |
||||
*.iml |
||||
*.ipr |
||||
|
||||
### NetBeans ### |
||||
/nbproject/private/ |
||||
/nbbuild/ |
||||
/dist/ |
||||
/nbdist/ |
||||
/.nb-gradle/ |
||||
build/ |
||||
!**/src/main/**/build/ |
||||
!**/src/test/**/build/ |
||||
|
||||
### VS Code ### |
||||
.vscode/ |
||||
@ -0,0 +1,480 @@
@@ -0,0 +1,480 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-parent</artifactId> |
||||
<version>2.6.6</version> |
||||
<relativePath/> |
||||
</parent> |
||||
|
||||
<groupId>cc.niushuai</groupId> |
||||
<artifactId>db-bastion-server</artifactId> |
||||
<version>0.0.1</version> |
||||
<name>db-bastion-server</name> |
||||
<description>db-bastion-server</description> |
||||
|
||||
<properties> |
||||
<java.version>1.8</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
<maven.compiler.source>8</maven.compiler.source> |
||||
<maven.compiler.target>8</maven.compiler.target> |
||||
|
||||
<!--maven相关插件版本--> |
||||
<plugin.git-commit-id.version>4.9.10</plugin.git-commit-id.version> |
||||
<maven.compiler.version>3.8.1</maven.compiler.version> |
||||
<maven.source.version>3.2.1</maven.source.version> |
||||
<maven.resources.version>3.1.0</maven.resources.version> |
||||
|
||||
<!--fastjson--> |
||||
<fastjson.version>1.2.83</fastjson.version> |
||||
<!--md2html--> |
||||
<pegdown.version>1.6.0</pegdown.version> |
||||
<!--swagger--> |
||||
<knife4j-spring-boot-starter.version>3.0.3</knife4j-spring-boot-starter.version> |
||||
<knife4j-spring-ui.version>2.0.9</knife4j-spring-ui.version> |
||||
<!-- 数据库驱动 --> |
||||
<mysql-connector-java.version>8.0.27</mysql-connector-java.version> |
||||
<hutool.version>5.7.22</hutool.version> |
||||
|
||||
<!-- 持久层 --> |
||||
<mybatis-plus.version>3.5.1</mybatis-plus.version> |
||||
<dynamic-datasource-spring-boot-starter.version>3.2.0</dynamic-datasource-spring-boot-starter.version> |
||||
<druid.version>1.1.22</druid.version> |
||||
|
||||
<!-- shiro --> |
||||
<shiro.version>1.10.0</shiro.version> |
||||
<java-jwt.version>3.11.0</java-jwt.version> |
||||
<shiro-redis.version>3.1.0</shiro-redis.version> |
||||
|
||||
<!--jeecg tools--> |
||||
<autopoi-web.version>1.4.5</autopoi-web.version> |
||||
|
||||
<!--第三方登录--> |
||||
<justauth-spring-boot-starter.version>1.3.4</justauth-spring-boot-starter.version> |
||||
|
||||
<!-- Log4j2爆雷漏洞 --> |
||||
<log4j2.version>2.17.0</log4j2.version> |
||||
<logback.version>1.2.9</logback.version> |
||||
|
||||
<!--aliyun sdk--> |
||||
<aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> |
||||
<aliyun.oss.version>3.11.2</aliyun.oss.version> |
||||
|
||||
|
||||
</properties> |
||||
|
||||
<dependencies> |
||||
|
||||
<!-- Lombok --> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</dependency> |
||||
|
||||
<!--集成springmvc框架并实现自动配置 --> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
<!--redis自动配置--> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
</dependency> |
||||
<!-- websocket --> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-websocket</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-mail</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-aop</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-configuration-processor</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-actuator</artifactId> |
||||
</dependency> |
||||
<!--springboot2.3+ 需引入validation对应的包--> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-validation</artifactId> |
||||
</dependency> |
||||
<!--springboot2.6+解决metrics端点不显示jvm信息的问题--> |
||||
<dependency> |
||||
<groupId>io.micrometer</groupId> |
||||
<artifactId>micrometer-registry-prometheus</artifactId> |
||||
</dependency> |
||||
|
||||
<!-- freemarker --> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-freemarker</artifactId> |
||||
</dependency> |
||||
|
||||
<!-- mybatis-plus --> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>${mybatis-plus.version}</version> |
||||
</dependency> |
||||
|
||||
<!-- druid --> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid-spring-boot-starter</artifactId> |
||||
<version>${druid.version}</version> |
||||
</dependency> |
||||
|
||||
<!-- 动态数据源 --> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
||||
<version>${dynamic-datasource-spring-boot-starter.version}</version> |
||||
</dependency> |
||||
|
||||
<!-- 数据库驱动 --> |
||||
<!--mysql--> |
||||
<dependency> |
||||
<groupId>mysql</groupId> |
||||
<artifactId>mysql-connector-java</artifactId> |
||||
<version>${mysql-connector-java.version}</version> |
||||
<scope>runtime</scope> |
||||
</dependency> |
||||
|
||||
<!-- Quartz定时任务 --> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-quartz</artifactId> |
||||
</dependency> |
||||
|
||||
<!--JWT--> |
||||
<dependency> |
||||
<groupId>com.auth0</groupId> |
||||
<artifactId>java-jwt</artifactId> |
||||
<version>${java-jwt.version}</version> |
||||
</dependency> |
||||
|
||||
<!--shiro--> |
||||
<dependency> |
||||
<groupId>org.apache.shiro</groupId> |
||||
<artifactId>shiro-spring-boot-starter</artifactId> |
||||
<version>${shiro.version}</version> |
||||
</dependency> |
||||
<!-- shiro-redis --> |
||||
<dependency> |
||||
<groupId>org.crazycake</groupId> |
||||
<artifactId>shiro-redis</artifactId> |
||||
<version>${shiro-redis.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.apache.shiro</groupId> |
||||
<artifactId>shiro-core</artifactId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>guava</artifactId> |
||||
<groupId>com.google.guava</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<!-- knife4j --> |
||||
<dependency> |
||||
<groupId>com.github.xiaoymin</groupId> |
||||
<artifactId>knife4j-spring-boot-starter</artifactId> |
||||
<version>${knife4j-spring-boot-starter.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<artifactId>guava</artifactId> |
||||
<groupId>com.google.guava</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>swagger-annotations</artifactId> |
||||
<groupId>io.swagger</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-all</artifactId> |
||||
<version>${hutool.version}</version> |
||||
</dependency> |
||||
|
||||
<!-- AutoPoi Excel工具类--> |
||||
<dependency> |
||||
<groupId>org.jeecgframework</groupId> |
||||
<artifactId>autopoi-web</artifactId> |
||||
<version>${autopoi-web.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>commons-codec</groupId> |
||||
<artifactId>commons-codec</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<!-- 阿里云短信 --> |
||||
<dependency> |
||||
<groupId>com.aliyun</groupId> |
||||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId> |
||||
<version>${aliyun-java-sdk-dysmsapi.version}</version> |
||||
</dependency> |
||||
<!-- aliyun oss --> |
||||
<dependency> |
||||
<groupId>com.aliyun.oss</groupId> |
||||
<artifactId>aliyun-sdk-oss</artifactId> |
||||
<version>${aliyun.oss.version}</version> |
||||
</dependency> |
||||
|
||||
|
||||
<!-- 企业微信/钉钉 api --> |
||||
<dependency> |
||||
<groupId>org.jeecgframework</groupId> |
||||
<artifactId>jeewx-api</artifactId> |
||||
<version>1.5.0</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<artifactId>commons-logging</artifactId> |
||||
<groupId>commons-logging</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>commons-beanutils</artifactId> |
||||
<groupId>commons-beanutils</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>commons-lang</artifactId> |
||||
<groupId>commons-lang</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
|
||||
<!-- json --> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>${fastjson.version}</version> |
||||
</dependency> |
||||
<!-- markdown --> |
||||
<dependency> |
||||
<groupId>org.pegdown</groupId> |
||||
<artifactId>pegdown</artifactId> |
||||
<version>${pegdown.version}</version> |
||||
</dependency> |
||||
|
||||
|
||||
<!--test--> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<!-- justauth第三方登录 --> |
||||
<dependency> |
||||
<groupId>com.xkcoding.justauth</groupId> |
||||
<artifactId>justauth-spring-boot-starter</artifactId> |
||||
<version>${justauth-spring-boot-starter.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<artifactId>hutool-core</artifactId> |
||||
<groupId>cn.hutool</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>fastjson</artifactId> |
||||
<groupId>com.alibaba</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
<artifactId>okhttp</artifactId> |
||||
<version>4.4.1</version> |
||||
</dependency> |
||||
|
||||
<!--minio--> |
||||
<dependency> |
||||
<groupId>io.minio</groupId> |
||||
<artifactId>minio</artifactId> |
||||
<version>8.0.3</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<artifactId>okio</artifactId> |
||||
<groupId>com.squareup.okio</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>okhttp</artifactId> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.swagger</groupId> |
||||
<artifactId>swagger-annotations</artifactId> |
||||
<version>1.6.9</version> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
|
||||
<repositories> |
||||
<repository> |
||||
<id>aliyun</id> |
||||
<url>https://maven.aliyun.com/repository/public</url> |
||||
<releases> |
||||
<enabled>true</enabled> |
||||
</releases> |
||||
<snapshots> |
||||
<enabled>false</enabled> |
||||
</snapshots> |
||||
</repository> |
||||
</repositories> |
||||
<pluginRepositories> |
||||
<pluginRepository> |
||||
<id>aliyun-plugin</id> |
||||
<url>https://maven.aliyun.com/repository/public</url> |
||||
<releases> |
||||
<enabled>true</enabled> |
||||
</releases> |
||||
<snapshots> |
||||
<enabled>false</enabled> |
||||
</snapshots> |
||||
</pluginRepository> |
||||
</pluginRepositories> |
||||
|
||||
<build> |
||||
<finalName>${project.name}</finalName> |
||||
<plugins> |
||||
<!--生成git提交信息插件--> |
||||
<plugin> |
||||
<groupId>pl.project13.maven</groupId> |
||||
<artifactId>git-commit-id-plugin</artifactId> |
||||
<version>${plugin.git-commit-id.version}</version> |
||||
<executions> |
||||
<execution> |
||||
<id>get-the-git-infos</id> |
||||
<goals> |
||||
<goal>revision</goal> |
||||
</goals> |
||||
<phase>initialize</phase> |
||||
</execution> |
||||
</executions> |
||||
<configuration> |
||||
<verbose>false</verbose> |
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory> |
||||
<prefix>git</prefix> |
||||
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat> |
||||
<dateFormatTimeZone>${user.timezone}</dateFormatTimeZone> |
||||
<generateGitPropertiesFile>true</generateGitPropertiesFile> |
||||
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename> |
||||
<commitIdGenerationMode>full</commitIdGenerationMode> |
||||
<format>properties</format> |
||||
</configuration> |
||||
</plugin> |
||||
<!--指定编译插件--> |
||||
<plugin> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>${maven.compiler.version}</version> |
||||
<configuration> |
||||
<source>${java.version}</source> |
||||
<target>${java.version}</target> |
||||
<encoding>UTF-8</encoding> |
||||
<compilerArgs> |
||||
<arg>-parameters</arg> |
||||
</compilerArgs> |
||||
</configuration> |
||||
</plugin> |
||||
<!-- 避免font文件的二进制文件格式压缩破坏 生成源码包--> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-resources-plugin</artifactId> |
||||
<version>${maven.resources.version}</version> |
||||
<configuration> |
||||
<nonFilteredFileExtensions> |
||||
<nonFilteredFileExtension>woff</nonFilteredFileExtension> |
||||
<nonFilteredFileExtension>woff2</nonFilteredFileExtension> |
||||
<nonFilteredFileExtension>eot</nonFilteredFileExtension> |
||||
<nonFilteredFileExtension>ttf</nonFilteredFileExtension> |
||||
<nonFilteredFileExtension>svg</nonFilteredFileExtension> |
||||
</nonFilteredFileExtensions> |
||||
</configuration> |
||||
</plugin> |
||||
<!--构建时生成源码包--> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-source-plugin</artifactId> |
||||
<version>${maven.source.version}</version> |
||||
<executions> |
||||
<execution> |
||||
<id>attach-sources</id> |
||||
<goals> |
||||
<goal>jar-no-fork</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<!--打包跳过测试--> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<skipTests>true</skipTests> |
||||
</configuration> |
||||
</plugin> |
||||
<!--jar打包插件--> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<finalName>${project.build.finalName}</finalName> |
||||
<fork>true</fork> |
||||
<excludes> |
||||
<exclude> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</exclude> |
||||
</excludes> |
||||
</configuration> |
||||
<executions> |
||||
<execution> |
||||
<goals> |
||||
<goal>repackage</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources</directory> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
<resource> |
||||
<directory>src/main/java</directory> |
||||
<includes> |
||||
<include>**/*.xml</include> |
||||
<include>**/*.json</include> |
||||
<include>**/*.ftl</include> |
||||
</includes> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
|
||||
</project> |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
package cc.niushuai.bastionserver; |
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
/** |
||||
* Db Bastion Server App Entrance |
||||
* |
||||
* @author: niushuai233 |
||||
* @date: 2022/12/22 17:28 |
||||
*/ |
||||
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) |
||||
public class DbBastionServerApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(DbBastionServerApplication.class, args); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
package cc.niushuai.bastionserver.common.annotation; |
||||
|
||||
import org.springframework.core.annotation.AliasFor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* @Author:zyf |
||||
* @Date:2019-07-31 10:43 |
||||
* @Description: 消息队列初始化注解 |
||||
**/ |
||||
@Documented |
||||
@Inherited |
||||
@Target({ElementType.TYPE}) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Component |
||||
public @interface RabbitComponent { |
||||
@AliasFor( |
||||
annotation = Component.class |
||||
) |
||||
String value(); |
||||
} |
||||
@ -0,0 +1,143 @@
@@ -0,0 +1,143 @@
|
||||
package cc.niushuai.bastionserver.common.api; |
||||
|
||||
import cc.niushuai.bastionserver.common.system.vo.*; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 通用api |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public interface CommonAPI { |
||||
|
||||
/** |
||||
* 1查询用户角色信息 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
Set<String> queryUserRoles(String username); |
||||
|
||||
|
||||
/** |
||||
* 2查询用户权限信息 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
Set<String> queryUserAuths(String username); |
||||
|
||||
/** |
||||
* 3根据 id 查询数据库中存储的 DynamicDataSourceModel |
||||
* |
||||
* @param dbSourceId |
||||
* @return |
||||
*/ |
||||
DynamicDataSourceModel getDynamicDbSourceById(String dbSourceId); |
||||
|
||||
/** |
||||
* 4根据 code 查询数据库中存储的 DynamicDataSourceModel |
||||
* |
||||
* @param dbSourceCode |
||||
* @return |
||||
*/ |
||||
DynamicDataSourceModel getDynamicDbSourceByCode(String dbSourceCode); |
||||
|
||||
/** |
||||
* 5根据用户账号查询用户信息 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public LoginUser getUserByName(String username); |
||||
|
||||
|
||||
/** |
||||
* 6字典表的 翻译 |
||||
* |
||||
* @param table |
||||
* @param text |
||||
* @param code |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
String translateDictFromTable(String table, String text, String code, String key); |
||||
|
||||
/** |
||||
* 7普通字典的翻译 |
||||
* |
||||
* @param code |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
String translateDict(String code, String key); |
||||
|
||||
/** |
||||
* 8查询数据权限 |
||||
* |
||||
* @param component 组件 |
||||
* @param username 用户名 |
||||
* @param requestPath 前段请求地址 |
||||
* @return |
||||
*/ |
||||
List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username); |
||||
|
||||
|
||||
/** |
||||
* 9查询用户信息 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
SysUserCacheInfo getCacheUser(String username); |
||||
|
||||
/** |
||||
* 10获取数据字典 |
||||
* |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public List<DictModel> queryDictItemsByCode(String code); |
||||
|
||||
/** |
||||
* 获取有效的数据字典项 |
||||
* |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public List<DictModel> queryEnableDictItemsByCode(String code); |
||||
|
||||
/** |
||||
* 13获取表数据字典 |
||||
* |
||||
* @param table |
||||
* @param text |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
List<DictModel> queryTableDictItemsByCode(String table, String text, String code); |
||||
|
||||
/** |
||||
* 14 普通字典的翻译,根据多个dictCode和多条数据,多个以逗号分割 |
||||
* |
||||
* @param dictCodes 例如:user_status,sex |
||||
* @param keys 例如:1,2,0 |
||||
* @return |
||||
*/ |
||||
Map<String, List<DictModel>> translateManyDict(String dictCodes, String keys); |
||||
|
||||
/** |
||||
* 15 字典表的 翻译,可批量 |
||||
* |
||||
* @param table |
||||
* @param text |
||||
* @param code |
||||
* @param keys 多个用逗号分割 |
||||
* @return |
||||
*/ |
||||
List<DictModel> translateDictFromTableByKeys(String table, String text, String code, String keys); |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @Author taoYan |
||||
* @Date 2022/7/26 14:44 |
||||
**/ |
||||
@Data |
||||
public class DataLogDTO { |
||||
|
||||
private String tableName; |
||||
|
||||
private String dataId; |
||||
|
||||
private String content; |
||||
|
||||
private String type; |
||||
|
||||
public DataLogDTO() { |
||||
|
||||
} |
||||
|
||||
public DataLogDTO(String tableName, String dataId, String content, String type) { |
||||
this.tableName = tableName; |
||||
this.dataId = dataId; |
||||
this.content = content; |
||||
this.type = type; |
||||
} |
||||
|
||||
public DataLogDTO(String tableName, String dataId, String type) { |
||||
this.tableName = tableName; |
||||
this.dataId = dataId; |
||||
this.type = type; |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* 文件下载 |
||||
* cloud api 用到的接口传输对象 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class FileDownDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 6749126258686446019L; |
||||
|
||||
private String filePath; |
||||
private String uploadpath; |
||||
private String uploadType; |
||||
private HttpServletResponse response; |
||||
|
||||
public FileDownDTO() { |
||||
} |
||||
|
||||
public FileDownDTO(String filePath, String uploadpath, String uploadType, HttpServletResponse response) { |
||||
this.filePath = filePath; |
||||
this.uploadpath = uploadpath; |
||||
this.uploadType = uploadType; |
||||
this.response = response; |
||||
} |
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* 文件上传 |
||||
* cloud api 用到的接口传输对象 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class FileUploadDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = -4111953058578954386L; |
||||
|
||||
private MultipartFile file; |
||||
|
||||
private String bizPath; |
||||
|
||||
private String uploadType; |
||||
|
||||
private String customBucket; |
||||
|
||||
public FileUploadDTO() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 简单上传 构造器1 |
||||
* |
||||
* @param file |
||||
* @param bizPath |
||||
* @param uploadType |
||||
*/ |
||||
public FileUploadDTO(MultipartFile file, String bizPath, String uploadType) { |
||||
this.file = file; |
||||
this.bizPath = bizPath; |
||||
this.uploadType = uploadType; |
||||
} |
||||
|
||||
/** |
||||
* 申明桶 文件上传 构造器2 |
||||
* |
||||
* @param file |
||||
* @param bizPath |
||||
* @param uploadType |
||||
* @param customBucket |
||||
*/ |
||||
public FileUploadDTO(MultipartFile file, String bizPath, String uploadType, String customBucket) { |
||||
this.file = file; |
||||
this.bizPath = bizPath; |
||||
this.uploadType = uploadType; |
||||
this.customBucket = customBucket; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto; |
||||
|
||||
import cc.niushuai.bastionserver.common.system.vo.LoginUser; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 日志对象 |
||||
* cloud api 用到的接口传输对象 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class LogDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 8482720462943906924L; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String logContent; |
||||
|
||||
/** |
||||
* 日志类型(0:操作日志;1:登录日志;2:定时任务) |
||||
*/ |
||||
private Integer logType; |
||||
|
||||
/** |
||||
* 操作类型(1:添加;2:修改;3:删除;) |
||||
*/ |
||||
private Integer operateType; |
||||
|
||||
/** |
||||
* 登录用户 |
||||
*/ |
||||
private LoginUser loginUser; |
||||
|
||||
private String id; |
||||
private String createBy; |
||||
private Date createTime; |
||||
private Long costTime; |
||||
private String ip; |
||||
|
||||
/** |
||||
* 请求参数 |
||||
*/ |
||||
private String requestParam; |
||||
|
||||
/** |
||||
* 请求类型 |
||||
*/ |
||||
private String requestType; |
||||
|
||||
/** |
||||
* 请求路径 |
||||
*/ |
||||
private String requestUrl; |
||||
|
||||
/** |
||||
* 请求方法 |
||||
*/ |
||||
private String method; |
||||
|
||||
/** |
||||
* 操作人用户名称 |
||||
*/ |
||||
private String username; |
||||
|
||||
/** |
||||
* 操作人用户账户 |
||||
*/ |
||||
private String userid; |
||||
|
||||
public LogDTO() { |
||||
|
||||
} |
||||
|
||||
public LogDTO(String logContent, Integer logType, Integer operatetype) { |
||||
this.logContent = logContent; |
||||
this.logType = logType; |
||||
this.operateType = operatetype; |
||||
} |
||||
|
||||
public LogDTO(String logContent, Integer logType, Integer operatetype, LoginUser loginUser) { |
||||
this.logContent = logContent; |
||||
this.logType = logType; |
||||
this.operateType = operatetype; |
||||
this.loginUser = loginUser; |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* online 拦截器权限判断 |
||||
* cloud api 用到的接口传输对象 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class OnlineAuthDTO implements Serializable { |
||||
private static final long serialVersionUID = 1771827545416418203L; |
||||
|
||||
|
||||
/** |
||||
* 用户名 |
||||
*/ |
||||
private String username; |
||||
|
||||
/** |
||||
* 可能的请求地址 |
||||
*/ |
||||
private List<String> possibleUrl; |
||||
|
||||
/** |
||||
* online开发的菜单地址 |
||||
*/ |
||||
private String onlineFormUrl; |
||||
|
||||
public OnlineAuthDTO() { |
||||
|
||||
} |
||||
|
||||
public OnlineAuthDTO(String username, List<String> possibleUrl, String onlineFormUrl) { |
||||
this.username = username; |
||||
this.possibleUrl = possibleUrl; |
||||
this.onlineFormUrl = onlineFormUrl; |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto.message; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* 带业务参数的消息 |
||||
* |
||||
* @author: taoyan |
||||
* @date: 2022/8/17 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class BusMessageDTO extends MessageDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 9104793287983367669L; |
||||
/** |
||||
* 业务类型 |
||||
*/ |
||||
private String busType; |
||||
|
||||
/** |
||||
* 业务id |
||||
*/ |
||||
private String busId; |
||||
|
||||
public BusMessageDTO() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 构造 带业务参数的消息 |
||||
* |
||||
* @param fromUser |
||||
* @param toUser |
||||
* @param title |
||||
* @param msgContent |
||||
* @param msgCategory |
||||
* @param busType |
||||
* @param busId |
||||
*/ |
||||
public BusMessageDTO(String fromUser, String toUser, String title, String msgContent, String msgCategory, String busType, String busId) { |
||||
super(fromUser, toUser, title, msgContent, msgCategory); |
||||
this.busId = busId; |
||||
this.busType = busType; |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto.message; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 带业务参数的模板消息 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class BusTemplateMessageDTO extends TemplateMessageDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = -4277810906346929459L; |
||||
|
||||
/** |
||||
* 业务类型 |
||||
*/ |
||||
private String busType; |
||||
|
||||
/** |
||||
* 业务id |
||||
*/ |
||||
private String busId; |
||||
|
||||
public BusTemplateMessageDTO() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 构造 带业务参数的模板消息 |
||||
* |
||||
* @param fromUser |
||||
* @param toUser |
||||
* @param title |
||||
* @param templateParam |
||||
* @param templateCode |
||||
* @param busType |
||||
* @param busId |
||||
*/ |
||||
public BusTemplateMessageDTO(String fromUser, String toUser, String title, Map<String, String> templateParam, String templateCode, String busType, String busId) { |
||||
super(fromUser, toUser, title, templateParam, templateCode); |
||||
this.busId = busId; |
||||
this.busType = busType; |
||||
} |
||||
} |
||||
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto.message; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 普通消息 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class MessageDTO implements Serializable { |
||||
private static final long serialVersionUID = -5690444483968058442L; |
||||
|
||||
/** |
||||
* 发送人(用户登录账户) |
||||
*/ |
||||
protected String fromUser; |
||||
|
||||
/** |
||||
* 发送给(用户登录账户) |
||||
*/ |
||||
protected String toUser; |
||||
|
||||
/** |
||||
* 发送给所有人 |
||||
*/ |
||||
protected Boolean toAll; |
||||
|
||||
/** |
||||
* 消息主题 |
||||
*/ |
||||
protected String title; |
||||
|
||||
/** |
||||
* 消息内容 |
||||
*/ |
||||
protected String content; |
||||
|
||||
/** |
||||
* 消息类型 1:消息 2:系统消息 |
||||
*/ |
||||
protected String category; |
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//update-begin---author:taoyan ---date:20220705 for:支持自定义推送类型,邮件、钉钉、企业微信、系统消息-----------
|
||||
|
||||
/** |
||||
* 模板消息对应的模板编码 |
||||
*/ |
||||
protected String templateCode; |
||||
/** |
||||
* 消息类型:cc.niushuai.bastionserver.common.constant.enums.MessageTypeEnum |
||||
* XT("system", "系统消息") |
||||
* YJ("email", "邮件消息") |
||||
* DD("dingtalk", "钉钉消息") |
||||
* QYWX("wechat_enterprise", "企业微信") |
||||
*/ |
||||
protected String type; |
||||
|
||||
/** |
||||
* 是否发送Markdown格式的消息 |
||||
*/ |
||||
protected boolean isMarkdown; |
||||
|
||||
/** |
||||
* 解析模板内容 对应的数据 |
||||
*/ |
||||
protected Map<String, Object> data; |
||||
//update-end---author:taoyan ---date::20220705 for:支持自定义推送类型,邮件、钉钉、企业微信、系统消息-----------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
public MessageDTO() { |
||||
} |
||||
|
||||
/** |
||||
* 构造器1 系统消息 |
||||
*/ |
||||
public MessageDTO(String fromUser, String toUser, String title, String content) { |
||||
this.fromUser = fromUser; |
||||
this.toUser = toUser; |
||||
this.title = title; |
||||
this.content = content; |
||||
//默认 都是2系统消息
|
||||
this.category = CommonConstant.MSG_CATEGORY_2; |
||||
} |
||||
|
||||
/** |
||||
* 构造器2 支持设置category 1:消息 2:系统消息 |
||||
*/ |
||||
public MessageDTO(String fromUser, String toUser, String title, String content, String category) { |
||||
this.fromUser = fromUser; |
||||
this.toUser = toUser; |
||||
this.title = title; |
||||
this.content = content; |
||||
this.category = category; |
||||
} |
||||
|
||||
public boolean isMarkdown() { |
||||
return this.isMarkdown; |
||||
} |
||||
|
||||
public void setIsMarkdown(boolean isMarkdown) { |
||||
this.isMarkdown = isMarkdown; |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto.message; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 消息模板dto |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class TemplateDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 5848247133907528650L; |
||||
|
||||
/** |
||||
* 模板编码 |
||||
*/ |
||||
protected String templateCode; |
||||
|
||||
/** |
||||
* 模板参数 |
||||
*/ |
||||
protected Map<String, String> templateParam; |
||||
|
||||
/** |
||||
* 构造器 通过设置模板参数和模板编码 作为参数获取消息内容 |
||||
*/ |
||||
public TemplateDTO(String templateCode, Map<String, String> templateParam) { |
||||
this.templateCode = templateCode; |
||||
this.templateParam = templateParam; |
||||
} |
||||
|
||||
public TemplateDTO() { |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
package cc.niushuai.bastionserver.common.api.dto.message; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 模板消息 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class TemplateMessageDTO extends TemplateDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 411137565170647585L; |
||||
|
||||
|
||||
/** |
||||
* 发送人(用户登录账户) |
||||
*/ |
||||
protected String fromUser; |
||||
|
||||
/** |
||||
* 发送给(用户登录账户) |
||||
*/ |
||||
protected String toUser; |
||||
|
||||
/** |
||||
* 消息主题 |
||||
*/ |
||||
protected String title; |
||||
|
||||
|
||||
public TemplateMessageDTO() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 构造器1 发模板消息用 |
||||
*/ |
||||
public TemplateMessageDTO(String fromUser, String toUser, String title, Map<String, String> templateParam, String templateCode) { |
||||
super(templateCode, templateParam); |
||||
this.fromUser = fromUser; |
||||
this.toUser = toUser; |
||||
this.title = title; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,178 @@
@@ -0,0 +1,178 @@
|
||||
package cc.niushuai.bastionserver.common.api.vo; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* 接口返回数据格式 |
||||
* |
||||
* @author scott |
||||
* @email jeecgos@163.com |
||||
* @date 2019年1月19日 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "接口返回对象", description = "接口返回对象") |
||||
public class Result<T> implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 成功标志 |
||||
*/ |
||||
@ApiModelProperty(value = "成功标志") |
||||
private boolean success = true; |
||||
|
||||
/** |
||||
* 返回处理消息 |
||||
*/ |
||||
@ApiModelProperty(value = "返回处理消息") |
||||
private String message = ""; |
||||
|
||||
/** |
||||
* 返回代码 |
||||
*/ |
||||
@ApiModelProperty(value = "返回代码") |
||||
private Integer code = 0; |
||||
|
||||
/** |
||||
* 返回数据对象 data |
||||
*/ |
||||
@ApiModelProperty(value = "返回数据对象") |
||||
private T result; |
||||
|
||||
/** |
||||
* 时间戳 |
||||
*/ |
||||
@ApiModelProperty(value = "时间戳") |
||||
private long timestamp = System.currentTimeMillis(); |
||||
@JsonIgnore |
||||
private String onlTable; |
||||
|
||||
public Result() { |
||||
} |
||||
|
||||
/** |
||||
* 兼容VUE3版token失效不跳转登录页面 |
||||
* |
||||
* @param code |
||||
* @param message |
||||
*/ |
||||
public Result(Integer code, String message) { |
||||
this.code = code; |
||||
this.message = message; |
||||
} |
||||
|
||||
public static <T> Result<T> ok() { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> ok(String msg) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
//Result OK(String msg)方法会造成兼容性问题 issues/I4IP3D
|
||||
r.setResult((T) msg); |
||||
r.setMessage(msg); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> ok(T data) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
r.setResult(data); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> OK() { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
return r; |
||||
} |
||||
|
||||
/** |
||||
* 此方法是为了兼容升级所创建 |
||||
* |
||||
* @param msg |
||||
* @param <T> |
||||
* @return |
||||
*/ |
||||
public static <T> Result<T> OK(String msg) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
r.setMessage(msg); |
||||
//Result OK(String msg)方法会造成兼容性问题 issues/I4IP3D
|
||||
r.setResult((T) msg); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> OK(T data) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
r.setResult(data); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> OK(String msg, T data) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(true); |
||||
r.setCode(CommonConstant.SC_OK_200); |
||||
r.setMessage(msg); |
||||
r.setResult(data); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> error(String msg, T data) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setSuccess(false); |
||||
r.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500); |
||||
r.setMessage(msg); |
||||
r.setResult(data); |
||||
return r; |
||||
} |
||||
|
||||
public static <T> Result<T> error(String msg) { |
||||
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); |
||||
} |
||||
|
||||
public static <T> Result<T> error(int code, String msg) { |
||||
Result<T> r = new Result<T>(); |
||||
r.setCode(code); |
||||
r.setMessage(msg); |
||||
r.setSuccess(false); |
||||
return r; |
||||
} |
||||
|
||||
/** |
||||
* 无权限访问返回结果 |
||||
*/ |
||||
public static <T> Result<T> noauth(String msg) { |
||||
return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg); |
||||
} |
||||
|
||||
public Result<T> success(String message) { |
||||
this.message = message; |
||||
this.code = CommonConstant.SC_OK_200; |
||||
this.success = true; |
||||
return this; |
||||
} |
||||
|
||||
public Result<T> error500(String message) { |
||||
this.message = message; |
||||
this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; |
||||
this.success = false; |
||||
return this; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,258 @@
@@ -0,0 +1,258 @@
|
||||
package cc.niushuai.bastionserver.common.aspect; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.dto.LogDTO; |
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.aspect.annotation.AutoLog; |
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.constant.enums.ModuleType; |
||||
import cc.niushuai.bastionserver.common.constant.enums.OperateTypeEnum; |
||||
import cc.niushuai.bastionserver.common.system.vo.LoginUser; |
||||
import cc.niushuai.bastionserver.common.util.IpUtils; |
||||
import cc.niushuai.bastionserver.common.util.SpringContextUtils; |
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
import cc.niushuai.bastionserver.modules.base.service.BaseCommonService; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.serializer.PropertyFilter; |
||||
import org.apache.shiro.SecurityUtils; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.validation.BindingResult; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.ServletRequest; |
||||
import javax.servlet.ServletResponse; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.lang.reflect.Method; |
||||
import java.util.Date; |
||||
|
||||
|
||||
/** |
||||
* 系统日志,切面处理类 |
||||
* |
||||
* @Author scott |
||||
* @email jeecgos@163.com |
||||
* @Date 2018年1月14日 |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
public class AutoLogAspect { |
||||
|
||||
@Resource |
||||
private BaseCommonService baseCommonService; |
||||
|
||||
@Pointcut("@annotation(cc.niushuai.bastionserver.common.aspect.annotation.AutoLog)") |
||||
public void logPointCut() { |
||||
|
||||
} |
||||
|
||||
@Around("logPointCut()") |
||||
public Object around(ProceedingJoinPoint point) throws Throwable { |
||||
long beginTime = System.currentTimeMillis(); |
||||
//执行方法
|
||||
Object result = point.proceed(); |
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime; |
||||
|
||||
//保存日志
|
||||
saveSysLog(point, time, result); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) { |
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
|
||||
LogDTO dto = new LogDTO(); |
||||
AutoLog syslog = method.getAnnotation(AutoLog.class); |
||||
if (syslog != null) { |
||||
//update-begin-author:taoyan date:
|
||||
String content = syslog.value(); |
||||
if (syslog.module() == ModuleType.ONLINE) { |
||||
content = getOnlineLogContent(obj, content); |
||||
} |
||||
//注解上的描述,操作日志内容
|
||||
dto.setLogType(syslog.logType()); |
||||
dto.setLogContent(content); |
||||
} |
||||
|
||||
//请求的方法名
|
||||
String className = joinPoint.getTarget().getClass().getName(); |
||||
String methodName = signature.getName(); |
||||
dto.setMethod(className + "." + methodName + "()"); |
||||
|
||||
|
||||
//设置操作类型
|
||||
if (CommonConstant.LOG_TYPE_2 == dto.getLogType()) { |
||||
dto.setOperateType(getOperateType(methodName, syslog.operateType())); |
||||
} |
||||
|
||||
//获取request
|
||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); |
||||
//请求的参数
|
||||
dto.setRequestParam(getReqestParams(request, joinPoint)); |
||||
//设置IP地址
|
||||
dto.setIp(IpUtils.getIpAddr(request)); |
||||
//获取登录用户信息
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
||||
if (sysUser != null) { |
||||
dto.setUserid(sysUser.getUsername()); |
||||
dto.setUsername(sysUser.getRealname()); |
||||
|
||||
} |
||||
//耗时
|
||||
dto.setCostTime(time); |
||||
dto.setCreateTime(new Date()); |
||||
//保存系统日志
|
||||
baseCommonService.addLog(dto); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取操作类型 |
||||
*/ |
||||
private int getOperateType(String methodName, int operateType) { |
||||
if (operateType > 0) { |
||||
return operateType; |
||||
} |
||||
//update-begin---author:wangshuai ---date:20220331 for:阿里云代码扫描规范(不允许任何魔法值出现在代码中)------------
|
||||
return OperateTypeEnum.getTypeByMethodName(methodName); |
||||
//update-end---author:wangshuai ---date:20220331 for:阿里云代码扫描规范(不允许任何魔法值出现在代码中)------------
|
||||
} |
||||
|
||||
/** |
||||
* @param request: request |
||||
* @param joinPoint: joinPoint |
||||
* @Description: 获取请求参数 |
||||
* @author: scott |
||||
* @date: 2020/4/16 0:10 |
||||
* @Return: java.lang.String |
||||
*/ |
||||
private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint) { |
||||
String httpMethod = request.getMethod(); |
||||
String params = ""; |
||||
if (CommonConstant.HTTP_POST.equals(httpMethod) || CommonConstant.HTTP_PUT.equals(httpMethod) || CommonConstant.HTTP_PATCH.equals(httpMethod)) { |
||||
Object[] paramsArray = joinPoint.getArgs(); |
||||
// java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
||||
// https://my.oschina.net/mengzhang6/blog/2395893
|
||||
Object[] arguments = new Object[paramsArray.length]; |
||||
for (int i = 0; i < paramsArray.length; i++) { |
||||
if (paramsArray[i] instanceof BindingResult || paramsArray[i] instanceof ServletRequest || paramsArray[i] instanceof ServletResponse || paramsArray[i] instanceof MultipartFile) { |
||||
//ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
||||
//ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
|
||||
continue; |
||||
} |
||||
arguments[i] = paramsArray[i]; |
||||
} |
||||
//update-begin-author:taoyan date:20200724 for:日志数据太长的直接过滤掉
|
||||
PropertyFilter profilter = new PropertyFilter() { |
||||
@Override |
||||
public boolean apply(Object o, String name, Object value) { |
||||
int length = 500; |
||||
if (value != null && value.toString().length() > length) { |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
}; |
||||
params = JSONObject.toJSONString(arguments, profilter); |
||||
//update-end-author:taoyan date:20200724 for:日志数据太长的直接过滤掉
|
||||
} else { |
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
// 请求的方法参数值
|
||||
Object[] args = joinPoint.getArgs(); |
||||
// 请求的方法参数名称
|
||||
LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); |
||||
String[] paramNames = u.getParameterNames(method); |
||||
if (args != null && paramNames != null) { |
||||
for (int i = 0; i < args.length; i++) { |
||||
params += " " + paramNames[i] + ": " + args[i]; |
||||
} |
||||
} |
||||
} |
||||
return params; |
||||
} |
||||
|
||||
/** |
||||
* online日志内容拼接 |
||||
* |
||||
* @param obj |
||||
* @param content |
||||
* @return |
||||
*/ |
||||
private String getOnlineLogContent(Object obj, String content) { |
||||
if (Result.class.isInstance(obj)) { |
||||
Result res = (Result) obj; |
||||
String msg = res.getMessage(); |
||||
String tableName = res.getOnlTable(); |
||||
if (oConvertUtils.isNotEmpty(tableName)) { |
||||
content += ",表名:" + tableName; |
||||
} |
||||
if (res.isSuccess()) { |
||||
content += "," + (oConvertUtils.isEmpty(msg) ? "操作成功" : msg); |
||||
} else { |
||||
content += "," + (oConvertUtils.isEmpty(msg) ? "操作失败" : msg); |
||||
} |
||||
} |
||||
return content; |
||||
} |
||||
|
||||
|
||||
/* private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) { |
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
|
||||
SysLog sysLog = new SysLog(); |
||||
AutoLog syslog = method.getAnnotation(AutoLog.class); |
||||
if(syslog != null){ |
||||
//update-begin-author:taoyan date:
|
||||
String content = syslog.value(); |
||||
if(syslog.module()== ModuleType.ONLINE){ |
||||
content = getOnlineLogContent(obj, content); |
||||
} |
||||
//注解上的描述,操作日志内容
|
||||
sysLog.setLogContent(content); |
||||
sysLog.setLogType(syslog.logType()); |
||||
} |
||||
|
||||
//请求的方法名
|
||||
String className = joinPoint.getTarget().getClass().getName(); |
||||
String methodName = signature.getName(); |
||||
sysLog.setMethod(className + "." + methodName + "()"); |
||||
|
||||
|
||||
//设置操作类型
|
||||
if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) { |
||||
sysLog.setOperateType(getOperateType(methodName, syslog.operateType())); |
||||
} |
||||
|
||||
//获取request
|
||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); |
||||
//请求的参数
|
||||
sysLog.setRequestParam(getReqestParams(request,joinPoint)); |
||||
|
||||
//设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request)); |
||||
|
||||
//获取登录用户信息
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
||||
if(sysUser!=null){ |
||||
sysLog.setUserid(sysUser.getUsername()); |
||||
sysLog.setUsername(sysUser.getRealname()); |
||||
|
||||
} |
||||
//耗时
|
||||
sysLog.setCostTime(time); |
||||
sysLog.setCreateTime(new Date()); |
||||
//保存系统日志
|
||||
sysLogService.save(sysLog); |
||||
}*/ |
||||
} |
||||
@ -0,0 +1,431 @@
@@ -0,0 +1,431 @@
|
||||
package cc.niushuai.bastionserver.common.aspect; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.CommonAPI; |
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.aspect.annotation.Dict; |
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.system.vo.DictModel; |
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.parser.Feature; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.util.*; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Description: 字典aop类 |
||||
* @Author: dangzhenghui |
||||
* @Date: 2019-3-17 21:50 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
@Slf4j |
||||
public class DictAspect { |
||||
private static final String JAVA_UTIL_DATE = "java.util.Date"; |
||||
@Autowired |
||||
public RedisTemplate redisTemplate; |
||||
@Lazy |
||||
@Autowired |
||||
private CommonAPI commonApi; |
||||
@Autowired |
||||
private ObjectMapper objectMapper; |
||||
|
||||
/** |
||||
* 定义切点Pointcut |
||||
*/ |
||||
@Pointcut("execution(public * cc.niushuai.bastionserver.modules..*.*Controller.*(..)) || @annotation(cc.niushuai.bastionserver.common.aspect.annotation.AutoDict)") |
||||
public void excudeService() { |
||||
} |
||||
|
||||
@Around("excudeService()") |
||||
public Object doAround(ProceedingJoinPoint pjp) throws Throwable { |
||||
long time1 = System.currentTimeMillis(); |
||||
Object result = pjp.proceed(); |
||||
long time2 = System.currentTimeMillis(); |
||||
log.trace("获取JSON数据 耗时:" + (time2 - time1) + "ms"); |
||||
long start = System.currentTimeMillis(); |
||||
result = this.parseDictText(result); |
||||
long end = System.currentTimeMillis(); |
||||
log.trace("注入字典到JSON数据 耗时" + (end - start) + "ms"); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 本方法针对返回对象为Result 的IPage的分页列表数据进行动态字典注入 |
||||
* 字典注入实现 通过对实体类添加注解@dict 来标识需要的字典内容,字典分为单字典code即可 ,table字典 code table text配合使用与原来jeecg的用法相同 |
||||
* 示例为SysUser 字段为sex 添加了注解@Dict(dicCode = "sex") 会在字典服务立马查出来对应的text 然后在请求list的时候将这个字典text,已字段名称加_dictText形式返回到前端 |
||||
* 例输入当前返回值的就会多出一个sex_dictText字段 |
||||
* { |
||||
* sex:1, |
||||
* sex_dictText:"男" |
||||
* } |
||||
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了 |
||||
* customRender:function (text) { |
||||
* if(text==1){ |
||||
* return "男"; |
||||
* }else if(text==2){ |
||||
* return "女"; |
||||
* }else{ |
||||
* return text; |
||||
* } |
||||
* } |
||||
* 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用 |
||||
* |
||||
* @param result |
||||
*/ |
||||
private Object parseDictText(Object result) { |
||||
if (result instanceof Result) { |
||||
if (((Result) result).getResult() instanceof IPage) { |
||||
List<JSONObject> items = new ArrayList<>(); |
||||
|
||||
//step.1 筛选出加了 Dict 注解的字段列表
|
||||
List<Field> dictFieldList = new ArrayList<>(); |
||||
// 字典数据列表, key = 字典code,value=数据列表
|
||||
Map<String, List<String>> dataListMap = new HashMap<>(5); |
||||
//取出结果集
|
||||
List<Object> records = ((IPage) ((Result) result).getResult()).getRecords(); |
||||
//update-begin--Author:zyf -- Date:20220606 ----for:【VUEN-1230】 判断是否含有字典注解,没有注解返回-----
|
||||
Boolean hasDict = checkHasDict(records); |
||||
if (!hasDict) { |
||||
return result; |
||||
} |
||||
|
||||
log.trace(" __ 进入字典翻译切面 DictAspect —— "); |
||||
//update-end--Author:zyf -- Date:20220606 ----for:【VUEN-1230】 判断是否含有字典注解,没有注解返回-----
|
||||
for (Object record : records) { |
||||
String json = "{}"; |
||||
try { |
||||
//update-begin--Author:zyf -- Date:20220531 ----for:【issues/#3629】 DictAspect Jackson序列化报错-----
|
||||
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
||||
json = objectMapper.writeValueAsString(record); |
||||
//update-end--Author:zyf -- Date:20220531 ----for:【issues/#3629】 DictAspect Jackson序列化报错-----
|
||||
} catch (JsonProcessingException e) { |
||||
log.error("json解析失败" + e.getMessage(), e); |
||||
} |
||||
//update-begin--Author:scott -- Date:20211223 ----for:【issues/3303】restcontroller返回json数据后key顺序错乱 -----
|
||||
JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); |
||||
//update-end--Author:scott -- Date:20211223 ----for:【issues/3303】restcontroller返回json数据后key顺序错乱 -----
|
||||
|
||||
//update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
||||
//for (Field field : record.getClass().getDeclaredFields()) {
|
||||
// 遍历所有字段,把字典Code取出来,放到 map 里
|
||||
for (Field field : oConvertUtils.getAllFields(record)) { |
||||
String value = item.getString(field.getName()); |
||||
if (oConvertUtils.isEmpty(value)) { |
||||
continue; |
||||
} |
||||
//update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
||||
if (field.getAnnotation(Dict.class) != null) { |
||||
if (!dictFieldList.contains(field)) { |
||||
dictFieldList.add(field); |
||||
} |
||||
String code = field.getAnnotation(Dict.class).dictCode(); |
||||
String text = field.getAnnotation(Dict.class).dictText(); |
||||
String table = field.getAnnotation(Dict.class).dictTable(); |
||||
|
||||
List<String> dataList; |
||||
String dictCode = code; |
||||
if (!StrUtil.isEmpty(table)) { |
||||
dictCode = String.format("%s,%s,%s", table, text, code); |
||||
} |
||||
dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>()); |
||||
this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(","))); |
||||
} |
||||
//date类型默认转换string格式化日期
|
||||
//update-begin--Author:zyf -- Date:20220531 ----for:【issues/#3629】 DictAspect Jackson序列化报错-----
|
||||
//if (JAVA_UTIL_DATE.equals(field.getType().getName())&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
|
||||
//SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
|
||||
//}
|
||||
//update-end--Author:zyf -- Date:20220531 ----for:【issues/#3629】 DictAspect Jackson序列化报错-----
|
||||
} |
||||
items.add(item); |
||||
} |
||||
|
||||
//step.2 调用翻译方法,一次性翻译
|
||||
Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap); |
||||
|
||||
//step.3 将翻译结果填充到返回结果里
|
||||
for (JSONObject record : items) { |
||||
for (Field field : dictFieldList) { |
||||
String code = field.getAnnotation(Dict.class).dictCode(); |
||||
String text = field.getAnnotation(Dict.class).dictText(); |
||||
String table = field.getAnnotation(Dict.class).dictTable(); |
||||
|
||||
String fieldDictCode = code; |
||||
if (!StrUtil.isEmpty(table)) { |
||||
fieldDictCode = String.format("%s,%s,%s", table, text, code); |
||||
} |
||||
|
||||
String value = record.getString(field.getName()); |
||||
if (oConvertUtils.isNotEmpty(value)) { |
||||
List<DictModel> dictModels = translText.get(fieldDictCode); |
||||
if (dictModels == null || dictModels.size() == 0) { |
||||
continue; |
||||
} |
||||
|
||||
String textValue = this.translDictText(dictModels, value); |
||||
log.trace(" 字典Val : " + textValue); |
||||
log.trace(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue); |
||||
|
||||
// TODO-sun 测试输出,待删
|
||||
log.trace(" ---- dictCode: " + fieldDictCode); |
||||
log.trace(" ---- value: " + value); |
||||
log.trace(" ----- text: " + textValue); |
||||
log.trace(" ---- dictModels: " + JSON.toJSONString(dictModels)); |
||||
|
||||
record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); |
||||
} |
||||
} |
||||
} |
||||
|
||||
((IPage) ((Result) result).getResult()).setRecords(items); |
||||
} |
||||
|
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* list 去重添加 |
||||
*/ |
||||
private void listAddAllDeduplicate(List<String> dataList, List<String> addList) { |
||||
// 筛选出dataList中没有的数据
|
||||
List<String> filterList = addList.stream().filter(i -> !dataList.contains(i)).collect(Collectors.toList()); |
||||
dataList.addAll(filterList); |
||||
} |
||||
|
||||
/** |
||||
* 一次性把所有的字典都翻译了 |
||||
* 1. 所有的普通数据字典的所有数据只执行一次SQL |
||||
* 2. 表字典相同的所有数据只执行一次SQL |
||||
* |
||||
* @param dataListMap |
||||
* @return |
||||
*/ |
||||
private Map<String, List<DictModel>> translateAllDict(Map<String, List<String>> dataListMap) { |
||||
// 翻译后的字典文本,key=dictCode
|
||||
Map<String, List<DictModel>> translText = new HashMap<>(5); |
||||
// 需要翻译的数据(有些可以从redis缓存中获取,就不走数据库查询)
|
||||
List<String> needTranslData = new ArrayList<>(); |
||||
//step.1 先通过redis中获取缓存字典数据
|
||||
for (String dictCode : dataListMap.keySet()) { |
||||
List<String> dataList = dataListMap.get(dictCode); |
||||
if (dataList.size() == 0) { |
||||
continue; |
||||
} |
||||
// 表字典需要翻译的数据
|
||||
List<String> needTranslDataTable = new ArrayList<>(); |
||||
for (String s : dataList) { |
||||
String data = s.trim(); |
||||
if (data.length() == 0) { |
||||
continue; //跳过循环
|
||||
} |
||||
if (dictCode.contains(",")) { |
||||
String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s]", dictCode, data); |
||||
if (redisTemplate.hasKey(keyString)) { |
||||
try { |
||||
String text = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); |
||||
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); |
||||
list.add(new DictModel(data, text)); |
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage()); |
||||
} |
||||
} else if (!needTranslDataTable.contains(data)) { |
||||
// 去重添加
|
||||
needTranslDataTable.add(data); |
||||
} |
||||
} else { |
||||
String keyString = String.format("sys:cache:dict::%s:%s", dictCode, data); |
||||
if (redisTemplate.hasKey(keyString)) { |
||||
try { |
||||
String text = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); |
||||
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); |
||||
list.add(new DictModel(data, text)); |
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage()); |
||||
} |
||||
} else if (!needTranslData.contains(data)) { |
||||
// 去重添加
|
||||
needTranslData.add(data); |
||||
} |
||||
} |
||||
|
||||
} |
||||
//step.2 调用数据库翻译表字典
|
||||
if (needTranslDataTable.size() > 0) { |
||||
String[] arr = dictCode.split(","); |
||||
String table = arr[0], text = arr[1], code = arr[2]; |
||||
String values = String.join(",", needTranslDataTable); |
||||
log.trace("translateDictFromTableByKeys.dictCode:" + dictCode); |
||||
log.trace("translateDictFromTableByKeys.values:" + values); |
||||
List<DictModel> texts = commonApi.translateDictFromTableByKeys(table, text, code, values); |
||||
log.trace("translateDictFromTableByKeys.result:" + texts); |
||||
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); |
||||
list.addAll(texts); |
||||
|
||||
// 做 redis 缓存
|
||||
for (DictModel dict : texts) { |
||||
String redisKey = String.format("sys:cache:dictTable::SimpleKey [%s,%s]", dictCode, dict.getValue()); |
||||
try { |
||||
// update-begin-author:taoyan date:20211012 for: 字典表翻译注解缓存未更新 issues/3061
|
||||
// 保留5分钟
|
||||
redisTemplate.opsForValue().set(redisKey, dict.getText(), 300, TimeUnit.SECONDS); |
||||
// update-end-author:taoyan date:20211012 for: 字典表翻译注解缓存未更新 issues/3061
|
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
//step.3 调用数据库进行翻译普通字典
|
||||
if (needTranslData.size() > 0) { |
||||
List<String> dictCodeList = Arrays.asList(dataListMap.keySet().toArray(new String[]{})); |
||||
// 将不包含逗号的字典code筛选出来,因为带逗号的是表字典,而不是普通的数据字典
|
||||
List<String> filterDictCodes = dictCodeList.stream().filter(key -> !key.contains(",")).collect(Collectors.toList()); |
||||
String dictCodes = String.join(",", filterDictCodes); |
||||
String values = String.join(",", needTranslData); |
||||
log.trace("translateManyDict.dictCodes:" + dictCodes); |
||||
log.trace("translateManyDict.values:" + values); |
||||
Map<String, List<DictModel>> manyDict = commonApi.translateManyDict(dictCodes, values); |
||||
log.trace("translateManyDict.result:" + manyDict); |
||||
for (String dictCode : manyDict.keySet()) { |
||||
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); |
||||
List<DictModel> newList = manyDict.get(dictCode); |
||||
list.addAll(newList); |
||||
|
||||
// 做 redis 缓存
|
||||
for (DictModel dict : newList) { |
||||
String redisKey = String.format("sys:cache:dict::%s:%s", dictCode, dict.getValue()); |
||||
try { |
||||
redisTemplate.opsForValue().set(redisKey, dict.getText()); |
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return translText; |
||||
} |
||||
|
||||
/** |
||||
* 字典值替换文本 |
||||
* |
||||
* @param dictModels |
||||
* @param values |
||||
* @return |
||||
*/ |
||||
private String translDictText(List<DictModel> dictModels, String values) { |
||||
List<String> result = new ArrayList<>(); |
||||
|
||||
// 允许多个逗号分隔,允许传数组对象
|
||||
String[] splitVal = values.split(","); |
||||
for (String val : splitVal) { |
||||
String dictText = val; |
||||
for (DictModel dict : dictModels) { |
||||
if (val.equals(dict.getValue())) { |
||||
dictText = dict.getText(); |
||||
break; |
||||
} |
||||
} |
||||
result.add(dictText); |
||||
} |
||||
return String.join(",", result); |
||||
} |
||||
|
||||
/** |
||||
* 翻译字典文本 |
||||
* |
||||
* @param code |
||||
* @param text |
||||
* @param table |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
@Deprecated |
||||
private String translateDictValue(String code, String text, String table, String key) { |
||||
if (oConvertUtils.isEmpty(key)) { |
||||
return null; |
||||
} |
||||
StringBuffer textValue = new StringBuffer(); |
||||
String[] keys = key.split(","); |
||||
for (String k : keys) { |
||||
String tmpValue = null; |
||||
log.trace(" 字典 key : " + k); |
||||
if (k.trim().length() == 0) { |
||||
continue; //跳过循环
|
||||
} |
||||
//update-begin--Author:scott -- Date:20210531 ----for: !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
|
||||
if (!StrUtil.isEmpty(table)) { |
||||
log.trace("--DictAspect------dicTable=" + table + " ,dicText= " + text + " ,dicCode=" + code); |
||||
String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s,%s,%s]", table, text, code, k.trim()); |
||||
if (redisTemplate.hasKey(keyString)) { |
||||
try { |
||||
tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); |
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage()); |
||||
} |
||||
} else { |
||||
tmpValue = commonApi.translateDictFromTable(table, text, code, k.trim()); |
||||
} |
||||
} else { |
||||
String keyString = String.format("sys:cache:dict::%s:%s", code, k.trim()); |
||||
if (redisTemplate.hasKey(keyString)) { |
||||
try { |
||||
tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); |
||||
} catch (Exception e) { |
||||
log.warn(e.getMessage()); |
||||
} |
||||
} else { |
||||
tmpValue = commonApi.translateDict(code, k.trim()); |
||||
} |
||||
} |
||||
//update-end--Author:scott -- Date:20210531 ----for: !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
|
||||
|
||||
if (tmpValue != null) { |
||||
if (!"".equals(textValue.toString())) { |
||||
textValue.append(","); |
||||
} |
||||
textValue.append(tmpValue); |
||||
} |
||||
|
||||
} |
||||
return textValue.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 检测返回结果集中是否包含Dict注解 |
||||
* |
||||
* @param records |
||||
* @return |
||||
*/ |
||||
private Boolean checkHasDict(List<Object> records) { |
||||
if (oConvertUtils.isNotEmpty(records) && records.size() > 0) { |
||||
for (Field field : oConvertUtils.getAllFields(records.get(0))) { |
||||
if (oConvertUtils.isNotEmpty(field.getAnnotation(Dict.class))) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,141 @@
@@ -0,0 +1,141 @@
|
||||
package cc.niushuai.bastionserver.common.aspect; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.CommonAPI; |
||||
import cc.niushuai.bastionserver.common.aspect.annotation.PermissionData; |
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.constant.SymbolConstant; |
||||
import cc.niushuai.bastionserver.common.system.query.QueryRuleEnum; |
||||
import cc.niushuai.bastionserver.common.system.util.JeecgDataAutorUtils; |
||||
import cc.niushuai.bastionserver.common.util.JwtUtil; |
||||
import cc.niushuai.bastionserver.common.system.vo.SysPermissionDataRuleModel; |
||||
import cc.niushuai.bastionserver.common.system.vo.SysUserCacheInfo; |
||||
import cc.niushuai.bastionserver.common.util.SpringContextUtils; |
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.lang.reflect.Method; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 数据权限切面处理类 |
||||
* 当被请求的方法有注解PermissionData时,会在往当前request中写入数据权限信息 |
||||
* |
||||
* @Date 2019年4月10日 |
||||
* @Version: 1.0 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
@Slf4j |
||||
public class PermissionDataAspect { |
||||
private static final String SPOT_DO = ".do"; |
||||
@Lazy |
||||
@Autowired |
||||
private CommonAPI commonApi; |
||||
|
||||
@Pointcut("@annotation(cc.niushuai.bastionserver.common.aspect.annotation.PermissionData)") |
||||
public void pointCut() { |
||||
|
||||
} |
||||
|
||||
@Around("pointCut()") |
||||
public Object arround(ProceedingJoinPoint point) throws Throwable { |
||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); |
||||
MethodSignature signature = (MethodSignature) point.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
PermissionData pd = method.getAnnotation(PermissionData.class); |
||||
String component = pd.pageComponent(); |
||||
String requestMethod = request.getMethod(); |
||||
String requestPath = request.getRequestURI().substring(request.getContextPath().length()); |
||||
requestPath = filterUrl(requestPath); |
||||
//update-begin-author:taoyan date:20211027 for:JTC-132【online报表权限】online报表带参数的菜单配置数据权限无效
|
||||
//先判断是否online报表请求
|
||||
// TODO 参数顺序调整有隐患
|
||||
if (requestPath.indexOf(UrlMatchEnum.CGREPORT_DATA.getMatchUrl()) >= 0) { |
||||
// 获取地址栏参数
|
||||
String urlParamString = request.getParameter(CommonConstant.ONL_REP_URL_PARAM_STR); |
||||
if (oConvertUtils.isNotEmpty(urlParamString)) { |
||||
requestPath += "?" + urlParamString; |
||||
} |
||||
} |
||||
//update-end-author:taoyan date:20211027 for:JTC-132【online报表权限】online报表带参数的菜单配置数据权限无效
|
||||
log.debug("数据权限拦截请求 >> {} ; 请求类型 >> {} . ", requestPath, requestMethod); |
||||
String username = JwtUtil.getUserNameByToken(request); |
||||
//查询数据权限信息
|
||||
//TODO 微服务情况下也得支持缓存机制
|
||||
List<SysPermissionDataRuleModel> dataRules = commonApi.queryPermissionDataRule(component, requestPath, username); |
||||
if (dataRules != null && dataRules.size() > 0) { |
||||
//临时存储
|
||||
JeecgDataAutorUtils.installDataSearchConditon(request, dataRules); |
||||
//TODO 微服务情况下也得支持缓存机制
|
||||
SysUserCacheInfo userinfo = commonApi.getCacheUser(username); |
||||
JeecgDataAutorUtils.installUserInfo(request, userinfo); |
||||
} |
||||
return point.proceed(); |
||||
} |
||||
|
||||
private String filterUrl(String requestPath) { |
||||
String url = ""; |
||||
if (oConvertUtils.isNotEmpty(requestPath)) { |
||||
url = requestPath.replace("\\", "/"); |
||||
url = url.replace("//", "/"); |
||||
if (url.indexOf(SymbolConstant.DOUBLE_SLASH) >= 0) { |
||||
url = filterUrl(url); |
||||
} |
||||
/*if(url.startsWith("/")){ |
||||
url=url.substring(1); |
||||
}*/ |
||||
} |
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求地址 |
||||
* |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
@Deprecated |
||||
private String getJgAuthRequsetPath(HttpServletRequest request) { |
||||
String queryString = request.getQueryString(); |
||||
String requestPath = request.getRequestURI(); |
||||
if (oConvertUtils.isNotEmpty(queryString)) { |
||||
requestPath += "?" + queryString; |
||||
} |
||||
// 去掉其他参数(保留一个参数) 例如:loginController.do?login
|
||||
if (requestPath.indexOf(SymbolConstant.AND) > -1) { |
||||
requestPath = requestPath.substring(0, requestPath.indexOf("&")); |
||||
} |
||||
if (requestPath.indexOf(QueryRuleEnum.EQ.getValue()) != -1) { |
||||
if (requestPath.indexOf(SPOT_DO) != -1) { |
||||
requestPath = requestPath.substring(0, requestPath.indexOf(".do") + 3); |
||||
} else { |
||||
requestPath = requestPath.substring(0, requestPath.indexOf("?")); |
||||
} |
||||
} |
||||
// 去掉项目路径
|
||||
requestPath = requestPath.substring(request.getContextPath().length() + 1); |
||||
return filterUrl(requestPath); |
||||
} |
||||
|
||||
@Deprecated |
||||
private boolean moHuContain(List<String> list, String key) { |
||||
for (String str : list) { |
||||
if (key.contains(str)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
package cc.niushuai.bastionserver.common.aspect; |
||||
|
||||
/** |
||||
* @Author scott |
||||
* @Date 2020/1/14 13:36 |
||||
* @Description: 请求URL与菜单路由URL转换规则(方便于采用菜单路由URL来配置数据权限规则) |
||||
*/ |
||||
public enum UrlMatchEnum { |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgform/api/getData/ |
||||
*/ |
||||
CGFORM_DATA("/online/cgform/api/getData/", "/online/cgformList/"), |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgform/api/exportXls/ |
||||
*/ |
||||
CGFORM_EXCEL_DATA("/online/cgform/api/exportXls/", "/online/cgformList/"), |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgform/api/getTreeData/ |
||||
*/ |
||||
CGFORM_TREE_DATA("/online/cgform/api/getTreeData/", "/online/cgformList/"), |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgreport/api/getColumnsAndData/ |
||||
*/ |
||||
CGREPORT_DATA("/online/cgreport/api/getColumnsAndData/", "/online/cgreport/"), |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgreport/api/exportXls/ |
||||
*/ |
||||
CGREPORT_EXCEL_DATA("/online/cgreport/api/exportXls/", "/online/cgreport/"), |
||||
/** |
||||
* 求URL与菜单路由URL转换规则 /online/cgreport/api/exportManySheetXls/ |
||||
*/ |
||||
CGREPORT_EXCEL_DATA2("/online/cgreport/api/exportManySheetXls/", "/online/cgreport/"); |
||||
|
||||
/** |
||||
* Request 请求 URL前缀 |
||||
*/ |
||||
private String url; |
||||
/** |
||||
* 菜单路由 URL前缀 (对应菜单路径) |
||||
*/ |
||||
private String matchUrl; |
||||
UrlMatchEnum(String url, String matchUrl) { |
||||
this.url = url; |
||||
this.matchUrl = matchUrl; |
||||
} |
||||
|
||||
/** |
||||
* 根据req url 获取到菜单配置路径(前端页面路由URL) |
||||
* |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String getMatchResultByUrl(String url) { |
||||
//获取到枚举
|
||||
UrlMatchEnum[] values = UrlMatchEnum.values(); |
||||
//加强for循环进行遍历操作
|
||||
for (UrlMatchEnum lr : values) { |
||||
//如果遍历获取的type和参数type一致
|
||||
if (url.indexOf(lr.url) != -1) { |
||||
//返回type对象的desc
|
||||
return url.replace(lr.url, lr.matchUrl); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getMatchUrl() { |
||||
return matchUrl; |
||||
} |
||||
// public static void main(String[] args) {
|
||||
// /**
|
||||
// * 比如request真实请求URL: /online/cgform/api/getData/81fcf7d8922d45069b0d5ba983612d3a
|
||||
// * 转换匹配路由URL后(对应配置的菜单路径):/online/cgformList/81fcf7d8922d45069b0d5ba983612d3a
|
||||
// */
|
||||
// System.out.println(UrlMatchEnum.getMatchResultByUrl("/online/cgform/api/getData/81fcf7d8922d45069b0d5ba983612d3a"));
|
||||
// }
|
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 通过此注解声明的接口,自动实现字典翻译 |
||||
* |
||||
* @Author scott |
||||
* @email jeecgos@163.com |
||||
* @Date 2022年01月05日 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface AutoDict { |
||||
|
||||
/** |
||||
* 暂时无用 |
||||
* |
||||
* @return |
||||
*/ |
||||
String value() default ""; |
||||
|
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.constant.enums.ModuleType; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 系统日志注解 |
||||
* |
||||
* @Author scott |
||||
* @email jeecgos@163.com |
||||
* @Date 2019年1月14日 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface AutoLog { |
||||
|
||||
/** |
||||
* 日志内容 |
||||
* |
||||
* @return |
||||
*/ |
||||
String value() default ""; |
||||
|
||||
/** |
||||
* 日志类型 |
||||
* |
||||
* @return 0:操作日志;1:登录日志;2:定时任务; |
||||
*/ |
||||
int logType() default CommonConstant.LOG_TYPE_2; |
||||
|
||||
/** |
||||
* 操作日志类型 |
||||
* |
||||
* @return (1查询,2添加,3修改,4删除) |
||||
*/ |
||||
int operateType() default 0; |
||||
|
||||
/** |
||||
* 模块类型 默认为common |
||||
* |
||||
* @return |
||||
*/ |
||||
ModuleType module() default ModuleType.COMMON; |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.enums.LowAppAopEnum; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 自动注入low_app_id |
||||
* |
||||
* @Author scott |
||||
* @email jeecgos@163.com |
||||
* @Date 2022年01月05日 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface AutoLowApp { |
||||
|
||||
/** |
||||
* 切面类型(add、delete、db_import等其他操作) |
||||
* |
||||
* @return |
||||
*/ |
||||
LowAppAopEnum action(); |
||||
|
||||
/** |
||||
* 业务类型(cgform等) |
||||
* |
||||
* @return |
||||
*/ |
||||
String bizType(); |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* 字典注解 |
||||
* |
||||
* @author: dangzhenghui |
||||
* @date: 2019年03月17日-下午9:37:16 |
||||
*/ |
||||
@Target(ElementType.FIELD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface Dict { |
||||
/** |
||||
* 方法描述: 数据code |
||||
* 作 者: dangzhenghui |
||||
* 日 期: 2019年03月17日-下午9:37:16 |
||||
* |
||||
* @return 返回类型: String |
||||
*/ |
||||
String dictCode(); |
||||
|
||||
/** |
||||
* 方法描述: 数据Text |
||||
* 作 者: dangzhenghui |
||||
* 日 期: 2019年03月17日-下午9:37:16 |
||||
* |
||||
* @return 返回类型: String |
||||
*/ |
||||
String dictText() default ""; |
||||
|
||||
/** |
||||
* 方法描述: 数据字典表 |
||||
* 作 者: dangzhenghui |
||||
* 日 期: 2019年03月17日-下午9:37:16 |
||||
* |
||||
* @return 返回类型: String |
||||
*/ |
||||
String dictTable() default ""; |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 动态table切换 |
||||
* |
||||
* @author :zyf |
||||
* @date:2020-04-25 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface DynamicTable { |
||||
/** |
||||
* 需要动态解析的表名 |
||||
* |
||||
* @return |
||||
*/ |
||||
String value(); |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* online请求拦截专用注解 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target({ElementType.TYPE, ElementType.METHOD}) |
||||
@Documented |
||||
public @interface OnlineAuth { |
||||
|
||||
/** |
||||
* 请求关键字,在xxx/code之前的字符串 |
||||
* |
||||
* @return |
||||
*/ |
||||
String value(); |
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
package cc.niushuai.bastionserver.common.aspect.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 数据权限注解 |
||||
* |
||||
* @Author taoyan |
||||
* @Date 2019年4月11日 |
||||
*/ |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target({ElementType.TYPE, ElementType.METHOD}) |
||||
@Documented |
||||
public @interface PermissionData { |
||||
/** |
||||
* 暂时没用 |
||||
* |
||||
* @return |
||||
*/ |
||||
String value() default ""; |
||||
|
||||
|
||||
/** |
||||
* 配置菜单的组件路径,用于数据权限 |
||||
*/ |
||||
String pageComponent() default ""; |
||||
} |
||||
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
package cc.niushuai.bastionserver.common.base; |
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import org.apache.commons.beanutils.ConvertUtils; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* BaseMap |
||||
* |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:17 |
||||
*/ |
||||
public class BaseMap extends HashMap<String, Object> { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
|
||||
public BaseMap() { |
||||
|
||||
} |
||||
|
||||
public BaseMap(Map<String, Object> map) { |
||||
this.putAll(map); |
||||
} |
||||
|
||||
public static BaseMap toBaseMap(Map<String, Object> obj) { |
||||
BaseMap map = new BaseMap(); |
||||
map.putAll(obj); |
||||
return map; |
||||
} |
||||
|
||||
@Override |
||||
public BaseMap put(String key, Object value) { |
||||
super.put(key, Optional.ofNullable(value).orElse("")); |
||||
return this; |
||||
} |
||||
|
||||
public BaseMap add(String key, Object value) { |
||||
super.put(key, Optional.ofNullable(value).orElse("")); |
||||
return this; |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public <T> T get(String key) { |
||||
Object obj = super.get(key); |
||||
if (ObjectUtil.isNotEmpty(obj)) { |
||||
return (T) obj; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public Boolean getBoolean(String key) { |
||||
Object obj = super.get(key); |
||||
if (ObjectUtil.isNotEmpty(obj)) { |
||||
return Boolean.valueOf(obj.toString()); |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public Long getLong(String key) { |
||||
Object v = get(key); |
||||
if (ObjectUtil.isNotEmpty(v)) { |
||||
return new Long(v.toString()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Long[] getLongs(String key) { |
||||
Object v = get(key); |
||||
if (ObjectUtil.isNotEmpty(v)) { |
||||
return (Long[]) v; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public List<Long> getListLong(String key) { |
||||
List<String> list = get(key); |
||||
if (ObjectUtil.isNotEmpty(list)) { |
||||
return list.stream().map(e -> new Long(e)).collect(Collectors.toList()); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public Long[] getLongIds(String key) { |
||||
Object ids = get(key); |
||||
if (ObjectUtil.isNotEmpty(ids)) { |
||||
return (Long[]) ConvertUtils.convert(ids.toString().split(","), Long.class); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public Integer getInt(String key, Integer def) { |
||||
Object v = get(key); |
||||
if (ObjectUtil.isNotEmpty(v)) { |
||||
return Integer.parseInt(v.toString()); |
||||
} else { |
||||
return def; |
||||
} |
||||
} |
||||
|
||||
public Integer getInt(String key) { |
||||
Object v = get(key); |
||||
if (ObjectUtil.isNotEmpty(v)) { |
||||
return Integer.parseInt(v.toString()); |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
public BigDecimal getBigDecimal(String key) { |
||||
Object v = get(key); |
||||
if (ObjectUtil.isNotEmpty(v)) { |
||||
return new BigDecimal(v.toString()); |
||||
} |
||||
return new BigDecimal("0"); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public <T> T get(String key, T def) { |
||||
Object obj = super.get(key); |
||||
if (ObjectUtil.isEmpty(obj)) { |
||||
return def; |
||||
} |
||||
return (T) obj; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,206 @@
@@ -0,0 +1,206 @@
|
||||
package cc.niushuai.bastionserver.common.base.controller; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.system.query.QueryGenerator; |
||||
import cc.niushuai.bastionserver.common.system.vo.LoginUser; |
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.beanutils.PropertyUtils; |
||||
import org.apache.shiro.SecurityUtils; |
||||
import org.jeecgframework.poi.excel.ExcelImportUtil; |
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
||||
import org.jeecgframework.poi.excel.entity.ExportParams; |
||||
import org.jeecgframework.poi.excel.entity.ImportParams; |
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType; |
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
import org.springframework.web.multipart.MultipartHttpServletRequest; |
||||
import org.springframework.web.servlet.ModelAndView; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @Description: Controller基类 |
||||
* @Author: dangzhenghui@163.com |
||||
* @Date: 2019-4-21 8:13 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Slf4j |
||||
public class BaseController<T, S extends IService<T>> { |
||||
/** |
||||
* issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service |
||||
*/ |
||||
@Autowired |
||||
protected S service; |
||||
|
||||
@Value("${jeecg.path.upload}") |
||||
private String upLoadPath; |
||||
|
||||
/** |
||||
* 导出excel |
||||
* |
||||
* @param request |
||||
*/ |
||||
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title) { |
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); |
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
||||
|
||||
// 过滤选中数据
|
||||
String selections = request.getParameter("selections"); |
||||
if (oConvertUtils.isNotEmpty(selections)) { |
||||
List<String> selectionList = Arrays.asList(selections.split(",")); |
||||
queryWrapper.in("id", selectionList); |
||||
} |
||||
// Step.2 获取导出数据
|
||||
List<T> exportList = service.list(queryWrapper); |
||||
|
||||
// Step.3 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
||||
//此处设置的filename无效 ,前端会重更新设置一下
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, title); |
||||
mv.addObject(NormalExcelConstants.CLASS, clazz); |
||||
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
||||
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title); |
||||
exportParams.setImageBasePath(upLoadPath); |
||||
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
||||
mv.addObject(NormalExcelConstants.PARAMS, exportParams); |
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList); |
||||
return mv; |
||||
} |
||||
|
||||
/** |
||||
* 根据每页sheet数量导出多sheet |
||||
* |
||||
* @param request |
||||
* @param object 实体类 |
||||
* @param clazz 实体类class |
||||
* @param title 标题 |
||||
* @param exportFields 导出字段自定义 |
||||
* @param pageNum 每个sheet的数据条数 |
||||
* @param request |
||||
*/ |
||||
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) { |
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); |
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
||||
// Step.2 计算分页sheet数据
|
||||
double total = service.count(); |
||||
int count = (int) Math.ceil(total / pageNum); |
||||
//update-begin-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
||||
// Step.3 过滤选中数据
|
||||
String selections = request.getParameter("selections"); |
||||
if (oConvertUtils.isNotEmpty(selections)) { |
||||
List<String> selectionList = Arrays.asList(selections.split(",")); |
||||
queryWrapper.in("id", selectionList); |
||||
} |
||||
//update-end-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
||||
// Step.4 多sheet处理
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>(); |
||||
for (int i = 1; i <= count; i++) { |
||||
Page<T> page = new Page<T>(i, pageNum); |
||||
IPage<T> pageList = service.page(page, queryWrapper); |
||||
List<T> exportList = pageList.getRecords(); |
||||
Map<String, Object> map = new HashMap<>(5); |
||||
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath); |
||||
exportParams.setType(ExcelType.XSSF); |
||||
//map.put("title",exportParams);
|
||||
//表格Title
|
||||
map.put(NormalExcelConstants.PARAMS, exportParams); |
||||
//表格对应实体
|
||||
map.put(NormalExcelConstants.CLASS, clazz); |
||||
//数据集合
|
||||
map.put(NormalExcelConstants.DATA_LIST, exportList); |
||||
listMap.add(map); |
||||
} |
||||
// Step.4 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
||||
//此处设置的filename无效 ,前端会重更新设置一下
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, title); |
||||
mv.addObject(NormalExcelConstants.MAP_LIST, listMap); |
||||
return mv; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据权限导出excel,传入导出字段参数 |
||||
* |
||||
* @param request |
||||
*/ |
||||
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields) { |
||||
ModelAndView mv = this.exportXls(request, object, clazz, title); |
||||
mv.addObject(NormalExcelConstants.EXPORT_FIELDS, exportFields); |
||||
return mv; |
||||
} |
||||
|
||||
/** |
||||
* 获取对象ID |
||||
* |
||||
* @return |
||||
*/ |
||||
private String getId(T item) { |
||||
try { |
||||
return PropertyUtils.getProperty(item, "id").toString(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 通过excel导入数据 |
||||
* |
||||
* @param request |
||||
* @param response |
||||
* @return |
||||
*/ |
||||
protected Result<?> importExcel(HttpServletRequest request, HttpServletResponse response, Class<T> clazz) { |
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue(); |
||||
ImportParams params = new ImportParams(); |
||||
params.setTitleRows(2); |
||||
params.setHeadRows(1); |
||||
params.setNeedSave(true); |
||||
try { |
||||
List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params); |
||||
//update-begin-author:taoyan date:20190528 for:批量插入数据
|
||||
long start = System.currentTimeMillis(); |
||||
service.saveBatch(list); |
||||
//400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
|
||||
//1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
|
||||
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); |
||||
//update-end-author:taoyan date:20190528 for:批量插入数据
|
||||
return Result.ok("文件导入成功!数据行数:" + list.size()); |
||||
} catch (Exception e) { |
||||
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
||||
String msg = e.getMessage(); |
||||
log.error(msg, e); |
||||
if (msg != null && msg.indexOf("Duplicate entry") >= 0) { |
||||
return Result.error("文件导入失败:有重复数据!"); |
||||
} else { |
||||
return Result.error("文件导入失败:" + e.getMessage()); |
||||
} |
||||
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
||||
} finally { |
||||
try { |
||||
file.getInputStream().close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
return Result.error("文件导入失败!"); |
||||
} |
||||
} |
||||
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
package cc.niushuai.bastionserver.common.base.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
import org.jeecgframework.poi.excel.annotation.Excel; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @Description: Entity基类 |
||||
* @Author: dangzhenghui@163.com |
||||
* @Date: 2019-4-28 |
||||
* @Version: 1.1 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
public class BaseEntity implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* ID |
||||
*/ |
||||
@TableId(type = IdType.ASSIGN_ID) |
||||
@ApiModelProperty(value = "ID") |
||||
private String id; |
||||
|
||||
/** |
||||
* 创建人 |
||||
*/ |
||||
@ApiModelProperty(value = "创建人") |
||||
@Excel(name = "创建人", width = 15) |
||||
private String createBy; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@ApiModelProperty(value = "创建时间") |
||||
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") |
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 更新人 |
||||
*/ |
||||
@ApiModelProperty(value = "更新人") |
||||
@Excel(name = "更新人", width = 15) |
||||
private String updateBy; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
@ApiModelProperty(value = "更新时间") |
||||
@Excel(name = "更新时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") |
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date updateTime; |
||||
|
||||
} |
||||
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
package cc.niushuai.bastionserver.common.base.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* @Description: Service基类 |
||||
* @Author: dangzhenghui@163.com |
||||
* @Date: 2019-4-21 8:13 |
||||
* @Version: 1.0 |
||||
*/ |
||||
public interface BaseService<T> extends IService<T> { |
||||
} |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
package cc.niushuai.bastionserver.common.base.service.impl; |
||||
|
||||
import cc.niushuai.bastionserver.common.base.entity.BaseEntity; |
||||
import cc.niushuai.bastionserver.common.base.service.BaseService; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
/** |
||||
* @Description: ServiceImpl基类 |
||||
* @Author: dangzhenghui@163.com |
||||
* @Date: 2019-4-21 8:13 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Slf4j |
||||
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> { |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
package cc.niushuai.bastionserver.common.config; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.SpringContextHolder; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* BeanConfig |
||||
* |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:00 |
||||
*/ |
||||
@Configuration |
||||
public class BeanConfig { |
||||
|
||||
/** |
||||
* Spring上下文工具配置 |
||||
* |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
@ConditionalOnMissingBean(SpringContextHolder.class) |
||||
public SpringContextHolder springContextHolder() { |
||||
SpringContextHolder holder = new SpringContextHolder(); |
||||
return holder; |
||||
} |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
package cc.niushuai.bastionserver.common.config; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
/** |
||||
* 多租户 tenant_id存储器 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Slf4j |
||||
public class TenantContext { |
||||
private static ThreadLocal<String> currentTenant = new ThreadLocal<>(); |
||||
|
||||
public static String getTenant() { |
||||
return currentTenant.get(); |
||||
} |
||||
|
||||
public static void setTenant(String tenant) { |
||||
log.trace(" setting tenant to " + tenant); |
||||
currentTenant.set(tenant); |
||||
} |
||||
|
||||
public static void clear() { |
||||
currentTenant.remove(); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
package cc.niushuai.bastionserver.common.config; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.factory.config.BeanPostProcessor; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* 容器内bean名称打印组件 |
||||
* |
||||
* @author niushuai |
||||
* @date: 2022/4/1 11:51 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
public class ZBeanFactory implements BeanPostProcessor { |
||||
|
||||
@Override |
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) |
||||
throws BeansException { |
||||
return bean; |
||||
} |
||||
|
||||
@Override |
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
||||
log.info("Initializing Spring Bean >>> '" + beanName + "' Succeed"); |
||||
return bean; |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
package cc.niushuai.bastionserver.common.config.mqtoken; |
||||
|
||||
import javax.servlet.*; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* 存放临时令牌Token到线程上下文 |
||||
* <p> |
||||
* 供队列、定时任务 feign调用使用(解决无会话Token问题) |
||||
* |
||||
* @author zyf |
||||
*/ |
||||
public class TransmitUserTokenFilter implements Filter { |
||||
|
||||
private static String X_ACCESS_TOKEN = "X-Access-Token"; |
||||
|
||||
public TransmitUserTokenFilter() { |
||||
} |
||||
|
||||
@Override |
||||
public void init(FilterConfig filterConfig) throws ServletException { |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { |
||||
this.initUserInfo((HttpServletRequest) request); |
||||
chain.doFilter(request, response); |
||||
} |
||||
|
||||
private void initUserInfo(HttpServletRequest request) { |
||||
String token = request.getHeader(X_ACCESS_TOKEN); |
||||
if (token != null) { |
||||
try { |
||||
//将Token放入当前线程上下文中
|
||||
UserTokenContext.setToken(token); |
||||
} catch (Exception e) { |
||||
//e.printStackTrace();
|
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
package cc.niushuai.bastionserver.common.config.mqtoken; |
||||
|
||||
|
||||
/** |
||||
* 用户Token线程上下文 |
||||
* <p> |
||||
* 供队列、定时任务 feign调用使用(解决无会话Token问题) |
||||
* |
||||
* @author zyf |
||||
*/ |
||||
public class UserTokenContext { |
||||
|
||||
/** |
||||
* 当前线程的TOKEN副本 |
||||
*/ |
||||
private static ThreadLocal<String> userToken = new ThreadLocal<String>(); |
||||
|
||||
public UserTokenContext() { |
||||
} |
||||
|
||||
public static String getToken() { |
||||
return userToken.get(); |
||||
} |
||||
|
||||
public static void setToken(String token) { |
||||
userToken.set(token); |
||||
} |
||||
|
||||
public static void remove() { |
||||
userToken.remove(); |
||||
} |
||||
} |
||||
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @author: huangxutao |
||||
* @date: 2019-06-14 |
||||
* @description: 缓存常量 |
||||
*/ |
||||
public interface CacheConstant { |
||||
|
||||
/** |
||||
* 字典信息缓存(含禁用的字典项) |
||||
*/ |
||||
public static final String SYS_DICT_CACHE = "sys:cache:dict"; |
||||
|
||||
/** |
||||
* 字典信息缓存 status为有效的 |
||||
*/ |
||||
public static final String SYS_ENABLE_DICT_CACHE = "sys:cache:dictEnable"; |
||||
/** |
||||
* 表字典信息缓存 |
||||
*/ |
||||
public static final String SYS_DICT_TABLE_CACHE = "sys:cache:dictTable"; |
||||
public static final String SYS_DICT_TABLE_BY_KEYS_CACHE = SYS_DICT_TABLE_CACHE + "ByKeys"; |
||||
|
||||
/** |
||||
* 数据权限配置缓存 |
||||
*/ |
||||
public static final String SYS_DATA_PERMISSIONS_CACHE = "sys:cache:permission:datarules"; |
||||
|
||||
/** |
||||
* 缓存用户信息【加密】 |
||||
*/ |
||||
public static final String SYS_USERS_CACHE = "sys:cache:encrypt:user"; |
||||
|
||||
/** |
||||
* 全部部门信息缓存 |
||||
*/ |
||||
public static final String SYS_DEPARTS_CACHE = "sys:cache:depart:alldata"; |
||||
|
||||
|
||||
/** |
||||
* 全部部门ids缓存 |
||||
*/ |
||||
public static final String SYS_DEPART_IDS_CACHE = "sys:cache:depart:allids"; |
||||
|
||||
|
||||
/** |
||||
* 测试缓存key |
||||
*/ |
||||
public static final String TEST_DEMO_CACHE = "test:demo"; |
||||
|
||||
/** |
||||
* 字典信息缓存 |
||||
*/ |
||||
public static final String SYS_DYNAMICDB_CACHE = "sys:cache:dbconnect:dynamic:"; |
||||
|
||||
/** |
||||
* gateway路由缓存 |
||||
*/ |
||||
public static final String GATEWAY_ROUTES = "sys:cache:cloud:gateway_routes"; |
||||
|
||||
|
||||
/** |
||||
* gateway路由 reload key |
||||
*/ |
||||
public static final String ROUTE_JVM_RELOAD_TOPIC = "gateway_jvm_route_reload_topic"; |
||||
|
||||
/** |
||||
* TODO 冗余代码 待删除 |
||||
* 插件商城排行榜 |
||||
*/ |
||||
public static final String PLUGIN_MALL_RANKING = "pluginMall::rankingList"; |
||||
/** |
||||
* TODO 冗余代码 待删除 |
||||
* 插件商城排行榜 |
||||
*/ |
||||
public static final String PLUGIN_MALL_PAGE_LIST = "pluginMall::queryPageList"; |
||||
|
||||
|
||||
/** |
||||
* online列表页配置信息缓存key |
||||
*/ |
||||
public static final String ONLINE_LIST = "sys:cache:online:list"; |
||||
|
||||
/** |
||||
* online表单页配置信息缓存key |
||||
*/ |
||||
public static final String ONLINE_FORM = "sys:cache:online:form"; |
||||
|
||||
/** |
||||
* online报表 |
||||
*/ |
||||
public static final String ONLINE_RP = "sys:cache:online:rp"; |
||||
|
||||
/** |
||||
* online图表 |
||||
*/ |
||||
public static final String ONLINE_GRAPH = "sys:cache:online:graph"; |
||||
/** |
||||
* 拖拽页面信息缓存 |
||||
*/ |
||||
public static final String DRAG_PAGE_CACHE = "drag:cache:page"; |
||||
} |
||||
@ -0,0 +1,506 @@
@@ -0,0 +1,506 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @Description: 通用常量 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public interface CommonConstant { |
||||
|
||||
/** |
||||
* 正常状态 |
||||
*/ |
||||
Integer STATUS_NORMAL = 0; |
||||
|
||||
/** |
||||
* 禁用状态 |
||||
*/ |
||||
Integer STATUS_DISABLE = -1; |
||||
|
||||
/** |
||||
* 删除标志 |
||||
*/ |
||||
Integer DEL_FLAG_1 = 1; |
||||
|
||||
/** |
||||
* 未删除 |
||||
*/ |
||||
Integer DEL_FLAG_0 = 0; |
||||
|
||||
/** |
||||
* 系统日志类型: 登录 |
||||
*/ |
||||
int LOG_TYPE_1 = 1; |
||||
|
||||
/** |
||||
* 系统日志类型: 操作 |
||||
*/ |
||||
int LOG_TYPE_2 = 2; |
||||
|
||||
/** |
||||
* 操作日志类型: 查询 |
||||
*/ |
||||
int OPERATE_TYPE_1 = 1; |
||||
|
||||
/** |
||||
* 操作日志类型: 添加 |
||||
*/ |
||||
int OPERATE_TYPE_2 = 2; |
||||
|
||||
/** |
||||
* 操作日志类型: 更新 |
||||
*/ |
||||
int OPERATE_TYPE_3 = 3; |
||||
|
||||
/** |
||||
* 操作日志类型: 删除 |
||||
*/ |
||||
int OPERATE_TYPE_4 = 4; |
||||
|
||||
/** |
||||
* 操作日志类型: 倒入 |
||||
*/ |
||||
int OPERATE_TYPE_5 = 5; |
||||
|
||||
/** |
||||
* 操作日志类型: 导出 |
||||
*/ |
||||
int OPERATE_TYPE_6 = 6; |
||||
|
||||
|
||||
/** |
||||
* {@code 500 Server Error} (HTTP/1.0 - RFC 1945) |
||||
*/ |
||||
Integer SC_INTERNAL_SERVER_ERROR_500 = 500; |
||||
/** |
||||
* {@code 200 OK} (HTTP/1.0 - RFC 1945) |
||||
*/ |
||||
Integer SC_OK_200 = 200; |
||||
|
||||
/** |
||||
* 访问权限认证未通过 510 |
||||
*/ |
||||
Integer SC_JEECG_NO_AUTHZ = 510; |
||||
|
||||
/** |
||||
* 登录用户Shiro权限缓存KEY前缀 |
||||
*/ |
||||
String PREFIX_USER_SHIRO_CACHE = "shiro:cache:cc.niushuai.bastionserver.config.shiro.ShiroRealm.authorizationCache:"; |
||||
/** |
||||
* 登录用户Token令牌缓存KEY前缀 |
||||
*/ |
||||
String PREFIX_USER_TOKEN = "prefix_user_token_"; |
||||
// /** Token缓存时间:3600秒即一小时 */
|
||||
// int TOKEN_EXPIRE_TIME = 3600;
|
||||
|
||||
/** |
||||
* 登录二维码 |
||||
*/ |
||||
String LOGIN_QRCODE_PRE = "QRCODELOGIN:"; |
||||
String LOGIN_QRCODE = "LQ:"; |
||||
/** |
||||
* 登录二维码token |
||||
*/ |
||||
String LOGIN_QRCODE_TOKEN = "LQT:"; |
||||
|
||||
|
||||
/** |
||||
* 0:一级菜单 |
||||
*/ |
||||
Integer MENU_TYPE_0 = 0; |
||||
/** |
||||
* 1:子菜单 |
||||
*/ |
||||
Integer MENU_TYPE_1 = 1; |
||||
/** |
||||
* 2:按钮权限 |
||||
*/ |
||||
Integer MENU_TYPE_2 = 2; |
||||
|
||||
/** |
||||
* 通告对象类型(USER:指定用户,ALL:全体用户) |
||||
*/ |
||||
String MSG_TYPE_UESR = "USER"; |
||||
String MSG_TYPE_ALL = "ALL"; |
||||
|
||||
/** |
||||
* 发布状态(0未发布,1已发布,2已撤销) |
||||
*/ |
||||
String NO_SEND = "0"; |
||||
String HAS_SEND = "1"; |
||||
String HAS_CANCLE = "2"; |
||||
|
||||
/** |
||||
* 阅读状态(0未读,1已读) |
||||
*/ |
||||
String HAS_READ_FLAG = "1"; |
||||
String NO_READ_FLAG = "0"; |
||||
|
||||
/** |
||||
* 优先级(L低,M中,H高) |
||||
*/ |
||||
String PRIORITY_L = "L"; |
||||
String PRIORITY_M = "M"; |
||||
String PRIORITY_H = "H"; |
||||
|
||||
/** |
||||
* 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板 |
||||
*/ |
||||
String SMS_TPL_TYPE_0 = "0"; |
||||
String SMS_TPL_TYPE_1 = "1"; |
||||
String SMS_TPL_TYPE_2 = "2"; |
||||
|
||||
/** |
||||
* 状态(0无效1有效) |
||||
*/ |
||||
String STATUS_0 = "0"; |
||||
String STATUS_1 = "1"; |
||||
|
||||
/** |
||||
* 同步工作流引擎1同步0不同步 |
||||
*/ |
||||
Integer ACT_SYNC_1 = 1; |
||||
Integer ACT_SYNC_0 = 0; |
||||
|
||||
/** |
||||
* 消息类型1:通知公告2:系统消息 |
||||
*/ |
||||
String MSG_CATEGORY_1 = "1"; |
||||
String MSG_CATEGORY_2 = "2"; |
||||
|
||||
/** |
||||
* 是否配置菜单的数据权限 1是0否 |
||||
*/ |
||||
Integer RULE_FLAG_0 = 0; |
||||
Integer RULE_FLAG_1 = 1; |
||||
|
||||
/** |
||||
* 是否用户已被冻结 1正常(解冻) 2冻结 |
||||
*/ |
||||
Integer USER_UNFREEZE = 1; |
||||
Integer USER_FREEZE = 2; |
||||
|
||||
/** |
||||
* 字典翻译文本后缀 |
||||
*/ |
||||
String DICT_TEXT_SUFFIX = "_dictText"; |
||||
|
||||
/** |
||||
* 表单设计器主表类型 |
||||
*/ |
||||
Integer DESIGN_FORM_TYPE_MAIN = 1; |
||||
|
||||
/** |
||||
* 表单设计器子表表类型 |
||||
*/ |
||||
Integer DESIGN_FORM_TYPE_SUB = 2; |
||||
|
||||
/** |
||||
* 表单设计器URL授权通过 |
||||
*/ |
||||
Integer DESIGN_FORM_URL_STATUS_PASSED = 1; |
||||
|
||||
/** |
||||
* 表单设计器URL授权未通过 |
||||
*/ |
||||
Integer DESIGN_FORM_URL_STATUS_NOT_PASSED = 2; |
||||
|
||||
/** |
||||
* 表单设计器新增 Flag |
||||
*/ |
||||
String DESIGN_FORM_URL_TYPE_ADD = "add"; |
||||
/** |
||||
* 表单设计器修改 Flag |
||||
*/ |
||||
String DESIGN_FORM_URL_TYPE_EDIT = "edit"; |
||||
/** |
||||
* 表单设计器详情 Flag |
||||
*/ |
||||
String DESIGN_FORM_URL_TYPE_DETAIL = "detail"; |
||||
/** |
||||
* 表单设计器复用数据 Flag |
||||
*/ |
||||
String DESIGN_FORM_URL_TYPE_REUSE = "reuse"; |
||||
/** |
||||
* 表单设计器编辑 Flag (已弃用) |
||||
*/ |
||||
String DESIGN_FORM_URL_TYPE_VIEW = "view"; |
||||
|
||||
/** |
||||
* online参数值设置(是:Y, 否:N) |
||||
*/ |
||||
String ONLINE_PARAM_VAL_IS_TURE = "Y"; |
||||
String ONLINE_PARAM_VAL_IS_FALSE = "N"; |
||||
|
||||
/** |
||||
* 文件上传类型(本地:local,Minio:minio,阿里云:alioss) |
||||
*/ |
||||
String UPLOAD_TYPE_LOCAL = "local"; |
||||
String UPLOAD_TYPE_MINIO = "minio"; |
||||
String UPLOAD_TYPE_OSS = "alioss"; |
||||
|
||||
/** |
||||
* 文档上传自定义桶名称 |
||||
*/ |
||||
String UPLOAD_CUSTOM_BUCKET = "eoafile"; |
||||
/** |
||||
* 文档上传自定义路径 |
||||
*/ |
||||
String UPLOAD_CUSTOM_PATH = "eoafile"; |
||||
/** |
||||
* 文件外链接有效天数 |
||||
*/ |
||||
Integer UPLOAD_EFFECTIVE_DAYS = 1; |
||||
|
||||
/** |
||||
* 员工身份 (1:普通员工 2:上级) |
||||
*/ |
||||
Integer USER_IDENTITY_1 = 1; |
||||
Integer USER_IDENTITY_2 = 2; |
||||
|
||||
/** |
||||
* sys_user 表 username 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_USER_USERNAME = "uniq_sys_user_username"; |
||||
/** |
||||
* sys_user 表 work_no 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_USER_WORK_NO = "uniq_sys_user_work_no"; |
||||
/** |
||||
* sys_user 表 phone 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_USER_PHONE = "uniq_sys_user_phone"; |
||||
/** |
||||
* 达梦数据库升提示。违反表[SYS_USER]唯一性约束 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_USER = "唯一性约束"; |
||||
|
||||
/** |
||||
* sys_user 表 email 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_USER_EMAIL = "uniq_sys_user_email"; |
||||
/** |
||||
* sys_quartz_job 表 job_class_name 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_JOB_CLASS_NAME = "uniq_job_class_name"; |
||||
/** |
||||
* sys_position 表 code 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_CODE = "uniq_code"; |
||||
/** |
||||
* sys_role 表 code 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_SYS_ROLE_CODE = "uniq_sys_role_role_code"; |
||||
/** |
||||
* sys_depart 表 code 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_DEPART_ORG_CODE = "uniq_depart_org_code"; |
||||
/** |
||||
* sys_category 表 code 唯一键索引 |
||||
*/ |
||||
String SQL_INDEX_UNIQ_CATEGORY_CODE = "idx_sc_code"; |
||||
/** |
||||
* 在线聊天 是否为默认分组 |
||||
*/ |
||||
String IM_DEFAULT_GROUP = "1"; |
||||
/** |
||||
* 在线聊天 图片文件保存路径 |
||||
*/ |
||||
String IM_UPLOAD_CUSTOM_PATH = "biz/user_imgs"; |
||||
/** |
||||
* 在线聊天 用户状态 |
||||
*/ |
||||
String IM_STATUS_ONLINE = "online"; |
||||
|
||||
/** |
||||
* 在线聊天 SOCKET消息类型 |
||||
*/ |
||||
String IM_SOCKET_TYPE = "chatMessage"; |
||||
|
||||
/** |
||||
* 在线聊天 是否开启默认添加好友 1是 0否 |
||||
*/ |
||||
String IM_DEFAULT_ADD_FRIEND = "1"; |
||||
|
||||
/** |
||||
* 在线聊天 用户好友缓存前缀 |
||||
*/ |
||||
String IM_PREFIX_USER_FRIEND_CACHE = "sys:cache:im:im_prefix_user_friend_"; |
||||
|
||||
/** |
||||
* 考勤补卡业务状态 (1:同意 2:不同意) |
||||
*/ |
||||
String SIGN_PATCH_BIZ_STATUS_1 = "1"; |
||||
String SIGN_PATCH_BIZ_STATUS_2 = "2"; |
||||
|
||||
/** |
||||
* 公文文档上传自定义路径 |
||||
*/ |
||||
String UPLOAD_CUSTOM_PATH_OFFICIAL = "officialdoc"; |
||||
/** |
||||
* 公文文档下载自定义路径 |
||||
*/ |
||||
String DOWNLOAD_CUSTOM_PATH_OFFICIAL = "officaldown"; |
||||
|
||||
/** |
||||
* WPS存储值类别(1 code文号 2 text(WPS模板还是公文发文模板)) |
||||
*/ |
||||
String WPS_TYPE_1 = "1"; |
||||
String WPS_TYPE_2 = "2"; |
||||
|
||||
|
||||
/**===============================================================================================*/ |
||||
/** |
||||
* ::非常重要:: |
||||
* 注意:这四个常量值如果修改,需要与 jeecg-boot-starter/jeecg-boot-common/cc.niushuai.bastionserver.config.FeignConfig 类中的值保持一致。 |
||||
*/ |
||||
String X_ACCESS_TOKEN = "X-Access-Token"; |
||||
String X_SIGN = "X-Sign"; |
||||
String X_TIMESTAMP = "X-TIMESTAMP"; |
||||
/** |
||||
* 租户 请求头 |
||||
*/ |
||||
String TENANT_ID = "tenant-id"; |
||||
/** |
||||
* =============================================================================================== |
||||
*/ |
||||
|
||||
String TOKEN_IS_INVALID_MSG = "Token失效,请重新登录!"; |
||||
String X_FORWARDED_SCHEME = "X-Forwarded-Scheme"; |
||||
|
||||
|
||||
/** |
||||
* 微服务读取配置文件属性 服务地址 |
||||
*/ |
||||
String CLOUD_SERVER_KEY = "spring.cloud.nacos.discovery.server-addr"; |
||||
|
||||
/** |
||||
* 第三方登录 验证密码/创建用户 都需要设置一个操作码 防止被恶意调用 |
||||
*/ |
||||
String THIRD_LOGIN_CODE = "third_login_code"; |
||||
|
||||
/** |
||||
* 第三方APP同步方向:本地 --> 第三方APP |
||||
*/ |
||||
String THIRD_SYNC_TO_APP = "SYNC_TO_APP"; |
||||
/** |
||||
* 第三方APP同步方向:第三方APP --> 本地 |
||||
*/ |
||||
String THIRD_SYNC_TO_LOCAL = "SYNC_TO_LOCAL"; |
||||
|
||||
/** |
||||
* 系统通告消息状态:0=未发布 |
||||
*/ |
||||
String ANNOUNCEMENT_SEND_STATUS_0 = "0"; |
||||
/** |
||||
* 系统通告消息状态:1=已发布 |
||||
*/ |
||||
String ANNOUNCEMENT_SEND_STATUS_1 = "1"; |
||||
/** |
||||
* 系统通告消息状态:2=已撤销 |
||||
*/ |
||||
String ANNOUNCEMENT_SEND_STATUS_2 = "2"; |
||||
|
||||
/** |
||||
* ONLINE 报表权限用 从request中获取地址栏后的参数 |
||||
*/ |
||||
String ONL_REP_URL_PARAM_STR = "onlRepUrlParamStr"; |
||||
|
||||
/** |
||||
* POST请求 |
||||
*/ |
||||
String HTTP_POST = "POST"; |
||||
|
||||
/** |
||||
* PUT请求 |
||||
*/ |
||||
String HTTP_PUT = "PUT"; |
||||
|
||||
/** |
||||
* PATCH请求 |
||||
*/ |
||||
String HTTP_PATCH = "PATCH"; |
||||
|
||||
/** |
||||
* 未知的 |
||||
*/ |
||||
String UNKNOWN = "unknown"; |
||||
|
||||
/** |
||||
* 字符串http |
||||
*/ |
||||
String STR_HTTP = "http"; |
||||
|
||||
/** |
||||
* String 类型的空值 |
||||
*/ |
||||
String STRING_NULL = "null"; |
||||
|
||||
/** |
||||
* 前端vue3版本Header参数名 |
||||
*/ |
||||
String VERSION = "X-Version"; |
||||
|
||||
/** |
||||
* 存储在线程变量里的动态表名 |
||||
*/ |
||||
String DYNAMIC_TABLE_NAME = "DYNAMIC_TABLE_NAME"; |
||||
/** |
||||
* http:// http协议
|
||||
*/ |
||||
String HTTP_PROTOCOL = "http://"; |
||||
|
||||
/** |
||||
* https:// https协议
|
||||
*/ |
||||
String HTTPS_PROTOCOL = "https://"; |
||||
|
||||
/** |
||||
* 部门表唯一key,id |
||||
*/ |
||||
String DEPART_KEY_ID = "id"; |
||||
/** |
||||
* 部门表唯一key,orgCode |
||||
*/ |
||||
String DEPART_KEY_ORG_CODE = "orgCode"; |
||||
|
||||
/** |
||||
* 发消息 会传递一些信息到map |
||||
*/ |
||||
String NOTICE_MSG_SUMMARY = "NOTICE_MSG_SUMMARY"; |
||||
|
||||
/** |
||||
* 发消息 会传递一个业务ID到map |
||||
*/ |
||||
String NOTICE_MSG_BUS_ID = "NOTICE_MSG_BUS_ID"; |
||||
|
||||
/** |
||||
* 邮箱消息中地址登录时地址后携带的token,需要替换成真实的token值 |
||||
*/ |
||||
String LOGIN_TOKEN = "{LOGIN_TOKEN}"; |
||||
|
||||
/** |
||||
* 模板消息中 跳转地址的对应的key |
||||
*/ |
||||
String MSG_HREF_URL = "url"; |
||||
|
||||
/** |
||||
* sys_data_log表的类型 用于区别评论区域的日志数据 |
||||
*/ |
||||
String DATA_LOG_TYPE_COMMENT = "comment"; |
||||
|
||||
/** |
||||
* sys_data_log表的类型 老的数据比较 类型都设置为json |
||||
*/ |
||||
String DATA_LOG_TYPE_JSON = "json"; |
||||
|
||||
/** |
||||
* 消息模板:markdown |
||||
*/ |
||||
String MSG_TEMPLATE_TYPE_MD = "5"; |
||||
|
||||
/** |
||||
* 短信验证码redis-key的前缀 |
||||
*/ |
||||
String PHONE_REDIS_KEY_PRE = "phone_msg"; |
||||
|
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* 系统通告 - 发布状态 |
||||
* |
||||
* @Author LeeShaoQing |
||||
*/ |
||||
public interface CommonSendStatus { |
||||
|
||||
/** |
||||
* 未发布 |
||||
*/ |
||||
public static final String UNPUBLISHED_STATUS_0 = "0"; |
||||
|
||||
/** |
||||
* 已发布 |
||||
*/ |
||||
public static final String PUBLISHED_STATUS_1 = "1"; |
||||
|
||||
/** |
||||
* 撤销 |
||||
*/ |
||||
public static final String REVOKE_STATUS_2 = "2"; |
||||
|
||||
/** |
||||
* app端推送会话标识后缀 |
||||
*/ |
||||
public static final String APP_SESSION_SUFFIX = "_app"; |
||||
|
||||
|
||||
/** |
||||
* 流程催办——系统通知消息模板 |
||||
*/ |
||||
public static final String TZMB_BPM_CUIBAN = "bpm_cuiban"; |
||||
/** |
||||
* 流程催办——邮件通知消息模板 |
||||
*/ |
||||
public static final String TZMB_BPM_CUIBAN_EMAIL = "bpm_cuiban_email"; |
||||
/** |
||||
* 标准模板—系统消息通知 |
||||
*/ |
||||
public static final String TZMB_SYS_TS_NOTE = "sys_ts_note"; |
||||
/** |
||||
* 流程超时提醒——系统通知消息模板 |
||||
*/ |
||||
public static final String TZMB_BPM_CHAOSHI_TIP = "bpm_chaoshi_tip"; |
||||
} |
||||
@ -0,0 +1,184 @@
@@ -0,0 +1,184 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* 数据库上下文常量 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public interface DataBaseConstant { |
||||
//*********数据库类型****************************************
|
||||
|
||||
/** |
||||
* MYSQL数据库 |
||||
*/ |
||||
public static final String DB_TYPE_MYSQL = "MYSQL"; |
||||
|
||||
/** |
||||
* ORACLE |
||||
*/ |
||||
public static final String DB_TYPE_ORACLE = "ORACLE"; |
||||
|
||||
/** |
||||
* 达梦数据库 |
||||
*/ |
||||
public static final String DB_TYPE_DM = "DM"; |
||||
|
||||
/** |
||||
* postgreSQL达梦数据库 |
||||
*/ |
||||
public static final String DB_TYPE_POSTGRESQL = "POSTGRESQL"; |
||||
|
||||
/** |
||||
* sqlserver数据库 |
||||
*/ |
||||
public static final String DB_TYPE_SQLSERVER = "SQLSERVER"; |
||||
|
||||
/** |
||||
* mariadb 数据库 |
||||
*/ |
||||
public static final String DB_TYPE_MARIADB = "MARIADB"; |
||||
|
||||
/** |
||||
* DB2 数据库 |
||||
*/ |
||||
public static final String DB_TYPE_DB2 = "DB2"; |
||||
|
||||
/** |
||||
* HSQL 数据库 |
||||
*/ |
||||
public static final String DB_TYPE_HSQL = "HSQL"; |
||||
|
||||
// // 数据库类型,对应 database_type 字典
|
||||
// public static final String DB_TYPE_MYSQL_NUM = "1";
|
||||
// public static final String DB_TYPE_MYSQL7_NUM = "6";
|
||||
// public static final String DB_TYPE_ORACLE_NUM = "2";
|
||||
// public static final String DB_TYPE_SQLSERVER_NUM = "3";
|
||||
// public static final String DB_TYPE_POSTGRESQL_NUM = "4";
|
||||
// public static final String DB_TYPE_MARIADB_NUM = "5";
|
||||
|
||||
//*********系统上下文变量****************************************
|
||||
/** |
||||
* 数据-所属机构编码 |
||||
*/ |
||||
public static final String SYS_ORG_CODE = "sysOrgCode"; |
||||
/** |
||||
* 数据-所属机构编码 |
||||
*/ |
||||
public static final String SYS_ORG_CODE_TABLE = "sys_org_code"; |
||||
/** |
||||
* 数据-所属机构编码 |
||||
*/ |
||||
public static final String SYS_MULTI_ORG_CODE = "sysMultiOrgCode"; |
||||
/** |
||||
* 数据-所属机构编码 |
||||
*/ |
||||
public static final String SYS_MULTI_ORG_CODE_TABLE = "sys_multi_org_code"; |
||||
/** |
||||
* 数据-系统用户编码(对应登录用户账号) |
||||
*/ |
||||
public static final String SYS_USER_CODE = "sysUserCode"; |
||||
/** |
||||
* 数据-系统用户编码(对应登录用户账号) |
||||
*/ |
||||
public static final String SYS_USER_CODE_TABLE = "sys_user_code"; |
||||
|
||||
/** |
||||
* 登录用户真实姓名 |
||||
*/ |
||||
public static final String SYS_USER_NAME = "sysUserName"; |
||||
/** |
||||
* 登录用户真实姓名 |
||||
*/ |
||||
public static final String SYS_USER_NAME_TABLE = "sys_user_name"; |
||||
/** |
||||
* 系统日期"yyyy-MM-dd" |
||||
*/ |
||||
public static final String SYS_DATE = "sysDate"; |
||||
/** |
||||
* 系统日期"yyyy-MM-dd" |
||||
*/ |
||||
public static final String SYS_DATE_TABLE = "sys_date"; |
||||
/** |
||||
* 系统时间"yyyy-MM-dd HH:mm" |
||||
*/ |
||||
public static final String SYS_TIME = "sysTime"; |
||||
/** |
||||
* 系统时间"yyyy-MM-dd HH:mm" |
||||
*/ |
||||
public static final String SYS_TIME_TABLE = "sys_time"; |
||||
/** |
||||
* 数据-所属机构编码 |
||||
*/ |
||||
public static final String SYS_BASE_PATH = "sys_base_path"; |
||||
//*********系统上下文变量****************************************
|
||||
|
||||
|
||||
//*********系统建表标准字段****************************************
|
||||
/** |
||||
* 创建者登录名称 |
||||
*/ |
||||
public static final String CREATE_BY_TABLE = "create_by"; |
||||
/** |
||||
* 创建者登录名称 |
||||
*/ |
||||
public static final String CREATE_BY = "createBy"; |
||||
/** |
||||
* 创建日期时间 |
||||
*/ |
||||
public static final String CREATE_TIME_TABLE = "create_time"; |
||||
/** |
||||
* 创建日期时间 |
||||
*/ |
||||
public static final String CREATE_TIME = "createTime"; |
||||
/** |
||||
* 更新用户登录名称 |
||||
*/ |
||||
public static final String UPDATE_BY_TABLE = "update_by"; |
||||
/** |
||||
* 更新用户登录名称 |
||||
*/ |
||||
public static final String UPDATE_BY = "updateBy"; |
||||
/** |
||||
* 更新日期时间 |
||||
*/ |
||||
public static final String UPDATE_TIME = "updateTime"; |
||||
/** |
||||
* 更新日期时间 |
||||
*/ |
||||
public static final String UPDATE_TIME_TABLE = "update_time"; |
||||
|
||||
/** |
||||
* 业务流程状态 |
||||
*/ |
||||
public static final String BPM_STATUS = "bpmStatus"; |
||||
/** |
||||
* 业务流程状态 |
||||
*/ |
||||
public static final String BPM_STATUS_TABLE = "bpm_status"; |
||||
//*********系统建表标准字段****************************************
|
||||
|
||||
|
||||
/** |
||||
* 租户ID 实体字段名 |
||||
*/ |
||||
String TENANT_ID = "tenantId"; |
||||
/** |
||||
* 租户ID 数据库字段名 |
||||
*/ |
||||
String TENANT_ID_TABLE = "tenant_id"; |
||||
|
||||
/** |
||||
* sql语句 where |
||||
*/ |
||||
String SQL_WHERE = "where"; |
||||
|
||||
/** |
||||
* sql语句 asc |
||||
*/ |
||||
String SQL_ASC = "asc"; |
||||
|
||||
/** |
||||
* sqlserver数据库,中间有空格 |
||||
*/ |
||||
String DB_TYPE_SQL_SERVER_BLANK = "sql server"; |
||||
} |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* 动态切换表配置常量 |
||||
* |
||||
* @author: scott |
||||
* @date: 2022年04月25日 22:30 |
||||
*/ |
||||
public class DynamicTableConstant { |
||||
/** |
||||
* 角色首页配置表 |
||||
* vue2表名: sys_role_index |
||||
* vue3表名: sys_role_index_vue3 |
||||
*/ |
||||
public static final String SYS_ROLE_INDEX = "sys_role_index"; |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* 规则值生成 编码常量类 |
||||
* |
||||
* @author: taoyan |
||||
* @date: 2020年04月02日 |
||||
*/ |
||||
public class FillRuleConstant { |
||||
|
||||
/** |
||||
* 公文发文编码 |
||||
*/ |
||||
public static final String DOC_SEND = "doc_send_code"; |
||||
|
||||
/** |
||||
* 部门编码 |
||||
*/ |
||||
public static final String DEPART = "org_num_role"; |
||||
|
||||
/** |
||||
* 分类字典编码 |
||||
*/ |
||||
public static final String CATEGORY = "category_code_rule"; |
||||
|
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @Description: GlobalConstants |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:01 |
||||
*/ |
||||
public class GlobalConstants { |
||||
|
||||
/** |
||||
* 业务处理器beanName传递参数 |
||||
*/ |
||||
public static final String HANDLER_NAME = "handlerName"; |
||||
/** |
||||
* 路由刷新触发器 |
||||
*/ |
||||
public static final String LODER_ROUDER_HANDLER = "loderRouderHandler"; |
||||
|
||||
/** |
||||
* redis消息通道名称 |
||||
*/ |
||||
public static final String REDIS_TOPIC_NAME = "jeecg_redis_topic"; |
||||
} |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* |
||||
* * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). |
||||
* * <p> |
||||
* * Licensed under the GNU Lesser General Public License 3.0 (the "License"); |
||||
* * you may not use this file except in compliance with the License. |
||||
* * You may obtain a copy of the License at |
||||
* * <p> |
||||
* * https://www.gnu.org/licenses/lgpl.html
|
||||
* * <p> |
||||
* * Unless required by applicable law or agreed to in writing, software |
||||
* * distributed under the License is distributed on an "AS IS" BASIS, |
||||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* * See the License for the specific language governing permissions and |
||||
* * limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @author scott |
||||
* @date 2019年05月18日 |
||||
* 服务名称 |
||||
*/ |
||||
public interface ServiceNameConstants { |
||||
|
||||
/** |
||||
* 微服务名:系统管理模块 |
||||
*/ |
||||
String SERVICE_SYSTEM = "jeecg-system"; |
||||
/** |
||||
* 微服务名: demo模块 |
||||
*/ |
||||
String SERVICE_DEMO = "jeecg-demo"; |
||||
|
||||
/** |
||||
* gateway通过header传递根路径 basePath |
||||
*/ |
||||
String X_GATEWAY_BASE_PATH = "X_GATEWAY_BASE_PATH"; |
||||
|
||||
} |
||||
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @Description: 符号和特殊符号常用类 |
||||
* @author: wangshuai |
||||
* @date: 2022年03月30日 17:44 |
||||
*/ |
||||
public class SymbolConstant { |
||||
|
||||
/** |
||||
* 符号:点 |
||||
*/ |
||||
public static final String SPOT = "."; |
||||
|
||||
/** |
||||
* 符号:双斜杠 |
||||
*/ |
||||
public static final String DOUBLE_BACKSLASH = "\\"; |
||||
|
||||
/** |
||||
* 符号:冒号 |
||||
*/ |
||||
public static final String COLON = ":"; |
||||
|
||||
/** |
||||
* 符号:逗号 |
||||
*/ |
||||
public static final String COMMA = ","; |
||||
|
||||
/** |
||||
* 符号:左花括号 } |
||||
*/ |
||||
public static final String LEFT_CURLY_BRACKET = "{"; |
||||
|
||||
/** |
||||
* 符号:右花括号 } |
||||
*/ |
||||
public static final String RIGHT_CURLY_BRACKET = "}"; |
||||
|
||||
/** |
||||
* 符号:井号 # |
||||
*/ |
||||
public static final String WELL_NUMBER = "#"; |
||||
|
||||
/** |
||||
* 符号:单斜杠 |
||||
*/ |
||||
public static final String SINGLE_SLASH = "/"; |
||||
|
||||
/** |
||||
* 符号:双斜杠 |
||||
*/ |
||||
public static final String DOUBLE_SLASH = "//"; |
||||
|
||||
/** |
||||
* 符号:感叹号 |
||||
*/ |
||||
public static final String EXCLAMATORY_MARK = "!"; |
||||
|
||||
/** |
||||
* 符号:下划线 |
||||
*/ |
||||
public static final String UNDERLINE = "_"; |
||||
|
||||
/** |
||||
* 符号:单引号 |
||||
*/ |
||||
public static final String SINGLE_QUOTATION_MARK = "'"; |
||||
|
||||
/** |
||||
* 符号:星号 |
||||
*/ |
||||
public static final String ASTERISK = "*"; |
||||
|
||||
/** |
||||
* 符号:百分号 |
||||
*/ |
||||
public static final String PERCENT_SIGN = "%"; |
||||
|
||||
/** |
||||
* 符号:美元 $ |
||||
*/ |
||||
public static final String DOLLAR = "$"; |
||||
|
||||
/** |
||||
* 符号:和 & |
||||
*/ |
||||
public static final String AND = "&"; |
||||
|
||||
/** |
||||
* 符号:../ |
||||
*/ |
||||
public static final String SPOT_SINGLE_SLASH = "../"; |
||||
|
||||
/** |
||||
* 符号:..\\ |
||||
*/ |
||||
public static final String SPOT_DOUBLE_BACKSLASH = "..\\"; |
||||
|
||||
/** |
||||
* 系统变量前缀 #{ |
||||
*/ |
||||
public static final String SYS_VAR_PREFIX = "#{"; |
||||
|
||||
/** |
||||
* 符号 {{ |
||||
*/ |
||||
public static final String DOUBLE_LEFT_CURLY_BRACKET = "{{"; |
||||
|
||||
/** |
||||
* 符号:[ |
||||
*/ |
||||
public static final String SQUARE_BRACKETS_LEFT = "["; |
||||
/** |
||||
* 符号:] |
||||
*/ |
||||
public static final String SQUARE_BRACKETS_RIGHT = "]"; |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* VXESocket 常量 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public class VxeSocketConst { |
||||
|
||||
/** |
||||
* 消息类型 |
||||
*/ |
||||
public static final String TYPE = "type"; |
||||
/** |
||||
* 消息数据 |
||||
*/ |
||||
public static final String DATA = "data"; |
||||
|
||||
/** |
||||
* 消息类型:心跳检测 |
||||
*/ |
||||
public static final String TYPE_HB = "heart_beat"; |
||||
/** |
||||
* 消息类型:通用数据传递 |
||||
*/ |
||||
public static final String TYPE_CSD = "common_send_date"; |
||||
/** |
||||
* 消息类型:更新vxe table数据 |
||||
*/ |
||||
public static final String TYPE_UVT = "update_vxe_table"; |
||||
|
||||
} |
||||
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
package cc.niushuai.bastionserver.common.constant; |
||||
|
||||
/** |
||||
* @Description: Websocket常量类 |
||||
* @author: taoyan |
||||
* @date: 2020年03月23日 |
||||
*/ |
||||
public class WebsocketConst { |
||||
|
||||
|
||||
/** |
||||
* 消息json key:cmd |
||||
*/ |
||||
public static final String MSG_CMD = "cmd"; |
||||
|
||||
/** |
||||
* 消息json key:msgId |
||||
*/ |
||||
public static final String MSG_ID = "msgId"; |
||||
|
||||
/** |
||||
* 消息json key:msgTxt |
||||
*/ |
||||
public static final String MSG_TXT = "msgTxt"; |
||||
|
||||
/** |
||||
* 消息json key:userId |
||||
*/ |
||||
public static final String MSG_USER_ID = "userId"; |
||||
|
||||
/** |
||||
* 消息json key:chat |
||||
*/ |
||||
public static final String MSG_CHAT = "chat"; |
||||
|
||||
/** |
||||
* 消息类型 heartcheck |
||||
*/ |
||||
public static final String CMD_CHECK = "heartcheck"; |
||||
|
||||
/** |
||||
* 消息类型 user 用户消息 |
||||
*/ |
||||
public static final String CMD_USER = "user"; |
||||
|
||||
/** |
||||
* 消息类型 topic 系统通知 |
||||
*/ |
||||
public static final String CMD_TOPIC = "topic"; |
||||
|
||||
/** |
||||
* 消息类型 email |
||||
*/ |
||||
public static final String CMD_EMAIL = "email"; |
||||
|
||||
/** |
||||
* 消息类型 meetingsign 会议签到 |
||||
*/ |
||||
public static final String CMD_SIGN = "sign"; |
||||
|
||||
/** |
||||
* 消息类型 新闻发布/取消 |
||||
*/ |
||||
public static final String NEWS_PUBLISH = "publish"; |
||||
|
||||
} |
||||
@ -0,0 +1,167 @@
@@ -0,0 +1,167 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* online表单枚举 代码生成器用到 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public enum CgformEnum { |
||||
|
||||
/** |
||||
* 单表 |
||||
*/ |
||||
ONE(1, "one", "/jeecg/code-template-online", "default.one", "经典风格", new String[]{"vue3", "vue", "vue3Native"}), |
||||
|
||||
/** |
||||
* 多表 |
||||
*/ |
||||
MANY(2, "many", "/jeecg/code-template-online", "default.onetomany", "经典风格", new String[]{"vue"}), |
||||
/** |
||||
* 多表(jvxe风格) |
||||
*/ |
||||
JVXE_TABLE(2, "jvxe", "/jeecg/code-template-online", "jvxe.onetomany", "JVXE风格", new String[]{"vue3", "vue", "vue3Native"}), |
||||
|
||||
/** |
||||
* 多表 (erp风格) |
||||
*/ |
||||
ERP(2, "erp", "/jeecg/code-template-online", "erp.onetomany", "ERP风格", new String[]{"vue3", "vue"}), |
||||
/** |
||||
* 多表(内嵌子表风格) |
||||
*/ |
||||
INNER_TABLE(2, "innerTable", "/jeecg/code-template-online", "inner-table.onetomany", "内嵌子表风格", new String[]{"vue3", "vue"}), |
||||
/** |
||||
* 多表(tab风格) |
||||
*/ |
||||
TAB(2, "tab", "/jeecg/code-template-online", "tab.onetomany", "Tab风格", new String[]{"vue3", "vue"}), |
||||
/** |
||||
* 树形列表 |
||||
*/ |
||||
TREE(3, "tree", "/jeecg/code-template-online", "default.tree", "树形列表", new String[]{"vue3", "vue", "vue3Native"}); |
||||
|
||||
/** |
||||
* 类型 1/单表 2/一对多 3/树 |
||||
*/ |
||||
int type; |
||||
/** |
||||
* 编码标识 |
||||
*/ |
||||
String code; |
||||
/** |
||||
* 代码生成器模板路径 |
||||
*/ |
||||
String templatePath; |
||||
/** |
||||
* 代码生成器模板路径 |
||||
*/ |
||||
String stylePath; |
||||
/** |
||||
* 模板风格名称 |
||||
*/ |
||||
String note; |
||||
/** |
||||
* 支持代码风格 vue3:vue3包装代码 vue3Native:vue3原生代码 vue:vue2代码 |
||||
*/ |
||||
String[] vueStyle; |
||||
|
||||
/** |
||||
* 构造器 |
||||
* |
||||
* @param type 类型 1/单表 2/一对多 3/树 |
||||
* @param code 模板编码 |
||||
* @param templatePath 模板路径 |
||||
* @param stylePath 模板子路径 |
||||
* @param note |
||||
* @param vueStyle 支持代码风格 |
||||
*/ |
||||
CgformEnum(int type, String code, String templatePath, String stylePath, String note, String[] vueStyle) { |
||||
this.type = type; |
||||
this.code = code; |
||||
this.templatePath = templatePath; |
||||
this.stylePath = stylePath; |
||||
this.note = note; |
||||
this.vueStyle = vueStyle; |
||||
} |
||||
|
||||
/** |
||||
* 根据code获取模板路径 |
||||
* |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public static String getTemplatePathByConfig(String code) { |
||||
return getCgformEnumByConfig(code).templatePath; |
||||
} |
||||
|
||||
/** |
||||
* 根据code找枚举 |
||||
* |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public static CgformEnum getCgformEnumByConfig(String code) { |
||||
for (CgformEnum e : CgformEnum.values()) { |
||||
if (e.code.equals(code)) { |
||||
return e; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 根据类型找所有 |
||||
* |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
public static List<Map<String, Object>> getJspModelList(int type) { |
||||
List<Map<String, Object>> ls = new ArrayList<Map<String, Object>>(); |
||||
for (CgformEnum e : CgformEnum.values()) { |
||||
if (e.type == type) { |
||||
Map<String, Object> map = new HashMap<String, Object>(); |
||||
map.put("code", e.code); |
||||
map.put("note", e.note); |
||||
ls.add(map); |
||||
} |
||||
} |
||||
return ls; |
||||
} |
||||
|
||||
public int getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(int type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getTemplatePath() { |
||||
return templatePath; |
||||
} |
||||
|
||||
public void setTemplatePath(String templatePath) { |
||||
this.templatePath = templatePath; |
||||
} |
||||
|
||||
public String getStylePath() { |
||||
return stylePath; |
||||
} |
||||
|
||||
public void setStylePath(String stylePath) { |
||||
this.stylePath = stylePath; |
||||
} |
||||
|
||||
public String[] getVueStyle() { |
||||
return vueStyle; |
||||
} |
||||
|
||||
public void setVueStyle(String[] vueStyle) { |
||||
this.vueStyle = vueStyle; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
|
||||
/** |
||||
* 文件类型 |
||||
*/ |
||||
public enum FileTypeEnum { |
||||
// 文档类型(folder:文件夹 excel:excel doc:word pp:ppt image:图片 archive:其他文档 video:视频)
|
||||
// FOLDER
|
||||
xls(".xls", "excel", "excel"), |
||||
xlsx(".xlsx", "excel", "excel"), |
||||
doc(".doc", "doc", "word"), |
||||
docx(".docx", "doc", "word"), |
||||
ppt(".ppt", "pp", "ppt"), |
||||
pptx(".pptx", "pp", "ppt"), |
||||
gif(".gif", "image", "图片"), |
||||
jpg(".jpg", "image", "图片"), |
||||
jpeg(".jpeg", "image", "图片"), |
||||
png(".png", "image", "图片"), |
||||
txt(".txt", "text", "文本"), |
||||
avi(".avi", "video", "视频"), |
||||
mov(".mov", "video", "视频"), |
||||
rmvb(".rmvb", "video", "视频"), |
||||
rm(".rm", "video", "视频"), |
||||
flv(".flv", "video", "视频"), |
||||
mp4(".mp4", "video", "视频"), |
||||
zip(".zip", "zip", "压缩包"), |
||||
pdf(".pdf", "pdf", "pdf"); |
||||
|
||||
private String type; |
||||
private String value; |
||||
private String text; |
||||
|
||||
private FileTypeEnum(String type, String value, String text) { |
||||
this.type = type; |
||||
this.value = value; |
||||
this.text = text; |
||||
} |
||||
|
||||
public static FileTypeEnum getByType(String type) { |
||||
if (oConvertUtils.isEmpty(type)) { |
||||
return null; |
||||
} |
||||
for (FileTypeEnum val : values()) { |
||||
if (val.getType().equals(type)) { |
||||
return val; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(String type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
public void setValue(String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public String getText() { |
||||
return text; |
||||
} |
||||
|
||||
public void setText(String text) { |
||||
this.text = text; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
/** |
||||
* LowApp 切面注解枚举 |
||||
* |
||||
* @date 2022-1-5 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public enum LowAppAopEnum { |
||||
|
||||
/** |
||||
* 新增方法 |
||||
*/ |
||||
ADD, |
||||
/** |
||||
* 删除方法(包含单个和批量删除) |
||||
*/ |
||||
DELETE, |
||||
/** |
||||
* 复制表单操作 |
||||
*/ |
||||
COPY, |
||||
|
||||
/** |
||||
* Online表单专用:数据库表转Online表单 |
||||
*/ |
||||
CGFORM_DB_IMPORT |
||||
} |
||||
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
import cc.niushuai.bastionserver.common.system.annotation.EnumDict; |
||||
import cc.niushuai.bastionserver.common.system.vo.DictModel; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 消息类型 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@EnumDict("messageType") |
||||
public enum MessageTypeEnum { |
||||
|
||||
/** |
||||
* 系统消息 |
||||
*/ |
||||
XT("system", "系统消息"), |
||||
/** |
||||
* 邮件消息 |
||||
*/ |
||||
YJ("email", "邮件消息"), |
||||
/** |
||||
* 钉钉消息 |
||||
*/ |
||||
DD("dingtalk", "钉钉消息"), |
||||
/** |
||||
* 企业微信 |
||||
*/ |
||||
QYWX("wechat_enterprise", "企业微信"); |
||||
|
||||
/** |
||||
* 消息类型 |
||||
*/ |
||||
String type; |
||||
/** |
||||
* 类型说明 |
||||
*/ |
||||
String note; |
||||
|
||||
MessageTypeEnum(String type, String note) { |
||||
this.type = type; |
||||
this.note = note; |
||||
} |
||||
|
||||
/** |
||||
* 获取字典数据 |
||||
* |
||||
* @return |
||||
*/ |
||||
public static List<DictModel> getDictList() { |
||||
List<DictModel> list = new ArrayList<>(); |
||||
DictModel dictModel = null; |
||||
for (MessageTypeEnum e : MessageTypeEnum.values()) { |
||||
dictModel = new DictModel(); |
||||
dictModel.setValue(e.getType()); |
||||
dictModel.setText(e.getNote()); |
||||
list.add(dictModel); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
/** |
||||
* 根据type获取枚举 |
||||
* |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
public static MessageTypeEnum valueOfType(String type) { |
||||
for (MessageTypeEnum e : MessageTypeEnum.values()) { |
||||
if (e.getType().equals(type)) { |
||||
return e; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getNote() { |
||||
return note; |
||||
} |
||||
|
||||
public void setNote(String note) { |
||||
this.note = note; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(String type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
/** |
||||
* 日志按模块分类 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public enum ModuleType { |
||||
|
||||
/** |
||||
* 普通 |
||||
*/ |
||||
COMMON, |
||||
|
||||
/** |
||||
* online |
||||
*/ |
||||
ONLINE; |
||||
} |
||||
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
|
||||
/** |
||||
* @Description: 操作类型 |
||||
* @author: jeecg-boot |
||||
* @date: 2022/3/31 10:05 |
||||
*/ |
||||
public enum OperateTypeEnum { |
||||
|
||||
/** |
||||
* 列表 |
||||
*/ |
||||
LIST(CommonConstant.OPERATE_TYPE_1, "list"), |
||||
|
||||
/** |
||||
* 新增 |
||||
*/ |
||||
ADD(CommonConstant.OPERATE_TYPE_2, "add"), |
||||
|
||||
/** |
||||
* 编辑 |
||||
*/ |
||||
EDIT(CommonConstant.OPERATE_TYPE_3, "edit"), |
||||
|
||||
/** |
||||
* 删除 |
||||
*/ |
||||
DELETE(CommonConstant.OPERATE_TYPE_4, "delete"), |
||||
|
||||
/** |
||||
* 导入 |
||||
*/ |
||||
IMPORT(CommonConstant.OPERATE_TYPE_5, "import"), |
||||
|
||||
/** |
||||
* 导出 |
||||
*/ |
||||
EXPORT(CommonConstant.OPERATE_TYPE_6, "export"); |
||||
|
||||
/** |
||||
* 类型 1列表,2新增,3编辑,4删除,5导入,6导出 |
||||
*/ |
||||
int type; |
||||
|
||||
/** |
||||
* 编码(请求方式) |
||||
*/ |
||||
String code; |
||||
|
||||
|
||||
/** |
||||
* 构造器 |
||||
* |
||||
* @param type 类型 |
||||
* @param code 编码(请求方式) |
||||
*/ |
||||
OperateTypeEnum(int type, String code) { |
||||
this.type = type; |
||||
this.code = code; |
||||
} |
||||
|
||||
/** |
||||
* 根据请求名称匹配 |
||||
* |
||||
* @param methodName 请求名称 |
||||
* @return Integer 类型 |
||||
*/ |
||||
public static Integer getTypeByMethodName(String methodName) { |
||||
for (OperateTypeEnum e : OperateTypeEnum.values()) { |
||||
if (methodName.startsWith(e.getCode())) { |
||||
return e.getType(); |
||||
} |
||||
} |
||||
return CommonConstant.OPERATE_TYPE_1; |
||||
} |
||||
|
||||
public int getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(int type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
} |
||||
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
package cc.niushuai.bastionserver.common.constant.enums; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 首页自定义 |
||||
* 通过角色编码与首页组件路径配置 |
||||
* 枚举的顺序有权限高低权重作用(也就是配置多个角色,在前面的角色首页,会优先生效) |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public enum RoleIndexConfigEnum { |
||||
|
||||
/** |
||||
* 首页自定义 admin |
||||
*/ |
||||
ADMIN("admin", "dashboard/Analysis"), |
||||
//TEST("test", "dashboard/IndexChart"),
|
||||
/** |
||||
* 首页自定义 hr |
||||
*/ |
||||
HR("hr", "dashboard/IndexBdc"); |
||||
//DM("dm", "dashboard/IndexTask"),
|
||||
|
||||
/** |
||||
* 角色编码 |
||||
*/ |
||||
String roleCode; |
||||
/** |
||||
* 路由index |
||||
*/ |
||||
String componentUrl; |
||||
|
||||
/** |
||||
* 构造器 |
||||
* |
||||
* @param roleCode 角色编码 |
||||
* @param componentUrl 首页组件路径(规则跟菜单配置一样) |
||||
*/ |
||||
RoleIndexConfigEnum(String roleCode, String componentUrl) { |
||||
this.roleCode = roleCode; |
||||
this.componentUrl = componentUrl; |
||||
} |
||||
|
||||
/** |
||||
* 根据code找枚举 |
||||
* |
||||
* @param roleCode 角色编码 |
||||
* @return |
||||
*/ |
||||
private static RoleIndexConfigEnum getEnumByCode(String roleCode) { |
||||
for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { |
||||
if (e.roleCode.equals(roleCode)) { |
||||
return e; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 根据code找index |
||||
* |
||||
* @param roleCode 角色编码 |
||||
* @return |
||||
*/ |
||||
private static String getIndexByCode(String roleCode) { |
||||
for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { |
||||
if (e.roleCode.equals(roleCode)) { |
||||
return e.componentUrl; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static String getIndexByRoles(List<String> roles) { |
||||
String[] rolesArray = roles.toArray(new String[roles.size()]); |
||||
for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { |
||||
if (oConvertUtils.isIn(e.roleCode, rolesArray)) { |
||||
return e.componentUrl; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getRoleCode() { |
||||
return roleCode; |
||||
} |
||||
|
||||
public void setRoleCode(String roleCode) { |
||||
this.roleCode = roleCode; |
||||
} |
||||
|
||||
public String getComponentUrl() { |
||||
return componentUrl; |
||||
} |
||||
|
||||
public void setComponentUrl(String componentUrl) { |
||||
this.componentUrl = componentUrl; |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 解密注解 |
||||
* <p> |
||||
* 在方法上定义 将方法返回对象中的敏感字段 解密,需要注意的是,如果没有加密过,解密会出问题,返回原字符串 |
||||
*/ |
||||
@Documented |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target({ElementType.METHOD}) |
||||
public @interface SensitiveDecode { |
||||
|
||||
/** |
||||
* 指明需要脱敏的实体类class |
||||
* |
||||
* @return |
||||
*/ |
||||
Class entity() default Object.class; |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 加密注解 |
||||
* <p> |
||||
* 在方法上声明 将方法返回对象中的敏感字段 加密/格式化 |
||||
*/ |
||||
@Documented |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target({ElementType.METHOD}) |
||||
public @interface SensitiveEncode { |
||||
|
||||
/** |
||||
* 指明需要脱敏的实体类class |
||||
* |
||||
* @return |
||||
*/ |
||||
Class entity() default Object.class; |
||||
} |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.annotation; |
||||
|
||||
|
||||
import cc.niushuai.bastionserver.common.desensitization.enums.SensitiveEnum; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 在字段上定义 标识字段存储的信息是敏感的 |
||||
*/ |
||||
@Documented |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target(ElementType.FIELD) |
||||
public @interface SensitiveField { |
||||
|
||||
/** |
||||
* 不同类型处理不同 |
||||
* |
||||
* @return |
||||
*/ |
||||
SensitiveEnum type() default SensitiveEnum.ENCODE; |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.aspect; |
||||
|
||||
import cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveDecode; |
||||
import cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveEncode; |
||||
import cc.niushuai.bastionserver.common.desensitization.util.SensitiveInfoUtil; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 敏感数据切面处理类 |
||||
* |
||||
* @Author taoYan |
||||
* @Date 2022/4/20 17:45 |
||||
**/ |
||||
@Slf4j |
||||
@Aspect |
||||
@Component |
||||
public class SensitiveDataAspect { |
||||
|
||||
/** |
||||
* 定义切点Pointcut |
||||
*/ |
||||
@Pointcut("@annotation(cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveEncode) || @annotation(cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveDecode)") |
||||
public void sensitivePointCut() { |
||||
} |
||||
|
||||
@Around("sensitivePointCut()") |
||||
public Object around(ProceedingJoinPoint point) throws Throwable { |
||||
// 处理结果
|
||||
Object result = point.proceed(); |
||||
if (result == null) { |
||||
return result; |
||||
} |
||||
Class resultClass = result.getClass(); |
||||
log.debug(" resultClass = {}", resultClass); |
||||
|
||||
if (resultClass.isPrimitive()) { |
||||
//是基本类型 直接返回 不需要处理
|
||||
return result; |
||||
} |
||||
// 获取方法注解信息:是哪个实体、是加密还是解密
|
||||
boolean isEncode = true; |
||||
Class entity = null; |
||||
MethodSignature methodSignature = (MethodSignature) point.getSignature(); |
||||
Method method = methodSignature.getMethod(); |
||||
SensitiveEncode encode = method.getAnnotation(SensitiveEncode.class); |
||||
if (encode == null) { |
||||
SensitiveDecode decode = method.getAnnotation(SensitiveDecode.class); |
||||
if (decode != null) { |
||||
entity = decode.entity(); |
||||
isEncode = false; |
||||
} |
||||
} else { |
||||
entity = encode.entity(); |
||||
} |
||||
|
||||
long startTime = System.currentTimeMillis(); |
||||
if (resultClass.equals(entity) || entity.equals(Object.class)) { |
||||
// 方法返回实体和注解的entity一样,如果注解没有申明entity属性则认为是(方法返回实体和注解的entity一样)
|
||||
SensitiveInfoUtil.handlerObject(result, isEncode); |
||||
} else if (result instanceof List) { |
||||
// 方法返回List<实体>
|
||||
SensitiveInfoUtil.handleList(result, entity, isEncode); |
||||
} else { |
||||
// 方法返回一个对象
|
||||
SensitiveInfoUtil.handleNestedObject(result, entity, isEncode); |
||||
} |
||||
long endTime = System.currentTimeMillis(); |
||||
log.info((isEncode ? "加密操作," : "解密操作,") + "Aspect程序耗时:" + (endTime - startTime) + "ms"); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.enums; |
||||
|
||||
/** |
||||
* 敏感字段信息类型 |
||||
*/ |
||||
public enum SensitiveEnum { |
||||
|
||||
|
||||
/** |
||||
* 加密 |
||||
*/ |
||||
ENCODE, |
||||
|
||||
/** |
||||
* 中文名 |
||||
*/ |
||||
CHINESE_NAME, |
||||
|
||||
/** |
||||
* 身份证号 |
||||
*/ |
||||
ID_CARD, |
||||
|
||||
/** |
||||
* 座机号 |
||||
*/ |
||||
FIXED_PHONE, |
||||
|
||||
/** |
||||
* 手机号 |
||||
*/ |
||||
MOBILE_PHONE, |
||||
|
||||
/** |
||||
* 地址 |
||||
*/ |
||||
ADDRESS, |
||||
|
||||
/** |
||||
* 电子邮件 |
||||
*/ |
||||
EMAIL, |
||||
|
||||
/** |
||||
* 银行卡 |
||||
*/ |
||||
BANK_CARD, |
||||
|
||||
/** |
||||
* 公司开户银行联号 |
||||
*/ |
||||
CNAPS_CODE; |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,380 @@
@@ -0,0 +1,380 @@
|
||||
package cc.niushuai.bastionserver.common.desensitization.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveField; |
||||
import cc.niushuai.bastionserver.common.desensitization.enums.SensitiveEnum; |
||||
import cc.niushuai.bastionserver.common.util.encryption.AesEncryptUtil; |
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.ParameterizedType; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 敏感信息处理工具类 |
||||
* |
||||
* @author taoYan |
||||
* @date 2022/4/20 18:01 |
||||
**/ |
||||
@Slf4j |
||||
public class SensitiveInfoUtil { |
||||
|
||||
/** |
||||
* 处理嵌套对象 |
||||
* |
||||
* @param obj 方法返回值 |
||||
* @param entity 实体class |
||||
* @param isEncode 是否加密(true: 加密操作 / false:解密操作) |
||||
* @throws IllegalAccessException |
||||
*/ |
||||
public static void handleNestedObject(Object obj, Class entity, boolean isEncode) throws IllegalAccessException { |
||||
Field[] fields = obj.getClass().getDeclaredFields(); |
||||
for (Field field : fields) { |
||||
if (field.getType().isPrimitive()) { |
||||
continue; |
||||
} |
||||
if (field.getType().equals(entity)) { |
||||
// 对象里面是实体
|
||||
field.setAccessible(true); |
||||
Object nestedObject = field.get(obj); |
||||
handlerObject(nestedObject, isEncode); |
||||
break; |
||||
} else { |
||||
// 对象里面是List<实体>
|
||||
if (field.getGenericType() instanceof ParameterizedType) { |
||||
ParameterizedType pt = (ParameterizedType) field.getGenericType(); |
||||
if (pt.getRawType().equals(List.class)) { |
||||
if (pt.getActualTypeArguments()[0].equals(entity)) { |
||||
field.setAccessible(true); |
||||
Object nestedObject = field.get(obj); |
||||
handleList(nestedObject, entity, isEncode); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 处理Object |
||||
* |
||||
* @param obj 方法返回值 |
||||
* @param isEncode 是否加密(true: 加密操作 / false:解密操作) |
||||
* @return |
||||
* @throws IllegalAccessException |
||||
*/ |
||||
public static Object handlerObject(Object obj, boolean isEncode) throws IllegalAccessException { |
||||
log.trace(" obj --> " + obj.toString()); |
||||
long startTime = System.currentTimeMillis(); |
||||
if (oConvertUtils.isEmpty(obj)) { |
||||
return obj; |
||||
} |
||||
// 判断是不是一个对象
|
||||
Field[] fields = obj.getClass().getDeclaredFields(); |
||||
for (Field field : fields) { |
||||
boolean isSensitiveField = field.isAnnotationPresent(SensitiveField.class); |
||||
if (isSensitiveField) { |
||||
// 必须有SensitiveField注解 才作处理
|
||||
if (field.getType().isAssignableFrom(String.class)) { |
||||
//必须是字符串类型 才作处理
|
||||
field.setAccessible(true); |
||||
String realValue = (String) field.get(obj); |
||||
if (realValue == null || "".equals(realValue)) { |
||||
continue; |
||||
} |
||||
SensitiveField sf = field.getAnnotation(SensitiveField.class); |
||||
if (isEncode == true) { |
||||
//加密
|
||||
String value = SensitiveInfoUtil.getEncodeData(realValue, sf.type()); |
||||
field.set(obj, value); |
||||
} else { |
||||
//解密只处理 encode类型的
|
||||
if (sf.type().equals(SensitiveEnum.ENCODE)) { |
||||
String value = SensitiveInfoUtil.getDecodeData(realValue); |
||||
field.set(obj, value); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
//long endTime=System.currentTimeMillis();
|
||||
//log.info((isEncode ? "加密操作," : "解密操作,") + "当前程序耗时:" + (endTime - startTime) + "ms");
|
||||
return obj; |
||||
} |
||||
|
||||
/** |
||||
* 处理 List<实体> |
||||
* |
||||
* @param obj |
||||
* @param entity |
||||
* @param isEncode(true: 加密操作 / false:解密操作) |
||||
*/ |
||||
public static void handleList(Object obj, Class entity, boolean isEncode) { |
||||
List list = (List) obj; |
||||
if (list.size() > 0) { |
||||
Object first = list.get(0); |
||||
if (first.getClass().equals(entity)) { |
||||
for (int i = 0; i < list.size(); i++) { |
||||
Object temp = list.get(i); |
||||
try { |
||||
handlerObject(temp, isEncode); |
||||
} catch (IllegalAccessException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 处理数据 获取解密后的数据 |
||||
* |
||||
* @param data |
||||
* @return |
||||
*/ |
||||
public static String getDecodeData(String data) { |
||||
String result = null; |
||||
try { |
||||
result = AesEncryptUtil.desEncrypt(data); |
||||
} catch (Exception exception) { |
||||
log.debug("数据解密错误,原数据:" + data); |
||||
} |
||||
//解决debug模式下,加解密失效导致中文被解密变成空的问题
|
||||
if (oConvertUtils.isEmpty(result) && oConvertUtils.isNotEmpty(data)) { |
||||
result = data; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 处理数据 获取加密后的数据 或是格式化后的数据 |
||||
* |
||||
* @param data 字符串 |
||||
* @param sensitiveEnum 类型 |
||||
* @return 处理后的字符串 |
||||
*/ |
||||
public static String getEncodeData(String data, SensitiveEnum sensitiveEnum) { |
||||
String result; |
||||
switch (sensitiveEnum) { |
||||
case ENCODE: |
||||
try { |
||||
result = AesEncryptUtil.encrypt(data); |
||||
} catch (Exception exception) { |
||||
log.error("数据加密错误", exception.getMessage()); |
||||
result = data; |
||||
} |
||||
break; |
||||
case CHINESE_NAME: |
||||
result = chineseName(data); |
||||
break; |
||||
case ID_CARD: |
||||
result = idCardNum(data); |
||||
break; |
||||
case FIXED_PHONE: |
||||
result = fixedPhone(data); |
||||
break; |
||||
case MOBILE_PHONE: |
||||
result = mobilePhone(data); |
||||
break; |
||||
case ADDRESS: |
||||
result = address(data, 3); |
||||
break; |
||||
case EMAIL: |
||||
result = email(data); |
||||
break; |
||||
case BANK_CARD: |
||||
result = bankCard(data); |
||||
break; |
||||
case CNAPS_CODE: |
||||
result = cnapsCode(data); |
||||
break; |
||||
default: |
||||
result = data; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* [中文姓名] 只显示第一个汉字,其他隐藏为2个星号 |
||||
* |
||||
* @param fullName 全名 |
||||
* @return <例子:李**> |
||||
*/ |
||||
private static String chineseName(String fullName) { |
||||
if (oConvertUtils.isEmpty(fullName)) { |
||||
return ""; |
||||
} |
||||
return formatRight(fullName, 1); |
||||
} |
||||
|
||||
/** |
||||
* [中文姓名] 只显示第一个汉字,其他隐藏为2个星号 |
||||
* |
||||
* @param familyName 姓 |
||||
* @param firstName 名 |
||||
* @return <例子:李**> |
||||
*/ |
||||
private static String chineseName(String familyName, String firstName) { |
||||
if (oConvertUtils.isEmpty(familyName) || oConvertUtils.isEmpty(firstName)) { |
||||
return ""; |
||||
} |
||||
return chineseName(familyName + firstName); |
||||
} |
||||
|
||||
/** |
||||
* [身份证号] 显示最后四位,其他隐藏。共计18位或者15位。 |
||||
* |
||||
* @param id 身份证号 |
||||
* @return <例子:*************5762> |
||||
*/ |
||||
private static String idCardNum(String id) { |
||||
if (oConvertUtils.isEmpty(id)) { |
||||
return ""; |
||||
} |
||||
return formatLeft(id, 4); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* [固定电话] 后四位,其他隐藏 |
||||
* |
||||
* @param num 固定电话 |
||||
* @return <例子:****1234> |
||||
*/ |
||||
private static String fixedPhone(String num) { |
||||
if (oConvertUtils.isEmpty(num)) { |
||||
return ""; |
||||
} |
||||
return formatLeft(num, 4); |
||||
} |
||||
|
||||
/** |
||||
* [手机号码] 前三位,后四位,其他隐藏 |
||||
* |
||||
* @param num 手机号码 |
||||
* @return <例子:138******1234> |
||||
*/ |
||||
private static String mobilePhone(String num) { |
||||
if (oConvertUtils.isEmpty(num)) { |
||||
return ""; |
||||
} |
||||
int len = num.length(); |
||||
if (len < 11) { |
||||
return num; |
||||
} |
||||
return formatBetween(num, 3, 4); |
||||
} |
||||
|
||||
/** |
||||
* [地址] 只显示到地区,不显示详细地址;我们要对个人信息增强保护 |
||||
* |
||||
* @param address 地址 |
||||
* @param sensitiveSize 敏感信息长度 |
||||
* @return <例子:北京市海淀区****> |
||||
*/ |
||||
private static String address(String address, int sensitiveSize) { |
||||
if (oConvertUtils.isEmpty(address)) { |
||||
return ""; |
||||
} |
||||
int len = address.length(); |
||||
if (len < sensitiveSize) { |
||||
return address; |
||||
} |
||||
return formatRight(address, sensitiveSize); |
||||
} |
||||
|
||||
/** |
||||
* [电子邮箱] 邮箱前缀仅显示第一个字母,前缀其他隐藏,用星号代替,@及后面的地址显示 |
||||
* |
||||
* @param email 电子邮箱 |
||||
* @return <例子:g**@163.com> |
||||
*/ |
||||
private static String email(String email) { |
||||
if (oConvertUtils.isEmpty(email)) { |
||||
return ""; |
||||
} |
||||
int index = email.indexOf("@"); |
||||
if (index <= 1) { |
||||
return email; |
||||
} |
||||
String begin = email.substring(0, 1); |
||||
String end = email.substring(index); |
||||
String stars = "**"; |
||||
return begin + stars + end; |
||||
} |
||||
|
||||
/** |
||||
* [银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号 |
||||
* |
||||
* @param cardNum 银行卡号 |
||||
* @return <例子:6222600**********1234> |
||||
*/ |
||||
private static String bankCard(String cardNum) { |
||||
if (oConvertUtils.isEmpty(cardNum)) { |
||||
return ""; |
||||
} |
||||
return formatBetween(cardNum, 6, 4); |
||||
} |
||||
|
||||
/** |
||||
* [公司开户银行联号] 公司开户银行联行号,显示前两位,其他用星号隐藏,每位1个星号 |
||||
* |
||||
* @param code 公司开户银行联号 |
||||
* @return <例子:12********> |
||||
*/ |
||||
private static String cnapsCode(String code) { |
||||
if (oConvertUtils.isEmpty(code)) { |
||||
return ""; |
||||
} |
||||
return formatRight(code, 2); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 将右边的格式化成* |
||||
* |
||||
* @param str 字符串 |
||||
* @param reservedLength 保留长度 |
||||
* @return 格式化后的字符串 |
||||
*/ |
||||
private static String formatRight(String str, int reservedLength) { |
||||
String name = str.substring(0, reservedLength); |
||||
String stars = String.join("", Collections.nCopies(str.length() - reservedLength, "*")); |
||||
return name + stars; |
||||
} |
||||
|
||||
/** |
||||
* 将左边的格式化成* |
||||
* |
||||
* @param str 字符串 |
||||
* @param reservedLength 保留长度 |
||||
* @return 格式化后的字符串 |
||||
*/ |
||||
private static String formatLeft(String str, int reservedLength) { |
||||
int len = str.length(); |
||||
String show = str.substring(len - reservedLength); |
||||
String stars = String.join("", Collections.nCopies(len - reservedLength, "*")); |
||||
return stars + show; |
||||
} |
||||
|
||||
/** |
||||
* 将中间的格式化成* |
||||
* |
||||
* @param str 字符串 |
||||
* @param beginLen 开始保留长度 |
||||
* @param endLen 结尾保留长度 |
||||
* @return 格式化后的字符串 |
||||
*/ |
||||
private static String formatBetween(String str, int beginLen, int endLen) { |
||||
int len = str.length(); |
||||
String begin = str.substring(0, beginLen); |
||||
String end = str.substring(len - endLen); |
||||
String stars = String.join("", Collections.nCopies(len - beginLen - endLen, "*")); |
||||
return begin + stars + end; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
package cc.niushuai.bastionserver.common.enums; |
||||
|
||||
/** |
||||
* @Description: 异常错误信息定义 |
||||
* @author: zyf |
||||
* @date: 2022/4/14 10:05 |
||||
*/ |
||||
public enum SentinelErrorInfoEnum { |
||||
|
||||
/** |
||||
* 流控异常 |
||||
*/ |
||||
FlowException("访问频繁,请稍候再试"), |
||||
|
||||
/** |
||||
* 热点参数异常 |
||||
*/ |
||||
ParamFlowException("热点参数限流"), |
||||
|
||||
/** |
||||
* 系统规则限流或降级 |
||||
*/ |
||||
SystemBlockException("系统规则限流或降级"), |
||||
|
||||
/** |
||||
* 授权规则不通过 |
||||
*/ |
||||
AuthorityException("授权规则不通过"), |
||||
|
||||
/** |
||||
* 授权规则不通过 |
||||
*/ |
||||
UnknownError("未知异常"), |
||||
|
||||
/** |
||||
* 服务降级 |
||||
*/ |
||||
DegradeException("服务降级"); |
||||
|
||||
|
||||
/** |
||||
* 错误信息 |
||||
*/ |
||||
String error; |
||||
|
||||
/** |
||||
* 错误代码 |
||||
*/ |
||||
Integer code; |
||||
|
||||
|
||||
/** |
||||
* 构造器 |
||||
* |
||||
* @param error 错误信息 |
||||
* @param code 错误代码 |
||||
*/ |
||||
SentinelErrorInfoEnum(String error, Integer code) { |
||||
this.error = error; |
||||
this.code = code; |
||||
} |
||||
|
||||
/** |
||||
* 构造器 |
||||
* |
||||
* @param error 错误信息 |
||||
*/ |
||||
SentinelErrorInfoEnum(String error) { |
||||
this.error = error; |
||||
this.code = 500; |
||||
} |
||||
|
||||
/** |
||||
* 根据异常名称匹配 |
||||
* |
||||
* @param throwable 异常 |
||||
* @return String 错误信息 |
||||
*/ |
||||
public static SentinelErrorInfoEnum getErrorByException(Throwable throwable) { |
||||
if (throwable == null) { |
||||
return null; |
||||
} |
||||
|
||||
String exceptionClass = throwable.getClass().getSimpleName(); |
||||
for (SentinelErrorInfoEnum e : SentinelErrorInfoEnum.values()) { |
||||
if (exceptionClass.equals(e.name())) { |
||||
return e; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getError() { |
||||
return error; |
||||
} |
||||
|
||||
public void setError(String error) { |
||||
this.error = error; |
||||
} |
||||
|
||||
public Integer getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(Integer code) { |
||||
this.code = code; |
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
package cc.niushuai.bastionserver.common.exception; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
/** |
||||
* Business自定义异常 |
||||
* @author: niushuai233 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
public class BusinessException extends RuntimeException { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private int code; |
||||
private String message; |
||||
private Object[] params; |
||||
|
||||
public BusinessException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
public BusinessException(Throwable cause) { |
||||
super(cause); |
||||
} |
||||
|
||||
public BusinessException(int code, String message) { |
||||
this.code = code; |
||||
this.message = message; |
||||
} |
||||
|
||||
public BusinessException(String message, Object... params) { |
||||
super(message); |
||||
this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; |
||||
this.params = params; |
||||
this.message = StrUtil.format(message, params); |
||||
} |
||||
|
||||
public BusinessException(int code, String message, Object... params) { |
||||
super(message); |
||||
this.code = code; |
||||
this.params = params; |
||||
this.message = StrUtil.format(message, params); |
||||
} |
||||
|
||||
public BusinessException(String message, Throwable cause) { |
||||
super(message, cause); |
||||
} |
||||
} |
||||
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
package cc.niushuai.bastionserver.common.exception; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.enums.SentinelErrorInfoEnum; |
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.authz.AuthorizationException; |
||||
import org.apache.shiro.authz.UnauthorizedException; |
||||
import org.springframework.dao.DataIntegrityViolationException; |
||||
import org.springframework.dao.DuplicateKeyException; |
||||
import org.springframework.data.redis.connection.PoolException; |
||||
import org.springframework.web.HttpRequestMethodNotSupportedException; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException; |
||||
import org.springframework.web.servlet.NoHandlerFoundException; |
||||
|
||||
/** |
||||
* 全局异常处理 |
||||
* |
||||
* @author niushuai233 |
||||
* @date: 2022/12/23 17:59 |
||||
*/ |
||||
@Slf4j |
||||
@RestControllerAdvice |
||||
public class GlobalExceptionHandler { |
||||
|
||||
/** |
||||
* 处理自定义异常 |
||||
*/ |
||||
@ExceptionHandler(BusinessException.class) |
||||
public Result<?> handleBusinessException(BusinessException e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error(e.getCode(), e.getMessage()); |
||||
} |
||||
|
||||
@ExceptionHandler(NoHandlerFoundException.class) |
||||
public Result<?> handlerNoFoundException(Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error(404, "路径不存在,请检查路径是否正确"); |
||||
} |
||||
|
||||
@ExceptionHandler(DuplicateKeyException.class) |
||||
public Result<?> handleDuplicateKeyException(DuplicateKeyException e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error("数据库中已存在该记录"); |
||||
} |
||||
|
||||
@ExceptionHandler({UnauthorizedException.class, AuthorizationException.class}) |
||||
public Result<?> handleAuthorizationException(AuthorizationException e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.noauth("没有权限,请联系管理员授权"); |
||||
} |
||||
|
||||
@ExceptionHandler(Exception.class) |
||||
public Result<?> handleException(Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error("操作失败," + e.getMessage()); |
||||
} |
||||
|
||||
/** |
||||
* @param e |
||||
* @return |
||||
* @Author 政辉 |
||||
*/ |
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) |
||||
public Result<?> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { |
||||
StringBuffer sb = new StringBuffer(); |
||||
sb.append("不支持"); |
||||
sb.append(e.getMethod()); |
||||
sb.append("请求方法,"); |
||||
sb.append("支持以下"); |
||||
String[] methods = e.getSupportedMethods(); |
||||
if (methods != null) { |
||||
for (String str : methods) { |
||||
sb.append(str); |
||||
sb.append("、"); |
||||
} |
||||
} |
||||
log.error(sb.toString(), e); |
||||
//return Result.error("没有权限,请联系管理员授权");
|
||||
return Result.error(405, sb.toString()); |
||||
} |
||||
|
||||
/** |
||||
* spring默认上传大小100MB 超出大小捕获异常MaxUploadSizeExceededException |
||||
*/ |
||||
@ExceptionHandler(MaxUploadSizeExceededException.class) |
||||
public Result<?> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error("文件大小超出10MB限制, 请压缩或降低文件质量! "); |
||||
} |
||||
|
||||
@ExceptionHandler(DataIntegrityViolationException.class) |
||||
public Result<?> handleDataIntegrityViolationException(DataIntegrityViolationException e) { |
||||
log.error(e.getMessage(), e); |
||||
//【issues/3624】数据库执行异常handleDataIntegrityViolationException提示有误 #3624
|
||||
return Result.error("执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等"); |
||||
} |
||||
|
||||
@ExceptionHandler(PoolException.class) |
||||
public Result<?> handlePoolException(PoolException e) { |
||||
log.error(e.getMessage(), e); |
||||
return Result.error("Redis 连接异常!"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
package cc.niushuai.bastionserver.common.handler; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
|
||||
/** |
||||
* 填值规则接口 |
||||
* |
||||
* @author Yan_东 |
||||
* 如需使用填值规则功能,规则实现类必须实现此接口 |
||||
*/ |
||||
public interface IFillRuleHandler { |
||||
|
||||
/** |
||||
* 填值规则 |
||||
* |
||||
* @param params 页面配置固定参数 |
||||
* @param formData 动态表单参数 |
||||
* @return |
||||
*/ |
||||
public Object execute(JSONObject params, JSONObject formData); |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package cc.niushuai.bastionserver.common.modules.redis.client; |
||||
|
||||
import cc.niushuai.bastionserver.common.base.BaseMap; |
||||
import cc.niushuai.bastionserver.common.constant.GlobalConstants; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @Description: redis客户端 |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:01 |
||||
*/ |
||||
@Configuration |
||||
public class JeecgRedisClient { |
||||
|
||||
@Resource |
||||
private RedisTemplate<String, Object> redisTemplate; |
||||
|
||||
|
||||
/** |
||||
* 发送消息 |
||||
* |
||||
* @param handlerName |
||||
* @param params |
||||
*/ |
||||
public void sendMessage(String handlerName, BaseMap params) { |
||||
params.put(GlobalConstants.HANDLER_NAME, handlerName); |
||||
redisTemplate.convertAndSend(GlobalConstants.REDIS_TOPIC_NAME, params); |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,146 @@
@@ -0,0 +1,146 @@
|
||||
package cc.niushuai.bastionserver.common.modules.redis.config; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CacheConstant; |
||||
import cc.niushuai.bastionserver.common.constant.GlobalConstants; |
||||
import cc.niushuai.bastionserver.common.modules.redis.receiver.RedisReceiver; |
||||
import cc.niushuai.bastionserver.common.modules.redis.writer.JeecgRedisCacheWriter; |
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; |
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; |
||||
import com.fasterxml.jackson.databind.jsontype.DefaultBaseTypeLimitingValidator; |
||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; |
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.poi.ss.formula.functions.T; |
||||
import org.springframework.cache.CacheManager; |
||||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration; |
||||
import org.springframework.data.redis.cache.RedisCacheManager; |
||||
import org.springframework.data.redis.cache.RedisCacheWriter; |
||||
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.data.redis.listener.ChannelTopic; |
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
||||
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; |
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.RedisSerializationContext; |
||||
import org.springframework.data.redis.serializer.RedisSerializer; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import static java.util.Collections.singletonMap; |
||||
|
||||
/** |
||||
* 开启缓存支持 |
||||
* |
||||
* @author zyf |
||||
* @Return: |
||||
*/ |
||||
@Slf4j |
||||
@EnableCaching |
||||
@Configuration |
||||
public class RedisConfig extends CachingConfigurerSupport { |
||||
|
||||
/** |
||||
* RedisTemplate配置 |
||||
* |
||||
* @param lettuceConnectionFactory |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) { |
||||
log.info(" --- redis config init --- "); |
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = jacksonSerializer(); |
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); |
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory); |
||||
RedisSerializer<String> stringSerializer = new StringRedisSerializer(); |
||||
|
||||
// key序列化
|
||||
redisTemplate.setKeySerializer(stringSerializer); |
||||
// value序列化
|
||||
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); |
||||
// Hash key序列化
|
||||
redisTemplate.setHashKeySerializer(stringSerializer); |
||||
// Hash value序列化
|
||||
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); |
||||
redisTemplate.afterPropertiesSet(); |
||||
return redisTemplate; |
||||
} |
||||
|
||||
/** |
||||
* 缓存配置管理器 |
||||
* |
||||
* @param factory |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public CacheManager cacheManager(LettuceConnectionFactory factory) { |
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = jacksonSerializer(); |
||||
// 配置序列化(解决乱码的问题),并且配置缓存默认有效期 6小时
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(6)); |
||||
RedisCacheConfiguration redisCacheConfiguration = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) |
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)); |
||||
//.disableCachingNullValues();
|
||||
|
||||
// 以锁写入的方式创建RedisCacheWriter对象
|
||||
//update-begin-author:taoyan date:20210316 for:注解CacheEvict根据key删除redis支持通配符*
|
||||
RedisCacheWriter writer = new JeecgRedisCacheWriter(factory, Duration.ofMillis(50L)); |
||||
//RedisCacheWriter.lockingRedisCacheWriter(factory);
|
||||
// 创建默认缓存配置对象
|
||||
/* 默认配置,设置缓存有效期 1小时*/ |
||||
//RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1));
|
||||
// 自定义配置test:demo 的超时时间为 5分钟
|
||||
RedisCacheManager cacheManager = RedisCacheManager.builder(writer).cacheDefaults(redisCacheConfiguration) |
||||
.withInitialCacheConfigurations(singletonMap(CacheConstant.SYS_DICT_TABLE_CACHE, |
||||
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(10)).disableCachingNullValues() |
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)))) |
||||
.withInitialCacheConfigurations(singletonMap(CacheConstant.TEST_DEMO_CACHE, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(5)).disableCachingNullValues())) |
||||
.withInitialCacheConfigurations(singletonMap(CacheConstant.PLUGIN_MALL_RANKING, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(24)).disableCachingNullValues())) |
||||
.withInitialCacheConfigurations(singletonMap(CacheConstant.PLUGIN_MALL_PAGE_LIST, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(24)).disableCachingNullValues())) |
||||
.transactionAware().build(); |
||||
//update-end-author:taoyan date:20210316 for:注解CacheEvict根据key删除redis支持通配符*
|
||||
return cacheManager; |
||||
} |
||||
|
||||
/** |
||||
* redis 监听配置 |
||||
* |
||||
* @param redisConnectionFactory redis 配置 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public RedisMessageListenerContainer redisContainer(RedisConnectionFactory redisConnectionFactory, RedisReceiver redisReceiver, MessageListenerAdapter commonListenerAdapter) { |
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
||||
container.setConnectionFactory(redisConnectionFactory); |
||||
container.addMessageListener(commonListenerAdapter, new ChannelTopic(GlobalConstants.REDIS_TOPIC_NAME)); |
||||
return container; |
||||
} |
||||
|
||||
|
||||
@Bean |
||||
MessageListenerAdapter commonListenerAdapter(RedisReceiver redisReceiver) { |
||||
MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(redisReceiver, "onMessage"); |
||||
messageListenerAdapter.setSerializer(jacksonSerializer()); |
||||
return messageListenerAdapter; |
||||
} |
||||
|
||||
private Jackson2JsonRedisSerializer<Object> jacksonSerializer() { |
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); |
||||
ObjectMapper objectMapper = new ObjectMapper(); |
||||
objectMapper.setVisibility(PropertyAccessor.ALL, Visibility.ANY); |
||||
objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY); |
||||
// 上面一行替代下面一行
|
||||
// objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(objectMapper); |
||||
return jackson2JsonRedisSerializer; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
package cc.niushuai.bastionserver.common.modules.redis.listener; |
||||
|
||||
import cc.niushuai.bastionserver.common.base.BaseMap; |
||||
|
||||
/** |
||||
* @Description: 自定义消息监听 |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:02 |
||||
*/ |
||||
public interface JeecgRedisListener { |
||||
/** |
||||
* 接受消息 |
||||
* |
||||
* @param message |
||||
*/ |
||||
void onMessage(BaseMap message); |
||||
|
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
package cc.niushuai.bastionserver.common.modules.redis.receiver; |
||||
|
||||
|
||||
import cc.niushuai.bastionserver.common.base.BaseMap; |
||||
import cc.niushuai.bastionserver.common.constant.GlobalConstants; |
||||
import cc.niushuai.bastionserver.common.modules.redis.listener.JeecgRedisListener; |
||||
import cc.niushuai.bastionserver.common.util.SpringContextHolder; |
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import lombok.Data; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* @author zyf |
||||
*/ |
||||
@Component |
||||
@Data |
||||
public class RedisReceiver { |
||||
|
||||
|
||||
/** |
||||
* 接受消息并调用业务逻辑处理器 |
||||
* |
||||
* @param params |
||||
*/ |
||||
public void onMessage(BaseMap params) { |
||||
Object handlerName = params.get(GlobalConstants.HANDLER_NAME); |
||||
JeecgRedisListener messageListener = SpringContextHolder.getHandler(handlerName.toString(), JeecgRedisListener.class); |
||||
if (ObjectUtil.isNotEmpty(messageListener)) { |
||||
messageListener.onMessage(params); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,250 @@
@@ -0,0 +1,250 @@
|
||||
package cc.niushuai.bastionserver.common.modules.redis.writer; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.dao.PessimisticLockingFailureException; |
||||
import org.springframework.data.redis.cache.CacheStatistics; |
||||
import org.springframework.data.redis.cache.CacheStatisticsCollector; |
||||
import org.springframework.data.redis.cache.RedisCacheWriter; |
||||
import org.springframework.data.redis.connection.RedisConnection; |
||||
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption; |
||||
import org.springframework.data.redis.core.types.Expiration; |
||||
import org.springframework.lang.Nullable; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.nio.charset.StandardCharsets; |
||||
import java.time.Duration; |
||||
import java.util.Collections; |
||||
import java.util.Optional; |
||||
import java.util.Set; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.function.Consumer; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* 该类参照 DefaultRedisCacheWriter 重写了 remove 方法实现通配符*删除 |
||||
* |
||||
* @author: scott |
||||
* @date: 2020/01/01 16:18 |
||||
*/ |
||||
@Slf4j |
||||
public class JeecgRedisCacheWriter implements RedisCacheWriter { |
||||
|
||||
private final RedisConnectionFactory connectionFactory; |
||||
private final Duration sleepTime; |
||||
//update-begin-author:zyf date:20220216 for:升级springboot版本到2.4.0+以后需要实现的方法*
|
||||
private final CacheStatisticsCollector statistics = CacheStatisticsCollector.create(); |
||||
|
||||
public JeecgRedisCacheWriter(RedisConnectionFactory connectionFactory) { |
||||
this(connectionFactory, Duration.ZERO); |
||||
} |
||||
|
||||
public JeecgRedisCacheWriter(RedisConnectionFactory connectionFactory, Duration sleepTime) { |
||||
Assert.notNull(connectionFactory, "ConnectionFactory must not be null!"); |
||||
Assert.notNull(sleepTime, "SleepTime must not be null!"); |
||||
this.connectionFactory = connectionFactory; |
||||
this.sleepTime = sleepTime; |
||||
} |
||||
|
||||
private static boolean shouldExpireWithin(@Nullable Duration ttl) { |
||||
return ttl != null && !ttl.isZero() && !ttl.isNegative(); |
||||
} |
||||
|
||||
private static byte[] createCacheLockKey(String name) { |
||||
return (name + "~lock").getBytes(StandardCharsets.UTF_8); |
||||
} |
||||
|
||||
@Override |
||||
public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl) { |
||||
Assert.notNull(name, "Name must not be null!"); |
||||
Assert.notNull(key, "Key must not be null!"); |
||||
Assert.notNull(value, "Value must not be null!"); |
||||
this.execute(name, (connection) -> { |
||||
if (shouldExpireWithin(ttl)) { |
||||
connection.set(key, value, Expiration.from(ttl.toMillis(), TimeUnit.MILLISECONDS), SetOption.upsert()); |
||||
} else { |
||||
connection.set(key, value); |
||||
} |
||||
|
||||
return "OK"; |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public byte[] get(String name, byte[] key) { |
||||
Assert.notNull(name, "Name must not be null!"); |
||||
Assert.notNull(key, "Key must not be null!"); |
||||
return (byte[]) this.execute(name, (connection) -> { |
||||
return connection.get(key); |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) { |
||||
Assert.notNull(name, "Name must not be null!"); |
||||
Assert.notNull(key, "Key must not be null!"); |
||||
Assert.notNull(value, "Value must not be null!"); |
||||
return (byte[]) this.execute(name, (connection) -> { |
||||
if (this.isLockingCacheWriter()) { |
||||
this.doLock(name, connection); |
||||
} |
||||
|
||||
Object var7; |
||||
try { |
||||
boolean put; |
||||
if (shouldExpireWithin(ttl)) { |
||||
put = connection.set(key, value, Expiration.from(ttl), SetOption.ifAbsent()); |
||||
} else { |
||||
put = connection.setNX(key, value); |
||||
} |
||||
|
||||
if (!put) { |
||||
byte[] var11 = connection.get(key); |
||||
return var11; |
||||
} |
||||
|
||||
var7 = null; |
||||
} finally { |
||||
if (this.isLockingCacheWriter()) { |
||||
this.doUnlock(name, connection); |
||||
} |
||||
|
||||
} |
||||
|
||||
return (byte[]) var7; |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void remove(String name, byte[] key) { |
||||
Assert.notNull(name, "Name must not be null!"); |
||||
Assert.notNull(key, "Key must not be null!"); |
||||
String keyString = new String(key); |
||||
log.info("redis remove key:" + keyString); |
||||
String keyIsAll = "*"; |
||||
if (keyString != null && keyString.endsWith(keyIsAll)) { |
||||
execute(name, connection -> { |
||||
// 获取某个前缀所拥有的所有的键,某个前缀开头,后面肯定是*
|
||||
Set<byte[]> keys = connection.keys(key); |
||||
int delNum = 0; |
||||
for (byte[] keyByte : keys) { |
||||
delNum += connection.del(keyByte); |
||||
} |
||||
return delNum; |
||||
}); |
||||
} else { |
||||
this.execute(name, (connection) -> { |
||||
return connection.del(new byte[][]{key}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void clean(String name, byte[] pattern) { |
||||
Assert.notNull(name, "Name must not be null!"); |
||||
Assert.notNull(pattern, "Pattern must not be null!"); |
||||
this.execute(name, (connection) -> { |
||||
boolean wasLocked = false; |
||||
|
||||
try { |
||||
if (this.isLockingCacheWriter()) { |
||||
this.doLock(name, connection); |
||||
wasLocked = true; |
||||
} |
||||
|
||||
byte[][] keys = (byte[][]) ((Set) Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())).toArray(new byte[0][]); |
||||
if (keys.length > 0) { |
||||
connection.del(keys); |
||||
} |
||||
} finally { |
||||
if (wasLocked && this.isLockingCacheWriter()) { |
||||
this.doUnlock(name, connection); |
||||
} |
||||
|
||||
} |
||||
|
||||
return "OK"; |
||||
}); |
||||
} |
||||
|
||||
void lock(String name) { |
||||
this.execute(name, (connection) -> { |
||||
return this.doLock(name, connection); |
||||
}); |
||||
} |
||||
|
||||
void unlock(String name) { |
||||
this.executeLockFree((connection) -> { |
||||
this.doUnlock(name, connection); |
||||
}); |
||||
} |
||||
|
||||
private Boolean doLock(String name, RedisConnection connection) { |
||||
return connection.setNX(createCacheLockKey(name), new byte[0]); |
||||
} |
||||
|
||||
private Long doUnlock(String name, RedisConnection connection) { |
||||
return connection.del(new byte[][]{createCacheLockKey(name)}); |
||||
} |
||||
|
||||
boolean doCheckLock(String name, RedisConnection connection) { |
||||
return connection.exists(createCacheLockKey(name)); |
||||
} |
||||
|
||||
private boolean isLockingCacheWriter() { |
||||
return !this.sleepTime.isZero() && !this.sleepTime.isNegative(); |
||||
} |
||||
|
||||
private <T> T execute(String name, Function<RedisConnection, T> callback) { |
||||
RedisConnection connection = this.connectionFactory.getConnection(); |
||||
|
||||
try { |
||||
this.checkAndPotentiallyWaitUntilUnlocked(name, connection); |
||||
return callback.apply(connection); |
||||
} finally { |
||||
connection.close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void executeLockFree(Consumer<RedisConnection> callback) { |
||||
RedisConnection connection = this.connectionFactory.getConnection(); |
||||
|
||||
try { |
||||
callback.accept(connection); |
||||
} finally { |
||||
connection.close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void checkAndPotentiallyWaitUntilUnlocked(String name, RedisConnection connection) { |
||||
if (this.isLockingCacheWriter()) { |
||||
try { |
||||
while (this.doCheckLock(name, connection)) { |
||||
Thread.sleep(this.sleepTime.toMillis()); |
||||
} |
||||
|
||||
} catch (InterruptedException var4) { |
||||
Thread.currentThread().interrupt(); |
||||
throw new PessimisticLockingFailureException(String.format("Interrupted while waiting to unlock cache %s", name), var4); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public CacheStatistics getCacheStatistics(String cacheName) { |
||||
return statistics.getCacheStatistics(cacheName); |
||||
} |
||||
|
||||
@Override |
||||
public void clearStatistics(String name) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public RedisCacheWriter withStatisticsCollector(CacheStatisticsCollector cacheStatisticsCollector) { |
||||
return null; |
||||
} |
||||
//update-begin-author:zyf date:20220216 for:升级springboot版本到2.4.0+以后需要实现的方法*
|
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
package cc.niushuai.bastionserver.common.system.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* 将枚举类转化成字典数据 |
||||
* |
||||
* @Author taoYan |
||||
* @Date 2022/7/8 10:34 |
||||
**/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface EnumDict { |
||||
|
||||
/** |
||||
* 作为字典数据的唯一编码 |
||||
*/ |
||||
String value() default ""; |
||||
} |
||||
@ -0,0 +1,436 @@
@@ -0,0 +1,436 @@
|
||||
package cc.niushuai.bastionserver.common.system.api; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.CommonAPI; |
||||
import cc.niushuai.bastionserver.common.api.dto.DataLogDTO; |
||||
import cc.niushuai.bastionserver.common.api.dto.OnlineAuthDTO; |
||||
import cc.niushuai.bastionserver.common.api.dto.message.*; |
||||
import cc.niushuai.bastionserver.common.system.vo.*; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @Description 底层共通业务API,提供其他独立模块调用 |
||||
* @Author scott |
||||
* @Date 2019-4-20 |
||||
* @Version V1.0 |
||||
*/ |
||||
public interface ISysBaseAPI extends CommonAPI { |
||||
|
||||
|
||||
/** |
||||
* 1发送系统消息 |
||||
* |
||||
* @param message 使用构造器赋值参数 如果不设置category(消息类型)则默认为2 发送系统消息 |
||||
*/ |
||||
void sendSysAnnouncement(MessageDTO message); |
||||
|
||||
/** |
||||
* 2发送消息 附带业务参数 |
||||
* |
||||
* @param message 使用构造器赋值参数 |
||||
*/ |
||||
void sendBusAnnouncement(BusMessageDTO message); |
||||
|
||||
/** |
||||
* 3通过模板发送消息 |
||||
* |
||||
* @param message 使用构造器赋值参数 |
||||
*/ |
||||
void sendTemplateAnnouncement(TemplateMessageDTO message); |
||||
|
||||
/** |
||||
* 4通过模板发送消息 附带业务参数 |
||||
* |
||||
* @param message 使用构造器赋值参数 |
||||
*/ |
||||
void sendBusTemplateAnnouncement(BusTemplateMessageDTO message); |
||||
|
||||
/** |
||||
* 5通过消息中心模板,生成推送内容 |
||||
* |
||||
* @param templateDTO 使用构造器赋值参数 |
||||
* @return |
||||
*/ |
||||
String parseTemplateByCode(TemplateDTO templateDTO); |
||||
|
||||
//update-begin---author:taoyan ---date:20220705 for:支持自定义推送类型,邮件、钉钉、企业微信、系统消息-----------
|
||||
|
||||
/** |
||||
* 发送模板消息【新,支持自定义推送类型】 |
||||
* |
||||
* @param message |
||||
*/ |
||||
void sendTemplateMessage(MessageDTO message); |
||||
|
||||
/** |
||||
* 根据模板编码获取模板内容【新,支持自定义推送类型】 |
||||
* |
||||
* @param templateCode |
||||
* @return |
||||
*/ |
||||
String getTemplateContent(String templateCode); |
||||
//update-begin---author:taoyan ---date:20220705 for:支持自定义推送类型,邮件、钉钉、企业微信、系统消息-----------
|
||||
|
||||
/** |
||||
* 6根据用户id查询用户信息 |
||||
* |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
LoginUser getUserById(String id); |
||||
|
||||
/** |
||||
* 7通过用户账号查询角色集合 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
List<String> getRolesByUsername(String username); |
||||
|
||||
/** |
||||
* 8通过用户账号查询部门集合 |
||||
* |
||||
* @param username |
||||
* @return 部门 id |
||||
*/ |
||||
List<String> getDepartIdsByUsername(String username); |
||||
|
||||
/** |
||||
* 9通过用户账号查询部门 name |
||||
* |
||||
* @param username |
||||
* @return 部门 name |
||||
*/ |
||||
List<String> getDepartNamesByUsername(String username); |
||||
|
||||
|
||||
/** |
||||
* 11查询所有的父级字典,按照create_time排序 |
||||
* |
||||
* @return List<DictModel> 字典集合 |
||||
*/ |
||||
public List<DictModel> queryAllDict(); |
||||
|
||||
/** |
||||
* 12查询所有分类字典 |
||||
* |
||||
* @return |
||||
*/ |
||||
public List<SysCategoryModel> queryAllSysCategory(); |
||||
|
||||
|
||||
/** |
||||
* 14查询所有部门 作为字典信息 id -->value,departName -->text |
||||
* |
||||
* @return |
||||
*/ |
||||
public List<DictModel> queryAllDepartBackDictModel(); |
||||
|
||||
/** |
||||
* 15根据业务类型及业务id修改消息已读 |
||||
* |
||||
* @param busType |
||||
* @param busId |
||||
*/ |
||||
public void updateSysAnnounReadFlag(String busType, String busId); |
||||
|
||||
/** |
||||
* 16查询表字典 支持过滤数据 |
||||
* |
||||
* @param table |
||||
* @param text |
||||
* @param code |
||||
* @param filterSql |
||||
* @return |
||||
*/ |
||||
public List<DictModel> queryFilterTableDictInfo(String table, String text, String code, String filterSql); |
||||
|
||||
/** |
||||
* 17查询指定table的 text code 获取字典,包含text和value |
||||
* |
||||
* @param table |
||||
* @param text |
||||
* @param code |
||||
* @param keyArray |
||||
* @return |
||||
*/ |
||||
@Deprecated |
||||
public List<String> queryTableDictByKeys(String table, String text, String code, String[] keyArray); |
||||
|
||||
/** |
||||
* 18查询所有用户 返回ComboModel |
||||
* |
||||
* @return |
||||
*/ |
||||
public List<ComboModel> queryAllUserBackCombo(); |
||||
|
||||
/** |
||||
* 19分页查询用户 返回JSONObject |
||||
* |
||||
* @param userIds 多个用户id |
||||
* @param pageNo 当前页数 |
||||
* @param pageSize 每页显示条数 |
||||
* @return |
||||
*/ |
||||
public JSONObject queryAllUser(String userIds, Integer pageNo, Integer pageSize); |
||||
|
||||
/** |
||||
* 20获取所有角色 |
||||
* |
||||
* @return |
||||
*/ |
||||
public List<ComboModel> queryAllRole(); |
||||
|
||||
/** |
||||
* 21获取所有角色 带参 |
||||
* |
||||
* @param roleIds 默认选中角色 |
||||
* @return |
||||
*/ |
||||
public List<ComboModel> queryAllRole(String[] roleIds); |
||||
|
||||
/** |
||||
* 22通过用户账号查询角色Id集合 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public List<String> getRoleIdsByUsername(String username); |
||||
|
||||
/** |
||||
* 23通过部门编号查询部门id |
||||
* |
||||
* @param orgCode |
||||
* @return |
||||
*/ |
||||
public String getDepartIdsByOrgCode(String orgCode); |
||||
|
||||
/** |
||||
* 24查询所有部门 |
||||
* |
||||
* @return |
||||
*/ |
||||
public List<SysDepartModel> getAllSysDepart(); |
||||
|
||||
/** |
||||
* 25查找父级部门 |
||||
* |
||||
* @param departId |
||||
* @return |
||||
*/ |
||||
DictModel getParentDepartId(String departId); |
||||
|
||||
/** |
||||
* 26根据部门Id获取部门负责人 |
||||
* |
||||
* @param deptId |
||||
* @return |
||||
*/ |
||||
public List<String> getDeptHeadByDepId(String deptId); |
||||
|
||||
/** |
||||
* 27给指定用户发消息 |
||||
* |
||||
* @param userIds |
||||
* @param cmd |
||||
*/ |
||||
public void sendWebSocketMsg(String[] userIds, String cmd); |
||||
|
||||
/** |
||||
* 28根据id获取所有参与用户 |
||||
* |
||||
* @param userIds 多个用户id |
||||
* @return |
||||
*/ |
||||
public List<LoginUser> queryAllUserByIds(String[] userIds); |
||||
|
||||
/** |
||||
* 29将会议签到信息推动到预览 |
||||
* userIds |
||||
* |
||||
* @param userId |
||||
* @return |
||||
*/ |
||||
void meetingSignWebsocket(String userId); |
||||
|
||||
/** |
||||
* 30根据name获取所有参与用户 |
||||
* |
||||
* @param userNames 多个用户账户 |
||||
* @return |
||||
*/ |
||||
List<LoginUser> queryUserByNames(String[] userNames); |
||||
|
||||
|
||||
/** |
||||
* 31获取用户的角色集合 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
Set<String> getUserRoleSet(String username); |
||||
|
||||
/** |
||||
* 32获取用户的权限集合 |
||||
* |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
Set<String> getUserPermissionSet(String username); |
||||
|
||||
/** |
||||
* 33判断是否有online访问的权限 |
||||
* |
||||
* @param onlineAuthDTO |
||||
* @return |
||||
*/ |
||||
boolean hasOnlineAuth(OnlineAuthDTO onlineAuthDTO); |
||||
|
||||
/** |
||||
* 34通过部门id获取部门全部信息 |
||||
* |
||||
* @param id 部门id |
||||
* @return SysDepartModel对象 |
||||
*/ |
||||
SysDepartModel selectAllById(String id); |
||||
|
||||
/** |
||||
* 35根据用户id查询用户所属公司下所有用户ids |
||||
* |
||||
* @param userId |
||||
* @return |
||||
*/ |
||||
List<String> queryDeptUsersByUserId(String userId); |
||||
|
||||
/** |
||||
* 36根据多个用户账号(逗号分隔),查询返回多个用户信息 |
||||
* |
||||
* @param usernames |
||||
* @return |
||||
*/ |
||||
List<JSONObject> queryUsersByUsernames(String usernames); |
||||
|
||||
/** |
||||
* 37根据多个用户ID(逗号分隔),查询返回多个用户信息 |
||||
* |
||||
* @param ids |
||||
* @return |
||||
*/ |
||||
List<JSONObject> queryUsersByIds(String ids); |
||||
|
||||
/** |
||||
* 38根据多个部门编码(逗号分隔),查询返回多个部门信息 |
||||
* |
||||
* @param orgCodes |
||||
* @return |
||||
*/ |
||||
List<JSONObject> queryDepartsByOrgcodes(String orgCodes); |
||||
|
||||
/** |
||||
* 39根据多个部门id(逗号分隔),查询返回多个部门信息 |
||||
* |
||||
* @param ids |
||||
* @return |
||||
*/ |
||||
List<JSONObject> queryDepartsByIds(String ids); |
||||
|
||||
/** |
||||
* 40发送邮件消息 |
||||
* |
||||
* @param email |
||||
* @param title |
||||
* @param content |
||||
*/ |
||||
void sendEmailMsg(String email, String title, String content); |
||||
|
||||
/** |
||||
* 41 获取公司下级部门和公司下所有用户信息 |
||||
* |
||||
* @param orgCode |
||||
* @return List<Map> |
||||
*/ |
||||
List<Map> getDeptUserByOrgCode(String orgCode); |
||||
|
||||
/** |
||||
* 查询分类字典翻译 |
||||
* |
||||
* @param ids 多个分类字典id |
||||
* @return List<String> |
||||
*/ |
||||
List<String> loadCategoryDictItem(String ids); |
||||
|
||||
/** |
||||
* 根据字典code加载字典text |
||||
* |
||||
* @param dictCode 顺序:tableName,text,code |
||||
* @param keys 要查询的key |
||||
* @return |
||||
*/ |
||||
List<String> loadDictItem(String dictCode, String keys); |
||||
|
||||
/** |
||||
* 根据字典code查询字典项 |
||||
* |
||||
* @param dictCode 顺序:tableName,text,code |
||||
* @param dictCode 要查询的key |
||||
* @return |
||||
*/ |
||||
List<DictModel> getDictItems(String dictCode); |
||||
|
||||
/** |
||||
* 根据多个字典code查询多个字典项 |
||||
* |
||||
* @param dictCodeList |
||||
* @return key = dictCode ; value=对应的字典项 |
||||
*/ |
||||
Map<String, List<DictModel>> getManyDictItems(List<String> dictCodeList); |
||||
|
||||
/** |
||||
* 【JSearchSelectTag下拉搜索组件专用接口】 |
||||
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据 |
||||
* |
||||
* @param dictCode 字典code格式:table,text,code |
||||
* @param keyword 过滤关键字 |
||||
* @param pageSize 分页条数 |
||||
* @return |
||||
*/ |
||||
List<DictModel> loadDictItemByKeyword(String dictCode, String keyword, Integer pageSize); |
||||
|
||||
/** |
||||
* 新增数据日志 |
||||
* |
||||
* @param dataLogDto |
||||
*/ |
||||
void saveDataLog(DataLogDTO dataLogDto); |
||||
|
||||
/** |
||||
* 添加文件到知识库 |
||||
* |
||||
* @param sysFilesModel |
||||
*/ |
||||
void addSysFiles(SysFilesModel sysFilesModel); |
||||
|
||||
/** |
||||
* 通过文件路径获取文件id |
||||
* |
||||
* @param fileId |
||||
*/ |
||||
String getFileUrl(String fileId); |
||||
|
||||
/** |
||||
* 更新头像 |
||||
* |
||||
* @param loginUser |
||||
*/ |
||||
void updateAvatar(LoginUser loginUser); |
||||
|
||||
/** |
||||
* 向app端 websocket推送聊天刷新消息 |
||||
* |
||||
* @param userId |
||||
*/ |
||||
void sendAppChatSocket(String userId); |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
package cc.niushuai.bastionserver.common.system.query; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
|
||||
/** |
||||
* 查询链接规则 |
||||
* |
||||
* @Author Sunjianlei |
||||
*/ |
||||
public enum MatchTypeEnum { |
||||
|
||||
/** |
||||
* 查询链接规则 AND |
||||
*/ |
||||
AND("AND"), |
||||
/** |
||||
* 查询链接规则 OR |
||||
*/ |
||||
OR("OR"); |
||||
|
||||
private String value; |
||||
|
||||
MatchTypeEnum(String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public static MatchTypeEnum getByValue(Object value) { |
||||
if (oConvertUtils.isEmpty(value)) { |
||||
return null; |
||||
} |
||||
return getByValue(value.toString()); |
||||
} |
||||
|
||||
public static MatchTypeEnum getByValue(String value) { |
||||
if (oConvertUtils.isEmpty(value)) { |
||||
return null; |
||||
} |
||||
for (MatchTypeEnum val : values()) { |
||||
if (val.getValue().toLowerCase().equals(value.toLowerCase())) { |
||||
return val; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
} |
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
package cc.niushuai.bastionserver.common.system.query; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: QueryCondition |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public class QueryCondition implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 4740166316629191651L; |
||||
|
||||
private String field; |
||||
/** |
||||
* 组件的类型(例如:input、select、radio) |
||||
*/ |
||||
private String type; |
||||
/** |
||||
* 对应的数据库字段的类型 |
||||
* 支持:int、bigDecimal、short、long、float、double、boolean |
||||
*/ |
||||
private String dbType; |
||||
private String rule; |
||||
private String val; |
||||
|
||||
public String getField() { |
||||
return field; |
||||
} |
||||
|
||||
public void setField(String field) { |
||||
this.field = field; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(String type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getDbType() { |
||||
return dbType; |
||||
} |
||||
|
||||
public void setDbType(String dbType) { |
||||
this.dbType = dbType; |
||||
} |
||||
|
||||
public String getRule() { |
||||
return rule; |
||||
} |
||||
|
||||
public void setRule(String rule) { |
||||
this.rule = rule; |
||||
} |
||||
|
||||
public String getVal() { |
||||
return val; |
||||
} |
||||
|
||||
public void setVal(String val) { |
||||
this.val = val; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
StringBuffer sb = new StringBuffer(); |
||||
if (field == null || "".equals(field)) { |
||||
return ""; |
||||
} |
||||
sb.append(this.field).append(" ").append(this.rule).append(" ").append(this.type).append(" ").append(this.dbType).append(" ").append(this.val); |
||||
return sb.toString(); |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
package cc.niushuai.bastionserver.common.system.query; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.oConvertUtils; |
||||
|
||||
/** |
||||
* Query 规则 常量 |
||||
* |
||||
* @Author Scott |
||||
* @Date 2019年02月14日 |
||||
*/ |
||||
public enum QueryRuleEnum { |
||||
|
||||
/** |
||||
* 查询规则 大于 |
||||
*/ |
||||
GT(">", "gt", "大于"), |
||||
/** |
||||
* 查询规则 大于等于 |
||||
*/ |
||||
GE(">=", "ge", "大于等于"), |
||||
/** |
||||
* 查询规则 小于 |
||||
*/ |
||||
LT("<", "lt", "小于"), |
||||
/** |
||||
* 查询规则 小于等于 |
||||
*/ |
||||
LE("<=", "le", "小于等于"), |
||||
/** |
||||
* 查询规则 等于 |
||||
*/ |
||||
EQ("=", "eq", "等于"), |
||||
/** |
||||
* 查询规则 不等于 |
||||
*/ |
||||
NE("!=", "ne", "不等于"), |
||||
/** |
||||
* 查询规则 包含 |
||||
*/ |
||||
IN("IN", "in", "包含"), |
||||
/** |
||||
* 查询规则 全模糊 |
||||
*/ |
||||
LIKE("LIKE", "like", "全模糊"), |
||||
/** |
||||
* 查询规则 左模糊 |
||||
*/ |
||||
LEFT_LIKE("LEFT_LIKE", "left_like", "左模糊"), |
||||
/** |
||||
* 查询规则 右模糊 |
||||
*/ |
||||
RIGHT_LIKE("RIGHT_LIKE", "right_like", "右模糊"), |
||||
/** |
||||
* 查询规则 带加号等于 |
||||
*/ |
||||
EQ_WITH_ADD("EQWITHADD", "eq_with_add", "带加号等于"), |
||||
/** |
||||
* 查询规则 多词模糊匹配 |
||||
*/ |
||||
LIKE_WITH_AND("LIKEWITHAND", "like_with_and", "多词模糊匹配————暂时未用上"), |
||||
/** |
||||
* 查询规则 自定义SQL片段 |
||||
*/ |
||||
SQL_RULES("USE_SQL_RULES", "ext", "自定义SQL片段"); |
||||
|
||||
private String value; |
||||
|
||||
private String condition; |
||||
|
||||
private String msg; |
||||
|
||||
QueryRuleEnum(String value, String condition, String msg) { |
||||
this.value = value; |
||||
this.condition = condition; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
public static QueryRuleEnum getByValue(String value) { |
||||
if (oConvertUtils.isEmpty(value)) { |
||||
return null; |
||||
} |
||||
for (QueryRuleEnum val : values()) { |
||||
if (val.getValue().equals(value) || val.getCondition().equals(value)) { |
||||
return val; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
public void setValue(String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public String getMsg() { |
||||
return msg; |
||||
} |
||||
|
||||
public void setMsg(String msg) { |
||||
this.msg = msg; |
||||
} |
||||
|
||||
public String getCondition() { |
||||
return condition; |
||||
} |
||||
|
||||
public void setCondition(String condition) { |
||||
this.condition = condition; |
||||
} |
||||
} |
||||
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
package cc.niushuai.bastionserver.common.system.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.system.vo.SysPermissionDataRuleModel; |
||||
import cc.niushuai.bastionserver.common.system.vo.SysUserCacheInfo; |
||||
import cc.niushuai.bastionserver.common.util.SpringContextUtils; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @ClassName: JeecgDataAutorUtils |
||||
* @Description: 数据权限查询规则容器工具类 |
||||
* @Author: 张代浩 |
||||
* @Date: 2012-12-15 下午11:27:39 |
||||
*/ |
||||
public class JeecgDataAutorUtils { |
||||
|
||||
public static final String MENU_DATA_AUTHOR_RULES = "MENU_DATA_AUTHOR_RULES"; |
||||
|
||||
public static final String MENU_DATA_AUTHOR_RULE_SQL = "MENU_DATA_AUTHOR_RULE_SQL"; |
||||
|
||||
public static final String SYS_USER_INFO = "SYS_USER_INFO"; |
||||
|
||||
/** |
||||
* 往链接请求里面,传入数据查询条件 |
||||
* |
||||
* @param request |
||||
* @param dataRules |
||||
*/ |
||||
public static synchronized void installDataSearchConditon(HttpServletRequest request, List<SysPermissionDataRuleModel> dataRules) { |
||||
@SuppressWarnings("unchecked") |
||||
// 1.先从request获取MENU_DATA_AUTHOR_RULES,如果存则获取到LIST
|
||||
List<SysPermissionDataRuleModel> list = (List<SysPermissionDataRuleModel>) loadDataSearchConditon(); |
||||
if (list == null) { |
||||
// 2.如果不存在,则new一个list
|
||||
list = new ArrayList<SysPermissionDataRuleModel>(); |
||||
} |
||||
for (SysPermissionDataRuleModel tsDataRule : dataRules) { |
||||
list.add(tsDataRule); |
||||
} |
||||
// 3.往list里面增量存指
|
||||
request.setAttribute(MENU_DATA_AUTHOR_RULES, list); |
||||
} |
||||
|
||||
/** |
||||
* 获取请求对应的数据权限规则 |
||||
* |
||||
* @return |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
public static synchronized List<SysPermissionDataRuleModel> loadDataSearchConditon() { |
||||
return (List<SysPermissionDataRuleModel>) SpringContextUtils.getHttpServletRequest().getAttribute(MENU_DATA_AUTHOR_RULES); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取请求对应的数据权限SQL |
||||
* |
||||
* @return |
||||
*/ |
||||
public static synchronized String loadDataSearchConditonSqlString() { |
||||
return (String) SpringContextUtils.getHttpServletRequest().getAttribute(MENU_DATA_AUTHOR_RULE_SQL); |
||||
} |
||||
|
||||
/** |
||||
* 往链接请求里面,传入数据查询条件 |
||||
* |
||||
* @param request |
||||
* @param sql |
||||
*/ |
||||
public static synchronized void installDataSearchConditon(HttpServletRequest request, String sql) { |
||||
String ruleSql = (String) loadDataSearchConditonSqlString(); |
||||
if (!StringUtils.hasText(ruleSql)) { |
||||
request.setAttribute(MENU_DATA_AUTHOR_RULE_SQL, sql); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 将用户信息存到request |
||||
* |
||||
* @param request |
||||
* @param userinfo |
||||
*/ |
||||
public static synchronized void installUserInfo(HttpServletRequest request, SysUserCacheInfo userinfo) { |
||||
request.setAttribute(SYS_USER_INFO, userinfo); |
||||
} |
||||
|
||||
/** |
||||
* 将用户信息存到request |
||||
* |
||||
* @param userinfo |
||||
*/ |
||||
public static synchronized void installUserInfo(SysUserCacheInfo userinfo) { |
||||
SpringContextUtils.getHttpServletRequest().setAttribute(SYS_USER_INFO, userinfo); |
||||
} |
||||
|
||||
/** |
||||
* 从request获取用户信息 |
||||
* |
||||
* @return |
||||
*/ |
||||
public static synchronized SysUserCacheInfo loadUserInfo() { |
||||
return (SysUserCacheInfo) SpringContextUtils.getHttpServletRequest().getAttribute(SYS_USER_INFO); |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: 文档管理 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class ComboModel implements Serializable { |
||||
private String id; |
||||
private String title; |
||||
/** |
||||
* 文档管理 表单table默认选中 |
||||
*/ |
||||
private boolean checked; |
||||
/** |
||||
* 文档管理 表单table 用户账号 |
||||
*/ |
||||
private String username; |
||||
/** |
||||
* 文档管理 表单table 用户邮箱 |
||||
*/ |
||||
private String email; |
||||
/** |
||||
* 文档管理 表单table 角色编码 |
||||
*/ |
||||
private String roleCode; |
||||
|
||||
public ComboModel() { |
||||
|
||||
} |
||||
|
||||
; |
||||
|
||||
public ComboModel(String id, String title, boolean checked, String username) { |
||||
this.id = id; |
||||
this.title = title; |
||||
this.checked = false; |
||||
this.username = username; |
||||
} |
||||
|
||||
; |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: 字典类 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class DictModel implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
/** |
||||
* 字典value |
||||
*/ |
||||
private String value; |
||||
/** |
||||
* 字典文本 |
||||
*/ |
||||
private String text; |
||||
|
||||
public DictModel() { |
||||
} |
||||
public DictModel(String value, String text) { |
||||
this.value = value; |
||||
this.text = text; |
||||
} |
||||
|
||||
/** |
||||
* 特殊用途: JgEditableTable |
||||
* |
||||
* @return |
||||
*/ |
||||
public String getTitle() { |
||||
return this.text; |
||||
} |
||||
|
||||
/** |
||||
* 特殊用途: vue3 Select组件 |
||||
*/ |
||||
public String getLabel() { |
||||
return this.text; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
/** |
||||
* 查询多个字典时用到 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class DictModelMany extends DictModel { |
||||
|
||||
/** |
||||
* 字典code,根据多个字段code查询时才用到,用于区分不同的字典选项 |
||||
*/ |
||||
private String dictCode; |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 字典查询参数实体 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class DictQuery { |
||||
/** |
||||
* 表名 |
||||
*/ |
||||
private String table; |
||||
/** |
||||
* 存储列 |
||||
*/ |
||||
private String code; |
||||
|
||||
/** |
||||
* 显示列 |
||||
*/ |
||||
private String text; |
||||
|
||||
/** |
||||
* 关键字查询 |
||||
*/ |
||||
private String keyword; |
||||
|
||||
/** |
||||
* 存储列的值 用于回显查询 |
||||
*/ |
||||
private String codeValue; |
||||
|
||||
} |
||||
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.beans.BeanUtils; |
||||
|
||||
/** |
||||
* @Description: 数据源 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class DynamicDataSourceModel { |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 数据源编码 |
||||
*/ |
||||
private String code; |
||||
/** |
||||
* 数据库类型 |
||||
*/ |
||||
private String dbType; |
||||
/** |
||||
* 驱动类 |
||||
*/ |
||||
private String dbDriver; |
||||
/** |
||||
* 数据源地址 |
||||
*/ |
||||
private String dbUrl; |
||||
/** |
||||
* 用户名 |
||||
*/ |
||||
private String dbUsername; |
||||
/** |
||||
* 密码 |
||||
*/ |
||||
private String dbPassword; |
||||
|
||||
// /**
|
||||
// * 数据库名称
|
||||
// */
|
||||
// private java.lang.String dbName;
|
||||
|
||||
public DynamicDataSourceModel() { |
||||
|
||||
} |
||||
public DynamicDataSourceModel(Object dbSource) { |
||||
if (dbSource != null) { |
||||
BeanUtils.copyProperties(dbSource, this); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,132 @@
@@ -0,0 +1,132 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import cc.niushuai.bastionserver.common.desensitization.annotation.SensitiveField; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* <p> |
||||
* 在线用户信息 |
||||
* </p> |
||||
* |
||||
* @Author scott |
||||
* @since 2018-12-20 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
public class LoginUser { |
||||
|
||||
/** |
||||
* 登录人id |
||||
*/ |
||||
@SensitiveField |
||||
private String id; |
||||
|
||||
/** |
||||
* 登录人账号 |
||||
*/ |
||||
@SensitiveField |
||||
private String username; |
||||
|
||||
/** |
||||
* 登录人名字 |
||||
*/ |
||||
@SensitiveField |
||||
private String realname; |
||||
|
||||
/** |
||||
* 登录人密码 |
||||
*/ |
||||
@SensitiveField |
||||
private String password; |
||||
|
||||
/** |
||||
* 当前登录部门code |
||||
*/ |
||||
private String orgCode; |
||||
/** |
||||
* 头像 |
||||
*/ |
||||
@SensitiveField |
||||
private String avatar; |
||||
|
||||
/** |
||||
* 生日 |
||||
*/ |
||||
@SensitiveField |
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd") |
||||
private Date birthday; |
||||
|
||||
/** |
||||
* 性别(1:男 2:女) |
||||
*/ |
||||
private Integer sex; |
||||
|
||||
/** |
||||
* 电子邮件 |
||||
*/ |
||||
@SensitiveField |
||||
private String email; |
||||
|
||||
/** |
||||
* 电话 |
||||
*/ |
||||
@SensitiveField |
||||
private String phone; |
||||
|
||||
/** |
||||
* 状态(1:正常 2:冻结 ) |
||||
*/ |
||||
private Integer status; |
||||
|
||||
private Integer delFlag; |
||||
/** |
||||
* 同步工作流引擎1同步0不同步 |
||||
*/ |
||||
private Integer activitiSync; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 身份(1 普通员工 2 上级) |
||||
*/ |
||||
private Integer userIdentity; |
||||
|
||||
/** |
||||
* 管理部门ids |
||||
*/ |
||||
private String departIds; |
||||
|
||||
/** |
||||
* 职务,关联职务表 |
||||
*/ |
||||
@SensitiveField |
||||
private String post; |
||||
|
||||
/** |
||||
* 座机号 |
||||
*/ |
||||
@SensitiveField |
||||
private String telephone; |
||||
|
||||
/** |
||||
* 多租户id配置,编辑用户的时候设置 |
||||
*/ |
||||
private String relTenantIds; |
||||
|
||||
/** |
||||
* 设备id uniapp推送用 |
||||
*/ |
||||
private String clientId; |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 下拉树 model |
||||
* |
||||
* @author jeecg-boot |
||||
*/ |
||||
@Data |
||||
public class SelectTreeModel implements Serializable { |
||||
|
||||
private String key; |
||||
private String title; |
||||
private String value; |
||||
/** |
||||
* 父Id |
||||
*/ |
||||
private String parentId; |
||||
/** |
||||
* 是否是叶节点 |
||||
*/ |
||||
private boolean isLeaf; |
||||
/** |
||||
* 子节点 |
||||
*/ |
||||
private List<SelectTreeModel> children; |
||||
|
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
/** |
||||
* @Author qinfeng |
||||
* @Date 2020/2/19 12:01 |
||||
* @Description: |
||||
* @Version 1.0 |
||||
*/ |
||||
public class SysCategoryModel { |
||||
/** |
||||
* 主键 |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 父级节点 |
||||
*/ |
||||
private String pid; |
||||
/** |
||||
* 类型名称 |
||||
*/ |
||||
private String name; |
||||
/** |
||||
* 类型编码 |
||||
*/ |
||||
private String code; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getPid() { |
||||
return pid; |
||||
} |
||||
|
||||
public void setPid(String pid) { |
||||
this.pid = pid; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
} |
||||
@ -0,0 +1,177 @@
@@ -0,0 +1,177 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
/** |
||||
* 部门机构model |
||||
* |
||||
* @author: lvdandan |
||||
*/ |
||||
public class SysDepartModel { |
||||
/** |
||||
* ID |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 父机构ID |
||||
*/ |
||||
private String parentId; |
||||
/** |
||||
* 机构/部门名称 |
||||
*/ |
||||
private String departName; |
||||
/** |
||||
* 英文名 |
||||
*/ |
||||
private String departNameEn; |
||||
/** |
||||
* 缩写 |
||||
*/ |
||||
private String departNameAbbr; |
||||
/** |
||||
* 排序 |
||||
*/ |
||||
private Integer departOrder; |
||||
/** |
||||
* 描述 |
||||
*/ |
||||
private String description; |
||||
/** |
||||
* 机构类别 1组织机构,2岗位 |
||||
*/ |
||||
private String orgCategory; |
||||
/** |
||||
* 机构类型 |
||||
*/ |
||||
private String orgType; |
||||
/** |
||||
* 机构编码 |
||||
*/ |
||||
private String orgCode; |
||||
/** |
||||
* 手机号 |
||||
*/ |
||||
private String mobile; |
||||
/** |
||||
* 传真 |
||||
*/ |
||||
private String fax; |
||||
/** |
||||
* 地址 |
||||
*/ |
||||
private String address; |
||||
/** |
||||
* 备注 |
||||
*/ |
||||
private String memo; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getParentId() { |
||||
return parentId; |
||||
} |
||||
|
||||
public void setParentId(String parentId) { |
||||
this.parentId = parentId; |
||||
} |
||||
|
||||
public String getDepartName() { |
||||
return departName; |
||||
} |
||||
|
||||
public void setDepartName(String departName) { |
||||
this.departName = departName; |
||||
} |
||||
|
||||
public String getDepartNameEn() { |
||||
return departNameEn; |
||||
} |
||||
|
||||
public void setDepartNameEn(String departNameEn) { |
||||
this.departNameEn = departNameEn; |
||||
} |
||||
|
||||
public String getDepartNameAbbr() { |
||||
return departNameAbbr; |
||||
} |
||||
|
||||
public void setDepartNameAbbr(String departNameAbbr) { |
||||
this.departNameAbbr = departNameAbbr; |
||||
} |
||||
|
||||
public Integer getDepartOrder() { |
||||
return departOrder; |
||||
} |
||||
|
||||
public void setDepartOrder(Integer departOrder) { |
||||
this.departOrder = departOrder; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public String getOrgCategory() { |
||||
return orgCategory; |
||||
} |
||||
|
||||
public void setOrgCategory(String orgCategory) { |
||||
this.orgCategory = orgCategory; |
||||
} |
||||
|
||||
public String getOrgType() { |
||||
return orgType; |
||||
} |
||||
|
||||
public void setOrgType(String orgType) { |
||||
this.orgType = orgType; |
||||
} |
||||
|
||||
public String getOrgCode() { |
||||
return orgCode; |
||||
} |
||||
|
||||
public void setOrgCode(String orgCode) { |
||||
this.orgCode = orgCode; |
||||
} |
||||
|
||||
public String getMobile() { |
||||
return mobile; |
||||
} |
||||
|
||||
public void setMobile(String mobile) { |
||||
this.mobile = mobile; |
||||
} |
||||
|
||||
public String getFax() { |
||||
return fax; |
||||
} |
||||
|
||||
public void setFax(String fax) { |
||||
this.fax = fax; |
||||
} |
||||
|
||||
public String getAddress() { |
||||
return address; |
||||
} |
||||
|
||||
public void setAddress(String address) { |
||||
this.address = address; |
||||
} |
||||
|
||||
public String getMemo() { |
||||
return memo; |
||||
} |
||||
|
||||
public void setMemo(String memo) { |
||||
this.memo = memo; |
||||
} |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
|
||||
/** |
||||
* @Description: 系统文件实体类 |
||||
* @author: wangshuai |
||||
* @date: 2022年08月11日 9:48 |
||||
*/ |
||||
public class SysFilesModel { |
||||
/** |
||||
* 主键id |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 文件名称 |
||||
*/ |
||||
private String fileName; |
||||
/** |
||||
* 文件地址 |
||||
*/ |
||||
private String url; |
||||
/** |
||||
* 文档类型(folder:文件夹 excel:excel doc:word pp:ppt image:图片 archive:其他文档 video:视频) |
||||
*/ |
||||
private String fileType; |
||||
/** |
||||
* 文件上传类型(temp/本地上传(临时文件) manage/知识库) |
||||
*/ |
||||
private String storeType; |
||||
/** |
||||
* 文件大小(kb) |
||||
*/ |
||||
private Double fileSize; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getFileName() { |
||||
return fileName; |
||||
} |
||||
|
||||
public void setFileName(String fileName) { |
||||
this.fileName = fileName; |
||||
} |
||||
|
||||
public String getUrl() { |
||||
return url; |
||||
} |
||||
|
||||
public void setUrl(String url) { |
||||
this.url = url; |
||||
} |
||||
|
||||
public String getFileType() { |
||||
return fileType; |
||||
} |
||||
|
||||
public void setFileType(String fileType) { |
||||
this.fileType = fileType; |
||||
} |
||||
|
||||
public String getStoreType() { |
||||
return storeType; |
||||
} |
||||
|
||||
public void setStoreType(String storeType) { |
||||
this.storeType = storeType; |
||||
} |
||||
|
||||
public Double getFileSize() { |
||||
return fileSize; |
||||
} |
||||
|
||||
public void setFileSize(Double fileSize) { |
||||
this.fileSize = fileSize; |
||||
} |
||||
} |
||||
@ -0,0 +1,144 @@
@@ -0,0 +1,144 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限规则表 |
||||
* </p> |
||||
* |
||||
* @Author huangzhilin |
||||
* @since 2019-03-29 |
||||
*/ |
||||
public class SysPermissionDataRuleModel { |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
private String id; |
||||
|
||||
/** |
||||
* 对应的菜单id |
||||
*/ |
||||
private String permissionId; |
||||
|
||||
/** |
||||
* 规则名称 |
||||
*/ |
||||
private String ruleName; |
||||
|
||||
/** |
||||
* 字段 |
||||
*/ |
||||
private String ruleColumn; |
||||
|
||||
/** |
||||
* 条件 |
||||
*/ |
||||
private String ruleConditions; |
||||
|
||||
/** |
||||
* 规则值 |
||||
*/ |
||||
private String ruleValue; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 创建人 |
||||
*/ |
||||
private String createBy; |
||||
|
||||
/** |
||||
* 修改时间 |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
/** |
||||
* 修改人 |
||||
*/ |
||||
private String updateBy; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getPermissionId() { |
||||
return permissionId; |
||||
} |
||||
|
||||
public void setPermissionId(String permissionId) { |
||||
this.permissionId = permissionId; |
||||
} |
||||
|
||||
public String getRuleName() { |
||||
return ruleName; |
||||
} |
||||
|
||||
public void setRuleName(String ruleName) { |
||||
this.ruleName = ruleName; |
||||
} |
||||
|
||||
public String getRuleColumn() { |
||||
return ruleColumn; |
||||
} |
||||
|
||||
public void setRuleColumn(String ruleColumn) { |
||||
this.ruleColumn = ruleColumn; |
||||
} |
||||
|
||||
public String getRuleConditions() { |
||||
return ruleConditions; |
||||
} |
||||
|
||||
public void setRuleConditions(String ruleConditions) { |
||||
this.ruleConditions = ruleConditions; |
||||
} |
||||
|
||||
public String getRuleValue() { |
||||
return ruleValue; |
||||
} |
||||
|
||||
public void setRuleValue(String ruleValue) { |
||||
this.ruleValue = ruleValue; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
public String getCreateBy() { |
||||
return createBy; |
||||
} |
||||
|
||||
public void setCreateBy(String createBy) { |
||||
this.createBy = createBy; |
||||
} |
||||
|
||||
public Date getUpdateTime() { |
||||
return updateTime; |
||||
} |
||||
|
||||
public void setUpdateTime(Date updateTime) { |
||||
this.updateTime = updateTime; |
||||
} |
||||
|
||||
public String getUpdateBy() { |
||||
return updateBy; |
||||
} |
||||
|
||||
public void setUpdateBy(String updateBy) { |
||||
this.updateBy = updateBy; |
||||
} |
||||
} |
||||
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
package cc.niushuai.bastionserver.common.system.vo; |
||||
|
||||
import cc.niushuai.bastionserver.common.util.DateUtils; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Description: 用户缓存信息 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public class SysUserCacheInfo { |
||||
|
||||
private String sysUserCode; |
||||
|
||||
private String sysUserName; |
||||
|
||||
private String sysOrgCode; |
||||
|
||||
private List<String> sysMultiOrgCode; |
||||
|
||||
private boolean oneDepart; |
||||
|
||||
public boolean isOneDepart() { |
||||
return oneDepart; |
||||
} |
||||
|
||||
public void setOneDepart(boolean oneDepart) { |
||||
this.oneDepart = oneDepart; |
||||
} |
||||
|
||||
public String getSysDate() { |
||||
return DateUtils.formatDate(); |
||||
} |
||||
|
||||
public String getSysTime() { |
||||
return DateUtils.now(); |
||||
} |
||||
|
||||
public String getSysUserCode() { |
||||
return sysUserCode; |
||||
} |
||||
|
||||
public void setSysUserCode(String sysUserCode) { |
||||
this.sysUserCode = sysUserCode; |
||||
} |
||||
|
||||
public String getSysUserName() { |
||||
return sysUserName; |
||||
} |
||||
|
||||
public void setSysUserName(String sysUserName) { |
||||
this.sysUserName = sysUserName; |
||||
} |
||||
|
||||
public String getSysOrgCode() { |
||||
return sysOrgCode; |
||||
} |
||||
|
||||
public void setSysOrgCode(String sysOrgCode) { |
||||
this.sysOrgCode = sysOrgCode; |
||||
} |
||||
|
||||
public List<String> getSysMultiOrgCode() { |
||||
return sysMultiOrgCode; |
||||
} |
||||
|
||||
public void setSysMultiOrgCode(List<String> sysMultiOrgCode) { |
||||
this.sysMultiOrgCode = sysMultiOrgCode; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
/** |
||||
* @Author 张代浩 |
||||
*/ |
||||
public enum BrowserType { |
||||
/** |
||||
* 浏览类型 IE11,IE10,IE9,IE8,IE7,IE6,Firefox,Safari,Chrome,Opera,Camino,Gecko |
||||
*/ |
||||
IE11, IE10, IE9, IE8, IE7, IE6, Firefox, Safari, Chrome, Opera, Camino, Gecko |
||||
} |
||||
@ -0,0 +1,208 @@
@@ -0,0 +1,208 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* @Author 张代浩 |
||||
*/ |
||||
public class BrowserUtils { |
||||
|
||||
private final static String IE11 = "rv:11.0"; |
||||
private final static String IE10 = "MSIE 10.0"; |
||||
private final static String IE9 = "MSIE 9.0"; |
||||
private final static String IE8 = "MSIE 8.0"; |
||||
private final static String IE7 = "MSIE 7.0"; |
||||
private final static String IE6 = "MSIE 6.0"; |
||||
private final static String MAXTHON = "Maxthon"; |
||||
private final static String QQ = "QQBrowser"; |
||||
private final static String GREEN = "GreenBrowser"; |
||||
private final static String SE360 = "360SE"; |
||||
private final static String FIREFOX = "Firefox"; |
||||
private final static String OPERA = "Opera"; |
||||
private final static String CHROME = "Chrome"; |
||||
private final static String SAFARI = "Safari"; |
||||
private final static String OTHER = "其它"; |
||||
private final static String CAMINO = "Camino"; |
||||
private final static String ZH = "zh"; |
||||
private final static String ZH_CN = "zh-cn"; |
||||
private final static String EN = "en"; |
||||
private final static String EN_US = "en"; |
||||
private static Map<String, String> langMap = new HashMap<String, String>(); |
||||
|
||||
static { |
||||
langMap.put(ZH, ZH_CN); |
||||
langMap.put(EN, EN_US); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是IE |
||||
* |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
public static boolean isIe(HttpServletRequest request) { |
||||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request |
||||
.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true |
||||
: false; |
||||
} |
||||
|
||||
/** |
||||
* 获取IE版本 |
||||
* |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
public static Double getIeVersion(HttpServletRequest request) { |
||||
Double version = 0.0; |
||||
if (getBrowserType(request, IE11)) { |
||||
version = 11.0; |
||||
} else if (getBrowserType(request, IE10)) { |
||||
version = 10.0; |
||||
} else if (getBrowserType(request, IE9)) { |
||||
version = 9.0; |
||||
} else if (getBrowserType(request, IE8)) { |
||||
version = 8.0; |
||||
} else if (getBrowserType(request, IE7)) { |
||||
version = 7.0; |
||||
} else if (getBrowserType(request, IE6)) { |
||||
version = 6.0; |
||||
} |
||||
return version; |
||||
} |
||||
|
||||
/** |
||||
* 获取浏览器类型 |
||||
* |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
public static BrowserType getBrowserType(HttpServletRequest request) { |
||||
BrowserType browserType = null; |
||||
if (getBrowserType(request, IE11)) { |
||||
browserType = BrowserType.IE11; |
||||
} |
||||
if (getBrowserType(request, IE10)) { |
||||
browserType = BrowserType.IE10; |
||||
} |
||||
if (getBrowserType(request, IE9)) { |
||||
browserType = BrowserType.IE9; |
||||
} |
||||
if (getBrowserType(request, IE8)) { |
||||
browserType = BrowserType.IE8; |
||||
} |
||||
if (getBrowserType(request, IE7)) { |
||||
browserType = BrowserType.IE7; |
||||
} |
||||
if (getBrowserType(request, IE6)) { |
||||
browserType = BrowserType.IE6; |
||||
} |
||||
if (getBrowserType(request, FIREFOX)) { |
||||
browserType = BrowserType.Firefox; |
||||
} |
||||
if (getBrowserType(request, SAFARI)) { |
||||
browserType = BrowserType.Safari; |
||||
} |
||||
if (getBrowserType(request, CHROME)) { |
||||
browserType = BrowserType.Chrome; |
||||
} |
||||
if (getBrowserType(request, OPERA)) { |
||||
browserType = BrowserType.Opera; |
||||
} |
||||
if (getBrowserType(request, CAMINO)) { |
||||
browserType = BrowserType.Camino; |
||||
} |
||||
return browserType; |
||||
} |
||||
|
||||
private static boolean getBrowserType(HttpServletRequest request, |
||||
String brosertype) { |
||||
return request.getHeader("USER-AGENT").toLowerCase() |
||||
.indexOf(brosertype) > 0 ? true : false; |
||||
} |
||||
|
||||
public static String checkBrowse(HttpServletRequest request) { |
||||
String userAgent = request.getHeader("USER-AGENT"); |
||||
if (regex(OPERA, userAgent)) { |
||||
return OPERA; |
||||
} |
||||
if (regex(CHROME, userAgent)) { |
||||
return CHROME; |
||||
} |
||||
if (regex(FIREFOX, userAgent)) { |
||||
return FIREFOX; |
||||
} |
||||
if (regex(SAFARI, userAgent)) { |
||||
return SAFARI; |
||||
} |
||||
if (regex(SE360, userAgent)) { |
||||
return SE360; |
||||
} |
||||
if (regex(GREEN, userAgent)) { |
||||
return GREEN; |
||||
} |
||||
if (regex(QQ, userAgent)) { |
||||
return QQ; |
||||
} |
||||
if (regex(MAXTHON, userAgent)) { |
||||
return MAXTHON; |
||||
} |
||||
if (regex(IE11, userAgent)) { |
||||
return IE11; |
||||
} |
||||
if (regex(IE10, userAgent)) { |
||||
return IE10; |
||||
} |
||||
if (regex(IE9, userAgent)) { |
||||
return IE9; |
||||
} |
||||
if (regex(IE8, userAgent)) { |
||||
return IE8; |
||||
} |
||||
if (regex(IE7, userAgent)) { |
||||
return IE7; |
||||
} |
||||
if (regex(IE6, userAgent)) { |
||||
return IE6; |
||||
} |
||||
return OTHER; |
||||
} |
||||
|
||||
public static boolean regex(String regex, String str) { |
||||
Pattern p = Pattern.compile(regex, Pattern.MULTILINE); |
||||
Matcher m = p.matcher(str); |
||||
return m.find(); |
||||
} |
||||
|
||||
public static String getBrowserLanguage(HttpServletRequest request) { |
||||
|
||||
String browserLang = request.getLocale().getLanguage(); |
||||
String browserLangCode = (String) langMap.get(browserLang); |
||||
|
||||
if (browserLangCode == null) { |
||||
browserLangCode = EN_US; |
||||
} |
||||
return browserLangCode; |
||||
} |
||||
|
||||
/** |
||||
* 判断请求是否来自电脑端 |
||||
*/ |
||||
public static boolean isDesktop(HttpServletRequest request) { |
||||
return !isMobile(request); |
||||
} |
||||
|
||||
/** |
||||
* 判断请求是否来自移动端 |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest request) { |
||||
String ua = request.getHeader("User-Agent").toLowerCase(); |
||||
String type = "(phone|pad|pod|iphone|ipod|ios|ipad|android|mobile|blackberry|iemobile|mqqbrowser|juc|fennec|wosbrowser|browserng|webos|symbian|windows phone)"; |
||||
Pattern pattern = Pattern.compile(type); |
||||
return pattern.matcher(ua).find(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,367 @@
@@ -0,0 +1,367 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.constant.DataBaseConstant; |
||||
import cc.niushuai.bastionserver.common.constant.ServiceNameConstants; |
||||
import cc.niushuai.bastionserver.common.constant.SymbolConstant; |
||||
import cc.niushuai.bastionserver.common.util.filter.FileTypeFilter; |
||||
import cc.niushuai.bastionserver.common.util.oss.OssBootUtil; |
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; |
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; |
||||
import com.baomidou.mybatisplus.annotation.DbType; |
||||
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.jeecgframework.poi.util.PoiPublicUtil; |
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource; |
||||
import org.springframework.util.FileCopyUtils; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.sql.DataSource; |
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.sql.Connection; |
||||
import java.sql.DatabaseMetaData; |
||||
import java.sql.SQLException; |
||||
import java.util.Map; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* @Description: 通用工具 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Slf4j |
||||
public class CommonUtils { |
||||
|
||||
/** |
||||
* 中文正则 |
||||
*/ |
||||
private static Pattern ZHONGWEN_PATTERN = Pattern.compile("[\u4e00-\u9fa5]"); |
||||
|
||||
/** |
||||
* 文件名 正则字符串 |
||||
* 文件名支持的字符串:字母数字中文.-_()() 除此之外的字符将被删除 |
||||
*/ |
||||
private static String FILE_NAME_REGEX = "[^A-Za-z\\.\\(\\)\\-()\\_0-9\\u4e00-\\u9fa5]"; |
||||
/** |
||||
* 当前系统数据库类型 |
||||
*/ |
||||
private static String DB_TYPE = ""; |
||||
private static DbType dbTypeEnum = null; |
||||
|
||||
public static String uploadOnlineImage(byte[] data, String basePath, String bizPath, String uploadType) { |
||||
String dbPath = null; |
||||
String fileName = "image" + Math.round(Math.random() * 100000000000L); |
||||
fileName += "." + PoiPublicUtil.getFileExtendName(data); |
||||
try { |
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) { |
||||
File file = new File(basePath + File.separator + bizPath + File.separator); |
||||
if (!file.exists()) { |
||||
file.mkdirs();// 创建文件根目录
|
||||
} |
||||
String savePath = file.getPath() + File.separator + fileName; |
||||
File savefile = new File(savePath); |
||||
FileCopyUtils.copy(data, savefile); |
||||
dbPath = bizPath + File.separator + fileName; |
||||
} else { |
||||
InputStream in = new ByteArrayInputStream(data); |
||||
String relativePath = bizPath + "/" + fileName; |
||||
if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) { |
||||
dbPath = MinioUtil.upload(in, relativePath); |
||||
} else if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) { |
||||
dbPath = OssBootUtil.upload(in, relativePath); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return dbPath; |
||||
} |
||||
|
||||
/** |
||||
* 判断文件名是否带盘符,重新处理 |
||||
* |
||||
* @param fileName |
||||
* @return |
||||
*/ |
||||
public static String getFileName(String fileName) { |
||||
//判断是否带有盘符信息
|
||||
// Check for Unix-style path
|
||||
int unixSep = fileName.lastIndexOf('/'); |
||||
// Check for Windows-style path
|
||||
int winSep = fileName.lastIndexOf('\\'); |
||||
// Cut off at latest possible point
|
||||
int pos = (winSep > unixSep ? winSep : unixSep); |
||||
if (pos != -1) { |
||||
// Any sort of path separator found...
|
||||
fileName = fileName.substring(pos + 1); |
||||
} |
||||
//替换上传文件名字的特殊字符
|
||||
fileName = fileName.replace("=", "").replace(",", "").replace("&", "") |
||||
.replace("#", "").replace("“", "").replace("”", ""); |
||||
//替换上传文件名字中的空格
|
||||
fileName = fileName.replaceAll("\\s", ""); |
||||
//update-beign-author:taoyan date:20220302 for: /issues/3381 online 在线表单 使用文件组件时,上传文件名中含%,下载异常
|
||||
fileName = fileName.replaceAll(FILE_NAME_REGEX, ""); |
||||
//update-end-author:taoyan date:20220302 for: /issues/3381 online 在线表单 使用文件组件时,上传文件名中含%,下载异常
|
||||
return fileName; |
||||
} |
||||
|
||||
/** |
||||
* java 判断字符串里是否包含中文字符 |
||||
* |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static boolean ifContainChinese(String str) { |
||||
if (str.getBytes().length == str.length()) { |
||||
return false; |
||||
} else { |
||||
Matcher m = ZHONGWEN_PATTERN.matcher(str); |
||||
if (m.find()) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 统一全局上传 |
||||
* |
||||
* @Return: java.lang.String |
||||
*/ |
||||
public static String upload(MultipartFile file, String bizPath, String uploadType) { |
||||
String url = ""; |
||||
try { |
||||
if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) { |
||||
url = MinioUtil.upload(file, bizPath); |
||||
} else { |
||||
url = OssBootUtil.upload(file, bizPath); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 本地文件上传 |
||||
* |
||||
* @param mf 文件 |
||||
* @param bizPath 自定义路径 |
||||
* @return |
||||
*/ |
||||
public static String uploadLocal(MultipartFile mf, String bizPath, String uploadpath) { |
||||
try { |
||||
//update-begin-author:liusq date:20210809 for: 过滤上传文件类型
|
||||
FileTypeFilter.fileTypeFilter(mf); |
||||
//update-end-author:liusq date:20210809 for: 过滤上传文件类型
|
||||
String fileName = null; |
||||
File file = new File(uploadpath + File.separator + bizPath + File.separator); |
||||
if (!file.exists()) { |
||||
// 创建文件根目录
|
||||
file.mkdirs(); |
||||
} |
||||
// 获取文件名
|
||||
String orgName = mf.getOriginalFilename(); |
||||
orgName = CommonUtils.getFileName(orgName); |
||||
if (orgName.indexOf(SymbolConstant.SPOT) != -1) { |
||||
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); |
||||
} else { |
||||
fileName = orgName + "_" + System.currentTimeMillis(); |
||||
} |
||||
String savePath = file.getPath() + File.separator + fileName; |
||||
File savefile = new File(savePath); |
||||
FileCopyUtils.copy(mf.getBytes(), savefile); |
||||
String dbpath = null; |
||||
if (oConvertUtils.isNotEmpty(bizPath)) { |
||||
dbpath = bizPath + File.separator + fileName; |
||||
} else { |
||||
dbpath = fileName; |
||||
} |
||||
if (dbpath.contains(SymbolConstant.DOUBLE_BACKSLASH)) { |
||||
dbpath = dbpath.replace("\\", "/"); |
||||
} |
||||
return dbpath; |
||||
} catch (IOException e) { |
||||
log.error(e.getMessage(), e); |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 统一全局上传 带桶 |
||||
* |
||||
* @Return: java.lang.String |
||||
*/ |
||||
public static String upload(MultipartFile file, String bizPath, String uploadType, String customBucket) { |
||||
String url = ""; |
||||
try { |
||||
if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) { |
||||
url = MinioUtil.upload(file, bizPath, customBucket); |
||||
} else { |
||||
url = OssBootUtil.upload(file, bizPath, customBucket); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 全局获取平台数据库类型(作废了) |
||||
* |
||||
* @return |
||||
*/ |
||||
@Deprecated |
||||
public static String getDatabaseType() { |
||||
if (oConvertUtils.isNotEmpty(DB_TYPE)) { |
||||
return DB_TYPE; |
||||
} |
||||
DataSource dataSource = SpringContextUtils.getApplicationContext().getBean(DataSource.class); |
||||
try { |
||||
return getDatabaseTypeByDataSource(dataSource); |
||||
} catch (SQLException e) { |
||||
//e.printStackTrace();
|
||||
log.warn(e.getMessage(), e); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 全局获取平台数据库类型(对应mybaisPlus枚举) |
||||
* |
||||
* @return |
||||
*/ |
||||
public static DbType getDatabaseTypeEnum() { |
||||
if (oConvertUtils.isNotEmpty(dbTypeEnum)) { |
||||
return dbTypeEnum; |
||||
} |
||||
try { |
||||
DataSource dataSource = SpringContextUtils.getApplicationContext().getBean(DataSource.class); |
||||
dbTypeEnum = JdbcUtils.getDbType(dataSource.getConnection().getMetaData().getURL()); |
||||
return dbTypeEnum; |
||||
} catch (SQLException e) { |
||||
log.warn(e.getMessage(), e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据数据源key获取DataSourceProperty |
||||
* |
||||
* @param sourceKey |
||||
* @return |
||||
*/ |
||||
public static DataSourceProperty getDataSourceProperty(String sourceKey) { |
||||
DynamicDataSourceProperties prop = SpringContextUtils.getApplicationContext().getBean(DynamicDataSourceProperties.class); |
||||
Map<String, DataSourceProperty> map = prop.getDatasource(); |
||||
DataSourceProperty db = (DataSourceProperty) map.get(sourceKey); |
||||
return db; |
||||
} |
||||
|
||||
/** |
||||
* 根据sourceKey 获取数据源连接 |
||||
* |
||||
* @param sourceKey |
||||
* @return |
||||
* @throws SQLException |
||||
*/ |
||||
public static Connection getDataSourceConnect(String sourceKey) throws SQLException { |
||||
if (oConvertUtils.isEmpty(sourceKey)) { |
||||
sourceKey = "master"; |
||||
} |
||||
DynamicDataSourceProperties prop = SpringContextUtils.getApplicationContext().getBean(DynamicDataSourceProperties.class); |
||||
Map<String, DataSourceProperty> map = prop.getDatasource(); |
||||
DataSourceProperty db = (DataSourceProperty) map.get(sourceKey); |
||||
if (db == null) { |
||||
return null; |
||||
} |
||||
DriverManagerDataSource ds = new DriverManagerDataSource(); |
||||
ds.setDriverClassName(db.getDriverClassName()); |
||||
ds.setUrl(db.getUrl()); |
||||
ds.setUsername(db.getUsername()); |
||||
ds.setPassword(db.getPassword()); |
||||
return ds.getConnection(); |
||||
} |
||||
|
||||
/** |
||||
* 获取数据库类型 |
||||
* |
||||
* @param dataSource |
||||
* @return |
||||
* @throws SQLException |
||||
*/ |
||||
private static String getDatabaseTypeByDataSource(DataSource dataSource) throws SQLException { |
||||
if ("".equals(DB_TYPE)) { |
||||
Connection connection = dataSource.getConnection(); |
||||
try { |
||||
DatabaseMetaData md = connection.getMetaData(); |
||||
String dbType = md.getDatabaseProductName().toUpperCase(); |
||||
String sqlserver = "SQL SERVER"; |
||||
if (dbType.indexOf(DataBaseConstant.DB_TYPE_MYSQL) >= 0) { |
||||
DB_TYPE = DataBaseConstant.DB_TYPE_MYSQL; |
||||
} else if (dbType.indexOf(DataBaseConstant.DB_TYPE_ORACLE) >= 0 || dbType.indexOf(DataBaseConstant.DB_TYPE_DM) >= 0) { |
||||
DB_TYPE = DataBaseConstant.DB_TYPE_ORACLE; |
||||
} else if (dbType.indexOf(DataBaseConstant.DB_TYPE_SQLSERVER) >= 0 || dbType.indexOf(sqlserver) >= 0) { |
||||
DB_TYPE = DataBaseConstant.DB_TYPE_SQLSERVER; |
||||
} else if (dbType.indexOf(DataBaseConstant.DB_TYPE_POSTGRESQL) >= 0) { |
||||
DB_TYPE = DataBaseConstant.DB_TYPE_POSTGRESQL; |
||||
} else if (dbType.indexOf(DataBaseConstant.DB_TYPE_MARIADB) >= 0) { |
||||
DB_TYPE = DataBaseConstant.DB_TYPE_MARIADB; |
||||
} else { |
||||
log.error("数据库类型:[" + dbType + "]不识别!"); |
||||
//throw new BusinessException("数据库类型:["+dbType+"]不识别!");
|
||||
} |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
} finally { |
||||
connection.close(); |
||||
} |
||||
} |
||||
return DB_TYPE; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取服务器地址 |
||||
* |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
public static String getBaseUrl(HttpServletRequest request) { |
||||
//1.【兼容】兼容微服务下的 base path-------
|
||||
String xGatewayBasePath = request.getHeader(ServiceNameConstants.X_GATEWAY_BASE_PATH); |
||||
if (oConvertUtils.isNotEmpty(xGatewayBasePath)) { |
||||
log.info("x_gateway_base_path = " + xGatewayBasePath); |
||||
return xGatewayBasePath; |
||||
} |
||||
//2.【兼容】SSL认证之后,request.getScheme()获取不到https的问题
|
||||
// https://blog.csdn.net/weixin_34376986/article/details/89767950
|
||||
String scheme = request.getHeader(CommonConstant.X_FORWARDED_SCHEME); |
||||
if (oConvertUtils.isEmpty(scheme)) { |
||||
scheme = request.getScheme(); |
||||
} |
||||
|
||||
//3.常规操作
|
||||
String serverName = request.getServerName(); |
||||
int serverPort = request.getServerPort(); |
||||
String contextPath = request.getContextPath(); |
||||
|
||||
//返回 host domain
|
||||
String baseDomainPath = null; |
||||
int length = 80; |
||||
if (length == serverPort) { |
||||
baseDomainPath = scheme + "://" + serverName + contextPath; |
||||
} else { |
||||
baseDomainPath = scheme + "://" + serverName + ":" + serverPort + contextPath; |
||||
} |
||||
log.debug("-----Common getBaseUrl----- : " + baseDomainPath); |
||||
return baseDomainPath; |
||||
} |
||||
} |
||||
@ -0,0 +1,688 @@
@@ -0,0 +1,688 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.SymbolConstant; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import java.beans.PropertyEditorSupport; |
||||
import java.sql.Timestamp; |
||||
import java.text.DateFormat; |
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
import java.util.GregorianCalendar; |
||||
|
||||
/** |
||||
* 类描述:时间操作定义类 |
||||
* |
||||
* @Author: 张代浩 |
||||
* @Date:2012-12-8 12:15:03 |
||||
* @Version 1.0 |
||||
*/ |
||||
public class DateUtils extends PropertyEditorSupport { |
||||
|
||||
/** |
||||
* 以毫秒表示的时间 |
||||
*/ |
||||
private static final long DAY_IN_MILLIS = 24 * 3600 * 1000; |
||||
private static final long HOUR_IN_MILLIS = 3600 * 1000; |
||||
private static final long MINUTE_IN_MILLIS = 60 * 1000; |
||||
private static final long SECOND_IN_MILLIS = 1000; |
||||
public static ThreadLocal<SimpleDateFormat> date_sdf = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyy-MM-dd"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> yyyyMMdd = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyyMMdd"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> date_sdf_wz = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyy年MM月dd日"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> time_sdf = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> yyyymmddhhmmss = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyyMMddHHmmss"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> short_time_sdf = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("HH:mm"); |
||||
} |
||||
}; |
||||
public static ThreadLocal<SimpleDateFormat> datetimeFormat = new ThreadLocal<SimpleDateFormat>() { |
||||
@Override |
||||
protected SimpleDateFormat initialValue() { |
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 指定模式的时间格式 |
||||
* |
||||
* @param pattern |
||||
* @return |
||||
*/ |
||||
private static SimpleDateFormat getSdFormat(String pattern) { |
||||
return new SimpleDateFormat(pattern); |
||||
} |
||||
|
||||
/** |
||||
* 当前日历,这里用中国时间表示 |
||||
* |
||||
* @return 以当地时区表示的系统当前日历 |
||||
*/ |
||||
public static Calendar getCalendar() { |
||||
return Calendar.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数表示的日历 |
||||
* |
||||
* @param millis 毫秒数 |
||||
* @return 指定毫秒数表示的日历 |
||||
*/ |
||||
public static Calendar getCalendar(long millis) { |
||||
Calendar cal = Calendar.getInstance(); |
||||
// --------------------cal.setTimeInMillis(millis);
|
||||
cal.setTime(new Date(millis)); |
||||
return cal; |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// getDate
|
||||
// 各种方式获取的Date
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 当前日期 |
||||
* |
||||
* @return 系统当前时间 |
||||
*/ |
||||
public static Date getDate() { |
||||
return new Date(); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数表示的日期 |
||||
* |
||||
* @param millis 毫秒数 |
||||
* @return 指定毫秒数表示的日期 |
||||
*/ |
||||
public static Date getDate(long millis) { |
||||
return new Date(millis); |
||||
} |
||||
|
||||
/** |
||||
* 时间戳转换为字符串 |
||||
* |
||||
* @param time |
||||
* @return |
||||
*/ |
||||
public static String timestamptoStr(Timestamp time) { |
||||
Date date = null; |
||||
if (null != time) { |
||||
date = new Date(time.getTime()); |
||||
} |
||||
return date2Str(date_sdf.get()); |
||||
} |
||||
|
||||
/** |
||||
* 字符串转换时间戳 |
||||
* |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static Timestamp str2Timestamp(String str) { |
||||
Date date = str2Date(str, date_sdf.get()); |
||||
return new Timestamp(date.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 字符串转换成日期 |
||||
* |
||||
* @param str |
||||
* @param sdf |
||||
* @return |
||||
*/ |
||||
public static Date str2Date(String str, SimpleDateFormat sdf) { |
||||
if (null == str || "".equals(str)) { |
||||
return null; |
||||
} |
||||
Date date = null; |
||||
try { |
||||
date = sdf.parse(str); |
||||
return date; |
||||
} catch (ParseException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 日期转换为字符串 |
||||
* |
||||
* @param dateSdf 日期格式 |
||||
* @return 字符串 |
||||
*/ |
||||
public static String date2Str(SimpleDateFormat dateSdf) { |
||||
synchronized (dateSdf) { |
||||
Date date = getDate(); |
||||
if (null == date) { |
||||
return null; |
||||
} |
||||
return dateSdf.format(date); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 格式化时间 |
||||
* |
||||
* @param date |
||||
* @param format |
||||
* @return |
||||
*/ |
||||
public static String dateformat(String date, String format) { |
||||
SimpleDateFormat sformat = new SimpleDateFormat(format); |
||||
Date nowDate = null; |
||||
try { |
||||
nowDate = sformat.parse(date); |
||||
} catch (ParseException e) { |
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace(); |
||||
} |
||||
return sformat.format(nowDate); |
||||
} |
||||
|
||||
/** |
||||
* 日期转换为字符串 |
||||
* |
||||
* @param date 日期 |
||||
* @param dateSdf 日期格式 |
||||
* @return 字符串 |
||||
*/ |
||||
public static String date2Str(Date date, SimpleDateFormat dateSdf) { |
||||
synchronized (dateSdf) { |
||||
if (null == date) { |
||||
return null; |
||||
} |
||||
return dateSdf.format(date); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 日期转换为字符串 |
||||
* |
||||
* @param format 日期格式 |
||||
* @return 字符串 |
||||
*/ |
||||
public static String getDate(String format) { |
||||
Date date = new Date(); |
||||
if (null == date) { |
||||
return null; |
||||
} |
||||
SimpleDateFormat sdf = new SimpleDateFormat(format); |
||||
return sdf.format(date); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数的时间戳 |
||||
* |
||||
* @param millis 毫秒数 |
||||
* @return 指定毫秒数的时间戳 |
||||
*/ |
||||
public static Timestamp getTimestamp(long millis) { |
||||
return new Timestamp(millis); |
||||
} |
||||
|
||||
/** |
||||
* 以字符形式表示的时间戳 |
||||
* |
||||
* @param time 毫秒数 |
||||
* @return 以字符形式表示的时间戳 |
||||
*/ |
||||
public static Timestamp getTimestamp(String time) { |
||||
return new Timestamp(Long.parseLong(time)); |
||||
} |
||||
|
||||
/** |
||||
* 系统当前的时间戳 |
||||
* |
||||
* @return 系统当前的时间戳 |
||||
*/ |
||||
public static Timestamp getTimestamp() { |
||||
return new Timestamp(System.currentTimeMillis()); |
||||
} |
||||
|
||||
/** |
||||
* 当前时间,格式 yyyy-MM-dd HH:mm:ss |
||||
* |
||||
* @return 当前时间的标准形式字符串 |
||||
*/ |
||||
public static String now() { |
||||
return datetimeFormat.get().format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的时间戳 |
||||
* |
||||
* @param date 指定日期 |
||||
* @return 指定日期的时间戳 |
||||
*/ |
||||
public static Timestamp getTimestamp(Date date) { |
||||
return new Timestamp(date.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日历的时间戳 |
||||
* |
||||
* @param cal 指定日历 |
||||
* @return 指定日历的时间戳 |
||||
*/ |
||||
public static Timestamp getCalendarTimestamp(Calendar cal) { |
||||
// ---------------------return new Timestamp(cal.getTimeInMillis());
|
||||
return new Timestamp(cal.getTime().getTime()); |
||||
} |
||||
|
||||
public static Timestamp gettimestamp() { |
||||
Date dt = new Date(); |
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
String nowTime = df.format(dt); |
||||
Timestamp buydate = Timestamp.valueOf(nowTime); |
||||
return buydate; |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// getMillis
|
||||
// 各种方式获取的Millis
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 系统时间的毫秒数 |
||||
* |
||||
* @return 系统时间的毫秒数 |
||||
*/ |
||||
public static long getMillis() { |
||||
return System.currentTimeMillis(); |
||||
} |
||||
|
||||
/** |
||||
* 指定日历的毫秒数 |
||||
* |
||||
* @param cal 指定日历 |
||||
* @return 指定日历的毫秒数 |
||||
*/ |
||||
public static long getMillis(Calendar cal) { |
||||
// --------------------return cal.getTimeInMillis();
|
||||
return cal.getTime().getTime(); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的毫秒数 |
||||
* |
||||
* @param date 指定日期 |
||||
* @return 指定日期的毫秒数 |
||||
*/ |
||||
public static long getMillis(Date date) { |
||||
return date.getTime(); |
||||
} |
||||
|
||||
/** |
||||
* 指定时间戳的毫秒数 |
||||
* |
||||
* @param ts 指定时间戳 |
||||
* @return 指定时间戳的毫秒数 |
||||
*/ |
||||
public static long getMillis(Timestamp ts) { |
||||
return ts.getTime(); |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// formatDate
|
||||
// 将日期按照一定的格式转化为字符串
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 默认方式表示的系统当前日期,具体格式:年-月-日 |
||||
* |
||||
* @return 默认日期按“年-月-日“格式显示 |
||||
*/ |
||||
public static String formatDate() { |
||||
return date_sdf.get().format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 默认方式表示的系统当前日期,具体格式:yyyy-MM-dd HH:mm:ss |
||||
* |
||||
* @return 默认日期按“yyyy-MM-dd HH:mm:ss“格式显示 |
||||
*/ |
||||
public static String formatDateTime() { |
||||
return datetimeFormat.get().format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 获取时间字符串 |
||||
*/ |
||||
public static String getDataString(SimpleDateFormat formatstr) { |
||||
synchronized (formatstr) { |
||||
return formatstr.format(getCalendar().getTime()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:年-月-日 |
||||
* |
||||
* @param cal 指定的日期 |
||||
* @return 指定日期按“年-月-日“格式显示 |
||||
*/ |
||||
public static String formatDate(Calendar cal) { |
||||
return date_sdf.get().format(cal.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:年-月-日 |
||||
* |
||||
* @param date 指定的日期 |
||||
* @return 指定日期按“年-月-日“格式显示 |
||||
*/ |
||||
public static String formatDate(Date date) { |
||||
return date_sdf.get().format(date); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数表示日期的默认显示,具体格式:年-月-日 |
||||
* |
||||
* @param millis 指定的毫秒数 |
||||
* @return 指定毫秒数表示日期按“年-月-日“格式显示 |
||||
*/ |
||||
public static String formatDate(long millis) { |
||||
return date_sdf.get().format(new Date(millis)); |
||||
} |
||||
|
||||
/** |
||||
* 默认日期按指定格式显示 |
||||
* |
||||
* @param pattern 指定的格式 |
||||
* @return 默认日期按指定格式显示 |
||||
*/ |
||||
public static String formatDate(String pattern) { |
||||
return getSdFormat(pattern).format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期按指定格式显示 |
||||
* |
||||
* @param cal 指定的日期 |
||||
* @param pattern 指定的格式 |
||||
* @return 指定日期按指定格式显示 |
||||
*/ |
||||
public static String formatDate(Calendar cal, String pattern) { |
||||
return getSdFormat(pattern).format(cal.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期按指定格式显示 |
||||
* |
||||
* @param date 指定的日期 |
||||
* @param pattern 指定的格式 |
||||
* @return 指定日期按指定格式显示 |
||||
*/ |
||||
public static String formatDate(Date date, String pattern) { |
||||
return getSdFormat(pattern).format(date); |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// formatTime
|
||||
// 将日期按照一定的格式转化为字符串
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 默认方式表示的系统当前日期,具体格式:年-月-日 时:分 |
||||
* |
||||
* @return 默认日期按“年-月-日 时:分“格式显示 |
||||
*/ |
||||
public static String formatTime() { |
||||
return time_sdf.get().format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数表示日期的默认显示,具体格式:年-月-日 时:分 |
||||
* |
||||
* @param millis 指定的毫秒数 |
||||
* @return 指定毫秒数表示日期按“年-月-日 时:分“格式显示 |
||||
*/ |
||||
public static String formatTime(long millis) { |
||||
return time_sdf.get().format(new Date(millis)); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:年-月-日 时:分 |
||||
* |
||||
* @param cal 指定的日期 |
||||
* @return 指定日期按“年-月-日 时:分“格式显示 |
||||
*/ |
||||
public static String formatTime(Calendar cal) { |
||||
return time_sdf.get().format(cal.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:年-月-日 时:分 |
||||
* |
||||
* @param date 指定的日期 |
||||
* @return 指定日期按“年-月-日 时:分“格式显示 |
||||
*/ |
||||
public static String formatTime(Date date) { |
||||
return time_sdf.get().format(date); |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// formatShortTime
|
||||
// 将日期按照一定的格式转化为字符串
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 默认方式表示的系统当前日期,具体格式:时:分 |
||||
* |
||||
* @return 默认日期按“时:分“格式显示 |
||||
*/ |
||||
public static String formatShortTime() { |
||||
return short_time_sdf.get().format(getCalendar().getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定毫秒数表示日期的默认显示,具体格式:时:分 |
||||
* |
||||
* @param millis 指定的毫秒数 |
||||
* @return 指定毫秒数表示日期按“时:分“格式显示 |
||||
*/ |
||||
public static String formatShortTime(long millis) { |
||||
return short_time_sdf.get().format(new Date(millis)); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:时:分 |
||||
* |
||||
* @param cal 指定的日期 |
||||
* @return 指定日期按“时:分“格式显示 |
||||
*/ |
||||
public static String formatShortTime(Calendar cal) { |
||||
return short_time_sdf.get().format(cal.getTime()); |
||||
} |
||||
|
||||
/** |
||||
* 指定日期的默认显示,具体格式:时:分 |
||||
* |
||||
* @param date 指定的日期 |
||||
* @return 指定日期按“时:分“格式显示 |
||||
*/ |
||||
public static String formatShortTime(Date date) { |
||||
return short_time_sdf.get().format(date); |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// parseDate
|
||||
// parseCalendar
|
||||
// parseTimestamp
|
||||
// 将字符串按照一定的格式转化为日期或时间
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 根据指定的格式将字符串转换成Date 如输入:2003-11-19 11:20:20将按照这个转成时间 |
||||
* |
||||
* @param src 将要转换的原始字符窜 |
||||
* @param pattern 转换的匹配格式 |
||||
* @return 如果转换成功则返回转换后的日期 |
||||
* @throws ParseException |
||||
*/ |
||||
public static Date parseDate(String src, String pattern) throws ParseException { |
||||
return getSdFormat(pattern).parse(src); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 根据指定的格式将字符串转换成Date 如输入:2003-11-19 11:20:20将按照这个转成时间 |
||||
* |
||||
* @param src 将要转换的原始字符窜 |
||||
* @param pattern 转换的匹配格式 |
||||
* @return 如果转换成功则返回转换后的日期 |
||||
* @throws ParseException |
||||
*/ |
||||
public static Calendar parseCalendar(String src, String pattern) throws ParseException { |
||||
|
||||
Date date = parseDate(src, pattern); |
||||
Calendar cal = Calendar.getInstance(); |
||||
cal.setTime(date); |
||||
return cal; |
||||
} |
||||
|
||||
public static String formatAddDate(String src, String pattern, int amount) throws ParseException { |
||||
Calendar cal; |
||||
cal = parseCalendar(src, pattern); |
||||
cal.add(Calendar.DATE, amount); |
||||
return formatDate(cal); |
||||
} |
||||
|
||||
/** |
||||
* 根据指定的格式将字符串转换成Date 如输入:2003-11-19 11:20:20将按照这个转成时间 |
||||
* |
||||
* @param src 将要转换的原始字符窜 |
||||
* @param pattern 转换的匹配格式 |
||||
* @return 如果转换成功则返回转换后的时间戳 |
||||
* @throws ParseException |
||||
*/ |
||||
public static Timestamp parseTimestamp(String src, String pattern) throws ParseException { |
||||
Date date = parseDate(src, pattern); |
||||
return new Timestamp(date.getTime()); |
||||
} |
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// dateDiff
|
||||
// 计算两个日期之间的差值
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** |
||||
* 计算两个时间之间的差值,根据标志的不同而不同 |
||||
* |
||||
* @param flag 计算标志,表示按照年/月/日/时/分/秒等计算 |
||||
* @param calSrc 减数 |
||||
* @param calDes 被减数 |
||||
* @return 两个日期之间的差值 |
||||
*/ |
||||
public static int dateDiff(char flag, Calendar calSrc, Calendar calDes) { |
||||
|
||||
long millisDiff = getMillis(calSrc) - getMillis(calDes); |
||||
char year = 'y'; |
||||
char day = 'd'; |
||||
char hour = 'h'; |
||||
char minute = 'm'; |
||||
char second = 's'; |
||||
|
||||
if (flag == year) { |
||||
return (calSrc.get(Calendar.YEAR) - calDes.get(Calendar.YEAR)); |
||||
} |
||||
|
||||
if (flag == day) { |
||||
return (int) (millisDiff / DAY_IN_MILLIS); |
||||
} |
||||
|
||||
if (flag == hour) { |
||||
return (int) (millisDiff / HOUR_IN_MILLIS); |
||||
} |
||||
|
||||
if (flag == minute) { |
||||
return (int) (millisDiff / MINUTE_IN_MILLIS); |
||||
} |
||||
|
||||
if (flag == second) { |
||||
return (int) (millisDiff / SECOND_IN_MILLIS); |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
public static Long getCurrentTimestamp() { |
||||
return Long.valueOf(DateUtils.yyyymmddhhmmss.get().format(new Date())); |
||||
} |
||||
|
||||
public static int getYear() { |
||||
GregorianCalendar calendar = new GregorianCalendar(); |
||||
calendar.setTime(getDate()); |
||||
return calendar.get(Calendar.YEAR); |
||||
} |
||||
|
||||
/** |
||||
* 将字符串转成时间 |
||||
* |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static Date parseDatetime(String str) { |
||||
try { |
||||
return datetimeFormat.get().parse(str); |
||||
} catch (Exception e) { |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd |
||||
* HH:mm:ss“ * @param text String类型的时间值 |
||||
*/ |
||||
@Override |
||||
public void setAsText(String text) throws IllegalArgumentException { |
||||
if (StringUtils.hasText(text)) { |
||||
try { |
||||
int length10 = 10; |
||||
int length19 = 19; |
||||
if (text.indexOf(SymbolConstant.COLON) == -1 && text.length() == length10) { |
||||
setValue(DateUtils.date_sdf.get().parse(text)); |
||||
} else if (text.indexOf(SymbolConstant.COLON) > 0 && text.length() == length19) { |
||||
setValue(DateUtils.datetimeFormat.get().parse(text)); |
||||
} else { |
||||
throw new IllegalArgumentException("Could not parse date, date format is error "); |
||||
} |
||||
} catch (ParseException ex) { |
||||
IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage()); |
||||
iae.initCause(ex); |
||||
throw iae; |
||||
} |
||||
} else { |
||||
setValue(null); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
|
||||
/** |
||||
* @Description: 短信枚举类 |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public enum DySmsEnum { |
||||
|
||||
/** |
||||
* 登录短信模板编码 |
||||
*/ |
||||
LOGIN_TEMPLATE_CODE("SMS_175435174", "JEECG", "code"), |
||||
/** |
||||
* 忘记密码短信模板编码 |
||||
*/ |
||||
FORGET_PASSWORD_TEMPLATE_CODE("SMS_175435174", "JEECG", "code"), |
||||
/** |
||||
* 注册账号短信模板编码 |
||||
*/ |
||||
REGISTER_TEMPLATE_CODE("SMS_175430166", "JEECG", "code"), |
||||
/** |
||||
* 会议通知 |
||||
*/ |
||||
MEET_NOTICE_TEMPLATE_CODE("SMS_201480469", "H5活动之家", "username,title,minute,time"), |
||||
/** |
||||
* 我的计划通知 |
||||
*/ |
||||
PLAN_NOTICE_TEMPLATE_CODE("SMS_201470515", "H5活动之家", "username,title,time"); |
||||
|
||||
/** |
||||
* 短信模板编码 |
||||
*/ |
||||
private String templateCode; |
||||
/** |
||||
* 签名 |
||||
*/ |
||||
private String signName; |
||||
/** |
||||
* 短信模板必需的数据名称,多个key以逗号分隔,此处配置作为校验 |
||||
*/ |
||||
private String keys; |
||||
|
||||
private DySmsEnum(String templateCode, String signName, String keys) { |
||||
this.templateCode = templateCode; |
||||
this.signName = signName; |
||||
this.keys = keys; |
||||
} |
||||
|
||||
public static DySmsEnum toEnum(String templateCode) { |
||||
if (StrUtil.isEmpty(templateCode)) { |
||||
return null; |
||||
} |
||||
for (DySmsEnum item : DySmsEnum.values()) { |
||||
if (item.getTemplateCode().equals(templateCode)) { |
||||
return item; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getTemplateCode() { |
||||
return templateCode; |
||||
} |
||||
|
||||
public void setTemplateCode(String templateCode) { |
||||
this.templateCode = templateCode; |
||||
} |
||||
|
||||
public String getSignName() { |
||||
return signName; |
||||
} |
||||
|
||||
public void setSignName(String signName) { |
||||
this.signName = signName; |
||||
} |
||||
|
||||
public String getKeys() { |
||||
return keys; |
||||
} |
||||
|
||||
public void setKeys(String keys) { |
||||
this.keys = keys; |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.config.StaticConfig; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.aliyuncs.DefaultAcsClient; |
||||
import com.aliyuncs.IAcsClient; |
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; |
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; |
||||
import com.aliyuncs.exceptions.ClientException; |
||||
import com.aliyuncs.profile.DefaultProfile; |
||||
import com.aliyuncs.profile.IClientProfile; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* Created on 17/6/7. |
||||
* 短信API产品的DEMO程序,工程中包含了一个SmsDemo类,直接通过 |
||||
* 执行main函数即可体验短信产品API功能(只需要将AK替换成开通了云通信-短信产品功能的AK即可) |
||||
* 工程依赖了2个jar包(存放在工程的libs目录下) |
||||
* 1:aliyun-java-sdk-core.jar |
||||
* 2:aliyun-java-sdk-dysmsapi.jar |
||||
* <p> |
||||
* 备注:Demo工程编码采用UTF-8 |
||||
* 国际短信发送请勿参照此DEMO |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
public class DySmsHelper { |
||||
|
||||
/** |
||||
* 产品名称:云通信短信API产品,开发者无需替换 |
||||
*/ |
||||
static final String PRODUCT = "Dysmsapi"; |
||||
/** |
||||
* 产品域名,开发者无需替换 |
||||
*/ |
||||
static final String DOMAIN = "dysmsapi.aliyuncs.com"; |
||||
private final static Logger logger = LoggerFactory.getLogger(DySmsHelper.class); |
||||
/** |
||||
* TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找) |
||||
*/ |
||||
static String accessKeyId; |
||||
static String accessKeySecret; |
||||
|
||||
public static String getAccessKeyId() { |
||||
return accessKeyId; |
||||
} |
||||
|
||||
public static void setAccessKeyId(String accessKeyId) { |
||||
DySmsHelper.accessKeyId = accessKeyId; |
||||
} |
||||
|
||||
public static String getAccessKeySecret() { |
||||
return accessKeySecret; |
||||
} |
||||
|
||||
public static void setAccessKeySecret(String accessKeySecret) { |
||||
DySmsHelper.accessKeySecret = accessKeySecret; |
||||
} |
||||
|
||||
public static boolean sendSms(String phone, JSONObject templateParamJson, DySmsEnum dySmsEnum) throws ClientException { |
||||
//可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); |
||||
System.setProperty("sun.net.client.defaultReadTimeout", "10000"); |
||||
|
||||
//update-begin-author:taoyan date:20200811 for:配置类数据获取
|
||||
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class); |
||||
setAccessKeyId(staticConfig.getAccessKeyId()); |
||||
setAccessKeySecret(staticConfig.getAccessKeySecret()); |
||||
//update-end-author:taoyan date:20200811 for:配置类数据获取
|
||||
|
||||
//初始化acsClient,暂不支持region化
|
||||
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); |
||||
DefaultProfile.addEndpoint("cn-hangzhou", PRODUCT, "cn-hangzhou"); |
||||
// DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", PRODUCT, DOMAIN);
|
||||
IAcsClient acsClient = new DefaultAcsClient(profile); |
||||
|
||||
//验证json参数
|
||||
validateParam(templateParamJson, dySmsEnum); |
||||
|
||||
//组装请求对象-具体描述见控制台-文档部分内容
|
||||
SendSmsRequest request = new SendSmsRequest(); |
||||
//必填:待发送手机号
|
||||
request.setPhoneNumbers(phone); |
||||
//必填:短信签名-可在短信控制台中找到
|
||||
request.setSignName(dySmsEnum.getSignName()); |
||||
//必填:短信模板-可在短信控制台中找到
|
||||
request.setTemplateCode(dySmsEnum.getTemplateCode()); |
||||
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
||||
request.setTemplateParam(templateParamJson.toJSONString()); |
||||
|
||||
//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
|
||||
//request.setSmsUpExtendCode("90997");
|
||||
|
||||
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
|
||||
//request.setOutId("yourOutId");
|
||||
|
||||
boolean result = false; |
||||
|
||||
//hint 此处可能会抛出异常,注意catch
|
||||
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); |
||||
logger.info("短信接口返回的数据----------------"); |
||||
logger.info("{Code:" + sendSmsResponse.getCode() + ",Message:" + sendSmsResponse.getMessage() + ",RequestId:" + sendSmsResponse.getRequestId() + ",BizId:" + sendSmsResponse.getBizId() + "}"); |
||||
String ok = "OK"; |
||||
if (ok.equals(sendSmsResponse.getCode())) { |
||||
result = true; |
||||
} |
||||
return result; |
||||
|
||||
} |
||||
|
||||
private static void validateParam(JSONObject templateParamJson, DySmsEnum dySmsEnum) { |
||||
String keys = dySmsEnum.getKeys(); |
||||
String[] keyArr = keys.split(","); |
||||
for (String item : keyArr) { |
||||
if (!templateParamJson.containsKey(item)) { |
||||
throw new RuntimeException("模板缺少参数:" + item); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
// public static void main(String[] args) throws ClientException, InterruptedException {
|
||||
// JSONObject obj = new JSONObject();
|
||||
// obj.put("code", "1234");
|
||||
// sendSms("13800138000", obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);
|
||||
// }
|
||||
} |
||||
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.handler.IFillRuleHandler; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
|
||||
/** |
||||
* 规则值自动生成工具类 |
||||
* |
||||
* @author qinfeng |
||||
* @举例: 自动生成订单号;自动生成当前日期 |
||||
*/ |
||||
@Slf4j |
||||
public class FillRuleUtil { |
||||
|
||||
/** |
||||
* @param ruleCode ruleCode |
||||
* @return |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
public static Object executeRule(String ruleCode, JSONObject formData) { |
||||
if (!StrUtil.isEmpty(ruleCode)) { |
||||
try { |
||||
// 获取 Service
|
||||
ServiceImpl impl = (ServiceImpl) SpringContextUtils.getBean("sysFillRuleServiceImpl"); |
||||
// 根据 ruleCode 查询出实体
|
||||
QueryWrapper queryWrapper = new QueryWrapper(); |
||||
queryWrapper.eq("rule_code", ruleCode); |
||||
JSONObject entity = JSON.parseObject(JSON.toJSONString(impl.getOne(queryWrapper))); |
||||
if (entity == null) { |
||||
log.warn("填值规则:" + ruleCode + " 不存在"); |
||||
return null; |
||||
} |
||||
// 获取必要的参数
|
||||
String ruleClass = entity.getString("ruleClass"); |
||||
JSONObject params = entity.getJSONObject("ruleParams"); |
||||
if (params == null) { |
||||
params = new JSONObject(); |
||||
} |
||||
if (formData == null) { |
||||
formData = new JSONObject(); |
||||
} |
||||
// 通过反射执行配置的类里的方法
|
||||
IFillRuleHandler ruleHandler = (IFillRuleHandler) Class.forName(ruleClass).newInstance(); |
||||
return ruleHandler.execute(params, formData); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import org.pegdown.PegDownProcessor; |
||||
import org.springframework.web.util.HtmlUtils; |
||||
|
||||
/** |
||||
* HTML 工具类 |
||||
* |
||||
* @author: jeecg-boot |
||||
* @date: 2022/3/30 14:43 |
||||
*/ |
||||
@SuppressWarnings("AlibabaClassNamingShouldBeCamel") |
||||
public class HTMLUtils { |
||||
|
||||
/** |
||||
* 获取HTML内的文本,不包含标签 |
||||
* |
||||
* @param html HTML 代码 |
||||
*/ |
||||
public static String getInnerText(String html) { |
||||
if (StrUtil.isNotBlank(html)) { |
||||
//去掉 html 的标签
|
||||
String content = html.replaceAll("</?[^>]+>", ""); |
||||
// 将多个空格合并成一个空格
|
||||
content = content.replaceAll("( )+", " "); |
||||
// 反向转义字符
|
||||
content = HtmlUtils.htmlUnescape(content); |
||||
return content.trim(); |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 将Markdown解析成Html |
||||
* |
||||
* @param markdownContent |
||||
* @return |
||||
*/ |
||||
public static String parseMarkdown(String markdownContent) { |
||||
PegDownProcessor pdp = new PegDownProcessor(); |
||||
return pdp.markdownToHtml(markdownContent); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 导出返回信息 |
||||
* |
||||
* @author: jeecg-boot |
||||
*/ |
||||
@Slf4j |
||||
public class ImportExcelUtil { |
||||
|
||||
public static Result<?> imporReturnRes(int errorLines, int successLines, List<String> errorMessage) throws IOException { |
||||
if (errorLines == 0) { |
||||
return Result.ok("共" + successLines + "行数据全部导入成功!"); |
||||
} else { |
||||
JSONObject result = new JSONObject(5); |
||||
int totalCount = successLines + errorLines; |
||||
result.put("totalCount", totalCount); |
||||
result.put("errorCount", errorLines); |
||||
result.put("successCount", successLines); |
||||
result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + successLines + ",错误行数:" + errorLines); |
||||
String fileUrl = PmsUtil.saveErrorTxtByList(errorMessage, "userImportExcelErrorLog"); |
||||
int lastIndex = fileUrl.lastIndexOf(File.separator); |
||||
String fileName = fileUrl.substring(lastIndex + 1); |
||||
result.put("fileUrl", "/sys/common/static/" + fileUrl); |
||||
result.put("fileName", fileName); |
||||
Result res = Result.ok(result); |
||||
res.setCode(201); |
||||
res.setMessage("文件导入成功,但有错误。"); |
||||
return res; |
||||
} |
||||
} |
||||
|
||||
public static List<String> importDateSave(List<?> list, Class serviceClass, List<String> errorMessage, String errorFlag) { |
||||
IService bean = (IService) SpringContextUtils.getBean(serviceClass); |
||||
for (int i = 0; i < list.size(); i++) { |
||||
try { |
||||
boolean save = bean.save(list.get(i)); |
||||
if (!save) { |
||||
throw new Exception(errorFlag); |
||||
} |
||||
} catch (Exception e) { |
||||
String message = e.getMessage().toLowerCase(); |
||||
int lineNumber = i + 1; |
||||
// 通过索引名判断出错信息
|
||||
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:角色编码已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:任务类名已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:职务编码已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:部门编码已经存在,忽略导入。"); |
||||
} else { |
||||
errorMessage.add("第 " + lineNumber + " 行:未知错误,忽略导入"); |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
return errorMessage; |
||||
} |
||||
|
||||
public static List<String> importDateSaveOne(Object obj, Class serviceClass, List<String> errorMessage, int i, String errorFlag) { |
||||
IService bean = (IService) SpringContextUtils.getBean(serviceClass); |
||||
try { |
||||
boolean save = bean.save(obj); |
||||
if (!save) { |
||||
throw new Exception(errorFlag); |
||||
} |
||||
} catch (Exception e) { |
||||
String message = e.getMessage().toLowerCase(); |
||||
int lineNumber = i + 1; |
||||
// 通过索引名判断出错信息
|
||||
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:角色编码已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:任务类名已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:职务编码已经存在,忽略导入。"); |
||||
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE)) { |
||||
errorMessage.add("第 " + lineNumber + " 行:部门编码已经存在,忽略导入。"); |
||||
} else { |
||||
errorMessage.add("第 " + lineNumber + " 行:未知错误,忽略导入"); |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
return errorMessage; |
||||
} |
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* IP地址 |
||||
* |
||||
* @Author scott |
||||
* @email jeecgos@163.com |
||||
* @Date 2019年01月14日 |
||||
*/ |
||||
public class IpUtils { |
||||
private static Logger logger = LoggerFactory.getLogger(IpUtils.class); |
||||
|
||||
/** |
||||
* 获取IP地址 |
||||
* <p> |
||||
* 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址 |
||||
* 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址 |
||||
*/ |
||||
public static String getIpAddr(HttpServletRequest request) { |
||||
String ip = null; |
||||
try { |
||||
ip = request.getHeader("x-forwarded-for"); |
||||
if (StrUtil.isEmpty(ip) || CommonConstant.UNKNOWN.equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("Proxy-Client-IP"); |
||||
} |
||||
if (StrUtil.isEmpty(ip) || ip.length() == 0 || CommonConstant.UNKNOWN.equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
if (StrUtil.isEmpty(ip) || CommonConstant.UNKNOWN.equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
if (StrUtil.isEmpty(ip) || CommonConstant.UNKNOWN.equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
if (StrUtil.isEmpty(ip) || CommonConstant.UNKNOWN.equalsIgnoreCase(ip)) { |
||||
ip = request.getRemoteAddr(); |
||||
} |
||||
} catch (Exception e) { |
||||
logger.error("IPUtils ERROR ", e); |
||||
} |
||||
|
||||
// //使用代理,则获取第一个IP地址
|
||||
// if(StrUtil.isEmpty(ip) && ip.length() > 15) {
|
||||
// if(ip.indexOf(",") > 0) {
|
||||
// ip = ip.substring(0, ip.indexOf(","));
|
||||
// }
|
||||
// }
|
||||
|
||||
return ip; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,256 @@
@@ -0,0 +1,256 @@
|
||||
package cc.niushuai.bastionserver.common.util; |
||||
|
||||
import cc.niushuai.bastionserver.common.api.vo.Result; |
||||
import cc.niushuai.bastionserver.common.constant.CommonConstant; |
||||
import cc.niushuai.bastionserver.common.constant.DataBaseConstant; |
||||
import cc.niushuai.bastionserver.common.constant.SymbolConstant; |
||||
import cc.niushuai.bastionserver.common.exception.BusinessException; |
||||
import cc.niushuai.bastionserver.common.system.util.JeecgDataAutorUtils; |
||||
import cc.niushuai.bastionserver.common.system.vo.LoginUser; |
||||
import cc.niushuai.bastionserver.common.system.vo.SysUserCacheInfo; |
||||
import com.auth0.jwt.JWT; |
||||
import com.auth0.jwt.JWTVerifier; |
||||
import com.auth0.jwt.algorithms.Algorithm; |
||||
import com.auth0.jwt.exceptions.JWTDecodeException; |
||||
import com.auth0.jwt.interfaces.DecodedJWT; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.google.common.base.Joiner; |
||||
import org.apache.shiro.SecurityUtils; |
||||
|
||||
import javax.servlet.ServletResponse; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @Author Scott |
||||
* @Date 2018-07-12 14:23 |
||||
* @Desc JWT工具类 |
||||
**/ |
||||
public class JwtUtil { |
||||
|
||||
/** |
||||
* Token有效期为1小时(Token在reids中缓存时间为两倍) |
||||
*/ |
||||
public static final long EXPIRE_TIME = 60 * 60 * 1000; |
||||
static final String WELL_NUMBER = SymbolConstant.WELL_NUMBER + SymbolConstant.LEFT_CURLY_BRACKET; |
||||
|
||||
/** |
||||
* @param response |
||||
* @param code |
||||
* @param errorMsg |
||||
*/ |
||||
public static void responseError(ServletResponse response, Integer code, String errorMsg) { |
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response; |
||||
// issues/I4YH95浏览器显示乱码问题
|
||||
httpServletResponse.setHeader("Content-type", "text/html;charset=UTF-8"); |
||||
Result jsonResult = new Result(code, errorMsg); |
||||
OutputStream os = null; |
||||
try { |
||||
os = httpServletResponse.getOutputStream(); |
||||
httpServletResponse.setCharacterEncoding("UTF-8"); |
||||
httpServletResponse.setStatus(code); |
||||
os.write(new ObjectMapper().writeValueAsString(jsonResult).getBytes("UTF-8")); |
||||
os.flush(); |
||||
os.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 校验token是否正确 |
||||
* |
||||
* @param token 密钥 |
||||
* @param secret 用户的密码 |
||||
* @return 是否正确 |
||||
*/ |
||||
public static boolean verify(String token, String username, String secret) { |
||||
try { |
||||
// 根据密码生成JWT效验器
|
||||
Algorithm algorithm = Algorithm.HMAC256(secret); |
||||
JWTVerifier verifier = JWT.require(algorithm).withClaim("username", username).build(); |
||||
// 效验TOKEN
|
||||
DecodedJWT jwt = verifier.verify(token); |
||||
return true; |
||||
} catch (Exception exception) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获得token中的信息无需secret解密也能获得 |
||||
* |
||||
* @return token中包含的用户名 |
||||
*/ |
||||
public static String getUsername(String token) { |
||||
try { |
||||
DecodedJWT jwt = JWT.decode(token); |
||||
return jwt.getClaim("username").asString(); |
||||
} catch (JWTDecodeException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 生成签名,5min后过期 |
||||
* |
||||
* @param username 用户名 |
||||
* @param secret 用户的密码 |
||||
* @return 加密的token |
||||
*/ |
||||
public static String sign(String username, String secret) { |
||||
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); |
||||
Algorithm algorithm = Algorithm.HMAC256(secret); |
||||
// 附带username信息
|
||||
return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 根据request中的token获取用户账号 |
||||
* |
||||
* @param request |
||||
* @return |
||||
* @throws BusinessException |
||||
*/ |
||||
public static String getUserNameByToken(HttpServletRequest request) throws BusinessException { |
||||
String accessToken = request.getHeader("X-Access-Token"); |
||||
String username = getUsername(accessToken); |
||||
if (oConvertUtils.isEmpty(username)) { |
||||
throw new BusinessException("未获取到用户"); |
||||
} |
||||
return username; |
||||
} |
||||
|
||||
/** |
||||
* 从session中获取变量 |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
public static String getSessionData(String key) { |
||||
//${myVar}%
|
||||
//得到${} 后面的值
|
||||
String moshi = ""; |
||||
String wellNumber = WELL_NUMBER; |
||||
|
||||
if (key.indexOf(SymbolConstant.RIGHT_CURLY_BRACKET) != -1) { |
||||
moshi = key.substring(key.indexOf("}") + 1); |
||||
} |
||||
String returnValue = null; |
||||
if (key.contains(wellNumber)) { |
||||
key = key.substring(2, key.indexOf("}")); |
||||
} |
||||
if (oConvertUtils.isNotEmpty(key)) { |
||||
HttpSession session = SpringContextUtils.getHttpServletRequest().getSession(); |
||||
returnValue = (String) session.getAttribute(key); |
||||
} |
||||
//结果加上${} 后面的值
|
||||
if (returnValue != null) { |
||||
returnValue = returnValue + moshi; |
||||
} |
||||
return returnValue; |
||||
} |
||||
|
||||
/** |
||||
* 从当前用户中获取变量 |
||||
* |
||||
* @param key |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static String getUserSystemData(String key, SysUserCacheInfo user) { |
||||
if (user == null) { |
||||
user = JeecgDataAutorUtils.loadUserInfo(); |
||||
} |
||||
//#{sys_user_code}%
|
||||
|
||||
// 获取登录用户信息
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
||||
|
||||
String moshi = ""; |
||||
String wellNumber = WELL_NUMBER; |
||||
if (key.indexOf(SymbolConstant.RIGHT_CURLY_BRACKET) != -1) { |
||||
moshi = key.substring(key.indexOf("}") + 1); |
||||
} |
||||
String returnValue = null; |
||||
//针对特殊标示处理#{sysOrgCode},判断替换
|
||||
if (key.contains(wellNumber)) { |
||||
key = key.substring(2, key.indexOf("}")); |
||||
} else { |
||||
key = key; |
||||
} |
||||
//替换为系统登录用户帐号
|
||||
if (key.equals(DataBaseConstant.SYS_USER_CODE) || key.toLowerCase().equals(DataBaseConstant.SYS_USER_CODE_TABLE)) { |
||||
if (user == null) { |
||||
returnValue = sysUser.getUsername(); |
||||
} else { |
||||
returnValue = user.getSysUserCode(); |
||||
} |
||||
} |
||||
//替换为系统登录用户真实名字
|
||||
else if (key.equals(DataBaseConstant.SYS_USER_NAME) || key.toLowerCase().equals(DataBaseConstant.SYS_USER_NAME_TABLE)) { |
||||
if (user == null) { |
||||
returnValue = sysUser.getRealname(); |
||||
} else { |
||||
returnValue = user.getSysUserName(); |
||||
} |
||||
} |
||||
|
||||
//替换为系统用户登录所使用的机构编码
|
||||
else if (key.equals(DataBaseConstant.SYS_ORG_CODE) || key.toLowerCase().equals(DataBaseConstant.SYS_ORG_CODE_TABLE)) { |
||||
if (user == null) { |
||||
returnValue = sysUser.getOrgCode(); |
||||
} else { |
||||
returnValue = user.getSysOrgCode(); |
||||
} |
||||
} |
||||
//替换为系统用户所拥有的所有机构编码
|
||||
else if (key.equals(DataBaseConstant.SYS_MULTI_ORG_CODE) || key.toLowerCase().equals(DataBaseConstant.SYS_MULTI_ORG_CODE_TABLE)) { |
||||
if (user == null) { |
||||
//TODO 暂时使用用户登录部门,存在逻辑缺陷,不是用户所拥有的部门
|
||||
returnValue = sysUser.getOrgCode(); |
||||
} else { |
||||
if (user.isOneDepart()) { |
||||
returnValue = user.getSysMultiOrgCode().get(0); |
||||
} else { |
||||
returnValue = Joiner.on(",").join(user.getSysMultiOrgCode()); |
||||
} |
||||
} |
||||
} |
||||
//替换为当前系统时间(年月日)
|
||||
else if (key.equals(DataBaseConstant.SYS_DATE) || key.toLowerCase().equals(DataBaseConstant.SYS_DATE_TABLE)) { |
||||
returnValue = DateUtils.formatDate(); |
||||
} |
||||
//替换为当前系统时间(年月日时分秒)
|
||||
else if (key.equals(DataBaseConstant.SYS_TIME) || key.toLowerCase().equals(DataBaseConstant.SYS_TIME_TABLE)) { |
||||
returnValue = DateUtils.now(); |
||||
} |
||||
//流程状态默认值(默认未发起)
|
||||
else if (key.equals(DataBaseConstant.BPM_STATUS) || key.toLowerCase().equals(DataBaseConstant.BPM_STATUS_TABLE)) { |
||||
returnValue = "1"; |
||||
} |
||||
//update-begin-author:taoyan date:20210330 for:多租户ID作为系统变量
|
||||
else if (key.equals(DataBaseConstant.TENANT_ID) || key.toLowerCase().equals(DataBaseConstant.TENANT_ID_TABLE)) { |
||||
returnValue = sysUser.getRelTenantIds(); |
||||
boolean flag = returnValue != null && returnValue.indexOf(SymbolConstant.COMMA) > 0; |
||||
if (oConvertUtils.isEmpty(returnValue) || flag) { |
||||
returnValue = SpringContextUtils.getHttpServletRequest().getHeader(CommonConstant.TENANT_ID); |
||||
} |
||||
} |
||||
//update-end-author:taoyan date:20210330 for:多租户ID作为系统变量
|
||||
if (returnValue != null) { |
||||
returnValue = returnValue + moshi; |
||||
} |
||||
return returnValue; |
||||
} |
||||
|
||||
// public static void main(String[] args) {
|
||||
// String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NjUzMzY1MTMsInVzZXJuYW1lIjoiYWRtaW4ifQ.xjhud_tWCNYBOg_aRlMgOdlZoWFFKB_givNElHNw3X0";
|
||||
// System.out.println(JwtUtil.getUsername(token));
|
||||
// }
|
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue