├── .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 | 5 | 6 | com.goblin 7 | goblin-parent 8 | 0.0.1-SNAPSHOT 9 | ../goblin-parent 10 | 11 | 4.0.0 12 | 13 | goblin-admin-ui 14 | 15 | 16 | 17 | 18 | 19 | 20 | de.codecentric 21 | spring-boot-admin-starter-server 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-security 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-mail 38 | 39 | 40 | 41 | 42 | 43 | ${project.artifactId} 44 | 45 | 46 | 47 | src/main/resources 48 | 49 | ** 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | com.goblin.AdminUiApplication 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /goblin-admin-ui/src/main/java/com/goblin/AdminUiApplication.java: -------------------------------------------------------------------------------- 1 | package com.goblin; 2 | 3 | import de.codecentric.boot.admin.server.config.EnableAdminServer; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.builder.SpringApplicationBuilder; 8 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 9 | 10 | /** 11 | * 对于需要部署到传统servlet容器之中的应用,Boot提供了一种方式以编码的方式初始化Web配置。 12 | * 为了使用这一点,Boot提供了可选的WebApplicationInitializer,它会使用servlet容器来 13 | * 注册应用,这会通过Servlet 3.0 API以编码的方式注册servlet并且会用到ServletContext。 14 | * 通过提供SpringBootServletInitializer的子类,Boot应用能够使用嵌入的Spring上下文来 15 | * 注册配置,这个Spring上下文是在容器初始化的时候创建的。 16 | * 17 | * @author : 披荆斩棘 18 | * @date : 2017/7/2 19 | */ 20 | @EnableAutoConfiguration 21 | @EnableAdminServer 22 | @SpringBootApplication 23 | public class AdminUiApplication extends SpringBootServletInitializer { 24 | 25 | public static void main ( String[] args ) { 26 | SpringApplication.run( AdminUiApplication.class , args ); 27 | } 28 | 29 | /** 30 | * Application类中被重写的configure方法就是使用嵌入式的Spring上下文注册应用的地方。 31 | * 在更为正式的场景之中,这个方法可能会用来注册Spring Java配置类,它会定义应用中所有 32 | * controller和服务的bean。 33 | * 34 | * @param application 35 | * @see info 36 | */ 37 | @Override 38 | protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) { 39 | return application.sources( AdminUiApplication.class ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /goblin-admin-ui/src/main/java/com/goblin/config/NotifierConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; 4 | import de.codecentric.boot.admin.server.notify.CompositeNotifier; 5 | import de.codecentric.boot.admin.server.notify.Notifier; 6 | import de.codecentric.boot.admin.server.notify.RemindingNotifier; 7 | import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier; 8 | import org.springframework.beans.factory.ObjectProvider; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Primary; 12 | 13 | import java.time.Duration; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | /** 18 | * 如果监控的服务down后,则会发送邮件提醒 19 | * 20 | * @author : 披荆斩棘 21 | * @date : 2017/7/2 22 | */ 23 | @Configuration 24 | public class NotifierConfiguration { 25 | 26 | private final InstanceRepository repository; 27 | private final ObjectProvider< List< Notifier > > otherNotifiers; 28 | 29 | public NotifierConfiguration ( InstanceRepository repository , ObjectProvider< List< Notifier > > otherNotifiers ) { 30 | this.repository = repository; 31 | this.otherNotifiers = otherNotifiers; 32 | } 33 | 34 | @Bean 35 | public FilteringNotifier filteringNotifier () { 36 | CompositeNotifier delegate = new CompositeNotifier( otherNotifiers.getIfAvailable( Collections::emptyList ) ); 37 | return new FilteringNotifier( delegate , repository ); 38 | } 39 | 40 | @Primary 41 | @Bean( initMethod = "start", destroyMethod = "stop" ) 42 | public RemindingNotifier remindingNotifier () { 43 | RemindingNotifier notifier = new RemindingNotifier( filteringNotifier() , repository ); 44 | notifier.setReminderPeriod( Duration.ofMinutes( 10 ) ); 45 | notifier.setCheckReminderInverval( Duration.ofSeconds( 10 ) ); 46 | return notifier; 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /goblin-admin-ui/src/main/java/com/goblin/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6 | 7 | /** 8 | * @author : 披荆斩棘 9 | * @date : 2017/7/2 10 | */ 11 | @Configuration 12 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 13 | 14 | @Override 15 | protected void configure ( HttpSecurity http ) throws Exception { 16 | http.authorizeRequests().anyRequest().permitAll().and().csrf().disable(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /goblin-admin-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 发件箱,配自己的发件箱,该发件箱已无效 2 | send.mail: pjzj8831@163.com 3 | 4 | # 服务器 5 | server: 6 | port: 8888 7 | 8 | spring: 9 | application: 10 | name: goblin-admin-ui 11 | mail: 12 | port: 25 13 | host: smtp.163.com 14 | protocol: smtp 15 | username: ${send.mail} 16 | password: a1234567890 17 | default-encoding: UTF-8 18 | properties: 19 | mail.smtp.auth: true 20 | mail.smtp.starttls: false 21 | mail.smtp.quitwait: false 22 | boot: 23 | admin: 24 | notify: 25 | mail: 26 | to: yujunhao_8831@yahoo.com # 通知到哪个邮箱 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /goblin-basic-config/src/main/java/com/goblin/config/FeignOkHttpConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import feign.Feign; 4 | import feign.Request; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.ToString; 8 | import okhttp3.ConnectionPool; 9 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 11 | import org.springframework.boot.context.properties.ConfigurationProperties; 12 | import org.springframework.cloud.netflix.feign.FeignAutoConfiguration; 13 | import org.springframework.context.annotation.Bean; 14 | import org.springframework.context.annotation.Configuration; 15 | 16 | import java.util.concurrent.TimeUnit; 17 | 18 | /** 19 | * application.yml 示例 : 20 | *
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 性能分析拦截器
21 | * 文档:http://mp.baomidou.com
22 | */ 23 | @Bean 24 | @ConditionalOnExpression( "${goblin.mybatis-plus.performance-interceptor.enabled:false}" ) 25 | public PerformanceInterceptor performanceInterceptor () { 26 | return new PerformanceInterceptor(); 27 | } 28 | 29 | 30 | @Bean 31 | public LogicSqlInjector logicSqlInjector () { 32 | return new LogicSqlInjector(); 33 | } 34 | 35 | 36 | 37 | @MapperScan( { "com.goblin.manage.mapper" } ) 38 | @Configuration 39 | public class MybatisPlusMapperScan { 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /goblin-basic-config/src/main/java/com/goblin/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | /** 4 | * 5 | * document 6 | * document 7 | *

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时间之后超时过期。
75 | * 这个命令等效于执行下面的命令 : 76 | *
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 | *

20 | *

21 | * 并在 22 | * 23 | * @author : 披荆斩棘 24 | * @date : 2017/7/26 25 | */ 26 | @Retention( RetentionPolicy.RUNTIME ) 27 | @Target( ElementType.METHOD ) 28 | public @interface NeedExport { 29 | 30 | String value () default ""; 31 | 32 | /** 33 | * 导出的对象类型 34 | *

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 |  *     @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 |  * 
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的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 } 44 | * 45 | * 注意,转换过程中,value直接取toString()方法 46 | * 47 | * @param bean 要转换的Bean 48 | * @return 返回bean字段getters方法的全部属性 , 字段名为key , 其属性为value的Map 49 | */ 50 | public static Map< String, String > toStringMap( Object bean ) { 51 | final Map< String, Object > map = toMap( bean ); 52 | Map stringMap = new HashMap<>( map.size() ); 53 | map.forEach( ( key , value ) -> stringMap.put( key, Objects.toString( value , null ) ) ); 54 | return stringMap; 55 | } 56 | 57 | /** 58 | * 拷贝属性 59 | * 60 | * @param sources 源 61 | * @param targetClass 目标 class 62 | * @param 目标类型 63 | * @return 目标集合 64 | */ 65 | public static < T > List< T > copyPropertiesToList ( List< ? > sources , Class targetClass) { 66 | AssertUtils.isTrue( CollectionUtils.isEmpty( sources ), "sources is null" ); 67 | AssertUtils.isTrue( targetClass == null, "targetClass is null" ); 68 | List< T > targets = new ArrayList<>( sources.size() ); 69 | for ( Object source : sources ) { 70 | T target; 71 | try { 72 | target = targetClass.newInstance(); 73 | BeanUtilsBean2.getInstance().copyProperties( target , source ); 74 | } catch ( InstantiationException | IllegalAccessException | InvocationTargetException e ) { 75 | throw new RuntimeException( e.getMessage() , e ); 76 | } 77 | targets.add( target ); 78 | } 79 | return targets; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/DateFormatStyle.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | import lombok.Getter; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * @author : 披荆斩棘 11 | * @date : 2017/7/17 12 | */ 13 | @Getter 14 | public enum DateFormatStyle { 15 | 16 | CN_DATE_BASIC_STYLE( "yyyy-MM-dd HH:mm:ss" ), 17 | CN_DATE_BASIC_STYLE1( "yyyy-MM-dd" ), 18 | CN_DATE_BASIC_STYLE2( "yyyy-MM" ), 19 | CN_DATE_BASIC_STYLE3( "yyyy/MM/dd HH:mm:ss" ), 20 | CN_DATE_BASIC_STYLE4( "yyyy/MM/dd" ), 21 | CN_DATE_BASIC_STYLE5( "yyyyMMdd" ), 22 | CN_DATE_BASIC_STYLE6( "yyyyMM" ), 23 | DATE_TIMESTAMP_STYLE( "yyyyMMddHHmmssSSS" ), 24 | DATE_TIMESTAMP_STYLE2( "yyyyMMddHHmmss" ), 25 | ISO_DATETIME_TIME_ZONE_FORMAT( "yyyy-MM-dd'T'HH:mm:ssZZ" ), 26 | ISO_DATETIME_FORMAT( "yyyy-MM-dd'T'HH:mm:ss" ), 27 | ISO_DATE_TIME_ZONE_FORMAT( "yyyy-MM-ddZZ" ), 28 | ISO_TIME_TIME_ZONE_FORMAT( "'T'HH:mm:ssZZ" ), 29 | ISO_TIME_FORMAT( "'T'HH:mm:ss" ), 30 | ISO_TIME_NO_T_TIME_ZONE_FORMAT( "HH:mm:ssZZ" ), 31 | ISO_TIME_NO_T_FORMAT( "HH:mm:ss" ); 32 | 33 | private String dateStyle; 34 | 35 | DateFormatStyle ( String dateStyle ) { 36 | this.dateStyle = dateStyle; 37 | } 38 | 39 | /** 40 | * @return 按照默认声明顺序 41 | */ 42 | public static List getDateFormatStyles() { 43 | return Arrays.stream(DateFormatStyle.values()) 44 | .map(DateFormatStyle::getDateStyle) 45 | .collect(Collectors.toList()); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/DistributedLock.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | /** 4 | * 基于Redis的分布式锁 5 | * document 6 | * {@link org.redisson.api.RedissonClient} 7 | * 8 | * @author : 披荆斩棘 9 | * @date : 2017/6/3 10 | */ 11 | public final class DistributedLock { 12 | } 13 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/HibernateValidatorPro.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | import org.hibernate.validator.HibernateValidator; 4 | 5 | import javax.validation.Validation; 6 | import javax.validation.Validator; 7 | import javax.validation.spi.ValidationProvider; 8 | 9 | /** 10 | * 用于本地测试,不用启动上下文 11 | * 12 | * @author : 披荆斩棘 13 | * @date : 2017/12/7 14 | */ 15 | public class HibernateValidatorPro { 16 | 17 | /** 18 | * 线程安全的 19 | * 20 | * @return {@link Validator} 21 | */ 22 | public static Validator getHibernateValidator () { 23 | return Validation.byProvider( HibernateValidator.class ) 24 | .configure() 25 | .buildValidatorFactory() 26 | .getValidator(); 27 | } 28 | 29 | /** 30 | * 线程安全的 31 | * 32 | * @return {@link Validator} 33 | */ 34 | public static Validator getValidator ( Class< ? extends ValidationProvider > providerType ) { 35 | return Validation.byProvider( providerType ) 36 | .configure() 37 | .buildValidatorFactory() 38 | .getValidator(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/TransactionUtils.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | import org.springframework.transaction.TransactionStatus; 4 | import org.springframework.transaction.interceptor.TransactionAspectSupport; 5 | 6 | /** 7 | * Spring 事务管理工具类 8 | * 9 | * @author : 披荆斩棘 10 | * @date : 2016/12/23 11 | */ 12 | public abstract class TransactionUtils { 13 | 14 | /** 15 | * 手动进行回滚事务. 16 | * 接口中如果 try catch 异常无法回滚时,这手动调用回滚处理 17 | */ 18 | public static void rollback () { 19 | TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); 20 | if ( null != transactionStatus ) { 21 | transactionStatus.setRollbackOnly(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /goblin-common/src/main/java/com/goblin/common/util/ValidatedGroups.java: -------------------------------------------------------------------------------- 1 | package com.goblin.common.util; 2 | 3 | /** 4 | * Hibernate Validated 分组验证,针对一个实体多种情况下的验证. 5 | *

6 | * {@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 | 5 | 6 | com.goblin 7 | goblin-generator 8 | 0.0.1-SNAPSHOT 9 | 4.0.0 10 | 构建代码 11 | 12 | 13 | com.goblin 14 | goblin-parent 15 | 0.0.1-SNAPSHOT 16 | ../goblin-parent 17 | 18 | 19 | 20 | 21 | 22 | 23 | ${project.groupId} 24 | goblin-common 25 | 26 | 27 | 28 | org.apache.velocity 29 | velocity 30 | 31 | 32 | 33 | com.baomidou 34 | mybatis-plus-boot-starter 35 | 36 | 37 | 38 | mysql 39 | mysql-connector-java 40 | 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /goblin-generator/src/main/resources/templates/mybatis/plus/controller.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | import org.springframework.http.ResponseEntity; 4 | import ${package.Entity}.${entity}; 5 | import ${package.Service}.${table.serviceName}; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | import com.github.pagehelper.PageInfo; 10 | import com.goblin.common.PagingRequest; 11 | 12 | #if(${restControllerStyle}) 13 | #else 14 | import org.springframework.stereotype.Controller; 15 | #end 16 | #if(${superControllerClassPackage}) 17 | import ${superControllerClassPackage}; 18 | #end 19 | 20 | /** 21 | *

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 |      *      
22 |      *          
23 |      *          
24 |      *              
25 |      *              
26 |      *              
27 |      *          
28 |      *          
29 |      *              
30 |      *              
31 |      *              
32 |      *          
33 |      *          
34 |      *              
35 |      *              
36 |      *              
37 |      *          
38 |      *      
参数说明({@link PagingRequest})
参数名称参数类型参数说明
PagingRequest#getPageNumber()int页码
PagingRequest#getPageSize()int每页显示数量
39 | *
40 | * 示例 : 41 | *
    42 | *
  • 1. PageInfo page = listPage(new PagingRequest(1,10));
  • 43 | *
  • 44 | * 2. 控制器中直接使用 PagingRequest 作为参数接收即可,就算客户端不传值也会有默认值.
    45 | * 默认分页起始值 : {@link com.goblin.common.GlobalConstant#DEFAULT_PAGE_NUMBER}
    46 | * 默认分页大小值 : {@link com.goblin.common.GlobalConstant#DEFAULT_PAGE_SIZE} 47 | *
  • 48 | *
49 | * 50 | * 51 | *
52 | * @param pagingRequest 53 | * @return PageInfo 54 | */ 55 | PageInfo<${entity}> listPage( PagingRequest pagingRequest ); 56 | 57 | 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /goblin-generator/src/main/resources/templates/mybatis/plus/serviceImpl.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.github.pagehelper.PageHelper; 10 | import com.github.pagehelper.PageInfo; 11 | import com.goblin.common.PagingRequest; 12 | 13 | 14 | /** 15 | *

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 | 5 | 6 | goblin-manage-system 7 | com.goblin 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | goblin-manage-system-bean 13 | 14 | 15 | 16 | 17 | com.goblin 18 | goblin-common 19 | provided 20 | 21 | 22 | 23 | com.goblin 24 | goblin-security 25 | provided 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-aop 31 | provided 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-security 37 | provided 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-validation 43 | provided 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-web 49 | provided 50 | 51 | 52 | 53 | 54 | org.projectlombok 55 | lombok 56 | provided 57 | true 58 | 59 | 60 | 61 | com.baomidou 62 | mybatis-plus-boot-starter 63 | provided 64 | 65 | 66 | 67 | 68 | com.github.pagehelper 69 | pagehelper-spring-boot-starter 70 | provided 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-bean/src/main/java/com/goblin/manage/bean/domain/MailSubscribe.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_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 BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/PermissionResourceMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.PermissionResource; 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 PermissionResourceMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.Role; 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 RoleMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/RolePermissionResourceMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.RolePermissionResource; 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 RolePermissionResourceMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/SmsSubscribeMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.goblin.manage.bean.domain.SmsSubscribe; 5 | 6 | /** 7 | *

8 | * 短信订阅表 Mapper 接口 9 | *

10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface SmsSubscribeMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/SystemConfigMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.SystemConfig; 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 SystemConfigMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/SystemLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.SystemLog; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * 系统日志表 Mapper 接口 9 | *

10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-12-29 13 | */ 14 | public interface SystemLogMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.goblin.manage.bean.domain.User; 5 | 6 | /** 7 | *

8 | * 后台管理用户 Mapper 接口 9 | *

10 | * 11 | * @author 披荆斩棘 12 | * @since 2017-08-31 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/UserRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.mapper; 2 | 3 | import com.goblin.manage.bean.domain.UserRole; 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 UserRoleMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/MailSubscribeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | id, user_id AS userId, to_email AS toEmail, to_email_type AS toEmailType, email_subject AS emailSubject, email_text AS emailText, email_attachment_url AS emailAttachmentUrl, email_send_time AS emailSendTime, email_send_state AS emailSendState, email_send_retry_number AS emailSendRetryNumber, email_send_retry_count AS emailSendRetryCount, remark, create_time AS createTime, update_time AS updateTime 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/PermissionResourceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | id, parent_id AS parentId, resource_depth AS resourceDepth, permission_sort AS permissionSort, permission_name AS permissionName, resource_class AS resourceClass, resource_style AS resourceStyle, resource_router_url AS resourceRouterUrl, resource_type AS resourceType, resource_api_uri AS resourceApiUri, resource_api_uri_methods AS resourceApiUriMethods, resource_api_uri_options_fields AS resourceApiUriOptionsFields, resource_api_protected_type AS resourceApiProtectedType, create_time AS createTime, update_time AS updateTime, remark, category_code AS categoryCode, is_enabled AS enabled, create_user_id AS createUserId, update_user_id AS updateUserId 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id, role_name AS roleName, role_name_code AS roleNameCode, role_type AS roleType, is_enabled AS enabled, description, create_time AS createTime, update_time AS updateTime, remark 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/RolePermissionResourceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | id, role_id AS roleId, permission_resource_id AS permissionResourceId, resource_api_uri_show_fields AS resourceApiUriShowFields 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/SmsSubscribeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | id, user_id AS userId, sms_phone AS smsPhone, mobile_operators AS mobileOperators, sms_content AS smsContent, sms_send_time AS smsSendTime, sms_send_state AS smsSendState, sms_send_retry_number AS smsSendRetryNumber, sms_send_retry_count AS smsSendRetryCount, remark, create_time AS createTime, update_time AS updateTime 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/SystemConfigMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id, config_key AS configKey, config_value AS configValue, config_description AS configDescription, create_user_id AS createUserId, update_user_id AS updateUserId, create_time AS createTime, update_time AS updateTime, remark 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/SystemLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | id, user_id AS userId, user_real_name AS userRealName, action_level AS actionLevel, action_type AS actionType, action_log AS actionLog, action_ip_address AS actionIpAddress, action_description AS actionDescription, action_start_time AS actionStartTime, action_end_time AS actionEndTime, action_total_time AS actionTotalTime, action_class AS actionClass, action_method AS actionMethod, action_args AS actionArgs, is_warn AS warn, create_time AS createTime, update_time AS updateTime 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | id, username, password, password_salt AS passwordSalt, nick_name AS nickName, real_name AS realName, email, phone, user_image_url AS userImageUrl, last_password_reset_date AS lastPasswordResetDate, create_user_id AS createUserId, update_user_id AS updateUserId, create_time AS createTime, update_time AS updateTime, is_enabled AS enabled, remark 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-dao/src/main/java/com/goblin/manage/mapper/xml/UserRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, user_id AS userId, role_id AS roleId 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/GlobalCacheConstant.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | /** 4 | * cache常量 5 | * 6 | * @author : 披荆斩棘 7 | * @date : 2017/5/19 8 | */ 9 | public abstract class GlobalCacheConstant { 10 | 11 | /** 12 | * {@link com.goblin.manage.jwt.service.JwtUserDetailsService} 13 | */ 14 | public static final String USER_DETAILS_SERVICE_NAMESPACE = "goblin.spring.cache.service-namespace.user-details-service"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/AggregationService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.goblin.manage.bean.domain.User; 4 | 5 | /** 6 | * @author : 披荆斩棘 7 | * @date : 2018/1/5 8 | */ 9 | public interface AggregationService { 10 | 11 | 12 | /** 13 | * {@link com.goblin.config.TransactionalConfig#DEFAULT_REQUIRED_METHOD_RULE_TRANSACTION_ATTRIBUTES} 14 | * 这里是受到事务管理的 15 | */ 16 | void saveUser( User user ); 17 | 18 | /** 19 | * 这里没有受到事务管理的,除非配置了into*的规则 20 | */ 21 | void intoUser( User user ); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/CaptchaService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | /** 4 | * @author : 披荆斩棘 5 | * @date : 2017/6/27 6 | */ 7 | public interface CaptchaService { 8 | 9 | /** 10 | * 存储验证码 11 | * 12 | * @param captchaStoreKey : 未登录用户,使用sessionId标识 13 | * @param captcha : 验证码 14 | */ 15 | boolean set ( String captchaStoreKey , String captcha ); 16 | 17 | /** 18 | * 验证验证码,如果验证码验证通过则会清除掉这个key 19 | * 20 | * @param sessionId : 未登录用户,使用sessionId标识 21 | * @param inputCaptcha : 用户输入的验证码 22 | * @return 如果正确返回 true 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 IService { 17 | 18 | 19 | PageInfo listPage ( PagingRequest pagingRequest ); 20 | 21 | 22 | 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/PermissionResourceService.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.PermissionResource; 6 | import com.goblin.manage.bean.domain.RolePermissionResource; 7 | import com.goblin.manage.bean.dto.PermissionResourceForm; 8 | import com.goblin.manage.bean.vo.PermissionResourceVO; 9 | import com.goblin.common.PagingRequest; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * 后台管理权限资源表 服务类 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 IService { 19 | 20 | PageInfo listPage ( PagingRequest pagingRequest ); 21 | 22 | List listByUserId ( Long userId ); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.goblin.manage.bean.domain.Role; 4 | import com.goblin.manage.bean.domain.UserRole; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 后台管理角色表 服务类 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 IService { 17 | 18 | PageInfo listPage ( PagingRequest pagingRequest ); 19 | 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/SystemLogService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.goblin.manage.bean.domain.SystemLog; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.github.pagehelper.PageInfo; 6 | import com.goblin.common.PagingRequest; 7 | 8 | /** 9 | *

10 | * 系统日志表 服务类 11 | *

12 | * 13 | * @author 披荆斩棘 14 | * @since 2017-12-29 15 | */ 16 | public interface SystemLogService extends IService { 17 | 18 | /** 19 | * 默认分页(PageHelper分页) 20 | *
21 |      *      
22 |      *          
23 |      *          
24 |      *              
25 |      *              
26 |      *              
27 |      *          
28 |      *          
29 |      *              
30 |      *              
31 |      *              
32 |      *          
33 |      *          
34 |      *              
35 |      *              
36 |      *              
37 |      *          
38 |      *      
参数说明({@link PagingRequest})
参数名称参数类型参数说明
PagingRequest#getPageNumber()int页码
PagingRequest#getPageSize()int每页显示数量
39 | *
40 | * 示例 : 41 | *
    42 | *
  • 1. PageInfo page = listPage(new PagingRequest(1,10));
  • 43 | *
  • 44 | * 2. 控制器中直接使用 PagingRequest 作为参数接收即可,就算客户端不传值也会有默认值.
    45 | * 默认分页起始值 : {@link com.goblin.common.GlobalConstant#DEFAULT_PAGE_NUMBER}
    46 | * 默认分页大小值 : {@link com.goblin.common.GlobalConstant#DEFAULT_PAGE_SIZE} 47 | *
  • 48 | *
49 | * 50 | * 51 | *
52 | * @param pagingRequest 53 | * @return PageInfo 54 | */ 55 | PageInfo listPage ( PagingRequest pagingRequest ); 56 | 57 | 58 | void asyncSave ( SystemLog systemLog ); 59 | } 60 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/UserRoleService.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.UserRole; 6 | import com.goblin.common.PagingRequest; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * 后台管理用户角色中间表 服务类 13 | *

14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-06-19 17 | */ 18 | public interface UserRoleService extends IService { 19 | 20 | 21 | PageInfo listPage ( PagingRequest pagingRequest ); 22 | 23 | 24 | List listByUserId ( Long userId ); 25 | } 26 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service; 2 | 3 | import com.goblin.common.PagingRequest; 4 | import com.goblin.manage.bean.domain.User; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.github.pagehelper.PageInfo; 7 | 8 | import java.util.concurrent.Future; 9 | 10 | /** 11 | *

12 | * 后台管理用户 服务类 13 | *

14 | * 15 | * @author 披荆斩棘 16 | * @since 2017-06-19 17 | */ 18 | public interface UserService extends IService< User > { 19 | 20 | PageInfo listPage( PagingRequest pagingRequest ); 21 | 22 | User get ( Long id ); 23 | 24 | User update ( User user ); 25 | 26 | boolean save ( User user ); 27 | 28 | boolean delete ( Long id ); 29 | 30 | User findByUsername ( String username ); 31 | 32 | boolean isExist ( Long userId ); 33 | 34 | boolean isNotExist ( Long userId ); 35 | 36 | 37 | Future pay (); 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/AggregationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.goblin.common.util.AssertUtils; 4 | import com.goblin.manage.bean.domain.User; 5 | import com.goblin.manage.service.AggregationService; 6 | import com.goblin.manage.service.UserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : 披荆斩棘 12 | * @date : 2018/1/5 13 | */ 14 | @Service 15 | public class AggregationServiceImpl implements AggregationService { 16 | 17 | @Autowired 18 | private UserService userService; 19 | 20 | 21 | @Override 22 | public void saveUser ( User user ) { 23 | userService.save( user ); 24 | AssertUtils.isTrue( true , "测试事务是否回滚(可传播),请查看数据库." ); 25 | } 26 | 27 | @Override 28 | public void intoUser ( User user ) { 29 | userService.save( user ); 30 | AssertUtils.isTrue( true , "测试事务是否回滚(可传播),请查看数据库." ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/CaptchaServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.service.impl; 2 | 3 | import com.goblin.cache.client.JedisClient; 4 | import com.goblin.common.GlobalConstant; 5 | import com.goblin.manage.service.CaptchaService; 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : 披荆斩棘 12 | * @date : 2017/6/27 13 | */ 14 | @Service 15 | public class CaptchaServiceImpl implements CaptchaService { 16 | @Autowired 17 | private JedisClient jedisClient; 18 | 19 | @Override 20 | public boolean set ( String captchaStoreKey, String captcha ) { 21 | return "ok".equalsIgnoreCase( 22 | jedisClient.setex( captchaStoreKey, captcha, GlobalConstant.CAPTCHA_TIME_OUT_SECOND ) 23 | ); 24 | } 25 | 26 | @Override 27 | public boolean validate ( String sessionId, String inputCaptcha ) { 28 | if ( StringUtils.isEmpty( inputCaptcha ) ) { 29 | return false; 30 | } 31 | if ( ! inputCaptcha.equalsIgnoreCase( this.jedisClient.get( sessionId ) ) ) { 32 | return false; 33 | } 34 | this.clear( sessionId ); 35 | return true; 36 | } 37 | 38 | @Override 39 | public boolean clear ( String sessionId ) { 40 | return jedisClient.del( sessionId ) > 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-service/src/main/java/com/goblin/manage/service/impl/MailSubscribeServiceImpl.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.MailSubscribe; 8 | import com.goblin.manage.mapper.MailSubscribeMapper; 9 | import com.goblin.manage.service.MailSubscribeService; 10 | import org.springframework.stereotype.Service; 11 | 12 | 13 | /** 14 | *

15 | * 邮件订阅 服务实现类 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 | 404 error 6 | 7 | 8 | 11 | 12 | 13 |

14 | 401 15 |
16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 error 6 | 7 | 8 | 11 | 12 | 13 |
14 | 404 15 |
16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 error 6 | 7 | 8 | 11 | 12 | 13 |
14 | 500 15 |
16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #f5f5f5; 3 | } 4 | 5 | #main-content { 6 | max-width: 940px; 7 | padding: 2em 3em; 8 | margin: 0 auto 20px; 9 | background-color: #fff; 10 | border: 1px solid #e5e5e5; 11 | -webkit-border-radius: 5px; 12 | -moz-border-radius: 5px; 13 | border-radius: 5px; 14 | } -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/rule/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | drools 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 |
23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/rule/js/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/rule/js/main.js -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/rule/js/plugins.js: -------------------------------------------------------------------------------- 1 | // Avoid `console` errors in browsers that lack a console. 2 | (function() { 3 | var method; 4 | var noop = function () {}; 5 | var methods = [ 6 | 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 7 | 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 8 | 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 9 | 'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn' 10 | ]; 11 | var length = methods.length; 12 | var console = (window.console = window.console || {}); 13 | 14 | while (length--) { 15 | method = methods[length]; 16 | 17 | // Only stub undefined methods. 18 | if (!console[method]) { 19 | console[method] = noop; 20 | } 21 | } 22 | }()); 23 | 24 | // Place any jQuery/helper plugins in here. 25 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/main/resources/static/success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Success 6 | 7 | 8 |

Success

9 | 10 | 11 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/AggregationServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import com.goblin.manage.bean.domain.User; 4 | import com.goblin.manage.service.AggregationService; 5 | import org.apache.commons.lang3.RandomStringUtils; 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.security.crypto.password.PasswordEncoder; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | /** 14 | * @author : 披荆斩棘 15 | * @date : 2017/12/28 16 | */ 17 | @RunWith( SpringRunner.class ) 18 | @SpringBootTest 19 | public class AggregationServiceTest { 20 | 21 | @Autowired 22 | private AggregationService aggregationService; 23 | 24 | @Autowired 25 | private PasswordEncoder passwordEncoder; 26 | 27 | @Test 28 | public void saveUser () throws Exception { 29 | User user = new User(); 30 | final String username = "admin" + RandomStringUtils.randomNumeric( 3 ); 31 | user.setEmail( "yujunhao_8831@yahoo.com" ) 32 | .setNickName( "披荆斩棘" ) 33 | .setUsername( username ) 34 | .setEnabled( true ) 35 | .setPassword( passwordEncoder.encode( "123456" ) ); 36 | aggregationService.saveUser( user ); 37 | 38 | System.err.println( "username = " + username ); 39 | 40 | } 41 | 42 | @Test 43 | public void intoUser () throws Exception { 44 | User user = new User(); 45 | final String username = "admin" + RandomStringUtils.randomNumeric( 3 ); 46 | user.setEmail( "yujunhao_8831@yahoo.com" ) 47 | .setNickName( "披荆斩棘" ) 48 | .setUsername( username ) 49 | .setEnabled( true ) 50 | .setPassword( passwordEncoder.encode( "123456" ) ); 51 | aggregationService.intoUser( user ); 52 | 53 | System.err.println( "username = " + username ); 54 | 55 | } 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/PasswordEncoderTest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import org.junit.Test; 4 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 5 | import org.springframework.security.crypto.password.PasswordEncoder; 6 | 7 | /** 8 | * @author : 披荆斩棘 9 | * @date : 2017/12/28 10 | */ 11 | public class PasswordEncoderTest { 12 | 13 | @Test 14 | public void name () throws Exception { 15 | PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); 16 | 17 | 18 | for ( int i = 0 ; i < 10 ; i++ ) { 19 | System.err.println( passwordEncoder.encode( "123456" ) ); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/UserServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage; 2 | 3 | import com.goblin.common.util.JsonUtils; 4 | import com.goblin.manage.bean.domain.User; 5 | import com.goblin.manage.service.UserService; 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.security.crypto.password.PasswordEncoder; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | /** 14 | * @author : 披荆斩棘 15 | * @date : 2017/12/28 16 | */ 17 | @RunWith( SpringRunner.class ) 18 | @SpringBootTest 19 | public class UserServiceTest { 20 | 21 | @Autowired 22 | private UserService userService; 23 | 24 | @Autowired 25 | private PasswordEncoder passwordEncoder; 26 | 27 | @Test 28 | public void save () throws Exception { 29 | User user = new User(); 30 | user.setEmail( "yujunhao_8831@yahoo.com" ) 31 | .setNickName( "披荆斩棘" ) 32 | .setUsername( "admin" ) 33 | .setEnabled( true ) 34 | .setPassword( passwordEncoder.encode( "admin" ) ); 35 | userService.save( user ); 36 | 37 | } 38 | 39 | @Test 40 | public void name() { 41 | final User admin = userService.findByUsername("admin"); 42 | 43 | System.err.println(admin); 44 | 45 | JsonUtils.toJson(admin); 46 | 47 | } 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /goblin-manage-system/goblin-manage-system-webapp/src/test/java/com/goblin/manage/encrypted/JasyptStringEncryptorTest.java: -------------------------------------------------------------------------------- 1 | package com.goblin.manage.encrypted; 2 | 3 | 4 | import org.jasypt.encryption.StringEncryptor; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | * @author : 披荆斩棘 13 | * @date : 2018/1/4 14 | */ 15 | @RunWith( SpringRunner.class ) 16 | @SpringBootTest 17 | public class JasyptStringEncryptorTest { 18 | 19 | /** 20 | * 前提是配置文件设置了 用于加密/解密属性的主密码 21 | *
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 | 5 | 6 | goblin-parent 7 | com.goblin 8 | 0.0.1-SNAPSHOT 9 | ../goblin-parent 10 | 11 | 4.0.0 12 | 13 | goblin-manage-system 14 | pom 15 | 16 | goblin-manage-system-service 17 | goblin-manage-system-dao 18 | goblin-manage-system-bean 19 | goblin-manage-system-webapp 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /goblin-manage-system/restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo stop goblin-manage-system-webapp 3 | source stop.sh 4 | echo start goblin-manage-system-webapp 5 | source start.sh 6 | -------------------------------------------------------------------------------- /goblin-manage-system/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | nohup java -jar goblin-manage-system-webapp.jar & 3 | -------------------------------------------------------------------------------- /goblin-manage-system/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PID=$(ps -ef | grep goblin-manage-system-webapp.jar | grep -v grep | awk '{ print $2 }') 3 | if [ -z "$PID" ] 4 | then 5 | echo "服务已关闭" 6 | else 7 | echo kill $PID 8 | kill $PID 9 | fi 10 | -------------------------------------------------------------------------------- /goblin-scheduling/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 | 14 | sudo ln -s /xxx/xxx/goblin-scheduling.jar /etc/init.d/goblin-scheduling 15 | 16 | /etc/init.d/goblin-scheduling start|stop|restart 17 | -------------------------------------------------------------------------------- /goblin-scheduling/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.goblin 7 | goblin-parent 8 | 0.0.1-SNAPSHOT 9 | ../goblin-parent 10 | 11 | 4.0.0 12 | 简单分布式调度 13 | 14 | goblin-scheduling 15 | 16 | 17 | 18 | 21 | 22 | net.javacrumbs.shedlock 23 | shedlock-spring 24 | 25 | 26 | 27 | net.javacrumbs.shedlock 28 | shedlock-provider-jedis 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-data-redis 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-logging 51 | 52 | 53 | 54 | 55 | 56 | org.projectlombok 57 | lombok 58 | true 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-starter-test 64 | test 65 | 66 | 67 | 68 | de.codecentric 69 | spring-boot-admin-starter-client 70 | 71 | 72 | 73 | 74 | org.jolokia 75 | jolokia-core 76 | 77 | 78 | 79 | 80 | 81 | 82 | ${project.artifactId} 83 | 84 | 85 | 86 | org.springframework.boot 87 | spring-boot-maven-plugin 88 | 89 | com.goblin.SchedulingApplication 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /goblin-scheduling/restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo stop goblin-scheduling 3 | source stop.sh 4 | echo start goblin-scheduling 5 | source start.sh 6 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/java/com/goblin/SchedulingApplication.java: -------------------------------------------------------------------------------- 1 | package com.goblin; 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 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | /** 10 | * 对于需要部署到传统servlet容器之中的应用,Boot提供了一种方式以编码的方式初始化Web配置。 11 | * 为了使用这一点,Boot提供了可选的WebApplicationInitializer,它会使用servlet容器来 12 | * 注册应用,这会通过Servlet 3.0 API以编码的方式注册servlet并且会用到ServletContext。 13 | * 通过提供SpringBootServletInitializer的子类,Boot应用能够使用嵌入的Spring上下文来 14 | * 注册配置,这个Spring上下文是在容器初始化的时候创建的。 15 | * @author pijingzhanji 16 | */ 17 | @SpringBootApplication 18 | @EnableScheduling 19 | public class SchedulingApplication extends SpringBootServletInitializer { 20 | 21 | public static void main ( String[] args ) { 22 | SpringApplication.run( SchedulingApplication.class, args ); 23 | } 24 | 25 | /** 26 | * Application类中被重写的configure方法就是使用嵌入式的Spring上下文注册应用的地方。 27 | * 在更为正式的场景之中,这个方法可能会用来注册Spring Java配置类,它会定义应用中所有 28 | * controller和服务的bean。 29 | * 30 | * @param application 31 | * @see info 32 | */ 33 | @Override 34 | protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) { 35 | return application.sources( SchedulingApplication.class ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/java/com/goblin/config/BeanConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import net.javacrumbs.shedlock.core.LockProvider; 4 | import net.javacrumbs.shedlock.provider.redis.jedis.JedisLockProvider; 5 | import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration; 6 | import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import redis.clients.jedis.JedisPool; 10 | 11 | import java.time.Duration; 12 | 13 | /** 14 | * @author : 披荆斩棘 15 | * @date : 2017/6/22 16 | */ 17 | @Configuration 18 | public class BeanConfig { 19 | 20 | 21 | /** 22 | * 配置锁 23 | * 24 | * @param jedisPool 25 | * @return 26 | */ 27 | @Bean 28 | public LockProvider lockProvider ( JedisPool jedisPool ) { 29 | return new JedisLockProvider( jedisPool, "goblin-scheduling" ); 30 | } 31 | 32 | 33 | /** 34 | * 计划任务分布式锁配置,保证在多个实例下,任务只在一台机器上运行. 35 | * 36 | * @param lockProvider 37 | * @return 38 | */ 39 | @Bean 40 | public ScheduledLockConfiguration taskScheduler ( LockProvider lockProvider ) { 41 | return ScheduledLockConfigurationBuilder 42 | .withLockProvider( lockProvider ) 43 | .withPoolSize( 30 ) 44 | .withDefaultLockAtMostFor( Duration.ofHours( 24 ) ) 45 | .build(); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/java/com/goblin/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.config; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import redis.clients.jedis.JedisPool; 10 | import redis.clients.jedis.JedisPoolConfig; 11 | 12 | /** 13 | * @author : 披荆斩棘 14 | * @date : 2017/5/15 15 | */ 16 | @Getter 17 | @Setter 18 | @ToString 19 | @Configuration 20 | @ConfigurationProperties( prefix = "redis" ) 21 | public class RedisConfig { 22 | 23 | private String host; 24 | private Integer port; 25 | private Integer timeout; 26 | 27 | 28 | @Bean 29 | public JedisPoolConfig jedisPoolConfig () { 30 | return new JedisPoolConfig(); 31 | } 32 | 33 | @Bean 34 | public JedisPool jedisPool () { 35 | return new JedisPool( jedisPoolConfig(), host, port, timeout ); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /goblin-scheduling/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 | * @author : 披荆斩棘 14 | * @date : 2017/5/24 15 | */ 16 | @Configuration 17 | @EnableAsync 18 | public class ThreadPoolConfig implements AsyncConfigurer { 19 | 20 | @Override 21 | public Executor getAsyncExecutor () { 22 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 23 | executor.setCorePoolSize( Runtime.getRuntime().availableProcessors() ); 24 | executor.setMaxPoolSize( Runtime.getRuntime().availableProcessors() * 5 ); 25 | executor.setQueueCapacity( Runtime.getRuntime().availableProcessors() * 2 ); 26 | executor.setThreadNamePrefix( "goblin-executor-" ); 27 | executor.initialize(); 28 | return executor; 29 | } 30 | 31 | @Override 32 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler () { 33 | return new SimpleAsyncUncaughtExceptionHandler(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/java/com/goblin/scheduling/DemoTask.java: -------------------------------------------------------------------------------- 1 | package com.goblin.scheduling; 2 | 3 | import net.javacrumbs.shedlock.core.SchedulerLock; 4 | import org.springframework.context.EnvironmentAware; 5 | import org.springframework.core.env.Environment; 6 | import org.springframework.scheduling.annotation.Scheduled; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.context.support.StandardServletEnvironment; 9 | 10 | /** 11 | * 这里是利用分布式锁实现了,不同机器上,同时只运行一个任务 12 | * 13 | * @author : 披荆斩棘 14 | * @date : 2017/7/1 15 | */ 16 | @Component 17 | public class DemoTask implements EnvironmentAware { 18 | 19 | private StandardServletEnvironment environment; 20 | 21 | @Scheduled( cron = "*/3 * * * * *" ) 22 | @SchedulerLock( name = "DemoTask" ) 23 | public void test () { 24 | System.err.println( environment.getPropertySources() 25 | .get( "server.ports" ) 26 | .getSource() + " : DemoTask test run " ); 27 | } 28 | 29 | @Override 30 | public void setEnvironment ( Environment environment ) { 31 | this.environment = ( StandardServletEnvironment ) environment; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | # 服务器 2 | server: 3 | port: 8081 4 | 5 | # 日志 6 | logging: 7 | config: classpath:log4j2.xml 8 | 9 | redis: 10 | host: 127.0.0.1 11 | port: 6379 12 | timeout: 60 13 | 14 | spring: 15 | # spring boot admin 监控 start 16 | boot: 17 | admin: 18 | client: 19 | enabled: true 20 | url: http://localhost:8888 21 | management: 22 | endpoints: 23 | web: 24 | exposure: 25 | include: "*" 26 | # spring boot admin 监控 end 27 | 28 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/goblin-scheduling/src/main/resources/application-prod.yml -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/application-test.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/goblin-scheduling/src/main/resources/application-test.yml -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | # 多环境配置文件 3 | profiles: 4 | active: dev 5 | 6 | # AOP 7 | aop: 8 | proxy-target-class: true 9 | auto: true 10 | application: 11 | name: goblin-scheduling 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/log4j2-production.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ${sys:user.home} 6 | 7 | 100 MB 8 | 9 | goblin-scheduling 10 | DEBUG 11 | 12 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 31 | 32 | %X %d{yyyy-MM-dd HH:mm:ss SSS} [%p] [%t] %c.%M(%L) | %m%n 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /goblin-scheduling/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | ${sys:user.home} 21 | 22 | 100 MB 23 | 24 | goblin-scheduling 25 | DEBUG 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 46 | 47 | %X %d{yyyy-MM-dd HH:mm:ss SSS} [%p] [%t] %c.%M(%L) | %m%n 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /goblin-scheduling/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | nohup java -jar goblin-scheduling.jar --spring.profiles.active=prod & 3 | -------------------------------------------------------------------------------- /goblin-scheduling/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PID=$(ps -ef | grep goblin-scheduling.jar | grep -v grep | awk '{ print $2 }') 3 | if [ -z "$PID" ] 4 | then 5 | echo "服务已关闭" 6 | else 7 | echo kill $PID 8 | kill $PID 9 | fi 10 | -------------------------------------------------------------------------------- /goblin-security/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | goblin-parent 7 | com.goblin 8 | 0.0.1-SNAPSHOT 9 | ../goblin-parent 10 | 11 | 12 | 4.0.0 13 | 14 | goblin-security 15 | 16 | 17 | 18 | 19 | 20 | 21 | ${project.groupId} 22 | goblin-common 23 | provided 24 | 25 | 26 | 27 | com.github.pagehelper 28 | pagehelper-spring-boot-starter 29 | provided 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-security 35 | provided 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-websocket 40 | provided 41 | 42 | 43 | 44 | 45 | io.jsonwebtoken 46 | jjwt 47 | provided 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | provided 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-web 67 | provided 68 | 69 | 70 | 71 | com.baomidou 72 | mybatis-plus-boot-starter 73 | provided 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /goblin-security/src/main/java/com/goblin/security/BasicJwtUser.java: -------------------------------------------------------------------------------- 1 | package com.goblin.security; 2 | 3 | import org.springframework.security.core.userdetails.UserDetails; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * @author : 披荆斩棘 10 | * @date : 2017/7/3 11 | */ 12 | public interface BasicJwtUser extends UserDetails { 13 | 14 | /** 15 | * 主键 16 | * 17 | * @return id 18 | */ 19 | Serializable getId (); 20 | 21 | /** 22 | * 密码最后重置(修改)日期 23 | * 24 | * @return Date 25 | */ 26 | Date getLastPasswordResetDate (); 27 | } 28 | -------------------------------------------------------------------------------- /goblin-security/src/main/java/com/goblin/security/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.goblin.security; 2 | 3 | import com.goblin.common.ResponseEntityPro; 4 | import com.goblin.common.util.JsonUtils; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.web.AuthenticationEntryPoint; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | import java.io.Serializable; 14 | import java.nio.charset.StandardCharsets; 15 | 16 | /** 17 | * {@link AuthenticationEntryPoint} 拒绝所有请求与未经授权的错误消息。 18 | * 19 | * @author pijingzhanji 20 | */ 21 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable { 22 | 23 | @Override 24 | public void commence ( HttpServletRequest request , 25 | HttpServletResponse response , 26 | AuthenticationException authException ) throws IOException { 27 | response.setHeader( "Content-type" , MediaType.APPLICATION_JSON_UTF8_VALUE ); 28 | response.setCharacterEncoding( StandardCharsets.UTF_8.displayName() ); 29 | try ( PrintWriter out = response.getWriter() ) { 30 | out.print( JsonUtils.toCustomizationJson( ResponseEntityPro.unauthorized( "未经授权:身份验证令牌丢失或无效。" ) ) ); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /goblin-security/src/main/java/com/goblin/security/config/SpringWebSocketSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.goblin.security.config; 2 | 3 | import com.goblin.security.websocket.JwtWebSocketInterceptorAdapter; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.messaging.support.ChannelInterceptor; 7 | 8 | /** 9 | * @author : 披荆斩棘 10 | * @date : 2017/6/8 11 | */ 12 | @Configuration 13 | public class SpringWebSocketSecurityConfig { 14 | 15 | @Bean 16 | public ChannelInterceptor channelInterceptor () { 17 | return new JwtWebSocketInterceptorAdapter(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /resources/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/resources/1.png -------------------------------------------------------------------------------- /resources/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/resources/2.png -------------------------------------------------------------------------------- /resources/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yujunhao8831/spring-boot-start-current/b0d7656e35f77df65de80ad788d613c11283d9f7/resources/3.png --------------------------------------------------------------------------------