作者 tangxvhui

调整handler返回

正在显示 32 个修改的文件 包含 123 行增加49 行删除
@@ -72,6 +72,12 @@ service Core { @@ -72,6 +72,12 @@ service Core {
72 @doc "小程序所有的定性标签" 72 @doc "小程序所有的定性标签"
73 @handler MiniAllArticleTag 73 @handler MiniAllArticleTag
74 get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse) 74 get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
  75 +
  76 + @doc "小程序首页数据展示"
  77 + @handler MinishowHomePage
  78 + get /show/home_page (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
  79 +
  80 +
75 } 81 }
76 82
77 // 管理后台接口 83 // 管理后台接口
@@ -424,4 +424,8 @@ type ( @@ -424,4 +424,8 @@ type (
424 Action string `json:"action"` //编辑类型 424 Action string `json:"action"` //编辑类型
425 UpdatedAt string `json:"updatedAt"` //编辑时间 425 UpdatedAt string `json:"updatedAt"` //编辑时间
426 } 426 }
427 -)  
  427 +)
  428 +
  429 +//小程序端 首页数据展示
  430 +// 统计各标签下的文章数量,和已被人员阅读的数量
  431 +type
@@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniAllArticleTagRequest 16 var req types.MiniAllArticleTagRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleBackupSearchRequest 16 var req types.MiniArticleBackupSearchRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 token := contextdata.GetUserTokenFromCtx(r.Context()) 21 token := contextdata.GetUserTokenFromCtx(r.Context())
1 package article 1 package article
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"  
5 "net/http" 4 "net/http"
6 5
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  7 +
7 "github.com/zeromicro/go-zero/rest/httpx" 8 "github.com/zeromicro/go-zero/rest/httpx"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
@@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
14 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
15 var req types.MiniArticleMarkListRequest 16 var req types.MiniArticleMarkListRequest
16 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
17 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
18 return 19 return
19 } 20 }
20 21
@@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
16 return func(w http.ResponseWriter, r *http.Request) { 16 return func(w http.ResponseWriter, r *http.Request) {
17 var req types.MiniArticleMarkUserReadRequest 17 var req types.MiniArticleMarkUserReadRequest
18 if err := httpx.Parse(r, &req); err != nil { 18 if err := httpx.Parse(r, &req); err != nil {
19 - httpx.ErrorCtx(r.Context(), w, err) 19 + result.HttpResult(r, w, nil, err)
20 return 20 return
21 } 21 }
22 22
@@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleSearchMeRequest 16 var req types.MiniArticleSearchMeRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleSetTagRequest 16 var req types.MiniArticleSetTagRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleDraftCreateRequest 16 var req types.MiniArticleDraftCreateRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleCreateRequest 16 var req types.MiniArticleCreateRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 token := contextdata.GetUserTokenFromCtx(r.Context()) 21 token := contextdata.GetUserTokenFromCtx(r.Context())
@@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleDraftDeleteMeRequest 16 var req types.MiniArticleDraftDeleteMeRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -7,22 +7,23 @@ import ( @@ -7,22 +7,23 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
10 ) 12 )
11 13
12 func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
13 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
14 var req types.MiniArticleDraftGetMeRequest 16 var req types.MiniArticleDraftGetMeRequest
15 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
16 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
17 return 19 return
18 } 20 }
19 21
20 l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx) 22 l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.AuthorId = token.UserId
  25 + req.CompanyId = token.CompanyId
21 resp, err := l.MiniGetArticleDraftMe(&req) 26 resp, err := l.MiniGetArticleDraftMe(&req)
22 - if err != nil {  
23 - httpx.ErrorCtx(r.Context(), w, err)  
24 - } else {  
25 - httpx.OkJsonCtx(r.Context(), w, resp)  
26 - } 27 + result.HttpResult(r, w, resp, err)
27 } 28 }
28 } 29 }
@@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleGetRequest 16 var req types.MiniArticleGetRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleDraftSearchMeRequest 16 var req types.MiniArticleDraftSearchMeRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniSetUserLikeRequset 16 var req types.MiniSetUserLikeRequset
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleDraftUpdateRequest 16 var req types.MiniArticleDraftUpdateRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx) 21 l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx)
@@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniUserLikeArticleRequest 16 var req types.MiniUserLikeArticleRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniArticleCommentAtWhoRequest 16 var req types.MiniArticleCommentAtWhoRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniCreateArticleCommentRequest 16 var req types.MiniCreateArticleCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx) 21 l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx)
@@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniDeleteArticleCommentRequest 16 var req types.MiniDeleteArticleCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniGetArticleCommentRequest 16 var req types.MiniGetArticleCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniListArticleCommentRequest 16 var req types.MiniListArticleCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) 21 l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
@@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.MiniTop5ArticleCommentRequest 16 var req types.MiniTop5ArticleCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.TagCreateRequest 16 var req types.TagCreateRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.TagDeleteRequest 16 var req types.TagDeleteRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.TagEditRequest 16 var req types.TagEditRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.TagGetRequest 16 var req types.TagGetRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 token := contextdata.GetUserTokenFromCtx(r.Context()) 21 token := contextdata.GetUserTokenFromCtx(r.Context())
@@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.TagListRequest 16 var req types.TagListRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string { @@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string {
53 } 53 }
54 return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") 54 return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
55 } 55 }
  56 +
  57 +// 统计所有已有标签的文章和人员已读的文章
  58 +type CountArticleTagRead struct {
  59 + TotalArticle int `gorm:"total_article"` //标签下文章的数量
  60 + ReadArticle int `gorm:"read_article"` //人员已读的文章
  61 + TagId int64 `gorm:"tag_id"` // 标签的id
  62 +}
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "fmt"
5 6
6 "github.com/jinzhu/copier" 7 "github.com/jinzhu/copier"
7 "github.com/pkg/errors" 8 "github.com/pkg/errors"
@@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic @@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic
132 return to, err 133 return to, err
133 } 134 }
134 135
  136 +// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
  137 +func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) {
  138 +
  139 + sqlStr := `
  140 +-- 首页统计数据
  141 +with
  142 +-- 按查看权限查询文章
  143 +-- 获取有标签的文章
  144 +-- 过滤出可展示的文章id
  145 +t_article_and_tag_2 as (
  146 + select article_and_tag.article_id , article_and_tag.tag_id
  147 + from article_and_tag
  148 + join article on article_and_tag.article_id = article.id
  149 + where article.deleted_at=0
  150 + and article.company_id =1598224576532189184
  151 + and article."show" =0
  152 + and (article.target_user =0 or article.who_read @>'[1]')
  153 +),
  154 +-- 查询人员已查看的文章
  155 +t_user_read as(
  156 + select user_read_article.article_id from user_read_article where user_read_article.user_id =1
  157 +)
  158 +-- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量
  159 +select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id
  160 +from t_article_and_tag_2
  161 +left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
  162 +group by t_article_and_tag_2.tag_id
  163 +`
  164 + condition := []interface{}{
  165 + companyId,
  166 + fmt.Sprintf("[%d]", userId),
  167 + userId,
  168 + }
  169 +
  170 + m := []*models.CountArticleTagRead{}
  171 + db := conn.DB()
  172 + result := db.Raw(sqlStr, condition...).Scan(&m)
  173 + if result.Error != nil {
  174 + return nil, result.Error
  175 + }
  176 +
  177 + var dm []*domain.CountArticleTagRead
  178 +
  179 + for _, val := range m {
  180 + dm = append(dm, &domain.CountArticleTagRead{
  181 + TagId: val.TagId,
  182 + TotalArticle: val.TotalArticle,
  183 + ReadArticle: val.ReadArticle,
  184 + })
  185 + }
  186 + return dm, nil
  187 +}
  188 +
135 func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository { 189 func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository {
136 return &ArticleAndTagRepository{CachedRepository: cache} 190 return &ArticleAndTagRepository{CachedRepository: cache}
137 } 191 }
@@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor @@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor
278 return &ArticleRepository{CachedRepository: cache} 278 return &ArticleRepository{CachedRepository: cache}
279 } 279 }
280 280
  281 +// -- 首页统计数据
281 // with 282 // with
282 // -- 按查看权限查询文章 283 // -- 按查看权限查询文章
283 -// t_article as(  
284 -// select article.id  
285 -// from article 284 +// -- 获取有标签的文章
  285 +// -- 过滤出可展示的文章id
  286 +// t_article_and_tag_2 as (
  287 +// select article_and_tag.article_id , article_and_tag.tag_id
  288 +// from article_and_tag
  289 +// join article on article_and_tag.article_id = article.id
286 // where article.deleted_at=0 290 // where article.deleted_at=0
287 // and article.company_id =1598224576532189184 291 // and article.company_id =1598224576532189184
288 // and article."show" =0 292 // and article."show" =0
289 // and (article.target_user =0 or article.who_read @>'[1]') 293 // and (article.target_user =0 or article.who_read @>'[1]')
290 // ), 294 // ),
291 -// -- 获取有标签的文章  
292 -// t_article_and_tag as (  
293 -// select article_and_tag.article_id ,article_and_tag.tag_id  
294 -// from article_and_tag  
295 -// where article_and_tag.company_id =1598224576532189184  
296 -// ),  
297 -// -- 过滤出可展示的文章id  
298 -// t_article_and_tag_2 as (  
299 -// select t_article_and_tag.article_id, t_article_and_tag.tag_id  
300 -// from t_article_and_tag  
301 -// join t_article on t_article_and_tag.article_id = t_article.id  
302 -// ),  
303 // -- 查询人员已查看的文章 295 // -- 查询人员已查看的文章
304 // t_user_read as( 296 // t_user_read as(
305 -// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 297 +// select user_read_article.article_id from user_read_article where user_read_article.user_id =1
306 // ) 298 // )
307 // -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量 299 // -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量
308 // select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id 300 // select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id
309 // from t_article_and_tag_2 301 // from t_article_and_tag_2
310 // left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id 302 // left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
311 // group by t_article_and_tag_2.tag_id 303 // group by t_article_and_tag_2.tag_id
  304 +// ;
@@ -16,10 +16,18 @@ type ArticleAndTag struct { @@ -16,10 +16,18 @@ type ArticleAndTag struct {
16 TagId int64 `json:"tagId"` 16 TagId int64 `json:"tagId"`
17 } 17 }
18 18
  19 +// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
  20 +type CountArticleTagRead struct {
  21 + TotalArticle int `gorm:"total_article"` //标签下文章的数量
  22 + ReadArticle int `gorm:"read_article"` //人员已读的文章
  23 + TagId int64 `gorm:"tag_id"` // 标签的id
  24 +}
  25 +
19 type ArticleAndTagRepository interface { 26 type ArticleAndTagRepository interface {
20 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) 27 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
21 Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) 28 Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
22 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) 29 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
23 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error) 30 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error)
24 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error) 31 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error)
  32 + CountArticleReadGroupByTag(ctx context.Context, con transaction.Conn, userId int64, companyId int64) ([]*CountArticleTagRead, error)
25 } 33 }