├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md └── workflows │ └── main.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── doc ├── file │ ├── common.yaml │ ├── db1.yaml │ ├── feignhystrix.yaml │ ├── mail.yaml │ ├── mybatis.yaml │ ├── oauth2db.yaml │ ├── oauth_token.yaml │ ├── redis.yaml │ └── zipkindb.yaml ├── img │ ├── access_token.JPG │ ├── auth.JPG │ ├── code.JPG │ ├── oauthLogin.JPG │ ├── swagger.png │ └── token.JPG └── sql │ ├── demo │ └── sys_logistics.sql │ ├── log │ └── loginfo.sql │ ├── sso │ ├── oauth.sql │ └── user.sql │ └── zipkin │ └── zipkin-init.sql ├── javayh-demo ├── javayh-demo-api │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── api │ │ │ ├── ApiApplication.java │ │ │ ├── conf │ │ │ └── ResourceServerConfiguration.java │ │ │ ├── sys │ │ │ ├── controller │ │ │ │ └── SysLogisticsController.java │ │ │ ├── dao │ │ │ │ └── SysLogisticsMapper.java │ │ │ ├── pojo │ │ │ │ ├── SysLogistics.java │ │ │ │ └── dto │ │ │ │ │ └── SysLogisticsDTO.java │ │ │ └── service │ │ │ │ ├── ISysLogisticsService.java │ │ │ │ └── impl │ │ │ │ └── SysLogisticsServiceImpl.java │ │ │ └── web │ │ │ └── ApiController.java │ │ └── resources │ │ ├── bootstrap.yml │ │ └── mapper │ │ └── sys │ │ └── SysLogisticsMapper.xml ├── javayh-demo-common │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ ├── service │ │ │ ├── DemoFallback.java │ │ │ └── DemoService.java │ │ │ └── web │ │ │ ├── Demo2Controller.java │ │ │ └── DemoCtroller.java │ │ └── resources │ │ └── bootstrap.yml ├── javayh-demo-config │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── config │ │ │ ├── ConfigApplication.java │ │ │ └── web │ │ │ └── DemoCtroller.java │ │ └── resources │ │ └── bootstrap.yml ├── javayh-demo-feign │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── feign │ │ │ ├── FeignApplication.java │ │ │ ├── conf │ │ │ ├── FeignConfig.java │ │ │ ├── ResourceServerConfiguration.java │ │ │ └── TokenFeignClientInterceptor.java │ │ │ ├── service │ │ │ ├── impl │ │ │ │ └── DemoFeignServiceImpl.java │ │ │ └── resource │ │ │ │ └── UserService.java │ │ │ └── web │ │ │ └── FeignCtr.java │ │ └── resources │ │ └── bootstrap.yml ├── javayh-demo-file │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── file │ │ │ └── FileApplication.java │ │ └── resources │ │ └── bootstrap.yml ├── javayh-demo-mail │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── mail │ │ │ ├── MailApplication.java │ │ │ └── web │ │ │ └── MailController.java │ │ └── resources │ │ ├── bootstrap.yml │ │ └── templates │ │ └── HelloMail.html └── pom.xml ├── javayh-dependencies ├── javayh-common-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── common │ │ │ ├── annotation │ │ │ └── JavayhBootApplication.java │ │ │ ├── config │ │ │ ├── JacksonConfig.java │ │ │ └── MyCommandLineRunner.java │ │ │ ├── constant │ │ │ ├── ConstantUtils.java │ │ │ └── EncryptConstantUtils.java │ │ │ ├── encrypt │ │ │ ├── aes │ │ │ │ └── AESUtil.java │ │ │ ├── key │ │ │ │ └── DataKeyGenerator.java │ │ │ ├── md5 │ │ │ │ └── MD5Util.java │ │ │ ├── rsa │ │ │ │ ├── HexUtil.java │ │ │ │ ├── RSAEncrypt.java │ │ │ │ └── RSAUtil.java │ │ │ └── sha │ │ │ │ └── Sha256.java │ │ │ ├── entity │ │ │ └── BaseEntity.java │ │ │ ├── exception │ │ │ ├── BaseException.java │ │ │ ├── GlobalExceptionHandler.java │ │ │ ├── annotation │ │ │ │ └── EnableAutoException.java │ │ │ ├── business │ │ │ │ └── BusinessException.java │ │ │ ├── controller │ │ │ │ └── ControllerException.java │ │ │ ├── dao │ │ │ │ └── DataAccessException.java │ │ │ ├── hystrix │ │ │ │ └── HytrixException.java │ │ │ └── service │ │ │ │ └── ServiceException.java │ │ │ ├── feign │ │ │ ├── FeignClientOkHttpConfiguration.java │ │ │ ├── FeignExceptionConfig.java │ │ │ ├── FeignFailResult.java │ │ │ └── GlobalFeignConfig.java │ │ │ ├── filter │ │ │ └── SensitiveWordFilter.java │ │ │ ├── hash │ │ │ └── ConsistentHashing.java │ │ │ ├── i18n │ │ │ ├── I18nResponseBodyAdvice.java │ │ │ ├── annotation │ │ │ │ └── EnableAutoInternationalization.java │ │ │ └── config │ │ │ │ ├── I18nProperties.java │ │ │ │ └── InternationalConfig.java │ │ │ ├── mdc │ │ │ └── MdcThreadPoolTaskExecutor.java │ │ │ ├── package-info.java │ │ │ ├── qrcode │ │ │ └── QRCodeGenerator.java │ │ │ ├── result │ │ │ ├── MessageBody.java │ │ │ └── ResultData.java │ │ │ ├── selector │ │ │ ├── ExceptionSelector.java │ │ │ ├── SpringI18nSelector.java │ │ │ └── SpringSelector.java │ │ │ └── util │ │ │ ├── DateUtils.java │ │ │ ├── IAction.java │ │ │ ├── IPUtils.java │ │ │ ├── MapUtils.java │ │ │ ├── NumberUtil.java │ │ │ ├── RandomUtil.java │ │ │ ├── Reflections.java │ │ │ ├── StringUtils.java │ │ │ ├── WebUtil.java │ │ │ ├── bean │ │ │ └── BeanUtils.java │ │ │ ├── file │ │ │ └── FileUtils.java │ │ │ ├── id │ │ │ ├── IdGen.java │ │ │ └── SnowflakeIdWorker.java │ │ │ ├── json │ │ │ └── JsonUtils.java │ │ │ ├── log │ │ │ └── Log.java │ │ │ ├── servlet │ │ │ ├── RequestHandleUtil.java │ │ │ └── RequestUtils.java │ │ │ ├── spring │ │ │ └── SpringUtils.java │ │ │ └── task │ │ │ └── ThreadTaskUtils.java │ │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ ├── SensitiveWord.txt │ │ ├── banner.txt │ │ └── i18n │ │ ├── common │ │ ├── common.properties │ │ ├── common_en_US.properties │ │ └── common_zh_CN.properties │ │ ├── login │ │ ├── login.properties │ │ ├── login_en_US.properties │ │ └── login_zh_CN.properties │ │ └── validation │ │ ├── validation.properties │ │ ├── validation_en_US.properties │ │ └── validation_zh_CN.properties ├── javayh-data-sources-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── datasource │ │ │ ├── annotation │ │ │ └── DataSource.java │ │ │ ├── aop │ │ │ └── DataSourceAOP.java │ │ │ ├── conf │ │ │ └── DataSourceAutoConfig.java │ │ │ ├── constant │ │ │ └── DataSourceKey.java │ │ │ └── util │ │ │ ├── DataSourceHolder.java │ │ │ └── DynamicDataSource.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── javayh-heartbeat-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── client │ │ │ ├── annotation │ │ │ └── EnableAutoHeartBeat.java │ │ │ ├── config │ │ │ └── HeartBeatConfig.java │ │ │ ├── encode │ │ │ └── HeartbeatEncode.java │ │ │ ├── handle │ │ │ └── EchoClientHandle.java │ │ │ ├── heart │ │ │ ├── CustomerHandleInitializer.java │ │ │ └── HeartbeatClient.java │ │ │ ├── properties │ │ │ └── HeartbeatClientProperties.java │ │ │ └── selector │ │ │ └── HeartImportSelector.java │ │ └── resources │ │ └── META-INF │ │ ├── spring-configuration-metadata.json │ │ └── spring.factories ├── javayh-kafka-starter │ └── pom.xml ├── javayh-log-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── log │ │ │ ├── annotation │ │ │ ├── EnableLogging.java │ │ │ └── SysLog.java │ │ │ ├── aop │ │ │ └── SysLogAop.java │ │ │ ├── conf │ │ │ └── LogAutoConfig.java │ │ │ ├── entity │ │ │ ├── LogInfoEntity.java │ │ │ └── OperationLog.java │ │ │ ├── interceptor │ │ │ └── LogInterceptor.java │ │ │ ├── log │ │ │ ├── LogError.java │ │ │ ├── LogTemplate.java │ │ │ └── LogUtils.java │ │ │ ├── mapper │ │ │ └── LogMapper.java │ │ │ └── selector │ │ │ └── LogImportSelector.java │ │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ └── logback-spring.xml ├── javayh-mail-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── mail │ │ │ ├── annotation │ │ │ └── EnableMail.java │ │ │ ├── conf │ │ │ └── EmailProperties.java │ │ │ ├── entity │ │ │ └── MailDO.java │ │ │ ├── selector │ │ │ └── MailImportSelector.java │ │ │ └── server │ │ │ └── MailSend.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── javayh-mybatis-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── mybatis │ │ │ ├── cache │ │ │ └── RedisCache.java │ │ │ ├── exception │ │ │ └── MybatisInjectionException.java │ │ │ ├── filter │ │ │ ├── IllegalSqlFilter.java │ │ │ ├── InterceptorForQuery.java │ │ │ ├── MybatisFilterAutoConfiguration.java │ │ │ ├── MybatisInterceptor.java │ │ │ └── SqlLog.java │ │ │ ├── mapper │ │ │ └── BaseMapper.java │ │ │ ├── page │ │ │ ├── PageEntity.java │ │ │ └── PageQuery.java │ │ │ ├── service │ │ │ └── IService.java │ │ │ ├── task │ │ │ ├── ForkJoinTaskUtils.java │ │ │ └── MybatisTask.java │ │ │ └── uitl │ │ │ └── Constant.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── javayh-nacos-starter │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── javayh │ │ └── nacos │ │ └── rule │ │ └── CustomizeRule.java ├── javayh-oauth-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── oauth │ │ │ ├── base │ │ │ ├── BaseSecurityConstants.java │ │ │ ├── BaseTokenEnhancer.java │ │ │ ├── BaseUserConverter.java │ │ │ ├── BaseUserDetails.java │ │ │ └── SecurityHelper.java │ │ │ ├── conf │ │ │ └── TokenFeignClientInterceptor.java │ │ │ ├── domain │ │ │ ├── TbPermission.java │ │ │ ├── TbRole.java │ │ │ └── TbUser.java │ │ │ └── exception │ │ │ └── WebException.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── javayh-redis-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── redis │ │ │ ├── conf │ │ │ ├── RedisAutoConfig.java │ │ │ └── RedissonProperties.java │ │ │ ├── prefix │ │ │ └── KeyUtils.java │ │ │ ├── serializer │ │ │ └── RedisObjectSerializer.java │ │ │ └── util │ │ │ └── RedisUtil.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── javayh-swagger-starter │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── swagger │ │ │ ├── annotation │ │ │ └── EnableAutoSwagger.java │ │ │ ├── conf │ │ │ └── SwaggerConfig.java │ │ │ └── selector │ │ │ └── SwaggerSelector.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories └── pom.xml ├── javayh-monitor-center ├── javayh-heartbeat-server │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── heartbeat │ │ │ ├── HeartApplication.java │ │ │ ├── config │ │ │ └── HeartBeatProperties.java │ │ │ ├── encode │ │ │ └── HeartbeatDecoder.java │ │ │ ├── handle │ │ │ └── HeartBeatSimpleHandle.java │ │ │ ├── server │ │ │ ├── HeartBeatServer.java │ │ │ └── HeartbeatInitializer.java │ │ │ └── util │ │ │ └── NettySocketHolder.java │ │ └── resources │ │ ├── META-INF │ │ └── spring-configuration-metadata.json │ │ └── bootstrap.yml ├── javayh-zipkin-center │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── zipkin │ │ │ └── ZipkinApplication.java │ │ └── resources │ │ └── bootstrap.yml └── pom.xml ├── javayh-plugins ├── javayh-generator │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── javayh │ │ └── generator │ │ ├── GeneratorMain.java │ │ ├── bean │ │ └── FieldBean.java │ │ ├── config │ │ └── GenerateConfig.java │ │ ├── file │ │ ├── GenBeanDTOFile.java │ │ ├── GenBeanFile.java │ │ ├── GenControllerFile.java │ │ ├── GenIServiceFile.java │ │ ├── GenMain.java │ │ ├── GenMapperJavaFile.java │ │ ├── GenMapperXmlFile.java │ │ └── GenServiceImplFile.java │ │ └── util │ │ ├── FileUtils.java │ │ ├── NameUtils.java │ │ ├── NotesUtils.java │ │ ├── StringUtil.java │ │ └── TimeUtils.java └── pom.xml ├── javayh-route ├── javayh-api-gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── gateway │ │ │ ├── GatewayApplication.java │ │ │ ├── conf │ │ │ ├── cosr │ │ │ │ └── GatewayCosrConfig.java │ │ │ ├── fallback │ │ │ │ └── GatewayFallbackConfig.java │ │ │ ├── limiter │ │ │ │ └── RateLimiterConfig.java │ │ │ └── swagger │ │ │ │ └── SwaggerProvider.java │ │ │ ├── filter │ │ │ └── SwaggerHeaderFilter.java │ │ │ └── handler │ │ │ ├── hystrix │ │ │ └── HystrixFallbackHandler.java │ │ │ └── swagger │ │ │ └── SwaggerHandler.java │ │ └── resources │ │ └── bootstrap.yml └── pom.xml ├── javayh-sso ├── javayh-resource │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── resource │ │ │ ├── ResourceApplication.java │ │ │ ├── conf │ │ │ └── ResourceServerConfiguration.java │ │ │ ├── controller │ │ │ └── UserApi.java │ │ │ ├── mapper │ │ │ └── TbUserMapper.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── vo │ │ │ └── UserVO.java │ │ └── resources │ │ ├── bootstrap.yml │ │ └── mapper │ │ └── user │ │ └── TbUserMapper.xml ├── javayh-server │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── javayh │ │ │ └── oauth2 │ │ │ └── server │ │ │ ├── OAuth2ServerApplication.java │ │ │ ├── conf │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ ├── ResourceServerConfiguration.java │ │ │ ├── WebSecurityConfiguration.java │ │ │ └── service │ │ │ │ └── UserDetailsServiceImpl.java │ │ │ ├── mapper │ │ │ ├── TbPermissionMapper.java │ │ │ ├── TbRoleMapper.java │ │ │ └── TbUserMapper.java │ │ │ └── service │ │ │ ├── TbPermissionService.java │ │ │ ├── TbRoleService.java │ │ │ ├── TbUserService.java │ │ │ └── impl │ │ │ ├── TbPermissionServiceImpl.java │ │ │ ├── TbRoleServiceImpl.java │ │ │ └── TbUserServiceImpl.java │ │ └── resources │ │ ├── bootstrap.yml │ │ └── mapper │ │ ├── permission │ │ └── TbPermissionMapper.xml │ │ ├── role │ │ └── TbRoleMapper.xml │ │ └── user │ │ └── TbUserMapper.xml └── pom.xml └── pom.xml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name : test—actions 2 | on: 3 | push: 4 | branches: [main,master] 5 | pull_request: 6 | branches: [main,master] 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Setup Java JDK 15 | uses: actions/checkout@v2 16 | with: 17 | java-version: '14' 18 | distribution: 'adopt' 19 | - name: Setup Maven 20 | # You may pin to the exact commit or the version. 21 | # uses: stCarolas/setup-maven@07fbbe97d97ef44336b7382563d66743297e442f 22 | uses: stCarolas/setup-maven@v.4.5 23 | - name: Build package 24 | run: mvn -DskipTests=true package -P 25 | 26 | - name: Login Registry 27 | uses: docker/login-action@v1 28 | with: 29 | registry: ghcr.io 30 | username: ${{ github.repository_owner }} 31 | password: ${{ secrets.GHCR_TOKEN }} 32 | 33 | - name: Push image 34 | run: 35 | docker push ghcr.io/shaowenchen/documents:latest 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | *.tar.gz 8 | *.class 9 | *.project 10 | *.factorypath 11 | 12 | # eclipse ignore 13 | .settings/ 14 | .classpath 15 | target/ 16 | bin/ 17 | NewCustServSer/ 18 | SrenewSer/ 19 | sms-drugstore/ 20 | 21 | # idea ignore 22 | .idea/ 23 | *.ipr 24 | *.iml 25 | *.iws 26 | 27 | # temp ignore 28 | *.log 29 | *.cache 30 | *.diff 31 | *.patch 32 | *.tmp 33 | 34 | # system ignore 35 | .DS_Store 36 | Thumbs.db 37 | 38 | # else 39 | .springBeans 40 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contact information 2 | Contact the author via wechat: 37277553 3 | 4 | Fill in remarks: javayh 5 | 6 | ## 联系方式 7 | 通过微信联系作者: 37277553 8 | 9 | 填写备注: javayh 10 | -------------------------------------------------------------------------------- /doc/file/common.yaml: -------------------------------------------------------------------------------- 1 | ## prometheus 监控使用 2 | management: 3 | endpoints: 4 | web: 5 | exposure: 6 | include: 'prometheus' #[*] 7 | metrics: 8 | tags: 9 | application: ${spring.application.name} 10 | endpoint: 11 | health: 12 | show-details: always 13 | -------------------------------------------------------------------------------- /doc/file/db1.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | druid: 4 | url: jdbc:mysql://localhost:3306/db1?serverTimezone=CTT&characterEncoding=utf8&autoReconnect=true&useUnicode=true&useSSL=true 5 | username: root 6 | password: root 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | initial-size: 1 9 | min-idle: 1 10 | max-active: 20 11 | max-wait: 60000 12 | time-between-eviction-runs-millis: 60000 13 | min-evictable-idle-time-millis: 30000 14 | validation-query: select '1' from dual 15 | test-while-idle: true 16 | test-on-borrow: false 17 | test-on-return: false 18 | pool-prepared-statements: false 19 | max-pool-prepared-statement-per-connection-size: 20 20 | filters: stat,wall 21 | aop-patterns: com.javayh.* 22 | web-stat-filter: 23 | enabled: true 24 | url-pattern: /* 25 | exclusions: /druid/*,*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico 26 | session-stat-enable: true 27 | session-stat-max-count: 10 28 | stat-view-servlet: 29 | enabled: true 30 | url-pattern: "/druid/*" 31 | reset-enable: false 32 | login-username: admin 33 | login-password: admin123 34 | -------------------------------------------------------------------------------- /doc/file/feignhystrix.yaml: -------------------------------------------------------------------------------- 1 | ## feign 服务容错 2 | feign: 3 | hystrix: 4 | enabled: true #是否开启断路器 5 | # sentinel: # 如果您使用sentinel,请将hystrix 置为false 6 | # enabled: true 7 | compression: #GZIP 请求压缩 8 | request: 9 | enabled: true 10 | mime-types: text/xml,application/xml,application/json 11 | min-request-size: 2048 12 | response: 13 | enabled: true 14 | useGzipDecoder: true 15 | client: 16 | config: 17 | feignName: 18 | connectTimeout: 5000 19 | readTimeout: 5000 20 | loggerLevel: full 21 | # errorDecoder: com.SimpleErrorDecoder 22 | # retryer: com.SimpleRetryer 23 | # requestInterceptors: 24 | # - com.FooRequestInterceptor 25 | # - com.BarRequestInterceptor 26 | # decode404: false 27 | # encoder: com.SimpleEncoder 28 | # decoder: com.SimpleDecoder 29 | # contract: com.Si 30 | httpclient: # 模式使用 31 | enabled: false 32 | okhttp: # 使用ok http 33 | enabled: true 34 | 35 | #hystrix的超时时间 36 | hystrix: 37 | command: 38 | default: 39 | execution: 40 | timeout: 41 | enabled: true 42 | isolation: 43 | thread: 44 | timeoutInMilliseconds: 30000 45 | #ribbon的超时时间 46 | ribbon: 47 | ReadTimeout: 30000 48 | ConnectTimeout: 30000 49 | # 同一实例最大重试次数,不包括首次调用。默认值为0 50 | MaxAutoRetries: 0 51 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1 52 | MaxAutoRetriesNextServer: 0 53 | # 是否所有操作(GET、POST等)都允许重试。默认值为false 54 | OkToRetryOnAllOperations: false 55 | okhttp: 56 | enabled: true -------------------------------------------------------------------------------- /doc/file/mail.yaml: -------------------------------------------------------------------------------- 1 | ## 邮件模板配置 2 | spring: 3 | mail: 4 | protocol: smtp 5 | host: smtp.qq.com 6 | # 自己的qq邮箱账号 7 | username: 372787553@qq.com 8 | # password 换成腾讯给的QQ授权码 9 | password: 10 | default-encoding: UTF-8 11 | properties: 12 | mail: 13 | smtp: 14 | auth: true 15 | starttls: 16 | enable: true 17 | required: true 18 | thymeleaf: 19 | enabled: true 20 | mode: LEGACYHTML5 21 | encoding: UTF-8 22 | prefix: classpath:/templates/ # 模板存放在资源目录的 templates/ 文件下 23 | suffix: .html # 模板后缀 24 | check-template-location: true 25 | check-template: false 26 | cache: false # 调试时关闭缓存 27 | servlet: 28 | content-type: text/html -------------------------------------------------------------------------------- /doc/file/mybatis.yaml: -------------------------------------------------------------------------------- 1 | ## mybatis 常用配置 2 | mybatis: 3 | ### xml存放路径 4 | mapper-locations: classpath*:mapper/*/*Mapper.xml 5 | configuration: 6 | cache-enabled: true 7 | lazy-loading-enabled: false 8 | aggressive-lazy-loading: true 9 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 10 | -------------------------------------------------------------------------------- /doc/file/oauth2db.yaml: -------------------------------------------------------------------------------- 1 | ## oauth2 权限验证配置 2 | spring: 3 | datasource: 4 | druid: 5 | url: jdbc:mysql://localhost:3306/oauth2?serverTimezone=CTT&characterEncoding=utf8&autoReconnect=true&useUnicode=true&useSSL=true 6 | username: root 7 | password: root 8 | driver-class-name: com.mysql.cj.jdbc.Driver 9 | initial-size: 1 10 | min-idle: 1 11 | max-active: 20 12 | max-wait: 60000 13 | time-between-eviction-runs-millis: 60000 14 | min-evictable-idle-time-millis: 30000 15 | validation-query: select '1' from dual 16 | test-while-idle: true 17 | test-on-borrow: false 18 | test-on-return: false 19 | pool-prepared-statements: false 20 | max-pool-prepared-statement-per-connection-size: 20 21 | filters: stat,wall 22 | aop-patterns: com.javayh.* 23 | web-stat-filter: 24 | enabled: true 25 | url-pattern: /* 26 | exclusions: /druid/*,*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico 27 | session-stat-enable: true 28 | session-stat-max-count: 10 29 | stat-view-servlet: 30 | enabled: true 31 | url-pattern: "/druid/*" 32 | reset-enable: false 33 | login-username: admin 34 | login-password: admin123 35 | 36 | mybatis: 37 | ### xml存放路径 38 | mapper-locations: classpath*:mapper/*/*Mapper.xml -------------------------------------------------------------------------------- /doc/file/oauth_token.yaml: -------------------------------------------------------------------------------- 1 | ## oauth 客户全token检测配置 2 | security: 3 | oauth2: 4 | client: 5 | client-id: client 6 | client-secret: secret 7 | access-token-uri: http://localhost:9090/oauth/token 8 | user-authorization-uri: http://localhost:9090/oauth/authorize 9 | resource: 10 | token-info-uri: http://localhost:9090/oauth/check_token 11 | -------------------------------------------------------------------------------- /doc/file/redis.yaml: -------------------------------------------------------------------------------- 1 | ## redis配置 2 | spring: 3 | redis: 4 | ################### redis 单机版 start ########################## 5 | host: 127.0.0.1 6 | port: 6379 7 | timeout: 6000 8 | database: 1 9 | lettuce: 10 | pool: 11 | max-active: 10 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽) 12 | max-idle: 8 # 连接池中的最大空闲连接 ,默认值也是8 13 | max-wait: 100 # # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException 14 | min-idle: 2 # 连接池中的最小空闲连接 ,默认值也是0 15 | shutdown-timeout: 100ms 16 | ################## redis 单机版 end ########################## 17 | # cluster: 18 | # nodes: 12.0.0.1:7000,12.0.0.1:7000 19 | # timeout: 1000 # 连接超时时间(毫秒) 20 | # lettuce: 21 | # pool: 22 | # max-active: 10 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽) 23 | # max-idle: 8 # 连接池中的最大空闲连接 ,默认值也是8 24 | # max-wait: 100 # # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException 25 | # min-idle: 2 # 连接池中的最小空闲连接 ,默认值也是0 26 | # shutdown-timeout: 100ms -------------------------------------------------------------------------------- /doc/file/zipkindb.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | druid: 4 | url: jdbc:mysql://localhost:3306/zipkin?serverTimezone=CTT&characterEncoding=utf8&autoReconnect=true&useUnicode=true&useSSL=true 5 | username: root 6 | password: root 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | initial-size: 1 9 | min-idle: 1 10 | max-active: 20 11 | max-wait: 60000 12 | time-between-eviction-runs-millis: 60000 13 | min-evictable-idle-time-millis: 30000 14 | validation-query: select '1' from dual 15 | test-while-idle: true 16 | test-on-borrow: false 17 | test-on-return: false 18 | pool-prepared-statements: false 19 | max-pool-prepared-statement-per-connection-size: 20 20 | filters: stat,wall 21 | aop-patterns: com.javayh.* 22 | web-stat-filter: 23 | enabled: true 24 | url-pattern: /* 25 | exclusions: /druid/*,*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico 26 | session-stat-enable: true 27 | session-stat-max-count: 10 28 | stat-view-servlet: 29 | enabled: true 30 | url-pattern: "/druid/*" 31 | reset-enable: false 32 | login-username: admin 33 | login-password: admin123 -------------------------------------------------------------------------------- /doc/img/access_token.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/access_token.JPG -------------------------------------------------------------------------------- /doc/img/auth.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/auth.JPG -------------------------------------------------------------------------------- /doc/img/code.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/code.JPG -------------------------------------------------------------------------------- /doc/img/oauthLogin.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/oauthLogin.JPG -------------------------------------------------------------------------------- /doc/img/swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/swagger.png -------------------------------------------------------------------------------- /doc/img/token.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/doc/img/token.JPG -------------------------------------------------------------------------------- /doc/sql/log/loginfo.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `sys_log_info` ( 2 | `id` varchar(64) NOT NULL COMMENT '主键', 3 | `level` varchar(255) DEFAULT NULL COMMENT '级别', 4 | `method` varchar(255) NOT NULL COMMENT '方法名', 5 | `args` varchar(255) NOT NULL COMMENT '参数', 6 | `user_id` varchar(64) DEFAULT NULL COMMENT '操作人id', 7 | `user_name` varchar(64) DEFAULT NULL COMMENT '操作人', 8 | `create_time` varchar(255) NOT NULL, 9 | `describe` varchar(255) NOT NULL COMMENT '描述', 10 | `run_time` varchar(255) NOT NULL COMMENT '运行时间', 11 | `caller_ip` varchar(32) NOT NULL COMMENT '调用方ip', 12 | `local_host_ip` varchar(32) NOT NULL COMMENT '本地ip', 13 | PRIMARY KEY (`id`) 14 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/ApiApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.exception.annotation.EnableAutoException; 5 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 6 | import com.javayh.swagger.annotation.EnableAutoSwagger; 7 | import org.springframework.boot.SpringApplication; 8 | 9 | /** 10 | *

11 | * 测试启动类 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-01 20:44 17 | */ 18 | @EnableAutoException 19 | @EnableAutoSwagger 20 | @EnableAutoInternationalization 21 | @JavayhBootApplication 22 | public class ApiApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(ApiApplication.class, args); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/conf/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | // package com.javayh.api.conf; 2 | // 3 | // import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; 4 | // import org.springframework.context.annotation.Configuration; 5 | // import 6 | // org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | // import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | // import 9 | // org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; 10 | // import org.springframework.security.config.http.SessionCreationPolicy; 11 | // import 12 | // org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 13 | // import 14 | // org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 15 | // 16 | // @Configuration 17 | // @EnableResourceServer 18 | // @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled 19 | // = true) 20 | // public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 21 | // 22 | // @Override 23 | // public void configure(HttpSecurity http) throws Exception { 24 | // ExpressionUrlAuthorizationConfigurer 25 | // .ExpressionInterceptUrlRegistry registry = 26 | // http.antMatcher("/**").authorizeRequests(); 27 | // http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) 28 | // .and() 29 | // .authorizeRequests() 30 | // // 指定监控访问权限 31 | // .requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll() 32 | // .anyRequest().authenticated() 33 | // .and() 34 | // .exceptionHandling() 35 | // // 认证鉴权错误处理,为了统一异常处理。每个资源服务器都应该加上。 36 | //// .accessDeniedHandler(new AccessDeniedHandler()) 37 | //// .authenticationEntryPoint(new WebException()) 38 | // //配置跨域 39 | // .and().cors() 40 | // .and().csrf().disable() 41 | // // 禁用httpBasic 42 | // .httpBasic().disable(); 43 | // registry.anyRequest().authenticated(); 44 | // } 45 | // 46 | // } 47 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/sys/dao/SysLogisticsMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api.sys.dao; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import com.javayh.mybatis.mapper.BaseMapper; 5 | 6 | /** 7 | *

* iMapper 8 | *

* @author:Dylan 9 | * @version:V1.0 10 | * @since:2020-04-16 11 | */ 12 | @Mapper 13 | public interface SysLogisticsMapper extends BaseMapper{ 14 | } 15 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/sys/pojo/SysLogistics.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api.sys.pojo; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import lombok.ToString; 9 | 10 | import java.util.Date; 11 | /** 12 | *

* Bean 13 | *

* @author:Dylan 14 | * @version:V1.0 15 | * @since:2020-04-16 16 | */ 17 | @SuppressWarnings("serial") 18 | @Data 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Builder 22 | @ToString 23 | public class SysLogistics implements java.io.Serializable{ 24 | 25 | /** 26 | * 27 | */ 28 | @ApiModelProperty(hidden = true) 29 | private Integer id; 30 | /** 31 | * 收件人 32 | */ 33 | @ApiModelProperty(value = "收件人") 34 | private String addresseeName; 35 | /** 36 | * 收件人地址 37 | */ 38 | @ApiModelProperty(value = "收件人地址") 39 | private String addressee; 40 | /** 41 | * 42 | */ 43 | @ApiModelProperty(hidden = true) 44 | private Integer addresseePhone; 45 | /** 46 | * 寄件人 47 | */ 48 | @ApiModelProperty(value = "寄件人") 49 | private String senderName; 50 | /** 51 | * 寄件人地址 52 | */ 53 | @ApiModelProperty(value = "寄件人地址") 54 | private String senderAdd; 55 | /** 56 | * 0,已接单,1,已发货,2,已签收 57 | */ 58 | @ApiModelProperty(value = "0,已接单,1,已发货,2,已签收") 59 | private Integer emsStatus; 60 | /** 61 | * 0,为退货,1,退货中,2,已退货 62 | */ 63 | @ApiModelProperty(value = "0,为退货,1,退货中,2,已退货") 64 | private Integer retreatStatus; 65 | /** 66 | * 退货原因 67 | */ 68 | @ApiModelProperty(value = "退货原因") 69 | private String retreatInfo; 70 | /** 71 | * 创建时间 72 | */ 73 | @ApiModelProperty(value = "创建时间") 74 | private Date createDate; 75 | /** 76 | * 77 | */ 78 | @ApiModelProperty(hidden = true) 79 | private Date updateDate; 80 | /** 81 | * 操作人 82 | */ 83 | @ApiModelProperty(value = "操作人") 84 | private String createBy; 85 | 86 | } 87 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/sys/pojo/dto/SysLogisticsDTO.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api.sys.pojo.dto; 2 | 3 | import lombok.*; 4 | import com.javayh.mybatis.page.PageEntity; 5 | 6 | import io.swagger.annotations.ApiModelProperty; 7 | import java.util.Date; 8 | /** 9 | *

* Bean 10 | *

* @author:Dylan 11 | * @version:V1.0 12 | * @since:2020-04-16 13 | */ 14 | @SuppressWarnings("serial") 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @Builder 19 | @ToString 20 | public class SysLogisticsDTO extends PageEntity implements java.io.Serializable{ 21 | 22 | /** 23 | * 24 | */ 25 | @ApiModelProperty(hidden = true) 26 | private Integer id; 27 | /** 28 | * 收件人 29 | */ 30 | @ApiModelProperty(value = "收件人") 31 | private String addresseeName; 32 | /** 33 | * 收件人地址 34 | */ 35 | @ApiModelProperty(value = "收件人地址") 36 | private String addressee; 37 | /** 38 | * 39 | */ 40 | @ApiModelProperty(hidden = true) 41 | private Integer addresseePhone; 42 | /** 43 | * 寄件人 44 | */ 45 | @ApiModelProperty(value = "寄件人") 46 | private String senderName; 47 | /** 48 | * 寄件人地址 49 | */ 50 | @ApiModelProperty(value = "寄件人地址") 51 | private String senderAdd; 52 | /** 53 | * 0,已接单,1,已发货,2,已签收 54 | */ 55 | @ApiModelProperty(value = "0,已接单,1,已发货,2,已签收") 56 | private Integer emsStatus; 57 | /** 58 | * 0,为退货,1,退货中,2,已退货 59 | */ 60 | @ApiModelProperty(value = "0,为退货,1,退货中,2,已退货") 61 | private Integer retreatStatus; 62 | /** 63 | * 退货原因 64 | */ 65 | @ApiModelProperty(value = "退货原因") 66 | private String retreatInfo; 67 | /** 68 | * 创建时间 69 | */ 70 | @ApiModelProperty(value = "创建时间") 71 | private Date createDate; 72 | /** 73 | * 74 | */ 75 | @ApiModelProperty(hidden = true) 76 | private Date updateDate; 77 | /** 78 | * 操作人 79 | */ 80 | @ApiModelProperty(value = "操作人") 81 | private String createBy; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/sys/service/ISysLogisticsService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api.sys.service; 2 | 3 | import com.javayh.api.sys.pojo.SysLogistics; 4 | import java.util.List; 5 | import com.javayh.api.sys.pojo.dto.SysLogisticsDTO; 6 | import com.javayh.mybatis.page.PageQuery; 7 | 8 | /** 9 | *

* iService 10 | *

* @author:Dylan 11 | * @version:V1.0 12 | * @since:2020-04-16 13 | */ 14 | public interface ISysLogisticsService { 15 | /** 16 | * 根据条件查找-分页 17 | */ 18 | PageQuery findByPage (SysLogisticsDTO sysLogisticsDTO); 19 | 20 | /** 21 | * 根据id查询 22 | */ 23 | SysLogistics findById(String id); 24 | 25 | 26 | /** 27 | * 添加数据 28 | */ 29 | int insert(SysLogistics sysLogistics); 30 | 31 | 32 | /** 33 | * 批量添加数据 34 | */ 35 | int batchInsert(List sysLogistics); 36 | 37 | /** 38 | * 修改数据 39 | */ 40 | int update(SysLogistics sysLogistics); 41 | 42 | /** 43 | * 根据id删除 44 | */ 45 | int deleteById(String id); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/java/com/javayh/api/web/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.javayh.api.web; 2 | 3 | import com.javayh.common.qrcode.QRCodeGenerator; 4 | import com.javayh.common.result.ResultData; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-03-06 9:48 21 | */ 22 | @Api("测试 API") 23 | @RestController 24 | @RequestMapping(value = "/api/") 25 | public class ApiController { 26 | 27 | @ApiOperation(value = "swagger测试", notes = "测试") 28 | @GetMapping(value = "swagger") 29 | public ResultData getSwagger() { 30 | return ResultData.success("Hello Swagger!"); 31 | } 32 | 33 | @ApiOperation(value = "二维码渲染", notes = "二维码") 34 | @RequestMapping("/test") 35 | public void getQRcode(HttpServletResponse response) throws Exception { 36 | // 参数为二维码的内容、长、宽、响应对象 37 | String text = "https://blog.csdn.net/weixin_38937840"; 38 | String logoPath = "C:\\Users\\haiyang\\Desktop\\webwxgetmsgimg.jpg"; 39 | QRCodeGenerator.outputQRCode(text, logoPath, response); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-api/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6062 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | main: 7 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 8 | profiles: 9 | active: ${profile.name} 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: ${discovery.server-addr} 14 | namespace: ${config.namespace} 15 | # ip: ${discovery.server-ip} 16 | config: 17 | server-addr: ${config.server-addr} 18 | namespace: ${config.namespace} 19 | file-extension: yaml 20 | shared-dataids: db1.yaml,common.yaml,redis.yaml,mail.yaml,mybatis.yaml 21 | messages: 22 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 23 | # zipkin: 24 | # base-url: http://localhost:7070 25 | # # 关闭服务发现,否则Spring Cloud会把zipkin的url当做服务名称 26 | # discoveryClientEnabled: false 27 | # sender: 28 | # type: web 29 | # sleuth: 30 | # sampler: 31 | # probability: 1 # 设置抽样采集率为100%,默认为0.1,即10% 32 | 33 | 34 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-demo 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-demo-common 13 | 14 | 15 | 16 | com.javayh 17 | javayh-log-starter 18 | true 19 | 20 | 21 | com.javayh 22 | javayh-redis-starter 23 | true 24 | 25 | 26 | com.javayh 27 | javayh-swagger-starter 28 | true 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | org.junit.vintage 37 | junit-vintage-engine 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-test 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-common/src/main/java/com/javayh/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.demo; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.exception.annotation.EnableAutoException; 5 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 6 | import com.javayh.log.annotation.EnableLogging; 7 | import com.javayh.swagger.annotation.EnableAutoSwagger; 8 | import org.springframework.boot.SpringApplication; 9 | 10 | /** 11 | *

12 | * 测试启动类 13 | *

14 | * 15 | * @author Dylan-haiji 16 | * @version 1.0.0 17 | * @since 2020-03-01 20:44 18 | */ 19 | @EnableAutoSwagger 20 | @EnableAutoException 21 | @EnableAutoInternationalization 22 | @JavayhBootApplication 23 | public class DemoApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(DemoApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-common/src/main/java/com/javayh/demo/service/DemoFallback.java: -------------------------------------------------------------------------------- 1 | package com.javayh.demo.service; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | *

7 | * 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-02 13:48 13 | */ 14 | @Component 15 | public class DemoFallback implements DemoService { 16 | 17 | @Override 18 | public String getFeign() { 19 | return "error"; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-common/src/main/java/com/javayh/demo/service/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.demo.service; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | 7 | /** 8 | *

9 | * 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-02 13:40 15 | */ 16 | @Service 17 | @FeignClient(name = "javayh-demo-feign", fallback = DemoFallback.class) 18 | public interface DemoService { 19 | 20 | @GetMapping(value = "/feign/getfeign") 21 | String getFeign(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-common/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6060 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | main: 7 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 8 | profiles: 9 | active: ${profile.name} 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: ${discovery.server-addr} 14 | namespace: ${config.namespace} 15 | # ip: ${discovery.server-ip} 16 | config: 17 | server-addr: ${config.server-addr} 18 | namespace: ${config.namespace} 19 | file-extension: yaml 20 | shared-dataids: redis.yaml,mail.yaml,feignhystrix.yaml 21 | messages: 22 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 23 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-config/README.md: -------------------------------------------------------------------------------- 1 | ## javayh-demo-config 2 | 3 | 这里主要讲解nacos分布式配置中心多环节的配置 4 | ### 5 | ``` 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 127.0.0.1:8848 10 | cluster-name: javayh-nacos 11 | config: 12 | group: haiji_dev 13 | server-addr: 127.0.0.1:8848 14 | prefix: javayh-demo 15 | file-extension: yml 16 | namespace: d7503bcd-e44c-475a-88d4-d28cbfb444fc 17 | shared-dataids: redis.yml 18 | ``` 19 | **配置中心实例** 20 | ![full stack developer tutorial](../../doc/config.png) 21 | 22 | `spring.cloud.nacos.config.group`: 分组信息,默认是 DEFAULT_GROUP 23 | `spring.cloud.nacos.config.namespace`: 环境的唯一id 24 | `spring.cloud.nacos.config.shared-dataids`: 需要加载的共享资源 ,这里对用配置文中心的`Data ID` 25 | `spring.cloud.nacos.config.refreshable-dataids`: 与shared-dataids效果一样,但是支持自动刷新 26 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-demo 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-demo-config 13 | 14 | 15 | 16 | com.javayh 17 | javayh-redis-starter 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-config/src/main/java/com/javayh/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.config; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 5 | import org.springframework.boot.SpringApplication; 6 | 7 | /** 8 | *

9 | * nacos分布式中心测试 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-09 17:45 15 | */ 16 | @EnableAutoInternationalization 17 | @JavayhBootApplication 18 | public class ConfigApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(ConfigApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-config/src/main/java/com/javayh/config/web/DemoCtroller.java: -------------------------------------------------------------------------------- 1 | package com.javayh.config.web; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import com.javayh.redis.prefix.KeyUtils; 5 | import com.javayh.redis.util.RedisUtil; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | *

13 | * demo 访问 14 | *

15 | * 16 | * @author Dylan-haiji 17 | * @version 1.0.0 18 | * @since 2020-03-01 20:46 19 | */ 20 | @RestController 21 | @RequestMapping(value = "/demo/") 22 | public class DemoCtroller { 23 | 24 | @Autowired 25 | private RedisUtil redisUtil; 26 | 27 | /** 28 | *

29 | * 测试Redis 30 | *

31 | * @version 1.0.0 32 | * @author Dylan-haiji 33 | * @since 2020/3/4 34 | * @param 35 | * @return com.javayh.common.result.ResultData 36 | */ 37 | @GetMapping(value = "redis") 38 | public ResultData redis() { 39 | String ceshi = KeyUtils.key("ceshi"); 40 | boolean hello_word = redisUtil.setObj(ceshi, "hello word", 100); 41 | String s = (String) redisUtil.get(ceshi); 42 | return ResultData.success(s); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-config/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6064 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | main: 7 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 8 | profiles: 9 | active: ${profile.name} 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: ${discovery.server-addr} 14 | namespace: ${config.namespace} 15 | # ip: ${discovery.server-ip} 16 | config: 17 | server-addr: ${config.server-addr} 18 | namespace: ${config.namespace} 19 | file-extension: yaml 20 | shared-dataids: redis.yaml,mail.yaml 21 | messages: 22 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-demo 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-demo-feign 13 | 14 | 15 | 16 | com.javayh 17 | javayh-swagger-starter 18 | true 19 | 20 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/FeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.feign; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 5 | import com.javayh.swagger.annotation.EnableAutoSwagger; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | 9 | /** 10 | *

11 | * feign 启动类 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-02 13:34 17 | */ 18 | @EnableFeignClients 19 | @EnableAutoSwagger 20 | // @EnableAutoHeartBeat 21 | @EnableAutoInternationalization 22 | @JavayhBootApplication 23 | public class FeignApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(FeignApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/conf/FeignConfig.java: -------------------------------------------------------------------------------- 1 | //package com.javayh.feign.conf; 2 | // 3 | //import feign.RequestInterceptor; 4 | //import org.springframework.boot.context.properties.ConfigurationProperties; 5 | //import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; 6 | //import org.springframework.context.annotation.Bean; 7 | //import org.springframework.context.annotation.Configuration; 8 | //import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; 9 | //import org.springframework.security.oauth2.client.OAuth2RestTemplate; 10 | //import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; 11 | // 12 | // 13 | //@Configuration 14 | //public class FeignConfig { 15 | // @Bean 16 | // @ConfigurationProperties(prefix = "security.oauth2.client") 17 | // public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { 18 | // return new ClientCredentialsResourceDetails(); 19 | // } 20 | // 21 | // @Bean 22 | // public RequestInterceptor oauth2FeignRequestInterceptor(){ 23 | // return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); 24 | // } 25 | // 26 | // @Bean 27 | // public OAuth2RestTemplate clientCredentialsRestTemplate() { 28 | // return new OAuth2RestTemplate(clientCredentialsResourceDetails()); 29 | // } 30 | //} 31 | // 32 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/conf/TokenFeignClientInterceptor.java: -------------------------------------------------------------------------------- 1 | //package com.javayh.feign.conf; 2 | // 3 | //import com.javayh.common.util.servlet.RequestUtils; 4 | //import feign.RequestInterceptor; 5 | //import feign.RequestTemplate; 6 | //import org.springframework.context.annotation.Configuration; 7 | //import org.springframework.security.core.Authentication; 8 | //import org.springframework.security.core.context.SecurityContext; 9 | //import org.springframework.security.core.context.SecurityContextHolder; 10 | //import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; 11 | //import org.springframework.web.context.request.RequestAttributes; 12 | //import org.springframework.web.context.request.RequestContextHolder; 13 | //import org.springframework.web.context.request.ServletRequestAttributes; 14 | // 15 | //import javax.servlet.http.HttpServletRequest; 16 | // 17 | ///** 18 | // *

19 | // * feign添加token 20 | // *

21 | // * 22 | // * @author Dylan-haiji 23 | // * @version 1.0.0 24 | // * @since 2020-04-08 22:33 25 | // */ 26 | //@Configuration 27 | //public class TokenFeignClientInterceptor implements RequestInterceptor { 28 | // 29 | // 30 | // private final String AUTHORIZATION_HEADER = "Authorization"; 31 | // private final String BEARER_TOKEN_TYPE = "Bearer"; 32 | // 33 | // @Override 34 | // public void apply(RequestTemplate requestTemplate) { 35 | // SecurityContext securityContext = SecurityContextHolder.getContext(); 36 | // Authentication authentication = securityContext.getAuthentication(); 37 | // if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { 38 | // OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); 39 | // requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue())); 40 | // } 41 | // 42 | // } 43 | // 44 | //} 45 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/service/impl/DemoFeignServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.javayh.feign.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | 7 | /** 8 | *

9 | * 接口实现 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-02 13:37 15 | */ 16 | @Service 17 | public class DemoFeignServiceImpl { 18 | 19 | // @GetMapping(value = "/feign/getFeign") 20 | public String getFeign() { 21 | return "Feign Success"; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/service/resource/UserService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.feign.service.resource; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | /** 10 | *

11 | * 通过feign调用资源服务器 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-04-08 22:22 17 | */ 18 | 19 | @FeignClient 20 | ( name = "javayh-resource", 21 | fallback = ResourceFallback.class 22 | ) 23 | public interface UserService { 24 | 25 | /** 26 | *

27 | * feign调用资源服务器 28 | *

29 | * @version 1.0.0 30 | * @author Dylan-haiji 31 | * @since 2020/4/8 32 | * @param username 33 | * @return com.javayh.common.result.ResultData 34 | */ 35 | @GetMapping(value = "/api/user/info") 36 | ResultData getByUserName(String username); 37 | } 38 | @Configuration 39 | class ResourceFallback implements UserService{ 40 | 41 | @Override 42 | public ResultData getByUserName(String username) { 43 | return ResultData.fail("service_call_exception"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/java/com/javayh/feign/web/FeignCtr.java: -------------------------------------------------------------------------------- 1 | package com.javayh.feign.web; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import com.javayh.feign.service.impl.DemoFeignServiceImpl; 5 | import com.javayh.feign.service.resource.UserService; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-03-02 14:20 21 | */ 22 | @Api("测试 Swagger API") 23 | @RestController 24 | @RequestMapping(value = "/feign/") 25 | public class FeignCtr { 26 | 27 | @Autowired 28 | private DemoFeignServiceImpl demoFeignService; 29 | 30 | @Autowired 31 | private UserService userService; 32 | @ApiOperation(value = "测试 ", notes = "测试") 33 | @GetMapping(value = "getfeign") 34 | public ResultData get() { 35 | return ResultData.success(demoFeignService.getFeign()); 36 | } 37 | 38 | /** 39 | *

40 | * 获取用户信息 41 | *

42 | * @version 1.0.0 43 | * @author Dylan-haiji 44 | * @since 2020/4/8 45 | * @param username 46 | * @return com.javayh.common.result.ResultData 47 | */ 48 | @GetMapping(value = "info") 49 | public ResultData getUser(String username) { 50 | return userService.getByUserName(username); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-feign/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6061 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | main: 7 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 8 | profiles: 9 | active: ${profile.name} 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: ${discovery.server-addr} 14 | namespace: ${config.namespace} 15 | # ip: ${discovery.server-ip} 16 | config: 17 | server-addr: ${config.server-addr} 18 | namespace: ${config.namespace} 19 | file-extension: yaml 20 | shared-dataids: redis.yaml,mail.yaml,feignhystrix.yaml 21 | messages: 22 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 23 | #heartbeat: 24 | # server: 25 | # host: 127.0.0.1 26 | # port: 8001 27 | # channel-id: 101 28 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-file/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-demo 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 文件测试 12 | javayh-demo-file 13 | 14 | 15 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-file/src/main/java/com/javayh/file/FileApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.file; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import org.springframework.boot.SpringApplication; 5 | 6 | /** 7 | *

8 | * file 启动类 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-05-07 14 | */ 15 | @JavayhBootApplication 16 | public class FileApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(FileApplication.class,args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-file/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6065 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | main: 7 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 8 | profiles: 9 | active: ${profile.name} 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: ${discovery.server-addr} 14 | namespace: ${config.namespace} 15 | # ip: ${discovery.server-ip} 16 | config: 17 | server-addr: ${config.server-addr} 18 | namespace: ${config.namespace} 19 | file-extension: yaml 20 | shared-dataids: redis.yaml,mail.yaml,feignhystrix.yaml 21 | messages: 22 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 23 | #heartbeat: 24 | # server: 25 | # host: 127.0.0.1 26 | # port: 8001 27 | # channel-id: 101 28 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-mail/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-demo 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-demo-mail 13 | 14 | 15 | 16 | com.javayh 17 | javayh-mail-starter 18 | 19 | 20 | com.javayh 21 | javayh-heartbeat-starter 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-maven-plugin 30 | 31 | 32 | maven-compiler-plugin 33 | 34 | ${java.version} 35 | ${java.version} 36 | UTF-8 37 | 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-jar-plugin 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-mail/src/main/java/com/javayh/mail/MailApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 5 | import org.springframework.boot.SpringApplication; 6 | 7 | /** 8 | *

9 | * 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-08 14:55 15 | */ 16 | @EnableAutoInternationalization 17 | @JavayhBootApplication 18 | public class MailApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(MailApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-mail/src/main/java/com/javayh/mail/web/MailController.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail.web; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import com.javayh.mail.entity.MailDO; 5 | import com.javayh.mail.server.MailSend; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | *

17 | * 18 | *

19 | * 20 | * @author Dylan-haiji 21 | * @version 1.0.0 22 | * @since 2020-03-0:14 23 | */ 24 | @RestController 25 | @RequestMapping(value = "/mail/") 26 | public class MailController { 27 | 28 | @Autowired(required = false) 29 | private MailSend mailSenderUtil; 30 | 31 | /** 32 | *

33 | * 34 | *

35 | * @version 1.0.0 36 | * @author Dylan-haiji 37 | * @since 2020/3/8 38 | * @param mailDO 39 | * @return com.javayh.common.result.ResultData 40 | */ 41 | @PostMapping(value = "send") 42 | public ResultData send(@RequestBody MailDO mailDO) { 43 | Map map = new HashMap<>(); 44 | map.put("username", "Yang haiji"); 45 | mailDO.setAttachment(map); 46 | mailDO.setTemplateName("HelloMail"); 47 | mailSenderUtil.sendTemplateMail(mailDO); 48 | return ResultData.success(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-mail/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 6063 3 | maxHttpHeaderSize: 2048 4 | spring: 5 | application: 6 | name: ${artifactId} 7 | main: 8 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 9 | profiles: 10 | active: ${profile.name} 11 | cloud: 12 | nacos: 13 | discovery: 14 | server-addr: ${discovery.server-addr} 15 | namespace: ${config.namespace} 16 | # ip: ${discovery.server-ip} 17 | config: 18 | server-addr: ${config.server-addr} 19 | namespace: ${config.namespace} 20 | file-extension: yaml 21 | refreshable-dataids: messages.yaml 22 | shared-dataids: redis.yaml,mail.yaml 23 | messages: 24 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 25 | heartbeat: 26 | server: 27 | host: 127.0.0.1 28 | port: 8001 29 | channel-id: 100 30 | app-name: ${artifactId} -------------------------------------------------------------------------------- /javayh-demo/javayh-demo-mail/src/main/resources/templates/HelloMail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

欢迎 同学:

5 | 6 |
作者:杨海吉
7 |
微信:372787553
8 | 更多微服务学习内容请点这里 9 |
我为胜利而来,不为失败低头
10 | 11 | -------------------------------------------------------------------------------- /javayh-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-platform 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-demo 13 | pom 14 | 15 | javayh-demo-common 16 | javayh-demo-feign 17 | javayh-demo-api 18 | javayh-demo-mail 19 | javayh-demo-config 20 | javayh-demo-file 21 | 22 | 23 | 24 | 25 | com.javayh 26 | javayh-common-starter 27 | 28 | 29 | com.javayh 30 | javayh-nacos-starter 31 | true 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/config/MyCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.config; 2 | 3 | import com.javayh.common.util.IPUtils; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.CommandLineRunner; 7 | 8 | /** 9 | *

10 | * 成功启动后的操作 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-03-23 20:58 16 | */ 17 | @Slf4j 18 | public class MyCommandLineRunner implements CommandLineRunner { 19 | 20 | @Value("${spring.application.name}") 21 | private String applicationName; 22 | 23 | @Value("${server.port}") 24 | private String port; 25 | 26 | private String pr = "项目< "; 27 | 28 | private String sr = " >已启动 访问地址为:{}"; 29 | 30 | @Override 31 | public void run(String... args) throws Exception { 32 | log.info(pr + applicationName + sr, IPUtils.getHostIp() + ":" + port + "/"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/constant/ConstantUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.constant; 2 | 3 | /** 4 | *

5 | * 公用常量 6 | *

7 | * 8 | * @author Dylan-haiji 9 | * @version 1.0.0 10 | * @since 2020-03-01 21:22 11 | */ 12 | public interface ConstantUtils { 13 | 14 | /** 统一消息提示 */ 15 | String SUCCESS_CODE = "0"; 16 | 17 | String FAIL_CODE = "1"; 18 | 19 | String SUCCESS_MSG = "success_msg"; 20 | 21 | String FAIL_MSG = "failure_msg"; 22 | 23 | String BUSINESS_DATA = "business_data"; 24 | 25 | String UTF = "UTF-8"; 26 | 27 | String PREFIX = "Java有货==>"; 28 | 29 | String NEWLINE = "\r\n"; 30 | 31 | int MAX_STACK_DEPTH = 100; 32 | } 33 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/constant/EncryptConstantUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.constant; 2 | 3 | /** 4 | *

5 | * 加密常量 6 | *

7 | * 8 | * @author Dylan-haiji 9 | * @version 1.0.0 10 | * @since 2020-03-25 17:34 11 | */ 12 | public interface EncryptConstantUtils { 13 | 14 | String ALGORITHM_AES = "AES"; 15 | 16 | String INSTANCE = "AES/ECB/PKCS5Padding"; 17 | 18 | String FILL_STR = "0"; 19 | 20 | String SUFFIX_SHA = "20200202"; 21 | 22 | String SUFFIX_AES = "2020020220"; 23 | 24 | char[] HEXADECIMAL = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 25 | 'c', 'd', 'e', 'f' }; 26 | 27 | char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 28 | 'c', 'd', 'e', 'f', 'g' }; 29 | 30 | char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 31 | 'C', 'D', 'E', 'F', 'G' }; 32 | 33 | String MD5 = "MD5"; 34 | 35 | String KEY_ALGORITHM = "RSA"; 36 | 37 | String PUBLIC_KEY = "RSAPublicKey"; 38 | 39 | String PRIVATE_KEY = "RSAPrivateKey"; 40 | 41 | String ALGORITHM = "RSA/ECB/PKCS1Padding"; 42 | 43 | String SHA = "SHA-256"; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/encrypt/key/DataKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.encrypt.key; 2 | 3 | import com.javayh.common.constant.EncryptConstantUtils; 4 | import com.javayh.common.encrypt.md5.MD5Util; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import javax.crypto.KeyGenerator; 8 | import javax.crypto.SecretKey; 9 | import java.security.SecureRandom; 10 | 11 | /** 12 | *

13 | * 系统生成datakey 14 | *

15 | * 16 | * @author Dylan-haiji 17 | * @version 1.0.0 18 | * @since 2020-03-24 15:40 19 | */ 20 | @Slf4j 21 | public class DataKeyGenerator { 22 | 23 | /** 24 | *

25 | * 安全随机种子 26 | *

27 | * @version 1.0.0 28 | * @author Dylan-haiji 29 | * @since 2020/3/24 30 | * @param keySize 31 | * @param seed 32 | * @return java.lang.String 33 | */ 34 | public static String getInstanceKey(int keySize, long seed) { 35 | String key = ""; 36 | try { 37 | KeyGenerator generator = KeyGenerator 38 | .getInstance(EncryptConstantUtils.ALGORITHM_AES); 39 | SecureRandom random = new SecureRandom(); 40 | random.setSeed(seed); 41 | generator.init(keySize, random); 42 | SecretKey secretKey = generator.generateKey(); 43 | key = MD5Util.hash32(new String(secretKey.getEncoded())); 44 | } 45 | catch (Exception e) { 46 | log.error("DataKeyGenerator NoSuchAlgorithmException{}", e.getMessage()); 47 | } 48 | return key; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/encrypt/md5/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.encrypt.md5; 2 | 3 | import com.javayh.common.constant.ConstantUtils; 4 | import com.javayh.common.constant.EncryptConstantUtils; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import java.security.MessageDigest; 8 | 9 | /** 10 | *

11 | * 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-24 21:22 17 | */ 18 | @Slf4j 19 | public class MD5Util { 20 | 21 | /** 22 | *

23 | * MD5 进行hash取模 24 | *

25 | * @version 1.0.0 26 | * @author Dylan-haiji 27 | * @since 2020/3/24 28 | * @param s 29 | * @return java.lang.String 30 | */ 31 | public static String hash32(String s) { 32 | try { 33 | byte[] btInput = s.getBytes(); 34 | // 获得MD5摘要算法的 MessageDigest 对象 35 | MessageDigest mdInst = MessageDigest.getInstance(EncryptConstantUtils.MD5); 36 | // 使用指定的字节更新摘要 37 | mdInst.update(btInput); 38 | // 获得密文 39 | byte[] md = mdInst.digest(); 40 | // 把密文转换成十六进制的字符串形式 41 | int j = md.length; 42 | char[] str = new char[j * 2]; 43 | int k = 0; 44 | for (int i = 0; i < j; i++) { 45 | byte byte0 = md[i]; 46 | str[k++] = EncryptConstantUtils.HEXADECIMAL[byte0 >>> 4 & 0xf]; 47 | str[k++] = EncryptConstantUtils.HEXADECIMAL[byte0 & 0xf]; 48 | } 49 | return new String(str); 50 | } 51 | catch (Exception e) { 52 | log.error("MD5 hash32 Exception {}", e.getMessage()); 53 | return null; 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.common.entity; 17 | 18 | import com.fasterxml.jackson.annotation.JsonFormat; 19 | import lombok.AllArgsConstructor; 20 | import lombok.Data; 21 | import lombok.Getter; 22 | import lombok.NoArgsConstructor; 23 | import lombok.Setter; 24 | import org.springframework.format.annotation.DateTimeFormat; 25 | 26 | import javax.validation.constraints.Min; 27 | import java.io.Serializable; 28 | import java.util.Date; 29 | import java.util.Objects; 30 | 31 | /** 32 | *

33 | * 常用字段 34 | * 35 | * @DateTimeFormat(pattern = "yyyy-MM-dd") 36 | *

37 | * @author Dylan-haiji 38 | * @version 1.0.0 39 | * @since 2020-04-03 10:43 40 | */ 41 | @AllArgsConstructor 42 | @NoArgsConstructor 43 | @Data 44 | public class BaseEntity implements Serializable { 45 | 46 | private static final long serialVersionUID = 170726482079531378L; 47 | 48 | /** 创建人 */ 49 | private String createBy; 50 | 51 | /** 创建时间 */ 52 | @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") 53 | private Date createDate; 54 | 55 | /** 修改人 */ 56 | private String updateBy; 57 | 58 | /** 修改时间 */ 59 | @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") 60 | private Date updateDate; 61 | 62 | /** 是否删除 */ 63 | private String isDelete; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception; 2 | 3 | import com.javayh.common.constant.ConstantUtils; 4 | 5 | /** 6 | *

7 | * 基础异常 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-01 21:30 13 | */ 14 | public class BaseException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 7859712770754900356L; 17 | 18 | public BaseException(String msg) { 19 | super(msg); 20 | } 21 | 22 | public BaseException(Exception e) { 23 | this(e.getMessage()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import com.javayh.common.util.log.Log; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.validation.FieldError; 7 | import org.springframework.web.bind.MethodArgumentNotValidException; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | import java.sql.SQLException; 12 | import java.util.List; 13 | 14 | /** 15 | *

16 | * 全局异常 17 | *

18 | * 19 | * @author Dylan-haiji 20 | * @version 1.0.0 21 | * @since 2020-03-01 21:36 22 | */ 23 | @Slf4j 24 | @RestControllerAdvice 25 | public class GlobalExceptionHandler { 26 | 27 | /** 28 | *

29 | * 全局Base异常处理 30 | *

31 | * @version 1.0.0 32 | * @author Dylan 33 | * @since 2020/2/27 34 | * @param e 35 | */ 36 | @ExceptionHandler({ BaseException.class }) 37 | public ResultData customExceptionHandler(BaseException e) { 38 | Log.error("全局Base异常处理", e.getStackTrace()); 39 | return ResultData.fail(e.getMessage()); 40 | } 41 | 42 | /** 43 | *

44 | * 其他类型的异常处理 45 | *

46 | * @version 1.0.0 47 | * @author Dylan 48 | * @since 2020/2/27 49 | * @param e 50 | */ 51 | @ExceptionHandler({ Exception.class }) 52 | public ResultData exceptionHandler(Exception e) { 53 | Log.error("未知的运行异常", e.getStackTrace()); 54 | return ResultData.fail(); 55 | } 56 | 57 | /** 58 | *

59 | * 参数异常处理 60 | *

61 | * @version 1.0.0 62 | * @author Dylan-haiji 63 | * @since 2020/2/28 64 | * @param exception 65 | */ 66 | @ExceptionHandler(value = MethodArgumentNotValidException.class) 67 | public ResultData methodNotValidHandler(MethodArgumentNotValidException exception) { 68 | Log.error("参数异常处理", exception.getStackTrace()); 69 | List fieldErrors = exception.getBindingResult().getFieldErrors(); 70 | return ResultData.fail(fieldErrors.get(0).getDefaultMessage()); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/annotation/EnableAutoException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.annotation; 2 | 3 | import com.javayh.common.selector.ExceptionSelector; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Inherited; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | /** 14 | *

15 | * 自定义启动类注解,以免多次引用 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-03-02 14:35 21 | */ 22 | @Target({ ElementType.TYPE }) 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Documented 25 | @Inherited 26 | @Import({ ExceptionSelector.class }) 27 | public @interface EnableAutoException { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/business/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.business; 2 | 3 | import com.javayh.common.constant.ConstantUtils; 4 | import com.javayh.common.exception.BaseException; 5 | 6 | /** 7 | *

8 | * 业务参数异常 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-01 21:34 14 | */ 15 | public class BusinessException extends BaseException { 16 | 17 | public BusinessException() { 18 | super(ConstantUtils.BUSINESS_DATA); 19 | } 20 | 21 | public BusinessException(String msg) { 22 | super(msg); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/controller/ControllerException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.controller; 2 | 3 | import com.javayh.common.exception.BaseException; 4 | 5 | /** 6 | *

7 | * controller 异常 8 | *

9 | * 10 | * @version 1.0.0 11 | * @author Dylan-haiji 12 | * @since 2020/3/1 13 | */ 14 | public class ControllerException extends BaseException { 15 | 16 | /** 17 | * 18 | */ 19 | private static final long serialVersionUID = 1412104290896291466L; 20 | 21 | public ControllerException(String msg) { 22 | super(msg); 23 | } 24 | 25 | public ControllerException(Exception e) { 26 | this(e.getMessage()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/dao/DataAccessException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.dao; 2 | 3 | import com.javayh.common.exception.BaseException; 4 | 5 | /** 6 | *

7 | * 数据库异常 8 | *

9 | * 10 | * @version 1.0.0 11 | * @author Dylan-haiji 12 | * @since 2020/3/1 13 | */ 14 | public class DataAccessException extends BaseException { 15 | 16 | private static final long serialVersionUID = 8325096920926406459L; 17 | 18 | public DataAccessException(String msg) { 19 | super(msg); 20 | } 21 | 22 | public DataAccessException(Exception e) { 23 | this(e.getMessage()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/hystrix/HytrixException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.hystrix; 2 | 3 | import com.netflix.hystrix.exception.HystrixBadRequestException; 4 | 5 | /** 6 | *

7 | * feign client 避免熔断异常处理 8 | *

9 | * 10 | * @version 1.0.0 11 | * @author Dylan-haiji 12 | * @since 2020/3/1 13 | */ 14 | public class HytrixException extends HystrixBadRequestException { 15 | 16 | private static final long serialVersionUID = -2437160791033393978L; 17 | 18 | public HytrixException(String msg) { 19 | super(msg); 20 | } 21 | 22 | public HytrixException(Exception e) { 23 | this(e.getMessage()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/exception/service/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.exception.service; 2 | 3 | import com.javayh.common.exception.BaseException; 4 | 5 | /** 6 | *

7 | * service处理异常 controller处理 8 | *

9 | * 10 | * @version 1.0.0 11 | * @author Dylan-haiji 12 | * @since 2020/3/1 13 | */ 14 | public class ServiceException extends BaseException { 15 | 16 | /** 17 | * 18 | */ 19 | private static final long serialVersionUID = -2437160791033393978L; 20 | 21 | public ServiceException(String msg) { 22 | super(msg); 23 | } 24 | 25 | public ServiceException(Exception e) { 26 | this(e.getMessage()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/feign/FeignClientOkHttpConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.feign; 2 | 3 | import feign.Feign; 4 | import okhttp3.ConnectionPool; 5 | import okhttp3.OkHttpClient; 6 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.cloud.openfeign.FeignAutoConfiguration; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | import java.util.concurrent.TimeUnit; 13 | 14 | /** 15 | *

16 | * Feign Client 17 | *

18 | * 19 | * @author Yang Haiji 20 | * @version 1.0.0 21 | * @since 2020-05-04 12:13 22 | */ 23 | @ConditionalOnClass(Feign.class) 24 | @AutoConfigureBefore(FeignAutoConfiguration.class) 25 | public class FeignClientOkHttpConfiguration { 26 | 27 | @Bean 28 | public OkHttpClient okHttpClient() { 29 | return new OkHttpClient.Builder() 30 | // 连接超时 31 | .connectTimeout(30, TimeUnit.SECONDS) 32 | // 响应超时 33 | .readTimeout(30, TimeUnit.SECONDS) 34 | // 写超时 35 | .writeTimeout(30, TimeUnit.SECONDS) 36 | // 是否自动重连 37 | .retryOnConnectionFailure(true) 38 | // 连接池 39 | .connectionPool(new ConnectionPool()) 40 | .build(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/feign/FeignFailResult.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.feign; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | *

7 | * feign异常返回 8 | *

9 | * 10 | * @version 1.0.0 11 | * @author Dylan-haiji 12 | * @since 2020/3/2 13 | */ 14 | @Data 15 | public class FeignFailResult { 16 | 17 | private int status; 18 | 19 | private String resp_msg; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/feign/GlobalFeignConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.common.feign; 17 | 18 | import feign.Logger; 19 | import feign.Request; 20 | import feign.Retryer; 21 | import org.springframework.context.annotation.Bean; 22 | 23 | import static java.util.concurrent.TimeUnit.SECONDS; 24 | 25 | /** 26 | *

27 | * feign全局 日志输出 28 | *

29 | * 30 | * @version 1.0.0 31 | * @author Dylan-haiji 32 | * @since 2020/3/2 33 | */ 34 | public class GlobalFeignConfig { 35 | 36 | /** 37 | *

38 | * 打印请求日志 39 | *

40 | * @version 1.0.0 41 | * @author Dylan-haiji 42 | * @since 2020/4/9 43 | * @param 44 | * @return feign.Logger.Level 45 | */ 46 | @Bean 47 | public feign.Logger.Level multipartLoggerLevel() { 48 | return feign.Logger.Level.FULL; 49 | } 50 | 51 | 52 | /** 53 | * 配置请求重试 54 | * 55 | */ 56 | @Bean 57 | public Retryer feignRetry() { 58 | return new Retryer.Default(200, SECONDS.toMillis(2), 10); 59 | } 60 | 61 | 62 | /** 63 | * 设置请求超时时间 64 | *默认 65 | * public Options() { 66 | * this(10 * 1000, 60 * 1000); 67 | * } 68 | * 69 | */ 70 | @Bean 71 | Request.Options feignOptions() { 72 | return new Request.Options(60 * 1000, 60 * 1000); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/i18n/annotation/EnableAutoInternationalization.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.i18n.annotation; 2 | 3 | import com.javayh.common.selector.SpringI18nSelector; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Inherited; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | /** 14 | *

15 | * 自定义启动类注解,以免多次引用 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-03-02 14:35 21 | */ 22 | @Target({ ElementType.TYPE }) 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Documented 25 | @Inherited 26 | @Import({ SpringI18nSelector.class }) 27 | public @interface EnableAutoInternationalization { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/i18n/config/I18nProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.common.i18n.config; 17 | 18 | import org.springframework.boot.context.properties.ConfigurationProperties; 19 | 20 | /** 21 | *

22 | * 国际化 23 | *

24 | * 25 | * @author Dylan-haiji 26 | * @version 1.0.0 27 | * @since 2020-03-27 15:23 28 | */ 29 | @ConfigurationProperties( 30 | prefix = "spring.messages", 31 | ignoreUnknownFields = true 32 | ) 33 | public class I18nProperties { 34 | 35 | private String basename; 36 | 37 | public String getBasename() { 38 | return basename; 39 | } 40 | 41 | public void setBasename(String basename) { 42 | this.basename = basename; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/mdc/MdcThreadPoolTaskExecutor.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.mdc; 2 | 3 | import org.slf4j.MDC; 4 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * 这是{@link ThreadPoolTaskExecutor}的一个简单替换,可以在每个任务之前设置子线程的MDC数据。 10 | *

11 | * 在记录日志的时候,一般情况下我们会使用MDC来存储每个线程的特有参数,如身份信息等,以便更好的查询日志。 12 | * 但是Logback在最新的版本中因为性能问题,不会自动的将MDC的内存传给子线程。所以Logback建议在执行异步线程前 13 | * 先通过MDC.getCopyOfContextMap()方法将MDC内存获取出来,再传给线程。 14 | * 并在子线程的执行的最开始调用MDC.setContextMap(context)方法将父线程的MDC内容传给子线程。 15 | *

16 | * https://logback.qos.ch/manual/mdc.html 17 | * 18 | * @author yuhao.wang3 19 | */ 20 | public class MdcThreadPoolTaskExecutor extends ThreadPoolTaskExecutor { 21 | 22 | /** 23 | * 所有线程都会委托给这个execute方法,在这个方法中我们把父线程的MDC内容赋值给子线程 24 | * https://logback.qos.ch/manual/mdc.html#managedThreads 25 | * @param runnable 26 | */ 27 | @Override 28 | public void execute(Runnable runnable) { 29 | /* 获取父线程MDC中的内容,必须在run方法之前,否则等异步线程执行的时候有可能MDC里面的值已经被清空了,这个时候就会返回null */ 30 | Map context = MDC.getCopyOfContextMap(); 31 | super.execute(() -> run(runnable, context)); 32 | } 33 | 34 | /** 35 | * 子线程委托的执行方法 36 | * @param runnable {@link Runnable} 37 | * @param context 父线程MDC内容 38 | */ 39 | private void run(Runnable runnable, Map context) { 40 | /* 将父线程的MDC内容传给子线程 */ 41 | if (context != null) { 42 | try { 43 | MDC.setContextMap(context); 44 | } 45 | catch (Exception e) { 46 | logger.error(e.getMessage(), e); 47 | } 48 | } 49 | try { 50 | /* 执行异步操作 */ 51 | runnable.run(); 52 | } 53 | finally { 54 | /* 清空MDC内容 */ 55 | MDC.clear(); 56 | } 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | *

3 | * 内部支持 http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20 4 | *

5 | * 6 | * @author Dylan-haiji 7 | * @version 1.0.0 8 | * @since 2020-03-01 21:11 9 | */ 10 | package com.javayh.common; -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/result/MessageBody.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 心跳健康消息体 14 | *

15 | * 16 | * @author Dylan-haiji 17 | * @version 1.0.0 18 | * @since 2020-03-10 13:56 19 | */ 20 | @Data 21 | @Builder 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public class MessageBody implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | /**服务标识*/ 28 | private Long msgId; 29 | /**发送的消息*/ 30 | private String msg; 31 | /**服务名*/ 32 | private String appName; 33 | /**接受消息的时间*/ 34 | private Date createDate; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/selector/ExceptionSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 实例化 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-03 10:53 14 | */ 15 | public class ExceptionSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { "com.javayh.common.exception.GlobalExceptionHandler" }; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/selector/SpringI18nSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 实例化 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-03 10:53 14 | */ 15 | public class SpringI18nSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { "com.javayh.common.i18n.config.InternationalConfig", 20 | "com.javayh.common.i18n.I18nResponseBodyAdvice" }; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/selector/SpringSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 实例化 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-03 10:53 14 | */ 15 | public class SpringSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { 20 | "com.javayh.common.util.spring.SpringUtils", 21 | "com.javayh.common.config.MyCommandLineRunner", 22 | "com.javayh.common.feign.GlobalFeignConfig", 23 | "com.javayh.common.feign.FeignClientOkHttpConfiguration", 24 | "com.javayh.common.feign.FeignExceptionConfig" 25 | }; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/IAction.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | /** 6 | *

7 | * 其他附属操作 8 | *

9 | * @version 1.0.0 10 | * @author Dylan-haiji 11 | * @since 2020/4/20 12 | */ 13 | @FunctionalInterface 14 | public interface IAction { 15 | 16 | /** 17 | *

18 | * 执行器 19 | *

20 | * @version 1.0.0 21 | * @author Dylan-haiji 22 | * @since 2020/4/20 23 | * @param param 24 | * @return void 25 | */ 26 | void run(T param); 27 | 28 | 29 | static Boolean allNotNull(T param){ 30 | return ObjectUtils.allNotNull(param); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/IPUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.net.Inet4Address; 6 | import java.net.InetAddress; 7 | import java.net.NetworkInterface; 8 | import java.util.Enumeration; 9 | 10 | /** 11 | *

12 | * 获取Ip 13 | *

14 | * 15 | * @author Dylan-haiji 16 | * @version 1.0.0 17 | * @since 2020-03-01 22:59 18 | */ 19 | @Slf4j 20 | public class IPUtils { 21 | 22 | public static String getHostIp() { 23 | try { 24 | Enumeration allNetInterfaces = NetworkInterface 25 | .getNetworkInterfaces(); 26 | while (allNetInterfaces.hasMoreElements()) { 27 | NetworkInterface netInterface = allNetInterfaces 28 | .nextElement(); 29 | Enumeration addresses = netInterface.getInetAddresses(); 30 | while (addresses.hasMoreElements()) { 31 | InetAddress ip = addresses.nextElement(); 32 | if (ip instanceof Inet4Address hostIp && !ip.isLoopbackAddress() && !ip.getHostAddress().contains(":")) { 33 | return hostIp.getHostAddress(); 34 | } 35 | } 36 | } 37 | } 38 | catch (Exception e) { 39 | log.error(e.getStackTrace()[0].getLineNumber() 40 | + e.getStackTrace()[0].getClassName()); 41 | } 42 | return null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/RandomUtil.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.concurrent.ThreadLocalRandom; 6 | 7 | /** 8 | *

9 | * 流水号生产 10 | *

11 | * 12 | * @version 1.0.0 13 | * @author Dylan-haiji 14 | * @since 2020/3/1 15 | */ 16 | public class RandomUtil { 17 | 18 | private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); 19 | 20 | /** 21 | *

22 | * 生产流水号 23 | *

24 | * @version 1.0.0 25 | * @author Dylan-haiji 26 | * @since 2020/3/1 27 | * @param 28 | * @return java.lang.String 29 | */ 30 | public static String generateOrderCode() { 31 | return DateTime.now().toString("yyyyMMddHHmmssSS") + generateNumber(4); 32 | } 33 | 34 | // num为随机数流水号 35 | public static String generateNumber(final int num) { 36 | StringBuilder sb = new StringBuilder(); 37 | for (int i = 1; i <= num; i++) { 38 | sb.append(RANDOM.nextInt(9)); 39 | } 40 | return sb.toString(); 41 | 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | *

7 | * 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-09 21:54 13 | */ 14 | public class StringUtils extends org.apache.commons.lang3.StringUtils { 15 | 16 | /** 17 | *

18 | * 加言处理 19 | *

20 | * @version 1.0.0 21 | * @author Dylan-haiji 22 | * @since 2020/3/24 23 | * @param str 24 | * @return java.lang.String 25 | */ 26 | public static String setSuffix(String str, String suffix) { 27 | return str + suffix; 28 | } 29 | 30 | public static boolean isEmpty(String str) { 31 | return isNull(str) || "".equals(str.trim()); 32 | } 33 | 34 | public static boolean isNotEmpty(String cs) { 35 | return !isEmpty(cs); 36 | } 37 | 38 | public static boolean isEmpty(Collection coll) { 39 | return isNull(coll) || coll.isEmpty(); 40 | } 41 | 42 | public static boolean isNull(Object object) { 43 | return object == null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/bean/BeanUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.bean; 2 | 3 | import com.javayh.common.util.IAction; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.commons.lang3.ObjectUtils; 6 | 7 | /** 8 | *

9 | * copy 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-04-20 15 | */ 16 | @Slf4j 17 | public class BeanUtils { 18 | 19 | /** 20 | *

21 | * 对象Copy 22 | *

23 | * @version 1.0.0 24 | * @author Dylan-haiji 25 | * @since 2020/4/20 26 | * @param source 源对象 27 | * @param target 目标对象 28 | * @return T 29 | */ 30 | public static T copyProperties(O source, Class target) { 31 | T t = baseMapper(source, target); 32 | return t; 33 | } 34 | 35 | /** 36 | *

37 | * 对象Copy 38 | *

39 | * @version 1.0.0 40 | * @author Dylan-haiji 41 | * @since 2020/4/20 42 | * @param source 源对象 43 | * @param target 目标对象 44 | * @param action 其他操作 45 | * @return T 46 | */ 47 | public static T copyProperties(O source, Class target, IAction action) { 48 | T t = baseMapper(source, target); 49 | action.run(t); 50 | return t; 51 | } 52 | 53 | private static T baseMapper(O source, Class target) { 54 | if(!ObjectUtils.allNotNull(source)){ 55 | log.error("源对象为空"); 56 | return null; 57 | } 58 | T instance = null; 59 | try { 60 | instance = target.getDeclaredConstructor().newInstance(); 61 | } catch (Exception e) { 62 | log.error("创建对象异常" + e.getMessage()); 63 | } 64 | org.springframework.beans.BeanUtils.copyProperties(source,instance); 65 | return instance; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/file/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.file; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.io.File; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | import java.nio.file.StandardCopyOption; 12 | 13 | /** 14 | *

15 | * 文件操作 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-03-30 11:10 21 | */ 22 | @Slf4j 23 | public class FileUtils { 24 | 25 | public static void writeFile(String content, String path) { 26 | // 检测文件夹是否存在,不存在则创建文件夹和文件 27 | createFile(path); 28 | FileWriter writer = null; 29 | try { 30 | writer = new FileWriter(path); 31 | writer.write(content); 32 | writer.flush(); 33 | } 34 | catch (IOException e) { 35 | log.error("写入文件错误 " + e); 36 | } 37 | finally { 38 | try { 39 | writer.close(); 40 | } 41 | catch (IOException e) { 42 | log.error("文件流关闭异常 " + e); 43 | } 44 | } 45 | } 46 | 47 | /** 48 | *

49 | * 创建文件 50 | *

51 | * @version 1.0.0 52 | * @author Dylan-haiji 53 | * @since 2020/3/30 54 | * @param path 路径 55 | * @return java.io.File 56 | */ 57 | private static File createFile(String path) { 58 | // 创建文件夹 59 | if (path.contains("/")) { 60 | String[] split = path.split("/"); 61 | String fileName = split[split.length - 1]; 62 | String dirPath = path.replace(fileName, ""); 63 | File dir = new File(dirPath); 64 | if (!dir.exists()) { 65 | dir.mkdirs(); 66 | } 67 | } 68 | File file = new File(path); 69 | if (!file.exists()) { 70 | try { 71 | file.createNewFile(); 72 | } 73 | catch (IOException e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | return file; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/id/IdGen.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.id; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | *

7 | * id生成器 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-06 15:55 13 | */ 14 | public class IdGen { 15 | 16 | /** 17 | *

18 | * uuid 19 | *

20 | * @version 1.0.0 21 | * @author Dylan-haiji 22 | * @since 2020/3/6 23 | * @param 24 | * @return java.lang.String 25 | */ 26 | public static String UUID() { 27 | return UUID.randomUUID().toString(); 28 | } 29 | 30 | /** 31 | *

32 | * 去除 - 的uuid 33 | *

34 | * @version 1.0.0 35 | * @author Dylan-haiji 36 | * @since 2020/3/6 37 | * @param 38 | * @return java.lang.Integer 39 | */ 40 | public static String UUIDReplace() { 41 | return UUID.randomUUID().toString().replaceAll("-", "").trim(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/log/Log.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.log; 2 | 3 | import com.javayh.common.constant.ConstantUtils; 4 | import com.javayh.common.util.servlet.RequestUtils; 5 | import com.javayh.common.util.spring.SpringUtils; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.core.task.TaskExecutor; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.util.concurrent.CompletableFuture; 12 | 13 | /** 14 | *

15 | * Log记录 16 | *

17 | * 18 | * @author Dylan-haiji 19 | * @version 1.0.0 20 | * @since 2020-04-01 21:53 21 | */ 22 | @Slf4j 23 | public class Log { 24 | 25 | @Autowired(required = false) 26 | private static TaskExecutor taskExecutor = SpringUtils.getBean("taskExecutor", 27 | TaskExecutor.class); 28 | 29 | /** 30 | *

31 | * 统一日志输出 32 | *

33 | * @version 1.0.0 34 | * @author Dylan-haiji 35 | * @since 2020/2/28 36 | * @param 37 | * @param stackTrace 38 | * @return void 39 | */ 40 | public static void error(String pr, StackTraceElement[] stackTrace) { 41 | HttpServletRequest request = RequestUtils.getRequest(); 42 | StringBuilder sb = new StringBuilder(); 43 | String requestUri = request.getRequestURI(); 44 | sb.append(ConstantUtils.NEWLINE).append(ConstantUtils.PREFIX).append(pr).append("异常 method -->").append(request.getMethod()); 45 | sb.append(ConstantUtils.NEWLINE).append(ConstantUtils.PREFIX).append(pr).append("异常 requestURI -->").append(requestUri); 46 | CompletableFuture.runAsync(() -> { 47 | for (int depth = 1,count = 0; depth < stackTrace.length; ++depth) { 48 | sb.append(ConstantUtils.NEWLINE).append(ConstantUtils.PREFIX).append(pr).append(" -->").append(stackTrace[depth]); 49 | if (count == ConstantUtils.MAX_STACK_DEPTH) { 50 | break; 51 | } 52 | count ++; 53 | } 54 | log.error(sb.toString()); 55 | }, taskExecutor); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/servlet/RequestUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.servlet; 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 | *

10 | * 获取Request 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-03-03 13:42 16 | */ 17 | public class RequestUtils { 18 | 19 | public static HttpServletRequest getRequest() { 20 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder 21 | .getRequestAttributes()).getRequest(); 22 | return request; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/spring/SpringUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.spring; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.core.env.Environment; 7 | 8 | /** 9 | *

10 | * spring获取bean 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-03-01 23:03 16 | */ 17 | public class SpringUtils implements ApplicationContextAware { 18 | 19 | private static ApplicationContext applicationContext = null; 20 | 21 | @Override 22 | public void setApplicationContext(ApplicationContext applicationContext) 23 | throws BeansException { 24 | SpringUtils.applicationContext = applicationContext; 25 | } 26 | 27 | public static T getBean(Class clazz) { 28 | checkApplicationContext(); 29 | return applicationContext.getBean(clazz); 30 | } 31 | 32 | public static T getBean(String name, Class clazz) { 33 | checkApplicationContext(); 34 | return applicationContext.getBean(name, clazz); 35 | } 36 | 37 | public static String getProperty(String key) { 38 | return applicationContext.getBean(Environment.class).getProperty(key); 39 | } 40 | 41 | private static void checkApplicationContext() { 42 | if (applicationContext == null) { 43 | throw new IllegalStateException( 44 | "applicaitonContext未注入,请在applicationContext.xml中定义SpringUtils"); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/java/com/javayh/common/util/task/ThreadTaskUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.common.util.task; 2 | 3 | import com.javayh.common.mdc.MdcThreadPoolTaskExecutor; 4 | 5 | import java.util.concurrent.ThreadPoolExecutor; 6 | 7 | /** 8 | *

9 | * 线程池 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-01 23:08 15 | */ 16 | public class ThreadTaskUtils { 17 | 18 | private static MdcThreadPoolTaskExecutor taskExecutor = null; 19 | 20 | static { 21 | taskExecutor = new MdcThreadPoolTaskExecutor(); 22 | // 核心线程数 23 | taskExecutor.setCorePoolSize(5); 24 | // 最大线程数 25 | taskExecutor.setMaxPoolSize(50); 26 | // 队列最大长度 27 | taskExecutor.setQueueCapacity(1000); 28 | // 线程池维护线程所允许的空闲时间(单位秒) 29 | taskExecutor.setKeepAliveSeconds(120); 30 | // 线程池对拒绝任务(无线程可用)的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 31 | // ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃. 32 | taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); 33 | 34 | taskExecutor.initialize(); 35 | } 36 | 37 | public static void run(Runnable runnable) { 38 | taskExecutor.execute(runnable); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/javayh-dependencies/javayh-common-starter/src/main/resources/META-INF/spring.factories -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/SensitiveWord.txt: -------------------------------------------------------------------------------- 1 | sb 2 | shabi 3 | 傻逼 4 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.BLUE} 2 | _ _ ____ _ 3 | | | | | | _ \ | | 4 | | | __ _ __ __ __ _ _ _ | |__ | |_) | ___ ___ | |_ 5 | _ | | / _` |\ \ / // _` || | | || '_ \ | _ < / _ \ / _ \ | __| 6 | | |__| || (_| | \ V /| (_| || |_| || | | | | |_) || (_) || (_) || |_ 7 | \____/ \__,_| \_/ \__,_| \__, ||_| |_| |____/ \___/ \___/ \__| 8 | __/ | 9 | |___/ 10 | ${AnsiColor.BRIGHT_RED} 11 | Project (version): Javayh-Boot 1.0.0 12 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/common/common.properties: -------------------------------------------------------------------------------- 1 | business_data=\u53C2\u6570\u5F02\u5E38 2 | failure_msg=\u5931\u8D25 3 | hystrix_fallback_handler=\u670D\u52A1\u7AEF\u5F02\u5E38,\u7A0D\u540E \u518D\u8BD5 4 | service_call_exception=\u670D\u52A1\u8C03\u7528\u5F02\u5E38 5 | success_msg=\u6210\u529F -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/common/common_en_US.properties: -------------------------------------------------------------------------------- 1 | business_data=parameters of the abnormal 2 | failure_msg=server exception 3 | hystrix_fallback_handler=server exception, try again later 4 | service_call_exception=service_call_exception 5 | success_msg=success -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/common/common_zh_CN.properties: -------------------------------------------------------------------------------- 1 | business_data=\u53C2\u6570\u5F02\u5E38 2 | failure_msg=\u5931\u8D25 3 | hystrix_fallback_handler=\u670D\u52A1\u7AEF\u5F02\u5E38,\u7A0D\u540E \u518D\u8BD5 4 | service_call_exception=\u670D\u52A1\u8C03\u7528\u5F02\u5E38 5 | success_msg=\u6210\u529F -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login.properties -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login_en_US.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login_en_US.properties -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login_zh_CN.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanghaiji/javayh-platform/aedf95ec3ffab57c56a8870d05145838cef97805/javayh-dependencies/javayh-common-starter/src/main/resources/i18n/login/login_zh_CN.properties -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/validation/validation.properties: -------------------------------------------------------------------------------- 1 | content_not_blank=\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A 2 | path_not_blank=\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/validation/validation_en_US.properties: -------------------------------------------------------------------------------- 1 | content_not_blank=the content can not be blank 2 | path_not_blank=the path can not be blank -------------------------------------------------------------------------------- /javayh-dependencies/javayh-common-starter/src/main/resources/i18n/validation/validation_zh_CN.properties: -------------------------------------------------------------------------------- 1 | content_not_blank=\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A 2 | path_not_blank=\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 关系性数据库多数据源 12 | javayh-data-sources-starter 13 | jar 14 | 15 | 16 | com.javayh 17 | javayh-mybatis-starter 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/java/com/javayh/datasource/annotation/DataSource.java: -------------------------------------------------------------------------------- 1 | package com.javayh.datasource.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * @ClassName DataSource 11 | * @Description 数据源注解 12 | * @Author Yang haiji 13 | * @Version 1.0.0 14 | */ 15 | @Target({ ElementType.METHOD, ElementType.TYPE }) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Documented 18 | public @interface DataSource { 19 | 20 | /** 21 | * @Description 数据库名称 22 | * @UserModule: javayh-datasource 23 | * @author Yang haiji 24 | */ 25 | String name(); 26 | 27 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/java/com/javayh/datasource/aop/DataSourceAOP.java: -------------------------------------------------------------------------------- 1 | package com.javayh.datasource.aop; 2 | 3 | import com.javayh.datasource.annotation.DataSource; 4 | import com.javayh.datasource.constant.DataSourceKey; 5 | import com.javayh.datasource.util.DataSourceHolder; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.aspectj.lang.JoinPoint; 8 | import org.aspectj.lang.annotation.After; 9 | import org.aspectj.lang.annotation.Aspect; 10 | import org.aspectj.lang.annotation.Before; 11 | import org.springframework.core.annotation.Order; 12 | 13 | /** 14 | * @ClassName DataSourceAOP 15 | * @Description 切换数据源Advice 16 | * @Author Yang haiji 17 | * @Version 1.0.0 18 | */ 19 | @Slf4j 20 | @Aspect 21 | @Order(-1) // 保证该AOP在@Transactional之前执行 22 | public class DataSourceAOP { 23 | 24 | @Before("@annotation(ds)") 25 | public void changeDataSource(JoinPoint point, DataSource ds) throws Throwable { 26 | String dsId = ds.name(); 27 | try { 28 | DataSourceKey dataSourceKey = DataSourceKey.valueOf(dsId); 29 | DataSourceHolder.setDataSourceKey(dataSourceKey); 30 | } 31 | catch (Exception e) { 32 | log.error("数据源[{}]不存在,使用默认数据源 > {}", ds.name(), point.getSignature()); 33 | } 34 | 35 | } 36 | 37 | @After("@annotation(ds)") 38 | public void restoreDataSource(JoinPoint point, DataSource ds) { 39 | log.debug("Revert DataSource :transIdo {}, > {}", ds.name(), point.getSignature()); 40 | DataSourceHolder.clearDataSourceKey(); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/java/com/javayh/datasource/constant/DataSourceKey.java: -------------------------------------------------------------------------------- 1 | package com.javayh.datasource.constant; 2 | 3 | /** 4 | * @ClassName DataSourceKey 5 | * @Description 数据源定义 6 | * @Author Yang haiji 7 | * @Version 1.0.0 8 | */ 9 | public enum DataSourceKey { 10 | 11 | core, follower 12 | 13 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/java/com/javayh/datasource/util/DataSourceHolder.java: -------------------------------------------------------------------------------- 1 | package com.javayh.datasource.util; 2 | 3 | import com.javayh.datasource.constant.DataSourceKey; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | /** 7 | * @ClassName DataSourceHolder 8 | * @Description 用于数据源切换 9 | * @Author Yang haiji 10 | * @Version 1.0.0 11 | */ 12 | @Slf4j 13 | public class DataSourceHolder { 14 | 15 | /** 16 | * 获取线程数据源 17 | */ 18 | private static final ThreadLocal dataSourceKey = new ThreadLocal<>(); 19 | 20 | /** 21 | * @Description 得到当前的数据库连接 22 | * @UserModule: javayh-datasource 23 | * @author Yang haiji 24 | * @date 2020/1/8 25 | */ 26 | public static DataSourceKey getDataSourceKey() { 27 | return DataSourceHolder.dataSourceKey.get(); 28 | } 29 | 30 | /** 31 | * @Description 设置当前的数据库连接 32 | * @UserModule: javayh-datasource 33 | * @author Yang haiji 34 | * @date 2020/1/8 35 | */ 36 | public static void setDataSourceKey(DataSourceKey type) { 37 | dataSourceKey.set(type); 38 | } 39 | 40 | /** 41 | * @Description 清除当前的数据库连接 42 | * @UserModule: javayh-datasource 43 | * @author Yang haiji 44 | * @date 2020/1/8 45 | */ 46 | public static void clearDataSourceKey() { 47 | dataSourceKey.remove(); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/java/com/javayh/datasource/util/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | package com.javayh.datasource.util; 2 | 3 | import com.javayh.datasource.constant.DataSourceKey; 4 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 5 | import javax.sql.DataSource; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * spring动态数据源(需要继承AbstractRoutingDataSource) 11 | */ 12 | public class DynamicDataSource extends AbstractRoutingDataSource { 13 | 14 | private Map datasources; 15 | 16 | public DynamicDataSource() { 17 | datasources = new HashMap<>(); 18 | 19 | super.setTargetDataSources(datasources); 20 | 21 | } 22 | 23 | public void addDataSource(DataSourceKey key, T data) { 24 | datasources.put(key, data); 25 | } 26 | 27 | @Override 28 | protected Object determineCurrentLookupKey() { 29 | return DataSourceHolder.getDataSourceKey(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-data-sources-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.javayh.datasource.conf.DataSourceAutoConfig -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | jar 12 | javayh-heartbeat-starter 13 | 心跳检测 14 | 15 | 16 | 17 | com.javayh 18 | javayh-common-starter 19 | true 20 | 21 | 22 | io.netty 23 | netty-all 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/annotation/EnableAutoHeartBeat.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.annotation; 2 | 3 | import com.javayh.client.selector.HeartImportSelector; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | *

14 | * 自动开启心跳检测 15 | *

16 | * 17 | * @author Dylan-haiji 18 | * @version 1.0.0 19 | * @since 2020-03-10 15:36 20 | */ 21 | @Target({ ElementType.TYPE }) 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Documented 24 | @Deprecated 25 | @Import(HeartImportSelector.class) 26 | public @interface EnableAutoHeartBeat { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/config/HeartBeatConfig.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.config; 2 | 3 | import com.javayh.client.properties.HeartbeatClientProperties; 4 | import com.javayh.common.result.MessageBody; 5 | import org.apache.commons.lang3.time.DateFormatUtils; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @version 1.0.0 16 | * @author Dylan-haiji 17 | * @since 2020/3/10 18 | */ 19 | public class HeartBeatConfig { 20 | 21 | @Bean(value = "heartBeat") 22 | public MessageBody heartBeat(HeartbeatClientProperties properties) { 23 | return MessageBody.builder() 24 | .msgId(properties.getChannelId()) 25 | .msg("ping") 26 | .appName(properties.getAppName()) 27 | .createDate(new Date()).build(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/encode/HeartbeatEncode.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.encode; 2 | 3 | import com.javayh.common.result.MessageBody; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.Unpooled; 6 | import io.netty.channel.ChannelHandlerContext; 7 | import io.netty.handler.codec.MessageToByteEncoder; 8 | 9 | import java.io.ByteArrayOutputStream; 10 | 11 | import org.apache.commons.io.IOUtils; 12 | 13 | import com.esotericsoftware.kryo.Kryo; 14 | import com.esotericsoftware.kryo.KryoException; 15 | import com.esotericsoftware.kryo.io.Output; 16 | 17 | /** 18 | *

19 | * 客户端编码器 20 | *

21 | * 22 | * @version 1.0.0 23 | * @author Dylan-haiji 24 | * @since 2020/3/10 25 | */ 26 | public class HeartbeatEncode extends MessageToByteEncoder { 27 | private Kryo kryo = new Kryo(); 28 | @Override 29 | protected void encode(ChannelHandlerContext handlerContext, 30 | MessageBody messageBody, ByteBuf byteBuf) throws Exception { 31 | //将对象转换为byte 32 | byte[] body = convertToBytes(messageBody); 33 | //读取消息的长度 34 | int dataLength = body.length; 35 | //先将消息长度写入,也就是消息头 36 | byteBuf.writeInt(dataLength); 37 | //消息体中包含我们要发送的数据 38 | byteBuf.writeBytes(body); 39 | } 40 | 41 | private byte[] convertToBytes(MessageBody messageBody) { 42 | 43 | ByteArrayOutputStream bos = null; 44 | Output output = null; 45 | try { 46 | bos = new ByteArrayOutputStream(); 47 | output = new Output(bos); 48 | kryo.writeObject(output, messageBody); 49 | output.flush(); 50 | 51 | return bos.toByteArray(); 52 | } catch (KryoException e) { 53 | e.printStackTrace(); 54 | }finally{ 55 | IOUtils.closeQuietly(output); 56 | IOUtils.closeQuietly(bos); 57 | } 58 | return null; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/handle/EchoClientHandle.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.handle; 2 | 3 | import com.javayh.common.constant.ConstantUtils; 4 | import com.javayh.common.result.MessageBody; 5 | import com.javayh.common.util.spring.SpringUtils; 6 | import io.netty.buffer.ByteBuf; 7 | import io.netty.channel.ChannelFutureListener; 8 | import io.netty.channel.ChannelHandlerContext; 9 | import io.netty.channel.SimpleChannelInboundHandler; 10 | import io.netty.handler.timeout.IdleState; 11 | import io.netty.handler.timeout.IdleStateEvent; 12 | import io.netty.util.CharsetUtil; 13 | import lombok.extern.slf4j.Slf4j; 14 | 15 | /** 16 | *

17 | * 18 | *

19 | * 20 | * @version 1.0.0 21 | * @author Dylan-haiji 22 | * @since 2020/3/10 23 | */ 24 | @Slf4j 25 | public class EchoClientHandle extends SimpleChannelInboundHandler { 26 | 27 | @Override 28 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) 29 | throws Exception { 30 | if (evt instanceof IdleStateEvent) { 31 | IdleStateEvent idleStateEvent = (IdleStateEvent) evt; 32 | if (idleStateEvent.state() == IdleState.WRITER_IDLE) { 33 | log.info("已经10秒没收到消息了"); 34 | // 向服务端发送消息 35 | MessageBody heartBeat = SpringUtils.getBean("heartBeat", 36 | MessageBody.class); 37 | ctx.writeAndFlush(heartBeat) 38 | .addListener(ChannelFutureListener.CLOSE_ON_FAILURE); 39 | } 40 | 41 | } 42 | super.userEventTriggered(ctx, evt); 43 | } 44 | 45 | /** 46 | * 每当从服务端接收到新数据时,都会使用收到的消息调用此方法 channelRead0(),在此示例中,接收消息的类型是ByteBuf。 47 | * @param channelHandlerContext 48 | * @param byteBuf 49 | * @throws Exception 50 | */ 51 | @Override 52 | protected void channelRead0(ChannelHandlerContext channelHandlerContext, 53 | ByteBuf byteBuf) throws Exception { 54 | // 从服务端收到消息时被调用 55 | StringBuilder sb = new StringBuilder(); 56 | sb.append("客户端收到消息==>") 57 | .append(byteBuf.toString(CharsetUtil.UTF_8)); 58 | log.info(sb.toString()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/heart/CustomerHandleInitializer.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.heart; 2 | 3 | import com.javayh.client.encode.HeartbeatEncode; 4 | import com.javayh.client.handle.EchoClientHandle; 5 | import io.netty.channel.Channel; 6 | import io.netty.channel.ChannelInitializer; 7 | import io.netty.handler.timeout.IdleStateHandler; 8 | 9 | /** 10 | *

11 | * 12 | *

13 | * 14 | * @version 1.0.0 15 | * @author Dylan-haiji 16 | * @since 2020/3/10 17 | */ 18 | public class CustomerHandleInitializer extends ChannelInitializer { 19 | 20 | @Override 21 | protected void initChannel(Channel channel) throws Exception { 22 | channel.pipeline() 23 | // 10 秒没发送消息 将IdleStateHandler 添加到 ChannelPipeline 中 24 | .addLast(new IdleStateHandler(0, 10, 0)).addLast(new HeartbeatEncode()) 25 | .addLast(new EchoClientHandle()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/heart/HeartbeatClient.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.heart; 2 | 3 | import com.javayh.client.properties.HeartbeatClientProperties; 4 | import io.netty.bootstrap.Bootstrap; 5 | import io.netty.channel.ChannelFuture; 6 | import io.netty.channel.EventLoopGroup; 7 | import io.netty.channel.nio.NioEventLoopGroup; 8 | import io.netty.channel.socket.SocketChannel; 9 | import io.netty.channel.socket.nio.NioSocketChannel; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 14 | 15 | import javax.annotation.PostConstruct; 16 | 17 | /** 18 | *

19 | * 客户端 20 | *

21 | * 22 | * @version 1.0.0 23 | * @author Dylan-haiji 24 | * @since 2020/3/10 25 | */ 26 | // @EnableConfigurationProperties(value = HeartbeatClientProperties.class) 27 | public class HeartbeatClient { 28 | 29 | private final static Logger LOGGER = LoggerFactory.getLogger(HeartbeatClient.class); 30 | 31 | private EventLoopGroup group = new NioEventLoopGroup(); 32 | 33 | private SocketChannel socketChannel; 34 | 35 | @Autowired(required = false) 36 | private HeartbeatClientProperties properties; 37 | 38 | @PostConstruct 39 | public void start() throws InterruptedException { 40 | Bootstrap bootstrap = new Bootstrap(); 41 | /** 42 | * NioSocketChannel用于创建客户端通道,而不是NioServerSocketChannel。 43 | * 请注意,我们不像在ServerBootstrap中那样使用childOption(),因为客户端SocketChannel没有父服务器。 44 | */ 45 | bootstrap.group(group).channel(NioSocketChannel.class) 46 | .handler(new CustomerHandleInitializer()); 47 | /** 48 | * 启动客户端 我们应该调用connect()方法而不是bind()方法。 49 | */ 50 | ChannelFuture future = bootstrap 51 | .connect(properties.getHost(), properties.getPort()).sync(); 52 | if (future.isSuccess()) { 53 | LOGGER.info("启动 Netty 成功"); 54 | } 55 | 56 | socketChannel = (SocketChannel) future.channel(); 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/properties/HeartbeatClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.properties; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import javax.validation.constraints.NotBlank; 5 | import javax.validation.constraints.NotNull; 6 | 7 | /** 8 | *

9 | * 监听配置类 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-10 15:41 15 | */ 16 | @ConfigurationProperties( 17 | prefix = "heartbeat.server", 18 | ignoreUnknownFields = true 19 | ) 20 | public class HeartbeatClientProperties { 21 | 22 | private @NotNull Long channelId; 23 | private @NotBlank String host; 24 | private @NotNull Integer port; 25 | private @NotBlank String appName; 26 | 27 | public HeartbeatClientProperties() { 28 | } 29 | 30 | public Long getChannelId() { 31 | return channelId; 32 | } 33 | 34 | public void setChannelId(Long channelId) { 35 | this.channelId = channelId; 36 | } 37 | 38 | public String getHost() { 39 | return host; 40 | } 41 | 42 | public void setHost(String host) { 43 | this.host = host; 44 | } 45 | 46 | public Integer getPort() { 47 | return port; 48 | } 49 | 50 | public void setPort(Integer port) { 51 | this.port = port; 52 | } 53 | 54 | public String getAppName() { 55 | return appName; 56 | } 57 | 58 | public void setAppName(String appName) { 59 | this.appName = appName; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/java/com/javayh/client/selector/HeartImportSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.client.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 实现字段装配 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-02 15:59 14 | */ 15 | public class HeartImportSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { "com.javayh.client.config.HeartBeatConfig", 20 | "com.javayh.client.heart.HeartbeatClient", 21 | "com.javayh.client.properties.HeartbeatClientProperties" }; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/resources/META-INF/spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "groups": [ 3 | { 4 | "name": "heartbeat", 5 | "type": "com.javayh.client.properties.HeartbeatClientProperties", 6 | "sourceType": "com.javayh.client.properties.HeartbeatClientProperties" 7 | } 8 | ], 9 | "properties": [ 10 | { 11 | "name":"heartbeat.server.host", 12 | "type": "java.lang.String", 13 | "sourceType": "com.javayh.client.properties.HeartbeatClientProperties", 14 | "defaultValue": "localhost", 15 | "description": "heartbeat server host" 16 | }, 17 | { 18 | "name":"heartbeat.server.port", 19 | "type": "java.lang.Integer", 20 | "sourceType": "com.javayh.client.properties.HeartbeatClientProperties", 21 | "defaultValue": 8001, 22 | "description": "heartbeat server post" 23 | }, 24 | { 25 | "name":"heartbeat.server.channel-id", 26 | "type": "java.lang.Long", 27 | "sourceType": "com.javayh.client.properties.HeartbeatClientProperties", 28 | "defaultValue": 100, 29 | "description": "heartbeat server channel-id" 30 | } 31 | , 32 | { 33 | "name":"heartbeat.server.app-name", 34 | "type": "java.lang.String", 35 | "sourceType": "com.javayh.client.properties.HeartbeatClientProperties", 36 | "description": "heartbeat server app-name" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-heartbeat-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.javayh.client.config.HeartBeatConfig,\ 3 | com.javayh.client.heart.HeartbeatClient,\ 4 | com.javayh.client.properties.HeartbeatClientProperties -------------------------------------------------------------------------------- /javayh-dependencies/javayh-kafka-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | jar 12 | javayh-kafka-starter 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-stream-kafka 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-stream-binder-kafka 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-bus-kafka 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 日志处理 12 | javayh-log-starter 13 | jar 14 | 15 | 16 | com.javayh 17 | javayh-common-starter 18 | true 19 | 20 | 21 | com.javayh 22 | javayh-mybatis-starter 23 | true 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/annotation/EnableLogging.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.log.annotation; 17 | 18 | import com.javayh.log.selector.LogImportSelector; 19 | import org.springframework.context.annotation.Import; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | *

29 | * 启动日志框架支持 30 | *

31 | * @version 1.0.0 32 | * @author Dylan-haiji 33 | * @since 2020/3/2 34 | */ 35 | @Target(ElementType.TYPE) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Documented 38 | @Deprecated 39 | @Import(LogImportSelector.class) 40 | public @interface EnableLogging { 41 | 42 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/annotation/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.annotation; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.core.annotation.AliasFor; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | *

14 | * 日志记录 15 | *

16 | * 17 | * @author Dylan-haiji 18 | * @version 1.0.0 19 | * @since 2020-03-01 23:43 20 | */ 21 | @Documented 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target({ ElementType.METHOD, ElementType.TYPE }) 24 | public @interface SysLog { 25 | 26 | /** 27 | * 模块 28 | */ 29 | String value(); 30 | 31 | /** 32 | * 方法描述 33 | */ 34 | String detail() default ""; 35 | 36 | /** 37 | * 记录执行参数 38 | */ 39 | boolean recordRequestParam() default true; 40 | 41 | /** 42 | * 等级 1 - 9 等级越高 ,数字越大 43 | */ 44 | int level() default 1; 45 | 46 | /** 47 | * 是否持久化 48 | */ 49 | boolean persistence() default true; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/conf/LogAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.conf; 2 | 3 | import com.javayh.log.interceptor.LogInterceptor; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 5 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | /** 9 | *

10 | * 自定义拦截 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-03-02 16:10 16 | */ 17 | @ConditionalOnClass(WebMvcConfigurer.class) 18 | public class LogAutoConfig implements WebMvcConfigurer { 19 | 20 | @Override 21 | public void addInterceptors(InterceptorRegistry registry) { 22 | 23 | /** 24 | * 自定义拦截器,添加拦截路径和排除拦截路径 addPathPatterns():添加需要拦截的路径 25 | * excludePathPatterns():添加不需要拦截的路径 在括号中还可以使用集合的形式,如注释部分代码所示 26 | */ 27 | registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**"); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/entity/LogInfoEntity.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.entity; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | *

7 | * 日志记录 8 | *

9 | * 10 | * @author Yang Haiji 11 | * @version 1.0.0 12 | * @since 2020-04-16 22:05 13 | */ 14 | public record LogInfoEntity(List log) { 15 | } 16 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/entity/OperationLog.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | *

11 | * 记录参数 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-01 23:58 17 | */ 18 | @Data 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class OperationLog implements Serializable { 22 | 23 | /** 24 | * 唯一id 25 | */ 26 | private String id; 27 | 28 | /** 29 | * 模块 30 | */ 31 | private String mode; 32 | 33 | /* 34 | * 调用时间 35 | */ 36 | private String createTime; 37 | 38 | /** 39 | * 日志等级 40 | */ 41 | private Integer level; 42 | 43 | /** 44 | * 方法名 45 | */ 46 | private String method; 47 | 48 | /** 49 | * 参数 50 | */ 51 | private String args; 52 | 53 | /** 54 | * 操作人id 55 | */ 56 | private String userId; 57 | 58 | /** 59 | * 操作人 60 | */ 61 | private String userName; 62 | 63 | /** 64 | * 日志描述 65 | */ 66 | private String describe; 67 | 68 | /** 69 | * 方法运行时间 70 | */ 71 | private Long runTime; 72 | 73 | /** 74 | * 调用方ip 75 | */ 76 | private String callerIp; 77 | 78 | /** 79 | * 本地ip 80 | */ 81 | private String localHostIp; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/interceptor/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.interceptor; 2 | 3 | import org.springframework.web.servlet.HandlerInterceptor; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | /** 9 | *

10 | * 创建拦截器 11 | *

12 | * 13 | * @version 1.0.0 14 | * @author Dylan-haiji 15 | * @since 2020/3/2 16 | */ 17 | public class LogInterceptor implements HandlerInterceptor { 18 | 19 | @Override 20 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 21 | Object handler) { 22 | return true; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/mapper/LogMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.mapper; 2 | 3 | import com.javayh.log.entity.OperationLog; 4 | import org.apache.ibatis.annotations.Insert; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * 日志持久化 14 | *

15 | * @author Yang Haiji 16 | * @version 1.0.0 17 | * @since 2020-04-16 23:07 18 | */ 19 | public interface LogMapper { 20 | 21 | /** 22 | *

23 | * 分页查询 24 | *

25 | * @version 1.0.0 26 | * @author Dylan 27 | * @since 2020/4/16 28 | * @param t 29 | * @return java.util.List 30 | */ 31 | List findByPage(OperationLog t); 32 | 33 | 34 | /** 35 | *

36 | * 批量新增 37 | *

38 | * @version 1.0.0 39 | * @author Dylan 40 | * @since 2020/4/16 41 | * @param t 42 | * @return int 43 | */ 44 | int batchInsert(List t); 45 | } 46 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/java/com/javayh/log/selector/LogImportSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.log.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 实现字段装配 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-02 15:59 14 | */ 15 | public class LogImportSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { 20 | "com.javayh.log.aop.SysLogAop", 21 | "com.javayh.log.conf.LogAutoConfig", 22 | "com.javayh.log.log.LogError" 23 | }; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-log-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.javayh.log.aop.SysLogAop,\ 3 | com.javayh.log.conf.LogAutoConfig,\ 4 | com.javayh.log.log.LogError -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | jar 12 | javayh-mail-starter 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-mail 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-thymeleaf 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/src/main/java/com/javayh/mail/annotation/EnableMail.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail.annotation; 2 | 3 | import com.javayh.mail.selector.MailImportSelector; 4 | import org.springframework.context.annotation.Import; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | *

14 | * 启动日志框架支持 15 | *

16 | * @version 1.0.0 17 | * @author Dylan-haiji 18 | * @since 2020/3/2 19 | */ 20 | @Target(ElementType.TYPE) 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Documented 23 | @Deprecated 24 | @Import(MailImportSelector.class) 25 | public @interface EnableMail { 26 | 27 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/src/main/java/com/javayh/mail/conf/EmailProperties.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail.conf; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | *

7 | * 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-08 14:44 13 | */ 14 | @ConfigurationProperties( 15 | prefix = "spring.mail", 16 | ignoreUnknownFields = true 17 | ) 18 | public class EmailProperties { 19 | 20 | /** 用户名 */ 21 | private String username; 22 | 23 | /** 密码 */ 24 | private String password; 25 | 26 | public String getUsername() { 27 | return username; 28 | } 29 | 30 | public void setUsername(String username) { 31 | this.username = username; 32 | } 33 | 34 | public String getPassword() { 35 | return password; 36 | } 37 | 38 | public void setPassword(String password) { 39 | this.password = password; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/src/main/java/com/javayh/mail/entity/MailDO.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | *

9 | * 邮件接收参数 10 | *

11 | * 12 | * @author Dylan-haiji 13 | * @version 1.0.0 14 | * @since 2020-03-08 15:01 15 | */ 16 | @Data 17 | public class MailDO { 18 | 19 | /** 标题 */ 20 | private String title; 21 | 22 | /** 内容 */ 23 | private String content; 24 | 25 | /** 接收人邮件地址 */ 26 | private String email; 27 | 28 | /** 模板名称 */ 29 | private String templateName; 30 | 31 | /** 附加,value 文件的绝对地址/动态模板数据 */ 32 | private Map attachment; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/src/main/java/com/javayh/mail/selector/MailImportSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mail.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-08 17:05 14 | */ 15 | public class MailImportSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { "com.javayh.mail.server.MailSend" }; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mail-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.javayh.mail.server.MailSend -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/java/com/javayh/mybatis/exception/MybatisInjectionException.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mybatis.exception; 2 | 3 | /** 4 | *

5 | * mybatis sql注入异常 6 | *

7 | * 8 | * @author Dylan-haiji 9 | * @version 1.0.0 10 | * @since 2020-04-05 11:51 11 | */ 12 | public class MybatisInjectionException extends Exception { 13 | 14 | private static final long serialVersionUID = 7859712770754900356L; 15 | 16 | public MybatisInjectionException(String msg) { 17 | super(msg); 18 | } 19 | 20 | public MybatisInjectionException(Exception e) { 21 | this(e.getMessage()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/java/com/javayh/mybatis/filter/MybatisFilterAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.mybatis.filter; 17 | 18 | import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration; 19 | import org.apache.ibatis.session.SqlSessionFactory; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 22 | import org.springframework.context.annotation.Configuration; 23 | 24 | import javax.annotation.PostConstruct; 25 | import java.util.List; 26 | 27 | /** 28 | *

29 | * 30 | *

31 | * 32 | * @author Dylan-haiji 33 | * @version 1.0.0 34 | * @since 2020-04-05 11:44 35 | */ 36 | @AutoConfigureAfter(PageHelperAutoConfiguration.class) 37 | public class MybatisFilterAutoConfiguration { 38 | 39 | @Autowired(required = false) 40 | private List sqlSessionFactoryList; 41 | 42 | @PostConstruct 43 | public void addMyInterceptor() { 44 | MybatisInterceptor e = new MybatisInterceptor(); 45 | for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) { 46 | sqlSessionFactory.getConfiguration().addInterceptor(e); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/java/com/javayh/mybatis/task/ForkJoinTaskUtils.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mybatis.task; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.ForkJoinPool; 7 | import java.util.concurrent.ForkJoinTask; 8 | 9 | /** 10 | *

11 | * 分片工具 12 | *

13 | * 14 | * @author Yang Haiji 15 | * @version 1.0.0 16 | * @since 2020-04-16 14:12 17 | */ 18 | public class ForkJoinTaskUtilsimplements Serializable { 19 | 20 | 21 | public static Long batchOperation(List list){ 22 | // fork/join: 23 | ForkJoinTask task = new MybatisTask( list, 0, list.size()); 24 | Long invoke = ForkJoinPool.commonPool().invoke(task); 25 | return invoke; 26 | } 27 | 28 | // public static void main(String[] args) { 29 | // List list = new ArrayList<>(); 30 | // list.add("1234"); 31 | // list.add("1234"); 32 | // list.add("1234"); 33 | // list.add("1234"); 34 | // list.add("1234"); 35 | // list.add("1234"); 36 | // list.add("1234"); 37 | // list.add("1234"); 38 | // list.add("1234"); 39 | // Long aLong = batchOperation(list); 40 | // System.out.println(aLong); 41 | // } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/java/com/javayh/mybatis/task/MybatisTask.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mybatis.task; 2 | 3 | import lombok.SneakyThrows; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.util.CollectionUtils; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.concurrent.RecursiveTask; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author Yang Haiji 17 | * @version 1.0.0 18 | * @since 2020-04-16 14:55 19 | */ 20 | @Slf4j 21 | public class MybatisTask extends RecursiveTask { 22 | 23 | 24 | static final int THRESHOLD = 2; 25 | private List list; 26 | volatile int start; 27 | volatile int end; 28 | public MybatisTask(List list, int start, int end) { 29 | if(CollectionUtils.isEmpty(list)){ 30 | list = new ArrayList<>(); 31 | } 32 | this.list = list; 33 | this.start = start; 34 | this.end = end; 35 | } 36 | 37 | @SneakyThrows 38 | @Override 39 | protected Long compute() { 40 | long flag = 0; 41 | if (end - start <= THRESHOLD) { 42 | // 如果任务足够小,直接操作: 43 | try{ 44 | log.info("成功操作:" + (end - start)); 45 | flag = end - start; 46 | }catch (Exception e){ 47 | log.info("操作失败的区间---开始位置{},终止位置{}",start,end); 48 | log.error("Fork Join {}",e.getStackTrace()); 49 | throw new Exception("Fork Join"); 50 | } 51 | return flag; 52 | } 53 | // 任务太大,一分为二: 54 | int middle = (end + start) / 2; 55 | log.info(String.format("split %d~%d ==> %d~%d, %d~%d", start, end, start, middle, middle, end)); 56 | MybatisTask insert1 = new MybatisTask(this.list, start, middle); 57 | MybatisTask insert2 = new MybatisTask(this.list, middle, end); 58 | invokeAll(insert1, insert2); 59 | Long join1 = (Long) insert1.join(); 60 | Long join2 = (Long) insert2.join(); 61 | return join1 + join2; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/java/com/javayh/mybatis/uitl/Constant.java: -------------------------------------------------------------------------------- 1 | package com.javayh.mybatis.uitl; 2 | 3 | /** 4 | *

5 | * 6 | *

7 | * 8 | * @author Dylan-haiji 9 | * @version 1.0.0 10 | * @since 2020-04-05 10:04 11 | */ 12 | public interface Constant { 13 | 14 | String DELETE = "DELETE"; 15 | 16 | String ASCII = "ASCII"; 17 | 18 | String UPDATE = "UPDATE"; 19 | 20 | String SELECT = "SELECT"; 21 | 22 | String S = "'"; 23 | 24 | String SUBSTR = "SUBSTR("; 25 | 26 | String COUNT = "COUNT("; 27 | 28 | String OR = " OR "; 29 | 30 | String DROP = "DROP"; 31 | 32 | String EXECUTE = "EXECUTE"; 33 | 34 | String EXEC = "EXEC"; 35 | 36 | String TRUNCATE = "TRUNCATE"; 37 | 38 | String INTO = "INTO"; 39 | 40 | String DECLARE = "DECLARE"; 41 | 42 | String MASTER = "MASTER"; 43 | 44 | String AND = " AND "; 45 | 46 | String MINUS_SIGN = "-"; 47 | String PLUS = "+"; 48 | String PLUS_II = "\\+"; 49 | String DESC = " desc"; 50 | String ASC = " asc"; 51 | } 52 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-mybatis-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.javayh.mybatis.cache.RedisCache 3 | #com.javayh.mybatis.filter.MybatisFilterAutoConfiguration -------------------------------------------------------------------------------- /javayh-dependencies/javayh-nacos-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | javayh-nacos-starter 12 | jar 13 | 14 | 15 | 16 | com.alibaba.cloud 17 | spring-cloud-starter-alibaba-nacos-discovery 18 | 19 | 20 | 21 | com.alibaba.cloud 22 | spring-cloud-starter-alibaba-nacos-config 23 | 24 | 25 | 26 | com.alibaba.cloud 27 | spring-cloud-starter-alibaba-sentinel 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-hystrix 32 | 33 | 34 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-oauth-starter 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-oauth2 19 | 20 | 21 | com.javayh 22 | javayh-common-starter 23 | true 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/base/BaseSecurityConstants.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.base; 2 | 3 | public class BaseSecurityConstants { 4 | 5 | public final static String OPEN_ID = "openid"; 6 | 7 | public final static String DOMAIN = "domain"; 8 | 9 | public final static String EMAIL = "email"; 10 | 11 | public final static String IS_ADMIN = "isAdmin"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/base/BaseTokenEnhancer.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.base; 2 | 3 | import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; 4 | import org.springframework.security.oauth2.common.OAuth2AccessToken; 5 | import org.springframework.security.oauth2.provider.OAuth2Authentication; 6 | import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * 自定义JwtAccessToken转换器 13 | */ 14 | public class BaseTokenEnhancer extends TokenEnhancerChain { 15 | 16 | /** 17 | * 生成token 18 | * @param accessToken 19 | * @param authentication 20 | * @return 21 | */ 22 | @Override 23 | public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, 24 | OAuth2Authentication authentication) { 25 | DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken( 26 | accessToken); 27 | final Map additionalInfo = new HashMap<>(8); 28 | if (!authentication.isClientOnly()) { 29 | if (authentication.getPrincipal() != null 30 | && authentication.getPrincipal() instanceof BaseUserDetails) { 31 | // 设置额外用户信息 32 | BaseUserDetails baseUser = ((BaseUserDetails) authentication 33 | .getPrincipal()); 34 | additionalInfo.put(BaseSecurityConstants.OPEN_ID, baseUser.getUserId()); 35 | additionalInfo.put(BaseSecurityConstants.DOMAIN, baseUser.getDomain()); 36 | additionalInfo.put(BaseSecurityConstants.EMAIL, baseUser.getEmail()); 37 | additionalInfo.put(BaseSecurityConstants.IS_ADMIN, baseUser.getAdmin()); 38 | } 39 | } 40 | defaultOAuth2AccessToken.setAdditionalInformation(additionalInfo); 41 | return super.enhance(defaultOAuth2AccessToken, authentication); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/conf/TokenFeignClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.conf; 2 | 3 | import feign.RequestInterceptor; 4 | import feign.RequestTemplate; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.security.core.context.SecurityContext; 8 | import org.springframework.security.core.context.SecurityContextHolder; 9 | import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; 10 | 11 | 12 | /** 13 | *

14 | * feign添加token 15 | *

16 | * 17 | * @author Dylan-haiji 18 | * @version 1.0.0 19 | * @since 2020-04-08 22:33 20 | */ 21 | @Configuration 22 | public class TokenFeignClientInterceptor implements RequestInterceptor { 23 | 24 | 25 | private final String AUTHORIZATION_HEADER = "Authorization"; 26 | private final String BEARER_TOKEN_TYPE = "Bearer"; 27 | 28 | @Override 29 | public void apply(RequestTemplate requestTemplate) { 30 | SecurityContext securityContext = SecurityContextHolder.getContext(); 31 | Authentication authentication = securityContext.getAuthentication(); 32 | if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { 33 | OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); 34 | requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue())); 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/domain/TbPermission.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.domain; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | @Data 9 | public class TbPermission implements Serializable { 10 | 11 | private Long id; 12 | 13 | /** 14 | * 父权限 15 | */ 16 | private Long parentId; 17 | 18 | /** 19 | * 权限名称 20 | */ 21 | private String name; 22 | 23 | /** 24 | * 权限英文名称 25 | */ 26 | private String enname; 27 | 28 | /** 29 | * 备注 30 | */ 31 | private String description; 32 | 33 | private Date created; 34 | 35 | private Date updated; 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/domain/TbRole.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.domain; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | @Data 9 | public class TbRole implements Serializable { 10 | 11 | private Long id; 12 | 13 | /** 14 | * 父角色 15 | */ 16 | private Long parentId; 17 | 18 | /** 19 | * 角色名称 20 | */ 21 | private String name; 22 | 23 | /** 24 | * 角色英文名称 25 | */ 26 | private String enname; 27 | 28 | /** 29 | * 备注 30 | */ 31 | private String description; 32 | 33 | private Date created; 34 | 35 | private Date updated; 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/java/com/javayh/oauth/domain/TbUser.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth.domain; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | @Data 9 | public class TbUser implements Serializable { 10 | 11 | private Long id; 12 | 13 | /** 14 | * 用户名 15 | */ 16 | private String username; 17 | 18 | /** 19 | * 密码,加密存储 20 | */ 21 | private String password; 22 | 23 | /** 24 | * 注册手机号 25 | */ 26 | private String phone; 27 | 28 | /** 29 | * 注册邮箱 30 | */ 31 | private String email; 32 | 33 | private Date created; 34 | 35 | private Date updated; 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | } -------------------------------------------------------------------------------- /javayh-dependencies/javayh-oauth-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.javayh.oauth.conf.TokenFeignClientInterceptor -------------------------------------------------------------------------------- /javayh-dependencies/javayh-redis-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | redis 非关系数据 12 | javayh-redis-starter 13 | jar 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-data-redis 18 | 19 | 20 | 21 | org.apache.commons 22 | commons-pool2 23 | 24 | 29 | 30 | 31 | org.redisson 32 | redisson 33 | 3.12.0 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-configuration-processor 38 | true 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-redis-starter/src/main/java/com/javayh/redis/conf/RedissonProperties.java: -------------------------------------------------------------------------------- 1 | package com.javayh.redis.conf; 2 | 3 | /** 4 | * Copyright (c) 2013-2019 Nikita Koksharov 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | 21 | /** 22 | * @author Nikita Koksharov 23 | * 24 | */ 25 | @ConfigurationProperties(prefix = "spring.redis.redisson") 26 | public class RedissonProperties { 27 | 28 | private String config; 29 | 30 | public String getConfig() { 31 | return config; 32 | } 33 | 34 | public void setConfig(String config) { 35 | this.config = config; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-redis-starter/src/main/java/com/javayh/redis/prefix/KeyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.redis.prefix; 17 | 18 | /** 19 | *

20 | * redis前缀处理器,提供基础模板,可根据业务进行扩展 用于规范key的使用 21 | *

22 | * 23 | * @author Dylan-haiji 24 | * @version 1.0.0 25 | * @since 2020-03-04 16:20 26 | */ 27 | public abstract class KeyUtils { 28 | 29 | static final String UID = "javayh:"; 30 | 31 | static String followers(String uid) { 32 | return UID + uid + ":followers"; 33 | } 34 | 35 | public static String key(String name) { 36 | return UID + name; 37 | } 38 | 39 | static String auth(String uid) { 40 | return UID + uid + ":auth"; 41 | } 42 | 43 | public static String route(String name) { 44 | return UID + name + ":route"; 45 | } 46 | 47 | public static String user(String name) { 48 | return UID + name + ":user"; 49 | } 50 | 51 | public static String login(String name) { 52 | return UID + name + ":login"; 53 | } 54 | 55 | public static String other(String name) { 56 | return UID + name + ":other"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-redis-starter/src/main/java/com/javayh/redis/serializer/RedisObjectSerializer.java: -------------------------------------------------------------------------------- 1 | package com.javayh.redis.serializer; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | import org.springframework.core.serializer.support.DeserializingConverter; 5 | import org.springframework.core.serializer.support.SerializingConverter; 6 | import org.springframework.data.redis.serializer.RedisSerializer; 7 | import org.springframework.data.redis.serializer.SerializationException; 8 | 9 | /** 10 | *

11 | * 序列化redis value值 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-04 16:58 17 | */ 18 | public class RedisObjectSerializer implements RedisSerializer { 19 | 20 | /** 为了方便进行对象与字节数组的转换,所以应该首先准备出两个转换器 */ 21 | private Converter serializingConverter = new SerializingConverter(); 22 | 23 | private Converter deserializingConverter = new DeserializingConverter(); 24 | 25 | /** 初始化数组 */ 26 | private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; 27 | 28 | /** 29 | *

30 | * 序列化 31 | *

32 | * @version 1.0.0 33 | * @author Dylan-haiji 34 | * @since 2020/3/4 35 | * @param obj 36 | * @return byte[] 37 | */ 38 | @Override 39 | public byte[] serialize(Object obj) throws SerializationException { 40 | /** 这个时候没有要序列化的对象出现,所以返回的字节数组应该就是一个空数组 */ 41 | if (obj == null) { 42 | return EMPTY_BYTE_ARRAY; 43 | } 44 | /** 将对象变为字节数组 */ 45 | return this.serializingConverter.convert(obj); 46 | } 47 | 48 | /** 49 | *

50 | * 反序列化 51 | *

52 | * @version 1.0.0 53 | * @author Dylan-haiji 54 | * @since 2020/3/4 55 | * @param data 56 | * @return java.lang.Object 57 | */ 58 | @Override 59 | public Object deserialize(byte[] data) throws SerializationException { 60 | /** 此时没有对象的内容信息 */ 61 | if (data == null || data.length == 0) { 62 | return null; 63 | } 64 | return this.deserializingConverter.convert(data); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-redis-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.javayh.redis.conf.RedisAutoConfig -------------------------------------------------------------------------------- /javayh-dependencies/javayh-swagger-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-dependencies 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | Api 文档 12 | javayh-swagger-starter 13 | jar 14 | 15 | 1.9.6 16 | 2.9.2 17 | 1.5.21 18 | 19 | 20 | 21 | com.github.xiaoymin 22 | swagger-bootstrap-ui 23 | ${knife4j.version} 24 | 25 | 26 | io.springfox 27 | springfox-swagger2 28 | ${springfox.version} 29 | 30 | 31 | io.springfox 32 | springfox-bean-validators 33 | ${springfox.version} 34 | 35 | 36 | com.javayh 37 | javayh-common-starter 38 | true 39 | 40 | 41 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-swagger-starter/src/main/java/com/javayh/swagger/annotation/EnableAutoSwagger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.swagger.annotation; 17 | 18 | import com.javayh.swagger.selector.SwaggerSelector; 19 | import org.springframework.context.annotation.Import; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | *

30 | * 自定义启动类注解,以免多次引用 31 | *

32 | * 33 | * @author Dylan-haiji 34 | * @version 1.0.0 35 | * @since 2020-03-02 14:35 36 | */ 37 | @Target({ ElementType.TYPE }) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Documented 40 | @Inherited 41 | @Import({ SwaggerSelector.class }) 42 | public @interface EnableAutoSwagger { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-swagger-starter/src/main/java/com/javayh/swagger/selector/SwaggerSelector.java: -------------------------------------------------------------------------------- 1 | package com.javayh.swagger.selector; 2 | 3 | import org.springframework.context.annotation.ImportSelector; 4 | import org.springframework.core.type.AnnotationMetadata; 5 | 6 | /** 7 | *

8 | * swagger 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-30 17:37 14 | */ 15 | public class SwaggerSelector implements ImportSelector { 16 | 17 | @Override 18 | public String[] selectImports(AnnotationMetadata annotationMetadata) { 19 | return new String[] { "com.javayh.swagger.conf.SwaggerConfig" }; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-dependencies/javayh-swagger-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | #org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.javayh.swagger.conf.SwaggerConfig -------------------------------------------------------------------------------- /javayh-dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-platform 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-dependencies 13 | pom 14 | 15 | javayh-common-starter 16 | javayh-data-sources-starter 17 | javayh-log-starter 18 | javayh-redis-starter 19 | javayh-swagger-starter 20 | javayh-nacos-starter 21 | javayh-kafka-starter 22 | javayh-mail-starter 23 | javayh-mybatis-starter 24 | javayh-oauth-starter 25 | javayh-heartbeat-starter 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-monitor-center 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-heartbeat-server 13 | 14 | 15 | 16 | io.netty 17 | netty-all 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/java/com/javayh/heartbeat/HeartApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.heartbeat; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import org.springframework.boot.SpringApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-10 13:45 14 | */ 15 | @JavayhBootApplication 16 | public class HeartApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(HeartApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/java/com/javayh/heartbeat/config/HeartBeatProperties.java: -------------------------------------------------------------------------------- 1 | package com.javayh.heartbeat.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | *

7 | * 8 | *

9 | * 10 | * @author Dylan-haiji 11 | * @version 1.0.0 12 | * @since 2020-03-27 15:55 13 | */ 14 | @ConfigurationProperties(prefix = "heartbeat.server") 15 | public class HeartBeatProperties { 16 | 17 | private Integer port; 18 | 19 | public Integer getPort() { 20 | return port; 21 | } 22 | 23 | public void setPort(Integer port) { 24 | this.port = port; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/java/com/javayh/heartbeat/server/HeartbeatInitializer.java: -------------------------------------------------------------------------------- 1 | package com.javayh.heartbeat.server; 2 | 3 | import com.javayh.heartbeat.encode.HeartbeatDecoder; 4 | import com.javayh.heartbeat.handle.HeartBeatSimpleHandle; 5 | import io.netty.channel.Channel; 6 | import io.netty.channel.ChannelInitializer; 7 | import io.netty.handler.timeout.IdleStateHandler; 8 | 9 | /** 10 | *

11 | * 12 | *

13 | * 14 | * @version 1.0.0 15 | * @author Dylan-haiji 16 | * @since 2020/3/10 17 | */ 18 | public class HeartbeatInitializer extends ChannelInitializer { 19 | 20 | @Override 21 | protected void initChannel(Channel channel) throws Exception { 22 | channel.pipeline() 23 | // 五秒没有收到消息 将IdleStateHandler 添加到 ChannelPipeline 中 24 | .addLast(new IdleStateHandler(5, 0, 0)).addLast(new HeartbeatDecoder()) 25 | .addLast(new HeartBeatSimpleHandle()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/java/com/javayh/heartbeat/util/NettySocketHolder.java: -------------------------------------------------------------------------------- 1 | package com.javayh.heartbeat.util; 2 | 3 | import io.netty.channel.socket.nio.NioSocketChannel; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | 8 | /** 9 | *

10 | * 用于储存链接 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-03-10 13:46 16 | */ 17 | public class NettySocketHolder { 18 | 19 | /** 初始化容器 */ 20 | private static final Map mapChannel = new ConcurrentHashMap<>(16); 21 | 22 | /** 23 | *

24 | * 存入 25 | *

26 | * @version 1.0.0 27 | * @author Dylan-haiji 28 | * @since 2020/3/10 29 | * @param id 30 | * @param socketChannel 31 | * @return void 32 | */ 33 | public static void put(String id, NioSocketChannel socketChannel) { 34 | mapChannel.put(id, socketChannel); 35 | } 36 | 37 | /** 38 | *

39 | * 获取链接 40 | *

41 | * @version 1.0.0 42 | * @author Dylan-haiji 43 | * @since 2020/3/10 44 | * @param id 45 | * @return io.netty.channel.socket.nio.NioSocketChannel 46 | */ 47 | public static NioSocketChannel get(String id) { 48 | return mapChannel.get(id); 49 | } 50 | 51 | /** 52 | *

53 | * 获取容器 54 | *

55 | * @version 1.0.0 56 | * @author Dylan-haiji 57 | * @since 2020/3/10 58 | * @param 59 | * @return java.util.Map 60 | */ 61 | public static Map getMapChannel() { 62 | return mapChannel; 63 | } 64 | 65 | /** 66 | *

67 | * 删除链接 68 | *

69 | * @version 1.0.0 70 | * @author Dylan-haiji 71 | * @since 2020/3/10 72 | * @param nioSocketChannel 73 | * @return void 74 | */ 75 | public static void remove(NioSocketChannel nioSocketChannel) { 76 | mapChannel.entrySet().stream() 77 | .filter(entry -> entry.getValue() == nioSocketChannel) 78 | .forEach(entry -> mapChannel.remove(entry.getKey())); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/resources/META-INF/spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "groups": [ 3 | { 4 | "name": "heartbeat", 5 | "type": "com.javayh.heartbeat.config.HeartBeatProperties", 6 | "sourceType": "com.javayh.heartbeat.config.HeartBeatProperties" 7 | } 8 | ], 9 | "properties": [ 10 | { 11 | "name":"heartbeat.server.port", 12 | "type": "java.lang.Integer", 13 | "sourceType": "com.javayh.heartbeat.config.HeartBeatProperties", 14 | "defaultValue": 8001, 15 | "description": "heartbeat server post" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-heartbeat-server/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | maxHttpHeaderSize: 2048 4 | 5 | spring: 6 | application: 7 | name: ${artifactId} 8 | main: 9 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 10 | profiles: 11 | active: ${profile.name} 12 | cloud: 13 | nacos: 14 | discovery: 15 | server-addr: ${discovery.server-addr} 16 | namespace: ${config.namespace} 17 | ip: ${discovery.server-ip} 18 | config: 19 | server-addr: ${config.server-addr} 20 | namespace: ${config.namespace} 21 | file-extension: yaml 22 | shared-dataids: redis.yaml,mail.yaml 23 | heartbeat: 24 | server: 25 | port: 8001 26 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-zipkin-center/src/main/java/com/javayh/zipkin/ZipkinApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.context.annotation.Bean; 7 | import zipkin2.server.internal.EnableZipkinServer; 8 | import zipkin2.storage.mysql.v1.MySQLStorage; 9 | 10 | import javax.sql.DataSource; 11 | 12 | /** 13 | *

14 | * ZipkinServer 15 | *

16 | * 17 | * @author Dylan-haiji 18 | * @version 1.0.0 19 | * @since 2020-04-23 20 | */ 21 | @EnableDiscoveryClient 22 | @EnableZipkinServer 23 | @SpringBootApplication 24 | public class ZipkinApplication { 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(ZipkinApplication.class, args); 28 | } 29 | 30 | @Bean 31 | public MySQLStorage mySQLStorage(DataSource datasource) { 32 | return MySQLStorage.newBuilder().datasource(datasource).executor(Runnable::run).build(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /javayh-monitor-center/javayh-zipkin-center/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7070 3 | maxHttpHeaderSize: 2048 4 | spring: 5 | application: 6 | name: javayh-zipkin-center 7 | main: 8 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 9 | cloud: 10 | nacos: 11 | discovery: 12 | server-addr: 127.0.0.1:8848 13 | namespace: d7503bcd-e44c-475a-88d4-d28cbfb444fc 14 | config: 15 | server-addr: 127.0.0.1:8848 16 | namespace: d7503bcd-e44c-475a-88d4-d28cbfb444fc 17 | file-extension: yaml 18 | shared-dataids: zipkindb.yaml 19 | 20 | management: 21 | metrics: 22 | web: 23 | server: 24 | auto-time-requests: false 25 | 26 | zipkin: 27 | storage: 28 | type: mysql 29 | -------------------------------------------------------------------------------- /javayh-monitor-center/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-platform 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | pom 12 | javayh-monitor-center 13 | 14 | 15 | javayh-zipkin-center 16 | javayh-heartbeat-server 17 | 18 | 19 | 20 | 21 | com.javayh 22 | javayh-common-starter 23 | true 24 | 25 | 26 | com.javayh 27 | javayh-nacos-starter 28 | true 29 | 30 | 31 | -------------------------------------------------------------------------------- /javayh-plugins/javayh-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-plugins 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-generator 13 | 14 | 15 | com.javayh 16 | javayh-common-starter 17 | 18 | 19 | com.javayh 20 | javayh-mybatis-starter 21 | 22 | 23 | com.googlecode.htmlcompressor 24 | htmlcompressor 25 | 1.5.2 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /javayh-plugins/javayh-generator/src/main/java/com/javayh/generator/GeneratorMain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.generator; 17 | 18 | import com.javayh.generator.file.GenMain; 19 | 20 | /** 21 | * 执行逆向测试类 22 | */ 23 | public class GeneratorMain { 24 | 25 | /** 26 | * 时间工具类:util.TimeUtils 命名方式工具类:util.NameUtils 注释信息工具类:util.NotesUtils 27 | * 数据库、包名、类的前后缀的配置文件:config.GenerateConfig new GenMain("数据库对应的表名","代码生成所在的包名",false) 28 | * @param args 29 | */ 30 | public static void main(String[] args) { 31 | GenMain gMain = new GenMain("sys_logistics", "sys", false); 32 | try { 33 | gMain.generate(); 34 | } 35 | catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /javayh-plugins/javayh-generator/src/main/java/com/javayh/generator/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.generator.util; 17 | 18 | import java.io.File; 19 | import java.io.FileNotFoundException; 20 | import java.io.FileOutputStream; 21 | import java.io.OutputStreamWriter; 22 | import java.io.PrintStream; 23 | 24 | /** 25 | * 创建文件工具类 26 | */ 27 | public class FileUtils { 28 | 29 | public static void WriteStringToFile(File file, String content) { 30 | try { 31 | PrintStream ps = new PrintStream(new FileOutputStream(file)); 32 | ps.println(content);// 往文件里写入字符串 33 | ps.close(); 34 | } 35 | catch (FileNotFoundException e) { 36 | // TODO Auto-generated catch block 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | public static void changeFileEncoding(File file, String encoding) { 42 | try { 43 | OutputStreamWriter osw = new OutputStreamWriter( 44 | new FileOutputStream(file, true), encoding); 45 | osw.close(); 46 | } 47 | catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /javayh-plugins/javayh-generator/src/main/java/com/javayh/generator/util/NameUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2020] [Yang Hai Ji of copyright owner] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.javayh.generator.util; 17 | 18 | /** 19 | * 命名方式工具类 20 | */ 21 | public class NameUtils { 22 | 23 | /** 24 | * 驼峰命名 25 | * @param name 26 | * @return 27 | */ 28 | public static String formatName(String name) { 29 | String[] nameArr = name.split("_"); 30 | String result = ""; 31 | for (int i = 0; i < nameArr.length; i++) { 32 | if (i == 0) { 33 | result += nameArr[i].toLowerCase(); 34 | } 35 | else { 36 | result += nameArr[i].substring(0, 1).toUpperCase(); 37 | result += nameArr[i].substring(1).toLowerCase(); 38 | } 39 | } 40 | return result; 41 | } 42 | 43 | /** 44 | * 首字母大写命名 45 | * @param name 46 | * @return 47 | */ 48 | public static String formatClassName(String name) { 49 | String[] nameArr = name.split("_"); 50 | String result = ""; 51 | for (int i = 0; i < nameArr.length; i++) { 52 | result += nameArr[i].substring(0, 1).toUpperCase(); 53 | result += nameArr[i].substring(1).toLowerCase(); 54 | } 55 | return result; 56 | } 57 | 58 | public static void main(String[] args) { 59 | System.out.println(formatName("BASE_PACKAGE_NAME")); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /javayh-plugins/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-platform 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-plugins 13 | pom 14 | 15 | javayh-generator 16 | 17 | 18 | -------------------------------------------------------------------------------- /javayh-route/javayh-api-gateway/src/main/java/com/javayh/gateway/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.gateway; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import org.springframework.boot.SpringApplication; 5 | 6 | /** 7 | *

8 | * gateway启动类 全局api文档 http://localhost:7000/doc.html# 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-03-02 10:03 14 | */ 15 | @JavayhBootApplication 16 | public class GatewayApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(GatewayApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-route/javayh-api-gateway/src/main/java/com/javayh/gateway/conf/fallback/GatewayFallbackConfig.java: -------------------------------------------------------------------------------- 1 | package com.javayh.gateway.conf.fallback; 2 | 3 | import com.javayh.gateway.handler.hystrix.HystrixFallbackHandler; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.web.reactive.function.server.RequestPredicates; 9 | import org.springframework.web.reactive.function.server.RouterFunction; 10 | import org.springframework.web.reactive.function.server.RouterFunctions; 11 | 12 | /** 13 | *

14 | * 服务回滚 15 | *

16 | * 17 | * @author Dylan-haiji 18 | * @version 1.0.0 19 | * @since 2020-03-02 12:29 20 | */ 21 | @Configuration 22 | public class GatewayFallbackConfig { 23 | 24 | @Autowired 25 | private HystrixFallbackHandler hystrixFallbackHandler; 26 | 27 | /** 28 | *

29 | * 实例化,用于服务降级配置 30 | *

31 | * @version 1.0.0 32 | * @author Dylan-haiji 33 | * @since 2020/3/2 34 | * @param 35 | * @return org.springframework.web.reactive.function.server.RouterFunction 36 | */ 37 | @Bean 38 | public RouterFunction routerFunction() { 39 | return RouterFunctions.route( 40 | RequestPredicates.GET("/defaultfallback") 41 | .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), 42 | hystrixFallbackHandler); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /javayh-route/javayh-api-gateway/src/main/java/com/javayh/gateway/conf/limiter/RateLimiterConfig.java: -------------------------------------------------------------------------------- 1 | package com.javayh.gateway.conf.limiter; 2 | 3 | import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Primary; 7 | import reactor.core.publisher.Mono; 8 | 9 | /** 10 | *

11 | * 限流配置器 key-resolver:"#{@ipKeyResolver}" #SPEL表达式去的对应的bean 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-03-05 22:38 17 | */ 18 | @Configuration 19 | public class RateLimiterConfig { 20 | 21 | /** 22 | *

23 | * 根据Ip限流 24 | *

25 | * @version 1.0.0 26 | * @author Dylan-haiji 27 | * @since 2020/3/5 28 | * @param 29 | * @return org.springframework.cloud.gateway.filter.ratelimit.KeyResolver 30 | */ 31 | @Primary 32 | @Bean 33 | public KeyResolver ipKeyResolver() { 34 | return exchange -> Mono 35 | .just(exchange.getRequest().getRemoteAddress().getHostName()); 36 | } 37 | 38 | /** 39 | *

40 | * 根据用户限流 官方不建议再生产使用该参数,这样路需要携带用户信息 41 | *

42 | * @version 1.0.0 43 | * @author Dylan-haiji 44 | * @since 2020/3/5 45 | * @param 46 | * @return org.springframework.cloud.gateway.filter.ratelimit.KeyResolver 47 | */ 48 | @Bean 49 | KeyResolver userKeyResolver() { 50 | return exchange -> Mono 51 | .just(exchange.getRequest().getQueryParams().getFirst("user")); 52 | } 53 | 54 | /** 55 | *

56 | * 根据请求地址限流 57 | *

58 | * @version 1.0.0 59 | * @author Dylan-haiji 60 | * @since 2020/3/5 61 | * @param 62 | * @return org.springframework.cloud.gateway.filter.ratelimit.KeyResolver 63 | */ 64 | @Bean 65 | KeyResolver apiKeyResolver() { 66 | return exchange -> Mono.just(exchange.getRequest().getPath().value()); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /javayh-route/javayh-api-gateway/src/main/java/com/javayh/gateway/filter/SwaggerHeaderFilter.java: -------------------------------------------------------------------------------- 1 | package com.javayh.gateway.filter; 2 | 3 | import org.springframework.cloud.gateway.filter.GatewayFilter; 4 | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; 5 | import org.springframework.http.server.reactive.ServerHttpRequest; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.util.StringUtils; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author Dylan-haiji 16 | * @version 1.0.0 17 | * @since 2020-03-06 9:42 18 | */ 19 | @Component 20 | public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { 21 | 22 | private static final String HEADER_NAME = "X-Forwarded-Prefix"; 23 | 24 | private static final String URI = "/v2/api-docs"; 25 | 26 | @Override 27 | public GatewayFilter apply(Object config) { 28 | return (exchange, chain) -> { 29 | ServerHttpRequest request = exchange.getRequest(); 30 | String path = request.getURI().getPath(); 31 | if (!StringUtils.endsWithIgnoreCase(path, URI)) { 32 | return chain.filter(exchange); 33 | } 34 | String basePath = path.substring(0, path.lastIndexOf(URI)); 35 | ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath) 36 | .build(); 37 | ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); 38 | return chain.filter(newExchange); 39 | }; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /javayh-route/javayh-api-gateway/src/main/java/com/javayh/gateway/handler/hystrix/HystrixFallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.javayh.gateway.handler.hystrix; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.reactive.function.BodyInserters; 10 | import org.springframework.web.reactive.function.server.HandlerFunction; 11 | import org.springframework.web.reactive.function.server.ServerRequest; 12 | import org.springframework.web.reactive.function.server.ServerResponse; 13 | import reactor.core.publisher.Mono; 14 | 15 | /** 16 | *

17 | * 服务降级处理 18 | *

19 | * 20 | * @version 1.0.0 21 | * @author Dylan-haiji 22 | * @since 2020/3/2 23 | */ 24 | @Slf4j 25 | @Component 26 | public class HystrixFallbackHandler implements HandlerFunction { 27 | 28 | @Override 29 | public Mono handle(ServerRequest serverRequest) { 30 | serverRequest.attribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR) 31 | .ifPresent(originalUrls -> log.error("网关执行请求:{}失败,hystrix服务降级处理", 32 | originalUrls)); 33 | return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR) 34 | .contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters 35 | .fromObject(ResultData.fail("Hystrix Fallback Handler"))); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/README.md: -------------------------------------------------------------------------------- 1 | ## javayh-resource 2 | 3 | ## 服务使用流程 4 | 5 | - 初始化数据脚本 6 | 7 | `doc/sql/sso/user.sql` 8 | 9 | `doc/sql/sso/oauth.sql` 10 | 11 | 12 | - [获取token的流程](../../javayh-sso/javayh-server/README.md) 13 | 14 | - 访问资源 15 | 16 | [localhost:9099/api/user/info](localhost:9099/api/user/info) 17 | 18 | 这时有两种方式访问: 19 | 20 | 1. access_toke 21 | 22 | 表单携带 23 | ![full stack developer tutorial](../../doc/img/access_token.JPG) 24 | 25 | 26 | 2.Authorization 27 | 28 | headers携带 29 | ![full stack developer tutorial](../../doc/img/auth.JPG) 30 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-sso 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-resource 13 | 14 | 15 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/ResourceApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 5 | import org.mybatis.spring.annotation.MapperScan; 6 | import org.springframework.boot.SpringApplication; 7 | 8 | /** 9 | *

10 | * 11 | *

12 | * 13 | * @author Dylan-haiji 14 | * @version 1.0.0 15 | * @since 2020-04-06 14:21 16 | */ 17 | @EnableAutoInternationalization 18 | @MapperScan(basePackages = "com.javayh.resource.mapper") 19 | @JavayhBootApplication 20 | public class ResourceApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(ResourceApplication.class, args); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/conf/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.conf; 2 | 3 | import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; 8 | import org.springframework.security.config.http.SessionCreationPolicy; 9 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 10 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 11 | 12 | /** 13 | *

14 | * 资源服务器配置 15 | *

16 | * @version 1.0.0 17 | * @author Dylan-haiji 18 | * @since 2020/4/8 19 | */ 20 | @Configuration 21 | @EnableResourceServer 22 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) 23 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 24 | 25 | @Override 26 | public void configure(HttpSecurity http) throws Exception { 27 | ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry = http 28 | .antMatcher("/**").authorizeRequests(); 29 | http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) 30 | .and().authorizeRequests() 31 | // 指定监控访问权限 32 | .requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll().anyRequest() 33 | .authenticated().and().exceptionHandling() 34 | // 认证鉴权错误处理,为了统一异常处理。每个资源服务器都应该加上。 35 | // .accessDeniedHandler(new AccessDeniedHandler()) 36 | // .authenticationEntryPoint(new WebException()) 37 | // 配置跨域 38 | .and().cors().and().csrf().disable() 39 | // 禁用httpBasic 40 | .httpBasic().disable(); 41 | registry.anyRequest().authenticated(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/controller/UserApi.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.controller; 2 | 3 | import com.javayh.common.result.ResultData; 4 | import com.javayh.resource.mapper.TbUserMapper; 5 | import com.javayh.resource.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | *

13 | * 用户信息 14 | *

15 | * 16 | * @author Dylan-haiji 17 | * @version 1.0.0 18 | * @since 2020-04-06 14:16 19 | */ 20 | @RestController 21 | @RequestMapping("/api/user/") 22 | public class UserApi { 23 | 24 | @Autowired 25 | private UserService userService; 26 | 27 | @GetMapping(value = "info") 28 | public ResultData getUser(String username) { 29 | return ResultData.success(userService.getByUserName(username)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/mapper/TbUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.mapper; 2 | 3 | import com.javayh.resource.vo.UserVO; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface TbUserMapper { 7 | 8 | UserVO getByUserName(@Param("username") String username); 9 | 10 | } -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.service; 2 | 3 | import com.javayh.resource.vo.UserVO; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | /** 7 | *

8 | * 9 | *

10 | * 11 | * @author Dylan-haiji 12 | * @version 1.0.0 13 | * @since 2020-04-06 16:32 14 | */ 15 | public interface UserService { 16 | 17 | UserVO getByUserName(String username); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.service.impl; 2 | 3 | import com.javayh.resource.mapper.TbUserMapper; 4 | import com.javayh.resource.service.UserService; 5 | import com.javayh.resource.vo.UserVO; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 12 | *

13 | * 14 | * @author Dylan-haiji 15 | * @version 1.0.0 16 | * @since 2020-04-06 16:32 17 | */ 18 | @Service 19 | public class UserServiceImpl implements UserService { 20 | 21 | @Autowired 22 | private TbUserMapper tbUserMapper; 23 | 24 | @Override 25 | public UserVO getByUserName(String username) { 26 | return tbUserMapper.getByUserName(username); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/java/com/javayh/resource/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package com.javayh.resource.vo; 2 | 3 | import com.javayh.oauth.domain.TbPermission; 4 | import com.javayh.oauth.domain.TbRole; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author Dylan-haiji 16 | * @version 1.0.0 17 | * @since 2020-04-06 16:25 18 | */ 19 | @Data 20 | public class UserVO implements Serializable { 21 | 22 | private Long id; 23 | 24 | /** 25 | * 用户名 26 | */ 27 | private String username; 28 | 29 | /** 30 | * 密码,加密存储 31 | */ 32 | private String password; 33 | 34 | /** 35 | * 注册手机号 36 | */ 37 | private String phone; 38 | 39 | /** 40 | * 注册邮箱 41 | */ 42 | private String email; 43 | 44 | private List permission; 45 | 46 | private List role; 47 | 48 | } 49 | 50 | @Data 51 | class PermissionRole { 52 | 53 | private String pname; 54 | 55 | private String penname; 56 | 57 | } 58 | 59 | @Data 60 | class Role { 61 | 62 | private String rname; 63 | 64 | private String renname; 65 | 66 | } -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9099 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | security: 7 | user: 8 | name: root # 账号 9 | password: 123456 # 密码 10 | main: 11 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 12 | profiles: 13 | active: ${profile.name} 14 | cloud: 15 | nacos: 16 | discovery: 17 | server-addr: ${discovery.server-addr} 18 | namespace: ${config.namespace} 19 | ip: ${discovery.server-ip} 20 | config: 21 | server-addr: ${config.server-addr} 22 | namespace: ${config.namespace} 23 | file-extension: yaml 24 | shared-dataids: redis.yaml,mail.yaml,oauth2db.yaml 25 | messages: 26 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 27 | 28 | security: 29 | oauth2: 30 | client: 31 | client-id: client 32 | client-secret: secret 33 | access-token-uri: http://localhost:9090/oauth/token 34 | user-authorization-uri: http://localhost:9090/oauth/authorize 35 | resource: 36 | token-info-uri: http://localhost:9090/oauth/check_token 37 | 38 | mybatis: 39 | ### xml存放路径 40 | mapper-locations: classpath*:mapper/*/*Mapper.xml 41 | type-aliases-package: com.javayh.resource.domain -------------------------------------------------------------------------------- /javayh-sso/javayh-resource/src/main/resources/mapper/user/TbUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | u.id, 22 | u.username, 23 | u.password, 24 | u.phone, 25 | u.email, 26 | r.name rname, 27 | r.enname renname, 28 | p.name pname, 29 | p.enname penname 30 | 31 | 32 | 46 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/README.md: -------------------------------------------------------------------------------- 1 | ## javayh-server 2 | 3 | ## 服务使用流程 4 | 5 | - 初始化数据脚本 6 | 7 | `doc/sql/sso/user.sql` 8 | 9 | `doc/sql/sso/oauth.sql` 10 | 11 | - 启动服务服务获取code 12 | 13 | 访问:[http://localhost:9090/oauth/authorize?client_id=client&response_type=code](http://localhost:9090/oauth/authorize?client_id=client&response_type=code) 14 | 15 | 初次需要登录,如下图 16 | 17 | **登录名:admin , 密码:123456** 18 | 19 | ![full stack developer tutorial](../../doc/img/oauthLogin.JPG) 20 | 21 | **这时我们选择统一授权,获取code** 22 | 23 | ![full stack developer tutorial](../../doc/img/code.JPG) 24 | 25 | 26 | - 获取token 27 | 28 | 这里我们使用postman获取token 29 | 30 | 访问:[http://client:secret@localhost:9090/oauth/token](http://client:secret@localhost:9090/oauth/token) 31 | 32 | 如下图: 33 | 34 | ![full stack developer tutorial](../../doc/img/token.JPG) 35 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javayh-sso 7 | com.javayh 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | javayh-server 13 | 14 | 15 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/OAuth2ServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server; 2 | 3 | import com.javayh.common.annotation.JavayhBootApplication; 4 | import com.javayh.common.exception.annotation.EnableAutoException; 5 | import com.javayh.common.i18n.annotation.EnableAutoInternationalization; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 9 | 10 | /** 11 | *

12 | * 启动类 13 | *

14 | * 15 | * @author Dylan-haiji 16 | * @version 1.0.0 17 | * @since 2020-04-05 14:17 18 | */ 19 | @EnableAutoException 20 | @EnableAutoInternationalization 21 | @MapperScan(basePackages = "com.javayh.oauth2.server.mapper") 22 | @JavayhBootApplication 23 | public class OAuth2ServerApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(OAuth2ServerApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/mapper/TbPermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.mapper; 2 | 3 | import com.javayh.oauth.domain.TbPermission; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | public interface TbPermissionMapper { 9 | 10 | List selectByUserId(@Param("userId") Long userId); 11 | 12 | } -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/mapper/TbRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.mapper; 2 | 3 | public interface TbRoleMapper { 4 | 5 | } -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/mapper/TbUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.mapper; 2 | 3 | import com.javayh.oauth.domain.TbUser; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface TbUserMapper { 7 | 8 | TbUser findByUserName(@Param("username") String username); 9 | 10 | } -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/TbPermissionService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service; 2 | 3 | import com.javayh.oauth.domain.TbPermission; 4 | 5 | import java.util.List; 6 | 7 | public interface TbPermissionService { 8 | 9 | List selectByUserId(Long userId); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/TbRoleService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service; 2 | 3 | public interface TbRoleService { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/TbUserService.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service; 2 | 3 | import com.javayh.oauth.domain.TbUser; 4 | 5 | public interface TbUserService { 6 | 7 | TbUser getByUsername(String username); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/impl/TbPermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service.impl; 2 | 3 | import com.javayh.oauth.domain.TbPermission; 4 | import com.javayh.oauth2.server.mapper.TbPermissionMapper; 5 | import com.javayh.oauth2.server.service.TbPermissionService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class TbPermissionServiceImpl implements TbPermissionService { 13 | 14 | @Autowired 15 | private TbPermissionMapper tbPermissionMapper; 16 | 17 | @Override 18 | public List selectByUserId(Long userId) { 19 | return tbPermissionMapper.selectByUserId(userId); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/impl/TbRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service.impl; 2 | 3 | import com.javayh.oauth2.server.mapper.TbRoleMapper; 4 | import com.javayh.oauth2.server.service.TbRoleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class TbRoleServiceImpl implements TbRoleService { 10 | 11 | @Autowired 12 | private TbRoleMapper tbRoleMapper; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/java/com/javayh/oauth2/server/service/impl/TbUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.javayh.oauth2.server.service.impl; 2 | 3 | import com.javayh.oauth.domain.TbUser; 4 | import com.javayh.oauth2.server.mapper.TbUserMapper; 5 | import com.javayh.oauth2.server.service.TbUserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class TbUserServiceImpl implements TbUserService { 11 | 12 | @Autowired 13 | private TbUserMapper tbUserMapper; 14 | 15 | @Override 16 | public TbUser getByUsername(String username) { 17 | return tbUserMapper.findByUserName(username); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9098 3 | spring: 4 | application: 5 | name: ${artifactId} 6 | security: 7 | user: 8 | name: root # 账号 9 | password: 123456 # 密码 10 | main: 11 | allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 12 | profiles: 13 | active: ${profile.name} 14 | cloud: 15 | nacos: 16 | discovery: 17 | server-addr: ${discovery.server-addr} 18 | namespace: ${config.namespace} 19 | ip: ${discovery.server-ip} 20 | config: 21 | server-addr: ${config.server-addr} 22 | namespace: ${config.namespace} 23 | file-extension: yaml 24 | shared-dataids: redis.yaml,mail.yaml,oauth2db.yaml 25 | messages: 26 | basename: i18n.login.login,i18n.common.common,i18n.validation.validation 27 | 28 | mybatis: 29 | ### xml存放路径 30 | mapper-locations: classpath*:mapper/*/*Mapper.xml 31 | type-aliases-package: com.javayh.oauth2.server.domain -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/resources/mapper/permission/TbPermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id, parent_id, `name`, `enname`, description, created, updated 17 | 18 | 33 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/resources/mapper/role/TbRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id, parent_id, `name`, `enname`, description, created, updated 17 | 18 | -------------------------------------------------------------------------------- /javayh-sso/javayh-server/src/main/resources/mapper/user/TbUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id, username, password, phone, email, created, updated 17 | 18 | 19 | 25 | --------------------------------------------------------------------------------