├── .gitignore
├── LICENSE
├── README.md
├── maozi-cloud-common
├── maozi-cloud-common-generate-code
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── generate
│ │ └── code
│ │ ├── GenerateCodeRun.java
│ │ ├── datasource
│ │ ├── C3P0.java
│ │ ├── DataBaseDao.java
│ │ └── TheReflectionClasses.java
│ │ ├── entity
│ │ ├── DataSourceConfig.java
│ │ ├── EntityData.java
│ │ └── TableData.java
│ │ ├── parent
│ │ ├── GenerateParentPom.java
│ │ ├── dto
│ │ │ └── GenerateDtoPom.java
│ │ ├── enums
│ │ │ └── GenerateEnumPom.java
│ │ ├── rest
│ │ │ └── GenerateRestPom.java
│ │ ├── rpc
│ │ │ └── GenerateRpcPom.java
│ │ ├── service
│ │ │ ├── GenerateEntity.java
│ │ │ ├── GenerateMapper.java
│ │ │ ├── GenerateMapperXML.java
│ │ │ ├── GenerateProperties.java
│ │ │ ├── GenerateRun.java
│ │ │ ├── GenerateService.java
│ │ │ ├── GenerateServiceImpl.java
│ │ │ └── GenerateServicePom.java
│ │ └── vo
│ │ │ └── GenerateVoPom.java
│ │ └── tool
│ │ └── SQLType.java
├── maozi-cloud-common-result
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── common
│ │ ├── BaseCommon.java
│ │ └── result
│ │ ├── AbstractBaseResult.java
│ │ ├── error
│ │ ├── ErrorResult.java
│ │ └── exception
│ │ │ └── BusinessResultException.java
│ │ └── success
│ │ └── SuccessResult.java
├── maozi-cloud-common-utils
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── utils
│ │ ├── MapperUtils.java
│ │ ├── SpringUtil.java
│ │ ├── WeightedRandomSelector.java
│ │ └── context
│ │ ├── ApplicationEnvironmentContext.java
│ │ └── ApplicationLinkContext.java
└── pom.xml
├── maozi-cloud-config
├── maozi-cloud-config-db
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── db
│ │ ├── config
│ │ ├── CustomMetaObjectHandler.java
│ │ ├── EasySqlInjector.java
│ │ ├── MybatisPlusConfig.java
│ │ ├── MybatisPlusLog.java
│ │ └── RedisCache.java
│ │ └── handler
│ │ ├── CustomJsonTypeHandler.java
│ │ └── ListTypeHandler.java
├── maozi-cloud-config-discovery
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── discovery
│ │ └── balancer
│ │ ├── GrayLoadBalancerAutoConfiguration.java
│ │ ├── GrayLoadBalancerClientConfiguration.java
│ │ └── GrayRoundRobinLoadBalancer.java
├── maozi-cloud-config-dubbo
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── maozi
│ │ │ └── dubbo
│ │ │ ├── filter
│ │ │ ├── ApplicationLinkContextSetFilter.java
│ │ │ └── ApplicationLinkContextTransmitFilter.java
│ │ │ ├── provider
│ │ │ └── ProviderFirstParams.java
│ │ │ └── router
│ │ │ ├── GrayRouter.java
│ │ │ └── RouterFactory.java
│ │ └── resources
│ │ └── META-INF
│ │ └── dubbo
│ │ ├── org.apache.dubbo.registry.ProviderFirstParams
│ │ ├── org.apache.dubbo.rpc.Filter
│ │ └── org.apache.dubbo.rpc.cluster.RouterFactory
├── maozi-cloud-config-feign
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── feign
│ │ └── config
│ │ ├── ErrorDecoder.java
│ │ ├── ResultDecoder.java
│ │ └── TokenRequestInterceptor.java
├── maozi-cloud-config-job
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── job
│ │ ├── XxlJobConfig.java
│ │ └── config
│ │ └── JobEntranceLogAop.java
├── maozi-cloud-config-lock
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── lock
│ │ ├── annotation
│ │ ├── Lock.java
│ │ └── LockKey.java
│ │ ├── config
│ │ ├── LockAop.java
│ │ └── RedissonConfig.java
│ │ ├── error
│ │ └── strategy
│ │ │ ├── LockTimeoutHandler.java
│ │ │ ├── UnLockTimeoutHandler.java
│ │ │ └── impl
│ │ │ ├── LockTimeoutStrategy.java
│ │ │ └── UnLockTimeoutStrategy.java
│ │ ├── lock
│ │ ├── Lock.java
│ │ ├── LockType.java
│ │ └── impl
│ │ │ ├── FairLock.java
│ │ │ ├── ReadLock.java
│ │ │ ├── ReentrantLock.java
│ │ │ └── WriteLock.java
│ │ └── properties
│ │ └── LockProperties.java
├── maozi-cloud-config-log
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ ├── com
│ │ └── maozi
│ │ │ └── log
│ │ │ ├── config
│ │ │ ├── RemoteInvokeErrorToleranceAop.java
│ │ │ ├── RestEntranceLogAop.java
│ │ │ └── TtlMDCAdapterInitializer.java
│ │ │ ├── convert
│ │ │ ├── ApplicationNameMessageConverter.java
│ │ │ └── EnvironmentMessageConverter.java
│ │ │ └── utils
│ │ │ └── RestEntranceLogUtils.java
│ │ └── org
│ │ └── slf4j
│ │ └── TtlMDCAdapter.java
├── maozi-cloud-config-monitor
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── health
│ │ ├── api
│ │ └── impl
│ │ │ └── rest
│ │ │ └── RestErrorLog.java
│ │ └── config
│ │ └── ApplicationHealthIndicator.java
├── maozi-cloud-config-oauth
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── oauth
│ │ ├── config
│ │ ├── IAccessDeniedHandler.java
│ │ ├── IAuthenticationEntryPoint.java
│ │ ├── IRequestRejectedHandler.java
│ │ └── ResourceServerConfig.java
│ │ ├── properties
│ │ └── ApiWhitelistProperties.java
│ │ └── service
│ │ └── IRemoteTokenServices.java
├── maozi-cloud-config-redis
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── redis
│ │ └── RedisTemplateConf.java
├── maozi-cloud-config-seata
│ └── pom.xml
├── maozi-cloud-config-sentinel
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ ├── alibaba
│ │ ├── cloud
│ │ │ └── sentinel
│ │ │ │ ├── custom
│ │ │ │ └── SentinelAutoConfiguration.java
│ │ │ │ └── datasource
│ │ │ │ └── converter
│ │ │ │ └── AuthorityRuleJsonConverter.java
│ │ └── csp
│ │ │ └── sentinel
│ │ │ ├── dashboard
│ │ │ └── datasource
│ │ │ │ └── entity
│ │ │ │ └── rule
│ │ │ │ ├── AbstractRuleEntity.java
│ │ │ │ ├── AuthorityRuleEntity.java
│ │ │ │ └── RuleEntity.java
│ │ │ ├── log
│ │ │ └── LogBase.java
│ │ │ └── slots
│ │ │ └── statistic
│ │ │ └── StatisticSlot.java
│ │ └── maozi
│ │ └── monitor
│ │ └── config
│ │ └── sentinel
│ │ ├── CustomUrlBlockHandler.java
│ │ ├── DubboFallback.java
│ │ └── IpLimiter.java
├── maozi-cloud-config-stream
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── stream
│ │ ├── config
│ │ ├── MessageSendStream.java
│ │ └── StreamEntranceLogAop.java
│ │ └── enums
│ │ └── DelayMessageLevel.java
├── maozi-cloud-config-swagger
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── swagger
│ │ └── config
│ │ └── Knife4jConfig.java
├── maozi-cloud-config-web
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── maozi
│ │ └── mvc
│ │ ├── config
│ │ ├── async
│ │ │ └── AsyncConfig.java
│ │ ├── cache
│ │ │ └── CacheConfig.java
│ │ ├── code
│ │ │ └── CodeConfig.java
│ │ ├── enums
│ │ │ └── EnumConfig.java
│ │ ├── error
│ │ │ └── ErrorParamTranslation.java
│ │ ├── json
│ │ │ ├── JacksonConfig.java
│ │ │ └── ReadOnlyMultipartFormDataEndpointConverter.java
│ │ └── rest
│ │ │ ├── ErrorRestHandler.java
│ │ │ ├── RestTemplate.java
│ │ │ ├── RestTemplateConfig.java
│ │ │ └── WebConfig.java
│ │ └── filter
│ │ └── ApplicationLinkContextFilter.java
└── pom.xml
├── maozi-cloud-entity
├── maozi-cloud-base-entity
│ ├── maozi-cloud-base-do
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ ├── AbstractBaseDomain.java
│ │ │ └── AbstractBaseNameDomain.java
│ ├── maozi-cloud-base-dto
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ ├── AbstractBaseDtomain.java
│ │ │ ├── param
│ │ │ ├── PageParam.java
│ │ │ ├── SaveUpdateBatch.java
│ │ │ ├── SearchParam.java
│ │ │ ├── ValidCollectionParam.java
│ │ │ └── plugin
│ │ │ │ ├── OrderParam.java
│ │ │ │ └── TimeParam.java
│ │ │ ├── plugin
│ │ │ ├── StoreClass.java
│ │ │ ├── join
│ │ │ │ ├── JoinBaseType.java
│ │ │ │ ├── JoinPlugin.java
│ │ │ │ └── JoinPlugins.java
│ │ │ ├── mapping
│ │ │ │ └── QueryMapping.java
│ │ │ └── query
│ │ │ │ ├── QueryBaseType.java
│ │ │ │ └── QueryPlugin.java
│ │ │ ├── result
│ │ │ ├── DropDownResult.java
│ │ │ ├── EnumResult.java
│ │ │ └── ListStringResult.java
│ │ │ └── validator
│ │ │ ├── excel
│ │ │ ├── ExcelFile.java
│ │ │ └── ExcelFileValidator.java
│ │ │ ├── image
│ │ │ ├── ImageFile.java
│ │ │ └── ImageFileValidator.java
│ │ │ └── video
│ │ │ ├── VideoFile.java
│ │ │ └── VideoFileValidator.java
│ ├── maozi-cloud-base-enum
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ ├── AbstractBaseCode.java
│ │ │ ├── BaseEnum.java
│ │ │ ├── CodeData.java
│ │ │ ├── enums
│ │ │ ├── Deleted.java
│ │ │ ├── EnvironmentType.java
│ │ │ ├── Status.java
│ │ │ └── StoreClassType.java
│ │ │ └── error
│ │ │ └── code
│ │ │ └── SystemErrorCode.java
│ ├── maozi-cloud-base-vo
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ ├── AbstractBaseVomain.java
│ │ │ └── result
│ │ │ └── PageResult.java
│ └── pom.xml
├── maozi-cloud-business-entity
│ ├── maozi-cloud-do
│ │ ├── maozi-cloud-seata-do
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── resources
│ │ │ │ └── db
│ │ │ │ └── V1.0.0.20240825000000__init.sql
│ │ └── pom.xml
│ ├── maozi-cloud-dto
│ │ ├── maozi-cloud-oauth-token-dto
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── oauth
│ │ │ │ └── token
│ │ │ │ └── dto
│ │ │ │ └── platform
│ │ │ │ ├── dto
│ │ │ │ └── OauthToken.java
│ │ │ │ └── param
│ │ │ │ ├── ClientParam.java
│ │ │ │ ├── ClientUserParam.java
│ │ │ │ └── TokenInfoParam.java
│ │ ├── maozi-cloud-system-user-dto
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── system
│ │ │ │ └── user
│ │ │ │ └── dto
│ │ │ │ └── global
│ │ │ │ └── dto
│ │ │ │ └── SystemUser.java
│ │ └── pom.xml
│ ├── maozi-cloud-enum
│ │ └── pom.xml
│ ├── maozi-cloud-vo
│ │ └── pom.xml
│ └── pom.xml
└── pom.xml
├── maozi-cloud-service
├── maozi-cloud-service-base
│ ├── maozi-cloud-service-base-impl
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ └── api
│ │ │ └── impl
│ │ │ └── rest
│ │ │ └── RestApplicationCode.java
│ ├── maozi-cloud-service-base-rest-api
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ └── annotation
│ │ │ ├── Get.java
│ │ │ ├── Post.java
│ │ │ └── RestService.java
│ ├── maozi-cloud-service-base-rpc-api
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── maozi
│ │ │ └── base
│ │ │ └── api
│ │ │ └── rpc
│ │ │ └── BaseServiceResult.java
│ ├── maozi-cloud-service-base-run
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ ├── com
│ │ │ └── maozi
│ │ │ │ └── BaseApplication.java
│ │ │ └── org
│ │ │ ├── apache
│ │ │ └── dubbo
│ │ │ │ └── spring
│ │ │ │ └── boot
│ │ │ │ └── context
│ │ │ │ └── event
│ │ │ │ └── WelcomeLogoApplicationListener.java
│ │ │ └── springframework
│ │ │ └── boot
│ │ │ ├── SpringApplication.java
│ │ │ └── StartupInfoLogger.java
│ └── pom.xml
├── maozi-cloud-service-business
│ ├── maozi-cloud-service-impl
│ │ ├── maozi-cloud-service-bd
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── bd
│ │ │ │ ├── api
│ │ │ │ ├── BDService.java
│ │ │ │ └── impl
│ │ │ │ │ └── BDServiceImpl.java
│ │ │ │ └── properties
│ │ │ │ └── BDProperties.java
│ │ ├── maozi-cloud-service-company-wechat
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── wx
│ │ │ │ ├── api
│ │ │ │ ├── WxService.java
│ │ │ │ └── impl
│ │ │ │ │ └── WxServiceImpl.java
│ │ │ │ ├── config
│ │ │ │ ├── AesException.java
│ │ │ │ ├── ByteGroup.java
│ │ │ │ ├── PKCS7Encoder.java
│ │ │ │ ├── SHA1.java
│ │ │ │ ├── WXBizMsgCrypt.java
│ │ │ │ └── XMLParse.java
│ │ │ │ └── properties
│ │ │ │ └── WxProperties.java
│ │ ├── maozi-cloud-service-qny
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── qny
│ │ │ │ ├── api
│ │ │ │ ├── QNYService.java
│ │ │ │ └── impl
│ │ │ │ │ ├── QNYServiceImpl.java
│ │ │ │ │ └── rest
│ │ │ │ │ └── OssServiceRestImpl.java
│ │ │ │ └── properties
│ │ │ │ └── QNYProperties.java
│ │ ├── maozi-cloud-service-ss
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── ss
│ │ │ │ ├── api
│ │ │ │ ├── SSService.java
│ │ │ │ └── impl
│ │ │ │ │ └── SSServiceImpl.java
│ │ │ │ ├── config
│ │ │ │ └── SSConfig.java
│ │ │ │ └── properties
│ │ │ │ └── SSProperties.java
│ │ └── pom.xml
│ ├── maozi-cloud-service-rest-api
│ │ ├── maozi-cloud-service-rest-api-oauth-token
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── oauth
│ │ │ │ └── token
│ │ │ │ └── api
│ │ │ │ └── rest
│ │ │ │ └── v1
│ │ │ │ ├── RestOauthTokenServiceV1.java
│ │ │ │ └── fallback
│ │ │ │ └── OauthTokenServiceRestFallBackFactory.java
│ │ └── pom.xml
│ ├── maozi-cloud-service-rpc-api
│ │ ├── maozi-cloud-service-rpc-api-oauth-token
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── oauth
│ │ │ │ └── token
│ │ │ │ └── api
│ │ │ │ └── rpc
│ │ │ │ └── v1
│ │ │ │ └── RpcOauthTokenServiceV1.java
│ │ ├── maozi-cloud-service-rpc-api-system-config
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── system
│ │ │ │ └── config
│ │ │ │ └── api
│ │ │ │ └── rpc
│ │ │ │ └── v1
│ │ │ │ └── RpcRegionServiceV1.java
│ │ ├── maozi-cloud-service-rpc-api-system-user
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── maozi
│ │ │ │ └── system
│ │ │ │ └── user
│ │ │ │ └── api
│ │ │ │ └── rpc
│ │ │ │ └── v1
│ │ │ │ └── RpcUserInfoServiceV1.java
│ │ └── pom.xml
│ └── pom.xml
├── maozi-cloud-service-plugin
│ ├── maozi-cloud-service-db-impl
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ ├── baomidou
│ │ │ └── mybatisplus
│ │ │ │ └── extension
│ │ │ │ └── service
│ │ │ │ └── impl
│ │ │ │ └── ServiceImpl.java
│ │ │ ├── github
│ │ │ └── yulichang
│ │ │ │ └── base
│ │ │ │ └── MPJBaseServiceImpl.java
│ │ │ └── maozi
│ │ │ ├── BaseApplicationDB.java
│ │ │ └── base
│ │ │ ├── api
│ │ │ ├── IBaseMapper.java
│ │ │ └── impl
│ │ │ │ └── BaseServiceImpl.java
│ │ │ └── plugin
│ │ │ ├── JoinBasePlugin.java
│ │ │ ├── QueryBasePlugin.java
│ │ │ ├── StoreClassDBScan.java
│ │ │ ├── impl
│ │ │ ├── join
│ │ │ │ ├── QueryInnerJoinPlugin.java
│ │ │ │ ├── QueryLeftJoinPlugin.java
│ │ │ │ └── QueryRightJoinPlugin.java
│ │ │ └── query
│ │ │ │ ├── QueryEqPlugin.java
│ │ │ │ ├── QueryGePlugin.java
│ │ │ │ ├── QueryInPlugin.java
│ │ │ │ ├── QueryLePlugin.java
│ │ │ │ ├── QueryLikePlugin.java
│ │ │ │ └── QueryNePlugin.java
│ │ │ └── type
│ │ │ ├── JoinType.java
│ │ │ └── QueryType.java
│ └── pom.xml
└── pom.xml
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # IDEA project environment #
26 | *.iml
27 | .idea
28 |
29 | # Eclipse project environment #
30 | .settings
31 | .project
32 | .classpath
33 | .factorypath
34 | .springBeans
35 | target
36 |
37 | # Spring Tool Suits project environment #
38 | .sts4-cache
39 |
40 | .flattened-pom.xml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # maozi-cloud-parent
2 |
3 |
4 |
5 | 基于 Spring-Cloud-Alibaba-Dubbo 开源封装一站式分布式解决方案,它包含开发分布式应用程序所需的所有组件,为开发团队代码风格一致,提升代码质量,专注高效快速开发业务
6 |
7 |
8 |
9 | 亮点组件:全链路灰度( Web Job Mq Dubbo Gateway ) 、全链路完整日志 、结合WSL2自动化部署开发环境 、DTO VO TO CRUD 、重写Klock分布式锁 、服务监控 、领域模型 、结构设计
10 |
11 |
12 |
13 | 为什么选择 maozi-cloud-parent 而不选择 Pigx 、Ruoyi 、Guns 、JeeSite 等开源框架,他们的底层代码我都读完 ,结构非常不清晰 、父模块子模块依赖耦合度极高 没有聚合层 依赖超级乱 、收费 、领域模型非常神奇 、全链路日志不完善 、没有灰度模式 、很多人用了到最后十个有九个成屎山 动也不是 不动也不是
14 |
15 |
16 |
17 | 官方文档:[快速开始](https://www.yuque.com/pengjinlong/maozi-cloud-parent)
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | 微信联系方式:x_mao_zi
28 |
29 | QQ联系方式:1095071913
30 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-common
8 | ${parent-revision}
9 |
10 | maozi-cloud-common-generate-code
11 |
12 |
13 |
14 |
15 |
16 | com.mchange
17 | c3p0
18 | 0.9.5.4
19 |
20 |
21 |
22 | org.dom4j
23 | dom4j
24 | 2.1.3
25 |
26 |
27 |
28 | com.maozi
29 | maozi-cloud-base-do
30 | ${maozi-cloud-base-do.version}
31 |
32 |
33 |
34 | com.maozi
35 | maozi-cloud-config-db
36 | ${maozi-cloud-config-db.version}
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/datasource/C3P0.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2012-2018 the original author or authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 |
19 | package com.maozi.generate.code.datasource;
20 |
21 | import com.maozi.generate.code.entity.DataSourceConfig;
22 | import com.mchange.v2.c3p0.ComboPooledDataSource;
23 | import java.sql.Connection;
24 | import java.sql.SQLException;
25 |
26 | public class C3P0 {
27 | ComboPooledDataSource c = null;
28 | private C3P0() {
29 | try {
30 | c = new ComboPooledDataSource();
31 | c.setDriverClass("com.mysql.cj.jdbc.Driver");//FinancingProduct
32 | c.setJdbcUrl("jdbc:mysql://"+DataSourceConfig.JDBCURL+"?useSSL=false&serverTimezone=UTC&characterEncoding=utf8&nullCatalogMeansCurrent=true");
33 | c.setUser(DataSourceConfig.USER);
34 | c.setPassword(DataSourceConfig.PASSWORD);
35 | c.setMaxPoolSize(1);
36 | } catch (Exception e) {
37 |
38 | }
39 | }
40 | private static C3P0 c3p0=new C3P0();
41 |
42 | public static C3P0 getDBManager(){
43 | return c3p0;
44 | }
45 | public Connection createDBManager() throws Exception{
46 | return c.getConnection();
47 | }
48 | public static void releaseConnection(Connection connection){
49 | try {
50 | connection.close();
51 | } catch (SQLException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/entity/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 | package com.maozi.generate.code.entity;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class DataSourceConfig {
7 |
8 | public static String JDBCURL;
9 |
10 | public static String USER;
11 |
12 | public static String PASSWORD;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/entity/EntityData.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2012-2018 the original author or authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 |
19 | package com.maozi.generate.code.entity;
20 |
21 | import java.util.List;
22 | import lombok.AllArgsConstructor;
23 | import lombok.Data;
24 | import lombok.NoArgsConstructor;
25 |
26 | @Data
27 | @AllArgsConstructor
28 | @NoArgsConstructor
29 | public class EntityData {
30 |
31 | private String tableName;
32 |
33 | private String className;
34 |
35 | private List field;
36 |
37 | private String moduleName;
38 |
39 | private String packageName;
40 |
41 | // private List foreignEntityOne;
42 | //
43 | // private List foreignEntityMany;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/entity/TableData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 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 | */
17 |
18 | package com.maozi.generate.code.entity;
19 |
20 | import lombok.AllArgsConstructor;
21 | import lombok.Data;
22 | import lombok.NoArgsConstructor;
23 |
24 |
25 |
26 | @Data
27 | @AllArgsConstructor
28 | @NoArgsConstructor
29 | public class TableData {
30 |
31 | private String tableName;
32 |
33 | private String prefixFilter;
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/parent/service/GenerateProperties.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2012-2018 the original author or authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 |
19 | package com.maozi.generate.code.parent.service;
20 |
21 | import com.maozi.generate.code.tool.SQLType;
22 |
23 | public class GenerateProperties {
24 |
25 | public static void generate(String mobule,String pash,Boolean db) throws Exception {
26 |
27 | StringBuilder properties = new StringBuilder();
28 |
29 | if(db) {
30 | properties.append("spring.cloud.nacos.config.shared-dataids=${application-nacos-config},boot-datasource.yml,boot-db.yml\r\n");
31 | }else {
32 | properties.append("spring.cloud.nacos.config.shared-dataids=${application-nacos-config}\r\n");
33 | }
34 |
35 | /* 创建文件 Begin */
36 | SQLType.fileCreate(pash, "bootstrap", properties,"properties");
37 | /* 创建文件 End */
38 |
39 |
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-generate-code/src/main/java/com/maozi/generate/code/parent/service/GenerateRun.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 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 | */
17 |
18 | package com.maozi.generate.code.parent.service;
19 |
20 | import com.maozi.generate.code.tool.SQLType;
21 |
22 | public class GenerateRun {
23 |
24 | public static void generate(String module,String packageName, String pash,Boolean db) throws Exception {
25 |
26 | StringBuilder service = new StringBuilder();
27 |
28 | service.append("package " + packageName + ";\r\n\r\n");
29 |
30 | service.append("public class " + SQLType.initial(module) + "Application extends BaseApplication"+(db?"DB":"")+" {\r\n\r\n");
31 |
32 | service.append(" public static void main(String[] args) {\r\n");
33 | service.append(" ApplicationRun();\r\n");
34 | service.append(" }\r\n");
35 |
36 | service.append("\r\n}");
37 |
38 | /* 创建文件 Begin */
39 | SQLType.fileCreate(pash+"\\"+packageName.replace(".", "\\"), SQLType.initial(module) + "Application", service);
40 | /* 创建文件 End */
41 |
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-result/pom.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 | 4.0.0
6 |
7 | com.maozi
8 | maozi-cloud-common
9 | ${parent-revision}
10 |
11 | maozi-cloud-common-result
12 |
13 |
14 |
15 |
16 |
17 |
18 | com.maozi
19 | maozi-cloud-base-enum
20 | ${maozi-cloud-base-enum.version}
21 |
22 |
23 |
24 | com.maozi
25 | maozi-cloud-oauth-token-dto
26 | ${maozi-cloud-oauth-token-dto.version}
27 |
28 |
29 |
30 | com.maozi
31 | maozi-cloud-common-utils
32 | ${maozi-cloud-common-utils.version}
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.apache.skywalking
41 | apm-toolkit-trace
42 | ${skywalking.version}
43 |
44 |
45 |
46 | org.apache.skywalking
47 | apm-toolkit-logback-1.x
48 | ${skywalking.version}
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.security
57 | spring-security-core
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-result/src/main/java/com/maozi/common/result/success/SuccessResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 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 | */
17 |
18 | package com.maozi.common.result.success;
19 |
20 | import com.maozi.common.result.AbstractBaseResult;
21 | import io.swagger.v3.oas.annotations.media.Schema;
22 | import java.io.Serializable;
23 | import lombok.Data;
24 | import lombok.EqualsAndHashCode;
25 | import lombok.NoArgsConstructor;
26 | import lombok.ToString;
27 |
28 | @Data
29 | @NoArgsConstructor
30 | @ToString(callSuper = true)
31 | @EqualsAndHashCode(callSuper=true)
32 | @Schema(description = "接口成功结果集")
33 | public class SuccessResult extends AbstractBaseResult implements Serializable {
34 |
35 | private D data;
36 |
37 | public SuccessResult(D data) {
38 | this.data=data;
39 | }
40 |
41 | @Override
42 | public Integer getCode() {
43 | return 200;
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-utils/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.maozi
6 | maozi-cloud-common
7 | ${parent-revision}
8 |
9 | maozi-cloud-common-utils
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | cglib
19 | cglib
20 | ${cglib.version}
21 |
22 |
23 |
24 | org.apache.commons
25 | commons-lang3
26 |
27 |
28 |
29 | com.google.guava
30 | guava
31 | 33.2.1-jre
32 |
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-json
37 |
38 |
39 |
40 | com.alibaba
41 | transmittable-thread-local
42 | ${transmittable.version}
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-starter-validation
48 |
49 |
50 |
51 | org.springframework.cloud
52 | spring-cloud-context
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | maven_central
61 | Maven Central
62 | https://repo.maven.apache.org/maven2/
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-utils/src/main/java/com/maozi/utils/WeightedRandomSelector.java:
--------------------------------------------------------------------------------
1 | package com.maozi.utils;
2 |
3 | import java.util.NavigableMap;
4 | import java.util.Random;
5 | import java.util.TreeMap;
6 |
7 | /**
8 | * 概率随机执行函数
9 | * @param
10 | */
11 | public class WeightedRandomSelector {
12 |
13 | //ConcurrentSkipListMap保证线程安全
14 | private final NavigableMap map = new TreeMap<>();
15 |
16 | private final Random random;
17 |
18 | private double total = 0;
19 |
20 | public WeightedRandomSelector() {
21 | this(new Random());
22 | }
23 |
24 | public WeightedRandomSelector(Random random) {
25 | this.random = random;
26 | }
27 |
28 | public void add(double weight, T result) {
29 | if (weight <= 0) {
30 | return;
31 | }
32 | total += weight;
33 | map.put(total, result);
34 | }
35 |
36 | public T next() {
37 | double value = random.nextDouble() * total;
38 | return map.higherEntry(value).getValue();
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/maozi-cloud-common/maozi-cloud-common-utils/src/main/java/com/maozi/utils/context/ApplicationLinkContext.java:
--------------------------------------------------------------------------------
1 | package com.maozi.utils.context;
2 |
3 | import com.alibaba.ttl.TransmittableThreadLocal;
4 | import lombok.Data;
5 |
6 | @Data
7 | public class ApplicationLinkContext {
8 |
9 | public static TransmittableThreadLocal VERSIONS = new TransmittableThreadLocal<>();
10 |
11 | public static TransmittableThreadLocal USERNAMES = new TransmittableThreadLocal<>();
12 |
13 | public static void set(String version,String username){
14 |
15 | VERSIONS.set(version);
16 |
17 | USERNAMES.set(username);
18 |
19 | }
20 |
21 | public static void clear(){
22 |
23 | VERSIONS.remove();
24 |
25 | USERNAMES.remove();
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/maozi-cloud-common/pom.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 | 4.0.0
6 |
7 | com.maozi
8 | maozi-cloud-parent
9 | ${parent-revision}
10 |
11 | maozi-cloud-common
12 | pom
13 |
14 |
15 |
16 |
17 | cn.hutool
18 | hutool-all
19 | ${hutool.version}
20 |
21 |
22 |
23 |
24 |
25 | maozi-cloud-common-utils
26 | maozi-cloud-common-result
27 | maozi-cloud-common-generate-code
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-db/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-db
11 |
12 |
13 |
14 |
15 |
16 |
17 | com.maozi
18 | maozi-cloud-service-base-run
19 | ${maozi-cloud-service-base-run.version}
20 |
21 |
22 |
23 | com.baomidou
24 | mybatis-plus-boot-starter
25 | ${mybatis-plus.version}
26 |
27 |
28 |
29 | mysql
30 | mysql-connector-java
31 |
32 |
33 |
34 | org.jetbrains.kotlin
35 | kotlin-stdlib-jdk8
36 |
37 |
38 |
39 | org.flywaydb
40 | flyway-core
41 |
42 |
43 |
44 | com.github.yulichang
45 | mybatis-plus-join
46 | ${mybatis-plus-join.version}
47 |
48 |
49 |
50 |
51 |
52 |
53 | com.maozi
54 | maozi-cloud-base-enum
55 | ${maozi-cloud-base-enum.version}
56 |
57 |
58 |
59 | com.maozi
60 | maozi-cloud-config-redis
61 | ${maozi-cloud-config-redis.version}
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-db/src/main/java/com/maozi/db/config/EasySqlInjector.java:
--------------------------------------------------------------------------------
1 | package com.maozi.db.config;
2 |
3 | import com.baomidou.mybatisplus.annotation.FieldFill;
4 | import com.baomidou.mybatisplus.core.injector.AbstractMethod;
5 | import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
6 | import com.baomidou.mybatisplus.core.metadata.TableInfo;
7 | import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
8 | import java.util.List;
9 | import org.springframework.context.annotation.Configuration;
10 |
11 | @Configuration
12 | public class EasySqlInjector extends DefaultSqlInjector {
13 |
14 | @Override
15 | public List getMethodList(Class> mapperClass, TableInfo tableInfo) {
16 |
17 | List methodList = super.getMethodList(mapperClass, tableInfo);
18 |
19 | methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
20 |
21 | return methodList;
22 |
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-db/src/main/java/com/maozi/db/config/MybatisPlusLog.java:
--------------------------------------------------------------------------------
1 | package com.maozi.db.config;
2 |
3 | import com.maozi.common.BaseCommon;
4 | import com.maozi.utils.context.ApplicationEnvironmentContext;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.apache.ibatis.logging.Log;
7 |
8 | @Slf4j
9 | public class MybatisPlusLog implements Log {
10 |
11 | public MybatisPlusLog(String clazz) {}
12 |
13 | public boolean isDebugEnabled() {return true;}
14 |
15 | public boolean isTraceEnabled() {return true;}
16 |
17 | public void error(String s, Throwable e) {log.error(s);}
18 |
19 | public void error(String s) {log.error(s); }
20 |
21 | public void debug(String s) {
22 |
23 | if(!ApplicationEnvironmentContext.IS_RUNNING){
24 | return;
25 | }
26 |
27 | StringBuilder sql = BaseCommon.sql.get();
28 |
29 | if(BaseCommon.isNull(sql)) {
30 |
31 | sql = new StringBuilder();
32 |
33 | BaseCommon.sql.set(sql);
34 |
35 | }
36 |
37 | if(s.contains("==> Preparing: ")) {
38 |
39 | s=s.replace("==> Preparing: ","");
40 |
41 | sql.append(s);
42 |
43 | }
44 |
45 | if(s.contains("==> Parameters: ")) {
46 |
47 | s=s.replace("==> Parameters: ","");
48 |
49 | if(BaseCommon.isNotEmpty(s)) {
50 |
51 | String [] params = s.split("\\),");
52 |
53 | for(Integer i = 0 ; i < params.length ; i++) {
54 |
55 | String param = params[i];
56 |
57 | param = "'"+param.substring(0,param.indexOf("("))+"'";
58 |
59 | int index = sql.indexOf("?");
60 |
61 | if(index != -1) {
62 | sql.replace(index, index+1, param);
63 |
64 | }
65 |
66 | }
67 |
68 | }
69 |
70 | sql.append(";");
71 |
72 | }
73 |
74 | }
75 |
76 | public void trace(String s) {}
77 |
78 | public void warn(String s) {}
79 |
80 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-db/src/main/java/com/maozi/db/handler/CustomJsonTypeHandler.java:
--------------------------------------------------------------------------------
1 | package com.maozi.db.handler;
2 |
3 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
4 | import com.fasterxml.jackson.core.JsonProcessingException;
5 | import com.maozi.utils.MapperUtils;
6 | import java.io.IOException;
7 |
8 | public class CustomJsonTypeHandler extends JacksonTypeHandler {
9 |
10 | private final Class> type;
11 |
12 | public CustomJsonTypeHandler(Class> type) {
13 |
14 | super(type);
15 |
16 | this.type = type;
17 |
18 | }
19 |
20 | protected Object parse(String json) {
21 |
22 | try {
23 | return MapperUtils.getObjectMapper().readValue(json, this.type);
24 | } catch (IOException var3) {
25 | IOException e = var3;
26 | throw new RuntimeException(e);
27 | }
28 |
29 | }
30 |
31 | protected String toJson(Object obj) {
32 |
33 | try {
34 | return MapperUtils.getObjectMapper().writeValueAsString(obj);
35 | } catch (JsonProcessingException var3) {
36 | JsonProcessingException e = var3;
37 | throw new RuntimeException(e);
38 | }
39 |
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-discovery/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-discovery
11 |
12 |
13 |
14 |
15 |
16 | com.alibaba.cloud
17 | spring-cloud-starter-alibaba-nacos-discovery
18 |
19 |
20 |
21 | com.maozi
22 | maozi-cloud-common-result
23 | ${maozi-cloud-common-result.version}
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-loadbalancer
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-discovery/src/main/java/com/maozi/discovery/balancer/GrayLoadBalancerAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.maozi.discovery.balancer;
2 |
3 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @LoadBalancerClients(defaultConfiguration = GrayLoadBalancerClientConfiguration.class)
8 | public class GrayLoadBalancerAutoConfiguration {
9 |
10 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-discovery/src/main/java/com/maozi/discovery/balancer/GrayLoadBalancerClientConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.maozi.discovery.balancer;
2 |
3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4 | import org.springframework.cloud.client.ServiceInstance;
5 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClientConfiguration;
6 | import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
7 | import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
8 | import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.core.env.Environment;
11 |
12 | public class GrayLoadBalancerClientConfiguration extends LoadBalancerClientConfiguration {
13 |
14 | @Bean
15 | @Override
16 | @ConditionalOnMissingBean
17 | public ReactorLoadBalancer reactorServiceInstanceLoadBalancer(Environment environment,LoadBalancerClientFactory loadBalancerClientFactory) {
18 |
19 | String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
20 |
21 | return new GrayRoundRobinLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class));
22 |
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/java/com/maozi/dubbo/filter/ApplicationLinkContextSetFilter.java:
--------------------------------------------------------------------------------
1 | package com.maozi.dubbo.filter;
2 |
3 | import com.maozi.common.BaseCommon;
4 | import com.maozi.utils.context.ApplicationLinkContext;
5 | import org.apache.dubbo.rpc.Filter;
6 | import org.apache.dubbo.rpc.Invocation;
7 | import org.apache.dubbo.rpc.Invoker;
8 | import org.apache.dubbo.rpc.Result;
9 | import org.apache.dubbo.rpc.RpcContext;
10 | import org.apache.dubbo.rpc.RpcContextAttachment;
11 | import org.apache.dubbo.rpc.RpcException;
12 |
13 | public class ApplicationLinkContextSetFilter implements Filter {
14 |
15 | @Override
16 | public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
17 |
18 | RpcContextAttachment serverAttachment = RpcContext.getServerAttachment();
19 |
20 | ApplicationLinkContext.set(serverAttachment.getAttachment("revision"),serverAttachment.getAttachment("username"));
21 |
22 | try{ return invoker.invoke(invocation); }catch (Throwable e){ throw e; }finally{
23 | BaseCommon.clearContext();
24 | }
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/java/com/maozi/dubbo/filter/ApplicationLinkContextTransmitFilter.java:
--------------------------------------------------------------------------------
1 | package com.maozi.dubbo.filter;
2 |
3 | import com.maozi.utils.context.ApplicationLinkContext;
4 | import org.apache.dubbo.rpc.Filter;
5 | import org.apache.dubbo.rpc.Invocation;
6 | import org.apache.dubbo.rpc.Invoker;
7 | import org.apache.dubbo.rpc.Result;
8 | import org.apache.dubbo.rpc.RpcContext;
9 | import org.apache.dubbo.rpc.RpcContextAttachment;
10 | import org.apache.dubbo.rpc.RpcException;
11 |
12 | public class ApplicationLinkContextTransmitFilter implements Filter {
13 |
14 | @Override
15 | public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
16 |
17 | RpcContextAttachment clientAttachment = RpcContext.getClientAttachment();
18 |
19 | clientAttachment.setAttachment("revision",ApplicationLinkContext.VERSIONS.get());
20 |
21 | clientAttachment.setAttachment("username", ApplicationLinkContext.USERNAMES.get());
22 |
23 | return invoker.invoke(invocation);
24 |
25 | // return new AsyncRpcResult(CompletableFuture.completedFuture(new AppResponse(BaseCommon.error(new CodeData(6,"服务错误" + "(" + applicationName + ")"),500))), invocation);
26 |
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/java/com/maozi/dubbo/provider/ProviderFirstParams.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.maozi.dubbo.provider;
18 |
19 | import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
20 | import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
21 | import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
22 | import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
23 | import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
24 |
25 | import java.util.Arrays;
26 | import java.util.Collections;
27 | import java.util.HashSet;
28 | import java.util.Set;
29 | import org.apache.dubbo.registry.support.DefaultProviderFirstParams;
30 |
31 | public class ProviderFirstParams extends DefaultProviderFirstParams {
32 | private final static Set PARAMS = Collections.unmodifiableSet(new HashSet() {{
33 | addAll(Arrays.asList(RELEASE_KEY, DUBBO_VERSION_KEY, METHODS_KEY, TIMESTAMP_KEY, TAG_KEY,"application.version"));
34 | }});
35 |
36 | @Override
37 | public Set params() {
38 | return PARAMS;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/java/com/maozi/dubbo/router/GrayRouter.java:
--------------------------------------------------------------------------------
1 | package com.maozi.dubbo.router;
2 |
3 | import com.google.common.collect.Lists;
4 | import com.maozi.common.BaseCommon;
5 | import com.maozi.utils.context.ApplicationLinkContext;
6 | import java.util.List;
7 | import org.apache.dubbo.common.URL;
8 | import org.apache.dubbo.rpc.Invocation;
9 | import org.apache.dubbo.rpc.Invoker;
10 | import org.apache.dubbo.rpc.RpcException;
11 | import org.apache.dubbo.rpc.cluster.router.AbstractRouter;
12 | import org.apache.dubbo.rpc.cluster.router.RouterResult;
13 |
14 | public class GrayRouter extends AbstractRouter {
15 |
16 | @Override
17 | public RouterResult> route(List> invokers, URL url, Invocation invocation, boolean needToPrintMessage) throws RpcException {
18 |
19 | String version = ApplicationLinkContext.VERSIONS.get();
20 |
21 | List> mainApplicationClients = Lists.newArrayList();
22 |
23 | List> grayApplicationClients = Lists.newArrayList();
24 |
25 | invokers.stream().forEach(invoker ->{
26 |
27 | String clientApplicationVersion = invoker.getUrl().getParameter("application.version");
28 |
29 | if(BaseCommon.isNotEmpty(version) && version.equals(clientApplicationVersion)){
30 | grayApplicationClients.add(invoker);
31 | }
32 |
33 | if("main".equals(clientApplicationVersion)){
34 | mainApplicationClients.add(invoker);
35 | }
36 |
37 | });
38 |
39 | return new RouterResult<>(BaseCommon.collectionIsNotEmpty(grayApplicationClients) ? grayApplicationClients : mainApplicationClients);
40 |
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/java/com/maozi/dubbo/router/RouterFactory.java:
--------------------------------------------------------------------------------
1 | package com.maozi.dubbo.router;
2 |
3 | import org.apache.dubbo.common.URL;
4 | import org.apache.dubbo.common.constants.CommonConstants;
5 | import org.apache.dubbo.common.extension.Activate;
6 | import org.apache.dubbo.rpc.cluster.CacheableRouterFactory;
7 | import org.apache.dubbo.rpc.cluster.Router;
8 |
9 | @Activate(group = CommonConstants.CONSUMER)
10 | public class RouterFactory extends CacheableRouterFactory {
11 |
12 | @Override
13 | protected Router createRouter(URL url) {
14 | return new GrayRouter();
15 | }
16 |
17 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.registry.ProviderFirstParams:
--------------------------------------------------------------------------------
1 | providerFirstParams=com.maozi.dubbo.provider.ProviderFirstParams
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter:
--------------------------------------------------------------------------------
1 | applicationLinkContextSetFilter=com.maozi.dubbo.filter.ApplicationLinkContextSetFilter
2 | applicationLinkContextTransmitFilter=com.maozi.dubbo.filter.ApplicationLinkContextTransmitFilter
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory:
--------------------------------------------------------------------------------
1 | routerFactory=com.maozi.dubbo.router.RouterFactory
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-feign/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-feign
11 |
12 |
13 |
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-openfeign
19 |
20 |
21 |
22 | io.github.openfeign
23 | feign-okhttp
24 |
25 |
26 |
27 | com.maozi
28 | maozi-cloud-common-result
29 | ${maozi-cloud-common-result.version}
30 |
31 |
32 |
33 | javax.ws.rs
34 | javax.ws.rs-api
35 | 2.1
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-feign/src/main/java/com/maozi/feign/config/ErrorDecoder.java:
--------------------------------------------------------------------------------
1 | package com.maozi.feign.config;
2 |
3 | import com.maozi.common.result.error.exception.BusinessResultException;
4 | import feign.Response;
5 | import feign.Util;
6 | import java.io.IOException;
7 | import java.nio.charset.Charset;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class ErrorDecoder implements feign.codec.ErrorDecoder {
12 |
13 | @Override
14 | public Exception decode(String methodKey, Response response) {
15 |
16 | try {return new BusinessResultException(response.status(),Util.toString(response.body().asReader(Charset.defaultCharset())),response.status());} catch (IOException e) {
17 | return e;
18 | }
19 |
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-feign/src/main/java/com/maozi/feign/config/TokenRequestInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.maozi.feign.config;
2 |
3 | import static com.maozi.common.BaseCommon.getRequest;
4 |
5 | import com.maozi.utils.context.ApplicationLinkContext;
6 | import feign.RequestInterceptor;
7 | import feign.RequestTemplate;
8 | import java.util.Enumeration;
9 | import javax.servlet.http.HttpServletRequest;
10 | import org.springframework.stereotype.Component;
11 |
12 | @Component
13 | public class TokenRequestInterceptor implements RequestInterceptor {
14 |
15 | @Override
16 | public void apply(RequestTemplate requestTemplate) {
17 |
18 | HttpServletRequest request = getRequest();
19 |
20 | Enumeration headerNames = request.getHeaderNames();
21 |
22 | if (headerNames != null) {
23 |
24 | while (headerNames.hasMoreElements()) {
25 |
26 | String name = headerNames.nextElement();
27 |
28 | if("authorization".equals(name)) {
29 | requestTemplate.header(name, request.getHeader(name));
30 | }
31 |
32 | }
33 |
34 | requestTemplate.header("Version", ApplicationLinkContext.VERSIONS.get());
35 |
36 | }
37 |
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-job/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-job
11 |
12 |
13 |
14 |
15 |
16 | com.xuxueli
17 | xxl-job-core
18 | ${xxl-job-core.version}
19 |
20 |
21 |
22 | com.maozi
23 | maozi-cloud-common-result
24 | ${maozi-cloud-common-result.version}
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-aop
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-job/src/main/java/com/maozi/job/XxlJobConfig.java:
--------------------------------------------------------------------------------
1 | package com.maozi.job;
2 |
3 | import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | @Configuration
9 | public class XxlJobConfig {
10 |
11 | @Value("${xxl.job.admin.addresses}")
12 | private String adminAddresses;
13 |
14 | @Value("${xxl.job.accessToken}")
15 | private String accessToken;
16 |
17 | @Value("${xxl.job.executor.appname}")
18 | private String appname;
19 |
20 | @Value("${xxl.job.executor.address}")
21 | private String address;
22 |
23 | @Value("${xxl.job.executor.ip}")
24 | private String ip;
25 |
26 | @Value("${xxl.job.executor.port}")
27 | private int port;
28 |
29 | @Value("${xxl.job.executor.logpath}")
30 | private String logPath;
31 |
32 | @Value("${xxl.job.executor.logretentiondays}")
33 | private int logRetentionDays;
34 |
35 |
36 | @Bean
37 | public XxlJobSpringExecutor xxlJobExecutor() {
38 | XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
39 | xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
40 | xxlJobSpringExecutor.setAppname(appname);
41 | xxlJobSpringExecutor.setIp(ip);
42 | xxlJobSpringExecutor.setPort(port);
43 | xxlJobSpringExecutor.setAccessToken(accessToken);
44 | xxlJobSpringExecutor.setLogPath(logPath);
45 | xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
46 | return xxlJobSpringExecutor;
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.maozi
8 | maozi-cloud-config
9 | ${parent-revision}
10 |
11 | maozi-cloud-config-lock
12 |
13 |
14 |
15 |
16 | org.redisson
17 | redisson
18 | ${redisson.version}
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-aop
24 |
25 |
26 |
27 |
28 | com.maozi
29 | maozi-cloud-common-result
30 | ${maozi-cloud-common-result.version}
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/annotation/Lock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.annotation;
2 |
3 | import com.maozi.lock.error.strategy.impl.LockTimeoutStrategy;
4 | import com.maozi.lock.error.strategy.impl.UnLockTimeoutStrategy;
5 | import com.maozi.lock.lock.LockType;
6 | import java.lang.annotation.ElementType;
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 | import java.lang.annotation.Target;
10 |
11 |
12 | @Target(value = {ElementType.METHOD})
13 | @Retention(value = RetentionPolicy.RUNTIME)
14 | public @interface Lock {
15 |
16 | /**
17 | * 锁的名称
18 | * @return name
19 | */
20 | String name() default "";
21 |
22 | /**
23 | * 锁类型,默认可重入锁
24 | * @return lockType
25 | */
26 | LockType type() default LockType.Reentrant;
27 |
28 | /**
29 | * 尝试加锁,最多等待时间
30 | * @return waitTime
31 | */
32 | long waitTime() default Long.MIN_VALUE;
33 |
34 | /**
35 | *上锁以后xxx秒自动解锁
36 | * @return leaseTime
37 | */
38 | long leaseTime() default Long.MIN_VALUE;
39 |
40 | /**
41 | * 自定义业务key
42 | * @return keys
43 | */
44 | String [] keys() default {};
45 |
46 | /**
47 | * 加锁超时的处理策略
48 | * @return lockTimeoutStrategy
49 | */
50 | LockTimeoutStrategy lockTimeoutStrategy() default LockTimeoutStrategy.KEEP_ACQUIRE;
51 |
52 | /**
53 | * 释放锁时已超时的处理策略
54 | * @return releaseTimeoutStrategy
55 | */
56 | UnLockTimeoutStrategy releaseTimeoutStrategy() default UnLockTimeoutStrategy.NO_OPERATION;
57 |
58 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/annotation/LockKey.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(value = RetentionPolicy.RUNTIME)
9 | @Target(value = {ElementType.PARAMETER, ElementType.TYPE})
10 | public @interface LockKey {
11 |
12 | String value() default "";
13 |
14 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/config/RedissonConfig.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.config;
2 |
3 | import com.maozi.common.BaseCommon;
4 | import com.maozi.lock.properties.LockProperties;
5 | import io.netty.channel.nio.NioEventLoopGroup;
6 | import javax.annotation.Resource;
7 | import org.redisson.Redisson;
8 | import org.redisson.api.RedissonClient;
9 | import org.redisson.config.Config;
10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 |
14 | @Configuration
15 | public class RedissonConfig {
16 |
17 | @Resource
18 | private LockProperties properties;
19 |
20 | @Bean(destroyMethod = "shutdown")
21 | @ConditionalOnMissingBean
22 | public RedissonClient redisson() throws Exception {
23 |
24 | Config config = new Config();
25 |
26 | if(BaseCommon.isNotNull(properties.getNodeAddresses())){
27 | config.useClusterServers().setPassword(properties.getPassword()).addNodeAddress(properties.getNodeAddresses());
28 | }else {
29 | config.useSingleServer().setAddress(properties.getAddress()).setDatabase(properties.getDatabase()).setPassword(properties.getPassword());
30 | }
31 |
32 | config.setEventLoopGroup(new NioEventLoopGroup());
33 |
34 | return Redisson.create(config);
35 |
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/error/strategy/LockTimeoutHandler.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.error.strategy;
2 |
3 | import com.maozi.lock.lock.Lock;
4 |
5 | public interface LockTimeoutHandler {
6 |
7 | void handle(String key,Long waitTime,Long leaseTime,Lock lock) throws Exception ;
8 |
9 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/error/strategy/UnLockTimeoutHandler.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.error.strategy;
2 |
3 | public interface UnLockTimeoutHandler {
4 |
5 | void handle();
6 |
7 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/error/strategy/impl/LockTimeoutStrategy.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.error.strategy.impl;
2 |
3 | import com.maozi.base.error.code.SystemErrorCode;
4 | import com.maozi.common.result.error.exception.BusinessResultException;
5 | import com.maozi.lock.error.strategy.LockTimeoutHandler;
6 | import com.maozi.lock.lock.Lock;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | public enum LockTimeoutStrategy implements LockTimeoutHandler {
10 |
11 | FAIL_FAST() {
12 | @Override
13 | public void handle(String key,Long waitTime,Long leaseTime,Lock lock) throws Exception {
14 | throw new BusinessResultException(SystemErrorCode.CURRENT_LIMITING_ERROR,429);
15 | }
16 | },
17 |
18 | KEEP_ACQUIRE() {
19 |
20 | private final Long DEFAULT_INTERVAL = 100L;
21 |
22 | private final Long DEFAULT_MAX_INTERVAL = 3L * 60L * 1000L;
23 |
24 | @Override
25 | public void handle(String key,Long waitTime,Long leaseTime,Lock lock) throws Exception {
26 |
27 | Long interval = DEFAULT_INTERVAL;
28 |
29 | while (!lock.lock(key,waitTime,leaseTime)) {
30 |
31 | if (interval > DEFAULT_MAX_INTERVAL) {
32 | throw new BusinessResultException(SystemErrorCode.CURRENT_LIMITING_ERROR,429);
33 | }
34 |
35 | TimeUnit.MILLISECONDS.sleep(interval);
36 |
37 | interval <<= 1;
38 |
39 | }
40 |
41 | }
42 |
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/error/strategy/impl/UnLockTimeoutStrategy.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.error.strategy.impl;
2 |
3 | import com.maozi.base.error.code.SystemErrorCode;
4 | import com.maozi.common.result.error.exception.BusinessResultException;
5 | import com.maozi.lock.error.strategy.UnLockTimeoutHandler;
6 |
7 | public enum UnLockTimeoutStrategy implements UnLockTimeoutHandler {
8 |
9 | NO_OPERATION() {
10 |
11 | @Override
12 | public void handle() {}
13 |
14 | },
15 |
16 | FAIL_FAST() {
17 |
18 | @Override
19 | public void handle() {
20 | throw new BusinessResultException(SystemErrorCode.CURRENT_LIMITING_ERROR,429);
21 | }
22 |
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/lock/Lock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.lock;
2 |
3 | public interface Lock {
4 |
5 | boolean lock(String key,Long waitTime,Long leaseTime) throws Exception;
6 |
7 | boolean unLock(String key) throws Exception;
8 |
9 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/lock/impl/FairLock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.lock.impl;
2 |
3 | import com.maozi.lock.lock.Lock;
4 | import java.util.concurrent.TimeUnit;
5 | import javax.annotation.Resource;
6 | import org.redisson.api.RLock;
7 | import org.redisson.api.RedissonClient;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class FairLock implements Lock {
12 |
13 | @Resource
14 | private RedissonClient redissonClient;
15 |
16 | @Override
17 | public boolean lock(String key,Long waitTime,Long leaseTime) throws Exception {
18 | return redissonClient.getFairLock(key).tryLock(waitTime,leaseTime,TimeUnit.SECONDS);
19 | }
20 |
21 | @Override
22 | public boolean unLock(String key) throws Exception {
23 |
24 | RLock lock = redissonClient.getFairLock(key);
25 |
26 | return lock.isHeldByCurrentThread() ? lock.forceUnlockAsync().get() : false;
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/lock/impl/ReadLock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.lock.impl;
2 |
3 | import com.maozi.lock.lock.Lock;
4 | import java.util.concurrent.TimeUnit;
5 | import javax.annotation.Resource;
6 | import org.redisson.api.RReadWriteLock;
7 | import org.redisson.api.RedissonClient;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class ReadLock implements Lock {
12 |
13 | @Resource
14 | private RedissonClient redissonClient;
15 |
16 | @Override
17 | public boolean lock(String key,Long waitTime,Long leaseTime) throws Exception {
18 | return redissonClient.getReadWriteLock(key).readLock().tryLock(waitTime,leaseTime,TimeUnit.SECONDS);
19 | }
20 |
21 | @Override
22 | public boolean unLock(String key) throws Exception {
23 |
24 | RReadWriteLock lock = redissonClient.getReadWriteLock(key);
25 |
26 | return lock.readLock().isHeldByCurrentThread() ? lock.readLock().forceUnlockAsync().get() : false;
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/lock/impl/ReentrantLock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.lock.impl;
2 |
3 | import com.maozi.lock.lock.Lock;
4 | import java.util.concurrent.TimeUnit;
5 | import javax.annotation.Resource;
6 | import org.redisson.api.RLock;
7 | import org.redisson.api.RedissonClient;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class ReentrantLock implements Lock {
12 |
13 | @Resource
14 | private RedissonClient redissonClient;
15 |
16 | @Override
17 | public boolean lock(String key,Long waitTime,Long leaseTime) throws Exception {
18 | return redissonClient.getLock(key).tryLock(waitTime,leaseTime,TimeUnit.SECONDS);
19 | }
20 |
21 | @Override
22 | public boolean unLock(String key) throws Exception {
23 |
24 | RLock lock = redissonClient.getLock(key);
25 |
26 | return lock.isHeldByCurrentThread() ? lock.forceUnlockAsync().get() : false;
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/lock/impl/WriteLock.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.lock.impl;
2 |
3 | import com.maozi.lock.lock.Lock;
4 | import java.util.concurrent.TimeUnit;
5 | import javax.annotation.Resource;
6 | import org.redisson.api.RReadWriteLock;
7 | import org.redisson.api.RedissonClient;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class WriteLock implements Lock {
12 |
13 | @Resource
14 | private RedissonClient redissonClient;
15 |
16 | @Override
17 | public boolean lock(String key,Long waitTime,Long leaseTime) throws Exception {
18 | return redissonClient.getReadWriteLock(key).writeLock().tryLock(waitTime,leaseTime,TimeUnit.SECONDS);
19 | }
20 |
21 | @Override
22 | public boolean unLock(String key) throws Exception {
23 |
24 | RReadWriteLock lock = redissonClient.getReadWriteLock(key);
25 |
26 | return lock.writeLock().isHeldByCurrentThread() ? lock.writeLock().forceUnlockAsync().get() : false;
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-lock/src/main/java/com/maozi/lock/properties/LockProperties.java:
--------------------------------------------------------------------------------
1 | package com.maozi.lock.properties;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Data
8 | @Configuration
9 | @ConfigurationProperties(prefix = "spring.lock")
10 | public class LockProperties {
11 |
12 | private String address;
13 |
14 | private String password;
15 |
16 | private int database = 0;
17 |
18 | private String[] nodeAddresses;
19 |
20 | private long waitTime = 60;
21 |
22 | private long leaseTime = 60;
23 |
24 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-log/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-log
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | com.maozi
19 | maozi-cloud-common-result
20 | ${maozi-cloud-common-result.version}
21 |
22 |
23 |
24 | com.maozi
25 | maozi-cloud-config-oauth
26 | ${maozi-cloud-config-oauth.version}
27 |
28 |
29 |
30 | com.maozi
31 | maozi-cloud-config-sentinel
32 | ${maozi-cloud-config-sentinel.version}
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-aop
38 |
39 |
40 |
41 | org.codehaus.janino
42 | janino
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-log/src/main/java/com/maozi/log/config/TtlMDCAdapterInitializer.java:
--------------------------------------------------------------------------------
1 | package com.maozi.log.config;
2 |
3 | import org.slf4j.TtlMDCAdapter;
4 | import org.springframework.context.ApplicationContextInitializer;
5 | import org.springframework.context.ConfigurableApplicationContext;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | @Configuration
9 | public class TtlMDCAdapterInitializer implements ApplicationContextInitializer {
10 |
11 | @Override
12 | public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
13 | TtlMDCAdapter.getInstance();
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-log/src/main/java/com/maozi/log/convert/ApplicationNameMessageConverter.java:
--------------------------------------------------------------------------------
1 | package com.maozi.log.convert;
2 |
3 | import ch.qos.logback.classic.pattern.MessageConverter;
4 | import ch.qos.logback.classic.spi.ILoggingEvent;
5 | import com.maozi.utils.context.ApplicationEnvironmentContext;
6 |
7 | public class ApplicationNameMessageConverter extends MessageConverter {
8 | @Override
9 | public String convert(ILoggingEvent event) {
10 | return ApplicationEnvironmentContext.APPLICATION_NAME;
11 | }
12 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-log/src/main/java/com/maozi/log/convert/EnvironmentMessageConverter.java:
--------------------------------------------------------------------------------
1 | package com.maozi.log.convert;
2 |
3 | import ch.qos.logback.classic.pattern.MessageConverter;
4 | import ch.qos.logback.classic.spi.ILoggingEvent;
5 | import com.maozi.utils.context.ApplicationEnvironmentContext;
6 |
7 | public class EnvironmentMessageConverter extends MessageConverter {
8 | @Override
9 | public String convert(ILoggingEvent event) {
10 | return ApplicationEnvironmentContext.ENVIRONMENT;
11 | }
12 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-monitor/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-monitor
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | com.maozi
19 | maozi-cloud-common-result
20 | ${maozi-cloud-common-result.version}
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | de.codecentric
29 | spring-boot-admin-starter-client
30 | ${spring-boot-admin-starter.version}
31 |
32 |
33 |
34 | io.micrometer
35 | micrometer-registry-prometheus
36 |
37 |
38 |
39 | com.taobao.arthas
40 | arthas-spring-boot-starter
41 | ${arthas.version}
42 |
43 |
44 |
45 | org.jolokia
46 | jolokia-core
47 |
48 |
49 |
50 | com.maozi
51 | maozi-cloud-service-base-rest-api
52 | ${maozi-cloud-service-base-rest-api.version}
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-monitor/src/main/java/com/maozi/health/api/impl/rest/RestErrorLog.java:
--------------------------------------------------------------------------------
1 | package com.maozi.health.api.impl.rest;
2 |
3 | import com.maozi.base.annotation.Post;
4 | import com.maozi.base.annotation.RestService;
5 | import com.maozi.base.error.code.SystemErrorCode;
6 | import com.maozi.common.BaseCommon;
7 | import com.maozi.common.result.AbstractBaseResult;
8 | import io.swagger.v3.oas.annotations.tags.Tag;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 |
11 | @RestService
12 | @Tag(name = "【全局】告警日志")
13 | public class RestErrorLog extends BaseCommon {
14 |
15 | private static final String PATH = "/application/error/log";
16 |
17 | @Post(value = PATH + "/{id}/remove",description = "删除")
18 | public AbstractBaseResult remove(@PathVariable String id) {
19 | adminHealthError.remove(id);
20 | return success(null);
21 | }
22 |
23 | @Post(value = PATH + "/removeAll",description = "清空")
24 | public AbstractBaseResult removeAll() {
25 | adminHealthError.clear();
26 | return success(null);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-oauth/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-oauth
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | org.springframework.cloud
19 | spring-cloud-starter-oauth2
20 | ${spring-cloud-starter-oauth2.version}
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.maozi
29 | maozi-cloud-config-dubbo
30 | ${maozi-cloud-config-dubbo.version}
31 |
32 |
33 |
34 | com.maozi
35 | maozi-cloud-service-rpc-api-oauth-token
36 | ${maozi-cloud-service-rpc-api-oauth-token.version}
37 |
38 |
39 |
40 | com.maozi
41 | maozi-cloud-service-rest-api-oauth-token
42 | ${maozi-cloud-service-rest-api-oauth-token.version}
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-oauth/src/main/java/com/maozi/oauth/config/IAccessDeniedHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 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 | */
17 |
18 | package com.maozi.oauth.config;
19 |
20 | import com.maozi.base.error.code.SystemErrorCode;
21 | import com.maozi.common.BaseCommon;
22 | import com.maozi.utils.MapperUtils;
23 | import javax.servlet.http.HttpServletRequest;
24 | import javax.servlet.http.HttpServletResponse;
25 | import org.springframework.security.access.AccessDeniedException;
26 | import org.springframework.security.web.access.AccessDeniedHandler;
27 |
28 | public class IAccessDeniedHandler extends BaseCommon implements AccessDeniedHandler {
29 |
30 | //权限错误显示
31 | private Integer errorCode = 403;
32 |
33 | @Override
34 | public void handle(HttpServletRequest request, HttpServletResponse response,AccessDeniedException accessDeniedException){
35 | MapperUtils.setResponseBody(response, error(getCodes().PERMISSION_ERROR,errorCode).autoIdentifyHttpCode());
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-oauth/src/main/java/com/maozi/oauth/config/IAuthenticationEntryPoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 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 | */
17 |
18 | package com.maozi.oauth.config;
19 |
20 | import com.maozi.base.CodeData;
21 | import com.maozi.base.error.code.SystemErrorCode;
22 | import com.maozi.common.BaseCommon;
23 | import com.maozi.common.result.AbstractBaseResult;
24 | import com.maozi.utils.MapperUtils;
25 | import javax.servlet.ServletException;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | import org.springframework.security.core.AuthenticationException;
29 | import org.springframework.security.web.AuthenticationEntryPoint;
30 |
31 | public class IAuthenticationEntryPoint extends BaseCommon implements AuthenticationEntryPoint {
32 |
33 | private Integer errorCode = 401;
34 |
35 | @Override
36 | public void commence(HttpServletRequest request,HttpServletResponse response,AuthenticationException authException) throws ServletException {
37 |
38 | try {
39 |
40 | String errorMessage = "Full authentication is required to access this resource".equals(authException.getMessage()) ? "未携带Token" : authException.getMessage();
41 |
42 | AbstractBaseResult error = error(new CodeData(errorCode,errorMessage),errorCode).autoIdentifyHttpCode();
43 |
44 | MapperUtils.setResponseBody(response,error);
45 |
46 | } catch (Exception e) {
47 |
48 | BaseCommon.error(e);
49 |
50 | throw new ServletException();
51 |
52 | }
53 |
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-oauth/src/main/java/com/maozi/oauth/config/IRequestRejectedHandler.java:
--------------------------------------------------------------------------------
1 | package com.maozi.oauth.config;
2 |
3 | import com.maozi.base.error.code.SystemErrorCode;
4 | import com.maozi.common.BaseCommon;
5 | import com.maozi.utils.MapperUtils;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.security.web.firewall.RequestRejectedException;
10 | import org.springframework.security.web.firewall.RequestRejectedHandler;
11 |
12 | @Configuration
13 | public class IRequestRejectedHandler extends BaseCommon implements RequestRejectedHandler {
14 |
15 | private Integer errorCode = 402;
16 |
17 | @Override
18 | public void handle(HttpServletRequest request, HttpServletResponse response,RequestRejectedException ex){
19 | MapperUtils.setResponseBody(response,error(getCodes().MALICE_REQUEST_ERROR,errorCode).autoIdentifyHttpCode());
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-oauth/src/main/java/com/maozi/oauth/properties/ApiWhitelistProperties.java:
--------------------------------------------------------------------------------
1 | package com.maozi.oauth.properties;
2 |
3 | import com.google.common.collect.Lists;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.annotation.Value;
8 | import org.springframework.stereotype.Component;
9 |
10 |
11 | @Data
12 | @Component
13 | public class ApiWhitelistProperties {
14 |
15 | @Value("${application-project-whitelist:#{null}}")
16 | private List whitelist = Lists.newArrayList();
17 |
18 | private List defaultWitelist = new ArrayList(){
19 |
20 | {
21 | add("/oauth/check_token");
22 | add("/webjars/**");
23 |
24 | add("/actuator/**");
25 | add("/application/**");
26 |
27 | add("/v3/api-docs/**");
28 |
29 | }
30 |
31 | };
32 |
33 | }
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-redis/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.maozi
7 | maozi-cloud-config
8 | ${parent-revision}
9 |
10 | maozi-cloud-config-redis
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | com.maozi
20 | maozi-cloud-common-result
21 | ${maozi-cloud-common-result.version}
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.apache.commons
30 | commons-pool2
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-data-redis
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/maozi-cloud-config/maozi-cloud-config-redis/src/main/java/com/maozi/redis/RedisTemplateConf.java:
--------------------------------------------------------------------------------
1 | package com.maozi.redis;
2 |
3 | import com.fasterxml.jackson.annotation.PropertyAccessor;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import org.springframework.cache.annotation.CachingConfigurerSupport;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.data.redis.connection.RedisConnectionFactory;
9 | import org.springframework.data.redis.core.RedisTemplate;
10 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
11 | import org.springframework.data.redis.serializer.RedisSerializer;
12 | import org.springframework.data.redis.serializer.StringRedisSerializer;
13 |
14 | @Configuration
15 | public class RedisTemplateConf extends CachingConfigurerSupport {
16 | @Bean
17 | public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
18 |
19 | RedisTemplate redisTemplate = new RedisTemplate<>();
20 |
21 | redisTemplate.setConnectionFactory(connectionFactory);
22 |
23 | Jackson2JsonRedisSerializer