李磊
5 years ago
79 changed files with 3852 additions and 1 deletions
@ -0,0 +1,3 @@ |
|||
Manifest-Version: 1.0 |
|||
Main-Class: com.stone.Application |
|||
|
@ -1,2 +1,17 @@ |
|||
# DYBG |
|||
# DYBGManager |
|||
|
|||
打印报告 |
|||
|
|||
济南16版报检到18版出具承压报告时间 和 济南18版报检到16版出具机电报告时间的报告都得做特殊的处理。 |
|||
|
|||
> 全部从18版报检,承压走18版查询报告,机电走16版查询报告 |
|||
> |
|||
> |
|||
|
|||
# aspose在pdf里添加电子印章 |
|||
https://www.evget.com/article/2013/3/13/18632.html |
|||
|
|||
https://www.evget.com/article/2011/9/2/16570.html |
|||
|
|||
http://www.componentcn.com/kongjianjishu/kongjianjishu/2015-06-15/2823.html |
|||
|
|||
|
@ -0,0 +1,224 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<!-- 认认真真的注释一下maven的配置文件 --> |
|||
|
|||
<!-- 声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。--> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<!-- 项目的全球唯一标识符,通常使用全限定的包名区分该项目和其他项目。并且构建时生成的路径也是由此生成 --> |
|||
<groupId>com.stone</groupId> |
|||
<!-- 构件的标识符,它和group ID一起唯一标识一个构件;在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源码,二进制发布和WARs等。--> |
|||
<artifactId>DYBGManager</artifactId> |
|||
<packaging>war</packaging> |
|||
|
|||
<!-- 父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。--> |
|||
<parent> |
|||
<!-- Spring boot的项目必须要将parent设置为spring boot的parent,该parent包含了大量默认的配置,大大简化了我们的开发 --> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-parent</artifactId> |
|||
<version>2.1.0.RELEASE</version> |
|||
</parent> |
|||
|
|||
<!-- 以值替代名称,Properties可以在整个POM中使用,也可以作为触发条件;格式是<name>value</name>。--> |
|||
<properties> |
|||
<java.version>1.8</java.version> |
|||
<mybatis.spring.version>1.2.4</mybatis.spring.version> |
|||
<mapper.starter.version>2.0.4</mapper.starter.version> |
|||
<pagehelper.starter.version>1.2.9</pagehelper.starter.version> |
|||
</properties> |
|||
|
|||
<!-- 该元素描述了项目相关的所有依赖。这些依赖组成了项目构建过程中的一个个环节。它们自动从项目定义的仓库中下载。--> |
|||
<dependencies> |
|||
<!-- 导入spring boot的web支持 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<!-- 去除内嵌tomcat 生产环境下开启--> |
|||
<!--<exclusions> |
|||
<exclusion> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-tomcat</artifactId> |
|||
</exclusion> |
|||
</exclusions>--> |
|||
</dependency> |
|||
<!-- 导入spring boot对数据库jdbc的支持 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-jdbc</artifactId> |
|||
</dependency> |
|||
<!-- 使用spring-aop和AspectJ 支持面向切面编程 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-aop</artifactId> |
|||
</dependency> |
|||
<!-- 对常用的测试框架Junit,Hamcrest 和 Mockito的支持 包含spring-test的模块 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
</dependency> |
|||
<!-- 增加redis数据库配置 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-data-redis</artifactId> |
|||
</dependency> |
|||
<!-- 可以从被@ConfigurationProperties注解的节点轻松的产生自己的配置元数据文件 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<!-- 导入mysql连接设置 --> |
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
<version>8.0.13</version> |
|||
</dependency> |
|||
<!-- 导入oracle连接设置 --> |
|||
<!--<dependency> |
|||
<groupId>com.oracle</groupId> |
|||
<artifactId>ojdbc14</artifactId> |
|||
<version>10.2.0.4.0</version> |
|||
<scope>system</scope> |
|||
<systemPath>${project.basedir}/src/main/resources/generator/ojdbc14.jar</systemPath> |
|||
</dependency>--> |
|||
<!-- 导入sqlserver连接设置 --> |
|||
<!--<dependency> |
|||
<groupId>com.microsoft</groupId> |
|||
<artifactId>sqlserver</artifactId> |
|||
<version>1.0</version> |
|||
<scope>system</scope> |
|||
<systemPath>${project.basedir}/src/main/resources/generator/sqljdbc2008.jar</systemPath> |
|||
</dependency>--> |
|||
<!-- 导入大圣之前写的消红jar包 --> |
|||
<!--<dependency> |
|||
<groupId>org.tempuri</groupId> |
|||
<artifactId>webclient</artifactId> |
|||
<scope>system</scope> |
|||
<systemPath>${project.basedir}/src/main/resources/generator/webclient.jar</systemPath> |
|||
</dependency>--> |
|||
<!-- 导入spring对Apache Shiro的 --> |
|||
<dependency> |
|||
<groupId>org.apache.shiro</groupId> |
|||
<artifactId>shiro-spring</artifactId> |
|||
<version>1.4.2</version> |
|||
</dependency> |
|||
<!-- springBoot与mybatis的整合 --> |
|||
<dependency> |
|||
<groupId>org.mybatis.spring.boot</groupId> |
|||
<artifactId>mybatis-spring-boot-starter</artifactId> |
|||
<version>1.3.2</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>tk.mybatis</groupId> |
|||
<artifactId>mapper-spring-boot-starter</artifactId> |
|||
<version>${mapper.starter.version}</version> |
|||
</dependency> |
|||
<!-- springBoot的分页工具 --> |
|||
<dependency> |
|||
<groupId>com.github.pagehelper</groupId> |
|||
<artifactId>pagehelper-spring-boot-starter</artifactId> |
|||
<version>${pagehelper.starter.version}</version> |
|||
<!-- 当计算传递依赖时, 从依赖构件列表里,列出被排除的依赖构件集。即告诉maven你只依赖指定的项目,不依赖项目的依赖。此元素主要用于解决版本冲突问题 --> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>org.mybatis.spring.boot</groupId> |
|||
<artifactId>mybatis-spring-boot-starter</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<!-- 添加druid数据库连接池对springBoot的支持 --> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>druid-spring-boot-starter</artifactId> |
|||
<version>1.1.10</version> |
|||
</dependency> |
|||
<!-- 添加hutool工具类 --> |
|||
<dependency> |
|||
<groupId>cn.hutool</groupId> |
|||
<artifactId>hutool-all</artifactId> |
|||
<version>4.1.19</version> |
|||
</dependency> |
|||
<!-- 添加fastjson对json串的处理 --> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
<version>1.2.51</version> |
|||
</dependency> |
|||
<!-- 添加shiro+redis缓存插件 --> |
|||
<dependency> |
|||
<groupId>org.crazycake</groupId> |
|||
<artifactId>shiro-redis</artifactId> |
|||
<version>3.2.3</version> |
|||
</dependency> |
|||
<!-- 添加lombok插件简化实体类冗余代码 --> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<version>1.18.4</version> |
|||
</dependency> |
|||
<!-- Swagger API文档 --> |
|||
<dependency> |
|||
<groupId>io.springfox</groupId> |
|||
<artifactId>springfox-swagger2</artifactId> |
|||
<version>2.9.2</version> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>io.swagger</groupId> |
|||
<artifactId>swagger-annotations</artifactId> |
|||
</exclusion> |
|||
<exclusion> |
|||
<groupId>io.swagger</groupId> |
|||
<artifactId>swagger-models</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.springfox</groupId> |
|||
<artifactId>springfox-swagger-ui</artifactId> |
|||
<version>2.9.2</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.swagger</groupId> |
|||
<artifactId>swagger-annotations</artifactId> |
|||
<version>1.5.21</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.swagger</groupId> |
|||
<artifactId>swagger-models</artifactId> |
|||
<version>1.5.21</version> |
|||
</dependency> |
|||
<!--添加servlet的依赖 生产环境下开启--> |
|||
<!--<dependency> |
|||
<groupId>javax.servlet</groupId> |
|||
<artifactId>javax.servlet-api</artifactId> |
|||
<version>4.0.1</version> |
|||
<scope>provided</scope> |
|||
</dependency>--> |
|||
|
|||
<!-- 增加打包构建插件 --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
<version>2.1.8.RELEASE</version> |
|||
</dependency> |
|||
|
|||
</dependencies> |
|||
|
|||
<!-- 构建项目需要的信息 --> |
|||
<build> |
|||
<!-- 打包项目名称 --> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<!-- 使用的插件列表 --> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<configuration> |
|||
<testFailureIgnore>true</testFailureIgnore> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
|
|||
</project> |
@ -0,0 +1,41 @@ |
|||
package com.stone; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.boot.CommandLineRunner; |
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
import org.springframework.boot.builder.SpringApplicationBuilder; |
|||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
|||
import org.springframework.scheduling.annotation.EnableScheduling; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
|||
import tk.mybatis.spring.annotation.MapperScan; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
@Controller |
|||
@EnableWebMvc |
|||
@SpringBootApplication |
|||
@MapperScan(basePackages = "com.stone.mapper") |
|||
public class Application extends SpringBootServletInitializer implements CommandLineRunner { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(Application.class); |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(Application.class, args); |
|||
} |
|||
|
|||
/*// 生产环境
|
|||
@Override |
|||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { |
|||
return application.sources(Application.class); |
|||
}*/ |
|||
|
|||
@Override |
|||
public void run(String... args) { |
|||
logger.info("服务启动完成!"); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,123 @@ |
|||
package com.stone.api.enums; |
|||
|
|||
import com.stone.conf.exception.*; |
|||
import org.springframework.http.HttpStatus; |
|||
|
|||
/** |
|||
* 异常、HTTP状态码、默认自定义返回码 映射类 |
|||
*/ |
|||
public enum BusinessExceptionEnum { |
|||
|
|||
/** |
|||
* 无效参数 |
|||
*/ |
|||
PARAMETER_INVALID(ParameterInvalidException.class, HttpStatus.BAD_REQUEST, ResultCode.PARAM_IS_INVALID), |
|||
|
|||
/** |
|||
* 数据未找到 |
|||
*/ |
|||
NOT_FOUND(DataNotFoundException.class, HttpStatus.NOT_FOUND, ResultCode.RESULE_DATA_NONE), |
|||
|
|||
/** |
|||
* 接口方法不允许 |
|||
*/ |
|||
METHOD_NOT_ALLOWED(MethodNotAllowException.class, HttpStatus.METHOD_NOT_ALLOWED, ResultCode.INTERFACE_ADDRESS_INVALID), |
|||
|
|||
/** |
|||
* 数据已存在 |
|||
*/ |
|||
CONFLICT(DataConflictException.class, HttpStatus.CONFLICT, ResultCode.DATA_ALREADY_EXISTED), |
|||
|
|||
/** |
|||
* 用户未登录 |
|||
*/ |
|||
UNAUTHORIZED(UserNotLoginException.class, HttpStatus.UNAUTHORIZED, ResultCode.USER_NOT_LOGGED_IN), |
|||
|
|||
/** |
|||
* 无访问权限 |
|||
*/ |
|||
FORBIDDEN(PermissionForbiddenException.class, HttpStatus.FORBIDDEN, ResultCode.PERMISSION_NO_ACCESS), |
|||
|
|||
/** |
|||
* 远程访问时错误 |
|||
*/ |
|||
REMOTE_ACCESS_ERROR(RemoteAccessException.class, HttpStatus.INTERNAL_SERVER_ERROR, ResultCode.INTERFACE_OUTTER_INVOKE_ERROR), |
|||
|
|||
/** |
|||
* 系统内部错误 |
|||
*/ |
|||
INTERNAL_SERVER_ERROR(InternalServerException.class, HttpStatus.INTERNAL_SERVER_ERROR, ResultCode.SYSTEM_INNER_ERROR); |
|||
|
|||
private Class<? extends BusinessException> eClass; |
|||
|
|||
private HttpStatus httpStatus; |
|||
|
|||
private ResultCode resultCode; |
|||
|
|||
BusinessExceptionEnum(Class<? extends BusinessException> eClass, HttpStatus httpStatus, ResultCode resultCode) { |
|||
this.eClass = eClass; |
|||
this.httpStatus = httpStatus; |
|||
this.resultCode = resultCode; |
|||
} |
|||
|
|||
public Class<? extends BusinessException> getEClass() { |
|||
return eClass; |
|||
} |
|||
|
|||
public HttpStatus getHttpStatus() { |
|||
return httpStatus; |
|||
} |
|||
|
|||
public ResultCode getResultCode() { |
|||
return resultCode; |
|||
} |
|||
|
|||
public static boolean isSupportHttpStatus(int httpStatus) { |
|||
for (BusinessExceptionEnum exceptionEnum : BusinessExceptionEnum.values()) { |
|||
if (exceptionEnum.httpStatus.value() == httpStatus) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public static boolean isSupportException(Class<?> z) { |
|||
for (BusinessExceptionEnum exceptionEnum : BusinessExceptionEnum.values()) { |
|||
if (exceptionEnum.eClass.equals(z)) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public static BusinessExceptionEnum getByHttpStatus(HttpStatus httpStatus) { |
|||
if (httpStatus == null) { |
|||
return null; |
|||
} |
|||
|
|||
for (BusinessExceptionEnum exceptionEnum : BusinessExceptionEnum.values()) { |
|||
if (httpStatus.equals(exceptionEnum.httpStatus)) { |
|||
return exceptionEnum; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static BusinessExceptionEnum getByEClass(Class<? extends BusinessException> eClass) { |
|||
if (eClass == null) { |
|||
return null; |
|||
} |
|||
|
|||
for (BusinessExceptionEnum exceptionEnum : BusinessExceptionEnum.values()) { |
|||
if (eClass.equals(exceptionEnum.eClass)) { |
|||
return exceptionEnum; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
package com.stone.api.enums; |
|||
|
|||
/** |
|||
* API 统一返回状态码 |
|||
*/ |
|||
public enum ResultCode { |
|||
|
|||
/* 成功状态码 */ |
|||
SUCCESS(1, "成功"), |
|||
|
|||
/* 参数错误:10001-19999 */ |
|||
PARAM_IS_INVALID(10001, "参数无效"), |
|||
PARAM_IS_BLANK(10002, "参数为空"), |
|||
PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"), |
|||
PARAM_NOT_COMPLETE(10004, "参数缺失"), |
|||
|
|||
/* 用户错误:20001-29999*/ |
|||
USER_NOT_LOGGED_IN(20001, "用户未登录"), |
|||
USER_LOGIN_ERROR(20002, "账号不存在或密码错误"), |
|||
USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"), |
|||
USER_NOT_EXIST(20004, "用户不存在"), |
|||
USER_HAS_EXISTED(20005, "用户已存在"), |
|||
LOGIN_CREDENTIAL_EXISTED(20006, "凭证已存在"), |
|||
USER_SIGN_PASSWORD_ERROR(20007, "签名密码错误,请重新输入"), |
|||
|
|||
/* 业务错误:30001-39999 */ |
|||
SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "业务错误"), |
|||
|
|||
/* 系统错误:40001-49999 */ |
|||
SYSTEM_INNER_ERROR(40001, "系统繁忙,请稍后重试"), |
|||
|
|||
/* 数据错误:50001-599999 */ |
|||
RESULE_DATA_NONE(50001, "数据未找到"), |
|||
DATA_IS_WRONG(50002, "数据有误"), |
|||
DATA_ALREADY_EXISTED(50003, "数据已存在"), |
|||
|
|||
/* 接口错误:60001-69999 */ |
|||
INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"), |
|||
INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"), |
|||
INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"), |
|||
INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"), |
|||
INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"), |
|||
INTERFACE_EXCEED_LOAD(60006, "接口负载过高"), |
|||
|
|||
/* 权限错误:70001-79999 */ |
|||
PERMISSION_NO_ACCESS(70001, "无访问权限"), |
|||
RESOURCE_EXISTED(70002, "资源已存在"), |
|||
RESOURCE_NOT_EXISTED(70003, "资源不存在"), |
|||
|
|||
/* 预览错误:80001-89999 */ |
|||
PREVIEW_CHILD_PARAM_ERROR(80001, "子报告生成参数异常"), |
|||
PREVIEW_CONVERT_PDF_ERROR(80002, "转换 PDF 文件异常"); |
|||
|
|||
private Integer code; |
|||
|
|||
private String message; |
|||
|
|||
ResultCode(Integer code, String message) { |
|||
this.code = code; |
|||
this.message = message; |
|||
} |
|||
|
|||
public Integer code() { |
|||
return this.code; |
|||
} |
|||
|
|||
public String message() { |
|||
return this.message; |
|||
} |
|||
|
|||
public static String getMessage(String name) { |
|||
for (ResultCode item : ResultCode.values()) { |
|||
if (item.name().equals(name)) { |
|||
return item.message; |
|||
} |
|||
} |
|||
return name; |
|||
} |
|||
|
|||
public static Integer getCode(String name) { |
|||
for (ResultCode item : ResultCode.values()) { |
|||
if (item.name().equals(name)) { |
|||
return item.code; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return this.name(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.stone.base; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
public abstract class BaseController<E, ID extends Serializable> { |
|||
|
|||
/** |
|||
* 获取service |
|||
* @return |
|||
*/ |
|||
@Autowired |
|||
public abstract BaseService<E,ID> getService(); |
|||
|
|||
} |
@ -0,0 +1,42 @@ |
|||
package com.stone.base; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.persistence.Column; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 基础信息 |
|||
* @author zichen |
|||
*/ |
|||
@Data |
|||
public abstract class BaseEntity implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "创建时间") |
|||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@Column(name = "create_time") |
|||
private Date createTime; |
|||
|
|||
@ApiModelProperty(value = "创建人") |
|||
@Column(name = "create_by") |
|||
private String createBy; |
|||
|
|||
@ApiModelProperty(value = "修改时间") |
|||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@Column(name = "update_time") |
|||
private Date updateTime; |
|||
|
|||
@ApiModelProperty(value = "修改人") |
|||
@Column(name = "update_by") |
|||
private String updateBy; |
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
package com.stone.base; |
|||
|
|||
import tk.mybatis.mapper.common.Mapper; |
|||
import tk.mybatis.mapper.common.MySqlMapper; |
|||
|
|||
public interface BaseMapper<T> extends Mapper<T>, MySqlMapper<T> { |
|||
// FIXME 特别注意,该接口不能被扫描到,否则会出错
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.stone.base; |
|||
|
|||
import org.apache.shiro.SecurityUtils; |
|||
import org.apache.shiro.session.Session; |
|||
import org.apache.shiro.subject.Subject; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* JDK8函数式接口注解 仅能包含一个抽象方法 |
|||
* @author zichen |
|||
*/ |
|||
@FunctionalInterface |
|||
public interface BaseService<E, ID extends Serializable> { |
|||
|
|||
BaseMapper<E> getRepository(); |
|||
|
|||
default Session getSession() { |
|||
Subject sub = SecurityUtils.getSubject(); |
|||
return sub.getSession(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,48 @@ |
|||
package com.stone.conf; |
|||
|
|||
import com.stone.conf.enums.FilePathConstants; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.Ordered; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
|||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
|||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
|
|||
@Configuration |
|||
public class WebMvcConfig implements WebMvcConfigurer { |
|||
|
|||
@Value("${front.ip}") |
|||
private String frontIp; |
|||
|
|||
@Value("${front.projectName}") |
|||
private String projectName; |
|||
|
|||
@Override |
|||
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
|||
// 定义PDF预览网络路径
|
|||
registry.addResourceHandler(projectName + "18/pdf/**") |
|||
.addResourceLocations("file:" + FilePathConstants.TEMPLATE_18 + projectName + "/pdf/"); |
|||
// 定义图片资源路径
|
|||
registry.addResourceHandler(projectName + "16/pdf/**") |
|||
.addResourceLocations("file:" + FilePathConstants.TEMPLATE_16 + "/PDF/" + projectName); |
|||
} |
|||
|
|||
/** |
|||
* 允许跨域访问 |
|||
*/ |
|||
@Override |
|||
public void addCorsMappings(CorsRegistry registry) { |
|||
registry.addMapping("/**") |
|||
.allowedHeaders("*") |
|||
.allowedMethods("*") |
|||
.allowedOrigins(frontIp) //此处为前台项目的ip地址
|
|||
.allowCredentials(true) |
|||
.exposedHeaders(HttpHeaders.SET_COOKIE); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package com.stone.conf.datasource.intermediate; |
|||
|
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.mybatis.spring.SqlSessionFactoryBean; |
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
|||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
|||
import tk.mybatis.spring.annotation.MapperScan; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
@Configuration |
|||
@MapperScan(basePackages = "com.stone.mapper.intermediate", sqlSessionFactoryRef = "SessionTemplateIntermediate") |
|||
public class DruidIntermediate { |
|||
|
|||
@Bean |
|||
@ConfigurationProperties(prefix = "spring.datasource.intermediate") |
|||
public DataSourceProperties DataSourcePropertiesIntermediate(){ |
|||
return new DataSourceProperties(); |
|||
} |
|||
|
|||
@Bean |
|||
@ConfigurationProperties(prefix = "spring.datasource.intermediate") |
|||
public DataSource DataSourceIntermediates() { |
|||
return DataSourcePropertiesIntermediate().initializeDataSourceBuilder().build(); |
|||
// return DataSourceBuilder.create().build();
|
|||
} |
|||
|
|||
@Bean |
|||
public DataSourceTransactionManager TransactionManagerIntermediate() { |
|||
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(); |
|||
dataSourceTransactionManager.setDataSource(DataSourceIntermediates()); |
|||
return dataSourceTransactionManager; |
|||
} |
|||
|
|||
@Bean(name = "SessionTemplateIntermediate") |
|||
public SqlSessionFactory SqlSessionFactoryIntermediate() throws Exception { |
|||
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
|||
sessionFactory.setDataSource(DataSourceIntermediates()); |
|||
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() |
|||
.getResources( "classpath*:mapper/intermediate/*.xml")); |
|||
return sessionFactory.getObject(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,56 @@ |
|||
package com.stone.conf.datasource.senior; |
|||
|
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.mybatis.spring.SqlSessionFactoryBean; |
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.context.annotation.Primary; |
|||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
|||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
|||
import tk.mybatis.spring.annotation.MapperScan; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
@Configuration |
|||
@MapperScan(basePackages = "com.stone.mapper.senior", sqlSessionFactoryRef = "SessionTemplateSenior") |
|||
public class DruidSenior { |
|||
|
|||
@Bean |
|||
@Primary |
|||
@ConfigurationProperties(prefix = "spring.datasource.senior") |
|||
public DataSourceProperties DataSourcePropertiesSenior(){ |
|||
return new DataSourceProperties(); |
|||
} |
|||
|
|||
@Bean |
|||
@Primary |
|||
@ConfigurationProperties(prefix = "spring.datasource.senior") |
|||
public DataSource DataSourceSeniors() { |
|||
return DataSourcePropertiesSenior().initializeDataSourceBuilder().build(); |
|||
// return DataSourceBuilder.create().build();
|
|||
} |
|||
|
|||
@Bean |
|||
@Primary |
|||
public DataSourceTransactionManager TransactionManagerSenior() { |
|||
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(); |
|||
dataSourceTransactionManager.setDataSource(DataSourceSeniors()); |
|||
return dataSourceTransactionManager; |
|||
} |
|||
|
|||
@Bean(name = "SessionTemplateSenior") |
|||
@Primary |
|||
public SqlSessionFactory SqlSessionFactorySenior() throws Exception { |
|||
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
|||
sessionFactory.setDataSource(DataSourceSeniors()); |
|||
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() |
|||
.getResources( "classpath*:mapper/senior/*.xml")); |
|||
return sessionFactory.getObject(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
public class Constants { |
|||
|
|||
public static final String SUCCESS_CODE = "100"; |
|||
public static final String SUCCESS_MSG = "请求成功"; |
|||
|
|||
/** |
|||
* session中存放用户信息的key值 |
|||
*/ |
|||
public static final String SESSION_USER_PERMISSION = "userPermission"; |
|||
|
|||
public final static String SESSION_USER_OBJECT = "SESSION_USER_OBJECT_EXP"; |
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import lombok.*; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@ApiModel(value = "设备种类代码") |
|||
public enum EquipmentCodeEnum { |
|||
|
|||
/* |
|||
* 错误信息 |
|||
* */ |
|||
GL("1000", "锅炉"), |
|||
|
|||
YLRQ("2000", "压力容器"), |
|||
|
|||
DT("3000", "电梯"), |
|||
|
|||
QZJ("4000", "起重机"), |
|||
|
|||
CC("5000", "厂车"), |
|||
|
|||
YLGDYJ("7000", "压力管道原件"), |
|||
|
|||
YLGD("8000", "压力管道"); |
|||
|
|||
@Getter @Setter |
|||
private String code; |
|||
|
|||
@Getter @Setter |
|||
private String name; |
|||
|
|||
} |
@ -0,0 +1,52 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
public enum ErrorEnum { |
|||
|
|||
/* |
|||
* 错误信息 |
|||
* */ |
|||
E_400("400", "请求处理异常,请稍后再试"), |
|||
|
|||
E_10009("10009", "账户已存在"), |
|||
|
|||
E_10008("10008", "原始密码输入错误,请重试"), |
|||
|
|||
E_10007("10007", "签名密码输入错误,请重试"), |
|||
|
|||
E_10006("10006", "模板文件不存在,请上传后下载"), |
|||
|
|||
E_10005("10005", "上传文件格式有误,请核对后导入"), |
|||
|
|||
E_20011("20011", "登陆已过期,请重新登陆"), |
|||
|
|||
E_90003("90003", "缺少必填参数"); |
|||
|
|||
private String errorCode; |
|||
|
|||
private String errorMsg; |
|||
|
|||
ErrorEnum() { |
|||
} |
|||
|
|||
ErrorEnum(String errorCode, String errorMsg) { |
|||
this.errorCode = errorCode; |
|||
this.errorMsg = errorMsg; |
|||
} |
|||
|
|||
public String getErrorCode() { |
|||
return errorCode; |
|||
} |
|||
|
|||
public void setErrorCode(String errorCode) { |
|||
this.errorCode = errorCode; |
|||
} |
|||
|
|||
public String getErrorMsg() { |
|||
return errorMsg; |
|||
} |
|||
|
|||
public void setErrorMsg(String errorMsg) { |
|||
this.errorMsg = errorMsg; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
/** |
|||
* 文件路径 |
|||
* @author zichen |
|||
*/ |
|||
public final class FilePathConstants { |
|||
|
|||
public static final String TEMPLATE_18 = "D:/static/"; |
|||
|
|||
public static final String TEMPLATE_16 = "D:/SDMA/"; |
|||
|
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
public final class LinkConstants { |
|||
|
|||
public final static String BJ = "bjState"; |
|||
|
|||
public final static String RENWU = "fpState"; |
|||
|
|||
public final static String ALLOT_RENWU = "renwuState"; |
|||
|
|||
public final static String YSJL = "ysjlState"; |
|||
|
|||
public final static String REPORT = "reportState"; |
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
import io.swagger.annotations.ApiModelProperty; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
public class MagicValueConstants { |
|||
|
|||
@ApiModelProperty(value = "日期格式化") |
|||
public final static String DATE_FORMAT = "yyyy-MM-dd"; |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
public final class StateConstants { |
|||
|
|||
public final static String BJ = "bjState"; |
|||
|
|||
public final static String RENWU = "fpState"; |
|||
|
|||
public final static String ALLOT_RENWU = "renwuState"; |
|||
|
|||
public final static String YSJL = "ysjlState"; |
|||
|
|||
public final static String REPORT = "reportState"; |
|||
|
|||
} |
@ -0,0 +1,12 @@ |
|||
package com.stone.conf.enums; |
|||
|
|||
/** |
|||
* @author zichen |
|||
*/ |
|||
public class VersionConstants { |
|||
|
|||
public final static String SENIOR = "18"; |
|||
|
|||
public final static String Intermediate = "16"; |
|||
|
|||
} |
@ -0,0 +1,54 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.stone.api.enums.BusinessExceptionEnum; |
|||
import com.stone.api.enums.ResultCode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class BusinessException extends RuntimeException { |
|||
|
|||
private static final long serialVersionUID = 194906846739586856L; |
|||
|
|||
protected String code; |
|||
|
|||
protected String message; |
|||
|
|||
protected ResultCode resultCode; |
|||
|
|||
protected Object data; |
|||
|
|||
public BusinessException() { |
|||
BusinessExceptionEnum exceptionEnum = BusinessExceptionEnum.getByEClass(this.getClass()); |
|||
if (exceptionEnum != null) { |
|||
resultCode = exceptionEnum.getResultCode(); |
|||
code = exceptionEnum.getResultCode().code().toString(); |
|||
message = exceptionEnum.getResultCode().message(); |
|||
} |
|||
|
|||
} |
|||
|
|||
public BusinessException(String message) { |
|||
this(); |
|||
this.message = message; |
|||
} |
|||
|
|||
public BusinessException(String format, Object... objects) { |
|||
this(); |
|||
this.message = StrUtil.format(format, "{}", objects); |
|||
} |
|||
|
|||
public BusinessException(ResultCode resultCode, Object data) { |
|||
this(resultCode); |
|||
this.data = data; |
|||
} |
|||
|
|||
public BusinessException(ResultCode resultCode) { |
|||
this.resultCode = resultCode; |
|||
this.code = resultCode.code().toString(); |
|||
this.message = resultCode.message(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.stone.conf.enums.ErrorEnum; |
|||
import com.stone.util.common.ReturnJSONUtils; |
|||
|
|||
/** |
|||
* 本系统使用的自定义错误类 |
|||
* 比如在校验参数时,如果不符合要求,可以抛出此错误类 |
|||
* 拦截器可以统一拦截此错误,将其中json返回给前端 |
|||
*/ |
|||
|
|||
public class CommonJsonException extends RuntimeException { |
|||
|
|||
private JSONObject resultJson; |
|||
|
|||
/** |
|||
* 调用时可以在任何代码处直接throws这个Exception, |
|||
* 都会统一被拦截,并封装好json返回给前台 |
|||
* @param errorEnum 以错误的ErrorEnum做参数 |
|||
*/ |
|||
public CommonJsonException(ErrorEnum errorEnum) { |
|||
this.resultJson = ReturnJSONUtils.errorJson(errorEnum); |
|||
} |
|||
|
|||
public CommonJsonException(JSONObject resultJson) { |
|||
this.resultJson = resultJson; |
|||
} |
|||
|
|||
public JSONObject getResultJson() { |
|||
return resultJson; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 数据已经存在异常 |
|||
*/ |
|||
public class DataConflictException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = 3721036867889297081L; |
|||
|
|||
public DataConflictException() { |
|||
super(); |
|||
} |
|||
|
|||
public DataConflictException(Object data) { |
|||
super.data = data; |
|||
} |
|||
|
|||
public DataConflictException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public DataConflictException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public DataConflictException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public DataConflictException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 数据没有找到异常 |
|||
*/ |
|||
public class DataNotFoundException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = 3721036867889297081L; |
|||
|
|||
public DataNotFoundException() { |
|||
super(); |
|||
} |
|||
|
|||
public DataNotFoundException(Object data) { |
|||
super(); |
|||
super.data = data; |
|||
} |
|||
|
|||
public DataNotFoundException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public DataNotFoundException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public DataNotFoundException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public DataNotFoundException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
/** |
|||
* 内部服务异常 |
|||
*/ |
|||
public class InternalServerException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = 2659909836556958676L; |
|||
|
|||
public InternalServerException() { |
|||
super(); |
|||
} |
|||
|
|||
public InternalServerException(String msg, Throwable cause) { |
|||
super(msg, cause); |
|||
} |
|||
|
|||
public InternalServerException(String msg, Throwable cause, Object... objects) { |
|||
super(msg, cause, objects); |
|||
} |
|||
|
|||
public InternalServerException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public InternalServerException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 方法不允许异常 |
|||
*/ |
|||
public class MethodNotAllowException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = -3813290937049524713L; |
|||
|
|||
public MethodNotAllowException() { |
|||
super(); |
|||
} |
|||
|
|||
public MethodNotAllowException(Object data) { |
|||
super.data = data; |
|||
} |
|||
|
|||
public MethodNotAllowException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public MethodNotAllowException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public MethodNotAllowException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public MethodNotAllowException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 参数无效异常 |
|||
*/ |
|||
public class ParameterInvalidException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = 3721036867889297081L; |
|||
|
|||
public ParameterInvalidException() { |
|||
super(); |
|||
} |
|||
|
|||
public ParameterInvalidException(Object data) { |
|||
super(); |
|||
super.data = data; |
|||
} |
|||
|
|||
public ParameterInvalidException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public ParameterInvalidException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public ParameterInvalidException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public ParameterInvalidException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 权限不足异常 |
|||
*/ |
|||
public class PermissionForbiddenException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = 3721036867889297081L; |
|||
|
|||
public PermissionForbiddenException() { |
|||
super(); |
|||
} |
|||
|
|||
public PermissionForbiddenException(Object data) { |
|||
super.data = data; |
|||
} |
|||
|
|||
public PermissionForbiddenException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public PermissionForbiddenException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public PermissionForbiddenException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public PermissionForbiddenException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
import com.stone.api.enums.ResultCode; |
|||
|
|||
/** |
|||
* 远程访问异常 |
|||
*/ |
|||
public class RemoteAccessException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = -832464574076215195L; |
|||
|
|||
public RemoteAccessException() { |
|||
super(); |
|||
} |
|||
|
|||
public RemoteAccessException(Object data) { |
|||
super.data = data; |
|||
} |
|||
|
|||
public RemoteAccessException(ResultCode resultCode) { |
|||
super(resultCode); |
|||
} |
|||
|
|||
public RemoteAccessException(ResultCode resultCode, Object data) { |
|||
super(resultCode, data); |
|||
} |
|||
|
|||
public RemoteAccessException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public RemoteAccessException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.stone.conf.exception; |
|||
|
|||
/** |
|||
* 用户未登录异常 |
|||
*/ |
|||
public class UserNotLoginException extends BusinessException { |
|||
|
|||
private static final long serialVersionUID = -1879503946782379204L; |
|||
|
|||
public UserNotLoginException() { |
|||
super(); |
|||
} |
|||
|
|||
public UserNotLoginException(String msg) { |
|||
super(msg); |
|||
} |
|||
|
|||
public UserNotLoginException(String formatMsg, Object... objects) { |
|||
super(formatMsg, objects); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,67 @@ |
|||
package com.stone.conf.filter; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.stone.api.enums.ResultCode; |
|||
import com.stone.conf.redis.RedisHelper; |
|||
import org.apache.shiro.SecurityUtils; |
|||
import org.apache.shiro.subject.Subject; |
|||
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; |
|||
import org.apache.shiro.web.util.WebUtils; |
|||
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|||
import org.springframework.context.annotation.Bean; |
|||
|
|||
import javax.servlet.ServletRequest; |
|||
import javax.servlet.ServletResponse; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.PrintWriter; |
|||
|
|||
/** |
|||
* 对没有登录的请求进行拦截, 全部返回json信息. |
|||
* 覆盖掉shiro原本的跳转login.jsp的拦截方式 |
|||
*/ |
|||
public class AjaxPermissionsAuthorizationFilter extends FormAuthenticationFilter { |
|||
|
|||
@Override |
|||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) { |
|||
if ("OPTIONS".equals(WebUtils.toHttp(request).getMethod())) { |
|||
return true; |
|||
} |
|||
String token = WebUtils.toHttp(request).getHeader("Authorization"); |
|||
if (StrUtil.isEmpty(token) || (StrUtil.isNotEmpty(token) && !RedisHelper.exists(token))) { |
|||
JSONObject jsonObject = new JSONObject(); |
|||
jsonObject.put("returnCode", 20011); |
|||
jsonObject.put("returnMsg", "用户未登录"); |
|||
PrintWriter out = null; |
|||
HttpServletResponse res = (HttpServletResponse) response; |
|||
// 接下来的几句话是个坑,一定要加上,跨域访问才可以正常退出。
|
|||
res.setHeader("Access-Control-Allow-Origin", ((HttpServletRequest) request).getHeader("Origin")); |
|||
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"); |
|||
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE"); |
|||
res.setHeader("Access-Control-Allow-Credentials", "true"); |
|||
try { |
|||
res.setCharacterEncoding("UTF-8"); |
|||
res.setContentType("application/json"); |
|||
out = response.getWriter(); |
|||
out.println(jsonObject); |
|||
} catch (Exception ignored) { |
|||
} finally { |
|||
if (out != null) { |
|||
out.flush(); |
|||
out.close(); |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
@Bean |
|||
public FilterRegistrationBean<AjaxPermissionsAuthorizationFilter> registration(AjaxPermissionsAuthorizationFilter filter) { |
|||
FilterRegistrationBean<AjaxPermissionsAuthorizationFilter> registration = new FilterRegistrationBean<>(filter); |
|||
registration.setEnabled(false); |
|||
return registration; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,43 @@ |
|||
package com.stone.conf.redis; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
|||
import org.springframework.cache.annotation.EnableCaching; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import redis.clients.jedis.JedisPool; |
|||
import redis.clients.jedis.JedisPoolConfig; |
|||
|
|||
@Configuration |
|||
@EnableCaching |
|||
public class RedisConfig extends CachingConfigurerSupport { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(RedisConfig.class); |
|||
|
|||
@Value("${spring.redis.host}") |
|||
private String host; |
|||
|
|||
@Value("${spring.redis.port}") |
|||
private int port; |
|||
|
|||
@Value("${spring.redis.timeout}") |
|||
private int timeout; |
|||
|
|||
@Value("${spring.redis.jedis.pool.max-idle}") |
|||
private int maxIdle; |
|||
|
|||
@Value("${spring.redis.jedis.pool.max-wait}") |
|||
private long maxWaitMillis; |
|||
|
|||
@Bean |
|||
public JedisPool redisPoolFactory() { |
|||
logger.info("JedisPool注入成功!!"); |
|||
logger.info("redis地址:" + host + ":" + port); |
|||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); |
|||
jedisPoolConfig.setMaxIdle(maxIdle); |
|||
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); |
|||
return new JedisPool(jedisPoolConfig, host, port, timeout); |
|||
} |
|||
} |
@ -0,0 +1,132 @@ |
|||
package com.stone.conf.redis; |
|||
|
|||
import redis.clients.jedis.Jedis; |
|||
|
|||
import java.io.*; |
|||
|
|||
/** |
|||
* redis 序列化辅助类 |
|||
* |
|||
* @author zhoujl |
|||
* @date 2019-04-30 |
|||
*/ |
|||
public class RedisHelper { |
|||
|
|||
/** |
|||
* 添加缓存信息 |
|||
*/ |
|||
public static void add(String key, Object value) { |
|||
Jedis jedis = new Jedis("localhost"); |
|||
try { |
|||
jedis.set(key.getBytes(), ObjectTranscoder.serialize(value)); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取缓存信息 |
|||
*/ |
|||
public static Object get(String key) { |
|||
Jedis jedis = new Jedis("localhost"); |
|||
if (!jedis.exists(key.getBytes())) { |
|||
return null; |
|||
} |
|||
byte[] in = jedis.get(key.getBytes()); |
|||
return ObjectTranscoder.deserialize(in); |
|||
} |
|||
|
|||
/** |
|||
* 判断 key 是否存在 |
|||
* |
|||
* @param key 键信息 |
|||
* @return 是否存在 |
|||
*/ |
|||
public static Boolean exists(String key) { |
|||
Jedis jedis = new Jedis("localhost"); |
|||
return jedis.exists(key.getBytes()); |
|||
} |
|||
|
|||
/** |
|||
* 删除key |
|||
* |
|||
* @param key 键信息 |
|||
*/ |
|||
public static void delKey(String key) { |
|||
Jedis jedis = new Jedis("localhost"); |
|||
jedis.del(key.getBytes()); |
|||
} |
|||
|
|||
static class ObjectTranscoder { |
|||
|
|||
/** |
|||
* 序列化参数 |
|||
* |
|||
* @param value object |
|||
* @return byte |
|||
*/ |
|||
static byte[] serialize(Object value) { |
|||
if (value == null) { |
|||
throw new NullPointerException("参数不能为空"); |
|||
} |
|||
byte[] rv; |
|||
ByteArrayOutputStream bos = null; |
|||
ObjectOutputStream os = null; |
|||
try { |
|||
bos = new ByteArrayOutputStream(); |
|||
os = new ObjectOutputStream(bos); |
|||
os.writeObject(value); |
|||
os.close(); |
|||
bos.close(); |
|||
rv = bos.toByteArray(); |
|||
} catch (IOException e) { |
|||
throw new IllegalArgumentException("该对象不可序列化", e); |
|||
} finally { |
|||
try { |
|||
if (os != null) |
|||
os.close(); |
|||
if (bos != null) |
|||
bos.close(); |
|||
} catch (Exception e2) { |
|||
e2.printStackTrace(); |
|||
} |
|||
} |
|||
return rv; |
|||
} |
|||
|
|||
/** |
|||
* 反序列化参数 |
|||
* |
|||
* @param in byte |
|||
* @return object |
|||
*/ |
|||
static Object deserialize(byte[] in) { |
|||
|
|||
Object rv = null; |
|||
ByteArrayInputStream bis = null; |
|||
ObjectInputStream is = null; |
|||
try { |
|||
if (in != null) { |
|||
bis = new ByteArrayInputStream(in); |
|||
is = new ObjectInputStream(bis); |
|||
rv = is.readObject(); |
|||
is.close(); |
|||
bis.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
try { |
|||
if (is != null) |
|||
is.close(); |
|||
if (bis != null) |
|||
bis.close(); |
|||
} catch (Exception e2) { |
|||
e2.printStackTrace(); |
|||
} |
|||
} |
|||
return rv; |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,63 @@ |
|||
package com.stone.conf.session; |
|||
|
|||
import com.stone.conf.redis.RedisHelper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.shiro.session.Session; |
|||
import org.apache.shiro.session.SessionListener; |
|||
|
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
|
|||
/** |
|||
* shiro session监听 |
|||
* |
|||
* @author zhoujl |
|||
* @date 2019-09-17 |
|||
*/ |
|||
@Slf4j |
|||
public class ShiroSessionListener implements SessionListener { |
|||
|
|||
/** |
|||
* 统计在线人数 |
|||
*/ |
|||
private final AtomicInteger sessionCount = new AtomicInteger(0); |
|||
|
|||
/** |
|||
* 会话创建时触发 |
|||
*/ |
|||
@Override |
|||
public void onStart(Session session) { |
|||
log.info("会话创建:" + session.getId()); |
|||