├── .gitignore
├── LICENSE
├── README.md
├── doc
└── images
│ └── 2685774-17a60e1ead7fd232.png
├── kitty-cloud-article
├── kitty-cloud-article-api
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── article
│ │ │ └── api
│ │ │ ├── autoconfigure
│ │ │ └── RemoteServiceAutoConfigure.java
│ │ │ ├── fallback
│ │ │ └── ArticleRemoteServiceFallbackFactory.java
│ │ │ ├── request
│ │ │ └── ArticleQueryRequest.java
│ │ │ ├── response
│ │ │ └── ArticleResponse.java
│ │ │ └── service
│ │ │ ├── ArticleRemoteService.java
│ │ │ └── ArticleRemoteServiceMock.java
│ │ └── resources
│ │ └── META-INF
│ │ └── spring.factories
├── kitty-cloud-article-biz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── article
│ │ └── biz
│ │ ├── bo
│ │ └── ArticleBO.java
│ │ ├── convert
│ │ └── ArticleBoConvert.java
│ │ ├── dao
│ │ ├── ArticleDao.java
│ │ └── impl
│ │ │ └── ArticleDaoImpl.java
│ │ ├── dataobject
│ │ └── ArticleDO.java
│ │ ├── enums
│ │ ├── ArticleStatusEnum.java
│ │ └── ArticleTypeEnum.java
│ │ ├── filter
│ │ ├── FilterProcessor.java
│ │ ├── ISensitiveWordFilter.java
│ │ ├── SensitiveWordFilter.java
│ │ ├── SensitiveWordFilterResult.java
│ │ └── impl
│ │ │ ├── ChineseSensitiveWordFilter.java
│ │ │ └── EnglishSensitiveWordFilter.java
│ │ ├── manager
│ │ ├── DistributedIdManager.java
│ │ ├── UserManager.java
│ │ └── impl
│ │ │ ├── DistributedIdManagerImpl.java
│ │ │ └── UserManagerImpl.java
│ │ ├── mapper
│ │ └── ArticleMapper.java
│ │ └── service
│ │ ├── ArticleService.java
│ │ └── impl
│ │ └── ArticleServiceImpl.java
├── kitty-cloud-article-provider
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cxytiandi
│ │ │ │ └── kittycloud
│ │ │ │ └── article
│ │ │ │ └── provider
│ │ │ │ ├── KittyCloudArticleProviderApp.java
│ │ │ │ ├── convert
│ │ │ │ └── ArticleResponseConvert.java
│ │ │ │ └── service
│ │ │ │ └── ArticleRemoteServiceImpl.java
│ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── app.properties
│ │ │ ├── bootstrap.properties
│ │ │ └── logback.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── article
│ │ └── provider
│ │ ├── ArticleServiceTest.java
│ │ └── DistributedIdManagerTest.java
└── pom.xml
├── kitty-cloud-comment
├── kitty-cloud-comment-api
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── comment
│ │ └── api
│ │ ├── fallback
│ │ ├── CommentRemoteServiceFallbackFactory.java
│ │ └── CommentReplyRemoteServiceFallbackFactory.java
│ │ ├── request
│ │ ├── CommentQueryRequest.java
│ │ ├── CommentReplySaveRequest.java
│ │ └── CommentSaveRequest.java
│ │ ├── response
│ │ ├── CommentReplyResponse.java
│ │ └── CommentResponse.java
│ │ └── service
│ │ ├── CommentRemoteService.java
│ │ ├── CommentRemoteServiceMock.java
│ │ ├── CommentReplyRemoteService.java
│ │ └── CommentReplyRemoteServiceMock.java
├── kitty-cloud-comment-biz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── comment
│ │ └── biz
│ │ ├── bo
│ │ └── CommentBO.java
│ │ ├── convert
│ │ ├── CommentBOConvert.java
│ │ ├── CommentDocumentConvert.java
│ │ └── CommentReplyDocumentConvert.java
│ │ ├── dao
│ │ ├── CommentDao.java
│ │ └── impl
│ │ │ └── CommentDaoImpl.java
│ │ ├── document
│ │ ├── CommentDocument.java
│ │ └── CommentReplyDocument.java
│ │ ├── enums
│ │ └── CommentBizTypeEnum.java
│ │ ├── manager
│ │ ├── UserManager.java
│ │ ├── fallback
│ │ │ ├── dubbo
│ │ │ │ └── CustomUserRemoteServiceMock.java
│ │ │ └── feign
│ │ │ │ └── CustomUserRemoteServiceFallbackFactory.java
│ │ └── impl
│ │ │ └── UserManagerImpl.java
│ │ ├── param
│ │ ├── CommentQueryParam.java
│ │ ├── CommentReplySaveParam.java
│ │ └── CommentSaveParam.java
│ │ └── service
│ │ ├── CommentService.java
│ │ └── impl
│ │ └── CommentServiceImpl.java
├── kitty-cloud-comment-provider
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cxytiandi
│ │ │ │ └── kittycloud
│ │ │ │ └── comment
│ │ │ │ └── provider
│ │ │ │ ├── KittyCloudCommentProviderApp.java
│ │ │ │ ├── convert
│ │ │ │ ├── CommentQueryParamConvert.java
│ │ │ │ ├── CommentReplySaveParamConvert.java
│ │ │ │ ├── CommentResponseConvert.java
│ │ │ │ └── CommentSaveParamConvert.java
│ │ │ │ └── service
│ │ │ │ ├── CommentRemoteServiceImpl.java
│ │ │ │ └── CommentReplyRemoteServiceImpl.java
│ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── app.properties
│ │ │ ├── bootstrap.properties
│ │ │ └── logback.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── comment
│ │ └── provider
│ │ ├── CommentRemoteServiceTest.java
│ │ └── CommentReplyRemoteServiceTest.java
└── pom.xml
├── kitty-cloud-common
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── common
│ │ ├── aop
│ │ └── RemoteServiceAspect.java
│ │ ├── autoconfigure
│ │ ├── CommonBeanAutoConfigure.java
│ │ ├── JWTAutoConfigure.java
│ │ └── UrlBlockHandlerAutoConfigure.java
│ │ ├── base
│ │ ├── Entity.java
│ │ ├── EntityConvert.java
│ │ ├── PageEntity.java
│ │ ├── Response.java
│ │ ├── ResponseCode.java
│ │ └── ResponseData.java
│ │ ├── config
│ │ └── JwtRsaConfig.java
│ │ ├── constant
│ │ ├── CommonConstant.java
│ │ ├── DubboConstant.java
│ │ ├── EsConstant.java
│ │ └── NacosConstant.java
│ │ ├── exception
│ │ ├── BizException.java
│ │ ├── DubboExceptionHandlerFilter.java
│ │ ├── FallbackException.java
│ │ └── GlobalExceptionHandler.java
│ │ ├── handler
│ │ └── KittyCloudUrlBlockHandler.java
│ │ ├── helper
│ │ ├── ApplicationContextHelper.java
│ │ └── JWTHelper.java
│ │ └── utils
│ │ └── RSAUtils.java
│ └── resources
│ └── META-INF
│ ├── dubbo
│ └── org.apache.dubbo.rpc.Filter
│ └── spring.factories
├── kitty-cloud-gateway
├── kitty-cloud-gateway-web
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── gateway
│ │ │ └── web
│ │ │ ├── KittyCloudWebGatewayApp.java
│ │ │ ├── controller
│ │ │ └── ErrorHandlerController.java
│ │ │ └── filter
│ │ │ └── UserAuthFilter.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── app.properties
│ │ ├── bootstrap.properties
│ │ └── logback.xml
└── pom.xml
├── kitty-cloud-goods
├── kitty-cloud-goods-api
│ └── pom.xml
├── kitty-cloud-goods-biz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── goods
│ │ └── biz
│ │ ├── document
│ │ ├── AttrDocument.java
│ │ ├── AttrValueDocument.java
│ │ ├── CategoryDocument.java
│ │ ├── PoiDocument.java
│ │ ├── PoiValueDocument.java
│ │ ├── ProductDocument.java
│ │ ├── SaleAttrValueDocument.java
│ │ └── SkuDocument.java
│ │ ├── param
│ │ ├── ProductSaveParam.java
│ │ └── ProductUpdateParam.java
│ │ └── service
│ │ ├── ProductService.java
│ │ └── impl
│ │ └── ProductServiceImpl.java
├── kitty-cloud-goods-provider
│ └── pom.xml
└── pom.xml
├── kitty-cloud-job
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── job
│ │ ├── KittyCloudJobApp.java
│ │ ├── convert
│ │ └── ArticleIndexSaveRequestConvert.java
│ │ ├── handler
│ │ └── EsIndexBuildHandler.java
│ │ ├── param
│ │ └── EsIndexBuildParam.java
│ │ ├── service
│ │ └── ArticleEsIndexBuildService.java
│ │ └── template
│ │ └── AbstractEsIndexBuildTemplate.java
│ └── resources
│ ├── META-INF
│ └── app.properties
│ └── bootstrap.properties
├── kitty-cloud-mqconsume
├── kitty-cloud-mqconsume-es
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── mqconsume
│ │ │ └── es
│ │ │ ├── EsMqConsumeApp.java
│ │ │ ├── async
│ │ │ └── support
│ │ │ │ ├── CustomApplicationContextAware.java
│ │ │ │ ├── DefaultFuture.java
│ │ │ │ └── EventListenerAspect.java
│ │ │ ├── consume
│ │ │ └── DataChangeConsume.java
│ │ │ ├── controller
│ │ │ └── EsMqProduceMockRestController.java
│ │ │ ├── enums
│ │ │ └── ChangeTypeEnum.java
│ │ │ ├── event
│ │ │ └── DataChangeEvent.java
│ │ │ ├── factory
│ │ │ └── ArticleIndexServiceFactory.java
│ │ │ ├── listener
│ │ │ └── DataChangeEventListener.java
│ │ │ ├── request
│ │ │ └── DataChangeRequest.java
│ │ │ └── service
│ │ │ ├── ArticleIndexService.java
│ │ │ └── impl
│ │ │ ├── ArticleIndexRemoveServiceImpl.java
│ │ │ ├── ArticleIndexSaveServiceImpl.java
│ │ │ └── ArticleIndexUpdateServiceImpl.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── app.properties
│ │ └── bootstrap.properties
└── pom.xml
├── kitty-cloud-search
├── kitty-cloud-search-api
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── search
│ │ │ └── api
│ │ │ ├── autoconfigure
│ │ │ └── RemoteServiceAutoConfigure.java
│ │ │ ├── fallback
│ │ │ └── ArticleIndexRemoteServiceFallbackFactory.java
│ │ │ ├── request
│ │ │ ├── ArticleIndexSaveRequest.java
│ │ │ └── ArticleIndexSearchRequest.java
│ │ │ ├── response
│ │ │ └── ArticleIndexResponse.java
│ │ │ └── service
│ │ │ └── ArticleIndexRemoteService.java
│ │ └── resources
│ │ └── META-INF
│ │ └── spring.factories
├── kitty-cloud-search-biz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── search
│ │ └── biz
│ │ ├── bo
│ │ └── ArticleIndexBO.java
│ │ ├── config
│ │ └── ElasticSearchIndexConfig.java
│ │ ├── convert
│ │ ├── ArticleDocumentConvert.java
│ │ └── ArticleIndexBOConvert.java
│ │ ├── dao
│ │ ├── ArticleIndexDao.java
│ │ └── impl
│ │ │ └── ArticleIndexDaoImpl.java
│ │ ├── document
│ │ └── ArticleDocument.java
│ │ ├── param
│ │ ├── ArticleIndexSaveParam.java
│ │ └── ArticleIndexSearchParam.java
│ │ └── service
│ │ ├── ArticleIndexService.java
│ │ └── impl
│ │ └── ArticleIndexServiceImpl.java
├── kitty-cloud-search-provider
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cxytiandi
│ │ │ │ └── kittycloud
│ │ │ │ └── search
│ │ │ │ └── provider
│ │ │ │ ├── KittyCloudSearchProviderApp.java
│ │ │ │ ├── convert
│ │ │ │ ├── ArticleIndexResponseConvert.java
│ │ │ │ ├── ArticleIndexSaveParamConvert.java
│ │ │ │ └── ArticleIndexSearchParamConvert.java
│ │ │ │ └── service
│ │ │ │ └── ArticleIndexRemoteServiceImpl.java
│ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── app.properties
│ │ │ └── bootstrap.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── search
│ │ └── provider
│ │ ├── client
│ │ ├── KittyRestHighLevelClientDeleteTest.java
│ │ ├── KittyRestHighLevelClientIndexTest.java
│ │ ├── KittyRestHighLevelClientSearchTest.java
│ │ └── KittyRestHighLevelClientUpdateTest.java
│ │ └── service
│ │ └── ArticleIndexRemoteServiceTest.java
└── pom.xml
├── kitty-cloud-user
├── kitty-cloud-user-api
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── user
│ │ │ └── api
│ │ │ ├── autoconfigure
│ │ │ └── RemoteServiceAutoConfigure.java
│ │ │ ├── fallback
│ │ │ └── UserRemoteServiceFallbackFactory.java
│ │ │ ├── request
│ │ │ └── UserLoginRequest.java
│ │ │ ├── response
│ │ │ └── UserResponse.java
│ │ │ └── service
│ │ │ ├── UserRemoteService.java
│ │ │ └── UserRemoteServiceMock.java
│ │ └── resources
│ │ └── META-INF
│ │ └── spring.factories
├── kitty-cloud-user-biz
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── cxytiandi
│ │ └── kittycloud
│ │ └── user
│ │ └── biz
│ │ ├── bo
│ │ └── UserBO.java
│ │ ├── convert
│ │ └── UserBoConvert.java
│ │ ├── dao
│ │ ├── UserDao.java
│ │ └── impl
│ │ │ └── UserDaoImpl.java
│ │ ├── dataobject
│ │ └── UserDO.java
│ │ ├── enums
│ │ ├── SexEnum.java
│ │ └── UserStatusEnum.java
│ │ ├── mapper
│ │ └── UserMapper.java
│ │ └── service
│ │ ├── UserService.java
│ │ └── impl
│ │ └── UserServiceImpl.java
├── kitty-cloud-user-provider
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── cxytiandi
│ │ │ └── kittycloud
│ │ │ └── user
│ │ │ └── provider
│ │ │ ├── KittyCloudUserProviderApp.java
│ │ │ ├── convert
│ │ │ └── UserResponseConvert.java
│ │ │ └── service
│ │ │ └── UserRemoteServiceImpl.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── app.properties
│ │ ├── bootstrap.properties
│ │ └── logback.xml
└── pom.xml
├── pom.xml
└── script
└── table.sql
/.gitignore:
--------------------------------------------------------------------------------
1 | # maven ignore
2 | target/
3 | *.jar
4 | *.war
5 | *.zip
6 | *.tar
7 | *.tar.gz
8 |
9 | # eclipse ignore
10 | .settings/
11 | .project
12 | .classpath
13 |
14 | # idea ignore
15 | .idea/
16 | *.ipr
17 | *.iml
18 | *.iws
19 |
20 | # temp ignore
21 | *.log
22 | *.cache
23 | *.diff
24 | *.patch
25 | *.tmp
26 | *.java~
27 | *.properties~
28 | *.xml~
29 |
30 | # system ignore
31 | .DS_Store
32 | Thumbs.db
33 |
--------------------------------------------------------------------------------
/doc/images/2685774-17a60e1ead7fd232.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinjihuan/kitty-cloud/639424b9f5c41f5f02ebcf50bcac6c19fea2a05a/doc/images/2685774-17a60e1ead7fd232.png
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-article
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-article-api
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 | true
19 |
20 |
21 |
22 | com.spring4all
23 | swagger-spring-boot-starter
24 |
25 |
26 |
27 | com.cxytiandi
28 | kitty-spring-cloud-starter-feign
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-api/src/main/java/com/cxytiandi/kittycloud/article/api/autoconfigure/RemoteServiceAutoConfigure.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.api.autoconfigure;
2 |
3 | import org.springframework.cloud.openfeign.EnableFeignClients;
4 | import org.springframework.context.annotation.ComponentScan;
5 |
6 | /**
7 | * Feign Client自动初始化
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-13 20:44:04
15 | */
16 | @EnableFeignClients("com.cxytiandi.kittycloud.article.api")
17 | @ComponentScan("com.cxytiandi.kittycloud.article.api")
18 | public class RemoteServiceAutoConfigure {
19 |
20 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-api/src/main/java/com/cxytiandi/kittycloud/article/api/request/ArticleQueryRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.api.request;
2 |
3 | import com.cxytiandi.kittycloud.common.base.PageEntity;
4 | import lombok.Data;
5 |
6 | /**
7 | * 文章查询参数
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-28 14:10
15 | */
16 | @Data
17 | public class ArticleQueryRequest extends PageEntity {
18 |
19 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-api/src/main/java/com/cxytiandi/kittycloud/article/api/response/ArticleResponse.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.api.response;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 文章Response
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-12 20:01:04
16 | */
17 | @Data
18 | public class ArticleResponse {
19 |
20 | /**
21 | * 文章ID
22 | */
23 | private Long id;
24 |
25 | /**
26 | * 标题
27 | */
28 | private String title;
29 |
30 | /**
31 | * 类型
32 | */
33 | private int type;
34 |
35 | /**
36 | * 访问次数
37 | */
38 | private Long visitCount;
39 |
40 | /**
41 | * 用户ID
42 | */
43 | private Long userId;
44 |
45 | /**
46 | * 昵称
47 | */
48 | private String nickname;
49 |
50 | /**
51 | * 标签
52 | */
53 | private List tags;
54 |
55 | /**
56 | * 内容(包含HTML)
57 | */
58 | private String content;
59 |
60 | /**
61 | * 文本内容
62 | */
63 | private String textContent;
64 |
65 | /**
66 | * 热度值(点赞数+评论数+访问数)
67 | */
68 | private Integer heat;
69 |
70 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-api/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.cxytiandi.kittycloud.article.api.autoconfigure.RemoteServiceAutoConfigure
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/bo/ArticleBO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.bo;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.enums.ArticleStatusEnum;
4 | import com.cxytiandi.kittycloud.article.biz.enums.ArticleTypeEnum;
5 | import lombok.Data;
6 |
7 | /**
8 | * 文章BO
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-12 20:01:04
16 | */
17 | @Data
18 | public class ArticleBO {
19 |
20 | /**
21 | * 文章ID
22 | */
23 | private Long id;
24 |
25 | /**
26 | * 标题
27 | */
28 | private String title;
29 |
30 | /**
31 | * 类型
32 | */
33 | private ArticleTypeEnum type;
34 |
35 | /**
36 | * 访问次数
37 | */
38 | private Long visitCount;
39 |
40 | /**
41 | * 用户ID
42 | */
43 | private Long userId;
44 |
45 | /**
46 | * 昵称
47 | */
48 | private String nickname;
49 |
50 | /**
51 | * 标签(多个英文逗号分隔)
52 | */
53 | private String tags;
54 |
55 | /**
56 | * 内容(包含HTML)
57 | */
58 | private String content;
59 |
60 | /**
61 | * 文本内容
62 | */
63 | private String textContent;
64 |
65 | /**
66 | * 文章状态
67 | */
68 | private ArticleStatusEnum status;
69 |
70 | /**
71 | * 热度值(点赞数+评论数+访问数)
72 | */
73 | private Integer heat;
74 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/convert/ArticleBoConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.convert;
2 |
3 |
4 | import com.cxytiandi.kittycloud.article.biz.bo.ArticleBO;
5 | import com.cxytiandi.kittycloud.article.biz.dataobject.ArticleDO;
6 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
7 | import org.springframework.beans.BeanUtils;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * 文章BO转换器
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-12 20:01:04
19 | */
20 | @Component
21 | public class ArticleBoConvert implements EntityConvert {
22 |
23 | public ArticleBO convertPlus(ArticleDO source, String nickname) {
24 | ArticleBO target = new ArticleBO();
25 | BeanUtils.copyProperties(source, target);
26 | target.setNickname(nickname);
27 | return target;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/dao/ArticleDao.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.dao;
2 |
3 | import com.baomidou.mybatisplus.core.metadata.IPage;
4 | import com.cxytiandi.kittycloud.article.biz.dataobject.ArticleDO;
5 |
6 | /**
7 | * 文章DAO
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-12 20:01:04
15 | */
16 |
17 | public interface ArticleDao {
18 |
19 | /**
20 | * 获取文章
21 | * @param id 文章ID
22 | * @return
23 | */
24 | ArticleDO getById(Long id);
25 |
26 | /**
27 | * 热门文章
28 | * @param page 页数
29 | * @param pageSize 页大小
30 | * @return
31 | */
32 | IPage listHotArticles(int page, int pageSize);
33 |
34 | /**
35 | * 最新文章
36 | * @param page 页数
37 | * @param pageSize 页大小
38 | * @return
39 | */
40 | IPage listNewestArticles(int page, int pageSize);
41 |
42 | /**
43 | * 所有文章
44 | * @param page 页数
45 | * @param pageSize 页大小
46 | * @return
47 | */
48 | IPage listArticles(int page, int pageSize);
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/dao/impl/ArticleDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.dao.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.baomidou.mybatisplus.core.metadata.IPage;
5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 | import com.cxytiandi.kittycloud.article.biz.dao.ArticleDao;
7 | import com.cxytiandi.kittycloud.article.biz.dataobject.ArticleDO;
8 | import com.cxytiandi.kittycloud.article.biz.mapper.ArticleMapper;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Repository;
11 |
12 | /**
13 | * 文章DAO实现
14 | *
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-04-11 21:49
21 | */
22 | @Repository
23 | public class ArticleDaoImpl implements ArticleDao {
24 |
25 | @Autowired
26 | private ArticleMapper articleMapper;
27 |
28 | @Override
29 | public ArticleDO getById(Long id) {
30 | return articleMapper.selectById(id);
31 | }
32 |
33 | @Override
34 | public IPage listHotArticles(int page, int pageSize) {
35 | QueryWrapper queryWrapper = new QueryWrapper<>();
36 | queryWrapper.orderByDesc("heat");
37 |
38 | Page queryPage = new Page<>(page, pageSize);
39 | return articleMapper.selectPage(queryPage, queryWrapper);
40 | }
41 |
42 | @Override
43 | public IPage listNewestArticles(int page, int pageSize) {
44 | QueryWrapper queryWrapper = new QueryWrapper<>();
45 | queryWrapper.orderByDesc("add_time");
46 |
47 | Page queryPage = new Page<>(page, pageSize);
48 | return articleMapper.selectPage(queryPage, queryWrapper);
49 | }
50 |
51 | @Override
52 | public IPage listArticles(int page, int pageSize) {
53 | Page queryPage = new Page<>(page, pageSize);
54 | return articleMapper.selectPage(queryPage, null);
55 | }
56 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/dataobject/ArticleDO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.dataobject;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import com.cxytiandi.kittycloud.article.biz.enums.ArticleStatusEnum;
7 | import com.cxytiandi.kittycloud.article.biz.enums.ArticleTypeEnum;
8 | import com.cxytiandi.kittycloud.common.base.Entity;
9 | import lombok.Data;
10 |
11 | /**
12 | * 文章DO
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-12 20:01:04
20 | */
21 | @Data
22 | @TableName("article")
23 | public class ArticleDO extends Entity {
24 |
25 | /**
26 | * 文章ID
27 | */
28 | @TableId(type = IdType.ID_WORKER)
29 | private Long id;
30 |
31 | /**
32 | * 标题
33 | */
34 | private String title;
35 |
36 | /**
37 | * 类型
38 | */
39 | private ArticleTypeEnum type;
40 |
41 | /**
42 | * 访问次数
43 | */
44 | private Long visitCount;
45 |
46 | /**
47 | * 用户ID
48 | */
49 | private Long userId;
50 |
51 | /**
52 | * 标签(多个英文逗号分隔)
53 | */
54 | private String tags;
55 |
56 | /**
57 | * 内容(包含HTML)
58 | */
59 | private String content;
60 |
61 | /**
62 | * 文本内容
63 | */
64 | private String textContent;
65 |
66 | /**
67 | * 文章状态
68 | */
69 | private ArticleStatusEnum status;
70 |
71 | /**
72 | * 热度值(点赞数+评论数+访问数)
73 | */
74 | private Integer heat;
75 |
76 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/enums/ArticleStatusEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.enums;
2 |
3 | import com.baomidou.mybatisplus.annotation.EnumValue;
4 |
5 | /**
6 | * 文章状态枚举
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-12 20:01:04
14 | */
15 | public enum ArticleStatusEnum {
16 |
17 | /**
18 | * 无效
19 | */
20 | INVALID(0, "无效"),
21 | /**
22 | * 有效
23 | */
24 | VALID(1, "有效");
25 |
26 | ArticleStatusEnum(int status, String descp) {
27 | this.status = status;
28 | this.descp = descp;
29 | }
30 |
31 | /**
32 | * 状态
33 | */
34 | @EnumValue
35 | private int status;
36 |
37 | /**
38 | * 描述
39 | */
40 | private String descp;
41 |
42 | public int getStatus() {
43 | return status;
44 | }
45 |
46 | public String getDescp() {
47 | return descp;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/enums/ArticleTypeEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.enums;
2 |
3 | import com.baomidou.mybatisplus.annotation.EnumValue;
4 |
5 | /**
6 | * 文章类型枚举
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-12 20:01:04
14 | */
15 | public enum ArticleTypeEnum {
16 |
17 | /**
18 | * 原创
19 | */
20 | ORIGINAL(1, "原创"),
21 | /**
22 | * 转载
23 | */
24 | REPRINT(2, "转载"),
25 |
26 | /**
27 | * 翻译
28 | */
29 | TRANSLATE(3, "转载");
30 |
31 | ArticleTypeEnum(int type, String descp) {
32 | this.type = type;
33 | this.descp = descp;
34 | }
35 |
36 | /**
37 | * 类型
38 | */
39 | @EnumValue
40 | private int type;
41 |
42 | /**
43 | * 描述
44 | */
45 | private String descp;
46 |
47 | public int getType() {
48 | return type;
49 | }
50 |
51 | public String getDescp() {
52 | return descp;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/FilterProcessor.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Component;
5 |
6 | import java.util.List;
7 | import java.util.stream.Collectors;
8 |
9 | /**
10 | * 负责执行过滤器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-30 23:08
18 | */
19 | @Component
20 | public class FilterProcessor {
21 |
22 | @Autowired
23 | private List sensitiveWordFilters;
24 |
25 | public SensitiveWordFilterResult runSensitiveWordFilters(String content) {
26 | List filters = sensitiveWordFilters.stream().filter(f -> f.shouldFilter()).sorted(SensitiveWordFilter::compareTo).collect(Collectors.toList());
27 | for (SensitiveWordFilter filter : filters) {
28 | SensitiveWordFilterResult filterResult = filter.runFilter(content);
29 | if (filterResult != null && filterResult.isSuccess()) {
30 | return filterResult;
31 | }
32 | }
33 |
34 | SensitiveWordFilterResult result = new SensitiveWordFilterResult();
35 | result.setSuccess(false);
36 | return result;
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/ISensitiveWordFilter.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter;
2 |
3 | /**
4 | * 敏感词过滤器接口
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-30 22:55
12 | */
13 | public interface ISensitiveWordFilter {
14 |
15 | /**
16 | * 是否执行过滤器
17 | * @return
18 | */
19 | boolean shouldFilter();
20 |
21 | /**
22 | * 过滤逻辑
23 | * @param content 过滤内容
24 | * @return
25 | */
26 | SensitiveWordFilterResult run(String content);
27 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/SensitiveWordFilter.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter;
2 |
3 | /**
4 | * 敏感词过滤器抽象类
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-30 22:55
12 | */
13 | public abstract class SensitiveWordFilter implements ISensitiveWordFilter, Comparable {
14 |
15 | /**
16 | * 过滤器执行顺序,数字越小,越先执行
17 | * @return
18 | */
19 | abstract public int filterOrder();
20 |
21 | @Override
22 | public int compareTo(SensitiveWordFilter filter) {
23 | return Integer.compare(this.filterOrder(), filter.filterOrder());
24 | }
25 |
26 | public SensitiveWordFilterResult runFilter(String content) {
27 | return run(content);
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/SensitiveWordFilterResult.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * 敏感词过滤结果
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-03-30 23:02
14 | */
15 | @Data
16 | public class SensitiveWordFilterResult {
17 |
18 | /**
19 | * 是否命中敏感词
20 | */
21 | private boolean success;
22 |
23 | /**
24 | * 提示信息
25 | */
26 | private String message;
27 |
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/impl/ChineseSensitiveWordFilter.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter.impl;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.filter.SensitiveWordFilter;
4 | import com.cxytiandi.kittycloud.article.biz.filter.SensitiveWordFilterResult;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.util.List;
9 | import java.util.Optional;
10 |
11 | /**
12 | * 中文敏感词过滤器
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-03-30 23:07
20 | */
21 | @Component
22 | public class ChineseSensitiveWordFilter extends SensitiveWordFilter {
23 |
24 | /**
25 | * 敏感词可以维护在数据中或者配置中心里面
26 | */
27 | @Value("${kitty.cloud.article.chineseSensitiveWords:逗比,小可爱}")
28 | private List sensitiveWords;
29 |
30 | @Override
31 | public int filterOrder() {
32 | return 1;
33 | }
34 |
35 | @Override
36 | public boolean shouldFilter() {
37 | return true;
38 | }
39 |
40 | @Override
41 | public SensitiveWordFilterResult run(String content) {
42 | SensitiveWordFilterResult result = new SensitiveWordFilterResult();
43 | Optional sensitiveWordOptional = sensitiveWords.stream().filter(s -> content.contains(s)).findFirst();
44 | if (!sensitiveWordOptional.isPresent()) {
45 | result.setSuccess(false);
46 | return result;
47 | }
48 |
49 | result.setSuccess(true);
50 | result.setMessage(sensitiveWordOptional.get() + "命中敏感词");
51 | return result;
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/filter/impl/EnglishSensitiveWordFilter.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.filter.impl;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.filter.SensitiveWordFilter;
4 | import com.cxytiandi.kittycloud.article.biz.filter.SensitiveWordFilterResult;
5 | import org.springframework.stereotype.Component;
6 |
7 | /**
8 | * 英文敏感词过滤器
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-30 23:07
16 | */
17 | @Component
18 | public class EnglishSensitiveWordFilter extends SensitiveWordFilter {
19 |
20 | @Override
21 | public int filterOrder() {
22 | return 0;
23 | }
24 |
25 | @Override
26 | public boolean shouldFilter() {
27 | return true;
28 | }
29 |
30 | @Override
31 | public SensitiveWordFilterResult run(String content) {
32 | return null;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/manager/DistributedIdManager.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.manager;
2 |
3 | /**
4 | * 分布式ID Manager接口
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-12 20:01:04
12 | */
13 | public interface DistributedIdManager {
14 |
15 | /**
16 | * 获取分布式ID
17 | * @return
18 | */
19 | String getDistributedId();
20 |
21 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/manager/UserManager.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.manager;
2 |
3 | /**
4 | * 用户Manager接口
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-12 20:01:04
12 | */
13 | public interface UserManager {
14 |
15 | /**
16 | * 获取用户昵称
17 | * @param userId 用户ID
18 | * @return
19 | */
20 | String getNickname(Long userId);
21 |
22 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/manager/impl/DistributedIdManagerImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.manager.impl;
2 |
3 | import com.cxytiandi.kitty.id.service.DistributedIdLeafSnowflakeRemoteService;
4 | import com.cxytiandi.kittycloud.article.biz.manager.DistributedIdManager;
5 | import com.cxytiandi.kittycloud.common.constant.DubboConstant;
6 | import org.apache.dubbo.config.annotation.Reference;
7 | import org.springframework.beans.factory.annotation.Value;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * 分布式ID Manager接口实现
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-12 20:01:04
19 | */
20 | @Component
21 | public class DistributedIdManagerImpl implements DistributedIdManager {
22 |
23 | @Value("${spring.application.name}")
24 | private String applicationName;
25 |
26 | @Reference(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, check = false)
27 | private DistributedIdLeafSnowflakeRemoteService distributedIdLeafSnowflakeRemoteService;
28 |
29 | @Override
30 | public String getDistributedId() {
31 | String snowflakeId = distributedIdLeafSnowflakeRemoteService.getSnowflakeId(applicationName);
32 | return snowflakeId;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/manager/impl/UserManagerImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.manager.impl;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.manager.UserManager;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import com.cxytiandi.kittycloud.common.constant.DubboConstant;
6 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
7 | import com.cxytiandi.kittycloud.user.api.service.UserRemoteService;
8 | import org.apache.dubbo.config.annotation.Reference;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.beans.factory.annotation.Value;
11 | import org.springframework.stereotype.Component;
12 |
13 | /**
14 | * 用户Manager实现
15 | *
16 | * @作者 尹吉欢
17 | * @个人微信 jihuan900
18 | * @微信公众号 猿天地
19 | * @GitHub https://github.com/yinjihuan
20 | * @作者介绍 http://cxytiandi.com/about
21 | * @时间 2020-02-12 20:01:04
22 | */
23 | @Component
24 | public class UserManagerImpl implements UserManager {
25 |
26 | @Value("${spring.application.name}")
27 | private String applicationName;
28 |
29 | // @Reference dubbo调用, @Autowired Feign调用
30 | @Autowired
31 | // @Reference(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, check = false)
32 | private UserRemoteService userRemoteService;
33 |
34 | //@Cached(name = "UserManagerImpl:getNickname:", key = "#userId", expire = 1, timeUnit = TimeUnit.DAYS)
35 | @Override
36 | public String getNickname(Long userId) {
37 | ResponseData user = userRemoteService.getUser(userId);
38 | return user.isSuccess() ? user.getData().getNickname() : "";
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/mapper/ArticleMapper.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.cxytiandi.kittycloud.article.biz.dataobject.ArticleDO;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * 文章Mapper
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-04-11 21:48
16 | */
17 | @Mapper
18 | public interface ArticleMapper extends BaseMapper {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-biz/src/main/java/com/cxytiandi/kittycloud/article/biz/service/ArticleService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.biz.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.article.biz.bo.ArticleBO;
5 | import com.cxytiandi.kittycloud.common.base.ResponseData;
6 |
7 | /**
8 | * 文章业务接口
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-12 20:01:04
16 | */
17 | public interface ArticleService {
18 |
19 | /**
20 | * 文章信息
21 | * @param articleId 文章ID
22 | * @return
23 | */
24 | ArticleBO getArticle(Long articleId);
25 |
26 | /**
27 | * 热门文章
28 | * @param page 页数
29 | * @param pageSize 页大小
30 | * @return
31 | */
32 | Page listHotArticles(int page, int pageSize);
33 |
34 | /**
35 | * 最新文章
36 | * @param page 页数
37 | * @param pageSize 页大小
38 | * @return
39 | */
40 | Page listNewestArticles(int page, int pageSize);
41 |
42 | /**
43 | * 所有文章
44 | * @param page 页数
45 | * @param pageSize 页大小
46 | * @return
47 | */
48 | Page listArticles(int page, int pageSize);
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-article
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-article-provider
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-cloud-article-api
18 | 1.0-SNAPSHOT
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-article-biz
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 | com.cxytiandi
35 | kitty-spring-cloud-starter-redis
36 | 1.0-SNAPSHOT
37 |
38 |
39 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/main/java/com/cxytiandi/kittycloud/article/provider/KittyCloudArticleProviderApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.provider;
2 |
3 | import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
4 | import com.alicp.jetcache.anno.config.EnableMethodCache;
5 | import com.spring4all.swagger.EnableSwagger2Doc;
6 | import org.mybatis.spring.annotation.MapperScan;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10 |
11 | /**
12 | * 文章服务启动类
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-12 20:01:04
20 | */
21 | @EnableSwagger2Doc
22 | @MapperScan("com.cxytiandi.kittycloud.article.biz.mapper")
23 | @EnableDiscoveryClient
24 | @EnableCreateCacheAnnotation
25 | @EnableMethodCache(basePackages = "com.cxytiandi.kittycloud.article.biz.manager")
26 | @SpringBootApplication(scanBasePackages = {"com.cxytiandi.kittycloud.article","com.cxytiandi.kitty.web.config"})
27 | public class KittyCloudArticleProviderApp {
28 | public static void main(String[] args) {
29 | SpringApplication.run(KittyCloudArticleProviderApp.class);
30 | }
31 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/main/java/com/cxytiandi/kittycloud/article/provider/convert/ArticleResponseConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.article.api.response.ArticleResponse;
4 | import com.cxytiandi.kittycloud.article.biz.bo.ArticleBO;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | import java.util.Arrays;
10 |
11 | /**
12 | * 文章Response转换器
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-12 20:01:04
20 | */
21 | @Component
22 | public class ArticleResponseConvert implements EntityConvert {
23 |
24 | @Override
25 | public ArticleResponse convert(ArticleBO source) {
26 | ArticleResponse target = new ArticleResponse();
27 | BeanUtils.copyProperties(source, target);
28 | target.setTags(Arrays.asList(source.getTags().split(",")));
29 | return target;
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-article-provider
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-article-provider
2 |
3 | dubbo.scan.base-packages=com.cxytiandi.kittycloud.article.provider.service
4 | dubbo.protocol.name=dubbo
5 | dubbo.protocol.port=20081
6 | dubbo.registry.address=spring-cloud://localhost
7 |
8 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
9 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
10 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
11 |
12 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-mysql.properties
13 | spring.cloud.nacos.config.ext-config[0].group=MIDDLEWARE_GROUP
14 | spring.cloud.nacos.config.ext-config[0].refresh=true
15 |
16 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-article-provider-application.properties
17 | spring.cloud.nacos.config.ext-config[1].group=APPLICATION_GROUP
18 | spring.cloud.nacos.config.ext-config[1].refresh=true
19 |
20 | spring.cloud.nacos.config.ext-config[2].data-id=kitty-cloud-redis-jetcache.properties
21 | spring.cloud.nacos.config.ext-config[2].group=MIDDLEWARE_GROUP
22 | spring.cloud.nacos.config.ext-config[2].refresh=true
23 |
24 | spring.cloud.nacos.config.ext-config[3].data-id=kitty-cloud-sentinel.properties
25 | spring.cloud.nacos.config.ext-config[3].group=MIDDLEWARE_GROUP
26 | spring.cloud.nacos.config.ext-config[3].refresh=true
27 |
28 | spring.cloud.nacos.config.ext-config[4].data-id=kitty-cloud-redis-redisson.properties
29 | spring.cloud.nacos.config.ext-config[4].group=MIDDLEWARE_GROUP
30 | spring.cloud.nacos.config.ext-config[4].refresh=true
31 |
32 | spring.cloud.nacos.config.ext-config[5].data-id=kitty-cloud-thread-pool.properties
33 | spring.cloud.nacos.config.ext-config[5].group=BIZ_GROUP
34 | spring.cloud.nacos.config.ext-config[5].refresh=true
35 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ${FILE_LOG_PATTERN}
15 |
16 |
17 |
18 | ${LOG_HOME_PATH}/${APP_NAME}-debug.%d{yyyy-MM-dd}.log
19 | 60
20 |
21 |
22 |
23 | DEBUG
24 | ACCEPT
25 | DENY
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/test/java/com/cxytiandi/kittycloud/article/provider/ArticleServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.provider;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.filter.FilterProcessor;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 |
10 | /**
11 | * 文章Service测试
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-03-31 21:34
19 | */
20 | @RunWith(SpringRunner.class)
21 | @SpringBootTest
22 | public class ArticleServiceTest {
23 |
24 | @Autowired
25 | private FilterProcessor filterProcessor;
26 |
27 | @Test
28 | public void testSensitiveWordFilters() {
29 | filterProcessor.runSensitiveWordFilters("你是一个逗比吗?");
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/kitty-cloud-article-provider/src/test/java/com/cxytiandi/kittycloud/article/provider/DistributedIdManagerTest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.article.provider;
2 |
3 | import com.cxytiandi.kittycloud.article.biz.manager.DistributedIdManager;
4 | import com.cxytiandi.kittycloud.article.biz.manager.UserManager;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | /**
13 | * 分布式ID测试
14 | *
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-04-06 17:40
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | public class DistributedIdManagerTest {
25 |
26 | @Autowired
27 | private DistributedIdManager distributedIdManager;
28 |
29 | @Test
30 | public void testGetDistributedId() {
31 | String distributedId = distributedIdManager.getDistributedId();
32 | Assert.assertNotNull(distributedId);
33 | }
34 | }
--------------------------------------------------------------------------------
/kitty-cloud-article/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-article
13 | pom
14 |
15 | kitty-cloud-article-api
16 | kitty-cloud-article-biz
17 | kitty-cloud-article-provider
18 |
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-common
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-comment
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-comment-api
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 | true
19 |
20 |
21 |
22 | com.spring4all
23 | swagger-spring-boot-starter
24 |
25 |
26 |
27 | com.cxytiandi
28 | kitty-spring-cloud-starter-feign
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/fallback/CommentReplyRemoteServiceFallbackFactory.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.fallback;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
4 | import com.cxytiandi.kittycloud.comment.api.service.CommentReplyRemoteService;
5 | import com.cxytiandi.kittycloud.common.base.Response;
6 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
7 | import com.cxytiandi.kittycloud.common.base.ResponseData;
8 | import feign.hystrix.FallbackFactory;
9 | import lombok.extern.slf4j.Slf4j;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.text.MessageFormat;
13 |
14 | /**
15 | * Feign CommentReplyRemoteService回退逻辑
16 | *
17 | * @作者 尹吉欢
18 | * @个人微信 jihuan900
19 | * @微信公众号 猿天地
20 | * @GitHub https://github.com/yinjihuan
21 | * @作者介绍 http://cxytiandi.com/about
22 | * @时间 2020-03-05 21:26
23 | */
24 | @Slf4j
25 | @Component
26 | public class CommentReplyRemoteServiceFallbackFactory implements FallbackFactory {
27 |
28 | @Override
29 | public CommentReplyRemoteService create(Throwable cause) {
30 | return new CommentReplyRemoteService() {
31 | @Override
32 | public ResponseData saveCommentReply(CommentReplySaveRequest request) {
33 | log.error(MessageFormat.format("CommentReplyRemoteService.saveCommentReply fallback,参数为 [{0}]", request), cause);
34 | return Response.fail(cause.getMessage(), ResponseCode.SERVER_DOWNGRADE_CODE);
35 | }
36 |
37 | @Override
38 | public ResponseData removeCommentReply(String id) {
39 | log.error(MessageFormat.format("CommentReplyRemoteService.removeCommentReply fallback,参数为 [{0}]", id), cause);
40 | return Response.fail(cause.getMessage(), ResponseCode.SERVER_DOWNGRADE_CODE);
41 | }
42 | };
43 | }
44 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/request/CommentQueryRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.request;
2 |
3 | import lombok.*;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-16 15:08
14 | */
15 | @Data
16 | @Builder
17 | @ToString
18 | @NoArgsConstructor
19 | @AllArgsConstructor
20 | public class CommentQueryRequest implements Serializable {
21 |
22 | /**
23 | * 评论业务类型
24 | */
25 | private int commentBizType;
26 |
27 | /**
28 | * 评论业务ID
29 | */
30 | private String commentBizId;
31 |
32 | /**
33 | * 页数
34 | */
35 | private int page;
36 |
37 | /**
38 | * 页大小
39 | */
40 | private int pageSize;
41 |
42 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/request/CommentReplySaveRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.request;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 | import lombok.ToString;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * 评论回复Request
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-13 20:44:04
18 | */
19 | @Data
20 | @Builder
21 | @ToString
22 | public class CommentReplySaveRequest implements Serializable {
23 |
24 | /**
25 | * 评论ID
26 | */
27 | private String commentId;
28 |
29 | /**
30 | * 回复内容
31 | */
32 | private String content;
33 |
34 | /**
35 | * 用户ID
36 | */
37 | private Long userId;
38 |
39 | /**
40 | * 回复引用的用户ID
41 | */
42 | private Long replayRefUserId;
43 |
44 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/request/CommentSaveRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.request;
2 |
3 | import lombok.*;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * 评论Request
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Data
18 | @Builder
19 | @ToString
20 | @AllArgsConstructor
21 | @NoArgsConstructor
22 | public class CommentSaveRequest implements Serializable {
23 |
24 | /**
25 | * 评论内容
26 | */
27 | private String content;
28 |
29 | /**
30 | * 评论业务类型
31 | */
32 | private int commentBizType;
33 |
34 | /**
35 | * 评论业务ID
36 | */
37 | private String commentBizId;
38 |
39 | /**
40 | * 评论业务的用户ID
41 | */
42 | private Long commentBizUserId;
43 |
44 | /**
45 | * 用户ID
46 | */
47 | private Long userId;
48 |
49 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/response/CommentReplyResponse.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.response;
2 |
3 |
4 | /**
5 | * 评论回复Response
6 | *
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-02-13 20:44:04
13 | */
14 | public class CommentReplyResponse {
15 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/response/CommentResponse.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.response;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.Date;
7 |
8 |
9 | /**
10 | * 评论Response
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-13 20:44:04
18 | */
19 | @Data
20 | public class CommentResponse implements Serializable {
21 |
22 | /**
23 | * ID
24 | */
25 | private String id;
26 |
27 | /**
28 | * 评论内容
29 | */
30 | private String content;
31 |
32 | /**
33 | * 评论业务用户ID
34 | */
35 | private Long commentBizUserId;
36 |
37 | /**
38 | * 用户ID
39 | */
40 | private Long userId;
41 |
42 | /**
43 | * 用户昵称
44 | */
45 | private String nickname;
46 |
47 | /**
48 | * 添加时间
49 | */
50 | private Date addTime;
51 |
52 | /**
53 | * 回复数量
54 | */
55 | private int replyCount;
56 |
57 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/service/CommentRemoteService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.comment.api.fallback.CommentRemoteServiceFallbackFactory;
5 | import com.cxytiandi.kittycloud.comment.api.request.CommentQueryRequest;
6 | import com.cxytiandi.kittycloud.comment.api.request.CommentSaveRequest;
7 | import com.cxytiandi.kittycloud.comment.api.response.CommentResponse;
8 | import com.cxytiandi.kittycloud.common.base.ResponseData;
9 | import org.springframework.cloud.openfeign.FeignClient;
10 | import org.springframework.web.bind.annotation.*;
11 |
12 |
13 | /**
14 | * 评论RPC/REST接口
15 | *
16 | * @作者 尹吉欢
17 | * @个人微信 jihuan900
18 | * @微信公众号 猿天地
19 | * @GitHub https://github.com/yinjihuan
20 | * @作者介绍 http://cxytiandi.com/about
21 | * @时间 2020-02-13 20:44:04
22 | */
23 | @FeignClient(name = "kitty-cloud-comment-provider", contextId = "CommentRemoteService", fallbackFactory = CommentRemoteServiceFallbackFactory.class)
24 | public interface CommentRemoteService {
25 |
26 | /**
27 | * 保存评论
28 | * @param request 评论参数
29 | * @return 评论ID
30 | */
31 | @PostMapping("/comments")
32 | ResponseData saveComment(@RequestBody CommentSaveRequest request);
33 |
34 | /**
35 | * 删除评论
36 | * @param id 评论ID
37 | * @return 是否删除成功
38 | */
39 | @DeleteMapping("/comments/{id}")
40 | ResponseData removeComment(@PathVariable String id);
41 |
42 | /**
43 | * 分页查询评论
44 | * @param request
45 | * @return
46 | */
47 | @GetMapping("/comments")
48 | ResponseData> listComments(CommentQueryRequest request);
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/service/CommentRemoteServiceMock.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.comment.api.request.CommentQueryRequest;
5 | import com.cxytiandi.kittycloud.comment.api.request.CommentSaveRequest;
6 | import com.cxytiandi.kittycloud.comment.api.response.CommentResponse;
7 | import com.cxytiandi.kittycloud.common.base.Response;
8 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
9 | import com.cxytiandi.kittycloud.common.base.ResponseData;
10 | import lombok.extern.slf4j.Slf4j;
11 |
12 | import java.text.MessageFormat;
13 |
14 | /**
15 | * Dubbo CommentRemoteService回退逻辑
16 | *
17 | * @作者 尹吉欢
18 | * @个人微信 jihuan900
19 | * @微信公众号 猿天地
20 | * @GitHub https://github.com/yinjihuan
21 | * @作者介绍 http://cxytiandi.com/about
22 | * @时间 2020-03-05 21:46
23 | */
24 | @Slf4j
25 | public class CommentRemoteServiceMock implements CommentRemoteService {
26 |
27 | @Override
28 | public ResponseData saveComment(CommentSaveRequest request) {
29 | log.error(MessageFormat.format("CommentRemoteService.saveComment fallback,参数为 [{0}]", request));
30 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
31 | }
32 |
33 | @Override
34 | public ResponseData removeComment(String id) {
35 | log.error(MessageFormat.format("CommentRemoteService.removeComment fallback,参数为 [{0}]", id));
36 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
37 | }
38 |
39 | @Override
40 | public ResponseData> listComments(CommentQueryRequest request) {
41 | log.error(MessageFormat.format("CommentRemoteService.listComments fallback,参数为 [{0}]", request));
42 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
43 | }
44 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/service/CommentReplyRemoteService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.service;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.fallback.CommentReplyRemoteServiceFallbackFactory;
4 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
5 | import com.cxytiandi.kittycloud.common.base.ResponseData;
6 | import org.springframework.cloud.openfeign.FeignClient;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 |
10 | /**
11 | * 评论回复RPC/REST接口
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-13 20:44:04
19 | */
20 | @FeignClient(name = "kitty-cloud-comment-provider", contextId = "CommentReplyRemoteService", fallbackFactory = CommentReplyRemoteServiceFallbackFactory.class)
21 | public interface CommentReplyRemoteService {
22 |
23 | /**
24 | * 保存回复
25 | * @param request 回复参数
26 | * @return 评论ID
27 | */
28 | @PostMapping("/replys")
29 | ResponseData saveCommentReply(@RequestBody CommentReplySaveRequest request);
30 |
31 | /**
32 | * 删除回复
33 | * @param id 回复ID
34 | * @return 是否删除成功
35 | */
36 | @DeleteMapping("/replys/{id}")
37 | ResponseData removeCommentReply(@PathVariable String id);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-api/src/main/java/com/cxytiandi/kittycloud/comment/api/service/CommentReplyRemoteServiceMock.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.api.service;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
4 | import com.cxytiandi.kittycloud.common.base.Response;
5 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
6 | import com.cxytiandi.kittycloud.common.base.ResponseData;
7 | import lombok.extern.slf4j.Slf4j;
8 |
9 | import java.text.MessageFormat;
10 |
11 | /**
12 | * Dubbo CommentReplyRemoteService回退逻辑
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-03-05 21:53
20 | */
21 | @Slf4j
22 | public class CommentReplyRemoteServiceMock implements CommentReplyRemoteService {
23 |
24 | @Override
25 | public ResponseData saveCommentReply(CommentReplySaveRequest request) {
26 | log.error(MessageFormat.format("CommentReplyRemoteService.saveCommentReply fallback,参数为 [{0}]", request));
27 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
28 | }
29 |
30 | @Override
31 | public ResponseData removeCommentReply(String id) {
32 | log.error(MessageFormat.format("CommentReplyRemoteService.removeCommentReply fallback,参数为 [{0}]", id));
33 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
34 | }
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/bo/CommentBO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.bo;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 | /**
7 | * 评论BO
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-16 15:12
15 | */
16 | @Data
17 | public class CommentBO {
18 |
19 | /**
20 | * ID
21 | */
22 | private String id;
23 |
24 | /**
25 | * 评论内容
26 | */
27 | private String content;
28 |
29 | /**
30 | * 评论业务用户ID
31 | */
32 | private Long commentBizUserId;
33 |
34 | /**
35 | * 用户ID
36 | */
37 | private Long userId;
38 |
39 | /**
40 | * 用户昵称
41 | */
42 | private String nickname;
43 |
44 | /**
45 | * 添加时间
46 | */
47 | private Date addTime;
48 |
49 | /**
50 | * 回复数量
51 | */
52 | private int replyCount;
53 |
54 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/convert/CommentBOConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.bo.CommentBO;
4 | import com.cxytiandi.kittycloud.comment.biz.document.CommentDocument;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 评论BO转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-16 15:24
18 | */
19 | @Component
20 | public class CommentBOConvert implements EntityConvert {
21 |
22 | public CommentBO convertPlus(CommentDocument source, String nickname, int replyCount) {
23 | CommentBO commentBO = new CommentBO();
24 | BeanUtils.copyProperties(source, commentBO);
25 | commentBO.setNickname(nickname);
26 | commentBO.setReplyCount(replyCount);
27 | return commentBO;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/convert/CommentDocumentConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.document.CommentDocument;
4 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 评论Document转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-13 21:54
18 | */
19 | @Component
20 | public class CommentDocumentConvert implements EntityConvert {
21 |
22 | @Override
23 | public CommentDocument convert(CommentSaveParam source) {
24 | CommentDocument commentDocument = new CommentDocument();
25 | BeanUtils.copyProperties(source, commentDocument);
26 | return commentDocument;
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/convert/CommentReplyDocumentConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.document.CommentDocument;
4 | import com.cxytiandi.kittycloud.comment.biz.document.CommentReplyDocument;
5 | import com.cxytiandi.kittycloud.comment.biz.param.CommentReplySaveParam;
6 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
7 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
8 | import org.springframework.beans.BeanUtils;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * 评论回复Document转换器
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-13 21:54
20 | */
21 | @Component
22 | public class CommentReplyDocumentConvert implements EntityConvert {
23 |
24 | @Override
25 | public CommentReplyDocument convert(CommentReplySaveParam source) {
26 | CommentReplyDocument replyDocument = new CommentReplyDocument();
27 | BeanUtils.copyProperties(source, replyDocument);
28 | return replyDocument;
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/dao/CommentDao.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.dao;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.document.CommentDocument;
4 | import com.cxytiandi.kittycloud.comment.biz.document.CommentReplyDocument;
5 | import com.cxytiandi.kittycloud.comment.biz.param.CommentQueryParam;
6 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 评论DAO
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-13 20:44:04
19 | */
20 | public interface CommentDao {
21 |
22 | /**
23 | * 保存评论
24 | * @param commentDocument 评论参数
25 | * @return 评论ID
26 | */
27 | String saveComment(CommentDocument commentDocument);
28 |
29 | /**
30 | * 删除评论(包括回复)
31 | * @param id
32 | * @return
33 | */
34 | boolean removeComment(String id);
35 |
36 | /**
37 | * 保存评论回复
38 | * @param commentId 评论ID
39 | * @param commentReplyDocument 回复参数
40 | * @return 回复ID
41 | */
42 | String saveCommentReply(String commentId, CommentReplyDocument commentReplyDocument);
43 |
44 | /**
45 | * 获取评论
46 | * @param id 评论ID
47 | * @return
48 | */
49 | CommentDocument getComment(String id);
50 |
51 | /**
52 | * 删除评论回复
53 | * @param replyId 回复ID
54 | * @return
55 | */
56 | boolean removeCommentReply(String replyId);
57 |
58 | /**
59 | * 查询评论的数量
60 | * @param param
61 | * @return
62 | */
63 | long countComment(CommentQueryParam param);
64 |
65 | /**
66 | * 查询评论信息
67 | * @param param
68 | * @return
69 | */
70 | List listComments(CommentQueryParam param);
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/document/CommentDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.document;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.enums.CommentBizTypeEnum;
4 | import lombok.Data;
5 | import org.springframework.data.annotation.Id;
6 | import org.springframework.data.mongodb.core.mapping.Document;
7 |
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | /**
12 | * 评论Document
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-13 20:44:04
20 | */
21 | @Data
22 | @Document(collection = "comment")
23 | public class CommentDocument {
24 |
25 | /**
26 | * ID
27 | */
28 | @Id
29 | private String id;
30 |
31 | /**
32 | * 评论内容
33 | */
34 | private String content;
35 |
36 | /**
37 | * 评论业务类型
38 | * @see CommentBizTypeEnum
39 | */
40 | private int commentBizType;
41 |
42 | /**
43 | * 评论业务ID
44 | */
45 | private String commentBizId;
46 |
47 | /**
48 | * 评论业务用户ID
49 | */
50 | private Long commentBizUserId;
51 |
52 | /**
53 | * 用户ID
54 | */
55 | private Long userId;
56 |
57 | /**
58 | * 评论的回复
59 | */
60 | private List replys;
61 |
62 | /**
63 | * 添加时间
64 | */
65 | private Date addTime;
66 |
67 | /**
68 | * 更新时间
69 | */
70 | private Date updateTime;
71 |
72 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/document/CommentReplyDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.document;
2 |
3 | import lombok.Data;
4 | import org.springframework.data.annotation.Id;
5 | import java.util.Date;
6 |
7 | /**
8 | * 评论回复Document
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Data
18 | public class CommentReplyDocument {
19 |
20 | /**
21 | * ID
22 | */
23 | @Id
24 | private String id;
25 |
26 | /**
27 | * 回复内容
28 | */
29 | private String content;
30 |
31 | /**
32 | * 用户ID
33 | */
34 | private Long userId;
35 |
36 | /**
37 | * 回复引用的用户ID
38 | */
39 | private Long replayRefUserId;
40 |
41 | /**
42 | * 添加时间
43 | */
44 | private Date addTime;
45 |
46 | /**
47 | * 更新时间
48 | */
49 | private Date updateTime;
50 |
51 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/enums/CommentBizTypeEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.enums;
2 |
3 |
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 | import com.cxytiandi.kittycloud.common.exception.BizException;
6 |
7 | /**
8 | * 评论业务类型枚举
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-12 20:01:04
16 | */
17 | public enum CommentBizTypeEnum {
18 |
19 | /**
20 | * 文章
21 | */
22 | ARTICLE(0, "文章"),
23 | /**
24 | * 问题
25 | */
26 | QUESTION(1, "问题");
27 |
28 | CommentBizTypeEnum(int type, String descp) {
29 | this.type = type;
30 | this.descp = descp;
31 | }
32 |
33 | /**
34 | * 类型
35 | */
36 | private int type;
37 |
38 | /**
39 | * 描述
40 | */
41 | private String descp;
42 |
43 | public int getType() {
44 | return type;
45 | }
46 |
47 | public String getDescp() {
48 | return descp;
49 | }
50 |
51 | public static CommentBizTypeEnum fromType(int type) {
52 | for (CommentBizTypeEnum commentBizTypeEnum : CommentBizTypeEnum.values()) {
53 | if (commentBizTypeEnum.getType() == type) {
54 | return commentBizTypeEnum;
55 | }
56 | }
57 | return null;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/manager/UserManager.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.manager;
2 |
3 | /**
4 | * 用户Manager接口
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-16 16:02
12 | */
13 | public interface UserManager {
14 |
15 | /**
16 | * 获取用户昵称
17 | * @param userId 用户ID
18 | * @return
19 | */
20 | String getNickname(Long userId);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/manager/fallback/dubbo/CustomUserRemoteServiceMock.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.manager.fallback.dubbo;
2 |
3 | import com.cxytiandi.kittycloud.common.base.Response;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import com.cxytiandi.kittycloud.user.api.request.UserLoginRequest;
6 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
7 | import com.cxytiandi.kittycloud.user.api.service.UserRemoteService;
8 | import lombok.extern.slf4j.Slf4j;
9 |
10 | import java.text.MessageFormat;
11 |
12 | /**
13 | * 自定义Dubbo UserRemoteService回退逻辑,可以替换服务提供方的默认实现
14 | *
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-02-27 22:11
21 | */
22 | @Slf4j
23 | public class CustomUserRemoteServiceMock implements UserRemoteService {
24 |
25 | @Override
26 | public ResponseData getUser(Long userId) {
27 | log.error(MessageFormat.format("UserRemoteService.getUser fallback,参数为 [{0}]", userId));
28 | UserResponse userResponse = new UserResponse();
29 | userResponse.setNickname("尹吉欢");
30 | return Response.ok(userResponse);
31 | }
32 |
33 | @Override
34 | public ResponseData login(UserLoginRequest loginRequest) {
35 | return null;
36 | }
37 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/manager/impl/UserManagerImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.manager.impl;
2 |
3 | import com.cxytiandi.kittycloud.comment.biz.manager.UserManager;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import com.cxytiandi.kittycloud.common.constant.DubboConstant;
6 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
7 | import com.cxytiandi.kittycloud.user.api.service.UserRemoteService;
8 | import org.apache.dubbo.config.annotation.Reference;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * 用户Manager接口实现
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-16 16:04
20 | */
21 | @Component
22 | public class UserManagerImpl implements UserManager {
23 |
24 | // @Reference dubbo调用, @Autowired Feign调用
25 | //@Autowired
26 | // mock = DubboConstant.MOCK 开启Dubbo默认回退
27 | @Reference(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, check = false, mock = "com.cxytiandi.kittycloud.comment.biz.manager.fallback.dubbo.CustomUserRemoteServiceMock")
28 | private UserRemoteService userRemoteService;
29 |
30 | //@Cached(name = "UserManagerImpl:getNickname:", key = "#userId", expire = 1, timeUnit = TimeUnit.DAYS)
31 | @Override
32 | public String getNickname(Long userId) {
33 | ResponseData user = userRemoteService.getUser(userId);
34 | return user.isSuccess() ? user.getData().getNickname() : "";
35 | }
36 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/param/CommentQueryParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.param;
2 |
3 | import com.github.structlog4j.IToLog;
4 | import lombok.Data;
5 |
6 | /**
7 | * 评论查询参数
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-16 15:12
15 | */
16 | @Data
17 | public class CommentQueryParam implements IToLog {
18 |
19 | /**
20 | * 评论业务类型
21 | */
22 | private int commentBizType;
23 |
24 | /**
25 | * 评论业务ID
26 | */
27 | private String commentBizId;
28 |
29 | /**
30 | * 页数
31 | */
32 | private int page;
33 |
34 | /**
35 | * 页大小
36 | */
37 | private int pageSize;
38 |
39 | @Override
40 | public Object[] toLog() {
41 | return new Object[] {
42 | "commentBizType", commentBizType,
43 | "commentBizId", commentBizId,
44 | "page", page,
45 | "pageSize", pageSize
46 | };
47 | }
48 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/param/CommentReplySaveParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.param;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * 评论回复报错参数
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-13 20:44:04
14 | */
15 | @Data
16 | public class CommentReplySaveParam {
17 |
18 | /**
19 | * 评论ID
20 | */
21 | private String commentId;
22 |
23 | /**
24 | * 回复内容
25 | */
26 | private String content;
27 |
28 | /**
29 | * 用户ID
30 | */
31 | private Long userId;
32 |
33 | /**
34 | * 回复引用的用户ID
35 | */
36 | private Long replayRefUserId;
37 |
38 |
39 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/param/CommentSaveParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.param;
2 |
3 | import lombok.Data;
4 |
5 |
6 | /**
7 | * 评论保存参数
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-13 20:44:04
15 | */
16 | @Data
17 | public class CommentSaveParam {
18 |
19 | /**
20 | * 评论内容
21 | */
22 | private String content;
23 |
24 | /**
25 | * 评论业务类型
26 | */
27 | private int commentBizType;
28 |
29 | /**
30 | * 评论业务ID
31 | */
32 | private String commentBizId;
33 |
34 | /**
35 | * 评论业务的用户ID
36 | */
37 | private Long commentBizUserId;
38 |
39 | /**
40 | * 用户ID
41 | */
42 | private Long userId;
43 |
44 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-biz/src/main/java/com/cxytiandi/kittycloud/comment/biz/service/CommentService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.biz.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.comment.biz.bo.CommentBO;
5 | import com.cxytiandi.kittycloud.comment.biz.param.CommentQueryParam;
6 | import com.cxytiandi.kittycloud.comment.biz.param.CommentReplySaveParam;
7 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
8 |
9 | /**
10 | * 评论业务接口
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-13 20:44:04
18 | */
19 | public interface CommentService {
20 |
21 | /**
22 | * 保存评论
23 | * @param param 评论参数
24 | * @return 评论ID
25 | */
26 | String saveComment(CommentSaveParam param);
27 |
28 | /**
29 | * 删除评论(包括回复)
30 | * @param id
31 | * @return
32 | */
33 | boolean removeComment(String id);
34 |
35 | /**
36 | * 保存评论回复
37 | * @param param 评论回复参数
38 | * @return 回复ID
39 | */
40 | String saveCommentReply(CommentReplySaveParam param);
41 |
42 | /**
43 | * 删除评论回复
44 | * @param replyId 回复ID
45 | * @return
46 | */
47 | boolean removeCommentReply(String replyId);
48 |
49 | /**
50 | * 分页查询评论
51 | * @param param
52 | * @return
53 | */
54 | Page listComments(CommentQueryParam param);
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-comment
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-comment-provider
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-cloud-comment-api
18 | 1.0-SNAPSHOT
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-comment-biz
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-aop
36 |
37 |
38 |
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/KittyCloudCommentProviderApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider;
2 |
3 | import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
4 | import com.alicp.jetcache.anno.config.EnableMethodCache;
5 | import com.spring4all.swagger.EnableSwagger2Doc;
6 | import org.springframework.boot.SpringApplication;
7 | import org.springframework.boot.autoconfigure.SpringBootApplication;
8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9 |
10 | /**
11 | * 评论服务启动类
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-13 20:44:04
19 | */
20 | @EnableSwagger2Doc
21 | @EnableDiscoveryClient
22 | @EnableCreateCacheAnnotation
23 | @EnableMethodCache(basePackages = "com.cxytiandi.kittycloud.comment.biz.manager")
24 | @SpringBootApplication(scanBasePackages = {"com.cxytiandi.kittycloud.comment","com.cxytiandi.kitty.web.config"})
25 | public class KittyCloudCommentProviderApp {
26 | public static void main(String[] args) {
27 | SpringApplication.run(KittyCloudCommentProviderApp.class);
28 | }
29 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/convert/CommentQueryParamConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentQueryRequest;
4 | import com.cxytiandi.kittycloud.comment.biz.param.CommentQueryParam;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 评论查询参数转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-16 16:14
18 | */
19 | @Component
20 | public class CommentQueryParamConvert implements EntityConvert {
21 |
22 | @Override
23 | public CommentQueryParam convert(CommentQueryRequest source) {
24 | CommentQueryParam param = new CommentQueryParam();
25 | BeanUtils.copyProperties(source, param);
26 | return param;
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/convert/CommentReplySaveParamConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
4 | import com.cxytiandi.kittycloud.comment.api.request.CommentSaveRequest;
5 | import com.cxytiandi.kittycloud.comment.biz.param.CommentReplySaveParam;
6 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
7 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
8 | import org.springframework.beans.BeanUtils;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * 评论回复保存参数转化器
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-15 19:26
20 | */
21 | @Component
22 | public class CommentReplySaveParamConvert implements EntityConvert {
23 |
24 | @Override
25 | public CommentReplySaveParam convert(CommentReplySaveRequest source) {
26 | CommentReplySaveParam saveParam = new CommentReplySaveParam();
27 | BeanUtils.copyProperties(source, saveParam);
28 | return saveParam;
29 | }
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/convert/CommentResponseConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.response.CommentResponse;
4 | import com.cxytiandi.kittycloud.comment.biz.bo.CommentBO;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 评论Response转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-16 16:20
18 | */
19 | @Component
20 | public class CommentResponseConvert implements EntityConvert {
21 |
22 | @Override
23 | public CommentResponse convert(CommentBO source) {
24 | CommentResponse response = new CommentResponse();
25 | BeanUtils.copyProperties(source, response);
26 | return response;
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/convert/CommentSaveParamConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentSaveRequest;
4 | import com.cxytiandi.kittycloud.comment.biz.param.CommentSaveParam;
5 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 评论保存参数转化器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-15 19:26
18 | */
19 | @Component
20 | public class CommentSaveParamConvert implements EntityConvert {
21 |
22 | @Override
23 | public CommentSaveParam convert(CommentSaveRequest source) {
24 | CommentSaveParam saveParam = new CommentSaveParam();
25 | BeanUtils.copyProperties(source, saveParam);
26 | return saveParam;
27 | }
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/java/com/cxytiandi/kittycloud/comment/provider/service/CommentReplyRemoteServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider.service;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
4 | import com.cxytiandi.kittycloud.comment.api.service.CommentReplyRemoteService;
5 | import com.cxytiandi.kittycloud.comment.biz.param.CommentReplySaveParam;
6 | import com.cxytiandi.kittycloud.comment.biz.service.CommentService;
7 | import com.cxytiandi.kittycloud.comment.provider.convert.CommentReplySaveParamConvert;
8 | import com.cxytiandi.kittycloud.common.base.Response;
9 | import com.cxytiandi.kittycloud.common.base.ResponseData;
10 | import com.cxytiandi.kittycloud.common.constant.DubboConstant;
11 | import org.apache.dubbo.config.annotation.Service;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | /**
16 | * 评论回复RPC/REST接口实现
17 | *
18 | * @作者 尹吉欢
19 | * @个人微信 jihuan900
20 | * @微信公众号 猿天地
21 | * @GitHub https://github.com/yinjihuan
22 | * @作者介绍 http://cxytiandi.com/about
23 | * @时间 2020-02-13 20:44:04
24 | */
25 | @RestController
26 | @Service(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP)
27 | public class CommentReplyRemoteServiceImpl implements CommentReplyRemoteService {
28 |
29 | @Autowired
30 | private CommentService commentService;
31 |
32 | @Autowired
33 | private CommentReplySaveParamConvert commentReplySaveParamConvert;
34 |
35 | @Override
36 | public ResponseData saveCommentReply(CommentReplySaveRequest request) {
37 | CommentReplySaveParam saveParam = commentReplySaveParamConvert.convert(request);
38 | return Response.ok(commentService.saveCommentReply(saveParam));
39 | }
40 |
41 | @Override
42 | public ResponseData removeCommentReply(String id) {
43 | return Response.ok(commentService.removeCommentReply(id));
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-comment-provider
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-comment-provider
2 |
3 | dubbo.scan.base-packages=com.cxytiandi.kittycloud.comment.provider.service
4 | dubbo.protocol.name=dubbo
5 | dubbo.protocol.port=20082
6 | dubbo.registry.address=spring-cloud://localhost
7 |
8 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
9 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
10 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
11 |
12 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-mongodb.properties
13 | spring.cloud.nacos.config.ext-config[0].group=MIDDLEWARE_GROUP
14 | spring.cloud.nacos.config.ext-config[0].refresh=true
15 |
16 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-comment-provider-application.properties
17 | spring.cloud.nacos.config.ext-config[1].group=APPLICATION_GROUP
18 | spring.cloud.nacos.config.ext-config[1].refresh=true
19 |
20 | spring.cloud.nacos.config.ext-config[2].data-id=kitty-cloud-redis-jetcache.properties
21 | spring.cloud.nacos.config.ext-config[2].group=MIDDLEWARE_GROUP
22 | spring.cloud.nacos.config.ext-config[2].refresh=true
23 |
24 | spring.cloud.nacos.config.ext-config[3].data-id=kitty-cloud-sentinel.properties
25 | spring.cloud.nacos.config.ext-config[3].group=MIDDLEWARE_GROUP
26 | spring.cloud.nacos.config.ext-config[3].refresh=true
27 |
28 | spring.cloud.nacos.config.ext-config[4].data-id=kitty-cloud-redis-redisson.properties
29 | spring.cloud.nacos.config.ext-config[4].group=MIDDLEWARE_GROUP
30 | spring.cloud.nacos.config.ext-config[4].refresh=true
31 |
32 | dubbo.provider.filter=tracing
33 | dubbo.consumer.filter=tracing
--------------------------------------------------------------------------------
/kitty-cloud-comment/kitty-cloud-comment-provider/src/test/java/com/cxytiandi/kittycloud/comment/provider/CommentReplyRemoteServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.comment.provider;
2 |
3 | import com.cxytiandi.kittycloud.comment.api.request.CommentReplySaveRequest;
4 | import com.cxytiandi.kittycloud.comment.api.service.CommentReplyRemoteService;
5 | import com.cxytiandi.kittycloud.common.base.ResponseData;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | /**
14 | * CommentReplyRemoteService测试类
15 | *
16 | * @作者 尹吉欢
17 | * @个人微信 jihuan900
18 | * @微信公众号 猿天地
19 | * @GitHub https://github.com/yinjihuan
20 | * @作者介绍 http://cxytiandi.com/about
21 | * @时间 2020-02-15 20:50
22 | */
23 | @RunWith(SpringRunner.class)
24 | @SpringBootTest
25 | public class CommentReplyRemoteServiceTest {
26 |
27 | @Autowired
28 | private CommentReplyRemoteService commentReplyRemoteService;
29 |
30 | @Test
31 | public void saveCommentReply() {
32 | CommentReplySaveRequest request = CommentReplySaveRequest.builder()
33 | .commentId("5e47df88b0aa74aa95a96c14")
34 | .content("你说的真好")
35 | .replayRefUserId(2L)
36 | .userId(3L)
37 | .build();
38 | ResponseData saveCommentReplyResp = commentReplyRemoteService.saveCommentReply(request);
39 | Assert.assertTrue(saveCommentReplyResp.isSuccess());
40 | }
41 |
42 | @Test
43 | public void removeCommentReply() {
44 | ResponseData removeCommentReplyResp = commentReplyRemoteService.removeCommentReply("5e47f09ab0aa74adc80f9c6e");
45 | Assert.assertTrue(removeCommentReplyResp.isSuccess() && removeCommentReplyResp.getData());
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/kitty-cloud-comment/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-comment
13 | pom
14 |
15 | kitty-cloud-comment-api
16 | kitty-cloud-comment-biz
17 | kitty-cloud-comment-provider
18 |
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-common
24 | 1.0-SNAPSHOT
25 |
26 |
27 | net.logstash.logback
28 | logstash-logback-encoder
29 | 5.2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/kitty-cloud-common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-common
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 | true
19 |
20 |
21 | com.cxytiandi
22 | kitty-spring-cloud-starter-sentinel
23 | true
24 |
25 |
26 | com.cxytiandi
27 | kitty-spring-cloud-starter-dubbo
28 | true
29 |
30 |
31 | com.cxytiandi
32 | kitty-spring-cloud-starter-nacos
33 | true
34 |
35 |
36 | io.jsonwebtoken
37 | jjwt
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.apache.maven.plugins
46 | maven-compiler-plugin
47 |
48 | 1.8
49 | 1.8
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/aop/RemoteServiceAspect.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.aop;
2 |
3 | import brave.Tracer;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import org.aspectj.lang.ProceedingJoinPoint;
6 | import org.aspectj.lang.annotation.Around;
7 | import org.aspectj.lang.annotation.Aspect;
8 | import org.slf4j.MDC;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.beans.factory.annotation.Value;
11 |
12 | /**
13 | * RPC/REST Service切面
14 | *
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-03-07 11:09
21 | */
22 | @Aspect
23 | public class RemoteServiceAspect {
24 |
25 | @Autowired
26 | private Tracer tracer;
27 |
28 | @Value("${spring.profiles.active:dev}")
29 | private String env;
30 |
31 | @Around("execution(public * com.cxytiandi.kittycloud..provider.service..*(..)))")
32 | public Object around(ProceedingJoinPoint pjp) throws Throwable {
33 | try {
34 | // 日志输出环境
35 | MDC.put("env", env);
36 |
37 | Object result = pjp.proceed();
38 | // Trace ID 添加到响应内容中
39 | if (result instanceof ResponseData && tracer != null && tracer.currentSpan() != null) {
40 | String traceId = tracer.currentSpan().context().traceIdString();
41 | ResponseData responseData = (ResponseData)result;
42 | responseData.setRequestId(traceId);
43 | }
44 | return result;
45 | } catch (Throwable throwable) {
46 | throw throwable;
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/autoconfigure/CommonBeanAutoConfigure.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.autoconfigure;
2 |
3 | import com.cxytiandi.kittycloud.common.aop.RemoteServiceAspect;
4 | import com.cxytiandi.kittycloud.common.exception.GlobalExceptionHandler;
5 | import com.cxytiandi.kittycloud.common.helper.ApplicationContextHelper;
6 | import com.github.structlog4j.StructLog4J;
7 | import com.github.structlog4j.json.JsonFormatter;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 |
11 | import javax.annotation.PostConstruct;
12 |
13 | /**
14 | * Common中的自动配置
15 | *
16 | * @作者 尹吉欢
17 | * @个人微信 jihuan900
18 | * @微信公众号 猿天地
19 | * @GitHub https://github.com/yinjihuan
20 | * @作者介绍 http://cxytiandi.com/about
21 | * @时间 2020-02-17 20:47
22 | */
23 | @Configuration
24 | public class CommonBeanAutoConfigure {
25 |
26 | @PostConstruct
27 | public void init() {
28 | StructLog4J.setFormatter(JsonFormatter.getInstance());
29 | }
30 |
31 | @Bean
32 | public GlobalExceptionHandler globalExceptionHandler() {
33 | return new GlobalExceptionHandler();
34 | }
35 |
36 | @Bean
37 | public RemoteServiceAspect remoteServiceAspect() {
38 | return new RemoteServiceAspect();
39 | }
40 |
41 | @Bean
42 | public ApplicationContextHelper applicationContextHelper() {
43 | return new ApplicationContextHelper();
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/autoconfigure/UrlBlockHandlerAutoConfigure.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.autoconfigure;
2 |
3 | import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
4 | import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
5 | import com.cxytiandi.kittycloud.common.handler.KittyCloudUrlBlockHandler;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | import javax.annotation.PostConstruct;
10 |
11 | /**
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-27 22:51
18 | */
19 | @ConditionalOnClass(UrlBlockHandler.class)
20 | @Configuration
21 | public class UrlBlockHandlerAutoConfigure {
22 |
23 | @PostConstruct
24 | public void init() {
25 | WebCallbackManager.setUrlBlockHandler(new KittyCloudUrlBlockHandler());
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/base/Entity.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.base;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * DO父类
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Data
18 | public class Entity {
19 |
20 | private Date addTime;
21 |
22 | private Date updateTime;
23 |
24 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/base/EntityConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.base;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * 实体转换器
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-13 20:44:04
14 | */
15 | public interface EntityConvert {
16 |
17 | default T convert(S source) {
18 | return null;
19 | }
20 |
21 | default T convertPlus(S source, Objects ...objects) {
22 | return null;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/base/PageEntity.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.base;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-03-28 13:59
14 | */
15 | @Data
16 | public class PageEntity implements Serializable {
17 |
18 | /**
19 | * 页数
20 | */
21 | private int page;
22 |
23 | /**
24 | * 页大小
25 | */
26 | private int size;
27 |
28 | /**
29 | * 排序字段
30 | */
31 | private String sortField;
32 |
33 | /**
34 | * 排序类型(0:升序 1:降序)
35 | */
36 | private int sortType;
37 |
38 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/base/ResponseCode.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.base;
2 |
3 | /**
4 | * REST API 响应码
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-13 20:44:04
12 | */
13 | public enum ResponseCode {
14 | SUCCESS_CODE(200, "成功"),
15 | PARAM_ERROR_CODE(400, "参数错误"),
16 | FORBIDDEN_CODE(403, "禁止访问"),
17 | NOT_FOUND_CODE(404, "资源不存在"),
18 | REQUEST_METHOD_NOT_SUPPORTED_CODE(405, "不支持的请求方法"),
19 | SERVER_LIMIT_CODE(429, "服务限流"),
20 | SERVER_ERROR_CODE(500, "服务器错误"),
21 | SERVER_DOWNGRADE_CODE(700, "服务降级"),
22 | TOKEN_TIMEOUT_CODE(800, "登录信息过期"),
23 |
24 |
25 | /**
26 | * 用户服务
27 | * 前三位 100
28 | * 中两位 01 通用异常 02 登录业务
29 | * 后三位 具体错误
30 | */
31 | USER_EXCEPTION_CODE(10001001, "用户通用异常"),
32 | USER_LOGIN_ERROR_CODE(10002001, "用户名或密码错误")
33 | ;
34 |
35 |
36 |
37 | private int code;
38 | private String message;
39 |
40 | public void setCode(int code) {
41 | this.code = code;
42 | }
43 |
44 | public int getCode() {
45 | return code;
46 | }
47 |
48 | public void setMessage(String message) {
49 | this.message = message;
50 | }
51 |
52 | public String getMessage() {
53 | return message;
54 | }
55 |
56 | private ResponseCode(int code, String message) {
57 | this.code = code;
58 | this.message = message;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/config/JwtRsaConfig.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.config;
2 |
3 | import com.fasterxml.jackson.annotation.JsonAlias;
4 | import lombok.Data;
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-04-07 22:17
15 | */
16 | @Data
17 | @Configuration
18 | @ConfigurationProperties("kitty.cloud.jwt.rsa")
19 | public class JwtRsaConfig {
20 |
21 | /**
22 | * 模
23 | */
24 | @JsonAlias("kitty.cloud.jwt.rsa.modulus")
25 | private String modulus;
26 |
27 | /**
28 | * 私钥
29 | */
30 | @JsonAlias("kitty.cloud.jwt.rsa.privateExponent")
31 | private String privateExponent;
32 |
33 | /**
34 | * 公钥
35 | */
36 | @JsonAlias("kitty.cloud.jwt.rsa.publicExponent")
37 | private String publicExponent;
38 |
39 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/constant/CommonConstant.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.constant;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-03-24 23:13
10 | */
11 | public class CommonConstant {
12 |
13 | public static int ZERO_NUM = 0;
14 |
15 | public static int DEFAULT_PAGE_SIZE = 20;
16 |
17 | public static final String DEFAULT_EMPTY_STR = "";
18 |
19 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/constant/DubboConstant.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.constant;
2 |
3 | /**
4 | * Dubbo常量
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-13 20:44:04
12 | */
13 | public class DubboConstant {
14 |
15 | public static final String VERSION_V100 = "1.0.0";
16 | public static final String DEFAULT_GROUP = "default";
17 | public static final String MOCK = "true";
18 |
19 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/constant/EsConstant.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.constant;
2 |
3 | /**
4 | * ES常量
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-02-13 20:44:04
12 | */
13 | public class EsConstant {
14 |
15 | public static final String DEFAULT_TYPE = "doc";
16 |
17 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/constant/NacosConstant.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.constant;
2 |
3 | /**
4 | * Nacos常量
5 | *
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-10 21:22
12 | */
13 | public class NacosConstant {
14 |
15 | /**
16 | * 业务分组
17 | */
18 | public static final String BIZ_GROUP = "BIZ_GROUP";
19 |
20 | public static final String JWT_RSA_BIZ = "kitty-cloud-user-jwt-rsa-biz.properties";
21 |
22 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/exception/BizException.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.exception;
2 |
3 |
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 |
6 | /**
7 | * 自定义业务异常
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-13 20:44:04
15 | */
16 | public class BizException extends RuntimeException {
17 |
18 | private static final long serialVersionUID = -5701182284190108797L;
19 |
20 | private ResponseCode code;
21 |
22 | public void setCode(ResponseCode code) {
23 | this.code = code;
24 | }
25 |
26 | public ResponseCode getCode() {
27 | return code;
28 | }
29 |
30 | public BizException() {
31 | super("");
32 | }
33 |
34 | public BizException(String message) {
35 | super(message);
36 | }
37 |
38 | public BizException(ResponseCode code) {
39 | super(code.getMessage());
40 | this.code = code;
41 | }
42 |
43 | public BizException(ResponseCode code, String message) {
44 | super(message);
45 | this.code = code;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/exception/FallbackException.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.exception;
2 |
3 |
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 |
6 | /**
7 | * 自定义降级异常
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-27 20:44:04
15 | */
16 | public class FallbackException extends RuntimeException {
17 |
18 | private ResponseCode code = ResponseCode.SERVER_DOWNGRADE_CODE;
19 |
20 | public ResponseCode getCode() {
21 | return code;
22 | }
23 |
24 | public FallbackException(String message) {
25 | super(message);
26 | }
27 |
28 | public FallbackException() {
29 | this.code = code;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/handler/KittyCloudUrlBlockHandler.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.handler;
2 |
3 | import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
4 | import com.alibaba.csp.sentinel.slots.block.BlockException;
5 | import com.cxytiandi.kitty.common.json.JsonUtils;
6 | import com.cxytiandi.kittycloud.common.base.Response;
7 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.io.PrintWriter;
13 |
14 | /**
15 | * Sentinel Url限流后的响应处理
16 | *
17 | * @作者 尹吉欢
18 | * @个人微信 jihuan900
19 | * @微信公众号 猿天地
20 | * @GitHub https://github.com/yinjihuan
21 | * @作者介绍 http://cxytiandi.com/about
22 | * @时间 2020-03-01 21:35
23 | */
24 | public class KittyCloudUrlBlockHandler implements UrlBlockHandler {
25 |
26 | @Override
27 | public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
28 | httpServletResponse.setContentType("application/json; charset=utf-8");
29 | PrintWriter writer = httpServletResponse.getWriter();
30 | writer.write(JsonUtils.toJson(Response.fail("访问过于频繁,请休息一会儿!", ResponseCode.SERVER_LIMIT_CODE)));
31 | writer.flush();
32 | writer.close();
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/java/com/cxytiandi/kittycloud/common/helper/ApplicationContextHelper.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.common.helper;
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 | * spring上下文帮助类
10 | *
11 | * @作者 尹吉欢
12 | * @个人微信 jihuan900
13 | * @微信公众号 猿天地
14 | * @GitHub https://github.com/yinjihuan
15 | * @作者介绍 http://cxytiandi.com/about
16 | * @时间 2020-03-08 15:12
17 | */
18 | public class ApplicationContextHelper implements ApplicationContextAware {
19 |
20 | private static ApplicationContext applicationContext;
21 |
22 | @Override
23 | public void setApplicationContext(ApplicationContext context) throws BeansException {
24 | applicationContext = context;
25 | }
26 |
27 | public static Environment getEnvironment() {
28 | return applicationContext.getEnvironment();
29 | }
30 |
31 | public static T getBean(Class requiredType) {
32 | return applicationContext.getBean(requiredType);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter:
--------------------------------------------------------------------------------
1 | DubboExceptionHandlerFilter=com.cxytiandi.kittycloud.common.exception.DubboExceptionHandlerFilter
--------------------------------------------------------------------------------
/kitty-cloud-common/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.cxytiandi.kittycloud.common.autoconfigure.CommonBeanAutoConfigure,\
3 | com.cxytiandi.kittycloud.common.autoconfigure.UrlBlockHandlerAutoConfigure,\
4 | com.cxytiandi.kittycloud.common.autoconfigure.JWTAutoConfigure
--------------------------------------------------------------------------------
/kitty-cloud-gateway/kitty-cloud-gateway-web/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-gateway
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-gateway-web
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-gateway-zuul
18 |
19 |
20 |
21 | com.cxytiandi
22 | kitty-spring-cloud-starter-nacos
23 |
24 |
25 |
26 | com.cxytiandi
27 | kitty-spring-cloud-starter-cat
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-logging
33 |
34 |
35 |
36 | com.cxytiandi
37 | kitty-spring-cloud-starter-sentinel
38 |
39 |
40 |
41 | com.cxytiandi
42 | kitty-spring-cloud-starter-jetcache
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/kitty-cloud-gateway/kitty-cloud-gateway-web/src/main/java/com/cxytiandi/kittycloud/gateway/web/KittyCloudWebGatewayApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.gateway.web;
2 |
3 | import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
8 |
9 | /**
10 | * Web网关启动类
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-02-17 20:01:04
18 | */
19 | @EnableZuulProxy
20 | @EnableCreateCacheAnnotation
21 | @EnableDiscoveryClient
22 | @SpringBootApplication
23 | public class KittyCloudWebGatewayApp {
24 | public static void main(String[] args) {
25 | SpringApplication.run(KittyCloudWebGatewayApp.class);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-gateway/kitty-cloud-gateway-web/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-gateway-web
--------------------------------------------------------------------------------
/kitty-cloud-gateway/kitty-cloud-gateway-web/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-gateway-web
2 |
3 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
4 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
5 |
6 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-gateway-web-application.properties
7 | spring.cloud.nacos.config.ext-config[0].group=APPLICATION_GROUP
8 | spring.cloud.nacos.config.ext-config[0].refresh=true
9 |
10 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-user-jwt-rsa-biz.properties
11 | spring.cloud.nacos.config.ext-config[1].group=BIZ_GROUP
12 | spring.cloud.nacos.config.ext-config[1].refresh=true
13 |
14 | spring.cloud.nacos.config.ext-config[2].data-id=kitty-cloud-redis-jetcache.properties
15 | spring.cloud.nacos.config.ext-config[2].group=MIDDLEWARE_GROUP
16 | spring.cloud.nacos.config.ext-config[2].refresh=true
--------------------------------------------------------------------------------
/kitty-cloud-gateway/kitty-cloud-gateway-web/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ${FILE_LOG_PATTERN}
15 |
16 |
17 |
18 | ${LOG_HOME_PATH}/${APP_NAME}-debug.%d{yyyy-MM-dd}.log
19 | 60
20 |
21 |
22 |
23 | DEBUG
24 | ACCEPT
25 | DENY
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/kitty-cloud-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-gateway
13 | pom
14 |
15 | kitty-cloud-gateway-web
16 |
17 |
18 |
19 |
20 | com.cxytiandi
21 | kitty-cloud-common
22 | 1.0-SNAPSHOT
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-goods
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-goods-api
13 |
14 |
15 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-goods
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-goods-biz
13 |
14 |
15 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/AttrDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-07-24 21:25
12 | */
13 | public class AttrDocument {
14 |
15 | private String id;
16 |
17 | private String name;
18 |
19 | private int type;
20 |
21 | private int inputType;
22 |
23 | private int poiId;
24 |
25 | private List arrtValus;
26 | }
27 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/AttrValueDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-07-24 21:28
10 | */
11 | public class AttrValueDocument {
12 |
13 | private String id;
14 |
15 | private String value;
16 |
17 | private int poiValueId;
18 | }
19 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/CategoryDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-07-24 21:33
12 | */
13 | public class CategoryDocument {
14 |
15 | private String id;
16 |
17 | private String name;
18 |
19 | private int level;
20 |
21 | private boolean isLeaf;
22 |
23 | private String parentId;
24 |
25 | private List attrs;
26 | }
27 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/PoiDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-07-24 21:37
10 | */
11 | public class PoiDocument {
12 | }
13 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/PoiValueDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-07-24 21:37
10 | */
11 | public class PoiValueDocument {
12 | }
13 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/ProductDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-07-24 21:21
14 | */
15 | @Data
16 | public class ProductDocument {
17 |
18 | /**
19 | * ID
20 | */
21 | private String id;
22 |
23 | /**
24 | * 名称
25 | */
26 | private String name;
27 |
28 | /**
29 | * 状态
30 | */
31 | private int status;
32 |
33 | /**
34 | * 业务类型
35 | */
36 | private int bizType;
37 |
38 | /**
39 | * 客户
40 | */
41 | private String customer;
42 |
43 | /**
44 | * 是否标准Product
45 | */
46 | private int standard;
47 |
48 | /**
49 | * 属性
50 | */
51 | private List attrs;
52 |
53 | /**
54 | * SKU
55 | */
56 | private List skus;
57 | }
58 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/SaleAttrValueDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-07-24 21:31
10 | */
11 | public class SaleAttrValueDocument {
12 |
13 | private int attrId;
14 |
15 | private int attrValueId;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/document/SkuDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.document;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.List;
5 |
6 | /**
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-07-24 21:25
13 | */
14 | public class SkuDocument {
15 |
16 | private String id;
17 |
18 | private String name;
19 |
20 | private BigDecimal price;
21 |
22 | private List saleAttrValues;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/param/ProductSaveParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.param;
2 |
3 | import com.cxytiandi.kittycloud.goods.biz.document.AttrDocument;
4 | import com.cxytiandi.kittycloud.goods.biz.document.SkuDocument;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-07-24 22:14
15 | */
16 | public class ProductSaveParam {
17 |
18 | /**
19 | * 名称
20 | */
21 | private String name;
22 |
23 | /**
24 | * 状态
25 | */
26 | private int status;
27 |
28 | /**
29 | * 业务类型
30 | */
31 | private int bizType;
32 |
33 | /**
34 | * 客户
35 | */
36 | private String customer;
37 |
38 | /**
39 | * 属性
40 | */
41 | private List attrs;
42 |
43 | /**
44 | * SKU
45 | */
46 | private List skus;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/param/ProductUpdateParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.param;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-07-24 22:14
10 | */
11 | public class ProductUpdateParam extends ProductSaveParam {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/service/ProductService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.service;
2 |
3 | import com.cxytiandi.kittycloud.goods.biz.param.ProductSaveParam;
4 | import com.cxytiandi.kittycloud.goods.biz.param.ProductUpdateParam;
5 |
6 | /**
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-07-24 21:40
13 | */
14 | public interface ProductService {
15 |
16 | String saveProduct(ProductSaveParam param);
17 |
18 | String saveProductBySpu(String spuId, ProductSaveParam param);
19 |
20 | void updateProduct(ProductUpdateParam param);
21 |
22 | void removeProduct(String id);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-biz/src/main/java/com/cxytiandi/kittycloud/goods/biz/service/impl/ProductServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.goods.biz.service.impl;
2 |
3 | import com.cxytiandi.kittycloud.goods.biz.param.ProductSaveParam;
4 | import com.cxytiandi.kittycloud.goods.biz.param.ProductUpdateParam;
5 | import com.cxytiandi.kittycloud.goods.biz.service.ProductService;
6 |
7 | /**
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-07-24 21:41
14 | */
15 | public class ProductServiceImpl implements ProductService {
16 |
17 | @Override
18 | public String saveProduct(ProductSaveParam param) {
19 | return null;
20 | }
21 |
22 | @Override
23 | public String saveProductBySpu(String spuId, ProductSaveParam param) {
24 | return null;
25 | }
26 |
27 | @Override
28 | public void updateProduct(ProductUpdateParam param) {
29 |
30 | }
31 |
32 | @Override
33 | public void removeProduct(String id) {
34 |
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/kitty-cloud-goods-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-goods
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-goods-provider
13 |
14 |
15 |
--------------------------------------------------------------------------------
/kitty-cloud-goods/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-goods
13 | pom
14 |
15 | kitty-cloud-goods-api
16 | kitty-cloud-goods-biz
17 | kitty-cloud-goods-provider
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/kitty-cloud-job/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-job
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-cloud-common
18 | 1.0-SNAPSHOT
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-search-api
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 | com.cxytiandi
29 | kitty-cloud-article-api
30 | 1.0-SNAPSHOT
31 |
32 |
33 |
34 | com.cxytiandi
35 | kitty-spring-cloud-starter-xxljob
36 |
37 |
38 |
39 | com.cxytiandi
40 | kitty-spring-cloud-starter-nacos
41 |
42 |
43 |
44 | com.cxytiandi
45 | kitty-spring-cloud-starter-web
46 |
47 |
48 |
49 | com.cxytiandi
50 | kitty-spring-cloud-starter-sentinel
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/java/com/cxytiandi/kittycloud/job/KittyCloudJobApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.job;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * Job启动类
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-11 21:09
15 | */
16 | @SpringBootApplication(scanBasePackages = {"com.cxytiandi.kittycloud.job","com.cxytiandi.kitty.web.config"})
17 | public class KittyCloudJobApp {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(KittyCloudJobApp.class);
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/java/com/cxytiandi/kittycloud/job/convert/ArticleIndexSaveRequestConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.job.convert;
2 |
3 | import com.cxytiandi.kittycloud.article.api.response.ArticleResponse;
4 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
5 | import com.cxytiandi.kittycloud.search.api.request.ArticleIndexSaveRequest;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 文章索引保存请求参数转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-28 11:23
18 | */
19 | @Component
20 | public class ArticleIndexSaveRequestConvert implements EntityConvert {
21 |
22 | @Override
23 | public ArticleIndexSaveRequest convert(ArticleResponse source) {
24 | ArticleIndexSaveRequest request = new ArticleIndexSaveRequest();
25 | BeanUtils.copyProperties(source, request);
26 | return request;
27 | }
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/java/com/cxytiandi/kittycloud/job/handler/EsIndexBuildHandler.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.job.handler;
2 |
3 | import com.cxytiandi.kittycloud.common.constant.CommonConstant;
4 | import com.cxytiandi.kittycloud.job.param.EsIndexBuildParam;
5 | import com.cxytiandi.kittycloud.job.service.ArticleEsIndexBuildService;
6 | import com.xxl.job.core.biz.model.ReturnT;
7 | import com.xxl.job.core.handler.annotation.XxlJob;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * ES索引构建任务
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-03-26 23:06
20 | */
21 | @Component
22 | public class EsIndexBuildHandler {
23 |
24 | @Autowired
25 | private ArticleEsIndexBuildService articleEsIndexBuildService;
26 |
27 | @XxlJob(value = "ArticleEsIndexBuildHandler")
28 | public ReturnT execute(String param) {
29 | EsIndexBuildParam buildParam = EsIndexBuildParam.builder().param(param).size(CommonConstant.DEFAULT_PAGE_SIZE).build();
30 | articleEsIndexBuildService.execute(buildParam);
31 | return ReturnT.SUCCESS;
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/java/com/cxytiandi/kittycloud/job/param/EsIndexBuildParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.job.param;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 |
6 | /**
7 | * ES索引构建参数
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-26 23:01
15 | */
16 | @Data
17 | @Builder
18 | public class EsIndexBuildParam {
19 |
20 | /**
21 | * 任务调度参数
22 | */
23 | private String param;
24 |
25 | /**
26 | * 分页大小
27 | */
28 | private int size;
29 |
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/java/com/cxytiandi/kittycloud/job/template/AbstractEsIndexBuildTemplate.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.job.template;
2 |
3 |
4 | import org.springframework.util.CollectionUtils;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * ES索引构建模板
10 | *
11 | * @作者 尹吉欢
12 | * @个人微信 jihuan900
13 | * @微信公众号 猿天地
14 | * @GitHub https://github.com/yinjihuan
15 | * @作者介绍 http://cxytiandi.com/about
16 | * @时间 2020-03-26 21:43
17 | */
18 | public abstract class AbstractEsIndexBuildTemplate {
19 |
20 | public final void execute(Request request) {
21 | doExecute(request, false);
22 | }
23 |
24 | public final void executeWithParallelStream(Request request) {
25 | doExecute(request, true);
26 | }
27 |
28 | private void doExecute(Request request, boolean isParalleStream) {
29 | int page = 1;
30 | while (true) {
31 | List sources = getIndexSource(page, request);
32 |
33 | if (CollectionUtils.isEmpty(sources)) {
34 | break;
35 | }
36 |
37 | if (isParalleStream) {
38 | sources.parallelStream().forEach(this::buildIndex);
39 | } else {
40 | sources.stream().forEach(this::buildIndex);
41 | }
42 |
43 | page++;
44 | }
45 | }
46 |
47 | protected abstract List getIndexSource(int page, Request request);
48 |
49 | protected abstract void buildIndex(Source source);
50 |
51 | }
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-job
--------------------------------------------------------------------------------
/kitty-cloud-job/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-job
2 |
3 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
4 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
5 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
6 |
7 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-job-application.properties
8 | spring.cloud.nacos.config.ext-config[0].group=APPLICATION_GROUP
9 | spring.cloud.nacos.config.ext-config[0].refresh=true
10 |
11 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-xxljob.properties
12 | spring.cloud.nacos.config.ext-config[1].group=MIDDLEWARE_GROUP
13 | spring.cloud.nacos.config.ext-config[1].refresh=true
14 |
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-mqconsume
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-mqconsume-es
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 |
19 |
20 | com.cxytiandi
21 | kitty-spring-cloud-starter-rocketmq
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/EsMqConsumeApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.scheduling.annotation.EnableAsync;
6 |
7 | /**
8 | * ES MQ消费者启动类
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-29 21:09
16 | */
17 | @EnableAsync
18 | @SpringBootApplication
19 | public class EsMqConsumeApp {
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(EsMqConsumeApp.class);
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/async/support/CustomApplicationContextAware.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.async.support;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.context.event.EventListener;
7 | import org.springframework.core.annotation.AnnotationUtils;
8 | import org.springframework.stereotype.Component;
9 |
10 | import java.lang.reflect.Method;
11 | import java.util.Map;
12 |
13 | /**
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-04-27 21:01
20 | */
21 | @Component
22 | public class CustomApplicationContextAware implements ApplicationContextAware {
23 |
24 | /**
25 | * 总任务数量
26 | */
27 | private long taskCount;
28 |
29 | public long getTaskCount() {
30 | return taskCount;
31 | }
32 |
33 | @Override
34 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
35 | Map beanMap = applicationContext.getBeansWithAnnotation(Component.class);
36 | if (beanMap == null) {
37 | return;
38 | }
39 | for (Object bean : beanMap.values()) {
40 | Class> clz = bean.getClass();
41 | Method[] methods = clz.getMethods();
42 | for (Method method : methods) {
43 | EventListener eventListener = AnnotationUtils.findAnnotation(method, EventListener.class);
44 | if (eventListener != null) {
45 | taskCount++;
46 | }
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/async/support/EventListenerAspect.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.async.support;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
4 | import org.aspectj.lang.ProceedingJoinPoint;
5 | import org.aspectj.lang.annotation.Around;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.springframework.context.event.EventListener;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Aspect
11 | @Component
12 | public class EventListenerAspect {
13 |
14 | @Around(value = "@annotation(eventListener)")
15 | public Object aroundAdvice(ProceedingJoinPoint joinpoint, EventListener eventListener) throws Throwable {
16 | DataChangeEvent event = null;
17 | boolean executeResult = true;
18 | try {
19 | event = (DataChangeEvent)joinpoint.getArgs()[0];
20 | Object result = joinpoint.proceed();
21 | return result;
22 | } catch (Exception e) {
23 | executeResult = false;
24 | throw e;
25 | } finally {
26 | DefaultFuture.received(event.getMessageId(), executeResult);
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/controller/EsMqProduceMockRestController.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.controller;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.request.DataChangeRequest;
5 | import org.apache.rocketmq.common.message.Message;
6 | import org.apache.rocketmq.spring.core.RocketMQTemplate;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | /**
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-29 20:45
18 | */
19 | @RestController
20 | public class EsMqProduceMockRestController {
21 |
22 | @Autowired
23 | private RocketMQTemplate rocketMQTemplate;
24 |
25 | @GetMapping("/message/send")
26 | public String sendMessage() {
27 | DataChangeRequest request = new DataChangeRequest();
28 | request.setMessageId("1");
29 | request.setMessage("xxx");
30 | request.setChangeType(ChangeTypeEnum.INSERT.getType());
31 | rocketMQTemplate.syncSend("data_change", request);
32 | return "success";
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/enums/ChangeTypeEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.enums;
2 |
3 | /**
4 | * @作者 尹吉欢
5 | * @个人微信 jihuan900
6 | * @微信公众号 猿天地
7 | * @GitHub https://github.com/yinjihuan
8 | * @作者介绍 http://cxytiandi.com/about
9 | * @时间 2020-03-29 23:09
10 | */
11 | public enum ChangeTypeEnum {
12 |
13 | /**
14 | * 新增
15 | */
16 | INSERT(1, "新增"),
17 | /**
18 | * 修改
19 | */
20 | UPDATE(2, "修改"),
21 |
22 | /**
23 | * 删除
24 | */
25 | DELETE(3, "删除");
26 |
27 | ChangeTypeEnum(int type, String descp) {
28 | this.type = type;
29 | this.descp = descp;
30 | }
31 |
32 | /**
33 | * 类型
34 | */
35 | private int type;
36 |
37 | /**
38 | * 描述
39 | */
40 | private String descp;
41 |
42 | public int getType() {
43 | return type;
44 | }
45 |
46 | public String getDescp() {
47 | return descp;
48 | }
49 |
50 | public static ChangeTypeEnum from(int type) {
51 | for (ChangeTypeEnum changeType: ChangeTypeEnum.values()) {
52 | if (changeType.getType() == type) {
53 | return changeType;
54 | }
55 | }
56 | return null;
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/event/DataChangeEvent.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.event;
2 |
3 | import lombok.Data;
4 | import org.springframework.context.ApplicationEvent;
5 |
6 | /**
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-03-29 20:26
13 | */
14 | @Data
15 | public class DataChangeEvent extends ApplicationEvent {
16 |
17 | private String table;
18 |
19 | private int changeType;
20 |
21 | private String messageId;
22 |
23 | private String message;
24 |
25 | /**
26 | * Create a new ApplicationEvent.
27 | *
28 | * @param source the object on which the event initially occurred (never {@code null})
29 | */
30 | public DataChangeEvent(Object source) {
31 | super(source);
32 | }
33 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/factory/ArticleIndexServiceFactory.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.factory;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.service.ArticleIndexService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 文章索引Service工厂类
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-03-30 21:31
19 | */
20 | @Component
21 | public class ArticleIndexServiceFactory {
22 |
23 | @Autowired
24 | private List articleIndexServices;
25 |
26 | public ArticleIndexService getArticleIndexService(ChangeTypeEnum changeType) {
27 | if (changeType == null) {
28 | return null;
29 | }
30 | return articleIndexServices.stream().filter(s -> s.changeType() == changeType).findAny()
31 | .orElseGet(null);
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/listener/DataChangeEventListener.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.listener;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
5 | import com.cxytiandi.kittycloud.mqconsume.es.factory.ArticleIndexServiceFactory;
6 | import com.cxytiandi.kittycloud.mqconsume.es.service.ArticleIndexService;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.context.event.EventListener;
10 | import org.springframework.scheduling.annotation.Async;
11 | import org.springframework.stereotype.Component;
12 |
13 |
14 | /**
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-03-29 22:21
21 | */
22 | @Slf4j
23 | @Component
24 | public class DataChangeEventListener {
25 |
26 | @Autowired
27 | private ArticleIndexServiceFactory articleIndexServiceFactory;
28 |
29 | /**
30 | * 文章索引更新
31 | * @param event
32 | */
33 | @Async
34 | @EventListener
35 | public void onArticleIndexChangeEvent(DataChangeEvent event) {
36 | ArticleIndexService articleIndexService = articleIndexServiceFactory.getArticleIndexService(ChangeTypeEnum.from(event.getChangeType()));
37 | if (articleIndexService != null) {
38 | articleIndexService.changeArticleIndex(event);
39 | }
40 | log.info("articleIndexChange Thread {}", Thread.currentThread().getName());
41 | }
42 |
43 | /**
44 | * 评论索引更新
45 | * @param event
46 | */
47 | @Async
48 | @EventListener
49 | public void onCommentIndexChangeEvent(DataChangeEvent event) {
50 | log.info("commentIndexChange Thread {}", Thread.currentThread().getName());
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/request/DataChangeRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.request;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-29 20:26
12 | */
13 | @Data
14 | public class DataChangeRequest {
15 |
16 | private String table;
17 |
18 | private int changeType;
19 |
20 | private String message;
21 |
22 | private String messageId;
23 |
24 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/service/ArticleIndexService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.service;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
5 |
6 | /**
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-03-29 22:40
13 | */
14 | public interface ArticleIndexService {
15 |
16 | void changeArticleIndex(DataChangeEvent event);
17 |
18 | ChangeTypeEnum changeType();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/service/impl/ArticleIndexRemoveServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.service.impl;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
5 | import com.cxytiandi.kittycloud.mqconsume.es.service.ArticleIndexService;
6 | import org.springframework.stereotype.Service;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | /**
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-29 22:40
18 | */
19 | @Service
20 | public class ArticleIndexRemoveServiceImpl implements ArticleIndexService {
21 |
22 | private List consumerTables = Arrays.asList("article");
23 |
24 | @Override
25 | public void changeArticleIndex(DataChangeEvent event) {
26 | if (!consumerTables.contains(event.getTable())) {
27 | return;
28 | }
29 | }
30 |
31 | @Override
32 | public ChangeTypeEnum changeType() {
33 | return ChangeTypeEnum.DELETE;
34 | }
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/service/impl/ArticleIndexSaveServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.service.impl;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
5 | import com.cxytiandi.kittycloud.mqconsume.es.service.ArticleIndexService;
6 | import org.springframework.stereotype.Service;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | /**
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-29 22:40
18 | */
19 | @Service
20 | public class ArticleIndexSaveServiceImpl implements ArticleIndexService {
21 |
22 | private List consumerTables = Arrays.asList("article");
23 |
24 | @Override
25 | public void changeArticleIndex(DataChangeEvent event) {
26 | try {
27 | Thread.sleep(5000);
28 | } catch (InterruptedException e) {
29 | e.printStackTrace();
30 | }
31 | int a = 2/0;
32 | if (!consumerTables.contains(event.getTable())) {
33 | return;
34 | }
35 | }
36 |
37 | @Override
38 | public ChangeTypeEnum changeType() {
39 | return ChangeTypeEnum.INSERT;
40 | }
41 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/java/com/cxytiandi/kittycloud/mqconsume/es/service/impl/ArticleIndexUpdateServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.mqconsume.es.service.impl;
2 |
3 | import com.cxytiandi.kittycloud.mqconsume.es.enums.ChangeTypeEnum;
4 | import com.cxytiandi.kittycloud.mqconsume.es.event.DataChangeEvent;
5 | import com.cxytiandi.kittycloud.mqconsume.es.service.ArticleIndexService;
6 | import org.springframework.stereotype.Service;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | /**
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-29 22:40
18 | */
19 | @Service
20 | public class ArticleIndexUpdateServiceImpl implements ArticleIndexService {
21 |
22 | private List consumerTables = Arrays.asList("article");
23 |
24 | @Override
25 | public void changeArticleIndex(DataChangeEvent event) {
26 | if (!consumerTables.contains(event.getTable())) {
27 | return;
28 | }
29 | }
30 |
31 | @Override
32 | public ChangeTypeEnum changeType() {
33 | return ChangeTypeEnum.UPDATE;
34 | }
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-mqconsume-es
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/kitty-cloud-mqconsume-es/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-mqconsume-es
2 |
3 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
4 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
5 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
6 |
7 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-mqconsume-es-application.properties
8 | spring.cloud.nacos.config.ext-config[0].group=APPLICATION_GROUP
9 | spring.cloud.nacos.config.ext-config[0].refresh=true
10 |
11 | rocketmq.name-server=47.105.66.210:9876
12 | rocketmq.producer.group=my-group1
13 | rocketmq.producer.sendMessageTimeout=300000
14 |
15 | rocketmq.topic.data_change=data_change
16 | rocketmq.group.data_change_consumer=data_change_consumer
--------------------------------------------------------------------------------
/kitty-cloud-mqconsume/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-mqconsume
13 | pom
14 |
15 | kitty-cloud-mqconsume-es
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-search
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-search-api
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 | true
19 |
20 |
21 |
22 | com.spring4all
23 | swagger-spring-boot-starter
24 |
25 |
26 |
27 | com.cxytiandi
28 | kitty-spring-cloud-starter-feign
29 |
30 |
31 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/java/com/cxytiandi/kittycloud/search/api/autoconfigure/RemoteServiceAutoConfigure.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.api.autoconfigure;
2 |
3 | import org.springframework.cloud.openfeign.EnableFeignClients;
4 | import org.springframework.context.annotation.ComponentScan;
5 |
6 | /**
7 | * Feign Client自动初始化
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-13 20:44:04
15 | */
16 | @EnableFeignClients("com.cxytiandi.kittycloud.search.api")
17 | @ComponentScan("com.cxytiandi.kittycloud.search.api")
18 | public class RemoteServiceAutoConfigure {
19 |
20 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/java/com/cxytiandi/kittycloud/search/api/request/ArticleIndexSaveRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.api.request;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.List;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-10 23:47
15 | */
16 | @Data
17 | public class ArticleIndexSaveRequest implements Serializable {
18 |
19 | private Long id;
20 |
21 | /**
22 | * 标题
23 | */
24 | private String title;
25 |
26 | /**
27 | * 类型
28 | */
29 | private int type;
30 |
31 | /**
32 | * 用户ID
33 | */
34 | private Long userId;
35 |
36 | /**
37 | * 标签
38 | */
39 | private List tags;
40 |
41 | /**
42 | * 文本内容
43 | */
44 | private String textContent;
45 |
46 | /**
47 | * 文章状态
48 | */
49 | private int status;
50 |
51 | /**
52 | * 热度值(点赞数+评论数+访问数)
53 | */
54 | private Integer heat;
55 |
56 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/java/com/cxytiandi/kittycloud/search/api/request/ArticleIndexSearchRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.api.request;
2 |
3 | import com.cxytiandi.kittycloud.common.base.PageEntity;
4 | import lombok.Data;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-10 23:47
15 | */
16 | @Data
17 | public class ArticleIndexSearchRequest extends PageEntity implements Serializable {
18 |
19 | /**
20 | * 搜索词
21 | */
22 | private String keyword;
23 |
24 | /**
25 | * 类型
26 | */
27 | private int type;
28 |
29 | /**
30 | * 标签
31 | */
32 | private String tag;
33 |
34 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/java/com/cxytiandi/kittycloud/search/api/response/ArticleIndexResponse.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.api.response;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-24 23:50
12 | */
13 | @Data
14 | public class ArticleIndexResponse {
15 |
16 | private Long id;
17 |
18 | /**
19 | * 标题
20 | */
21 | private String title;
22 |
23 | /**
24 | * 类型
25 | */
26 | private int type;
27 |
28 | /**
29 | * 用户ID
30 | */
31 | private Long userId;
32 |
33 | /**
34 | * 标签(多个英文逗号分隔)
35 | */
36 | private String tags;
37 |
38 | /**
39 | * 文本内容
40 | */
41 | private String textContent;
42 |
43 | /**
44 | * 文章状态
45 | */
46 | private int status;
47 |
48 | /**
49 | * 热度值(点赞数+评论数+访问数)
50 | */
51 | private Integer heat;
52 |
53 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/java/com/cxytiandi/kittycloud/search/api/service/ArticleIndexRemoteService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.api.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import com.cxytiandi.kittycloud.search.api.fallback.ArticleIndexRemoteServiceFallbackFactory;
6 | import com.cxytiandi.kittycloud.search.api.request.ArticleIndexSaveRequest;
7 | import com.cxytiandi.kittycloud.search.api.request.ArticleIndexSearchRequest;
8 | import com.cxytiandi.kittycloud.search.api.response.ArticleIndexResponse;
9 | import org.springframework.cloud.openfeign.FeignClient;
10 | import org.springframework.cloud.openfeign.SpringQueryMap;
11 | import org.springframework.web.bind.annotation.GetMapping;
12 | import org.springframework.web.bind.annotation.PostMapping;
13 | import org.springframework.web.bind.annotation.RequestBody;
14 |
15 | /**
16 | * 文章索引RPC/REST接口
17 | *
18 | * @作者 尹吉欢
19 | * @个人微信 jihuan900
20 | * @微信公众号 猿天地
21 | * @GitHub https://github.com/yinjihuan
22 | * @作者介绍 http://cxytiandi.com/about
23 | * @时间 2020-03-10 23:40
24 | */
25 | @FeignClient(name = "kitty-cloud-search-provider", fallbackFactory = ArticleIndexRemoteServiceFallbackFactory.class)
26 | public interface ArticleIndexRemoteService {
27 |
28 | /**
29 | * 保存文章索引
30 | * @param request
31 | * @return
32 | */
33 | @PostMapping("/articles")
34 | ResponseData saveArticleIndex(@RequestBody ArticleIndexSaveRequest request);
35 |
36 | /**
37 | * 搜索文章
38 | * @param request
39 | * @return
40 | */
41 | @GetMapping("/articles")
42 | ResponseData> searchArticleIndex(@SpringQueryMap ArticleIndexSearchRequest request);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-api/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.cxytiandi.kittycloud.search.api.autoconfigure.RemoteServiceAutoConfigure
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/bo/ArticleIndexBO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.bo;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @作者 尹吉欢
7 | * @个人微信 jihuan900
8 | * @微信公众号 猿天地
9 | * @GitHub https://github.com/yinjihuan
10 | * @作者介绍 http://cxytiandi.com/about
11 | * @时间 2020-03-24 23:00
12 | */
13 | @Data
14 | public class ArticleIndexBO {
15 |
16 | private Long id;
17 |
18 | /**
19 | * 标题
20 | */
21 | private String title;
22 |
23 | /**
24 | * 类型
25 | */
26 | private int type;
27 |
28 | /**
29 | * 用户ID
30 | */
31 | private Long userId;
32 |
33 | /**
34 | * 标签(多个英文逗号分隔)
35 | */
36 | private String tags;
37 |
38 | /**
39 | * 文本内容
40 | */
41 | private String textContent;
42 |
43 | /**
44 | * 文章状态
45 | */
46 | private int status;
47 |
48 | /**
49 | * 热度值(点赞数+评论数+访问数)
50 | */
51 | private Integer heat;
52 |
53 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/config/ElasticSearchIndexConfig.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.config;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | /**
8 | * ES 索引配置
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-10 21:18
16 | */
17 | @Data
18 | @Configuration
19 | @ConfigurationProperties("kitty.cloud.search.es")
20 | public class ElasticSearchIndexConfig {
21 |
22 | /**
23 | * 文章搜索索引名(搜索和保存分开,方便重建索引)
24 | */
25 | private String articleSearchIndexName;
26 |
27 | /**
28 | * 文章保存索引名(搜索和保存分开,方便重建索引)
29 | */
30 | private String articleSaveIndexName;
31 |
32 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/convert/ArticleDocumentConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.search.biz.document.ArticleDocument;
5 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSaveParam;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-10 22:50
16 | */
17 | @Component
18 | public class ArticleDocumentConvert implements EntityConvert {
19 |
20 | @Override
21 | public ArticleDocument convert(ArticleIndexSaveParam source) {
22 | ArticleDocument document = new ArticleDocument();
23 | BeanUtils.copyProperties(source, document);
24 | return document;
25 | }
26 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/convert/ArticleIndexBOConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.search.biz.bo.ArticleIndexBO;
5 | import com.cxytiandi.kittycloud.search.biz.document.ArticleDocument;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-24 23:43
16 | */
17 | @Component
18 | public class ArticleIndexBOConvert implements EntityConvert {
19 |
20 | @Override
21 | public ArticleIndexBO convert(ArticleDocument source) {
22 | ArticleIndexBO articleIndexBO = new ArticleIndexBO();
23 | BeanUtils.copyProperties(source, articleIndexBO);
24 | return articleIndexBO;
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/dao/ArticleIndexDao.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.dao;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.search.biz.bo.ArticleIndexBO;
5 | import com.cxytiandi.kittycloud.search.biz.document.ArticleDocument;
6 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSearchParam;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-10 22:48
15 | */
16 | public interface ArticleIndexDao {
17 |
18 | /**
19 | * 保存文章索引
20 | * @param document
21 | * @return
22 | */
23 | Boolean saveArticleIndex(ArticleDocument document);
24 |
25 | /**
26 | * 搜索文章
27 | * @param param
28 | * @return
29 | */
30 | Page searchArticleIndex(ArticleIndexSearchParam param);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/document/ArticleDocument.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.document;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 文章ES Document
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-10 21:33
16 | */
17 | @Data
18 | public class ArticleDocument {
19 |
20 | private Long id;
21 |
22 | /**
23 | * 标题
24 | */
25 | private String title;
26 |
27 | /**
28 | * 类型
29 | */
30 | private int type;
31 |
32 | /**
33 | * 用户ID
34 | */
35 | private Long userId;
36 |
37 | /**
38 | * 标签
39 | */
40 | private List tags;
41 |
42 | /**
43 | * 文本内容
44 | */
45 | private String textContent;
46 |
47 | /**
48 | * 文章状态
49 | */
50 | private int status;
51 |
52 | /**
53 | * 热度值(点赞数+评论数+访问数)
54 | */
55 | private Integer heat;
56 |
57 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/param/ArticleIndexSaveParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.param;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 文章索引保存参数
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-10 21:10
16 | */
17 | @Data
18 | public class ArticleIndexSaveParam {
19 |
20 | private Long id;
21 |
22 | /**
23 | * 标题
24 | */
25 | private String title;
26 |
27 | /**
28 | * 类型
29 | */
30 | private int type;
31 |
32 | /**
33 | * 用户ID
34 | */
35 | private Long userId;
36 |
37 | /**
38 | * 标签
39 | */
40 | private List tags;
41 |
42 | /**
43 | * 文本内容
44 | */
45 | private String textContent;
46 |
47 | /**
48 | * 文章状态
49 | */
50 | private int status;
51 |
52 | /**
53 | * 热度值(点赞数+评论数+访问数)
54 | */
55 | private Integer heat;
56 |
57 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/param/ArticleIndexSearchParam.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.param;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-03-10 23:47
14 | */
15 | @Data
16 | public class ArticleIndexSearchParam implements Serializable {
17 |
18 | /**
19 | * 搜索词
20 | */
21 | private String keyword;
22 |
23 | /**
24 | * 类型
25 | */
26 | private int type;
27 |
28 | /**
29 | * 标签
30 | */
31 | private String tag;
32 |
33 | /**
34 | * 页数
35 | */
36 | private int page;
37 |
38 | /**
39 | * 页大小
40 | */
41 | private int size;
42 |
43 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-biz/src/main/java/com/cxytiandi/kittycloud/search/biz/service/ArticleIndexService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.biz.service;
2 |
3 | import com.cxytiandi.kitty.common.page.Page;
4 | import com.cxytiandi.kittycloud.search.biz.bo.ArticleIndexBO;
5 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSaveParam;
6 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSearchParam;
7 |
8 | /**
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-03-10 20:54
15 | */
16 | public interface ArticleIndexService {
17 |
18 | /**
19 | * 保存文章索引
20 | * @param param
21 | * @return
22 | */
23 | Boolean saveArticleIndex(ArticleIndexSaveParam param);
24 |
25 | /**
26 | * 搜索文章
27 | * @param param
28 | * @return
29 | */
30 | Page searchArticleIndex(ArticleIndexSearchParam param);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/java/com/cxytiandi/kittycloud/search/provider/KittyCloudSearchProviderApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.provider;
2 |
3 | import com.spring4all.swagger.EnableSwagger2Doc;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 |
8 | /**
9 | * 搜索服务启动类
10 | *
11 | * @作者 尹吉欢
12 | * @个人微信 jihuan900
13 | * @微信公众号 猿天地
14 | * @GitHub https://github.com/yinjihuan
15 | * @作者介绍 http://cxytiandi.com/about
16 | * @时间 2020-03-10 21:51
17 | */
18 | @EnableSwagger2Doc
19 | @EnableDiscoveryClient
20 | @SpringBootApplication(scanBasePackages = {"com.cxytiandi.kittycloud.search","com.cxytiandi.kitty.web.config"})
21 | public class KittyCloudSearchProviderApp {
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(KittyCloudSearchProviderApp.class);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/java/com/cxytiandi/kittycloud/search/provider/convert/ArticleIndexResponseConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.search.api.response.ArticleIndexResponse;
5 | import com.cxytiandi.kittycloud.search.biz.bo.ArticleIndexBO;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-24 23:52
16 | */
17 | @Component
18 | public class ArticleIndexResponseConvert implements EntityConvert {
19 |
20 | @Override
21 | public ArticleIndexResponse convert(ArticleIndexBO source) {
22 | ArticleIndexResponse response = new ArticleIndexResponse();
23 | BeanUtils.copyProperties(source, response);
24 | return response;
25 | }
26 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/java/com/cxytiandi/kittycloud/search/provider/convert/ArticleIndexSaveParamConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.search.api.request.ArticleIndexSaveRequest;
5 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSaveParam;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 文章索引保存参数转换器
11 | *
12 | * @作者 尹吉欢
13 | * @个人微信 jihuan900
14 | * @微信公众号 猿天地
15 | * @GitHub https://github.com/yinjihuan
16 | * @作者介绍 http://cxytiandi.com/about
17 | * @时间 2020-03-10 22:45
18 | */
19 | @Component
20 | public class ArticleIndexSaveParamConvert implements EntityConvert {
21 |
22 | @Override
23 | public ArticleIndexSaveParam convert(ArticleIndexSaveRequest source) {
24 | ArticleIndexSaveParam param = new ArticleIndexSaveParam();
25 | BeanUtils.copyProperties(source, param);
26 | return param;
27 | }
28 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/java/com/cxytiandi/kittycloud/search/provider/convert/ArticleIndexSearchParamConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.provider.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.search.api.request.ArticleIndexSearchRequest;
5 | import com.cxytiandi.kittycloud.search.biz.param.ArticleIndexSearchParam;
6 | import org.springframework.beans.BeanUtils;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-03-24 23:48
16 | */
17 | @Component
18 | public class ArticleIndexSearchParamConvert implements EntityConvert {
19 |
20 | @Override
21 | public ArticleIndexSearchParam convert(ArticleIndexSearchRequest source) {
22 | ArticleIndexSearchParam param = new ArticleIndexSearchParam();
23 | BeanUtils.copyProperties(source, param);
24 | return param;
25 | }
26 | }
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-search-provider
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-search-provider
2 |
3 | dubbo.scan.base-packages=com.cxytiandi.kittycloud.search.provider.service
4 | dubbo.protocol.name=dubbo
5 | dubbo.protocol.port=20083
6 | dubbo.registry.address=spring-cloud://localhost
7 |
8 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
9 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
10 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
11 |
12 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-search-provider-application.properties
13 | spring.cloud.nacos.config.ext-config[0].group=APPLICATION_GROUP
14 | spring.cloud.nacos.config.ext-config[0].refresh=true
15 |
16 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-sentinel.properties
17 | spring.cloud.nacos.config.ext-config[1].group=MIDDLEWARE_GROUP
18 | spring.cloud.nacos.config.ext-config[1].refresh=true
19 |
20 | spring.cloud.nacos.config.ext-config[2].data-id=kitty-cloud-elasticsearch.properties
21 | spring.cloud.nacos.config.ext-config[2].group=MIDDLEWARE_GROUP
22 | spring.cloud.nacos.config.ext-config[2].refresh=true
23 |
24 | spring.cloud.nacos.config.ext-config[3].data-id=kitty-cloud-search-elasticsearch-biz.properties
25 | spring.cloud.nacos.config.ext-config[3].group=BIZ_GROUP
26 | spring.cloud.nacos.config.ext-config[3].refresh=true
27 |
--------------------------------------------------------------------------------
/kitty-cloud-search/kitty-cloud-search-provider/src/test/java/com/cxytiandi/kittycloud/search/provider/client/KittyRestHighLevelClientDeleteTest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.search.provider.client;
2 |
3 | import com.cxytiandi.kitty.db.elasticsearch.client.KittyRestHighLevelClient;
4 | import com.cxytiandi.kittycloud.common.constant.EsConstant;
5 | import com.cxytiandi.kittycloud.search.biz.config.ElasticSearchIndexConfig;
6 | import org.elasticsearch.action.DocWriteResponse;
7 | import org.elasticsearch.action.delete.DeleteRequest;
8 | import org.elasticsearch.action.delete.DeleteResponse;
9 | import org.junit.Assert;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.test.context.SpringBootTest;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 |
16 | /**
17 | * KittyRestHighLevelClient Delete 单测
18 | *
19 | * @作者 尹吉欢
20 | * @个人微信 jihuan900
21 | * @微信公众号 猿天地
22 | * @GitHub https://github.com/yinjihuan
23 | * @作者介绍 http://cxytiandi.com/about
24 | * @时间 2020-04-26 23:49
25 | */
26 | @RunWith(SpringRunner.class)
27 | @SpringBootTest
28 | public class KittyRestHighLevelClientDeleteTest {
29 |
30 | @Autowired
31 | private KittyRestHighLevelClient kittyRestHighLevelClient;
32 |
33 | @Autowired
34 | private ElasticSearchIndexConfig elasticSearchIndexConfig;
35 |
36 | @Test
37 | public void testDelete() {
38 | DeleteResponse deleteResponse = kittyRestHighLevelClient.delete(elasticSearchIndexConfig.getArticleSearchIndexName(), EsConstant.DEFAULT_TYPE, "1");
39 | Assert.assertTrue(deleteResponse.getResult() == DocWriteResponse.Result.DELETED);
40 | }
41 |
42 | @Test
43 | public void testDelete2() {
44 | DeleteRequest deleteRequest = new DeleteRequest(elasticSearchIndexConfig.getArticleSearchIndexName(), EsConstant.DEFAULT_TYPE, "1");
45 | DeleteResponse deleteResponse = kittyRestHighLevelClient.delete(deleteRequest);
46 | Assert.assertTrue(deleteResponse.getResult() == DocWriteResponse.Result.DELETED);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/kitty-cloud-search/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-search
13 | pom
14 |
15 | kitty-cloud-search-api
16 | kitty-cloud-search-biz
17 | kitty-cloud-search-provider
18 |
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-common
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-user
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-user-api
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 | true
19 |
20 |
21 |
22 | com.spring4all
23 | swagger-spring-boot-starter
24 |
25 |
26 |
27 | com.cxytiandi
28 | kitty-spring-cloud-starter-feign
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/autoconfigure/RemoteServiceAutoConfigure.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.autoconfigure;
2 |
3 | import org.springframework.cloud.openfeign.EnableFeignClients;
4 | import org.springframework.context.annotation.ComponentScan;
5 |
6 | /**
7 | * Feign Client自动初始化
8 | *
9 | * @作者 尹吉欢
10 | * @个人微信 jihuan900
11 | * @微信公众号 猿天地
12 | * @GitHub https://github.com/yinjihuan
13 | * @作者介绍 http://cxytiandi.com/about
14 | * @时间 2020-02-13 20:44:04
15 | */
16 | @EnableFeignClients("com.cxytiandi.kittycloud.user.api")
17 | @ComponentScan("com.cxytiandi.kittycloud.user.api")
18 | public class RemoteServiceAutoConfigure {
19 |
20 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/fallback/UserRemoteServiceFallbackFactory.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.fallback;
2 |
3 | import com.cxytiandi.kittycloud.common.base.Response;
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 | import com.cxytiandi.kittycloud.common.base.ResponseData;
6 | import com.cxytiandi.kittycloud.user.api.request.UserLoginRequest;
7 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
8 | import com.cxytiandi.kittycloud.user.api.service.UserRemoteService;
9 | import feign.hystrix.FallbackFactory;
10 | import lombok.extern.slf4j.Slf4j;
11 | import org.springframework.stereotype.Component;
12 |
13 | import java.text.MessageFormat;
14 |
15 | /**
16 | * Feign UserRemoteService回退逻辑
17 | * @作者 尹吉欢
18 | * @个人微信 jihuan900
19 | * @微信公众号 猿天地
20 | * @GitHub https://github.com/yinjihuan
21 | * @作者介绍 http://cxytiandi.com/about
22 | * @时间 2020-02-27 20:36
23 | */
24 | @Slf4j
25 | @Component
26 | public class UserRemoteServiceFallbackFactory implements FallbackFactory {
27 |
28 | @Override
29 | public UserRemoteService create(Throwable cause) {
30 | return new UserRemoteService() {
31 | @Override
32 | public ResponseData getUser(Long userId) {
33 | log.error(MessageFormat.format("UserRemoteService.getUser fallback,参数为 [{0}]", userId), cause);
34 | return Response.fail(cause.getMessage(), ResponseCode.SERVER_DOWNGRADE_CODE);
35 | }
36 |
37 | @Override
38 | public ResponseData login(UserLoginRequest loginRequest) {
39 | log.error(MessageFormat.format("UserRemoteService.login fallback,参数为 [{0}]", loginRequest), cause);
40 | return Response.fail(cause.getMessage(), ResponseCode.SERVER_DOWNGRADE_CODE);
41 | }
42 | };
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/request/UserLoginRequest.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.request;
2 |
3 | import lombok.Data;
4 | import lombok.ToString;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * 用户登录Request
10 | *
11 | * @作者 尹吉欢
12 | * @个人微信 jihuan900
13 | * @微信公众号 猿天地
14 | * @GitHub https://github.com/yinjihuan
15 | * @作者介绍 http://cxytiandi.com/about
16 | * @时间 2020-02-13 20:44:04
17 | */
18 | @Data
19 | @ToString
20 | public class UserLoginRequest implements Serializable {
21 |
22 | /**
23 | * 用户名
24 | */
25 | private String username;
26 |
27 | /**
28 | * 密码
29 | */
30 | private String pass;
31 |
32 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/response/UserResponse.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.response;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * 用户Response
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Data
18 | public class UserResponse implements Serializable {
19 |
20 | /**
21 | * 用户ID
22 | */
23 | private Long id;
24 |
25 | /**
26 | * 昵称
27 | */
28 | private String nickname;
29 |
30 | /**
31 | * 年龄
32 | */
33 | private Integer age;
34 |
35 | /**
36 | * 邮箱
37 | */
38 | private String email;
39 |
40 | /**
41 | * 手机
42 | */
43 | private String mobile;
44 |
45 | /**
46 | * 性别
47 | */
48 | private int sex;
49 |
50 | /**
51 | * 个性签名
52 | */
53 | private String sign;
54 |
55 | /**
56 | * 头像地址
57 | */
58 | private String headPhotoUrl;
59 |
60 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/service/UserRemoteService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.service;
2 |
3 | import com.cxytiandi.kittycloud.common.base.ResponseData;
4 | import com.cxytiandi.kittycloud.user.api.fallback.UserRemoteServiceFallbackFactory;
5 | import com.cxytiandi.kittycloud.user.api.request.UserLoginRequest;
6 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
7 | import org.springframework.cloud.openfeign.FeignClient;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.RequestBody;
12 |
13 | /**
14 | * 用户PRC/REST接口
15 | *
16 | * @作者 尹吉欢
17 | * @个人微信 jihuan900
18 | * @微信公众号 猿天地
19 | * @GitHub https://github.com/yinjihuan
20 | * @作者介绍 http://cxytiandi.com/about
21 | * @时间 2020-02-13 20:44:04
22 | */
23 | @FeignClient(name = "kitty-cloud-user-provider", fallbackFactory = UserRemoteServiceFallbackFactory.class)
24 | public interface UserRemoteService {
25 |
26 | /**
27 | * 根据用户ID查询用户
28 | * @param userId 用户ID
29 | * @return
30 | */
31 | @GetMapping("/users/{userId}")
32 | ResponseData getUser(@PathVariable("userId") Long userId);
33 |
34 | /**
35 | * 用户登录
36 | * @param loginRequest 登录参数
37 | * @return token
38 | */
39 | @PostMapping("/users/login")
40 | ResponseData login(@RequestBody UserLoginRequest loginRequest);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/java/com/cxytiandi/kittycloud/user/api/service/UserRemoteServiceMock.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.api.service;
2 |
3 | import com.cxytiandi.kittycloud.common.base.Response;
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 | import com.cxytiandi.kittycloud.common.base.ResponseData;
6 | import com.cxytiandi.kittycloud.user.api.request.UserLoginRequest;
7 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
8 | import lombok.extern.slf4j.Slf4j;
9 |
10 | import java.text.MessageFormat;
11 |
12 | /**
13 | * Dubbo UserRemoteService回退逻辑
14 | *
15 | * @作者 尹吉欢
16 | * @个人微信 jihuan900
17 | * @微信公众号 猿天地
18 | * @GitHub https://github.com/yinjihuan
19 | * @作者介绍 http://cxytiandi.com/about
20 | * @时间 2020-02-27 22:11
21 | */
22 | @Slf4j
23 | public class UserRemoteServiceMock implements UserRemoteService {
24 |
25 | @Override
26 | public ResponseData getUser(Long userId) {
27 | log.error(MessageFormat.format("UserRemoteService.getUser fallback,参数为 [{0}]", userId));
28 | return Response.fail("fallback", ResponseCode.SERVER_DOWNGRADE_CODE);
29 | }
30 |
31 | @Override
32 | public ResponseData login(UserLoginRequest loginRequest) {
33 | return null;
34 | }
35 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-api/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.cxytiandi.kittycloud.user.api.autoconfigure.RemoteServiceAutoConfigure
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-user
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-user-biz
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-spring-cloud-starter-web
18 |
19 |
20 |
21 | com.cxytiandi
22 | kitty-spring-cloud-starter-mybatis
23 |
24 |
25 |
26 | com.cxytiandi
27 | kitty-spring-cloud-starter-nacos
28 |
29 |
30 |
31 | com.cxytiandi
32 | kitty-spring-cloud-starter-jetcache
33 |
34 |
35 |
36 | com.cxytiandi
37 | kitty-spring-cloud-starter-cat
38 |
39 |
40 |
41 | com.cxytiandi
42 | kitty-spring-cloud-starter-dubbo
43 |
44 |
45 |
46 | com.cxytiandi
47 | kitty-spring-cloud-starter-sentinel
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/bo/UserBO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.bo;
2 |
3 | import com.cxytiandi.kittycloud.user.biz.enums.SexEnum;
4 | import com.cxytiandi.kittycloud.user.biz.enums.UserStatusEnum;
5 | import lombok.Data;
6 |
7 | /**
8 | * 用户BO
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Data
18 | public class UserBO {
19 |
20 | /**
21 | * 用户ID
22 | */
23 | private Long id;
24 |
25 | /**
26 | * 昵称
27 | */
28 | private String nickname;
29 |
30 | /**
31 | * 年龄
32 | */
33 | private Integer age;
34 |
35 | /**
36 | * 邮箱
37 | */
38 | private String email;
39 |
40 | /**
41 | * 手机
42 | */
43 | private String mobile;
44 |
45 | /**
46 | * 性别
47 | */
48 | private SexEnum sex;
49 |
50 | /**
51 | * 个性签名
52 | */
53 | private String sign;
54 |
55 | /**
56 | * 头像地址
57 | */
58 | private String headPhotoUrl;
59 |
60 | /**
61 | * 状态
62 | */
63 | private UserStatusEnum status;
64 |
65 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/convert/UserBoConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.convert;
2 |
3 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
4 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
5 | import com.cxytiandi.kittycloud.common.exception.BizException;
6 | import com.cxytiandi.kittycloud.user.biz.bo.UserBO;
7 | import com.cxytiandi.kittycloud.user.biz.dataobject.UserDO;
8 | import org.springframework.beans.BeanUtils;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * 用户BO转换器
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-13 20:44:04
20 | */
21 | @Component
22 | public class UserBoConvert implements EntityConvert {
23 |
24 | @Override
25 | public UserBO convert(UserDO source) {
26 | UserBO target = new UserBO();
27 | BeanUtils.copyProperties(source, target);
28 | return target;
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.dao;
2 |
3 | import com.cxytiandi.kittycloud.user.biz.dataobject.UserDO;
4 |
5 | /**
6 | * 用户DAO
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-13 20:44:04
14 | */
15 | public interface UserDao {
16 |
17 | /**
18 | * 获取用户信息
19 | * @param id 用户ID
20 | * @return 用户DO
21 | */
22 | UserDO getById(Long id);
23 |
24 | /**
25 | * 用户登录
26 | * @param username 用户名
27 | * @param pass 密码
28 | * @return 用户DO
29 | */
30 | UserDO getByUsernameAndPass(String username, String pass);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/dao/impl/UserDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.dao.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.cxytiandi.kittycloud.user.biz.dao.UserDao;
5 | import com.cxytiandi.kittycloud.user.biz.dataobject.UserDO;
6 | import com.cxytiandi.kittycloud.user.biz.mapper.UserMapper;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Repository;
9 |
10 | /**
11 | * 用户DAO实现
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-04-12 20:53
19 | */
20 | @Repository
21 | public class UserDaoImpl implements UserDao {
22 |
23 | @Autowired
24 | private UserMapper userMapper;
25 |
26 | @Override
27 | public UserDO getById(Long id) {
28 | return userMapper.selectById(id);
29 | }
30 |
31 | @Override
32 | public UserDO getByUsernameAndPass(String username, String pass) {
33 | QueryWrapper queryWrapper = new QueryWrapper<>();
34 | queryWrapper.eq("mobile", username).eq("pass", pass);
35 |
36 | return userMapper.selectOne(queryWrapper);
37 | }
38 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/dataobject/UserDO.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.dataobject;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import com.cxytiandi.kittycloud.common.base.Entity;
7 | import com.cxytiandi.kittycloud.user.biz.enums.SexEnum;
8 | import com.cxytiandi.kittycloud.user.biz.enums.UserStatusEnum;
9 | import lombok.Data;
10 |
11 | /**
12 | * 用户DO
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-13 20:44:04
20 | */
21 | @Data
22 | @TableName("user")
23 | public class UserDO extends Entity {
24 |
25 | /**
26 | * 用户ID
27 | */
28 | @TableId(type = IdType.ID_WORKER)
29 | private Long id;
30 |
31 | /**
32 | * 昵称
33 | */
34 | private String nickname;
35 |
36 | /**
37 | * 年龄
38 | */
39 | private Integer age;
40 |
41 | /**
42 | * 邮箱
43 | */
44 | private String email;
45 |
46 | /**
47 | * 手机
48 | */
49 | private String mobile;
50 |
51 | /**
52 | * 密码
53 | */
54 | private String pass;
55 |
56 | /**
57 | * 性别
58 | */
59 | private SexEnum sex;
60 |
61 | /**
62 | * 个性签名
63 | */
64 | private String sign;
65 |
66 | /**
67 | * 头像地址
68 | */
69 | private String headPhotoUrl;
70 |
71 | /**
72 | * 状态
73 | */
74 | private UserStatusEnum status;
75 |
76 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/enums/SexEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.enums;
2 |
3 | import com.baomidou.mybatisplus.annotation.EnumValue;
4 | /**
5 | * 性别枚举
6 | *
7 | * @作者 尹吉欢
8 | * @个人微信 jihuan900
9 | * @微信公众号 猿天地
10 | * @GitHub https://github.com/yinjihuan
11 | * @作者介绍 http://cxytiandi.com/about
12 | * @时间 2020-02-13 20:44:04
13 | */
14 | public enum SexEnum {
15 |
16 | /**
17 | * 男
18 | */
19 | MALE(0, "男"),
20 | /**
21 | * 女
22 | */
23 | FEMALE(1, "女");
24 |
25 | SexEnum(int sex, String descp) {
26 | this.sex = sex;
27 | this.descp = descp;
28 | }
29 |
30 | /**
31 | * 性别
32 | */
33 | @EnumValue
34 | private int sex;
35 |
36 | /**
37 | * 描述
38 | */
39 | private String descp;
40 |
41 | public int getSex() {
42 | return sex;
43 | }
44 |
45 | public String getDescp() {
46 | return descp;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/enums/UserStatusEnum.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.enums;
2 |
3 | import com.baomidou.mybatisplus.annotation.EnumValue;
4 |
5 | /**
6 | * 用户状态枚举
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-13 20:44:04
14 | */
15 | public enum UserStatusEnum {
16 |
17 | /**
18 | * 无效
19 | */
20 | INVALID(0, "无效"),
21 | /**
22 | * 有效
23 | */
24 | VALID(1, "有效");
25 |
26 | UserStatusEnum(int status, String descp) {
27 | this.status = status;
28 | this.descp = descp;
29 | }
30 |
31 | /**
32 | * 状态
33 | */
34 | @EnumValue
35 | private int status;
36 |
37 | /**
38 | * 描述
39 | */
40 | private String descp;
41 |
42 | public String getDescp() {
43 | return descp;
44 | }
45 |
46 | public int getStatus() {
47 | return status;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.cxytiandi.kittycloud.user.biz.dataobject.UserDO;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * 用户Mapper
9 | *
10 | * @作者 尹吉欢
11 | * @个人微信 jihuan900
12 | * @微信公众号 猿天地
13 | * @GitHub https://github.com/yinjihuan
14 | * @作者介绍 http://cxytiandi.com/about
15 | * @时间 2020-02-13 20:44:04
16 | */
17 | @Mapper
18 | public interface UserMapper extends BaseMapper {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.service;
2 |
3 | import com.cxytiandi.kittycloud.user.biz.bo.UserBO;
4 |
5 | /**
6 | * 用户业务接口
7 | *
8 | * @作者 尹吉欢
9 | * @个人微信 jihuan900
10 | * @微信公众号 猿天地
11 | * @GitHub https://github.com/yinjihuan
12 | * @作者介绍 http://cxytiandi.com/about
13 | * @时间 2020-02-13 20:44:04
14 | */
15 | public interface UserService {
16 |
17 | /**
18 | * 获取用户
19 | * @param id 用户ID
20 | * @return
21 | */
22 | UserBO getUser(Long id);
23 |
24 | /**
25 | * 用户登录
26 | * @param username 用户名
27 | * @param pass 密码
28 | * @return
29 | */
30 | String login(String username, String pass);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-biz/src/main/java/com/cxytiandi/kittycloud/user/biz/service/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.biz.service.impl;
2 |
3 | import com.cxytiandi.kittycloud.common.base.ResponseCode;
4 | import com.cxytiandi.kittycloud.common.exception.BizException;
5 | import com.cxytiandi.kittycloud.common.helper.JWTHelper;
6 | import com.cxytiandi.kittycloud.user.biz.bo.UserBO;
7 | import com.cxytiandi.kittycloud.user.biz.convert.UserBoConvert;
8 | import com.cxytiandi.kittycloud.user.biz.dao.UserDao;
9 | import com.cxytiandi.kittycloud.user.biz.dataobject.UserDO;
10 | import com.cxytiandi.kittycloud.user.biz.service.UserService;
11 | import lombok.extern.slf4j.Slf4j;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.stereotype.Service;
14 |
15 | /**
16 | * 用户业务接口实现
17 | *
18 | * @作者 尹吉欢
19 | * @个人微信 jihuan900
20 | * @微信公众号 猿天地
21 | * @GitHub https://github.com/yinjihuan
22 | * @作者介绍 http://cxytiandi.com/about
23 | * @时间 2020-02-13 20:44:04
24 | */
25 | @Slf4j
26 | @Service
27 | public class UserServiceImpl implements UserService {
28 |
29 | @Autowired
30 | private UserDao userDao;
31 |
32 | @Autowired
33 | private UserBoConvert userBoConvert;
34 |
35 | @Autowired
36 | private JWTHelper jwtHelper;
37 |
38 | @Override
39 | public UserBO getUser(Long id) {
40 | log.info("查询用户 [{}]", id);
41 | if (id == null) {
42 | throw new BizException(ResponseCode.PARAM_ERROR_CODE, "id不能为空");
43 | }
44 |
45 | UserDO userDO = userDao.getById(id);
46 | if (userDO == null) {
47 | throw new BizException(ResponseCode.NOT_FOUND_CODE);
48 | }
49 |
50 | return userBoConvert.convert(userDO);
51 | }
52 |
53 | @Override
54 | public String login(String username, String pass) {
55 | UserDO userDO = userDao.getByUsernameAndPass(username, pass);
56 | if (userDO == null) {
57 | throw new BizException(ResponseCode.USER_LOGIN_ERROR_CODE);
58 | }
59 |
60 | return jwtHelper.getToken(userDO.getId().toString());
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud-user
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-user-provider
13 |
14 |
15 |
16 | com.cxytiandi
17 | kitty-cloud-user-api
18 | 1.0-SNAPSHOT
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-user-biz
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/java/com/cxytiandi/kittycloud/user/provider/KittyCloudUserProviderApp.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.provider;
2 |
3 | import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
4 | import com.alicp.jetcache.anno.config.EnableMethodCache;
5 | import com.spring4all.swagger.EnableSwagger2Doc;
6 | import org.mybatis.spring.annotation.MapperScan;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10 |
11 | /**
12 | * 用户服务启动类
13 | *
14 | * @作者 尹吉欢
15 | * @个人微信 jihuan900
16 | * @微信公众号 猿天地
17 | * @GitHub https://github.com/yinjihuan
18 | * @作者介绍 http://cxytiandi.com/about
19 | * @时间 2020-02-13 20:44:04
20 | */
21 | @MapperScan("com.cxytiandi.kittycloud.user.biz.mapper")
22 | @EnableDiscoveryClient
23 | @EnableSwagger2Doc
24 | @EnableCreateCacheAnnotation
25 | @EnableMethodCache(basePackages = "com.cxytiandi.kittycloud.user.biz.manager")
26 | @SpringBootApplication(scanBasePackages = {"com.cxytiandi.kittycloud.user","com.cxytiandi.kitty.web.config"})
27 | public class KittyCloudUserProviderApp {
28 |
29 | public static void main(String[] args) {
30 | SpringApplication.run(KittyCloudUserProviderApp.class);
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/java/com/cxytiandi/kittycloud/user/provider/convert/UserResponseConvert.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.provider.convert;
2 |
3 |
4 | import com.cxytiandi.kittycloud.common.base.EntityConvert;
5 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
6 | import com.cxytiandi.kittycloud.user.biz.bo.UserBO;
7 | import org.springframework.beans.BeanUtils;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * 用户Response转换器
12 | *
13 | * @作者 尹吉欢
14 | * @个人微信 jihuan900
15 | * @微信公众号 猿天地
16 | * @GitHub https://github.com/yinjihuan
17 | * @作者介绍 http://cxytiandi.com/about
18 | * @时间 2020-02-13 20:44:04
19 | */
20 | @Component
21 | public class UserResponseConvert implements EntityConvert {
22 |
23 | @Override
24 | public UserResponse convert(UserBO source) {
25 | UserResponse target = new UserResponse();
26 | BeanUtils.copyProperties(source, target);
27 | return target;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/java/com/cxytiandi/kittycloud/user/provider/service/UserRemoteServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.cxytiandi.kittycloud.user.provider.service;
2 |
3 | import com.cxytiandi.kittycloud.common.base.Response;
4 | import com.cxytiandi.kittycloud.common.base.ResponseData;
5 | import com.cxytiandi.kittycloud.common.constant.DubboConstant;
6 | import com.cxytiandi.kittycloud.user.api.request.UserLoginRequest;
7 | import com.cxytiandi.kittycloud.user.api.response.UserResponse;
8 | import com.cxytiandi.kittycloud.user.api.service.UserRemoteService;
9 | import com.cxytiandi.kittycloud.user.biz.bo.UserBO;
10 | import com.cxytiandi.kittycloud.user.biz.service.UserService;
11 | import com.cxytiandi.kittycloud.user.provider.convert.UserResponseConvert;
12 | import org.apache.dubbo.config.annotation.Service;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.web.bind.annotation.RestController;
15 |
16 | /**
17 | * 用户PRC/REST接口实现
18 | *
19 | * @作者 尹吉欢
20 | * @个人微信 jihuan900
21 | * @微信公众号 猿天地
22 | * @GitHub https://github.com/yinjihuan
23 | * @作者介绍 http://cxytiandi.com/about
24 | * @时间 2020-02-13 20:44:04
25 | */
26 | @Service(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, timeout = 3000)
27 | @RestController
28 | public class UserRemoteServiceImpl implements UserRemoteService {
29 |
30 | @Autowired
31 | private UserService userService;
32 |
33 | @Autowired
34 | private UserResponseConvert userResponseConvert;
35 |
36 | @Override
37 | public ResponseData getUser(Long userId) {
38 | UserBO user = userService.getUser(userId);
39 | return Response.ok(userResponseConvert.convert(user));
40 | }
41 |
42 | @Override
43 | public ResponseData login(UserLoginRequest loginRequest) {
44 | return Response.ok(userService.login(loginRequest.getUsername(), loginRequest.getPass()));
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/resources/META-INF/app.properties:
--------------------------------------------------------------------------------
1 | app.name=kitty-cloud-user-provider
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=kitty-cloud-user-provider
2 |
3 | dubbo.scan.base-packages=com.cxytiandi.kittycloud.user.provider.service
4 | dubbo.protocol.name=dubbo
5 | dubbo.protocol.port=20080
6 | dubbo.registry.address=spring-cloud://localhost
7 |
8 | spring.cloud.nacos.discovery.server-addr=47.105.66.210:8848
9 | spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.discovery.server-addr}
10 | spring.cloud.sentinel.datasource.nacos.server-addr=${spring.cloud.nacos.discovery.server-addr}
11 |
12 | spring.cloud.nacos.config.ext-config[0].data-id=kitty-cloud-mysql.properties
13 | spring.cloud.nacos.config.ext-config[0].group=MIDDLEWARE_GROUP
14 | spring.cloud.nacos.config.ext-config[0].refresh=true
15 |
16 | spring.cloud.nacos.config.ext-config[1].data-id=kitty-cloud-user-provider-application.properties
17 | spring.cloud.nacos.config.ext-config[1].group=APPLICATION_GROUP
18 | spring.cloud.nacos.config.ext-config[1].refresh=true
19 |
20 | spring.cloud.nacos.config.ext-config[2].data-id=kitty-cloud-redis-jetcache.properties
21 | spring.cloud.nacos.config.ext-config[2].group=MIDDLEWARE_GROUP
22 | spring.cloud.nacos.config.ext-config[2].refresh=true
23 |
24 | spring.cloud.nacos.config.ext-config[3].data-id=kitty-cloud-sentinel.properties
25 | spring.cloud.nacos.config.ext-config[3].group=MIDDLEWARE_GROUP
26 | spring.cloud.nacos.config.ext-config[3].refresh=true
27 |
28 | spring.cloud.nacos.config.ext-config[4].data-id=kitty-cloud-user-jwt-rsa-biz.properties
29 | spring.cloud.nacos.config.ext-config[4].group=BIZ_GROUP
30 | spring.cloud.nacos.config.ext-config[4].refresh=true
31 |
32 | dubbo.provider.filter=tracing
33 | dubbo.consumer.filter=tracing
--------------------------------------------------------------------------------
/kitty-cloud-user/kitty-cloud-user-provider/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ${FILE_LOG_PATTERN}
15 |
16 |
17 |
18 | ${LOG_HOME_PATH}/${APP_NAME}-debug.%d{yyyy-MM-dd}.log
19 | 60
20 |
21 |
22 |
23 | DEBUG
24 | ACCEPT
25 | DENY
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/kitty-cloud-user/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | kitty-cloud
7 | com.cxytiandi
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | kitty-cloud-user
13 | pom
14 |
15 | kitty-cloud-user-api
16 | kitty-cloud-user-biz
17 | kitty-cloud-user-provider
18 |
19 |
20 |
21 |
22 | com.cxytiandi
23 | kitty-cloud-common
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/script/table.sql:
--------------------------------------------------------------------------------
1 | create table `user`(
2 | id bigint(20) not null,
3 | nickname varchar(20) not null comment '昵称',
4 | pass varchar(200) not null comment '密码',
5 | status tinyint(1) not null comment '状态',
6 | mobile varchar(11) null comment '手机',
7 | email varchar(30) not null comment '邮箱',
8 | sex tinyint(1) not null comment '性别',
9 | age int(11) not null comment '年龄',
10 | sign varchar(100) null comment '个性签名',
11 | head_photo_url varchar(100) null comment '头像',
12 | add_time datetime not null comment '添加时间',
13 | update_time datetime not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间',
14 | PRIMARY KEY (`id`)
15 | )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 comment='用户';
16 |
17 | create table article(
18 | id bigint(20) not null auto_increment,
19 | type varchar(20) not null comment '文章类型(原创,转载,翻译)',
20 | title varchar(50) not null comment '标题',
21 | status tinyint(1) not null DEFAULT 1 comment '是否可见',
22 | visit_count int(11) not null DEFAULT 0 comment '访问次数',
23 | userId bigint(20) not null comment '用户ID',
24 | tags varchar(100) not null comment '标签',
25 | content longtext not null comment '内容(包含HTML)',
26 | text_content text not null comment '文本内容',
27 | heat int(11) not null comment '热度值(点赞数+评论数+访问数)',
28 | add_time datetime not null comment '添加时间',
29 | update_time datetime not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间',
30 | PRIMARY KEY (`id`)
31 | )ENGINE=InnoDB DEFAULT CHARSET=utf8 comment='文章表';
--------------------------------------------------------------------------------