commit
e643ea1514
244 changed files with 17189 additions and 0 deletions
@ -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,324 @@ |
||||
<?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> |
||||
<poi.version>4.0.1</poi.version> |
||||
<poi-ooxml.version>4.0.1</poi-ooxml.version> |
||||
<easypoi-base.version>4.1.3</easypoi-base.version> |
||||
<easypoi-web.version>4.1.3</easypoi-web.version> |
||||
<easypoi-annotation.version>4.1.3</easypoi-annotation.version> |
||||
</properties> |
||||
|
||||
<dependencyManagement> |
||||
<dependencies> |
||||
<!--Spring Cloud-alibaba--> |
||||
<dependency> |
||||
<groupId>com.alibaba.cloud</groupId> |
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> |
||||
<version>2.1.0.RELEASE</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</dependencyManagement> |
||||
|
||||
<dependencies> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-configuration-processor</artifactId> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
|
||||
<!-- 发送邮箱 --> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-email</artifactId> |
||||
<version>1.3.3</version> |
||||
</dependency> |
||||
|
||||
<!--短信发送--> |
||||
<dependency> |
||||
<groupId>com.aliyun</groupId> |
||||
<artifactId>aliyun-java-sdk-core</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-cache</artifactId> |
||||
</dependency> |
||||
|
||||
<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>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-generator</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> |
||||
|
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-core</artifactId> |
||||
<version>5.3.6</version> |
||||
</dependency> |
||||
|
||||
<!-- Easy poi--> |
||||
<!-- excle导入导出依赖包 start --> |
||||
<!-- excel文件导入导出 --> |
||||
<dependency> |
||||
<groupId>cn.afterturn</groupId> |
||||
<artifactId>easypoi-base</artifactId> |
||||
<version>${easypoi-base.version}</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<artifactId>guava</artifactId> |
||||
<groupId>com.google.guava</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>guava</artifactId> |
||||
<groupId>com.google.guava</groupId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<artifactId>poi-ooxml-schemas</artifactId> |
||||
<groupId>org.apache.poi</groupId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>cn.afterturn</groupId> |
||||
<artifactId>easypoi-web</artifactId> |
||||
<version>${easypoi-web.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>cn.afterturn</groupId> |
||||
<artifactId>easypoi-annotation</artifactId> |
||||
<version>${easypoi-annotation.version}</version> |
||||
</dependency> |
||||
<!-- excle导入导出依赖包 end --> |
||||
<dependency> |
||||
<groupId>org.apache.poi</groupId> |
||||
<artifactId>poi-ooxml</artifactId> |
||||
<version>${poi-ooxml.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.poi</groupId> |
||||
<artifactId>poi</artifactId> |
||||
<version>${poi.version}</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,32 @@ |
||||
package com.huoran.iasf; |
||||
|
||||
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 |
||||
@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,23 @@ |
||||
package com.huoran.iasf.common.aop.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,17 @@ |
||||
package com.huoran.iasf.common.aop.annotation; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* @Description 不重复提交注解 |
||||
*/ |
||||
|
||||
@Target(ElementType.METHOD) // 作用到方法上
|
||||
@Retention(RetentionPolicy.RUNTIME) // 运行时有效
|
||||
public @interface NoRepeatSubmit { |
||||
|
||||
String name() default "name:"; |
||||
} |
@ -0,0 +1,133 @@ |
||||
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.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
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.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.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) { |
||||
//获取当前登陆人
|
||||
Integer 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<SysRole> sysRoles, Integer userId) { |
||||
//本人
|
||||
SysUser sysUser = userService.getById(userId); |
||||
//本部门
|
||||
// SysDept sysDept = deptService.getById(sysUser.getDeptId());
|
||||
//部门ids, 定义哪些部门最终拥有权限查看
|
||||
LinkedList<Object> deptList = new LinkedList<>(); |
||||
//用户ids,定义列表中哪些人创建的可查看
|
||||
LinkedList<Object> userIdList = new LinkedList<>(); |
||||
//根据数据权限范围分组, 不同的数据范围不同的逻辑处理
|
||||
/*Map<Integer, List<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(BaseResponseCode.NOT_ACCOUNT); |
||||
} |
||||
return userIdList.parallelStream().map(Object::toString).collect(Collectors.toList()); |
||||
} |
||||
} |
@ -0,0 +1,95 @@ |
||||
package com.huoran.iasf.common.aop.aspect; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
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 io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.Jwts; |
||||
import lombok.Synchronized; |
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
import static com.huoran.iasf.service.HttpApiSessionService.APP_SECRET; |
||||
|
||||
|
||||
/** |
||||
* @Description aop解析注解 |
||||
*/ |
||||
|
||||
@Aspect |
||||
@Component |
||||
public class NoRepeatSubmitAop { |
||||
|
||||
private Log logger = LogFactory.getLog(getClass()); |
||||
|
||||
@Autowired |
||||
private RedisServiceAop redisService; |
||||
|
||||
@Synchronized |
||||
@Around("execution(* com.huoran.*.controller.*.*(..)) && @annotation(noRepeatSubmit)") |
||||
public Object around(ProceedingJoinPoint pjp, NoRepeatSubmit noRepeatSubmit) throws Throwable { |
||||
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||
HttpServletRequest request = attributes.getRequest(); |
||||
HttpServletResponse response = attributes.getResponse(); |
||||
String token = request.getHeader(Constant.ACCESS_TOKEN); |
||||
//如果header中不存在token,则从参数中获取token
|
||||
if (StringUtils.isEmpty(token)) { |
||||
token = request.getParameter(Constant.ACCESS_TOKEN); |
||||
} |
||||
if (StringUtils.isEmpty(token)) { |
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
response.setCharacterEncoding("utf-8"); |
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
// 校验并解析token,如果token过期或者篡改,则会返回null
|
||||
Claims claims = checkJWT(token); |
||||
if (null == claims) { |
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
response.setCharacterEncoding("utf-8"); |
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR); |
||||
} |
||||
String key = token + "-" + request.getServletPath(); |
||||
if ( !redisService.haskey(key) ) {// 如果缓存中有这个url视为重复提交
|
||||
Object o = pjp.proceed(); |
||||
redisService.setCacheObject(key, 0, 1, TimeUnit.SECONDS); |
||||
return o; |
||||
} else { |
||||
redisService.setCacheObject(key, 0, 1, TimeUnit.SECONDS);//点了同样的URL继续限制,直到2次点击中间间隔超过了限制
|
||||
return R.fail("请勿重复提交或者操作过于频繁!"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 校验token |
||||
*/ |
||||
public Claims checkJWT(String token) { |
||||
|
||||
try { |
||||
final Claims claims = Jwts.parser().setSigningKey(APP_SECRET). |
||||
parseClaimsJws(token).getBody(); |
||||
return claims; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,228 @@ |
||||
package com.huoran.iasf.common.aop.aspect; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.redis.core.*; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.*; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
/** |
||||
* @Description RedisService |
||||
*/ |
||||
@Component |
||||
@SuppressWarnings(value = {"unchecked", "rawtypes"}) |
||||
public class RedisServiceAop { |
||||
|
||||
@Autowired |
||||
public RedisTemplate redisTemplate; |
||||
|
||||
/** |
||||
* 缓存基本的对象,Integer、String、实体类等 |
||||
* |
||||
* @param key 缓存的键值 |
||||
* @param value 缓存的值 |
||||
* @return 缓存的对象 |
||||
*/ |
||||
public <T> ValueOperations<String, T> setCacheObject(String key, T value) { |
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
||||
operation.set(key, value); |
||||
return operation; |
||||
} |
||||
|
||||
/** |
||||
* 缓存基本的对象,Integer、String、实体类等 |
||||
* |
||||
* @param key 缓存的键值 |
||||
* @param value 缓存的值 |
||||
* @param timeout 时间 |
||||
* @param timeUnit 时间颗粒度 |
||||
* @return 缓存的对象 |
||||
*/ |
||||
public <T> ValueOperations<String, T> setCacheObject(String key, T value, Integer timeout, TimeUnit timeUnit) { |
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
||||
operation.set(key, value, timeout, timeUnit); |
||||
return operation; |
||||
} |
||||
|
||||
/** |
||||
* 获得缓存的基本对象。 |
||||
* |
||||
* @param key 缓存键值 |
||||
* @return 缓存键值对应的数据 |
||||
*/ |
||||
public <T> T getCacheObject(String key) { |
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
||||
return operation.get(key); |
||||
} |
||||
|
||||
/** |
||||
* 删除单个对象 |
||||
* |
||||
* @param key |
||||
*/ |
||||
public void deleteObject(String key) { |
||||
redisTemplate.delete(key); |
||||
} |
||||
|
||||
/** |
||||
* 删除集合对象 |
||||
* |
||||
* @param collection |
||||
*/ |
||||
public void deleteObject(Collection collection) { |
||||
redisTemplate.delete(collection); |
||||
} |
||||
|
||||
/** |
||||
* 缓存List数据 |
||||
* |
||||
* @param key 缓存的键值 |
||||
* @param dataList 待缓存的List数据 |
||||
* @return 缓存的对象 |
||||
*/ |
||||
public <T> ListOperations<String, T> setCacheList(String key, List<T> dataList) { |
||||
ListOperations listOperation = redisTemplate.opsForList(); |
||||
if (null != dataList) { |
||||
int size = dataList.size(); |
||||
for (int i = 0; i < size; i++) { |
||||
listOperation.leftPush(key, dataList.get(i)); |
||||
} |
||||
} |
||||
return listOperation; |
||||
} |
||||
|
||||
/** |
||||
* 获得缓存的list对象 |
||||
* |
||||
* @param key 缓存的键值 |
||||
* @return 缓存键值对应的数据 |
||||
*/ |
||||
public <T> List<T> getCacheList(String key) { |
||||
List<T> dataList = new ArrayList<T>(); |
||||
ListOperations<String, T> listOperation = redisTemplate.opsForList(); |
||||
Long size = listOperation.size(key); |
||||
|
||||
for (int i = 0; i < size; i++) { |
||||
dataList.add(listOperation.index(key, i)); |
||||
} |
||||
return dataList; |
||||
} |
||||
|
||||
/** |
||||
* 缓存Set |
||||
* |
||||
* @param key 缓存键值 |
||||
* @param dataSet 缓存的数据 |
||||
* @return 缓存数据的对象 |
||||
*/ |
||||
public <T> BoundSetOperations<String, T> setCacheSet(String key, Set<T> dataSet) { |
||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key); |
||||
Iterator<T> it = dataSet.iterator(); |
||||
while (it.hasNext()) { |
||||
setOperation.add(it.next()); |
||||
} |
||||
return setOperation; |
||||
} |
||||
|
||||
/** |
||||
* 获得缓存的set |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
public <T> Set<T> getCacheSet(String key) { |
||||
Set<T> dataSet = new HashSet<T>(); |
||||
BoundSetOperations<String, T> operation = redisTemplate.boundSetOps(key); |
||||
dataSet = operation.members(); |
||||
return dataSet; |
||||
} |
||||
|
||||
/** |
||||
* 缓存Map |
||||
* |
||||
* @param key |
||||
* @param dataMap |
||||
* @return |
||||
*/ |
||||
public <T> HashOperations<String, String, T> setCacheMap(String key, Map<String, T> dataMap) { |
||||
HashOperations hashOperations = redisTemplate.opsForHash(); |
||||
if (null != dataMap) { |
||||
for (Map.Entry<String, T> entry : dataMap.entrySet()) { |
||||
hashOperations.put(key, entry.getKey(), entry.getValue()); |
||||
} |
||||
} |
||||
return hashOperations; |
||||
} |
||||
|
||||
/** |
||||
* 获得缓存的Map |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
public <T> Map<String, T> getCacheMap(String key) { |
||||
Map<String, T> map = redisTemplate.opsForHash().entries(key); |
||||
return map; |
||||
} |
||||
|
||||
/** |
||||
* 获得缓存的基本对象列表 |
||||
* |
||||
* @param pattern 字符串前缀 |
||||
* @return 对象列表 |
||||
*/ |
||||
public Collection<String> keys(String pattern) { |
||||
return redisTemplate.keys(pattern); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
public boolean haskey(String key){ |
||||
return redisTemplate.hasKey(key); |
||||
} |
||||
|
||||
public Long getExpire(String key){ |
||||
return redisTemplate.getExpire(key); |
||||
} |
||||
|
||||
|
||||
public <T> ValueOperations<String, T> setBillObject(String key, List<Map<String, Object>> value) { |
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
||||
operation.set(key, (T) value); |
||||
return operation; |
||||
} |
||||
/** |
||||
* 缓存list<Map<String, Object>> |
||||
* |
||||
* @param key 缓存的键值 |
||||
* @param value 缓存的值 |
||||
* @param timeout 时间 |
||||
* @param timeUnit 时间颗粒度 |
||||
* @return 缓存的对象 |
||||
*/ |
||||
public <T> ValueOperations<String, T> setBillObject(String key, List<Map<String, Object>> value, Integer timeout, TimeUnit timeUnit) { |
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
||||
operation.set(key,(T)value, timeout, timeUnit); |
||||
return operation; |
||||
} |
||||
/** |
||||
* 缓存Map |
||||
* |
||||
* @param key |
||||
* @param dataMap |
||||
* @return |
||||
*/ |
||||
public <T> HashOperations<String, String, T> setCKdBillMap(String key, Map<String, T> dataMap) { |
||||
HashOperations hashOperations = redisTemplate.opsForHash(); |
||||
if (null != dataMap) { |
||||
for (Map.Entry<String, T> entry : dataMap.entrySet()) { |
||||
hashOperations.put(key, entry.getKey(), entry.getValue()); |
||||
} |
||||
} |
||||
return hashOperations; |
||||
} |
||||
} |
@ -0,0 +1,116 @@ |
||||
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.Pointcut; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.context.annotation.Lazy; |
||||
|
||||
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()); |
||||
//用户名
|
||||
Integer userId = httpSessionService.getCurrentUserId(); |
||||
String username = httpSessionService.getCurrentUsername(); |
||||
sysLog.setUsername(username); |
||||
sysLog.setUserId(userId.toString()); |
||||
sysLog.setTime((int) time); |
||||
log.info(sysLog.toString()); |
||||
sysLogMapper.insert(sysLog); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
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 ip; |
||||
private String url; |
||||
private String accessUrl; |
||||
|
||||
|
||||
public String getPath() { |
||||
return path; |
||||
} |
||||
|
||||
public void setPath(String path) { |
||||
this.path = path; |
||||
} |
||||
|
||||
public String getIp() { |
||||
return ip; |
||||
} |
||||
|
||||
public void setIp(String ip) { |
||||
this.ip = ip; |
||||
} |
||||
|
||||
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,25 @@ |
||||
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() { |
||||
PaginationInterceptor page = new PaginationInterceptor(); |
||||
page.setDialectType("mysql"); |
||||
return page; |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import org.springframework.boot.autoconfigure.cache.CacheProperties; |
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration; |
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.RedisSerializationContext; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
/** |
||||
* @Author chen |
||||
* @DATE 2021/12/28 10:42 |
||||
* @Version 1.0 |
||||
*/ |
||||
@EnableConfigurationProperties(CacheProperties.class) |
||||
@Configuration |
||||
@EnableCaching |
||||
public class MyCacheConfig { |
||||
|
||||
@Bean |
||||
RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties){ |
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); |
||||
//修改缓存key、value的序列化机制,返回json数据格式
|
||||
config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())); |
||||
config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())); |
||||
//读取redis配置文件
|
||||
CacheProperties.Redis redisProperties = cacheProperties.getRedis(); |
||||
if (redisProperties.getTimeToLive() != null) { |
||||
config = config.entryTtl(redisProperties.getTimeToLive()); |
||||
} |
||||
|
||||
if (redisProperties.getKeyPrefix() != null) { |
||||
config = config.prefixKeysWith(redisProperties.getKeyPrefix()); |
||||
} |
||||
|
||||
if (!redisProperties.isCacheNullValues()) { |
||||
config = config.disableCachingNullValues(); |
||||
} |
||||
|
||||
if (!redisProperties.isUseKeyPrefix()) { |
||||
config = config.disableKeyPrefix(); |
||||
} |
||||
return config; |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import java.util.concurrent.Executors; |
||||
import java.util.concurrent.LinkedBlockingDeque; |
||||
import java.util.concurrent.ThreadPoolExecutor; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
/** |
||||
* @Author chen |
||||
* @DATE 2021/12/28 17:48 |
||||
* @Version 1.0 |
||||
*/ |
||||
@Configuration |
||||
public class MyThreadConfig { |
||||
|
||||
@Bean |
||||
public ThreadPoolExecutor threadPoolExecutor(){ |
||||
return new ThreadPoolExecutor(20, |
||||
300, |
||||
10, |
||||
TimeUnit.SECONDS, |
||||
new LinkedBlockingDeque<>(), |
||||
Executors.defaultThreadFactory(), |
||||
new ThreadPoolExecutor.AbortPolicy()); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.huoran.iasf.common.config; |
||||
|
||||
import org.springframework.core.io.FileSystemResource; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.nio.file.Path; |
||||
|
||||
@Component |
||||
public class NonStaticResourceHttpRequestConfig extends ResourceHttpRequestHandler { |
||||
|
||||
public final static String ATTR_FILE = "NON-STATIC-FILE"; |
||||
|
||||
@Override |
||||
protected Resource getResource(HttpServletRequest request) { |
||||
final Path filePath = (Path) request.getAttribute(ATTR_FILE); |
||||
return new FileSystemResource(filePath); |
||||
} |
||||
|
||||
} |
@ -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,160 @@ |
||||
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.cors.CorsConfiguration; |
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
||||
import org.springframework.web.filter.CorsFilter; |
||||
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; |
||||
|
||||
|
||||
private CorsConfiguration buildConfig() { |
||||
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
||||
corsConfiguration.addAllowedHeader("*"); // 允许任何头
|
||||
corsConfiguration.addAllowedOrigin("*"); // 允许任何头
|
||||
corsConfiguration.addAllowedMethod("*"); // 允许任何方法(post、get等)
|
||||
return corsConfiguration; |
||||
} |
||||
|
||||
@Bean |
||||
public CorsFilter corsFilter() { |
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
||||
source.registerCorsConfiguration("/**", buildConfig()); // 对接口配置跨域设置
|
||||
return new CorsFilter(source); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 使用阿里 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("*") |
||||
.allowCredentials(true) |
||||
.allowedMethods("*") |
||||
.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,20 @@ |
||||
package com.huoran.iasf.common.exception; |
||||
|
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* BusinessException |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Getter |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class BusinessException extends RuntimeException { |
||||
private BaseResponseCode baseResponseCode; |
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.huoran.iasf.common.exception; |
||||
|
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* BusinessException |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Getter |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class NotFoundException extends RuntimeException { |
||||
private BaseResponseCode baseResponseCode; |
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.huoran.iasf.common.exception; |
||||
|
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@Getter |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class UnauthorizedException extends RuntimeException { |
||||
private BaseResponseCode baseResponseCode; |
||||
} |
@ -0,0 +1,69 @@ |
||||
package com.huoran.iasf.common.exception.code; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.ToString; |
||||
|
||||
/** |
||||
* 错误码 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Getter |
||||
@ToString |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public enum BaseResponseCode implements ResponseCodeInterface { |
||||
/** |
||||
* 错误码 |
||||
*/ |
||||
USERNAME_EXISTS(10008, "用户名已存在!"), |
||||
KEY_OR_TOMEUNIT(10009, "key or TomeUnit 不能为空!"), |
||||
DICTIONARY_DATA_FAILED(10010, "获取字典数据失败"), |
||||
UPLOAD_EMPTY(10011, "上传内容为空"), |
||||
UPLOAD_FAILED(10012, "上传失败"), |
||||
VERIFICATION_CODE_ERROR(10007, "验证码错误!"), |
||||
VERIFICATION_CODE_EXPIRED(10006, "验证码已过期!"), |
||||
CANNOT_SAME(10005, "新密码不能与旧密码相同!"), |
||||
EXCEL_FILE_INVALID(10004, "上传excel文件错误!"), |
||||
VALID_EXCEPTION(10003, "参数格式校验异常!"), |
||||
OPERATION_ERROR(10002, "操作失败"), |
||||
SYSTEM_BUSY(500, "系统繁忙,请稍候再试"), |
||||
SUCCESS(200, "success"), |
||||
|
||||
EXCEL_FILE_FORMAT_ERROR(40007, "请根据模板使用说明录入正确的用户信息!"), |
||||
TOKEN_ERROR(401, "登录凭证已过期,请重新登录"), |
||||
DATA_ERROR(401003, "传入数据异常"), |
||||
NOT_ACCOUNT(401004, "该用户不存在,请先注册"), |
||||
USER_LOCK(401005, "该用户已被锁定,请联系运营人员"), |
||||
PASSWORD_ERROR(401006, "用户名或密码错误"), |
||||
METHOD_ARGUMENT_NOT_VALID_EXCEPTION(400, "请求参数有误"), |
||||
UNAUTHORIZED_ERROR(401008, "权鉴校验不通过"), |
||||
ROLE_PERMISSION_RELATION(401009, "该菜单权限存在子集关联,不允许删除"), |
||||
OLD_PASSWORD_ERROR(401010, "旧密码不正确"), |
||||
NOT_PERMISSION_DELETED_DEPT(401011, "该组织机构下还关联着用户,不允许删除"), |
||||
DELETE_SUB_DEPARTMENTS_FIRST(401018, "请先删除子级部门!"), |
||||
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, "菜单权限的标识符不能为空"), |
||||
ROLE_ERROR(401017, "账号角色被删,请联系管理员添加角色后再试"), |
||||
EXCEL_FILE_NULL(40006, "导入失败,导入数据为空!"), |
||||
|
||||
DATA_DOES_NOT_EXIST(500, "当前数据不存在"), |
||||
; |
||||
|
||||
/** |
||||
* 错误码 |
||||
*/ |
||||
private int code; |
||||
/** |
||||
* 错误消息 |
||||
*/ |
||||
private String 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,145 @@ |
||||
package com.huoran.iasf.common.exception.handler; |
||||
|
||||
import com.google.common.collect.Maps; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.UnauthorizedException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.shiro.authc.AuthenticationException; |
||||
import org.apache.shiro.authz.AuthorizationException; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.validation.BindingResult; |
||||
import org.springframework.web.bind.MethodArgumentNotValidException; |
||||
import org.springframework.web.bind.annotation.ControllerAdvice; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
import org.springframework.web.bind.annotation.ResponseStatus; |
||||
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||
|
||||
import javax.validation.ConstraintViolation; |
||||
import javax.validation.ConstraintViolationException; |
||||
import javax.validation.ValidationException; |
||||
import java.util.HashMap; |
||||
import java.util.Set; |
||||
import java.util.concurrent.atomic.AtomicReference; |
||||
|
||||
/** |
||||
* RestExceptionHandler |
||||
* 全局异常拦截器 |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Slf4j |
||||
@RestControllerAdvice |
||||
public class RestExceptionHandler { |
||||
|
||||
/** |
||||
* 系统繁忙,请稍候再试" |
||||
*/ |
||||
@ExceptionHandler(Exception.class) |
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED) |
||||
public R handleException(Exception e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return R.getResult(BaseResponseCode.SYSTEM_BUSY); |
||||
} |
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class) |
||||
@ResponseStatus(HttpStatus.BAD_REQUEST) |
||||
public R illegalArgumentException(IllegalArgumentException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return R.getResult(BaseResponseCode.METHOD_ARGUMENT_NOT_VALID_EXCEPTION); |
||||
} |
||||
|
||||
@ExceptionHandler(AuthenticationException.class) |
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED) |
||||
public R authenticationException(AuthenticationException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
// throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
|
||||
return new R(BaseResponseCode.TOKEN_ERROR.getCode(), BaseResponseCode.TOKEN_ERROR.getMsg()); |
||||
} |
||||
|
||||
/** |
||||
* 自定义全局异常处理 |
||||
*/ |
||||
@ExceptionHandler(value = BusinessException.class) |
||||
@ResponseStatus(HttpStatus.OK) |
||||
public R businessExceptionHandler(BusinessException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
BaseResponseCode em = e.getBaseResponseCode(); |
||||
return new R(em.getCode(), em.getMsg()); |
||||
} |
||||
|
||||
/** |
||||
* 权限全局异常处理 |
||||
*/ |
||||
@ExceptionHandler(value = UnauthorizedException.class) |
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED) |
||||
public R businessExceptionHandler(UnauthorizedException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
BaseResponseCode em = e.getBaseResponseCode(); |
||||
return new R(em.getCode(), em.getMsg()); |
||||
} |
||||
|
||||
@ExceptionHandler(value = NotFoundException.class) |
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) |
||||
public R businessExceptionHandler(NotFoundException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
BaseResponseCode em = e.getBaseResponseCode(); |
||||
return new R(em.getCode(), em.getMsg()); |
||||
} |
||||
|
||||
/** |
||||
* 没有权限 返回403视图 |
||||
*/ |
||||
@ExceptionHandler(value = AuthorizationException.class) |
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED) |
||||
public R errorPermission(AuthorizationException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return new R(BaseResponseCode.UNAUTHORIZED_ERROR); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 处理参数格式校验异常 |
||||
*/ |
||||
@ExceptionHandler(value = MethodArgumentNotValidException.class) |
||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) |
||||
public R handleValidException(MethodArgumentNotValidException e){ |
||||
log.error("参数格式校验异常"); |
||||
BindingResult bindingResult = e.getBindingResult(); |
||||
HashMap<String, String> errorMap = Maps.newHashMap(); |
||||
AtomicReference<String> errorMsg = new AtomicReference<>(""); |
||||
bindingResult.getFieldErrors().forEach(fieldError -> { |
||||
errorMsg.set(fieldError.getDefaultMessage()); |
||||
errorMap.put(fieldError.getField(),fieldError.getDefaultMessage()); |
||||
}); |
||||
return R.fail(errorMsg); |
||||
} |
||||
|
||||
/** |
||||
* 校验List<entity>类型, 需要controller添加@Validated注解 |
||||
* 处理Validated List<entity> 异常 |
||||
*/ |
||||
@ExceptionHandler |
||||
@ResponseStatus(HttpStatus.BAD_REQUEST) |
||||
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()); |
||||
} |
||||
|
||||
@ExceptionHandler |
||||
@ResponseStatus(HttpStatus.NOT_FOUND) |
||||
public R handle(ValidationException e) { |
||||
log.error("Exception,exception:{}", e, e); |
||||
return new R(404, e.getMessage()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,110 @@ |
||||
package com.huoran.iasf.common.filter; |
||||
|
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.UnauthorizedException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.Jwts; |
||||
import lombok.SneakyThrows; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.apache.shiro.subject.Subject; |
||||
import org.springframework.core.annotation.Order; |
||||
import org.springframework.http.MediaType; |
||||
|
||||
import javax.servlet.*; |
||||
import javax.servlet.annotation.WebFilter; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Arrays; |
||||
|
||||
import static com.huoran.iasf.service.HttpApiSessionService.*; |
||||
|
||||
/** |
||||
* shiro过滤器 登录用户权限认证授权 |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Slf4j |
||||
@WebFilter(filterName = "tokenFilter", urlPatterns = "/**") |
||||
@Order(1) |
||||
//@Component
|
||||
public class AuthFilter implements Filter { |
||||
/** |
||||
* 白名单 |
||||
*/ |
||||
private static final String[] whiteList = |
||||
{"/iasf/sys/user/login", |
||||
"/iasf/sys/exportFailure","/iasf/sys/getVerify","/iasf/doc.html"}; |
||||
|
||||
//需要拦截的地址,验证token是否存在及有效
|
||||
@Override |
||||
@SneakyThrows |
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { |
||||
//每一次的请求先校验cookie
|
||||
|
||||
HttpServletRequest req = (HttpServletRequest) request; |
||||
HttpServletResponse resp = (HttpServletResponse) response; |
||||
resp.setHeader("Access-Control-Allow-Origin", req.getHeader("Origin")); |
||||
resp.setHeader("Access-Control-Allow-Methods", req.getMethod()); |
||||
resp.setHeader("Access-Control-Max-Age", "3600"); |
||||
resp.setHeader("Access-Control-Allow-Headers", req.getHeader("Access-Control-Request-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)) { |
||||
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
resp.setCharacterEncoding("utf-8"); |
||||
resp.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); |
||||
// 指定处理该请求的处理器
|
||||
request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp); |
||||
} |
||||
// 校验并解析token,如果token过期或者篡改,则会返回null
|
||||
Claims claims = checkJWT(token); |
||||
if (null == claims) { |
||||
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
resp.setCharacterEncoding("utf-8"); |
||||
resp.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); |
||||
// 指定处理该请求的处理器
|
||||
request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp); |
||||
}else { |
||||
// 校验通过后,设置用户信息到request里,在Controller中从Request域中获取用户信息
|
||||
request.setAttribute(USER_ID_KEY, claims.get(USER_ID_KEY)); |
||||
request.setAttribute(USER_USERNAME_KEY, claims.get(USER_USERNAME_KEY)); |
||||
} |
||||
chain.doFilter(request, response); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 校验token |
||||
*/ |
||||
public Claims checkJWT(String token) { |
||||
|
||||
try { |
||||
final Claims claims = Jwts.parser().setSigningKey(APP_SECRET). |
||||
parseClaimsJws(token).getBody(); |
||||
return claims; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.huoran.iasf.common.job.task; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* 测试定时任务(演示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,117 @@ |
||||
/* |
||||
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,172 @@ |
||||
/* |
||||
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,139 @@ |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.UnauthorizedException; |
||||
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 io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.Jwts; |
||||
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.apache.shiro.web.util.WebUtils; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.ServletRequest; |
||||
import javax.servlet.ServletResponse; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.nio.charset.StandardCharsets; |
||||
|
||||
import static com.huoran.iasf.service.HttpApiSessionService.*; |
||||
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; |
||||
|
||||
|
||||
/** |
||||
* shiro过滤器 登录用户权限认证授权 |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Slf4j |
||||
public class CustomAccessControlFilter extends AccessControlFilter { |
||||
|
||||
// @Override
|
||||
// protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
|
||||
// HttpServletRequest httpRequest = WebUtils.toHttp(request);
|
||||
// HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
||||
// if (httpRequest.getMethod().equals(RequestMethod.OPTIONS.name())) {
|
||||
// httpResponse.setHeader("Access-control-Allow-Origin", httpRequest.getHeader("Origin"));
|
||||
// httpResponse.setHeader("Access-Control-Allow-Methods", httpRequest.getMethod());
|
||||
// // httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT");
|
||||
// httpResponse.setHeader("Access-Control-Allow-Headers", httpRequest.getHeader("Access-Control-Request-Headers"));
|
||||
// httpResponse.setStatus(HttpStatus.OK.value());
|
||||
// return false;
|
||||
// }
|
||||
// return super.preHandle(request, response);
|
||||
// }
|
||||
|
||||
|
||||
@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 {
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse; |
||||
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); |
||||
System.out.println("token===============" + token); |
||||
//如果header中不存在token,则从参数中获取token
|
||||
if (StringUtils.isEmpty(token)) { |
||||
token = request.getParameter(Constant.ACCESS_TOKEN); |
||||
} |
||||
if (StringUtils.isEmpty(token)) { |
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
response.setCharacterEncoding("utf-8"); |
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); |
||||
// 指定处理该请求的处理器
|
||||
request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response); |
||||
} |
||||
// 校验并解析token,如果token过期或者篡改,则会返回null
|
||||
Claims claims = checkJWT(token); |
||||
if (null == claims) { |
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
||||
response.setCharacterEncoding("utf-8"); |
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
||||
request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); |
||||
// 指定处理该请求的处理器
|
||||
request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response); |
||||
}else { |
||||
Subject subject1 = getSubject(servletRequest, servletResponse); |
||||
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token); |
||||
subject1.login(usernamePasswordToken); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 校验token |
||||
*/ |
||||
public Claims checkJWT(String token) { |
||||
|
||||
try { |
||||
final Claims claims = Jwts.parser().setSigningKey(APP_SECRET). |
||||
parseClaimsJws(token).getBody(); |
||||
return claims; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
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,39 @@ |
||||
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 false; |
||||
} |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
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.AuthorizationException; |
||||
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);
|
||||
throw new AuthorizationException(); |
||||
} |
||||
JSONObject redisSession = JSON.parseObject(sessionInfoStr); |
||||
if (redisSession == null) { |
||||
throw new AuthorizationException(); |
||||
} |
||||
|
||||
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,203 @@ |
||||
/* |
||||
package com.huoran.iasf.common.shiro; |
||||
|
||||
import com.huoran.iasf.common.config.FileUploadProperties; |
||||
import com.huoran.iasf.common.filter.AuthFilter; |
||||
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 org.springframework.core.annotation.Order; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.Filter; |
||||
import java.util.HashMap; |
||||
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("/sys/getVerify", "anon"); |
||||
filterChainDefinitionMap.put("/sys/user/login", "anon");*//*
|
||||
*/ |
||||
/* |
||||
filterChainDefinitionMap.put("/**", "token,authc"); |
||||
shiroFilterFactoryBean.setLoginUrl("/login"); |
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); |
||||
return shiroFilterFactoryBean; |
||||
}*//*
|
||||
|
||||
|
||||
@Bean |
||||
public ShiroFilterFactoryBean shirFilter() { |
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); |
||||
shiroFilterFactoryBean.setLoginUrl("/login"); |
||||
shiroFilterFactoryBean.setSecurityManager(securityManager()); |
||||
Map<String, Filter> filterMap = new HashMap<>(); |
||||
|
||||
// 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 :这是一个坑呢,一不小心代码就不好使了;
|
||||
// ① authc:所有url都必须认证通过才可以访问; ② anon:所有url都都可以匿名访问
|
||||
|
||||
//过滤器1
|
||||
filterMap.put("token", new AuthFilter()); |
||||
//过滤器2
|
||||
//用来校验token
|
||||
filterMap.put("authc", new CustomAccessControlFilter()); |
||||
shiroFilterFactoryBean.setFilters(filterMap); |
||||
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("/sysFiles/preview/**", "anon"); |
||||
filterChainDefinitionMap.put("/sysContent/findById", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/findById", "anon"); |
||||
filterChainDefinitionMap.put("/sysContent/articlePreview", "anon"); |
||||
filterChainDefinitionMap.put("/sysContent/newlyPublishedArticles", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/listWithTreeMenuVisible", "anon"); |
||||
filterChainDefinitionMap.put("/sysContent/hotContent", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/listWithTree", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumnLongPage/getLongPageInformation", "anon"); |
||||
filterChainDefinitionMap.put("/favicon.ico", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/queryArticlesByColumnType", "anon"); |
||||
filterChainDefinitionMap.put("/content/label/queryAllArticleSubjectTags", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/oneLevelChecksThemAll", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/getTheFullArticleByColumn", "anon"); |
||||
filterChainDefinitionMap.put("/sys/exportFailure", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumnLongPage/getRedisCache", "anon"); |
||||
filterChainDefinitionMap.put("/content/classification/allTheQuery", "anon"); |
||||
filterChainDefinitionMap.put("/sysColumn/getsSublevelColumnsUnderALevel", "anon"); |
||||
filterChainDefinitionMap.put("/sysFiles/upload", "anon"); |
||||
*/ |
||||
/*filterChainDefinitionMap.put("/index/**", "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("*.html", "anon"); |
||||
filterChainDefinitionMap.put("/static/**", "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("/**", "authc,token"); |
||||
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,85 @@ |
||||
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 = "token"; |
||||
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:草稿 1:已发布 |
||||
*/ |
||||
public static final Integer ARTICLE_PUBLISHED = 1; |
||||
|
||||
public static final Integer ARTICLE_NOT_PUBLISHED = 0; |
||||
|
||||
|
||||
/** |
||||
* 文章模板状态:0禁用;1启用 |
||||
*/ |
||||
public static final Integer TEMPLATE_STATUS_DISABLED = 0; |
||||
|
||||
public static final Integer TEMPLATE_STATUS_ENABLED = 1; |
||||
|
||||
|
||||
/** |
||||
* 模板类型 类型(0:列表样式 1:详情样式)', |
||||
*/ |
||||
|
||||
public static final Integer LIST_TEMPLATE_TYPES = 0; |
||||
|
||||
public static final Integer DETAILS_TEMPLATE_TYPE = 1; |
||||
|
||||
|
||||
/** |
||||
* 栏目导航菜单是否可见 菜单是否可见(默认0可见 1不可见) |
||||
*/ |
||||
|
||||
public static final Integer NAVIGATION_MENU_VISIBLE = 0; |
||||
|
||||
public static final Integer THE_NAVIGATION_MENU_IS_NOT_VISIBLE = 1; |
||||
|
||||
/** |
||||
* 异常处理 controller request url |
||||
*/ |
||||
public static final String ERROR_CONTROLLER_PATH = "/error/throw"; |
||||
} |
@ -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,70 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.apache.commons.mail.DefaultAuthenticator; |
||||
import org.apache.commons.mail.HtmlEmail; |
||||
|
||||
|
||||
public class EmailUtils { |
||||
|
||||
//服务器地址
|
||||
private static final String SERVER_ADDRESS = "smtp.mxhichina.com"; |
||||
//邮箱地址
|
||||
private static final String EMAILADDRESS = "postmaster@huorantech.cn"; |
||||
//发生邮箱密码
|
||||
private static final String EMAILPASSWORD = "HR111aaa"; |
||||
//发送人姓名
|
||||
private static final String EMAILUSERNAME = "DataForward"; |
||||
//授权码
|
||||
//private static final String AUTHORIZATION_CODE = "smtp.mxhichina.com";
|
||||
//邮件标题
|
||||
private static final String EMAILHEAD = "粒子研究院"; |
||||
//邮件信息(后接验证码)头部信息
|
||||
private static final String EMAILMASSAGEHEAD = "尊敬的用户,欢迎使用粒子研究院,您本次的验证码是: "; |
||||
//邮件信息(后接验证码)尾部信息
|
||||
private static final String EMAILMASSAGETAIL = ",有效时间为5分钟"; |
||||
|
||||
|
||||
//邮箱验证码
|
||||
public static boolean sendEmail(String emailaddress,String code){ |
||||
try { |
||||
HtmlEmail email = new HtmlEmail(); |
||||
email.setHostName(SERVER_ADDRESS); |
||||
email.setSSLOnConnect(true); //使用ssl加密true
|
||||
email.setSslSmtpPort("465"); //使用465端口
|
||||
email.setCharset("UTF-8"); |
||||
email.addTo(emailaddress); |
||||
|
||||
email.setFrom(EMAILADDRESS, EMAILUSERNAME); |
||||
// -- 使用阿里企业邮箱无授权码
|
||||
// email.setAuthentication(EMAILADDRESS, AUTHORIZATION_CODE);
|
||||
|
||||
email.setAuthenticator(new DefaultAuthenticator(EMAILADDRESS,EMAILPASSWORD)); |
||||
email.setSubject(EMAILHEAD); |
||||
email.setMsg( EMAILMASSAGEHEAD + code + EMAILMASSAGETAIL); |
||||
|
||||
email.send(); |
||||
return true; |
||||
} |
||||
catch(Exception e){ |
||||
e.printStackTrace(); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 描述:是否是邮箱. |
||||
* |
||||
* @param str 指定的字符串 |
||||
* @return 是否是邮箱:是为true,否则false |
||||
*/ |
||||
public static Boolean isEmail(String str) { |
||||
Boolean isEmail = false; |
||||
String expr = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$"; |
||||
|
||||
if (str.matches(expr)) { |
||||
isEmail = true; |
||||
} |
||||
return isEmail; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Target(ElementType.FIELD) |
||||
public @interface ExcelAttribute { |
||||
/** |
||||
* 对应的列名称 |
||||
*/ |
||||
String name() default ""; |
||||
|
||||
/** |
||||
* excel列的索引 |
||||
*/ |
||||
int sort(); |
||||
|
||||
/** |
||||
* 字段类型对应的格式 |
||||
*/ |
||||
String format() default ""; |
||||
} |
@ -0,0 +1,183 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.vo.req.ExcelImpUserReq; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
import org.apache.poi.ss.usermodel.*; |
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class ExcelImportHelper { |
||||
|
||||
//判断row是否为空
|
||||
public static boolean isRowEmpty(Row row) { |
||||
if (null == row) { |
||||
return true; |
||||
} |
||||
int firstCellNum = row.getFirstCellNum(); //第一个列位置
|
||||
int lastCellNum = row.getLastCellNum(); //最后一列位置
|
||||
int nullCellNum = 0; //空列数量
|
||||
for (int c = firstCellNum; c < lastCellNum; c++) { |
||||
Cell cell = row.getCell(c); |
||||
if (null == cell || CellType.BLANK == cell.getCellType()) { |
||||
nullCellNum++; |
||||
continue; |
||||
} |
||||
cell.setCellType(CellType.STRING); |
||||
String cellValue = cell.getStringCellValue().trim(); |
||||
if (StringUtils.isEmpty(cellValue)) { |
||||
nullCellNum++; |
||||
} |
||||
} |
||||
//所有列都为空
|
||||
if (nullCellNum == (lastCellNum - firstCellNum)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
private static Workbook getWorkbook(MultipartFile file) { |
||||
String fileName = file.getOriginalFilename(); |
||||
Workbook workbook = null; |
||||
|
||||
if (fileName.endsWith("xlsx")) { |
||||
try { |
||||
workbook = new XSSFWorkbook(file.getInputStream()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} else if (fileName.endsWith("xls")) { |
||||
try { |
||||
workbook = new HSSFWorkbook(file.getInputStream()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return workbook; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @Description : 读取文件数据 |
||||
* @Param file |
||||
* @Author Rong---2021/10/15 |
||||
*/ |
||||
public static List<ExcelImpUserReq> readUser(MultipartFile file) { |
||||
List<ExcelImpUserReq> list = new ArrayList<>(); |
||||
|
||||
Workbook workbook = getWorkbook(file); |
||||
ExcelImpUserReq excelImpUserReq = null; |
||||
// 循环工作表Sheet
|
||||
for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { |
||||
Sheet hssfSheet = workbook.getSheetAt(numSheet); |
||||
if (hssfSheet == null) { |
||||
continue; |
||||
} |
||||
|
||||
int count = 1; |
||||
// 循环行Row//开始行2
|
||||
for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { |
||||
Row row = hssfSheet.getRow(rowNum); |
||||
|
||||
if (isRowEmpty(row)) { |
||||
count++; |
||||
if (count == hssfSheet.getLastRowNum()) { |
||||
throw new BusinessException(BaseResponseCode.EXCEL_FILE_NULL); |
||||
} |
||||
continue; |
||||
} |
||||
|
||||
Cell realName;//姓名
|
||||
Cell userName;//账号
|
||||
Cell jobNumber;//工号
|
||||
Cell dept;//所在部门
|
||||
Cell roleName;//角色
|
||||
Cell phone;//手机号
|
||||
Cell email;//邮箱
|
||||
Cell groupName;//用户组
|
||||
if (row != null) { |
||||
|
||||
excelImpUserReq = new ExcelImpUserReq(); |
||||
|
||||
if (row.getCell(7) != null) { |
||||
row.getCell(7).setCellType(CellType.STRING); |
||||
groupName = row.getCell(7); |
||||
} else { |
||||
groupName = row.createCell(7); |
||||
} |
||||
|
||||
if (row.getCell(6) != null) { |
||||
row.getCell(6).setCellType(CellType.STRING); |
||||
email = row.getCell(6); |
||||
} else { |
||||
email = row.createCell(6); |
||||
} |
||||
|
||||
if (row.getCell(5) != null) { |
||||
row.getCell(5).setCellType(CellType.STRING); |
||||
phone = row.getCell(5); |
||||
} else { |
||||
phone = row.createCell(5); |
||||
} |
||||
|
||||
if (row.getCell(4) != null) { |
||||
row.getCell(4).setCellType(CellType.STRING); |
||||
dept = row.getCell(4); |
||||
} else { |
||||
dept = row.createCell(4); |
||||
} |
||||
|
||||
if (row.getCell(3) != null) { |
||||
row.getCell(3).setCellType(CellType.STRING); |
||||
jobNumber = row.getCell(3); |
||||
} else { |
||||
jobNumber = row.createCell(3); |
||||
} |
||||
|
||||
if (row.getCell(2) != null) { |
||||
row.getCell(2).setCellType(CellType.STRING); |
||||
roleName = row.getCell(2); |
||||
} else { |
||||
roleName = row.createCell(3); |
||||
} |
||||
|
||||
if (row.getCell(1) != null) { |
||||
row.getCell(1).setCellType(CellType.STRING); |
||||
userName = row.getCell(1); |
||||
} else { |
||||
userName = row.createCell(1); |
||||
} |
||||
|
||||
if (row.getCell(0) != null) { |
||||
row.getCell(0).setCellType(CellType.STRING); |
||||
realName = row.getCell(0); |
||||
} else { |
||||
realName = row.createCell(0); |
||||
} |
||||
|
||||
excelImpUserReq.setRealName(realName.getStringCellValue()); |
||||
excelImpUserReq.setUserName(userName.getStringCellValue()); |
||||
excelImpUserReq.setJobNumber(jobNumber.getStringCellValue()); |
||||
excelImpUserReq.setDept(dept.getStringCellValue()); |
||||
excelImpUserReq.setRoleName(roleName.getStringCellValue()); |
||||
excelImpUserReq.setPhone(phone.getStringCellValue()); |
||||
excelImpUserReq.setEmail(email.getStringCellValue()); |
||||
excelImpUserReq.setGroupName(groupName.getStringCellValue()); |
||||
|
||||
list.add(excelImpUserReq); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
return list; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,187 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; |
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; |
||||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; |
||||
import org.apache.poi.ss.usermodel.*; |
||||
|
||||
/** |
||||
* @ProjectName: huorantech |
||||
* @Package: com.huoran.common.utils |
||||
* @ClassName: ExcelStyleUtil |
||||
* @Description: easy poi导出设置样式 |
||||
* @Author: Maureen.Rong |
||||
* @CreateDate: 2021/9/1 14:29 |
||||
* @UpdateDate: 2021/9/1 14:29 |
||||
* @Version: 1.0 |
||||
*/ |
||||
public class ExcelStyleUtil implements IExcelExportStyler { |
||||
private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); |
||||
private static final short FONT_SIZE_TEN = 9; |
||||
private static final short FONT_SIZE_ELEVEN = 10; |
||||
private static final short FONT_SIZE_TWELVE = 50; |
||||
|
||||
/** |
||||
* 大标题样式 |
||||
*/ |
||||
private CellStyle headerStyle; |
||||
/** |
||||
* 每列标题样式 |
||||
*/ |
||||
private CellStyle titleStyle; |
||||
/** |
||||
* 数据行样式 |
||||
*/ |
||||
private CellStyle styles; |
||||
|
||||
public ExcelStyleUtil(Workbook workbook) { |
||||
this.init(workbook); |
||||
} |
||||
|
||||
/** |
||||
* 初始化样式 |
||||
* |
||||
* @param workbook |
||||
*/ |
||||
private void init(Workbook workbook) { |
||||
this.headerStyle = initHeaderStyle(workbook); |
||||
this.titleStyle = initTitleStyle(workbook); |
||||
this.styles = initStyles(workbook); |
||||
} |
||||
|
||||
/** |
||||
* 大标题样式 |
||||
* |
||||
* @param color |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public CellStyle getHeaderStyle(short color) { |
||||
return headerStyle; |
||||
} |
||||
|
||||
/** |
||||
* 每列标题样式 |
||||
* |
||||
* @param color |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public CellStyle getTitleStyle(short color) { |
||||
return titleStyle; |
||||
} |
||||
|
||||
/** |
||||
* 数据行样式 |
||||
* |
||||
* @param parity 可以用来表示奇偶行 |
||||
* @param entity 数据内容 |
||||
* @return 样式 |
||||
*/ |
||||
@Override |
||||
public CellStyle getStyles(boolean parity, ExcelExportEntity entity) { |
||||
return styles; |
||||
} |
||||
|
||||
/** |
||||
* 获取样式方法 |
||||
* |
||||
* @param dataRow 数据行 |
||||
* @param obj 对象 |
||||
* @param data 数据 |
||||
*/ |
||||
@Override |
||||
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) { |
||||
return getStyles(true, entity); |
||||
} |
||||
|
||||
/** |
||||
* 模板使用的样式设置 |
||||
*/ |
||||
@Override |
||||
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 初始化--大标题样式 |
||||
* |
||||
* @param workbook |
||||
* @return |
||||
*/ |
||||
private CellStyle initHeaderStyle(Workbook workbook) { |
||||
CellStyle style = getBaseCellStyle(workbook); |
||||
style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true)); |
||||
return style; |
||||
} |
||||
|
||||
/** |
||||
* 初始化--每列标题样式 |
||||
* |
||||
* @param workbook |
||||
* @return |
||||
*/ |
||||
private CellStyle initTitleStyle(Workbook workbook) { |
||||
CellStyle style = getBaseCellStyle(workbook); |
||||
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false)); |
||||
//背景色
|
||||
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
||||
return style; |
||||
} |
||||
|
||||
/** |
||||
* 初始化--数据行样式 |
||||
* |
||||
* @param workbook |
||||
* @return |
||||
*/ |
||||
private CellStyle initStyles(Workbook workbook) { |
||||
CellStyle style = getBaseCellStyle(workbook); |
||||
style.setFont(getFont(workbook, FONT_SIZE_TEN, false)); |
||||
style.setDataFormat(STRING_FORMAT); |
||||
return style; |
||||
} |
||||
|
||||
/** |
||||
* 基础样式 |
||||
* |
||||
* @return |
||||
*/ |
||||
private CellStyle getBaseCellStyle(Workbook workbook) { |
||||
CellStyle style = workbook.createCellStyle(); |
||||
//下边框
|
||||
style.setBorderBottom(BorderStyle.THIN); |
||||
//左边框
|
||||
style.setBorderLeft(BorderStyle.THIN); |
||||
//上边框
|
||||
style.setBorderTop(BorderStyle.THIN); |
||||
//右边框
|
||||
style.setBorderRight(BorderStyle.THIN); |
||||
//水平居中
|
||||
style.setAlignment(HorizontalAlignment.CENTER); |
||||
//上下居中
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER); |
||||
//设置自动换行
|
||||
style.setWrapText(true); |
||||
return style; |
||||
} |
||||
|
||||
/** |
||||
* 字体样式 |
||||
* |
||||
* @param size 字体大小 |
||||
* @param isBold 是否加粗 |
||||
* @return |
||||
*/ |
||||
private Font getFont(Workbook workbook, short size, boolean isBold) { |
||||
Font font = workbook.createFont(); |
||||
//字体样式
|
||||
font.setFontName("宋体"); |
||||
//是否加粗
|
||||
font.setBold(isBold); |
||||
//字体大小
|
||||
font.setFontHeightInPoints(size); |
||||
return font; |
||||
} |
||||
} |
@ -0,0 +1,224 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import org.apache.commons.lang.StringUtils; |
||||
|
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 代码生成器 工具类 |
||||
* |
||||
* @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,116 @@ |
||||
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); |
||||
} |
||||
|
||||
public static R fail(Object data) { |
||||
return new R(data); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 自定义返回 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,64 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import java.text.DecimalFormat; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Random; |
||||
|
||||
/** |
||||
* 获取随机数 |
||||
* |
||||
* @author cheney |
||||
* |
||||
*/ |
||||
public class RandomUtil { |
||||
|
||||
private static final Random random = new Random(); |
||||
|
||||
private static final DecimalFormat fourdf = new DecimalFormat("0000"); |
||||
|
||||
private static final DecimalFormat sixdf = new DecimalFormat("000000"); |
||||
|
||||
public static String getFourBitRandom() { |
||||
return fourdf.format(random.nextInt(10000)); |
||||
} |
||||
|
||||
public static String getSixBitRandom() { |
||||
return sixdf.format(random.nextInt(1000000)); |
||||
} |
||||
|
||||
/** |
||||
* 给定数组,抽取n个数据 |
||||
* @param list |
||||
* @param n |
||||
* @return |
||||
*/ |
||||
public static ArrayList getRandom(List list, int n) { |
||||
|
||||
Random random = new Random(); |
||||
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>(); |
||||
|
||||
// 生成随机数字并存入HashMap
|
||||
for (int i = 0; i < list.size(); i++) { |
||||
|
||||
int number = random.nextInt(100) + 1; |
||||
|
||||
hashMap.put(number, i); |
||||
} |
||||
|
||||
// 从HashMap导入数组
|
||||
Object[] robjs = hashMap.values().toArray(); |
||||
|
||||
ArrayList r = new ArrayList(); |
||||
|
||||
// 遍历数组并打印数据
|
||||
for (int i = 0; i < n; i++) { |
||||
r.add(list.get((int) robjs[i])); |
||||
System.out.print(list.get((int) robjs[i]) + "\t"); |
||||
} |
||||
System.out.print("\n"); |
||||
return r; |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
/** |
||||
* @Author chen |
||||
* @DATE 2021/7/7 14:14 |
||||
* @Version 1.0 |
||||
*/ |
||||
public interface SMSTemplate { |
||||
|
||||
// 短信签名
|
||||
String SMS_SIGNATURE = "或然科技"; |
||||
|
||||
// 找回密码验证码
|
||||
String RETRIEVE_PASSWORD_CODE = "SMS_219310031"; |
||||
|
||||
// 身份验证验证码
|
||||
String AUTHENTICATION_CODE = "SMS_221515019"; |
||||
|
||||
// 登录确认验证码
|
||||
String LOGIN_VERIFICATION_CODE = "SMS_204155296"; |
||||
|
||||
// 登录异常验证码
|
||||
String LOGIN_EXCEPTION_CODE = "SMS_204155295"; |
||||
|
||||
// 用户注册验证码
|
||||
String USER_REGISTRATION_CODE = "SMS_204155294"; |
||||
|
||||
// 修改密码验证码
|
||||
String MODIFY_PASSWORD_CODE = "SMS_204155293"; |
||||
|
||||
// 信息变更验证码
|
||||
String INFORMATION_CHANGE_CODE = "SMS_204155292"; |
||||
|
||||
} |
@ -0,0 +1,51 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.aliyuncs.CommonRequest; |
||||
import com.aliyuncs.CommonResponse; |
||||
import com.aliyuncs.DefaultAcsClient; |
||||
import com.aliyuncs.IAcsClient; |
||||
import com.aliyuncs.exceptions.ClientException; |
||||
import com.aliyuncs.http.MethodType; |
||||
import com.aliyuncs.profile.DefaultProfile; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.util.Map; |
||||
|
||||
|
||||
@Slf4j |
||||
public class SendSMSUtils { |
||||
|
||||
public static boolean send(String PhoneNumbers, String templateCode, Map<String,Object> param) { |
||||
|
||||
if(StringUtils.isEmpty(PhoneNumbers)) { |
||||
return false; |
||||
} |
||||
|
||||
DefaultProfile profile = |
||||
DefaultProfile.getProfile("default", "LTAI4FzqQHnk4rozqLZ8jCNj", "mveW7B1OyFoKUkHm8WsxmrjHmkJWHq"); |
||||
IAcsClient client = new DefaultAcsClient(profile); |
||||
|
||||
CommonRequest request = new CommonRequest(); |
||||
request.setMethod(MethodType.GET); |
||||
request.setDomain("dysmsapi.aliyuncs.com"); |
||||
request.setVersion("2017-05-25"); |
||||
request.setAction("SendSms"); |
||||
|
||||
request.putQueryParameter("PhoneNumbers", PhoneNumbers); |
||||
request.putQueryParameter("SignName", SMSTemplate.SMS_SIGNATURE); |
||||
request.putQueryParameter("TemplateCode", templateCode); |
||||
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param)); |
||||
|
||||
try { |
||||
CommonResponse response = client.getCommonResponse(request); |
||||
System.out.println(response.getData()); |
||||
return response.getHttpResponse().isSuccess(); |
||||
} catch (ClientException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
@ -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,110 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
||||
import com.huoran.iasf.entity.SysColumn; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
public class TreeStructureUtils { |
||||
|
||||
// 获取树结构数据
|
||||
public static List<SysColumn> getList(List<SysColumn> columns) { |
||||
try { |
||||
List<SysColumn> result = new ArrayList<>(); |
||||
for (SysColumn test : columns) { |
||||
if (test.getFatherId() == 0) { |
||||
result.add(test); |
||||
} |
||||
} |
||||
for (SysColumn test : result) { |
||||
List<SysColumn> childList = getChildren(test.getId(), columns); |
||||
test.setChildren(childList); |
||||
} |
||||
// 将一层一层的树结构数据返回吧!
|
||||
return result; |
||||
} catch (Exception e) { |
||||
// 这里可以抛个异常
|
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
//把一个List转成树
|
||||
public static List<SysColumn> buildTree(List<SysColumn> list, Integer pid) { |
||||
List<SysColumn> tree = new ArrayList<>(); |
||||
for (SysColumn node : list) { |
||||
if (Objects.equals(node.getFatherId(), pid)) { |
||||
tree.add(findChild(node, list)); |
||||
} |
||||
} |
||||
return tree; |
||||
} |
||||
|
||||
static SysColumn findChild(SysColumn node, List<SysColumn> list) { |
||||
for (SysColumn n : list) { |
||||
if (Objects.equals(n.getFatherId(), node.getId())) { |
||||
if (node.getChildren() == null) { |
||||
node.setChildren(new ArrayList<SysColumn>()); |
||||
} |
||||
node.getChildren().add(findChild(n, list)); |
||||
} |
||||
} |
||||
return node; |
||||
} |
||||
|
||||
public static List<SysColumn> getChildren(Integer id, List<SysColumn> allDept) { |
||||
//存放子节点
|
||||
List<SysColumn> childList = new ArrayList<>(); |
||||
//遍历所有栏目,如果父id与传来的id相同,则为传来的id这个栏目的子栏目
|
||||
for (SysColumn dept : allDept) { |
||||
Integer parentId = dept.getFatherId(); |
||||
if (parentId.equals(id)) { |
||||
childList.add(dept); |
||||
} |
||||
} |
||||
|
||||
//自调用来判断是否还有子节点
|
||||
for (SysColumn dept : childList) { |
||||
dept.setChildren(getChildren(dept.getId(), allDept)); |
||||
} |
||||
|
||||
//如果没有子节点则返回空集合
|
||||
if (childList.size() == 0) { |
||||
return new ArrayList<>(); |
||||
} |
||||
return childList; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* 双重for循环方法转换成树形结构 |
||||
* @param treeList |
||||
* @return |
||||
*/ |
||||
public static List<SysColumn> forMethod(List<SysColumn> treeList) { |
||||
List<SysColumn> rootTree = new ArrayList<>(); |
||||
for (SysColumn tree : treeList) { |
||||
// 第一步 筛选出最顶级的父节点
|
||||
if (0 == tree.getFatherId()) { |
||||
rootTree.add(tree); |
||||
} |
||||
// 第二步 筛选出该父节点下的所有子节点列表
|
||||
for (SysColumn node : treeList) { |
||||
if (node.getFatherId().equals(tree.getId())) { |
||||
if (CollectionUtils.isEmpty(tree.getChildren())) { |
||||
tree.setChildren(new ArrayList<>()); |
||||
} |
||||
tree.getChildren().add(node); |
||||
} |
||||
} |
||||
} |
||||
return rootTree; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.huoran.iasf.common.utils; |
||||
|
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
|
||||
/** |
||||
* 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,68 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.service.RedisService; |
||||
import com.wf.captcha.ArithmeticCaptcha; |
||||
import com.wf.captcha.base.Captcha; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpHeaders; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
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 { |
||||
|
||||
@Resource |
||||
private RedisService redisService; |
||||
/** |
||||
* 获取验证码图片 |
||||
* Gets captcha code. |
||||
*/ |
||||
/* @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); |
||||
}*/ |
||||
|
||||
@ApiOperation(value = "登录验证码") |
||||
@GetMapping(value = "/getVerify",produces = "image/png") |
||||
public void captcha( |
||||
@ApiParam(name = "random", value = "随机数", required = true) |
||||
@RequestParam String random, HttpServletResponse response){ |
||||
Captcha captcha = new ArithmeticCaptcha(); |
||||
//生成验证码
|
||||
String text = captcha.text(); |
||||
//缓存验证码
|
||||
redisService.setAndExpire(random,text,120); |
||||
response.setContentType(MediaType.IMAGE_PNG_VALUE); |
||||
response.setHeader(HttpHeaders.PRAGMA, "No-cache"); |
||||
response.setHeader(HttpHeaders.CACHE_CONTROL, "No-cache"); |
||||
response.setDateHeader(HttpHeaders.EXPIRES, 0L); |
||||
try { |
||||
captcha.out(response.getOutputStream()); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,105 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysDept; |
||||
import com.huoran.iasf.service.DeptService; |
||||
import com.huoran.iasf.vo.resp.DeptRespNodeVO; |
||||
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.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 DeptController { |
||||
@Resource |
||||
private DeptService deptService; |
||||
@NoRepeatSubmit |
||||
@PostMapping("/dept") |
||||
@ApiOperation(value = "新增组织接口") |
||||
@LogAnnotation(title = "机构管理", action = "新增组织") |
||||
@RequiresPermissions("sys:dept:add") |
||||
public R addDept(@RequestBody @Valid SysDept vo) { |
||||
boolean ok = deptService.checkDeptRepeat(vo); |
||||
if (ok) { |
||||
return R.fail("同级下已存在相同的名称:" + vo.getName()); |
||||
} |
||||
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不能为空"); |
||||
} |
||||
boolean ok = deptService.checkDeptRepeat(vo); |
||||
if (ok) { |
||||
return R.fail("同级下已存在相同的名称:" + vo.getName()); |
||||
} |
||||
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 = "树型组织列表接口",response = DeptRespNodeVO.class) |
||||
@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( |
||||
@ApiParam(name = "deptId", value = "部门id",required = false) |
||||
@RequestParam(required = false) String deptId) { |
||||
return R.success(deptService.deptTreeList(deptId)); |
||||
} |
||||
|
||||
/* @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,25 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.exception.BusinessException; |
||||
import com.huoran.iasf.common.exception.UnauthorizedException; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.ResponseStatus; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* 过滤器异常控制器 |
||||
*/ |
||||
@RestController |
||||
public class ExceptionController { |
||||
|
||||
@RequestMapping(Constant.ERROR_CONTROLLER_PATH) |
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED) |
||||
public void handleException(HttpServletRequest request){ |
||||
throw (UnauthorizedException) request.getAttribute("filterError"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,44 @@ |
||||
/* |
||||
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,102 @@ |
||||
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; |
||||
|
||||
/** |
||||
* 菜单权限管理 |
||||
* |
||||
* @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(); |
||||
}*/ |
||||
|
||||
@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,129 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysRole; |
||||
import com.huoran.iasf.entity.SysRolePermission; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import com.huoran.iasf.service.RolePermissionService; |
||||
import com.huoran.iasf.service.RoleService; |
||||
import com.huoran.iasf.vo.req.RolePermissionOperationReqVO; |
||||
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 javax.validation.Valid; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
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 RolePermissionService rolePermissionService; |
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
@NoRepeatSubmit |
||||
@PostMapping("/role") |
||||
@ApiOperation(value = "新增角色接口") |
||||
@LogAnnotation(title = "角色管理", action = "新增角色") |
||||
@RequiresPermissions("sys:role:add") |
||||
public R addRole(@RequestBody @Valid SysRole vo) { |
||||
boolean ok = roleService.checkDeptRepeat(vo); |
||||
if (ok) { |
||||
return R.fail("已存在相同的角色名称:" + vo.getName()); |
||||
} |
||||
roleService.addRole(vo); |
||||
//删除角色权限关联
|
||||
rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, vo.getId())); |
||||
if (!CollectionUtils.isEmpty(vo.getPermissions())) { |
||||
RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO(); |
||||
reqVO.setRoleId(vo.getId()); |
||||
reqVO.setPermissionIds(vo.getPermissions()); |
||||
rolePermissionService.addRolePermission(reqVO); |
||||
// 刷新权限
|
||||
httpSessionService.refreshRolePermission(vo.getId()); |
||||
} |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/role/deleted") |
||||
@ApiOperation(value = "删除角色接口") |
||||
@LogAnnotation(title = "角色管理", action = "删除角色") |
||||
@RequiresPermissions("sys:role:deleted") |
||||
public R deleted(@RequestBody @ApiParam(value = "id集合") List<Integer> ids) { |
||||
roleService.deletedRole(ids); |
||||
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不能为空"); |
||||
} |
||||
boolean ok = roleService.checkDeptRepeat(vo); |
||||
if (ok) { |
||||
return R.fail("已存在相同的角色名称:" + vo.getName()); |
||||
} |
||||
roleService.updateRole(vo); |
||||
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));
|
||||
SysRole role = roleService.getById(id); |
||||
QueryWrapper<SysRolePermission> wrapper = new QueryWrapper<>(); |
||||
wrapper.eq("role_id", id).select("permission_id"); |
||||
List<SysRolePermission> list = rolePermissionService.list(wrapper); |
||||
List<Integer> permissionList = new ArrayList<>(); |
||||
list.forEach(rolePermission -> { |
||||
permissionList.add(rolePermission.getPermissionId()); |
||||
}); |
||||
HashMap<String, Object> map = new HashMap<>(); |
||||
map.put("role", role); |
||||
map.put("permissionList", permissionList); |
||||
return R.success(map); |
||||
} |
||||
|
||||
@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()); |
||||
} |
||||
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,93 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
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.Site; |
||||
import com.huoran.iasf.service.SiteService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 站点管理 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author cheney |
||||
* @since 2022-08-24 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sys/site") |
||||
@Api(tags = "站点管理") |
||||
public class SiteController { |
||||
|
||||
@Autowired |
||||
private SiteService siteService; |
||||
|
||||
@PostMapping("/add") |
||||
// @ApiOperation(value = "新增站点")
|
||||
// @LogAnnotation(title = "站点管理", action = "新增站点")
|
||||
// @RequiresPermissions("sys:site:add")
|
||||
public R addUserGroup(@RequestBody Site site) { |
||||
Site one = siteService.getOne(new QueryWrapper<Site>(). |
||||
eq("site_name", site.getSiteName())); |
||||
if (ObjectUtil.isNotNull(one)){ |
||||
R.fail("站点已存在"); |
||||
} |
||||
siteService.save(site); |
||||
return R.success(); |
||||
} |
||||
|
||||
@DeleteMapping("/delete/{id}") |
||||
// @ApiOperation(value = "删除站点")
|
||||
// @LogAnnotation(title = "站点管理", action = "删除站点")
|
||||
// @RequiresPermissions("sys:site:deleted")
|
||||
public R deleted(@PathVariable("id") Integer id) { |
||||
siteService.removeById(id); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
// @ApiOperation(value = "更新站点")
|
||||
// @LogAnnotation(title = "站点管理", action = "更新站点")
|
||||
// @RequiresPermissions("sys:site:update")
|
||||
public R updateUserGroup(@RequestBody Site site) { |
||||
if (StringUtils.isEmpty(site.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
QueryWrapper<Site> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("domain_name", site.getDomainName()); |
||||
queryWrapper.last(" and id != " + site.getId()); |
||||
List<Site> groups = siteService.list(queryWrapper); |
||||
if (ObjectUtil.isNotNull(groups) && groups.size()>0){ |
||||
R.fail("域名已存在"); |
||||
} |
||||
siteService.updateById(site); |
||||
return R.success(); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/list") |
||||
@ApiOperation(value = "站点列表") |
||||
@LogAnnotation(title = "站点管理", action = "获取所有站点") |
||||
// @RequiresPermissions("sys:site:list")
|
||||
public R getUserGroupAll(@RequestBody Site site) { |
||||
LambdaQueryWrapper<Site> queryWrapper = Wrappers.lambdaQuery(); |
||||
if (!StringUtils.isEmpty(site.getSiteName())) { |
||||
queryWrapper.like(Site::getSiteName, site.getSiteName()); |
||||
} |
||||
IPage<Site> iPage = siteService.page(site.getQueryPage(),queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,352 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.*; |
||||
import com.huoran.iasf.service.*; |
||||
import com.huoran.iasf.vo.req.ColumnWeightReqVO; |
||||
import com.huoran.iasf.vo.req.PaginationColumnReqVO; |
||||
import com.huoran.iasf.vo.resp.SortColumnRespVO; |
||||
import io.swagger.annotations.*; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiOperation; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.validation.Valid; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.util.ArrayList; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
|
||||
/** |
||||
* @描述:栏目基础信息控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-01 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sysColumn") |
||||
@Api(value = "栏目基础信息:SysColumnController", tags = "R-栏目管理") |
||||
public class SysColumnController { |
||||
|
||||
@Autowired |
||||
public SysColumnService service; |
||||
|
||||
@Autowired |
||||
public SysContentService contentService; |
||||
|
||||
@Autowired |
||||
public SysTemplateService templateService; |
||||
|
||||
@Autowired |
||||
public SysTemplateStyleService styleService; |
||||
|
||||
@Autowired |
||||
public SysColumnLongPageService sysColumnLongPageService; |
||||
|
||||
@Autowired |
||||
public SysTemplateStyleConfigurationService templateStyleConfigurationService; |
||||
|
||||
@Autowired |
||||
public SysFilesService sysFilesService; |
||||
|
||||
@PostMapping("/listWithTree") |
||||
@ApiOperation(value = "栏目树结构", response = SysColumn.class) |
||||
public R listWithTree(@RequestBody @Valid PaginationColumnReqVO sysColumn) { |
||||
return R.success(service.listWithTree(sysColumn)); |
||||
} |
||||
|
||||
@PostMapping("/listWithTreeMenuVisible") |
||||
@ApiOperation(value = "栏目树结构(前台可见,只展示试单可见的栏目)", response = SysColumn.class) |
||||
public R listWithTreeMenuVisible(@RequestBody @Valid PaginationColumnReqVO sysColumn) { |
||||
return R.success(service.listWithTreeMenuVisible(sysColumn)); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysColumn.class) |
||||
public R findById(@RequestParam("id") @ApiParam(value = "序号") Integer id) { |
||||
SysColumn sysColumn = service.getById(id); |
||||
if (sysColumn == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
SysTemplateStyle sysTemplateStyle = styleService.getById(sysColumn.getListStyleId()); |
||||
|
||||
if (sysTemplateStyle.getPath() != null) { |
||||
sysColumn.setPath(sysTemplateStyle.getPath()); |
||||
} |
||||
|
||||
return R.success(sysColumn); |
||||
} |
||||
|
||||
@NoRepeatSubmit |
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysColumn.class) |
||||
public R save(@RequestBody @Valid SysColumn sysColumn) { |
||||
QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<SysColumn>(); |
||||
queryWrapper.eq("father_id", sysColumn.getFatherId()); |
||||
Integer count = service.count(queryWrapper); |
||||
sysColumn.setSort(count + 1); |
||||
boolean addState = service.save(sysColumn); |
||||
return addState ? R.success(sysColumn.getId()) : R.fail("新增失败"); |
||||
} |
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysColumn.class) |
||||
public R update(@RequestBody SysColumn sysColumn) { |
||||
boolean updateState = service.updateById(sysColumn); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
/*@NoRepeatSubmit |
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysContent.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>(); |
||||
filesEntityUpdateWrapper.eq("quote_id", id); |
||||
filesEntityUpdateWrapper.eq("quote_type", 1); |
||||
filesEntityUpdateWrapper.set("is_del", 1); |
||||
sysFilesService.update(filesEntityUpdateWrapper); |
||||
|
||||
boolean delState = service.removeById(id); |
||||
|
||||
QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.in("column_id", id); |
||||
//删除栏目后删除栏目下的文章
|
||||
List<SysContent> contentId = contentService.list(queryWrapper); |
||||
contentService.removeByIds(contentId); |
||||
|
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
}*/ |
||||
|
||||
@NoRepeatSubmit |
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除栏目", response = SysColumn.class) |
||||
public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List<Integer> ids) { |
||||
boolean ret = false; |
||||
for (Integer id : ids) { |
||||
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>(); |
||||
filesEntityUpdateWrapper.eq("quote_id", id); |
||||
filesEntityUpdateWrapper.eq("quote_type", 1); |
||||
filesEntityUpdateWrapper.set("is_del", 1); |
||||
sysFilesService.update(filesEntityUpdateWrapper); |
||||
//1 创建list集合,用于封装所有删除菜单id值
|
||||
List<Integer> idList = new ArrayList<>(); |
||||
//2 向idList集合设置删除菜单id
|
||||
//找到当前菜单的子菜单 把结果id封装到idlist里面去
|
||||
this.selectCategoryChildById(id + "", idList); |
||||
//把当前id封装到list里面 //现在把当前id封装进去 之前都是子菜单的id
|
||||
idList.add(id); |
||||
|
||||
//删除当前栏目以及栏目下的文章
|
||||
QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.in("column_id", idList); |
||||
//删除栏目后删除栏目下的文章
|
||||
contentService.remove(queryWrapper); |
||||
|
||||
|
||||
//删除长页栏目
|
||||
QueryWrapper<SysColumnLongPage> queryWrapper1 = new QueryWrapper<SysColumnLongPage>(); |
||||
queryWrapper1.in("column_id", idList); |
||||
//删除栏目后删除栏目下的文章
|
||||
sysColumnLongPageService.remove(queryWrapper1); |
||||
ret = service.removeByIds(idList); |
||||
} |
||||
|
||||
|
||||
return R.success(); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/sameLevelJudgment") |
||||
@ApiOperation(value = "同级判重", response = ColumnWeightReqVO.class) |
||||
public R sameLevelJudgment(@RequestBody @Valid ColumnWeightReqVO sysColumn) { |
||||
return service.sameLevelJudgment(sysColumn) ? R.success() : R.fail("同级下已存在重复栏目!"); |
||||
} |
||||
|
||||
@PostMapping("/sortByColumn") |
||||
@ApiOperation(value = "栏目排序(依据id更改)", response = SysColumn.class) |
||||
public R sortByColumn(@RequestBody List<SortColumnRespVO> sortColumnRespVOList) { |
||||
for (SortColumnRespVO sort : sortColumnRespVOList) { |
||||
|
||||
SysColumn column = service.getById(sort.getId()); |
||||
|
||||
QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("column_name", column.getColumnName()); |
||||
queryWrapper.eq("site_id", column.getSiteId()); |
||||
queryWrapper.eq("father_id", sort.getFatherId()); |
||||
queryWrapper.last(" and id <> " + sort.getId()); |
||||
List<SysColumn> columnList = service.list(queryWrapper); |
||||
if (columnList.size() > 0) { |
||||
return R.fail("同级下已存在重复栏目:" + column.getColumnName()); |
||||
} |
||||
|
||||
SysColumn sysColumn = new SysColumn(); |
||||
BeanUtils.copyProperties(sort, sysColumn); |
||||
service.updateById(sysColumn); |
||||
} |
||||
|
||||
return R.success(); |
||||
} |
||||
|
||||
@ApiOperation("获取一级下的子级栏目") |
||||
@PostMapping("/getsTheSubColumn") |
||||
public R getsTheSubColumn(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id, |
||||
@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) { |
||||
String ids = this.getIds(id); |
||||
return service.getsTheSubColumn(id, ids,siteId); |
||||
|
||||
} |
||||
|
||||
|
||||
@ApiOperation("获取某层级下的子级栏目") |
||||
@PostMapping("/getsSublevelColumnsUnderALevel") |
||||
public R getsSublevelColumnsUnderALevel(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id, |
||||
@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) { |
||||
String ids = this.getIds(id); |
||||
return service.getsTheSubColumn(id, ids,siteId); |
||||
|
||||
} |
||||
|
||||
|
||||
public String getIds(Integer id) { |
||||
//1 创建list集合,用于封装所有删除菜单id值
|
||||
List<Integer> idList = new ArrayList<>(); |
||||
//2 向idList集合设置删除菜单id
|
||||
this.selectCategoryChildById(id + "", idList);//找到当前菜单的子菜单 把结果id封装到idlist里面去
|
||||
//把当前id封装到list里面
|
||||
idList.add(id);//现在把当前id封装进去 之前都是子菜单的id
|
||||
String str = ""; |
||||
for (Integer idstr : idList) { |
||||
str += idstr + ","; |
||||
} |
||||
String ids = str.substring(0, str.length() - 1); |
||||
return ids; |
||||
} |
||||
|
||||
public void selectCategoryChildById(String id, List<Integer> idList) { |
||||
//查询菜单里面子菜单id
|
||||
QueryWrapper<SysColumn> wrapper = new QueryWrapper<SysColumn>(); |
||||
wrapper.eq("father_id", id); |
||||
wrapper.eq("deleted", Constant.DATA_NOT_DELETED); |
||||
//查询指定列的值
|
||||
wrapper.select("id"); |
||||
//当前菜单的所有子菜单
|
||||
List<SysColumn> childIdList = service.list(wrapper); |
||||
//把childIdList里面菜单id值获取出来,封装idList里面,做递归查询
|
||||
//遍历集合得到每一个对象item
|
||||
childIdList.stream().forEach(item -> { |
||||
//封装idList里面
|
||||
idList.add(item.getId()); |
||||
//递归查询
|
||||
this.selectCategoryChildById(item.getId() + "", idList); |
||||
}); |
||||
} |
||||
|
||||
|
||||
@ApiOperation("获取一级下的子级栏目以及下的全部文章标签") |
||||
@PostMapping("/getTheFullArticleByColumn") |
||||
public R getTheFullArticleByColumn(@ApiParam(name = "id", value = "一级栏目id", required = true) @RequestParam Integer id) { |
||||
String ids = this.getIds(id); |
||||
return contentService.getTheFullArticleByColumn(ids); |
||||
} |
||||
|
||||
|
||||
@ApiOperation("获取子级栏目id") |
||||
@PostMapping("/getsTheChildColumnId") |
||||
public R getsTheSublevelColumnIdOfTheNextLevel(@ApiParam(name = "id", value = "一级栏目id", required = true) @RequestParam Integer id) { |
||||
//1 创建list集合,用于封装所有删除菜单id值
|
||||
List<Integer> idList = new ArrayList<>(); |
||||
//2 向idList集合设置删除菜单id
|
||||
this.selectCategoryChildById(id + "", idList);//找到当前菜单的子菜单 把结果id封装到idlist里面去
|
||||
//把当前id封装到list里面
|
||||
idList.add(id);//现在把当前id封装进去 之前都是子菜单的id
|
||||
return R.success(idList); |
||||
|
||||
} |
||||
|
||||
@ApiOperation("某一级查全部") |
||||
@PostMapping("/oneLevelChecksThemAll") |
||||
public R oneLevelChecksThemAll(@ApiParam(name = "id", value = "栏目id", required = true) @RequestParam Integer id, |
||||
@ApiParam(name = "isSort", value = "判断是否为排序接口调用(1为排序接口调用 0我栏目管理列表调用)", required = true) @RequestParam Integer isSort, |
||||
@ApiParam(name = "ids", value = "主键", required = true) @RequestParam Integer siteId |
||||
) { |
||||
|
||||
Integer pid = service.oneLevelChecksThemAll(id); |
||||
String ids = this.getIds(pid); |
||||
return service.getSubColumn(pid, ids, isSort,siteId); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 查询栏目下的文章(若选中栏目与子级全部栏目类型一致返回全部文章,反之查询选中栏目下的文章) |
||||
* 2023.02.22依需求更改为以发布时间排序(非创建时间) |
||||
* |
||||
* @param columnId |
||||
* @return |
||||
*/ |
||||
@ApiOperation("查询栏目下的文章(若选中栏目与子级全部栏目类型一致返回全部文章,反之查询选中栏目下的文章)") |
||||
@PostMapping("/queryArticlesByColumnType") |
||||
public R queryArticlesByColumnType(@ApiParam(name = "columnId", value = "栏目id", required = true) @RequestParam Integer columnId) { |
||||
String ids = this.getIds(columnId); |
||||
return service.queryArticlesByColumnType(ids, columnId); |
||||
} |
||||
|
||||
|
||||
@NoRepeatSubmit |
||||
@PostMapping("/deleteUselessData") |
||||
@ApiOperation(value = "删除无用数据", response = SysColumn.class) |
||||
public R deleteUselessData() { |
||||
|
||||
QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("deleted", 0).select("id"); |
||||
List<SysColumn> list = service.list(queryWrapper); |
||||
|
||||
for (SysColumn column : list) { |
||||
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>(); |
||||
filesEntityUpdateWrapper.eq("quote_id", column.getId()); |
||||
filesEntityUpdateWrapper.eq("quote_type", 1); |
||||
filesEntityUpdateWrapper.set("is_del", 1); |
||||
sysFilesService.update(filesEntityUpdateWrapper); |
||||
//1 创建list集合,用于封装所有删除菜单id值
|
||||
List<Integer> idList = new ArrayList<>(); |
||||
//2 向idList集合设置删除菜单id
|
||||
//找到当前菜单的子菜单 把结果id封装到idlist里面去
|
||||
this.selectCategoryChildById(column.getId() + "", idList); |
||||
//把当前id封装到list里面 //现在把当前id封装进去 之前都是子菜单的id
|
||||
idList.add(column.getId()); |
||||
|
||||
//删除当前栏目以及栏目下的文章
|
||||
QueryWrapper<SysContent> queryWrapper1 = new QueryWrapper<>(); |
||||
queryWrapper1.in("column_id", idList); |
||||
//删除栏目后删除栏目下的文章
|
||||
contentService.remove(queryWrapper1); |
||||
|
||||
|
||||
//删除长页栏目
|
||||
QueryWrapper<SysColumnLongPage> queryWrapper2 = new QueryWrapper<SysColumnLongPage>(); |
||||
queryWrapper2.in("column_id", idList); |
||||
//删除栏目后删除栏目下的文章
|
||||
sysColumnLongPageService.remove(queryWrapper2); |
||||
service.removeByIds(idList); |
||||
} |
||||
|
||||
|
||||
return R.success(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,145 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysColumn; |
||||
import com.huoran.iasf.service.SysColumnService; |
||||
import com.huoran.iasf.vo.req.SysColumnLongRedisVO; |
||||
import io.swagger.annotations.*; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.data.redis.core.StringRedisTemplate; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiImplicitParam; |
||||
import io.swagger.annotations.ApiImplicitParams; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import com.huoran.iasf.service.SysColumnLongPageService; |
||||
import com.huoran.iasf.entity.SysColumnLongPage; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
|
||||
/** |
||||
* @描述:长页栏目拓展表控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-09 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sysColumnLongPage") |
||||
@Api(value = "长页栏目拓展表:SysColumnLongPageController", tags = "R-长页栏目拓展信息") |
||||
public class SysColumnLongPageController { |
||||
|
||||
@Autowired |
||||
public SysColumnLongPageService service; |
||||
@Autowired |
||||
public SysColumnService columnService; |
||||
@Autowired |
||||
private StringRedisTemplate redisTemplate; |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysColumnLongPage.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
SysColumnLongPage sysColumnLongPage = service.getById(id); |
||||
if (sysColumnLongPage == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
return R.success(sysColumnLongPage); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/getLongPageInformation") |
||||
@ApiOperation(value = "根据栏目id查询类型长页栏目信息", response = SysColumnLongPage.class) |
||||
public R getLongPageInformation(@ApiParam(name = "columnId", value = "栏目id", required = true) @RequestParam Integer columnId) { |
||||
QueryWrapper<SysColumnLongPage> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("column_id", columnId); |
||||
List<SysColumnLongPage> longPageList = service.list(queryWrapper); |
||||
return R.success(longPageList); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysColumnLongPage.class) |
||||
public R save(@RequestBody @Valid @ApiParam(name = "长页栏目拓展表对象", value = "传入json格式", required = true) SysColumnLongPage sysColumnLongPage) { |
||||
|
||||
SysColumn column = columnService.getById(sysColumnLongPage.getColumnId()); |
||||
if (sysColumnLongPage.getState() == Constant.ARTICLE_NOT_PUBLISHED) {//发布状态(0:草稿 1已发布)
|
||||
//发布状态为草稿箱时候 导航菜单是否启用为禁用状态
|
||||
column.setMenuVisible(Constant.THE_NAVIGATION_MENU_IS_NOT_VISIBLE); |
||||
} else { |
||||
column.setMenuVisible(Constant.NAVIGATION_MENU_VISIBLE); |
||||
} |
||||
|
||||
columnService.updateById(column); |
||||
boolean addState = service.save(sysColumnLongPage); |
||||
return addState ? R.success() : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysColumnLongPage.class) |
||||
public R update(@RequestBody @ApiParam(name = "长页栏目拓展表对象", value = "传入json格式", required = true) SysColumnLongPage sysColumnLongPage) { |
||||
SysColumn column = columnService.getById(sysColumnLongPage.getColumnId()); |
||||
if (sysColumnLongPage.getState() == Constant.ARTICLE_NOT_PUBLISHED) {//发布状态(0:草稿 1已发布)
|
||||
//发布状态为草稿箱时候 导航菜单是否启用为禁用状态
|
||||
column.setMenuVisible(Constant.THE_NAVIGATION_MENU_IS_NOT_VISIBLE); |
||||
|
||||
} else { |
||||
column.setMenuVisible(Constant.NAVIGATION_MENU_VISIBLE); |
||||
} |
||||
|
||||
columnService.updateById(column); |
||||
boolean updateState = service.updateById(sysColumnLongPage); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysColumnLongPage.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/saveTheCache") |
||||
@ApiOperation(value = "预览至储存(整个页面存储)") |
||||
public R saveTheCache(@RequestBody @ApiParam(name = "预览至储存对象", required = true) SysColumnLongRedisVO vo) { |
||||
String key = "saveTheCache:columnId:" + vo.getColumnId(); |
||||
//保存到缓存中
|
||||
redisTemplate.opsForValue().set(key, vo.getJson()); |
||||
return R.success(); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/getRedisCache") |
||||
@ApiOperation(value = "获取Redis缓存") |
||||
public R getRedisCache(@ApiParam(name = "columnId", value = "栏目id主键", required = true) @RequestParam Integer columnId) { |
||||
//保存的key名
|
||||
String key = "saveTheCache:columnId:" + columnId; |
||||
//查看缓存是否有数据
|
||||
String returnValue = redisTemplate.opsForValue().get(key); |
||||
|
||||
//使用缓存返回数据
|
||||
if (returnValue != null) { |
||||
return R.success(returnValue); |
||||
} |
||||
|
||||
|
||||
return R.success(); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,115 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysContentClassification; |
||||
import com.huoran.iasf.service.SysContentClassificationService; |
||||
import io.swagger.annotations.*; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiImplicitParam; |
||||
import io.swagger.annotations.ApiImplicitParams; |
||||
import io.swagger.annotations.ApiOperation; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @描述:文章所属分类控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-08 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/content/classification") |
||||
@Api(value = "文章所属分类:SysContentClassificationController", tags = "R-文章所属分类") |
||||
public class SysContentClassificationController { |
||||
|
||||
@Autowired |
||||
public SysContentClassificationService service; |
||||
|
||||
|
||||
@PostMapping("/allTheQuery") |
||||
@ApiOperation(value = "查询全部文章所属分类", response = SysContentClassification.class) |
||||
public R allTheQuery(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId, |
||||
@ApiParam(name = "templateId", value = "模板id", required = true) @RequestParam Integer templateId) { |
||||
List<SysContentClassification> list = service.list(new QueryWrapper<SysContentClassification>() |
||||
.eq("site_id", siteId).eq("template_id",templateId)); |
||||
return R.success(list); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysContentClassification.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
SysContentClassification sysContentClassification = service.getById(id); |
||||
if (sysContentClassification == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
return R.success(sysContentClassification); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/checkForHeavy") |
||||
@ApiOperation(value = "分类校验判重", response = SysContentClassification.class) |
||||
public R checkForHeavy(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId, |
||||
@ApiParam(name = "classificationName", value = "分类名称", required = true) @RequestParam String classificationName, |
||||
@ApiParam(name = "classificationId", value = "分类id(新增不传,编辑传)", required = false) @RequestParam Integer classificationId) { |
||||
|
||||
QueryWrapper<SysContentClassification> queryWrapper = new QueryWrapper<SysContentClassification>().eq("site_id", siteId). |
||||
eq("classification_name", classificationName); |
||||
|
||||
//id不得空表示编辑校验
|
||||
if (classificationId != null) { |
||||
queryWrapper.last(" and id != " + classificationId); |
||||
} |
||||
SysContentClassification sysContentClassification = service.getOne(queryWrapper); |
||||
if (sysContentClassification != null) { |
||||
return R.fail("当前分类名称已存在!"); |
||||
} |
||||
return R.success(); |
||||
|
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysContentClassification.class) |
||||
public R save(@RequestBody @Valid @ApiParam(name = "文章所属分类对象", value = "传入json格式", required = true) SysContentClassification sysContentClassification) { |
||||
boolean addState = service.save(sysContentClassification); |
||||
return addState ? R.success() : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysContentClassification.class) |
||||
public R update(@RequestBody @ApiParam(name = "文章所属分类对象", value = "传入json格式", required = true) SysContentClassification sysContentClassification) { |
||||
boolean updateState = service.updateById(sysContentClassification); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysContentClassification.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除", response = SysContentClassification.class) |
||||
public R batchDeletion(@ApiParam(name = "id", value = "主键", required = true) @RequestParam List<Integer> ids) { |
||||
boolean delState = service.removeByIds(ids); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
//
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,254 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.entity.SysColumn; |
||||
import com.huoran.iasf.entity.SysContentFile; |
||||
import com.huoran.iasf.entity.SysFilesEntity; |
||||
import com.huoran.iasf.service.SysColumnService; |
||||
import com.huoran.iasf.service.SysContentFileService; |
||||
import com.huoran.iasf.service.SysFilesService; |
||||
import com.huoran.iasf.vo.req.ArticleModifiedSortReq; |
||||
import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO; |
||||
import com.huoran.iasf.vo.req.ContentReq; |
||||
import com.huoran.iasf.vo.req.PageContentReqVO; |
||||
import com.huoran.iasf.vo.resp.PageContentRespVO; |
||||
import io.swagger.annotations.*; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import org.apache.ibatis.annotations.Update; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.redis.core.StringRedisTemplate; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import com.huoran.iasf.service.SysContentService; |
||||
import com.huoran.iasf.entity.SysContent; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
import java.util.stream.Stream; |
||||
|
||||
|
||||
/** |
||||
* @描述:文章管理控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-05 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sysContent") |
||||
@Api(value = "文章管理:SysContentController", tags = "R-文章管理") |
||||
public class SysContentController { |
||||
|
||||
@Autowired |
||||
public SysContentService service; |
||||
@Autowired |
||||
public SysColumnService columnService; |
||||
|
||||
@Autowired |
||||
public SysContentFileService fileService; |
||||
|
||||
@Autowired |
||||
public SysFilesService sysFilesService; |
||||
|
||||
|
||||
@PostMapping("/pagingQuery") |
||||
@ApiOperation(value = "分页查询文章列表", response = PageContentRespVO.class) |
||||
public R pagingQuery(@RequestBody @Valid @ApiParam(name = "分页查询参数", value = "传入json格式", required = true) PageContentReqVO sysContent) { |
||||
return service.articlePaginationList(sysContent); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysContent.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
|
||||
|
||||
SysContent sysContent = service.getById(id); |
||||
if (sysContent == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
|
||||
SysColumn sysColumn = columnService.getById(sysContent.getColumnId()); |
||||
if (sysColumn == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
/*if (sysColumn == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
}*/ |
||||
if (sysColumn.getColumnName() != null) { |
||||
sysContent.setColumnName(sysColumn.getColumnName()); |
||||
} |
||||
List<SysContentFile> fileList = fileService.getFileByContentId(id); |
||||
sysContent.setFileList(fileList); |
||||
|
||||
|
||||
return R.success(sysContent); |
||||
} |
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysContent.class) |
||||
public R save(@RequestBody @Valid @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) { |
||||
|
||||
/* QueryWrapper<SysContent> queryWrap = new QueryWrapper<>(); |
||||
queryWrap.eq("column_id", sysContent.getColumnId()); |
||||
queryWrap.eq("deleted", 1); |
||||
Integer count = service.count(queryWrap); |
||||
if (count == 0) { |
||||
count = 1; |
||||
} |
||||
sysContent.setSequence(count + 1);*/ |
||||
boolean addState = service.save(sysContent); |
||||
|
||||
|
||||
return addState ? R.success(sysContent.getId()) : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysContent.class) |
||||
public R update(@RequestBody @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) { |
||||
boolean updateState = service.updateById(sysContent); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysContent.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
UpdateWrapper<SysFilesEntity> queryWrapper = new UpdateWrapper<>(); |
||||
queryWrapper.eq("quote_id", id); |
||||
queryWrapper.eq("quote_type", 0); |
||||
queryWrapper.set("is_del", 1); |
||||
sysFilesService.update(queryWrapper); |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除文章", response = SysContent.class) |
||||
public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List<Integer> ids) { |
||||
for (Integer id : ids) { |
||||
UpdateWrapper<SysFilesEntity> queryWrapper = new UpdateWrapper<>(); |
||||
queryWrapper.eq("quote_id", id); |
||||
queryWrapper.eq("quote_type", 0); |
||||
queryWrapper.set("is_del", 1); |
||||
sysFilesService.update(queryWrapper); |
||||
} |
||||
boolean delState = service.removeByIds(ids); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
@PostMapping("/checkIfTheTitleIsRepeat") |
||||
@ApiOperation(value = "标题判重——只对已发布的判重(新增,编辑,点击发布时候都要调用判断))", response = ContentHeavyTitleReqVO.class) |
||||
public R checkIfTheTitleIsRepeat(@RequestBody @Valid ContentHeavyTitleReqVO content) { |
||||
return service.checkIfTheTitleIsRepeat(content) ? R.success() : R.fail("该标题已重复!"); |
||||
} |
||||
|
||||
@PostMapping("/newlyPublishedArticles") |
||||
@ApiOperation(value = "站点最新发布的文章", response = PageContentReqVO.class) |
||||
public R newlyPublishedArticles(@Valid @RequestBody PageContentReqVO content) { |
||||
return service.newlyPublishedArticles(content); |
||||
} |
||||
|
||||
|
||||
/*查询已发布的、启用了的文章列表接口*/ |
||||
/* @PostMapping("/publishedEnabledArticles") |
||||
@ApiOperation(value = "查询已发布的、启用了的文章列表", response = PageContentReqVO.class) |
||||
public R publishedEnabledArticles() { |
||||
return service.publishedEnabledArticles(); |
||||
}*/ |
||||
|
||||
|
||||
/** |
||||
* 获取栏目下的文章 |
||||
* |
||||
* @param pageReq |
||||
* @return |
||||
*/ |
||||
@PostMapping("/getColumnArticles") |
||||
@ApiOperation(value = "获取栏目下的文章", response = SysContent.class) |
||||
public R getColumnArticles(@RequestBody @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) ContentReq pageReq) { |
||||
IPage page = new Page(pageReq.getPageNum(), pageReq.getPageSize()); |
||||
QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.in("column_id", pageReq.getColumnIds()); |
||||
IPage<SysContent> iPage = service.page(page, queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/articleEnableOrDisable") |
||||
@ApiOperation(value = "文章启用禁用", response = SysContent.class) |
||||
public R articleEnableOrDisable(@ApiParam(name = "id", value = "文章id", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用(0默认,0启用 1禁用)", required = true) @RequestParam Integer isDisable) { |
||||
UpdateWrapper<SysContent> updateWrapper = new UpdateWrapper<>(); |
||||
updateWrapper.set("is_disable", isDisable); |
||||
updateWrapper.eq("id", id); |
||||
boolean ret = service.update(updateWrapper); |
||||
return ret ? R.success() : R.fail("禁用/启用失败"); |
||||
} |
||||
|
||||
@PostMapping("/articlePreview") |
||||
@ApiOperation(value = "增加文章浏览量(点击一次算一次)", response = SysContent.class) |
||||
public R articlePreview(@ApiParam(name = "contentId", value = "文章id", required = true) @RequestParam Integer contentId) { |
||||
return R.success(service.statisticsOfPageViews(contentId)); |
||||
|
||||
} |
||||
|
||||
|
||||
@PostMapping("/hotContent") |
||||
@ApiOperation(value = "热点内容", response = SysContent.class) |
||||
public R hotContent(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) { |
||||
return R.success(service.hotContent(siteId)); |
||||
|
||||
} |
||||
|
||||
@PostMapping("/siteSearchArticles") |
||||
@ApiOperation(value = "站点搜索文章", response = SysContent.class) |
||||
public R siteSearchArticles(@RequestBody PageContentReqVO req) { |
||||
return service.siteSearchArticles(req); |
||||
|
||||
} |
||||
|
||||
|
||||
@PostMapping("/articleTopOperation") |
||||
@ApiOperation(value = "文章置顶/取消置顶", response = SysContent.class) |
||||
public R articleTopOperation(@ApiParam(name = "isTop", value = "是否置顶(默认为0 不置顶 1为置顶)", required = true) @RequestParam Integer isTop, @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) { |
||||
//是否置顶(默认为0 不置顶 1为置顶)
|
||||
UpdateWrapper<SysContent> updateWrap = new UpdateWrapper<>(); |
||||
|
||||
if (isTop == 1) { |
||||
//置顶时间(置顶一次更新一次)
|
||||
updateWrap.set("top_time", new Date()); |
||||
} else { |
||||
updateWrap.set("top_time", null); |
||||
} |
||||
updateWrap.set("is_top", isTop); |
||||
updateWrap.eq("id", articleId); |
||||
updateWrap.eq("deleted", 1); |
||||
boolean ret = service.update(updateWrap); |
||||
return ret ? R.success() : R.fail("操作失败"); |
||||
|
||||
} |
||||
|
||||
|
||||
@PostMapping("/queryArticleColumnParent") |
||||
@ApiOperation(value = "查询文章的栏目父级", response = PageContentReqVO.class) |
||||
public R queryArticleColumnParent(@ApiParam(name = "articleId", value = "文章id", required = true) @RequestParam Integer articleId) { |
||||
return service.queryArticleColumnParent(articleId); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,82 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysContentFile; |
||||
import com.huoran.iasf.service.SysContentFileService; |
||||
import io.swagger.annotations.*; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiOperation; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @描述:文章附件管理表控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-07 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/content/file") |
||||
@Api(value = "文章附件管理表:SysContentFileController", tags = "文章附件管理表") |
||||
public class SysContentFileController { |
||||
|
||||
@Autowired |
||||
public SysContentFileService service; |
||||
|
||||
|
||||
@PostMapping("/theAttachmentUnderTheQueryColumn") |
||||
@ApiOperation(value = "查询文章id下的附件", response = SysContentFile.class) |
||||
public R theAttachmentUnderTheQueryColumn(@ApiParam(name = "contentId", value = "文章id", required = true) @RequestParam Integer contentId) { |
||||
QueryWrapper<SysContentFile> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("content_id",contentId); |
||||
List<SysContentFile> sysContentFile = service.list(queryWrapper); |
||||
return R.success(sysContentFile); |
||||
} |
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysContentFile.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
SysContentFile sysContentFile = service.getById(id); |
||||
return R.success(sysContentFile); |
||||
} |
||||
|
||||
@NoRepeatSubmit |
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysContentFile.class) |
||||
public R save(@RequestBody @ApiParam(name = "文章附件管理表对象", value = "传入json格式", required = true) SysContentFile sysContentFile) { |
||||
boolean addState = service.save(sysContentFile); |
||||
return addState ? R.success(sysContentFile.getId()) : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysContentFile.class) |
||||
public R update(@RequestBody @ApiParam(name = "文章附件管理表对象", value = "传入json格式", required = true) SysContentFile sysContentFile) { |
||||
boolean updateState = service.updateById(sysContentFile); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
@NoRepeatSubmit |
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysContentFile.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除", response = SysContentFile.class) |
||||
public R batchDeletion(@ApiParam(name = "id", value = "主键", required = true) @RequestParam List<Integer> ids) { |
||||
boolean delState = service.removeByIds(ids); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,107 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.exception.NotFoundException; |
||||
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysContentClassification; |
||||
import com.huoran.iasf.entity.SysContentLabel; |
||||
import com.huoran.iasf.service.SysContentLabelService; |
||||
import io.swagger.annotations.*; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiOperation; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @描述:文章主题标签控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-08 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/content/label") |
||||
@Api(value = "文章主题标签:SysContentLabelController", tags = "R-文章主题标签") |
||||
public class SysContentLabelController { |
||||
|
||||
@Autowired |
||||
public SysContentLabelService service; |
||||
|
||||
|
||||
@PostMapping("/queryAllArticleSubjectTags") |
||||
@ApiOperation(value = "查询全部文章主题标签", response = SysContentLabel.class) |
||||
public R queryAllArticleSubjectTags(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) { |
||||
List<SysContentLabel> list = service.list(new QueryWrapper<SysContentLabel>().eq("site_id", siteId)); |
||||
return R.success(list); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysContentLabel.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
SysContentLabel sysContentLabel = service.getById(id); |
||||
if (sysContentLabel == null) { |
||||
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST); |
||||
} |
||||
return R.success(sysContentLabel); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysContentLabel.class) |
||||
public R save(@RequestBody @Valid @ApiParam(name = "文章主题标签对象", value = "传入json格式", required = true) SysContentLabel sysContentLabel) { |
||||
boolean addState = service.save(sysContentLabel); |
||||
return addState ? R.success() : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/checkForHeavy") |
||||
@ApiOperation(value = "标签校验判重", response = SysContentLabel.class) |
||||
public R checkForHeavy(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId, @ApiParam(name = "labelName", value = "标签名称", required = true) @RequestParam String labelName, @ApiParam(name = "labelId", value = "标签id(新增不传,编辑传)", required = false) @RequestParam Integer labelId) { |
||||
|
||||
QueryWrapper<SysContentLabel> queryWrapper = new QueryWrapper<SysContentLabel>().eq("site_id", siteId).eq("label_name", labelName); |
||||
|
||||
//id不得空表示编辑校验
|
||||
if (labelId != null) { |
||||
queryWrapper.last(" and id != " + labelId); |
||||
} |
||||
SysContentLabel contentLabel = service.getOne(queryWrapper); |
||||
if (contentLabel != null) { |
||||
return R.fail("当前标签名称已存在!"); |
||||
} |
||||
return R.success(); |
||||
|
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysContentLabel.class) |
||||
public R update(@RequestBody @ApiParam(name = "文章主题标签对象", value = "传入json格式", required = true) SysContentLabel sysContentLabel) { |
||||
boolean updateState = service.updateById(sysContentLabel); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysContentLabel.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除", response = SysContentLabel.class) |
||||
public R batchDeletion(@ApiParam(name = "id", value = "主键", required = true) @RequestParam List<Integer> ids) { |
||||
boolean delState = service.removeByIds(ids); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,100 @@ |
||||
/* |
||||
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,94 @@ |
||||
/* |
||||
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,163 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.config.NonStaticResourceHttpRequestConfig; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysFilesEntity; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import com.huoran.iasf.service.SysFilesService; |
||||
import com.huoran.iasf.service.UserService; |
||||
import com.huoran.iasf.vo.UEditorResultVO; |
||||
import com.huoran.iasf.vo.req.FileParameters; |
||||
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.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
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; |
||||
|
||||
@Autowired |
||||
private UserService userService; |
||||
|
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
|
||||
@ApiOperation(value = "上传文件前获取配置文件") |
||||
@GetMapping("/upload") |
||||
public String upload(@RequestParam(required = false) String action,HttpServletResponse response) throws IOException { |
||||
// response.sendRedirect("static/ueditor/config.json");
|
||||
// return "redirect:static/ueditor/config.json";
|
||||
// 将获取的json数据封装一层,然后在给返回
|
||||
JSONObject result = new JSONObject(); |
||||
result.put("imageActionName", "upload"); |
||||
result.put("imageFieldName", "file"); |
||||
return result.toJSONString(); |
||||
} |
||||
@NoRepeatSubmit |
||||
@ApiOperation(value = "新增") |
||||
@PostMapping("/upload") |
||||
// @RequiresPermissions(value = {"sysFiles:add", "sysContent:update", "sysContent:add"}, logical = Logical.OR)
|
||||
public UEditorResultVO add( |
||||
@RequestParam(required = false) String action, |
||||
@RequestParam(value = "file") MultipartFile file, FileParameters fileParameters) { |
||||
Integer userId = httpSessionService.getCurrentUserId(); |
||||
fileParameters.setUploader(userId.toString()); |
||||
//判断文件是否空
|
||||
if (file == null || file.getOriginalFilename() == null || "".equalsIgnoreCase(file.getOriginalFilename().trim())) { |
||||
UEditorResultVO uEditorResult = new UEditorResultVO(); |
||||
uEditorResult.setState("error"); |
||||
return uEditorResult; |
||||
} |
||||
return sysFilesService.saveFile(file,fileParameters); |
||||
} |
||||
|
||||
@ApiOperation(value = "更新文件信息") |
||||
@PostMapping("/update") |
||||
public R update(@RequestBody FileParameters fileParameters) { |
||||
if (StrUtil.isEmpty(fileParameters.getId())){ |
||||
return R.fail("id不能为空"); |
||||
} |
||||
UpdateWrapper<SysFilesEntity> updateWrapper = new UpdateWrapper<>(); |
||||
updateWrapper.set("quote",fileParameters.getQuote()). |
||||
set("is_release",fileParameters.getIsRelease()). |
||||
set("quote_id",fileParameters.getQuoteId()). |
||||
eq("id", fileParameters.getId()); |
||||
return sysFilesService.update(updateWrapper) ? R.success() : R.fail("更新失败"); |
||||
} |
||||
@ApiOperation(value = "文件预览") |
||||
@GetMapping("/preview/{id}") |
||||
public void preview(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { |
||||
sysFilesService.preview(id, req, res); |
||||
} |
||||
@NoRepeatSubmit |
||||
@ApiOperation(value = "文件下载") |
||||
@GetMapping("/download/{id}") |
||||
public void download(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) { |
||||
sysFilesService.download(id, req, res); |
||||
} |
||||
|
||||
@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 = "查询分页数据",response = SysFilesEntity.class) |
||||
@PostMapping("/listByPage") |
||||
@RequiresPermissions("sysFiles:list") |
||||
public R findListByPage(@RequestBody SysFilesEntity sysFiles) { |
||||
return sysFilesService.getPage(sysFiles); |
||||
|
||||
/*LambdaQueryWrapper<SysFilesEntity> queryWrapper = Wrappers.lambdaQuery(); |
||||
if (!StringUtils.isEmpty(sysFiles.getFileName())) { |
||||
queryWrapper.like(SysFilesEntity::getFileName, sysFiles.getFileName()); |
||||
} |
||||
if (!StringUtils.isEmpty(sysFiles.getUploader())) { |
||||
queryWrapper.like(SysFilesEntity::getUploader, sysFiles.getUploader()); |
||||
} |
||||
if (!StringUtils.isEmpty(sysFiles.getQuote())) { |
||||
queryWrapper.like(SysFilesEntity::getQuote, sysFiles.getQuote()); |
||||
} |
||||
if (!StringUtils.isEmpty(sysFiles.getType())) { |
||||
queryWrapper.eq(SysFilesEntity::getType, sysFiles.getType()); |
||||
} |
||||
if (!StringUtils.isEmpty(sysFiles.getSite())) { |
||||
queryWrapper.eq(SysFilesEntity::getSite, sysFiles.getSite()); |
||||
} |
||||
queryWrapper.orderByDesc(SysFilesEntity::getCreateDate); |
||||
queryWrapper.isNotNull(SysFilesEntity::getQuote); |
||||
//只查看已发布的文件
|
||||
queryWrapper.eq(SysFilesEntity::getIsRelease,1); |
||||
//查看文章未删除的
|
||||
queryWrapper.eq(SysFilesEntity::getIsDel,0); |
||||
IPage<SysFilesEntity> iPage = sysFilesService.page(sysFiles.getQueryPage(),queryWrapper); |
||||
iPage.getRecords().forEach(sysFilesEntity -> { |
||||
if (sysFilesEntity.getUploader()!=null){ |
||||
SysUser sysUser = userService.getById(sysFilesEntity.getUploader()); |
||||
if (sysUser!=null){ |
||||
sysFilesEntity.setUploader(sysUser.getRealName()); |
||||
} |
||||
} |
||||
}); |
||||
return R.success(iPage);*/ |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@ |
||||
/* |
||||
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,190 @@ |
||||
/* |
||||
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,59 @@ |
||||
/* |
||||
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,63 @@ |
||||
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,79 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import io.swagger.annotations.*; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiImplicitParam; |
||||
import io.swagger.annotations.ApiImplicitParams; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import com.huoran.iasf.service.SysNavigationStyleService; |
||||
import com.huoran.iasf.entity.SysNavigationStyle; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @描述:导航样式配置控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-09-01 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sysNavigationStyle") |
||||
@Api(value = "导航样式配置:SysNavigationStyleController", tags = "R-导航样式配置") |
||||
public class SysNavigationStyleController { |
||||
|
||||
@Autowired |
||||
public SysNavigationStyleService service; |
||||
|
||||
|
||||
@PostMapping("/searchAllBySite") |
||||
@ApiOperation(value = "按站点搜索所有", response = SysNavigationStyle.class) |
||||
public R listByEntity(@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) { |
||||
QueryWrapper<SysNavigationStyle> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("site_id", siteId); |
||||
List<SysNavigationStyle> pageList = service.list(queryWrapper); |
||||
return R.success(pageList); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = SysNavigationStyle.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
SysNavigationStyle sysNavigationStyle = service.getById(id); |
||||
return R.success(sysNavigationStyle); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = SysNavigationStyle.class) |
||||
public R save(@RequestBody @ApiParam(name = "导航样式配置对象", value = "传入json格式", required = true) SysNavigationStyle sysNavigationStyle) { |
||||
boolean addState = service.save(sysNavigationStyle); |
||||
return addState ? R.success() : R.fail("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = SysNavigationStyle.class) |
||||
public R update(@RequestBody @ApiParam(name = "导航样式配置对象", value = "传入json格式", required = true) SysNavigationStyle sysNavigationStyle) { |
||||
boolean updateState = service.updateById(sysNavigationStyle); |
||||
return updateState ? R.success() : R.fail("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/delete") |
||||
@ApiOperation(value = "删除", response = SysNavigationStyle.class) |
||||
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.success() : R.fail("删除失败"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,57 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysColumn; |
||||
import com.huoran.iasf.entity.SysContent; |
||||
import com.huoran.iasf.service.SysColumnService; |
||||
import com.huoran.iasf.service.SysContentService; |
||||
import com.huoran.iasf.vo.req.ColumnWeightReqVO; |
||||
import com.huoran.iasf.vo.req.LongPageColumnReqVO; |
||||
import com.huoran.iasf.vo.req.PageContentReqVO; |
||||
import com.huoran.iasf.vo.req.PaginationColumnReqVO; |
||||
import com.huoran.iasf.vo.resp.PageContentRespVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @描述:页面管理 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-08 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/pageManagement") |
||||
@Api(value = "页面管理:SysPageManagementController", tags = "R-页面管理") |
||||
public class SysPageManagementController { |
||||
|
||||
@Autowired |
||||
public SysColumnService columnService; |
||||
|
||||
|
||||
/** |
||||
* 需求:当前接口只查栏目类型为长页栏目的数据 |
||||
* |
||||
* @param sysContent |
||||
* @return |
||||
*/ |
||||
@PostMapping("/longPageColumnList") |
||||
@ApiOperation(value = "长页列列表", response = PageContentRespVO.class) |
||||
public R longPageColumnList(@RequestBody @Valid @ApiParam(name = "分页查询参数", value = "传入json格式", required = true) LongPageColumnReqVO sysContent) { |
||||
return columnService.longPageColumnList(sysContent); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,108 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.iasf.common.utils.Constant; |
||||
import com.huoran.iasf.entity.SysTemplateStyle; |
||||
import com.huoran.iasf.entity.SysTemplateStyleConfiguration; |
||||
import com.huoran.iasf.service.SysTemplateStyleConfigurationService; |
||||
import com.huoran.iasf.service.SysTemplateStyleService; |
||||
import io.swagger.annotations.*; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import io.swagger.annotations.ApiImplicitParam; |
||||
import io.swagger.annotations.ApiImplicitParams; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import com.huoran.iasf.service.SysTemplateService; |
||||
import com.huoran.iasf.entity.SysTemplate; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* @描述:栏目模板控制类 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-11 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/template") |
||||
@Api(value = "栏目模板:SysTemplateController", tags = "栏目模板:栏目模板相关") |
||||
public class SysTemplateController { |
||||
|
||||
@Autowired |
||||
public SysTemplateService templateService; |
||||
|
||||
@Autowired |
||||
public SysTemplateStyleService styleService; |
||||
@Autowired |
||||
public SysTemplateStyleConfigurationService templateStyleConfigurationService; |
||||
|
||||
@PostMapping("/listOfColumnTemplates") |
||||
@ApiOperation(value = "获取文章模板列表、详情样式", response = SysTemplate.class) |
||||
public R listOfColumnTemplates() { |
||||
List<SysTemplate> list = templateService.list(new QueryWrapper<SysTemplate>().eq("type", 1).eq("is_hide",0)); |
||||
return R.success(list); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/longPageListStyle") |
||||
@ApiOperation(value = "长页列表样式", response = SysTemplate.class) |
||||
public R longPageListStyle() { |
||||
List<SysTemplateStyle> list = styleService.list(new QueryWrapper<SysTemplateStyle>().eq("is_long_page", 1)); |
||||
return R.success(list); |
||||
} |
||||
|
||||
@PostMapping("/theTemplateIdGetsTheStyle") |
||||
@ApiOperation(value = "根据模板id获取样式", response = SysTemplateStyle.class) |
||||
public R theTemplateIdGetsTheStyle(@ApiParam(name = "templateId", value = "模板id", required = true) @RequestParam Integer templateId) { |
||||
|
||||
/*QueryWrapper<SysTemplateStyle> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("type", Constant.LIST_TEMPLATE_TYPES); |
||||
queryWrapper.eq("is_long_page", 0); |
||||
List<SysTemplateStyle> listingTemplateTypes = styleService.list(queryWrapper); |
||||
|
||||
|
||||
QueryWrapper<SysTemplateStyle> queryWrapper1 = new QueryWrapper<>(); |
||||
queryWrapper1.eq("template_id",templateId); |
||||
queryWrapper1.eq("type", Constant.DETAILS_TEMPLATE_TYPE); |
||||
List<SysTemplateStyle> detailsTypeOfTheTemplate = styleService.list(queryWrapper1);*/ |
||||
|
||||
List<SysTemplateStyle> listingTemplateTypes = templateStyleConfigurationService.getsTheStyleUnderTheTemplate(templateId, 0); |
||||
List<SysTemplateStyle> detailsTypeOfTheTemplate = templateStyleConfigurationService.getsTheStyleUnderTheTemplate(templateId, 1); |
||||
|
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("listingTemplateTypes", listingTemplateTypes);//列表样式
|
||||
map.put("detailsTypeOfTheTemplate", detailsTypeOfTheTemplate);//详情样式
|
||||
return R.success(map); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/fullDetailsTemplateStyle") |
||||
@ApiOperation(value = "全部详情模板样式", response = SysTemplateStyle.class) |
||||
public R fullDetailsTemplateStyle() { |
||||
|
||||
QueryWrapper<SysTemplateStyle> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("type", Constant.DETAILS_TEMPLATE_TYPE); |
||||
List<SysTemplateStyle> listingTemplateTypes = styleService.list(queryWrapper); |
||||
return R.success(listingTemplateTypes); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/individualTemplateDetailsStyle") |
||||
@ApiOperation(value = "独立模板详情样式", response = SysTemplate.class) |
||||
public R individualTemplateDetailsStyle() { |
||||
List<SysTemplateStyle> list = styleService.list(new QueryWrapper<SysTemplateStyle>().eq("type", 1).eq("is_long_page", 0).eq("is_hide",0)); |
||||
return R.success(list); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,227 @@ |
||||
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.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysUser; |
||||
import com.huoran.iasf.entity.UserDept; |
||||
import com.huoran.iasf.mapper.UserDeptMapper; |
||||
import com.huoran.iasf.service.HttpSessionService; |
||||
import com.huoran.iasf.service.UserService; |
||||
import com.huoran.iasf.vo.CheckVo; |
||||
import com.huoran.iasf.vo.req.UpdatePhoneOrEmailReq; |
||||
import com.huoran.iasf.vo.req.UserListReq; |
||||
import com.huoran.iasf.vo.resp.UserListResp; |
||||
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.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.naming.Name; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.validation.Valid; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 用户管理 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@RestController |
||||
@Api(tags = "用户管理") |
||||
@RequestMapping("/sys") |
||||
@Slf4j |
||||
public class UserController { |
||||
@Resource |
||||
private UserService userService; |
||||
|
||||
@Resource |
||||
private UserDeptMapper userDeptMapper; |
||||
|
||||
@Resource |
||||
private HttpSessionService httpSessionService; |
||||
|
||||
@PostMapping(value = "/user/login") |
||||
@ApiOperation(value = "用户登录接口") |
||||
public R login(@RequestBody @Valid SysUser vo) { |
||||
return R.success(userService.login(vo)); |
||||
} |
||||
|
||||
/* @PostMapping("/user/register") |
||||
@ApiOperation(value = "用户注册接口") |
||||
public R register(@RequestBody @Valid SysUser vo) { |
||||
userService.register(vo); |
||||
return R.success(); |
||||
}*/ |
||||
|
||||
@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(); |
||||
} |
||||
|
||||
@GetMapping("/user/{id}") |
||||
@ApiOperation(value = "查询用户详情接口") |
||||
@LogAnnotation(title = "用户管理", action = "查询用户详情") |
||||
// @RequiresPermissions("sys:user:detail")
|
||||
public R detailInfo(@PathVariable("id") String id) { |
||||
UserListResp userResp = userService.detailInfo(id); |
||||
return R.success(userResp); |
||||
} |
||||
|
||||
@PostMapping("/users") |
||||
@ApiOperation(value = "分页获取用户列表接口") |
||||
// @RequiresPermissions("sys:user:list")
|
||||
@LogAnnotation(title = "用户管理", action = "分页获取用户列表") |
||||
public R pageInfo(@RequestBody UserListReq userListReq) { |
||||
return userService.pageInfo(userListReq); |
||||
} |
||||
|
||||
@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("/checkJobNumber") |
||||
@ApiOperation(value = "工号验证") |
||||
public R checkJobNumber(@RequestParam String jobNumber) { |
||||
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getJobNumber, jobNumber)); |
||||
if (sysUser != null) { |
||||
return R.fail("工号已存在,请勿重复添加!"); |
||||
} |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/checkUsername") |
||||
@ApiOperation(value = "账号验证") |
||||
public R checkUsername(@RequestParam String userName) { |
||||
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userName)); |
||||
if (sysUser != null) { |
||||
return R.fail("账号已存在,请勿重复添加!"); |
||||
} |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/checkEmail") |
||||
@ApiOperation(value = "邮箱验证") |
||||
public R checkEmail(@RequestParam String email) { |
||||
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getEmail, email)); |
||||
if (sysUser != null) { |
||||
return R.fail("邮箱已存在,请勿重复添加!"); |
||||
} |
||||
return R.success(); |
||||
} |
||||
|
||||
@GetMapping("/checkPhone") |
||||
@ApiOperation(value = "手机验证") |
||||
public R checkPhone(@RequestParam String phone) { |
||||
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone)); |
||||
if (sysUser != null) { |
||||
return R.fail("手机号已存在,请勿重复添加!"); |
||||
} |
||||
return R.success(); |
||||
} |
||||
@NoRepeatSubmit |
||||
@ApiOperation(value = "密码重置", notes = "密码重置") |
||||
@GetMapping("/resetPwd") |
||||
public R resetPwd(@RequestParam("userId") String userId) { |
||||
return userService.resetPwd(userId); |
||||
} |
||||
|
||||
@GetMapping("/user/logout") |
||||
@ApiOperation(value = "退出接口") |
||||
@LogAnnotation(title = "用户管理", action = "退出") |
||||
public R logout() { |
||||
httpSessionService.abortUserByToken(); |
||||
Subject subject = SecurityUtils.getSubject(); |
||||
subject.logout(); |
||||
return R.success(); |
||||
} |
||||
@NoRepeatSubmit |
||||
@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("旧密码与新密码不能为空"); |
||||
} |
||||
// Integer userId = httpSessionService.getCurrentUserId();
|
||||
// vo.setId(userId);
|
||||
userService.updatePwd(vo); |
||||
return R.success(); |
||||
} |
||||
@NoRepeatSubmit |
||||
@DeleteMapping("/user") |
||||
@ApiOperation(value = "删除用户接口") |
||||
@LogAnnotation(title = "用户管理", action = "删除用户") |
||||
// @RequiresPermissions("sys:user:deleted")
|
||||
public R deletedUser(@RequestBody @ApiParam(value = "用户id集合") List<Integer> userIds) { |
||||
//删除用户, 删除redis的绑定的角色跟权限
|
||||
httpSessionService.abortUserByUserIds(userIds); |
||||
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); |
||||
queryWrapper.in(SysUser::getId, userIds); |
||||
userService.remove(queryWrapper); |
||||
//删除用户部门
|
||||
userDeptMapper.delete(Wrappers.<UserDept>lambdaQuery().in(UserDept::getUserId, userIds)); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PostMapping("/importStaff") |
||||
@ApiOperation("批量导入员工") |
||||
public R importStaff(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request) throws IOException { |
||||
Map<String, String> map = userService.importStaff(file); |
||||
return R.success(map); |
||||
} |
||||
|
||||
/** |
||||
* 批量导入员工失败数据导出 |
||||
*/ |
||||
@ApiOperation(value = "批量导入员工失败数据导出") |
||||
@GetMapping("/exportFailure") |
||||
public void exportFailureRecord(HttpServletResponse response, @ApiParam(name = "exportCode", value = "importQuestion接口返回的exportCode", required = true) @RequestParam String exportCode) throws Exception { |
||||
userService.exportFailureRecord(response, exportCode); |
||||
} |
||||
@NoRepeatSubmit |
||||
@ApiOperation(value = "更换手机号或邮箱--发送验证码") |
||||
@PostMapping("/sendPhoneOrEmailCode") |
||||
public R sendPhoneOrEmailCode(@RequestBody CheckVo checkVo) { |
||||
return userService.sendCheckPhoneCode(checkVo); |
||||
} |
||||
@NoRepeatSubmit |
||||
@ApiOperation(value = "更新手机号或邮箱") |
||||
@PostMapping("/updatePhoneOrEmail") |
||||
public R updatePhoneOrEmail(@RequestBody UpdatePhoneOrEmailReq updatePhoneOrEmailReq) { |
||||
return userService.updatePhoneOrEmail(updatePhoneOrEmailReq); |
||||
} |
||||
|
||||
@ApiOperation(value = "修改用户头像") |
||||
@PostMapping("/updateUserAvatars") |
||||
public R updateUserAvatars(@RequestParam String userId, MultipartFile file) { |
||||
return userService.updateUserAvatars(userId, file); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户员工部门表 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author cheney |
||||
* @since 2022-08-15 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/userDept") |
||||
public class UserDeptController { |
||||
|
||||
} |
||||
|
@ -0,0 +1,106 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
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.aop.annotation.NoRepeatSubmit; |
||||
import com.huoran.iasf.common.utils.R; |
||||
import com.huoran.iasf.entity.SysFilesEntity; |
||||
import com.huoran.iasf.entity.UserGroup; |
||||
import com.huoran.iasf.service.UserGroupService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.validation.Valid; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户组 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author cheney |
||||
* @since 2022-08-10 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/sys/userGroup") |
||||
@Api(tags = "用户组管理") |
||||
public class UserGroupController { |
||||
|
||||
@Autowired |
||||
private UserGroupService userGroupService; |
||||
@NoRepeatSubmit |
||||
@PostMapping("/add") |
||||
@ApiOperation(value = "新增用户组") |
||||
@LogAnnotation(title = "用户组管理", action = "新增用户组") |
||||
@RequiresPermissions("sys:userGroup:add") |
||||
public R addUserGroup(@RequestBody @Valid UserGroup userGroup) { |
||||
UserGroup one = userGroupService.getOne(new QueryWrapper<UserGroup>(). |
||||
eq("group_name", userGroup.getGroupName())); |
||||
if (ObjectUtil.isNotNull(one)){ |
||||
return R.fail("用户组已存在"); |
||||
} |
||||
userGroupService.save(userGroup); |
||||
return R.success(); |
||||
} |
||||
@NoRepeatSubmit |
||||
@DeleteMapping("/delete/{id}") |
||||
@ApiOperation(value = "删除用户组") |
||||
@LogAnnotation(title = "用户组管理", action = "删除用户组") |
||||
@RequiresPermissions("sys:userGroup:deleted") |
||||
public R deleted(@PathVariable("id") Integer id) { |
||||
userGroupService.removeById(id); |
||||
return R.success(); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
@ApiOperation(value = "更新用户组信息") |
||||
@LogAnnotation(title = "用户组管理", action = "更新用户组信息") |
||||
@RequiresPermissions("sys:userGroup:update") |
||||
public R updateUserGroup(@RequestBody UserGroup userGroup) { |
||||
if (StringUtils.isEmpty(userGroup.getId())) { |
||||
return R.fail("id不能为空"); |
||||
} |
||||
QueryWrapper<UserGroup> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("group_name", userGroup.getGroupName()); |
||||
queryWrapper.last(" and id != " + userGroup.getId()); |
||||
List<UserGroup> groups = userGroupService.list(queryWrapper); |
||||
if (ObjectUtil.isNotNull(groups) && groups.size()>0){ |
||||
return R.fail("用户组已存在"); |
||||
} |
||||
userGroupService.updateById(userGroup); |
||||
return R.success(); |
||||
} |
||||
|
||||
/* @GetMapping("/detail/{id}") |
||||
@ApiOperation(value = "查询用户组详情接口") |
||||
@LogAnnotation(title = "用户组管理", action = "查询用户组详情") |
||||
@RequiresPermissions("sys:userGroup:detail") |
||||
public R detailInfo(@PathVariable("id") Integer id) { |
||||
return R.success(userGroupService.getById(id)); |
||||
}*/ |
||||
|
||||
|
||||
@PostMapping("/list") |
||||
@ApiOperation(value = "用户组列表") |
||||
@LogAnnotation(title = "用户组管理", action = "获取所有用户组机构") |
||||
@RequiresPermissions("sys:userGroup:list") |
||||
public R getUserGroupAll(@RequestBody UserGroup userGroup) { |
||||
LambdaQueryWrapper<UserGroup> queryWrapper = Wrappers.lambdaQuery(); |
||||
if (!StringUtils.isEmpty(userGroup.getGroupName())) { |
||||
queryWrapper.like(UserGroup::getGroupName, userGroup.getGroupName()); |
||||
} |
||||
queryWrapper.orderByDesc(UserGroup::getCreateTime); |
||||
IPage<SysFilesEntity> iPage = userGroupService.page(userGroup.getQueryPage(),queryWrapper); |
||||
return R.success(iPage); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,38 @@ |
||||
package com.huoran.iasf.controller; |
||||
|
||||
import com.huoran.iasf.common.aop.annotation.LogAnnotation; |
||||
import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit; |
||||
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,47 @@ |
||||
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 io.swagger.annotations.ApiModelProperty; |
||||
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) |
||||
@ApiModelProperty(value = "页码",example = "1") |
||||
private int page = 1; |
||||
|
||||
@JSONField(serialize = false) |
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "页数",example = "10") |
||||
private int limit = 10; |
||||
|
||||
/** |
||||
* 数据权限:用户id |
||||
*/ |
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "用户id") |
||||
private List<String> createIds; |
||||
|
||||
/** |
||||
* page条件 |
||||
* @param <T> |
||||
* @return |
||||
*/ |
||||
@ApiModelProperty(value = "getQueryPage", hidden = true) |
||||
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,45 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* <p> |
||||
* 站点管理 |
||||
* </p> |
||||
* |
||||
* @author cheney |
||||
* @since 2022-08-24 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@TableName("sys_site") |
||||
@ApiModel(value="Site对象", description="站点管理") |
||||
public class Site extends BaseEntity implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String siteName; |
||||
|
||||
@ApiModelProperty(value = "域名") |
||||
private String domainName; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,158 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
/** |
||||
* @描述:栏目基础信息 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-03 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "栏目基础信息") |
||||
@TableName("sys_column") |
||||
public class SysColumn implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "id") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "父id(第一级为0)") |
||||
private Integer fatherId; |
||||
|
||||
@ApiModelProperty(value = "排序") |
||||
private Integer sort; |
||||
|
||||
@ApiModelProperty(value = "层级((1-一级分类 2-二级分类 3-三级分类以此叠加))") |
||||
private Integer level; |
||||
|
||||
@ApiModelProperty(value = "栏目名称") |
||||
private String columnName; |
||||
|
||||
@ApiModelProperty(value = "banner路径") |
||||
private String columnBanner; |
||||
|
||||
@ApiModelProperty(value = "分页条数") |
||||
private Integer pageSize; |
||||
|
||||
@ApiModelProperty(value = "菜单是否可见(默认0可见 1不可见)") |
||||
private Integer menuVisible; |
||||
|
||||
@ApiModelProperty(value = "栏目类型id") |
||||
private Integer typeId; |
||||
|
||||
@ApiModelProperty(value = "栏目模板id") |
||||
private Integer templateId; |
||||
|
||||
@ApiModelProperty(value = "列表样式id") |
||||
private Integer listStyleId; |
||||
|
||||
@ApiModelProperty(value = "详情样式id") |
||||
private Integer detailStyleId; |
||||
|
||||
@ApiModelProperty(value = "链接类型") |
||||
private Integer connectionType; |
||||
|
||||
@ApiModelProperty(value = "链接地址") |
||||
private String linkAddress; |
||||
|
||||
@ApiModelProperty(value = "只有一篇文章时,以详情方式展示(0默认否 1为是)") |
||||
private Integer showWithDetails; |
||||
|
||||
@ApiModelProperty(value = "站点选择(连接类型为其它站点连接时储存)1.EFL中文2.SRL中文") |
||||
private Integer siteSelection; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
@NotNull(message = "创建人id不能为空") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
@NotNull(message = "编辑人id能为空") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "更新时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@ApiModelProperty(value = "状态(0默认草稿箱 1为已发布)") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
|
||||
@ApiModelProperty(value = "是否在新窗口打开(0:否 1:是)") |
||||
private Integer isOpen; |
||||
|
||||
@ApiModelProperty(value = "站点id") |
||||
@NotNull(message = "站点id不能为空!") |
||||
private Integer siteId; |
||||
|
||||
|
||||
@ApiModelProperty(value = "栏目副标题") |
||||
private String subtitle; |
||||
|
||||
|
||||
//----------------------非数据库字段Start----------------------
|
||||
|
||||
@ApiModelProperty("子分类") |
||||
@TableField(exist = false) |
||||
private List<SysColumn> children; |
||||
|
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "创建人") |
||||
private String creteUser; |
||||
|
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "修改人") |
||||
private String editorUser; |
||||
|
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "总浏览") |
||||
private Integer totalBrowsing; |
||||
|
||||
public Integer getTotalBrowsing() { |
||||
return 0; |
||||
} |
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "模板名称") |
||||
private String templateName; |
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "列表样式") |
||||
private String listStyle; |
||||
|
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "详情样式") |
||||
private String detailStyle; |
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "路径") |
||||
private String path; |
||||
|
||||
//----------------------非数据库字段End----------------------
|
||||
|
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
/** |
||||
* @描述:长页栏目拓展表 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-09 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "长页栏目拓展表") |
||||
@TableName("sys_column_long_page") |
||||
public class SysColumnLongPage implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "id") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "栏目id") |
||||
@NotNull(message = "栏目id不能为空!") |
||||
private Integer columnId; |
||||
|
||||
@ApiModelProperty(value = "当前页面版面排序") |
||||
@NotNull(message = "排序不能为空!") |
||||
private Integer sort; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
@NotNull(message = "创建人id不能为空!") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
@NotNull(message = "编辑人id不能为空!") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "更新时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
@ApiModelProperty(value = "备注") |
||||
private String remark; |
||||
|
||||
@ApiModelProperty(value = "内容(编辑前存储的json字符串)") |
||||
private String jsonBeforeEditing; |
||||
|
||||
@ApiModelProperty(value = "内容(编辑后存储的json字符串)") |
||||
private String theEditedJson; |
||||
|
||||
@ApiModelProperty(value = "发布状态(0:草稿 1已发布)") |
||||
private Integer state; |
||||
|
||||
|
||||
} |
@ -0,0 +1,224 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
/** |
||||
* @描述:文章管理 |
||||
* @作者: Rong |
||||
* @日期: 2022-08-08 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "文章管理") |
||||
@TableName("sys_content") |
||||
public class SysContent implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "主键") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "标题(全库判重)") |
||||
private String title; |
||||
|
||||
@ApiModelProperty(value = "所属栏目") |
||||
private Integer columnId; |
||||
|
||||
@ApiModelProperty(value = "发布时间") |
||||
private String releaseTime; |
||||
|
||||
@ApiModelProperty(value = "来源") |
||||
private String source; |
||||
|
||||
@ApiModelProperty(value = "作者") |
||||
private String author; |
||||
|
||||
@ApiModelProperty(value = "banner图") |
||||
private String bannerImg; |
||||
|
||||
@ApiModelProperty(value = "文章模板(前端自定义)") |
||||
private Integer articleTemplate; |
||||
|
||||
@ApiModelProperty(value = "摘要") |
||||
private String summary; |
||||
|
||||
@ApiModelProperty(value = "标题图(封面图)") |
||||
private String titleImg; |
||||
|
||||
@ApiModelProperty(value = "正文") |
||||
private String mainBody; |
||||
|
||||
@ApiModelProperty(value = "是否发布(0:草稿 1:已发布)") |
||||
private Integer isRelease; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "更新时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
@ApiModelProperty(value = "文章总浏览量") |
||||
private Integer totalBrowsing; |
||||
|
||||
@ApiModelProperty(value = "是否在新窗口打开(0:否 1:是)") |
||||
private Integer isOpen; |
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
@ApiModelProperty(value = "站点id") |
||||
private Integer siteId; |
||||
|
||||
@ApiModelProperty(value = "模板状态(0禁用;1启用)") |
||||
private Integer templateStatus; |
||||
|
||||
/* @ApiModelProperty(value = "其余模板字段") |
||||
private String remainingTemplateFields;*/ |
||||
|
||||
@ApiModelProperty(value = "链接类型") |
||||
private Integer connectionType; |
||||
|
||||
@ApiModelProperty(value = "链接地址") |
||||
private String linkAddress; |
||||
|
||||
@ApiModelProperty(value = "站点选择(连接类型为其它站点连接时储存)") |
||||
private Integer siteSelection; |
||||
|
||||
@ApiModelProperty(value = "编辑人") |
||||
private String edit; |
||||
|
||||
@ApiModelProperty(value = "审核人") |
||||
private String audit; |
||||
|
||||
@ApiModelProperty(value = "活动开始时间") |
||||
private String activityStartTime; |
||||
|
||||
@ApiModelProperty(value = "活动结束时间") |
||||
private String activityEndTime; |
||||
|
||||
@ApiModelProperty(value = "演讲系列") |
||||
private String lectureSeries; |
||||
|
||||
@ApiModelProperty(value = "线上地点") |
||||
private String onlineLocation; |
||||
|
||||
@ApiModelProperty(value = "线下地点") |
||||
private String offlineLocation; |
||||
|
||||
@ApiModelProperty(value = "主讲人") |
||||
private String keynoteSpeaker; |
||||
|
||||
@ApiModelProperty(value = "活动简介") |
||||
private String eventProfile; |
||||
|
||||
@ApiModelProperty(value = "出版年份") |
||||
private String publicationYear; |
||||
|
||||
@ApiModelProperty(value = "出版类型(前端自定义)") |
||||
private Integer publicationTypeId; |
||||
|
||||
@ApiModelProperty(value = "DOI") |
||||
private String doi; |
||||
|
||||
@ApiModelProperty(value = "引用") |
||||
private String quote; |
||||
|
||||
@ApiModelProperty(value = "主题标签(sys_content_label表外键) 可多选逗号隔开") |
||||
private String lableId; |
||||
|
||||
@ApiModelProperty(value = "所属分类(sys_content_classification表外键)") |
||||
private Integer classificationId; |
||||
|
||||
@ApiModelProperty(value = "是否禁用(0默认,0启用 1禁用)") |
||||
private Integer isDisable; |
||||
|
||||
@ApiModelProperty(value = "栏目名称") |
||||
@TableField(exist = false) |
||||
private String columnName; |
||||
|
||||
@ApiModelProperty(value = "文章附件") |
||||
@TableField(exist = false) |
||||
List<SysContentFile> fileList; |
||||
|
||||
|
||||
@ApiModelProperty(value = "刊物名称") |
||||
private String periodicalName; |
||||
|
||||
@ApiModelProperty(value = "卷") |
||||
private String reel; |
||||
|
||||
@ApiModelProperty(value = "文献号") |
||||
private String documentNumber; |
||||
|
||||
@ApiModelProperty(value = "文章关键字") |
||||
private String articleKeyWord; |
||||
|
||||
/*@ApiModelProperty(value = "顺序(排序号)") |
||||
private Integer sequence;*/ |
||||
|
||||
@ApiModelProperty(value = "是否置顶(默认为0 不置顶 1为置顶)") |
||||
private Integer isTop; |
||||
|
||||
@ApiModelProperty(value = "置顶时间") |
||||
private Date topTime; |
||||
@ApiModelProperty(value = "专利类别id") |
||||
private Integer patentClassId; |
||||
|
||||
@ApiModelProperty(value = "申请时间") |
||||
private String applicationDate; |
||||
|
||||
@ApiModelProperty(value = "授权日期") |
||||
private String dateOfAuthorization; |
||||
|
||||
@ApiModelProperty(value = "发明人") |
||||
private String inventor; |
||||
|
||||
@ApiModelProperty(value = "专利名称") |
||||
private String patentName; |
||||
|
||||
@ApiModelProperty(value = "申请号") |
||||
private String applicationNumber; |
||||
|
||||
@ApiModelProperty(value = "出版社") |
||||
private String publishingHouse; |
||||
|
||||
@ApiModelProperty(value = "著名著作") |
||||
private String famousWorks; |
||||
|
||||
@ApiModelProperty(value = "编写人员") |
||||
private String writersAndEditors; |
||||
|
||||
@ApiModelProperty(value = "出版日期") |
||||
private String publicationTime; |
||||
|
||||
|
||||
@ApiModelProperty(value = "岗位") |
||||
private String post; |
||||
|
||||
@ApiModelProperty(value = "专业") |
||||
private String major; |
||||
@ApiModelProperty(value = "爱好") |
||||
private String hobby; |
||||
@ApiModelProperty(value = "荣誉") |
||||
private String honor; |
||||
} |
@ -0,0 +1,61 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
/** |
||||
* @描述:文章所属分类 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-08 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "文章所属分类") |
||||
@TableName("sys_content_classification") |
||||
public class SysContentClassification implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "主键") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "分类名称") |
||||
private String classificationName; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
@NotNull(message = "创建人id不能为空") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
@NotNull(message = "编辑人id不能为空") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
@ApiModelProperty(value = "站点id") |
||||
@NotNull(message = "站点id不能为空!") |
||||
private Integer siteId; |
||||
|
||||
@ApiModelProperty(value = "模板id(用于区分哪个模板下的分类)") |
||||
@NotNull(message = "模板id不能为空!") |
||||
private Integer templateId; |
||||
|
||||
|
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
/** |
||||
* @描述:文章附件管理表 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-07 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "文章附件管理表") |
||||
@TableName("sys_content_file") |
||||
public class SysContentFile implements Serializable { |
||||
|
||||
private static final long serialVersionUID=1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "主键") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "文章id") |
||||
private Integer contentId; |
||||
|
||||
@ApiModelProperty(value = "文件名") |
||||
private String fileName; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "文件大小") |
||||
private String fileSize; |
||||
|
||||
@ApiModelProperty(value = "文件格式") |
||||
private String fileFormat; |
||||
|
||||
@ApiModelProperty(value = "oss文件名") |
||||
private String ossFileName; |
||||
|
||||
@ApiModelProperty(value = "文件路径") |
||||
private String filePath; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
/** |
||||
* @描述:文章主题标签 |
||||
* @作者: Rong |
||||
* @日期: 2022-11-08 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "文章主题标签") |
||||
@TableName("sys_content_label") |
||||
public class SysContentLabel implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "主键") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "标签名称") |
||||
private String labelName; |
||||
|
||||
@ApiModelProperty(value = "创建人id") |
||||
private Integer founderId; |
||||
|
||||
@ApiModelProperty(value = "编辑人id") |
||||
private Integer editorId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
@ApiModelProperty(value = "站点id") |
||||
@NotNull(message = "站点id不能为空!") |
||||
private Integer siteId; |
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
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 { |
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") |
||||
private String deptNo; |
||||
|
||||
@NotBlank(message = "部门名称不能为空") |
||||
@ApiModelProperty(value = "部门名称") |
||||
private String name; |
||||
|
||||
// @NotBlank(message = "父级不能为空")
|
||||
@ApiModelProperty(value = "父级id") |
||||
private Integer pid; |
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "父级部门名称") |
||||
private String pidName; |
||||
|
||||
@ApiModelProperty(value = "状态(1:正常;0:弃用)") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "为了维护更深层级关系") |
||||
private String relationCode; |
||||
|
||||
/* @ApiModelProperty(value = "部门经理user_id") |
||||
private String deptManagerId; |
||||
|
||||
@ApiModelProperty(value = "部门经理名称") |
||||
private String managerName; |
||||
|
||||
@ApiModelProperty(value = "部门经理联系电话") |
||||
private String phone;*/ |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@TableLogic |
||||
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,77 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
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; |
||||
|
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id") |
||||
private String id; |
||||
|
||||
@ApiModelProperty(value = "url地址") |
||||
private String url; |
||||
|
||||
@TableField("file_name") |
||||
@ApiModelProperty(value = "文件名称") |
||||
private String fileName; |
||||
|
||||
@ApiModelProperty(value = "文件路径") |
||||
private String filePath; |
||||
|
||||
@TableField("type") |
||||
@ApiModelProperty(value = "文件类型") |
||||
private String type; |
||||
|
||||
@ApiModelProperty(value = "文件格式") |
||||
private String format; |
||||
|
||||
@ApiModelProperty(value = "文件大小") |
||||
private Integer fileSize; |
||||
|
||||
@ApiModelProperty(value = "是否发布(默认0未发布,1已发布)") |
||||
private Integer isRelease; |
||||
|
||||
@ApiModelProperty(value = "上传人") |
||||
private String uploader; |
||||
|
||||
@ApiModelProperty(value = "引用地方") |
||||
private String quote; |
||||
|
||||
@TableField("site") |
||||
@ApiModelProperty(value = "站点来源") |
||||
private String site; |
||||
|
||||
@ApiModelProperty(value = "是否已删除,未删除表示该文件正在使用") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
@ApiModelProperty(value = "文章是否删除") |
||||
private Integer isDel; |
||||
|
||||
@ApiModelProperty(value = "引用id") |
||||
private Integer quoteId; |
||||
|
||||
@ApiModelProperty(value = "0为文章,1为栏目") |
||||
private Integer quoteType; |
||||
|
||||
@TableField(value = "create_date", fill = FieldFill.INSERT) |
||||
@ApiModelProperty(value = "创建时间") |
||||
private Date createDate; |
||||
} |
@ -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,52 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
|
||||
/** |
||||
* @描述:导航样式配置 |
||||
* @作者: Rong |
||||
* @日期: 2022-09-01 |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "导航样式配置") |
||||
@TableName("sys_navigation_style") |
||||
public class SysNavigationStyle implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
@ApiModelProperty(value = "主键") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "导航样式") |
||||
private Integer navigationStyle; |
||||
|
||||
@ApiModelProperty(value = "样式模板") |
||||
private Integer styleTemplate; |
||||
|
||||
@ApiModelProperty(value = "站点id") |
||||
private Integer siteId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "更新时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
@TableLogic |
||||
private Integer deleted; |
||||
|
||||
|
||||
} |
@ -0,0 +1,77 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import javax.validation.constraints.NotNull; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 权限菜单 |
||||
* |
||||
* @author cheney |
||||
* @version V1.0 |
||||
* @date 2022年7月28日 |
||||
*/ |
||||
@Data |
||||
public class SysPermission implements Serializable { |
||||
|
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@NotBlank(message = "菜单权限名称不能为空") |
||||
@ApiModelProperty(value = "菜单权限名称") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "授权(多个用逗号分隔,如:sys:user:add,sys:user:edit)") |
||||
private String perms; |
||||
|
||||
@ApiModelProperty(value = "访问地址URL") |
||||
private String url; |
||||
|
||||
@ApiModelProperty(value = "图标") |
||||
private String icon; |
||||
|
||||
@ApiModelProperty(value = "a target属性:_self _blank") |
||||
private String target; |
||||
|
||||
@NotNull(message = "所属菜单不能为空") |
||||
@ApiModelProperty(value = "父级菜单权限id") |
||||
private Integer pid; |
||||
|
||||
@ApiModelProperty(value = "排序") |
||||
private Integer orderNum; |
||||
|
||||
@NotNull(message = "菜单权限类型不能为空") |
||||
@ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") |
||||
private Integer type; |
||||
|
||||
@ApiModelProperty(value = "状态1:正常 0:禁用") |
||||
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; |
||||
|
||||
@ApiModelProperty(value = "层级") |
||||
@TableField(exist = false) |
||||
private Integer level; |
||||
|
||||
@ApiModelProperty(value = "下级") |
||||
@TableField(exist = false) |
||||
private List<SysPermission> children; |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
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 { |
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@NotBlank(message = "名称不能为空") |
||||
@ApiModelProperty(value = "角色名称") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "角色描述") |
||||
private String description; |
||||
|
||||
@ApiModelProperty(value = "状态(1:正常0:弃用)") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "数据范围(1:所有 2:自定义 3: 本部门及以下部门 4:仅本部门") |
||||
private Integer dataScope; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
@ApiModelProperty(value = "创建时间") |
||||
private Date createTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
@ApiModelProperty(value = "更新时间") |
||||
private Date updateTime; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") |
||||
private Integer deleted; |
||||
|
||||
@TableField(exist = false) |
||||
@ApiModelProperty(value = "权限") |
||||
private List<Integer> permissions; |
||||
|
||||
|
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.huoran.iasf.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
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 { |
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
private Integer roleId; |
||||
|
||||
private Integer permissionId; |
||||
|
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue