Commit 6357c717 by naan1993

新版分离出parent

parent c0cb838c
*.js linguist-language=java
*.css linguist-language=java
*.html linguist-language=java
\ No newline at end of file
*.class
# Package Files #
*.jar
*.war
*.ear
/target/
# eclipse
.settings/
.classpath
.project
logs/
# idea
.idea/
*.iml
*velocity.log*
Copyright 2017 StyleFeng
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
# 上线发布流程
# 上线发布流程
项目如果要发布到生产环境,步骤如下:
## 修改application.yml相关配置
1.开启验证码验证:
```
guns.kaptcha-open=true
```
2.开启session超时验证:
```
guns.session-open=true
```
并根据需求配置这两个参数的大小:session-invalidate-time 和 session-validation-interval.
3.服务器端口根据上线需要进行修改:
```
server.port=xxxx
```
4.beetl文件检测要改为false:
```
beetl.resource-auto-check=false
```
5.激活的相关的profile
```
spring.profiles.active=produce
```
6.关闭开发者工具
```
spring.devtools.restart.enabled=false
```
## 打包
guns支持多种启动方式(详情见readme),根据启动方式下面介绍两种打包方式:
1.打成jar包启动,执行maven命令:
```
clean package -Dmaven.test.skip=true
```
然后放到linxu中执行后台运行命令
```
nohup java -jar xxx.jar >out.txt 2>&1 &
```
2.打成war包启动,首先修改pom中packaging改为war,然后执行1的打包命令,直接放入服务器tomcat的webapp文件夹即可
\ No newline at end of file
# 多机环境部署注意事项
# 多机环境部署注意事项
多机环境把session托管给redis存储,所以要部署和配置redis,另外需要注意的是开启相关配置
## 注意事项如下
1.单机环境下不需要依赖spring-session,所以需要把相关依赖的注释打开
```
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<scope>compile</scope><!-- 需要分布式session的话需要改为compile -->
</dependency>
```
2.修改application.yml中guns.spring-session-open配置,改为true,打开spring-session
```
guns.spring-session-open=true
```
3.配置application.yml中,spring.redis.host,spring.redis.port,spring.redis.password
```
spring.redis.host=xxx
spring.redis.port=xxx
spring.redis.password=xxx
```
4.需要把SpringSessionConfig类中的注释打开
```
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800)
```
5.如需配置session失效时间,请在SpringSessionConfig类中修改maxInactiveIntervalInSeconds属性值
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stylefeng</groupId>
<artifactId>guns</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>guns</name>
<description>guns 的spring boot版本</description>
<parent>
<groupId>com.stylefeng</groupId>
<artifactId>guns-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../guns-parent/pom.xml</relativePath>
</parent>
<dependencies>
<!--spring boot依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--shiro依赖-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--其他依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 需要分布式session的话需要放开注释
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
</project>
/*
Navicat MySQL Data Transfer
Source Server : 本地
Source Server Version : 50621
Source Host : localhost:3306
Source Database : biz
Target Server Type : MYSQL
Target Server Version : 50621
File Encoding : 65001
Date: 2017-06-24 23:18:50
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int(11) NOT NULL,
`value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES ('1', 'qwe');
package com.stylefeng.guns;
import com.stylefeng.guns.config.properties.GunsProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* SpringBoot方式启动类
*
* @author stylefeng
* @Date 2017/5/21 12:06
*/
@SpringBootApplication
public class GunsApplication extends WebMvcConfigurerAdapter{
protected final static Logger logger = LoggerFactory.getLogger(GunsApplication.class);
@Autowired
GunsProperties gunsProperties;
/**
* 增加swagger的支持
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if(gunsProperties.getSwaggerOpen()){
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
public static void main(String[] args) {
SpringApplication.run(GunsApplication.class, args);
logger.info("GunsApplication is success!");
}
}
package com.stylefeng.guns;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
* Guns Web程序启动类
*
* @author fengshuonan
* @date 2017-05-21 9:43
*/
public class GunsServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(GunsApplication.class);
}
}
package com.stylefeng.guns.common.annotion;
import java.lang.annotation.*;
/**
*
* 多数据源标识
*
* @author fengshuonan
* @date 2017年3月5日 上午9:44:24
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface DataSource {
String name() default "";
}
package com.stylefeng.guns.common.annotion;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 权限注解 用于检查权限 规定访问权限
*
* @example @Permission({roleID1,roleID2})
* @example @Permission
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Permission {
String[] value() default {};
}
package com.stylefeng.guns.common.annotion.log;
import java.lang.annotation.*;
/**
* 标记需要做业务日志的方法
*
* @author fengshuonan
* @date 2017-03-31 12:46
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface BussinessLog {
/**
* 业务的名称,例如:"修改菜单"
*/
String value() default "";
/**
* 被修改的实体的唯一标识,例如:菜单实体的唯一标识为"id"
*/
String key() default "id";
/**
* 字典(用于查找key的中文名称和字段的中文名称)
*/
String dict() default "SystemDict";
}
package com.stylefeng.guns.common.constant;
/**
* 系统常量
*
* @author fengshuonan
* @date 2017年2月12日 下午9:42:53
*/
public interface Const {
/**
* 系统默认的管理员密码
*/
String DEFAULT_PWD = "111111";
/**
* 管理员角色的名字
*/
String ADMIN_NAME = "administrator";
/**
* 管理员id
*/
Integer ADMIN_ID = 1;
/**
* 超级管理员角色id
*/
Integer ADMIN_ROLE_ID = 1;
/**
* 接口文档的菜单名
*/
String API_MENU_NAME = "接口文档";
}
package com.stylefeng.guns.common.constant;
/**
* 一些服务的快捷获取
*
* @author fengshuonan
* @date 2017-03-30 15:58
*/
public class Cst {
private Cst() {
}
private static Cst cst = new Cst();
public static Cst me() {
return cst;
}
}
package com.stylefeng.guns.common.constant;
/**
*
* 多数据源的枚举
*
* @author fengshuonan
* @date 2017年3月5日 上午10:15:02
*/
public interface DSEnum {
String DATA_SOURCE_GUNS = "dataSourceGuns"; //guns数据源
String DATA_SOURCE_BIZ = "dataSourceBiz"; //其他业务的数据源
}
package com.stylefeng.guns.common.constant;
/**
* 字典常量
*
* @author fengshuonan
* @date 2017年5月16日21:44:56
*/
public interface Dict {
/**
* 系统管理员字典
*/
String UserDict = "UserDict";
/**
* 角色管理员字典
*/
String RoleDict = "RoleDict";
/**
* 删除业务的字典
*/
String DeleteDict = "DeleteDict";
/**
* 部门管理业务的字典
*/
String DeptDict = "DeptDict";
/**
* 菜单管理业务的字典
*/
String MenuDict = "MenuDict";
/**
* 字典管理业务的字典
*/
String DictMap = "DictMap";
/**
* 通知管理业务的字典
*/
String NoticeMap = "NoticeMap";
}
package com.stylefeng.guns.common.constant.cache;
/**
* 所有缓存名称的集合
*
* @author fengshuonan
* @date 2017-04-24 21:56
*/
public interface Cache {
/**
* 常量缓存
*/
String CONSTANT = "CONSTANT";
}
package com.stylefeng.guns.common.constant.cache;
/**
* 缓存的key集合
*
* @author fengshuonan
* @date 2017-04-25 9:37
*/
public interface CacheKey {
/**
* ConstantFactory中的缓存
*/
String ROLES_NAME = "roles_name_";
String SINGLE_ROLE_NAME = "single_role_name_";
String SINGLE_ROLE_TIP = "single_role_tip_";
String DEPT_NAME = "dept_name_";
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 用于删除业务的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class DeleteDict extends AbstractDictMap {
@Override
public void init() {
put("roleId","角色名称");
put("deptId", "部门名称");
put("menuId", "菜单名称");
put("dictId", "字典名称");
put("noticeId", "标题");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("roleId","getCacheObject");
putFieldWrapperMethodName("deptId","getCacheObject");
putFieldWrapperMethodName("menuId","getCacheObject");
putFieldWrapperMethodName("dictId","getCacheObject");
putFieldWrapperMethodName("noticeId","getCacheObject");
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 部门的映射
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class DeptDict extends AbstractDictMap {
@Override
public void init() {
put("deptId", "部门名称");
put("num", "部门排序");
put("pid", "上级名称");
put("simplename", "部门简称");
put("fullname", "部门全称");
put("tips", "备注");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("deptId", "getDeptName");
putFieldWrapperMethodName("pid", "getDeptName");
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 字典map
*
* @author fengshuonan
* @date 2017-05-06 15:43
*/
public class DictMap extends AbstractDictMap {
@Override
public void init() {
put("dictId","字典名称");
put("dictName","字典名称");
put("dictValues","字典内容");
}
@Override
protected void initBeWrapped() {
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 日志的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class LogDict extends AbstractDictMap {
@Override
public void init() {
put("tips","备注");
}
@Override
protected void initBeWrapped() {
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 菜单的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class MenuDict extends AbstractDictMap {
@Override
public void init() {
put("menuId","菜单id");
put("id","菜单id");
put("code","菜单编号");
put("pcode","菜单父编号");
put("name","菜单名称");
put("icon","菜单图标");
put("url","url地址");
put("num","菜单排序号");
put("levels","菜单层级");
put("tips","备注");
put("status","菜单状态");
put("isopen","是否打开");
put("","");
}
@Override
protected void initBeWrapped() {
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 通知的映射
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class NoticeMap extends AbstractDictMap {
@Override
public void init() {
put("title", "标题");
put("content", "内容");
}
@Override
protected void initBeWrapped() {
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 角色的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class RoleDict extends AbstractDictMap {
@Override
public void init() {
put("roleId","角色名称");
put("num","角色排序");
put("pid","角色的父级");
put("name","角色名称");
put("deptid","部门名称");
put("tips","备注");
put("ids","资源名称");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("pid","getSingleRoleName");
putFieldWrapperMethodName("deptid","getDeptName");
putFieldWrapperMethodName("roleId","getSingleRoleName");
putFieldWrapperMethodName("ids","getMenuNames");
}
}
package com.stylefeng.guns.common.constant.dictmap;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
/**
* 用户的字典
*
* @author fengshuonan
* @date 2017-05-06 15:01
*/
public class UserDict extends AbstractDictMap {
@Override
public void init() {
put("userId","账号");
put("avatar","头像");
put("account","账号");
put("name","名字");
put("birthday","生日");
put("sex","性别");
put("email","电子邮件");
put("phone","电话");
put("roleid","角色名称");
put("deptid","部门名称");
put("roleIds","角色名称集合");
}
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("sex","getSexName");
putFieldWrapperMethodName("deptid","getDeptName");
putFieldWrapperMethodName("roleid","getSingleRoleName");
putFieldWrapperMethodName("userId","getUserAccountById");
putFieldWrapperMethodName("roleIds","getRoleName");
}
}
package com.stylefeng.guns.common.constant.dictmap.base;
import java.util.HashMap;
/**
* 字典映射抽象类
*
* @author fengshuonan
* @date 2017-05-06 14:58
*/
public abstract class AbstractDictMap {
protected HashMap<String, String> dictory = new HashMap<>();
protected HashMap<String, String> fieldWarpperDictory = new HashMap<>();
public AbstractDictMap(){
put("id","主键id");
init();
initBeWrapped();
}
/**
* 初始化字段英文名称和中文名称对应的字典
*
* @author stylefeng
* @Date 2017/5/9 19:39
*/
public abstract void init();
/**
* 初始化需要被包装的字段(例如:性别为1:男,2:女,需要被包装为汉字)
*
* @author stylefeng
* @Date 2017/5/9 19:35
*/
protected abstract void initBeWrapped();
public String get(String key) {
return this.dictory.get(key);
}
public void put(String key, String value) {
this.dictory.put(key, value);
}
public String getFieldWarpperMethodName(String key){
return this.fieldWarpperDictory.get(key);
}
public void putFieldWrapperMethodName(String key,String methodName){
this.fieldWarpperDictory.put(key,methodName);
}
}
package com.stylefeng.guns.common.constant.dictmap.base;
/**
* 系统相关的字典
*
* @author fengshuonan
* @date 2017-05-06 15:48
*/
public class SystemDict extends AbstractDictMap {
@Override
public void init() {
}
@Override
protected void initBeWrapped() {
}
}
package com.stylefeng.guns.common.constant.dictmap.factory;
import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.constant.factory.IConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import java.lang.reflect.Method;
/**
* 字段的包装创建工厂
*
* @author fengshuonan
* @date 2017-05-06 15:12
*/
public class DictFieldWarpperFactory {
public static Object createFieldWarpper(Object field, String methodName) {
IConstantFactory me = ConstantFactory.me();
try {
Method method = IConstantFactory.class.getMethod(methodName, field.getClass());
Object result = method.invoke(me, field);
return result;
} catch (Exception e) {
try {
Method method = IConstantFactory.class.getMethod(methodName, Integer.class);
Object result = method.invoke(me, Integer.parseInt(field.toString()));
return result;
} catch (Exception e1) {
throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
}
}
}
}
package com.stylefeng.guns.common.constant.dictmap.factory;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
import com.stylefeng.guns.common.constant.dictmap.base.SystemDict;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
/**
* 字典的创建工厂
*
* @author fengshuonan
* @date 2017-05-06 15:12
*/
public class DictMapFactory {
private static final String basePath = "com.stylefeng.guns.common.constant.dictmap.";
/**
* 通过类名创建具体的字典类
*/
public static AbstractDictMap createDictMap(String className) {
if("SystemDict".equals(className)){
return new SystemDict();
}else{
try {
Class<AbstractDictMap> clazz = (Class<AbstractDictMap>) Class.forName(basePath + className);
return clazz.newInstance();
} catch (Exception e) {
throw new BussinessException(BizExceptionEnum.ERROR_CREATE_DICT);
}
}
}
}
package com.stylefeng.guns.common.constant.factory;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.persistence.dao.*;
import com.stylefeng.guns.common.persistence.model.*;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.support.StrKit;
import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.core.util.ToolUtil;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 常量的生产工厂
*
* @author fengshuonan
* @date 2017年2月13日 下午10:55:21
*/
@Component
@DependsOn("springContextHolder")
public class ConstantFactory implements IConstantFactory {
private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class);
private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class);
private DictMapper dictMapper = SpringContextHolder.getBean(DictMapper.class);
private UserMapper userMapper = SpringContextHolder.getBean(UserMapper.class);
private MenuMapper menuMapper = SpringContextHolder.getBean(MenuMapper.class);
private NoticeMapper noticeMapper = SpringContextHolder.getBean(NoticeMapper.class);
public static IConstantFactory me() {
return SpringContextHolder.getBean("constantFactory");
}
/**
* 根据用户id获取用户名称
*
* @author stylefeng
* @Date 2017/5/9 23:41
*/
@Override
public String getUserNameById(Integer userId) {
User user = userMapper.selectById(userId);
if (user != null) {
return user.getName();
} else {
return "--";
}
}
/**
* 根据用户id获取用户账号
*
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
@Override
public String getUserAccountById(Integer userId) {
User user = userMapper.selectById(userId);
if (user != null) {
return user.getAccount();
} else {
return "--";
}
}
/**
* 通过角色ids获取角色名称
*/
@Override
public String getRoleName(String roleIds) {
Integer[] roles = Convert.toIntArray(roleIds);
StringBuilder sb = new StringBuilder();
for (int role : roles) {
Role roleObj = roleMapper.selectById(role);
if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
sb.append(roleObj.getName()).append(",");
}
}
return StrKit.removeSuffix(sb.toString(), ",");
}
/**
* 通过角色id获取角色名称
*/
@Override
public String getSingleRoleName(Integer roleId) {
if (0 == roleId) {
return "--";
}
Role roleObj = roleMapper.selectById(roleId);
if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
return roleObj.getName();
}
return "";
}
/**
* 通过角色id获取角色英文名称
*/
@Override
public String getSingleRoleTip(Integer roleId) {
if (0 == roleId) {
return "--";
}
Role roleObj = roleMapper.selectById(roleId);
if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
return roleObj.getTips();
}
return "";
}
/**
* 获取部门名称
*/
@Override
public String getDeptName(Integer deptId) {
Dept dept = deptMapper.selectById(deptId);
if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) {
return dept.getFullname();
}
return "";
}
/**
* 获取菜单的名称们(多个)
*/
@Override
public String getMenuNames(String menuIds) {
Integer[] menus = Convert.toIntArray(menuIds);
StringBuilder sb = new StringBuilder();
for (int menu : menus) {
Menu menuObj = menuMapper.selectById(menu);
if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
sb.append(menuObj.getName()).append(",");
}
}
return StrKit.removeSuffix(sb.toString(), ",");
}
/**
* 获取菜单名称
*/
@Override
public String getMenuName(Integer menuId) {
if (ToolUtil.isEmpty(menuId)) {
return "";
} else {
Menu menu = menuMapper.selectById(menuId);
if (menu == null) {
return "";
} else {
return menu.getName();
}
}
}
/**
* 获取菜单名称通过编号
*/
@Override
public String getMenuNameByCode(String code) {
if (ToolUtil.isEmpty(code)) {
return "";
} else {
Menu param = new Menu();
param.setCode(code);
Menu menu = menuMapper.selectOne(param);
if (menu == null) {
return "";
} else {
return menu.getName();
}
}
}
/**
* 获取字典名称
*/
@Override
public String getDictName(Integer dictId) {
if (ToolUtil.isEmpty(dictId)) {
return "";
} else {
Dict dict = dictMapper.selectById(dictId);
if (dict == null) {
return "";
} else {
return dict.getName();
}
}
}
/**
* 获取通知标题
*/
@Override
public String getNoticeTitle(Integer dictId) {
if (ToolUtil.isEmpty(dictId)) {
return "";
} else {
Notice notice = noticeMapper.selectById(dictId);
if (notice == null) {
return "";
} else {
return notice.getTitle();
}
}
}
/**
* 根据字典名称和字典中的值获取对应的名称
*/
@Override
public String getDictsByName(String name, Integer val) {
Dict temp = new Dict();
temp.setName(name);
Dict dict = dictMapper.selectOne(temp);
if (dict == null) {
return "";
} else {
Wrapper<Dict> wrapper = new EntityWrapper<>();
wrapper = wrapper.eq("pid", dict.getId());
List<Dict> dicts = dictMapper.selectList(wrapper);
for (Dict item : dicts) {
if (item.getNum() != null && item.getNum().equals(val)) {
return item.getName();
}
}
return "";
}
}
/**
* 获取性别名称
*/
@Override
public String getSexName(Integer sex) {
return getDictsByName("性别", sex);
}
/**
* 获取用户登录状态
*/
@Override
public String getStatusName(Integer status) {
return ManagerStatus.valueOf(status);
}
/**
* 获取菜单状态
*/
@Override
public String getMenuStatusName(Integer status) {
return MenuStatus.valueOf(status);
}
/**
* 查询字典
*/
@Override
public List<Dict> findInDict(Integer id) {
if (ToolUtil.isEmpty(id)) {
return null;
} else {
EntityWrapper<Dict> wrapper = new EntityWrapper<>();
List<Dict> dicts = dictMapper.selectList(wrapper.eq("pid", id));
if (dicts == null || dicts.size() == 0) {
return null;
} else {
return dicts;
}
}
}
/**
* 获取被缓存的对象(用户删除业务)
*/
@Override
public String getCacheObject(String para) {
return LogObjectHolder.me().get().toString();
}
/**
* 获取子部门id
*/
@Override
public List<Integer> getSubDeptId(Integer deptid) {
Wrapper<Dept> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pids", "%[" + deptid + "]%");
List<Dept> depts = this.deptMapper.selectList(wrapper);
ArrayList<Integer> deptids = new ArrayList<>();
if(depts != null || depts.size() > 0){
for (Dept dept : depts) {
deptids.add(dept.getId());
}
}
return deptids;
}
/**
* 获取所有父部门id
*/
@Override
public List<Integer> getParentDeptIds(Integer deptid) {
Dept dept = deptMapper.selectById(deptid);
String pids = dept.getPids();
String[] split = pids.split(",");
ArrayList<Integer> parentDeptIds = new ArrayList<>();
for (String s : split) {
parentDeptIds.add(Integer.valueOf(StrKit.removeSuffix(StrKit.removePrefix(s, "["), "]")));
}
return parentDeptIds;
}
}
package com.stylefeng.guns.common.constant.factory;
import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.persistence.model.Dict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
/**
* 常量生产工厂的接口
*
* @author fengshuonan
* @date 2017-06-14 21:12
*/
public interface IConstantFactory {
/**
* 根据用户id获取用户名称
*
* @author stylefeng
* @Date 2017/5/9 23:41
*/
String getUserNameById(Integer userId);
/**
* 根据用户id获取用户账号
*
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
String getUserAccountById(Integer userId);
/**
* 通过角色ids获取角色名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
String getRoleName(String roleIds);
/**
* 通过角色id获取角色名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
String getSingleRoleName(Integer roleId);
/**
* 通过角色id获取角色英文名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
String getSingleRoleTip(Integer roleId);
/**
* 获取部门名称
*/
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
String getDeptName(Integer deptId);
/**
* 获取菜单的名称们(多个)
*/
String getMenuNames(String menuIds);
/**
* 获取菜单名称
*/
String getMenuName(Integer menuId);
/**
* 获取菜单名称通过编号
*/
String getMenuNameByCode(String code);
/**
* 获取字典名称
*/
String getDictName(Integer dictId);
/**
* 获取通知标题
*/
String getNoticeTitle(Integer dictId);
/**
* 根据字典名称和字典中的值获取对应的名称
*/
String getDictsByName(String name, Integer val);
/**
* 获取性别名称
*/
String getSexName(Integer sex);
/**
* 获取用户登录状态
*/
String getStatusName(Integer status);
/**
* 获取菜单状态
*/
String getMenuStatusName(Integer status);
/**
* 查询字典
*/
List<Dict> findInDict(Integer id);
/**
* 获取被缓存的对象(用户删除业务)
*/
String getCacheObject(String para);
/**
* 获取子部门id
*/
List<Integer> getSubDeptId(Integer deptid);
/**
* 获取所有父部门id
*/
List<Integer> getParentDeptIds(Integer deptid);
}
package com.stylefeng.guns.common.constant.factory;
import com.stylefeng.guns.core.support.StrKit;
import com.stylefeng.guns.core.util.ToolUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 组合字符串生产者
*
* @author fengshuonan
* @date 2017-04-27 16:42
*/
public class MutiStrFactory {
/**
* 每个条目之间的分隔符
*/
public static final String ITEM_SPLIT = ";";
/**
* 属性之间的分隔符
*/
public static final String ATTR_SPLIT = ":";
/**
* 拼接字符串的id
*/
public static final String MUTI_STR_ID = "ID";
/**
* 拼接字符串的key
*/
public static final String MUTI_STR_KEY = "KEY";
/**
* 拼接字符串的value
*/
public static final String MUTI_STR_VALUE = "VALUE";
/**
* 解析一个组合字符串(例如: "1:启用;2:禁用;3:冻结" 这样的字符串)
*
* @author fengshuonan
* @Date 2017/4/27 16:44
*/
public static List<Map<String,String>> parseKeyValue(String mutiString){
if(ToolUtil.isEmpty(mutiString)){
return new ArrayList<>();
}else{
ArrayList<Map<String,String>> results = new ArrayList<>();
String[] items = StrKit.split(StrKit.removeSuffix(mutiString, ITEM_SPLIT), ITEM_SPLIT);
for (String item : items) {
String[] attrs = item.split(ATTR_SPLIT);
HashMap<String, String> itemMap = new HashMap<>();
itemMap.put(MUTI_STR_KEY,attrs[0]);
itemMap.put(MUTI_STR_VALUE,attrs[1]);
results.add(itemMap);
}
return results;
}
}
/**
* 解析id:key:value这样类型的字符串
*
* @author fengshuonan
* @Date 2017/4/28 11:06
*/
public static List<Map<String,String>> parseIdKeyValue(String mutiString){
if(ToolUtil.isEmpty(mutiString)){
return new ArrayList<>();
}else{
ArrayList<Map<String,String>> results = new ArrayList<>();
String[] items = StrKit.split(StrKit.removeSuffix(mutiString, ITEM_SPLIT), ITEM_SPLIT);
for (String item : items) {
String[] attrs = item.split(ATTR_SPLIT);
HashMap<String, String> itemMap = new HashMap<>();
itemMap.put(MUTI_STR_ID,attrs[0]);
itemMap.put(MUTI_STR_KEY,attrs[1]);
itemMap.put(MUTI_STR_VALUE,attrs[2]);
results.add(itemMap);
}
return results;
}
}
}
package com.stylefeng.guns.common.constant.factory;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.state.Order;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.ToolUtil;
import javax.servlet.http.HttpServletRequest;
/**
* BootStrap Table默认的分页参数创建
*
* @author fengshuonan
* @date 2017-04-05 22:25
*/
public class PageFactory<T> {
public Page<T> defaultPage() {
HttpServletRequest request = HttpKit.getRequest();
int limit = Integer.valueOf(request.getParameter("limit"));
int offset = Integer.valueOf(request.getParameter("offset"));
String sort = request.getParameter("sort");
String order = request.getParameter("order");
if(ToolUtil.isEmpty(sort)){
Page<T> page = new Page<>((offset / limit + 1), limit);
page.setOpenSort(false);
return page;
}else{
Page<T> page = new Page<>((offset / limit + 1), limit, sort);
if(Order.ASC.getDes().equals(order)){
page.setAsc(true);
}else{
page.setAsc(false);
}
return page;
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 业务日志类型
*
* @author fengshuonan
* @Date 2017年1月22日 下午12:14:59
*/
public enum BizLogType {
ALL(0, null),//全部日志
BUSSINESS(1, "业务日志"),
EXCEPTION(2, "异常日志");
Integer val;
String message;
BizLogType(Integer val, String message) {
this.val = val;
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getVal() {
return val;
}
public void setVal(Integer val) {
this.val = val;
}
public static String valueOf(Integer value) {
if (value == null) {
return null;
} else {
for (BizLogType bizLogType : BizLogType.values()) {
if (bizLogType.getVal().equals(value)) {
return bizLogType.getMessage();
}
}
return null;
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 是否是菜单的枚举
*
* @author fengshuonan
* @date 2017年6月1日22:50:11
*/
public enum IsMenu {
YES(1, "是"),
NO(0, "不是");//不是菜单的是按钮
int code;
String message;
IsMenu(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static String valueOf(Integer status) {
if (status == null) {
return "";
} else {
for (IsMenu s : IsMenu.values()) {
if (s.getCode() == status) {
return s.getMessage();
}
}
return "";
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 业务是否成功的日志记录
*
* @author fengshuonan
* @Date 2017年1月22日 下午12:14:59
*/
public enum LogSucceed {
SUCCESS("成功"),
FAIL("失败");
String message;
LogSucceed(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 日志类型
*
* @author fengshuonan
* @Date 2017年1月22日 下午12:14:59
*/
public enum LogType {
LOGIN("登录日志"),
LOGIN_FAIL("登录失败日志"),
EXIT("退出日志"),
EXCEPTION("异常日志"),
BUSSINESS("业务日志");
String message;
LogType(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 管理员的状态
*
* @author fengshuonan
* @Date 2017年1月10日 下午9:54:13
*/
public enum ManagerStatus {
OK(1, "启用"), FREEZED(2, "冻结"), DELETED(3, "被删除");
int code;
String message;
ManagerStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static String valueOf(Integer value) {
if (value == null) {
return "";
} else {
for (ManagerStatus ms : ManagerStatus.values()) {
if (ms.getCode() == value) {
return ms.getMessage();
}
}
return "";
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 菜单是否打开的状态
*
* @author fengshuonan
* @Date 2017年4月8日10:12:15
*/
public enum MenuOpenStatus {
OPEN(1, "打开"),
CLOSE(0, "关闭");
int code;
String message;
MenuOpenStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static String valueOf(Integer status) {
if (status == null) {
return "";
} else {
for (MenuOpenStatus s : MenuOpenStatus.values()) {
if (s.getCode() == status) {
return s.getMessage();
}
}
return "";
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 菜单的状态
*
* @author fengshuonan
* @Date 2017年1月22日 下午12:14:59
*/
public enum MenuStatus {
ENABLE(1, "启用"),
DISABLE(0, "禁用");
int code;
String message;
MenuStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static String valueOf(Integer status) {
if (status == null) {
return "";
} else {
for (MenuStatus s : MenuStatus.values()) {
if (s.getCode() == status) {
return s.getMessage();
}
}
return "";
}
}
}
package com.stylefeng.guns.common.constant.state;
/**
* 数据库排序
*
* @author fengshuonan
* @Date 2017年5月31日20:48:41
*/
public enum Order {
ASC("asc"), DESC("desc");
private String des;
Order(String des) {
this.des = des;
}
public String getDes() {
return des;
}
public void setDes(String des) {
this.des = des;
}
}
package com.stylefeng.guns.common.constant.tips;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
/**
* 返回给前台的错误提示
*
* @author fengshuonan
* @date 2016年11月12日 下午5:05:22
*/
public class ErrorTip extends Tip {
public ErrorTip(int code, String message) {
super();
this.code = code;
this.message = message;
}
public ErrorTip(BizExceptionEnum bizExceptionEnum) {
this.code = bizExceptionEnum.getCode();
this.message = bizExceptionEnum.getMessage();
}
}
package com.stylefeng.guns.common.constant.tips;
/**
* 返回给前台的成功提示
*
* @author fengshuonan
* @date 2016年11月12日 下午5:05:22
*/
public class SuccessTip extends Tip{
public SuccessTip(){
super.code = 200;
super.message = "操作成功";
}
}
package com.stylefeng.guns.common.constant.tips;
/**
* 返回给前台的提示(最终转化为json形式)
*
* @author fengshuonan
* @Date 2017年1月11日 下午11:58:00
*/
public abstract class Tip {
protected int code;
protected String message;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.stylefeng.guns.common.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.tips.SuccessTip;
import com.stylefeng.guns.common.page.PageInfoBT;
import com.stylefeng.guns.common.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.FileUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
public class BaseController {
protected static String SUCCESS = "SUCCESS";
protected static String ERROR = "ERROR";
protected static String REDIRECT = "redirect:";
protected static String FORWARD = "forward:";
protected static SuccessTip SUCCESS_TIP = new SuccessTip();
protected HttpServletRequest getHttpServletRequest() {
return HttpKit.getRequest();
}
protected HttpServletResponse getHttpServletResponse() {
return HttpKit.getResponse();
}
protected HttpSession getSession() {
return HttpKit.getRequest().getSession();
}
protected HttpSession getSession(Boolean flag) {
return HttpKit.getRequest().getSession(flag);
}
protected String getPara(String name) {
return HttpKit.getRequest().getParameter(name);
}
protected void setAttr(String name, Object value) {
HttpKit.getRequest().setAttribute(name, value);
}
protected Integer getSystemInvokCount() {
return (Integer) this.getHttpServletRequest().getServletContext().getAttribute("systemCount");
}
/**
* 把service层的分页信息,封装为bootstrap table通用的分页封装
*/
protected <T> PageInfoBT<T> packForBT(Page<T> page) {
return new PageInfoBT<T>(page);
}
/**
* 包装一个list,让list增加额外属性
*/
protected Object warpObject(BaseControllerWarpper warpper) {
return warpper.warp();
}
/**
* 删除cookie
*/
protected void deleteCookieByName(String cookieName) {
Cookie[] cookies = this.getHttpServletRequest().getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookieName)) {
Cookie temp = new Cookie(cookie.getName(), "");
temp.setMaxAge(0);
this.getHttpServletResponse().addCookie(temp);
}
}
}
/**
* 返回前台文件流
*
* @author fengshuonan
* @date 2017年2月28日 下午2:53:19
*/
protected ResponseEntity<byte[]> renderFile(String fileName, String filePath) {
byte[] bytes = FileUtil.toByteArray(filePath);
return renderFile(fileName, bytes);
}
/**
* 返回前台文件流
*
* @author fengshuonan
* @date 2017年2月28日 下午2:53:19
*/
protected ResponseEntity<byte[]> renderFile(String fileName, byte[] fileBytes) {
String dfileName = null;
try {
dfileName = new String(fileName.getBytes("gb2312"), "iso8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", dfileName);
return new ResponseEntity<byte[]>(fileBytes, headers, HttpStatus.CREATED);
}
}
package com.stylefeng.guns.common.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 全局的控制器
*
* @author fengshuonan
* @date 2016年11月13日 下午11:04:45
*/
@Controller
@RequestMapping("/global")
public class GlobalController {
/**
* 跳转到404页面
*
* @author fengshuonan
*/
@RequestMapping(path = "/error")
public String errorPage() {
return "/404.html";
}
/**
* 跳转到session超时页面
*
* @author fengshuonan
*/
@RequestMapping(path = "/sessionError")
public String errorPageInfo(Model model) {
model.addAttribute("tips", "session超时");
return "/login.html";
}
}
package com.stylefeng.guns.common.controller;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* 错误页面的默认跳转
*
* @author fengshuonan
* @date 2017-05-21 11:34
*/
@Component("error")
public class GunsErrorView implements View{
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(Map<String, ?> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
httpServletRequest.getRequestDispatcher("/global/error").forward(httpServletRequest,httpServletResponse);
}
}
package com.stylefeng.guns.common.exception;
/**
* @Description 所有业务异常的枚举
* @author fengshuonan
* @date 2016年11月12日 下午5:04:51
*/
public enum BizExceptionEnum {
/**
* 字典
*/
DICT_EXISTED(400,"字典已经存在"),
ERROR_CREATE_DICT(500,"创建字典失败"),
ERROR_WRAPPER_FIELD(500,"包装字典属性失败"),
/**
* 文件上传
*/
FILE_READING_ERROR(400,"FILE_READING_ERROR!"),
FILE_NOT_FOUND(400,"FILE_NOT_FOUND!"),
UPLOAD_ERROR(500,"上传图片出错"),
/**
* 权限和数据问题
*/
DB_RESOURCE_NULL(400,"数据库中没有该资源"),
NO_PERMITION(405, "权限异常"),
REQUEST_INVALIDATE(400,"请求数据格式不正确"),
INVALID_KAPTCHA(400,"验证码不正确"),
CANT_DELETE_ADMIN(600,"不能删除超级管理员"),
CANT_FREEZE_ADMIN(600,"不能冻结超级管理员"),
CANT_CHANGE_ADMIN(600,"不能修改超级管理员角色"),
/**
* 账户问题
*/
USER_ALREADY_REG(401,"该用户已经注册"),
NO_THIS_USER(400,"没有此用户"),
USER_NOT_EXISTED(400, "没有此用户"),
ACCOUNT_FREEZED(401, "账号被冻结"),
OLD_PWD_NOT_RIGHT(402, "原密码不正确"),
TWO_PWD_NOT_MATCH(405, "两次输入密码不一致"),
/**
* 错误的请求
*/
MENU_PCODE_COINCIDENCE(400,"菜单编号和副编号不能一致"),
EXISTED_THE_MENU(400,"菜单编号重复,不能添加"),
DICT_MUST_BE_NUMBER(400,"字典的值必须为数字"),
REQUEST_NULL(400, "请求有错误"),
SESSION_TIMEOUT(400, "会话超时"),
SERVER_ERROR(500, "服务器异常");
BizExceptionEnum(int code, String message) {
this.friendlyCode = code;
this.friendlyMsg = message;
}
BizExceptionEnum(int code, String message,String urlPath) {
this.friendlyCode = code;
this.friendlyMsg = message;
this.urlPath = urlPath;
}
private int friendlyCode;
private String friendlyMsg;
private String urlPath;
public int getCode() {
return friendlyCode;
}
public void setCode(int code) {
this.friendlyCode = code;
}
public String getMessage() {
return friendlyMsg;
}
public void setMessage(String message) {
this.friendlyMsg = message;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
}
package com.stylefeng.guns.common.exception;
/**
* @Description 业务异常的封装
* @author fengshuonan
* @date 2016年11月12日 下午5:05:10
*/
@SuppressWarnings("serial")
public class BussinessException extends RuntimeException{
//友好提示的code码
private int friendlyCode;
//友好提示
private String friendlyMsg;
//业务异常跳转的页面
private String urlPath;
public BussinessException(BizExceptionEnum bizExceptionEnum){
this.friendlyCode = bizExceptionEnum.getCode();
this.friendlyMsg = bizExceptionEnum.getMessage();
this.urlPath = bizExceptionEnum.getUrlPath();
}
public int getCode() {
return friendlyCode;
}
public void setCode(int code) {
this.friendlyCode = code;
}
public String getMessage() {
return friendlyMsg;
}
public void setMessage(String message) {
this.friendlyMsg = message;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
}
package com.stylefeng.guns.common.exception;
/**
* 验证码错误异常
*
* @author fengshuonan
* @date 2017-05-05 23:52
*/
public class InvalidKaptchaException extends RuntimeException {
}
/**
* Copyright (c) 2015-2017, Chill Zhuang 庄骞 (smallchill@163.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.common.exception;
import com.stylefeng.guns.core.support.StrKit;
/**
* 工具类初始化异常
*/
public class ToolBoxException extends RuntimeException{
private static final long serialVersionUID = 8247610319171014183L;
public ToolBoxException(Throwable e) {
super(e.getMessage(), e);
}
public ToolBoxException(String message) {
super(message);
}
public ToolBoxException(String messageTemplate, Object... params) {
super(StrKit.format(messageTemplate, params));
}
public ToolBoxException(String message, Throwable throwable) {
super(message, throwable);
}
public ToolBoxException(Throwable throwable, String messageTemplate, Object... params) {
super(StrKit.format(messageTemplate, params), throwable);
}
}
package com.stylefeng.guns.common.node;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.constant.state.IsMenu;
import com.stylefeng.guns.config.properties.GunsProperties;
import com.stylefeng.guns.core.util.SpringContextHolder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* @author fengshuonan
* @Description 菜单的节点
* @date 2016年12月6日 上午11:34:17
*/
public class MenuNode implements Comparable {
/**
* 节点id
*/
private Integer id;
/**
* 父节点
*/
private Integer parentId;
/**
* 节点名称
*/
private String name;
/**
* 按钮级别
*/
private Integer levels;
/**
* 按钮级别
*/
private Integer ismenu;
/**
* 按钮的排序
*/
private Integer num;
/**
* 节点的url
*/
private String url;
/**
* 节点图标
*/
private String icon;
/**
* 子节点的集合
*/
private List<MenuNode> children;
/**
* 查询子节点时候的临时集合
*/
private List<MenuNode> linkedList = new ArrayList<MenuNode>();
public MenuNode() {
super();
}
public MenuNode(Integer id, Integer parentId) {
super();
this.id = id;
this.parentId = parentId;
}
public Integer getLevels() {
return levels;
}
public void setLevels(Integer levels) {
this.levels = levels;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public static MenuNode createRoot() {
return new MenuNode(0, -1);
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<MenuNode> getChildren() {
return children;
}
public void setChildren(List<MenuNode> children) {
this.children = children;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getIsmenu() {
return ismenu;
}
public void setIsmenu(Integer ismenu) {
this.ismenu = ismenu;
}
@Override
public String toString() {
return "MenuNode{" +
"id=" + id +
", parentId=" + parentId +
", name='" + name + '\'' +
", levels=" + levels +
", num=" + num +
", url='" + url + '\'' +
", icon='" + icon + '\'' +
", children=" + children +
", linkedList=" + linkedList +
'}';
}
@Override
public int compareTo(Object o) {
MenuNode menuNode = (MenuNode) o;
Integer num = menuNode.getNum();
if (num == null) {
num = 0;
}
return this.num.compareTo(num);
}
/**
* 构建整个菜单树
*
* @author fengshuonan
*/
public void buildNodeTree(List<MenuNode> nodeList) {
for (MenuNode treeNode : nodeList) {
List<MenuNode> linkedList = treeNode.findChildNodes(nodeList, treeNode.getId());
if (linkedList.size() > 0) {
treeNode.setChildren(linkedList);
}
}
}
/**
* 查询子节点的集合
*
* @author fengshuonan
*/
public List<MenuNode> findChildNodes(List<MenuNode> nodeList, Integer parentId) {
if (nodeList == null && parentId == null)
return null;
for (Iterator<MenuNode> iterator = nodeList.iterator(); iterator.hasNext(); ) {
MenuNode node = (MenuNode) iterator.next();
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
if (node.getParentId() != 0 && parentId.equals(node.getParentId())) {
recursionFn(nodeList, node, parentId);
}
}
return linkedList;
}
/**
* 遍历一个节点的子节点
*
* @author fengshuonan
*/
public void recursionFn(List<MenuNode> nodeList, MenuNode node, Integer pId) {
List<MenuNode> childList = getChildList(nodeList, node);// 得到子节点列表
if (childList.size() > 0) {// 判断是否有子节点
if (node.getParentId().equals(pId)) {
linkedList.add(node);
}
Iterator<MenuNode> it = childList.iterator();
while (it.hasNext()) {
MenuNode n = (MenuNode) it.next();
recursionFn(nodeList, n, pId);
}
} else {
if (node.getParentId().equals(pId)) {
linkedList.add(node);
}
}
}
/**
* 得到子节点列表
*
* @author fengshuonan
*/
private List<MenuNode> getChildList(List<MenuNode> list, MenuNode node) {
List<MenuNode> nodeList = new ArrayList<MenuNode>();
Iterator<MenuNode> it = list.iterator();
while (it.hasNext()) {
MenuNode n = (MenuNode) it.next();
if (n.getParentId().equals(node.getId())) {
nodeList.add(n);
}
}
return nodeList;
}
/**
* 清除掉按钮级别的资源
*
* @date 2017年2月19日 下午11:04:11
*/
public static List<MenuNode> clearBtn(List<MenuNode> nodes) {
ArrayList<MenuNode> noBtns = new ArrayList<MenuNode>();
for (MenuNode node : nodes) {
if(node.getIsmenu() == IsMenu.YES.getCode()){
noBtns.add(node);
}
}
return noBtns;
}
/**
* 清除所有二级菜单
*
* @date 2017年2月19日 下午11:18:19
*/
public static List<MenuNode> clearLevelTwo(List<MenuNode> nodes) {
ArrayList<MenuNode> results = new ArrayList<MenuNode>();
for (MenuNode node : nodes) {
Integer levels = node.getLevels();
if (levels.equals(1)) {
results.add(node);
}
}
return results;
}
/**
* 构建菜单列表
*
* @date 2017年2月19日 下午11:18:19
*/
public static List<MenuNode> buildTitle(List<MenuNode> nodes) {
List<MenuNode> clearBtn = clearBtn(nodes);
new MenuNode().buildNodeTree(clearBtn);
List<MenuNode> menuNodes = clearLevelTwo(clearBtn);
//对菜单排序
Collections.sort(menuNodes);
//对菜单的子菜单进行排序
for (MenuNode menuNode : menuNodes) {
if (menuNode.getChildren() != null && menuNode.getChildren().size() > 0) {
Collections.sort(menuNode.getChildren());
}
}
//如果关闭了接口文档,则不显示接口文档菜单
GunsProperties gunsProperties = SpringContextHolder.getBean(GunsProperties.class);
if (!gunsProperties.getSwaggerOpen()) {
List<MenuNode> menuNodesCopy = new ArrayList<>();
for (MenuNode menuNode : menuNodes) {
if (Const.API_MENU_NAME.equals(menuNode.getName())) {
continue;
} else {
menuNodesCopy.add(menuNode);
}
}
menuNodes = menuNodesCopy;
}
return menuNodes;
}
}
package com.stylefeng.guns.common.node;
/**
*
* jquery ztree 插件的节点
*
* @author fengshuonan
* @date 2017年2月17日 下午8:25:14
*/
public class ZTreeNode {
private Integer id; //节点id
private Integer pId;//父节点id
private String name;//节点名称
private Boolean open;//是否打开节点
private Boolean checked;//是否被选中
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getpId() {
return pId;
}
public void setpId(Integer pId) {
this.pId = pId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getOpen() {
return open;
}
public void setOpen(Boolean open) {
this.open = open;
}
public Boolean getIsOpen() {
return open;
}
public void setIsOpen(Boolean open) {
this.open = open;
}
public Boolean getChecked() {
return checked;
}
public void setChecked(Boolean checked) {
this.checked = checked;
}
public static ZTreeNode createParent(){
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setChecked(true);
zTreeNode.setId(0);
zTreeNode.setName("顶级");
zTreeNode.setOpen(true);
zTreeNode.setpId(0);
return zTreeNode;
}
}
package com.stylefeng.guns.common.page;
/**
* 分页参数类(for BootStrap Table)
*
* @author fengshuonan
* @date 2017年1月21日 下午2:21:35
*/
public class PageBT {
private int limit; // 每页显示个数
private int offset; // 查询的偏移量(查询的页数 = offset/limit + 1)
private String order; // 排序方式
public PageBT() {
super();
}
public PageBT(int limit, int offset) {
super();
this.limit = limit;
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
public int getPageSize() {
return this.limit;
}
public int getPageNumber() {
return this.offset / this.limit + 1;
}
@Override
public String toString() {
return "PageBT [limit=" + limit + ", offset=" + offset + ", order=" + order + "]";
}
}
package com.stylefeng.guns.common.page;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;
/**
* 分页结果的封装(for Bootstrap Table)
*
* @author fengshuonan
* @Date 2017年1月22日 下午11:06:41
*/
public class PageInfoBT<T> {
// 结果集
private List<T> rows;
// 总数
private long total;
public PageInfoBT(Page<T> page) {
this.rows = page.getRecords();
this.total = page.getTotal();
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
}
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Dept;
/**
* <p>
* 部门表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface DeptMapper extends BaseMapper<Dept> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Dict;
/**
* <p>
* 字典表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface DictMapper extends BaseMapper<Dict> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.LoginLog;
/**
* <p>
* 登录记录 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface LoginLogMapper extends BaseMapper<LoginLog> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Menu;
/**
* <p>
* 菜单表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface MenuMapper extends BaseMapper<Menu> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Notice;
/**
* <p>
* 通知表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface NoticeMapper extends BaseMapper<Notice> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.OperationLog;
/**
* <p>
* 操作日志 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface OperationLogMapper extends BaseMapper<OperationLog> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Relation;
/**
* <p>
* 角色和菜单关联表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface RelationMapper extends BaseMapper<Relation> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Role;
/**
* <p>
* 角色表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface RoleMapper extends BaseMapper<Role> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.Test;
/**
* <p>
* Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface TestMapper extends BaseMapper<Test> {
}
\ No newline at end of file
package com.stylefeng.guns.common.persistence.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.common.persistence.model.User;
/**
* <p>
* 管理员表 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public interface UserMapper extends BaseMapper<User> {
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.DeptMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Dept">
<id column="id" property="id" />
<result column="num" property="num" />
<result column="pid" property="pid" />
<result column="pids" property="pids" />
<result column="simplename" property="simplename" />
<result column="fullname" property="fullname" />
<result column="tips" property="tips" />
<result column="version" property="version" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.DictMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Dict">
<id column="id" property="id" />
<result column="num" property="num" />
<result column="pid" property="pid" />
<result column="name" property="name" />
<result column="tips" property="tips" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.LoginLogMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.LoginLog">
<id column="id" property="id" />
<result column="logname" property="logname" />
<result column="userid" property="userid" />
<result column="createtime" property="createtime" />
<result column="succeed" property="succeed" />
<result column="message" property="message" />
<result column="ip" property="ip" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.MenuMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Menu">
<id column="id" property="id" />
<result column="code" property="code" />
<result column="pcode" property="pcode" />
<result column="pcodes" property="pcodes" />
<result column="name" property="name" />
<result column="icon" property="icon" />
<result column="url" property="url" />
<result column="num" property="num" />
<result column="levels" property="levels" />
<result column="ismenu" property="ismenu" />
<result column="tips" property="tips" />
<result column="status" property="status" />
<result column="isopen" property="isopen" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.NoticeMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Notice">
<id column="id" property="id" />
<result column="title" property="title" />
<result column="type" property="type" />
<result column="content" property="content" />
<result column="createtime" property="createtime" />
<result column="creater" property="creater" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.OperationLogMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.OperationLog">
<id column="id" property="id" />
<result column="logtype" property="logtype" />
<result column="logname" property="logname" />
<result column="userid" property="userid" />
<result column="classname" property="classname" />
<result column="method" property="method" />
<result column="createtime" property="createtime" />
<result column="succeed" property="succeed" />
<result column="message" property="message" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.RelationMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Relation">
<id column="id" property="id" />
<result column="menuid" property="menuid" />
<result column="roleid" property="roleid" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.RoleMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Role">
<id column="id" property="id" />
<result column="num" property="num" />
<result column="pid" property="pid" />
<result column="name" property="name" />
<result column="deptid" property="deptid" />
<result column="tips" property="tips" />
<result column="version" property="version" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.TestMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.Test">
<id column="id" property="id" />
<result column="value" property="value" />
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.common.persistence.dao.UserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.stylefeng.guns.common.persistence.model.User">
<id column="id" property="id" />
<result column="avatar" property="avatar" />
<result column="account" property="account" />
<result column="password" property="password" />
<result column="salt" property="salt" />
<result column="name" property="name" />
<result column="birthday" property="birthday" />
<result column="sex" property="sex" />
<result column="email" property="email" />
<result column="phone" property="phone" />
<result column="roleid" property="roleid" />
<result column="deptid" property="deptid" />
<result column="status" property="status" />
<result column="createtime" property="createtime" />
<result column="version" property="version" />
</resultMap>
</mapper>
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
/**
* <p>
* 部门表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Dept extends Model<Dept> {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 排序
*/
private Integer num;
/**
* 父部门id
*/
private Integer pid;
/**
* 父级ids
*/
private String pids;
/**
* 简称
*/
private String simplename;
/**
* 全称
*/
private String fullname;
/**
* 提示
*/
private String tips;
/**
* 版本(乐观锁保留字段)
*/
private Integer version;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getPids() {
return pids;
}
public void setPids(String pids) {
this.pids = pids;
}
public String getSimplename() {
return simplename;
}
public void setSimplename(String simplename) {
this.simplename = simplename;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Dept{" +
"id=" + id +
", num=" + num +
", pid=" + pid +
", pids=" + pids +
", simplename=" + simplename +
", fullname=" + fullname +
", tips=" + tips +
", version=" + version +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
/**
* <p>
* 字典表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Dict extends Model<Dict> {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 排序
*/
private Integer num;
/**
* 父级字典
*/
private Integer pid;
/**
* 名称
*/
private String name;
/**
* 提示
*/
private String tips;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Dict{" +
"id=" + id +
", num=" + num +
", pid=" + pid +
", name=" + name +
", tips=" + tips +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 登录记录
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
@TableName("login_log")
public class LoginLog extends Model<LoginLog> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 日志名称
*/
private String logname;
/**
* 管理员id
*/
private Integer userid;
/**
* 创建时间
*/
private Date createtime;
/**
* 是否执行成功
*/
private String succeed;
/**
* 具体消息
*/
private String message;
/**
* 登录ip
*/
private String ip;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public String getSucceed() {
return succeed;
}
public void setSucceed(String succeed) {
this.succeed = succeed;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "LoginLog{" +
"id=" + id +
", logname=" + logname +
", userid=" + userid +
", createtime=" + createtime +
", succeed=" + succeed +
", message=" + message +
", ip=" + ip +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
/**
* <p>
* 菜单表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Menu extends Model<Menu> {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 菜单编号
*/
private String code;
/**
* 菜单父编号
*/
private String pcode;
/**
* 当前菜单的所有父菜单编号
*/
private String pcodes;
/**
* 菜单名称
*/
private String name;
/**
* 菜单图标
*/
private String icon;
/**
* url地址
*/
private String url;
/**
* 菜单排序号
*/
private Integer num;
/**
* 菜单层级
*/
private Integer levels;
/**
* 是否是菜单(1:是 0:不是)
*/
private Integer ismenu;
/**
* 备注
*/
private String tips;
/**
* 菜单状态 : 1:启用 0:不启用
*/
private Integer status;
/**
* 是否打开: 1:打开 0:不打开
*/
private Integer isopen;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPcode() {
return pcode;
}
public void setPcode(String pcode) {
this.pcode = pcode;
}
public String getPcodes() {
return pcodes;
}
public void setPcodes(String pcodes) {
this.pcodes = pcodes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getLevels() {
return levels;
}
public void setLevels(Integer levels) {
this.levels = levels;
}
public Integer getIsmenu() {
return ismenu;
}
public void setIsmenu(Integer ismenu) {
this.ismenu = ismenu;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getIsopen() {
return isopen;
}
public void setIsopen(Integer isopen) {
this.isopen = isopen;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Menu{" +
"id=" + id +
", code=" + code +
", pcode=" + pcode +
", pcodes=" + pcodes +
", name=" + name +
", icon=" + icon +
", url=" + url +
", num=" + num +
", levels=" + levels +
", ismenu=" + ismenu +
", tips=" + tips +
", status=" + status +
", isopen=" + isopen +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 通知表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Notice extends Model<Notice> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 标题
*/
private String title;
/**
* 类型
*/
private Integer type;
/**
* 内容
*/
private String content;
/**
* 创建时间
*/
private Date createtime;
/**
* 创建人
*/
private Integer creater;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Integer getCreater() {
return creater;
}
public void setCreater(Integer creater) {
this.creater = creater;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Notice{" +
"id=" + id +
", title=" + title +
", type=" + type +
", content=" + content +
", createtime=" + createtime +
", creater=" + creater +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 操作日志
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
@TableName("operation_log")
public class OperationLog extends Model<OperationLog> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 日志类型
*/
private String logtype;
/**
* 日志名称
*/
private String logname;
/**
* 用户id
*/
private Integer userid;
/**
* 类名称
*/
private String classname;
/**
* 方法名称
*/
private String method;
/**
* 创建时间
*/
private Date createtime;
/**
* 是否成功
*/
private String succeed;
/**
* 备注
*/
private String message;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLogtype() {
return logtype;
}
public void setLogtype(String logtype) {
this.logtype = logtype;
}
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getClassname() {
return classname;
}
public void setClassname(String classname) {
this.classname = classname;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public String getSucceed() {
return succeed;
}
public void setSucceed(String succeed) {
this.succeed = succeed;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "OperationLog{" +
"id=" + id +
", logtype=" + logtype +
", logname=" + logname +
", userid=" + userid +
", classname=" + classname +
", method=" + method +
", createtime=" + createtime +
", succeed=" + succeed +
", message=" + message +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
/**
* <p>
* 角色和菜单关联表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Relation extends Model<Relation> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 菜单id
*/
private Integer menuid;
/**
* 角色id
*/
private Integer roleid;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getMenuid() {
return menuid;
}
public void setMenuid(Integer menuid) {
this.menuid = menuid;
}
public Integer getRoleid() {
return roleid;
}
public void setRoleid(Integer roleid) {
this.roleid = roleid;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Relation{" +
"id=" + id +
", menuid=" + menuid +
", roleid=" + roleid +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
/**
* <p>
* 角色表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Role extends Model<Role> {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 序号
*/
private Integer num;
/**
* 父角色id
*/
private Integer pid;
/**
* 角色名称
*/
private String name;
/**
* 部门名称
*/
private Integer deptid;
/**
* 提示
*/
private String tips;
/**
* 保留字段(暂时没用)
*/
private Integer version;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Role{" +
"id=" + id +
", num=" + num +
", pid=" + pid +
", name=" + name +
", deptid=" + deptid +
", tips=" + tips +
", version=" + version +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class Test extends Model<Test> {
private static final long serialVersionUID = 1L;
private Integer id;
private String value;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "Test{" +
"id=" + id +
", value=" + value +
"}";
}
}
package com.stylefeng.guns.common.persistence.model;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 管理员表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public class User extends Model<User> {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value="id", type= IdType.AUTO)
private Integer id;
/**
* 头像
*/
private String avatar;
/**
* 账号
*/
private String account;
/**
* 密码
*/
private String password;
/**
* md5密码盐
*/
private String salt;
/**
* 名字
*/
private String name;
/**
* 生日
*/
private Date birthday;
/**
* 性别(1:男 2:女)
*/
private Integer sex;
/**
* 电子邮件
*/
private String email;
/**
* 电话
*/
private String phone;
/**
* 角色id
*/
private String roleid;
/**
* 部门id
*/
private Integer deptid;
/**
* 状态(1:启用 2:冻结 3:删除)
*/
private Integer status;
/**
* 创建时间
*/
private Date createtime;
/**
* 保留字段
*/
private Integer version;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getRoleid() {
return roleid;
}
public void setRoleid(String roleid) {
this.roleid = roleid;
}
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Override
protected Serializable pkVal() {
return this.id;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", avatar=" + avatar +
", account=" + account +
", password=" + password +
", salt=" + salt +
", name=" + name +
", birthday=" + birthday +
", sex=" + sex +
", email=" + email +
", phone=" + phone +
", roleid=" + roleid +
", deptid=" + deptid +
", status=" + status +
", createtime=" + createtime +
", version=" + version +
"}";
}
}
package com.stylefeng.guns.common.warpper;
import java.util.List;
import java.util.Map;
/**
* 控制器查询结果的包装类基类
*
* @author fengshuonan
* @date 2017年2月13日 下午10:49:36
*/
public abstract class BaseControllerWarpper {
public Object obj = null;
public BaseControllerWarpper(Object obj) {
this.obj = obj;
}
@SuppressWarnings("unchecked")
public Object warp() {
if (this.obj instanceof List) {
List<Map<String, Object>> list = (List<Map<String, Object>>) this.obj;
for (Map<String, Object> map : list) {
warpTheMap(map);
}
return list;
} else if (this.obj instanceof Map) {
Map<String, Object> map = (Map<String, Object>) this.obj;
warpTheMap(map);
return map;
} else {
return this.obj;
}
}
protected abstract void warpTheMap(Map<String, Object> map);
}
package com.stylefeng.guns.config;
import net.sf.ehcache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
/**
* ehcache配置
*
* @author fengshuonan
* @date 2017-05-20 23:11
*/
@Configuration
@EnableCaching
public class EhCacheConfig {
/**
* EhCache的配置
*/
@Bean
public EhCacheCacheManager cacheManager(CacheManager cacheManager) {
return new EhCacheCacheManager(cacheManager);
}
/**
* EhCache的配置
*/
@Bean
public EhCacheManagerFactoryBean ehcache() {
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
return ehCacheManagerFactoryBean;
}
}
package com.stylefeng.guns.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import java.nio.charset.Charset;
import java.util.ArrayList;
/**
* fastjson配置类
*
* @author fengshuonan
* @date 2017-05-23 22:56
*/
@Configuration
public class FastjsonConfig {
@Bean
public FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat,
SerializerFeature.WriteMapNullValue
);
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
ValueFilter valueFilter = new ValueFilter() {
public Object process(Object o, String s, Object o1) {
if (null == o1) {
o1 = "";
}
return o1;
}
};
fastJsonConfig.setCharset(Charset.forName("utf-8"));
fastJsonConfig.setSerializeFilters(valueFilter);
converter.setFastJsonConfig(fastJsonConfig);
ArrayList<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
converter.setSupportedMediaTypes(mediaTypes);
return converter;
}
}
package com.stylefeng.guns.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.stylefeng.guns.common.constant.DSEnum;
import com.stylefeng.guns.config.properties.DruidProperties;
import com.stylefeng.guns.config.properties.MutiDataSourceProperties;
import com.stylefeng.guns.core.datascope.DataScopeInterceptor;
import com.stylefeng.guns.core.mutidatesource.DynamicDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.sql.SQLException;
import java.util.HashMap;
/**
* MybatisPlus配置
*
* @author stylefeng
* @Date 2017/5/20 21:58
*/
@Configuration
@EnableTransactionManagement(order = 2)//由于引入多数据源,所以让spring事务的aop要在多数据源切换aop的后面
@MapperScan(basePackages = {"com.stylefeng.guns.modular.*.dao", "com.stylefeng.guns.common.persistence.dao"})
public class MybatisPlusConfig {
@Autowired
DruidProperties druidProperties;
@Autowired
MutiDataSourceProperties mutiDataSourceProperties;
/**
* 另一个数据源
*/
private DruidDataSource bizDataSource() {
DruidDataSource dataSource = new DruidDataSource();
druidProperties.config(dataSource);
mutiDataSourceProperties.config(dataSource);
return dataSource;
}
/**
* guns的数据源
*/
private DruidDataSource dataSourceGuns(){
DruidDataSource dataSource = new DruidDataSource();
druidProperties.config(dataSource);
return dataSource;
}
/**
* 单数据源连接池配置
*/
@Bean
@ConditionalOnProperty(prefix = "guns", name = "muti-datasource-open", havingValue = "false")
public DruidDataSource singleDatasource() {
return dataSourceGuns();
}
/**
* 多数据源连接池配置
*/
@Bean
@ConditionalOnProperty(prefix = "guns", name = "muti-datasource-open", havingValue = "true")
public DynamicDataSource mutiDataSource() {
DruidDataSource dataSourceGuns = dataSourceGuns();
DruidDataSource bizDataSource = bizDataSource();
try {
dataSourceGuns.init();
bizDataSource.init();
}catch (SQLException sql){
sql.printStackTrace();
}
DynamicDataSource dynamicDataSource = new DynamicDataSource();
HashMap<Object, Object> hashMap = new HashMap();
hashMap.put(DSEnum.DATA_SOURCE_GUNS, dataSourceGuns);
hashMap.put(DSEnum.DATA_SOURCE_BIZ, bizDataSource);
dynamicDataSource.setTargetDataSources(hashMap);
dynamicDataSource.setDefaultTargetDataSource(dataSourceGuns);
return dynamicDataSource;
}
/**
* mybatis-plus分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
/**
* 数据范围mybatis插件
*/
@Bean
public DataScopeInterceptor dataScopeInterceptor() {
return new DataScopeInterceptor();
}
}
package com.stylefeng.guns.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
* spring session配置
*
* @author fengshuonan
* @date 2017-07-13 21:05
*/
//@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800) //session过期时间 如果部署多机环境,需要打开注释
@ConditionalOnProperty(prefix = "guns", name = "spring-session-open", havingValue = "true")
public class SpringSessionConfig {
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment