From 8e7ec767743c5a826746c92d3457864975ecd1bc Mon Sep 17 00:00:00 2001 From: aisensiy Date: Mon, 21 Aug 2017 17:25:00 +0800 Subject: [PATCH] refactor query mappers --- .../application/ArticleQueryService.java | 10 ++--- .../mapper/ArticleFavoritesQueryService.xml | 8 +--- .../resources/mapper/ArticleReadService.xml | 29 ++------------ .../resources/mapper/CommentReadService.xml | 12 +----- src/main/resources/mapper/TransferData.xml | 39 +++++++++++++++++++ 5 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 src/main/resources/mapper/TransferData.xml diff --git a/src/main/java/io/spring/application/ArticleQueryService.java b/src/main/java/io/spring/application/ArticleQueryService.java index 0e82cae..110329b 100644 --- a/src/main/java/io/spring/application/ArticleQueryService.java +++ b/src/main/java/io/spring/application/ArticleQueryService.java @@ -2,11 +2,10 @@ package io.spring.application; import io.spring.application.data.ArticleData; import io.spring.application.data.ArticleDataList; -import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService; import io.spring.core.user.User; import io.spring.infrastructure.mybatis.readservice.ArticleReadService; -import lombok.Data; -import lombok.NoArgsConstructor; +import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService; +import lombok.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -130,9 +129,8 @@ public class ArticleQueryService { } } -@Data -@NoArgsConstructor +@Value class ArticleFavoriteCount { private String id; - private int count; + private Integer count; } \ No newline at end of file diff --git a/src/main/resources/mapper/ArticleFavoritesQueryService.xml b/src/main/resources/mapper/ArticleFavoritesQueryService.xml index faf7340..e7247b8 100644 --- a/src/main/resources/mapper/ArticleFavoritesQueryService.xml +++ b/src/main/resources/mapper/ArticleFavoritesQueryService.xml @@ -7,7 +7,7 @@ - select A.id, count(AF.user_id) as favoriteCount from articles A left join article_favorites AF on A.id = AF.article_id where id in @@ -27,10 +27,4 @@ and AF.user_id = #{currentUser.id} - - - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/ArticleReadService.xml b/src/main/resources/mapper/ArticleReadService.xml index cde823b..d7819a3 100644 --- a/src/main/resources/mapper/ArticleReadService.xml +++ b/src/main/resources/mapper/ArticleReadService.xml @@ -25,11 +25,11 @@ left join users U on U.id = A.user_id - where A.id = #{id} - where A.slug = #{slug} @@ -79,7 +79,7 @@ - where A.id in @@ -87,7 +87,7 @@ order by A.created_at desc - where A.user_id in @@ -105,25 +105,4 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/CommentReadService.xml b/src/main/resources/mapper/CommentReadService.xml index 06e8763..1e47227 100644 --- a/src/main/resources/mapper/CommentReadService.xml +++ b/src/main/resources/mapper/CommentReadService.xml @@ -12,20 +12,12 @@ on C.user_id = U.id - where C.id = #{id} - where C.article_id = #{articleId} - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/TransferData.xml b/src/main/resources/mapper/TransferData.xml new file mode 100644 index 0000000..719486c --- /dev/null +++ b/src/main/resources/mapper/TransferData.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file