diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c6fdded --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.stone.Application + diff --git a/README.md b/README.md index 7f18d9d..6696344 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..747b737 --- /dev/null +++ b/pom.xml @@ -0,0 +1,224 @@ + + + + + + 4.0.0 + + com.stone + + DYBGManager + war + + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.0.RELEASE + + + + + 1.8 + 1.2.4 + 2.0.4 + 1.2.9 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + mysql + mysql-connector-java + 8.0.13 + + + + + + + + + + org.apache.shiro + shiro-spring + 1.4.2 + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.2 + + + tk.mybatis + mapper-spring-boot-starter + ${mapper.starter.version} + + + + com.github.pagehelper + pagehelper-spring-boot-starter + ${pagehelper.starter.version} + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + + cn.hutool + hutool-all + 4.1.19 + + + + com.alibaba + fastjson + 1.2.51 + + + + org.crazycake + shiro-redis + 3.2.3 + + + + org.projectlombok + lombok + 1.18.4 + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.swagger + swagger-annotations + + + io.swagger + swagger-models + + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + io.swagger + swagger-annotations + 1.5.21 + + + io.swagger + swagger-models + 1.5.21 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.8.RELEASE + + + + + + + + ${project.artifactId} + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + + \ No newline at end of file diff --git a/src/main/java/com/stone/Application.java b/src/main/java/com/stone/Application.java new file mode 100644 index 0000000..bdc41d6 --- /dev/null +++ b/src/main/java/com/stone/Application.java @@ -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("服务启动完成!"); + } + +} diff --git a/src/main/java/com/stone/api/enums/BusinessExceptionEnum.java b/src/main/java/com/stone/api/enums/BusinessExceptionEnum.java new file mode 100644 index 0000000..ac5f851 --- /dev/null +++ b/src/main/java/com/stone/api/enums/BusinessExceptionEnum.java @@ -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 eClass; + + private HttpStatus httpStatus; + + private ResultCode resultCode; + + BusinessExceptionEnum(Class eClass, HttpStatus httpStatus, ResultCode resultCode) { + this.eClass = eClass; + this.httpStatus = httpStatus; + this.resultCode = resultCode; + } + + public Class 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 eClass) { + if (eClass == null) { + return null; + } + + for (BusinessExceptionEnum exceptionEnum : BusinessExceptionEnum.values()) { + if (eClass.equals(exceptionEnum.eClass)) { + return exceptionEnum; + } + } + + return null; + } + +} diff --git a/src/main/java/com/stone/api/enums/ResultCode.java b/src/main/java/com/stone/api/enums/ResultCode.java new file mode 100644 index 0000000..df41e02 --- /dev/null +++ b/src/main/java/com/stone/api/enums/ResultCode.java @@ -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(); + } + +} diff --git a/src/main/java/com/stone/base/BaseController.java b/src/main/java/com/stone/base/BaseController.java new file mode 100644 index 0000000..2ab7a2f --- /dev/null +++ b/src/main/java/com/stone/base/BaseController.java @@ -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 { + + /** + * 获取service + * @return + */ + @Autowired + public abstract BaseService getService(); + +} diff --git a/src/main/java/com/stone/base/BaseEntity.java b/src/main/java/com/stone/base/BaseEntity.java new file mode 100644 index 0000000..3297d86 --- /dev/null +++ b/src/main/java/com/stone/base/BaseEntity.java @@ -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; + +} diff --git a/src/main/java/com/stone/base/BaseMapper.java b/src/main/java/com/stone/base/BaseMapper.java new file mode 100644 index 0000000..acfdc82 --- /dev/null +++ b/src/main/java/com/stone/base/BaseMapper.java @@ -0,0 +1,8 @@ +package com.stone.base; + +import tk.mybatis.mapper.common.Mapper; +import tk.mybatis.mapper.common.MySqlMapper; + +public interface BaseMapper extends Mapper, MySqlMapper { + // FIXME 特别注意,该接口不能被扫描到,否则会出错 +} diff --git a/src/main/java/com/stone/base/BaseService.java b/src/main/java/com/stone/base/BaseService.java new file mode 100644 index 0000000..9567b07 --- /dev/null +++ b/src/main/java/com/stone/base/BaseService.java @@ -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 { + + BaseMapper getRepository(); + + default Session getSession() { + Subject sub = SecurityUtils.getSubject(); + return sub.getSession(); + } + +} diff --git a/src/main/java/com/stone/conf/WebMvcConfig.java b/src/main/java/com/stone/conf/WebMvcConfig.java new file mode 100644 index 0000000..724451a --- /dev/null +++ b/src/main/java/com/stone/conf/WebMvcConfig.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/datasource/intermediate/DruidIntermediate.java b/src/main/java/com/stone/conf/datasource/intermediate/DruidIntermediate.java new file mode 100644 index 0000000..bd66755 --- /dev/null +++ b/src/main/java/com/stone/conf/datasource/intermediate/DruidIntermediate.java @@ -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(); + } + +} diff --git a/src/main/java/com/stone/conf/datasource/senior/DruidSenior.java b/src/main/java/com/stone/conf/datasource/senior/DruidSenior.java new file mode 100644 index 0000000..4ca96ae --- /dev/null +++ b/src/main/java/com/stone/conf/datasource/senior/DruidSenior.java @@ -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(); + } + +} diff --git a/src/main/java/com/stone/conf/enums/Constants.java b/src/main/java/com/stone/conf/enums/Constants.java new file mode 100644 index 0000000..44b3ad7 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/Constants.java @@ -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"; + +} diff --git a/src/main/java/com/stone/conf/enums/EquipmentCodeEnum.java b/src/main/java/com/stone/conf/enums/EquipmentCodeEnum.java new file mode 100644 index 0000000..06d0221 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/EquipmentCodeEnum.java @@ -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; + +} diff --git a/src/main/java/com/stone/conf/enums/ErrorEnum.java b/src/main/java/com/stone/conf/enums/ErrorEnum.java new file mode 100644 index 0000000..c95c7fb --- /dev/null +++ b/src/main/java/com/stone/conf/enums/ErrorEnum.java @@ -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; + } + +} diff --git a/src/main/java/com/stone/conf/enums/FilePathConstants.java b/src/main/java/com/stone/conf/enums/FilePathConstants.java new file mode 100644 index 0000000..afe02af --- /dev/null +++ b/src/main/java/com/stone/conf/enums/FilePathConstants.java @@ -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/"; + +} \ No newline at end of file diff --git a/src/main/java/com/stone/conf/enums/LinkConstants.java b/src/main/java/com/stone/conf/enums/LinkConstants.java new file mode 100644 index 0000000..465aea4 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/LinkConstants.java @@ -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"; + +} diff --git a/src/main/java/com/stone/conf/enums/MagicValueConstants.java b/src/main/java/com/stone/conf/enums/MagicValueConstants.java new file mode 100644 index 0000000..7281223 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/MagicValueConstants.java @@ -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"; + +} diff --git a/src/main/java/com/stone/conf/enums/StateConstants.java b/src/main/java/com/stone/conf/enums/StateConstants.java new file mode 100644 index 0000000..0a944d4 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/StateConstants.java @@ -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"; + +} \ No newline at end of file diff --git a/src/main/java/com/stone/conf/enums/VersionConstants.java b/src/main/java/com/stone/conf/enums/VersionConstants.java new file mode 100644 index 0000000..9951e30 --- /dev/null +++ b/src/main/java/com/stone/conf/enums/VersionConstants.java @@ -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"; + +} diff --git a/src/main/java/com/stone/conf/exception/BusinessException.java b/src/main/java/com/stone/conf/exception/BusinessException.java new file mode 100644 index 0000000..da3950e --- /dev/null +++ b/src/main/java/com/stone/conf/exception/BusinessException.java @@ -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(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/stone/conf/exception/CommonJsonException.java b/src/main/java/com/stone/conf/exception/CommonJsonException.java new file mode 100644 index 0000000..1537fdd --- /dev/null +++ b/src/main/java/com/stone/conf/exception/CommonJsonException.java @@ -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; + } + +} diff --git a/src/main/java/com/stone/conf/exception/DataConflictException.java b/src/main/java/com/stone/conf/exception/DataConflictException.java new file mode 100644 index 0000000..371a431 --- /dev/null +++ b/src/main/java/com/stone/conf/exception/DataConflictException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/DataNotFoundException.java b/src/main/java/com/stone/conf/exception/DataNotFoundException.java new file mode 100644 index 0000000..221e5ba --- /dev/null +++ b/src/main/java/com/stone/conf/exception/DataNotFoundException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/InternalServerException.java b/src/main/java/com/stone/conf/exception/InternalServerException.java new file mode 100644 index 0000000..e49bb9a --- /dev/null +++ b/src/main/java/com/stone/conf/exception/InternalServerException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/MethodNotAllowException.java b/src/main/java/com/stone/conf/exception/MethodNotAllowException.java new file mode 100644 index 0000000..0260c6d --- /dev/null +++ b/src/main/java/com/stone/conf/exception/MethodNotAllowException.java @@ -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); + } + + +} diff --git a/src/main/java/com/stone/conf/exception/ParameterInvalidException.java b/src/main/java/com/stone/conf/exception/ParameterInvalidException.java new file mode 100644 index 0000000..96d6fe5 --- /dev/null +++ b/src/main/java/com/stone/conf/exception/ParameterInvalidException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/PermissionForbiddenException.java b/src/main/java/com/stone/conf/exception/PermissionForbiddenException.java new file mode 100644 index 0000000..3aa4626 --- /dev/null +++ b/src/main/java/com/stone/conf/exception/PermissionForbiddenException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/RemoteAccessException.java b/src/main/java/com/stone/conf/exception/RemoteAccessException.java new file mode 100644 index 0000000..3761720 --- /dev/null +++ b/src/main/java/com/stone/conf/exception/RemoteAccessException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/exception/UserNotLoginException.java b/src/main/java/com/stone/conf/exception/UserNotLoginException.java new file mode 100644 index 0000000..0472d01 --- /dev/null +++ b/src/main/java/com/stone/conf/exception/UserNotLoginException.java @@ -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); + } + +} diff --git a/src/main/java/com/stone/conf/filter/AjaxPermissionsAuthorizationFilter.java b/src/main/java/com/stone/conf/filter/AjaxPermissionsAuthorizationFilter.java new file mode 100644 index 0000000..a499a1a --- /dev/null +++ b/src/main/java/com/stone/conf/filter/AjaxPermissionsAuthorizationFilter.java @@ -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 registration(AjaxPermissionsAuthorizationFilter filter) { + FilterRegistrationBean registration = new FilterRegistrationBean<>(filter); + registration.setEnabled(false); + return registration; + } + +} diff --git a/src/main/java/com/stone/conf/redis/RedisConfig.java b/src/main/java/com/stone/conf/redis/RedisConfig.java new file mode 100644 index 0000000..ebe7bab --- /dev/null +++ b/src/main/java/com/stone/conf/redis/RedisConfig.java @@ -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); + } +} diff --git a/src/main/java/com/stone/conf/redis/RedisHelper.java b/src/main/java/com/stone/conf/redis/RedisHelper.java new file mode 100644 index 0000000..d64e0c6 --- /dev/null +++ b/src/main/java/com/stone/conf/redis/RedisHelper.java @@ -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; + } + } + +} diff --git a/src/main/java/com/stone/conf/session/ShiroSessionListener.java b/src/main/java/com/stone/conf/session/ShiroSessionListener.java new file mode 100644 index 0000000..31d06d0 --- /dev/null +++ b/src/main/java/com/stone/conf/session/ShiroSessionListener.java @@ -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()); + // 会话创建,在线人数加一 + sessionCount.incrementAndGet(); + } + + /** + * 退出会话时触发 + */ + @Override + public void onStop(Session session) { + log.info("会话退出:" + session.getId()); + // 会话退出,在线人数减一 + sessionCount.decrementAndGet(); + } + + /** + * 会话过期时触发 + */ + @Override + public void onExpiration(Session session) { + log.info("会话过期:" + session.getId()); + // 会话过期,在线人数减一 + sessionCount.decrementAndGet(); + RedisHelper.delKey(session.getId() + ""); + } + + /** + * 获取在线人数使用 + * @return 在线人数 + */ + public AtomicInteger getSessionCount() { + return sessionCount; + } + +} \ No newline at end of file diff --git a/src/main/java/com/stone/conf/shiro/MyShiroRealm.java b/src/main/java/com/stone/conf/shiro/MyShiroRealm.java new file mode 100644 index 0000000..b7c6203 --- /dev/null +++ b/src/main/java/com/stone/conf/shiro/MyShiroRealm.java @@ -0,0 +1,61 @@ +package com.stone.conf.shiro; + +import com.stone.conf.redis.RedisHelper; +import com.stone.mapper.senior.BjdSeniorMapper; +import com.stone.model.po.bjd.BjdSenior; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.AuthenticationInfo; +import org.apache.shiro.authc.AuthenticationToken; +import org.apache.shiro.authc.SimpleAuthenticationInfo; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.subject.Subject; +import tk.mybatis.mapper.weekend.Weekend; +import tk.mybatis.mapper.weekend.WeekendSqls; + +import javax.annotation.Resource; + +public class MyShiroRealm extends AuthorizingRealm { + + @Resource + private BjdSeniorMapper bjdSeniorMapper; + + /** + * 获取授权信息 + */ + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { + return null; + } + + /** + * 获取身份验证信息 + * Shiro中,最终是通过 Realm 来获取应用程序中的用户、角色及权限信息的。 + * + * @param token 用户身份信息 token + * @return 返回封装了用户信息的 AuthenticationInfo 实例 + */ + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { + // 获取用户的输入的账号. + String loginName = (String) token.getPrincipal(); + // 通过username从数据库中查找 User对象,如果找到,没找到. + // 实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法 + BjdSenior user = bjdSeniorMapper.selectOneByExample(Weekend.builder(BjdSenior.class).where(WeekendSqls.custom() + .andEqualTo(BjdSenior::getSerialNumber, loginName)).build()); + if (user == null) { + return null; + } + Subject subject = SecurityUtils.getSubject(); + // 将用户信息存入redis中 + RedisHelper.add(subject.getSession().getId() + "", user); + return new SimpleAuthenticationInfo( + user.getSerialNumber(), //用户名 + user.getWwcxmima(), //密码 + getName() //realm name + ); + } + +} diff --git a/src/main/java/com/stone/conf/shiro/ShiroConfig.java b/src/main/java/com/stone/conf/shiro/ShiroConfig.java new file mode 100644 index 0000000..54e1a8f --- /dev/null +++ b/src/main/java/com/stone/conf/shiro/ShiroConfig.java @@ -0,0 +1,189 @@ +package com.stone.conf.shiro; + +import com.stone.conf.filter.AjaxPermissionsAuthorizationFilter; +import com.stone.conf.session.ShiroSessionListener; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authc.credential.HashedCredentialsMatcher; +import org.apache.shiro.codec.Base64; +import org.apache.shiro.mgt.RememberMeManager; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.session.SessionListener; +import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; +import org.apache.shiro.spring.web.ShiroFilterFactoryBean; +import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; +import org.apache.shiro.web.mgt.CookieRememberMeManager; +import org.apache.shiro.web.mgt.DefaultWebSecurityManager; +import org.apache.shiro.web.servlet.SimpleCookie; +import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; +import org.crazycake.shiro.RedisCacheManager; +import org.crazycake.shiro.RedisManager; +import org.crazycake.shiro.RedisSessionDAO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.Filter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * shiro 配置核心类 + * + * @author zhoujl + * @since 2018-07-05 + */ +@Slf4j +@Configuration +public class ShiroConfig { + + @Value("${spring.redis.host}") + private String host; + @Value("${spring.redis.port}") + private int port; + @Value("${spring.redis.timeout}") + private int timeout; + + /** + * cacheManager 缓存 redis实现 + * 使用的是shiro-redis开源插件 + */ + private RedisCacheManager cacheManager() { + RedisCacheManager redisCacheManager = new RedisCacheManager(); + redisCacheManager.setRedisManager(redisManager()); + final String CACHE_KEY = "shiro:cache:"; + redisCacheManager.setKeyPrefix(CACHE_KEY); + // 配置缓存的话要求放在session里面的实体类必须有个id标识 + redisCacheManager.setPrincipalIdFieldName("id"); + return redisCacheManager; + } + + /** + * 配置shiro redisManager + * 使用的是shiro-redis开源插件 + */ + private RedisManager redisManager() { + RedisManager redisManager = new RedisManager(); + redisManager.setHost(host + ":" + port); + redisManager.setTimeout(timeout); + return redisManager; + } + + /** + * RedisSessionDAO shiro sessionDao层的实现 通过redis + * 使用的是shiro-redis开源插件 + */ + @Bean + public RedisSessionDAO redisSessionDAO() { + RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); + redisSessionDAO.setRedisManager(redisManager()); + redisSessionDAO.setSessionIdGenerator(sessionIdGenerator()); + String SESSION_KEY = "shiro:session:"; + redisSessionDAO.setKeyPrefix(SESSION_KEY); + int EXPIRE = 1800; + redisSessionDAO.setExpire(EXPIRE); + return redisSessionDAO; + } + + /** + * SessionID生成器 + */ + @Bean + public ShiroSessionIdGenerator sessionIdGenerator(){ + return new ShiroSessionIdGenerator(); + } + + /** + * 配置保存sessionId的cookie + */ + @Bean("sessionIdCookie") + public SimpleCookie sessionIdCookie(){ + //这个参数是cookie的名称 + SimpleCookie simpleCookie = new SimpleCookie("sid"); + //setcookie的httponly属性如果设为true的话,会增加对xss防护的安全系数 + simpleCookie.setHttpOnly(true); + simpleCookie.setPath("/"); + //maxAge=-1表示浏览器关闭时失效此Cookie + simpleCookie.setMaxAge(-1); + return simpleCookie; + } + + /** + * 配置session监听 + */ + @Bean("sessionListener") + public ShiroSessionListener sessionListener(){ + return new ShiroSessionListener(); + } + + /** + * Session Manager + * 使用的是shiro-redis开源插件 + */ + @Bean + public DefaultWebSessionManager sessionManager() { + DefaultWebSessionManager webSessionManager = new DefaultWebSessionManager(); + Collection listeners = new ArrayList<>(); + // 配置监听 + listeners.add(sessionListener()); + webSessionManager.setSessionListeners(listeners); + webSessionManager.setSessionIdCookie(sessionIdCookie()); + webSessionManager.setSessionDAO(redisSessionDAO()); + // 全局会话超时时间(单位毫秒) + webSessionManager.setGlobalSessionTimeout(30 * 60 * 1000); + // 是否开启删除无效的session对象 默认为true + webSessionManager.setDeleteInvalidSessions(true); + // 是否开启定时调度器进行检测过期session 默认为true + webSessionManager.setSessionValidationSchedulerEnabled(true); + // 设置session失效的扫描时间, 清理用户直接关闭浏览器造成的孤立会话 默认为 1个小时 + webSessionManager.setSessionValidationInterval(60 * 1000); + // 取消url 后面的 JSESSIONID + webSessionManager.setSessionIdUrlRewritingEnabled(false); + return webSessionManager; + } + + @Bean("shiroFilter") + public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { + ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); + shiroFilterFactoryBean.setSecurityManager(securityManager); + // 拦截器. + Map filterChainDefinitionMap = new LinkedHashMap<>(); + // 配置不会被拦截的链接 顺序判断 + // :这是一个坑呢,一不小心代码就不好使了; + // 配置swagger访问路径 加载顺序不可改变 + // + filterChainDefinitionMap.put("/user/login", "anon"); + filterChainDefinitionMap.put("/**", "user"); + // 自定义拦截器 + Map filtersMap = new LinkedHashMap<>(); + filtersMap.put("user", new AjaxPermissionsAuthorizationFilter()); + shiroFilterFactoryBean.setFilters(filtersMap); + shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); + return shiroFilterFactoryBean; + } + + /** + * 注入 securityManager + */ + @Bean(name = "securityManager") + public SecurityManager securityManager() { + DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); + // 设置realm. + securityManager.setRealm(myShiroRealm()); + // 自定义缓存实现 使用redis + securityManager.setCacheManager(cacheManager()); + // 自定义session管理 使用redis + securityManager.setSessionManager(sessionManager()); + return securityManager; + } + + /** + * 身份验证器 + */ + @Bean + public MyShiroRealm myShiroRealm() { + return new MyShiroRealm(); + } + +} diff --git a/src/main/java/com/stone/conf/shiro/ShiroSessionIdGenerator.java b/src/main/java/com/stone/conf/shiro/ShiroSessionIdGenerator.java new file mode 100644 index 0000000..160f970 --- /dev/null +++ b/src/main/java/com/stone/conf/shiro/ShiroSessionIdGenerator.java @@ -0,0 +1,33 @@ +package com.stone.conf.shiro; + +import org.apache.shiro.session.Session; +import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator; +import org.apache.shiro.session.mgt.eis.SessionIdGenerator; +import org.springframework.beans.factory.annotation.Value; + +import java.io.Serializable; + +/** + * 自定义SessionId生成器 + * + * @author zhoujl + * @date 2019-09-16 + */ +public class ShiroSessionIdGenerator implements SessionIdGenerator { + + @Value("${projectName}") + private String projectName; + + /** + * 实现sessionId生成 + * + * @param session session对象 + * @return id + */ + @Override + public Serializable generateId(Session session) { + Serializable sessionId = new JavaUuidSessionIdGenerator().generateId(session); + return String.format(projectName + "_login_token_%s", sessionId); + } + +} diff --git a/src/main/java/com/stone/controller/CategoryController.java b/src/main/java/com/stone/controller/CategoryController.java new file mode 100644 index 0000000..5102ba7 --- /dev/null +++ b/src/main/java/com/stone/controller/CategoryController.java @@ -0,0 +1,38 @@ +package com.stone.controller; + +import com.stone.model.vo.PageVO; +import com.stone.service.CategoryService; +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 zhoujl + * @date 2019-03-25 + */ +@RestController +@RequestMapping("/category") +@Api(tags = "检验类别接口") +public class CategoryController { + + @Resource + private CategoryService categoryService; + + /** + * 查询检验类别列表 + * + * @return 检验类别分页信息 + */ + @GetMapping("/pull") + @ApiOperation(value = "查询检验类别列表", response = PageVO.class, notes = "根据条件查询检验类别列表并进行分页", httpMethod = "GET") + public PageVO pull() { + return categoryService.pull(); + } + +} diff --git a/src/main/java/com/stone/controller/DownloadController.java b/src/main/java/com/stone/controller/DownloadController.java new file mode 100644 index 0000000..4ff56ec --- /dev/null +++ b/src/main/java/com/stone/controller/DownloadController.java @@ -0,0 +1,46 @@ +package com.stone.controller; + +import com.stone.base.BaseController; +import com.stone.base.BaseService; +import com.stone.model.vo.PageVO; +import com.stone.service.DownloadService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author zichen + */ +@RequestMapping("/download") +@RestController +public class DownloadController extends BaseController { + + @Resource + private DownloadService downloadService; + + /** + * 获取service + * + * @return + */ + @Override + public BaseService getService() { + return downloadService; + } + + @GetMapping("/pullSeniorPath") + @ResponseBody + public PageVO pullSeniorPath(String id, String type) { + return downloadService.pullSeniorPath(id, type); + } + + @GetMapping("/pullIntermediatePath") + @ResponseBody + public PageVO pullIntermediatePath(String id, String type) { + return downloadService.pullIntermediatePath(id, type); + } + +} diff --git a/src/main/java/com/stone/controller/SearchController.java b/src/main/java/com/stone/controller/SearchController.java new file mode 100644 index 0000000..5e5a89b --- /dev/null +++ b/src/main/java/com/stone/controller/SearchController.java @@ -0,0 +1,49 @@ +package com.stone.controller; + +import com.stone.base.BaseController; +import com.stone.base.BaseService; +import com.stone.model.vo.PageVO; +import com.stone.service.SearchService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * @author zichen + */ +@RequestMapping("/search") +@RestController +public class SearchController extends BaseController { + + @Resource + private SearchService searchService; + + /** + * 获取service + * + * @return + */ + @Override + public BaseService getService() { + return searchService; + } + + @GetMapping("/intermediate") + @ResponseBody + public PageVO pullIntermediate(String id) { + return searchService.pullIntermediate(id); + } + + @GetMapping("/senior") + @ResponseBody + public PageVO pullSenior(@RequestParam(name = "id") String id) { + return searchService.pullSenior(id); + } + + @GetMapping("/progress") + @ResponseBody + public PageVO pullProgress(@RequestParam(name = "id") String id, @RequestParam(name = "bianhao") String bianhao) { + return searchService.pullProgress(id, bianhao); + } + +} diff --git a/src/main/java/com/stone/controller/UserController.java b/src/main/java/com/stone/controller/UserController.java new file mode 100644 index 0000000..9d73485 --- /dev/null +++ b/src/main/java/com/stone/controller/UserController.java @@ -0,0 +1,41 @@ +package com.stone.controller; + +import com.stone.base.BaseController; +import com.stone.base.BaseService; +import com.stone.model.dto.UserDTO; +import com.stone.model.po.bjd.BjdSenior; +import com.stone.model.vo.PageVO; +import com.stone.service.UserService; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * @author zichen + */ +@Api(value = "企业用户") +@RequestMapping("/user") +@RestController +public class UserController extends BaseController { + + @Resource + private UserService userService; + + /** + * 获取service + * + * @return + */ + @Override + public BaseService getService() { + return userService; + } + + @PostMapping("/login") + @ResponseBody + public PageVO login(@RequestBody UserDTO userDTO) { + return userService.login(userDTO); + } + +} diff --git a/src/main/java/com/stone/mapper/intermediate/BjdIntermediateMapper.java b/src/main/java/com/stone/mapper/intermediate/BjdIntermediateMapper.java new file mode 100644 index 0000000..56ea9d8 --- /dev/null +++ b/src/main/java/com/stone/mapper/intermediate/BjdIntermediateMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.intermediate; + +import com.stone.base.BaseMapper; +import com.stone.model.po.bjd.BjdIntermediate; +import com.stone.model.po.bjd.BjdSenior; + +/** + * @author zichen + */ +public interface BjdIntermediateMapper extends BaseMapper { +} diff --git a/src/main/java/com/stone/mapper/intermediate/HzdIntermediateMapper.java b/src/main/java/com/stone/mapper/intermediate/HzdIntermediateMapper.java new file mode 100644 index 0000000..c353911 --- /dev/null +++ b/src/main/java/com/stone/mapper/intermediate/HzdIntermediateMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.intermediate; + +import com.stone.base.BaseMapper; +import com.stone.model.po.bjd.BjdIntermediate; +import com.stone.model.po.bjd.HzdIntermediate; + +/** + * @author zichen + */ +public interface HzdIntermediateMapper extends BaseMapper { +} diff --git a/src/main/java/com/stone/mapper/intermediate/RenwuIntermediateMapper.java b/src/main/java/com/stone/mapper/intermediate/RenwuIntermediateMapper.java new file mode 100644 index 0000000..10e7021 --- /dev/null +++ b/src/main/java/com/stone/mapper/intermediate/RenwuIntermediateMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.intermediate; + +import com.stone.base.BaseMapper; +import com.stone.model.po.renwu.RenwuIntermediate; + +/** + * @author zichen + */ +public interface RenwuIntermediateMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/stone/mapper/intermediate/ReportIntermediateMapper.java b/src/main/java/com/stone/mapper/intermediate/ReportIntermediateMapper.java new file mode 100644 index 0000000..b197fcc --- /dev/null +++ b/src/main/java/com/stone/mapper/intermediate/ReportIntermediateMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.intermediate; + +import com.stone.base.BaseMapper; +import com.stone.model.po.report.Report; + +/** + * @author zichen + */ +public interface ReportIntermediateMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/stone/mapper/intermediate/YsjlIntermediateMapper.java b/src/main/java/com/stone/mapper/intermediate/YsjlIntermediateMapper.java new file mode 100644 index 0000000..5f03336 --- /dev/null +++ b/src/main/java/com/stone/mapper/intermediate/YsjlIntermediateMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.intermediate; + +import com.stone.base.BaseMapper; +import com.stone.model.po.ysjl.YsjlIntermediate; + +/** + * @author zichen + */ +public interface YsjlIntermediateMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/stone/mapper/senior/BjdSeniorMapper.java b/src/main/java/com/stone/mapper/senior/BjdSeniorMapper.java new file mode 100644 index 0000000..d65e8a2 --- /dev/null +++ b/src/main/java/com/stone/mapper/senior/BjdSeniorMapper.java @@ -0,0 +1,10 @@ +package com.stone.mapper.senior; + +import com.stone.base.BaseMapper; +import com.stone.model.po.bjd.BjdSenior; + +/** + * @author zichen + */ +public interface BjdSeniorMapper extends BaseMapper { +} diff --git a/src/main/java/com/stone/mapper/senior/CategoryMapper.java b/src/main/java/com/stone/mapper/senior/CategoryMapper.java new file mode 100644 index 0000000..97c2410 --- /dev/null +++ b/src/main/java/com/stone/mapper/senior/CategoryMapper.java @@ -0,0 +1,10 @@ +package com.stone.mapper.senior; + +import com.stone.base.BaseMapper; +import com.stone.model.po.dic.Category; + +/** + * @author zichen + */ +public interface CategoryMapper extends BaseMapper { +} \ No newline at end of file diff --git a/src/main/java/com/stone/mapper/senior/RenwuSeniorMapper.java b/src/main/java/com/stone/mapper/senior/RenwuSeniorMapper.java new file mode 100644 index 0000000..83ef4d8 --- /dev/null +++ b/src/main/java/com/stone/mapper/senior/RenwuSeniorMapper.java @@ -0,0 +1,11 @@ +package com.stone.mapper.senior; + +import com.stone.base.BaseMapper; +import com.stone.model.po.renwu.RenwuSenior; +import com.stone.model.po.ysjl.YsjlSenior; + +/** + * @author zichen + */ +public interface RenwuSeniorMapper extends BaseMapper { +} \ No newline at end of file diff --git a/src/main/java/com/stone/mapper/senior/TemplateMapper.java b/src/main/java/com/stone/mapper/senior/TemplateMapper.java new file mode 100644 index 0000000..4a0422d --- /dev/null +++ b/src/main/java/com/stone/mapper/senior/TemplateMapper.java @@ -0,0 +1,10 @@ +package com.stone.mapper.senior; + +import com.stone.base.BaseMapper; +import com.stone.model.po.template.Template; + +/** + * @author zichen + */ +public interface TemplateMapper extends BaseMapper