├── monitor ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── jxph │ │ └── cloud │ │ └── monitor │ │ └── MonitorApplication.java └── pom.xml ├── eureka-server ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ └── main │ │ ├── resources │ │ ├── application-dev.properties │ │ ├── application.properties │ │ └── application-cluster.properties │ │ └── java │ │ └── com │ │ └── jxph │ │ └── cloud │ │ └── eureka │ │ └── EurekaServerApplication.java └── pom.xml ├── api-gateway ├── src │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── application-dev.properties │ │ └── application-cluster.properties │ │ └── java │ │ └── com │ │ └── jxph │ │ └── cloud │ │ └── api │ │ ├── ApiGatewayApplication.java │ │ ├── config │ │ ├── FilterConfig.java │ │ └── HystrixMonitor.java │ │ ├── utils │ │ ├── LimitResponseDecorate.java │ │ └── ClientHttpResponseUtils.java │ │ ├── provider │ │ ├── AuthFallbackProvider.java │ │ └── FastFallbackProvider.java │ │ └── filter │ │ ├── RateLimitZuulFilter.java │ │ ├── DefaultFilter.java │ │ └── FastRateLimitZuulFilter.java └── pom.xml ├── service ├── fast │ ├── fast-server │ │ ├── .mvn │ │ │ └── wrapper │ │ │ │ ├── maven-wrapper.jar │ │ │ │ └── maven-wrapper.properties │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.properties │ │ │ │ ├── application-dev.properties │ │ │ │ ├── application-cluster.properties │ │ │ │ ├── logback.xml │ │ │ │ └── mybatis-generator.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jxph │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── fast │ │ │ │ └── server │ │ │ │ ├── task │ │ │ │ ├── job │ │ │ │ │ ├── TaskJob.java │ │ │ │ │ ├── TaskSaveManagerInfoJob.java │ │ │ │ │ ├── TestJob.java │ │ │ │ │ ├── RetryMessageJob.java │ │ │ │ │ └── CouponJob.java │ │ │ │ ├── manager │ │ │ │ │ ├── TaskFactory.java │ │ │ │ │ ├── TaskManagerFactory.java │ │ │ │ │ ├── TaskManagerService.java │ │ │ │ │ ├── DefaultManagerTask.java │ │ │ │ │ ├── AbstractManagerTask.java │ │ │ │ │ └── SaveInfoManagerTask.java │ │ │ │ ├── RetryMessageTask.java │ │ │ │ └── CouponTask.java │ │ │ │ ├── feign │ │ │ │ ├── TestFeignClientWithFactory.java │ │ │ │ ├── TestFeignClient.java │ │ │ │ └── TestFacadeFallbackFactory.java │ │ │ │ ├── service │ │ │ │ ├── TestService.java │ │ │ │ ├── TaskManagerService.java │ │ │ │ ├── OrderService.java │ │ │ │ ├── BrokerMessageLogService.java │ │ │ │ ├── CouponTaskService.java │ │ │ │ └── impl │ │ │ │ │ ├── TestServiceImpl.java │ │ │ │ │ ├── TaskManagerServiceImpl.java │ │ │ │ │ ├── CouponTaskServiceImpl.java │ │ │ │ │ ├── BrokerMessageLogServiceImpl.java │ │ │ │ │ └── OrderServiceImpl.java │ │ │ │ ├── config │ │ │ │ ├── datasource │ │ │ │ │ ├── DataSourceConstant.java │ │ │ │ │ ├── annotation │ │ │ │ │ │ └── DataSource.java │ │ │ │ │ ├── DataSourceContextHolder.java │ │ │ │ │ ├── DynamicDataSource.java │ │ │ │ │ ├── aspect │ │ │ │ │ │ └── DataSourceAspect.java │ │ │ │ │ ├── DataSourceConfig.java │ │ │ │ │ └── MybatisConfig.java │ │ │ │ ├── CorsConfig.java │ │ │ │ ├── HystrixConfig.java │ │ │ │ ├── TaskExecutePool.java │ │ │ │ ├── InterceptorConfig.java │ │ │ │ ├── SchedulerConfig.java │ │ │ │ └── SwaggerConfig.java │ │ │ │ ├── common │ │ │ │ ├── constant │ │ │ │ │ ├── RedisKeyConstant.java │ │ │ │ │ ├── TaskManagerLogStatusConstant.java │ │ │ │ │ └── CouponTaskJobStatusConstant.java │ │ │ │ └── exception │ │ │ │ │ └── ExceptionHandlerAdvice.java │ │ │ │ ├── controller │ │ │ │ ├── TestFeignController.java │ │ │ │ └── OrderController.java │ │ │ │ ├── dao │ │ │ │ ├── TOrderMapper.java │ │ │ │ ├── CouponTaskJobMapper.java │ │ │ │ ├── TaskManagerLogMapper.java │ │ │ │ └── BrokerMessageLogMapper.java │ │ │ │ ├── FastServerApplication.java │ │ │ │ ├── mq │ │ │ │ ├── OrderReceiver.java │ │ │ │ └── OrderSender.java │ │ │ │ └── hystrix │ │ │ │ └── UserCommand.java │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jxph │ │ │ └── cloud │ │ │ └── service │ │ │ └── fast │ │ │ └── server │ │ │ └── ServerApplicationTests.java │ ├── fast-api │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jxph │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── fast │ │ │ │ └── api │ │ │ │ ├── common │ │ │ │ └── constant │ │ │ │ │ ├── TaskManagerLogStatusConstant.java │ │ │ │ │ └── CouponTaskJobStatusConstant.java │ │ │ │ ├── form │ │ │ │ └── TestForm.java │ │ │ │ ├── facade │ │ │ │ ├── TestFeignFacade.java │ │ │ │ └── OrderFacade.java │ │ │ │ └── pojo │ │ │ │ ├── TOrder.java │ │ │ │ ├── TaskManagerLog.java │ │ │ │ ├── BrokerMessageLog.java │ │ │ │ └── CouponTaskJob.java │ │ └── pom.xml │ └── pom.xml ├── auth │ ├── auth-server │ │ ├── src │ │ │ ├── main │ │ │ │ ├── resources │ │ │ │ │ ├── application.properties │ │ │ │ │ ├── application-dev.properties │ │ │ │ │ ├── application-cluster.properties │ │ │ │ │ ├── logback.xml │ │ │ │ │ └── mybatis-generator.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── jxph │ │ │ │ │ └── cloud │ │ │ │ │ └── service │ │ │ │ │ └── auth │ │ │ │ │ └── server │ │ │ │ │ ├── service │ │ │ │ │ ├── LoginService.java │ │ │ │ │ ├── UserService.java │ │ │ │ │ └── impl │ │ │ │ │ │ ├── LoginServiceImpl.java │ │ │ │ │ │ └── UserServiceImpl.java │ │ │ │ │ ├── config │ │ │ │ │ ├── datasource │ │ │ │ │ │ ├── DataSourceConstant.java │ │ │ │ │ │ ├── annotation │ │ │ │ │ │ │ └── DataSource.java │ │ │ │ │ │ ├── DataSourceContextHolder.java │ │ │ │ │ │ ├── DynamicDataSource.java │ │ │ │ │ │ ├── aspect │ │ │ │ │ │ │ └── DataSourceAspect.java │ │ │ │ │ │ └── DataSourceConfig.java │ │ │ │ │ ├── CorsConfig.java │ │ │ │ │ ├── InterceptorConfig.java │ │ │ │ │ ├── SchedulerConfig.java │ │ │ │ │ ├── HystrixConfig.java │ │ │ │ │ └── SwaggerConfig.java │ │ │ │ │ ├── common │ │ │ │ │ ├── constant │ │ │ │ │ │ └── RedisConstant.java │ │ │ │ │ ├── utils │ │ │ │ │ │ └── MD5Helper.java │ │ │ │ │ └── exception │ │ │ │ │ │ └── ExceptionHandlerAdvice.java │ │ │ │ │ ├── dao │ │ │ │ │ └── SysUserMapper.java │ │ │ │ │ ├── AuthServerApplication.java │ │ │ │ │ └── controller │ │ │ │ │ ├── TestController.java │ │ │ │ │ ├── UserController.java │ │ │ │ │ └── LoginController.java │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jxph │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── auth │ │ │ │ └── server │ │ │ │ └── AuthApplicationTests.java │ │ └── pom.xml │ ├── auth-api │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jxph │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── auth │ │ │ │ └── api │ │ │ │ ├── common │ │ │ │ ├── constant │ │ │ │ │ └── RedisKeyConstant.java │ │ │ │ └── enums │ │ │ │ │ └── SysUserStatusEnums.java │ │ │ │ ├── facade │ │ │ │ ├── TestFacade.java │ │ │ │ ├── UserFacade.java │ │ │ │ └── LoginFacade.java │ │ │ │ ├── form │ │ │ │ └── LoginForm.java │ │ │ │ └── pojo │ │ │ │ └── SysUser.java │ │ └── pom.xml │ ├── auth-client │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jxph │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── auth │ │ │ │ └── client │ │ │ │ ├── runner │ │ │ │ ├── annotation │ │ │ │ │ ├── EnableDruidClient.java │ │ │ │ │ ├── EnableRedisClient.java │ │ │ │ │ └── EnableCommonUtilsClient.java │ │ │ │ ├── SpringContextUtils.java │ │ │ │ ├── DistributedLock.java │ │ │ │ ├── RedisConfig.java │ │ │ │ ├── IpConfig.java │ │ │ │ ├── DruidConfig.java │ │ │ │ └── JwtHelper.java │ │ │ │ ├── EnableAuthClient.java │ │ │ │ └── interceptor │ │ │ │ └── AuthorizationInterceptor.java │ │ └── pom.xml │ └── pom.xml └── pom.xml ├── common ├── src │ └── main │ │ └── java │ │ └── com │ │ └── jxph │ │ └── cloud │ │ └── common │ │ ├── constant │ │ ├── BrokerMessageTryCountConstant.java │ │ ├── UserConstant.java │ │ └── BrokerMessageStatusConstant.java │ │ ├── annotation │ │ └── Login.java │ │ ├── validator │ │ └── flag │ │ │ ├── FlagValidatorAnnotation.java │ │ │ └── FlagValidator.java │ │ ├── xss │ │ ├── XssFilter.java │ │ ├── SQLFilter.java │ │ └── XssHttpServletRequestWrapper.java │ │ ├── exception │ │ ├── UserInvalidException.java │ │ ├── AuthorizationException.java │ │ └── BaseException.java │ │ ├── enums │ │ └── ResultCodeEnum.java │ │ ├── utils │ │ ├── HttpContextUtils.java │ │ ├── ResponseResult.java │ │ ├── IPUtils.java │ │ ├── RestUtil.java │ │ └── DateUtils.java │ │ └── context │ │ └── UserContextHolder.java └── pom.xml ├── README.md └── pom.xml /monitor/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/monitor/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /monitor/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/monitor/src/main/resources/application.properties -------------------------------------------------------------------------------- /api-gateway/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/api-gateway/src/main/resources/application.properties -------------------------------------------------------------------------------- /monitor/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /service/fast/fast-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/fast/fast-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /service/fast/fast-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/auth/auth-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/fast/fast-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/auth/auth-server/src/main/resources/application-dev.properties -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/fast/fast-server/src/main/resources/application-dev.properties -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/resources/application-cluster.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/auth/auth-server/src/main/resources/application-cluster.properties -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/resources/application-cluster.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/794147572/cloud/HEAD/service/fast/fast-server/src/main/resources/application-cluster.properties -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/common/constant/RedisKeyConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 18:51 6 | */ 7 | public interface RedisKeyConstant { 8 | } 9 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/job/TaskJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.job; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 20:03 6 | */ 7 | public interface TaskJob { 8 | void processImpl(); 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/constant/BrokerMessageTryCountConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/30 17:57 6 | */ 7 | public interface BrokerMessageTryCountConstant { 8 | int TRYCOUNT_MAX_LIMIT = 3; 9 | } 10 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/TaskFactory.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 20:29 6 | */ 7 | public interface TaskFactory { 8 | void process(); 9 | } 10 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/feign/TestFeignClientWithFactory.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.feign; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 15:24 6 | */ 7 | public interface TestFeignClientWithFactory extends TestFeignClient { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /eureka-server/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | eureka.client.serviceUrl.defaultZone=http://${eureka.server.hostname2}:${eureka.server.port2}/eureka/ 2 | eureka.client.register-with-eureka=false 3 | eureka.server.port=8761 4 | eureka.server.hostname=localhost 5 | eureka.server.hostname2=localhost 6 | eureka.server.port2=8761 7 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/job/TaskSaveManagerInfoJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.job; 2 | 3 | /** 4 | * @author xqh 5 | * @date 2018/9/30 0:12 6 | */ 7 | public interface TaskSaveManagerInfoJob extends TaskJob { 8 | void setTaskManagerId(int id); 9 | } 10 | -------------------------------------------------------------------------------- /eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=${eureka.server.port} 2 | spring.application.name=eureka-server 3 | eureka.instance.hostname=${eureka.server.hostname} 4 | eureka.server.renewal-percent-threshold=0.5 5 | eureka.server.enable-self-preservation=true 6 | eureka.client.fetch-registry=true 7 | spring.profiles.active=dev 8 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/TestService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/3 20:52 8 | */ 9 | public interface TestService { 10 | ResponseResult testFeign(); 11 | } 12 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/TaskManagerFactory.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 20:30 6 | */ 7 | public interface TaskManagerFactory extends TaskFactory { 8 | void initializeManager(); 9 | void endTaskManager(); 10 | } 11 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.service; 2 | 3 | import com.jxph.cloud.service.auth.api.form.LoginForm; 4 | 5 | import javax.validation.Valid; /** 6 | * @author 谢秋豪 7 | * @date 2018/9/3 22:20 8 | */ 9 | public interface LoginService { 10 | String login(LoginForm loginForm); 11 | } 12 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.service; 2 | 3 | import com.jxph.cloud.service.auth.api.pojo.SysUser; /** 4 | * @author 谢秋豪 5 | * @date 2018/9/3 22:05 6 | */ 7 | public interface UserService { 8 | Long addUser(SysUser sysUser); 9 | 10 | SysUser getUserByUserId(Long userId); 11 | } 12 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/DataSourceConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/31 23:30 6 | */ 7 | public interface DataSourceConstant { 8 | String DATASOURCE_NAME_FIRST = "dataSourceFirst"; 9 | String DATASOURCE_NAME_SECOND = "dataSourceSecond"; 10 | } 11 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/common/constant/TaskManagerLogStatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 20:58 6 | */ 7 | public interface TaskManagerLogStatusConstant { 8 | int TASK_MANAGER_START = 0; 9 | int TASK_MANAGER_SUCCESS = 1; 10 | int TASK_MANAGER_FAILURE =2; 11 | } 12 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/DataSourceConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/31 23:30 6 | */ 7 | public interface DataSourceConstant { 8 | String DATASOURCE_NAME_FIRST = "dataSourceFirst"; 9 | String DATASOURCE_NAME_SECOND = "dataSourceSecond"; 10 | } 11 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/TaskManagerService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TaskManagerLog; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/8 15:54 8 | */ 9 | public interface TaskManagerService extends com.jxph.cloud.service.fast.server.task.manager.TaskManagerService { 10 | } 11 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 12:30 6 | */ 7 | public interface UserConstant { 8 | String CONTEXT_KEY_USER_ID = "userId"; 9 | String CONTEXT_KEY_USERNAME = "userName"; 10 | String CONTEXT_KEY_USER_NAME = "name"; 11 | String CONTEXT_KEY_USER_IS_LOGIN = "isLogin"; 12 | } 13 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/common/constant/CouponTaskJobStatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 22:24 6 | */ 7 | public interface CouponTaskJobStatusConstant { 8 | int JOB_CREATION = 0; 9 | int JOB_EXECUTION = 1; 10 | int JOB_SUCCESS = 2; 11 | int JOB_FAILURE = 3 ; 12 | } 13 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/common/constant/RedisKeyConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 18:51 6 | */ 7 | public interface RedisKeyConstant { 8 | String RETRY_MESSAGE_KEY = "FAST:SCHEDULER:RETRY:MESSAGE:KEY"; 9 | String COUPON_JOB_KEY = "FAST:SCHEDULER:COUPON:JOB:KEY"; 10 | } 11 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/common/constant/TaskManagerLogStatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 20:58 6 | */ 7 | public interface TaskManagerLogStatusConstant { 8 | int TASK_MANAGER_START = 0; 9 | int TASK_MANAGER_SUCCESS = 1; 10 | int TASK_MANAGER_FAILURE =2; 11 | } 12 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/constant/BrokerMessageStatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/30 17:57 6 | */ 7 | public interface BrokerMessageStatusConstant { 8 | int ORDER_SENDING = 0; 9 | int ORDER_SEND_SUCCESS = 1; 10 | int ORDER_SEND_FAILURE = 2; 11 | /** 12 | * min 13 | */ 14 | int ORDER_TIMEOUT = 1; 15 | } 16 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service; 2 | 3 | 4 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 5 | 6 | /** 7 | * @author 谢秋豪 8 | * @date 2018/8/30 20:36 9 | */ 10 | public interface OrderService { 11 | void createOrder(TOrder order); 12 | 13 | void confirmMessage(String messageId); 14 | } 15 | -------------------------------------------------------------------------------- /eureka-server/src/main/resources/application-cluster.properties: -------------------------------------------------------------------------------- 1 | eureka.client.serviceUrl.defaultZone=http://${eureka.server.hostname2}:${eureka.server.port2}/eureka/ 2 | eureka.server.port=8762 3 | eureka.server.hostname=localhost 4 | eureka.server.hostname2=localhost 5 | eureka.server.port2=8761 6 | 7 | #eureka.server.port=8761 8 | #eureka.server.hostname=localhost 9 | #eureka.server.hostname2=localhost 10 | #eureka.server.port2=8762 -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/common/constant/CouponTaskJobStatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/2 22:24 6 | */ 7 | public interface CouponTaskJobStatusConstant { 8 | int JOB_CREATION = 0; 9 | int JOB_EXECUTION = 1; 10 | int JOB_SUCCESS = 2; 11 | int JOB_FAILURE = 3 ; 12 | } 13 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/job/TestJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.job; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/8 15:18 8 | */ 9 | @Component 10 | public class TestJob implements TaskJob { 11 | @Override 12 | public void processImpl() { 13 | System.out.println("错误"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/TaskManagerService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TaskManagerLog; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/28 20:04 8 | */ 9 | public interface TaskManagerService { 10 | Integer createTaskManager(); 11 | void updateTaskMangerToSuccess(Integer taskManagerId); 12 | } 13 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/annotation/Login.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.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 | * @author 谢秋豪 10 | * @date 2018/9/1 11:54 11 | */ 12 | @Target(ElementType.METHOD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface Login { 15 | } 16 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/feign/TestFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.feign; 2 | 3 | import com.jxph.cloud.service.auth.api.facade.TestFacade; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @author 谢秋豪 8 | * @date 2018/9/2 12:52 9 | */ 10 | @FeignClient(value="auth", fallbackFactory = TestFacadeFallbackFactory.class) 11 | public interface TestFeignClient extends TestFacade { 12 | } 13 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/common/constant/RedisConstant.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.common.constant; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 18:51 6 | */ 7 | public interface RedisConstant { 8 | String REDIS_SESSION = "AUTH:SESSION:"; 9 | int REDIS_SESSION_EXPIRE = 1800; 10 | String REIDS_USER_PREFIX = "AUTH:USER:"; 11 | int REDIS_USER_EXPIRE = 1800; 12 | int REDIS_USER_NULL_EXPIRE = 100; 13 | } 14 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/test/java/com/jxph/cloud/service/auth/server/AuthApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 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 AuthApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/common/enums/SysUserStatusEnums.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.common.enums; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/3 22:43 6 | */ 7 | public enum SysUserStatusEnums { 8 | DISABLE((byte)1), 9 | NORMAL((byte)0); 10 | 11 | private Byte status; 12 | 13 | SysUserStatusEnums(Byte status) { 14 | this.status = status; 15 | } 16 | 17 | public Byte getStatus() { 18 | return status; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /api-gateway/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zuul-gateway 2 | # 3 | eureka.client.serviceUrl.defaultZone=http://${eureka.server.hostname}:${eureka.server.port}/eureka/ 4 | 5 | 6 | #zuul.prefix=/v1 7 | zuul.routes.fast.path=/fast/** 8 | zuul.routes.fast.serviceId=fast 9 | zuul.routes.auth.path=/auth/** 10 | zuul.routes.auth.serviceId=auth 11 | 12 | #spring.sleuth.sampler.percentage=1 13 | #spring.zipkin.baseUrl=http://localhost:9411 14 | eureka.server.hostname=localhost 15 | eureka.server.port=8761 16 | zuul.server.port=8080 -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/form/TestForm.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.form; 2 | 3 | import com.jxph.cloud.common.validator.flag.FlagValidatorAnnotation; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/1 16:08 8 | */ 9 | public class TestForm { 10 | @FlagValidatorAnnotation(values = "1,2,3") 11 | private String flag; 12 | 13 | public String getFlag() { 14 | return flag; 15 | } 16 | 17 | public void setFlag(String flag) { 18 | this.flag = flag; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##cloud 2 | 整合SpringBoot 2.0.4、SpringCloud(Finchley.SR1)、MyBatis、Redis、RabbitMQ的代码脚手架
3 | 4 | 目前主要分为common(通用)、api-gateway(网关)、eureka(注册中心)、monitor(监控)、service(服务)模块
5 | 服务模块分为auth、fast模块,auth模块分为api、client、server模块,client模块是公共启动项的抽取,fast分为api、server模块 6 | 7 | ##基本组件/功能 8 | 9 | * Jwt加密解密 10 | * eureka注册中心 11 | * hystrix熔断与降级 12 | * feign服务调用 13 | * zuul网关 14 | * redis集群缓存 15 | * rabbitMQ,实现消息100%投递 16 | * turbine、actuator监控 17 | * scheduled+redis分布式锁 18 | * 注解方式动态切换数据源 19 | 20 | ##服务启动 21 | 修改auth.server与fast.server模块中的application-dev.properties文件,修改文件中rabbitmq和redis的配置 22 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/facade/TestFeignFacade.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.facade; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/3 20:50 10 | */ 11 | @RequestMapping("/test") 12 | public interface TestFeignFacade { 13 | @RequestMapping(value= "/test",method = RequestMethod.GET) 14 | ResponseResult testFeign(); 15 | } 16 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/annotation/EnableDruidClient.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner.annotation; 2 | 3 | import com.jxph.cloud.service.auth.client.runner.DruidConfig; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/3 20:21 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Import({DruidConfig.class}) 15 | @Documented 16 | @Inherited 17 | public @interface EnableDruidClient { 18 | } 19 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/annotation/DataSource.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource.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 | * @author 谢秋豪 10 | * @date 2018/8/31 23:38 11 | */ 12 | @Target(ElementType.METHOD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface DataSource { 15 | String value() default "dataSourceFirst"; 16 | } 17 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/annotation/DataSource.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource.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 | * @author 谢秋豪 10 | * @date 2018/8/31 23:38 11 | */ 12 | @Target(ElementType.METHOD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface DataSource { 15 | String value() default "dataSourceFirst"; 16 | } 17 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/BrokerMessageLogService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/8 23:28 10 | */ 11 | public interface BrokerMessageLogService { 12 | List selectSendMessage(); 13 | 14 | void updateBrokerMessageLogTryCount(BrokerMessageLog brokerMessageLog); 15 | 16 | void updateBrokerMessageLogStatusToFail(BrokerMessageLog brokerMessageLog); 17 | } 18 | -------------------------------------------------------------------------------- /eureka-server/src/main/java/com/jxph/cloud/eureka/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaServer 10 | public class EurekaServerApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(EurekaServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/EnableAuthClient.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client; 2 | 3 | 4 | import com.jxph.cloud.service.auth.client.runner.*; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import java.lang.annotation.*; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/3 14:40 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Import({DruidConfig.class, IpConfig.class, JwtHelper.class, RedisConfig.class, DistributedLock.class,SpringContextUtils.class}) 16 | @Documented 17 | @Inherited 18 | public @interface EnableAuthClient { 19 | } 20 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/CouponTaskService.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJob; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/8 16:05 10 | */ 11 | public interface CouponTaskService { 12 | /** 13 | * 查找状态为已创建的couponJob 14 | */ 15 | List selectCreationCouponJob(); 16 | 17 | void updateCouponTask(CouponTaskJob couponTaskJob, int status); 18 | 19 | void updateCouponTask(CouponTaskJob couponTaskJob, int status, String remark); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api-gateway/src/main/resources/application-cluster.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zuul-gateway 2 | # 3 | eureka.client.serviceUrl.defaultZone=http://${eureka.server.hostname}:${eureka.server.port}/eureka/,${eureka.server.hostname2}:${eureka.server.port2}/eureka/ 4 | 5 | #zuul.prefix=/v1 6 | zuul.routes.fast.path=/fast/** 7 | zuul.routes.fast.serviceId=fast 8 | zuul.routes.auth.path=/auth/** 9 | zuul.routes.auth.serviceId=auth 10 | 11 | #spring.sleuth.sampler.percentage=1 12 | #spring.zipkin.baseUrl=http://localhost:9411 13 | eureka.server.hostname=localhost 14 | eureka.server.port=8761 15 | eureka.server.hostname2=localhost 16 | eureka.server.port2=8762 17 | zuul.server.port=8080 -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/annotation/EnableRedisClient.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner.annotation; 2 | 3 | import com.jxph.cloud.service.auth.client.runner.DistributedLock; 4 | import com.jxph.cloud.service.auth.client.runner.RedisConfig; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import java.lang.annotation.*; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/3 20:21 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Import({RedisConfig.class, DistributedLock.class}) 16 | @Documented 17 | @Inherited 18 | public @interface EnableRedisClient { 19 | } 20 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/facade/OrderFacade.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.facade; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/3 20:44 12 | */ 13 | @RequestMapping("/orders") 14 | public interface OrderFacade { 15 | 16 | @PostMapping("") 17 | ResponseResult createOrder(@RequestBody TOrder tOrder); 18 | } 19 | -------------------------------------------------------------------------------- /monitor/src/main/java/com/jxph/cloud/monitor/MonitorApplication.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.monitor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 7 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 8 | 9 | @SpringBootApplication 10 | @EnableTurbine 11 | @EnableHystrixDashboard 12 | public class MonitorApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(MonitorApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/facade/TestFacade.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.facade; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestHeader; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/2 12:50 11 | */ 12 | @RequestMapping("/test") 13 | public interface TestFacade { 14 | @GetMapping("") 15 | ResponseResult testFeign(); 16 | @GetMapping("/token") 17 | ResponseResult token(@RequestHeader("token")String token); 18 | } 19 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/DataSourceContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/31 23:25 6 | */ 7 | public class DataSourceContextHolder { 8 | private static final ThreadLocal contextHolder = new ThreadLocal<>(); 9 | 10 | public static void setDataSource(String dataSource){ 11 | contextHolder.set(dataSource); 12 | } 13 | 14 | public static String getDataSource(){ 15 | return contextHolder.get(); 16 | } 17 | 18 | public static void clearDataSource(){ 19 | contextHolder.remove(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/DataSourceContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/31 23:25 6 | */ 7 | public class DataSourceContextHolder { 8 | private static final ThreadLocal contextHolder = new ThreadLocal<>(); 9 | 10 | public static void setDataSource(String dataSource){ 11 | contextHolder.set(dataSource); 12 | } 13 | 14 | public static String getDataSource(){ 15 | return contextHolder.get(); 16 | } 17 | 18 | public static void clearDataSource(){ 19 | contextHolder.remove(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/validator/flag/FlagValidatorAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.validator.flag; 2 | 3 | 4 | import javax.validation.Constraint; 5 | import javax.validation.Payload; 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/1 15:38 11 | */ 12 | @Target({ElementType.PARAMETER, ElementType.FIELD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Constraint(validatedBy = FlagValidator.class) 15 | @Documented 16 | public @interface FlagValidatorAnnotation { 17 | String values(); 18 | 19 | String message() default "状态不存在"; 20 | 21 | Class[] groups() default {}; 22 | 23 | Class[] payload() default {}; 24 | } 25 | -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/facade/UserFacade.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.facade; 2 | 3 | 4 | import com.jxph.cloud.common.utils.ResponseResult; 5 | import com.jxph.cloud.service.auth.api.pojo.SysUser; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/2 11:13 11 | */ 12 | @RequestMapping("/users") 13 | public interface UserFacade { 14 | @RequestMapping(value = "/{id}",method = RequestMethod.GET) 15 | ResponseResult getUser(@PathVariable(name="id") Long userId, @RequestHeader("token") String token); 16 | 17 | @PostMapping(value = "") 18 | ResponseResult addUser(@RequestBody SysUser sysUser); 19 | } 20 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/annotation/EnableCommonUtilsClient.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner.annotation; 2 | 3 | import com.jxph.cloud.service.auth.client.runner.IpConfig; 4 | import com.jxph.cloud.service.auth.client.runner.JwtHelper; 5 | import com.jxph.cloud.service.auth.client.runner.SpringContextUtils; 6 | import org.springframework.context.annotation.Import; 7 | 8 | import java.lang.annotation.*; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/9/3 20:21 13 | */ 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Import({IpConfig.class, JwtHelper.class, SpringContextUtils.class}) 17 | @Documented 18 | @Inherited 19 | public @interface EnableCommonUtilsClient { 20 | } 21 | -------------------------------------------------------------------------------- /service/auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jxph.cloud.service 7 | auth 8 | 1.0-SNAPSHOT 9 | 10 | auth-api 11 | auth-server 12 | auth-client 13 | 14 | pom 15 | 16 | auth 17 | 18 | 19 | com.jxph.cloud 20 | service 21 | 1.0-SNAPSHOT 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/facade/LoginFacade.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.facade; 2 | 3 | 4 | import com.jxph.cloud.common.utils.ResponseResult; 5 | import com.jxph.cloud.service.auth.api.form.LoginForm; 6 | import org.springframework.validation.BindingResult; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.validation.Valid; 11 | 12 | /** 13 | * @author 谢秋豪 14 | * @date 2018/9/2 11:10 15 | */ 16 | @RequestMapping("/sessions") 17 | public interface LoginFacade { 18 | /** 19 | * @LoginForm 20 | * @ResponseResult 21 | */ 22 | @PostMapping() 23 | ResponseResult login(@Valid @RequestBody LoginForm loginForm, HttpServletResponse response); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /service/fast/fast-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | fast 8 | com.jxph.cloud.service 9 | 1.0-SNAPSHOT 10 | 11 | com.jxph.cloud.service.fast 12 | fast-api 13 | fast-api 14 | 15 | 16 | 17 | com.jxph.cloud 18 | common 19 | 1.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /service/fast/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jxph.cloud.service 7 | fast 8 | 1.0-SNAPSHOT 9 | pom 10 | 11 | fast 12 | 13 | com.jxph.cloud 14 | service 15 | 1.0-SNAPSHOT 16 | 17 | 18 | 19 | fast-api 20 | fast-server 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/DefaultManagerTask.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | import com.jxph.cloud.service.fast.server.service.TaskManagerService; 4 | import com.jxph.cloud.service.fast.server.task.job.TaskJob; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/1 20:16 10 | */ 11 | @Slf4j 12 | public class DefaultManagerTask extends AbstractManagerTask { 13 | public DefaultManagerTask(TaskJob taskJob) { 14 | super(taskJob); 15 | } 16 | 17 | @Override 18 | public void initializeManager() { 19 | log.info("-----定时任务开始------"); 20 | } 21 | 22 | @Override 23 | public void endTaskManager() { 24 | log.info("-----定时任务结束------"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/8/18 23:41 10 | */ 11 | @Configuration 12 | public class CorsConfig implements WebMvcConfigurer { 13 | 14 | @Override 15 | public void addCorsMappings(CorsRegistry registry) { 16 | registry.addMapping("/**") 17 | .allowedOrigins("*") 18 | .allowCredentials(true) 19 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 20 | .maxAge(3600); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/8/18 23:41 10 | */ 11 | @Configuration 12 | public class CorsConfig implements WebMvcConfigurer { 13 | 14 | @Override 15 | public void addCorsMappings(CorsRegistry registry) { 16 | registry.addMapping("/**") 17 | .allowedOrigins("*") 18 | .allowCredentials(true) 19 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 20 | .maxAge(3600); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/ApiGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/31 15:28 13 | */ 14 | @SpringBootApplication 15 | @EnableDiscoveryClient 16 | @EnableZuulProxy 17 | public class ApiGatewayApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(ApiGatewayApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/xss/XssFilter.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.xss; 2 | 3 | import javax.servlet.*; 4 | import javax.servlet.http.HttpServletRequest; 5 | import java.io.IOException; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/8/18 23:38 10 | */ 11 | public class XssFilter implements Filter { 12 | 13 | @Override 14 | public void init(FilterConfig config) throws ServletException { 15 | } 16 | 17 | @Override 18 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 19 | throws IOException, ServletException { 20 | XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper( 21 | (HttpServletRequest) request); 22 | chain.doFilter(xssRequest, response); 23 | } 24 | 25 | @Override 26 | public void destroy() { 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/exception/UserInvalidException.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.exception; 2 | 3 | import com.jxph.cloud.common.enums.ResultCodeEnum; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/3 22:23 8 | */ 9 | public class UserInvalidException extends BaseException { 10 | 11 | private String msg; 12 | private int code = ResultCodeEnum.DATA_IS_WRONG.getCode(); 13 | 14 | public UserInvalidException(String msg) { 15 | super(msg); 16 | } 17 | 18 | @Override 19 | public String getMsg() { 20 | return msg; 21 | } 22 | 23 | @Override 24 | public void setMsg(String msg) { 25 | this.msg = msg; 26 | } 27 | 28 | @Override 29 | public int getCode() { 30 | return code; 31 | } 32 | 33 | @Override 34 | public void setCode(int code) { 35 | this.code = code; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /service/auth/auth-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auth 7 | com.jxph.cloud.service 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | com.jxph.cloud.service.auth 12 | auth-api 13 | auth-api 14 | 15 | 16 | 17 | com.jxph.cloud 18 | common 19 | 1.0-SNAPSHOT 20 | 21 | 22 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/config/FilterConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.config; 2 | 3 | import com.jxph.cloud.api.filter.DefaultFilter; 4 | import com.jxph.cloud.api.filter.FastRateLimitZuulFilter; 5 | import com.jxph.cloud.api.filter.RateLimitZuulFilter; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/1 22:16 12 | */ 13 | @Configuration 14 | public class FilterConfig { 15 | @Bean 16 | public DefaultFilter fastFilter(){ 17 | return new DefaultFilter(); 18 | } 19 | @Bean 20 | public RateLimitZuulFilter rateLimitZuulFilter(){ 21 | return new RateLimitZuulFilter(); 22 | } 23 | @Bean 24 | public FastRateLimitZuulFilter fastRateLimitZuulFilter(){ 25 | return new FastRateLimitZuulFilter(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/utils/LimitResponseDecorate.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.utils; 2 | 3 | import com.netflix.zuul.context.RequestContext; 4 | import com.netflix.zuul.exception.ZuulException; 5 | import org.springframework.http.HttpStatus; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/2 16:45 10 | */ 11 | public class LimitResponseDecorate { 12 | public static void failResponse(RequestContext currentContext) throws ZuulException { 13 | currentContext.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value()); 14 | currentContext.setResponseBody("请求过多,发生中断"); 15 | currentContext.setSendZuulResponse(false); 16 | currentContext.set("route", false); 17 | throw new ZuulException(HttpStatus.TOO_MANY_REQUESTS.getReasonPhrase(), 18 | HttpStatus.TOO_MANY_REQUESTS.value(), HttpStatus.TOO_MANY_REQUESTS.getReasonPhrase()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/AbstractManagerTask.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | import com.jxph.cloud.service.fast.server.task.job.TaskJob; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | /** 7 | * @author 谢秋豪 8 | * @date 2018/9/1 19:55 9 | */ 10 | @Slf4j 11 | public abstract class AbstractManagerTask implements TaskManagerFactory { 12 | private T taskJob; 13 | 14 | public T getTaskJob() { 15 | return taskJob; 16 | } 17 | 18 | public void setTaskJob(T taskJob) { 19 | this.taskJob = taskJob; 20 | } 21 | 22 | public AbstractManagerTask(T taskJob) { 23 | this.taskJob = taskJob; 24 | } 25 | 26 | @Override 27 | public void process(){ 28 | initializeManager(); 29 | taskJob.processImpl(); 30 | endTaskManager(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/controller/TestFeignController.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.controller; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | 5 | import com.jxph.cloud.service.fast.api.facade.TestFeignFacade; 6 | import com.jxph.cloud.service.fast.server.feign.TestFeignClient; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/9/2 12:53 13 | */ 14 | @RestController 15 | public class TestFeignController implements TestFeignFacade { 16 | @Autowired 17 | private TestFeignClient testFeignClient; 18 | 19 | @Override 20 | public ResponseResult testFeign(){ 21 | //.... 业务代码 22 | ResponseResult result = testFeignClient.testFeign(); 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/enums/ResultCodeEnum.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.enums; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/9/1 14:50 6 | */ 7 | public enum ResultCodeEnum { 8 | SUCCESS(200), 9 | FAILURE(500), 10 | // -------------------失败状态码---------------------- 11 | // 参数错误 12 | // 参数为空 13 | PARAMS_IS_NULL(10001), 14 | // 参数不全 15 | PARAMS_NOT_COMPLETE(10002), 16 | // 参数类型错误 17 | PARAMS_TYPE_ERROR(10003), 18 | // 参数无效 19 | PARAMS_IS_INVALID(10004), 20 | // 系统业务出现问题 21 | BUSINESS_ERROR(30001), 22 | //--------- 数据错误---------- 23 | // 数据未找到 24 | DATA_NOT_FOUND(50001), 25 | // 数据有误 26 | DATA_IS_WRONG(50002), 27 | // 数据已存在 28 | DATA_ALREADY_EXISTED(50003); 29 | private int code; 30 | 31 | ResultCodeEnum(int code) { 32 | this.code = code; 33 | } 34 | 35 | public int getCode() { 36 | return code; 37 | } 38 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/HystrixConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/1 20:54 10 | */ 11 | @Configuration 12 | public class HystrixConfig { 13 | @Bean 14 | public HystrixCommandAspect hystrixCommandAspect(){ 15 | return new HystrixCommandAspect(); 16 | } 17 | 18 | /*@Bean 19 | public ServletRegistrationBean hystrixMetricsStreamServlet(){ 20 | ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(new HystrixMetricsStreamServlet()); 21 | registrationBean.addUrlMappings("/hystrix.stream"); 22 | return registrationBean; 23 | }*/ 24 | } 25 | 26 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 5 | import org.springframework.lang.Nullable; 6 | 7 | import javax.sql.DataSource; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/31 23:16 13 | */ 14 | @Slf4j 15 | public class DynamicDataSource extends AbstractRoutingDataSource { 16 | public DynamicDataSource(DataSource defaultDataSource, Map map){ 17 | super.setDefaultTargetDataSource(defaultDataSource); 18 | super.setTargetDataSources(map); 19 | super.afterPropertiesSet(); 20 | } 21 | 22 | @Nullable 23 | @Override 24 | protected Object determineCurrentLookupKey() { 25 | return DataSourceContextHolder.getDataSource(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 5 | import org.springframework.lang.Nullable; 6 | 7 | import javax.sql.DataSource; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/31 23:16 13 | */ 14 | @Slf4j 15 | public class DynamicDataSource extends AbstractRoutingDataSource { 16 | public DynamicDataSource(DataSource defaultDataSource, Map map){ 17 | super.setDefaultTargetDataSource(defaultDataSource); 18 | super.setTargetDataSources(map); 19 | super.afterPropertiesSet(); 20 | } 21 | 22 | @Nullable 23 | @Override 24 | protected Object determineCurrentLookupKey() { 25 | return DataSourceContextHolder.getDataSource(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/TaskExecutePool.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/3 0:22 12 | */ 13 | @Configuration 14 | public class TaskExecutePool { 15 | @Bean(name="myTaskExecutePool") 16 | public Executor taskExecutePool(){ 17 | ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); 18 | threadPoolTaskExecutor.setCorePoolSize(40); 19 | threadPoolTaskExecutor.setMaxPoolSize(100); 20 | threadPoolTaskExecutor.setKeepAliveSeconds(300); 21 | threadPoolTaskExecutor.setQueueCapacity(50); 22 | return threadPoolTaskExecutor; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/feign/TestFacadeFallbackFactory.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.feign; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import feign.hystrix.FallbackFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/9/2 0:59 10 | */ 11 | @Component 12 | public class TestFacadeFallbackFactory implements FallbackFactory{ 13 | 14 | @Override 15 | public TestFeignClient create(Throwable throwable) { 16 | return new TestFeignClientWithFactory() { 17 | @Override 18 | public ResponseResult testFeign() { 19 | return ResponseResult.error("test 降级"); 20 | } 21 | 22 | @Override 23 | public ResponseResult token(String token) { 24 | return ResponseResult.error("test 降级"); 25 | } 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/provider/AuthFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.provider; 2 | 3 | import com.jxph.cloud.api.utils.ClientHttpResponseUtils; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 7 | import org.springframework.http.client.ClientHttpResponse; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/9/4 11:46 13 | */ 14 | @Slf4j 15 | @Component 16 | public class AuthFallbackProvider implements FallbackProvider { 17 | @Value("${zuul.routes.auth.serviceId}") 18 | private String auth; 19 | 20 | @Override 21 | public String getRoute() { 22 | return auth; 23 | } 24 | 25 | @Override 26 | public ClientHttpResponse fallbackResponse(String route, Throwable cause) { 27 | return ClientHttpResponseUtils.newFallBackClientHttpResponse(route,cause); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/validator/flag/FlagValidator.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.validator.flag; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | /** 7 | * @author 谢秋豪 8 | * @date 2018/9/1 16:02 9 | */ 10 | public class FlagValidator implements ConstraintValidator { 11 | private String values; 12 | 13 | @Override 14 | public void initialize(FlagValidatorAnnotation constraintAnnotation) { 15 | this.values = constraintAnnotation.values(); 16 | } 17 | 18 | @Override 19 | public boolean isValid(String o, ConstraintValidatorContext constraintValidatorContext) { 20 | String[] str = values.split(","); 21 | boolean flag = false; 22 | for (int i = 0; i < str.length; i++) { 23 | if (str[i].equals(values)) { 24 | flag = true; 25 | break; 26 | } 27 | } 28 | return flag; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/form/LoginForm.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.form; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import javax.validation.constraints.NotBlank; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/1 15:27 11 | */ 12 | @ApiModel(value = "登录表单") 13 | public class LoginForm { 14 | @ApiModelProperty(value = "手机号") 15 | @NotBlank(message="手机号不能为空") 16 | private String username; 17 | 18 | @ApiModelProperty(value = "密码") 19 | @NotBlank(message="密码不能为空") 20 | private String password; 21 | 22 | public String getUsername() { 23 | return username; 24 | } 25 | 26 | public void setUsername(String username) { 27 | this.username = username; 28 | } 29 | 30 | public String getPassword() { 31 | return password; 32 | } 33 | 34 | public void setPassword(String password) { 35 | this.password = password; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/InterceptorConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config; 2 | 3 | 4 | import com.jxph.cloud.service.auth.client.interceptor.AuthorizationInterceptor; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/18 23:01 13 | */ 14 | @Configuration 15 | public class InterceptorConfig implements WebMvcConfigurer { 16 | 17 | @Override 18 | public void addInterceptors(InterceptorRegistry registry) { 19 | registry.addInterceptor(authorizationInterceptor()).addPathPatterns("/**"); 20 | } 21 | 22 | @Bean 23 | public AuthorizationInterceptor authorizationInterceptor() { 24 | return new AuthorizationInterceptor(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/InterceptorConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | 4 | import com.jxph.cloud.service.auth.client.interceptor.AuthorizationInterceptor; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/18 23:01 13 | */ 14 | @Configuration 15 | public class InterceptorConfig implements WebMvcConfigurer { 16 | 17 | @Override 18 | public void addInterceptors(InterceptorRegistry registry) { 19 | registry.addInterceptor(authorizationInterceptor()).addPathPatterns("/**"); 20 | } 21 | 22 | @Bean 23 | public AuthorizationInterceptor authorizationInterceptor() { 24 | return new AuthorizationInterceptor(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/utils/HttpContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.utils; 2 | 3 | import org.springframework.web.context.request.RequestContextHolder; 4 | import org.springframework.web.context.request.ServletRequestAttributes; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/8/18 23:28 11 | */ 12 | public class HttpContextUtils { 13 | 14 | public static HttpServletRequest getHttpServletRequest() { 15 | return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 16 | } 17 | 18 | public static String getDomain(){ 19 | HttpServletRequest request = getHttpServletRequest(); 20 | StringBuffer url = request.getRequestURL(); 21 | return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); 22 | } 23 | 24 | public static String getOrigin(){ 25 | HttpServletRequest request = getHttpServletRequest(); 26 | return request.getHeader("Origin"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/dao/TOrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.dao; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 4 | import com.jxph.cloud.service.fast.api.pojo.TOrderExample; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | public interface TOrderMapper { 10 | long countByExample(TOrderExample example); 11 | 12 | int deleteByExample(TOrderExample example); 13 | 14 | int deleteByPrimaryKey(String id); 15 | 16 | int insert(TOrder record); 17 | 18 | int insertSelective(TOrder record); 19 | 20 | List selectByExample(TOrderExample example); 21 | 22 | TOrder selectByPrimaryKey(String id); 23 | 24 | int updateByExampleSelective(@Param("record") TOrder record, @Param("example") TOrderExample example); 25 | 26 | int updateByExample(@Param("record") TOrder record, @Param("example") TOrderExample example); 27 | 28 | int updateByPrimaryKeySelective(TOrder record); 29 | 30 | int updateByPrimaryKey(TOrder record); 31 | } -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/dao/SysUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.dao; 2 | 3 | import com.jxph.cloud.service.auth.api.pojo.SysUser; 4 | import com.jxph.cloud.service.auth.api.pojo.SysUserExample; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | public interface SysUserMapper { 10 | long countByExample(SysUserExample example); 11 | 12 | int deleteByExample(SysUserExample example); 13 | 14 | int deleteByPrimaryKey(Long userId); 15 | 16 | int insert(SysUser record); 17 | 18 | int insertSelective(SysUser record); 19 | 20 | List selectByExample(SysUserExample example); 21 | 22 | SysUser selectByPrimaryKey(Long userId); 23 | 24 | int updateByExampleSelective(@Param("record") SysUser record, @Param("example") SysUserExample example); 25 | 26 | int updateByExample(@Param("record") SysUser record, @Param("example") SysUserExample example); 27 | 28 | int updateByPrimaryKeySelective(SysUser record); 29 | 30 | int updateByPrimaryKey(SysUser record); 31 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.controller; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import com.jxph.cloud.service.fast.api.facade.OrderFacade; 5 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 6 | import com.jxph.cloud.service.fast.server.service.OrderService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/3 20:46 16 | */ 17 | @RestController 18 | @Api("订单接口") 19 | public class OrderController implements OrderFacade { 20 | @Autowired 21 | private OrderService orderService; 22 | 23 | @Override 24 | @ApiOperation("测试创建订单") 25 | public ResponseResult createOrder(@RequestBody TOrder tOrder) { 26 | orderService.createOrder(tOrder); 27 | return ResponseResult.ok(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/AuthServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server; 2 | 3 | import com.jxph.cloud.service.auth.client.EnableAuthClient; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 9 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 10 | import org.springframework.cloud.openfeign.EnableFeignClients; 11 | 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | @EnableFeignClients 18 | @EnableSwagger2 19 | @EnableHystrixDashboard 20 | @EnableHystrix 21 | @MapperScan(value = "com.jxph.cloud.service.auth.server.dao") 22 | @EnableAuthClient 23 | public class AuthServerApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(AuthServerApplication.class, args); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/dao/CouponTaskJobMapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.dao; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJob; 4 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJobExample; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | public interface CouponTaskJobMapper { 10 | long countByExample(CouponTaskJobExample example); 11 | 12 | int deleteByExample(CouponTaskJobExample example); 13 | 14 | int deleteByPrimaryKey(Integer id); 15 | 16 | int insert(CouponTaskJob record); 17 | 18 | int insertSelective(CouponTaskJob record); 19 | 20 | List selectByExample(CouponTaskJobExample example); 21 | 22 | CouponTaskJob selectByPrimaryKey(Integer id); 23 | 24 | int updateByExampleSelective(@Param("record") CouponTaskJob record, @Param("example") CouponTaskJobExample example); 25 | 26 | int updateByExample(@Param("record") CouponTaskJob record, @Param("example") CouponTaskJobExample example); 27 | 28 | int updateByPrimaryKeySelective(CouponTaskJob record); 29 | 30 | int updateByPrimaryKey(CouponTaskJob record); 31 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/dao/TaskManagerLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.dao; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TaskManagerLog; 4 | import com.jxph.cloud.service.fast.api.pojo.TaskManagerLogExample; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | public interface TaskManagerLogMapper { 10 | long countByExample(TaskManagerLogExample example); 11 | 12 | int deleteByExample(TaskManagerLogExample example); 13 | 14 | int deleteByPrimaryKey(Integer id); 15 | 16 | int insert(TaskManagerLog record); 17 | 18 | int insertSelective(TaskManagerLog record); 19 | 20 | List selectByExample(TaskManagerLogExample example); 21 | 22 | TaskManagerLog selectByPrimaryKey(Integer id); 23 | 24 | int updateByExampleSelective(@Param("record") TaskManagerLog record, @Param("example") TaskManagerLogExample example); 25 | 26 | int updateByExample(@Param("record") TaskManagerLog record, @Param("example") TaskManagerLogExample example); 27 | 28 | int updateByPrimaryKeySelective(TaskManagerLog record); 29 | 30 | int updateByPrimaryKey(TaskManagerLog record); 31 | } -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.controller; 2 | 3 | import com.jxph.cloud.common.annotation.Login; 4 | import com.jxph.cloud.common.context.UserContextHolder; 5 | import com.jxph.cloud.common.utils.ResponseResult; 6 | import com.jxph.cloud.service.auth.api.facade.TestFacade; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiModel; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.web.bind.annotation.RequestHeader; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/2 12:51 16 | */ 17 | @RestController 18 | @Api("测试接口") 19 | public class TestController implements TestFacade { 20 | @Override 21 | public ResponseResult testFeign() { 22 | return ResponseResult.ok("feign 调用成功"); 23 | } 24 | 25 | @Override 26 | @Login 27 | @ApiOperation("测试登录成功") 28 | public ResponseResult token(@RequestHeader("token")String token) { 29 | String userName = UserContextHolder.getUserName(); 30 | return ResponseResult.ok(userName); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/xss/SQLFilter.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.xss; 2 | 3 | 4 | import com.jxph.cloud.common.exception.BaseException; 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | /** 8 | * @author 谢秋豪 9 | * @date 2018/8/18 23:36 10 | */ 11 | public class SQLFilter { 12 | 13 | /** 14 | * SQL注入过滤 15 | * @param str 待验证的字符串 16 | */ 17 | public static String sqlInject(String str){ 18 | if(StringUtils.isBlank(str)){ 19 | return null; 20 | } 21 | //去掉'|"|;|\字符 22 | str = StringUtils.replace(str, "'", ""); 23 | str = StringUtils.replace(str, "\"", ""); 24 | str = StringUtils.replace(str, ";", ""); 25 | str = StringUtils.replace(str, "\\", ""); 26 | 27 | //转换成小写 28 | str = str.toLowerCase(); 29 | 30 | //非法字符 31 | String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop"}; 32 | 33 | //判断是否包含非法字符 34 | for(String keyword : keywords){ 35 | if(str.indexOf(keyword) != -1){ 36 | throw new BaseException("包含非法字符"); 37 | } 38 | } 39 | 40 | return str; 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/config/HystrixMonitor.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.config; 2 | 3 | import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect; 4 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 5 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * @author 谢秋豪 11 | * @date 2018/9/1 23:38 12 | */ 13 | @Configuration 14 | public class HystrixMonitor { 15 | @Bean 16 | public HystrixCommandAspect hystrixCommandAspect() { 17 | return new HystrixCommandAspect(); 18 | } 19 | 20 | @Bean 21 | public ServletRegistrationBean getServlet() { 22 | HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 23 | ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(streamServlet); 24 | registrationBean.setLoadOnStartup(1); 25 | registrationBean.addUrlMappings("/hystrix.stream"); 26 | registrationBean.setName("HystrixMetricsStreamServlet"); 27 | return registrationBean; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${name} 5 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | logs/infisa.${name}.log 13 | 14 | logs/${name}.%d{yyyy-MM-dd}.log 15 | 16 | 17 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/pojo/TOrder.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.pojo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.io.Serializable; 7 | 8 | @ApiModel(value = "订单") 9 | public class TOrder implements Serializable { 10 | private static final long serialVersionUID = 6694440593947361863L; 11 | @ApiModelProperty(value = "订单编号") 12 | private String id; 13 | 14 | @ApiModelProperty(value = "订单内容") 15 | private String name; 16 | 17 | @ApiModelProperty(value = "消息编号") 18 | private String messageId; 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id == null ? null : id.trim(); 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name == null ? null : name.trim(); 34 | } 35 | 36 | public String getMessageId() { 37 | return messageId; 38 | } 39 | 40 | public void setMessageId(String messageId) { 41 | this.messageId = messageId == null ? null : messageId.trim(); 42 | } 43 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${name} 5 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | logs/infisa.${name}.log 13 | 14 | logs/${name}.%d{yyyy-MM-dd}.log 15 | 16 | 17 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jxph.cloud 7 | eureka-server 8 | 1.0.0-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | 13 | com.jxph.cloud 14 | root 15 | 1.0-SNAPSHOT 16 | 17 | 18 | 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-netflix-eureka-server 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-actuator 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-maven-plugin 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/dao/BrokerMessageLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.dao; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 4 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLogExample; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | public interface BrokerMessageLogMapper { 10 | long countByExample(BrokerMessageLogExample example); 11 | 12 | int deleteByExample(BrokerMessageLogExample example); 13 | 14 | int deleteByPrimaryKey(String messageId); 15 | 16 | int insert(BrokerMessageLog record); 17 | 18 | int insertSelective(BrokerMessageLog record); 19 | 20 | List selectByExample(BrokerMessageLogExample example); 21 | 22 | BrokerMessageLog selectByPrimaryKey(String messageId); 23 | 24 | int updateByExampleSelective(@Param("record") BrokerMessageLog record, @Param("example") BrokerMessageLogExample example); 25 | 26 | int updateByExample(@Param("record") BrokerMessageLog record, @Param("example") BrokerMessageLogExample example); 27 | 28 | int updateByPrimaryKeySelective(BrokerMessageLog record); 29 | 30 | int updateByPrimaryKey(BrokerMessageLog record); 31 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/impl/TestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service.impl; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import com.jxph.cloud.service.fast.server.config.datasource.DataSourceConstant; 5 | import com.jxph.cloud.service.fast.server.config.datasource.DataSourceContextHolder; 6 | import com.jxph.cloud.service.fast.server.config.datasource.annotation.DataSource; 7 | import com.jxph.cloud.service.fast.server.feign.TestFeignClient; 8 | import com.jxph.cloud.service.fast.server.service.TestService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/3 20:53 16 | */ 17 | @Service 18 | @Slf4j 19 | public class TestServiceImpl implements TestService { 20 | @Autowired 21 | private TestFeignClient testFeignClient; 22 | 23 | @Override 24 | @DataSource(DataSourceConstant.DATASOURCE_NAME_SECOND) 25 | public ResponseResult testFeign() { 26 | ResponseResult result = testFeignClient.testFeign(); 27 | log.info(DataSourceContextHolder.getDataSource()); 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/FastServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server; 2 | 3 | import com.jxph.cloud.service.auth.client.EnableAuthClient; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 8 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 10 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 11 | import org.springframework.cloud.openfeign.EnableFeignClients; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 15 | @EnableDiscoveryClient 16 | @EnableSwagger2 17 | @EnableCircuitBreaker 18 | @EnableHystrixDashboard 19 | @EnableFeignClients 20 | @EnableAuthClient 21 | @MapperScan(value = "com.jxph.cloud.service.fast.server.dao") 22 | public class FastServerApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(FastServerApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/exception/AuthorizationException.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.exception; 2 | 3 | /** 4 | * @author 谢秋豪 5 | * @date 2018/8/18 23:37 6 | */ 7 | public class AuthorizationException extends RuntimeException { 8 | private static final long serialVersionUID = 1L; 9 | 10 | private String msg; 11 | private int code = 0401; 12 | 13 | public AuthorizationException(String msg) { 14 | super(msg); 15 | this.msg = msg; 16 | } 17 | 18 | public AuthorizationException(String msg, Throwable e) { 19 | super(msg, e); 20 | this.msg = msg; 21 | } 22 | 23 | public AuthorizationException(String msg, int code) { 24 | super(msg); 25 | this.msg = msg; 26 | this.code = code; 27 | } 28 | 29 | public AuthorizationException(String msg, int code, Throwable e) { 30 | super(msg, e); 31 | this.msg = msg; 32 | this.code = code; 33 | } 34 | 35 | public String getMsg() { 36 | return msg; 37 | } 38 | 39 | public void setMsg(String msg) { 40 | this.msg = msg; 41 | } 42 | 43 | public int getCode() { 44 | return code; 45 | } 46 | 47 | public void setCode(int code) { 48 | this.code = code; 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/provider/FastFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.provider; 2 | 3 | import com.jxph.cloud.api.utils.ClientHttpResponseUtils; 4 | import com.jxph.cloud.common.utils.JSONUtils; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 8 | import org.springframework.http.HttpHeaders; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.http.client.ClientHttpResponse; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.io.ByteArrayInputStream; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | 18 | /** 19 | * @author 谢秋豪 20 | * @date 2018/9/1 22:06 21 | */ 22 | @Slf4j 23 | @Component 24 | public class FastFallbackProvider implements FallbackProvider { 25 | @Value("${zuul.routes.fast.serviceId}") 26 | private String fast; 27 | 28 | @Override 29 | public String getRoute() { 30 | return fast; 31 | } 32 | 33 | @Override 34 | public ClientHttpResponse fallbackResponse(String route, Throwable cause) { 35 | return ClientHttpResponseUtils.newFallBackClientHttpResponse(route,cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.exception; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author 谢秋豪 7 | * @date 2018/9/1 16:19 8 | */ 9 | public class BaseException extends RuntimeException implements Serializable { 10 | 11 | private static final long serialVersionUID = -8915516558804880980L; 12 | private String msg; 13 | private int code = 0500; 14 | 15 | public BaseException(String msg) { 16 | super(msg); 17 | this.msg = msg; 18 | } 19 | 20 | public BaseException(String msg, Throwable e) { 21 | super(msg, e); 22 | this.msg = msg; 23 | } 24 | 25 | public BaseException(String msg, int code) { 26 | super(msg); 27 | this.msg = msg; 28 | this.code = code; 29 | } 30 | 31 | public BaseException(String msg, int code, Throwable e) { 32 | super(msg, e); 33 | this.msg = msg; 34 | this.code = code; 35 | } 36 | 37 | public String getMsg() { 38 | return msg; 39 | } 40 | 41 | public void setMsg(String msg) { 42 | this.msg = msg; 43 | } 44 | 45 | public int getCode() { 46 | return code; 47 | } 48 | 49 | public void setCode(int code) { 50 | this.code = code; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jxph.cloud 8 | root 9 | 1.0-SNAPSHOT 10 | pom 11 | 12 | eureka-server 13 | common 14 | service 15 | api-gateway 16 | monitor 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.0.4.RELEASE 22 | 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-dependencies 28 | Finchley.SR1 29 | pom 30 | import 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/SchedulerConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 10 | 11 | 12 | /** 13 | * @author 谢秋豪 14 | * @date 2018/9/1 0:36 15 | */ 16 | @Configuration 17 | @ConfigurationProperties(prefix = "spring.scheduler") 18 | @Data 19 | @EnableScheduling 20 | public class SchedulerConfig { 21 | private int poolSize; 22 | private String threadNamePrefix; 23 | private int awaitTerminationSeconds; 24 | private boolean waitForTasksToCompleteOnShutdown; 25 | 26 | @Bean(destroyMethod = "shutdown") 27 | 28 | public ThreadPoolTaskScheduler taskScheduler() { 29 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); 30 | scheduler.setPoolSize(100); 31 | scheduler.setThreadNamePrefix("task-"); 32 | scheduler.setAwaitTerminationSeconds(60); 33 | scheduler.setWaitForTasksToCompleteOnShutdown(true); 34 | return scheduler; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/SchedulerConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config; 2 | 3 | 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 10 | 11 | 12 | /** 13 | * @author 谢秋豪 14 | * @date 2018/9/1 0:36 15 | */ 16 | @Configuration 17 | @ConfigurationProperties(prefix = "spring.scheduler") 18 | @Data 19 | @EnableScheduling 20 | public class SchedulerConfig { 21 | private int poolSize; 22 | private String threadNamePrefix; 23 | private int awaitTerminationSeconds; 24 | private boolean waitForTasksToCompleteOnShutdown; 25 | 26 | @Bean(destroyMethod = "shutdown") 27 | 28 | public ThreadPoolTaskScheduler taskScheduler() { 29 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); 30 | scheduler.setPoolSize(100); 31 | scheduler.setThreadNamePrefix("scheduler-task-"); 32 | scheduler.setAwaitTerminationSeconds(60); 33 | scheduler.setWaitForTasksToCompleteOnShutdown(true); 34 | return scheduler; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/HystrixConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect; 5 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 6 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/9/1 20:54 13 | */ 14 | @Configuration 15 | public class HystrixConfig { 16 | @Bean 17 | public HystrixCommandAspect hystrixCommandAspect(){ 18 | return new HystrixCommandAspect(); 19 | } 20 | 21 | /* @Bean 22 | public ServletRegistrationBean hystrixMetricsStreamServlet(){ 23 | HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 24 | ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(streamServlet); 25 | registrationBean.setLoadOnStartup(1); 26 | registrationBean.addUrlMappings("/hystrix.stream"); 27 | registrationBean.setName("HystrixMetricsStreamServlet"); 28 | return registrationBean; 29 | }*/ 30 | } 31 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/manager/SaveInfoManagerTask.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.manager; 2 | 3 | import com.jxph.cloud.service.fast.server.service.TaskManagerService; 4 | import com.jxph.cloud.service.fast.server.task.job.TaskSaveManagerInfoJob; 5 | 6 | /** 7 | * @author xqh 8 | * @date 2018/9/29 23:59 9 | */ 10 | public class SaveInfoManagerTask extends AbstractManagerTask { 11 | private int taskManagerId; 12 | private TaskManagerService taskManagerService; 13 | 14 | public SaveInfoManagerTask(TaskSaveManagerInfoJob taskJob, TaskManagerService taskManagerService) { 15 | super(taskJob); 16 | this.taskManagerService = taskManagerService; 17 | } 18 | 19 | public int getTaskManagerId() { 20 | return taskManagerId; 21 | } 22 | 23 | private void setTaskManagerId(int taskManagerId) { 24 | this.taskManagerId = taskManagerId; 25 | } 26 | 27 | 28 | @Override 29 | public void initializeManager() { 30 | Integer taskManagerId = taskManagerService.createTaskManager(); 31 | setTaskManagerId(taskManagerId); 32 | getTaskJob().setTaskManagerId(taskManagerId); 33 | } 34 | 35 | @Override 36 | public void endTaskManager() { 37 | taskManagerService.updateTaskMangerToSuccess(getTaskManagerId()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/mq/OrderReceiver.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.mq; 2 | 3 | 4 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 5 | import com.rabbitmq.client.Channel; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.amqp.rabbit.annotation.*; 8 | import org.springframework.amqp.support.AmqpHeaders; 9 | import org.springframework.messaging.handler.annotation.Headers; 10 | import org.springframework.messaging.handler.annotation.Payload; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.Map; 14 | 15 | /** 16 | * @author 谢秋豪 17 | * @date 2018/8/30 15:24 18 | */ 19 | @Component 20 | @Slf4j 21 | public class OrderReceiver { 22 | 23 | @RabbitHandler() 24 | @RabbitListener(bindings = @QueueBinding( 25 | value = @Queue(value = "order-queue", durable = "true"), 26 | exchange = @Exchange(name = "order-exchange", durable = "true", type = "topic"), 27 | key = "order.*" 28 | )) 29 | public void onOrderMessage(@Payload TOrder order, @Headers Map headers, Channel channel) throws Exception { 30 | //消费者操作 31 | channel.basicQos(1); 32 | log.info("收到消息开始消费,订单编号:{}",order.getId()); 33 | Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG); 34 | channel.basicAck(deliveryTag, false); 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/test/java/com/jxph/cloud/service/fast/server/ServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 4 | import com.jxph.cloud.service.fast.server.service.OrderService; 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.data.redis.core.RedisTemplate; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import java.util.UUID; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class ServerApplicationTests { 18 | 19 | @Test 20 | public void contextLoads() { 21 | } 22 | @Autowired 23 | private OrderService orderService; 24 | 25 | @Test 26 | public void testCreateOrder() throws Exception{ 27 | TOrder order = new TOrder(); 28 | order.setId("201808300000003"); 29 | order.setName("测试"); 30 | order.setMessageId(System.currentTimeMillis()+"$"+ UUID.randomUUID().toString()); 31 | orderService.createOrder(order); 32 | } 33 | @Autowired 34 | private RedisTemplate redisTemplate; 35 | 36 | @Test 37 | public void testRedis(){ 38 | redisTemplate.opsForValue().set("test","test",60, TimeUnit.SECONDS); 39 | Object test = redisTemplate.opsForValue().get("test"); 40 | System.out.println(test); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.controller; 2 | 3 | import com.jxph.cloud.common.annotation.Login; 4 | import com.jxph.cloud.common.utils.ResponseResult; 5 | import com.jxph.cloud.service.auth.api.facade.UserFacade; 6 | import com.jxph.cloud.service.auth.api.pojo.SysUser; 7 | import com.jxph.cloud.service.auth.server.service.UserService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.validation.Valid; 14 | 15 | /** 16 | * @author 谢秋豪 17 | * @date 2018/9/3 21:59 18 | */ 19 | @Api("用户接口") 20 | @RestController 21 | public class UserController implements UserFacade { 22 | @Autowired 23 | private UserService userSerice; 24 | 25 | @Override 26 | @ApiOperation("获取某个用户") 27 | @Login 28 | public ResponseResult getUser(@PathVariable(name="id") Long userId, @RequestHeader("token") String token) { 29 | SysUser sysUser = userSerice.getUserByUserId(userId); 30 | return ResponseResult.ok(sysUser); 31 | } 32 | 33 | @Override 34 | @ApiOperation("新增用户") 35 | public ResponseResult addUser(@RequestBody @Valid SysUser sysUser) { 36 | Long id = userSerice.addUser(sysUser); 37 | return ResponseResult.ok(id); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/hystrix/UserCommand.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.hystrix;/* 2 | package com.jxph.cloud.service.fast.hystrix; 3 | 4 | import com.netflix.hystrix.*; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.net.URL; 9 | 10 | */ 11 | /** 12 | * @author 谢秋豪 13 | * @date 2018/9/2 0:45 14 | *//* 15 | 16 | @Slf4j 17 | @Component 18 | public class UserCommand extends HystrixCommand { 19 | protected UserCommand() { 20 | super( 21 | Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("userGroup")) 22 | .andCommandKey(HystrixCommandKey.Factory.asKey("userCommandKey")) 23 | .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("userThreadPool")) 24 | .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()) 25 | .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(20)) 26 | ); 27 | } 28 | 29 | @Override 30 | protected String run() throws Exception { 31 | log.info("userCommand start"); 32 | URL url = new URL("http://localhost:8001/test"); 33 | byte[] result = new byte[1024]; 34 | url.openStream().read(result); 35 | return new String(result); 36 | } 37 | 38 | @Override 39 | protected String getFallback() { 40 | return "服务降级,暂时不可用"; 41 | } 42 | } 43 | */ 44 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/context/UserContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.context; 2 | 3 | import com.jxph.cloud.common.constant.UserConstant; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/1 12:25 11 | */ 12 | public class UserContextHolder { 13 | public static ThreadLocal> threadLocal = new ThreadLocal<>(); 14 | 15 | public static void set(String key, Object value) { 16 | Map map = threadLocal.get(); 17 | if(map==null){ 18 | map = new HashMap<>(); 19 | threadLocal.set(map); 20 | } 21 | map.put(key, value); 22 | } 23 | 24 | public static Object get(String key) { 25 | Map map = threadLocal.get(); 26 | return map.get(key); 27 | } 28 | 29 | public static void remove() { 30 | threadLocal.remove(); 31 | } 32 | 33 | public static String getUserId() { 34 | return returnStringValue(get(UserConstant.CONTEXT_KEY_USER_ID)); 35 | } 36 | 37 | public static String getUserName() { 38 | return returnStringValue(get(UserConstant.CONTEXT_KEY_USERNAME)); 39 | } 40 | 41 | public static String getName() { 42 | return returnStringValue(get(UserConstant.CONTEXT_KEY_USER_NAME)); 43 | } 44 | 45 | private static String returnStringValue(Object value) { 46 | return value == null ? null : value.toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/filter/RateLimitZuulFilter.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.filter; 2 | 3 | import com.google.common.util.concurrent.RateLimiter; 4 | import com.jxph.cloud.api.utils.LimitResponseDecorate; 5 | import com.netflix.zuul.ZuulFilter; 6 | import com.netflix.zuul.context.RequestContext; 7 | import com.netflix.zuul.exception.ZuulException; 8 | import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; 9 | import org.springframework.core.Ordered; 10 | import org.springframework.http.HttpStatus; 11 | 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/9/2 16:08 17 | */ 18 | public class RateLimitZuulFilter extends ZuulFilter { 19 | private final RateLimiter rateLimiter = RateLimiter.create(1000); 20 | 21 | 22 | @Override 23 | public String filterType() { 24 | return FilterConstants.PRE_TYPE; 25 | } 26 | 27 | @Override 28 | public int filterOrder() { 29 | return Ordered.HIGHEST_PRECEDENCE; 30 | } 31 | 32 | /** 33 | * 不开启限流设置为false 34 | */ 35 | @Override 36 | public boolean shouldFilter() { 37 | return true; 38 | } 39 | 40 | @Override 41 | public Object run() throws ZuulException { 42 | RequestContext currentContext = RequestContext.getCurrentContext(); 43 | if (!rateLimiter.tryAcquire()) { 44 | LimitResponseDecorate.failResponse(currentContext); 45 | } 46 | return null; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/SpringContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/8/18 23:25 11 | */ 12 | @Component 13 | public class SpringContextUtils implements ApplicationContextAware { 14 | public static ApplicationContext applicationContext; 15 | 16 | @Override 17 | public void setApplicationContext(ApplicationContext applicationContext) 18 | throws BeansException { 19 | SpringContextUtils.applicationContext = applicationContext; 20 | } 21 | 22 | public static Object getBean(String name) { 23 | return applicationContext.getBean(name); 24 | } 25 | 26 | public static T getBean(String name, Class requiredType) { 27 | return applicationContext.getBean(name, requiredType); 28 | } 29 | 30 | public static boolean containsBean(String name) { 31 | return applicationContext.containsBean(name); 32 | } 33 | 34 | public static boolean isSingleton(String name) { 35 | return applicationContext.isSingleton(name); 36 | } 37 | 38 | public static Class getType(String name) { 39 | return applicationContext.getType(name); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | root 7 | com.jxph.cloud 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.jxph.cloud 13 | service 14 | pom 15 | 16 | 17 | fast 18 | auth 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | io.springfox 32 | springfox-swagger2 33 | 2.5.0 34 | 35 | 36 | 37 | io.springfox 38 | springfox-swagger-ui 39 | 2.5.0 40 | 41 | 42 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config; 2 | 3 | import io.swagger.annotations.ApiOperation; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/1 16:12 16 | */ 17 | @Configuration 18 | public class SwaggerConfig { 19 | @Bean 20 | public Docket createRestApi(){ 21 | return new Docket(DocumentationType.SWAGGER_2) 22 | .apiInfo(apiInfo()) 23 | .select() 24 | //加了ApiOperation注解的类,才生成接口文档 25 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 26 | //包下的类,才生成接口文档 27 | .apis(RequestHandlerSelectors.basePackage("com.jxph.cloud.service.auth")) 28 | .paths(PathSelectors.any()) 29 | .build(); 30 | } 31 | 32 | private ApiInfo apiInfo() { 33 | return new ApiInfoBuilder() 34 | .title("auth-api") 35 | .description("文档") 36 | .version("1.0") 37 | .build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config; 2 | 3 | import io.swagger.annotations.ApiOperation; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/1 16:12 16 | */ 17 | @Configuration 18 | public class SwaggerConfig { 19 | @Bean 20 | public Docket createRestApi(){ 21 | return new Docket(DocumentationType.SWAGGER_2) 22 | .apiInfo(apiInfo()) 23 | .select() 24 | //加了ApiOperation注解的类,才生成接口文档 25 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 26 | //包下的类,才生成接口文档 27 | .apis(RequestHandlerSelectors.basePackage("com.jxph.cloud.service.fast")) 28 | .paths(PathSelectors.any()) 29 | .build(); 30 | } 31 | 32 | private ApiInfo apiInfo() { 33 | return new ApiInfoBuilder() 34 | .title("fast-api") 35 | .description("文档") 36 | .version("1.0") 37 | .build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.controller; 2 | 3 | import com.jxph.cloud.common.utils.ResponseResult; 4 | import com.jxph.cloud.service.auth.api.facade.LoginFacade; 5 | import com.jxph.cloud.service.auth.api.form.LoginForm; 6 | import com.jxph.cloud.service.auth.client.runner.JwtHelper; 7 | import com.jxph.cloud.service.auth.server.service.LoginService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import javax.servlet.http.HttpServletResponse; 16 | import javax.validation.Valid; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * @author 谢秋豪 22 | * @date 2018/9/2 12:19 23 | */ 24 | @RestController 25 | @Api("登录接口") 26 | public class LoginController implements LoginFacade { 27 | @Autowired 28 | private JwtHelper jwtHelper; 29 | 30 | @Autowired 31 | private LoginService loginService; 32 | 33 | @ApiOperation("测试登录") 34 | @Override 35 | public ResponseResult login(@RequestBody @Valid LoginForm loginForm, HttpServletResponse response) { 36 | String token = loginService.login(loginForm); 37 | response.setHeader(jwtHelper.getHeader(),token); 38 | return ResponseResult.ok(token); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/pojo/TaskManagerLog.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.pojo; 2 | 3 | import java.util.Date; 4 | 5 | public class TaskManagerLog { 6 | private Integer id; 7 | 8 | private Date createTime; 9 | 10 | private Date updateTime; 11 | 12 | private Integer status; 13 | 14 | private String operatorAddress; 15 | 16 | private String taskJobId; 17 | 18 | public Integer getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Integer id) { 23 | this.id = id; 24 | } 25 | 26 | public Date getCreateTime() { 27 | return createTime; 28 | } 29 | 30 | public void setCreateTime(Date createTime) { 31 | this.createTime = createTime; 32 | } 33 | 34 | public Date getUpdateTime() { 35 | return updateTime; 36 | } 37 | 38 | public void setUpdateTime(Date updateTime) { 39 | this.updateTime = updateTime; 40 | } 41 | 42 | public Integer getStatus() { 43 | return status; 44 | } 45 | 46 | public void setStatus(Integer status) { 47 | this.status = status; 48 | } 49 | 50 | public String getOperatorAddress() { 51 | return operatorAddress; 52 | } 53 | 54 | public void setOperatorAddress(String operatorAddress) { 55 | this.operatorAddress = operatorAddress == null ? null : operatorAddress.trim(); 56 | } 57 | 58 | public String getTaskJobId() { 59 | return taskJobId; 60 | } 61 | 62 | public void setTaskJobId(String taskJobId) { 63 | this.taskJobId = taskJobId == null ? null : taskJobId.trim(); 64 | } 65 | } -------------------------------------------------------------------------------- /monitor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | com.jxph.cloud 8 | root 9 | 1.0-SNAPSHOT 10 | 11 | com.jxph.cloud 12 | monitor 13 | 1.0-SNAPSHOT 14 | monitor 15 | jar 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-turbine 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-eureka-client 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-netflix-hystrix-dashboard 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /service/auth/auth-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | com.jxph.cloud.service 8 | auth 9 | 1.0-SNAPSHOT 10 | 11 | 12 | com.jxph.cloud.service.auth 13 | auth-client 14 | 1.0-SNAPSHOT 15 | 16 | auth-client 17 | 18 | 19 | 20 | com.jxph.cloud 21 | common 22 | 1.0-SNAPSHOT 23 | 24 | 25 | 26 | mysql 27 | mysql-connector-java 28 | runtime 29 | 30 | 31 | 32 | org.mybatis.spring.boot 33 | mybatis-spring-boot-starter 34 | 1.2.0 35 | 36 | 37 | 38 | com.alibaba 39 | druid-spring-boot-starter 40 | 1.1.10 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-data-redis 46 | 47 | 48 | 49 | com.auth0 50 | java-jwt 51 | 3.1.0 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/DistributedLock.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.core.RedisTemplate; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/9/3 0:37 13 | */ 14 | @Component 15 | public class DistributedLock { 16 | @Autowired 17 | private RedisTemplate redisTemplate; 18 | 19 | public Boolean tryLock(String key,int timeout) { 20 | long expires = System.currentTimeMillis() + timeout; 21 | Boolean flag = redisTemplate.opsForValue().setIfAbsent(key, expires); 22 | if (flag) { 23 | redisTemplate.expire(key, timeout, TimeUnit.MILLISECONDS); 24 | return true; 25 | } 26 | Object currentValue = redisTemplate.opsForValue().get(key); 27 | if (currentValue != null && Long.parseLong(currentValue.toString()) < System.currentTimeMillis()) { 28 | Object oldValue = redisTemplate.opsForValue().getAndSet(key, expires); 29 | if (oldValue == null) { 30 | redisTemplate.expire(key, timeout, TimeUnit.MILLISECONDS); 31 | return true; 32 | } else { 33 | if (StringUtils.equals(currentValue.toString(), oldValue.toString())) { 34 | redisTemplate.expire(key, timeout, TimeUnit.MILLISECONDS); 35 | return true; 36 | } 37 | } 38 | } 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/RetryMessageTask.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task; 2 | 3 | import com.jxph.cloud.common.constant.BrokerMessageTryCountConstant; 4 | import com.jxph.cloud.common.utils.JSONUtils; 5 | import com.jxph.cloud.service.auth.client.runner.DistributedLock; 6 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 7 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 8 | import com.jxph.cloud.service.fast.server.common.constant.RedisKeyConstant; 9 | import com.jxph.cloud.service.fast.server.mq.OrderSender; 10 | import com.jxph.cloud.service.fast.server.service.BrokerMessageLogService; 11 | import com.jxph.cloud.service.fast.server.task.job.RetryMessageJob; 12 | import com.jxph.cloud.service.fast.server.task.manager.DefaultManagerTask; 13 | import lombok.extern.slf4j.Slf4j; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.scheduling.annotation.Scheduled; 16 | import org.springframework.stereotype.Component; 17 | 18 | import java.util.List; 19 | 20 | 21 | /** 22 | * @author 谢秋豪 23 | * @date 2018/8/30 21:09 24 | */ 25 | @Component 26 | @Slf4j 27 | public class RetryMessageTask { 28 | @Autowired 29 | private DistributedLock distributedLock; 30 | @Autowired 31 | private RetryMessageJob retryMessageJob; 32 | 33 | @Scheduled(cron = "0/15 * * * * ?") 34 | public void reSend() { 35 | Boolean tryLock = distributedLock.tryLock(RedisKeyConstant.RETRY_MESSAGE_KEY,5000); 36 | if (tryLock) { 37 | log.info("本机拿到锁,执行reSend任务"); 38 | DefaultManagerTask defaultManagerTask = new DefaultManagerTask(retryMessageJob); 39 | defaultManagerTask.process(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jxph.cloud 7 | common 8 | 1.0-SNAPSHOT 9 | 10 | common 11 | 12 | 13 | com.jxph.cloud 14 | root 15 | 1.0-SNAPSHOT 16 | 17 | 18 | 19 | 20 | 21 | joda-time 22 | joda-time 23 | 24 | 25 | commons-lang 26 | commons-lang 27 | 2.6 28 | 29 | 30 | commons-io 31 | commons-io 32 | 2.5 33 | 34 | 35 | commons-codec 36 | commons-codec 37 | 38 | 39 | com.fasterxml.jackson.core 40 | jackson-databind 41 | 42 | 43 | javax.servlet 44 | javax.servlet-api 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-web 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-logging 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/mq/OrderSender.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.mq; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 4 | import com.jxph.cloud.service.fast.server.service.OrderService; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 7 | import org.springframework.amqp.rabbit.support.CorrelationData; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author 谢秋豪 13 | * @date 2018/8/30 14:50 14 | */ 15 | @Component 16 | @Slf4j 17 | public class OrderSender { 18 | @Autowired 19 | private RabbitTemplate rabbitTemplate; 20 | @Autowired 21 | private OrderService orderService; 22 | 23 | /** 24 | * 回调函数:confirm确认 25 | */ 26 | final RabbitTemplate.ConfirmCallback confirmCallback = new RabbitTemplate.ConfirmCallback(){ 27 | @Override 28 | public void confirm(CorrelationData correlationData, boolean ack, String s) { 29 | log.info("correlationData:{}",correlationData); 30 | String messageId = correlationData.getId(); 31 | if(ack){ 32 | orderService.confirmMessage(messageId); 33 | }else { 34 | //补偿处理,根据mq broker原因(队列已满就没有必要重投等等)进行重投或补偿 35 | log.info("confirm error"); 36 | } 37 | } 38 | }; 39 | 40 | public void sendOrder(TOrder order){ 41 | rabbitTemplate.setConfirmCallback(confirmCallback); 42 | CorrelationData correlationData = new CorrelationData(); 43 | correlationData.setId(order.getMessageId()); 44 | rabbitTemplate.convertAndSend("order-exchange","order.abcd",order,correlationData); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 4 | import com.fasterxml.jackson.annotation.PropertyAccessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.data.redis.connection.RedisConnectionFactory; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 12 | import org.springframework.data.redis.serializer.StringRedisSerializer; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/8/31 21:52 17 | */ 18 | @Configuration 19 | @EnableCaching 20 | public class RedisConfig { 21 | @Bean 22 | public RedisTemplate redisTemplate(RedisConnectionFactory factory){ 23 | RedisTemplate redisTemplate = new RedisTemplate<>(); 24 | redisTemplate.setConnectionFactory(factory); 25 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class); 26 | ObjectMapper objectMapper = new ObjectMapper(); 27 | objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 28 | objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 29 | jackson2JsonRedisSerializer.setObjectMapper(objectMapper); 30 | redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); 31 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 32 | redisTemplate.afterPropertiesSet(); 33 | return redisTemplate; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/pojo/BrokerMessageLog.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.pojo; 2 | 3 | import java.util.Date; 4 | 5 | public class BrokerMessageLog { 6 | private String messageId; 7 | 8 | private String message; 9 | 10 | private Integer tryCount; 11 | 12 | private Integer status; 13 | 14 | private Date nextRetry; 15 | 16 | private Date createTime; 17 | 18 | private Date updateTime; 19 | 20 | public String getMessageId() { 21 | return messageId; 22 | } 23 | 24 | public void setMessageId(String messageId) { 25 | this.messageId = messageId == null ? null : messageId.trim(); 26 | } 27 | 28 | public String getMessage() { 29 | return message; 30 | } 31 | 32 | public void setMessage(String message) { 33 | this.message = message == null ? null : message.trim(); 34 | } 35 | 36 | public Integer getTryCount() { 37 | return tryCount; 38 | } 39 | 40 | public void setTryCount(Integer tryCount) { 41 | this.tryCount = tryCount; 42 | } 43 | 44 | public Integer getStatus() { 45 | return status; 46 | } 47 | 48 | public void setStatus(Integer status) { 49 | this.status = status; 50 | } 51 | 52 | public Date getNextRetry() { 53 | return nextRetry; 54 | } 55 | 56 | public void setNextRetry(Date nextRetry) { 57 | this.nextRetry = nextRetry; 58 | } 59 | 60 | public Date getCreateTime() { 61 | return createTime; 62 | } 63 | 64 | public void setCreateTime(Date createTime) { 65 | this.createTime = createTime; 66 | } 67 | 68 | public Date getUpdateTime() { 69 | return updateTime; 70 | } 71 | 72 | public void setUpdateTime(Date updateTime) { 73 | this.updateTime = updateTime; 74 | } 75 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/job/RetryMessageJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.job; 2 | 3 | import com.jxph.cloud.common.constant.BrokerMessageTryCountConstant; 4 | import com.jxph.cloud.common.utils.JSONUtils; 5 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 6 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 7 | import com.jxph.cloud.service.fast.server.mq.OrderSender; 8 | import com.jxph.cloud.service.fast.server.service.BrokerMessageLogService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @author xqh 17 | * @date 2018/9/30 0:20 18 | */ 19 | @Component 20 | @Slf4j 21 | public class RetryMessageJob implements TaskJob { 22 | @Autowired 23 | private OrderSender orderSender; 24 | @Autowired 25 | private BrokerMessageLogService brokerMessageLogService; 26 | 27 | @Override 28 | public void processImpl() { 29 | List list = brokerMessageLogService.selectSendMessage(); 30 | list.forEach(messageLog -> { 31 | if (messageLog.getTryCount() >= BrokerMessageTryCountConstant.TRYCOUNT_MAX_LIMIT) { 32 | brokerMessageLogService.updateBrokerMessageLogStatusToFail(messageLog); 33 | //解决方案 34 | } else { 35 | brokerMessageLogService.updateBrokerMessageLogTryCount(messageLog); 36 | TOrder order = JSONUtils.parse(messageLog.getMessage(), TOrder.class); 37 | try { 38 | orderSender.sendOrder(order); 39 | } catch (Exception e) { 40 | log.error("send error"); 41 | } 42 | } 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/aspect/DataSourceAspect.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource.aspect; 2 | 3 | import com.jxph.cloud.service.fast.server.config.datasource.DataSourceContextHolder; 4 | import com.jxph.cloud.service.fast.server.config.datasource.annotation.DataSource; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.Around; 8 | import org.aspectj.lang.annotation.Aspect; 9 | import org.aspectj.lang.annotation.Pointcut; 10 | import org.aspectj.lang.reflect.MethodSignature; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.lang.reflect.Method; 14 | 15 | /** 16 | * @author 谢秋豪 17 | * @date 2018/8/31 23:40 18 | */ 19 | @Aspect 20 | @Component 21 | @Slf4j 22 | public class DataSourceAspect { 23 | @Pointcut("@annotation(com.jxph.cloud.service.fast.server.config.datasource.annotation.DataSource)") 24 | public void dataSourcePointCut() { 25 | 26 | } 27 | 28 | @Around("dataSourcePointCut()") 29 | public void around(ProceedingJoinPoint point) { 30 | String methodName = null; 31 | try{ 32 | MethodSignature signature = (MethodSignature) point.getSignature(); 33 | Method method = signature.getMethod(); 34 | methodName = method.getName(); 35 | DataSource annotation = method.getAnnotation(DataSource.class); 36 | DataSourceContextHolder.setDataSource(annotation.value()); 37 | point.proceed(); 38 | } catch (Throwable throwable) { 39 | log.error("routing dataSource error,methodName:{},exception:{}",methodName,throwable); 40 | } finally { 41 | DataSourceContextHolder.clearDataSource(); 42 | log.info("clear dataSource"); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/aspect/DataSourceAspect.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource.aspect; 2 | 3 | 4 | import com.jxph.cloud.service.auth.server.config.datasource.DataSourceContextHolder; 5 | import com.jxph.cloud.service.auth.server.config.datasource.annotation.DataSource; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.aspectj.lang.ProceedingJoinPoint; 8 | import org.aspectj.lang.annotation.Around; 9 | import org.aspectj.lang.annotation.Aspect; 10 | import org.aspectj.lang.annotation.Pointcut; 11 | import org.aspectj.lang.reflect.MethodSignature; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.lang.reflect.Method; 15 | 16 | /** 17 | * @author 谢秋豪 18 | * @date 2018/8/31 23:40 19 | */ 20 | @Aspect 21 | @Component 22 | @Slf4j 23 | public class DataSourceAspect { 24 | @Pointcut("@annotation(com.jxph.cloud.service.auth.server.config.datasource.annotation.DataSource)") 25 | public void dataSourcePointCut() { 26 | 27 | } 28 | 29 | @Around("dataSourcePointCut()") 30 | public void around(ProceedingJoinPoint point) { 31 | String methodName = null; 32 | try{ 33 | MethodSignature signature = (MethodSignature) point.getSignature(); 34 | Method method = signature.getMethod(); 35 | methodName = method.getName(); 36 | DataSource annotation = method.getAnnotation(DataSource.class); 37 | DataSourceContextHolder.setDataSource(annotation.value()); 38 | point.proceed(); 39 | } catch (Throwable throwable) { 40 | log.error("routing dataSource error,methodName:{},exception:{}",methodName,throwable); 41 | } finally { 42 | DataSourceContextHolder.clearDataSource(); 43 | log.info("clear dataSource"); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/CouponTask.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task; 2 | 3 | import com.jxph.cloud.service.auth.client.runner.DistributedLock; 4 | import com.jxph.cloud.service.fast.server.common.constant.RedisKeyConstant; 5 | import com.jxph.cloud.service.fast.server.config.datasource.DataSourceConstant; 6 | import com.jxph.cloud.service.fast.server.config.datasource.annotation.DataSource; 7 | import com.jxph.cloud.service.fast.server.service.TaskManagerService; 8 | import com.jxph.cloud.service.fast.server.task.manager.DefaultManagerTask; 9 | import com.jxph.cloud.service.fast.server.task.job.CouponJob; 10 | import com.jxph.cloud.service.fast.server.task.job.TestJob; 11 | import com.jxph.cloud.service.fast.server.task.manager.SaveInfoManagerTask; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.scheduling.annotation.Scheduled; 15 | import org.springframework.stereotype.Component; 16 | 17 | /** 18 | * @author 谢秋豪 19 | * @date 2018/9/2 21:48 20 | */ 21 | @Slf4j 22 | @Component 23 | public class CouponTask { 24 | @Autowired 25 | private DistributedLock distributedLock; 26 | @Autowired 27 | private TestJob testJob; 28 | @Autowired 29 | private TaskManagerService taskManagerService; 30 | @Autowired 31 | private CouponJob couponJob; 32 | 33 | @Scheduled(cron = "0 */1 * * * ?") 34 | @DataSource(DataSourceConstant.DATASOURCE_NAME_SECOND) 35 | public void couponJob(){ 36 | Boolean tryLock = distributedLock.tryLock(RedisKeyConstant.COUPON_JOB_KEY,5000); 37 | if (tryLock) { 38 | log.info("本机拿到锁,执行job任务"); 39 | SaveInfoManagerTask managerTask = new SaveInfoManagerTask(couponJob, taskManagerService); 40 | managerTask.process(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource; 2 | 3 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | 10 | import javax.sql.DataSource; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/8/16 18:01 17 | */ 18 | @Configuration 19 | public class DataSourceConfig { 20 | @Bean(name = DataSourceConstant.DATASOURCE_NAME_FIRST) 21 | @ConfigurationProperties(prefix = "spring.datasource.druid.first") 22 | public DataSource dataSourceFirst() { 23 | return DruidDataSourceBuilder.create().build(); 24 | } 25 | 26 | @Bean(name = DataSourceConstant.DATASOURCE_NAME_SECOND) 27 | @ConfigurationProperties(prefix = "spring.datasource.druid.second") 28 | public DataSource dataSourceSecond() { 29 | return DruidDataSourceBuilder.create().build(); 30 | } 31 | 32 | @Bean 33 | @Primary 34 | public DynamicDataSource dataSource(@Qualifier(DataSourceConstant.DATASOURCE_NAME_FIRST) DataSource firstDataSource, 35 | @Qualifier(DataSourceConstant.DATASOURCE_NAME_SECOND) DataSource secondDataSource) { 36 | Map targetDataSources = new HashMap<>(); 37 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_FIRST, firstDataSource); 38 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_SECOND, secondDataSource); 39 | return new DynamicDataSource(firstDataSource, targetDataSources); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/impl/TaskManagerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service.impl; 2 | 3 | import com.jxph.cloud.service.auth.client.runner.IpConfig; 4 | import com.jxph.cloud.service.fast.api.pojo.TaskManagerLog; 5 | import com.jxph.cloud.service.fast.server.common.constant.TaskManagerLogStatusConstant; 6 | import com.jxph.cloud.service.fast.server.dao.TaskManagerLogMapper; 7 | import com.jxph.cloud.service.fast.server.service.TaskManagerService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.Date; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/8 15:55 16 | */ 17 | @Service 18 | public class TaskManagerServiceImpl implements TaskManagerService { 19 | @Autowired 20 | private IpConfig ipConfig; 21 | @Autowired 22 | private TaskManagerLogMapper taskManagerLogMapper; 23 | 24 | @Override 25 | public Integer createTaskManager() { 26 | TaskManagerLog taskManagerLog = new TaskManagerLog(); 27 | taskManagerLog.setStatus(TaskManagerLogStatusConstant.TASK_MANAGER_START); 28 | taskManagerLog.setCreateTime(new Date()); 29 | taskManagerLog.setUpdateTime(new Date()); 30 | taskManagerLog.setOperatorAddress(ipConfig.getHostIp() + ":" + ipConfig.getPort()); 31 | taskManagerLogMapper.insertSelective(taskManagerLog); 32 | return taskManagerLog.getId(); 33 | } 34 | 35 | @Override 36 | public void updateTaskMangerToSuccess(Integer taskManagerId) { 37 | TaskManagerLog taskManagerLog = new TaskManagerLog(); 38 | taskManagerLog.setId(taskManagerId); 39 | taskManagerLog.setStatus(TaskManagerLogStatusConstant.TASK_MANAGER_SUCCESS); 40 | taskManagerLog.setUpdateTime(new Date()); 41 | taskManagerLogMapper.updateByPrimaryKeySelective(taskManagerLog); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/filter/DefaultFilter.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import com.netflix.zuul.exception.ZuulException; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.apache.commons.lang.StringUtils; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | /** 12 | * @author 谢秋豪 13 | * @date 2018/9/1 22:12 14 | */ 15 | @Slf4j 16 | public class DefaultFilter extends ZuulFilter { 17 | /** 18 | * 定义filter的类型,有pre、route、post、error四种 19 | */ 20 | @Override 21 | public String filterType() { 22 | return "pre"; 23 | } 24 | 25 | /** 26 | * 定义filter的顺序,数字越小表示顺序越高,越先执行 27 | */ 28 | @Override 29 | public int filterOrder() { 30 | return 0; 31 | } 32 | 33 | /** 34 | * 表示是否需要执行该filter,true表示执行,false表示不执行 35 | */ 36 | @Override 37 | public boolean shouldFilter() { 38 | return true; 39 | } 40 | 41 | /** 42 | * filter需要执行的具体操作 43 | */ 44 | @Override 45 | public Object run() throws ZuulException { 46 | RequestContext currentContext = RequestContext.getCurrentContext(); 47 | HttpServletRequest request = currentContext.getRequest(); 48 | log.info("tokenFilter:{},{}", request.getMethod(), request.getRequestURL().toString()); 49 | String requestURL = request.getRequestURL().toString(); 50 | /*if (flag) { 51 | currentContext.setSendZuulResponse(true); 52 | currentContext.setResponseStatusCode(200); 53 | currentContext.set("router", true); 54 | } else { 55 | //不对其进行路由 56 | currentContext.setSendZuulResponse(false); 57 | currentContext.setResponseStatusCode(400); 58 | currentContext.setResponseBody("fast is empty"); 59 | currentContext.set("router", false); 60 | }*/ 61 | return null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/utils/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.utils; 2 | 3 | 4 | import com.jxph.cloud.common.enums.ResultCodeEnum; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author 谢秋豪 10 | * @date 2018/9/1 14:38 11 | */ 12 | public class ResponseResult implements Serializable { 13 | private static final long serialVersionUID = -3796886832705747283L; 14 | private int status; 15 | private String msg; 16 | private T data; 17 | 18 | public ResponseResult() { 19 | 20 | } 21 | 22 | public static long getSerialVersionUID() { 23 | return serialVersionUID; 24 | } 25 | 26 | public int getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(int status) { 31 | this.status = status; 32 | } 33 | 34 | public String getMsg() { 35 | return msg; 36 | } 37 | 38 | public void setMsg(String msg) { 39 | this.msg = msg; 40 | } 41 | 42 | public T getData() { 43 | return data; 44 | } 45 | 46 | public void setData(T data) { 47 | this.data = data; 48 | } 49 | 50 | public ResponseResult(int status, String msg) { 51 | this.status = status; 52 | this.msg = msg; 53 | this.data = data; 54 | } 55 | 56 | 57 | public ResponseResult(int status, String msg, T data) { 58 | this.status = status; 59 | this.msg = msg; 60 | this.data = data; 61 | } 62 | 63 | public static ResponseResult ok() { 64 | return ok(null); 65 | } 66 | 67 | public static ResponseResult ok(T data) { 68 | return new ResponseResult(ResultCodeEnum.SUCCESS.getCode(), null, data); 69 | } 70 | 71 | public static ResponseResult error(String msg, T data) { 72 | return new ResponseResult(ResultCodeEnum.FAILURE.getCode(), msg, data); 73 | } 74 | 75 | public static ResponseResult error(String msg) { 76 | return error(msg, null); 77 | } 78 | } -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/utils/IPUtils.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.utils; 2 | 3 | 4 | import org.apache.commons.lang.StringUtils; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | /** 11 | * @author 谢秋豪 12 | * @date 2018/8/18 23:26 13 | */ 14 | public class IPUtils { 15 | private static final Logger logger = LoggerFactory.getLogger(IPUtils.class); 16 | /** 17 | * 获取IP地址 18 | *

19 | * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址 20 | * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址 21 | */ 22 | public static String getIpAddr(HttpServletRequest request) { 23 | String ip = null; 24 | try { 25 | ip = request.getHeader("x-forwarded-for"); 26 | if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 27 | ip = request.getHeader("Proxy-Client-IP"); 28 | } 29 | if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 30 | ip = request.getHeader("WL-Proxy-Client-IP"); 31 | } 32 | if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 33 | ip = request.getHeader("HTTP_CLIENT_IP"); 34 | } 35 | if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 36 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 37 | } 38 | if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 39 | ip = request.getRemoteAddr(); 40 | } 41 | } catch (Exception e) { 42 | logger.error("IPUtils ERROR ", e); 43 | } 44 | /*使用代理,则获取第一个IP地址 45 | if(StringUtils.isEmpty(ip) && ip.length() > 15) { 46 | if(ip.indexOf(",") > 0) { 47 | ip = ip.substring(0, ip.indexOf(",")); 48 | } 49 | } 50 | */ 51 | return ip; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/common/utils/MD5Helper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.common.utils; 2 | 3 | 4 | import com.google.common.base.Throwables; 5 | import com.google.common.hash.HashCode; 6 | import com.google.common.hash.HashFunction; 7 | import com.google.common.hash.Hashing; 8 | 9 | import java.io.UnsupportedEncodingException; 10 | import java.nio.charset.Charset; 11 | import java.util.UUID; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/3 21:36 16 | */ 17 | public class MD5Helper { 18 | private static final HashFunction FUNCTION = Hashing.md5(); 19 | 20 | private static final HashFunction MURMUR_FUNC = Hashing.murmur3_128(); 21 | 22 | public static String[] chars = new String[] { "0", "1", "2", "3", "4", "5", 23 | "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", 24 | "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", 25 | "W", "X", "Y", "Z" }; 26 | 27 | public static String encryPassword(String password,String salt){ 28 | HashCode code = FUNCTION.hashString(password+salt, Charset.forName("UTF-8")); 29 | return code.toString(); 30 | } 31 | 32 | public static String hashString(String input){ 33 | HashCode code = null; 34 | try { 35 | code = MURMUR_FUNC.hashBytes(input.getBytes("utf-8")); 36 | } catch (UnsupportedEncodingException e) { 37 | Throwables.propagate(e); 38 | } 39 | return code.toString(); 40 | } 41 | 42 | public static String getUUID() { 43 | StringBuffer shortBuffer = new StringBuffer(); 44 | String uuid = UUID.randomUUID().toString().replace("-", ""); 45 | for (int i = 0; i < 16; i++) { 46 | String str = uuid.substring(i * 2, i * 2 + 2); 47 | int x = Integer.parseInt(str, 16); 48 | shortBuffer.append(chars[x % 36]); 49 | } 50 | return shortBuffer.toString(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/IpConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import org.springframework.boot.web.context.WebServerInitializedEvent; 4 | import org.springframework.context.ApplicationListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.net.Inet4Address; 8 | import java.net.InetAddress; 9 | import java.net.NetworkInterface; 10 | import java.util.Enumeration; 11 | 12 | /** 13 | * @author 谢秋豪 14 | * @date 2018/9/3 1:27 15 | */ 16 | @Component 17 | public class IpConfig implements ApplicationListener { 18 | private int serverPort; 19 | 20 | @Override 21 | public void onApplicationEvent(WebServerInitializedEvent event) { 22 | this.serverPort = event.getWebServer().getPort(); 23 | } 24 | 25 | public int getPort() { 26 | return this.serverPort; 27 | } 28 | 29 | public String getHostIp(){ 30 | try{ 31 | Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces(); 32 | while (allNetInterfaces.hasMoreElements()){ 33 | NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); 34 | Enumeration addresses = netInterface.getInetAddresses(); 35 | while (addresses.hasMoreElements()){ 36 | InetAddress ip = (InetAddress) addresses.nextElement(); 37 | if (ip != null 38 | && ip instanceof Inet4Address 39 | && !ip.isLoopbackAddress() //loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255 40 | && ip.getHostAddress().indexOf(":")==-1){ 41 | return ip.getHostAddress(); 42 | } 43 | } 44 | } 45 | }catch(Exception e){ 46 | e.printStackTrace(); 47 | } 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/impl/CouponTaskServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service.impl; 2 | 3 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJob; 4 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJobExample; 5 | import com.jxph.cloud.service.fast.server.common.constant.CouponTaskJobStatusConstant; 6 | import com.jxph.cloud.service.fast.server.dao.CouponTaskJobMapper; 7 | import com.jxph.cloud.service.fast.server.service.CouponTaskService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.Date; 12 | import java.util.List; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/9/8 16:07 17 | */ 18 | @Service 19 | public class CouponTaskServiceImpl implements CouponTaskService { 20 | @Autowired 21 | private CouponTaskJobMapper couponTaskJobMapper; 22 | 23 | @Override 24 | public List selectCreationCouponJob() { 25 | CouponTaskJobExample example = new CouponTaskJobExample(); 26 | CouponTaskJobExample.Criteria criteria = example.createCriteria(); 27 | criteria.andStatusEqualTo(CouponTaskJobStatusConstant.JOB_CREATION); 28 | example.setOrderByClause("create_time"); 29 | example.setLimit(100); 30 | example.setOffset(0); 31 | return couponTaskJobMapper.selectByExample(example); 32 | } 33 | 34 | @Override 35 | public void updateCouponTask(CouponTaskJob couponTaskJob, int status) { 36 | updateCouponTask(couponTaskJob, status, null); 37 | } 38 | 39 | @Override 40 | public void updateCouponTask(CouponTaskJob couponTaskJob, int status, String remark) { 41 | couponTaskJob.setStatus(status); 42 | couponTaskJob.setUpdateTime(new Date()); 43 | if (remark != null) { 44 | couponTaskJob.setRemark(remark); 45 | } 46 | couponTaskJobMapper.updateByPrimaryKeySelective(couponTaskJob); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/DruidConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import com.alibaba.druid.support.http.StatViewServlet; 4 | import com.alibaba.druid.support.http.WebStatFilter; 5 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 6 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; 10 | 11 | import javax.servlet.Servlet; 12 | 13 | /** 14 | * @author 谢秋豪 15 | * @date 2018/9/3 14:47 16 | */ 17 | @Configuration 18 | public class DruidConfig { 19 | @Bean 20 | public ServletRegistrationBean servletRegistrationBean() { 21 | ServletRegistrationBean servletServletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*"); 22 | //白名单 23 | servletServletRegistrationBean.addInitParameter("allow", "127.0.0.1"); 24 | servletServletRegistrationBean.addInitParameter("deny", "192.168.11.100"); 25 | servletServletRegistrationBean.addInitParameter("loginUsername", "admin"); 26 | servletServletRegistrationBean.addInitParameter("loginPassword", "admin"); 27 | servletServletRegistrationBean.addInitParameter("resetEnable", "false"); 28 | return servletServletRegistrationBean; 29 | } 30 | 31 | @Bean 32 | public FilterRegistrationBean startFilter() { 33 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); 34 | filterRegistrationBean.addUrlPatterns("/*"); 35 | filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.icon,/druid/**"); 36 | return filterRegistrationBean; 37 | } 38 | 39 | @Bean 40 | public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() { 41 | return new PersistenceExceptionTranslationPostProcessor(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/utils/ClientHttpResponseUtils.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.utils; 2 | 3 | import com.jxph.cloud.common.utils.JSONUtils; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.client.ClientHttpResponse; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/9/4 11:51 17 | */ 18 | @Slf4j 19 | public class ClientHttpResponseUtils { 20 | public static ClientHttpResponse newFallBackClientHttpResponse(String route, Throwable cause){ 21 | return new ClientHttpResponse() { 22 | @Override 23 | public HttpStatus getStatusCode() throws IOException { 24 | return HttpStatus.OK; 25 | } 26 | 27 | @Override 28 | public int getRawStatusCode() throws IOException { 29 | return HttpStatus.OK.value(); 30 | } 31 | 32 | @Override 33 | public String getStatusText() throws IOException { 34 | return HttpStatus.OK.getReasonPhrase(); 35 | } 36 | 37 | @Override 38 | public void close() { 39 | 40 | } 41 | 42 | @Override 43 | public InputStream getBody() throws IOException { 44 | if (cause != null) { 45 | log.error("http exception:{}", cause); 46 | } 47 | return new ByteArrayInputStream(JSONUtils.toJsonString("The service is unavailable").getBytes("UTF-8")); 48 | /*return new ByteArrayInputStream("The service is unavailable".getBytes("UTF-8"));*/ 49 | } 50 | 51 | @Override 52 | public HttpHeaders getHeaders() { 53 | HttpHeaders headers = new HttpHeaders(); 54 | headers.setContentType(MediaType.APPLICATION_JSON); 55 | return headers; 56 | } 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/impl/BrokerMessageLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service.impl; 2 | 3 | import com.jxph.cloud.common.constant.BrokerMessageStatusConstant; 4 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 5 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLogExample; 6 | import com.jxph.cloud.service.fast.server.dao.BrokerMessageLogMapper; 7 | import com.jxph.cloud.service.fast.server.service.BrokerMessageLogService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.Date; 12 | import java.util.List; 13 | 14 | /** 15 | * @author 谢秋豪 16 | * @date 2018/9/8 23:29 17 | */ 18 | @Service 19 | public class BrokerMessageLogServiceImpl implements BrokerMessageLogService { 20 | @Autowired 21 | private BrokerMessageLogMapper brokerMessageLogMapper; 22 | @Override 23 | public List selectSendMessage() { 24 | BrokerMessageLogExample brokerMessageLogExample = new BrokerMessageLogExample(); 25 | BrokerMessageLogExample.Criteria criteria = brokerMessageLogExample.createCriteria(); 26 | criteria.andStatusEqualTo(BrokerMessageStatusConstant.ORDER_SENDING); 27 | criteria.andNextRetryGreaterThan(new Date()); 28 | List brokerMessageLogs = brokerMessageLogMapper.selectByExample(brokerMessageLogExample); 29 | return brokerMessageLogs; 30 | } 31 | 32 | @Override 33 | public void updateBrokerMessageLogTryCount(BrokerMessageLog brokerMessageLog) { 34 | brokerMessageLog.setUpdateTime(new Date()); 35 | brokerMessageLog.setTryCount(brokerMessageLog.getTryCount()+1); 36 | brokerMessageLogMapper.updateByPrimaryKeySelective(brokerMessageLog); 37 | } 38 | 39 | @Override 40 | public void updateBrokerMessageLogStatusToFail(BrokerMessageLog brokerMessageLog) { 41 | brokerMessageLog.setUpdateTime(new Date()); 42 | brokerMessageLog.setStatus(BrokerMessageStatusConstant.ORDER_SEND_FAILURE); 43 | brokerMessageLogMapper.updateByPrimaryKeySelective(brokerMessageLog); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/config/datasource/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.config.datasource; 2 | 3 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; 4 | 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 8 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Primary; 12 | import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; 13 | 14 | import javax.servlet.Servlet; 15 | import javax.sql.DataSource; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | /** 20 | * @author 谢秋豪 21 | * @date 2018/8/16 18:01 22 | */ 23 | @Configuration 24 | public class DataSourceConfig { 25 | 26 | @Bean(name = DataSourceConstant.DATASOURCE_NAME_FIRST) 27 | @ConfigurationProperties(prefix = "spring.datasource.druid.first") 28 | public DataSource dataSourceFirst() { 29 | return DruidDataSourceBuilder.create().build(); 30 | } 31 | 32 | @Bean(name = DataSourceConstant.DATASOURCE_NAME_SECOND) 33 | @ConfigurationProperties(prefix = "spring.datasource.druid.second") 34 | public DataSource dataSourceSecond() { 35 | return DruidDataSourceBuilder.create().build(); 36 | } 37 | 38 | @Bean 39 | @Primary 40 | public DynamicDataSource dataSource(@Qualifier(DataSourceConstant.DATASOURCE_NAME_FIRST) DataSource firstDataSource, 41 | @Qualifier(DataSourceConstant.DATASOURCE_NAME_SECOND) DataSource secondDataSource) { 42 | Map targetDataSources = new HashMap<>(); 43 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_FIRST, firstDataSource); 44 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_SECOND, secondDataSource); 45 | return new DynamicDataSource(firstDataSource, targetDataSources); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/runner/JwtHelper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.runner; 2 | 3 | import com.auth0.jwt.JWT; 4 | import com.auth0.jwt.JWTCreator; 5 | import com.auth0.jwt.JWTVerifier; 6 | import com.auth0.jwt.algorithms.Algorithm; 7 | import com.auth0.jwt.interfaces.DecodedJWT; 8 | import com.jxph.cloud.common.utils.DateUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.io.UnsupportedEncodingException; 15 | import java.util.Date; 16 | import java.util.Map; 17 | 18 | /** 19 | * @author 谢秋豪 20 | * @date 2018/9/1 11:06 21 | */ 22 | 23 | @Component 24 | public class JwtHelper { 25 | private static final Logger logger = LoggerFactory.getLogger(JwtHelper.class); 26 | 27 | @Value("${jwt.security.secret}") 28 | private String SECRET; 29 | @Value("${jwt.security.issuer}") 30 | private String ISSUER; 31 | @Value("${jwt.header}") 32 | private String header; 33 | 34 | public String getHeader() { 35 | return header; 36 | } 37 | 38 | public String createJWT(Map map) { 39 | String sign = null; 40 | try { 41 | Date date = DateUtils.addDateDays(new Date(), 1); 42 | JWTCreator.Builder builder = JWT.create(); 43 | map.forEach((k, v) -> { 44 | builder.withClaim(k, v); 45 | }); 46 | sign = builder.withIssuer(ISSUER).withExpiresAt(date).sign(Algorithm.HMAC256(SECRET)); 47 | } catch (UnsupportedEncodingException e) { 48 | logger.error("create jwt error:{}", e); 49 | } 50 | return sign; 51 | } 52 | 53 | public DecodedJWT verifyJWT(String token) { 54 | DecodedJWT jwt = null; 55 | try { 56 | JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SECRET)).withIssuer(ISSUER).build(); 57 | jwt = verifier.verify(token); 58 | } catch (UnsupportedEncodingException e) { 59 | logger.error("verify jwt error"); 60 | } 61 | return jwt; 62 | } 63 | 64 | public boolean isTokenExpired(DecodedJWT jwt) { 65 | Date date = jwt.getExpiresAt(); 66 | return date.before(new Date()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /service/fast/fast-api/src/main/java/com/jxph/cloud/service/fast/api/pojo/CouponTaskJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.api.pojo; 2 | 3 | import java.util.Date; 4 | 5 | public class CouponTaskJob { 6 | private Integer id; 7 | 8 | private Integer status; 9 | 10 | private Integer operaorUserId; 11 | 12 | private Date createTime; 13 | 14 | private Date updateTime; 15 | 16 | private String application; 17 | 18 | private String couponCondition; 19 | 20 | private String remark; 21 | 22 | private Integer taskManagerId; 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public Integer getStatus() { 33 | return status; 34 | } 35 | 36 | public void setStatus(Integer status) { 37 | this.status = status; 38 | } 39 | 40 | public Integer getOperaorUserId() { 41 | return operaorUserId; 42 | } 43 | 44 | public void setOperaorUserId(Integer operaorUserId) { 45 | this.operaorUserId = operaorUserId; 46 | } 47 | 48 | public Date getCreateTime() { 49 | return createTime; 50 | } 51 | 52 | public void setCreateTime(Date createTime) { 53 | this.createTime = createTime; 54 | } 55 | 56 | public Date getUpdateTime() { 57 | return updateTime; 58 | } 59 | 60 | public void setUpdateTime(Date updateTime) { 61 | this.updateTime = updateTime; 62 | } 63 | 64 | public String getApplication() { 65 | return application; 66 | } 67 | 68 | public void setApplication(String application) { 69 | this.application = application == null ? null : application.trim(); 70 | } 71 | 72 | public String getCouponCondition() { 73 | return couponCondition; 74 | } 75 | 76 | public void setCouponCondition(String couponCondition) { 77 | this.couponCondition = couponCondition == null ? null : couponCondition.trim(); 78 | } 79 | 80 | public String getRemark() { 81 | return remark; 82 | } 83 | 84 | public void setRemark(String remark) { 85 | this.remark = remark == null ? null : remark.trim(); 86 | } 87 | 88 | public Integer getTaskManagerId() { 89 | return taskManagerId; 90 | } 91 | 92 | public void setTaskManagerId(Integer taskManagerId) { 93 | this.taskManagerId = taskManagerId; 94 | } 95 | } -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/jxph/cloud/api/filter/FastRateLimitZuulFilter.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.api.filter; 2 | 3 | import com.google.common.util.concurrent.RateLimiter; 4 | import com.jxph.cloud.api.utils.LimitResponseDecorate; 5 | import com.netflix.zuul.ZuulFilter; 6 | import com.netflix.zuul.context.RequestContext; 7 | import com.netflix.zuul.exception.ZuulException; 8 | import io.micrometer.core.instrument.Metrics; 9 | import io.micrometer.core.instrument.binder.hystrix.MicrometerMetricsPublisher; 10 | import io.micrometer.core.instrument.binder.hystrix.MicrometerMetricsPublisherCommand; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; 13 | import org.springframework.core.Ordered; 14 | 15 | import java.net.URL; 16 | import java.util.Map; 17 | import java.util.concurrent.ConcurrentHashMap; 18 | 19 | /** 20 | * @author 谢秋豪 21 | * @date 2018/9/2 16:32 22 | */ 23 | public class FastRateLimitZuulFilter extends ZuulFilter { 24 | private Map map = new ConcurrentHashMap<>(); 25 | 26 | @Override 27 | public String filterType() { 28 | return FilterConstants.PRE_TYPE; 29 | } 30 | 31 | @Override 32 | public int filterOrder() { 33 | return Ordered.LOWEST_PRECEDENCE; 34 | } 35 | 36 | @Override 37 | public boolean shouldFilter() { 38 | return true; 39 | } 40 | 41 | @Override 42 | public Object run() throws ZuulException { 43 | RequestContext currentContext = RequestContext.getCurrentContext(); 44 | Object service = currentContext.get("serviceId"); 45 | if (service != null) { 46 | //RibbonRoutingFilter 47 | if (map.get(service.toString()) == null) { 48 | map.put(service.toString(), RateLimiter.create(500)); 49 | } 50 | } else { 51 | //SimpleHostRoutingFilter 52 | URL host = currentContext.getRouteHost(); 53 | if (host != null) { 54 | String url = host.toString(); 55 | if(map.get(url)==null){ 56 | map.put(url, RateLimiter.create(500)); 57 | } 58 | } 59 | } 60 | RateLimiter rateLimiter = map.get(service); 61 | if (!rateLimiter.tryAcquire()) { 62 | LimitResponseDecorate.failResponse(currentContext); 63 | } 64 | return null; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/common/exception/ExceptionHandlerAdvice.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.common.exception; 2 | 3 | import com.jxph.cloud.common.enums.ResultCodeEnum; 4 | import com.jxph.cloud.common.exception.AuthorizationException; 5 | import com.jxph.cloud.common.exception.BaseException; 6 | import com.jxph.cloud.common.utils.ResponseResult; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.validation.BindException; 9 | import org.springframework.validation.FieldError; 10 | import org.springframework.web.bind.annotation.ControllerAdvice; 11 | import org.springframework.web.bind.annotation.ExceptionHandler; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.util.List; 16 | 17 | /** 18 | * @author 谢秋豪 19 | * @date 2018/8/18 23:07 20 | */ 21 | @ControllerAdvice 22 | @Slf4j 23 | public class ExceptionHandlerAdvice { 24 | @ExceptionHandler(Exception.class) 25 | @ResponseBody 26 | public String handleException(Exception e) { 27 | log.error(e.getMessage(), e); 28 | return ""; 29 | } 30 | 31 | @ExceptionHandler(AuthorizationException.class) 32 | @ResponseBody 33 | public ResponseResult authorizationException(HttpServletResponse response, AuthorizationException e) { 34 | response.setStatus(ResultCodeEnum.FAILURE.getCode()); 35 | log.error(e.getMsg(), e); 36 | return new ResponseResult(e.getCode(), e.getMsg()); 37 | } 38 | 39 | @ExceptionHandler(BaseException.class) 40 | @ResponseBody 41 | public ResponseResult baseException(HttpServletResponse response, BaseException e) { 42 | response.setStatus(ResultCodeEnum.FAILURE.getCode()); 43 | log.error(e.getMsg(), e); 44 | return new ResponseResult(e.getCode(), e.getMsg()); 45 | } 46 | 47 | @ExceptionHandler(BindException.class) 48 | @ResponseBody 49 | public ResponseResult validationException(HttpServletResponse response, BindException error) { 50 | response.setStatus(ResultCodeEnum.FAILURE.getCode()); 51 | StringBuilder errorMessage = new StringBuilder(); 52 | List errors = error.getFieldErrors(); 53 | errors.forEach(fieldError -> { 54 | errorMessage.append(fieldError.getDefaultMessage()); 55 | }); 56 | return ResponseResult.error(errorMessage.toString()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/common/exception/ExceptionHandlerAdvice.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.common.exception; 2 | 3 | import com.jxph.cloud.common.enums.ResultCodeEnum; 4 | import com.jxph.cloud.common.exception.AuthorizationException; 5 | import com.jxph.cloud.common.exception.BaseException; 6 | import com.jxph.cloud.common.exception.UserInvalidException; 7 | import com.jxph.cloud.common.utils.ResponseResult; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.validation.BindException; 10 | import org.springframework.validation.FieldError; 11 | import org.springframework.web.bind.annotation.ControllerAdvice; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.ResponseBody; 14 | 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.util.List; 17 | 18 | /** 19 | * @author 谢秋豪 20 | * @date 2018/8/18 23:07 21 | */ 22 | @ControllerAdvice 23 | @Slf4j 24 | public class ExceptionHandlerAdvice { 25 | @ExceptionHandler(Exception.class) 26 | @ResponseBody 27 | public String handleException(Exception e) { 28 | log.error(e.getMessage(), e); 29 | return ""; 30 | } 31 | 32 | @ExceptionHandler(AuthorizationException.class) 33 | @ResponseBody 34 | public ResponseResult authorizationException(AuthorizationException e) { 35 | log.error(e.getMsg(), e); 36 | return new ResponseResult(e.getCode(), e.getMsg()); 37 | } 38 | 39 | @ExceptionHandler(BaseException.class) 40 | @ResponseBody 41 | public ResponseResult baseException(BaseException e) { 42 | log.error(e.getMsg(), e); 43 | return new ResponseResult(e.getCode(), e.getMsg()); 44 | } 45 | 46 | @ExceptionHandler(BindException.class) 47 | @ResponseBody 48 | public ResponseResult validationException(BindException error) { 49 | StringBuilder errorMessage = new StringBuilder(); 50 | List errors = error.getFieldErrors(); 51 | errors.forEach(fieldError -> { 52 | errorMessage.append(fieldError.getDefaultMessage() + " "); 53 | }); 54 | return ResponseResult.error(errorMessage.toString()); 55 | } 56 | 57 | @ExceptionHandler(UserInvalidException.class) 58 | @ResponseBody 59 | public ResponseResult userInvalidException(UserInvalidException e) { 60 | return new ResponseResult(e.getCode(),e.getMsg()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/config/datasource/MybatisConfig.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.config.datasource; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * @author 谢秋豪 8 | * @date 2018/9/1 0:07 9 | */ 10 | @Configuration 11 | @Slf4j 12 | public class MybatisConfig { 13 | /*@Autowired 14 | @Qualifier(DataSourceConstant.DATASOURCE_NAME_FIRST) 15 | private DataSource firstDB; 16 | @Autowired 17 | @Qualifier(DataSourceConstant.DATASOURCE_NAME_SECOND) 18 | private DataSource secondDB;*/ 19 | 20 | /*@Value("${mybatis.mapper-locations}") 21 | private String mapperLocations;*/ 22 | 23 | /*@Bean(name = "dynamicDataSource") 24 | @Primary 25 | public DynamicDataSource dataSource() { 26 | Map targetDataSources = new HashMap<>(); 27 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_FIRST, firstDB); 28 | targetDataSources.put(DataSourceConstant.DATASOURCE_NAME_SECOND, secondDB); 29 | return new DynamicDataSource(firstDB, targetDataSources); 30 | }*/ 31 | 32 | /* @Bean(name="sqlSessionFactory") 33 | @ConfigurationProperties(prefix = "mybatis") 34 | public SqlSessionFactoryBean sqlSessionFactoryBean() { 35 | SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); 36 | try { 37 | sqlSessionFactoryBean.setDataSource(dataSource); 38 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 39 | sqlSessionFactoryBean.setMapperLocations(resolver.getResources(mapperLocations)); 40 | //-- 加载mybatis的全局配置文件 41 | //Resource mybatisConfigXml = resolver.getResource("classpath:mybatis/mybatis-config.xml"); 42 | //sqlSessionFactoryBean.setConfigLocation(mybatisConfigXml); 43 | } catch (IOException e) { 44 | log.error("sqlSession error:{}",e); 45 | } 46 | return sqlSessionFactoryBean; 47 | } 48 | 49 | @Bean 50 | public MapperScannerConfigurer mapperScannerConfigurer() { 51 | MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); 52 | mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory"); 53 | mapperScannerConfigurer.setBasePackage("com.jxph.cloud.service.fast.server.dao"); 54 | return mapperScannerConfigurer; 55 | }*/ 56 | } 57 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/service/impl/LoginServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.service.impl; 2 | 3 | import com.jxph.cloud.common.constant.UserConstant; 4 | import com.jxph.cloud.common.exception.UserInvalidException; 5 | import com.jxph.cloud.service.auth.api.form.LoginForm; 6 | import com.jxph.cloud.service.auth.api.pojo.SysUser; 7 | import com.jxph.cloud.service.auth.api.pojo.SysUserExample; 8 | import com.jxph.cloud.service.auth.client.runner.JwtHelper; 9 | import com.jxph.cloud.service.auth.server.common.utils.MD5Helper; 10 | import com.jxph.cloud.service.auth.server.dao.SysUserMapper; 11 | import com.jxph.cloud.service.auth.server.service.LoginService; 12 | import org.apache.commons.lang.StringUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | import org.springframework.transaction.annotation.Propagation; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * @author 谢秋豪 24 | * @date 2018/9/3 22:27 25 | */ 26 | @Service 27 | public class LoginServiceImpl implements LoginService { 28 | @Autowired 29 | private JwtHelper jwtHelper; 30 | @Autowired 31 | private SysUserMapper sysUserMapper; 32 | 33 | @Override 34 | @Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class) 35 | public String login(LoginForm loginForm) throws UserInvalidException { 36 | SysUserExample sysUserExample = new SysUserExample(); 37 | SysUserExample.Criteria criteria = sysUserExample.createCriteria(); 38 | criteria.andUsernameEqualTo(loginForm.getUsername()); 39 | List sysUsers = sysUserMapper.selectByExample(sysUserExample); 40 | if (sysUsers.isEmpty()) { 41 | throw new UserInvalidException("用户名或密码不正确"); 42 | } 43 | SysUser sysUser = sysUsers.get(0); 44 | if(!StringUtils.equals(sysUser.getPassword(),MD5Helper.encryPassword(loginForm.getPassword(),sysUser.getSalt()))){ 45 | throw new UserInvalidException("用户名或密码不正确"); 46 | } 47 | Map map = new HashMap<>(); 48 | map.put(UserConstant.CONTEXT_KEY_USERNAME, sysUser.getUsername()); 49 | map.put(UserConstant.CONTEXT_KEY_USER_ID, sysUser.getUserId().toString()); 50 | map.put(UserConstant.CONTEXT_KEY_USER_IS_LOGIN, "true"); 51 | String token = jwtHelper.createJWT(map); 52 | return token; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/resources/mybatis-generator.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 47 |
48 |
49 |
-------------------------------------------------------------------------------- /service/fast/fast-server/src/main/resources/mybatis-generator.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 47 |
48 |
49 |
-------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/utils/RestUtil.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.utils; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.http.HttpEntity; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | 15 | public class RestUtil { 16 | 17 | static Logger log = LoggerFactory.getLogger(RestUtil.class); 18 | 19 | /** 20 | * 发送post 请求 21 | * 22 | * @param restTemplate 23 | * @param url 24 | * @param param 25 | * @param responseType 26 | * @param 27 | * @return 28 | */ 29 | public static T postJSON(RestTemplate restTemplate, String url, Object param, Class responseType) { 30 | HttpEntity formEntity = makePostJSONEntiry(param); 31 | T result = restTemplate.postForObject(url, formEntity, responseType); 32 | log.info("rest-post-json 响应信息:{}", JSONUtils.toJsonString(result)); 33 | return result; 34 | } 35 | 36 | /** 37 | * 生成json形式的请求头 38 | * 39 | * @param param 40 | * @return 41 | */ 42 | public static HttpEntity makePostJSONEntiry(Object param) { 43 | HttpHeaders headers = new HttpHeaders(); 44 | headers.setContentType(MediaType.APPLICATION_JSON_UTF8); 45 | headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); 46 | HttpEntity formEntity = new HttpEntity( 47 | JSONUtils.toJsonString(param), headers); 48 | log.info("rest-post-json-请求参数:{}", formEntity.toString()); 49 | return formEntity; 50 | } 51 | 52 | 53 | public static HttpEntity makePostTextEntiry(Map param) { 54 | HttpHeaders headers = new HttpHeaders(); 55 | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); 56 | headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); 57 | HttpEntity formEntity = new HttpEntity( 58 | makeGetParamContent(param), headers); 59 | log.info("rest-post-text-请求参数:{}", formEntity.toString()); 60 | return formEntity; 61 | } 62 | 63 | 64 | /** 65 | * 生成Get请求内容 66 | * 67 | * @param param 68 | * @param excluedes 69 | * @return 70 | */ 71 | public static String makeGetParamContent(Map param, String... excluedes) { 72 | StringBuilder content = new StringBuilder(); 73 | List excludeKeys = Arrays.asList(excluedes); 74 | param.forEach((key, v) -> { 75 | content.append(key).append("=").append(v).append("&"); 76 | }); 77 | if (content.length() > 0) { 78 | content.deleteCharAt(content.length() - 1); 79 | } 80 | return content.toString(); 81 | } 82 | } -------------------------------------------------------------------------------- /service/auth/auth-api/src/main/java/com/jxph/cloud/service/auth/api/pojo/SysUser.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.api.pojo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import javax.validation.constraints.NotBlank; 7 | import java.util.Date; 8 | 9 | @ApiModel(value= "用户") 10 | public class SysUser { 11 | @ApiModelProperty(value = "用户编号") 12 | private Long userId; 13 | 14 | @ApiModelProperty(value = "手机号") 15 | @NotBlank(message = "用户名不能为空") 16 | private String username; 17 | 18 | @ApiModelProperty(value = "密码") 19 | @NotBlank(message = "密码不能为空") 20 | private String password; 21 | 22 | @ApiModelProperty(value = "盐") 23 | private String salt; 24 | 25 | @ApiModelProperty(value = "邮箱") 26 | private String email; 27 | 28 | @ApiModelProperty(value = "手机号") 29 | private String mobile; 30 | 31 | @ApiModelProperty(value = "状态") 32 | private Byte status; 33 | 34 | @ApiModelProperty(value = "创建者ID") 35 | private Long createUserId; 36 | 37 | @ApiModelProperty(value = "创建时间") 38 | private Date createTime; 39 | 40 | public Long getUserId() { 41 | return userId; 42 | } 43 | 44 | public void setUserId(Long userId) { 45 | this.userId = userId; 46 | } 47 | 48 | public String getUsername() { 49 | return username; 50 | } 51 | 52 | public void setUsername(String username) { 53 | this.username = username == null ? null : username.trim(); 54 | } 55 | 56 | public String getPassword() { 57 | return password; 58 | } 59 | 60 | public void setPassword(String password) { 61 | this.password = password == null ? null : password.trim(); 62 | } 63 | 64 | public String getSalt() { 65 | return salt; 66 | } 67 | 68 | public void setSalt(String salt) { 69 | this.salt = salt == null ? null : salt.trim(); 70 | } 71 | 72 | public String getEmail() { 73 | return email; 74 | } 75 | 76 | public void setEmail(String email) { 77 | this.email = email == null ? null : email.trim(); 78 | } 79 | 80 | public String getMobile() { 81 | return mobile; 82 | } 83 | 84 | public void setMobile(String mobile) { 85 | this.mobile = mobile == null ? null : mobile.trim(); 86 | } 87 | 88 | public Byte getStatus() { 89 | return status; 90 | } 91 | 92 | public void setStatus(Byte status) { 93 | this.status = status; 94 | } 95 | 96 | public Long getCreateUserId() { 97 | return createUserId; 98 | } 99 | 100 | public void setCreateUserId(Long createUserId) { 101 | this.createUserId = createUserId; 102 | } 103 | 104 | public Date getCreateTime() { 105 | return createTime; 106 | } 107 | 108 | public void setCreateTime(Date createTime) { 109 | this.createTime = createTime; 110 | } 111 | } -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.service.impl; 2 | 3 | 4 | import com.jxph.cloud.common.constant.BrokerMessageStatusConstant; 5 | import com.jxph.cloud.common.utils.DateUtils; 6 | import com.jxph.cloud.common.utils.JSONUtils; 7 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLog; 8 | import com.jxph.cloud.service.fast.api.pojo.BrokerMessageLogExample; 9 | import com.jxph.cloud.service.fast.api.pojo.TOrder; 10 | import com.jxph.cloud.service.fast.server.dao.BrokerMessageLogMapper; 11 | import com.jxph.cloud.service.fast.server.dao.TOrderMapper; 12 | import com.jxph.cloud.service.fast.server.mq.OrderSender; 13 | import com.jxph.cloud.service.fast.server.service.OrderService; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Propagation; 17 | import org.springframework.transaction.annotation.Transactional; 18 | 19 | import java.util.Date; 20 | 21 | /** 22 | * @author 谢秋豪 23 | * @date 2018/8/30 20:37 24 | */ 25 | @Service 26 | public class OrderServiceImpl implements OrderService { 27 | @Autowired 28 | private TOrderMapper orderMapper; 29 | @Autowired 30 | private BrokerMessageLogMapper brokerMessageLogMapper; 31 | @Autowired 32 | private OrderSender orderSender; 33 | 34 | @Override 35 | @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class) 36 | public void createOrder(TOrder order) { 37 | orderMapper.insert(order); 38 | Date date = new Date(); 39 | BrokerMessageLog brokerMessageLog = new BrokerMessageLog(); 40 | brokerMessageLog.setMessageId(order.getMessageId()); 41 | brokerMessageLog.setMessage(JSONUtils.toJsonString(order)); 42 | brokerMessageLog.setUpdateTime(new Date()); 43 | brokerMessageLog.setCreateTime(new Date()); 44 | brokerMessageLog.setNextRetry(DateUtils.addDateMinutes(date, BrokerMessageStatusConstant.ORDER_TIMEOUT)); 45 | brokerMessageLog.setStatus(BrokerMessageStatusConstant.ORDER_SENDING); 46 | brokerMessageLogMapper.insertSelective(brokerMessageLog); 47 | orderSender.sendOrder(order); 48 | } 49 | 50 | @Override 51 | @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class) 52 | public void confirmMessage(String messageId) { 53 | BrokerMessageLog brokerMessageLog = new BrokerMessageLog(); 54 | brokerMessageLog.setStatus(BrokerMessageStatusConstant.ORDER_SEND_SUCCESS); 55 | brokerMessageLog.setUpdateTime(new Date()); 56 | BrokerMessageLogExample brokerMessageLogExample = new BrokerMessageLogExample(); 57 | BrokerMessageLogExample.Criteria criteria = brokerMessageLogExample.createCriteria(); 58 | criteria.andMessageIdEqualTo(messageId); 59 | brokerMessageLogMapper.updateByExampleSelective(brokerMessageLog,brokerMessageLogExample); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | root 7 | com.jxph.cloud 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.jxph.cloud 13 | api-gateway 14 | 15 | 16 | 17 | com.jxph.cloud 18 | common 19 | 1.0-SNAPSHOT 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-actuator 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | org.apache.httpcomponents 32 | httpclient 33 | 34 | 35 | org.projectlombok 36 | lombok 37 | 1.16.20 38 | provided 39 | 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-netflix-eureka-client 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-netflix-hystrix 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix-dashboard 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-ribbon 56 | 57 | 61 | 62 | org.springframework.cloud 63 | spring-cloud-starter-netflix-zuul 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-maven-plugin 73 | 74 | true 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /service/auth/auth-client/src/main/java/com/jxph/cloud/service/auth/client/interceptor/AuthorizationInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.client.interceptor; 2 | 3 | import com.auth0.jwt.interfaces.Claim; 4 | import com.auth0.jwt.interfaces.DecodedJWT; 5 | import com.jxph.cloud.common.annotation.Login; 6 | import com.jxph.cloud.common.constant.UserConstant; 7 | import com.jxph.cloud.common.context.UserContextHolder; 8 | import com.jxph.cloud.common.exception.AuthorizationException; 9 | import com.jxph.cloud.service.auth.client.runner.JwtHelper; 10 | import org.apache.commons.lang.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.web.method.HandlerMethod; 14 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.util.Map; 19 | 20 | /** 21 | * @author 谢秋豪 22 | * @date 2018/9/1 11:50 23 | */ 24 | public class AuthorizationInterceptor extends HandlerInterceptorAdapter { 25 | 26 | @Autowired 27 | private JwtHelper jwtHelper; 28 | 29 | @Override 30 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 31 | Login annotation; 32 | if (handler instanceof HandlerMethod) { 33 | annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class); 34 | } else { 35 | return true; 36 | } 37 | if (annotation == null) { 38 | return true; 39 | } 40 | String token = request.getHeader(jwtHelper.getHeader()); 41 | if (StringUtils.isBlank(token)) { 42 | throw new AuthorizationException(jwtHelper.getHeader() + "不能为空", HttpStatus.UNAUTHORIZED.value()); 43 | } 44 | DecodedJWT jwt = jwtHelper.verifyJWT(token); 45 | Map claims = jwt.getClaims(); 46 | if (claims == null || jwtHelper.isTokenExpired(jwt)) { 47 | throw new AuthorizationException(jwtHelper.getHeader() + "失效,请重新登录", HttpStatus.UNAUTHORIZED.value()); 48 | } 49 | if(!StringUtils.equals("true",claims.get(UserConstant.CONTEXT_KEY_USER_IS_LOGIN).asString())){ 50 | throw new AuthorizationException("用户未登录,请登录", HttpStatus.UNAUTHORIZED.value()); 51 | } 52 | if(claims.get(UserConstant.CONTEXT_KEY_USER_ID)!=null){ 53 | UserContextHolder.set(UserConstant.CONTEXT_KEY_USER_ID, claims.get(UserConstant.CONTEXT_KEY_USER_ID).asString()); 54 | } 55 | if(claims.get(UserConstant.CONTEXT_KEY_USER_NAME)!=null){ 56 | UserContextHolder.set(UserConstant.CONTEXT_KEY_USER_NAME, claims.get(UserConstant.CONTEXT_KEY_USER_NAME).asString()); 57 | } 58 | if(claims.get(UserConstant.CONTEXT_KEY_USERNAME)!=null){ 59 | UserContextHolder.set(UserConstant.CONTEXT_KEY_USERNAME, claims.get(UserConstant.CONTEXT_KEY_USERNAME).asString()); 60 | } 61 | return super.preHandle(request, response, handler); 62 | } 63 | 64 | @Override 65 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 66 | UserContextHolder.remove(); 67 | super.afterCompletion(request, response, handler, ex); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /service/fast/fast-server/src/main/java/com/jxph/cloud/service/fast/server/task/job/CouponJob.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.fast.server.task.job; 2 | 3 | import com.jxph.cloud.common.exception.BaseException; 4 | import com.jxph.cloud.service.fast.api.pojo.CouponTaskJob; 5 | import com.jxph.cloud.service.fast.server.common.constant.CouponTaskJobStatusConstant; 6 | import com.jxph.cloud.service.fast.server.config.datasource.DataSourceContextHolder; 7 | import com.jxph.cloud.service.fast.server.service.CouponTaskService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Qualifier; 10 | import org.springframework.stereotype.Component; 11 | 12 | import java.util.List; 13 | import java.util.concurrent.Executor; 14 | 15 | /** 16 | * @author 谢秋豪 17 | * @date 2018/9/2 21:58 18 | */ 19 | @Component 20 | public class CouponJob implements TaskSaveManagerInfoJob { 21 | @Autowired 22 | private CouponTaskService couponTaskService; 23 | @Autowired 24 | @Qualifier("myTaskExecutePool") 25 | private Executor taskExecutePool; 26 | 27 | private int couponThreadCounts = 10; 28 | 29 | private int taskManagerId; 30 | 31 | @Override 32 | public void processImpl() { 33 | List list = couponTaskService.selectCreationCouponJob(); 34 | int len = list.size() / couponThreadCounts; 35 | String dataSource = DataSourceContextHolder.getDataSource(); 36 | if (len == 0) { 37 | taskExecutePool.execute(new CouponThread(list,dataSource)); 38 | } else { 39 | for (int i = 0; i < couponThreadCounts; i++) { 40 | List subList = list.subList(i * len, len * (i + 1) > list.size() ? list.size() : len * (i + 1)); 41 | taskExecutePool.execute(new CouponThread(subList,dataSource)); 42 | } 43 | } 44 | } 45 | 46 | @Override 47 | public void setTaskManagerId(int id) { 48 | this.taskManagerId = id; 49 | } 50 | 51 | class CouponThread extends Thread { 52 | private List couponTaskJobs; 53 | private String dataSource; 54 | 55 | public CouponThread(List couponTaskJobs,String dataSource) { 56 | this.couponTaskJobs = couponTaskJobs; 57 | this.dataSource = dataSource; 58 | } 59 | 60 | @Override 61 | public void run() { 62 | try { 63 | DataSourceContextHolder.setDataSource(dataSource); 64 | couponTaskJobs.forEach(couponTaskJob -> { 65 | couponTaskJob.setTaskManagerId(taskManagerId); 66 | couponTaskService.updateCouponTask(couponTaskJob, CouponTaskJobStatusConstant.JOB_EXECUTION); 67 | try { 68 | //业务处理 69 | couponTaskService.updateCouponTask(couponTaskJob, CouponTaskJobStatusConstant.JOB_SUCCESS); 70 | } catch (Exception e) { 71 | couponTaskService.updateCouponTask(couponTaskJob, CouponTaskJobStatusConstant.JOB_FAILURE, e.toString()); 72 | } 73 | }); 74 | } catch (Exception e){ 75 | throw new BaseException("异常"); 76 | } finally { 77 | DataSourceContextHolder.clearDataSource(); 78 | } 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /service/auth/auth-server/src/main/java/com/jxph/cloud/service/auth/server/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.service.auth.server.service.impl; 2 | 3 | import com.jxph.cloud.common.exception.UserInvalidException; 4 | import com.jxph.cloud.common.utils.JSONUtils; 5 | import com.jxph.cloud.service.auth.api.pojo.SysUser; 6 | import com.jxph.cloud.service.auth.api.pojo.SysUserExample; 7 | import com.jxph.cloud.service.auth.server.common.constant.RedisConstant; 8 | import com.jxph.cloud.service.auth.api.common.enums.SysUserStatusEnums; 9 | import com.jxph.cloud.service.auth.server.common.utils.MD5Helper; 10 | import com.jxph.cloud.service.auth.server.dao.SysUserMapper; 11 | import com.jxph.cloud.service.auth.server.service.UserService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.data.redis.core.RedisTemplate; 14 | import org.springframework.stereotype.Service; 15 | import org.springframework.transaction.annotation.Propagation; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | import java.util.Date; 19 | import java.util.List; 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * @author 谢秋豪 24 | * @date 2018/9/3 22:04 25 | */ 26 | @Service 27 | public class UserServiceImpl implements UserService { 28 | @Autowired 29 | private SysUserMapper sysUserMapper; 30 | @Autowired 31 | private RedisTemplate redisTemplate; 32 | 33 | @Override 34 | @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) 35 | public Long addUser(SysUser sysUser) throws UserInvalidException { 36 | SysUserExample sysUserExample = new SysUserExample(); 37 | SysUserExample.Criteria criteria = sysUserExample.createCriteria(); 38 | criteria.andUsernameEqualTo(sysUser.getUsername()); 39 | List sysUsers = sysUserMapper.selectByExample(sysUserExample); 40 | if (!sysUsers.isEmpty()) { 41 | throw new UserInvalidException("该用户名已存在"); 42 | } 43 | String uuid = MD5Helper.getUUID(); 44 | sysUser.setSalt(uuid); 45 | sysUser.setStatus(SysUserStatusEnums.NORMAL.getStatus()); 46 | sysUser.setCreateTime(new Date()); 47 | String password = MD5Helper.encryPassword(sysUser.getPassword(), uuid); 48 | sysUser.setPassword(password); 49 | sysUserMapper.insertSelective(sysUser); 50 | return sysUser.getUserId(); 51 | } 52 | 53 | @Override 54 | @Transactional(propagation = Propagation.NOT_SUPPORTED, rollbackFor = Exception.class) 55 | public SysUser getUserByUserId(Long userId) { 56 | Boolean hasKey = redisTemplate.hasKey(RedisConstant.REIDS_USER_PREFIX + userId); 57 | if (hasKey) { 58 | return getObjectByRedis(userId.toString(), SysUser.class); 59 | } 60 | getObjectByRedis(userId.toString(), SysUser.class); 61 | SysUser user = sysUserMapper.selectByPrimaryKey(userId); 62 | if(user!=null){ 63 | user.setPassword(null); 64 | } 65 | setObjectToRedis(userId.toString(), user); 66 | return user; 67 | } 68 | 69 | private T getObjectByRedis(String objectKey, Class clazz) { 70 | Object value = redisTemplate.opsForValue().get(RedisConstant.REIDS_USER_PREFIX + objectKey); 71 | if (value != null) { 72 | redisTemplate.expire(RedisConstant.REIDS_USER_PREFIX + objectKey, RedisConstant.REDIS_USER_EXPIRE, TimeUnit.SECONDS); 73 | return JSONUtils.parse(value.toString(), clazz); 74 | } 75 | return null; 76 | } 77 | 78 | private void setObjectToRedis(String objectKey, Object object) { 79 | if (object == null) { 80 | redisTemplate.opsForValue().set(RedisConstant.REIDS_USER_PREFIX + objectKey, null); 81 | redisTemplate.expire(RedisConstant.REIDS_USER_PREFIX + objectKey, RedisConstant.REDIS_USER_NULL_EXPIRE, TimeUnit.SECONDS); 82 | } else { 83 | redisTemplate.opsForValue().set(RedisConstant.REIDS_USER_PREFIX + objectKey, JSONUtils.toJsonString(object)); 84 | redisTemplate.expire(RedisConstant.REIDS_USER_PREFIX + objectKey, RedisConstant.REDIS_USER_EXPIRE, TimeUnit.SECONDS); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/xss/XssHttpServletRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.xss; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | import org.apache.commons.lang.StringUtils; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.MediaType; 7 | 8 | import javax.servlet.ReadListener; 9 | import javax.servlet.ServletInputStream; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletRequestWrapper; 12 | import java.io.ByteArrayInputStream; 13 | import java.io.IOException; 14 | import java.util.LinkedHashMap; 15 | import java.util.Map; 16 | 17 | /** 18 | * @author 谢秋豪 19 | * @date 2018/8/18 23:38 20 | */ 21 | public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { 22 | //没被包装过的HttpServletRequest(特殊场景,需要自己过滤) 23 | HttpServletRequest orgRequest; 24 | //html过滤 25 | private final static HTMLFilter htmlFilter = new HTMLFilter(); 26 | 27 | public XssHttpServletRequestWrapper(HttpServletRequest request) { 28 | super(request); 29 | orgRequest = request; 30 | } 31 | 32 | @Override 33 | public ServletInputStream getInputStream() throws IOException { 34 | //非json类型,直接返回 35 | if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){ 36 | return super.getInputStream(); 37 | } 38 | 39 | //为空,直接返回 40 | String json = IOUtils.toString(super.getInputStream(), "utf-8"); 41 | if (StringUtils.isBlank(json)) { 42 | return super.getInputStream(); 43 | } 44 | 45 | //xss过滤 46 | json = xssEncode(json); 47 | final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); 48 | return new ServletInputStream() { 49 | @Override 50 | public boolean isFinished() { 51 | return true; 52 | } 53 | 54 | @Override 55 | public boolean isReady() { 56 | return true; 57 | } 58 | 59 | @Override 60 | public void setReadListener(ReadListener readListener) { 61 | 62 | } 63 | 64 | @Override 65 | public int read() throws IOException { 66 | return bis.read(); 67 | } 68 | }; 69 | } 70 | 71 | @Override 72 | public String getParameter(String name) { 73 | String value = super.getParameter(xssEncode(name)); 74 | if (StringUtils.isNotBlank(value)) { 75 | value = xssEncode(value); 76 | } 77 | return value; 78 | } 79 | 80 | @Override 81 | public String[] getParameterValues(String name) { 82 | String[] parameters = super.getParameterValues(name); 83 | if (parameters == null || parameters.length == 0) { 84 | return null; 85 | } 86 | 87 | for (int i = 0; i < parameters.length; i++) { 88 | parameters[i] = xssEncode(parameters[i]); 89 | } 90 | return parameters; 91 | } 92 | 93 | @Override 94 | public Map getParameterMap() { 95 | Map map = new LinkedHashMap<>(); 96 | Map parameters = super.getParameterMap(); 97 | for (String key : parameters.keySet()) { 98 | String[] values = parameters.get(key); 99 | for (int i = 0; i < values.length; i++) { 100 | values[i] = xssEncode(values[i]); 101 | } 102 | map.put(key, values); 103 | } 104 | return map; 105 | } 106 | 107 | @Override 108 | public String getHeader(String name) { 109 | String value = super.getHeader(xssEncode(name)); 110 | if (StringUtils.isNotBlank(value)) { 111 | value = xssEncode(value); 112 | } 113 | return value; 114 | } 115 | 116 | private String xssEncode(String input) { 117 | return htmlFilter.filter(input); 118 | } 119 | 120 | /** 121 | * 获取最原始的request 122 | */ 123 | public HttpServletRequest getOrgRequest() { 124 | return orgRequest; 125 | } 126 | 127 | /** 128 | * 获取最原始的request 129 | */ 130 | public static HttpServletRequest getOrgRequest(HttpServletRequest request) { 131 | if (request instanceof XssHttpServletRequestWrapper) { 132 | return ((XssHttpServletRequestWrapper) request).getOrgRequest(); 133 | } 134 | 135 | return request; 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /common/src/main/java/com/jxph/cloud/common/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.jxph.cloud.common.utils; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.joda.time.DateTime; 5 | import org.joda.time.LocalDate; 6 | import org.joda.time.format.DateTimeFormat; 7 | import org.joda.time.format.DateTimeFormatter; 8 | 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author 谢秋豪 14 | * @date 2018/8/18 23:30 15 | */ 16 | public class DateUtils { 17 | /** 18 | * 时间格式(yyyy-MM-dd) 19 | */ 20 | public final static String DATE_PATTERN = "yyyy-MM-dd"; 21 | /** 22 | * 时间格式(yyyy-MM-dd HH:mm:ss) 23 | */ 24 | public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; 25 | 26 | /** 27 | * 日期格式化 日期格式为:yyyy-MM-dd 28 | * 29 | * @param date 日期 30 | * @return 返回yyyy-MM-dd格式日期 31 | */ 32 | public static String format(Date date) { 33 | return format(date, DATE_PATTERN); 34 | } 35 | 36 | /** 37 | * 日期格式化 日期格式为:yyyy-MM-dd 38 | * 39 | * @param date 日期 40 | * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN 41 | * @return 返回yyyy-MM-dd格式日期 42 | */ 43 | public static String format(Date date, String pattern) { 44 | if (date != null) { 45 | SimpleDateFormat df = new SimpleDateFormat(pattern); 46 | return df.format(date); 47 | } 48 | return null; 49 | } 50 | 51 | /** 52 | * 字符串转换成日期 53 | * 54 | * @param strDate 日期字符串 55 | * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN 56 | */ 57 | public static Date stringToDate(String strDate, String pattern) { 58 | if (StringUtils.isBlank(strDate)) { 59 | return null; 60 | } 61 | 62 | DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); 63 | return fmt.parseLocalDateTime(strDate).toDate(); 64 | } 65 | 66 | /** 67 | * 根据周数,获取开始日期、结束日期 68 | * 69 | * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周 70 | * @return 返回date[0]开始日期、date[1]结束日期 71 | */ 72 | public static Date[] getWeekStartAndEnd(int week) { 73 | DateTime dateTime = new DateTime(); 74 | LocalDate date = new LocalDate(dateTime.plusWeeks(week)); 75 | 76 | date = date.dayOfWeek().withMinimumValue(); 77 | Date beginDate = date.toDate(); 78 | Date endDate = date.plusDays(6).toDate(); 79 | return new Date[]{beginDate, endDate}; 80 | } 81 | 82 | /** 83 | * 对日期的【秒】进行加/减 84 | * 85 | * @param date 日期 86 | * @param seconds 秒数,负数为减 87 | * @return 加/减几秒后的日期 88 | */ 89 | public static Date addDateSeconds(Date date, int seconds) { 90 | DateTime dateTime = new DateTime(date); 91 | return dateTime.plusSeconds(seconds).toDate(); 92 | } 93 | 94 | /** 95 | * 对日期的【分钟】进行加/减 96 | * 97 | * @param date 日期 98 | * @param minutes 分钟数,负数为减 99 | * @return 加/减几分钟后的日期 100 | */ 101 | public static Date addDateMinutes(Date date, int minutes) { 102 | DateTime dateTime = new DateTime(date); 103 | return dateTime.plusMinutes(minutes).toDate(); 104 | } 105 | 106 | /** 107 | * 对日期的【小时】进行加/减 108 | * 109 | * @param date 日期 110 | * @param hours 小时数,负数为减 111 | * @return 加/减几小时后的日期 112 | */ 113 | public static Date addDateHours(Date date, int hours) { 114 | DateTime dateTime = new DateTime(date); 115 | return dateTime.plusHours(hours).toDate(); 116 | } 117 | 118 | /** 119 | * 对日期的【天】进行加/减 120 | * 121 | * @param date 日期 122 | * @param days 天数,负数为减 123 | * @return 加/减几天后的日期 124 | */ 125 | public static Date addDateDays(Date date, int days) { 126 | DateTime dateTime = new DateTime(date); 127 | return dateTime.plusDays(days).toDate(); 128 | } 129 | 130 | /** 131 | * 对日期的【周】进行加/减 132 | * 133 | * @param date 日期 134 | * @param weeks 周数,负数为减 135 | * @return 加/减几周后的日期 136 | */ 137 | public static Date addDateWeeks(Date date, int weeks) { 138 | DateTime dateTime = new DateTime(date); 139 | return dateTime.plusWeeks(weeks).toDate(); 140 | } 141 | 142 | /** 143 | * 对日期的【月】进行加/减 144 | * 145 | * @param date 日期 146 | * @param months 月数,负数为减 147 | * @return 加/减几月后的日期 148 | */ 149 | public static Date addDateMonths(Date date, int months) { 150 | DateTime dateTime = new DateTime(date); 151 | return dateTime.plusMonths(months).toDate(); 152 | } 153 | 154 | /** 155 | * 对日期的【年】进行加/减 156 | * 157 | * @param date 日期 158 | * @param years 年数,负数为减 159 | * @return 加/减几年后的日期 160 | */ 161 | public static Date addDateYears(Date date, int years) { 162 | DateTime dateTime = new DateTime(date); 163 | return dateTime.plusYears(years).toDate(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /service/auth/auth-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auth 7 | com.jxph.cloud.service 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.jxph.cloud.service.auth 13 | auth-server 14 | 15 | 16 | 17 | com.jxph.cloud.service.auth 18 | auth-api 19 | 1.0-SNAPSHOT 20 | 21 | 22 | com.jxph.cloud.service.auth 23 | auth-client 24 | 1.0-SNAPSHOT 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-amqp 41 | 42 | 43 | 44 | org.projectlombok 45 | lombok 46 | 1.16.20 47 | provided 48 | 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-starter-netflix-eureka-client 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-starter-netflix-hystrix 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-starter-netflix-hystrix-dashboard 61 | 62 | 63 | org.springframework.cloud 64 | spring-cloud-starter-netflix-ribbon 65 | 66 | 67 | org.springframework.cloud 68 | spring-cloud-starter-openfeign 69 | 70 | 71 | 72 | 73 | ${project.artifactId} 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | 79 | true 80 | 81 | 82 | 83 | 84 | org.mybatis.generator 85 | mybatis-generator-maven-plugin 86 | 1.3.5 87 | 88 | 89 | mysql 90 | mysql-connector-java 91 | 5.1.39 92 | 93 | 94 | com.xxg 95 | mbg-limit-plugin 96 | 1.0.0 97 | 98 | 99 | 100 | 101 | Generate MyBatis Artifacts 102 | package 103 | 104 | generate 105 | 106 | 107 | 108 | 109 | 110 | true 111 | 112 | false 113 | 114 | 115 | src/main/resources/mybatis-generator.xml 116 | 117 | 118 | 119 | 120 | 121 | --------------------------------------------------------------------------------