├── .editorconfig
├── LICENSE
├── README.md
├── goblin-admin-ui
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── goblin
│ │ ├── AdminUiApplication.java
│ │ └── config
│ │ ├── NotifierConfiguration.java
│ │ └── SecurityConfig.java
│ └── resources
│ └── application.yml
├── goblin-basic-config
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── goblin
│ ├── GlobalErrorController.java
│ └── config
│ ├── FeignOkHttpConfig.java
│ ├── MybatisPlusConfig.java
│ ├── SpringConfig.java
│ ├── Swagger2Config.java
│ ├── ThreadPoolConfig.java
│ ├── TransactionalConfig.java
│ └── WebSocketConfig.java
├── goblin-cache
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── goblin
│ └── cache
│ ├── client
│ ├── JedisClient.java
│ └── impl
│ │ └── JedisClientPool.java
│ └── config
│ ├── RedisConfig.java
│ └── SpringCacheConfig.java
├── goblin-common
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── goblin
│ │ └── common
│ │ ├── GlobalConstant.java
│ │ ├── PagingRequest.java
│ │ ├── ResponseEntityPro.java
│ │ ├── SimpleDateFormatPro.java
│ │ ├── Tips.java
│ │ ├── annotation
│ │ ├── ExportFiledComment.java
│ │ ├── FiledComment.java
│ │ ├── Log.java
│ │ ├── NeedExport.java
│ │ └── PassInjectionAttackIntercept.java
│ │ ├── converter
│ │ └── StringToDateConverter.java
│ │ ├── cron
│ │ └── CustomizeCron.java
│ │ ├── drools
│ │ └── DroolsUtils.java
│ │ ├── exception
│ │ ├── CaptchaException.java
│ │ ├── DaoException.java
│ │ ├── ForbiddenException.java
│ │ ├── ResourceNotFoundException.java
│ │ ├── ServiceException.java
│ │ └── ValidatedIllegalArgumentException.java
│ │ ├── filter
│ │ ├── BodyReaderWrapper.java
│ │ ├── InjectionAttackFilter.java
│ │ ├── RequestLoggingFilter.java
│ │ └── handler
│ │ │ ├── DefaultInjectionAttackHandler.java
│ │ │ ├── InjectionAttackHandler.java
│ │ │ └── InjectionAttackPassHandle.java
│ │ ├── http
│ │ └── OkHttpFactory.java
│ │ ├── interceptor
│ │ └── InjectionAttackInterceptor.java
│ │ ├── regex
│ │ └── RegexType.java
│ │ └── util
│ │ ├── AssertUtils.java
│ │ ├── BeanProUtils.java
│ │ ├── BigDecimalUtils.java
│ │ ├── CollectionProUtils.java
│ │ ├── DateFormatStyle.java
│ │ ├── DateUtils.java
│ │ ├── DistributedCode.java
│ │ ├── DistributedLock.java
│ │ ├── Export.java
│ │ ├── HibernateValidatorPro.java
│ │ ├── JsonUtils.java
│ │ ├── LogUtils.java
│ │ ├── RecursionUtils.java
│ │ ├── ReflectionProUtils.java
│ │ ├── RequestUtils.java
│ │ ├── StringProUtils.java
│ │ ├── TransactionUtils.java
│ │ └── ValidatedGroups.java
│ └── test
│ └── java
│ └── com
│ └── goblin
│ ├── excel
│ └── ExcelTest.java
│ ├── json
│ └── User.java
│ └── response
│ ├── ResponseEntityProTest.java
│ └── User.java
├── goblin-generator
├── pom.xml
└── src
│ ├── main
│ └── resources
│ │ └── templates
│ │ └── mybatis
│ │ └── plus
│ │ ├── controller.java.vm
│ │ ├── entity.java.vm
│ │ ├── service.java.vm
│ │ └── serviceImpl.java.vm
│ └── test
│ └── java
│ └── com
│ └── goblin
│ └── generator
│ └── mybatis
│ └── plus
│ └── MysqlGenerator.java
├── goblin-manage-system
├── README.md
├── goblin-manage-system-bean
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── goblin
│ │ └── manage
│ │ └── bean
│ │ ├── domain
│ │ ├── MailSubscribe.java
│ │ ├── PermissionResource.java
│ │ ├── Role.java
│ │ ├── RolePermissionResource.java
│ │ ├── SmsSubscribe.java
│ │ ├── SystemConfig.java
│ │ ├── SystemLog.java
│ │ ├── User.java
│ │ ├── UserRole.java
│ │ └── enums
│ │ │ ├── EmailSendState.java
│ │ │ ├── NoticeType.java
│ │ │ ├── ResourceType.java
│ │ │ └── ToEmailType.java
│ │ ├── dto
│ │ ├── PermissionResourceForm.java
│ │ ├── RoleUpdateForm.java
│ │ └── UserForm.java
│ │ └── vo
│ │ ├── PermissionResourceVO.java
│ │ └── UserVO.java
├── goblin-manage-system-dao
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── goblin
│ │ └── manage
│ │ └── mapper
│ │ ├── MailSubscribeMapper.java
│ │ ├── PermissionResourceMapper.java
│ │ ├── RoleMapper.java
│ │ ├── RolePermissionResourceMapper.java
│ │ ├── SmsSubscribeMapper.java
│ │ ├── SystemConfigMapper.java
│ │ ├── SystemLogMapper.java
│ │ ├── UserMapper.java
│ │ ├── UserRoleMapper.java
│ │ └── xml
│ │ ├── MailSubscribeMapper.xml
│ │ ├── PermissionResourceMapper.xml
│ │ ├── RoleMapper.xml
│ │ ├── RolePermissionResourceMapper.xml
│ │ ├── SmsSubscribeMapper.xml
│ │ ├── SystemConfigMapper.xml
│ │ ├── SystemLogMapper.xml
│ │ ├── UserMapper.xml
│ │ └── UserRoleMapper.xml
├── goblin-manage-system-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── goblin
│ │ └── manage
│ │ ├── GlobalCacheConstant.java
│ │ └── service
│ │ ├── AggregationService.java
│ │ ├── CaptchaService.java
│ │ ├── MailSubscribeService.java
│ │ ├── PermissionResourceService.java
│ │ ├── RolePermissionResourceService.java
│ │ ├── RoleService.java
│ │ ├── SystemConfigService.java
│ │ ├── SystemLogService.java
│ │ ├── UserRoleService.java
│ │ ├── UserService.java
│ │ └── impl
│ │ ├── AggregationServiceImpl.java
│ │ ├── CaptchaServiceImpl.java
│ │ ├── MailSubscribeServiceImpl.java
│ │ ├── PermissionResourceServiceImpl.java
│ │ ├── RolePermissionResourceServiceImpl.java
│ │ ├── RoleServiceImpl.java
│ │ ├── SystemConfigServiceImpl.java
│ │ ├── SystemLogServiceImpl.java
│ │ ├── UserRoleServiceImpl.java
│ │ └── UserServiceImpl.java
├── goblin-manage-system-webapp
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── docker
│ │ │ └── Dockerfile
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── goblin
│ │ │ │ └── manage
│ │ │ │ ├── ContextUtils.java
│ │ │ │ ├── LogAspect.java
│ │ │ │ ├── ManageSystemWebAppApplication.java
│ │ │ │ ├── PagingRequestBodyAdvice.java
│ │ │ │ ├── ResponseEntityAspect.java
│ │ │ │ ├── config
│ │ │ │ ├── BasicBeanConfig.java
│ │ │ │ └── SpringInterceptorConfig.java
│ │ │ │ ├── controller
│ │ │ │ ├── AuthenticationController.java
│ │ │ │ ├── DemoController.java
│ │ │ │ ├── DistributedDemoController.java
│ │ │ │ ├── EnumDemoController.java
│ │ │ │ ├── LogDemoController.java
│ │ │ │ ├── RuleController.java
│ │ │ │ ├── UserValidatorDemoController.java
│ │ │ │ └── WebSocketDemoController.java
│ │ │ │ ├── jwt
│ │ │ │ ├── JwtUser.java
│ │ │ │ └── JwtUserDetailsService.java
│ │ │ │ └── permission
│ │ │ │ ├── AdminPermissionInterceptor.java
│ │ │ │ ├── NotNeedPermission.java
│ │ │ │ └── Pass.java
│ │ └── resources
│ │ │ ├── application-dev.yml
│ │ │ ├── application-prod.yml
│ │ │ ├── application-test.yml
│ │ │ ├── application.yml
│ │ │ ├── log4j2-production.xml
│ │ │ ├── log4j2.xml
│ │ │ └── static
│ │ │ ├── 401.html
│ │ │ ├── 404.html
│ │ │ ├── 500.html
│ │ │ ├── app.js
│ │ │ ├── index.html
│ │ │ ├── main.css
│ │ │ ├── rule
│ │ │ ├── css
│ │ │ │ ├── main.css
│ │ │ │ └── normalize.css
│ │ │ ├── index.html
│ │ │ └── js
│ │ │ │ ├── main.js
│ │ │ │ ├── plugins.js
│ │ │ │ └── vendor
│ │ │ │ ├── jquery-3.3.1.min.js
│ │ │ │ └── modernizr-3.6.0.min.js
│ │ │ ├── sockjs.js
│ │ │ ├── stomp.js
│ │ │ └── success.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── goblin
│ │ └── manage
│ │ ├── AggregationServiceTest.java
│ │ ├── PasswordEncoderTest.java
│ │ ├── UserServiceTest.java
│ │ ├── encrypted
│ │ └── JasyptStringEncryptorTest.java
│ │ └── service
│ │ ├── MailSubscribeServiceTest.java
│ │ ├── PermissionResourceServiceTest.java
│ │ ├── RolePermissionResourceServiceTest.java
│ │ ├── RoleServiceTest.java
│ │ ├── SystemConfigServiceTest.java
│ │ ├── SystemLogServiceTest.java
│ │ ├── UserRoleServiceTest.java
│ │ └── UserServiceTest.java
├── pom.xml
├── restart.sh
├── start.sh
└── stop.sh
├── goblin-parent
└── pom.xml
├── goblin-scheduling
├── README.md
├── pom.xml
├── restart.sh
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── goblin
│ │ │ ├── SchedulingApplication.java
│ │ │ ├── config
│ │ │ ├── BeanConfig.java
│ │ │ ├── RedisConfig.java
│ │ │ └── ThreadPoolConfig.java
│ │ │ └── scheduling
│ │ │ └── DemoTask.java
│ │ └── resources
│ │ ├── application-dev.yml
│ │ ├── application-prod.yml
│ │ ├── application-test.yml
│ │ ├── application.yml
│ │ ├── log4j2-production.xml
│ │ └── log4j2.xml
├── start.sh
└── stop.sh
├── goblin-security
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── goblin
│ └── security
│ ├── BasicJwtUser.java
│ ├── JwtAuthenticationEntryPoint.java
│ ├── JwtAuthenticationTokenFilter.java
│ ├── JwtTokenUtil.java
│ ├── config
│ ├── SpringSecurityConfig.java
│ └── SpringWebSocketSecurityConfig.java
│ └── websocket
│ └── JwtWebSocketInterceptorAdapter.java
├── pom.xml
└── resources
├── 1.png
├── 2.png
├── 3.png
├── init-mysql.sql
└── manage_system.pdm
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = UTF-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 |
8 | # 对java和xml文件生效
9 | [*.{java,xml}]
10 | trim_trailing_whitespace = true
11 | indent_style = tab
12 | indent_size = 4
13 |
14 |
15 | # Matches the exact files either package.json or .travis.yml
16 | [*.yml]
17 | indent_style = space
18 | indent_size = 2
19 |
--------------------------------------------------------------------------------
/goblin-admin-ui/README.md:
--------------------------------------------------------------------------------
1 | spring boot 2.0 暂未支持
2 |
--------------------------------------------------------------------------------
/goblin-admin-ui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 | * goblin: 22 | * feign-ok-http-config: 23 | * readTimeout: 60 24 | * connectTimeout: 60 25 | * writeTimeout: 180 26 | * feign: 27 | * httpclient: 28 | * enabled: false 29 | * okhttp: 30 | * enabled: true 31 | *32 | * 33 | * @author : 披荆斩棘 34 | * @date : 2017/8/4 35 | */ 36 | @Setter 37 | @Getter 38 | @ToString 39 | @Configuration 40 | @ConditionalOnClass( Feign.class ) 41 | @AutoConfigureBefore( FeignAutoConfiguration.class ) 42 | @ConfigurationProperties( prefix = "goblin.feign-ok-http-config" ) 43 | public class FeignOkHttpConfig { 44 | 45 | /** 设置新连接的默认读取超时,值0表示没有超时,单位秒 **/ 46 | private int readTimeout = 60; 47 | /** 连接超时时间,值0表示没有超时,单位秒 **/ 48 | private int connectTimeout = 60; 49 | /** 设置新连接的默认写入超时,值0表示没有超时,单位秒 **/ 50 | private int writeTimeout = 180; 51 | 52 | @Bean 53 | public okhttp3.OkHttpClient okHttpClient () { 54 | return new okhttp3.OkHttpClient.Builder() 55 | .readTimeout( readTimeout , TimeUnit.SECONDS ) 56 | .connectTimeout( connectTimeout , TimeUnit.SECONDS ) 57 | .writeTimeout( writeTimeout , TimeUnit.SECONDS ) 58 | .connectionPool( new ConnectionPool() ) 59 | .build(); 60 | } 61 | 62 | @Bean 63 | public Request.Options feignOptions () { 64 | return new Request.Options( connectTimeout * 1000 , readTimeout * 1000 ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /goblin-basic-config/src/main/java/com/goblin/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector; 4 | import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor; 5 | import org.mybatis.spring.annotation.MapperScan; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * @author : 披荆斩棘 12 | * @date : 2017/5/10 13 | */ 14 | @Configuration 15 | @ConditionalOnExpression( "${goblin.mybatis-plus.enabled:true}" ) 16 | public class MybatisPlusConfig { 17 | 18 | 19 | /** 20 | * mybatis-plus 性能分析拦截器
8 | * 废弃 9 | * 10 | * @author : 披荆斩棘 11 | * @date : 2017/5/21 12 | */ 13 | @Deprecated 14 | public class Swagger2Config { 15 | 16 | 17 | /*public Docket docket () { 18 | return new Docket( DocumentationType.SWAGGER_2 ) 19 | .apiInfo( apiInfo() ) 20 | .select() 21 | .apis( RequestHandlerSelectors.basePackage( "com.goblin" ) ) 22 | .paths( PathSelectors.any() ) 23 | .build(); 24 | } 25 | 26 | private ApiInfo apiInfo () { 27 | return new ApiInfoBuilder() 28 | .title( "RESTful API" ) 29 | .description( "api接口文档" ) 30 | .contact( new Contact( "披荆斩棘", "https://yujunhao8831.github.io", "yujunhao_8831@yahoo.com" ) ) 31 | .version( "1.0" ) 32 | .build(); 33 | }*/ 34 | 35 | } 36 | -------------------------------------------------------------------------------- /goblin-basic-config/src/main/java/com/goblin/config/ThreadPoolConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; 4 | import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.scheduling.annotation.AsyncConfigurer; 7 | import org.springframework.scheduling.annotation.EnableAsync; 8 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 9 | 10 | import java.util.concurrent.Executor; 11 | 12 | /** 13 | * 线程池配置 14 | * 15 | * @author : 披荆斩棘 16 | * @date : 2017/5/24 17 | */ 18 | @Configuration 19 | @EnableAsync 20 | public class ThreadPoolConfig implements AsyncConfigurer { 21 | 22 | @Override 23 | public Executor getAsyncExecutor () { 24 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 25 | executor.setCorePoolSize( Runtime.getRuntime().availableProcessors() ); 26 | executor.setMaxPoolSize( Runtime.getRuntime().availableProcessors() * 5 ); 27 | executor.setQueueCapacity( Runtime.getRuntime().availableProcessors() * 2 ); 28 | executor.setThreadNamePrefix( "goblin-executor-" ); 29 | executor.initialize(); 30 | return executor; 31 | } 32 | 33 | @Override 34 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler () { 35 | return new SimpleAsyncUncaughtExceptionHandler(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /goblin-cache/src/main/java/com/goblin/cache/client/JedisClient.java: -------------------------------------------------------------------------------- 1 | package com.goblin.cache.client; 2 | 3 | 4 | import redis.clients.jedis.exceptions.JedisDataException; 5 | 6 | /** 7 | * redis基本操作,单机版 8 | * 9 | * @author pijingzhanji 10 | */ 11 | public interface JedisClient { 12 | 13 | /** 14 | *
获取指定键的值.如果键不存在返回null.
15 | * document 16 | * 17 | * @param key 18 | * @return 如果key的value不是string,就返回错误,因为GET只处理string类型的values 19 | */ 20 | String get ( String key ); 21 | 22 | /** 23 | *将键key设定为指定的"字符串"值。
24 | * document 25 | * 26 | * 如果key已经保存了一个值,那么这个操作会直接覆盖原来的值,并且忽略原始类型。 27 | * 当set命令执行成功之后,之前设置的过期时间都将失效 28 | * 29 | * 30 | * @param key 31 | * @param value 32 | * @return 如果SET命令正常执行那么回返回OK. 33 | */ 34 | String set ( String key , String value ); 35 | 36 | /** 37 | *对存储在指定key的数值执行原子的加1操作。
38 | * document 39 | * 40 | * 如果指定的key不存在,那么在执行incr操作之前,会先将它的值设定为0。 41 | * 如果指定的key中存储的值不是字符串类型或者存储的字符串类型不能表示为一个整数 42 | * 那么执行这个命令时服务器会抛异常 {@link JedisDataException} 43 | * 44 | * 45 | * @param key 46 | * @return 执行递增操作后key对应的值。 47 | */ 48 | Long incr ( String key ) throws JedisDataException; 49 | 50 | /** 51 | * 删除指定的一批keys,如果删除中的某些key不存在,则直接忽略。 52 | * document 53 | * 54 | * @param keys 55 | * @return 被删除的keys的数量 56 | */ 57 | Long del ( final String... keys ); 58 | 59 | /** 60 | *设置key的过期时间,超过时间后,将会自动删除该key.
61 | * 62 | * 对已经有过期时间的key执行EXPIRE操作,将会更新它的过期时间。有很多应用有这种业务场景,例如记录会话的session。 63 | * 64 | * document 65 | * 66 | * @param key 67 | * @param second : 过期时间,单位 : 秒 68 | * @return 1 如果成功设置过期时间,0 如果key不存在或者不能设置过期时间. 69 | */ 70 | Long expire ( String key , int second ); 71 | 72 | 73 | /** 74 | * 设置key对应字符串value,并且设置key在给定的seconds时间之后超时过期。77 | * 1. {@link #get(String)} 78 | * 2. {@link #expire(String , int)} 79 | *80 | * 81 | * SETEX是原子的,也可以通过把上面两个命令放到MULTI/EXEC块中执行的方式重现。 82 | * 相比连续执行上面两个命令,它更快,因为当Redis当做缓存使用时,这个操作更加常用。 83 | * 84 | * 85 | * @param key 86 | * @param value 87 | * @param second : 过期时间,单位 : 秒 88 | * @return 如果SET命令正常执行那么回返回OK. 89 | */ 90 | String setex ( String key , String value , int second ); 91 | } 92 | -------------------------------------------------------------------------------- /goblin-cache/src/main/java/com/goblin/cache/client/impl/JedisClientPool.java: -------------------------------------------------------------------------------- 1 | package com.goblin.cache.client.impl; 2 | 3 | 4 | import com.goblin.cache.client.JedisClient; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | import redis.clients.jedis.Jedis; 8 | import redis.clients.jedis.JedisPool; 9 | import redis.clients.jedis.exceptions.JedisDataException; 10 | 11 | /** 12 | * 单机情况使用 try-with-resources 自动关闭 13 | * 集群情况下就不能使用这种方式 14 | * 15 | * @author pijingzhanji 16 | */ 17 | @Component 18 | public class JedisClientPool implements JedisClient { 19 | 20 | @Autowired 21 | private JedisPool jedisPool; 22 | 23 | 24 | @Override 25 | public String get ( String key ) { 26 | try ( Jedis jedis = jedisPool.getResource() ) { 27 | return jedis.get( key ); 28 | } 29 | } 30 | 31 | @Override 32 | public String set ( String key, String value ) { 33 | try ( Jedis jedis = jedisPool.getResource() ) { 34 | return jedis.set( key, value ); 35 | } 36 | } 37 | 38 | @Override 39 | public Long incr ( String key ) throws JedisDataException { 40 | try ( Jedis jedis = jedisPool.getResource() ) { 41 | return jedis.incr( key ); 42 | } 43 | } 44 | 45 | 46 | @Override 47 | public Long del ( final String... keys ) { 48 | try ( Jedis jedis = jedisPool.getResource() ) { 49 | return jedis.del( keys ); 50 | } 51 | } 52 | 53 | 54 | @Override 55 | public Long expire ( String key, int second ) { 56 | try ( Jedis jedis = jedisPool.getResource() ) { 57 | return jedis.expire( key, second ); 58 | } 59 | } 60 | 61 | @Override 62 | public String setex ( String key, String value, int second ) { 63 | try ( Jedis jedis = jedisPool.getResource() ) { 64 | return jedis.setex( key, second, value ); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /goblin-cache/src/main/java/com/goblin/cache/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.cache.config; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import org.redisson.Redisson; 7 | import org.redisson.api.RedissonClient; 8 | import org.redisson.config.Config; 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.data.redis.connection.RedisConnectionFactory; 13 | import org.springframework.data.redis.connection.RedisPassword; 14 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; 15 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 16 | import redis.clients.jedis.JedisPool; 17 | import redis.clients.jedis.JedisPoolConfig; 18 | 19 | /** 20 | *
21 | * goblin: 22 | * redis: 23 | * host: 127.0.0.1 24 | * port: 6379 25 | * password: 123456 26 | * timeout: 60 27 | * database: 1 28 | *29 | * 30 | * @author : 披荆斩棘 31 | * @date : 2017/5/15 32 | */ 33 | @Getter 34 | @Setter 35 | @ToString 36 | @Configuration 37 | @ConfigurationProperties( prefix = "goblin.redis" ) 38 | public class RedisConfig { 39 | 40 | private static final String REDISSON_ADDRESS_PREFIX = "redis://"; 41 | private String host = "127.0.0.1"; 42 | private Integer port = 6379; 43 | private Integer timeout = 60; 44 | private String password = null; 45 | private Integer database = 0; 46 | 47 | /** 48 | * redisson文档 49 | */ 50 | @Bean( destroyMethod = "shutdown" ) 51 | public RedissonClient redisson (){ 52 | Config config = new Config(); 53 | config.useSingleServer() 54 | .setAddress( this.getRedissonAddress( host , port ) ) 55 | .setPassword( password ) 56 | .setDatabase( database ); 57 | return Redisson.create( config ); 58 | } 59 | 60 | private String getRedissonAddress ( String host , Integer port ) { 61 | return REDISSON_ADDRESS_PREFIX + host + ":" + port; 62 | } 63 | 64 | 65 | @Bean 66 | public JedisPoolConfig jedisPoolConfig () { 67 | return new JedisPoolConfig(); 68 | } 69 | 70 | @Bean 71 | public JedisPool jedisPool () { 72 | return new JedisPool( jedisPoolConfig() , host , port , timeout , password , database ); 73 | } 74 | 75 | @Bean 76 | public RedisConnectionFactory redisConnectionFactory () { 77 | RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration( ); 78 | standaloneConfig.setHostName( host ); 79 | standaloneConfig.setPort( port ); 80 | standaloneConfig.setPassword( RedisPassword.of( password ) ); 81 | standaloneConfig.setDatabase( database ); 82 | return new JedisConnectionFactory(standaloneConfig); 83 | } 84 | 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/GlobalConstant.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common; 2 | 3 | /** 4 | * 全局常量 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/5/19 8 | */ 9 | public abstract class GlobalConstant { 10 | 11 | /** 默认分页起始值 */ 12 | public static final int DEFAULT_PAGE_NUMBER = 1; 13 | /** 默认分页大小值 */ 14 | public static final int DEFAULT_PAGE_SIZE = 10; 15 | /** 分页起始参数名称 */ 16 | public static final String PAGE_NUMBER_PARAM_NAME = "pageNumber"; 17 | /** 分页大小参数名称 */ 18 | public static final String PAGE_SIZE_PARAM_NAME = "pageSize"; 19 | /** 20 | * 祖先id 21 | */ 22 | public static final Long ROOT_ID = 0L; 23 | /** 验证码请求头key **/ 24 | public static final String CAPTCHA_REQUEST_HEADER_KEY = "captcha"; 25 | /** 验证码有效期,单位:秒 **/ 26 | public static final int CAPTCHA_TIME_OUT_SECOND = 600; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/PagingRequest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import lombok.experimental.Accessors; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 分页信息接收实体 12 | * 13 | * @author : 披荆斩棘 14 | * @date : 2017/7/13 15 | */ 16 | @Getter 17 | @Setter 18 | @ToString 19 | @Accessors( chain = true ) 20 | public class PagingRequest implements Serializable { 21 | 22 | private int pageNumber; 23 | private int pageSize; 24 | 25 | 26 | public PagingRequest () { 27 | this( GlobalConstant.DEFAULT_PAGE_NUMBER , GlobalConstant.DEFAULT_PAGE_SIZE ); 28 | } 29 | 30 | public PagingRequest ( int pageNumber , int pageSize ) { 31 | this.pageNumber = pageNumber; 32 | this.pageSize = pageSize; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/SimpleDateFormatPro.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common; 2 | 3 | import com.goblin.common.util.DateUtils; 4 | 5 | import java.text.SimpleDateFormat; 6 | import java.util.*; 7 | 8 | /** 9 | * 多重解析,单一格式化 10 | * 11 | * @author : 披荆斩棘 12 | * @date : 2017/12/21 13 | * @see SimpleDateFormat 14 | */ 15 | public class SimpleDateFormatPro extends SimpleDateFormat { 16 | 17 | 18 | /** 19 | * 默认的日期时间pattern 20 | */ 21 | private static String CN_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; 22 | /** 23 | * 解析日期时间格式的pattern,可以有多个. 24 | *
25 | * 注意:是解析. 26 | *
27 | * 因为是多种日期解析pattern 需要注意的是 {@link #parse(String)} 会按照顺序进行解析,无法按照最优匹配原则进行解析,这样可能会损失一定时间精度 28 | *
29 | *30 | * SimpleDateFormatPro format = new SimpleDateFormatPro(Arrays.asList("yyyy-MM-dd","yyyy-MM-dd HH:mm:ss")); 31 | * final String text = "2017-12-22 10:59:40"; 32 | * // 结果是 : 2017-12-22 00:00:00 33 | * System.err.println(format.format(format.parse(text))); 34 | * 35 | * // ---------------------------- 36 | * 37 | * format = new SimpleDateFormatPro(Arrays.asList("yyyy-MM-dd HH:mm:ss","yyyy-MM-dd")); 38 | * // 结果是 : 2017-12-22 10:59:40 39 | * System.err.println(format.format(format.parse(text))); 40 | *41 | */ 42 | private LinkedHashSet< String > parsePatterns; 43 | 44 | /** 45 | * 默认只能解析 : {@link #CN_DATETIME_PATTERN},输出也是按照 {@link #CN_DATETIME_PATTERN} 进行输出 46 | */ 47 | public SimpleDateFormatPro () { 48 | this( CN_DATETIME_PATTERN , Collections.singletonList( CN_DATETIME_PATTERN ) ); 49 | } 50 | 51 | 52 | /** 53 | * 指定日期解析格式,默认输出格式为 {@link #CN_DATETIME_PATTERN} 54 | * 55 | * @param parsePatterns {@link #parsePatterns},多重日期解析 56 | */ 57 | public SimpleDateFormatPro ( List< String > parsePatterns ) { 58 | this( CN_DATETIME_PATTERN , parsePatterns ); 59 | } 60 | 61 | /** 62 | * 指定格式化输出及日期解析格式 63 | *
64 | * SimpleDateFormatPro format = new SimpleDateFormatPro("yyyy-MM-dd HH:mm:ss",Arrays.asList("yyyy-MM-dd HH:mm:ss","yyyy-MM-dd"))); 65 | *66 | * 67 | * @param formatPattern 输出时日期时间格式的pattern,单一格式化输出 68 | * @param parsePatterns {@link #parsePatterns},多重日期解析 69 | */ 70 | public SimpleDateFormatPro ( String formatPattern , List< String > parsePatterns ) { 71 | super( formatPattern ); 72 | this.parsePatterns = new LinkedHashSet<>( parsePatterns ); 73 | } 74 | 75 | /** 76 | * 解析字符串为
Date
77 | *
78 | * @param text 待解析的String
79 | * @return 如果无法解析则返回 null
,注意该实现这里不会抛异常
80 | */
81 | @Override
82 | public Date parse ( String text ) {
83 | Date date = null;
84 | for ( String parsePattern : this.parsePatterns ) {
85 | date = DateUtils.formatStringByStyle( text , parsePattern );
86 | if ( Objects.nonNull( date ) ) {
87 | break;
88 | }
89 | }
90 | return date;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/Tips.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common;
2 |
3 | import org.apache.commons.collections4.CollectionUtils;
4 | import org.apache.commons.collections4.ListUtils;
5 | import org.apache.commons.collections4.SetUtils;
6 | import org.apache.commons.lang3.ArrayUtils;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | /**
10 | * 小贴士
11 | *
12 | * @author : 披荆斩棘
13 | * @date : 2017/7/19
14 | * @see tips
15 | */
16 | final class Tips {
17 |
18 | /**
19 | * 字符串处理工具
20 | */
21 | StringUtils stringUtils;
22 | /**
23 | * 集合相关工具
24 | */
25 | CollectionUtils collectionUtils;
26 | /**
27 | * List相关工具
28 | */
29 | ListUtils listUtils;
30 | /**
31 | * Set相关工具
32 | */
33 | SetUtils setUtils;
34 | /**
35 | * 数组相关工具
36 | */
37 | ArrayUtils arrayUtils;
38 |
39 | // ... ...
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/annotation/ExportFiledComment.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 导出释义
10 | *
11 | * @author : 披荆斩棘
12 | * @date : 2017/7/26
13 | */
14 | @Retention( RetentionPolicy.RUNTIME )
15 | @Target( ElementType.FIELD )
16 | public @interface ExportFiledComment {
17 |
18 | /**
19 | * 字段释义
20 | */
21 | String value () default "";
22 | }
23 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/annotation/FiledComment.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 字段注释
10 | *
11 | * @author : 披荆斩棘
12 | * @date : 2017/7/26
13 | */
14 | @Retention( RetentionPolicy.RUNTIME )
15 | @Target( ElementType.FIELD )
16 | public @interface FiledComment {
17 |
18 | /**
19 | * 字段释义
20 | */
21 | String value () default "";
22 | }
23 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/annotation/Log.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common.annotation;
2 |
3 |
4 | import lombok.Getter;
5 |
6 | import java.lang.annotation.*;
7 |
8 | /**
9 | * @author : 披荆斩棘
10 | * @date : 2017/12/28
11 | */
12 | @Target( { ElementType.METHOD } )
13 | @Retention( RetentionPolicy.RUNTIME )
14 | @Documented
15 | public @interface Log {
16 |
17 | /**
18 | * 如有异常是否进行报警.
19 | *
20 | * @return boolean
21 | */
22 | boolean warn () default false;
23 |
24 | /**
25 | * 描述.
26 | */
27 | String description () default "";
28 |
29 | /**
30 | * 通知类型(SMS:短信,MAIL:邮箱).
31 | */
32 | NoticeType noticeType () default NoticeType.MAIL;
33 |
34 | @Getter
35 | enum NoticeType {
36 | /**
37 | *
38 | */
39 | SMS( "SMS" , "短信通知" ),
40 | MAIL( "MAIL" , "邮箱通知" );
41 |
42 | /** 数据库存储值 **/
43 | private String value;
44 | /** 相应注释 **/
45 | private String comment;
46 |
47 | NoticeType ( String value , String comment ) {
48 | this.value = value;
49 | this.comment = comment;
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/annotation/NeedExport.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common.annotation;
2 |
3 | import com.goblin.common.util.Export;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * 导出注解,如果控制器某个方法需要进行导出操作,请在该方法上注上该注解
12 | * 配合{@link ExportFiledComment}使用
13 | * 14 | *
15 | * 要求 : 16 | *
35 | * 不支持Map类型,如果需要采用此方法导出,就必须写一个实体,否则请直接使用 {@link Export} 导出 36 | *
37 | * 38 | * @return 39 | */ 40 | Class< ? > exportClass (); 41 | 42 | /** 43 | * 导出类型,默认 xlsx 格式 44 | * 45 | * @return {@link Export} 46 | */ 47 | Export.Type exportDefaultType () default Export.Type.MS07; 48 | 49 | /** 50 | * 导出文件名称,默认""
+ 当前时间
51 | *
52 | * @return
53 | */
54 | String exportFileDefaultName () default "文档";
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/goblin-common/src/main/java/com/goblin/common/annotation/PassInjectionAttackIntercept.java:
--------------------------------------------------------------------------------
1 | package com.goblin.common.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * 不需要注入攻击拦截注解
12 | * 13 | * 控制器中加入该注解,这个Mapping则不会进行注入拦截处理 14 | *
15 | *
16 | * // 表示该请求,不会进行注入攻击拦截处理 17 | *33 | * 34 | * @author : 披荆斩棘 35 | * @date : 2017/8/28 36 | * @see com.goblin.common.interceptor.InjectionAttackInterceptor 37 | */ 38 | @Retention( RetentionPolicy.RUNTIME ) 39 | @Target( {ElementType.METHOD,ElementType.TYPE} ) 40 | public @interface PassInjectionAttackIntercept { 41 | 42 | /** 43 | * 忽略的字符 44 | */ 45 | @AliasFor( "ignoreStrings" ) 46 | String[] value () default {}; 47 | 48 | @AliasFor( "value" ) 49 | String[] ignoreStrings () default {}; 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/converter/StringToDateConverter.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.converter; 2 | 3 | import com.goblin.common.SimpleDateFormatPro; 4 | import com.goblin.common.util.DateFormatStyle; 5 | import com.goblin.common.util.DateUtils; 6 | import org.springframework.core.convert.converter.Converter; 7 | 8 | import java.util.Date; 9 | import java.util.Objects; 10 | 11 | /** 12 | * 这里只能对普通参数进行转换 13 | * 14 | * 对 {@link org.springframework.web.bind.annotation.RequestBody} 接收的参数无效 15 | * 16 | * @author : 披荆斩棘 17 | * @date : 17/7/17 18 | */ 19 | public class StringToDateConverter implements Converter< String, Date > { 20 | 21 | @Override 22 | public Date convert ( String source ) { 23 | return new SimpleDateFormatPro( DateFormatStyle.getDateFormatStyles() ).parse( source ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/cron/CustomizeCron.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.cron; 2 | 3 | import lombok.Getter; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import lombok.experimental.Accessors; 8 | import org.springframework.scheduling.support.CronSequenceGenerator; 9 | 10 | import java.io.Serializable; 11 | 12 | import static org.apache.commons.lang3.StringUtils.SPACE; 13 | import static org.apache.commons.lang3.StringUtils.split; 14 | 15 | /** 16 | * @author : 披荆斩棘 17 | * @date : 2017/8/9 18 | */ 19 | @Getter 20 | @Setter 21 | @ToString 22 | @Accessors( chain = true ) 23 | public class CustomizeCron implements Serializable { 24 | 25 | // seconds(60) minutes(60) hours(24) daysOfMonth(31) months(12) daysOfWeek(7) 26 | protected static final String ALWAYS = "*"; 27 | // 秒 最大值 : 60 28 | private String seconds; 29 | // 分 最大值 : 60 30 | private String minutes; 31 | // 小时 最大值 : 24 32 | private String hours = ALWAYS; 33 | // 月内天数 最大值 : 31 34 | private String daysOfMonth = ALWAYS; 35 | // 月份 最大值 : 12 -> FOO,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC 36 | private String months = ALWAYS; 37 | // 周内天 最大值 : 7 -> SUN,MON,TUE,WED,THU,FRI,SAT 38 | private String daysOfWeek = ALWAYS; 39 | 40 | 41 | // Example patterns: 42 | // "0 0 * * * *" = the top of every hour of every day. 43 | // "*/10 * * * * *" = every ten seconds. 44 | // "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day. 45 | // "0 0 6,19 * * *" = 6:00 AM and 7:00 PM every day. 46 | // "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day. 47 | // "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays 48 | // "0 0 0 25 12 ?" = every Christmas Day at midnight 49 | // * * * * * 50 | // seconds(60) minutes(60) hours(24) daysOfMonth(31) months(12) daysOfWeek(7) 51 | 52 | public CustomizeCron () { 53 | } 54 | 55 | public CustomizeCron ( String expression ) { 56 | final String[] fields = split( expression , " " ); 57 | if ( fields.length > 6 ) { 58 | throw new RuntimeException( String.format( "cron表达式不正确,expression : %s " , expression ) ); 59 | } 60 | this.seconds = fields[0]; 61 | this.minutes = fields[1]; 62 | this.hours = fields[2]; 63 | this.daysOfMonth = fields[3]; 64 | this.months = fields[4]; 65 | this.daysOfWeek = fields[5]; 66 | } 67 | 68 | 69 | /** 70 | * 得到 {@link CronSequenceGenerator} 71 | */ 72 | public CronSequenceGenerator toCron () { 73 | return new CronSequenceGenerator( this.toCronString() ); 74 | } 75 | 76 | /** 77 | * 得到表达式 78 | */ 79 | public String toCronString () { 80 | return this.seconds + SPACE + 81 | this.minutes + SPACE + 82 | this.hours + SPACE + 83 | this.daysOfMonth + SPACE + 84 | this.months + SPACE + 85 | this.daysOfWeek; 86 | } 87 | 88 | 89 | protected void init () { 90 | this.seconds = "0"; 91 | this.minutes = "0"; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/CaptchaException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | /** 4 | * @author : 披荆斩棘 5 | * @date : 2017/6/27 6 | */ 7 | public class CaptchaException extends RuntimeException { 8 | public CaptchaException () { 9 | super(); 10 | } 11 | 12 | public CaptchaException ( String message ) { 13 | super( message ); 14 | } 15 | 16 | public CaptchaException ( String message, Throwable cause ) { 17 | super( message, cause ); 18 | } 19 | 20 | public CaptchaException ( Throwable cause ) { 21 | super( cause ); 22 | } 23 | 24 | protected CaptchaException ( String message, 25 | Throwable cause, 26 | boolean enableSuppression, 27 | boolean writableStackTrace ) { 28 | super( message, cause, enableSuppression, writableStackTrace ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/DaoException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | /** 4 | * dao异常 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/5/19 8 | */ 9 | public class DaoException extends RuntimeException { 10 | 11 | public DaoException () { 12 | super(); 13 | } 14 | 15 | public DaoException ( String message ) { 16 | super( message ); 17 | } 18 | 19 | public DaoException ( String message, Throwable cause ) { 20 | super( message, cause ); 21 | } 22 | 23 | public DaoException ( Throwable cause ) { 24 | super( cause ); 25 | } 26 | 27 | protected DaoException ( String message, 28 | Throwable cause, 29 | boolean enableSuppression, 30 | boolean writableStackTrace ) { 31 | super( message, cause, enableSuppression, writableStackTrace ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/ForbiddenException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | /** 4 | * 权限 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/6/22 8 | */ 9 | public class ForbiddenException extends RuntimeException { 10 | 11 | public ForbiddenException () { 12 | super(); 13 | } 14 | 15 | public ForbiddenException ( String message ) { 16 | super( message ); 17 | } 18 | 19 | public ForbiddenException ( String message, Throwable cause ) { 20 | super( message, cause ); 21 | } 22 | 23 | public ForbiddenException ( Throwable cause ) { 24 | super( cause ); 25 | } 26 | 27 | protected ForbiddenException ( String message, 28 | Throwable cause, 29 | boolean enableSuppression, 30 | boolean writableStackTrace ) { 31 | super( message, cause, enableSuppression, writableStackTrace ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | /** 4 | * 资源不存在 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/7/10 8 | */ 9 | public class ResourceNotFoundException extends RuntimeException { 10 | 11 | public ResourceNotFoundException () { 12 | super(); 13 | } 14 | 15 | public ResourceNotFoundException ( String message ) { 16 | super( message ); 17 | } 18 | 19 | public ResourceNotFoundException ( String message, Throwable cause ) { 20 | super( message, cause ); 21 | } 22 | 23 | public ResourceNotFoundException ( Throwable cause ) { 24 | super( cause ); 25 | } 26 | 27 | protected ResourceNotFoundException ( String message, 28 | Throwable cause, 29 | boolean enableSuppression, 30 | boolean writableStackTrace ) { 31 | super( message, cause, enableSuppression, writableStackTrace ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | /** 4 | * service异常 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/5/19 8 | */ 9 | public class ServiceException extends RuntimeException { 10 | 11 | public ServiceException () { 12 | super(); 13 | } 14 | 15 | public ServiceException ( String message ) { 16 | super( message ); 17 | } 18 | 19 | public ServiceException ( String message, Throwable cause ) { 20 | super( message, cause ); 21 | } 22 | 23 | public ServiceException ( Throwable cause ) { 24 | super( cause ); 25 | } 26 | 27 | protected ServiceException ( String message, 28 | Throwable cause, 29 | boolean enableSuppression, 30 | boolean writableStackTrace ) { 31 | super( message, cause, enableSuppression, writableStackTrace ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/exception/ValidatedIllegalArgumentException.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.exception; 2 | 3 | import org.springframework.validation.BindingResult; 4 | 5 | /** 6 | * 参数异常 7 | * {@link org.springframework.validation.Validator} 8 | * 9 | * @author : 披荆斩棘 10 | * @date : 2017/5/19 11 | */ 12 | public class ValidatedIllegalArgumentException extends RuntimeException { 13 | 14 | private final BindingResult bindingResult; 15 | 16 | public ValidatedIllegalArgumentException ( BindingResult bindingResult ) { 17 | super(); 18 | this.bindingResult = bindingResult; 19 | } 20 | 21 | public ValidatedIllegalArgumentException ( String message , 22 | BindingResult bindingResult ) { 23 | super( message ); 24 | this.bindingResult = bindingResult; 25 | } 26 | 27 | public ValidatedIllegalArgumentException ( String message , 28 | Throwable cause , 29 | BindingResult bindingResult ) { 30 | super( message , cause ); 31 | this.bindingResult = bindingResult; 32 | } 33 | 34 | public ValidatedIllegalArgumentException ( Throwable cause , 35 | BindingResult bindingResult ) { 36 | super( cause ); 37 | this.bindingResult = bindingResult; 38 | } 39 | 40 | protected ValidatedIllegalArgumentException ( String message , 41 | Throwable cause , 42 | boolean enableSuppression , 43 | boolean writableStackTrace , 44 | BindingResult bindingResult ) { 45 | super( message , cause , enableSuppression , writableStackTrace ); 46 | this.bindingResult = bindingResult; 47 | } 48 | 49 | 50 | public BindingResult getBindingResult () { 51 | return bindingResult; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/filter/BodyReaderWrapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.filter; 2 | 3 | import com.goblin.common.util.RequestUtils; 4 | import org.springframework.util.StreamUtils; 5 | 6 | import javax.servlet.ReadListener; 7 | import javax.servlet.ServletInputStream; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletRequestWrapper; 10 | import java.io.BufferedReader; 11 | import java.io.ByteArrayInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | 15 | 16 | /** 17 | * 解决流不能二次读取问题. 18 | * 对于Content-Type=application/json;请求需要解析其中的参数. 19 | * 这样在Controller中@RequestBody也可以获取到参数了. 20 | * 21 | * @author : 披荆斩棘 22 | * @date : 2016/11/13 23 | */ 24 | public class BodyReaderWrapper extends HttpServletRequestWrapper { 25 | 26 | private final byte[] body; 27 | 28 | public BodyReaderWrapper ( HttpServletRequest request ) throws IOException { 29 | super( request ); 30 | if ( RequestUtils.isApplicationJsonHeader( request ) ) { 31 | body = StreamUtils.copyToByteArray( request.getInputStream() ); 32 | } else { 33 | body = null; 34 | } 35 | } 36 | 37 | @Override 38 | public BufferedReader getReader () throws IOException { 39 | return new BufferedReader( new InputStreamReader( this.getInputStream() ) ); 40 | } 41 | 42 | @Override 43 | public ServletInputStream getInputStream () throws IOException { 44 | if ( null == body ) { 45 | return super.getInputStream(); 46 | } 47 | final ByteArrayInputStream inputStream = new ByteArrayInputStream( body ); 48 | return new ServletInputStream() { 49 | @Override 50 | public boolean isFinished () { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean isReady () { 56 | return false; 57 | } 58 | 59 | @Override 60 | public void setReadListener ( ReadListener readListener ) { 61 | 62 | } 63 | 64 | @Override 65 | public int read () throws IOException { 66 | return inputStream.read(); 67 | } 68 | }; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/filter/RequestLoggingFilter.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.filter; 2 | 3 | 4 | import com.goblin.common.util.LogUtils; 5 | import com.goblin.common.util.RequestUtils; 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.springframework.util.PatternMatchUtils; 8 | 9 | import javax.servlet.*; 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.io.IOException; 12 | 13 | /** 14 | * 请求信息打印过滤器 15 | * 16 | * @author : 披荆斩棘 17 | * @date : 2017/1/17 18 | */ 19 | public class RequestLoggingFilter implements Filter { 20 | 21 | private static final String PASSWORD_FILTER_REGEX = 22 | "(password=\\[([\\S\\s])*\\])|(\"password\":\"([\\S\\s])*\")"; 23 | private String[] excludeUrlPatterns; 24 | 25 | 26 | @Override 27 | public void doFilter ( ServletRequest request , ServletResponse response , FilterChain chain ) 28 | throws IOException, ServletException { 29 | 30 | if ( PatternMatchUtils.simpleMatch( excludeUrlPatterns , ( ( HttpServletRequest ) request ).getRequestURI() ) ) { 31 | chain.doFilter( request , response ); 32 | return; 33 | } 34 | 35 | 36 | final BodyReaderWrapper wrapper = new BodyReaderWrapper( ( HttpServletRequest ) request ); 37 | String requestMessage = RequestUtils.getRequestMessage( wrapper ); 38 | if ( ! LogUtils.getLogger().isDebugEnabled() ) { 39 | requestMessage = StringUtils.replaceAll( requestMessage , PASSWORD_FILTER_REGEX , 40 | "enable password protection, if not debug so do not see" 41 | ); 42 | } 43 | LogUtils.getLogger().info( requestMessage ); 44 | chain.doFilter( wrapper , response ); 45 | } 46 | 47 | @Override 48 | public void init ( FilterConfig filterConfig ) { } 49 | 50 | @Override 51 | public void destroy () { } 52 | 53 | public RequestLoggingFilter setExcludeUrlPatterns ( String[] excludeUrlPatterns ) { 54 | this.excludeUrlPatterns = excludeUrlPatterns; 55 | return this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/filter/handler/InjectionAttackHandler.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.filter.handler; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | import java.io.IOException; 6 | 7 | /** 8 | * @author : 披荆斩棘 9 | * @date : 2017/1/17 10 | * 字符注入攻击判断 11 | */ 12 | public interface InjectionAttackHandler { 13 | 14 | /** 15 | * 是注入攻击(SQL,XSS,特殊字符注入) 16 | * 17 | * @param rawCharacters 18 | * @return 19 | */ 20 | boolean isInjectionAttack ( String rawCharacters ); 21 | 22 | boolean isInjectionAttack ( String parameters , String[] ignoreStrings ); 23 | 24 | /** 25 | * 是SQL注入 26 | * 27 | * @param rawCharacters 28 | * @return 29 | */ 30 | boolean isSqlInjectionAttack ( String rawCharacters ); 31 | 32 | boolean isSqlInjectionAttack ( String rawCharacters , String[] ignoreStrings ); 33 | 34 | /** 35 | * 是XSS攻击 36 | * 37 | * @param rawCharacters 38 | * @return 39 | */ 40 | boolean isXSSInjectionAttack ( String rawCharacters ); 41 | 42 | boolean isXSSInjectionAttack ( String rawCharacters , String[] ignoreStrings ); 43 | 44 | /** 45 | * 是特殊字符注入 46 | * 47 | * @param rawCharacters 48 | * @return 49 | */ 50 | boolean isSpecialCharactersInjectionAttack ( String rawCharacters ); 51 | 52 | boolean isSpecialCharactersInjectionAttack ( String rawCharacters , String[] ignoreStrings ); 53 | 54 | /** 55 | * 过滤(SQL,XSS,特殊字符注入) 56 | * 57 | * @param rawCharacters : 原字符 58 | * @return 过滤后的字符 59 | */ 60 | String filter ( String rawCharacters ); 61 | 62 | /** 63 | * 过滤SQL注入 64 | * 65 | * @param rawCharacters : 原字符 66 | * @return 过滤后的字符 67 | */ 68 | String filterSqlInjection ( String rawCharacters ); 69 | 70 | /** 71 | * 过滤XSS注入 72 | * 73 | * @param rawCharacters : 原字符 74 | * @return 过滤后的字符 75 | */ 76 | String filterXSSInjection ( String rawCharacters ); 77 | 78 | /** 79 | * 过滤特殊字符 80 | * 81 | * @param rawCharacters : 原字符 82 | * @return 过滤后的字符 83 | */ 84 | String filterSpecialCharacters ( String rawCharacters ); 85 | 86 | 87 | /** 88 | * 攻击处理 89 | * 90 | * @param request 91 | * @param response 92 | * @param parameters 93 | */ 94 | void attackHandle ( HttpServletRequest request , HttpServletResponse response , String parameters ) throws 95 | IOException; 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/filter/handler/InjectionAttackPassHandle.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.filter.handler; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | import java.io.IOException; 6 | 7 | /** 8 | * @author : 披荆斩棘 9 | * @date : 2017/1/17 10 | * 对于注入攻击不做任何处理 11 | */ 12 | public class InjectionAttackPassHandle implements InjectionAttackHandler { 13 | 14 | 15 | private InjectionAttackPassHandle () { 16 | } 17 | 18 | public static InjectionAttackPassHandle getInstance () { 19 | return SingletonDefaultInjectionAttackHandler.instance; 20 | } 21 | 22 | @Override 23 | public boolean isInjectionAttack ( String rawCharacters ) { 24 | return this.isSqlInjectionAttack( rawCharacters ) || 25 | this.isXSSInjectionAttack( rawCharacters ) || 26 | this.isSpecialCharactersInjectionAttack( rawCharacters ); 27 | } 28 | 29 | @Override 30 | public boolean isInjectionAttack ( String parameters , String[] ignoreStrings ) { 31 | return false; 32 | } 33 | 34 | @Override 35 | public boolean isSqlInjectionAttack ( String rawCharacters ) { 36 | return false; 37 | } 38 | 39 | @Override 40 | public boolean isSqlInjectionAttack ( String rawCharacters , String[] ignoreStrings ) { 41 | return false; 42 | } 43 | 44 | @Override 45 | public boolean isXSSInjectionAttack ( String rawCharacters ) { 46 | return false; 47 | } 48 | 49 | @Override 50 | public boolean isXSSInjectionAttack ( String rawCharacters , String[] ignoreStrings ) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean isSpecialCharactersInjectionAttack ( String rawCharacters ) { 56 | return false; 57 | } 58 | 59 | @Override 60 | public boolean isSpecialCharactersInjectionAttack ( String rawCharacters , String[] ignoreStrings ) { 61 | return false; 62 | } 63 | 64 | @Override 65 | public String filter ( String rawCharacters ) { 66 | return rawCharacters; 67 | } 68 | 69 | @Override 70 | public String filterSqlInjection ( String rawCharacters ) { 71 | return rawCharacters; 72 | } 73 | 74 | @Override 75 | public String filterXSSInjection ( String rawCharacters ) { 76 | return rawCharacters; 77 | } 78 | 79 | @Override 80 | public String filterSpecialCharacters ( String rawCharacters ) { 81 | return rawCharacters; 82 | } 83 | 84 | @Override 85 | public void attackHandle ( HttpServletRequest request, HttpServletResponse response, String parameters ) throws 86 | IOException { 87 | return; 88 | } 89 | 90 | private static class SingletonDefaultInjectionAttackHandler { 91 | private static final InjectionAttackPassHandle instance = new InjectionAttackPassHandle(); 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/BeanProUtils.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | import org.apache.commons.beanutils.BeanUtilsBean2; 4 | import org.apache.commons.collections4.CollectionUtils; 5 | 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.util.*; 9 | 10 | import static com.goblin.common.util.ReflectionProUtils.invokeFieldGettersMethod; 11 | import static org.reflections.ReflectionUtils.getAllFields; 12 | 13 | /** 14 | * @author : 披荆斩棘 15 | * @date : 2017/12/12 16 | */ 17 | public class BeanProUtils { 18 | 19 | /** 20 | * bean转换成Map 21 | * 22 | * @param bean 要转换的Bean 23 | * @return 返回bean字段getters方法的全部属性 , 字段名为key , 其属性为value的@
RequestMapping( "demo" ) 18 | *@
PassInjectionAttackIntercept 19 | * public ResponseEntity< String > demo () { 20 | * return ResponseEntity.ok(); 21 | * } 22 | * 23 | * // 表示该请求,进行注入攻击拦截处理时,如果请求参数中包含了 "update" 或者 "exec",那么对此进行忽略,排除这些关键字符 24 | *@
RequestMapping( "demo" ) 25 | *@
PassInjectionAttackIntercept( { "update" , "exec" } ) 26 | * public ResponseEntity< String > demo () { 27 | * return ResponseEntity.ok(); 28 | * } 29 | * 30 | * // 注解在控制器方法上同理 31 | * 32 | *
Map
24 | */
25 | public static Map< String, Object > toMap ( Object bean ) {
26 | final Set< Field > fields = getAllFields( bean.getClass() );
27 | if ( CollectionUtils.isEmpty( fields ) ) {
28 | return Collections.emptyMap();
29 | }
30 | Map< String, Object > map = new HashMap<>();
31 | for ( Field field : fields ) {
32 | final Object result = invokeFieldGettersMethod( bean , field.getName() );
33 | if ( null == result ) {
34 | continue;
35 | }
36 | map.put( field.getName() , result );
37 | }
38 | return map;
39 | }
40 |
41 |
42 | /**
43 | * bean转换成Map{@code Map
49 | */
50 | public static Map< String, String > toStringMap( Object bean ) {
51 | final Map< String, Object > map = toMap( bean );
52 | Map6 | * {@link javax.validation.groups.Default} 不指定组的情况下这个是默认的 7 | *
8 | *
9 | * public class User { 10 | * // 该字段校验只做用于 ValidatedGroups.Update.class 11 | * {@code @NotBlank}( message = "id can not be null", groups = ValidatedGroups.Update.class ) 12 | * private Long id; 13 | * 14 | * // 该字段校验只做用于 ValidatedGroups.Save.class 15 | * {@code @NotBlank}( message = "username can not be null", groups = ValidatedGroups.Save.class ) 16 | * private String username; 17 | * 18 | * // 该字段校验只做用于 ValidatedGroups.Save.class 和 ValidatedGroups.Special.class 19 | * {@code @NotBlank}( message = "password can not be null", groups = { ValidatedGroups.Save.class , ValidatedGroups.Special.class } ) 20 | * private String password; 21 | * 22 | * // 该字段校验只做用于 Default.class,默认情况下就是 Default.class 23 | * {@code @NotBlank}( message = "address can not be null", groups = Default.class) 24 | * private String address; 25 | * // 不指定 groups , 默认情况下就是 Default.class 26 | * {@code @NotBlank}( message = "age can not be null" ) 27 | * private String age; 28 | * } 29 | *30 | *
31 | * 控制器中使用 32 | *
33 | *
34 | * // 校验指定组校验 35 | * {@code @RequestMapping}( method = RequestMethod.POST ) 36 | * public ResponseEntity save ( @Validated( ValidatedGroups.Save.class ) @RequestBody User user ,BindingResult result ) { 37 | * // ... ... 38 | * return ResponseEntity.ok().body( "" ); 39 | * } 40 | * 41 | * 42 | *43 | * 44 | * @author : 披荆斩棘 45 | * @date : 2017/12/11 46 | */ 47 | public interface ValidatedGroups { 48 | 49 | 50 | /** 51 | * 更新 52 | */ 53 | interface Update { 54 | } 55 | 56 | /** 57 | * 保存 58 | */ 59 | interface Save { 60 | } 61 | 62 | /** 63 | * 保存 64 | */ 65 | interface Delete { 66 | } 67 | 68 | /** 69 | * 查询 70 | */ 71 | interface Query { 72 | } 73 | 74 | /** 75 | * 特殊的 76 | */ 77 | interface Special { 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /goblin-common/src/test/java/com/goblin/excel/ExcelTest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.excel; 2 | 3 | import org.junit.Test; 4 | 5 | public class ExcelTest { 6 | 7 | @Test 8 | public void excel () { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /goblin-common/src/test/java/com/goblin/json/User.java: -------------------------------------------------------------------------------- 1 | package com.goblin.json; 2 | 3 | /** 4 | * @author : 披荆斩棘 5 | * @date : 2017/5/25 6 | */ 7 | 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | import java.util.Arrays; 15 | import java.util.Date; 16 | import java.util.List; 17 | 18 | @Getter 19 | @Setter 20 | @ToString 21 | @Accessors( chain = true ) 22 | public class User implements Serializable { 23 | private static final long serialVersionUID = 1L; 24 | private Long id; 25 | private String name; 26 | private String[] names; 27 | private String username; 28 | private List< String > info; 29 | private Date time; 30 | private Address address; 31 | private Order order; 32 | 33 | public User () { 34 | this.id = 1001L; 35 | this.name = null; 36 | this.names = new String[]{ "令狐冲" , "张三" , "大毛" }; 37 | this.info = Arrays.asList( "北京" , "朝阳" , "密云" ); 38 | this.time = new Date(); 39 | this.username = "admin"; 40 | this.address = new Address().setZip( "518000" ).setProvince( "北京" ).setName( "地址" ); 41 | this.order = new Order().setId( 8888L ).setName( "支付宝" ); 42 | } 43 | 44 | @Getter 45 | @Setter 46 | @ToString 47 | @Accessors( chain = true ) 48 | public class Order implements Serializable { 49 | private Long id; 50 | private String name; 51 | } 52 | 53 | @Getter 54 | @Setter 55 | @ToString 56 | @Accessors( chain = true ) 57 | public class Address implements Serializable { 58 | private String name; 59 | private String province; 60 | private String zip; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /goblin-common/src/test/java/com/goblin/response/User.java: -------------------------------------------------------------------------------- 1 | package com.goblin.response; 2 | 3 | import lombok.*; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | *
10 | * 后台管理用户 11 | *
12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-07-12 15 | */ 16 | @Getter 17 | @Setter 18 | @ToString 19 | @Accessors( chain = true ) 20 | public class User { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** 25 | * 主键 26 | */ 27 | private Long id; 28 | /** 29 | * 用户名(登录名称) 30 | */ 31 | private String username; 32 | /** 33 | * 密码 34 | */ 35 | private String password; 36 | /** 37 | * 盐(目前未用到,目前使用全局的) 38 | */ 39 | private String passwordSalt; 40 | /** 41 | * 昵称 42 | */ 43 | private String nickName; 44 | /** 45 | * 真实姓名 46 | */ 47 | private String realName; 48 | /** 49 | * 电子邮箱 50 | */ 51 | private String email; 52 | /** 53 | * 手机号码 54 | */ 55 | private String phone; 56 | /** 57 | * 用户头像 58 | */ 59 | private String userImageUrl; 60 | /** 61 | * 密码最后重置(修改)日期 62 | */ 63 | private Date lastPasswordResetDate; 64 | /** 65 | * 创建人 66 | */ 67 | private Long createUserId; 68 | /** 69 | * 修改人 70 | */ 71 | private Long updateUserId; 72 | /** 73 | * 创建时间 74 | */ 75 | private Date createTime; 76 | /** 77 | * 修改时间 78 | */ 79 | private Date updateTime; 80 | /** 81 | * 账户状态(1:激活,0:锁定) 82 | */ 83 | private Boolean enabled; 84 | /** 85 | * 备注 86 | */ 87 | private String remark; 88 | 89 | } 90 | -------------------------------------------------------------------------------- /goblin-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |22 | * $!{table.comment} 前端控制器 23 | *
24 | * 25 | * @author ${author} 26 | * @since ${date} 27 | */ 28 | #if(${restControllerStyle}) 29 | @RestController 30 | #else 31 | @Controller 32 | #end 33 | @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}s#end#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}s#else${table.entityPath}s#end") 34 | #if(${superControllerClass}) 35 | public class ${table.controllerName} extends ${superControllerClass} { 36 | #else 37 | public class ${table.controllerName} { 38 | #end 39 | @Autowired 40 | private ${table.serviceName} ${serviceVariableName}; 41 | 42 | /* 43 | #foreach($field in ${table.fields}) 44 | 45 | #if("$!field.comment" != "") ${field.comment} #end ${field.propertyName} #if(${field.propertyType.equals("Boolean")}) boolean #else ${field.propertyType} #end 46 | 47 | #end 48 | 49 | */ 50 | 51 | 52 | @GetMapping("{id}") 53 | public ResponseEntity< ${entity} > get ( @PathVariable ${primaryKeyTypeString} id ){ 54 | return ResponseEntity.ok().setResponseContent(${serviceVariableName}.selectById( id )); 55 | } 56 | 57 | @GetMapping 58 | public ResponseEntity< PageInfo<${entity}> > list ( PagingRequest pagingRequest ){ 59 | return ResponseEntity.ok().setResponseContent(${serviceVariableName}.listPage( pagingRequest )); 60 | } 61 | 62 | @PostMapping 63 | public ResponseEntity insert ( @RequestBody ${entity} ${entityVariableName} ){ 64 | if ( ! ${serviceVariableName}.insert( ${entityVariableName}) ){ 65 | return ResponseEntity.badRequest("保存失败"); 66 | } 67 | return ResponseEntity.ok("保存成功"); 68 | } 69 | 70 | @PutMapping("{id}") 71 | public ResponseEntity update ( @PathVariable ${primaryKeyTypeString} id, 72 | @RequestBody ${entity} ${entityVariableName} ){ 73 | if ( ! ${serviceVariableName}.updateById( ${entityVariableName}.setId(id)) ){ 74 | return ResponseEntity.badRequest("更新失败"); 75 | } 76 | return ResponseEntity.ok("更新成功"); 77 | } 78 | 79 | @DeleteMapping("{id}") 80 | public ResponseEntity delete ( @PathVariable ${primaryKeyTypeString} id ){ 81 | if ( ! ${serviceVariableName}.deleteById(id) ){ 82 | return ResponseEntity.badRequest("删除失败"); 83 | } 84 | return ResponseEntity.ok("删除成功"); 85 | } 86 | 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /goblin-generator/src/main/resources/templates/mybatis/plus/entity.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Entity}; 2 | 3 | #foreach($pkg in ${table.importPackages}) 4 | import ${pkg}; 5 | #end 6 | #if(${entityLombokModel}) 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | import lombok.experimental.Accessors; 10 | #end 11 | 12 | /** 13 | *14 | * $!{table.comment} 15 | *
16 | * 17 | * @author ${author} 18 | * @since ${date} 19 | */ 20 | #if(${entityLombokModel}) 21 | @Data 22 | @EqualsAndHashCode( callSuper = true ) 23 | @Accessors(chain = true) 24 | #end 25 | #if(${table.convert}) 26 | @TableName("${table.name}") 27 | #end 28 | #if(${superEntityClass}) 29 | public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end { 30 | #elseif(${activeRecord}) 31 | public class ${entity} extends Model<${entity}> { 32 | #else 33 | public class ${entity} implements Serializable { 34 | #end 35 | 36 | private static final long serialVersionUID = 1L; 37 | 38 | #foreach($field in ${table.fields}) 39 | #if(${field.keyFlag}) 40 | #set($keyPropertyName=${field.propertyName}) 41 | #end 42 | #if("$!field.comment" != "") 43 | /** 44 | * ${field.comment} 45 | */ 46 | #end 47 | #if(${field.keyFlag}) 48 | #if(${field.keyIdentityFlag}) 49 | @TableId(value="${field.name}", type= IdType.AUTO) 50 | #elseif(${field.convert}) 51 | @TableId("${field.name}") 52 | #end 53 | #elseif(${field.convert}) 54 | @TableField("${field.name}") 55 | #end 56 | private ${field.propertyType} ${field.propertyName}; 57 | #end 58 | 59 | #if(!${entityLombokModel}) 60 | #foreach($field in ${table.fields}) 61 | #if(${field.propertyType.equals("Boolean")}) 62 | #set($getprefix="is") 63 | #else 64 | #set($getprefix="get") 65 | #end 66 | 67 | public ${field.propertyType} ${getprefix}${field.capitalName}() { 68 | return ${field.propertyName}; 69 | } 70 | 71 | #if(${entityBuilderModel}) 72 | public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { 73 | #else 74 | public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { 75 | #end 76 | this.${field.propertyName} = ${field.propertyName}; 77 | #if(${entityBuilderModel}) 78 | return this; 79 | #end 80 | } 81 | #end 82 | #end 83 | 84 | #if(${entityColumnConstant}) 85 | #foreach($field in ${table.fields}) 86 | public static final String ${field.name.toUpperCase()} = "${field.name}"; 87 | 88 | #end 89 | #end 90 | #if(${activeRecord}) 91 | @Override 92 | protected Serializable pkVal() { 93 | #if(${keyPropertyName}) 94 | return this.${keyPropertyName}; 95 | #else 96 | return this.id; 97 | #end 98 | } 99 | 100 | #end 101 | #if(!${entityLombokModel}) 102 | @Override 103 | public String toString() { 104 | return "${entity}{" + 105 | #foreach($field in ${table.fields}) 106 | #if($!{velocityCount}==1) 107 | "${field.propertyName}=" + ${field.propertyName} + 108 | #else 109 | ", ${field.propertyName}=" + ${field.propertyName} + 110 | #end 111 | #end 112 | "}"; 113 | } 114 | } 115 | #end 116 | } 117 | -------------------------------------------------------------------------------- /goblin-generator/src/main/resources/templates/mybatis/plus/service.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | import com.github.pagehelper.PageInfo; 6 | import com.goblin.common.PagingRequest; 7 | 8 | /** 9 | *10 | * $!{table.comment} 服务类 11 | *
12 | * 13 | * @author ${author} 14 | * @since ${date} 15 | */ 16 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 17 | 18 | /** 19 | * 默认分页(PageHelper分页) 20 | *21 | *
参数名称 | 25 | *参数类型 | 26 | *参数说明 | 27 | *
PagingRequest#getPageNumber() | 30 | *int | 31 | *页码 | 32 | *
PagingRequest#getPageSize() | 35 | *int | 36 | *每页显示数量 | 37 | *
16 | * $!{table.comment} 服务实现类 17 | *
18 | * 19 | * @author ${author} 20 | * @since ${date} 21 | */ 22 | @Service 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | 26 | @Override 27 | public PageInfo<${entity}> listPage( PagingRequest pagingRequest ) { 28 | PageHelper.startPage( pagingRequest.getPageNumber(), pagingRequest.getPageSize() ); 29 | return new PageInfo<>( super.selectList( null ) ); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /goblin-manage-system/README.md: -------------------------------------------------------------------------------- 1 | # 服务管理 2 | http://blog.didispace.com/spring-boot-run-backend/ 3 | ## 以脚本管理 4 | + start.sh 5 | 启动服务 6 | + stop.sh 7 | 关闭服务 8 | + restart.sh 9 | 重启服务 10 | 11 | ## 以系统服务进行管理 12 | 13 | sudo ln -s /xxx/xxx/goblin-manage-system-webapp.jar /etc/init.d/goblin-manage-system-webapp 14 | 15 | /etc/init.d/goblin-manage-system-webapp start|stop|restart 16 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |18 | * 修改时间 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "manage_mail_subscribe" ) 29 | public class MailSubscribe extends Model< MailSubscribe > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * 用户ID 40 | */ 41 | @TableField( "user_id" ) 42 | private Long userId; 43 | /** 44 | * 收件箱 45 | */ 46 | @TableField( "to_email" ) 47 | private String toEmail; 48 | /** 49 | * 收件箱类型(SYSTEM:系统邮箱,OTHER:其他邮箱[非系统邮箱]), 50 | * 默认为 : SYSTEM 51 | */ 52 | @TableField( "to_email_type" ) 53 | private String toEmailType; 54 | /** 55 | * 邮件主题 56 | */ 57 | @TableField( "email_subject" ) 58 | private String emailSubject; 59 | /** 60 | * 邮件内容 61 | */ 62 | @TableField( "email_text" ) 63 | private String emailText; 64 | /** 65 | * 邮件附件地址(多个用逗号','分隔) 66 | */ 67 | @TableField( "email_attachment_url" ) 68 | private String emailAttachmentUrl; 69 | /** 70 | * 邮件发送时间(默认:即刻发送) 71 | */ 72 | @TableField( "email_send_time" ) 73 | private Date emailSendTime; 74 | /** 75 | * 发送状态( NOT_SEND : 未发送,SEND : 已发送,FAIL_SEND : 发送失败, 76 | * FINAL_FAIL_SEND : 重试次数用完后,还是发送失败 ) 77 | */ 78 | @TableField( "email_send_state" ) 79 | private String emailSendState; 80 | /** 81 | * 失败重试次数 82 | */ 83 | @TableField( "email_send_retry_number" ) 84 | private Boolean emailSendRetryNumber; 85 | /** 86 | * 重试发送统计 87 | */ 88 | @TableField( "email_send_retry_count" ) 89 | private Boolean emailSendRetryCount; 90 | /** 91 | * 备注 92 | */ 93 | private String remark; 94 | /** 95 | * 创建时间 96 | */ 97 | @TableField( "create_time" ) 98 | private Date createTime; 99 | /** 100 | * 修改时间 101 | */ 102 | @TableField( "update_time" ) 103 | private Date updateTime; 104 | 105 | 106 | @Override 107 | protected Serializable pkVal () { 108 | return this.id; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/Role.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.baomidou.mybatisplus.extension.activerecord.Model; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | import java.util.Date; 15 | 16 | /** 17 | *18 | * 后台管理角色表 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "manage_role" ) 29 | public class Role extends Model< Role > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * 角色名称 40 | */ 41 | @TableField( "role_name" ) 42 | private String roleName; 43 | /** 44 | * 角色名称code 45 | */ 46 | @TableField( "role_name_code" ) 47 | private String roleNameCode; 48 | /** 49 | * 角色状态(1:激活,0:锁定) 50 | */ 51 | @TableField( "is_enabled" ) 52 | private Boolean enabled; 53 | /** 54 | * 描述 55 | */ 56 | private String description; 57 | /** 58 | * 创建时间 59 | */ 60 | @TableField( "create_time" ) 61 | private Date createTime; 62 | /** 63 | * 修改时间 64 | */ 65 | @TableField( "update_time" ) 66 | private Date updateTime; 67 | /** 68 | * 备注 69 | */ 70 | private String remark; 71 | 72 | 73 | @Override 74 | protected Serializable pkVal () { 75 | return this.id; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/RolePermissionResource.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.baomidou.mybatisplus.extension.activerecord.Model; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | 15 | /** 16 | *17 | * 角色和权限资源中间表 18 | *
19 | * 20 | * @author 披荆斩棘 21 | * @since 2017-12-28 22 | */ 23 | @Getter 24 | @Setter 25 | @ToString 26 | @Accessors( chain = true ) 27 | @TableName( "manage_role_permission_resource" ) 28 | public class RolePermissionResource extends Model< RolePermissionResource > { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * 主键 34 | */ 35 | @TableId( value = "id", type = IdType.AUTO ) 36 | private Long id; 37 | /** 38 | * 后台管理角色_id 39 | */ 40 | @TableField( "role_id" ) 41 | private Long roleId; 42 | /** 43 | * 后台管理权限资源_id 44 | */ 45 | @TableField( "permission_resource_id" ) 46 | private Long permissionResourceId; 47 | /** 48 | * 资源API URI 显示字段 49 | * ( 50 | * "*":表示显示所有[默认"*"]. 51 | * "-" + 字段名,表示排除某个字段.如果要排除多个以","进行分隔,比如: -username,-password. 52 | * 字段名,表示只显示某个字段,如果只要显示某几个字段可以用","分隔,比如:username,password. 53 | * 示例 : 54 | * : 显示所有字段 55 | * -username,-password : 除了不显示username,password这2个字段,其他字段都显示 56 | * username,password : 只显示username,password这2个字段,都不显示 57 | * ) 58 | * 目前只是精确到角色,具体到用户,还需要后续思考 59 | */ 60 | @TableField( "resource_api_uri_show_fields" ) 61 | private String resourceApiUriShowFields; 62 | 63 | 64 | @Override 65 | protected Serializable pkVal () { 66 | return this.id; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/SmsSubscribe.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.baomidou.mybatisplus.extension.activerecord.Model; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | import java.util.Date; 15 | 16 | /** 17 | *18 | * 短信订阅 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "manage_sms_subscribe" ) 29 | public class SmsSubscribe extends Model< SmsSubscribe > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * 用户ID 40 | */ 41 | @TableField( "user_id" ) 42 | private Long userId; 43 | /** 44 | * 手机号码 45 | */ 46 | @TableField( "sms_phone" ) 47 | private String smsPhone; 48 | /** 49 | * 运营商(CHINA_UNICOM:中国联通,CHINA_TELICOM:中国电信,CHINA_MOBILE:中国移动,UNDEFINED:未指定) 50 | */ 51 | @TableField( "mobile_operators" ) 52 | private String mobileOperators; 53 | /** 54 | * 短信内容 55 | */ 56 | @TableField( "sms_content" ) 57 | private String smsContent; 58 | /** 59 | * 短信发送时间(默认:即刻发送) 60 | */ 61 | @TableField( "sms_send_time" ) 62 | private Date smsSendTime; 63 | /** 64 | * 发送状态 65 | * ( NOT_SEND : 未发送,SEND : 已发送, 66 | * FAIL_SEND : 发送失败,FINAL_FAIL_SEND : 重试次数用完后,还是发送失败 ) 67 | */ 68 | @TableField( "sms_send_state" ) 69 | private String smsSendState; 70 | /** 71 | * 失败重试次数 72 | */ 73 | @TableField( "sms_send_retry_number" ) 74 | private Boolean smsSendRetryNumber; 75 | /** 76 | * 重试发送统计 77 | */ 78 | @TableField( "sms_send_retry_count" ) 79 | private Boolean smsSendRetryCount; 80 | /** 81 | * 备注 82 | */ 83 | private String remark; 84 | /** 85 | * 创建时间 86 | */ 87 | @TableField( "create_time" ) 88 | private Date createTime; 89 | /** 90 | * 修改时间 91 | */ 92 | @TableField( "update_time" ) 93 | private Date updateTime; 94 | 95 | 96 | @Override 97 | protected Serializable pkVal () { 98 | return this.id; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/SystemConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.baomidou.mybatisplus.extension.activerecord.Model; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | import java.util.Date; 15 | 16 | /** 17 | *18 | * 系统配置 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "system_config" ) 29 | public class SystemConfig extends Model< SystemConfig > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * key 40 | */ 41 | @TableField( "config_key" ) 42 | private String configKey; 43 | /** 44 | * value 45 | */ 46 | @TableField( "config_value" ) 47 | private String configValue; 48 | /** 49 | * 说明 50 | */ 51 | @TableField( "config_description" ) 52 | private String configDescription; 53 | /** 54 | * 创建人 55 | */ 56 | @TableField( "create_user_id" ) 57 | private Long createUserId; 58 | /** 59 | * 修改人 60 | */ 61 | @TableField( "update_user_id" ) 62 | private Long updateUserId; 63 | /** 64 | * 创建时间 65 | */ 66 | @TableField( "create_time" ) 67 | private Date createTime; 68 | /** 69 | * 修改时间 70 | */ 71 | @TableField( "update_time" ) 72 | private Date updateTime; 73 | /** 74 | * 备注 75 | */ 76 | private String remark; 77 | 78 | 79 | @Override 80 | protected Serializable pkVal () { 81 | return this.id; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.baomidou.mybatisplus.extension.activerecord.Model; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import lombok.ToString; 11 | import lombok.experimental.Accessors; 12 | 13 | import java.io.Serializable; 14 | import java.util.Date; 15 | 16 | /** 17 | *18 | * 用户 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "manage_user" ) 29 | public class User extends Model< User > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * 用户名(登录名称) 40 | */ 41 | private String username; 42 | /** 43 | * 密码 44 | */ 45 | private String password; 46 | /** 47 | * 盐 48 | */ 49 | @TableField( "password_salt" ) 50 | private String passwordSalt; 51 | /** 52 | * 昵称 53 | */ 54 | @TableField( "nick_name" ) 55 | private String nickName; 56 | /** 57 | * 真实姓名 58 | */ 59 | @TableField( "real_name" ) 60 | private String realName; 61 | /** 62 | * 电子邮箱 63 | */ 64 | private String email; 65 | /** 66 | * 手机号码 67 | */ 68 | private String phone; 69 | /** 70 | * 用户头像 71 | */ 72 | @TableField( "user_image_url" ) 73 | private String userImageUrl; 74 | /** 75 | * 密码最后重置(修改)日期 76 | */ 77 | @TableField( "last_password_reset_date" ) 78 | private Date lastPasswordResetDate; 79 | /** 80 | * 创建人 81 | */ 82 | @TableField( "create_user_id" ) 83 | private Long createUserId; 84 | /** 85 | * 修改人 86 | */ 87 | @TableField( "update_user_id" ) 88 | private Long updateUserId; 89 | /** 90 | * 创建时间 91 | */ 92 | @TableField( "create_time" ) 93 | private Date createTime; 94 | /** 95 | * 修改时间 96 | */ 97 | @TableField( "update_time" ) 98 | private Date updateTime; 99 | /** 100 | * 账户状态(1:激活,0:锁定) 101 | */ 102 | @TableField( "is_enabled" ) 103 | private Boolean enabled; 104 | /** 105 | * 备注 106 | */ 107 | private String remark; 108 | 109 | 110 | @Override 111 | protected Serializable pkVal () { 112 | return this.id; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/UserRole.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain; 2 | 3 | 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import com.baomidou.mybatisplus.extension.activerecord.Model; 9 | import lombok.Getter; 10 | import lombok.Setter; 11 | import lombok.ToString; 12 | import lombok.experimental.Accessors; 13 | 14 | import java.io.Serializable; 15 | 16 | /** 17 | *18 | * 后台管理角色_id 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-28 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @TableName( "manage_user_role" ) 29 | public class UserRole extends Model< UserRole > { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId( value = "id", type = IdType.AUTO ) 37 | private Long id; 38 | /** 39 | * 后台管理用户_id 40 | */ 41 | @TableField( "user_id" ) 42 | private Long userId; 43 | /** 44 | * 后台管理角色_id 45 | */ 46 | @TableField( "role_id" ) 47 | private Long roleId; 48 | 49 | 50 | @Override 51 | protected Serializable pkVal () { 52 | return this.id; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/enums/EmailSendState.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain.enums; 2 | 3 | import com.baomidou.mybatisplus.core.enums.IEnum; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 发送状态 8 | * ( 9 | * NOT_SEND : 未发送, 10 | * SEND : 已发送, 11 | * FAIL_SEND : 发送失败, 12 | * FINAL_FAIL_SEND : 重试次数用完后,还是发送失败 13 | * ) 14 | * 15 | * @author : 披荆斩棘 16 | * @date : 2017/8/7 17 | */ 18 | @Getter 19 | public enum EmailSendState implements IEnum { 20 | 21 | /** 22 | * 23 | */ 24 | NOT_SEND( "NOT_SEND" , "未发送" ), 25 | SEND( "SEND" , "已发送" ), 26 | FAIL_SEND( "FAIL_SEND" , "发送失败" ), 27 | FINAL_FAIL_SEND( "FINAL_FAIL_SEND" , "重试次数用完后,还是发送失败" ); 28 | 29 | /** 数据库存储值 **/ 30 | private String value; 31 | /** 相应注释 **/ 32 | private String comment; 33 | 34 | EmailSendState ( String value , String comment ) { 35 | this.value = value; 36 | this.comment = comment; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/enums/NoticeType.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain.enums; 2 | 3 | import com.baomidou.mybatisplus.core.enums.IEnum; 4 | import com.goblin.manage.bean.domain.SystemLog; 5 | import lombok.Getter; 6 | 7 | /** 8 | * 通知类型(SMS:短信,MAIL:邮箱) 9 | * 10 | * @author : 披荆斩棘 11 | * @date : 2017/12/29 12 | * 对应字段 {@link SystemLog#getNoticeType()} 13 | */ 14 | @Getter 15 | public enum NoticeType implements IEnum { 16 | /** 17 | * 18 | */ 19 | SMS( "SMS" , "短信通知" ), 20 | MAIL( "MAIL" , "邮箱通知" ); 21 | 22 | /** 数据库存储值 **/ 23 | private String value; 24 | /** 相应注释 **/ 25 | private String comment; 26 | 27 | NoticeType ( String value , String comment ) { 28 | this.value = value; 29 | this.comment = comment; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/enums/ResourceType.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain.enums; 2 | 3 | import com.baomidou.mybatisplus.core.enums.IEnum; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.goblin.manage.bean.domain.PermissionResource; 6 | import lombok.Getter; 7 | 8 | /** 9 | * 资源类型(API:接口,MENU:菜单,BUTTON:按钮) 10 | *11 | * 对应字段 {@link PermissionResource#getResourceType()} 12 | */ 13 | @Getter 14 | public enum ResourceType implements IEnum { 15 | 16 | /** 17 | * 18 | */ 19 | API( "API" , "接口" ), 20 | MENU( "MENU" , "菜单" ), 21 | BUTTON( "BUTTON" , "按钮" ); 22 | 23 | /** 数据库存储值 **/ 24 | private String value; 25 | /** 相应注释 **/ 26 | private String comment; 27 | 28 | ResourceType ( String value , String comment ) { 29 | this.value = value; 30 | this.comment = comment; 31 | } 32 | 33 | /** 34 | * {@link JsonValue} 指定序列化为该字段,也就是显示时以该字段显示 35 | */ 36 | @JsonValue 37 | public String getComment () { 38 | return comment; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/enums/ToEmailType.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.domain.enums; 2 | 3 | import com.baomidou.mybatisplus.core.enums.IEnum; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 收件箱类型(SYSTEM:系统邮箱,OTHER:其他邮箱[非系统邮箱]),默认为 : SYSTEM 8 | * 9 | * @author : 披荆斩棘 10 | * @date : 2017/8/7 11 | */ 12 | @Getter 13 | public enum ToEmailType implements IEnum { 14 | 15 | /** 16 | * 17 | */ 18 | SYSTEM( "SYSTEM" , "系统邮箱" ), 19 | OTHER( "OTHER" , "其他邮箱[非系统邮箱])" ); 20 | 21 | /** 数据库存储值 **/ 22 | private String value; 23 | /** 相应注释 **/ 24 | private String comment; 25 | 26 | ToEmailType ( String value , String comment ) { 27 | this.value = value; 28 | this.comment = comment; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/dto/PermissionResourceForm.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.dto; 2 | 3 | import com.goblin.manage.bean.domain.enums.ResourceType; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import lombok.experimental.Accessors; 8 | 9 | import javax.validation.constraints.NotEmpty; 10 | import javax.validation.constraints.NotNull; 11 | import java.io.Serializable; 12 | import java.util.Set; 13 | 14 | /** 15 | *
16 | * 权限资源表单 17 | *
18 | * 19 | * @author 披荆斩棘 20 | * @since 2017-06-19 21 | */ 22 | @Getter 23 | @Setter 24 | @ToString 25 | @Accessors( chain = true ) 26 | public class PermissionResourceForm implements Serializable { 27 | 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | private Long id; 32 | /** 33 | * 父权限资源ID(0:表示root级) 34 | */ 35 | private Long parentId; 36 | /** 37 | * 排序字段 38 | */ 39 | private Integer permissionSort; 40 | /** 41 | * 权限名称 42 | */ 43 | @NotEmpty( message = "permissionName不能为空" ) 44 | private String permissionName; 45 | /** 46 | * 资源样式class(前端class属性) 47 | */ 48 | private String resourceClass; 49 | /** 50 | * 资源样式style(前端style属性) 51 | */ 52 | private String resourceStyle; 53 | /** 54 | * 资源路由URL(前端使用) 55 | */ 56 | private String resourceRouterUrl; 57 | /** 58 | * 资源类型(API:接口,MENU:菜单,BUTTON:按钮) 59 | */ 60 | @NotNull( message = "resourceType不能为空" ) 61 | private ResourceType resourceType; 62 | /** 63 | * 资源API URI(非必须,api才有) 64 | */ 65 | private String resourceApiUri; 66 | /** 67 | * 资源API URI方法methods 68 | */ 69 | private Set< String > resourceApiUriMethods; 70 | /** 71 | * 资源API URI 显示字段列表 72 | * 提供选择以','逗号分隔 73 | */ 74 | private String resourceApiUriOptionsFields; 75 | /** 76 | * 备注 77 | */ 78 | private String remark; 79 | /** 80 | * 分类(C,R,U,D)冗余字段 81 | */ 82 | private String categoryCode; 83 | /** 84 | * 资源API URI 可显示字段 85 | */ 86 | private String resourceApiUriShowFields; 87 | 88 | } 89 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/dto/RoleUpdateForm.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.dto; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import lombok.experimental.Accessors; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | *12 | * 后台管理角色表 13 | *
14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-07-04 17 | */ 18 | @Getter 19 | @Setter 20 | @ToString 21 | @Accessors( chain = true ) 22 | public class RoleUpdateForm implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | /** 27 | * 角色名称 28 | */ 29 | private String roleName; 30 | /** 31 | * 角色名称core(组code+角色code) 32 | */ 33 | private String roleNameCode; 34 | /** 35 | * 角色状态(1:激活,0:锁定) 36 | */ 37 | private Boolean enabled; 38 | /** 39 | * 描述 40 | */ 41 | private String description; 42 | /** 43 | * 备注 44 | */ 45 | private String remark; 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/dto/UserForm.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.dto; 2 | 3 | import com.goblin.common.util.ValidatedGroups; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import lombok.experimental.Accessors; 8 | import org.hibernate.validator.constraints.Length; 9 | 10 | import javax.validation.constraints.*; 11 | import java.io.Serializable; 12 | 13 | /** 14 | * 用户表单 15 | * 16 | * @author : 披荆斩棘 17 | * @date : 2017/7/5 18 | */ 19 | @Getter 20 | @Setter 21 | @ToString 22 | @Accessors( chain = true ) 23 | public class UserForm implements Serializable { 24 | 25 | @NotNull( message = "id不能为空", groups = ValidatedGroups.Update.class ) 26 | private Long id; 27 | /** 28 | * 用户名(登录名称) 29 | */ 30 | @NotEmpty( message = "username不能为空", groups = { ValidatedGroups.Special.class , ValidatedGroups.Save.class } ) 31 | @Size( min = 3, max = 32, message = "username长度必须在{min}和{max}之间" ) 32 | private String username; 33 | /** 34 | * 密码 35 | */ 36 | @NotEmpty( message = "password不能为空", groups = { ValidatedGroups.Special.class , ValidatedGroups.Save.class } ) 37 | @Length( min = 6, message = "password长度不能小于6位" ) 38 | private String password; 39 | /** 40 | * 昵称 41 | */ 42 | private String nickName; 43 | /** 44 | * 真实姓名 45 | */ 46 | private String realName; 47 | /** 48 | * 电子邮箱 49 | */ 50 | @Email( message = "email格式不正确", groups = { ValidatedGroups.Save.class } ) 51 | private String email; 52 | /** 53 | * 手机号码 54 | */ 55 | @Pattern( regexp = "^(1[0-9])\\d{9}$", message = "手机号格式不正确", groups = { ValidatedGroups.Save.class } ) 56 | private String phone; 57 | /** 58 | * 用户头像 59 | */ 60 | private String userImageUrl; 61 | /** 62 | * 创建人 63 | */ 64 | private Long createManagerAdminUserId; 65 | /** 66 | * 账户状态(1:激活,0:锁定) 67 | */ 68 | private Boolean enabled; 69 | /** 70 | * 备注 71 | */ 72 | private String remark; 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/vo/PermissionResourceVO.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.vo; 2 | 3 | import com.goblin.common.util.RecursionUtils; 4 | import com.goblin.manage.bean.domain.PermissionResource; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.ToString; 8 | import lombok.experimental.Accessors; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * @author : 披荆斩棘 15 | * @date : 2017/6/21 16 | */ 17 | @Getter 18 | @Setter 19 | @Accessors( chain = true ) 20 | @ToString( callSuper = true ) 21 | public class PermissionResourceVO extends PermissionResource implements RecursionUtils.ParentChildrenRecursion< PermissionResourceVO > { 22 | 23 | private List< String > methods = new ArrayList<>(); 24 | private List< PermissionResourceVO > children = new ArrayList<>(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.bean.vo; 2 | 3 | import com.goblin.manage.bean.domain.Role; 4 | import com.goblin.manage.bean.domain.User; 5 | import lombok.*; 6 | import lombok.experimental.Accessors; 7 | 8 | /** 9 | *10 | * 后台管理用户 11 | *
12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-06-19 15 | */ 16 | @Getter 17 | @Setter 18 | @ToString 19 | @Accessors( chain = true ) 20 | public class UserVO extends User { 21 | 22 | private Role role; 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/MailSubscribeMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.MailSubscribe; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *8 | * 邮件订阅 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface MailSubscribeMapper extends BaseMapper8 | * 后台管理权限资源表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface PermissionResourceMapper extends BaseMapper8 | * 后台管理角色表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface RoleMapper extends BaseMapper8 | * 后台管理角色资源中间表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface RolePermissionResourceMapper extends BaseMapper8 | * 短信订阅表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface SmsSubscribeMapper extends BaseMapper8 | * 系统配置表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface SystemConfigMapper extends BaseMapper8 | * 系统日志表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-12-29 13 | */ 14 | public interface SystemLogMapper extends BaseMapper8 | * 后台管理用户 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface UserMapper extends BaseMapper8 | * 后台管理用户角色中间表 Mapper 接口 9 | *
10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface UserRoleMapper extends BaseMappertrue
23 | */
24 | boolean validate ( String sessionId , String inputCaptcha );
25 |
26 | /**
27 | * 清除验证码
28 | *
29 | * @param sessionId
30 | * @return 如果清除成功返回 true
31 | */
32 | boolean clear ( String sessionId );
33 | }
34 |
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/MailSubscribeService.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import com.goblin.common.PagingRequest;
4 | import com.goblin.manage.bean.domain.MailSubscribe;
5 | import com.baomidou.mybatisplus.extension.service.IService;
6 | import com.github.pagehelper.PageInfo;
7 |
8 | /**
9 | * 10 | * 邮件订阅 服务类 11 | *
12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-08-07 15 | */ 16 | public interface MailSubscribeService extends IService15 | * 后台管理权限资源表 服务类 16 | *
17 | * 18 | * @author 披荆斩棘 19 | * @since 2017-06-19 20 | */ 21 | public interface PermissionResourceService extends IService< PermissionResource > { 22 | 23 | PageInfo< PermissionResource > listPage ( PagingRequest pagingRequest ); 24 | /** 25 | * 所有权限资源列表,层级关系已整理 26 | * 27 | * @return 28 | */ 29 | List< PermissionResourceVO > listPermission (); 30 | 31 | /** 32 | * 用户权限资源列表,层级关系已整理 33 | * 34 | * @param userId 35 | * @return 36 | */ 37 | List< PermissionResourceVO > listUserPermission ( Long userId ); 38 | 39 | List< PermissionResourceVO > listUserPermissionByRolePermissionResource ( List< RolePermissionResource > rolePermissionResources ); 40 | 41 | boolean save ( PermissionResourceForm form ); 42 | 43 | boolean deleteRelatePermissionResource ( List< PermissionResourceVO > vo ); 44 | 45 | boolean update ( PermissionResourceForm form ); 46 | 47 | List< PermissionResourceVO > listSuperAdminPermissionResource (); 48 | 49 | boolean roleHasResource ( Long roleId , Long permissionResourceId ); 50 | } 51 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/RolePermissionResourceService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.pagehelper.PageInfo; 5 | import com.goblin.common.PagingRequest; 6 | import com.goblin.manage.bean.domain.RolePermissionResource; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *12 | * 后台管理角色资源中间表 服务类 13 | *
14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-06-19 17 | */ 18 | public interface RolePermissionResourceService extends IService11 | * 后台管理角色表 服务类 12 | *
13 | * 14 | * @author 披荆斩棘 15 | * @since 2017-06-19 16 | */ 17 | public interface RoleService extends IService< Role > { 18 | 19 | 20 | List< Role > listByUserId ( Long userId ); 21 | 22 | boolean save ( Long userId , Long roleId ); 23 | 24 | List< Role > listByUserRole ( List< UserRole > userRoles ); 25 | 26 | boolean deleteRelatedById ( Long id ); 27 | 28 | Role getByRoleNameCode ( String roleCode ); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/SystemConfigService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.pagehelper.PageInfo; 5 | import com.goblin.manage.bean.domain.SystemConfig; 6 | import com.goblin.common.PagingRequest; 7 | 8 | /** 9 | *10 | * 系统配置表服务类 11 | *
12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-06-19 15 | */ 16 | public interface SystemConfigService extends IService10 | * 系统日志表 服务类 11 | *
12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-12-29 15 | */ 16 | public interface SystemLogService extends IService21 | *
参数名称 | 25 | *参数类型 | 26 | *参数说明 | 27 | *
PagingRequest#getPageNumber() | 30 | *int | 31 | *页码 | 32 | *
PagingRequest#getPageSize() | 35 | *int | 36 | *每页显示数量 | 37 | *
12 | * 后台管理用户角色中间表 服务类 13 | *
14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-06-19 17 | */ 18 | public interface UserRoleService extends IService12 | * 后台管理用户 服务类 13 | *
14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-06-19 17 | */ 18 | public interface UserService extends IService< User > { 19 | 20 | PageInfo15 | * 邮件订阅 服务实现类 16 | *
17 | * 18 | * @author 披荆斩棘 19 | * @since 2017-08-07 20 | */ 21 | @Service 22 | public class MailSubscribeServiceImpl extends ServiceImpl< MailSubscribeMapper, MailSubscribe > implements MailSubscribeService { 23 | 24 | @Override 25 | public PageInfo< MailSubscribe > listPage ( PagingRequest pagingRequest ) { 26 | PageHelper.startPage( pagingRequest.getPageNumber() , pagingRequest.getPageSize() ); 27 | return new PageInfo<>( super.list() ); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/RolePermissionResourceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.github.pagehelper.PageHelper; 6 | import com.github.pagehelper.PageInfo; 7 | import com.goblin.common.PagingRequest; 8 | import com.goblin.manage.bean.domain.Role; 9 | import com.goblin.manage.bean.domain.RolePermissionResource; 10 | import com.goblin.manage.bean.domain.User; 11 | import com.goblin.manage.mapper.RolePermissionResourceMapper; 12 | import com.goblin.manage.service.RolePermissionResourceService; 13 | import com.goblin.manage.service.RoleService; 14 | import com.goblin.manage.service.UserService; 15 | import org.apache.commons.collections4.CollectionUtils; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Service; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | import java.util.Objects; 22 | import java.util.stream.Collectors; 23 | 24 | /** 25 | *26 | * 后台管理角色资源中间表 服务实现类 27 | *
28 | * 29 | * @author 披荆斩棘 30 | * @since 2017-06-19 31 | */ 32 | @Service 33 | public class RolePermissionResourceServiceImpl extends ServiceImpl< RolePermissionResourceMapper, RolePermissionResource > implements RolePermissionResourceService { 34 | 35 | @Autowired 36 | private RoleService roleService; 37 | @Autowired 38 | private UserService userService; 39 | 40 | @Override 41 | public PageInfo< RolePermissionResource > listPage ( PagingRequest pagingRequest ) { 42 | PageHelper.startPage( pagingRequest.getPageNumber() , pagingRequest.getPageSize() ); 43 | return new PageInfo<>( super.list() ); 44 | } 45 | 46 | @Override 47 | public List< RolePermissionResource > listByUserId ( Long userId ) { 48 | // 1. 得到用户 49 | final User user = userService.getById( userId ); 50 | 51 | if ( Objects.isNull( user ) ) { 52 | return Collections.emptyList(); 53 | } 54 | // 2. 得到角色 55 | final List< Role > roles = roleService.listByUserId( user.getId() ); 56 | 57 | if ( CollectionUtils.isEmpty( roles ) ) { 58 | return Collections.emptyList(); 59 | } 60 | // 3. 得到角色资源中间表信息 61 | return super.list( 62 | new QueryWrapper< RolePermissionResource >().lambda().in( 63 | RolePermissionResource::getRoleId , 64 | roles.parallelStream().map( Role::getId ).collect( Collectors.toList() ) 65 | ) 66 | ); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/SystemConfigServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.pagehelper.PageHelper; 5 | import com.github.pagehelper.PageInfo; 6 | import com.goblin.common.PagingRequest; 7 | import com.goblin.manage.bean.domain.SystemConfig; 8 | import com.goblin.manage.mapper.SystemConfigMapper; 9 | import com.goblin.manage.service.SystemConfigService; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | *14 | * 系统配置表(MYISAM引擎) 服务实现类 15 | *
16 | * 17 | * @author 披荆斩棘 18 | * @since 2017-06-19 19 | */ 20 | @Service 21 | public class SystemConfigServiceImpl extends ServiceImpl< SystemConfigMapper, SystemConfig > implements SystemConfigService { 22 | 23 | 24 | @Override 25 | public PageInfo listPage ( PagingRequest pagingRequest ) { 26 | PageHelper.startPage( pagingRequest.getPageNumber() , pagingRequest.getPageSize() ); 27 | return new PageInfo( super.list() ); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/SystemLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.pagehelper.PageHelper; 5 | import com.github.pagehelper.PageInfo; 6 | import com.goblin.common.PagingRequest; 7 | import com.goblin.manage.bean.domain.SystemLog; 8 | import com.goblin.manage.mapper.SystemLogMapper; 9 | import com.goblin.manage.service.SystemLogService; 10 | import org.springframework.scheduling.annotation.Async; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Propagation; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | 16 | /** 17 | *18 | * 系统日志表 服务实现类 19 | *
20 | * 21 | * @author 披荆斩棘 22 | * @since 2017-12-29 23 | */ 24 | @Service 25 | public class SystemLogServiceImpl extends ServiceImpl< SystemLogMapper, SystemLog > implements SystemLogService { 26 | 27 | 28 | @Override 29 | public PageInfo< SystemLog > listPage ( PagingRequest pagingRequest ) { 30 | PageHelper.startPage( pagingRequest.getPageNumber() , pagingRequest.getPageSize() ); 31 | return new PageInfo<>( super.list() ); 32 | } 33 | 34 | @Async 35 | @Transactional( propagation = Propagation.NOT_SUPPORTED ) 36 | @Override 37 | public void asyncSave ( SystemLog systemLog ) { 38 | super.save( systemLog ); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/UserRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.github.pagehelper.PageHelper; 6 | import com.github.pagehelper.PageInfo; 7 | import com.goblin.common.PagingRequest; 8 | import com.goblin.manage.bean.domain.UserRole; 9 | import com.goblin.manage.mapper.UserRoleMapper; 10 | import com.goblin.manage.service.UserRoleService; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.Objects; 16 | 17 | /** 18 | *19 | * 后台管理用户角色中间表 服务实现类 20 | *
21 | * 22 | * @author 披荆斩棘 23 | * @since 2017-06-19 24 | */ 25 | @Service 26 | public class UserRoleServiceImpl extends ServiceImpl< UserRoleMapper, UserRole > implements UserRoleService { 27 | 28 | 29 | @Override 30 | public PageInfo< UserRole > listPage ( PagingRequest pagingRequest ) { 31 | PageHelper.startPage( pagingRequest.getPageNumber() , pagingRequest.getPageSize() ); 32 | return new PageInfo<>( super.list() ); 33 | } 34 | 35 | @Override 36 | public List< UserRole > listByUserId ( Long userId ) { 37 | if ( Objects.isNull( userId ) ) { 38 | return Collections.emptyList(); 39 | } 40 | return super.list( new QueryWrapper< UserRole >().eq( "user_id" , userId ) ); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # 定制镜像,以一个镜像为基础,在其上进行定制,基础镜像是必须指定的.FROM就是指定基础镜像 2 | # FROM 是必备的指令,并 且必须是第一条指令。 3 | FROM frolvlad/alpine-oraclejdk8:slim 4 | VOLUME /tmp 5 | ADD goblin-manage-system-webapp-0.0.1-SNAPSHOT.jar app.jar 6 | # RUN 指令是用来执行命令行命令的。 7 | RUN sh -c 'touch /app.jar' 8 | ENV JAVA_OPTS="" 9 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 10 | 11 | 12 | # * Dockerfile 中每一个指令都会建立一层 13 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/ManageSystemWebAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | /** 9 | * @author pijingzhanji 10 | */ 11 | @SpringBootApplication( scanBasePackages = "com.goblin" ) 12 | public class ManageSystemWebAppApplication extends SpringBootServletInitializer { 13 | 14 | public static void main ( String[] args ) { 15 | SpringApplication.run( ManageSystemWebAppApplication.class , args ); 16 | } 17 | 18 | 19 | @Override 20 | protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) { 21 | return application.sources( SpringBootServletInitializer.class ); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/PagingRequestBodyAdvice.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import com.goblin.common.PagingRequest; 4 | import org.springframework.core.MethodParameter; 5 | import org.springframework.http.HttpInputMessage; 6 | import org.springframework.http.converter.HttpMessageConverter; 7 | import org.springframework.web.bind.annotation.RestControllerAdvice; 8 | import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice; 9 | 10 | import java.io.IOException; 11 | import java.lang.reflect.Type; 12 | 13 | /** 14 | * application/json 15 | * 处理 {@link org.springframework.web.bind.annotation.RequestBody} 16 | * 17 | * @author : 披荆斩棘 18 | * @date : 2017/7/14 19 | */ 20 | @RestControllerAdvice 21 | public class PagingRequestBodyAdvice implements RequestBodyAdvice { 22 | 23 | @Override 24 | public boolean supports ( MethodParameter methodParameter, 25 | Type targetType, 26 | Class< ? extends HttpMessageConverter< ? > > converterType ) { 27 | return PagingRequest.class.isAssignableFrom( methodParameter.getParameterType() ); 28 | } 29 | 30 | @Override 31 | public Object handleEmptyBody ( Object body, 32 | HttpInputMessage inputMessage, 33 | MethodParameter parameter, 34 | Type targetType, 35 | Class< ? extends HttpMessageConverter< ? > > converterType ) { 36 | // 如果为空,给个默认值 37 | return new PagingRequest(); 38 | } 39 | 40 | @Override 41 | public HttpInputMessage beforeBodyRead ( HttpInputMessage inputMessage, 42 | MethodParameter parameter, 43 | Type targetType, 44 | Class< ? extends HttpMessageConverter< ? > > converterType ) throws 45 | IOException { 46 | return inputMessage; 47 | } 48 | 49 | @Override 50 | public Object afterBodyRead ( Object body, 51 | HttpInputMessage inputMessage, 52 | MethodParameter parameter, 53 | Type targetType, 54 | Class< ? extends HttpMessageConverter< ? > > converterType ) { 55 | return body; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/ResponseEntityAspect.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import com.goblin.common.ResponseEntityPro; 4 | import com.goblin.manage.bean.domain.RolePermissionResource; 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.Around; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Objects; 12 | 13 | import static com.goblin.common.util.JsonUtils.jsonToType; 14 | import static com.goblin.common.util.JsonUtils.toFilterJson; 15 | 16 | /** 17 | * api {@link ResponseEntity} 返回类型处理,针对 {@link RolePermissionResource#getResourceApiUriShowFields()} 字段 18 | * 19 | * @author : 披荆斩棘 20 | * @date : 2017/11/14 21 | */ 22 | @Aspect 23 | @Component 24 | public class ResponseEntityAspect { 25 | 26 | 27 | @Around( "execution(org.springframework.http.ResponseEntity com.goblin.*.controller.*Controller.*(..)) )" ) 28 | public Object returnValueHandle ( ProceedingJoinPoint joinPoint ) throws Throwable { 29 | 30 | Object returnValue = joinPoint.proceed(); 31 | 32 | ResponseEntity responseEntity = ( ResponseEntity ) returnValue; 33 | 34 | // 用户权限或者用户自定义处理 35 | final RolePermissionResource currentRequestRolePermissionResource = ContextUtils.getCurrentRequestRolePermissionResource(); 36 | if ( Objects.isNull( currentRequestRolePermissionResource ) ) { 37 | return returnValue; 38 | } 39 | if ( ResponseEntityPro.WILDCARD_ALL.equals( currentRequestRolePermissionResource.getResourceApiUriShowFields() ) ) { 40 | ContextUtils.removeCurrentRequestRolePermissionResource(); 41 | return returnValue; 42 | } 43 | 44 | final String resourceApiUriShowFields = currentRequestRolePermissionResource.getResourceApiUriShowFields(); 45 | final String filterAfterJsonBody = toFilterJson( responseEntity.getBody() , resourceApiUriShowFields ); 46 | final Object filterAfterBody = jsonToType( filterAfterJsonBody , responseEntity.getBody().getClass() ); 47 | ContextUtils.removeCurrentRequestRolePermissionResource(); 48 | return new ResponseEntity<>( filterAfterBody , 49 | responseEntity.getHeaders() , 50 | responseEntity.getStatusCode() ); 51 | 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/config/SpringInterceptorConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.config; 2 | 3 | import com.goblin.manage.permission.AdminPermissionInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * @author : 披荆斩棘 11 | * @date : 2017/5/10 12 | */ 13 | @Configuration 14 | public class SpringInterceptorConfig implements WebMvcConfigurer { 15 | 16 | @Bean 17 | public AdminPermissionInterceptor adminPermissionInterceptor () { 18 | return new AdminPermissionInterceptor(); 19 | } 20 | 21 | /** 22 | * 添加拦截器 23 | * 24 | * @param registry 25 | */ 26 | @Override 27 | public void addInterceptors ( InterceptorRegistry registry ) { 28 | registry.addInterceptor( adminPermissionInterceptor() ).addPathPatterns( "/**" ); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.common.ResponseEntityPro; 4 | import com.goblin.common.annotation.PassInjectionAttackIntercept; 5 | import com.goblin.common.util.DistributedCode; 6 | import com.goblin.manage.bean.domain.User; 7 | import com.goblin.manage.permission.Pass; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.Date; 13 | 14 | /** 15 | * @author : 披荆斩棘 16 | * @date : 2017/8/26 17 | */ 18 | @Pass 19 | @RestController 20 | public class DemoController { 21 | 22 | 23 | @GetMapping( "demo" ) 24 | public ResponseEntity demo () { 25 | return new ResponseEntityPro().add( "id" , DistributedCode.globalUniqueId() ) 26 | .add( "password" , "123456" ) 27 | .buildOk(); 28 | } 29 | 30 | @GetMapping( "demo2" ) 31 | public ResponseEntity demo2 () { 32 | return ResponseEntityPro.badRequest( 33 | new User().setPassword( "123456" ) 34 | .setNickName( "披荆斩棘" ) 35 | .setPhone( "18696666666" ) 36 | .setRealName( "渣渣辉" ) 37 | .setLastPasswordResetDate( new Date() ) 38 | .setRemark( "地精风险投资公司" ) 39 | .setEmail( "yujunhao_8831@yahoo.com" ) , 40 | "-password" 41 | ); 42 | } 43 | 44 | @GetMapping( "injection" ) 45 | @PassInjectionAttackIntercept( { "update" , "delete" } ) 46 | public ResponseEntity< String > injection () { 47 | return ResponseEntityPro.ok( DistributedCode.globalUniqueId() ); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/DistributedDemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.manage.permission.Pass; 4 | import com.goblin.manage.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * 分布式异步业务示例 13 | * 14 | * @author : 披荆斩棘 15 | * @date : 2017/12/22 16 | */ 17 | @Pass 18 | @RestController 19 | @RequestMapping( "distributed" ) 20 | public class DistributedDemoController { 21 | 22 | 23 | @Autowired 24 | private UserService userService; 25 | 26 | /** 27 | * 支付 28 | */ 29 | @GetMapping( "pay" ) 30 | public ResponseEntity pay () { 31 | // 支付处理 32 | userService.pay(); 33 | return ResponseEntity.ok().body( "支付成功" ); 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/EnumDemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.manage.bean.domain.PermissionResource; 4 | import com.goblin.manage.permission.Pass; 5 | import com.goblin.manage.service.PermissionResourceService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 枚举映射 16 | * 17 | * @author : 披荆斩棘 18 | * @date : 2017/12/22 19 | */ 20 | @Pass 21 | @RestController 22 | @RequestMapping( "enums" ) 23 | public class EnumDemoController { 24 | 25 | @Autowired 26 | private PermissionResourceService permissionResourceService; 27 | 28 | 29 | @GetMapping 30 | public ResponseEntity< List< PermissionResource > > list () { 31 | return ResponseEntity.ok().body( permissionResourceService.list() ); 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/LogDemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.goblin.common.PagingRequest; 5 | import com.goblin.common.ResponseEntityPro; 6 | import com.goblin.common.annotation.Log; 7 | import com.goblin.manage.bean.domain.User; 8 | import com.goblin.manage.permission.Pass; 9 | import com.goblin.manage.service.UserService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * @author : 披荆斩棘 20 | * @date : 2017/8/26 21 | */ 22 | @Pass 23 | @RestController 24 | @RequestMapping( "log" ) 25 | public class LogDemoController { 26 | 27 | @Autowired 28 | private UserService userService; 29 | 30 | @Log 31 | @GetMapping( "users" ) 32 | public ResponseEntity< List< User > > users () { 33 | return ResponseEntityPro.ok( userService.list() ); 34 | } 35 | 36 | @GetMapping( "users-page" ) 37 | public ResponseEntity< PageInfo< User > > listPage ( PagingRequest pagingRequest ) { 38 | return ResponseEntityPro.ok( userService.listPage( pagingRequest ) ); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/RuleController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.manage.permission.Pass; 4 | import com.goblin.manage.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author pijingzhanji 11 | */ 12 | @Pass 13 | @RestController 14 | @RequestMapping( "rules" ) 15 | public class RuleController { 16 | 17 | @Autowired 18 | private UserService userService; 19 | 20 | public static void main ( String[] args ) { 21 | 22 | 23 | 24 | } 25 | 26 | 27 | public void rule () { 28 | 29 | 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/UserValidatorDemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.common.ResponseEntityPro; 4 | import com.goblin.common.util.AssertUtils; 5 | import com.goblin.common.util.LogUtils; 6 | import com.goblin.common.util.ValidatedGroups; 7 | import com.goblin.manage.bean.dto.UserForm; 8 | import com.goblin.manage.permission.Pass; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.validation.BindingResult; 11 | import org.springframework.validation.annotation.Validated; 12 | import org.springframework.web.bind.MethodArgumentNotValidException; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestBody; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | import javax.validation.groups.Default; 19 | 20 | /** 21 | * HibernateValidator 校验示例 22 | * 23 | * @author : 披荆斩棘 24 | * @date : 2017/8/26 25 | */ 26 | @Pass 27 | @RestController 28 | @RequestMapping( "user" ) 29 | public class UserValidatorDemoController { 30 | 31 | 32 | @PostMapping 33 | public ResponseEntity< UserForm > saveValidated ( @RequestBody 34 | @Validated( { ValidatedGroups.Save.class , Default.class } ) UserForm user , 35 | BindingResult result ) { 36 | // 这里可以自己进行处理 37 | AssertUtils.bindingResult( result ); 38 | LogUtils.getLogger().debug( "user : {},验证通过" , user ); 39 | return ResponseEntityPro.ok( user ); 40 | } 41 | 42 | /** 43 | * 如果说不在被 {@link Validated} 注解的实体后面加入 {@link BindingResult} , 44 | * 进行校验过程中,一旦验证不通过那么Spring会抛异常, {@link org.springframework.web.bind.MethodArgumentNotValidException} 异常45 | * 会在 {@link com.goblin.GlobalErrorController#methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException)} 中得到处理 46 | *
47 | * 这样代码整洁些,多余的动作交给框架处理,当然如果要进行细粒度的处理还是要使用 {@link BindingResult} 进行处理 48 | * 49 | * @param user 50 | * @return 51 | */ 52 | @PostMapping( "save-validated-2" ) 53 | public ResponseEntity< UserForm > saveValidated2 ( @RequestBody 54 | @Validated( { ValidatedGroups.Save.class , Default.class } ) UserForm user ) { 55 | LogUtils.getLogger().debug( "user : {},验证通过" , user ); 56 | return ResponseEntityPro.ok( user ); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/controller/WebSocketDemoController.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.controller; 2 | 3 | import com.goblin.common.ResponseEntityPro; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.messaging.handler.annotation.SendTo; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author : 披荆斩棘 11 | * @date : 2017/8/26 12 | */ 13 | @RestController 14 | public class WebSocketDemoController { 15 | 16 | @MessageMapping( "/hello" ) // 接收客户端 17 | @SendTo( "/topic/greetings" ) // 广播消息 18 | public ResponseEntity< String > greeting ( String message ) { 19 | return ResponseEntityPro.ok( "Hello, " + message + "!" ); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/jwt/JwtUser.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.jwt; 2 | 3 | import com.goblin.manage.bean.domain.Role; 4 | import com.goblin.manage.bean.domain.RolePermissionResource; 5 | import com.goblin.manage.bean.vo.PermissionResourceVO; 6 | import com.goblin.security.BasicJwtUser; 7 | import com.fasterxml.jackson.annotation.JsonIgnore; 8 | import lombok.*; 9 | import lombok.experimental.Accessors; 10 | import org.springframework.security.core.GrantedAuthority; 11 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 12 | import org.springframework.util.CollectionUtils; 13 | 14 | import java.util.Collection; 15 | import java.util.Date; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | /** 20 | * jwt对象 21 | * 22 | * @author pijingzhanji 23 | */ 24 | @Getter 25 | @Setter 26 | @ToString 27 | @Accessors( chain = true ) 28 | @AllArgsConstructor 29 | @NoArgsConstructor 30 | public class JwtUser implements BasicJwtUser { 31 | 32 | private Long id; 33 | private String username; 34 | private String password; 35 | private String nickName; 36 | private String realName; 37 | private String email; 38 | private String phone; 39 | private String userImageUrl; 40 | private Date lastPasswordResetDate; 41 | private Long createManagerAdminUserId; 42 | private Date createTime; 43 | private Date updateTime; 44 | private String remark; 45 | private boolean enabled; 46 | /** 用户角色信息 **/ 47 | private List< Role > roles; 48 | /** 用户权限资源信息 **/ 49 | private List< PermissionResourceVO > permissionResource; 50 | /** 用户后台管理角色资源中间表 **/ 51 | private List< RolePermissionResource > rolePermissionResources; 52 | 53 | 54 | @Override 55 | public String getUsername () { 56 | return this.username; 57 | } 58 | 59 | @Override 60 | public boolean isEnabled () { 61 | return this.enabled; 62 | } 63 | 64 | @JsonIgnore 65 | @Override 66 | public Collection< ? extends GrantedAuthority > getAuthorities () { 67 | if ( CollectionUtils.isEmpty( this.getRoles() ) ) { 68 | return null; 69 | } 70 | return this.getRoles().parallelStream() 71 | .map( role -> new SimpleGrantedAuthority( role.getRoleNameCode() ) ) 72 | .collect( Collectors.toList() ); 73 | } 74 | 75 | @Override 76 | public String getPassword () { 77 | return this.password; 78 | } 79 | 80 | @Override 81 | public boolean isAccountNonExpired () { 82 | return true; 83 | } 84 | 85 | @Override 86 | public boolean isAccountNonLocked () { 87 | return true; 88 | } 89 | 90 | @Override 91 | public boolean isCredentialsNonExpired () { 92 | return true; 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/permission/NotNeedPermission.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.permission; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 不需要权限,只需登录即可 7 | * 8 | * @author : 披荆斩棘 9 | * @date : 2017/6/25 10 | */ 11 | @Target( { ElementType.METHOD , ElementType.TYPE } ) 12 | @Retention( RetentionPolicy.RUNTIME ) 13 | @Documented 14 | public @interface NotNeedPermission { 15 | } 16 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/java/com/goblin/manage/permission/Pass.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.permission; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 放行,不需要登录,也不需要权限 7 | * 8 | * @author : 披荆斩棘 9 | * @date : 2017/6/25 10 | */ 11 | @Target( { ElementType.METHOD , ElementType.TYPE } ) 12 | @Retention( RetentionPolicy.RUNTIME ) 13 | @Documented 14 | public @interface Pass { 15 | } 16 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | # 服务器 2 | server: 3 | port: 8080 4 | 5 | # 日志 6 | logging: 7 | config: classpath:log4j2.xml 8 | 9 | # 数据库 10 | spring: 11 | datasource: 12 | username: root 13 | password: 123456789 14 | url: jdbc:mysql://127.0.0.1:3306/goblin?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 15 | type: com.alibaba.druid.pool.DruidDataSource 16 | # 文档 : https://github.com/alibaba/druid/tree/1.1.0/druid-spring-boot-starter 17 | druid: 18 | # 连接池配置,说明请参考Druid Wiki,配置_DruidDataSource参考配置 -> https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE 19 | filters: stat # 配置监控统计拦截的filters,默认值为stat,配置多个请以英文逗号分隔,如stat,wall,log4j 20 | initialSize: 5 21 | minIdle: 5 22 | maxActive: 20 23 | maxWait: 60000 # 配置获取连接等待超时的时间 24 | timeBetweenEvictionRunsMillis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 25 | minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最小生存的时间,单位是毫秒 26 | validationQuery: SELECT 1 27 | testWhileIdle: true 28 | testOnBorrow: false 29 | testOnReturn: false 30 | poolPreparedStatements: true # 是否打开PSCache 31 | maxPoolPreparedStatementPerConnectionSize: 20 # 指定每个连接上PSCache的大小 32 | # spring boot admin 监控 start 33 | boot: 34 | admin: 35 | client: 36 | enabled: true 37 | url: http://localhost:8888 38 | management: 39 | endpoints: 40 | web: 41 | exposure: 42 | include: "*" 43 | # spring boot admin 监控 end 44 | 45 | 46 | 47 | goblin: 48 | # 缓存相关 49 | spring: 50 | cache: 51 | redis-manager: 52 | default-expiration: 1800 53 | expires: 54 | users: 900 55 | redis: 56 | host: 127.0.0.1 57 | port: 6379 58 | timeout: 60 59 | # mybatis plus 性能分析拦截器 60 | mybatis-plus: 61 | performance-interceptor: 62 | enabled: true 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | # 服务器 2 | server: 3 | port: 8080 4 | 5 | # 设置用于加密/解密属性的主密码 6 | jasypt: 7 | encryptor: 8 | password: goblin 9 | 10 | # 日志 11 | logging: 12 | config: classpath:log4j2.xml 13 | 14 | # 数据库 15 | spring: 16 | datasource: 17 | username: ENC(jEmjzNoC9rTYorAj5mI84A==) 18 | password: ENC(jEmjzNoC9rTYorAj5mI84A==) 19 | url: jdbc:mysql://127.0.0.1:3306/goblin?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 20 | type: com.alibaba.druid.pool.DruidDataSource 21 | # 文档 : https://github.com/alibaba/druid/tree/1.1.0/druid-spring-boot-starter 22 | druid: 23 | # 连接池配置,说明请参考Druid Wiki,配置_DruidDataSource参考配置 -> https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE 24 | filters: stat # 配置监控统计拦截的filters,默认值为stat,配置多个请以英文逗号分隔,如stat,wall,log4j 25 | initialSize: 5 26 | minIdle: 5 27 | maxActive: 20 28 | maxWait: 60000 # 配置获取连接等待超时的时间 29 | timeBetweenEvictionRunsMillis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 30 | minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最小生存的时间,单位是毫秒 31 | validationQuery: SELECT 1 32 | testWhileIdle: true 33 | testOnBorrow: false 34 | testOnReturn: false 35 | poolPreparedStatements: true # 是否打开PSCache 36 | maxPoolPreparedStatementPerConnectionSize: 20 # 指定每个连接上PSCache的大小 37 | # WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter -> https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter 38 | 39 | # spring boot admin 监控 start 40 | boot: 41 | admin: 42 | client: 43 | enabled: true 44 | url: http://localhost:8888 45 | management: 46 | endpoints: 47 | web: 48 | exposure: 49 | include: "*" 50 | # spring boot admin 监控 end 51 | 52 | 53 | 54 | 55 | goblin: 56 | # 缓存相关 57 | spring: 58 | cache: 59 | redis-manager: 60 | default-expiration: 1800 61 | expires: 62 | users: 900 63 | redis: 64 | host: 127.0.0.1 65 | port: 6379 66 | timeout: 60 67 | # mybatis plus 性能分析拦截器 68 | mybatis-plus: 69 | performance-interceptor: 70 | enabled: true 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/application-test.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/goblin-manage-system/goblin-manage-system-webapp/src/main/resources/application-test.yml -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | # 多环境配置文件 4 | profiles: 5 | active: dev 6 | application: 7 | name: goblin-manage-system-webapp 8 | # HTTP字符编码 9 | http: 10 | encoding: 11 | enabled: true 12 | charset: UTF-8 13 | force: true 14 | # 缓存 15 | cache: 16 | type: redis 17 | # AOP 18 | aop: 19 | proxy-target-class: true 20 | auto: true 21 | # 分页 page helper 22 | pagehelper: 23 | helperDialect: mysql 24 | reasonable: true 25 | supportMethodsArguments: true 26 | params: count=countSql 27 | # 压缩,这个属性样板打开了压缩选项,这样稍后应用到JSON正文的压缩就有保证了。 28 | server: 29 | compression: 30 | enabled: true 31 | mime-types: application/json 32 | 33 | mybatis-plus: 34 | mapper-locations: com/goblin/manage/mapper/xml/*.xml 35 | type-aliases-package: com.goblin.manage.bean.domain 36 | type-enums-package: com.goblin.manage.bean.domain.enums 37 | global-config: 38 | db-config: 39 | db-type: mysql 40 | id-type: auto 41 | field-strategy: not_empty 42 | table-underline: true 43 | configuration: 44 | map-underscore-to-camel-case: true 45 | cache-enabled: false 46 | 47 | # 项目自定义配置 48 | goblin: 49 | mybatis-plus: 50 | performance-interceptor: 51 | enabled: true 52 | web-socket: 53 | client-broker-destination-prefixes: /topic 54 | server-application-destination-prefixes: /app 55 | stomp-endpoints-paths: /goblin 56 | filter: 57 | injection-attack-interceptor: 58 | enabled: true 59 | 60 | # jwt 配置 61 | jwt: 62 | # header中key,以改值为key在header中获取 request.getHeader('key') 63 | header: Authorization 64 | # 签名密钥 65 | secret: goblin 66 | # 过期时间,单位:秒 67 | expiration: 3600 68 | 69 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/401.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |22 | * jasypt: 23 | * encryptor: 24 | * password: 你的密钥 25 | *26 | *
27 | * 使用示例 : ENC(加密串)
28 | */
29 | @Autowired
30 | private StringEncryptor stringEncryptor;
31 |
32 | @Test
33 | public void name () throws Exception {
34 | final String username = stringEncryptor.encrypt( "root" );
35 | final String password = stringEncryptor.encrypt( "root" );
36 |
37 | System.err.println( "username = " + username );
38 | System.err.println( "password = " + password );
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/MailSubscribeServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import com.github.pagehelper.PageInfo;
4 | import com.goblin.common.PagingRequest;
5 | import com.goblin.manage.bean.domain.MailSubscribe;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith( SpringRunner.class )
13 | @SpringBootTest
14 | public class MailSubscribeServiceTest {
15 |
16 | @Autowired
17 | private MailSubscribeService mailSubscribeService;
18 |
19 | @Test
20 | public void listPage () {
21 | final PageInfo< MailSubscribe > pageInfo = mailSubscribeService.listPage( new PagingRequest() );
22 | System.err.println("pageInfo = " + pageInfo);
23 | }
24 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/PermissionResourceServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | @RunWith( SpringRunner.class )
10 | @SpringBootTest
11 | public class PermissionResourceServiceTest {
12 |
13 | @Autowired
14 | private PermissionResourceService permissionResourceService;
15 |
16 | @Test
17 | public void name () {
18 |
19 | }
20 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/RolePermissionResourceServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class RolePermissionResourceServiceTest {
11 |
12 | @Autowired
13 | private RolePermissionResourceService rolePermissionResourceService;
14 |
15 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/RoleServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class RoleServiceTest {
11 |
12 | @Autowired
13 | private RoleService roleService;
14 |
15 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/SystemConfigServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class SystemConfigServiceTest {
11 |
12 | @Autowired
13 | private SystemConfigService systemConfigService;
14 |
15 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/SystemLogServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class SystemLogServiceTest {
11 |
12 | @Autowired
13 | private SystemLogService systemLogService;
14 |
15 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/UserRoleServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class UserRoleServiceTest {
11 |
12 | @Autowired
13 | private UserRoleService userRoleService;
14 |
15 | }
--------------------------------------------------------------------------------
/goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/service/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.goblin.manage.service;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith( SpringRunner.class )
9 | @SpringBootTest
10 | public class UserServiceTest {
11 |
12 | @Autowired
13 | private UserService userService;
14 |
15 |
16 | }
--------------------------------------------------------------------------------
/goblin-manage-system/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |