commit
a700a45b2b
138 changed files with 8952 additions and 0 deletions
@ -0,0 +1,45 @@ |
||||
# ---> Java |
||||
# Compiled class file |
||||
*.class |
||||
|
||||
# Log file |
||||
*.log |
||||
|
||||
# BlueJ files |
||||
*.ctxt |
||||
|
||||
# Mobile Tools for Java (J2ME) |
||||
.mtj.tmp/ |
||||
|
||||
# Package Files # |
||||
*.jar |
||||
*.war |
||||
*.nar |
||||
*.ear |
||||
*.zip |
||||
*.tar.gz |
||||
*.rar |
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml |
||||
hs_err_pid* |
||||
replay_pid* |
||||
|
||||
# ---> Maven |
||||
target/ |
||||
pom.xml.tag |
||||
pom.xml.releaseBackup |
||||
pom.xml.versionsBackup |
||||
pom.xml.next |
||||
release.properties |
||||
dependency-reduced-pom.xml |
||||
buildNumber.properties |
||||
.mvn/timing.properties |
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar |
||||
.mvn/wrapper/maven-wrapper.jar |
||||
|
||||
# Eclipse m2e generated files |
||||
# Eclipse Core |
||||
.project |
||||
# JDT-specific (Eclipse Java Development Tools) |
||||
.classpath |
||||
|
@ -0,0 +1,13 @@ |
||||
# 基础镜像 |
||||
FROM openjdk:8-jre |
||||
# author |
||||
MAINTAINER cheney |
||||
# 复制jar文件到路径 |
||||
ADD manager.jar manager.jar |
||||
# 时间 |
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
||||
RUN echo 'Asia/Shanghai' >/etc/timezone |
||||
# 启动服务 |
||||
ENTRYPOINT ["java","-jar","/manager.jar"] |
||||
# 暴露端口 |
||||
EXPOSE 8080 |
@ -0,0 +1,73 @@ |
||||
Apache License |
||||
Version 2.0, January 2004 |
||||
http://www.apache.org/licenses/ |
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
||||
1. Definitions. |
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. |
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. |
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. |
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. |
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. |
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). |
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. |
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." |
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. |
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. |
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. |
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: |
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and |
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and |
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and |
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. |
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. |
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. |
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. |
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. |
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. |
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
APPENDIX: How to apply the Apache License to your work. |
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. |
||||
|
||||
Copyright [yyyy] [name of copyright owner] |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
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. |
@ -0,0 +1,78 @@ |
||||
<<<<<<< HEAD |
||||
# IASF |
||||
|
||||
粒子研究院网站 |
||||
======= |
||||
#IASF 粒子研究院网站 |
||||
|
||||
## 代码结构 |
||||
``` |
||||
├─main |
||||
│ ├─java |
||||
│ │ └─com |
||||
│ │ └─company |
||||
│ │ └─project |
||||
│ │ ├─CompanyProjectApplication.java 项目启动类 |
||||
│ │ ├─common 公共资源,如注解、切面、定时、全局异常处理、shiro集成、通用工具类等 |
||||
│ │ ├─controller Controler层 |
||||
│ │ ├─entity 实体类 |
||||
│ │ ├─mapper DAO层 |
||||
│ │ ├─service Service层 |
||||
│ │ │ └─impl Service层实现 |
||||
│ └─resources |
||||
│ ├── application-dev.yml 开发环境配置文件 |
||||
│ ├── application-test.yml 测试环境配置文件 |
||||
│ ├── application-prod.yml 生产环境配置文件 |
||||
│ ├── application.yml 通用配置文件 |
||||
│ ├── logback-spring.xml 日志配置文件 |
||||
│ └──mapper Mybatis XML文件 |
||||
└─test |
||||
└─java |
||||
└─com |
||||
└─company |
||||
└─project |
||||
├── CompanyFrameApplicationTests.java 单元测试 |
||||
``` |
||||
|
||||
## 开发建议 |
||||
- Model内成员变量建议与表字段数量对应,如需扩展成员变量(比如连表查询)建议创建VO,否则需在扩展的成员变量上加@TableField(exist = false) |
||||
- 建议业务失败直接使用throw new BusinessException("ErrorMessage")抛出,由统一异常处理器来封装业务失败的响应结果,会直接被封装为{"code":500002,"message":"ErrorMessage"}返回,尽情抛出; |
||||
- token支持header跟query传参形式,如: |
||||
- ajax中设置header:```beforeSend: function(request) {request.setRequestHeader("authorization", "有效的token");}``` |
||||
- query:```?authorization=有效的token ``` |
||||
- 数据库基础字段:id(bigint)、remark(varchar)、unable_flag(tinyint)、deleted(tinyint)、create_id(bigint)、update_id(bigint)、create_time(datetime)、update_time(datetime) |
||||
|
||||
## 使用说明 |
||||
- 使用IDE导入本项目,IDE需要安装lombok插件 |
||||
- 下载redis 启动redis |
||||
- 创建数据库, 导入***.sql |
||||
- 配置application-dev.yml中的redis以及数据库连接 |
||||
- 运行项目 |
||||
1. 直接运行CompanyProjectApplication.java |
||||
2. 项目根目录下执行mvn -X clean package -Dmaven.test.skip=true编译打包,然后执行java -jar manager.jar |
||||
- 登录地址 http://localhost:8080/index/login 用户名密码:admin/123456 |
||||
- 代码生成使用 |
||||
1. 逻辑删除字段,请统一用deleted字段: 1未删 0已删; 主键请统一格式: `id` varchar(50) 类型; 列名请勿使用数据库关键字 |
||||
2. application.yml中配置: 使用代码生成模块时 指定要生成的表存在于哪种数据库。project.database=mysql |
||||
3. 点击[代码生成]菜单,生成一个或多个表的代码,下载到本地 |
||||
4. 解压下载的代码,直接复制main文件夹到本地项目的src目录下 |
||||
5. 数据库执行sql,生成菜单 |
||||
6. 点击[角色管理]菜单,修改角色所绑定的菜单的权限,刷新页面查看 |
||||
|
||||
- 数据权限配置及使用 示例:文章管理列表 |
||||
1. 需要数据权限所控制的表(如sys_content), 需要有创建人字段 |
||||
2. 配置角色的数据范围(本部门,其他部门等), 以及绑定的部门 |
||||
3. 在列表加个注解@DataScope(用来查询当前等路人的多个角色(并集), 根据角色数据范围, 获取绑定的部门id, 查关联的用户id) |
||||
4. 在查某个模块的list或page的时候,手动queryWrapper.in(createId, 关联的用户id) |
||||
|
||||
|
||||
## 技术文档 |
||||
* 核心框架:[Spring Boot](https://spring.io/projects/spring-boot) |
||||
* 持久层框架:[MyBatis-Plus](https://mybatis.plus) |
||||
* 分页:[Page](https://mybatis.plus/guide/page.html) |
||||
* 数据库连接池:[Alibaba Druid](https://github.com/alibaba/druid/) |
||||
* 安全框架:[Apache Shiro](http://shiro.apache.org/) |
||||
* 缓存框架:[Redis](https://redis.io/) |
||||
* 接口文档:[Knife4j](https://doc.xiaominfo.com/) |
||||
* 阿里巴巴Java开发手册[最新版下载](https://github.com/alibaba/p3c) |
||||
>>>>>>> 粒子研究院网站提交 |
@ -0,0 +1,225 @@ |
||||
<?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.1.6.RELEASE</version> |
||||
<relativePath/> <!-- lookup parent from repository --> |
||||
</parent> |
||||
|
||||
<groupId>com.huoran</groupId> |
||||
<artifactId>iasf</artifactId> |
||||
<version>1.0.0</version> |
||||
<name>IASF</name> |
||||
<packaging>jar</packaging> |
||||
<description>粒子研究院网站</description> |
||||
|
||||
<properties> |
||||
<java.version>1.8</java.version> |
||||
<mybatis-plus.version>3.4.0</mybatis-plus.version> |
||||
<mybatis-plus-dynamic.version>2.5.5</mybatis-plus-dynamic.version> |
||||
<commons.lang.version>2.6</commons.lang.version> |
||||
<commons.io.version>2.5</commons.io.version> |
||||
<commons.configuration.version>1.10</commons.configuration.version> |
||||
<velocity.version>1.7</velocity.version> |
||||
<quartz.version>2.3.2</quartz.version> |
||||
<shiro.version>1.4.0</shiro.version> |
||||
<druid.version>1.1.10</druid.version> |
||||
<fastjson.version>1.2.74</fastjson.version> |
||||
<knife4j.version>2.0.2</knife4j.version> |
||||
<easy-captcha.version>1.6.2</easy-captcha.version> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-aop</artifactId> |
||||
</dependency> |
||||
|
||||
<!--数据源--> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid-spring-boot-starter</artifactId> |
||||
<version>${druid.version}</version> |
||||
</dependency> |
||||
<!--redis 依赖--> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
</dependency> |
||||
|
||||
<!--shiro 依赖--> |
||||
<dependency> |
||||
<groupId>org.apache.shiro</groupId> |
||||
<artifactId>shiro-spring</artifactId> |
||||
<version>${shiro.version}</version> |
||||
</dependency> |
||||
<!--lombok--> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</dependency> |
||||
<!--fastJson--> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>${fastjson.version}</version> |
||||
</dependency> |
||||
<!--数据库持久化 及 插件依赖--> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
||||
<version>${mybatis-plus-dynamic.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus</artifactId> |
||||
<version>${mybatis-plus.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>${mybatis-plus.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>mysql</groupId> |
||||
<artifactId>mysql-connector-java</artifactId> |
||||
<scope>runtime</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.xiaoymin</groupId> |
||||
<artifactId>knife4j-spring-boot-starter</artifactId> |
||||
<version>${knife4j.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-lang</groupId> |
||||
<artifactId>commons-lang</artifactId> |
||||
<version>${commons.lang.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
<version>${commons.io.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-configuration</groupId> |
||||
<artifactId>commons-configuration</artifactId> |
||||
<version>${commons.configuration.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<artifactId>velocity</artifactId> |
||||
<groupId>org.apache.velocity</groupId> |
||||
<version>${velocity.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.quartz-scheduler</groupId> |
||||
<artifactId>quartz</artifactId> |
||||
<version>${quartz.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.mchange</groupId> |
||||
<artifactId>c3p0</artifactId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<groupId>com.zaxxer</groupId> |
||||
<artifactId>HikariCP-java6</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.whvcse</groupId> |
||||
<artifactId>easy-captcha</artifactId> |
||||
<version>${easy-captcha.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-codec</groupId> |
||||
<artifactId>commons-codec</artifactId> |
||||
<version>1.13</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>io.jsonwebtoken</groupId> |
||||
<artifactId>jjwt</artifactId> |
||||
<version>0.9.0</version> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> |
||||
<dependency> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
<artifactId>okhttp</artifactId> |
||||
<version>3.14.9</version> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
|
||||
<build> |
||||
<finalName>iasf</finalName> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<fork>true</fork> |
||||
</configuration> |
||||
</plugin> |
||||
|
||||
<!--添加配置跳过测试--> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<version>2.22.2</version> |
||||
<configuration> |
||||
<skipTests>true</skipTests> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
|
||||
<resources> |
||||
<resource> |
||||
<!-- 描述存放资源的目录,该路径相对POM路径--> |
||||
<directory>src/main/java</directory> |
||||
<includes> |
||||
<include>**/*.xml</include> |
||||
</includes> |
||||
</resource> |
||||
<resource> |
||||
<directory>src/main/resources</directory> |
||||
<includes> |
||||
<include>**/*</include> |
||||
</includes> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
|
||||
<repositories> |
||||
<repository> |
||||
<id>aliyun-repos</id> |
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> |
||||
<snapshots> |
||||
<enabled>false</enabled> |
||||
</snapshots> |
||||
</repository> |
||||
</repositories> |
||||
|
||||
<pluginRepositories> |
||||
<pluginRepository> |
||||
<id>aliyun-plugin</id> |
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> |
||||
<snapshots> |
||||
<enabled>false</enabled> |
||||
</snapshots> |
||||
</pluginRepository> |
||||
</pluginRepositories> |
||||
</project> |
@ -0,0 +1,33 @@ |
||||
package com.huoran.iasf; |
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.ServletComponentScan; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
import java.net.InetAddress; |
||||
|
||||
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) |
||||
@MapperScan("com.huoran.iasf.mapper") |
||||
@Slf4j |
||||
@ServletComponentScan(basePackages = {"com.huoran.iasf.common.filter"}) //这一句完成了配置,Springboot的”懒理念“真的厉害。
|
||||
public class IASFApplication { |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
ConfigurableApplicationContext application = SpringApplication.run(IASFApplication.class, args); |
||||
|
||||
Environment env = application.getEnvironment(); |
||||
log.info("\n----------------------------------------------------------\n\t" + |
||||
"Application '{}' is running! Access URLs:\n\t" + |
||||
"Doc: \thttp://{}:{}/iasf/doc.html\n" + |
||||
"----------------------------------------------------------", |
||||
env.getProperty("spring.application.name"), |
||||
InetAddress.getLocalHost().getHostAddress(), |
||||
env.getProperty("server.port")); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.huoran.iasf.common.aop.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* LogAnnotation |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface DataScope { |
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.huoran.iasf.common.aop.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* LogAnnotation |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface LogAnnotation { |
||||
/** |
||||
* 模块 |
||||
*/ |
||||
String title() default ""; |
||||
|
||||
/** |
||||
* 功能 |
||||
*/ |
||||
String action() default ""; |
||||
} |
@ -0,0 +1,135 @@ |
||||
package com.huoran.iasf.common.aop.aspect; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Before; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* 概念:最终控制列表中显示哪些 部门/人 创建的数据 |
||||
* 1、需要数据权限控制的列表, 需要有创建人字段, 示例:文章管理 |
||||
* 2、配置角色的数据范围(本部门,其他部门等), 以及绑定的部门 |
||||
* 3、加个注解,用来查询当前等路人的多个角色(并集), 根据角色数据范围, 获取绑定的部门id, 查关联的用户id |
||||
* 4、在查某个模块的list或page的时候,手动queryWrapper.in(createId, 关联的用户id) |
||||
* |
||||
* @author cheney |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
public class DataScopeAspect { |
||||
|
||||
@Resource |
||||
HttpSessionService sessionService; |
||||
@Resource |
||||
com.huoran.iasf.service.RoleService roleService; |
||||
@Resource |
||||
com.huoran.iasf.service.SysRoleDeptService sysRoleDeptService; |
||||
@Resource |
||||
com.huoran.iasf.service.DeptService deptService; |
||||
@Resource |
||||
com.huoran.iasf.service.UserService userService; |
||||
|
||||
|
||||
@Pointcut("@annotation(com.huoran.iasf.common.aop.annotation.DataScope)") |
||||
public void dataScopePointCut() { |
||||
} |
||||
|
||||
@Before("dataScopePointCut()") |
||||
public void doBefore(JoinPoint point) { |
||||
handleDataScope(point); |
||||
} |
||||
|
||||
protected void handleDataScope(final JoinPoint joinPoint) { |
||||
//获取当前登陆人
|
||||
String id = sessionService.getCurrentUserId(); |
||||
//获取当前登陆人角色, 如果无角色, 那么不限制
|
||||
List<SysRole> sysRoles = roleService.getRoleInfoByUserId(id); |
||||
if (CollectionUtils.isEmpty(sysRoles) || sysRoles.size() == 0) { |
||||
return; |
||||
} |
||||
//角色未配置数据权限范围, 那么不限制
|
||||
List<SysRole> list = sysRoles.parallelStream().filter(one -> null != one.getDataScope()).collect(Collectors.toList()); |
||||
if (CollectionUtils.isEmpty(list) || list.size() == 0) { |
||||
return; |
||||
} |
||||
//如果存在某角色配置了全部范围, 那么不限制
|
||||
if (list.stream().anyMatch(sysRole -> Constant.DATA_SCOPE_ALL.equals(sysRole.getDataScope()))) { |
||||
return; |
||||
} |
||||
//获取绑定的人
|
||||
List<String> userIds = this.getUserIdsByRoles(list, id); |
||||
Object params = joinPoint.getArgs()[0]; |
||||
if (params instanceof com.huoran.iasf.entity.BaseEntity) { |
||||
com.huoran.iasf.entity.BaseEntity baseEntity = (com.huoran.iasf.entity.BaseEntity) params; |
||||
baseEntity.setCreateIds(userIds); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取最终的用户id |
||||
* |
||||
* @param sysRoles 角色 |
||||
* @param userId 当前用户id |
||||
* @return 用户id集合 |
||||
*/ |
||||
private List<String> getUserIdsByRoles(List<com.huoran.iasf.entity.SysRole> sysRoles, String userId) { |
||||
//本人
|
||||
com.huoran.iasf.entity.SysUser sysUser = userService.getById(userId); |
||||
//本部门
|
||||
com.huoran.iasf.entity.SysDept sysDept = deptService.getById(sysUser.getDeptId()); |
||||
//部门ids, 定义哪些部门最终拥有权限查看
|
||||
LinkedList<Object> deptList = new LinkedList<>(); |
||||
//用户ids,定义列表中哪些人创建的可查看
|
||||
LinkedList<Object> userIdList = new LinkedList<>(); |
||||
//根据数据权限范围分组, 不同的数据范围不同的逻辑处理
|
||||
Map<Integer, List<com.huoran.iasf.entity.SysRole>> dataScopeMap = sysRoles.parallelStream().collect(Collectors.groupingBy(com.huoran.iasf.entity.SysRole::getDataScope)); |
||||
dataScopeMap.forEach((k, v) -> { |
||||
if (Constant.DATA_SCOPE_CUSTOM.equals(k)) { |
||||
//自定义
|
||||
//根据角色id,获取所有自定义关联的部门id
|
||||
QueryWrapper<com.huoran.iasf.entity.SysRoleDeptEntity> queryWrapper = Wrappers.<com.huoran.iasf.entity.SysRoleDeptEntity>query().select("dept_id").in("role_id", v.parallelStream().map(com.huoran.iasf.entity.SysRole::getId).collect(Collectors.toList())); |
||||
deptList.addAll(sysRoleDeptService.listObjs(queryWrapper)); |
||||
} else if (Constant.DATA_SCOPE_DEPT_AND_CHILD.equals(k)) { |
||||
//本部门及以下
|
||||
if (sysDept != null && StringUtils.isNotBlank(sysDept.getDeptNo())) { |
||||
//获取本部门以下所有关联的部门
|
||||
QueryWrapper<com.huoran.iasf.entity.SysDept> queryWrapper = Wrappers.<com.huoran.iasf.entity.SysDept>query().select("id").like("relation_code", sysDept.getDeptNo()); |
||||
deptList.addAll(deptService.listObjs(queryWrapper)); |
||||
} |
||||
} else if (Constant.DATA_SCOPE_DEPT.equals(k)) { |
||||
//本部门
|
||||
if (sysDept != null && StringUtils.isNotBlank(sysDept.getId())) { |
||||
deptList.add(sysDept.getId()); |
||||
} |
||||
} else if (Constant.DATA_SCOPE_DEPT_SELF.equals(k)) { |
||||
//自己
|
||||
userIdList.add(userId); |
||||
} |
||||
}); |
||||
if (!CollectionUtils.isEmpty(deptList)) { |
||||
QueryWrapper<com.huoran.iasf.entity.SysUser> queryWrapper = Wrappers.<com.huoran.iasf.entity.SysUser>query().select("id").in("dept_id", deptList); |
||||
userIdList.addAll(userService.listObjs(queryWrapper)); |
||||
} |
||||
//如果配置了角色数据范围, 最终没有查到userId, 那么返回无数据
|
||||
if (CollectionUtils.isEmpty(userIdList)) { |
||||
throw new BusinessException("无数据"); |
||||
} |
||||
return userIdList.parallelStream().map(Object::toString).collect(Collectors.toList()); |
||||
} |
||||
} |
@ -0,0 +1,118 @@ |
||||
package com.huoran.iasf.common.aop.aspect; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.HttpContextUtils; |
||||
import com.huoran.iasf.common.utils.IPUtils; |
||||
import com.huoran.iasf.entity.SysLog; |
||||
import com.huoran.iasf.mapper.SysLogMapper; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
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.context.annotation.Lazy; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* 日志切面 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
@Slf4j |
||||
public class SysLogAspect { |
||||
@Lazy |
||||
@Resource |
||||
private SysLogMapper sysLogMapper; |
||||
|
||||
@Lazy |
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
|
||||
/** |
||||
* 此处的切点是注解的方式 |
||||
* 只要出现 @LogAnnotation注解都会进入 |
||||
*/ |
||||
@Pointcut("@annotation(com.huoran.iasf.common.aop.annotation.LogAnnotation)") |
||||
public void logPointCut() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 环绕增强,相当于MethodInterceptor |
||||
*/ |
||||
@Around("logPointCut()") |
||||
public Object around(ProceedingJoinPoint point) throws Throwable { |
||||
long beginTime = System.currentTimeMillis(); |
||||
//执行方法
|
||||
Object result = point.proceed(); |
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime; |
||||
|
||||
//保存日志
|
||||
try { |
||||
saveSysLog(point, time); |
||||
} catch (Exception e) { |
||||
log.error("sysLog,exception:{}", e, e); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 把日志保存 |
||||
*/ |
||||
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) { |
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
|
||||
SysLog sysLog = new SysLog(); |
||||
LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class); |
||||
if (logAnnotation != null) { |
||||
//注解上的描述
|
||||
sysLog.setOperation(logAnnotation.title() + "-" + logAnnotation.action()); |
||||
} |
||||
|
||||
//请求的方法名
|
||||
String className = joinPoint.getTarget().getClass().getName(); |
||||
String methodName = signature.getName(); |
||||
sysLog.setMethod(className + "." + methodName + "()"); |
||||
log.info("请求{}.{}耗时{}毫秒", className, methodName, time); |
||||
try { |
||||
//请求的参数
|
||||
Object[] args = joinPoint.getArgs(); |
||||
String params = null; |
||||
if (args.length != 0) { |
||||
params = JSON.toJSONString(args); |
||||
} |
||||
|
||||
sysLog.setParams(params); |
||||
} catch (Exception e) { |
||||
log.error("sysLog,exception:{}", e, e); |
||||
} |
||||
//获取request
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); |
||||
//设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request)); |
||||
log.info("Ip{},接口地址{},请求方式{},入参:{}", sysLog.getIp(), request.getRequestURL(), request.getMethod(), sysLog.getParams()); |
||||
//用户名
|
||||
String userId = httpSessionService.getCurrentUserId(); |
||||
String username = httpSessionService.getCurrentUsername(); |
||||
sysLog.setUsername(username); |
||||
sysLog.setUserId(userId); |
||||
sysLog.setTime((int) time); |
||||
log.info(sysLog.toString()); |
||||
sysLogMapper.insert(sysLog); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* 文件上传参数配置类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Component |
||||
@ConfigurationProperties(prefix = "file") |
||||
public class FileUploadProperties { |
||||
|
||||
private String path; |
||||
private String url; |
||||
private String accessUrl; |
||||
|
||||
|
||||
public String getPath() { |
||||
return path; |
||||
} |
||||
|
||||
public void setPath(String path) { |
||||
this.path = path; |
||||
} |
||||
|
||||
public String getUrl() { |
||||
return url; |
||||
} |
||||
|
||||
public void setUrl(String url) { |
||||
this.url = url; |
||||
|
||||
//set accessUrl
|
||||
if (StringUtils.isEmpty(url)) { |
||||
this.accessUrl = null; |
||||
} |
||||
this.accessUrl = url.substring(url.lastIndexOf("/")) + "/**"; |
||||
System.out.println("accessUrl=" + accessUrl); |
||||
} |
||||
|
||||
public String getAccessUrl() { |
||||
return accessUrl; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,85 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import org.apache.ibatis.reflection.MetaObject; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Arrays; |
||||
import java.util.Date; |
||||
import java.util.HashSet; |
||||
|
||||
|
||||
/** |
||||
* mybatis plus 默认值配置 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Component |
||||
public class MetaObjectHandlerConfig implements MetaObjectHandler { |
||||
|
||||
@Lazy |
||||
@Resource |
||||
HttpSessionService httpSessionService; |
||||
|
||||
@Override |
||||
public void insertFill(MetaObject metaObject) { |
||||
Date currentDate = new Date(); |
||||
String[] setterNames = metaObject.getSetterNames(); |
||||
HashSet<String> setterNameSet = new HashSet<>(Arrays.asList(setterNames)); |
||||
if (setterNameSet.contains("deleted")) { |
||||
//默认未删除
|
||||
setFieldValByName("deleted", Constant.DATA_NOT_DELETED, metaObject); |
||||
} |
||||
if (setterNameSet.contains("createTime")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("createTime", currentDate, metaObject); |
||||
} |
||||
if (setterNameSet.contains("createDate")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("createDate", currentDate, metaObject); |
||||
} |
||||
// if (setterNameSet.contains("createId")) {
|
||||
// //创建时间默认当前时间
|
||||
// setFieldValByName("createId", httpSessionService.getCurrentUserId(), metaObject);
|
||||
// }
|
||||
// if (setterNameSet.contains("updateId")) {
|
||||
// //创建时间默认当前时间
|
||||
// setFieldValByName("updateId", httpSessionService.getCurrentUserId(), metaObject);
|
||||
// }
|
||||
if (setterNameSet.contains("updateTime")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("updateTime", currentDate, metaObject); |
||||
} |
||||
if (setterNameSet.contains("updateDate")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("updateDate", currentDate, metaObject); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void updateFill(MetaObject metaObject) { |
||||
Date currentDate = new Date(); |
||||
String[] setterNames = metaObject.getSetterNames(); |
||||
HashSet<String> setterNameSet = new HashSet<>(Arrays.asList(setterNames)); |
||||
if (setterNameSet.contains("updateTime")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("updateTime", currentDate, metaObject); |
||||
} |
||||
if (setterNameSet.contains("updateDate")) { |
||||
//创建时间默认当前时间
|
||||
setFieldValByName("updateDate", currentDate, metaObject); |
||||
} |
||||
// if (setterNameSet.contains("updateId")) {
|
||||
// //创建时间默认当前时间
|
||||
// setFieldValByName("updateId", httpSessionService.getCurrentUserId(), metaObject);
|
||||
// }
|
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* mybatis plus config |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Configuration |
||||
public class MyBatisPlusConfig { |
||||
/** |
||||
* 配置mybatis-plus 分页查件 |
||||
*/ |
||||
@Bean |
||||
public PaginationInterceptor paginationInterceptor() { |
||||
return new PaginationInterceptor(); |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Import; |
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; |
||||
import springfox.documentation.builders.ApiInfoBuilder; |
||||
import springfox.documentation.builders.PathSelectors; |
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
import springfox.documentation.service.ApiInfo; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spring.web.plugins.Docket; |
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
||||
|
||||
/** |
||||
* SwaggerConfiguration |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Configuration |
||||
@EnableSwagger2 |
||||
@EnableKnife4j |
||||
@Import(BeanValidatorPluginsConfiguration.class) |
||||
public class SwaggerConfiguration { |
||||
|
||||
@Bean |
||||
public Docket createRestApi() { |
||||
return new Docket(DocumentationType.SWAGGER_2) |
||||
.apiInfo(apiInfo()) |
||||
.select() |
||||
.apis(RequestHandlerSelectors.basePackage("com.huoran.iasf.controller")) |
||||
.paths(PathSelectors.any()) |
||||
.build(); |
||||
} |
||||
|
||||
private ApiInfo apiInfo() { |
||||
return new ApiInfoBuilder() |
||||
.title("IASF APIs") |
||||
.description("粒子研究院 APIs") |
||||
.termsOfServiceUrl("http://localhost:10000/") |
||||
.version("V1.0") |
||||
.build(); |
||||
} |
||||
} |
@ -0,0 +1,140 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig; |
||||
import com.alibaba.fastjson.serializer.SerializerFeature; |
||||
import com.alibaba.fastjson.serializer.ToStringSerializer; |
||||
import com.alibaba.fastjson.serializer.ValueFilter; |
||||
import com.alibaba.fastjson.support.config.FastJsonConfig; |
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; |
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter; |
||||
import org.springframework.http.converter.HttpMessageConverter; |
||||
import org.springframework.http.converter.ResourceHttpMessageConverter; |
||||
import org.springframework.http.converter.StringHttpMessageConverter; |
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; |
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; |
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigInteger; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* spring mvc 配置 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Configuration |
||||
@EnableConfigurationProperties(FileUploadProperties.class) |
||||
public class WebMvcConfigurer extends WebMvcConfigurationSupport { |
||||
|
||||
@Resource |
||||
private FileUploadProperties fileUploadProperties; |
||||
|
||||
|
||||
/** |
||||
* 使用阿里 FastJson 作为JSON MessageConverter |
||||
*/ |
||||
@Override |
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
||||
converters.add(new ByteArrayHttpMessageConverter()); |
||||
converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));// @ResponseBody 解决乱码
|
||||
converters.add(new ResourceHttpMessageConverter()); |
||||
converters.add(new AllEncompassingFormHttpMessageConverter()); |
||||
converters.add(fastJsonHttpMessageConverter()); |
||||
} |
||||
|
||||
@Bean |
||||
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { |
||||
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); |
||||
FastJsonConfig config = new FastJsonConfig(); |
||||
//Long类型转String类型
|
||||
SerializeConfig serializeConfig = SerializeConfig.globalInstance; |
||||
// ToStringSerializer 是这个包 com.alibaba.fastjson.serializer.ToStringSerializer
|
||||
serializeConfig.put(BigInteger.class, ToStringSerializer.instance); |
||||
serializeConfig.put(Long.class, ToStringSerializer.instance); |
||||
serializeConfig.put(Long.TYPE, ToStringSerializer.instance); |
||||
config.setSerializeConfig(serializeConfig); |
||||
config.setSerializerFeatures( |
||||
SerializerFeature.WriteMapNullValue, // 保留map空的字段
|
||||
SerializerFeature.WriteNullStringAsEmpty, // 将String类型的null转成""
|
||||
SerializerFeature.WriteNullNumberAsZero, // 将Number类型的null转成0
|
||||
SerializerFeature.WriteNullListAsEmpty, // 将List类型的null转成[]
|
||||
SerializerFeature.WriteNullBooleanAsFalse, // 将Boolean类型的null转成false
|
||||
SerializerFeature.WriteDateUseDateFormat, //日期格式转换
|
||||
SerializerFeature.DisableCircularReferenceDetect // 避免循环引用
|
||||
); |
||||
config.setSerializeFilters(valueFilter); |
||||
converter.setFastJsonConfig(config); |
||||
converter.setDefaultCharset(StandardCharsets.UTF_8); |
||||
// 解决中文乱码问题,相当于在Controller上的@RequestMapping中加了个属性produces = "application/json"
|
||||
List<MediaType> mediaTypeList = new ArrayList<>(); |
||||
mediaTypeList.add(MediaType.APPLICATION_JSON); |
||||
converter.setSupportedMediaTypes(mediaTypeList); |
||||
return converter; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* FastJson过滤器将null值转换为字符串 |
||||
* obj 是class |
||||
* s 是key值 |
||||
* o1 是value值 |
||||
*/ |
||||
public static final ValueFilter valueFilter = (obj, s, v) -> { |
||||
if (v == null) { |
||||
return ""; |
||||
} |
||||
return v; |
||||
}; |
||||
|
||||
/** |
||||
* 页面跨域访问Controller过滤 |
||||
*/ |
||||
@Override |
||||
public void addCorsMappings(CorsRegistry registry) { |
||||
WebMvcConfigurer.super.addCorsMappings(registry); |
||||
registry.addMapping("/**") |
||||
.allowedHeaders("*") |
||||
.allowedMethods("POST", "GET", "PUT", "DELETE") |
||||
.allowedOrigins("*"); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。 需要重新指定静态资源 |
||||
*/ |
||||
@Override |
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
||||
registry.addResourceHandler("/**").addResourceLocations( |
||||
"classpath:/static/"); |
||||
registry.addResourceHandler("doc.html").addResourceLocations( |
||||
"classpath:/META-INF/resources/"); |
||||
registry.addResourceHandler("/webjars/**").addResourceLocations( |
||||
"classpath:/META-INF/resources/webjars/"); |
||||
registry.addResourceHandler(fileUploadProperties.getAccessUrl()) |
||||
.addResourceLocations("file:" + fileUploadProperties.getPath()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 配置servlet处理 |
||||
*/ |
||||
@Override |
||||
public void configureDefaultServletHandling( |
||||
DefaultServletHandlerConfigurer configurer) { |
||||
configurer.enable(); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,52 @@ |
||||
package com.huoran.iasf.common.exception; |
||||
|
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.exception.code.ResponseCodeInterface; |
||||
|
||||
/** |
||||
* BusinessException |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class BusinessException extends RuntimeException { |
||||
/** |
||||
* 异常编号 |
||||
*/ |
||||
private final int messageCode; |
||||
|
||||
/** |
||||
* 对messageCode 异常信息进行补充说明 |
||||
*/ |
||||
private final String detailMessage; |
||||
|
||||
public BusinessException(int messageCode, String message) { |
||||
super(message); |
||||
this.messageCode = messageCode; |
||||
this.detailMessage = message; |
||||
} |
||||
|
||||
public BusinessException(String message) { |
||||
super(message); |
||||
this.messageCode = BaseResponseCode.OPERATION_ERROR.getCode(); |
||||
this.detailMessage = message; |
||||
} |
||||
|
||||
/** |
||||
* 构造函数 |
||||
* |
||||
* @param code 异常码 |
||||
*/ |
||||
public BusinessException(ResponseCodeInterface code) { |
||||
this(code.getCode(), code.getMsg()); |
||||
} |
||||
|
||||
public int getMessageCode() { |
||||
return messageCode; |
||||
} |
||||
|
||||
public String getDetailMessage() { |
||||
return detailMessage; |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
package com.huoran.iasf.common.exception.code; |
||||
|
||||
|
||||
/** |
||||
* 错误码 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public enum BaseResponseCode implements ResponseCodeInterface { |
||||
/** |
||||
* 错误码 |
||||
*/ |
||||
SUCCESS(200, "success"), |
||||
SYSTEM_BUSY(10001, "系统繁忙,请稍候再试"), |
||||
OPERATION_ERROR(10002, "操作失败"), |
||||
|
||||
TOKEN_ERROR(401001, "登录凭证已过期,请重新登录"), |
||||
DATA_ERROR(401003, "传入数据异常"), |
||||
NOT_ACCOUNT(401004, "该用户不存在,请先注册"), |
||||
USER_LOCK(401005, "该用户已被锁定,请联系运营人员"), |
||||
PASSWORD_ERROR(401006, "用户名或密码错误"), |
||||
METHOD_ARGUMENT_NOT_VALID_EXCEPTION(401007, "方法参数校验异常"), |
||||
UNAUTHORIZED_ERROR(401008, "权鉴校验不通过"), |
||||
ROLE_PERMISSION_RELATION(401009, "该菜单权限存在子集关联,不允许删除"), |
||||
OLD_PASSWORD_ERROR(401010, "旧密码不正确"), |
||||
NOT_PERMISSION_DELETED_DEPT(401011, "该组织机构下还关联着用户,不允许删除"), |
||||
OPERATION_MENU_PERMISSION_CATALOG_ERROR(401012, "操作后的菜单类型是目录,所属菜单必须为默认顶级菜单或者目录"), |
||||
OPERATION_MENU_PERMISSION_MENU_ERROR(401013, "操作后的菜单类型是菜单,所属菜单必须为目录类型"), |
||||
OPERATION_MENU_PERMISSION_BTN_ERROR(401013, "操作后的菜单类型是按钮,所属菜单必须为菜单类型"), |
||||
OPERATION_MENU_PERMISSION_URL_NOT_NULL(401015, "菜单权限的url不能为空"), |
||||
OPERATION_MENU_PERMISSION_URL_PERMS_NULL(401016, "菜单权限的标识符不能为空"), |
||||
; |
||||
|
||||
/** |
||||
* 错误码 |
||||
*/ |
||||
private final int code; |
||||
/** |
||||
* 错误消息 |
||||
*/ |
||||
private final String msg; |
||||
|
||||
BaseResponseCode(int code, String msg) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
@Override |
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
@Override |
||||
public String getMsg() { |
||||
return msg; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.huoran.iasf.common.exception.code; |
||||
|
||||
/** |
||||
* ResponseCodeInterface |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface ResponseCodeInterface { |
||||
/** |
||||
* 获取code |
||||
* |
||||
* @return code |
||||
*/ |
||||
int getCode(); |
||||
|
||||
/** |
||||
* 获取信息 |
||||
* |
||||
* @return msg |
||||
*/ |
||||
String getMsg(); |
||||
} |
@ -0,0 +1,83 @@ |
||||
package com.huoran.iasf.common.exception.handler; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.authz.AuthorizationException; |
||||
import org.springframework.validation.ObjectError; |
||||
import org.springframework.web.bind.MethodArgumentNotValidException; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||
|
||||
import javax.validation.ConstraintViolation; |
||||
import javax.validation.ConstraintViolationException; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* RestExceptionHandler |
||||
* 全局异常拦截器 |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RestControllerAdvice |
||||
@Slf4j |
||||
public class RestExceptionHandler { |
||||
|
||||
/** |
||||
* 系统繁忙,请稍候再试" |
||||
*/ |
||||
@ExceptionHandler(Exception.class) |
||||
public R handleException(Exception e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return R.getResult(BaseResponseCode.SYSTEM_BUSY); |
||||
} |
||||
|
||||
/** |
||||
* 自定义全局异常处理 |
||||
*/ |
||||
@ExceptionHandler(value = BusinessException.class) |
||||
R businessExceptionHandler(BusinessException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return new R(e.getMessageCode(), e.getDetailMessage()); |
||||
} |
||||
|
||||
/** |
||||
* 没有权限 返回403视图 |
||||
*/ |
||||
@ExceptionHandler(value = AuthorizationException.class) |
||||
public R errorPermission(AuthorizationException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return new R(BaseResponseCode.UNAUTHORIZED_ERROR); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 处理validation 框架异常 |
||||
*/ |
||||
@ExceptionHandler(MethodArgumentNotValidException.class) |
||||
R methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { |
||||
log.error("methodArgumentNotValidExceptionHandler bindingResult.allErrors():{},exception:{}", e.getBindingResult().getAllErrors(), e); |
||||
List<ObjectError> errors = e.getBindingResult().getAllErrors(); |
||||
return R.getResult(BaseResponseCode.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getCode(), errors.get(0).getDefaultMessage()); |
||||
} |
||||
|
||||
/** |
||||
* 校验List<entity>类型, 需要controller添加@Validated注解 |
||||
* 处理Validated List<entity> 异常 |
||||
*/ |
||||
@ExceptionHandler |
||||
public R handle(ConstraintViolationException exception) { |
||||
log.error("methodArgumentNotValidExceptionHandler bindingResult.allErrors():{},exception:{}", exception, exception); |
||||
Set<ConstraintViolation<?>> violations = exception.getConstraintViolations(); |
||||
StringBuilder builder = new StringBuilder(); |
||||
for (ConstraintViolation<?> violation : violations) { |
||||
builder.append(violation.getMessage()); |
||||
break; |
||||
} |
||||
return R.getResult(BaseResponseCode.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getCode(), builder.toString()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,87 @@ |
||||
package com.huoran.iasf.common.filter; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.service.HttpApiSessionService; |
||||
import io.jsonwebtoken.Claims; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.core.annotation.Order; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.*; |
||||
import javax.servlet.annotation.WebFilter; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.util.Arrays; |
||||
|
||||
import static com.huoran.iasf.service.HttpApiSessionService.USER_ID_KEY; |
||||
import static com.huoran.iasf.service.HttpApiSessionService.USER_USERNAME_KEY; |
||||
|
||||
@Slf4j |
||||
@WebFilter(filterName = "authFilter", urlPatterns = "/iasf/app/api/*") |
||||
@Order(1) |
||||
public class AuthFilter implements Filter { |
||||
/** |
||||
* 白名单 |
||||
*/ |
||||
private static final String[] whiteList = {"/iasf/app/api/login", "/iasf/app/api/open/test"}; |
||||
@Resource |
||||
HttpApiSessionService httpApiSessionService; |
||||
//需要拦截的地址
|
||||
@Override |
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { |
||||
HttpServletRequest req = (HttpServletRequest) request; |
||||
HttpServletResponse resp = (HttpServletResponse) response; |
||||
resp.setHeader("Access-Control-Allow-Origin","*"); |
||||
resp.setHeader("Access-Control-Allow-Credentials", "true"); |
||||
resp.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT"); |
||||
resp.setHeader("Access-Control-Allow-Headers", "*"); |
||||
String url = req.getRequestURI(); |
||||
log.info("url:{}", url); |
||||
if (Arrays.asList(whiteList).contains(url)) { |
||||
chain.doFilter(request, response); |
||||
} else { |
||||
//拦截接口
|
||||
//从header中获取token
|
||||
String token = req.getHeader("token"); |
||||
//如果header中不存在token,则从参数中获取token
|
||||
if (StringUtils.isBlank(token)) { |
||||
token = request.getParameter("token"); |
||||
} |
||||
//token为空返回
|
||||
if (StringUtils.isBlank(token)) { |
||||
responseResult(resp, R.fail("token不能为空")); |
||||
} |
||||
// 校验并解析token,如果token过期或者篡改,则会返回null
|
||||
Claims claims = httpApiSessionService.checkJWT(token); |
||||
if (null == claims) { |
||||
responseResult(resp, R.fail("登陆失效, 请重新登陆")); |
||||
} |
||||
//TODO 校验用户状态等
|
||||
|
||||
// 校验通过后,设置用户信息到request里,在Controller中从Request域中获取用户信息
|
||||
assert claims != null; |
||||
request.setAttribute(USER_ID_KEY, claims.get(USER_ID_KEY)); |
||||
request.setAttribute(USER_USERNAME_KEY, claims.get(USER_USERNAME_KEY)); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* responseResult |
||||
* @param response |
||||
* @param result |
||||
*/ |
||||
private void responseResult(HttpServletResponse response, R result) { |
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setHeader("Content-type", "application/json;charset=UTF-8"); |
||||
response.setStatus(200); |
||||
try { |
||||
response.getWriter().write(JSON.toJSONString(result)); |
||||
} catch (IOException ex) { |
||||
log.error(ex.getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.huoran.iasf.common.job.task; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* 测试定时任务(演示Demo,可删除) |
||||
* testTask为spring bean的名称, 方法名称必须是run |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Component("testTask") |
||||
public class TestTask { |
||||
private Logger logger = LoggerFactory.getLogger(getClass()); |
||||
|
||||
public void run(String params){ |
||||
logger.debug("TestTask定时任务正在执行,参数为:{}", params); |
||||
} |
||||
} |
@ -0,0 +1,111 @@ |
||||
package com.huoran.iasf.common.job.utils; |
||||
|
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.common.utils.SpringContextUtils; |
||||
import com.huoran.iasf.entity.SysJobEntity; |
||||
import com.huoran.iasf.entity.SysJobLogEntity; |
||||
import com.huoran.iasf.service.SysJobLogService; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.quartz.JobExecutionContext; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.scheduling.quartz.QuartzJobBean; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
|
||||
/** |
||||
* 定时任务 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class ScheduleJob extends QuartzJobBean { |
||||
private Logger logger = LoggerFactory.getLogger(getClass()); |
||||
|
||||
final SysJobLogService sysJobLogService; |
||||
|
||||
public ScheduleJob(SysJobLogService sysJobLogService) { |
||||
this.sysJobLogService = sysJobLogService; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void executeInternal(JobExecutionContext context) { |
||||
SysJobEntity scheduleJob = (SysJobEntity) context.getMergedJobDataMap() |
||||
.get(SysJobEntity.JOB_PARAM_KEY); |
||||
|
||||
//获取spring bean
|
||||
SysJobLogService scheduleJobLogService = (SysJobLogService) SpringContextUtils.getBean("sysJobLogService"); |
||||
|
||||
//数据库保存执行记录
|
||||
SysJobLogEntity log = new SysJobLogEntity(); |
||||
log.setJobId(scheduleJob.getId()); |
||||
log.setBeanName(scheduleJob.getBeanName()); |
||||
log.setParams(scheduleJob.getParams()); |
||||
|
||||
//任务开始时间
|
||||
long startTime = System.currentTimeMillis(); |
||||
|
||||
try { |
||||
//执行任务
|
||||
logger.debug("任务准备执行,任务ID:" + scheduleJob.getId()); |
||||
|
||||
Object target = SpringContextUtils.getBean(scheduleJob.getBeanName()); |
||||
assert target != null; |
||||
Method method = target.getClass().getDeclaredMethod("run", String.class); |
||||
method.invoke(target, scheduleJob.getParams()); |
||||
|
||||
//任务执行总时长
|
||||
long times = System.currentTimeMillis() - startTime; |
||||
log.setTimes((int) times); |
||||
//任务状态 0:成功 1:失败
|
||||
log.setStatus(0); |
||||
|
||||
logger.debug("任务执行完毕,任务ID:" + scheduleJob.getId() + " 总共耗时:" + times + "毫秒"); |
||||
} catch (Exception e) { |
||||
logger.error("任务执行失败,任务ID:" + scheduleJob.getId(), e); |
||||
|
||||
//任务执行总时长
|
||||
long times = System.currentTimeMillis() - startTime; |
||||
log.setTimes((int) times); |
||||
|
||||
//任务状态 0:成功 1:失败
|
||||
log.setStatus(1); |
||||
log.setError(StringUtils.substring(e.toString(), 0, 2000)); |
||||
} finally { |
||||
assert scheduleJobLogService != null; |
||||
scheduleJobLogService.save(log); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断bean是否有效 |
||||
* |
||||
* @param beanName beanName |
||||
* @return 返回信息 |
||||
*/ |
||||
public static R judgeBean(String beanName) { |
||||
|
||||
if (org.springframework.util.StringUtils.isEmpty(beanName)) { |
||||
return R.fail("spring bean名称不能为空"); |
||||
} |
||||
|
||||
Object target = SpringContextUtils.getBean(beanName); |
||||
if (target == null) { |
||||
return R.fail("spring bean不存在,请检查"); |
||||
} |
||||
Method method; |
||||
try { |
||||
method = target.getClass().getDeclaredMethod("run", String.class); |
||||
} catch (Exception e) { |
||||
return R.fail("spring bean中的run方法不存在,请检查"); |
||||
} |
||||
if (method == null) { |
||||
return R.fail("spring bean中的run方法不存在,请检查"); |
||||
} |
||||
|
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,150 @@ |
||||
package com.huoran.iasf.common.job.utils; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysJobEntity; |
||||
import org.quartz.*; |
||||
|
||||
/** |
||||
* 定时任务工具类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class ScheduleUtils { |
||||
private final static String JOB_NAME = "TASK_"; |
||||
|
||||
/** |
||||
* 获取触发器key |
||||
*/ |
||||
public static TriggerKey getTriggerKey(String jobId) { |
||||
return TriggerKey.triggerKey(JOB_NAME + jobId); |
||||
} |
||||
|
||||
/** |
||||
* 获取jobKey |
||||
*/ |
||||
public static JobKey getJobKey(String jobId) { |
||||
return JobKey.jobKey(JOB_NAME + jobId); |
||||
} |
||||
|
||||
/** |
||||
* 获取表达式触发器 |
||||
*/ |
||||
public static CronTrigger getCronTrigger(Scheduler scheduler, String jobId) { |
||||
try { |
||||
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId)); |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("获取定时任务CronTrigger出现异常"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建定时任务 |
||||
*/ |
||||
public static void createScheduleJob(Scheduler scheduler, SysJobEntity scheduleJob) { |
||||
try { |
||||
//构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getId())).build(); |
||||
|
||||
//表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) |
||||
.withMisfireHandlingInstructionDoNothing(); |
||||
|
||||
//按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getId())).withSchedule(scheduleBuilder).build(); |
||||
|
||||
//放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(SysJobEntity.JOB_PARAM_KEY, scheduleJob); |
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger); |
||||
|
||||
//暂停任务
|
||||
if (Constant.SCHEDULER_STATUS_PAUSE.equals(scheduleJob.getStatus())) { |
||||
pauseJob(scheduler, scheduleJob.getId()); |
||||
} |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("创建定时任务失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 更新定时任务 |
||||
*/ |
||||
public static void updateScheduleJob(Scheduler scheduler, SysJobEntity scheduleJob) { |
||||
try { |
||||
TriggerKey triggerKey = getTriggerKey(scheduleJob.getId()); |
||||
|
||||
//表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) |
||||
.withMisfireHandlingInstructionDoNothing(); |
||||
|
||||
CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getId()); |
||||
|
||||
//按新的cronExpression表达式重新构建trigger
|
||||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); |
||||
|
||||
//参数
|
||||
trigger.getJobDataMap().put(SysJobEntity.JOB_PARAM_KEY, scheduleJob); |
||||
|
||||
scheduler.rescheduleJob(triggerKey, trigger); |
||||
|
||||
//暂停任务
|
||||
if (Constant.SCHEDULER_STATUS_PAUSE.equals(scheduleJob.getStatus())) { |
||||
pauseJob(scheduler, scheduleJob.getId()); |
||||
} |
||||
|
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("更新定时任务失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 立即执行任务 |
||||
*/ |
||||
public static void run(Scheduler scheduler, SysJobEntity scheduleJob) { |
||||
try { |
||||
//参数
|
||||
JobDataMap dataMap = new JobDataMap(); |
||||
dataMap.put(SysJobEntity.JOB_PARAM_KEY, scheduleJob); |
||||
|
||||
scheduler.triggerJob(getJobKey(scheduleJob.getId()), dataMap); |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("立即执行定时任务失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 暂停任务 |
||||
*/ |
||||
public static void pauseJob(Scheduler scheduler, String jobId) { |
||||
try { |
||||
scheduler.pauseJob(getJobKey(jobId)); |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("暂停定时任务失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 恢复任务 |
||||
*/ |
||||
public static void resumeJob(Scheduler scheduler, String jobId) { |
||||
try { |
||||
scheduler.resumeJob(getJobKey(jobId)); |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("暂停定时任务失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 删除定时任务 |
||||
*/ |
||||
public static void deleteScheduleJob(Scheduler scheduler, String jobId) { |
||||
try { |
||||
scheduler.deleteJob(getJobKey(jobId)); |
||||
} catch (SchedulerException e) { |
||||
throw new BusinessException("删除定时任务失败"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,116 @@ |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.common.utils.HttpContextUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.authc.AuthenticationException; |
||||
import org.apache.shiro.authc.UsernamePasswordToken; |
||||
import org.apache.shiro.subject.Subject; |
||||
import org.apache.shiro.web.filter.AccessControlFilter; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.ServletRequest; |
||||
import javax.servlet.ServletResponse; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.nio.charset.StandardCharsets; |
||||
|
||||
|
||||
/** |
||||
* 自定义过滤器 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Slf4j |
||||
public class CustomAccessControlFilter extends AccessControlFilter { |
||||
|
||||
|
||||
@Override |
||||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { |
||||
HttpServletRequest request = (HttpServletRequest) servletRequest; |
||||
try { |
||||
Subject subject = getSubject(servletRequest, servletResponse); |
||||
System.out.println(subject.isAuthenticated() + ""); |
||||
System.out.println(HttpContextUtils.isAjaxRequest(request)); |
||||
log.info(request.getMethod()); |
||||
log.info(request.getRequestURL().toString()); |
||||
//从header中获取token
|
||||
String token = request.getHeader(Constant.ACCESS_TOKEN); |
||||
//如果header中不存在token,则从参数中获取token
|
||||
if (StringUtils.isEmpty(token)) { |
||||
token = request.getParameter(Constant.ACCESS_TOKEN); |
||||
} |
||||
if (StringUtils.isEmpty(token)) { |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token); |
||||
getSubject(servletRequest, servletResponse).login(usernamePasswordToken); |
||||
} catch (BusinessException exception) { |
||||
if (HttpContextUtils.isAjaxRequest(request)) { |
||||
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); |
||||
} else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) { |
||||
servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse); |
||||
} else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) { |
||||
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); |
||||
} else { |
||||
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); |
||||
} |
||||
return false; |
||||
} catch (AuthenticationException e) { |
||||
if (HttpContextUtils.isAjaxRequest(request)) { |
||||
if (e.getCause() instanceof BusinessException) { |
||||
BusinessException exception = (BusinessException) e.getCause(); |
||||
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); |
||||
} else { |
||||
customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse); |
||||
} |
||||
} else { |
||||
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); |
||||
} |
||||
return false; |
||||
} catch (Exception e) { |
||||
if (HttpContextUtils.isAjaxRequest(request)) { |
||||
if (e.getCause() instanceof BusinessException) { |
||||
BusinessException exception = (BusinessException) e.getCause(); |
||||
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); |
||||
} else { |
||||
customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse); |
||||
} |
||||
} else { |
||||
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); |
||||
} |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
private void customResponse(int code, String msg, ServletResponse response) { |
||||
try { |
||||
R result = R.getResult(code, msg); |
||||
|
||||
response.setContentType("application/json; charset=utf-8"); |
||||
response.setCharacterEncoding("UTF-8"); |
||||
|
||||
String userJson = JSON.toJSONString(result); |
||||
OutputStream out = response.getOutputStream(); |
||||
out.write(userJson.getBytes(StandardCharsets.UTF_8)); |
||||
out.flush(); |
||||
} catch (IOException e) { |
||||
log.error("error={}", e, e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.service.RedisService; |
||||
import org.apache.shiro.SecurityUtils; |
||||
import org.apache.shiro.authc.AuthenticationInfo; |
||||
import org.apache.shiro.authc.AuthenticationToken; |
||||
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Lazy; |
||||
|
||||
/** |
||||
* 认证 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class CustomHashedCredentialsMatcher extends SimpleCredentialsMatcher { |
||||
|
||||
@Lazy |
||||
@Autowired |
||||
private RedisService redisDb; |
||||
@Value("${spring.redis.key.prefix.userToken}") |
||||
private String userTokenPrefix; |
||||
|
||||
@Override |
||||
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { |
||||
String accessToken = (String) token.getPrincipal(); |
||||
if (!redisDb.exists(userTokenPrefix + accessToken)) { |
||||
SecurityUtils.getSubject().logout(); |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.service.PermissionService; |
||||
import com.huoran.iasf.service.RedisService; |
||||
import com.huoran.iasf.service.RoleService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.authc.AuthenticationException; |
||||
import org.apache.shiro.authc.AuthenticationInfo; |
||||
import org.apache.shiro.authc.AuthenticationToken; |
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo; |
||||
import org.apache.shiro.authz.AuthorizationInfo; |
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo; |
||||
import org.apache.shiro.realm.AuthorizingRealm; |
||||
import org.apache.shiro.subject.PrincipalCollection; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
/** |
||||
* 授权 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Slf4j |
||||
public class CustomRealm extends AuthorizingRealm { |
||||
@Lazy |
||||
@Autowired |
||||
private PermissionService permissionService; |
||||
@Lazy |
||||
@Autowired |
||||
private RoleService roleService; |
||||
@Lazy |
||||
@Autowired |
||||
private RedisService redisService; |
||||
@Value("${spring.redis.key.prefix.permissionRefresh}") |
||||
private String redisPermissionRefreshKey; |
||||
@Value("${spring.redis.key.prefix.userToken}") |
||||
private String userTokenPrefix; |
||||
@Lazy |
||||
@Autowired |
||||
private RedisService redisDb; |
||||
|
||||
|
||||
/** |
||||
* 执行授权逻辑 |
||||
*/ |
||||
@Override |
||||
@SuppressWarnings("unchecked") |
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { |
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); |
||||
|
||||
String sessionInfoStr = redisDb.get(userTokenPrefix + principalCollection.getPrimaryPrincipal()); |
||||
if (StringUtils.isEmpty(sessionInfoStr)) { |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
JSONObject redisSession = JSON.parseObject(sessionInfoStr); |
||||
if (redisSession == null) { |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
|
||||
if (redisSession.get(Constant.ROLES_KEY) != null) { |
||||
authorizationInfo.addRoles((Collection<String>) redisSession.get(Constant.ROLES_KEY)); |
||||
} |
||||
if (redisSession.get(Constant.PERMISSIONS_KEY) != null) { |
||||
authorizationInfo.addStringPermissions((Collection<String>) redisSession.get(Constant.PERMISSIONS_KEY)); |
||||
} |
||||
return authorizationInfo; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 执行认证逻辑 |
||||
*/ |
||||
@Override |
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { |
||||
return new SimpleAuthenticationInfo(authenticationToken.getPrincipal(), authenticationToken.getPrincipal(), getName()); |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.huoran.iasf.common.config.FileUploadProperties; |
||||
import org.apache.shiro.mgt.SecurityManager; |
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; |
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; |
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.Filter; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* ShiroConfig |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Configuration |
||||
@EnableConfigurationProperties(FileUploadProperties.class) |
||||
public class ShiroConfig { |
||||
|
||||
@Resource |
||||
private FileUploadProperties fileUploadProperties; |
||||
|
||||
@Bean |
||||
public CustomHashedCredentialsMatcher customHashedCredentialsMatcher() { |
||||
return new CustomHashedCredentialsMatcher(); |
||||
} |
||||
|
||||
/** |
||||
* 创建realm |
||||
*/ |
||||
@Bean |
||||
public CustomRealm customRealm() { |
||||
CustomRealm customRealm = new CustomRealm(); |
||||
customRealm.setCredentialsMatcher(customHashedCredentialsMatcher()); |
||||
return customRealm; |
||||
} |
||||
|
||||
@Bean |
||||
public SecurityManager securityManager() { |
||||
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); |
||||
//关联realm
|
||||
securityManager.setRealm(customRealm()); |
||||
return securityManager; |
||||
} |
||||
|
||||
|
||||
@Bean |
||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) { |
||||
|
||||
//整个shiro执行过程: 过滤器、认证、授权
|
||||
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); |
||||
//设置安全管理器
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager); |
||||
LinkedHashMap<String, Filter> filtersMap = new LinkedHashMap<>(); |
||||
//用来校验token
|
||||
filtersMap.put("token", new CustomAccessControlFilter()); |
||||
shiroFilterFactoryBean.setFilters(filtersMap); |
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); |
||||
// 配置不会被拦截的链接 顺序判断
|
||||
filterChainDefinitionMap.put("/sys/user/login", "anon"); |
||||
filterChainDefinitionMap.put("/sys/user/token", "anon"); |
||||
filterChainDefinitionMap.put("/sys/getVerify", "anon"); |
||||
filterChainDefinitionMap.put("/sys/checkVerify", "anon"); |
||||
filterChainDefinitionMap.put("/index/**", "anon"); |
||||
filterChainDefinitionMap.put("*.html", "anon"); |
||||
filterChainDefinitionMap.put("/static/**", "anon"); |
||||
filterChainDefinitionMap.put("/doc.html", "anon"); |
||||
filterChainDefinitionMap.put("/swagger-resources/**", "anon"); |
||||
filterChainDefinitionMap.put("/v2/api-docs", "anon"); |
||||
filterChainDefinitionMap.put("/v2/api-docs-ext", "anon"); |
||||
filterChainDefinitionMap.put("/webjars/**", "anon"); |
||||
filterChainDefinitionMap.put("/druid/**", "anon"); |
||||
filterChainDefinitionMap.put("/favicon.ico", "anon"); |
||||
filterChainDefinitionMap.put("/captcha.jpg", "anon"); |
||||
filterChainDefinitionMap.put("/csrf", "anon"); |
||||
//文件上传可直接访问
|
||||
filterChainDefinitionMap.put(fileUploadProperties.getAccessUrl(), "anon"); |
||||
filterChainDefinitionMap.put("/images/**", "anon"); |
||||
filterChainDefinitionMap.put("/js/**", "anon"); |
||||
filterChainDefinitionMap.put("/layui/**", "anon"); |
||||
filterChainDefinitionMap.put("/css/**", "anon"); |
||||
filterChainDefinitionMap.put("/layui-ext/**", "anon"); |
||||
filterChainDefinitionMap.put("/app/api/**", "anon"); |
||||
filterChainDefinitionMap.put("/**", "token,authc"); |
||||
shiroFilterFactoryBean.setLoginUrl("/index/login"); |
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); |
||||
return shiroFilterFactoryBean; |
||||
} |
||||
|
||||
/** |
||||
* 开启shiro aop注解支持. |
||||
* 使用代理方式;所以需要开启代码支持; |
||||
* |
||||
* @return org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor |
||||
*/ |
||||
@Bean |
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { |
||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); |
||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); |
||||
return authorizationAttributeSourceAdvisor; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,47 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
/** |
||||
* Constant |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class Constant { |
||||
|
||||
/** |
||||
* redis的token相关 |
||||
*/ |
||||
public static final String ACCESS_TOKEN = "authorization"; |
||||
public static final String PERMISSIONS_KEY = "permissions-key"; |
||||
public static final String USERID_KEY = "userid-key"; |
||||
public static final String USERNAME_KEY = "username-key"; |
||||
public static final String ROLES_KEY = "roles-key"; |
||||
|
||||
/** |
||||
* 未删除值 |
||||
*/ |
||||
public static final Integer DATA_NOT_DELETED = 1; |
||||
|
||||
/** |
||||
* 数据库类型 |
||||
*/ |
||||
public static final String DB_TYPE_MYSQL = "mysql"; |
||||
public static final String DB_TYPE_ORACLE = "oracle"; |
||||
public static final String DB_TYPE_SQL_SERVER = "sqlServer"; |
||||
|
||||
/** |
||||
* 定时任务状态 |
||||
*/ |
||||
public static final Integer SCHEDULER_STATUS_NORMAL = 0; |
||||
public static final Integer SCHEDULER_STATUS_PAUSE = 1; |
||||
|
||||
/** |
||||
* 数据范围类型 1:所有/2:自定义/3:本部门及一下/4:仅本部门/5:自己 |
||||
*/ |
||||
public static final Integer DATA_SCOPE_ALL = 1; |
||||
public static final Integer DATA_SCOPE_CUSTOM = 2; |
||||
public static final Integer DATA_SCOPE_DEPT_AND_CHILD = 3; |
||||
public static final Integer DATA_SCOPE_DEPT = 4; |
||||
public static final Integer DATA_SCOPE_DEPT_SELF = 5; |
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 日期处理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class DateUtils { |
||||
/** |
||||
* 时间格式(yyyy-MM-dd HH:mm:ss) |
||||
*/ |
||||
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; |
||||
/** |
||||
* 时间格式(yyyyMMdd) |
||||
*/ |
||||
public final static String DATEPATTERN = "yyyyMMdd"; |
||||
|
||||
public static String format(Date date, String pattern) { |
||||
if (date != null) { |
||||
SimpleDateFormat df = new SimpleDateFormat(pattern); |
||||
return df.format(date); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,238 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.entity.ColumnEntity; |
||||
import com.huoran.iasf.entity.TableEntity; |
||||
import org.apache.commons.configuration.Configuration; |
||||
import org.apache.commons.configuration.ConfigurationException; |
||||
import org.apache.commons.configuration.PropertiesConfiguration; |
||||
import org.apache.commons.io.IOUtils; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.apache.velocity.Template; |
||||
import org.apache.velocity.VelocityContext; |
||||
import org.apache.velocity.app.Velocity; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.StringWriter; |
||||
import java.util.*; |
||||
import java.util.zip.ZipEntry; |
||||
import java.util.zip.ZipOutputStream; |
||||
|
||||
/** |
||||
* 代码生成器 工具类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class GenUtils { |
||||
|
||||
public static List<String> getTemplates() { |
||||
List<String> templates = new ArrayList<>(); |
||||
templates.add("template/Entity.java.vm"); |
||||
templates.add("template/Dao.java.vm"); |
||||
templates.add("template/Dao.xml.vm"); |
||||
templates.add("template/Service.java.vm"); |
||||
templates.add("template/ServiceImpl.java.vm"); |
||||
templates.add("template/Controller.java.vm"); |
||||
templates.add("template/menu.sql.vm"); |
||||
templates.add("template/list.html.vm"); |
||||
|
||||
return templates; |
||||
} |
||||
|
||||
/** |
||||
* 生成代码 |
||||
*/ |
||||
public static void generatorCode(Map<String, String> table, |
||||
List<Map<String, String>> columns, ZipOutputStream zip) { |
||||
//配置信息
|
||||
Configuration config = getConfig(); |
||||
boolean hasBigDecimal = false; |
||||
//表信息
|
||||
TableEntity tableEntity = new TableEntity(); |
||||
tableEntity.setTableName(table.get("tableName")); |
||||
tableEntity.setComments(table.get("tableComment")); |
||||
//表名转换成Java类名
|
||||
String className = tableToJava(tableEntity.getTableName(), config.getStringArray("tablePrefix")); |
||||
tableEntity.setClassName(className); |
||||
tableEntity.setClassname(StringUtils.uncapitalize(className)); |
||||
tableEntity.setClassNameLower(className.toLowerCase()); |
||||
|
||||
//列信息
|
||||
List<ColumnEntity> columsList = new ArrayList<>(); |
||||
for (Map<String, String> column : columns) { |
||||
ColumnEntity columnEntity = new ColumnEntity(); |
||||
columnEntity.setColumnName(column.get("columnName")); |
||||
columnEntity.setDataType(column.get("dataType")); |
||||
columnEntity.setComments(column.get("columnComment")); |
||||
columnEntity.setExtra(column.get("extra")); |
||||
|
||||
//列名转换成Java属性名
|
||||
String attrName = columnToJava(columnEntity.getColumnName()); |
||||
columnEntity.setAttrName(attrName); |
||||
columnEntity.setAttrname(StringUtils.uncapitalize(attrName)); |
||||
|
||||
//列的数据类型,转换成Java类型
|
||||
String attrType = config.getString(columnEntity.getDataType(), "unknowType"); |
||||
columnEntity.setAttrType(attrType); |
||||
if (!hasBigDecimal && "BigDecimal".equals(attrType)) { |
||||
hasBigDecimal = true; |
||||
} |
||||
//是否主键
|
||||
if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null) { |
||||
tableEntity.setPk(columnEntity); |
||||
} |
||||
|
||||
columsList.add(columnEntity); |
||||
} |
||||
tableEntity.setColumns(columsList); |
||||
|
||||
//没主键,则第一个字段为主键
|
||||
if (tableEntity.getPk() == null) { |
||||
tableEntity.setPk(tableEntity.getColumns().get(0)); |
||||
} |
||||
|
||||
//设置velocity资源加载器
|
||||
Properties prop = new Properties(); |
||||
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); |
||||
Velocity.init(prop); |
||||
String mainPath = config.getString("mainPath"); |
||||
mainPath = StringUtils.isBlank(mainPath) ? "com.company" : mainPath; |
||||
//封装模板数据
|
||||
Map<String, Object> map = new HashMap<>(15); |
||||
map.put("tableName", tableEntity.getTableName()); |
||||
map.put("comments", tableEntity.getComments()); |
||||
map.put("pk", tableEntity.getPk()); |
||||
map.put("className", tableEntity.getClassName()); |
||||
map.put("classname", tableEntity.getClassname()); |
||||
map.put("pathName", tableEntity.getClassname().toLowerCase()); |
||||
map.put("columns", tableEntity.getColumns()); |
||||
map.put("classNameLower", tableEntity.getClassNameLower()); |
||||
map.put("hasBigDecimal", hasBigDecimal); |
||||
map.put("mainPath", mainPath); |
||||
map.put("package", config.getString("package")); |
||||
map.put("author", config.getString("author")); |
||||
map.put("email", config.getString("email")); |
||||
map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN)); |
||||
map.put("identity", IdWorker.getId()); |
||||
map.put("addId", IdWorker.getId()); |
||||
map.put("updateId", IdWorker.getId()); |
||||
map.put("deleteId", IdWorker.getId()); |
||||
map.put("selectId", IdWorker.getId()); |
||||
map.put("identityJoinId", IdWorker.getId()); |
||||
map.put("addIdJoinId", IdWorker.getId()); |
||||
map.put("updateIdJoinId", IdWorker.getId()); |
||||
map.put("deleteIdJoinId", IdWorker.getId()); |
||||
map.put("selectIdJoinId", IdWorker.getId()); |
||||
VelocityContext context = new VelocityContext(map); |
||||
|
||||
//获取模板列表
|
||||
List<String> templates = getTemplates(); |
||||
for (String template : templates) { |
||||
//渲染模板
|
||||
StringWriter sw = new StringWriter(); |
||||
Template tpl = Velocity.getTemplate(template, "UTF-8"); |
||||
tpl.merge(context, sw); |
||||
|
||||
try { |
||||
//添加到zip
|
||||
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(getFileName(template, tableEntity.getClassName(), config.getString("package"))))); |
||||
IOUtils.write(sw.toString(), zip, "UTF-8"); |
||||
IOUtils.closeQuietly(sw); |
||||
zip.closeEntry(); |
||||
} catch (IOException e) { |
||||
throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 列名转换成Java属性名 |
||||
*/ |
||||
public static String columnToJava(String field) { |
||||
String[] fields = field.split("_"); |
||||
StringBuilder sbuilder = new StringBuilder(fields[0]); |
||||
for (int i = 1; i < fields.length; i++) { |
||||
char[] cs = fields[i].toCharArray(); |
||||
if(cs[0]>='a') { |
||||
cs[0] -= 32; |
||||
} |
||||
sbuilder.append(String.valueOf(cs)); |
||||
} |
||||
return sbuilder.toString().substring(0, 1).toUpperCase() + sbuilder.toString().substring(1); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 表名转换成Java类名 |
||||
*/ |
||||
public static String tableToJava(String tableName, String[] tablePrefixArray) { |
||||
tableName = tableName.toLowerCase(); |
||||
if (null != tablePrefixArray && tablePrefixArray.length > 0) { |
||||
for (String tablePrefix : tablePrefixArray) { |
||||
tablePrefix = tablePrefix.toLowerCase(); |
||||
tableName = tableName.replace(tablePrefix, ""); |
||||
} |
||||
} |
||||
return columnToJava(tableName); |
||||
} |
||||
|
||||
/** |
||||
* 获取配置信息 |
||||
*/ |
||||
public static Configuration getConfig() { |
||||
try { |
||||
return new PropertiesConfiguration("generator.properties"); |
||||
} catch (ConfigurationException e) { |
||||
throw new BusinessException("获取配置文件失败"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取文件名 |
||||
*/ |
||||
public static String getFileName(String template, String className, String packageName) { |
||||
String packagePath = "main" + File.separator + "java" + File.separator; |
||||
if (StringUtils.isNotBlank(packageName)) { |
||||
packagePath += packageName.replace(".", File.separator) + File.separator; |
||||
} |
||||
|
||||
if (template.contains("Entity.java.vm")) { |
||||
return packagePath + "entity" + File.separator + className + "Entity.java"; |
||||
} |
||||
|
||||
if (template.contains("Dao.java.vm")) { |
||||
return packagePath + "mapper" + File.separator + className + "Mapper.java"; |
||||
} |
||||
|
||||
if (template.contains("Service.java.vm")) { |
||||
return packagePath + "service" + File.separator + className + "Service.java"; |
||||
} |
||||
|
||||
if (template.contains("ServiceImpl.java.vm")) { |
||||
return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java"; |
||||
} |
||||
|
||||
if (template.contains("Controller.java.vm")) { |
||||
return packagePath + "controller" + File.separator + className + "Controller.java"; |
||||
} |
||||
|
||||
if (template.contains("Dao.xml.vm")) { |
||||
return "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + className + "Mapper.xml"; |
||||
} |
||||
|
||||
if (template.contains("menu.sql.vm")) { |
||||
return className.toLowerCase() + "_menu.sql"; |
||||
} |
||||
|
||||
if (template.contains("list.html.vm")) { |
||||
return "main" + File.separator + "resources" + File.separator + "templates" + File.separator + className.toLowerCase() + File.separator + "list" + ".html"; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* HttpContextUtils |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class HttpContextUtils { |
||||
|
||||
public static HttpServletRequest getHttpServletRequest() { |
||||
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
||||
} |
||||
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) { |
||||
|
||||
String accept = request.getHeader("accept"); |
||||
String xRequestedWith = request.getHeader("X-Requested-With"); |
||||
|
||||
// 如果是异步请求或是手机端,则直接返回信息
|
||||
return ((accept != null && accept.contains("application/json") |
||||
|| (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) |
||||
)); |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.net.InetAddress; |
||||
import java.net.UnknownHostException; |
||||
|
||||
/** |
||||
* IPUtils |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
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 (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("Proxy-Client-IP"); |
||||
} |
||||
if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getRemoteAddr(); |
||||
} |
||||
} catch (Exception e) { |
||||
logger.error("IPUtils ERROR ", e); |
||||
} |
||||
|
||||
// 使用代理,则获取第一个IP地址
|
||||
if (!StringUtils.isEmpty(ip) && ip.length() > 15) { |
||||
if (ip.indexOf(",") > 0) { |
||||
ip = ip.substring(0, ip.indexOf(",")); |
||||
} |
||||
} |
||||
|
||||
return ip; |
||||
} |
||||
|
||||
/** |
||||
* 获取客户端主机名称 |
||||
*/ |
||||
public static String getHostName() { |
||||
try { |
||||
return InetAddress.getLocalHost().getHostName(); |
||||
} catch (UnknownHostException e) { |
||||
logger.error(e.getMessage(), e); |
||||
} |
||||
return "未知"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,299 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import okhttp3.*; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URLEncoder; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
import java.util.concurrent.Semaphore; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
/** |
||||
* Ok http utils |
||||
* @author cheney.li |
||||
*/ |
||||
public class OkHttpUtils { |
||||
private static OkHttpClient okHttpClient; |
||||
private static Semaphore semaphore; |
||||
private Map<String, String> headerMap; |
||||
private Map<String, String> paramMap; |
||||
private String url; |
||||
private Request.Builder request; |
||||
private static final String ERROR_MESSAGE = "OkHttpUtils error:{}"; |
||||
private static final Logger logger = LoggerFactory.getLogger(OkHttpUtils.class); |
||||
/** |
||||
* 初始化okHttpClient,并且允许https访问 |
||||
*/ |
||||
private OkHttpUtils() { |
||||
if (okHttpClient == null) { |
||||
synchronized (OkHttpUtils.class) { |
||||
okHttpClient = new OkHttpClient.Builder() |
||||
.connectTimeout(15, TimeUnit.SECONDS) |
||||
.writeTimeout(20, TimeUnit.SECONDS) |
||||
.readTimeout(20, TimeUnit.SECONDS) |
||||
.retryOnConnectionFailure(true) |
||||
.build(); |
||||
addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 用于异步请求时,控制访问线程数,返回结果 |
||||
* |
||||
* @return |
||||
*/ |
||||
private static Semaphore getSemaphoreInstance() { |
||||
//只能1个线程同时访问
|
||||
synchronized (OkHttpUtils.class) { |
||||
if (semaphore == null) { |
||||
semaphore = new Semaphore(0); |
||||
} |
||||
} |
||||
return semaphore; |
||||
} |
||||
|
||||
/** |
||||
* 创建OkHttpUtils |
||||
* |
||||
* @return ok http utils |
||||
*/ |
||||
public static OkHttpUtils builder() { |
||||
return new OkHttpUtils(); |
||||
} |
||||
|
||||
/** |
||||
* 添加url |
||||
* |
||||
* @param url url |
||||
* @return ok http utils |
||||
*/ |
||||
public OkHttpUtils url(String url) { |
||||
this.url = url; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 添加参数 |
||||
* |
||||
* @param key 参数名 |
||||
* @param value 参数值 |
||||
* @return ok http utils |
||||
*/ |
||||
public OkHttpUtils addParam(String key, String value) { |
||||
if (paramMap == null) { |
||||
paramMap = new LinkedHashMap<>(16); |
||||
} |
||||
paramMap.put(key, value); |
||||
return this; |
||||
} |
||||
/** |
||||
* 添加参数 |
||||
* |
||||
* @param map map |
||||
* @return ok http utils |
||||
*/ |
||||
public OkHttpUtils addMap(Map<String, String> map) { |
||||
if (paramMap == null) { |
||||
paramMap = new LinkedHashMap<>(16); |
||||
} |
||||
paramMap.putAll(map); |
||||
return this; |
||||
} |
||||
/** |
||||
* 添加请求头 |
||||
* |
||||
* @param key 参数名 |
||||
* @param value 参数值 |
||||
* @return ok addHeader utils |
||||
*/ |
||||
public OkHttpUtils addHeader(String key, String value) { |
||||
if (headerMap == null) { |
||||
headerMap = new LinkedHashMap<>(16); |
||||
} |
||||
headerMap.put(key, value); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 初始化get方法 |
||||
* |
||||
* @return ok http utils |
||||
*/ |
||||
public OkHttpUtils get() { |
||||
request = new Request.Builder().get(); |
||||
StringBuilder urlBuilder = new StringBuilder(url); |
||||
if (paramMap != null) { |
||||
urlBuilder.append("?"); |
||||
try { |
||||
for (Map.Entry<String, String> entry : paramMap.entrySet()) { |
||||
urlBuilder.append(URLEncoder.encode(entry.getKey(), "utf-8")). |
||||
append("="). |
||||
append(URLEncoder.encode(entry.getValue(), "utf-8")). |
||||
append("&"); |
||||
} |
||||
} catch (Exception e) { |
||||
logger.error(ERROR_MESSAGE, e.getMessage()); |
||||
} |
||||
urlBuilder.deleteCharAt(urlBuilder.length() - 1); |
||||
} |
||||
request.url(urlBuilder.toString()); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 初始化post方法 |
||||
* |
||||
* @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw false等于普通的表单提交 |
||||
* @return ok http utils |
||||
*/ |
||||
public OkHttpUtils post(boolean isJsonPost) { |
||||
RequestBody requestBody; |
||||
if (isJsonPost) { |
||||
String json = ""; |
||||
if (paramMap != null) { |
||||
json = JSON.toJSONString(paramMap); |
||||
} |
||||
requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); |
||||
} else { |
||||
FormBody.Builder formBody = new FormBody.Builder(); |
||||
if (paramMap != null) { |
||||
paramMap.forEach(formBody::add); |
||||
} |
||||
requestBody = formBody.build(); |
||||
} |
||||
request = new Request.Builder().post(requestBody).url(url); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 同步请求 |
||||
* |
||||
* @return string |
||||
*/ |
||||
public String sync() { |
||||
setHeader(request); |
||||
try { |
||||
Response response = okHttpClient.newCall(request.build()).execute(); |
||||
assert response.body() != null; |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
return "请求失败:" + e.getMessage(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 异步请求,有返回值 |
||||
* |
||||
* @return the string |
||||
*/ |
||||
public String async() { |
||||
StringBuilder buffer = new StringBuilder(""); |
||||
setHeader(request); |
||||
okHttpClient.newCall(request.build()).enqueue(new Callback() { |
||||
@Override |
||||
public void onFailure(Call call, IOException e) { |
||||
buffer.append("请求出错:").append(e.getMessage()); |
||||
} |
||||
|
||||
@Override |
||||
public void onResponse(Call call, Response response) throws IOException { |
||||
if (response.body() != null) { |
||||
buffer.append(response.body().string()); |
||||
getSemaphoreInstance().release(); |
||||
} |
||||
} |
||||
}); |
||||
try { |
||||
getSemaphoreInstance().acquire(); |
||||
} catch (Exception e) { |
||||
logger.error(ERROR_MESSAGE, e.getMessage()); |
||||
} |
||||
return buffer.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 异步请求,带有接口回调 |
||||
* |
||||
* @param callBack call back |
||||
*/ |
||||
public void async(ICallBack callBack) { |
||||
setHeader(request); |
||||
okHttpClient.newCall(request.build()).enqueue(new Callback() { |
||||
@Override |
||||
public void onFailure(Call call, IOException e) { |
||||
callBack.onFailure(call, e.getMessage()); |
||||
} |
||||
|
||||
@Override |
||||
public void onResponse(Call call, Response response) throws IOException { |
||||
if (response.body() != null) { |
||||
callBack.onSuccessful(call, response.body().string()); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 为request添加请求头 |
||||
* |
||||
* @param request |
||||
*/ |
||||
private void setHeader(Request.Builder request) { |
||||
if (headerMap != null) { |
||||
try { |
||||
for (Map.Entry<String, String> entry : headerMap.entrySet()) { |
||||
request.addHeader(entry.getKey(), entry.getValue()); |
||||
} |
||||
} catch (Exception e) { |
||||
logger.error(ERROR_MESSAGE, e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 自定义一个接口回调 |
||||
*/ |
||||
public interface ICallBack { |
||||
|
||||
/** |
||||
* On successful * |
||||
* |
||||
* @param call call |
||||
* @param data data |
||||
*/ |
||||
void onSuccessful(Call call, String data); |
||||
|
||||
/** |
||||
* On failure * |
||||
* |
||||
* @param call call |
||||
* @param errorMsg error msg |
||||
*/ |
||||
void onFailure(Call call, String errorMsg); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Main |
||||
* |
||||
* @param args args |
||||
*/ |
||||
public static void main(String[] args) { |
||||
String tokenJson = OkHttpUtils.builder() |
||||
.url("https://10.1.50.198") |
||||
.addParam("client_id", "pbase_account") |
||||
.addParam("client_secret", "bed0bfd22d87b7bbab9b1d43191ddd57") |
||||
.addParam("grant_type", "client_credentials") |
||||
.post(false) |
||||
.sync(); |
||||
logger.info(tokenJson); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,117 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.MessageDigest; |
||||
|
||||
/** |
||||
* 密码加密 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class PasswordEncoder { |
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(PasswordEncoder.class); |
||||
|
||||
|
||||
private final static String[] HEX_DIGITS = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", |
||||
"e", "f"}; |
||||
|
||||
private final static String MD5 = "MD5"; |
||||
|
||||
private Object salt; |
||||
private String algorithm; |
||||
|
||||
public PasswordEncoder(Object salt) { |
||||
this(salt, MD5); |
||||
} |
||||
|
||||
public PasswordEncoder(Object salt, String algorithm) { |
||||
this.salt = salt; |
||||
this.algorithm = algorithm; |
||||
} |
||||
|
||||
/** |
||||
* 密码加密 |
||||
* |
||||
* @param rawPass 密码 |
||||
* @return 加密后 |
||||
*/ |
||||
public String encode(String rawPass) { |
||||
String result = null; |
||||
try { |
||||
MessageDigest md = MessageDigest.getInstance(algorithm); |
||||
// 加密后的字符串
|
||||
result = byteArrayToHexString(md.digest(mergePasswordAndSalt(rawPass).getBytes(StandardCharsets.UTF_8))); |
||||
} catch (Exception e) { |
||||
logger.error(e.toString(), e); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 密码匹配验证 |
||||
* |
||||
* @param encPass 密文 |
||||
* @param rawPass 明文 |
||||
* @return 是否匹配 |
||||
*/ |
||||
public boolean matches(String encPass, String rawPass) { |
||||
String pass1 = "" + encPass; |
||||
String pass2 = encode(rawPass); |
||||
|
||||
return pass1.equals(pass2); |
||||
} |
||||
|
||||
private String mergePasswordAndSalt(String password) { |
||||
if (password == null) { |
||||
password = ""; |
||||
} |
||||
|
||||
if ((salt == null) || "".equals(salt)) { |
||||
return password; |
||||
} else { |
||||
return password + "{" + salt.toString() + "}"; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 转换字节数组为16进制字串 |
||||
* |
||||
* @param b 字节数组 |
||||
* @return 16进制字串 |
||||
*/ |
||||
private String byteArrayToHexString(byte[] b) { |
||||
StringBuilder resultSb = new StringBuilder(); |
||||
for (byte value : b) { |
||||
resultSb.append(byteToHexString(value)); |
||||
} |
||||
return resultSb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 将字节转换为16进制 |
||||
* |
||||
* @param b 字节 |
||||
* @return 16进制 |
||||
*/ |
||||
private static String byteToHexString(byte b) { |
||||
int n = b; |
||||
if (n < 0) { |
||||
n = 256 + n; |
||||
} |
||||
int d1 = n / 16; |
||||
int d2 = n % 16; |
||||
return HEX_DIGITS[d1] + HEX_DIGITS[d2]; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
|
||||
/** |
||||
* 密码工具类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class PasswordUtils { |
||||
|
||||
/** |
||||
* 匹配密码 |
||||
* |
||||
* @param salt 盐 |
||||
* @param rawPass 明文 |
||||
* @param encPass 密文 |
||||
* @return 是否匹配 |
||||
*/ |
||||
public static boolean matches(String salt, String rawPass, String encPass) { |
||||
return new PasswordEncoder(salt).matches(encPass, rawPass); |
||||
} |
||||
|
||||
/** |
||||
* 明文密码加密 |
||||
* |
||||
* @param rawPass 明文 |
||||
* @param salt 盐 |
||||
* @reture 加密后 |
||||
*/ |
||||
public static String encode(String rawPass, String salt) { |
||||
return new PasswordEncoder(salt).encode(rawPass); |
||||
} |
||||
|
||||
/** |
||||
* 获取加密盐 |
||||
* |
||||
* @return 盐值 |
||||
*/ |
||||
public static String getSalt() { |
||||
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 20); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,113 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.exception.code.ResponseCodeInterface; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 返回值R |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class R { |
||||
|
||||
|
||||
|
||||
/** |
||||
* 请求响应code,0为成功 其他为失败 |
||||
*/ |
||||
@ApiModelProperty(value = "请求响应code,200为成功 其他为失败", name = "code") |
||||
private int code; |
||||
|
||||
/** |
||||
* 响应异常码详细信息 |
||||
*/ |
||||
@ApiModelProperty(value = "响应异常码详细信息", name = "msg") |
||||
private String msg; |
||||
|
||||
@ApiModelProperty(value = "需要返回的数据", name = "data") |
||||
private Object data; |
||||
|
||||
public R(int code, Object data) { |
||||
this.code = code; |
||||
this.data = data; |
||||
this.msg = null; |
||||
} |
||||
|
||||
public R(int code, String msg, Object data) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
this.data = data; |
||||
} |
||||
|
||||
public R(int code, String msg) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
this.data = null; |
||||
} |
||||
|
||||
public R() { |
||||
this.code = BaseResponseCode.SUCCESS.getCode(); |
||||
this.msg = BaseResponseCode.SUCCESS.getMsg(); |
||||
this.data = null; |
||||
} |
||||
|
||||
public R(Object data) { |
||||
this.data = data; |
||||
this.code = BaseResponseCode.SUCCESS.getCode(); |
||||
this.msg = BaseResponseCode.SUCCESS.getMsg(); |
||||
} |
||||
|
||||
public R(ResponseCodeInterface responseCodeInterface) { |
||||
this.data = null; |
||||
this.code = responseCodeInterface.getCode(); |
||||
this.msg = responseCodeInterface.getMsg(); |
||||
} |
||||
|
||||
public R(ResponseCodeInterface responseCodeInterface, Object data) { |
||||
this.data = data; |
||||
this.code = responseCodeInterface.getCode(); |
||||
this.msg = responseCodeInterface.getMsg(); |
||||
} |
||||
|
||||
/** |
||||
* 操作成功 data为null |
||||
*/ |
||||
public static R success() { |
||||
return new R(); |
||||
} |
||||
|
||||
/** |
||||
* 操作成功 data 不为null |
||||
*/ |
||||
public static R success(Object data) { |
||||
return new R(data); |
||||
} |
||||
|
||||
/** |
||||
* 操作失败 data 不为null |
||||
*/ |
||||
public static R fail(String msg) { |
||||
return new R(BaseResponseCode.OPERATION_ERROR.getCode(), msg); |
||||
} |
||||
|
||||
/** |
||||
* 自定义返回 data为null |
||||
*/ |
||||
public static R getResult(int code, String msg) { |
||||
return new R(code, msg); |
||||
} |
||||
|
||||
/** |
||||
* 自定义返回 入参一般是异常code枚举 data为空 |
||||
*/ |
||||
public static R getResult(BaseResponseCode responseCode) { |
||||
return new R(responseCode); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ApplicationContextAware; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* SpringContextUtils |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Component |
||||
public class SpringContextUtils implements ApplicationContextAware { |
||||
private static ApplicationContext applicationContext; |
||||
|
||||
@Override |
||||
public void setApplicationContext(ApplicationContext applicationContext) |
||||
throws BeansException { |
||||
SpringContextUtils.applicationContext = applicationContext; |
||||
} |
||||
|
||||
public static Object getBean(String name) { |
||||
try { |
||||
return applicationContext.getBean(name); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import org.apache.commons.lang.StringUtils; |
||||
|
||||
import javax.validation.ConstraintViolation; |
||||
import javax.validation.Validation; |
||||
import javax.validation.Validator; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* hibernate-validator校验工具类 |
||||
* |
||||
*/ |
||||
public class ValidatorUtils { |
||||
private static Validator validator; |
||||
|
||||
static { |
||||
validator = Validation.buildDefaultValidatorFactory().getValidator(); |
||||
} |
||||
|
||||
/** |
||||
* 校验对象 |
||||
* @param object 待校验对象 |
||||
* @param groups 待校验的组 |
||||
* @throws BusinessException 校验不通过,则报RRException异常 |
||||
*/ |
||||
public static void validateEntity(Object object, Class<?>... groups) |
||||
throws BusinessException { |
||||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); |
||||
if (!constraintViolations.isEmpty()) { |
||||
ConstraintViolation<Object> constraint = (ConstraintViolation<Object>)constraintViolations.iterator().next(); |
||||
throw new BusinessException(constraint.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 空判断处理 |
||||
* @param str |
||||
* @param message |
||||
*/ |
||||
public static void isBlank(Object str, String message) { |
||||
if (str == null) { |
||||
throw new BusinessException(message); |
||||
} |
||||
if (str instanceof String) { |
||||
if (StringUtils.isBlank(String.valueOf(str))) { |
||||
throw new BusinessException(message); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.wf.captcha.ArithmeticCaptcha; |
||||
import com.wf.captcha.utils.CaptchaUtil; |
||||
import io.swagger.annotations.Api; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* 验证码相关 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Api(tags = "验证码相关") |
||||
@RestController |
||||
@Slf4j |
||||
@RequestMapping("/sys") |
||||
public class CaptchaController { |
||||
/** |
||||
* 获取验证码图片 |
||||
* Gets captcha code. |
||||
* |
||||
* @param request the request |
||||
* @param response the response |
||||
* @throws IOException the io exception |
||||
*/ |
||||
@RequestMapping("/getVerify") |
||||
public void getCaptchaCode(HttpServletRequest request, HttpServletResponse response) throws IOException { |
||||
ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48); |
||||
captcha.setLen(2); |
||||
CaptchaUtil.out(captcha, request, response); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,93 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysDept; |
||||
import com.huoran.iasf.service.DeptService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.Logical; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 部门管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@RestController |
||||
@Api(tags = "组织模块-机构管理") |
||||
public class DeptController { |
||||
@Resource |
||||
private DeptService deptService; |
||||
|
||||
@PostMapping("/dept") |
||||
@ApiOperation(value = "新增组织接口") |
||||
@LogAnnotation(title = "机构管理", action = "新增组织") |
||||
@RequiresPermissions("sys:dept:add") |
||||
public R addDept(@RequestBody @Valid SysDept vo) { |
||||
deptService.addDept(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/dept/{id}") |
||||
@ApiOperation(value = "删除组织接口") |
||||
@LogAnnotation(title = "机构管理", action = "删除组织") |
||||
@RequiresPermissions("sys:dept:deleted") |
||||
public R deleted(@PathVariable("id") String id) { |
||||
deptService.deleted(id); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/dept") |
||||
@ApiOperation(value = "更新组织信息接口") |
||||
@LogAnnotation(title = "机构管理", action = "更新组织信息") |
||||
@RequiresPermissions("sys:dept:update") |
||||
public R updateDept(@RequestBody SysDept vo) { |
||||
if (StringUtils.isEmpty(vo.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
deptService.updateDept(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/dept/{id}") |
||||
@ApiOperation(value = "查询组织详情接口") |
||||
@LogAnnotation(title = "机构管理", action = "查询组织详情") |
||||
@RequiresPermissions("sys:dept:detail") |
||||
public R detailInfo(@PathVariable("id") String id) { |
||||
return R.success(deptService.getById(id)); |
||||
} |
||||
|
||||
@GetMapping("/dept/tree") |
||||
@ApiOperation(value = "树型组织列表接口") |
||||
@LogAnnotation(title = "机构管理", action = "树型组织列表") |
||||
@RequiresPermissions(value = {"sys:user:list", "sys:user:update", "sys:user:add", "sys:dept:add", "sys:dept:update"}, logical = Logical.OR) |
||||
public R getTree(@RequestParam(required = false) String deptId) { |
||||
return R.success(deptService.deptTreeList(deptId, false)); |
||||
} |
||||
|
||||
@GetMapping("/depts") |
||||
@ApiOperation(value = "获取机构列表接口") |
||||
@LogAnnotation(title = "机构管理", action = "获取所有组织机构") |
||||
@RequiresPermissions("sys:dept:list") |
||||
public R getDeptAll() { |
||||
List<SysDept> deptList = deptService.list(); |
||||
deptList.parallelStream().forEach(entity -> { |
||||
SysDept parentDept = deptService.getById(entity.getPid()); |
||||
if (parentDept != null) { |
||||
entity.setPidName(parentDept.getName()); |
||||
} |
||||
}); |
||||
return R.success(deptList); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.service.HomeService; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
|
||||
/** |
||||
* 首页 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sys") |
||||
@Api(tags = "首页数据") |
||||
public class HomeController { |
||||
@Resource |
||||
private HomeService homeService; |
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
|
||||
@GetMapping("/home") |
||||
@ApiOperation(value = "获取首页数据接口") |
||||
public R getHomeInfo() { |
||||
//通过access_token拿userId
|
||||
String userId = httpSessionService.getCurrentUserId(); |
||||
R result = R.success(); |
||||
result.setData(homeService.getHomeInfo(userId)); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,148 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysPermission; |
||||
import com.huoran.iasf.service.PermissionService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.Logical; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.validation.Valid; |
||||
|
||||
/** |
||||
* 菜单权限管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@RestController |
||||
@Api(tags = "组织模块-菜单权限管理") |
||||
public class PermissionController { |
||||
|
||||
@Resource |
||||
private PermissionService permissionService; |
||||
|
||||
@PostMapping("/permission") |
||||
@ApiOperation(value = "新增菜单权限接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "新增菜单权限") |
||||
@RequiresPermissions("sys:permission:add") |
||||
public R addPermission(@RequestBody @Valid SysPermission vo) { |
||||
verifyFormPid(vo); |
||||
vo.setStatus(1); |
||||
permissionService.save(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/permission/{id}") |
||||
@ApiOperation(value = "删除菜单权限接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "删除菜单权限") |
||||
@RequiresPermissions("sys:permission:deleted") |
||||
public R deleted(@PathVariable("id") String id) { |
||||
permissionService.deleted(id); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/permission") |
||||
@ApiOperation(value = "更新菜单权限接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "更新菜单权限") |
||||
@RequiresPermissions("sys:permission:update") |
||||
public R updatePermission(@RequestBody @Valid SysPermission vo) { |
||||
if (StringUtils.isEmpty(vo.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
SysPermission sysPermission = permissionService.getById(vo.getId()); |
||||
if (null == sysPermission) { |
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR); |
||||
} |
||||
// 只有类型变更或者所属菜单变更
|
||||
if (sysPermission.getType().equals(vo.getType()) || !sysPermission.getPid().equals(vo.getPid())) { |
||||
verifyFormPid(vo); |
||||
} |
||||
permissionService.updatePermission(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/permission/{id}") |
||||
@ApiOperation(value = "查询菜单权限接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "查询菜单权限") |
||||
@RequiresPermissions("sys:permission:detail") |
||||
public R detailInfo(@PathVariable("id") String id) { |
||||
return R.success(permissionService.getById(id)); |
||||
|
||||
} |
||||
|
||||
@GetMapping("/permissions") |
||||
@ApiOperation(value = "获取所有菜单权限接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "获取所有菜单权限") |
||||
@RequiresPermissions("sys:permission:list") |
||||
public R getAllMenusPermission() { |
||||
return R.success(permissionService.selectAll()); |
||||
} |
||||
|
||||
@GetMapping("/permission/tree") |
||||
@ApiOperation(value = "获取所有目录菜单树接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树") |
||||
@RequiresPermissions(value = {"sys:permission:update", "sys:permission:add"}, logical = Logical.OR) |
||||
public R getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) { |
||||
return R.success(permissionService.selectAllMenuByTree(permissionId)); |
||||
} |
||||
|
||||
@GetMapping("/permission/tree/all") |
||||
@ApiOperation(value = "获取所有目录菜单树接口") |
||||
@LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树") |
||||
@RequiresPermissions(value = {"sys:role:update", "sys:role:add"}, logical = Logical.OR) |
||||
public R getAllPermissionTree() { |
||||
return R.success(permissionService.selectAllByTree()); |
||||
} |
||||
|
||||
/** |
||||
* 操作后的菜单类型是目录的时候 父级必须为目录 |
||||
* 操作后的菜单类型是菜单的时候,父类必须为目录类型 |
||||
* 操作后的菜单类型是按钮的时候 父类必须为菜单类型 |
||||
*/ |
||||
private void verifyFormPid(SysPermission sysPermission) { |
||||
SysPermission parent; |
||||
parent = permissionService.getById(sysPermission.getPid()); |
||||
switch (sysPermission.getType()) { |
||||
case 1: |
||||
if (parent != null) { |
||||
if (parent.getType() != 1) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR); |
||||
} |
||||
} else if (!"0".equals(sysPermission.getPid())) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR); |
||||
} |
||||
break; |
||||
case 2: |
||||
if (parent == null || parent.getType() != 1) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_MENU_ERROR); |
||||
} |
||||
if (StringUtils.isEmpty(sysPermission.getUrl())) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL); |
||||
} |
||||
|
||||
break; |
||||
case 3: |
||||
if (parent == null || parent.getType() != 2) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_BTN_ERROR); |
||||
} |
||||
if (StringUtils.isEmpty(sysPermission.getPerms())) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_PERMS_NULL); |
||||
} |
||||
if (StringUtils.isEmpty(sysPermission.getUrl())) { |
||||
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL); |
||||
} |
||||
break; |
||||
default: |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
import com.huoran.iasf.entity.SysRoleDeptEntity; |
||||
import com.huoran.iasf.service.RoleService; |
||||
import com.huoran.iasf.service.SysRoleDeptService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.validation.Valid; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 角色管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@RestController |
||||
@Api(tags = "组织模块-角色管理") |
||||
public class RoleController { |
||||
@Resource |
||||
private RoleService roleService; |
||||
@Resource |
||||
private SysRoleDeptService sysRoleDeptService; |
||||
|
||||
@PostMapping("/role") |
||||
@ApiOperation(value = "新增角色接口") |
||||
@LogAnnotation(title = "角色管理", action = "新增角色") |
||||
@RequiresPermissions("sys:role:add") |
||||
public R addRole(@RequestBody @Valid SysRole vo) { |
||||
roleService.addRole(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/role/{id}") |
||||
@ApiOperation(value = "删除角色接口") |
||||
@LogAnnotation(title = "角色管理", action = "删除角色") |
||||
@RequiresPermissions("sys:role:deleted") |
||||
public R deleted(@PathVariable("id") String id) { |
||||
roleService.deletedRole(id); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/role") |
||||
@ApiOperation(value = "更新角色信息接口") |
||||
@LogAnnotation(title = "角色管理", action = "更新角色信息") |
||||
@RequiresPermissions("sys:role:update") |
||||
public R updateDept(@RequestBody SysRole vo) { |
||||
if (StringUtils.isEmpty(vo.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
roleService.updateRole(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PostMapping("/role/bindDept") |
||||
@ApiOperation(value = "绑定角色部门接口") |
||||
@LogAnnotation(title = "角色管理", action = "绑定角色部门信息") |
||||
@RequiresPermissions("sys:role:bindDept") |
||||
public R bindDept(@RequestBody SysRole vo) { |
||||
if (StringUtils.isEmpty(vo.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
if (roleService.getById(vo.getId()) == null) { |
||||
return R.fail("获取角色失败"); |
||||
} |
||||
|
||||
//先删除所有绑定
|
||||
sysRoleDeptService.remove(Wrappers.<SysRoleDeptEntity>lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId())); |
||||
//如果不是自定义
|
||||
if (vo.getDataScope() != 2) { |
||||
vo.setDepts(null); |
||||
} |
||||
if (!CollectionUtils.isEmpty(vo.getDepts())) { |
||||
List<SysRoleDeptEntity> list = new ArrayList<>(); |
||||
for (String deptId : vo.getDepts()) { |
||||
SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity(); |
||||
sysRoleDeptEntity.setDeptId(deptId); |
||||
sysRoleDeptEntity.setRoleId(vo.getId()); |
||||
list.add(sysRoleDeptEntity); |
||||
} |
||||
sysRoleDeptService.saveBatch(list); |
||||
} |
||||
roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope())); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/role/{id}") |
||||
@ApiOperation(value = "查询角色详情接口") |
||||
@LogAnnotation(title = "角色管理", action = "查询角色详情") |
||||
@RequiresPermissions("sys:role:detail") |
||||
public R detailInfo(@PathVariable("id") String id) { |
||||
return R.success(roleService.detailInfo(id)); |
||||
} |
||||
|
||||
@PostMapping("/roles") |
||||
@ApiOperation(value = "分页获取角色信息接口") |
||||
@LogAnnotation(title = "角色管理", action = "分页获取角色信息") |
||||
@RequiresPermissions("sys:role:list") |
||||
@SuppressWarnings("unchecked") |
||||
public R pageInfo(@RequestBody SysRole vo) { |
||||
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(); |
||||
if (!StringUtils.isEmpty(vo.getName())) { |
||||
queryWrapper.like(SysRole::getName, vo.getName()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getStartTime())) { |
||||
queryWrapper.gt(SysRole::getCreateTime, vo.getStartTime()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getEndTime())) { |
||||
queryWrapper.lt(SysRole::getCreateTime, vo.getEndTime()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getStatus())) { |
||||
queryWrapper.eq(SysRole::getStatus, vo.getStatus()); |
||||
} |
||||
queryWrapper.orderByDesc(SysRole::getCreateTime); |
||||
return R.success(roleService.page(vo.getQueryPage(), queryWrapper)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.service.RolePermissionService; |
||||
import com.huoran.iasf.vo.req.RolePermissionOperationReqVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.Logical; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.validation.Valid; |
||||
|
||||
/** |
||||
* 角色和菜单关联 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@RestController |
||||
@Api(tags = "组织管理-角色和菜单关联接口") |
||||
public class RolePermissionController { |
||||
@Resource |
||||
private RolePermissionService rolePermissionService; |
||||
|
||||
@PostMapping("/role/permission") |
||||
@ApiOperation(value = "修改或者新增角色菜单权限接口") |
||||
@LogAnnotation(title = "角色和菜单关联接口", action = "修改或者新增角色菜单权限") |
||||
@RequiresPermissions(value = {"sys:role:update", "sys:role:add"}, logical = Logical.OR) |
||||
public R operationRolePermission(@RequestBody @Valid RolePermissionOperationReqVO vo) { |
||||
rolePermissionService.addRolePermission(vo); |
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,79 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.DataScope; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysContentEntity; |
||||
import com.huoran.iasf.service.SysContentService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 文章管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Api(tags = "文章管理") |
||||
@RestController |
||||
@RequestMapping("/sysContent") |
||||
public class SysContentController { |
||||
@Resource |
||||
private SysContentService sysContentService; |
||||
|
||||
|
||||
@ApiOperation(value = "新增") |
||||
@PostMapping("/add") |
||||
@RequiresPermissions("sysContent:add") |
||||
public R add(@RequestBody SysContentEntity sysContent) { |
||||
sysContentService.save(sysContent); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "删除") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysContent:delete") |
||||
public R delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) { |
||||
sysContentService.removeByIds(ids); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "更新") |
||||
@PutMapping("/update") |
||||
@RequiresPermissions("sysContent:update") |
||||
public R update(@RequestBody SysContentEntity sysContent) { |
||||
sysContentService.updateById(sysContent); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysContent:list") |
||||
@DataScope |
||||
public R findListByPage(@RequestBody SysContentEntity sysContent) { |
||||
LambdaQueryWrapper<SysContentEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
//查询条件示例
|
||||
if (!StringUtils.isEmpty(sysContent.getTitle())) { |
||||
queryWrapper.like(SysContentEntity::getTitle, sysContent.getTitle()); |
||||
} |
||||
//数据权限示例, 需手动添加此条件 begin
|
||||
if (!CollectionUtils.isEmpty(sysContent.getCreateIds())) { |
||||
queryWrapper.in(SysContentEntity::getCreateId, sysContent.getCreateIds()); |
||||
} |
||||
//数据权限示例, 需手动添加此条件 end
|
||||
IPage<SysContentEntity> iPage = sysContentService.page(sysContent.getQueryPage(), queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
} |
@ -0,0 +1,96 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysDictDetailEntity; |
||||
import com.huoran.iasf.entity.SysDictEntity; |
||||
import com.huoran.iasf.service.SysDictDetailService; |
||||
import com.huoran.iasf.service.SysDictService; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 字典管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
// @Api(tags = "字典管理")
|
||||
// @RestController
|
||||
// @RequestMapping("/sysDict")
|
||||
public class SysDictController { |
||||
@Resource |
||||
private SysDictService sysDictService; |
||||
@Resource |
||||
private SysDictDetailService sysDictDetailService; |
||||
|
||||
|
||||
@ApiOperation(value = "新增") |
||||
@PostMapping("/add") |
||||
@RequiresPermissions("sysDict:add") |
||||
public R add(@RequestBody SysDictEntity sysDict) { |
||||
if (StringUtils.isEmpty(sysDict.getName())) { |
||||
return R.fail("字典名称不能为空"); |
||||
} |
||||
SysDictEntity q = sysDictService.getOne(Wrappers.<SysDictEntity>lambdaQuery().eq(SysDictEntity::getName, sysDict.getName())); |
||||
if (q != null) { |
||||
return R.fail("字典名称已存在"); |
||||
} |
||||
sysDictService.save(sysDict); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "删除") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysDict:delete") |
||||
public R delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) { |
||||
sysDictService.removeByIds(ids); |
||||
//删除detail
|
||||
sysDictDetailService.remove(Wrappers.<SysDictDetailEntity>lambdaQuery().in(SysDictDetailEntity::getDictId, ids)); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "更新") |
||||
@PutMapping("/update") |
||||
@RequiresPermissions("sysDict:update") |
||||
public R update(@RequestBody SysDictEntity sysDict) { |
||||
if (StringUtils.isEmpty(sysDict.getName())) { |
||||
return R.fail("字典名称不能为空"); |
||||
} |
||||
|
||||
SysDictEntity q = sysDictService.getOne(Wrappers.<SysDictEntity>lambdaQuery().eq(SysDictEntity::getName, sysDict.getName())); |
||||
if (q != null && !q.getId().equals(sysDict.getId())) { |
||||
return R.fail("字典名称已存在"); |
||||
} |
||||
|
||||
sysDictService.updateById(sysDict); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysDict:list") |
||||
public R findListByPage(@RequestBody SysDictEntity sysDict) { |
||||
LambdaQueryWrapper<SysDictEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
//查询条件示例
|
||||
if (!StringUtils.isEmpty(sysDict.getName())) { |
||||
queryWrapper.like(SysDictEntity::getName, sysDict.getName()); |
||||
queryWrapper.or(); |
||||
queryWrapper.like(SysDictEntity::getRemark, sysDict.getName()); |
||||
} |
||||
queryWrapper.orderByAsc(SysDictEntity::getName); |
||||
IPage<SysDictEntity> iPage = sysDictService.page(sysDict.getQueryPage(), queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,90 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysDictDetailEntity; |
||||
import com.huoran.iasf.service.SysDictDetailService; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 字典明细管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
// @Api(tags = "字典明细管理")
|
||||
// @RestController
|
||||
// @RequestMapping("/sysDictDetail")
|
||||
public class SysDictDetailController { |
||||
@Resource |
||||
private SysDictDetailService sysDictDetailService; |
||||
|
||||
@ApiOperation(value = "新增") |
||||
@PostMapping("/add") |
||||
@RequiresPermissions("sysDict:add") |
||||
public R add(@RequestBody SysDictDetailEntity sysDictDetail) { |
||||
if (StringUtils.isEmpty(sysDictDetail.getValue())) { |
||||
return R.fail("字典值不能为空"); |
||||
} |
||||
LambdaQueryWrapper<SysDictDetailEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
queryWrapper.eq(SysDictDetailEntity::getValue, sysDictDetail.getValue()); |
||||
queryWrapper.eq(SysDictDetailEntity::getDictId, sysDictDetail.getDictId()); |
||||
SysDictDetailEntity q = sysDictDetailService.getOne(queryWrapper); |
||||
if (q != null) { |
||||
return R.fail("字典名称-字典值已存在"); |
||||
} |
||||
sysDictDetailService.save(sysDictDetail); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "删除") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysDict:delete") |
||||
public R delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) { |
||||
sysDictDetailService.removeByIds(ids); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "更新") |
||||
@PutMapping("/update") |
||||
@RequiresPermissions("sysDict:update") |
||||
public R update(@RequestBody SysDictDetailEntity sysDictDetail) { |
||||
if (StringUtils.isEmpty(sysDictDetail.getValue())) { |
||||
return R.fail("字典值不能为空"); |
||||
} |
||||
LambdaQueryWrapper<SysDictDetailEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
queryWrapper.eq(SysDictDetailEntity::getValue, sysDictDetail.getValue()); |
||||
queryWrapper.eq(SysDictDetailEntity::getDictId, sysDictDetail.getDictId()); |
||||
SysDictDetailEntity q = sysDictDetailService.getOne(queryWrapper); |
||||
if (q != null && !q.getId().equals(sysDictDetail.getId())) { |
||||
return R.fail("字典名称-字典值已存在"); |
||||
} |
||||
|
||||
sysDictDetailService.updateById(sysDictDetail); |
||||
return R.success(); |
||||
} |
||||
|
||||
|
||||
@ApiOperation(value = "查询列表数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysDict:list") |
||||
public R findListByPage(@RequestBody SysDictDetailEntity sysDictDetail) { |
||||
if (StringUtils.isEmpty(sysDictDetail.getDictId())) { |
||||
return R.success(); |
||||
} |
||||
IPage<SysDictDetailEntity> iPage = sysDictDetailService.listByPage(sysDictDetail.getQueryPage(), sysDictDetail.getDictId()); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysFilesEntity; |
||||
import com.huoran.iasf.service.SysFilesService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.apache.shiro.authz.annotation.Logical; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 文件上传 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sysFiles") |
||||
@Api(tags = "文件管理") |
||||
public class SysFilesController { |
||||
@Resource |
||||
private SysFilesService sysFilesService; |
||||
|
||||
@ApiOperation(value = "新增") |
||||
@PostMapping("/upload") |
||||
@RequiresPermissions(value = {"sysFiles:add", "sysContent:update", "sysContent:add"}, logical = Logical.OR) |
||||
public R add(@RequestParam(value = "file") MultipartFile file) { |
||||
//判断文件是否空
|
||||
if (file == null || file.getOriginalFilename() == null || "".equalsIgnoreCase(file.getOriginalFilename().trim())) { |
||||
return R.fail("文件为空"); |
||||
} |
||||
return sysFilesService.saveFile(file); |
||||
} |
||||
|
||||
@ApiOperation(value = "删除") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysFiles:delete") |
||||
public R delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) { |
||||
sysFilesService.removeByIdsAndFiles(ids); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysFiles:list") |
||||
public R findListByPage(@RequestBody SysFilesEntity sysFiles) { |
||||
IPage<SysFilesEntity> iPage = sysFilesService.page(sysFiles.getQueryPage(), Wrappers.<SysFilesEntity>lambdaQuery().orderByDesc(SysFilesEntity::getCreateDate)); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,57 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysGenerator; |
||||
import com.huoran.iasf.service.ISysGeneratorService; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.io.IOUtils; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* 代码生成 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
// @Api(tags = "系统模块-代码生成")
|
||||
// @Slf4j
|
||||
// @RestController
|
||||
// @RequestMapping("/sysGenerator")
|
||||
public class SysGeneratorController { |
||||
@Resource |
||||
private ISysGeneratorService sysGeneratorService; |
||||
|
||||
/** |
||||
* 生成代码 |
||||
*/ |
||||
@ApiOperation(value = "生成") |
||||
@GetMapping("/gen") |
||||
@RequiresPermissions("sysGenerator:add") |
||||
public void code(String tables, HttpServletResponse response) throws IOException { |
||||
byte[] data = sysGeneratorService.generatorCode(tables.split(",")); |
||||
|
||||
response.reset(); |
||||
response.setHeader("Content-Disposition", "attachment; filename=\"manager.zip\""); |
||||
response.addHeader("Content-Length", "" + data.length); |
||||
response.setContentType("application/octet-stream; charset=UTF-8"); |
||||
|
||||
IOUtils.write(data, response.getOutputStream()); |
||||
} |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysGenerator:list") |
||||
public R findListByPage(@RequestBody SysGenerator vo) { |
||||
IPage<SysGenerator> iPage = sysGeneratorService.selectAllTables(vo.getQueryPage(), vo); |
||||
return R.success(iPage); |
||||
} |
||||
} |
@ -0,0 +1,178 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.job.utils.ScheduleJob; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysJobEntity; |
||||
import com.huoran.iasf.service.SysJobService; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.quartz.TriggerUtils; |
||||
import org.quartz.impl.triggers.CronTriggerImpl; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 定时任务 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
// @Api(tags = "定时任务")
|
||||
// @RestController
|
||||
// @RequestMapping("/sysJob")
|
||||
public class SysJobController { |
||||
@Resource |
||||
private SysJobService sysJobService; |
||||
|
||||
@ApiOperation(value = "新增") |
||||
@LogAnnotation(title = "新增") |
||||
@PostMapping("/add") |
||||
@RequiresPermissions("sysJob:add") |
||||
public R add(@RequestBody SysJobEntity sysJob) { |
||||
if (isValidExpression(sysJob.getCronExpression())) { |
||||
return R.fail("cron表达式有误"); |
||||
} |
||||
R R = ScheduleJob.judgeBean(sysJob.getBeanName()); |
||||
if (BaseResponseCode.SUCCESS.getCode() != R.getCode()) { |
||||
return R; |
||||
} |
||||
|
||||
sysJobService.saveJob(sysJob); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "删除") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysJob:delete") |
||||
@LogAnnotation(title = "删除") |
||||
public R delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) { |
||||
sysJobService.delete(ids); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "更新") |
||||
@PutMapping("/update") |
||||
@RequiresPermissions("sysJob:update") |
||||
@LogAnnotation(title = "更新") |
||||
public R update(@RequestBody SysJobEntity sysJob) { |
||||
if (isValidExpression(sysJob.getCronExpression())) { |
||||
return R.fail("cron表达式有误"); |
||||
} |
||||
R R = ScheduleJob.judgeBean(sysJob.getBeanName()); |
||||
if (BaseResponseCode.SUCCESS.getCode() != R.getCode()) { |
||||
return R; |
||||
} |
||||
|
||||
sysJobService.updateJobById(sysJob); |
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysJob:list") |
||||
public R findListByPage(@RequestBody SysJobEntity sysJob) { |
||||
LambdaQueryWrapper<SysJobEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
//查询条件示例
|
||||
if (!StringUtils.isEmpty(sysJob.getBeanName())) { |
||||
queryWrapper.like(SysJobEntity::getBeanName, sysJob.getBeanName()); |
||||
} |
||||
IPage<SysJobEntity> iPage = sysJobService.page(sysJob.getQueryPage(), queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 立即执行任务 |
||||
*/ |
||||
@ApiOperation(value = "立即执行任务") |
||||
@LogAnnotation(title = "立即执行任务") |
||||
@PostMapping("/run") |
||||
@RequiresPermissions("sysJob:run") |
||||
public R run(@RequestBody List<String> ids) { |
||||
sysJobService.run(ids); |
||||
|
||||
return R.success(); |
||||
} |
||||
|
||||
/** |
||||
* 暂停定时任务 |
||||
*/ |
||||
@ApiOperation(value = "暂停定时任务") |
||||
@LogAnnotation(title = "暂停定时任务") |
||||
@PostMapping("/pause") |
||||
@RequiresPermissions("sysJob:pause") |
||||
public R pause(@RequestBody List<String> ids) { |
||||
sysJobService.pause(ids); |
||||
|
||||
return R.success(); |
||||
} |
||||
|
||||
/** |
||||
* 恢复定时任务 |
||||
*/ |
||||
@ApiOperation(value = "恢复定时任务") |
||||
@LogAnnotation(title = "恢复定时任务") |
||||
@PostMapping("/resume") |
||||
@RequiresPermissions("sysJob:resume") |
||||
public R resume(@RequestBody List<String> ids) { |
||||
sysJobService.resume(ids); |
||||
return R.success(); |
||||
} |
||||
|
||||
/** |
||||
* 判断cron表达式 |
||||
* |
||||
* @param cronExpression cron表达式 |
||||
* @return 是否有误 |
||||
*/ |
||||
public static boolean isValidExpression(String cronExpression) { |
||||
CronTriggerImpl trigger = new CronTriggerImpl(); |
||||
try { |
||||
trigger.setCronExpression(cronExpression); |
||||
Date date = trigger.computeFirstFireTime(null); |
||||
return date == null || !date.after(new Date()); |
||||
} catch (Exception e) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
|
||||
@ApiOperation(value = "获取运行时间") |
||||
@LogAnnotation(title = "获取运行时间") |
||||
@PostMapping("/getRecentTriggerTime") |
||||
@RequiresPermissions("sysJob:add") |
||||
public R getRecentTriggerTime(String cron) { |
||||
List<String> list = new ArrayList<>(); |
||||
try { |
||||
CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); |
||||
cronTriggerImpl.setCronExpression(cron); |
||||
// 这个是重点,一行代码搞定
|
||||
List<Date> dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 5); |
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
for (Date date : dates) { |
||||
list.add(dateFormat.format(date)); |
||||
} |
||||
|
||||
} catch (ParseException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return R.success(list); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,55 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysJobLogEntity; |
||||
import com.huoran.iasf.service.SysJobLogService; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
|
||||
/** |
||||
* 定时任务日志 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
// @Api(tags = "定时任务日志")
|
||||
// @RestController
|
||||
// @RequestMapping("/sysJobLog")
|
||||
public class SysJobLogController { |
||||
@Resource |
||||
private SysJobLogService sysJobLogService; |
||||
|
||||
@ApiOperation(value = "查询分页数据") |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysJob:list") |
||||
public R findListByPage(@RequestBody SysJobLogEntity sysJobLog) { |
||||
LambdaQueryWrapper<SysJobLogEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
//查询条件示例
|
||||
if (!StringUtils.isEmpty(sysJobLog.getJobId())) { |
||||
queryWrapper.like(SysJobLogEntity::getJobId, sysJobLog.getJobId()); |
||||
} |
||||
queryWrapper.orderByDesc(SysJobLogEntity::getCreateTime); |
||||
IPage<SysJobLogEntity> iPage = sysJobLogService.page(sysJobLog.getQueryPage(), queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
@ApiOperation(value = "清空定时任务日志") |
||||
@DeleteMapping("/delete") |
||||
@RequiresPermissions("sysJob:delete") |
||||
@LogAnnotation(title = "清空") |
||||
public R delete() { |
||||
sysJobLogService.remove(Wrappers.emptyWrapper()); |
||||
return R.success(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysLog; |
||||
import com.huoran.iasf.service.LogService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 系统操作日志 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@Api(tags = "系统模块-系统操作日志管理") |
||||
@RestController |
||||
public class SysLogController { |
||||
@Resource |
||||
private LogService logService; |
||||
|
||||
@PostMapping("/logs") |
||||
@ApiOperation(value = "分页查询系统操作日志接口") |
||||
@LogAnnotation(title = "系统操作日志管理", action = "分页查询系统操作日志") |
||||
@RequiresPermissions("sys:log:list") |
||||
public R pageInfo(@RequestBody SysLog vo) { |
||||
LambdaQueryWrapper<SysLog> queryWrapper = Wrappers.lambdaQuery(); |
||||
if (!StringUtils.isEmpty(vo.getUsername())) { |
||||
queryWrapper.like(SysLog::getUsername, vo.getUsername()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getOperation())) { |
||||
queryWrapper.like(SysLog::getOperation, vo.getOperation()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getStartTime())) { |
||||
queryWrapper.gt(SysLog::getCreateTime, vo.getStartTime()); |
||||
} |
||||
if (!StringUtils.isEmpty(vo.getEndTime())) { |
||||
queryWrapper.lt(SysLog::getCreateTime, vo.getEndTime()); |
||||
} |
||||
queryWrapper.orderByDesc(SysLog::getCreateTime); |
||||
return R.success(logService.page(vo.getQueryPage(), queryWrapper)); |
||||
} |
||||
|
||||
@DeleteMapping("/logs") |
||||
@ApiOperation(value = "删除日志接口") |
||||
@LogAnnotation(title = "系统操作日志管理", action = "删除系统操作日志") |
||||
@RequiresPermissions("sys:log:deleted") |
||||
public R deleted(@RequestBody List<String> logIds) { |
||||
logService.removeByIds(logIds); |
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,194 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
import com.huoran.iasf.entity.SysUserRole; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import com.huoran.iasf.service.UserRoleService; |
||||
import com.huoran.iasf.service.UserService; |
||||
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; |
||||
import com.wf.captcha.utils.CaptchaUtil; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.SecurityUtils; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.apache.shiro.subject.Subject; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 用户管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RestController |
||||
@Api(tags = "组织模块-用户管理") |
||||
@RequestMapping("/sys") |
||||
@Slf4j |
||||
public class UserController { |
||||
@Resource |
||||
private UserService userService; |
||||
@Resource |
||||
private UserRoleService userRoleService; |
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
|
||||
@PostMapping(value = "/user/login") |
||||
@ApiOperation(value = "用户登录接口") |
||||
public R login(@RequestBody @Valid SysUser vo, HttpServletRequest request) { |
||||
//判断验证码
|
||||
if (!CaptchaUtil.ver(vo.getCaptcha(), request)) { |
||||
// 清除session中的验证码
|
||||
CaptchaUtil.clear(request); |
||||
return R.fail("验证码错误!"); |
||||
} |
||||
return R.success(userService.login(vo)); |
||||
} |
||||
|
||||
@PostMapping("/user/register") |
||||
@ApiOperation(value = "用户注册接口") |
||||
public R register(@RequestBody @Valid SysUser vo) { |
||||
userService.register(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/user/unLogin") |
||||
@ApiOperation(value = "引导客户端去登录") |
||||
public R unLogin() { |
||||
return R.getResult(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
|
||||
@PutMapping("/user") |
||||
@ApiOperation(value = "更新用户信息接口") |
||||
@LogAnnotation(title = "用户管理", action = "更新用户信息") |
||||
@RequiresPermissions("sys:user:update") |
||||
public R updateUserInfo(@RequestBody SysUser vo) { |
||||
if (StringUtils.isEmpty(vo.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
|
||||
userService.updateUserInfo(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/user/info") |
||||
@ApiOperation(value = "更新用户信息接口") |
||||
@LogAnnotation(title = "用户管理", action = "更新用户信息") |
||||
public R updateUserInfoById(@RequestBody SysUser vo) { |
||||
userService.updateUserInfoMy(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/user/{id}") |
||||
@ApiOperation(value = "查询用户详情接口") |
||||
@LogAnnotation(title = "用户管理", action = "查询用户详情") |
||||
@RequiresPermissions("sys:user:detail") |
||||
public R detailInfo(@PathVariable("id") String id) { |
||||
return R.success(userService.getById(id)); |
||||
} |
||||
|
||||
@GetMapping("/user") |
||||
@ApiOperation(value = "查询用户详情接口") |
||||
@LogAnnotation(title = "用户管理", action = "查询用户详情") |
||||
public R youSelfInfo() { |
||||
String userId = httpSessionService.getCurrentUserId(); |
||||
return R.success(userService.getById(userId)); |
||||
} |
||||
|
||||
@PostMapping("/users") |
||||
@ApiOperation(value = "分页获取用户列表接口") |
||||
@RequiresPermissions("sys:user:list") |
||||
@LogAnnotation(title = "用户管理", action = "分页获取用户列表") |
||||
public R pageInfo(@RequestBody SysUser vo) { |
||||
return R.success(userService.pageInfo(vo)); |
||||
} |
||||
|
||||
@PostMapping("/user") |
||||
@ApiOperation(value = "新增用户接口") |
||||
@RequiresPermissions("sys:user:add") |
||||
@LogAnnotation(title = "用户管理", action = "新增用户") |
||||
public R addUser(@RequestBody @Valid SysUser vo) { |
||||
userService.addUser(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/user/logout") |
||||
@ApiOperation(value = "退出接口") |
||||
@LogAnnotation(title = "用户管理", action = "退出") |
||||
public R logout() { |
||||
httpSessionService.abortUserByToken(); |
||||
Subject subject = SecurityUtils.getSubject(); |
||||
subject.logout(); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/user/pwd") |
||||
@ApiOperation(value = "修改密码接口") |
||||
@LogAnnotation(title = "用户管理", action = "更新密码") |
||||
public R updatePwd(@RequestBody SysUser vo) { |
||||
if (StringUtils.isEmpty(vo.getOldPwd()) || StringUtils.isEmpty(vo.getNewPwd())) { |
||||
return R.fail("旧密码与新密码不能为空"); |
||||
} |
||||
String userId = httpSessionService.getCurrentUserId(); |
||||
vo.setId(userId); |
||||
userService.updatePwd(vo); |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/user") |
||||
@ApiOperation(value = "删除用户接口") |
||||
@LogAnnotation(title = "用户管理", action = "删除用户") |
||||
@RequiresPermissions("sys:user:deleted") |
||||
public R deletedUser(@RequestBody @ApiParam(value = "用户id集合") List<String> userIds) { |
||||
//删除用户, 删除redis的绑定的角色跟权限
|
||||
httpSessionService.abortUserByUserIds(userIds); |
||||
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
||||
queryWrapper.in(SysUser::getId, userIds); |
||||
userService.remove(queryWrapper); |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/user/roles/{userId}") |
||||
@ApiOperation(value = "赋予角色-获取所有角色接口") |
||||
@LogAnnotation(title = "用户管理", action = "赋予角色-获取所有角色接口") |
||||
@RequiresPermissions("sys:user:role:detail") |
||||
public R getUserOwnRole(@PathVariable("userId") String userId) { |
||||
R result = R.success(); |
||||
result.setData(userService.getUserOwnRole(userId)); |
||||
return result; |
||||
} |
||||
|
||||
@PutMapping("/user/roles/{userId}") |
||||
@ApiOperation(value = "赋予角色-用户赋予角色接口") |
||||
@LogAnnotation(title = "用户管理", action = "赋予角色-用户赋予角色接口") |
||||
@RequiresPermissions("sys:user:update:role") |
||||
public R setUserOwnRole(@PathVariable("userId") String userId, @RequestBody List<String> roleIds) { |
||||
|
||||
LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.lambdaQuery(); |
||||
queryWrapper.eq(SysUserRole::getUserId, userId); |
||||
userRoleService.remove(queryWrapper); |
||||
if (!CollectionUtils.isEmpty(roleIds)) { |
||||
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); |
||||
reqVO.setUserId(userId); |
||||
reqVO.setRoleIds(roleIds); |
||||
userRoleService.addUserRoleInfo(reqVO); |
||||
} |
||||
//刷新权限
|
||||
httpSessionService.refreshUerId(userId); |
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.service.UserRoleService; |
||||
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.validation.Valid; |
||||
|
||||
/** |
||||
* 用户和角色关联 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RequestMapping("/sys") |
||||
@RestController |
||||
@Api(tags = "组织管理-用户和角色关联接口") |
||||
public class UserRoleController { |
||||
@Resource |
||||
private UserRoleService userRoleService; |
||||
|
||||
@PostMapping("/user/role") |
||||
@ApiOperation(value = "修改或者新增用户角色接口") |
||||
@LogAnnotation(title = "用户和角色关联接口", action = "修改或者新增用户角色") |
||||
public R operationUserRole(@RequestBody @Valid UserRoleOperationReqVO vo) { |
||||
userRoleService.addUserRoleInfo(vo); |
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.huoran.iasf.controller.api; |
||||
|
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.service.HttpApiSessionService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
|
||||
/** |
||||
* api test示例 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2020年5月11日 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/app/api") |
||||
@Api(tags = "test") |
||||
public class TestController { |
||||
|
||||
@Resource |
||||
HttpApiSessionService httpApiSessionService; |
||||
|
||||
@PostMapping("/login") |
||||
@ApiOperation(value = "登录接口") |
||||
public R login() { |
||||
//TODO 登录
|
||||
|
||||
//生成token
|
||||
String token = httpApiSessionService.geneJsonWebToken("123", "测试用户名"); |
||||
return R.success(token); |
||||
} |
||||
|
||||
|
||||
@GetMapping("/getCurUserInfo") |
||||
@ApiOperation(value = "获取当前登录人信息示例") |
||||
public R getAppUserInfo() { |
||||
//拿userId与userName
|
||||
String userId = httpApiSessionService.getCurrentUserId(); |
||||
String username = httpApiSessionService.getCurrentUsername(); |
||||
return R.success(); |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* BaseEntity |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class BaseEntity { |
||||
|
||||
@JSONField(serialize = false) |
||||
@TableField(exist = false) |
||||
private int page = 1; |
||||
|
||||
@JSONField(serialize = false) |
||||
@TableField(exist = false) |
||||
private int limit = 10; |
||||
|
||||
/** |
||||
* 数据权限:用户id |
||||
*/ |
||||
@TableField(exist = false) |
||||
private List<String> createIds; |
||||
|
||||
/** |
||||
* page条件 |
||||
* @param <T> |
||||
* @return |
||||
*/ |
||||
public <T> Page getQueryPage() { |
||||
return new Page<T>(page, limit); |
||||
} |
||||
} |
@ -0,0 +1,104 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 代码生成 列属性 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class ColumnEntity { |
||||
/** |
||||
* 列名 |
||||
*/ |
||||
private String columnName; |
||||
|
||||
/** |
||||
* 列名类型 |
||||
*/ |
||||
private String dataType; |
||||
|
||||
/** |
||||
* 列名备注 |
||||
*/ |
||||
private String comments; |
||||
|
||||
/** |
||||
* 属性名称(第一个字母大写),如:user_name => UserName |
||||
*/ |
||||
private String attrName; |
||||
|
||||
/** |
||||
* 属性名称(第一个字母小写),如:user_name => userName |
||||
*/ |
||||
private String attrname; |
||||
|
||||
/** |
||||
* 属性类型 |
||||
*/ |
||||
private String attrType; |
||||
|
||||
/** |
||||
* auto_increment |
||||
*/ |
||||
private String extra; |
||||
|
||||
public String getColumnName() { |
||||
return columnName; |
||||
} |
||||
|
||||
public void setColumnName(String columnName) { |
||||
this.columnName = columnName; |
||||
} |
||||
|
||||
public String getDataType() { |
||||
return dataType; |
||||
} |
||||
|
||||
public void setDataType(String dataType) { |
||||
this.dataType = dataType; |
||||
} |
||||
|
||||
public String getComments() { |
||||
return comments; |
||||
} |
||||
|
||||
public void setComments(String comments) { |
||||
this.comments = comments; |
||||
} |
||||
|
||||
public String getAttrname() { |
||||
return attrname; |
||||
} |
||||
|
||||
public void setAttrname(String attrname) { |
||||
this.attrname = attrname; |
||||
} |
||||
|
||||
public String getAttrName() { |
||||
return attrName; |
||||
} |
||||
|
||||
public void setAttrName(String attrName) { |
||||
this.attrName = attrName; |
||||
} |
||||
|
||||
public String getAttrType() { |
||||
return attrType; |
||||
} |
||||
|
||||
public void setAttrType(String attrType) { |
||||
this.attrType = attrType; |
||||
} |
||||
|
||||
public String getExtra() { |
||||
return extra; |
||||
} |
||||
|
||||
public void setExtra(String extra) { |
||||
this.extra = extra; |
||||
} |
||||
} |
@ -0,0 +1,78 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 内容管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_content") |
||||
public class SysContentEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键id |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* 主题 |
||||
*/ |
||||
@TableField("title") |
||||
private String title; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
@TableField("content") |
||||
private String content; |
||||
|
||||
/** |
||||
* 单个图片url |
||||
*/ |
||||
private String oneImg; |
||||
|
||||
/** |
||||
* 多个图片url |
||||
*/ |
||||
private String multipleImg; |
||||
|
||||
/** |
||||
* 关键字 |
||||
*/ |
||||
private String keywords; |
||||
|
||||
/** |
||||
* 类型(数据字典) |
||||
*/ |
||||
@TableField("type") |
||||
private String type; |
||||
|
||||
/** |
||||
* 创建人 |
||||
*/ |
||||
@TableField(value = "create_id", fill = FieldFill.INSERT) |
||||
private String createId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,54 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 部门 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class SysDept implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
private String deptNo; |
||||
|
||||
@NotBlank(message = "机构名称不能为空") |
||||
private String name; |
||||
|
||||
@NotBlank(message = "父级不能为空") |
||||
private String pid; |
||||
|
||||
@TableField(exist = false) |
||||
private String pidName; |
||||
|
||||
private Integer status; |
||||
|
||||
private String relationCode; |
||||
|
||||
private String deptManagerId; |
||||
|
||||
private String managerName; |
||||
|
||||
private String phone; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Integer deleted; |
||||
|
||||
} |
@ -0,0 +1,68 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 字典明细 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_dict_detail") |
||||
public class SysDictDetailEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* 字典标签 |
||||
*/ |
||||
@TableField("label") |
||||
private String label; |
||||
|
||||
/** |
||||
* 字典值 |
||||
*/ |
||||
@TableField("value") |
||||
private String value; |
||||
|
||||
/** |
||||
* 排序 |
||||
*/ |
||||
@TableField("sort") |
||||
private Integer sort; |
||||
|
||||
/** |
||||
* 字典id |
||||
*/ |
||||
@TableField("dict_id") |
||||
private String dictId; |
||||
|
||||
/** |
||||
* 创建日期 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 字典name |
||||
*/ |
||||
@TableField(exist = false) |
||||
private String dictName; |
||||
|
||||
} |
@ -0,0 +1,51 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 字典管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_dict") |
||||
public class SysDictEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* 字典名称 |
||||
*/ |
||||
@TableField("name") |
||||
private String name; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
@TableField("remark") |
||||
private String remark; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,51 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 文件上传 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_files") |
||||
public class SysFilesEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* URL地址 |
||||
*/ |
||||
@TableField("url") |
||||
private String url; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_date", fill = FieldFill.INSERT) |
||||
private Date createDate; |
||||
|
||||
@TableField("file_name") |
||||
private String fileName; |
||||
|
||||
@TableField("file_path") |
||||
private String filePath; |
||||
|
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 代码生成 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
public class SysGenerator extends BaseEntity implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private String tableName; |
||||
|
||||
private Date createTime; |
||||
|
||||
private String tableComment; |
||||
|
||||
} |
@ -0,0 +1,72 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 定时任务 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_job") |
||||
public class SysJobEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
/** |
||||
* 任务调度参数key |
||||
*/ |
||||
public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY"; |
||||
/** |
||||
* 任务id |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* spring bean名称 |
||||
*/ |
||||
@TableField("bean_name") |
||||
private String beanName; |
||||
|
||||
/** |
||||
* 参数 |
||||
*/ |
||||
@TableField("params") |
||||
private String params; |
||||
|
||||
/** |
||||
* cron表达式 |
||||
*/ |
||||
@TableField("cron_expression") |
||||
private String cronExpression; |
||||
|
||||
/** |
||||
* 任务状态 0:正常 1:暂停 |
||||
*/ |
||||
@TableField("status") |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
@TableField("remark") |
||||
private String remark; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,75 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 定时任务日志 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@TableName("sys_job_log") |
||||
public class SysJobLogEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 任务日志id |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* 任务id |
||||
*/ |
||||
@TableField("job_id") |
||||
private String jobId; |
||||
|
||||
/** |
||||
* spring bean名称 |
||||
*/ |
||||
@TableField("bean_name") |
||||
private String beanName; |
||||
|
||||
/** |
||||
* 参数 |
||||
*/ |
||||
@TableField("params") |
||||
private String params; |
||||
|
||||
/** |
||||
* 任务状态 0:成功 1:失败 |
||||
*/ |
||||
@TableField("status") |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 失败信息 |
||||
*/ |
||||
@TableField("error") |
||||
private String error; |
||||
|
||||
/** |
||||
* 耗时(单位:毫秒) |
||||
*/ |
||||
@TableField("times") |
||||
private Integer times; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 操作日志 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
public class SysLog extends BaseEntity implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
private String userId; |
||||
|
||||
private String username; |
||||
|
||||
private String operation; |
||||
|
||||
private Integer time; |
||||
|
||||
private String method; |
||||
|
||||
private String params; |
||||
|
||||
private String ip; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(exist = false) |
||||
private String startTime; |
||||
|
||||
@TableField(exist = false) |
||||
private String endTime; |
||||
|
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import javax.validation.constraints.NotNull; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 权限菜单 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class SysPermission implements Serializable { |
||||
|
||||
|
||||
@TableId |
||||
private String id; |
||||
|
||||
@NotBlank(message = "菜单权限名称不能为空") |
||||
private String name; |
||||
|
||||
private String perms; |
||||
|
||||
private String url; |
||||
|
||||
private String icon; |
||||
|
||||
private String target; |
||||
|
||||
@NotNull(message = "所属菜单不能为空") |
||||
private String pid; |
||||
|
||||
private Integer orderNum; |
||||
|
||||
@NotNull(message = "菜单权限类型不能为空") |
||||
private Integer type; |
||||
|
||||
/** |
||||
* 1正常 2禁用 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Integer deleted; |
||||
|
||||
@TableField(exist = false) |
||||
private String pidName; |
||||
|
||||
} |
@ -0,0 +1,66 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.huoran.iasf.vo.resp.DeptRespNodeVO; |
||||
import com.huoran.iasf.vo.resp.PermissionRespNode; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 角色 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
@Accessors(chain = true) |
||||
public class SysRole extends BaseEntity implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
@NotBlank(message = "名称不能为空") |
||||
private String name; |
||||
|
||||
private String description; |
||||
|
||||
private Integer status; |
||||
|
||||
private Integer dataScope; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Integer deleted; |
||||
|
||||
@TableField(exist = false) |
||||
private List<PermissionRespNode> permissionRespNodes; |
||||
@TableField(exist = false) |
||||
private List<DeptRespNodeVO> deptRespNodes; |
||||
|
||||
@TableField(exist = false) |
||||
private String startTime; |
||||
|
||||
@TableField(exist = false) |
||||
private String endTime; |
||||
|
||||
@TableField(exist = false) |
||||
private List<String> permissions; |
||||
|
||||
@TableField(exist = false) |
||||
private List<String> depts; |
||||
|
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 角色部门 |
||||
* |
||||
* @author cheney |
||||
* @email *****@mail.com |
||||
* @date 2020-09-27 17:30:15 |
||||
*/ |
||||
@Data |
||||
@TableName("sys_role_dept") |
||||
public class SysRoleDeptEntity extends BaseEntity implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId("id") |
||||
private String id; |
||||
|
||||
/** |
||||
* 角色id |
||||
*/ |
||||
@TableField("role_id") |
||||
private String roleId; |
||||
|
||||
/** |
||||
* 菜单权限id |
||||
*/ |
||||
@TableField("dept_id") |
||||
private String deptId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 角色权限 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class SysRolePermission implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
private String roleId; |
||||
|
||||
private String permissionId; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 用户 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
public class SysUser extends BaseEntity implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
@NotBlank(message = "账号不能为空") |
||||
private String username; |
||||
|
||||
private String salt; |
||||
|
||||
@NotBlank(message = "密码不能为空") |
||||
private String password; |
||||
|
||||
@TableField(exist = false) |
||||
private String oldPwd; |
||||
|
||||
@TableField(exist = false) |
||||
private String newPwd; |
||||
|
||||
private String phone; |
||||
|
||||
private String deptId; |
||||
|
||||
@TableField(exist = false) |
||||
private String deptName; |
||||
|
||||
@TableField(exist = false) |
||||
private String deptNo; |
||||
|
||||
|
||||
private String realName; |
||||
|
||||
private String nickName; |
||||
|
||||
private String email; |
||||
|
||||
private Integer status; |
||||
|
||||
private Integer sex; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Integer deleted; |
||||
|
||||
private String createId; |
||||
|
||||
private String updateId; |
||||
|
||||
private Integer createWhere; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@TableField(exist = false) |
||||
private String startTime; |
||||
|
||||
@TableField(exist = false) |
||||
private String endTime; |
||||
|
||||
@TableField(exist = false) |
||||
private List<String> roleIds; |
||||
|
||||
@TableField(exist = false) |
||||
private String captcha; |
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 用户角色 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class SysUserRole implements Serializable { |
||||
@TableId |
||||
private String id; |
||||
|
||||
private String userId; |
||||
|
||||
private String roleId; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,84 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 代码生成 表数据 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public class TableEntity { |
||||
//表的名称
|
||||
private String tableName; |
||||
//表的备注
|
||||
private String comments; |
||||
//表的主键
|
||||
private ColumnEntity pk; |
||||
//表的列名(不包含主键)
|
||||
private List<ColumnEntity> columns; |
||||
|
||||
//类名(第一个字母大写),如:sys_user => SysUser
|
||||
private String className; |
||||
//类名(第一个字母小写),如:sys_user => sysUser
|
||||
private String classname; |
||||
//类名(都小写),如:sys_user => sysuser
|
||||
private String classNameLower; |
||||
|
||||
public String getTableName() { |
||||
return tableName; |
||||
} |
||||
|
||||
public void setTableName(String tableName) { |
||||
this.tableName = tableName; |
||||
} |
||||
|
||||
public String getComments() { |
||||
return comments; |
||||
} |
||||
|
||||
public void setComments(String comments) { |
||||
this.comments = comments; |
||||
} |
||||
|
||||
public ColumnEntity getPk() { |
||||
return pk; |
||||
} |
||||
|
||||
public void setPk(ColumnEntity pk) { |
||||
this.pk = pk; |
||||
} |
||||
|
||||
public List<ColumnEntity> getColumns() { |
||||
return columns; |
||||
} |
||||
|
||||
public void setColumns(List<ColumnEntity> columns) { |
||||
this.columns = columns; |
||||
} |
||||
|
||||
public String getClassName() { |
||||
return className; |
||||
} |
||||
|
||||
public void setClassName(String className) { |
||||
this.className = className; |
||||
} |
||||
|
||||
public String getClassname() { |
||||
return classname; |
||||
} |
||||
|
||||
public void setClassname(String classname) { |
||||
this.classname = classname; |
||||
} |
||||
|
||||
public String getClassNameLower() { |
||||
return classNameLower; |
||||
} |
||||
|
||||
public void setClassNameLower(String classNameLower) { |
||||
this.classNameLower = classNameLower; |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.iasf.entity.SysGenerator; |
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 代码生成 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface GeneratorMapper extends BaseMapper<SysGenerator> { |
||||
|
||||
IPage<SysGenerator> selectAllTables(Page<SysGenerator> page, @Param(value = "vo") SysGenerator vo); |
||||
|
||||
Map<String, String> queryTable(String tableName); |
||||
|
||||
List<Map<String, String>> queryColumns(String tableName); |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysContentEntity; |
||||
|
||||
/** |
||||
* 内容管理 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysContentMapper extends BaseMapper<SysContentEntity> { |
||||
|
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysDept; |
||||
|
||||
/** |
||||
* 部门 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysDeptMapper extends BaseMapper<SysDept> { |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysDictDetailEntity; |
||||
|
||||
/** |
||||
* 字典详情 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysDictDetailMapper extends BaseMapper<SysDictDetailEntity> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysDictEntity; |
||||
|
||||
/** |
||||
* 字典 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysDictMapper extends BaseMapper<SysDictEntity> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysFilesEntity; |
||||
|
||||
/** |
||||
* 文件上传 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysFilesMapper extends BaseMapper<SysFilesEntity> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysJobLogEntity; |
||||
|
||||
/** |
||||
* 定时任务日志、 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysJobLogMapper extends BaseMapper<SysJobLogEntity> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysJobEntity; |
||||
|
||||
/** |
||||
* 定时任务 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysJobMapper extends BaseMapper<SysJobEntity> { |
||||
|
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysLog; |
||||
|
||||
/** |
||||
* 操作日志 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysLogMapper extends BaseMapper<SysLog> { |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysPermission; |
||||
|
||||
/** |
||||
* 菜单权限 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysPermissionMapper extends BaseMapper<SysPermission> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysRoleDeptEntity; |
||||
|
||||
/** |
||||
* 角色部门 |
||||
* |
||||
* @author cheney |
||||
* @email *****@mail.com |
||||
* @date 2020-09-27 17:30:15 |
||||
*/ |
||||
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDeptEntity> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
|
||||
/** |
||||
* 角色 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysRoleMapper extends BaseMapper<SysRole> { |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysRolePermission; |
||||
|
||||
/** |
||||
* 角色权限 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> { |
||||
|
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
|
||||
/** |
||||
* 用户 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysUserMapper extends BaseMapper<SysUser> { |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.huoran.iasf.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.huoran.iasf.entity.SysUserRole; |
||||
|
||||
/** |
||||
* 用户角色 Mapper |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { |
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysDept; |
||||
import com.huoran.iasf.vo.resp.DeptRespNodeVO; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 部门 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface DeptService extends IService<SysDept> { |
||||
|
||||
/** |
||||
* 添加部门 |
||||
* |
||||
* @param vo vo |
||||
*/ |
||||
void addDept(SysDept vo); |
||||
|
||||
/** |
||||
* 更新部门 |
||||
* |
||||
* @param vo vo |
||||
*/ |
||||
void updateDept(SysDept vo); |
||||
|
||||
/** |
||||
* 删除部门 |
||||
* |
||||
* @param id id |
||||
*/ |
||||
void deleted(String id); |
||||
|
||||
/** |
||||
* 部门树形列表 |
||||
* |
||||
* @param deptId deptId |
||||
* @param disabled 最顶级是否可用 |
||||
* @return 树形列表 |
||||
*/ |
||||
List<DeptRespNodeVO> deptTreeList(String deptId, Boolean disabled); |
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.huoran.iasf.vo.resp.HomeRespVO; |
||||
|
||||
/** |
||||
* 首页 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface HomeService { |
||||
|
||||
/** |
||||
* 获取首页信息 |
||||
* |
||||
* @param userId userId |
||||
* @return HomeRespVO |
||||
*/ |
||||
HomeRespVO getHomeInfo(String userId); |
||||
} |
@ -0,0 +1,97 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.Jwts; |
||||
import io.jsonwebtoken.SignatureAlgorithm; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* session管理器 |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2020年5月11日 |
||||
*/ |
||||
@Service |
||||
public class HttpApiSessionService { |
||||
|
||||
|
||||
public static final String USER_ID_KEY = "user_id_key"; |
||||
|
||||
public static final String USER_USERNAME_KEY = "user_username_key"; |
||||
|
||||
public static final String SUBJECT = "HuoRan_SUBJECT"; |
||||
|
||||
public static final long EXPIRE = 1000 * 60 * 60 * 24 * 2; //过期时间,毫秒,一天
|
||||
|
||||
//秘钥
|
||||
public static final String APP_SECRET = "HuoRan_SYMMETRIC_ENCRYPTION_HS256"; |
||||
|
||||
@Resource |
||||
private HttpServletRequest request; |
||||
|
||||
/** |
||||
* 生成jwt |
||||
* @param userId username |
||||
* @return token |
||||
*/ |
||||
public String geneJsonWebToken(String userId, String userName) { |
||||
String token = Jwts.builder().setSubject(SUBJECT) |
||||
.claim(USER_ID_KEY, userId) |
||||
.claim(USER_USERNAME_KEY, userName) |
||||
.setIssuedAt(new Date()) |
||||
.setExpiration(new Date(System.currentTimeMillis() + EXPIRE)) |
||||
.signWith(SignatureAlgorithm.HS256, APP_SECRET).compact(); |
||||
return token; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 校验token |
||||
* |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public Claims checkJWT(String token) { |
||||
|
||||
try { |
||||
final Claims claims = Jwts.parser().setSigningKey(APP_SECRET). |
||||
parseClaimsJws(token).getBody(); |
||||
return claims; |
||||
} catch (Exception e) { |
||||
} |
||||
return null; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取当前session信息 username |
||||
* |
||||
* @return username |
||||
*/ |
||||
public String getCurrentUsername() { |
||||
if (request.getAttribute(USER_USERNAME_KEY) != null) { |
||||
return request.getAttribute(USER_USERNAME_KEY).toString(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取当前session信息 UserId |
||||
* |
||||
* @return UserId |
||||
*/ |
||||
public String getCurrentUserId() { |
||||
if (request.getAttribute(USER_ID_KEY) != null) { |
||||
return request.getAttribute(USER_ID_KEY).toString(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,265 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
import java.util.Random; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* session管理器 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Service |
||||
public class HttpSessionService { |
||||
@Resource |
||||
private com.huoran.iasf.service.RedisService redisService; |
||||
@Resource |
||||
private com.huoran.iasf.service.UserRoleService userRoleService; |
||||
@Resource |
||||
private com.huoran.iasf.service.RolePermissionService rolePermissionService; |
||||
@Resource |
||||
private HttpServletRequest request; |
||||
@Resource |
||||
private com.huoran.iasf.service.PermissionService permissionService; |
||||
@Resource |
||||
private com.huoran.iasf.service.RoleService roleService; |
||||
|
||||
@Value("${spring.redis.key.prefix.userToken}") |
||||
private String userTokenPrefix; |
||||
|
||||
@Value("${spring.redis.key.expire.userToken}") |
||||
private int exire; |
||||
|
||||
@Value("${spring.redis.key.prefix.permissionRefresh}") |
||||
private String redisPermissionRefreshKey; |
||||
@Value("${spring.redis.key.expire.permissionRefresh}") |
||||
private Long redisPermissionRefreshExpire; |
||||
|
||||
public String createTokenAndUser(SysUser user, List<String> roles, Set<String> permissions) { |
||||
//方便根据id找到redis的key, 修改密码/退出登陆 方便使用
|
||||
String token = getRandomToken() + "#" + user.getId(); |
||||
JSONObject sessionInfo = new JSONObject(); |
||||
sessionInfo.put(Constant.USERID_KEY, user.getId()); |
||||
sessionInfo.put(Constant.USERNAME_KEY, user.getUsername()); |
||||
sessionInfo.put(Constant.ROLES_KEY, roles); |
||||
sessionInfo.put(Constant.PERMISSIONS_KEY, permissions); |
||||
String key = userTokenPrefix + token; |
||||
//设置该用户已登录的token
|
||||
redisService.setAndExpire(key, sessionInfo.toJSONString(), exire); |
||||
|
||||
//登陆后删除权限刷新标志
|
||||
redisService.del(redisPermissionRefreshKey + user.getId()); |
||||
return token; |
||||
} |
||||
|
||||
/** |
||||
* 根据token获取userid |
||||
* |
||||
* @param token token |
||||
* @return userid |
||||
*/ |
||||
public static String getUserIdByToken(String token) { |
||||
if (StringUtils.isBlank(token) || !token.contains("#")) { |
||||
return ""; |
||||
} else { |
||||
return token.substring(token.indexOf("#") + 1); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取参数中的token |
||||
* |
||||
* @return token |
||||
*/ |
||||
public String getTokenFromHeader() { |
||||
String token = request.getHeader(Constant.ACCESS_TOKEN); |
||||
//如果header中不存在token,则从参数中获取token
|
||||
if (StringUtils.isBlank(token)) { |
||||
token = request.getParameter(Constant.ACCESS_TOKEN); |
||||
} |
||||
return token; |
||||
} |
||||
|
||||
/** |
||||
* 获取当前session信息 |
||||
* |
||||
* @return session信息 |
||||
*/ |
||||
public JSONObject getCurrentSession() { |
||||
String token = getTokenFromHeader(); |
||||
if (null != token) { |
||||
if (redisService.exists(userTokenPrefix + token)) { |
||||
String sessionInfoStr = redisService.get(userTokenPrefix + token); |
||||
return JSON.parseObject(sessionInfoStr); |
||||
} else { |
||||
return null; |
||||
} |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取当前session信息 username |
||||
* |
||||
* @return username |
||||
*/ |
||||
public String getCurrentUsername() { |
||||
if (getCurrentSession() != null) { |
||||
return getCurrentSession().getString(Constant.USERNAME_KEY); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取当前session信息 UserId |
||||
* |
||||
* @return UserId |
||||
*/ |
||||
public String getCurrentUserId() { |
||||
if (getCurrentSession() != null) { |
||||
return getCurrentSession().getString(Constant.USERID_KEY); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 使当前用户的token失效 |
||||
*/ |
||||
public void abortUserByToken() { |
||||
String token = getTokenFromHeader(); |
||||
redisService.del(userTokenPrefix + token); |
||||
} |
||||
|
||||
/** |
||||
* 使所有用户的token失效 |
||||
*/ |
||||
public void abortAllUserByToken() { |
||||
String token = getTokenFromHeader(); |
||||
String userId = getUserIdByToken(token); |
||||
redisService.delKeys(userTokenPrefix + "*#" + userId); |
||||
} |
||||
|
||||
/** |
||||
* 使用户的token失效 |
||||
*/ |
||||
public void abortUserById(String userId) { |
||||
redisService.delKeys(userTokenPrefix + "*#" + userId); |
||||
} |
||||
|
||||
/** |
||||
* 使多个用户的token失效 |
||||
*/ |
||||
public void abortUserByUserIds(List<String> userIds) { |
||||
if (CollectionUtils.isNotEmpty(userIds)) { |
||||
for (String id : userIds) { |
||||
redisService.delKeys(userTokenPrefix + "*#" + id); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据用户id, 刷新redis用户权限 |
||||
* |
||||
* @param userId userId |
||||
*/ |
||||
public void refreshUerId(String userId) { |
||||
// redisService.delKeys(userTokenPrefix + "*#" + userId);
|
||||
|
||||
|
||||
// Set<String> keys = redisService.keys("#" + userId);
|
||||
// //如果修改了角色/权限, 那么刷新权限
|
||||
// for (String key : keys) {
|
||||
// JSONObject redisSession = JSON.parseObject(redisService.get(key));
|
||||
//
|
||||
// List<String> roleNames = getRolesByUserId(userId);
|
||||
// if (!CollectionUtils.isEmpty(roleNames)) {
|
||||
// redisSession.put(Constant.ROLES_KEY, roleNames);
|
||||
// }
|
||||
// Set<String> permissions = getPermissionsByUserId(userId);
|
||||
// redisSession.put(Constant.PERMISSIONS_KEY, permissions);
|
||||
// Long redisTokenKeyExpire = redisService.getExpire(key);
|
||||
// //刷新token绑定的角色权限
|
||||
// redisService.setAndExpire(key, redisSession.toJSONString(), redisTokenKeyExpire);
|
||||
//
|
||||
// }
|
||||
} |
||||
|
||||
/** |
||||
* 根据角色id, 刷新redis用户权限 |
||||
* |
||||
* @param roleId roleId |
||||
*/ |
||||
public void refreshRolePermission(String roleId) { |
||||
// List<String> userIds = userRoleService.getUserIdsByRoleId(roleId);
|
||||
// if (!CollectionUtils.isEmpty(userIds)) {
|
||||
// userIds.parallelStream().forEach(this::refreshUerId);
|
||||
// }
|
||||
} |
||||
|
||||
/** |
||||
* 根据权限id, 刷新redis用户权限 |
||||
* |
||||
* @param permissionId permissionId |
||||
*/ |
||||
public void refreshPermission(String permissionId) { |
||||
// List<String> userIds = permissionService.getUserIdsById(permissionId);
|
||||
// if (!CollectionUtils.isEmpty(userIds)) {
|
||||
// userIds.parallelStream().forEach(this::refreshUerId);
|
||||
// }
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* 生成随机的token |
||||
* |
||||
* @return token |
||||
*/ |
||||
private String getRandomToken() { |
||||
Random random = new Random(); |
||||
StringBuilder randomStr = new StringBuilder(); |
||||
|
||||
// 根据length生成相应长度的随机字符串
|
||||
for (int i = 0; i < 32; i++) { |
||||
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; |
||||
|
||||
//输出字母还是数字
|
||||
if ("char".equalsIgnoreCase(charOrNum)) { |
||||
//输出是大写字母还是小写字母
|
||||
int temp = random.nextInt(2) % 2 == 0 ? 65 : 97; |
||||
randomStr.append((char) (random.nextInt(26) + temp)); |
||||
} else { |
||||
randomStr.append(random.nextInt(10)); |
||||
} |
||||
} |
||||
|
||||
return randomStr.toString(); |
||||
} |
||||
|
||||
|
||||
private List<String> getRolesByUserId(String userId) { |
||||
return roleService.getRoleNames(userId); |
||||
} |
||||
|
||||
private Set<String> getPermissionsByUserId(String userId) { |
||||
return permissionService.getPermissionsByUserId(userId); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.iasf.entity.SysGenerator; |
||||
|
||||
/** |
||||
* 代码生成 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface ISysGeneratorService { |
||||
|
||||
/** |
||||
* 获取所有表 |
||||
* |
||||
* @param page page |
||||
* @param vo vo |
||||
* @return IPage |
||||
*/ |
||||
IPage<SysGenerator> selectAllTables(Page<SysGenerator> page, SysGenerator vo); |
||||
|
||||
/** |
||||
* 生成代码 |
||||
* |
||||
* @param tables tables |
||||
* @return byte[] |
||||
*/ |
||||
byte[] generatorCode(String[] tables); |
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysLog; |
||||
|
||||
/** |
||||
* 系统日志 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface LogService extends IService<SysLog> { |
||||
} |
@ -0,0 +1,87 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysPermission; |
||||
import com.huoran.iasf.vo.resp.PermissionRespNode; |
||||
|
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 菜单权限 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface PermissionService extends IService<SysPermission> { |
||||
|
||||
/** |
||||
* 根据userId获取权限 |
||||
* |
||||
* @param userId userId |
||||
* @return 权限 |
||||
*/ |
||||
List<SysPermission> getPermission(String userId); |
||||
|
||||
/** |
||||
* 删除权限 |
||||
* |
||||
* @param permissionId 权限id |
||||
*/ |
||||
void deleted(String permissionId); |
||||
|
||||
/** |
||||
* 获取所有 |
||||
* |
||||
* @return List |
||||
*/ |
||||
List<SysPermission> selectAll(); |
||||
|
||||
/** |
||||
* 根据userId获取权限标志 |
||||
* |
||||
* @param userId userId |
||||
* @return Set |
||||
*/ |
||||
Set<String> getPermissionsByUserId(String userId); |
||||
|
||||
/** |
||||
* 根据userId获取权限树 |
||||
* |
||||
* @param userId |
||||
* @return List |
||||
*/ |
||||
List<PermissionRespNode> permissionTreeList(String userId); |
||||
|
||||
/** |
||||
* 根据权限树 |
||||
* |
||||
* @return List |
||||
*/ |
||||
List<PermissionRespNode> selectAllByTree(); |
||||
|
||||
/** |
||||
* 根据目录树 |
||||
* |
||||
* @param permissionId permissionId |
||||
* @return List |
||||
*/ |
||||
List<PermissionRespNode> selectAllMenuByTree(String permissionId); |
||||
|
||||
|
||||
/** |
||||
* 根据权限id获取绑定的userId |
||||
* |
||||
* @param permissionId permissionId |
||||
* @return List |
||||
*/ |
||||
List<String> getUserIdsById(String permissionId); |
||||
|
||||
/** |
||||
* 更新 |
||||
* |
||||
* @param vo vo |
||||
*/ |
||||
void updatePermission(SysPermission vo); |
||||
} |
@ -0,0 +1,74 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import org.springframework.data.redis.core.StringRedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
import java.util.Set; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
|
||||
/** |
||||
* redis |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Service |
||||
public class RedisService { |
||||
private final StringRedisTemplate redisTemplate; |
||||
|
||||
public RedisService(StringRedisTemplate redisTemplate) { |
||||
this.redisTemplate = redisTemplate; |
||||
} |
||||
|
||||
public boolean exists(String key) { |
||||
return this.redisTemplate.hasKey(key); |
||||
} |
||||
|
||||
public Long getExpire(String key) { |
||||
if (null == key) { |
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR.getCode(), "key or TomeUnit 不能为空"); |
||||
} |
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS); |
||||
} |
||||
|
||||
|
||||
public void set(String key, String value) { |
||||
this.redisTemplate.opsForValue().set(key, value); |
||||
} |
||||
|
||||
|
||||
public String get(String key) { |
||||
return this.redisTemplate.opsForValue().get(key); |
||||
} |
||||
|
||||
public void del(String key) { |
||||
if (this.exists(key)) { |
||||
this.redisTemplate.delete(key); |
||||
} |
||||
|
||||
} |
||||
|
||||
public void setAndExpire(String key, String value, long seconds) { |
||||
this.redisTemplate.opsForValue().set(key, value); |
||||
this.redisTemplate.expire(key, seconds, TimeUnit.SECONDS); |
||||
} |
||||
|
||||
|
||||
public Set<String> keys(String pattern) { |
||||
return redisTemplate.keys("*" + pattern); |
||||
} |
||||
|
||||
public void delKeys(String pattern) { |
||||
Set<String> keys = redisTemplate.keys(pattern); |
||||
if (!CollectionUtils.isEmpty(keys)) { |
||||
this.redisTemplate.delete(keys); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysRolePermission; |
||||
import com.huoran.iasf.vo.req.RolePermissionOperationReqVO; |
||||
|
||||
/** |
||||
* 角色权限关联 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface RolePermissionService extends IService<SysRolePermission> { |
||||
|
||||
/** |
||||
* 角色绑定权限 |
||||
* |
||||
* @param vo vo |
||||
*/ |
||||
void addRolePermission(RolePermissionOperationReqVO vo); |
||||
} |
@ -0,0 +1,61 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 角色 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface RoleService extends IService<SysRole> { |
||||
|
||||
/** |
||||
* 添加角色 |
||||
* |
||||
* @param vo SysRole |
||||
*/ |
||||
void addRole(SysRole vo); |
||||
|
||||
/** |
||||
* 更新角色 |
||||
* |
||||
* @param vo SysRole |
||||
*/ |
||||
void updateRole(SysRole vo); |
||||
|
||||
/** |
||||
* 根据id获取角色详情 |
||||
* |
||||
* @param id id |
||||
* @return SysRole |
||||
*/ |
||||
SysRole detailInfo(String id); |
||||
|
||||
/** |
||||
* 根据id删除 |
||||
* |
||||
* @param id id |
||||
*/ |
||||
void deletedRole(String id); |
||||
|
||||
/** |
||||
* 根据userId获取绑定的角色 |
||||
* |
||||
* @param userId userId |
||||
* @return List |
||||
*/ |
||||
List<SysRole> getRoleInfoByUserId(String userId); |
||||
|
||||
/** |
||||
* 根据userId获取绑定的角色名 |
||||
* |
||||
* @param userId userId |
||||
* @return List |
||||
*/ |
||||
List<String> getRoleNames(String userId); |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysContentEntity; |
||||
|
||||
/** |
||||
* 内容 服务类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysContentService extends IService<SysContentEntity> { |
||||
|
||||
} |
||||
|
@ -0,0 +1,26 @@ |
||||
package com.huoran.iasf.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.iasf.entity.SysDictDetailEntity; |
||||
|
||||
/** |
||||
* 数据字典 服务类 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
public interface SysDictDetailService extends IService<SysDictDetailEntity> { |
||||
|
||||
/** |
||||
* 分页 |
||||
* |
||||
* @param page page |
||||
* @param dictId dictId |
||||
* @return IPage |
||||
*/ |
||||
IPage<SysDictDetailEntity> listByPage(Page<SysDictDetailEntity> page, String dictId); |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue