├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── github │ └── misterchangray │ ├── common │ ├── PageInfo.java │ ├── ResultSet.java │ ├── annotation │ │ ├── Authorization.java │ │ ├── OperationLog.java │ │ └── PrintRunTime.java │ ├── aop │ │ ├── OperationLogAop.java │ │ ├── PrintRunTimeAop.java │ │ └── UserLoginLogAop.java │ ├── config │ │ └── SwaggerConfig.java │ ├── enums │ │ ├── DBEnum.java │ │ └── ResultEnum.java │ ├── exception │ │ └── ServiceException.java │ ├── init │ │ └── Init.java │ ├── interceptor │ │ ├── AuthInterceptor.java │ │ └── GlobalExceptionHandler.java │ ├── quartz │ │ └── GlobalQuartz.java │ └── utils │ │ ├── AESUtils.java │ │ ├── CryptoUtils.java │ │ ├── DateUtils.java │ │ ├── EmailBuilder.java │ │ ├── EntityUtils.java │ │ ├── GZipUtils.java │ │ ├── HttpRequestParserUtils.java │ │ ├── HttpUtils.java │ │ ├── JSONUtils.java │ │ ├── ListBuilder.java │ │ ├── MapBuilder.java │ │ ├── RegExpValidatorUtils.java │ │ └── VerifyCodeUtils.java │ ├── controller │ ├── ConstantController.java │ ├── TestController.java │ ├── common │ │ └── VerifyCodeController.java │ └── user │ │ ├── LoginController.java │ │ ├── PermissionController.java │ │ ├── RoleController.java │ │ └── UserController.java │ ├── dao │ ├── entity │ │ ├── Constant.java │ │ ├── ConstantQuery.java │ │ ├── LoginLog.java │ │ ├── LoginLogQuery.java │ │ ├── OperationLog.java │ │ ├── OperationLogQuery.java │ │ ├── Permission.java │ │ ├── PermissionQuery.java │ │ ├── Role.java │ │ ├── RolePermissionMap.java │ │ ├── RolePermissionMapQuery.java │ │ ├── RoleQuery.java │ │ ├── User.java │ │ ├── UserQuery.java │ │ ├── UserRoleMap.java │ │ └── UserRoleMapQuery.java │ ├── mapper │ │ ├── ConstantMapper.java │ │ ├── LoginLogMapper.java │ │ ├── OperationLogMapper.java │ │ ├── PermissionMapper.java │ │ ├── RoleMapper.java │ │ ├── RolePermissionMapMapper.java │ │ ├── UserMapper.java │ │ └── UserRoleMapMapper.java │ └── xml │ │ ├── ConstantMapper.xml │ │ ├── LoginLogMapper.xml │ │ ├── OperationLogMapper.xml │ │ ├── PermissionMapper.xml │ │ ├── RoleMapper.xml │ │ ├── RolePermissionMapMapper.xml │ │ ├── UserMapper.xml │ │ └── UserRoleMapMapper.xml │ └── service │ ├── BaseService.java │ ├── common │ ├── ContextCacheService.java │ ├── RedisCacheService.java │ └── SensitiveWordService.java │ ├── log │ ├── LoginLogService.java │ ├── OperationLogService.java │ └── impl │ │ ├── LoginLogServiceImpl.java │ │ └── OperationLogServiceImpl.java │ └── user │ ├── LoginService.java │ ├── PermissionService.java │ ├── RoleService.java │ ├── UserService.java │ ├── bo │ └── UserSessionBo.java │ └── impl │ ├── LoginServiceImpl.java │ ├── PermissionServiceImpl.java │ ├── RoleServiceImpl.java │ └── UserServiceImpl.java ├── resources ├── applicationContext.xml ├── archives │ ├── common-core.pdb │ ├── common-core.pdm │ ├── common-core.sql │ └── table_data │ │ ├── constant.sql │ │ ├── permission.sql │ │ ├── readme.txt │ │ ├── role.sql │ │ └── user.sql ├── config.properties ├── generatorConfig.xml ├── jdbc.properties ├── log4j.properties ├── mybatis.xml ├── redis.properties ├── sensitiveWord.txt └── spring-mvc.xml └── webapp ├── WEB-INF ├── 404.html ├── error.html └── web.xml ├── common-core-swagger-ui ├── config.js ├── favicon.ico └── index.html ├── index.jsp └── swagger-ui ├── favicon-16x16.png ├── favicon-32x32.png ├── index.html ├── oauth2-redirect.html ├── swagger-ui-bundle.js ├── swagger-ui-bundle.js.map ├── swagger-ui-standalone-preset.js ├── swagger-ui-standalone-preset.js.map ├── swagger-ui.css ├── swagger-ui.css.map ├── swagger-ui.js └── swagger-ui.js.map /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | # See http://help.github.com/ignore-files/ for more about ignoring files. 25 | 26 | # compiled output 27 | /dist 28 | /tmp 29 | /out-tsc 30 | /target 31 | 32 | # dependencies 33 | /node_modules 34 | 35 | # IDEs and editors 36 | /.idea 37 | .project 38 | .classpath 39 | .c9/ 40 | *.launch 41 | .settings/ 42 | *.sublime-workspace 43 | 44 | # IDE - VSCode 45 | /.vscode 46 | /.vs 47 | .vscode/* 48 | !.vscode/settings.json 49 | !.vscode/tasks.json 50 | !.vscode/launch.json 51 | !.vscode/extensions.json 52 | 53 | # misc 54 | /.sass-cache 55 | /connect.lock 56 | /coverage 57 | /libpeerconnection.log 58 | npm-debug.log 59 | testem.log 60 | /typings 61 | 62 | # e2e 63 | /e2e/*.js 64 | /e2e/*.map 65 | 66 | # System Files 67 | .DS_Store 68 | Thumbs.db 69 | 70 | # Other Files 71 | *.iml 72 | *.zip 73 | *.rar 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 mr.zhang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 欢迎使用 Common-Mvc 2 | 基于maven的spring4.3+mybatis3.4+Swagger2.6的后台整合,用于快速构建中小型API、RESTful API项目,该项目简单、快速、易扩展;使我们摆脱那些重复劳动,专注于业务代码的编写。 3 | 4 | 5 | ### 已完成功能 6 | - 增加权限统一拦截注解`@Authentication` 7 | - 增加方法性能统计注解`@printRunTime` 8 | - 增加简单的操作日志`@OperationLog` 9 | - 实现了用户登录日志 10 | - 实现了简单的权限系统 11 | - 生成entity类时自动提取数据库注释生成swagger文档 12 | - 实现了更漂亮的swagger-ui 13 | - 实现了邮件发送/验证码生成/正则验证 14 | 15 | ### 快速开始 16 | - clone本项目,创建下面的数据库和表 17 | - 使用IDE导入本项目,使用maven方式导入项目 18 | - 配置`jdbc.properties`下面的数据库相关信息(如果你需要使用mybitis逆向插件,也需要配置`generatorConfig.xml`这个文件中的数据库信息) 19 | - 使用maven编译后,配置tomcat并部署 20 | - 启动tomcat,访问以下链接测试接口; 21 | - 访问`http://localhost:8080/docs/index.html` 查看swagger2生成的Api文档信息 22 | - 根据需求进行快速迭代开发 23 | 24 | ### 目前表单,详细信息在"/resources/archives"目录下 25 | ```sql 26 | drop database common_core; 27 | 28 | create database common_core; 29 | 30 | use common_core; 31 | 32 | create table user; 33 | 34 | create table role; 35 | 36 | create table permission; 37 | 38 | create table role_permission_map; 39 | 40 | create table user_role_map; 41 | 42 | create table constant; 43 | 44 | create table operation_log; 45 | 46 | ``` 47 | 48 | 49 | ### 开发者建议 50 | - 表名,建议使用小写,多个单词使用下划线拼接 51 | - entity内成员变量建议与表字段数量对应 52 | - 前端统一使用`Content-Type=application/json`传参;`controller`层统一使用`@RequestBody`入参,参数可以使用Map接收,也可考虑封装成VO对象(推荐) 53 | - 需要工具类的话建议先从`common/utils`中找,实在没有再造轮子或引入类库,尽量精简项目 54 | - 开发规范建议遵循阿里巴巴Java开发手册([最新版下载](https://github.com/lihengming/java-codes/blob/master/shared-resources/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8CV1.2.0.pdf)) 55 | - 建议在公司内部使用ShowDoc、Swagger2 、RAP等开源项目来编写、管理API文档 56 | - 页面常量信息建议放在`constants`表;如民族/地址/证件类型/性别等; 57 | - 所有项目文档放置在`/resources/archives`目录下 58 | - 建议所有DTO/BO放在相应service目录下;VO放在相应controller目录下 59 | - 修改已有表结构时,不建议修改以下字段(id,enabled,deleted);因为这些字段已在开发中用到 60 | - 增删改方法命名分别以`insert/delete/update`打头 61 | 62 | 63 | ### 相关环境(推荐使用环境) 64 | - OS Microsoft Windows 10 Pro 65 | - Editor IntelliJ IDEA 66 | - Java 8 67 | - SpringMVC 4.3 68 | - Mybitis 3.4 69 | - Mysql 5.5.50 70 | - Maven 3.5.3 71 | - Git 2.14.1 72 | - Tomcat 7.0.85 73 | - Swagger 2.6.1 74 | - Restful interface 75 | 76 | 77 | ### 注意事项 78 | - 使用mybaitis-generator插件生成dao层时请先删除原来的文件,不然生的的内容会追加到源文件中,出现代码重复 79 | - 下载后如打不开swagger2文档,可能需要修改`webapp/common-core-swagger-ui/config.js`文件中得地址 80 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/PageInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | /** 7 | * 页码信息类 8 | * 用于返回页码信息 9 | * 10 | * @author Rui.Zhang/misterchangray@hotmail.com 11 | * @author Created on 3/23/2018. 12 | */ 13 | @ApiModel(description = "页码信息封装对象-PageInfo") 14 | public class PageInfo { 15 | /** 16 | * 当前第几页 17 | */ 18 | @ApiModelProperty(value = "当前第几页", dataType = "Integer") 19 | private Integer page; 20 | /** 21 | * 总共有多少条记录 22 | */ 23 | @ApiModelProperty(value = "总共有多少条记录", dataType = "Integer") 24 | private Long count; 25 | /** 26 | * 每页多少数据 27 | */ 28 | @ApiModelProperty(value = "每页多少数据", dataType = "Integer") 29 | private Integer limit; 30 | 31 | 32 | public PageInfo(Integer page, Long count, Integer limit) { 33 | this.page = page; 34 | this.count = count; 35 | this.limit = limit; 36 | } 37 | 38 | public static PageInfo newInstance(Integer page, Integer limit) { 39 | return new PageInfo().setPage(page).setLimit(limit); 40 | } 41 | public static PageInfo newInstance() { 42 | return new PageInfo(); 43 | } 44 | 45 | public PageInfo() { 46 | // 默认每页10条,第一页开始 47 | this.page = 0; 48 | this.limit = 10; 49 | } 50 | public PageInfo(Integer page, Integer limit) { 51 | this.page = page; 52 | this.limit = limit; 53 | } 54 | 55 | public Integer getPage() { 56 | return page; 57 | } 58 | 59 | public PageInfo setPage(Integer page) { 60 | this.page = page; 61 | return this; 62 | } 63 | 64 | public Long getCount() { 65 | return count; 66 | } 67 | 68 | public PageInfo setCount(Long count) { 69 | this.count = count; 70 | return this; 71 | } 72 | 73 | public Integer getLimit() { 74 | return limit; 75 | } 76 | 77 | public PageInfo setLimit(Integer limit) { 78 | this.limit = limit; 79 | return this; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/ResultSet.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common; 2 | 3 | import com.github.misterchangray.common.enums.ResultEnum; 4 | import com.github.misterchangray.common.utils.JSONUtils; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | 8 | /** 9 | * 通用结果集 10 | * 用于ajax返回 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/20/2018. 14 | */ 15 | @ApiModel(description = "标准返回封装-ResultSet") 16 | public class ResultSet { 17 | /** 18 | * 返回消息 19 | */ 20 | @ApiModelProperty(value = "消息信息", dataType = "String") 21 | private String msg; 22 | /** 23 | * 结果代码,参见 ResultEnum 24 | */ 25 | @ApiModelProperty(value = "结果代码;0为成功;非0失败", dataType = "Integer") 26 | private Integer code; 27 | /** 28 | * 返回的数据,这里一般是函数的返回值 29 | */ 30 | @ApiModelProperty(value = "结果返回 JSON 格式", dataType = "JSON") 31 | private T data; 32 | /** 33 | * 页码信息 34 | */ 35 | @ApiModelProperty(value = "页码信息", dataType = "PageInfo") 36 | private PageInfo pageInfo; 37 | 38 | 39 | 40 | public PageInfo getPageInfo() { 41 | return pageInfo; 42 | } 43 | 44 | 45 | public ResultSet setPageInfo(PageInfo pageInfo) { 46 | this.pageInfo = pageInfo; 47 | return this; 48 | } 49 | 50 | public ResultSet setMsg(String msg) { 51 | this.msg = msg; 52 | return this; 53 | } 54 | 55 | public String getMsg() { 56 | return msg; 57 | } 58 | 59 | public ResultSet setCode(Integer code) { 60 | this.code = code; 61 | return this; 62 | } 63 | 64 | public ResultSet setCode(ResultEnum resultEnum) { 65 | this.code = resultEnum.getCode(); 66 | return this; 67 | } 68 | 69 | public Integer getCode() { 70 | return code; 71 | } 72 | 73 | public ResultSet setData(T data) { 74 | this.data = data; 75 | return this; 76 | } 77 | 78 | public T getData() { 79 | return data; 80 | } 81 | 82 | 83 | public static ResultSet build() { 84 | ResultSet resultSet = new ResultSet(); 85 | resultSet.setCode(ResultEnum.SUCCESS.getCode()); 86 | resultSet.setMsg(ResultEnum.SUCCESS.getMsg()); 87 | return resultSet; 88 | } 89 | 90 | public static ResultSet build(ResultEnum resultEnum) { 91 | ResultSet resultSet = new ResultSet(); 92 | if(null != resultEnum) { 93 | resultSet.setCode(resultEnum.getCode()); 94 | resultSet.setMsg(resultEnum.getMsg()); 95 | } else { 96 | resultSet.setCode(ResultEnum.SERVER_ERROR.getCode()); 97 | resultSet.setMsg(ResultEnum.SERVER_ERROR.getMsg()); 98 | } 99 | return resultSet; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return JSONUtils.obj2json(this); 105 | } 106 | 107 | private ResultSet() {} 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/annotation/Authorization.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.*; 6 | 7 | 8 | /** 9 | * 自定义注解 10 | * 在需要进行权限认证的方法或类上使用此注解 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 2018/4/23. 14 | */ 15 | @Target({ElementType.TYPE, ElementType.METHOD}) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Documented 18 | @Inherited 19 | @Component 20 | public @interface Authorization { 21 | String value() default ""; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/annotation/OperationLog.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * 自定义注解 9 | * 为此注解得service方法增加操作日志 10 | * 注意此注解只用于service方法中,简易在service实现类中增删改方法添加此注解 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 4/26/2018. 14 | */ 15 | @Target(ElementType.METHOD) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Documented 18 | @Inherited 19 | @Component 20 | public @interface OperationLog { 21 | String businessName(); 22 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/annotation/PrintRunTime.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.*; 6 | 7 | 8 | /** 9 | * 自定义注解 10 | * 在需要打印方法执行时间得函数上使用此注解 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/22/2018. 14 | */ 15 | @Target(ElementType.METHOD) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Documented 18 | @Inherited 19 | @Component 20 | public @interface PrintRunTime { 21 | String value() default ""; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/aop/OperationLogAop.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.aop; 2 | 3 | import com.github.misterchangray.common.annotation.OperationLog; 4 | import com.github.misterchangray.common.utils.JSONUtils; 5 | import com.github.misterchangray.dao.entity.User; 6 | import com.github.misterchangray.service.log.OperationLogService; 7 | import org.aspectj.lang.ProceedingJoinPoint; 8 | import org.aspectj.lang.annotation.Around; 9 | import org.aspectj.lang.annotation.Aspect; 10 | import org.aspectj.lang.annotation.Pointcut; 11 | import org.aspectj.lang.reflect.MethodSignature; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.web.context.request.RequestContextHolder; 15 | import org.springframework.web.context.request.ServletRequestAttributes; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import java.lang.reflect.Method; 19 | 20 | 21 | /** 22 | * 自定义注解 23 | * AOP统一处理操作日志 24 | * 这里统一拦截处理@OperationLog注解的方法 25 | * 26 | * @author Rui.Zhang/misterchangray@hotmail.com 27 | * @author Created on 2018/4/23. 28 | */ 29 | @Component 30 | @Aspect 31 | public class OperationLogAop { 32 | @Autowired 33 | OperationLogService operationLogService; 34 | 35 | @Pointcut(value = "@annotation(com.github.misterchangray.common.annotation.OperationLog)") 36 | private void OperationLog() {} 37 | 38 | 39 | @Around(value = "OperationLog()") 40 | public Object around(ProceedingJoinPoint point) throws Throwable { 41 | Object res; 42 | res = point.proceed(); 43 | 44 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 45 | User user = (User) request.getSession().getAttribute("user"); 46 | 47 | Method targetMethod = ((MethodSignature)(point.getSignature())).getMethod(); 48 | OperationLog annotation = targetMethod.getAnnotation(OperationLog.class); 49 | String signature, businessName, userName, data; 50 | Integer userId = user.getId(); 51 | signature = targetMethod.toString(); 52 | businessName = annotation.businessName(); 53 | userName = user.getUsername(); 54 | data = JSONUtils.obj2json(point.getArgs()); 55 | 56 | this.operationLogService.insertLog(signature, businessName, userId, userName, data); 57 | return res; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/aop/PrintRunTimeAop.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.aop; 2 | 3 | import com.github.misterchangray.common.utils.DateUtils; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Pointcut; 8 | import org.aspectj.lang.reflect.MethodSignature; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.lang.reflect.Method; 12 | import java.util.Date; 13 | 14 | /** 15 | * 自定义注解 16 | * 统计并打印函数执行时间 17 | * 18 | * @author Rui.Zhang/misterchangray@hotmail.com 19 | * @author Created on 3/22/2018. 20 | */ 21 | @Component 22 | @Aspect 23 | public class PrintRunTimeAop { 24 | 25 | @Pointcut(value = "@annotation(com.github.misterchangray.common.annotation.PrintRunTime)") 26 | private void pointcut() {} 27 | 28 | @Around(value = "pointcut() && @annotation(com.github.misterchangray.common.annotation.PrintRunTime)") 29 | public Object around(ProceedingJoinPoint point) throws Throwable { 30 | Long time, time2; 31 | Object res; 32 | time = new Date().getTime(); 33 | res = point.proceed(); 34 | 35 | time2 = new Date().getTime(); 36 | MethodSignature signature = (MethodSignature) point.getSignature(); 37 | Method method = signature.getMethod(); 38 | 39 | System.out.println("[" + DateUtils.dateToStr(new Date()) + "] " + method + "- has spend " + ((time2 - time) / 1000) + "s"); 40 | 41 | return res; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/aop/UserLoginLogAop.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.aop; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.enums.DBEnum; 5 | import com.github.misterchangray.common.utils.HttpRequestParserUtils; 6 | import com.github.misterchangray.common.utils.JSONUtils; 7 | import com.github.misterchangray.common.utils.MapBuilder; 8 | import com.github.misterchangray.dao.entity.LoginLog; 9 | import com.github.misterchangray.dao.entity.User; 10 | import com.github.misterchangray.service.common.RedisCacheService; 11 | import com.github.misterchangray.service.log.LoginLogService; 12 | import com.github.misterchangray.service.user.bo.UserSessionBo; 13 | import org.aspectj.lang.ProceedingJoinPoint; 14 | import org.aspectj.lang.annotation.Around; 15 | import org.aspectj.lang.annotation.Aspect; 16 | import org.aspectj.lang.annotation.Pointcut; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Component; 19 | 20 | import javax.servlet.http.HttpServletRequest; 21 | import java.util.Date; 22 | 23 | 24 | /** 25 | * 登录日志 26 | *

27 | * 从业务上来讲:衹要是系統用戶;无论是否登录成功都应该记录日志;方便日后分析 28 | * 增加登录日志在 LoginService.signIn 方法中调用 29 | * 登出时间在用户 session 销毁时更新;即 UserSession 30 | * 31 | * @author Rui.Zhang/misterchangray@hotmail.com 32 | * @author Created on 2018/5/2. 33 | */ 34 | @Component 35 | @Aspect 36 | public class UserLoginLogAop { 37 | @Autowired 38 | LoginLogService loginLogService; 39 | @Autowired 40 | HttpServletRequest httpServletRequest; 41 | @Autowired 42 | UserSessionBo userSessionBo; 43 | @Autowired 44 | RedisCacheService redisCacheService; 45 | 46 | //創建用戶session時;創建日志 47 | @Pointcut(value = "execution(com.github.misterchangray.common.ResultSet com.github.misterchangray.service.user.LoginService.signInBy*(..))") 48 | private void createSession() {} 49 | 50 | //銷毀用戶session時;更新用戶登出時間 51 | @Pointcut(value = "execution(void com.github.misterchangray.service.user.bo.UserSessionBo.destroySession(..))") 52 | private void destroySession() {} 53 | 54 | 55 | @Around(value = "createSession()") 56 | public Object createSessionAround(ProceedingJoinPoint point) throws Throwable { 57 | Object res; 58 | res = point.proceed(); 59 | 60 | 61 | ResultSet resultSet = (ResultSet) res; 62 | if(null == resultSet) return res; 63 | 64 | if(0 != resultSet.getCode()) return res; //打开此行则只记录登录成功的用户 65 | 66 | User user = null; 67 | String session = null; 68 | MapBuilder mapBuilder = null; 69 | if(null != resultSet.getData()) { 70 | mapBuilder = (MapBuilder) resultSet.getData(); 71 | if(null != mapBuilder) { 72 | user = (User) mapBuilder.get("user"); 73 | session = (String) mapBuilder.get("Authorization"); 74 | } 75 | } 76 | 77 | //登录日志数据 78 | LoginLog loginLog = new LoginLog(); 79 | if(null != user) { 80 | loginLog.setUserId(user.getId()); 81 | } 82 | loginLog.setSignInIp(HttpRequestParserUtils.getUserIpAddr(httpServletRequest)); 83 | loginLog.setDeviceInfo(HttpRequestParserUtils.getUserAgent(httpServletRequest)); 84 | loginLog.setSignInTime(new Date()); 85 | loginLog.setSuccess(0 == resultSet.getCode() ? DBEnum.TRUE.getCode() : DBEnum.FALSE.getCode()); 86 | if(0 != resultSet.getCode()) { 87 | loginLog.setDetailsOfFail(resultSet.getMsg()); 88 | } 89 | loginLog.setSignInParam(JSONUtils.obj2json(point.getArgs())); 90 | loginLog.setSession(session); 91 | loginLogService.insertLog(loginLog); 92 | 93 | return res; 94 | } 95 | 96 | 97 | @Around(value = "destroySession()") 98 | public Object destroySessionAround(ProceedingJoinPoint point) { 99 | Object res; 100 | 101 | String session = (String) point.getArgs()[0]; 102 | 103 | if(null != session) { 104 | loginLogService.updateSignOutTime(session); 105 | } 106 | 107 | try { 108 | res = point.proceed(); 109 | } catch (Throwable throwable) { 110 | throwable.printStackTrace(); 111 | return throwable.getMessage(); 112 | } 113 | return res; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.config; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import io.swagger.annotations.ApiOperation; 9 | import springfox.documentation.builders.ApiInfoBuilder; 10 | import springfox.documentation.builders.ParameterBuilder; 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.schema.ModelRef; 14 | import springfox.documentation.service.ApiInfo; 15 | import springfox.documentation.service.Parameter; 16 | import springfox.documentation.spi.DocumentationType; 17 | import springfox.documentation.spring.web.plugins.Docket; 18 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * 配置swagger2.6.1 25 | * 26 | * @author Rui.Zhang/misterchangray@hotmail.com 27 | * @author Created on 3/22/2018. 28 | */ 29 | @Configuration //让Spring来加载该类配置 30 | @EnableWebMvc //启用Mvc,非springboot框架需要引入注解@EnableWebMvc 31 | @EnableSwagger2 //启用Swagger2 32 | @ComponentScan(basePackages = "com.github.misterchangray") 33 | public class SwaggerConfig { 34 | @Value("${swagger2.enabled}") 35 | private boolean enabled; 36 | 37 | @Bean 38 | public Docket createRestApi() { 39 | //统一增加权限验证字段 40 | List params = new ArrayList(); 41 | ParameterBuilder tokenParam = new ParameterBuilder(); 42 | tokenParam.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(true).build(); 43 | params.add(tokenParam.build()); 44 | 45 | return new Docket(DocumentationType.SWAGGER_2) 46 | .enable(enabled) 47 | .apiInfo(apiInfo()).select() 48 | //扫描指定包中的swagger注解 49 | //.apis(RequestHandlerSelectors.basePackage("com.github.misterchangray.controller")) 50 | //扫描所有有注解的api,用这种方式更灵活 51 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 52 | .paths(PathSelectors.any()) 53 | .build().globalOperationParameters(params); 54 | } 55 | 56 | private ApiInfo apiInfo() { 57 | 58 | return new ApiInfoBuilder() 59 | .title("基础平台 RESTful APIs") 60 | .description("基础平台 RESTful 风格的接口文档,内容详细,极大的减少了前后端的沟通成本,同时确保代码与文档保持高度一致,极大的减少维护文档的时间。") 61 | .version("1.0.0") 62 | .termsOfServiceUrl("https://github.com/MisterChangRay") 63 | .build(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/enums/DBEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.enums; 2 | 3 | /** 4 | * 设置数据库中的一些枚举 5 | * 请注意此枚举为数据库中使用的枚举类型,非页面枚举 6 | * 页面枚举应放置到 constants 表中 7 | * 8 | * @author Rui.Zhang/misterchangray@hotmail.com 9 | * @author Created on 3/27/2018. 10 | */ 11 | public enum DBEnum { 12 | TRUE(1, "true"), //表肯定 13 | FALSE(0, "false"), //表否定 14 | 15 | QUERY(100, "query"), //查询 16 | INSERT(101, "insert"),//新增 17 | UPDATE(102, "update"),//修改 18 | DELETE(103, "delete");//删除 19 | 20 | private Integer code; 21 | private String desc; 22 | 23 | public void setCode(Integer code) { 24 | this.code = code; 25 | } 26 | 27 | public String getDesc() { 28 | return desc; 29 | } 30 | 31 | public void setDesc(String desc) { 32 | this.desc = desc; 33 | } 34 | 35 | public Integer getCode() { 36 | return code; 37 | } 38 | DBEnum(Integer code, String desc) { 39 | this.code = code; 40 | this.desc = desc; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/enums/ResultEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.enums; 2 | 3 | /** 4 | * 错误消息,请注意此类只应该包含错误消息: 5 | * 6 | * ID格式: 7 | * 1 01 001 8 | * 1 代表错误等级 9 | * 01 代表第01个模块 10 | * 001 代表第10模块内的第一个错误消息序号 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/20/2018. 14 | */ 15 | public enum ResultEnum { 16 | SUCCESS(0, "成功"), //成功 17 | FAILURE(1, "失败"), //失败 18 | INVALID_REQUEST(101001, "参数字段错误或参数格式错误"), //无效请求,请求有格式或数据错误 19 | NEED_AUTH(101002, "需要权限认证"), //需要认证,没有权限 20 | DISABLED(101003, "资源已被禁用"),//资源已被禁用 21 | INVALID(101004, "资源无效"),//资源无效 22 | NOT_FOUND(101005, "资源不存在"),//资源不存在 23 | EXIST(101006, "资源已存在"),//资源已存在 24 | GONE(1001007, "资源已被删除"), //资源已经被删除 25 | SERVER_ERROR(101008, "系统未知错误"); //服务器错误 26 | 27 | 28 | 29 | 30 | private int code; 31 | private String msg; 32 | 33 | public int getCode() { 34 | return code; 35 | } 36 | public String getMsg() { 37 | return msg; 38 | } 39 | private ResultEnum(Integer code, String msg) { 40 | this.code = code; 41 | this.msg = msg; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.exception; 2 | 3 | import com.github.misterchangray.common.enums.ResultEnum; 4 | 5 | /** 6 | * @author Created by rui.zhang on 2018/6/4. 7 | * @author rui.zhang 8 | * @version ver1.0 9 | * @email misterchangray@hotmail.com 10 | * @description 11 | * 封装全局统一异常返回; 12 | * 此类作为业务异常返回封装 13 | * 你可以在代码中任何地方返回错误信息到前端 14 | */ 15 | public class ServiceException extends Exception { 16 | private String msg; 17 | private ResultEnum resultEnum; 18 | 19 | public ServiceException(ResultEnum resultEnum, String errorMsg) { 20 | super(); 21 | this.resultEnum = resultEnum; 22 | this.msg = resultEnum.getMsg(); 23 | 24 | if(null != errorMsg) { 25 | this.msg = errorMsg; 26 | } 27 | } 28 | 29 | public ServiceException(ResultEnum resultEnum) { 30 | super(); 31 | this.resultEnum = resultEnum; 32 | this.msg = resultEnum.getMsg(); 33 | 34 | } 35 | 36 | public ServiceException(String errorMsg) { 37 | super(); 38 | this.msg = errorMsg; 39 | } 40 | 41 | 42 | 43 | public String getMsg() { 44 | return msg; 45 | } 46 | 47 | public void setMsg(String msg) { 48 | this.msg = msg; 49 | } 50 | 51 | public ResultEnum getResultEnum() { 52 | return resultEnum; 53 | } 54 | 55 | public void setResultEnum(ResultEnum resultEnum) { 56 | this.resultEnum = resultEnum; 57 | } 58 | 59 | 60 | @Override 61 | public String toString() { 62 | return "ServiceException{" + 63 | "msg='" + msg + '\'' + 64 | ", resultEnum=" + resultEnum + 65 | '}'; 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/init/Init.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.init; 2 | 3 | import org.springframework.context.ApplicationListener; 4 | import org.springframework.context.event.ContextRefreshedEvent; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * 9 | * spring 容器初始化方法;在spring初始化完成后執行此方法 10 | * @author Rui.Zhang/misterchangray@hotmail.com 11 | * @author Created on 4/29/2018. 12 | */ 13 | @Component 14 | public class Init implements ApplicationListener { 15 | 16 | 17 | //需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。 18 | public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/interceptor/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.interceptor; 2 | 3 | 4 | import com.github.misterchangray.common.ResultSet; 5 | import com.github.misterchangray.common.annotation.Authorization; 6 | import com.github.misterchangray.common.enums.ResultEnum; 7 | import com.github.misterchangray.common.utils.JSONUtils; 8 | import com.github.misterchangray.service.common.ContextCacheService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.method.HandlerMethod; 11 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.lang.reflect.Method; 16 | 17 | /** 18 | * 权限校验拦截器: 19 | * 1.首先判断访问的方法是否包含 @Authorization 注解; 20 | * 2.再判断当前登录用户集合中是否存在该session;并校验session正确性 21 | * 22 | * tips:请在 tokenValidate 方法中实现你自己的登录验证; 23 | * 24 | * 25 | * @author Rui.Zhang/misterchangray@hotmail.com 26 | * @author Created on 3/26/2018. 27 | */ 28 | public class AuthInterceptor extends HandlerInterceptorAdapter { 29 | @Autowired 30 | ContextCacheService contextCacheService; 31 | 32 | /** 33 | * 在这个方法里实现你的权限验证逻辑 34 | * 成功返回true;失败返回false 35 | * @return 36 | */ 37 | private boolean tokenValidate(String token) { 38 | if(null != contextCacheService.get(token)) { 39 | Long t = System.currentTimeMillis() - (Long)contextCacheService.get(token); 40 | if(t > 24 * 60 * 60 * 1000) { 41 | contextCacheService.remove(token); 42 | return false; 43 | } 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | 50 | @Override 51 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 52 | //如果是OPTIONS请求则跳过 53 | if( null != request.getMethod() && "options".equals(request.getMethod().toLowerCase())) { 54 | return true; 55 | } 56 | 57 | // 如果不是映射到方法直接通过 58 | if (!(handler instanceof HandlerMethod)) { 59 | return true; 60 | } 61 | 62 | HandlerMethod handlerMethod = (HandlerMethod) handler; 63 | Method method = handlerMethod.getMethod(); 64 | 65 | // 通过注解判断接口是否需要权限认证 66 | Authorization classAnnotation = method.getDeclaringClass().getAnnotation(Authorization.class); 67 | Authorization methodAnnotation = method.getAnnotation(Authorization.class); 68 | // 有 @Authorization 注解,需要认证 69 | if (null != classAnnotation || methodAnnotation != null) { 70 | // 执行权限认证 71 | String token = request.getHeader("Authorization"); // 从 http 请求头中取出 Authorization 72 | 73 | if (null == token) { 74 | response.setHeader("content-type", "application/json; charset=UTF-8"); 75 | response.getOutputStream().write(JSONUtils.obj2json(ResultSet.build(ResultEnum.NEED_AUTH).setMsg("无token,请先登录")).getBytes("utf8")); 76 | response.getOutputStream().flush(); 77 | return false; 78 | } 79 | 80 | if(false == tokenValidate(token)){ 81 | response.setHeader("content-type", "application/json; charset=UTF-8"); 82 | response.getOutputStream().write(JSONUtils.obj2json(ResultSet.build(ResultEnum.NEED_AUTH).setMsg("token异常,请重新登录")).getBytes("utf8")); 83 | response.getOutputStream().flush(); 84 | return false; 85 | } 86 | return true; 87 | } 88 | return true; 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/interceptor/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.interceptor; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.enums.ResultEnum; 5 | import com.github.misterchangray.common.exception.ServiceException; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | /** 14 | * 提供全局统一异常处理 15 | * @author Created by rui.zhang on 2018/6/4. 16 | * @author rui.zhang 17 | * @version ver1.0 18 | * @email misterchangray@hotmail.com 19 | * @description 20 | * 注意: 21 | * 如果你使用异常方式返回信息;请不要将错误信息try-catch进行处理;应该逐级上抛并统一到此处处理 22 | */ 23 | @ControllerAdvice() 24 | public class GlobalExceptionHandler { 25 | org.slf4j.Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); 26 | 27 | @ExceptionHandler(Exception.class) 28 | @ResponseBody 29 | public ResultSet serviceExceptionHandler(Exception ex, HttpServletResponse httpServletResponse) { 30 | //允许跨域访问 31 | httpServletResponse.setHeader("Access-Control-Allow-Origin","*"); 32 | 33 | //对捕获的异常进行处理并打印日志等,之后返回json数据,方式与Controller相同 34 | ex.printStackTrace(); 35 | ServiceException serviceException = null; 36 | 37 | //如果抛出的是系统自定义的异常则直接转换 38 | if(ex instanceof ServiceException) { 39 | serviceException = (ServiceException) ex; 40 | logger.info(ex.getMessage(), ex); 41 | } else { 42 | //如果抛出的不是系统自定义的异常则重新构造一个未知错误异常 43 | serviceException = new ServiceException(ResultEnum.SERVER_ERROR); 44 | logger.error(ex.getMessage(), ex); 45 | 46 | } 47 | 48 | ResultSet resultSet = ResultSet.build(serviceException.getResultEnum()); 49 | if(null != serviceException.getMsg()) resultSet.setMsg(serviceException.getMsg()); 50 | 51 | return resultSet; 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/quartz/GlobalQuartz.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.quartz; 2 | 3 | import com.github.misterchangray.common.utils.DateUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.scheduling.annotation.Scheduled; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * 11 | * 全局定时任务 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 2018/5/3. 14 | * 15 | * cronExpression的配置说明 16 | * 字段 允许值 允许的特殊字符 17 | * 秒 0-59 , - * / 18 | * 分 0-59 , - * / 19 | * 小时 0-23 , - * / 20 | * 日期 1-31 , - * ? / L W C 21 | * 月份 1-12 或者 JAN-DEC , - * / 22 | * 星期 1-7 或者 SUN-SAT , - * ? / L C # 23 | * 年(可选) 留空, 1970-2099 , - * / 24 | * - 区间 25 | * * 通配符 26 | * ? 你不想设置那个字段 27 | * 28 | */ 29 | @Component("GlobalQuartz") 30 | public class GlobalQuartz { 31 | Logger logger = LoggerFactory.getLogger(GlobalQuartz.class); 32 | 33 | /** 34 | * 简单轮询任务 35 | * fixedDelay = 60 * 1000;单位:毫秒 36 | */ 37 | @Scheduled(fixedDelay = 60 * 1000) 38 | public void globalQuartz() { 39 | // 每分钟执行一次 40 | logger.info("--------------------------- 定时任务开始[{}] ---------------------------", DateUtils.now(null)); 41 | System.out.println("定时任务"); 42 | logger.info("--------------------------- 定时任务结束[{}] ---------------------------", DateUtils.now(null)); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/AESUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import javax.crypto.Cipher; 4 | import javax.crypto.spec.IvParameterSpec; 5 | import javax.crypto.spec.SecretKeySpec; 6 | 7 | /** 8 | * @author Rui.Zhang/misterchangray@hotmail.com 9 | * @author Created on 4/29/2018. 10 | */ 11 | public class AESUtils { 12 | //初始化向量,aes 16位 13 | private static final String IV = "a5856355ef87955f"; 14 | 15 | public static void main(String[] args) throws Exception { 16 | 17 | String content = "梅须逊雪三分白,雪却输梅一段香。"; 18 | String password = "0123456789abcde1f"; //此处使用AES-128-CBC加密模式,key需要为16位 19 | 20 | System.out.println("加密前:" + content); 21 | String encryptResult = AESUtils.encrypt(content, password); 22 | System.out.println("加密后:" + encryptResult); 23 | String decryptResult = AESUtils.decrypt(encryptResult,password); 24 | System.out.println("解密后:" + decryptResult); 25 | } 26 | 27 | 28 | //加密 29 | public static String encrypt(String content, String keyWord) throws Exception { 30 | if(null == content || null == keyWord) throw new RuntimeException("参数错误"); 31 | if(16 != keyWord.length()) throw new RuntimeException("keyWord必须为16位字符"); 32 | 33 | try { 34 | SecretKeySpec key = new SecretKeySpec(keyWord.getBytes(), "AES"); 35 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 36 | cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(IV.getBytes())); 37 | byte[] encryptedData = cipher.doFinal(content.getBytes("UTF-8")); 38 | return parseByte2HexStr(encryptedData); 39 | } catch (Exception e) { 40 | throw new Exception("加密失败"); 41 | } 42 | } 43 | 44 | //解密 45 | public static String decrypt(String content, String keyWord) throws Exception { 46 | if(null == content || null == keyWord) throw new RuntimeException("参数错误"); 47 | if(16 != keyWord.length()) throw new RuntimeException("keyWord必须为16位字符"); 48 | 49 | byte[] contentBytes = parseHexStr2Byte(content); 50 | try { 51 | SecretKeySpec key = new SecretKeySpec(keyWord.getBytes(), "AES"); 52 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 53 | cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV.getBytes())); 54 | byte[] result = cipher.doFinal(contentBytes); 55 | return new String(result, "UTF-8"); 56 | } catch (Exception e) { 57 | throw new Exception("解密失败"); 58 | } 59 | } 60 | 61 | //二进制转变为16进制 62 | private static String parseByte2HexStr(byte[] buf) { 63 | StringBuffer sb = new StringBuffer(); 64 | for (int i = 0; i < buf.length; i++) { 65 | String hex = Integer.toHexString(buf[i] & 0xFF); 66 | if (hex.length() == 1) { 67 | hex = '0' + hex; 68 | } 69 | sb.append(hex); 70 | } 71 | return sb.toString(); 72 | } 73 | 74 | //将16进制转变为二进制 75 | private static byte[] parseHexStr2Byte(String hexStr) { 76 | if (hexStr.length() < 1) { 77 | return null; 78 | } 79 | byte[] result = new byte[hexStr.length() / 2]; 80 | for (int i = 0; i < hexStr.length() / 2; i++) { 81 | int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); 82 | int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); 83 | result[i] = (byte) (high * 16 + low); 84 | } 85 | return result; 86 | } 87 | 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import java.sql.Timestamp; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | 8 | /** 9 | * 常用静态工具类 10 | * 提供日期处理格式化方法 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/26/2018. 14 | */ 15 | public class DateUtils { 16 | /** 17 | * 获取当前日期,可格式化 18 | * @param format 日期格式化代码 19 | * @return 20 | */ 21 | public static String now(String format) { 22 | if(null == format) format = "yyyy-MM-dd hh:mm:ss"; 23 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); 24 | return simpleDateFormat.format(new Date()); 25 | } 26 | 27 | 28 | /** 29 | * 获取当前日期 30 | * @return 31 | */ 32 | public static Date now() { 33 | return new Date(); 34 | } 35 | 36 | 37 | /** 38 | * 字符串到日期 39 | * @param str_date 日期字符串数据 40 | * @param format 日期格式化代码 41 | * @return 42 | */ 43 | public static Date strToDate(String str_date, String format) { 44 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); 45 | Date date = null; 46 | try { 47 | date = simpleDateFormat.parse(str_date); 48 | } catch (ParseException e) { 49 | e.printStackTrace(); 50 | } 51 | return date; 52 | } 53 | 54 | /** 55 | * 字符串到日期 56 | * @param str_date 只能格式化yyyy-MM-dd 57 | * @return 58 | */ 59 | public static Date strToDate(String str_date) { 60 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 61 | Date date = null; 62 | try { 63 | date = simpleDateFormat.parse(str_date); 64 | } catch (ParseException e) { 65 | e.printStackTrace(); 66 | } 67 | return date; 68 | } 69 | 70 | /** 71 | * 日期到字符串,默认格式为"yyyy-MM-dd HH:mm:ss" 72 | * @param date 73 | * @return 74 | */ 75 | public static String dateToStr(Date date) { 76 | SimpleDateFormat tmp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 77 | return tmp.format(date); 78 | } 79 | 80 | /** 81 | * 日期到字符串 82 | * @param date 83 | * @param format 84 | * @return 85 | */ 86 | public static String dateToStr(Date date, String format) { 87 | SimpleDateFormat tmp = new SimpleDateFormat(format); 88 | return tmp.format(date); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/EmailBuilder.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.mail.SimpleMailMessage; 5 | import org.springframework.mail.javamail.JavaMailSenderImpl; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.io.IOException; 9 | import java.util.Properties; 10 | 11 | /** 12 | * 简单的邮件发送器; 13 | * 请注意此工具类需要注入使用 14 | * @author Created by rui.zhang on 2018/6/2. 15 | * @author rui.zhang 16 | * @version ver1.0 17 | * @email misterchangray@hotmail.com 18 | * @description 19 | */ 20 | @Component 21 | public class EmailBuilder extends JavaMailSenderImpl{ 22 | private static String emailHost; 23 | private static Integer emailPort; 24 | private static String emailUsername; 25 | private static String emailPassword; 26 | private static EmailBuilder emailBuilder = new EmailBuilder(); 27 | private static Properties properties = new Properties(); 28 | 29 | 30 | public static void main(String[] args) throws IOException { 31 | EmailBuilder.build().sendSimpleEmail("jioulongzi@qq.com", "914590431@qq.com", "hello", "world"); 32 | } 33 | 34 | 35 | /** 36 | * 发送简单邮件 37 | * @param from 发件人 38 | * @param to 收件人 39 | * @param subject 主题 40 | * @param text 正文 41 | */ 42 | public void sendSimpleEmail(String from, String to, String subject, String text){ 43 | SimpleMailMessage message = new SimpleMailMessage();//消息构造器 44 | message.setFrom(from);//发件人 45 | message.setTo(to);//收件人 46 | message.setSubject(subject);//主题 47 | message.setText(text);//正文 48 | this.send(message); 49 | } 50 | 51 | 52 | /** 53 | * 构建一个邮件发送器 54 | * @return 55 | */ 56 | public static EmailBuilder build() { 57 | emailBuilder.setHost(emailHost);//指定用来发送Email的邮件服务器主机名 58 | emailBuilder.setPort(emailPort);//默认端口,标准的SMTP端口 59 | emailBuilder.setUsername(emailUsername);//用户名 60 | emailBuilder.setPassword(emailPassword);//密码 61 | emailBuilder.setProtocol("smtp"); 62 | // 设定properties 63 | properties.put("mail.smtp.auth", true); 64 | properties.put("mail.smtp.ssl.enable", true); 65 | properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); 66 | properties.put("mail.smtp.timeout", 25000); 67 | emailBuilder.setJavaMailProperties(properties); 68 | 69 | return emailBuilder; 70 | } 71 | 72 | 73 | 74 | 75 | 76 | /** 以下为辅助方法和注入方法 **/ 77 | private EmailBuilder() {} 78 | 79 | @Value("${email.host}") 80 | public void setEmailHost(String emailHost) { 81 | EmailBuilder.emailHost = emailHost; 82 | } 83 | 84 | @Value("${email.port}") 85 | public void setEmailPort(Integer emailPort) { 86 | EmailBuilder.emailPort = emailPort; 87 | } 88 | @Value("${email.username}") 89 | public void setEmailUsername(String emailUsername) { 90 | EmailBuilder.emailUsername = emailUsername; 91 | } 92 | @Value("${email.password}") 93 | public void setEmailPassword(String emailPassword) { 94 | EmailBuilder.emailPassword = emailPassword; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/EntityUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import org.springframework.beans.BeanUtils; 4 | import org.springframework.beans.BeanWrapper; 5 | import org.springframework.beans.BeanWrapperImpl; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | 11 | /** 12 | * 常用静态工具类 13 | * 提供对象处理方法 14 | * 15 | * @author Rui.Zhang/misterchangray@hotmail.com 16 | * @author Created on 3/26/2018. 17 | */ 18 | public class EntityUtils { 19 | /** 20 | * 获取对象值为null的属性 21 | * @param source 22 | * @return 23 | */ 24 | public static String[] getNullPropertyNames (Object source) { 25 | final BeanWrapper src = new BeanWrapperImpl(source); 26 | java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); 27 | 28 | Set emptyNames = new HashSet(); 29 | for(java.beans.PropertyDescriptor pd : pds) { 30 | Object srcValue = src.getPropertyValue(pd.getName()); 31 | if (srcValue == null) emptyNames.add(pd.getName()); 32 | } 33 | String[] result = new String[emptyNames.size()]; 34 | return emptyNames.toArray(result); 35 | } 36 | 37 | /** 38 | * 对象属性拷贝,从右拷贝到左,拷贝时忽略null的属性 39 | * @param source 40 | * @param target 41 | */ 42 | public static void copyPropertiesIgnoreNull(Object source, Object target){ 43 | BeanUtils.copyProperties(source, target, getNullPropertyNames(source)); 44 | } 45 | 46 | 47 | /** 48 | * 对象属性拷贝,从右拷贝到左 49 | * 注意这个函数也回拷贝null值 50 | * @param source 51 | * @param target 52 | */ 53 | public static void copyProperties(Object source, Object target) { 54 | BeanUtils.copyProperties(source, target); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/GZipUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import java.io.*; 4 | import java.nio.ByteBuffer; 5 | import java.nio.channels.FileChannel; 6 | import java.util.zip.GZIPInputStream; 7 | import java.util.zip.GZIPOutputStream; 8 | import java.util.zip.ZipEntry; 9 | import java.util.zip.ZipFile; 10 | 11 | /** 12 | * @author tanml 13 | * 将一串数据按照gzip方式压缩和解压缩 14 | */ 15 | public class GZipUtils { 16 | // 压缩 17 | public static byte[] compress(byte[] data) throws IOException { 18 | if (data == null || data.length == 0) { 19 | return null; 20 | } 21 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 22 | GZIPOutputStream gzip = new GZIPOutputStream(out); 23 | gzip.write(data); 24 | gzip.close(); 25 | return out.toByteArray();//out.toString("ISO-8859-1"); 26 | } 27 | 28 | public static byte[] compress(String str) throws IOException { 29 | if (str == null || str.length() == 0) { 30 | return null; 31 | } 32 | return compress(str.getBytes("utf-8")); 33 | } 34 | 35 | // 解压缩 36 | public static byte[] uncompress(byte[] data) throws IOException { 37 | if (data == null || data.length == 0) { 38 | return data; 39 | } 40 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 41 | ByteArrayInputStream in = new ByteArrayInputStream(data); 42 | GZIPInputStream gunzip = new GZIPInputStream(in); 43 | byte[] buffer = new byte[256]; 44 | int n; 45 | while ((n = gunzip.read(buffer)) >= 0) { 46 | out.write(buffer, 0, n); 47 | } 48 | gunzip.close(); 49 | in.close(); 50 | return out.toByteArray(); 51 | } 52 | 53 | public static String uncompress(String str) throws IOException { 54 | if (str == null || str.length() == 0) { 55 | return str; 56 | } 57 | byte[] data = uncompress(str.getBytes("utf-8")); // ISO-8859-1 58 | return new String(data); 59 | } 60 | 61 | /** 62 | * @param @param unZipfile 63 | * @param @param destFile 指定读取文件,需要从压缩文件中读取文件内容的文件名 64 | * @param @return 设定文件 65 | * @return String 返回类型 66 | * @throws 67 | * @Title: unZip 68 | * @Description: TODO(这里用一句话描述这个方法的作用) 69 | */ 70 | public static String unZip(String unZipfile, String destFile) {// unZipfileName需要解压的zip文件名 71 | InputStream inputStream; 72 | String inData = null; 73 | try { 74 | // 生成一个zip的文件 75 | File f = new File(unZipfile); 76 | ZipFile zipFile = new ZipFile(f); 77 | 78 | // 遍历zipFile中所有的实体,并把他们解压出来 79 | ZipEntry entry = zipFile.getEntry(destFile); 80 | if (!entry.isDirectory()) { 81 | // 获取出该压缩实体的输入流 82 | inputStream = zipFile.getInputStream(entry); 83 | 84 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 85 | byte[] bys = new byte[4096]; 86 | for (int p = -1; (p = inputStream.read(bys)) != -1; ) { 87 | out.write(bys, 0, p); 88 | } 89 | inData = out.toString(); 90 | out.close(); 91 | inputStream.close(); 92 | } 93 | zipFile.close(); 94 | } catch (IOException ioe) { 95 | ioe.printStackTrace(); 96 | } 97 | return inData; 98 | } 99 | 100 | public static void main(String[] args) { 101 | String json = "{\"androidSdk\":22,\"androidVer\":\"5.1\",\"cpTime\":1612071603,\"cupABIs\":[\"armeabi-v7a\",\"armeabi\"],\"customId\":\"QT99999\",\"elfFlag\":false,\"id\":\"4a1b644858d83a98\",\"imsi\":\"460015984967892\",\"system\":true,\"systemUser\":true,\"test\":true,\"model\":\"Micromax R610\",\"netType\":0,\"oldVersion\":\"0\",\"pkg\":\"com.adups.fota.sysoper\",\"poll_time\":30,\"time\":1481634113876,\"timeZone\":\"Asia\\/Shanghai\",\"versions\":[{\"type\":\"gatherApks\",\"version\":1},{\"type\":\"kernel\",\"version\":9},{\"type\":\"shell\",\"version\":10},{\"type\":\"silent\",\"version\":4},{\"type\":\"jarUpdate\",\"version\":1},{\"type\":\"serverIps\",\"version\":1}]}"; 102 | json = "ksjdflkjsdflskjdflsdfkjsdf"; 103 | try { 104 | byte[] buf = GZipUtils.compress(json); 105 | 106 | File fin = new File("D:/temp/test4.txt"); 107 | FileChannel fcout = new RandomAccessFile(fin, "rws").getChannel(); 108 | ByteBuffer wBuffer = ByteBuffer.allocateDirect(buf.length); 109 | fcout.write(wBuffer.wrap(buf), fcout.size()); 110 | if (fcout != null) { 111 | fcout.close(); 112 | } 113 | } catch (IOException e) { 114 | // TODO Auto-generated catch block 115 | e.printStackTrace(); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/HttpRequestParserUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import java.net.InetAddress; 5 | 6 | /** 7 | * 8 | * 提供java http 协议解析工具 9 | * @author Rui.Zhang/misterchangray@hotmail.com 10 | * @author Created on 4/29/2018. 11 | */ 12 | public class HttpRequestParserUtils { 13 | /** 14 | * @Description: 获取客户端IP地址 15 | */ 16 | public static String getUserIpAddr(HttpServletRequest request) { 17 | String ip = request.getHeader("x-forwarded-for"); 18 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 19 | ip = request.getHeader("Proxy-Client-IP"); 20 | } 21 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 22 | ip = request.getHeader("WL-Proxy-Client-IP"); 23 | } 24 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 25 | ip = request.getRemoteAddr(); 26 | if (ip.equals("127.0.0.1")) { 27 | //根据网卡取本机配置的IP 28 | InetAddress inet = null; 29 | try { 30 | inet = InetAddress.getLocalHost(); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | ip = inet.getHostAddress(); 35 | } 36 | } 37 | // 多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 38 | if (ip != null && ip.length() > 15) { 39 | if (ip.indexOf(",") > 0) { 40 | ip = ip.substring(0, ip.indexOf(",")); 41 | } 42 | } 43 | return ip; 44 | } 45 | 46 | 47 | /** 48 | * 獲取用戶user-agent 49 | * @param httpServletRequest 50 | * @return 51 | */ 52 | public static String getUserAgent(HttpServletRequest httpServletRequest) { 53 | return httpServletRequest.getHeader("User-Agent"); 54 | } 55 | 56 | 57 | /** 58 | * 获取操作系统,浏览器及浏览器版本信息 59 | * 60 | * @param httpServletRequest 61 | * @return 62 | */ 63 | public static String getOsAndBrowserInfo(HttpServletRequest httpServletRequest) { 64 | String browserDetails = HttpRequestParserUtils.getUserAgent(httpServletRequest); 65 | String userAgent = browserDetails; 66 | String user = userAgent.toLowerCase(); 67 | 68 | String os = ""; 69 | String browser = ""; 70 | 71 | //=================OS Info======================= 72 | if (userAgent.toLowerCase().indexOf("windows") >= 0) { 73 | os = "Windows"; 74 | } else if (userAgent.toLowerCase().indexOf("mac") >= 0) { 75 | os = "Mac"; 76 | } else if (userAgent.toLowerCase().indexOf("x11") >= 0) { 77 | os = "Unix"; 78 | } else if (userAgent.toLowerCase().indexOf("android") >= 0) { 79 | os = "Android"; 80 | } else if (userAgent.toLowerCase().indexOf("iphone") >= 0) { 81 | os = "IPhone"; 82 | } else { 83 | os = "UnKnown, More-Info: " + userAgent; 84 | } 85 | //===============Browser=========================== 86 | if (user.contains("edge")) { 87 | browser = (userAgent.substring(userAgent.indexOf("Edge")).split(" ")[0]).replace("/", "-"); 88 | } else if (user.contains("msie")) { 89 | String substring = userAgent.substring(userAgent.indexOf("MSIE")).split(";")[0]; 90 | browser = substring.split(" ")[0].replace("MSIE", "IE") + "-" + substring.split(" ")[1]; 91 | } else if (user.contains("safari") && user.contains("version")) { 92 | browser = (userAgent.substring(userAgent.indexOf("Safari")).split(" ")[0]).split("/")[0] 93 | + "-" + (userAgent.substring(userAgent.indexOf("Version")).split(" ")[0]).split("/")[1]; 94 | } else if (user.contains("opr") || user.contains("opera")) { 95 | if (user.contains("opera")) { 96 | browser = (userAgent.substring(userAgent.indexOf("Opera")).split(" ")[0]).split("/")[0] 97 | + "-" + (userAgent.substring(userAgent.indexOf("Version")).split(" ")[0]).split("/")[1]; 98 | } else if (user.contains("opr")) { 99 | browser = ((userAgent.substring(userAgent.indexOf("OPR")).split(" ")[0]).replace("/", "-")) 100 | .replace("OPR", "Opera"); 101 | } 102 | 103 | } else if (user.contains("chrome")) { 104 | browser = (userAgent.substring(userAgent.indexOf("Chrome")).split(" ")[0]).replace("/", "-"); 105 | } else if ((user.indexOf("mozilla/7.0") > -1) || (user.indexOf("netscape6") != -1) || 106 | (user.indexOf("mozilla/4.7") != -1) || (user.indexOf("mozilla/4.78") != -1) || 107 | (user.indexOf("mozilla/4.08") != -1) || (user.indexOf("mozilla/3") != -1)) { 108 | browser = "Netscape-?"; 109 | 110 | } else if (user.contains("firefox")) { 111 | browser = (userAgent.substring(userAgent.indexOf("Firefox")).split(" ")[0]).replace("/", "-"); 112 | } else if (user.contains("rv")) { 113 | String IEVersion = (userAgent.substring(userAgent.indexOf("rv")).split(" ")[0]).replace("rv:", "-"); 114 | browser = "IE" + IEVersion.substring(0, IEVersion.length() - 1); 115 | } else { 116 | browser = "UnKnown, More-Info: " + userAgent; 117 | } 118 | 119 | return os + " --- " + browser; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/JSONUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.DeserializationFeature; 5 | import com.fasterxml.jackson.databind.JavaType; 6 | import com.fasterxml.jackson.databind.JsonNode; 7 | import com.fasterxml.jackson.databind.ObjectMapper; 8 | import org.aspectj.weaver.BCException; 9 | 10 | import java.io.IOException; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * 常用静态工具类 18 | * JSON相关操作工具 19 | * 20 | * 21 | * 连续访问一个JSON的多个属性时推荐先使用 buildJsonNode 方法建立 Json实体;再读取其中的属性;以提高效率 22 | * 23 | * @author Rui.Zhang/misterchangray@hotmail.com 24 | * @author Created on 2018/4/23. 25 | */ 26 | public class JSONUtils { 27 | private static ObjectMapper mapper = new ObjectMapper(); 28 | 29 | public static void main(String[] a) { 30 | 31 | buildJsonNode(null); 32 | } 33 | 34 | 35 | /** 36 | * 构建json树 37 | * @param json 38 | * @return 39 | */ 40 | public static JsonNode buildJsonNode(String json) { 41 | try { 42 | return mapper.readTree(json); 43 | } catch (Exception e) { 44 | // e.printStackTrace(); 45 | } 46 | return null; 47 | } 48 | 49 | 50 | 51 | /** 52 | * 53 | * 快捷获取json对象属性; 当获取对象多个属性时候;请搭配buildJsonNode使用 54 | * 注意;不能直接获取 55 | * @param json 字符串json数据;或JsonNode对象 56 | * @param propName 待获取属性名称 57 | * @param defaultVal 待获取属性未定义则返回此值 58 | * @returns {Object}, 获取的属性值 59 | * @return 60 | */ 61 | public static JsonNode getJsonPathVal(Object json, String propName, Object defaultVal) { 62 | String[] keys; 63 | JsonNode rootNode = null; 64 | if(null == propName) return mapper.valueToTree(defaultVal); 65 | if(null != json && json instanceof JsonNode) { 66 | rootNode = (JsonNode) json; 67 | } else if(json instanceof String){ 68 | try { 69 | rootNode = mapper.readTree(String.valueOf(json)); 70 | } catch (IOException e) { 71 | e.printStackTrace(); 72 | } 73 | } 74 | if(!propName.matches("^([a-zA-Z0-9_$]*?(\\[\\d+\\])?\\.?)+$")) { 75 | throw new RuntimeException("属性名称表达式语法错误"); 76 | } 77 | 78 | keys = propName.split("\\."); 79 | Integer index; 80 | String key; 81 | for(int i=0, j = keys.length; i 146 | * @param json 147 | * @return 148 | * @throws BCException 149 | */ 150 | public static List json2list(String json, Class clazz) { 151 | List configList = null; 152 | try { 153 | //忽略不存在的字段 154 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 155 | 156 | JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, clazz); 157 | configList = mapper.readValue(json, javaType); //这里不需要强制转换 158 | } catch (JsonProcessingException e) { 159 | e.printStackTrace(); 160 | } catch (IOException e) { 161 | e.printStackTrace(); 162 | } 163 | return configList; 164 | } 165 | 166 | /** 167 | * json转到指定对象 168 | * @param json 169 | * @return 170 | * @throws BCException 171 | */ 172 | public static T json2obj(String json, Class t) { 173 | T res = null; 174 | try { 175 | //忽略不存在的字段 176 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 177 | 178 | res = (T) mapper.readValue(json, t); 179 | } catch (JsonProcessingException e) { 180 | e.printStackTrace(); 181 | } catch (IOException e) { 182 | e.printStackTrace(); 183 | } 184 | return res; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/ListBuilder.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * @author Created by rui.zhang on 2018/5/24. 7 | * @author rui.zhang 8 | * @version ver1.0 9 | * @email misterchangray@hotmail.com 10 | * @description 11 | */ 12 | public class ListBuilder extends ArrayList { 13 | /** 14 | * new一个List实例 15 | * @return 16 | */ 17 | public static ListBuilder build() { 18 | return new ListBuilder(); 19 | } 20 | 21 | 22 | /** 23 | * 为List增加一个元素 24 | * @param obj 25 | * @return 26 | */ 27 | public ListBuilder append(Object obj) { 28 | super.add(obj); 29 | return this; 30 | } 31 | 32 | /** 33 | * 次函数主要解决字符串拼接问题,例如拼接过程中要加逗号,空值不拼接等等 34 | * 格式化输出 35 | * @return 36 | */ 37 | public String getText() { 38 | StringBuilder stringBuilder = new StringBuilder(); 39 | for(Object o : this) { 40 | if(null == o || "".equals(o.toString().trim())) continue;; 41 | stringBuilder.append(", " + o.toString()); 42 | } 43 | if(stringBuilder.toString().length() > 2) { 44 | return stringBuilder.toString().substring(2); 45 | } else { 46 | return stringBuilder.toString(); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/common/utils/MapBuilder.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.common.utils; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | /** 6 | * 返回对象为Map子类,可直接当Map使用 7 | * 简易的map构建器,用于链式构建map结构数据 8 | * 示例如下: 9 | * MapBuilder.build().add("key", "value").add("key2", "value2"); 10 | * 11 | * @author Rui.Zhang/misterchangray@hotmail.com 12 | * @author Created on 4/19/2018. 13 | */ 14 | public class MapBuilder extends ConcurrentHashMap { 15 | 16 | private MapBuilder() {} 17 | 18 | public static MapBuilder build() { 19 | return new MapBuilder(); 20 | } 21 | 22 | /** 23 | * 向map里增加元素 24 | * @param key 25 | * @param value 26 | * @return MapBuilder 27 | */ 28 | public MapBuilder add(String key, Object value) { 29 | if(null == value) return this; 30 | super.put(key, value); 31 | return this; 32 | } 33 | 34 | /** 35 | * 向map里增加元素 36 | * @param key 37 | * @param value 38 | * @return MapBuilder 39 | */ 40 | public MapBuilder put(String key, Object value) { 41 | if(null == value) return this; 42 | this.add(key, value); 43 | return this; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/ConstantController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.enums.DBEnum; 5 | import com.github.misterchangray.dao.entity.Constant; 6 | import com.github.misterchangray.dao.entity.ConstantQuery; 7 | import com.github.misterchangray.dao.mapper.ConstantMapper; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiImplicitParam; 10 | import io.swagger.annotations.ApiImplicitParams; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | import org.springframework.web.bind.annotation.ResponseBody; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * 页面常量控制类 23 | * 24 | * @author Rui.Zhang/misterchangray@hotmail.com 25 | * @author Created on 3/23/2018. 26 | */ 27 | @Api(tags ="页面常量获取", description = "ConstantController") 28 | @Controller 29 | @RequestMapping("/v1/constant") 30 | public class ConstantController { 31 | @Autowired 32 | private ConstantMapper constantMapper; 33 | 34 | 35 | @ApiOperation(value = "获取所有常量枚举", notes = "返回所有页面常量枚举,前端做缓存") 36 | @ApiImplicitParams({ 37 | @ApiImplicitParam(name="pid", value = "父ID", required = false, paramType = "query", dataType = "string"), 38 | @ApiImplicitParam(name="shortcut", value = "简称", required = false, paramType = "query", dataType = "string"), 39 | }) 40 | @RequestMapping(method = RequestMethod.GET) 41 | @ResponseBody 42 | public ResultSet constant(@RequestParam(required = false) String pid, @RequestParam(required = false) String shortcut) { 43 | ResultSet res = ResultSet.build(); 44 | 45 | ConstantQuery constantQuery = new ConstantQuery(); 46 | ConstantQuery.Criteria criteria = constantQuery.createCriteria(); 47 | criteria.andEnabledEqualTo(DBEnum.TRUE.getCode()); 48 | criteria.andDeletedEqualTo(DBEnum.FALSE.getCode()); 49 | 50 | if(null != pid) criteria.andPidEqualTo(pid); 51 | if(null != shortcut) criteria.andShortcutEqualTo(shortcut); 52 | 53 | List constantList = constantMapper.selectByQuery(constantQuery); 54 | 55 | res.setData(constantList); 56 | return res; 57 | } 58 | 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.annotation.Authorization; 5 | import com.github.misterchangray.common.enums.ResultEnum; 6 | import com.github.misterchangray.common.exception.ServiceException; 7 | import com.github.misterchangray.service.common.RedisCacheService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.ResponseBody; 15 | 16 | /** 17 | * @author Created by rui.zhang on 2018/5/25. 18 | * @author rui.zhang 19 | * @version ver1.0 20 | * @email misterchangray@hotmail.com 21 | * @description 22 | */ 23 | @Controller 24 | @Authorization 25 | @RequestMapping("/v1/test") 26 | public class TestController { 27 | @Autowired 28 | RedisCacheService redisCacheService; 29 | @Autowired 30 | ThreadPoolTaskExecutor executor; 31 | 32 | @RequestMapping(value = "test1",method = RequestMethod.GET) 33 | @ResponseBody 34 | public ResultSet constant(@RequestParam(required = false) Integer pid) throws Exception { 35 | ResultSet res = ResultSet.build(); 36 | 37 | // EmailBuilder.build().sendSimpleEmail("jioulongzi@qq.com", " 914590431@qq.com", "wocao", "dajia 快看啊 阿道夫为"); 38 | // res.getData().toString(); 39 | throw new ServiceException(ResultEnum.EXIST); 40 | // return res; 41 | } 42 | 43 | @RequestMapping(value = "test2",method = RequestMethod.GET) 44 | @ResponseBody 45 | public ResultSet constant2(@RequestParam(required = false) Integer pid) throws Exception { 46 | ResultSet res = ResultSet.build(); 47 | 48 | // EmailBuilder.build().sendSimpleEmail("jioulongzi@qq.com", " 914590431@qq.com", "wocao", "dajia 快看啊 阿道夫为"); 49 | res.getData().toString(); 50 | // throw new ServiceException(ResultEnum.EXIST); 51 | return res; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/common/VerifyCodeController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller.common; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.utils.MapBuilder; 5 | import com.github.misterchangray.common.utils.VerifyCodeUtils; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import javax.servlet.http.HttpServletResponse; 15 | import javax.servlet.http.HttpSession; 16 | import java.io.IOException; 17 | 18 | /** 19 | * 简易的验证码控制器 20 | * 21 | * @author Rui.Zhang/misterchangray@hotmail.com 22 | * @author Created on 6/1/2018. 23 | */ 24 | @Api(tags ="验证码控制", description = "VerifyCodeController") 25 | @Controller 26 | @RequestMapping("/v1/verifyCode") 27 | public class VerifyCodeController { 28 | @Autowired 29 | private HttpSession httpSession; 30 | 31 | 32 | /** 33 | * 将生成的图片验证码设置到 httpSession 的 verifyCode 属性中 34 | * @param response 35 | * @return 36 | */ 37 | @ApiOperation(value = "获取图片验证码", notes = "返回图片验证码的Base64编码") 38 | @RequestMapping(value = "/img", method = RequestMethod.GET) 39 | @ResponseBody 40 | public ResultSet verifyCodeForImg(HttpServletResponse response) { 41 | int w = 200, h = 80; //图片宽高 42 | int limit = 4; //验证码长度 43 | 44 | MapBuilder mapBuilder = null; 45 | try { 46 | mapBuilder = VerifyCodeUtils.outputVerifyImage(w, h, limit); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | 51 | httpSession.setAttribute("verifyCode", mapBuilder.get("verifyCode")); 52 | 53 | StringBuilder imgBase64 = new StringBuilder("data:image/jpg;base64,"); 54 | imgBase64.append(mapBuilder.get("imgData")); 55 | return ResultSet.build().setData(imgBase64.toString()); 56 | } 57 | 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/user/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.annotation.Authorization; 5 | import com.github.misterchangray.common.enums.ResultEnum; 6 | import com.github.misterchangray.service.user.LoginService; 7 | import com.github.misterchangray.service.user.UserService; 8 | import com.github.misterchangray.service.user.bo.UserSessionBo; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiImplicitParam; 11 | import io.swagger.annotations.ApiImplicitParams; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.context.ApplicationContext; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.web.bind.annotation.*; 17 | 18 | import javax.servlet.http.HttpSession; 19 | 20 | 21 | /** 22 | * 用户认证控制器 23 | * 24 | * 提供用户登陆认证以下用能 25 | * -用户登入 26 | * -用户登出 27 | * -用户心跳更新 28 | * 29 | * 30 | * 如果项目中使用的是单点登录;则可不理会此处实现(建议保留实现);也可以删除用户相关功能(不推荐) 31 | * 因为项目登入Token校验是在 AuthInterceptor 拦截器中校验;所以只需要改变拦截器实现即可。 32 | * 33 | * @author Rui.Zhang/misterchangray@hotmail.com 34 | * @author Created on 3/23/2018. 35 | */ 36 | @Api(tags ="用户认证", description = "AuthController") 37 | @Controller 38 | @RequestMapping("/v1/session") 39 | public class LoginController { 40 | @Autowired 41 | LoginService loginService; 42 | @Autowired 43 | UserService userService; 44 | @Autowired 45 | HttpSession httpSession; 46 | @Autowired 47 | ApplicationContext applicationContext; 48 | @Autowired 49 | UserSessionBo userSessionBo; 50 | 51 | 52 | /** 53 | * 用户登陆 54 | * @param username 55 | * @param password 56 | * @return 57 | */ 58 | @ApiOperation(value = "用户登陆", notes = "提供用户登陆接口,登陆成功后返回 Authorization ,在以后的请求中应该把此字段增加到请求头中,这里可以使用(手机号,帐号,邮箱)+密码进行登录") 59 | @ApiImplicitParams({ 60 | @ApiImplicitParam(name="username", value = "用户名", required = false, paramType = "query", dataType = "string"), 61 | @ApiImplicitParam(name="email", value = "邮箱", required = false, paramType = "query", dataType = "string"), 62 | @ApiImplicitParam(name="phone", value = "手机号", required = false, paramType = "query", dataType = "string"), 63 | @ApiImplicitParam(name="password", value = "密码", required = false, paramType = "query", dataType = "string") 64 | }) 65 | @RequestMapping(value = "/signIn", method = RequestMethod.POST) 66 | @ResponseBody 67 | public ResultSet signIn(@RequestParam(required = false) String username, 68 | @RequestParam(required = false) String email, 69 | @RequestParam(required = false) String phone, 70 | @RequestParam String password) throws Exception { 71 | 72 | ResultSet res = ResultSet.build(); 73 | if((null == username && null == email && null == phone) || null == password) { 74 | res.setCode(ResultEnum.INVALID_REQUEST); 75 | return res; 76 | } 77 | if(null != username && null != password) { 78 | res = loginService.signInByUserName(username, password); 79 | } 80 | return res; 81 | } 82 | 83 | 84 | /** 85 | * 用户登出 86 | * @param token 87 | * @return 88 | */ 89 | @ApiOperation(value = "用户登出", notes = "提供用户用户登出") 90 | @ApiImplicitParams({ 91 | @ApiImplicitParam(name="Authorization", value = "用户session", required = false, paramType = "header", dataType = "string"), 92 | }) 93 | @Authorization 94 | @RequestMapping(value = "/signOut", method = RequestMethod.POST) 95 | @ResponseBody 96 | public ResultSet signOut(@RequestHeader(value = "Authentication") String token) { 97 | return loginService.signOut(token); 98 | } 99 | 100 | 101 | 102 | /** 103 | * 更新心跳 104 | * @return 105 | */ 106 | @ApiOperation(value = "心跳检测", notes = "更新心跳,每隔1分钟访问一次;如3分钟后未访问断定位离线") 107 | @Authorization 108 | @RequestMapping(value = "/heartbeat", method = RequestMethod.GET) 109 | @ResponseBody 110 | public ResultSet heartbeat(@RequestHeader("Authentication") String authentication) { 111 | userSessionBo.heartbeat(authentication); 112 | return ResultSet.build(); 113 | } 114 | 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/user/PermissionController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.PageInfo; 5 | import com.github.misterchangray.common.annotation.Authorization; 6 | import com.github.misterchangray.dao.entity.Permission; 7 | import com.github.misterchangray.service.user.PermissionService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiImplicitParam; 10 | import io.swagger.annotations.ApiImplicitParams; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | /** 17 | * 权限管理控制器 18 | * 19 | * 提供用户权限以下用能 20 | * -权限列表 21 | * -权限新增 22 | * -权限编辑 23 | * -权限删除 24 | * 25 | * @author Rui.Zhang/misterchangray@hotmail.com 26 | * @author Created on 3/23/2018. 27 | */ 28 | @Api(tags ="权限控制", description = "PermissionController") 29 | @Controller 30 | @RequestMapping("/v1/permission") 31 | public class PermissionController { 32 | @Autowired 33 | PermissionService permissionService; 34 | 35 | 36 | /** 37 | * 根据ID获取权限 38 | * @param permissionId 39 | * @return 40 | */ 41 | @ApiOperation(value = "根据ID获取权限", notes = "根据ID获取权限") 42 | @ApiImplicitParams({ 43 | @ApiImplicitParam(name="permissionId", value = "权限ID", required = true, paramType = "path", dataType = "int"), 44 | }) 45 | @Authorization 46 | @RequestMapping(value="/{permissionId}", method = RequestMethod.GET) 47 | @ResponseBody 48 | public ResultSet getById(@PathVariable Integer permissionId) { 49 | ResultSet res = permissionService.getById(permissionId); 50 | return res; 51 | } 52 | 53 | 54 | /** 55 | * 权限列表 56 | * @param page 57 | * @param limit 58 | * @return 59 | */ 60 | @ApiOperation(value = "权限列表", notes = "获取权限列表") 61 | @ApiImplicitParams({ 62 | @ApiImplicitParam(name="page", value = "页码", required = true, paramType = "query", dataType = "int"), 63 | @ApiImplicitParam(name="limit", value = "每页条数", required = true, paramType = "query", dataType = "int"), 64 | }) 65 | @Authorization 66 | @RequestMapping(method = RequestMethod.GET) 67 | @ResponseBody 68 | public ResultSet list(@RequestParam() Integer page, @RequestParam() Integer limit) { 69 | Permission permission = new Permission(); 70 | return permissionService.list(permission, PageInfo.newInstance(page, limit)); 71 | } 72 | 73 | /** 74 | * 新增权限 75 | * @param permission 76 | * @return 77 | */ 78 | @ApiOperation(value = "新增权限", notes = "新增权限") 79 | @ApiImplicitParams({ 80 | @ApiImplicitParam(name="permission", value = "权限实体JSON对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.Permission"), 81 | }) 82 | @Authorization 83 | @RequestMapping(method = RequestMethod.POST) 84 | @ResponseBody 85 | public ResultSet add(@RequestBody Permission permission) { 86 | return permissionService.save(permission); 87 | } 88 | 89 | 90 | /** 91 | * 删除权限 92 | * @param id 93 | * @return 94 | */ 95 | @ApiOperation(value = "删除权限", notes = "根据ID删除权限") 96 | @ApiImplicitParams({ 97 | @ApiImplicitParam(name="id", value = "权限ID", required = true, paramType = "path", dataType = "int"), 98 | }) 99 | @Authorization 100 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 101 | @ResponseBody 102 | public ResultSet delete(@PathVariable Integer id) { 103 | Permission permission = new Permission(); 104 | permission.setId(id); 105 | return permissionService.delete(permission); 106 | } 107 | 108 | 109 | /** 110 | * 编辑权限 111 | * @param permission 112 | * @return 113 | */ 114 | @ApiOperation(value = "编辑权限", notes = "根据ID编辑权限") 115 | @ApiImplicitParams({ 116 | @ApiImplicitParam(name="permission", value = "权限实体JSON对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.Permission"), 117 | }) 118 | @Authorization 119 | @RequestMapping(method = RequestMethod.PUT) 120 | @ResponseBody 121 | public ResultSet edit(@RequestBody Permission permission) { 122 | return permissionService.edit(permission); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/user/RoleController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.PageInfo; 5 | import com.github.misterchangray.common.enums.ResultEnum; 6 | import com.github.misterchangray.service.user.PermissionService; 7 | import com.github.misterchangray.service.user.RoleService; 8 | import com.github.misterchangray.common.annotation.Authorization; 9 | import com.github.misterchangray.dao.entity.Role; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiImplicitParam; 12 | import io.swagger.annotations.ApiImplicitParams; 13 | import io.swagger.annotations.ApiOperation; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.web.bind.annotation.*; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 角色管理控制器 22 | * 23 | * 提供用户角色以下用能 24 | * -角色列表 25 | * -角色新增 26 | * -角色编辑 27 | * -角色启用/停用 28 | * -角色删除 29 | * -角色权限编辑 30 | * 31 | * @author Rui.Zhang/misterchangray@hotmail.com 32 | * @author Created on 3/23/2018. 33 | */ 34 | @Api(tags ="角色管理", description = "RoleController") 35 | @Controller 36 | @RequestMapping("/v1/role") 37 | public class RoleController { 38 | @Autowired 39 | PermissionService permissionService; 40 | @Autowired 41 | RoleService roleService; 42 | 43 | /** 44 | * 编辑角色权限 45 | * @param roleId 46 | * @return 47 | */ 48 | @ApiOperation(value = "编辑角色权限", notes = "编辑角色下的权限") 49 | @ApiImplicitParams({ 50 | @ApiImplicitParam(name="roleId", value = "角色ID", required = true, paramType = "query", dataType = "int"), 51 | @ApiImplicitParam(name="permissionIds", value = "权限ID", required = true, paramType = "form", dataType = "int"), 52 | }) 53 | @Authorization 54 | @RequestMapping(value="/{roleId}/permission", method = RequestMethod.PATCH) 55 | @ResponseBody 56 | public ResultSet editRolePermission(@PathVariable Integer roleId, @RequestParam List permissionIds) { 57 | ResultSet resultSet = ResultSet.build(); 58 | if(null != roleId && null != permissionIds && 0 < permissionIds.size()) { 59 | return roleService.updatePermission(roleId, permissionIds); 60 | } 61 | return resultSet.setCode(ResultEnum.INVALID_REQUEST); 62 | } 63 | 64 | 65 | /** 66 | * 获取角色列表 67 | * @param limit 68 | * @return 69 | */ 70 | @ApiOperation(value = "获取角色列表", notes = "获取角色列表") 71 | @ApiImplicitParams({ 72 | @ApiImplicitParam(name="page", value = "页码", required = true, paramType = "query", dataType = "int"), 73 | @ApiImplicitParam(name="limit", value = "每页条数", required = true, paramType = "query", dataType = "int"), 74 | }) 75 | @Authorization 76 | @RequestMapping(method = RequestMethod.GET) 77 | @ResponseBody 78 | public ResultSet list(@RequestParam Integer page, @RequestParam Integer limit) { 79 | Role role = new Role(); 80 | return roleService.list(role, PageInfo.newInstance(page, limit)); 81 | } 82 | 83 | /** 84 | * 新增角色 85 | * @param role 86 | * @return 87 | */ 88 | @ApiOperation(value = "新增角色", notes = "新增角色") 89 | @ApiImplicitParams({ 90 | @ApiImplicitParam(name="role", value = "角色实体对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.Role"), 91 | }) 92 | @Authorization 93 | @RequestMapping(method = RequestMethod.POST) 94 | @ResponseBody 95 | public ResultSet add(@RequestBody Role role) { 96 | return roleService.save(role); 97 | } 98 | 99 | 100 | /** 101 | * 删除角色 102 | * @param id 103 | * @return 104 | */ 105 | @ApiOperation(value = "删除角色", notes = "根据ID删除角色") 106 | @ApiImplicitParams({ 107 | @ApiImplicitParam(name="id", value = "角色ID", required = true, paramType = "path", dataType = "int"), 108 | }) 109 | @Authorization 110 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 111 | @ResponseBody 112 | public ResultSet delete(@PathVariable("id") Integer id) { 113 | Role role = new Role(); 114 | role.setId(id); 115 | return roleService.delete(role); 116 | } 117 | 118 | 119 | /** 120 | * 编辑角色 121 | * @param role 122 | * @return 123 | */ 124 | @ApiOperation(value = "编辑角色", notes = "根据ID编辑角色") 125 | @ApiImplicitParams({ 126 | @ApiImplicitParam(name="role", value = "角色实体对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.Role"), 127 | }) 128 | @Authorization 129 | @RequestMapping(method = RequestMethod.PUT) 130 | @ResponseBody 131 | public ResultSet edit(@RequestBody Role role) { 132 | return roleService.edit(role); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/controller/user/UserController.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.controller.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.PageInfo; 5 | import com.github.misterchangray.common.annotation.Authorization; 6 | import com.github.misterchangray.common.annotation.OperationLog; 7 | import com.github.misterchangray.dao.entity.User; 8 | import com.github.misterchangray.service.user.UserService; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiImplicitParam; 11 | import io.swagger.annotations.ApiImplicitParams; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Controller; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import java.util.List; 18 | 19 | /** 20 | * 用户管理控制器 21 | * 22 | * 提供用户管理以下用能 23 | * -根据ID获取指定用户 24 | * -用户列表 25 | * -用户新增 26 | * -用户删除 27 | * -用户启用/停用 28 | * -用户编辑 29 | * -用户角色编辑 30 | * -检查用户信息是否存在 31 | * 32 | * @author Rui.Zhang/misterchangray@hotmail.com 33 | * @author Created on 3/23/2018. 34 | */ 35 | @Api(tags ="用户管理", description = "UserController") 36 | @Controller 37 | @RequestMapping("/v1/user") 38 | @Authorization 39 | public class UserController { 40 | @Autowired 41 | UserService userService; 42 | 43 | 44 | 45 | /** 46 | * 检查用户信息是否存在 47 | * @param username 用户名 48 | * @param phone 手机号 49 | * @param idcard 身份证 50 | * @param email 邮箱 51 | * @return 52 | */ 53 | @ApiOperation(value = "用户信息校验", notes = "检查用户信息是否已经注册,true表示已经注册,false为未注册") 54 | @ApiImplicitParams({ 55 | @ApiImplicitParam(name="username", value = "用户名", required = false, paramType = "query", dataType = "string"), 56 | @ApiImplicitParam(name="phone", value = "手机号", required = false, paramType = "query", dataType = "string"), 57 | @ApiImplicitParam(name="idcard", value = "身份证", required = false, paramType = "query", dataType = "string"), 58 | @ApiImplicitParam(name="email", value = "邮箱", required = false, paramType = "query", dataType = "string"), 59 | }) 60 | @RequestMapping(value = "/checkUserInfo", method = RequestMethod.POST) 61 | @ResponseBody 62 | public ResultSet checkUser(@RequestParam(required = false) String username, 63 | @RequestParam(required = false) String phone, 64 | @RequestParam(required = false) String idcard, 65 | @RequestParam(required = false) String email) { 66 | 67 | return userService.checkUserInfo(username, email, phone, idcard); 68 | } 69 | 70 | /** 71 | * 编辑用户角色 72 | * @param userId 用户id 73 | * @param roleIds 角色Id集合 74 | * @return 75 | */ 76 | @ApiOperation(value = "编辑用户角色", notes = "编辑用户下的角色") 77 | @ApiImplicitParams({ 78 | @ApiImplicitParam(name="userId", value = "用户ID", required = true, paramType = "path", dataType = "int"), 79 | @ApiImplicitParam(name="roleIds", value = "角色ID", required = true, paramType = "query", dataType = "int", allowMultiple = true), 80 | }) 81 | @RequestMapping(value="/{userId}/role", method = RequestMethod.PATCH) 82 | @ResponseBody 83 | public ResultSet editUserRole(@PathVariable Integer userId, @RequestParam List roleIds) { 84 | return userService.updateRole(userId, roleIds); 85 | } 86 | 87 | /** 88 | * 根据ID获取用户 89 | * @param userId 90 | * @return 91 | */ 92 | @ApiOperation(value = "根据ID获取用户", notes = "根据ID获取用户") 93 | @ApiImplicitParams({ 94 | @ApiImplicitParam(name="userId", value = "用户ID", required = true, paramType = "path", dataType = "int"), 95 | }) 96 | @RequestMapping(value="/{userId}", method = RequestMethod.GET) 97 | @ResponseBody 98 | public ResultSet getById(@PathVariable Integer userId) { 99 | return userService.getById(userId); 100 | } 101 | 102 | 103 | /** 104 | * 用户列表 105 | * @param limit 106 | * @return 107 | */ 108 | @ApiOperation(value = "用户列表", notes = "获取用户列表") 109 | @ApiImplicitParams({ 110 | @ApiImplicitParam(name="page", value = "页码", required = true, paramType = "query", dataType = "int"), 111 | @ApiImplicitParam(name="limit", value = "每页条数", required = true, paramType = "query", dataType = "int"), 112 | }) 113 | @RequestMapping(method = RequestMethod.GET) 114 | @ResponseBody 115 | public ResultSet list(@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) { 116 | User user = new User(); 117 | 118 | return userService.list(user, PageInfo.newInstance(page, limit)); 119 | } 120 | 121 | /** 122 | * 新增用户 123 | * @param user 124 | * @return 125 | */ 126 | @ApiOperation(value = "新增用户", notes = "新增用户") 127 | @ApiImplicitParams({ 128 | @ApiImplicitParam(name="user", value = "用户实体JSON对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.User"), 129 | }) 130 | @OperationLog(businessName = "新增用户") 131 | @RequestMapping(method = RequestMethod.POST) 132 | @ResponseBody 133 | public ResultSet add(@RequestBody User user) { 134 | return userService.save(user); 135 | } 136 | 137 | 138 | /** 139 | * 删除用户 140 | * @param id 141 | * @return 142 | */ 143 | @ApiOperation(value = "删除用户", notes = "删除用户") 144 | @ApiImplicitParams({ 145 | @ApiImplicitParam(name="id", value = "根据ID删除用户", required = true, paramType = "path", dataType = "int"), 146 | }) 147 | @RequestMapping(value = "{id}", method = RequestMethod.DELETE) 148 | @ResponseBody 149 | public ResultSet delete(@PathVariable(value = "id") Integer id) { 150 | User user = new User(); 151 | user.setId(id); 152 | return userService.delete(user); 153 | } 154 | 155 | 156 | /** 157 | * 编辑用户 158 | * @param user 159 | * @return 160 | */ 161 | @ApiOperation(value = "编辑用户", notes = "编辑用户") 162 | @ApiImplicitParams({ 163 | @ApiImplicitParam(name="user", value = "用户实体JSON对象", required = true, paramType = "body", dataType = "com.github.misterchangray.dao.entity.User"), 164 | }) 165 | @RequestMapping(method = RequestMethod.PUT) 166 | @ResponseBody 167 | public ResultSet edit(@RequestBody User user) { 168 | return userService.edit(user); 169 | } 170 | 171 | 172 | 173 | } 174 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/Constant.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(value="com.github.misterchangray.dao.entity.Constant") 7 | public class Constant { 8 | @ApiModelProperty(value="id") 9 | private String id; 10 | 11 | @ApiModelProperty(value="name常量名称") 12 | private String name; 13 | 14 | @ApiModelProperty(value="shortcut常量简称,用于快速定位") 15 | private String shortcut; 16 | 17 | @ApiModelProperty(value="pid父ID,null为根节点") 18 | private String pid; 19 | 20 | @ApiModelProperty(value="hasChild是否有子节点0false,1true") 21 | private Integer hasChild; 22 | 23 | @ApiModelProperty(value="enabled是否启用0false,1true") 24 | private Integer enabled; 25 | 26 | @ApiModelProperty(value="deleted是否删除0false, 1true") 27 | private Integer deleted; 28 | 29 | @ApiModelProperty(value="extra附加数据;推荐存JSON") 30 | private String extra; 31 | 32 | @ApiModelProperty(value="priority") 33 | private Integer priority; 34 | 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | public Constant setId(String id) { 40 | this.id = id == null ? null : id.trim(); 41 | return this; 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public Constant setName(String name) { 49 | this.name = name == null ? null : name.trim(); 50 | return this; 51 | } 52 | 53 | public String getShortcut() { 54 | return shortcut; 55 | } 56 | 57 | public Constant setShortcut(String shortcut) { 58 | this.shortcut = shortcut == null ? null : shortcut.trim(); 59 | return this; 60 | } 61 | 62 | public String getPid() { 63 | return pid; 64 | } 65 | 66 | public Constant setPid(String pid) { 67 | this.pid = pid == null ? null : pid.trim(); 68 | return this; 69 | } 70 | 71 | public Integer getHasChild() { 72 | return hasChild; 73 | } 74 | 75 | public Constant setHasChild(Integer hasChild) { 76 | this.hasChild = hasChild; 77 | return this; 78 | } 79 | 80 | public Integer getEnabled() { 81 | return enabled; 82 | } 83 | 84 | public Constant setEnabled(Integer enabled) { 85 | this.enabled = enabled; 86 | return this; 87 | } 88 | 89 | public Integer getDeleted() { 90 | return deleted; 91 | } 92 | 93 | public Constant setDeleted(Integer deleted) { 94 | this.deleted = deleted; 95 | return this; 96 | } 97 | 98 | public String getExtra() { 99 | return extra; 100 | } 101 | 102 | public Constant setExtra(String extra) { 103 | this.extra = extra == null ? null : extra.trim(); 104 | return this; 105 | } 106 | 107 | public Integer getPriority() { 108 | return priority; 109 | } 110 | 111 | public Constant setPriority(Integer priority) { 112 | this.priority = priority; 113 | return this; 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | StringBuilder sb = new StringBuilder(); 119 | sb.append(getClass().getSimpleName()); 120 | sb.append(" ["); 121 | sb.append("Hash = ").append(hashCode()); 122 | sb.append(", id=").append(id); 123 | sb.append(", name=").append(name); 124 | sb.append(", shortcut=").append(shortcut); 125 | sb.append(", pid=").append(pid); 126 | sb.append(", hasChild=").append(hasChild); 127 | sb.append(", enabled=").append(enabled); 128 | sb.append(", deleted=").append(deleted); 129 | sb.append(", extra=").append(extra); 130 | sb.append(", priority=").append(priority); 131 | sb.append("]"); 132 | return sb.toString(); 133 | } 134 | 135 | /** 136 | * This enum was generated by MyBatis Generator. 137 | * This enum corresponds to the database table constant 138 | * 139 | * @mbg.generated 140 | * @project https://github.com/itfsw/mybatis-generator-plugin 141 | */ 142 | public enum Column { 143 | id("id"), 144 | name("name"), 145 | shortcut("shortcut"), 146 | pid("pid"), 147 | hasChild("has_child"), 148 | enabled("enabled"), 149 | deleted("deleted"), 150 | extra("extra"), 151 | priority("priority"); 152 | 153 | /** 154 | * This field was generated by MyBatis Generator. 155 | * This field corresponds to the database table constant 156 | * 157 | * @mbg.generated 158 | * @project https://github.com/itfsw/mybatis-generator-plugin 159 | */ 160 | private final String column; 161 | 162 | /** 163 | * This method was generated by MyBatis Generator. 164 | * This method corresponds to the database table constant 165 | * 166 | * @mbg.generated 167 | * @project https://github.com/itfsw/mybatis-generator-plugin 168 | */ 169 | public String value() { 170 | return this.column; 171 | } 172 | 173 | /** 174 | * This method was generated by MyBatis Generator. 175 | * This method corresponds to the database table constant 176 | * 177 | * @mbg.generated 178 | * @project https://github.com/itfsw/mybatis-generator-plugin 179 | */ 180 | public String getValue() { 181 | return this.column; 182 | } 183 | 184 | /** 185 | * This method was generated by MyBatis Generator. 186 | * This method corresponds to the database table constant 187 | * 188 | * @mbg.generated 189 | * @project https://github.com/itfsw/mybatis-generator-plugin 190 | */ 191 | Column(String column) { 192 | this.column = column; 193 | } 194 | 195 | /** 196 | * This method was generated by MyBatis Generator. 197 | * This method corresponds to the database table constant 198 | * 199 | * @mbg.generated 200 | * @project https://github.com/itfsw/mybatis-generator-plugin 201 | */ 202 | public String desc() { 203 | return this.column + " DESC"; 204 | } 205 | 206 | /** 207 | * This method was generated by MyBatis Generator. 208 | * This method corresponds to the database table constant 209 | * 210 | * @mbg.generated 211 | * @project https://github.com/itfsw/mybatis-generator-plugin 212 | */ 213 | public String asc() { 214 | return this.column + " ASC"; 215 | } 216 | } 217 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/OperationLog.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import java.util.Date; 6 | 7 | @ApiModel(value="com.github.misterchangray.dao.entity.OperationLog") 8 | public class OperationLog { 9 | @ApiModelProperty(value="id") 10 | private Integer id; 11 | 12 | @ApiModelProperty(value="signature调用方法的限定名") 13 | private String signature; 14 | 15 | @ApiModelProperty(value="businessName方法的业务名称") 16 | private String businessName; 17 | 18 | @ApiModelProperty(value="userId操作人用户表ID") 19 | private Integer userId; 20 | 21 | @ApiModelProperty(value="userName操作人名称") 22 | private String userName; 23 | 24 | @ApiModelProperty(value="createDate") 25 | private Date createDate; 26 | 27 | @ApiModelProperty(value="data") 28 | private String data; 29 | 30 | public Integer getId() { 31 | return id; 32 | } 33 | 34 | public OperationLog setId(Integer id) { 35 | this.id = id; 36 | return this; 37 | } 38 | 39 | public String getSignature() { 40 | return signature; 41 | } 42 | 43 | public OperationLog setSignature(String signature) { 44 | this.signature = signature == null ? null : signature.trim(); 45 | return this; 46 | } 47 | 48 | public String getBusinessName() { 49 | return businessName; 50 | } 51 | 52 | public OperationLog setBusinessName(String businessName) { 53 | this.businessName = businessName == null ? null : businessName.trim(); 54 | return this; 55 | } 56 | 57 | public Integer getUserId() { 58 | return userId; 59 | } 60 | 61 | public OperationLog setUserId(Integer userId) { 62 | this.userId = userId; 63 | return this; 64 | } 65 | 66 | public String getUserName() { 67 | return userName; 68 | } 69 | 70 | public OperationLog setUserName(String userName) { 71 | this.userName = userName == null ? null : userName.trim(); 72 | return this; 73 | } 74 | 75 | public Date getCreateDate() { 76 | return createDate; 77 | } 78 | 79 | public OperationLog setCreateDate(Date createDate) { 80 | this.createDate = createDate; 81 | return this; 82 | } 83 | 84 | public String getData() { 85 | return data; 86 | } 87 | 88 | public OperationLog setData(String data) { 89 | this.data = data == null ? null : data.trim(); 90 | return this; 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | StringBuilder sb = new StringBuilder(); 96 | sb.append(getClass().getSimpleName()); 97 | sb.append(" ["); 98 | sb.append("Hash = ").append(hashCode()); 99 | sb.append(", id=").append(id); 100 | sb.append(", signature=").append(signature); 101 | sb.append(", businessName=").append(businessName); 102 | sb.append(", userId=").append(userId); 103 | sb.append(", userName=").append(userName); 104 | sb.append(", createDate=").append(createDate); 105 | sb.append(", data=").append(data); 106 | sb.append("]"); 107 | return sb.toString(); 108 | } 109 | 110 | /** 111 | * This enum was generated by MyBatis Generator. 112 | * This enum corresponds to the database table operation_log 113 | * 114 | * @mbg.generated 115 | * @project https://github.com/itfsw/mybatis-generator-plugin 116 | */ 117 | public enum Column { 118 | id("id"), 119 | signature("Signature"), 120 | businessName("business_name"), 121 | userId("user_id"), 122 | userName("user_name"), 123 | createDate("create_date"), 124 | data("data"); 125 | 126 | /** 127 | * This field was generated by MyBatis Generator. 128 | * This field corresponds to the database table operation_log 129 | * 130 | * @mbg.generated 131 | * @project https://github.com/itfsw/mybatis-generator-plugin 132 | */ 133 | private final String column; 134 | 135 | /** 136 | * This method was generated by MyBatis Generator. 137 | * This method corresponds to the database table operation_log 138 | * 139 | * @mbg.generated 140 | * @project https://github.com/itfsw/mybatis-generator-plugin 141 | */ 142 | public String value() { 143 | return this.column; 144 | } 145 | 146 | /** 147 | * This method was generated by MyBatis Generator. 148 | * This method corresponds to the database table operation_log 149 | * 150 | * @mbg.generated 151 | * @project https://github.com/itfsw/mybatis-generator-plugin 152 | */ 153 | public String getValue() { 154 | return this.column; 155 | } 156 | 157 | /** 158 | * This method was generated by MyBatis Generator. 159 | * This method corresponds to the database table operation_log 160 | * 161 | * @mbg.generated 162 | * @project https://github.com/itfsw/mybatis-generator-plugin 163 | */ 164 | Column(String column) { 165 | this.column = column; 166 | } 167 | 168 | /** 169 | * This method was generated by MyBatis Generator. 170 | * This method corresponds to the database table operation_log 171 | * 172 | * @mbg.generated 173 | * @project https://github.com/itfsw/mybatis-generator-plugin 174 | */ 175 | public String desc() { 176 | return this.column + " DESC"; 177 | } 178 | 179 | /** 180 | * This method was generated by MyBatis Generator. 181 | * This method corresponds to the database table operation_log 182 | * 183 | * @mbg.generated 184 | * @project https://github.com/itfsw/mybatis-generator-plugin 185 | */ 186 | public String asc() { 187 | return this.column + " ASC"; 188 | } 189 | } 190 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/Permission.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(value="com.github.misterchangray.dao.entity.Permission") 7 | public class Permission { 8 | @ApiModelProperty(value="id") 9 | private Integer id; 10 | 11 | @ApiModelProperty(value="name") 12 | private String name; 13 | 14 | @ApiModelProperty(value="deleted是否删除0false, 1true") 15 | private Integer deleted; 16 | 17 | @ApiModelProperty(value="uri") 18 | private String uri; 19 | 20 | @ApiModelProperty(value="type1菜单2按钮") 21 | private Integer type; 22 | 23 | @ApiModelProperty(value="puri") 24 | private String puri; 25 | 26 | public Integer getId() { 27 | return id; 28 | } 29 | 30 | public Permission setId(Integer id) { 31 | this.id = id; 32 | return this; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public Permission setName(String name) { 40 | this.name = name == null ? null : name.trim(); 41 | return this; 42 | } 43 | 44 | public Integer getDeleted() { 45 | return deleted; 46 | } 47 | 48 | public Permission setDeleted(Integer deleted) { 49 | this.deleted = deleted; 50 | return this; 51 | } 52 | 53 | public String getUri() { 54 | return uri; 55 | } 56 | 57 | public Permission setUri(String uri) { 58 | this.uri = uri == null ? null : uri.trim(); 59 | return this; 60 | } 61 | 62 | public Integer getType() { 63 | return type; 64 | } 65 | 66 | public Permission setType(Integer type) { 67 | this.type = type; 68 | return this; 69 | } 70 | 71 | public String getPuri() { 72 | return puri; 73 | } 74 | 75 | public Permission setPuri(String puri) { 76 | this.puri = puri == null ? null : puri.trim(); 77 | return this; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | StringBuilder sb = new StringBuilder(); 83 | sb.append(getClass().getSimpleName()); 84 | sb.append(" ["); 85 | sb.append("Hash = ").append(hashCode()); 86 | sb.append(", id=").append(id); 87 | sb.append(", name=").append(name); 88 | sb.append(", deleted=").append(deleted); 89 | sb.append(", uri=").append(uri); 90 | sb.append(", type=").append(type); 91 | sb.append(", puri=").append(puri); 92 | sb.append("]"); 93 | return sb.toString(); 94 | } 95 | 96 | /** 97 | * This enum was generated by MyBatis Generator. 98 | * This enum corresponds to the database table permission 99 | * 100 | * @mbg.generated 101 | * @project https://github.com/itfsw/mybatis-generator-plugin 102 | */ 103 | public enum Column { 104 | id("id"), 105 | name("name"), 106 | deleted("deleted"), 107 | uri("uri"), 108 | type("type"), 109 | puri("puri"); 110 | 111 | /** 112 | * This field was generated by MyBatis Generator. 113 | * This field corresponds to the database table permission 114 | * 115 | * @mbg.generated 116 | * @project https://github.com/itfsw/mybatis-generator-plugin 117 | */ 118 | private final String column; 119 | 120 | /** 121 | * This method was generated by MyBatis Generator. 122 | * This method corresponds to the database table permission 123 | * 124 | * @mbg.generated 125 | * @project https://github.com/itfsw/mybatis-generator-plugin 126 | */ 127 | public String value() { 128 | return this.column; 129 | } 130 | 131 | /** 132 | * This method was generated by MyBatis Generator. 133 | * This method corresponds to the database table permission 134 | * 135 | * @mbg.generated 136 | * @project https://github.com/itfsw/mybatis-generator-plugin 137 | */ 138 | public String getValue() { 139 | return this.column; 140 | } 141 | 142 | /** 143 | * This method was generated by MyBatis Generator. 144 | * This method corresponds to the database table permission 145 | * 146 | * @mbg.generated 147 | * @project https://github.com/itfsw/mybatis-generator-plugin 148 | */ 149 | Column(String column) { 150 | this.column = column; 151 | } 152 | 153 | /** 154 | * This method was generated by MyBatis Generator. 155 | * This method corresponds to the database table permission 156 | * 157 | * @mbg.generated 158 | * @project https://github.com/itfsw/mybatis-generator-plugin 159 | */ 160 | public String desc() { 161 | return this.column + " DESC"; 162 | } 163 | 164 | /** 165 | * This method was generated by MyBatis Generator. 166 | * This method corresponds to the database table permission 167 | * 168 | * @mbg.generated 169 | * @project https://github.com/itfsw/mybatis-generator-plugin 170 | */ 171 | public String asc() { 172 | return this.column + " ASC"; 173 | } 174 | } 175 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(value="com.github.misterchangray.dao.entity.Role") 7 | public class Role { 8 | @ApiModelProperty(value="id") 9 | private Integer id; 10 | 11 | @ApiModelProperty(value="name") 12 | private String name; 13 | 14 | @ApiModelProperty(value="enabled是否启用0false, 1true") 15 | private Integer enabled; 16 | 17 | @ApiModelProperty(value="deleted是否删除0false, 1true") 18 | private Integer deleted; 19 | 20 | public Integer getId() { 21 | return id; 22 | } 23 | 24 | public Role setId(Integer id) { 25 | this.id = id; 26 | return this; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public Role setName(String name) { 34 | this.name = name == null ? null : name.trim(); 35 | return this; 36 | } 37 | 38 | public Integer getEnabled() { 39 | return enabled; 40 | } 41 | 42 | public Role setEnabled(Integer enabled) { 43 | this.enabled = enabled; 44 | return this; 45 | } 46 | 47 | public Integer getDeleted() { 48 | return deleted; 49 | } 50 | 51 | public Role setDeleted(Integer deleted) { 52 | this.deleted = deleted; 53 | return this; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | StringBuilder sb = new StringBuilder(); 59 | sb.append(getClass().getSimpleName()); 60 | sb.append(" ["); 61 | sb.append("Hash = ").append(hashCode()); 62 | sb.append(", id=").append(id); 63 | sb.append(", name=").append(name); 64 | sb.append(", enabled=").append(enabled); 65 | sb.append(", deleted=").append(deleted); 66 | sb.append("]"); 67 | return sb.toString(); 68 | } 69 | 70 | /** 71 | * This enum was generated by MyBatis Generator. 72 | * This enum corresponds to the database table role 73 | * 74 | * @mbg.generated 75 | * @project https://github.com/itfsw/mybatis-generator-plugin 76 | */ 77 | public enum Column { 78 | id("id"), 79 | name("name"), 80 | enabled("enabled"), 81 | deleted("deleted"); 82 | 83 | /** 84 | * This field was generated by MyBatis Generator. 85 | * This field corresponds to the database table role 86 | * 87 | * @mbg.generated 88 | * @project https://github.com/itfsw/mybatis-generator-plugin 89 | */ 90 | private final String column; 91 | 92 | /** 93 | * This method was generated by MyBatis Generator. 94 | * This method corresponds to the database table role 95 | * 96 | * @mbg.generated 97 | * @project https://github.com/itfsw/mybatis-generator-plugin 98 | */ 99 | public String value() { 100 | return this.column; 101 | } 102 | 103 | /** 104 | * This method was generated by MyBatis Generator. 105 | * This method corresponds to the database table role 106 | * 107 | * @mbg.generated 108 | * @project https://github.com/itfsw/mybatis-generator-plugin 109 | */ 110 | public String getValue() { 111 | return this.column; 112 | } 113 | 114 | /** 115 | * This method was generated by MyBatis Generator. 116 | * This method corresponds to the database table role 117 | * 118 | * @mbg.generated 119 | * @project https://github.com/itfsw/mybatis-generator-plugin 120 | */ 121 | Column(String column) { 122 | this.column = column; 123 | } 124 | 125 | /** 126 | * This method was generated by MyBatis Generator. 127 | * This method corresponds to the database table role 128 | * 129 | * @mbg.generated 130 | * @project https://github.com/itfsw/mybatis-generator-plugin 131 | */ 132 | public String desc() { 133 | return this.column + " DESC"; 134 | } 135 | 136 | /** 137 | * This method was generated by MyBatis Generator. 138 | * This method corresponds to the database table role 139 | * 140 | * @mbg.generated 141 | * @project https://github.com/itfsw/mybatis-generator-plugin 142 | */ 143 | public String asc() { 144 | return this.column + " ASC"; 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/RolePermissionMap.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(value="com.github.misterchangray.dao.entity.RolePermissionMap") 7 | public class RolePermissionMap { 8 | @ApiModelProperty(value="id") 9 | private Integer id; 10 | 11 | @ApiModelProperty(value="roleId") 12 | private Integer roleId; 13 | 14 | @ApiModelProperty(value="permissionId") 15 | private Integer permissionId; 16 | 17 | @ApiModelProperty(value="deleted是否删除0false, 1true") 18 | private Integer deleted; 19 | 20 | public Integer getId() { 21 | return id; 22 | } 23 | 24 | public RolePermissionMap setId(Integer id) { 25 | this.id = id; 26 | return this; 27 | } 28 | 29 | public Integer getRoleId() { 30 | return roleId; 31 | } 32 | 33 | public RolePermissionMap setRoleId(Integer roleId) { 34 | this.roleId = roleId; 35 | return this; 36 | } 37 | 38 | public Integer getPermissionId() { 39 | return permissionId; 40 | } 41 | 42 | public RolePermissionMap setPermissionId(Integer permissionId) { 43 | this.permissionId = permissionId; 44 | return this; 45 | } 46 | 47 | public Integer getDeleted() { 48 | return deleted; 49 | } 50 | 51 | public RolePermissionMap setDeleted(Integer deleted) { 52 | this.deleted = deleted; 53 | return this; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | StringBuilder sb = new StringBuilder(); 59 | sb.append(getClass().getSimpleName()); 60 | sb.append(" ["); 61 | sb.append("Hash = ").append(hashCode()); 62 | sb.append(", id=").append(id); 63 | sb.append(", roleId=").append(roleId); 64 | sb.append(", permissionId=").append(permissionId); 65 | sb.append(", deleted=").append(deleted); 66 | sb.append("]"); 67 | return sb.toString(); 68 | } 69 | 70 | /** 71 | * This enum was generated by MyBatis Generator. 72 | * This enum corresponds to the database table role_permission_map 73 | * 74 | * @mbg.generated 75 | * @project https://github.com/itfsw/mybatis-generator-plugin 76 | */ 77 | public enum Column { 78 | id("id"), 79 | roleId("role_id"), 80 | permissionId("permission_id"), 81 | deleted("deleted"); 82 | 83 | /** 84 | * This field was generated by MyBatis Generator. 85 | * This field corresponds to the database table role_permission_map 86 | * 87 | * @mbg.generated 88 | * @project https://github.com/itfsw/mybatis-generator-plugin 89 | */ 90 | private final String column; 91 | 92 | /** 93 | * This method was generated by MyBatis Generator. 94 | * This method corresponds to the database table role_permission_map 95 | * 96 | * @mbg.generated 97 | * @project https://github.com/itfsw/mybatis-generator-plugin 98 | */ 99 | public String value() { 100 | return this.column; 101 | } 102 | 103 | /** 104 | * This method was generated by MyBatis Generator. 105 | * This method corresponds to the database table role_permission_map 106 | * 107 | * @mbg.generated 108 | * @project https://github.com/itfsw/mybatis-generator-plugin 109 | */ 110 | public String getValue() { 111 | return this.column; 112 | } 113 | 114 | /** 115 | * This method was generated by MyBatis Generator. 116 | * This method corresponds to the database table role_permission_map 117 | * 118 | * @mbg.generated 119 | * @project https://github.com/itfsw/mybatis-generator-plugin 120 | */ 121 | Column(String column) { 122 | this.column = column; 123 | } 124 | 125 | /** 126 | * This method was generated by MyBatis Generator. 127 | * This method corresponds to the database table role_permission_map 128 | * 129 | * @mbg.generated 130 | * @project https://github.com/itfsw/mybatis-generator-plugin 131 | */ 132 | public String desc() { 133 | return this.column + " DESC"; 134 | } 135 | 136 | /** 137 | * This method was generated by MyBatis Generator. 138 | * This method corresponds to the database table role_permission_map 139 | * 140 | * @mbg.generated 141 | * @project https://github.com/itfsw/mybatis-generator-plugin 142 | */ 143 | public String asc() { 144 | return this.column + " ASC"; 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/entity/UserRoleMap.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(value="com.github.misterchangray.dao.entity.UserRoleMap") 7 | public class UserRoleMap { 8 | @ApiModelProperty(value="id") 9 | private Integer id; 10 | 11 | @ApiModelProperty(value="userId") 12 | private Integer userId; 13 | 14 | @ApiModelProperty(value="roleId") 15 | private Integer roleId; 16 | 17 | @ApiModelProperty(value="deleted是否删除0false, 1true") 18 | private Integer deleted; 19 | 20 | public Integer getId() { 21 | return id; 22 | } 23 | 24 | public UserRoleMap setId(Integer id) { 25 | this.id = id; 26 | return this; 27 | } 28 | 29 | public Integer getUserId() { 30 | return userId; 31 | } 32 | 33 | public UserRoleMap setUserId(Integer userId) { 34 | this.userId = userId; 35 | return this; 36 | } 37 | 38 | public Integer getRoleId() { 39 | return roleId; 40 | } 41 | 42 | public UserRoleMap setRoleId(Integer roleId) { 43 | this.roleId = roleId; 44 | return this; 45 | } 46 | 47 | public Integer getDeleted() { 48 | return deleted; 49 | } 50 | 51 | public UserRoleMap setDeleted(Integer deleted) { 52 | this.deleted = deleted; 53 | return this; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | StringBuilder sb = new StringBuilder(); 59 | sb.append(getClass().getSimpleName()); 60 | sb.append(" ["); 61 | sb.append("Hash = ").append(hashCode()); 62 | sb.append(", id=").append(id); 63 | sb.append(", userId=").append(userId); 64 | sb.append(", roleId=").append(roleId); 65 | sb.append(", deleted=").append(deleted); 66 | sb.append("]"); 67 | return sb.toString(); 68 | } 69 | 70 | /** 71 | * This enum was generated by MyBatis Generator. 72 | * This enum corresponds to the database table user_role_map 73 | * 74 | * @mbg.generated 75 | * @project https://github.com/itfsw/mybatis-generator-plugin 76 | */ 77 | public enum Column { 78 | id("id"), 79 | userId("user_id"), 80 | roleId("role_id"), 81 | deleted("deleted"); 82 | 83 | /** 84 | * This field was generated by MyBatis Generator. 85 | * This field corresponds to the database table user_role_map 86 | * 87 | * @mbg.generated 88 | * @project https://github.com/itfsw/mybatis-generator-plugin 89 | */ 90 | private final String column; 91 | 92 | /** 93 | * This method was generated by MyBatis Generator. 94 | * This method corresponds to the database table user_role_map 95 | * 96 | * @mbg.generated 97 | * @project https://github.com/itfsw/mybatis-generator-plugin 98 | */ 99 | public String value() { 100 | return this.column; 101 | } 102 | 103 | /** 104 | * This method was generated by MyBatis Generator. 105 | * This method corresponds to the database table user_role_map 106 | * 107 | * @mbg.generated 108 | * @project https://github.com/itfsw/mybatis-generator-plugin 109 | */ 110 | public String getValue() { 111 | return this.column; 112 | } 113 | 114 | /** 115 | * This method was generated by MyBatis Generator. 116 | * This method corresponds to the database table user_role_map 117 | * 118 | * @mbg.generated 119 | * @project https://github.com/itfsw/mybatis-generator-plugin 120 | */ 121 | Column(String column) { 122 | this.column = column; 123 | } 124 | 125 | /** 126 | * This method was generated by MyBatis Generator. 127 | * This method corresponds to the database table user_role_map 128 | * 129 | * @mbg.generated 130 | * @project https://github.com/itfsw/mybatis-generator-plugin 131 | */ 132 | public String desc() { 133 | return this.column + " DESC"; 134 | } 135 | 136 | /** 137 | * This method was generated by MyBatis Generator. 138 | * This method corresponds to the database table user_role_map 139 | * 140 | * @mbg.generated 141 | * @project https://github.com/itfsw/mybatis-generator-plugin 142 | */ 143 | public String asc() { 144 | return this.column + " ASC"; 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/ConstantMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.Constant; 4 | import com.github.misterchangray.dao.entity.ConstantQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface ConstantMapper { 9 | long countByQuery(ConstantQuery query); 10 | 11 | int deleteByQuery(ConstantQuery query); 12 | 13 | int deleteByPrimaryKey(String id); 14 | 15 | int insert(Constant record); 16 | 17 | int insertSelective(Constant record); 18 | 19 | List selectByQuery(ConstantQuery query); 20 | 21 | Constant selectByPrimaryKey(String id); 22 | 23 | int updateByQuerySelective(@Param("record") Constant record, @Param("example") ConstantQuery query); 24 | 25 | int updateByQuery(@Param("record") Constant record, @Param("example") ConstantQuery query); 26 | 27 | int updateByPrimaryKeySelective(Constant record); 28 | 29 | int updateByPrimaryKey(Constant record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table constant 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table constant 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") Constant.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/LoginLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.LoginLog; 4 | import com.github.misterchangray.dao.entity.LoginLogQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface LoginLogMapper { 9 | long countByQuery(LoginLogQuery query); 10 | 11 | int deleteByQuery(LoginLogQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(LoginLog record); 16 | 17 | int insertSelective(LoginLog record); 18 | 19 | List selectByQuery(LoginLogQuery query); 20 | 21 | LoginLog selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") LoginLog record, @Param("example") LoginLogQuery query); 24 | 25 | int updateByQuery(@Param("record") LoginLog record, @Param("example") LoginLogQuery query); 26 | 27 | int updateByPrimaryKeySelective(LoginLog record); 28 | 29 | int updateByPrimaryKey(LoginLog record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table login_log 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table login_log 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") LoginLog.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/OperationLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.OperationLog; 4 | import com.github.misterchangray.dao.entity.OperationLogQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface OperationLogMapper { 9 | long countByQuery(OperationLogQuery query); 10 | 11 | int deleteByQuery(OperationLogQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(OperationLog record); 16 | 17 | int insertSelective(OperationLog record); 18 | 19 | List selectByQueryWithBLOBs(OperationLogQuery query); 20 | 21 | List selectByQuery(OperationLogQuery query); 22 | 23 | OperationLog selectByPrimaryKey(Integer id); 24 | 25 | int updateByQuerySelective(@Param("record") OperationLog record, @Param("example") OperationLogQuery query); 26 | 27 | int updateByQueryWithBLOBs(@Param("record") OperationLog record, @Param("example") OperationLogQuery query); 28 | 29 | int updateByQuery(@Param("record") OperationLog record, @Param("example") OperationLogQuery query); 30 | 31 | int updateByPrimaryKeySelective(OperationLog record); 32 | 33 | int updateByPrimaryKeyWithBLOBs(OperationLog record); 34 | 35 | int updateByPrimaryKey(OperationLog record); 36 | 37 | /** 38 | * This method was generated by MyBatis Generator. 39 | * This method corresponds to the database table operation_log 40 | * 41 | * @mbg.generated 42 | * @project https://github.com/itfsw/mybatis-generator-plugin 43 | */ 44 | int batchInsert(@Param("list") List list); 45 | 46 | /** 47 | * This method was generated by MyBatis Generator. 48 | * This method corresponds to the database table operation_log 49 | * 50 | * @mbg.generated 51 | * @project https://github.com/itfsw/mybatis-generator-plugin 52 | */ 53 | int batchInsertSelective(@Param("list") List list, @Param("selective") OperationLog.Column ... selective); 54 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/PermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.Permission; 4 | import com.github.misterchangray.dao.entity.PermissionQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface PermissionMapper { 9 | long countByQuery(PermissionQuery query); 10 | 11 | int deleteByQuery(PermissionQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(Permission record); 16 | 17 | int insertSelective(Permission record); 18 | 19 | List selectByQuery(PermissionQuery query); 20 | 21 | Permission selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") Permission record, @Param("example") PermissionQuery query); 24 | 25 | int updateByQuery(@Param("record") Permission record, @Param("example") PermissionQuery query); 26 | 27 | int updateByPrimaryKeySelective(Permission record); 28 | 29 | int updateByPrimaryKey(Permission record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table permission 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table permission 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") Permission.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.Role; 4 | import com.github.misterchangray.dao.entity.RoleQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface RoleMapper { 9 | long countByQuery(RoleQuery query); 10 | 11 | int deleteByQuery(RoleQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(Role record); 16 | 17 | int insertSelective(Role record); 18 | 19 | List selectByQuery(RoleQuery query); 20 | 21 | Role selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") Role record, @Param("example") RoleQuery query); 24 | 25 | int updateByQuery(@Param("record") Role record, @Param("example") RoleQuery query); 26 | 27 | int updateByPrimaryKeySelective(Role record); 28 | 29 | int updateByPrimaryKey(Role record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table role 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table role 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") Role.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/RolePermissionMapMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.RolePermissionMap; 4 | import com.github.misterchangray.dao.entity.RolePermissionMapQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface RolePermissionMapMapper { 9 | long countByQuery(RolePermissionMapQuery query); 10 | 11 | int deleteByQuery(RolePermissionMapQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(RolePermissionMap record); 16 | 17 | int insertSelective(RolePermissionMap record); 18 | 19 | List selectByQuery(RolePermissionMapQuery query); 20 | 21 | RolePermissionMap selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") RolePermissionMap record, @Param("example") RolePermissionMapQuery query); 24 | 25 | int updateByQuery(@Param("record") RolePermissionMap record, @Param("example") RolePermissionMapQuery query); 26 | 27 | int updateByPrimaryKeySelective(RolePermissionMap record); 28 | 29 | int updateByPrimaryKey(RolePermissionMap record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table role_permission_map 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table role_permission_map 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") RolePermissionMap.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.User; 4 | import com.github.misterchangray.dao.entity.UserQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface UserMapper { 9 | long countByQuery(UserQuery query); 10 | 11 | int deleteByQuery(UserQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(User record); 16 | 17 | int insertSelective(User record); 18 | 19 | List selectByQuery(UserQuery query); 20 | 21 | User selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") User record, @Param("example") UserQuery query); 24 | 25 | int updateByQuery(@Param("record") User record, @Param("example") UserQuery query); 26 | 27 | int updateByPrimaryKeySelective(User record); 28 | 29 | int updateByPrimaryKey(User record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table user 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table user 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") User.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/dao/mapper/UserRoleMapMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.dao.mapper; 2 | 3 | import com.github.misterchangray.dao.entity.UserRoleMap; 4 | import com.github.misterchangray.dao.entity.UserRoleMapQuery; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface UserRoleMapMapper { 9 | long countByQuery(UserRoleMapQuery query); 10 | 11 | int deleteByQuery(UserRoleMapQuery query); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(UserRoleMap record); 16 | 17 | int insertSelective(UserRoleMap record); 18 | 19 | List selectByQuery(UserRoleMapQuery query); 20 | 21 | UserRoleMap selectByPrimaryKey(Integer id); 22 | 23 | int updateByQuerySelective(@Param("record") UserRoleMap record, @Param("example") UserRoleMapQuery query); 24 | 25 | int updateByQuery(@Param("record") UserRoleMap record, @Param("example") UserRoleMapQuery query); 26 | 27 | int updateByPrimaryKeySelective(UserRoleMap record); 28 | 29 | int updateByPrimaryKey(UserRoleMap record); 30 | 31 | /** 32 | * This method was generated by MyBatis Generator. 33 | * This method corresponds to the database table user_role_map 34 | * 35 | * @mbg.generated 36 | * @project https://github.com/itfsw/mybatis-generator-plugin 37 | */ 38 | int batchInsert(@Param("list") List list); 39 | 40 | /** 41 | * This method was generated by MyBatis Generator. 42 | * This method corresponds to the database table user_role_map 43 | * 44 | * @mbg.generated 45 | * @project https://github.com/itfsw/mybatis-generator-plugin 46 | */ 47 | int batchInsertSelective(@Param("list") List list, @Param("selective") UserRoleMap.Column ... selective); 48 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service; 2 | 3 | 4 | import com.github.misterchangray.common.ResultSet; 5 | import com.github.misterchangray.common.PageInfo; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 基础服务定义 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 2018/4/20. 14 | */ 15 | public interface BaseService { 16 | 17 | /** 18 | * 查询 Id 是否存在 19 | * @param ids 20 | * @return 21 | */ 22 | ResultSet exist(List ids); 23 | 24 | /** 25 | * 根据 Id 获取对象 26 | * @param id 27 | * @return 28 | */ 29 | ResultSet getById(Integer id); 30 | 31 | 32 | /** 33 | * 根据 Id 获取多个对象 34 | * @param ids 35 | * @return 36 | */ 37 | ResultSet getByIds(List ids); 38 | 39 | /** 40 | * 列表 41 | * @param entity 42 | * @return 43 | */ 44 | ResultSet list(Entity entity, PageInfo pageInfo); 45 | 46 | /** 47 | * 保存 48 | * @param entity 49 | * @return 50 | */ 51 | ResultSet save(Entity entity); 52 | 53 | /** 54 | * 批量保存 55 | * @param entities 56 | * @return 57 | */ 58 | ResultSet saveAll(List entities); 59 | 60 | /** 61 | * 编辑 62 | * @param entity 63 | * @return 64 | */ 65 | ResultSet edit(Entity entity); 66 | 67 | 68 | /** 69 | * 删除实体 70 | * @param entity 71 | * @return 72 | */ 73 | ResultSet delete(Entity entity); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/common/ContextCacheService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.common; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | import javax.servlet.ServletContext; 7 | 8 | /** 9 | * 10 | * 用于全局缓存;目前采用ServletContext;大量数据推荐使用redis 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 4/29/2018. 14 | */ 15 | @Service 16 | public class ContextCacheService { 17 | @Autowired 18 | ServletContext servletContext; 19 | 20 | /** 21 | * 缓存一个对象 22 | * @param key 23 | * @param value 24 | * @return 25 | */ 26 | public boolean add(String key, Object value) { 27 | if(null != servletContext.getAttribute(key)) return false; 28 | servletContext.setAttribute(key, value); 29 | return true; 30 | } 31 | 32 | 33 | /** 34 | * 缓存数据;可覆盖原始数据 35 | * @param key 36 | * @param value 37 | * @param override 38 | * @return 39 | */ 40 | public boolean add(String key, Object value, boolean override) { 41 | if(null != servletContext.getAttribute(key) && false == override) return false; 42 | servletContext.setAttribute(key, value); 43 | return true; 44 | } 45 | 46 | 47 | /** 48 | * 移除缓存 49 | * 50 | * @param key 51 | */ 52 | public void remove(String key) { 53 | this.servletContext.removeAttribute(key); 54 | } 55 | 56 | 57 | /** 58 | * 判断key是否已经存在 59 | * @param key 60 | * @return 61 | */ 62 | public boolean exist(String key) { 63 | if(null == servletContext.getAttribute(key)) return false; 64 | return true; 65 | } 66 | 67 | 68 | /** 69 | * 根据key获取对象 70 | * @param key 71 | * @return 72 | */ 73 | public Object get(String key) { 74 | return servletContext.getAttribute(key); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/log/LoginLogService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.log; 2 | 3 | 4 | import com.github.misterchangray.dao.entity.LoginLog; 5 | 6 | /** 7 | * 登录日志 8 | * 9 | * 从业务上来讲:衹要是系統用戶;无论是否登录成功都应该记录日志;方便日后分析 10 | * 增加登录日志在 LoginService.signIn 方法中调用 11 | * 登出时间在用户 session 销毁时更新;即 UserSessionBo.destroySession 方法调用时 12 | * 13 | * @author Rui.Zhang/misterchangray@hotmail.com 14 | * @author Created on 2018/6/6. 15 | */ 16 | public interface LoginLogService { 17 | /** 18 | * 增加登录日志 19 | * @param userId 登录用户ID 20 | * @param loginIp 登录IP地址 21 | * @param deviceInfo 登录设备标识符 22 | * @param signInTime 登录时间 23 | * @param success 是否成功 24 | * @param detailsOfFail 失败原因 25 | * @return 26 | */ 27 | int insertLog(String userId, String loginIp, String deviceInfo, Long signInTime, Boolean success, String detailsOfFail); 28 | 29 | 30 | /** 31 | * 增加登录日志 32 | * @param loginLog 33 | * @return 34 | */ 35 | int insertLog(LoginLog loginLog); 36 | 37 | /** 38 | * 更新登录日志的 登出时间 39 | * 此函数在每次发起心跳时更新;即刚登录时此值应该为null 40 | * @param session 待更新记录的session 41 | * @return 42 | */ 43 | int updateSignOutTime(String session); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/log/OperationLogService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.log; 2 | 3 | 4 | 5 | /** 6 | * 操作日志 7 | * 8 | * @author Rui.Zhang/misterchangray@hotmail.com 9 | * @author Created on 2018/4/20. 10 | */ 11 | public interface OperationLogService { 12 | /** 13 | * 增加业务日志记录 14 | * @param signature 方法限定符 15 | * @param businessName 业务名称 16 | * @param userId 用户id 17 | * @param userName 用户名称 18 | * @param data 更新数据 19 | * @return 20 | */ 21 | int insertLog(String signature, String businessName, Integer userId, String userName, String data); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/log/impl/LoginLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.log.impl; 2 | 3 | import com.github.misterchangray.common.enums.DBEnum; 4 | import com.github.misterchangray.dao.entity.LoginLog; 5 | import com.github.misterchangray.dao.entity.LoginLogQuery; 6 | import com.github.misterchangray.dao.mapper.LoginLogMapper; 7 | import com.github.misterchangray.service.log.LoginLogService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.Date; 12 | 13 | /** 14 | * 登录日志服务 15 | * 16 | * @author Rui.Zhang/misterchangray@hotmail.com 17 | * @author Created on 2018/5/6. 18 | */ 19 | @Service 20 | public class LoginLogServiceImpl implements LoginLogService { 21 | @Autowired 22 | LoginLogMapper loginLogMapper; 23 | 24 | /** 25 | * 增加登录日志 26 | * @param userId 登录用户ID 27 | * @param loginIp 登录IP地址 28 | * @param deviceInfo 登录设备标识符 29 | * @param signInTime 登录时间 30 | * @param success 是否成功 31 | * @param detailsOfFail 失败原因 32 | * @return 33 | */ 34 | public int insertLog(String userId, String loginIp, String deviceInfo, Long signInTime, Boolean success, String detailsOfFail){ 35 | LoginLog loginLog = new LoginLog(); 36 | loginLog.setUserId(Integer.parseInt(userId)); 37 | loginLog.setSignInIp(loginIp); 38 | loginLog.setDeviceInfo(deviceInfo); 39 | loginLog.setSignInTime(new Date(signInTime)); 40 | loginLog.setSuccess(success ? DBEnum.TRUE.getCode() : DBEnum.DELETE.getCode()); 41 | loginLog.setDeviceInfo(detailsOfFail); 42 | 43 | return this.insertLog(loginLog); 44 | } 45 | 46 | /** 47 | * 更新登录日志的登出时间 48 | * @param session 待更新记录的session 49 | * @return 50 | */ 51 | public int updateSignOutTime(String session) { 52 | LoginLog loginLog = new LoginLog(); 53 | loginLog.setSignOutTime(new Date()); 54 | 55 | LoginLogQuery loginLogQuery = new LoginLogQuery(); 56 | LoginLogQuery.Criteria criteria = loginLogQuery.createCriteria(); 57 | criteria.andSessionEqualTo(session); 58 | 59 | return loginLogMapper.updateByQuerySelective(loginLog, loginLogQuery); 60 | } 61 | 62 | 63 | 64 | public int insertLog(LoginLog loginLog) { 65 | return loginLogMapper.insert(loginLog); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/log/impl/OperationLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.log.impl; 2 | 3 | import com.github.misterchangray.common.enums.DBEnum; 4 | import com.github.misterchangray.dao.entity.OperationLog; 5 | import com.github.misterchangray.dao.mapper.OperationLogMapper; 6 | import com.github.misterchangray.service.log.OperationLogService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * 这里可以实现种日志写入方式,默认实现mysql;推荐es或者mongodb数据库 12 | * 13 | * @author Rui.Zhang/misterchangray@hotmail.com 14 | * @author Created on 2018/4/20. 15 | */ 16 | @Service 17 | public class OperationLogServiceImpl implements OperationLogService { 18 | @Autowired 19 | OperationLogMapper operationLogMapper; 20 | 21 | public int insertLog(String signature, String businessName, Integer userId, String userName, String data) { 22 | OperationLog operationLog = new OperationLog(); 23 | operationLog.setBusinessName(businessName); 24 | operationLog.setUserId(userId); 25 | operationLog.setUserName(userName); 26 | operationLog.setSignature(signature); 27 | operationLog.setData(data); 28 | return this.addLog(operationLog); 29 | } 30 | 31 | public int addLog(OperationLog operationLog) { 32 | operationLog.setCreateDate(new java.util.Date()); 33 | return operationLogMapper.insert(operationLog); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.exception.ServiceException; 5 | 6 | /** 7 | * LoginService 8 | * 提供用户登录服务 9 | * 10 | * @author Rui.Zhang/misterchangray@hotmail.com 11 | * @author Created on 3/29/2018. 12 | */ 13 | public interface LoginService { 14 | /** 15 | * 通过账号+密码登录 16 | * @param username 17 | * @param password 18 | * @return 19 | */ 20 | ResultSet signInByUserName(String username, String password) throws ServiceException; 21 | 22 | /** 23 | * 通过邮箱+密码登录 24 | * @param email 25 | * @param password 26 | * @return 27 | */ 28 | ResultSet signInByEmail(String email, String password); 29 | 30 | /** 31 | * 通过短信+验证码登录 32 | * @param phone 33 | * @param verificationCode 34 | * @return 35 | */ 36 | ResultSet signInByPhone(String phone, String verificationCode); 37 | 38 | 39 | 40 | /** 41 | * 登出用户 42 | * @param userId 43 | * @return 44 | */ 45 | ResultSet signOut(String userId); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/PermissionService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user; 2 | 3 | import com.github.misterchangray.dao.entity.Permission; 4 | import com.github.misterchangray.dao.entity.Permission; 5 | import com.github.misterchangray.dao.entity.PermissionQuery; 6 | import com.github.misterchangray.dao.mapper.PermissionMapper; 7 | import com.github.misterchangray.service.BaseService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 用户权限服务 14 | * 15 | * @author Rui.Zhang/misterchangray@hotmail.com 16 | * @author Created on 3/20/2018. 17 | */ 18 | public interface PermissionService extends BaseService { 19 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.dao.entity.Role; 5 | import com.github.misterchangray.service.BaseService; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 用户角色服务 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/20/2018. 14 | */ 15 | public interface RoleService extends BaseService { 16 | /** 17 | * 更新角色绑定的权限 18 | * @param roleId 角色ID 19 | * @param permissions 更新权限id集合 20 | * @return 21 | */ 22 | ResultSet updatePermission(Integer roleId, List permissions) ; 23 | 24 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/UserService.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.dao.entity.User; 5 | import com.github.misterchangray.service.BaseService; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 用户服务 11 | * 12 | * @author Rui.Zhang/misterchangray@hotmail.com 13 | * @author Created on 3/20/2018. 14 | */ 15 | public interface UserService extends BaseService { 16 | /** 17 | * 更新用户所绑定的角色 18 | * @param userId 用户ID 19 | * @param roles 角色id集合 20 | * @return 21 | */ 22 | ResultSet updateRole(Integer userId, List roles); 23 | 24 | 25 | /** 26 | * 检查用户信息是否已注册 27 | * @param username 28 | * @param email 29 | * @param phone 30 | * @param idcard 31 | * @return 32 | */ 33 | ResultSet checkUserInfo(String username, String email, String phone, String idcard); 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/bo/UserSessionBo.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user.bo; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.exception.ServiceException; 5 | import com.github.misterchangray.common.utils.JSONUtils; 6 | import com.github.misterchangray.dao.entity.User; 7 | import com.github.misterchangray.service.common.RedisCacheService; 8 | import com.github.misterchangray.service.log.LoginLogService; 9 | import com.github.misterchangray.service.user.UserService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.UUID; 14 | 15 | /** 16 | * 17 | * session管理 18 | * @author Rui.Zhang/misterchangray@hotmail.com 19 | * @author Created on 4/29/2018. 20 | */ 21 | @Component 22 | public class UserSessionBo { 23 | @Autowired 24 | private UserService userService; 25 | @Autowired 26 | private RedisCacheService redisCacheService; 27 | @Autowired 28 | private LoginLogService loginLogService; 29 | 30 | //心跳过期时间;统为3分钟 31 | private Integer timeout = 3 * 60; 32 | 33 | 34 | 35 | /** 36 | * 获取session 37 | * @param session 38 | * @return 39 | */ 40 | public String getSession(String session) { 41 | return String.valueOf(redisCacheService.get(session)); 42 | } 43 | 44 | 45 | /** 46 | * 根据用户ID创建session 47 | * 一个用户只能创建一个session;多次创建会覆盖 48 | * redis中的session用于判断登录状态 49 | * 50 | * @param userId 51 | */ 52 | public String createSession(String userId) throws ServiceException { 53 | if(null == userId) return null; 54 | 55 | ResultSet response = userService.getById(Integer.parseInt(userId)); 56 | if(0 != response.getCode()) return null; 57 | User user = (User) response.getData(); 58 | 59 | //构造session 60 | String token = UUID.randomUUID().toString().replace("-", ""); 61 | redisCacheService.set(token, JSONUtils.obj2json(user), timeout); 62 | 63 | 64 | return token; 65 | } 66 | 67 | 68 | /** 69 | * 销毁session 70 | * @param session 71 | */ 72 | public void destroySession(String session) { 73 | redisCacheService.del(session); 74 | } 75 | 76 | 77 | /** 78 | * 判断session是否存在 79 | * @param session 80 | */ 81 | public boolean exist(String session) { 82 | return null == redisCacheService.get(session) ? false : true; 83 | } 84 | 85 | 86 | /** 87 | * 更新session心跳時間 88 | * @param session 89 | */ 90 | public void heartbeat(String session) { 91 | redisCacheService.expire(session, timeout); 92 | 93 | loginLogService.updateSignOutTime(session); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/impl/LoginServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user.impl; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.enums.DBEnum; 5 | import com.github.misterchangray.common.enums.ResultEnum; 6 | import com.github.misterchangray.common.exception.ServiceException; 7 | import com.github.misterchangray.common.utils.MapBuilder; 8 | import com.github.misterchangray.dao.entity.User; 9 | import com.github.misterchangray.dao.entity.UserQuery; 10 | import com.github.misterchangray.dao.mapper.UserMapper; 11 | import com.github.misterchangray.service.user.LoginService; 12 | import com.github.misterchangray.service.user.bo.UserSessionBo; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import javax.servlet.http.HttpSession; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | 21 | /** 22 | * 23 | * @author Rui.Zhang/misterchangray@hotmail.com 24 | * @author Created on 3/29/2018. 25 | */ 26 | @Service 27 | public class LoginServiceImpl implements LoginService { 28 | @Autowired 29 | UserMapper userMapper; 30 | @Autowired 31 | HttpSession httpSession; 32 | @Autowired 33 | UserSessionBo userSessionBo; 34 | 35 | 36 | public ResultSet signInByUserName(String username, String password) throws ServiceException { 37 | ResultSet res = ResultSet.build(); 38 | 39 | UserQuery userQuery = new UserQuery(); 40 | UserQuery.Criteria criteria = userQuery.createCriteria(); 41 | criteria.andUsernameEqualTo(username).andPasswordEqualTo(password); 42 | 43 | List userList = userMapper.selectByQuery(userQuery); 44 | if(0 == userList.size()) throw new ServiceException(ResultEnum.INVALID, "无效用户名或密码"); 45 | User user = userList.get(0); 46 | if(DBEnum.TRUE.getCode().equals(user.getDeleted())) throw new ServiceException(ResultEnum.GONE, "该用户已被删除"); 47 | if(DBEnum.FALSE.getCode().equals(user.getEnabled())) throw new ServiceException(ResultEnum.DISABLED, "该用户已被禁用"); 48 | 49 | 50 | String session = userSessionBo.createSession(String.valueOf(user.getId())); 51 | httpSession.setAttribute("Authentication", session); 52 | httpSession.setAttribute("user", user); 53 | 54 | /** 55 | * 请注意: 56 | * 此返回结构在操作日志中有用到;故如果修改返回结构应该同步修改操作日志文件 57 | */ 58 | Map data = MapBuilder.build().put("Authorization", session).put("user", user); 59 | res.setData(data); 60 | return res; 61 | } 62 | 63 | public ResultSet signInByEmail(String email, String password) { 64 | return null; 65 | } 66 | 67 | public ResultSet signInByPhone(String phone, String verificationCode) { 68 | return null; 69 | } 70 | 71 | 72 | 73 | public ResultSet signOut(String userId) { 74 | userSessionBo.destroySession(userId); 75 | return ResultSet.build(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/github/misterchangray/service/user/impl/PermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.misterchangray.service.user.impl; 2 | 3 | import com.github.misterchangray.common.ResultSet; 4 | import com.github.misterchangray.common.annotation.OperationLog; 5 | import com.github.misterchangray.common.enums.DBEnum; 6 | import com.github.misterchangray.common.enums.ResultEnum; 7 | import com.github.misterchangray.dao.entity.Permission; 8 | import com.github.misterchangray.common.PageInfo; 9 | import com.github.misterchangray.dao.entity.PermissionQuery; 10 | 11 | import com.github.misterchangray.dao.mapper.PermissionMapper; 12 | import com.github.misterchangray.service.user.PermissionService; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * 用户权限实现类 21 | * 22 | * @author Rui.Zhang/misterchangray@hotmail.com 23 | * @author Created on 3/29/2018. 24 | */ 25 | @Service 26 | public class PermissionServiceImpl implements PermissionService{ 27 | @Autowired 28 | PermissionMapper permissionMapper; 29 | 30 | 31 | /** 32 | * 检查权限是否存在 33 | * @param ids 待检测的ID集合 34 | * @return false有部分不存在/true全都存在 35 | */ 36 | public ResultSet exist(List ids) { 37 | if(null == ids) return ResultSet.build(ResultEnum.INVALID_REQUEST); 38 | 39 | PermissionQuery permissionQuery = new PermissionQuery(); 40 | PermissionQuery.Criteria criteria = permissionQuery.createCriteria(); 41 | criteria.andIdIn(ids); 42 | criteria.andDeletedEqualTo(DBEnum.FALSE.getCode()); 43 | if(ids.size() == permissionMapper.countByQuery(permissionQuery)) { 44 | return ResultSet.build().setData(true); 45 | } else { 46 | return ResultSet.build().setData(false); 47 | } 48 | } 49 | 50 | /** 51 | * 根据ID获取权限对象 52 | * @param id 待获取的id 53 | * @return Permission 54 | */ 55 | public ResultSet getById(Integer id) { 56 | if(null == id) return ResultSet.build(ResultEnum.INVALID_REQUEST); 57 | Permission permission = permissionMapper.selectByPrimaryKey(id); 58 | if(permission.getDeleted().equals(DBEnum.TRUE.getCode())) return ResultSet.build().setCode(ResultEnum.GONE); 59 | return ResultSet.build().setData(permission); 60 | } 61 | 62 | /** 63 | * 根据ID集合获取权限对象 64 | * @param ids 待获取的ID集合 65 | * @return List[Permission] 66 | */ 67 | public ResultSet getByIds(List ids) { 68 | if(null == ids) ResultSet.build().setCode(ResultEnum.INVALID_REQUEST); 69 | 70 | PermissionQuery permissionQuery = new PermissionQuery(); 71 | permissionQuery.createCriteria().andIdIn(ids).andDeletedEqualTo(DBEnum.FALSE.getCode()); 72 | return ResultSet.build().setData(permissionMapper.selectByQuery(permissionQuery)); 73 | } 74 | 75 | /** 76 | * 分页获取权限对象 77 | * @param permission 筛选信息 78 | * @param pageInfo 分页信息 79 | * @return List[Permission] 80 | */ 81 | public ResultSet list(Permission permission, PageInfo pageInfo) { 82 | if(null == pageInfo) pageInfo = new PageInfo(); 83 | 84 | PermissionQuery permissionQuery = new PermissionQuery(); 85 | permissionQuery.page(pageInfo.getPage(), pageInfo.getLimit()); 86 | 87 | PermissionQuery.Criteria criteria = permissionQuery.createCriteria(); 88 | criteria.andDeletedEqualTo(DBEnum.FALSE.getCode()); 89 | if(null != permissionQuery) { 90 | if(null != permission.getName())criteria.andNameLike(permission.getName()); 91 | } 92 | 93 | pageInfo.setCount(permissionMapper.countByQuery(permissionQuery)); 94 | return ResultSet.build().setData(permissionMapper.selectByQuery(permissionQuery)).setPageInfo(pageInfo); 95 | } 96 | 97 | /** 98 | * 新增权限对象 99 | * @param permission 待新增的对象 100 | * @return Permission 101 | */ 102 | @OperationLog(businessName = "增加权限") 103 | public ResultSet save(Permission permission) { 104 | permission.setId(null); 105 | permission.setDeleted(DBEnum.FALSE.getCode()); 106 | permissionMapper.insert(permission); 107 | return ResultSet.build().setData(permission); 108 | } 109 | 110 | /** 111 | * 批量插入权限对象 112 | * @param permissions 待新增的对象集合 113 | * @return list[Permission] 114 | */ 115 | @OperationLog(businessName = "批量增加权限") 116 | public ResultSet saveAll(List permissions) { 117 | if(null == permissions) return ResultSet.build().setCode(ResultEnum.INVALID_REQUEST); 118 | 119 | return ResultSet.build().setData(permissionMapper.batchInsert(permissions)); 120 | } 121 | 122 | /** 123 | * 更新权限对象 124 | * @param permission 待更新的权限对象 125 | * @return Permission 126 | */ 127 | @OperationLog(businessName = "更新权限") 128 | public ResultSet edit(Permission permission) { 129 | if(null == permission || null == permission.getId()) return ResultSet.build().setCode(ResultEnum.INVALID_REQUEST); 130 | 131 | Permission dbPermission = permissionMapper.selectByPrimaryKey(permission.getId()); 132 | if(DBEnum.FALSE.getCode().equals(dbPermission.getDeleted())) { 133 | permissionMapper.updateByPrimaryKeySelective(permission); 134 | permission = permissionMapper.selectByPrimaryKey(permission.getId()); 135 | } 136 | 137 | return ResultSet.build().setData(permission); 138 | } 139 | 140 | /** 141 | * 删除权限对象 142 | * @param permission 待删除的权限对象 143 | * @return null 144 | */ 145 | @OperationLog(businessName = "删除权限") 146 | public ResultSet delete(Permission permission) { 147 | if(null == permission || null == permission.getId()) return ResultSet.build().setCode(ResultEnum.INVALID_REQUEST); 148 | 149 | permission.setDeleted(DBEnum.TRUE.getCode()); 150 | permissionMapper.updateByPrimaryKeySelective(permission); 151 | return ResultSet.build().setData(null); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/resources/archives/common-core.sql: -------------------------------------------------------------------------------- 1 | /*==============================================================*/ 2 | /* DBMS name: MySQL 5.0 */ 3 | /* Created on: 5/28/2018 7:52:33 AM */ 4 | /*==============================================================*/ 5 | 6 | 7 | drop table if exists constant; 8 | 9 | drop table if exists login_log; 10 | 11 | drop table if exists operation_log; 12 | 13 | drop table if exists permission; 14 | 15 | drop table if exists role; 16 | 17 | drop table if exists role_permission_map; 18 | 19 | drop table if exists user; 20 | 21 | drop table if exists user_role_map; 22 | 23 | /*==============================================================*/ 24 | /* Table: constant */ 25 | /*==============================================================*/ 26 | create table constant 27 | ( 28 | id varchar(100) not null, 29 | name varchar(100) comment '常量名称', 30 | shortcut varchar(100) comment '常量简称,用于快速定位', 31 | pid varchar(100) comment '父ID,null为根节点', 32 | has_child int unsigned comment '是否有子节点0false,1true', 33 | enabled int unsigned comment '是否启用0false,1true', 34 | deleted int unsigned comment '是否删除0false, 1true', 35 | extra varchar(500) comment '附加数据;推荐存JSON', 36 | priority int unsigned, 37 | primary key (id) 38 | ); 39 | 40 | /*==============================================================*/ 41 | /* Table: login_log */ 42 | /*==============================================================*/ 43 | create table login_log 44 | ( 45 | id int not null auto_increment, 46 | user_id int unsigned comment '成功登入有此数据', 47 | sign_in_ip varchar(100), 48 | device_info varchar(300), 49 | sign_in_time datetime default NULL, 50 | sign_out_time datetime default NULL comment '成功登入有此数据', 51 | success int unsigned, 52 | details_of_fail varchar(300), 53 | sign_in_param varchar(300), 54 | session varchar(100), 55 | primary key (id) 56 | ); 57 | 58 | /*==============================================================*/ 59 | /* Table: operation_log */ 60 | /*==============================================================*/ 61 | create table operation_log 62 | ( 63 | id int not null auto_increment, 64 | Signature varchar(500) comment '调用方法的限定名', 65 | business_name varchar(500) comment '方法的业务名称', 66 | user_id int unsigned comment '操作人用户表ID', 67 | user_name varchar(100) comment '操作人名称', 68 | create_date datetime default NULL, 69 | data text, 70 | primary key (id) 71 | ); 72 | 73 | /*==============================================================*/ 74 | /* Table: permission */ 75 | /*==============================================================*/ 76 | create table permission 77 | ( 78 | id int not null auto_increment, 79 | name varchar(100), 80 | deleted int unsigned comment '是否删除0false, 1true', 81 | uri varchar(100), 82 | type int unsigned comment '1菜单2按钮', 83 | puri varchar(100), 84 | primary key (id) 85 | ); 86 | 87 | /*==============================================================*/ 88 | /* Table: role */ 89 | /*==============================================================*/ 90 | create table role 91 | ( 92 | id int not null auto_increment, 93 | name varchar(100), 94 | enabled int unsigned comment '是否启用0false, 1true', 95 | deleted int unsigned comment '是否删除0false, 1true', 96 | primary key (id) 97 | ); 98 | 99 | /*==============================================================*/ 100 | /* Table: role_permission_map */ 101 | /*==============================================================*/ 102 | create table role_permission_map 103 | ( 104 | id int not null auto_increment, 105 | role_id int unsigned, 106 | permission_id int unsigned, 107 | deleted int unsigned comment '是否删除0false, 1true', 108 | primary key (id) 109 | ); 110 | 111 | /*==============================================================*/ 112 | /* Table: user */ 113 | /*==============================================================*/ 114 | create table user 115 | ( 116 | id int not null auto_increment, 117 | username varchar(100) comment '用户名', 118 | password varchar(100) comment '密码', 119 | idcard varchar(100) comment '身份证', 120 | email varchar(100) comment '邮箱', 121 | name varchar(100) comment '姓名', 122 | sex int unsigned comment '性别', 123 | phone varchar(100) comment '手机号', 124 | enabled int unsigned comment '是否启用0false,1true', 125 | deleted int unsigned comment '是否删除0false,1true', 126 | primary key (id) 127 | ); 128 | 129 | /*==============================================================*/ 130 | /* Table: user_role_map */ 131 | /*==============================================================*/ 132 | create table user_role_map 133 | ( 134 | id int not null auto_increment, 135 | user_id int unsigned, 136 | role_id int unsigned, 137 | deleted int unsigned comment '是否删除0false, 1true', 138 | primary key (id) 139 | ); 140 | 141 | -------------------------------------------------------------------------------- /src/main/resources/archives/table_data/permission.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO common_core.permission 2 | ( 3 | name, 4 | deleted, 5 | uri, 6 | TYPE, 7 | puri 8 | ) 9 | VALUES 10 | ( 11 | 'app', 12 | 0, 13 | 'app', 14 | 1, 15 | NULL 16 | ); 17 | 18 | INSERT INTO common_core.permission 19 | ( 20 | name, 21 | deleted, 22 | uri, 23 | TYPE, 24 | puri 25 | ) 26 | VALUES 27 | ( 28 | '系统管理', 29 | 0, 30 | 'app.system', 31 | 1, 32 | 'app' 33 | ); 34 | 35 | INSERT INTO common_core.permission 36 | ( 37 | name, 38 | deleted, 39 | uri, 40 | TYPE, 41 | puri 42 | ) 43 | VALUES 44 | ( 45 | '用户管理', 46 | 0, 47 | 'app.system.user', 48 | 1, 49 | 'app.system.user' 50 | ); 51 | 52 | INSERT INTO common_core.permission 53 | ( 54 | name, 55 | deleted, 56 | uri, 57 | TYPE, 58 | puri 59 | ) 60 | VALUES 61 | ( 62 | '新增用户', 63 | 0, 64 | 'app.system.user.add', 65 | 2, 66 | 'app.system.user' 67 | ); 68 | 69 | INSERT INTO common_core.permission 70 | ( 71 | name, 72 | deleted, 73 | uri, 74 | TYPE, 75 | puri 76 | ) 77 | VALUES 78 | ( 79 | '编辑用户', 80 | 0, 81 | 'app.system.user.edit', 82 | 2, 83 | 'app.system.user' 84 | ); 85 | 86 | INSERT INTO common_core.permission 87 | ( 88 | name, 89 | deleted, 90 | uri, 91 | TYPE, 92 | puri 93 | ) 94 | VALUES 95 | ( 96 | '删除用户', 97 | 0, 98 | 'app.system.user.delete', 99 | 2, 100 | 'app.system.user' 101 | ); 102 | 103 | INSERT INTO common_core.permission 104 | ( 105 | name, 106 | deleted, 107 | uri, 108 | TYPE, 109 | puri 110 | ) 111 | VALUES 112 | ( 113 | '禁用/启用用户', 114 | 0, 115 | 'app.system.user.enabled', 116 | 2, 117 | 'app.system.user' 118 | ); 119 | 120 | INSERT INTO common_core.permission 121 | ( 122 | name, 123 | deleted, 124 | uri, 125 | TYPE, 126 | puri 127 | ) 128 | VALUES 129 | ( 130 | '权限管理', 131 | 0, 132 | 'app.system.permission', 133 | 1, 134 | 'app.system' 135 | ); 136 | 137 | INSERT INTO common_core.permission 138 | ( 139 | name, 140 | deleted, 141 | uri, 142 | TYPE, 143 | puri 144 | ) 145 | VALUES 146 | ( 147 | '新增权限', 148 | 0, 149 | 'app.system.permission.add', 150 | 2, 151 | 'app.system.permission' 152 | ); 153 | 154 | INSERT INTO common_core.permission 155 | ( 156 | name, 157 | deleted, 158 | uri, 159 | TYPE, 160 | puri 161 | ) 162 | VALUES 163 | ( 164 | '编辑权限', 165 | 0, 166 | 'app.system.permission.edit', 167 | 2, 168 | 'app.system.permission' 169 | ); 170 | 171 | INSERT INTO common_core.permission 172 | ( 173 | name, 174 | deleted, 175 | uri, 176 | TYPE, 177 | puri 178 | ) 179 | VALUES 180 | ( 181 | '删除权限', 182 | 0, 183 | 'app.system.permission.delete', 184 | 2, 185 | 'app.system.permission' 186 | ); 187 | 188 | INSERT INTO common_core.permission 189 | ( 190 | name, 191 | deleted, 192 | uri, 193 | TYPE, 194 | puri 195 | ) 196 | VALUES 197 | ( 198 | '角色管理', 199 | 0, 200 | 'app.system.role', 201 | 1, 202 | 'app.system' 203 | ); 204 | 205 | INSERT INTO common_core.permission 206 | ( 207 | name, 208 | deleted, 209 | uri, 210 | TYPE, 211 | puri 212 | ) 213 | VALUES 214 | ( 215 | '新增角色', 216 | 0, 217 | 'app.system.role.add', 218 | 2, 219 | 'app.system.role' 220 | ); 221 | 222 | INSERT INTO common_core.permission 223 | ( 224 | name, 225 | deleted, 226 | uri, 227 | TYPE, 228 | puri 229 | ) 230 | VALUES 231 | ( 232 | '编辑角色', 233 | 0, 234 | 'app.system.role.edit', 235 | 2, 236 | 'app.system.role' 237 | ); 238 | 239 | INSERT INTO common_core.permission 240 | ( 241 | name, 242 | deleted, 243 | uri, 244 | TYPE, 245 | puri 246 | ) 247 | VALUES 248 | ( 249 | '删除角色', 250 | 0, 251 | 'app.system.role.delete', 252 | 2, 253 | 'app.system.role' 254 | ); 255 | 256 | INSERT INTO common_core.permission 257 | ( 258 | name, 259 | deleted, 260 | uri, 261 | TYPE, 262 | puri 263 | ) 264 | VALUES 265 | ( 266 | '禁用/启用角色', 267 | 0, 268 | 'app.system.role.enabled', 269 | 2, 270 | 'app.system.role' 271 | ); 272 | 273 | INSERT INTO common_core.permission 274 | ( 275 | name, 276 | deleted, 277 | uri, 278 | TYPE, 279 | puri 280 | ) 281 | VALUES 282 | ( 283 | '常量配置', 284 | 0, 285 | 'app.system.constant', 286 | 1, 287 | 'app.system' 288 | ); 289 | 290 | INSERT INTO common_core.permission 291 | ( 292 | name, 293 | deleted, 294 | uri, 295 | TYPE, 296 | puri 297 | ) 298 | VALUES 299 | ( 300 | '新增常量', 301 | 0, 302 | 'app.system.constant.add', 303 | 2, 304 | 'app.system.constant' 305 | ); 306 | 307 | INSERT INTO common_core.permission 308 | ( 309 | name, 310 | deleted, 311 | uri, 312 | TYPE, 313 | puri 314 | ) 315 | VALUES 316 | ( 317 | '编辑常量', 318 | 0, 319 | 'app.system.constant.edit', 320 | 2, 321 | 'app.system.constant' 322 | ); 323 | 324 | INSERT INTO common_core.permission 325 | ( 326 | name, 327 | deleted, 328 | uri, 329 | TYPE, 330 | puri 331 | ) 332 | VALUES 333 | ( 334 | '删除常量', 335 | 0, 336 | 'app.system.constant.delete', 337 | 2, 338 | 'app.system.constant' 339 | ); 340 | 341 | INSERT INTO common_core.permission 342 | ( 343 | name, 344 | deleted, 345 | uri, 346 | TYPE, 347 | puri 348 | ) 349 | VALUES 350 | ( 351 | '禁用/启用常量', 352 | 0, 353 | 'app.system.constant.enabled', 354 | 2, 355 | 'app.system.constant' 356 | ); 357 | 358 | 359 | COMMIT; 360 | -------------------------------------------------------------------------------- /src/main/resources/archives/table_data/readme.txt: -------------------------------------------------------------------------------- 1 | 此目录存放表得一些基本数据;不包含建表语句 2 | 由 Sql Workbench/j 导出,可直接执行 3 | 文件编码为UTF-8 4 | 5 | 建表语句在common-core.sql中 -------------------------------------------------------------------------------- /src/main/resources/archives/table_data/role.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO common_core.role 2 | ( 3 | name, 4 | enabled, 5 | deleted 6 | ) 7 | VALUES 8 | ( 9 | '管理员', 10 | 1, 11 | 0 12 | ); 13 | 14 | INSERT INTO common_core.role 15 | ( 16 | name, 17 | enabled, 18 | deleted 19 | ) 20 | VALUES 21 | ( 22 | '财务部', 23 | 1, 24 | 0 25 | ); 26 | 27 | INSERT INTO common_core.role 28 | ( 29 | name, 30 | enabled, 31 | deleted 32 | ) 33 | VALUES 34 | ( 35 | '信息科', 36 | 1, 37 | 0 38 | ); 39 | 40 | 41 | COMMIT; 42 | -------------------------------------------------------------------------------- /src/main/resources/archives/table_data/user.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO common_core.`user` 2 | ( 3 | username, 4 | password, 5 | idcard, 6 | email, 7 | name, 8 | sex, 9 | phone, 10 | enabled, 11 | deleted 12 | ) 13 | VALUES 14 | ( 15 | 'zr', 16 | 'zr', 17 | '513701199109064437', 18 | 'misterchangray@hotmail.com', 19 | '张瑞', 20 | 1, 21 | '18380370238', 22 | 1, 23 | 0 24 | ); 25 | 26 | 27 | COMMIT; 28 | -------------------------------------------------------------------------------- /src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | #是否启用swagger2文档 2 | swagger2.enabled=true 3 | 4 | 5 | #邮箱发信设置 6 | email.host=smtp.qq.com 7 | email.port=465 8 | email.username=jioulongzi@qq.com 9 | email.password=tzemkmthjhdvbcih -------------------------------------------------------------------------------- /src/main/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 58 | 59 | 60 | 61 | 62 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
73 | 74 | 75 |
76 | 77 | 78 |
79 | 80 | 81 |
82 | 83 | 84 |
85 | 86 | 87 |
88 | 89 | 90 |
91 | 92 | 93 |
94 | 95 | 96 | 100 | 101 |
102 |
-------------------------------------------------------------------------------- /src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | #JDBC Global Setting 2 | #jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.driver=com.mysql.jdbc.Driver 4 | jdbc.url=jdbc:mysql://47.98.188.65:18300/common_core?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&failOverReadOnly=false 5 | jdbc.username=zr 6 | jdbc.password=isx932mes 7 | 8 | ##DataSource Global Setting 9 | #配置初始化大小、最小、最大 10 | ds.initialSize=1 11 | ds.minIdle=1 12 | ds.maxActive=20 13 | 14 | #配置获取连接等待超时的时间 15 | ds.maxWait=60000 16 | 17 | #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 18 | ds.timeBetweenEvictionRunsMillis=60000 19 | 20 | #配置一个连接在池中最小生存的时间,单位是毫秒 21 | ds.minEvictableIdleTimeMillis=300000 -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ### set log levels ### 2 | log4j.rootLogger=info,stdout,D,E 3 | 4 | ### 输出到控制台 ### 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 9 | 10 | ### 输出到日志文件 ### 11 | log4j.appender.D=org.apache.log4j.DailyRollingFileAppender 12 | log4j.appender.D.File=../logs/common_mvc/log 13 | log4j.appender.D.DatePattern='_'yyyy-MM-dd-HH-mm'.log' 14 | log4j.appender.D.Append=true 15 | ## 输出DEBUG级别以上的日志 16 | log4j.appender.D.Threshold=DEBUG 17 | log4j.appender.D.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n 19 | 20 | ### 保存异常信息到单独文件 ### 21 | log4j.appender.E=org.apache.log4j.DailyRollingFileAppender 22 | log4j.appender.E.File=../logs/common_mvc/exception 23 | log4j.appender.E.DatePattern='_'yyyy-MM-dd-HH-mm'.log' 24 | log4j.appender.E.Append=true 25 | ## 只输出ERROR级别以上的日志!!! 26 | log4j.appender.E.Threshold=ERROR 27 | log4j.appender.E.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.E.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/resources/redis.properties: -------------------------------------------------------------------------------- 1 | redis.host=47.98.188.65 2 | redis.port=18301 3 | redis.password=une2wm3qps8hct3xiw2qj4ds743u412x 4 | 5 | #最大空闲数 6 | redis.pool.maxIdle=50 7 | #最大空连接数 8 | redis.pool.maxTotal=6000 9 | #最大等待时间 10 | redis.pool.maxWaitMillis=20000 11 | #当池内没有返回对象时,最大等待时间 12 | redis.pool.maxWait=300 13 | #连接超时时是否阻塞 14 | redis.pool.blockWhenExhausted=true 15 | #检测连接是否成功 16 | redis.pool.testOnBorrow=true 17 | #链接超时 18 | redis.timeout=30000 19 | #数据库选择 20 | redis.database=0 21 | -------------------------------------------------------------------------------- /src/main/resources/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | application/json;charset=UTF-8 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Page Not Found :( 6 | 141 | 142 | 143 |

144 |

Not found :(

145 |

Sorry, but the page you were trying to view does not exist.

146 |

It looks like this was the result of either:

147 | 151 | 154 | 155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Page Not Found :( 6 | 141 | 142 | 143 |
144 |

Not found :(

145 |

Sorry, but the page you were trying to view does not exist.

146 |

It looks like this was the result of either:

147 | 151 | 154 | 155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | web core package 7 | 8 | Archetype Created Web Application 9 | 10 | 11 | index.jsp 12 | 13 | 14 | 15 | 404 16 | /WEB-INF/404.html 17 | 18 | 19 | 20 | java.lang.NullPointerException 21 | /WEB-INF/error.html 22 | 23 | 24 | 25 | 360 26 | 27 | 28 | 31 | 32 | characterEncodingFilter 33 | org.springframework.web.filter.CharacterEncodingFilter 34 | 35 | encoding 36 | UTF-8 37 | 38 | 39 | forceEncoding 40 | true 41 | 42 | 43 | 44 | characterEncodingFilter 45 | /* 46 | 47 | 48 | 49 | 51 | 52 | org.springframework.web.context.ContextLoaderListener 53 | 54 | 59 | 60 | contextConfigLocation 61 | classpath:applicationContext.xml 62 | 63 | 64 | 65 | 66 | 67 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | springMVC 116 | org.springframework.web.servlet.DispatcherServlet 117 | 118 | 119 | contextConfigLocation 120 | 121 | 122 | 123 | 124 | 125 | classpath:spring-mvc.xml 126 | 127 | 128 | 1 129 | true 130 | 131 | 132 | 133 | 134 | springMVC 135 | 136 | 137 | 138 | / 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/main/webapp/common-core-swagger-ui/config.js: -------------------------------------------------------------------------------- 1 | window.appConfigs = { 2 | swaggerApiUrl : "/v2/api-docs", 3 | debugApiUrl : "http://localhost:8080" 4 | } 5 | -------------------------------------------------------------------------------- /src/main/webapp/common-core-swagger-ui/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisterChangRay/common-mvc/5b18f7837da1fa91a615cc227e2b7f608044586f/src/main/webapp/common-core-swagger-ui/favicon.ico -------------------------------------------------------------------------------- /src/main/webapp/common-core-swagger-ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MyApp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

欢迎使用 Common-Core

10 |

基于maven的spring4.3+mybatis3.4+swagger2.6的后台整合,用于快速构建中小型API、RESTful API项目,该项目简单、快速、易扩展;使我们摆脱那些重复劳动,专注于业务代码的编写。 11 | 12 | 13 |

14 |

已完成功能

15 | 24 |

快速开始

25 | 34 |

目前表单,详细信息在"/resources/archives"目录下

35 |
drop database common_core;
36 | 
37 |     create database common_core;
38 | 
39 |     use common_core;
40 | 
41 |     create table user;
42 | 
43 |     create table role;
44 | 
45 |     create table permission;
46 | 
47 |     create table role_permission_map;
48 | 
49 |     create table user_role_map;
50 | 
51 |     create table constant;
52 | 
53 |     create table operation_log;
54 |

开发者建议

55 | 68 |

相关环境(推荐使用环境)

69 | 82 |

注意事项

83 | 87 |

Edit By MaHua

88 | -------------------------------------------------------------------------------- /src/main/webapp/swagger-ui/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisterChangRay/common-mvc/5b18f7837da1fa91a615cc227e2b7f608044586f/src/main/webapp/swagger-ui/favicon-16x16.png -------------------------------------------------------------------------------- /src/main/webapp/swagger-ui/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisterChangRay/common-mvc/5b18f7837da1fa91a615cc227e2b7f608044586f/src/main/webapp/swagger-ui/favicon-32x32.png -------------------------------------------------------------------------------- /src/main/webapp/swagger-ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Swagger UI 7 | 8 | 9 | 10 | 11 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 | 71 | 72 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/webapp/swagger-ui/oauth2-redirect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 68 | -------------------------------------------------------------------------------- /src/main/webapp/swagger-ui/swagger-ui.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"swagger-ui.css","sourceRoot":""} --------------------------------------------------------------------------------