作者 tangxvhui

更新 列表的查询逻辑

@@ -417,6 +417,7 @@ type ( @@ -417,6 +417,7 @@ type (
417 Tags []int64 `json:"tags,optional"` //标签 417 Tags []int64 `json:"tags,optional"` //标签
418 Page int `json:"page"` //页码 418 Page int `json:"page"` //页码
419 Size int `json:"size"` //每页行数 419 Size int `json:"size"` //每页行数
  420 + OrderMode string `json:"orderMode"` //排序方式
420 } 421 }
421 422
422 SystemArticleSearchResponse { 423 SystemArticleSearchResponse {
@@ -39,6 +39,9 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) @@ -39,6 +39,9 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest)
39 if err != nil { 39 if err != nil {
40 return nil, xerr.NewErrMsgErr("获取文章汇总数量失败", err) 40 return nil, xerr.NewErrMsgErr("获取文章汇总数量失败", err)
41 } 41 }
  42 +
  43 + //TODO 拆分统计
  44 +
42 countDataMap := map[int64]*domain.CountArticleTagRead{} 45 countDataMap := map[int64]*domain.CountArticleTagRead{}
43 for _, val := range countData { 46 for _, val := range countData {
44 countDataMap[val.TagId] = val 47 countDataMap[val.TagId] = val
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 +
5 "github.com/samber/lo" 6 "github.com/samber/lo"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -33,7 +34,9 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -33,7 +34,9 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
33 WithKV("authorId", req.Author). 34 WithKV("authorId", req.Author).
34 WithKV("tags", req.Tags). 35 WithKV("tags", req.Tags).
35 WithKV("beginCreatedAt", req.BeginTime). 36 WithKV("beginCreatedAt", req.BeginTime).
36 - WithKV("endCreatedAt", req.EndTime) 37 + WithKV("endCreatedAt", req.EndTime).
  38 + WithKV("orderMode", req.OrderMode)
  39 +
37 total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions) 40 total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
38 if err != nil { 41 if err != nil {
39 return nil, xerr.NewErrMsgErr("搜索帖子异常", err) 42 return nil, xerr.NewErrMsgErr("搜索帖子异常", err)
@@ -1248,6 +1248,7 @@ type SystemArticleSearchRequest struct { @@ -1248,6 +1248,7 @@ type SystemArticleSearchRequest struct {
1248 Tags []int64 `json:"tags,optional"` //标签 1248 Tags []int64 `json:"tags,optional"` //标签
1249 Page int `json:"page"` //页码 1249 Page int `json:"page"` //页码
1250 Size int `json:"size"` //每页行数 1250 Size int `json:"size"` //每页行数
  1251 + OrderMode string `json:"orderMode"` //排序方式
1251 } 1252 }
1252 1253
1253 type SystemArticleSearchResponse struct { 1254 type SystemArticleSearchResponse struct {
@@ -121,7 +121,22 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -121,7 +121,22 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
121 total int64 121 total int64
122 ) 122 )
123 queryFunc := func() (interface{}, error) { 123 queryFunc := func() (interface{}, error) {
124 - tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId) 124 + tx = tx.Model(&ms).Where("company_id=?", companyId)
  125 + if v, ok := queryOptions["orderMode"]; ok {
  126 + mode := v.(string)
  127 + switch mode {
  128 + case "CountComment ASC":
  129 + tx = tx.Order("count_comment asc")
  130 + case "CountComment DESC":
  131 + tx = tx.Order("count_comment desc")
  132 + case "CountLove ASC":
  133 + tx = tx.Order("count_love asc")
  134 + case "CountLove DESC":
  135 + tx = tx.Order("count_love desc")
  136 + default:
  137 + tx = tx.Order("id desc")
  138 + }
  139 + }
125 if v, ok := queryOptions["ids"]; ok { 140 if v, ok := queryOptions["ids"]; ok {
126 tx = tx.Where("id in (?)", v) 141 tx = tx.Where("id in (?)", v)
127 } 142 }
@@ -3,14 +3,15 @@ package database @@ -3,14 +3,15 @@ package database
3 import ( 3 import (
4 "context" 4 "context"
5 "fmt" 5 "fmt"
  6 + "log"
  7 + "os"
  8 + "time"
  9 +
6 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
7 "gorm.io/driver/mysql" 11 "gorm.io/driver/mysql"
8 "gorm.io/driver/postgres" 12 "gorm.io/driver/postgres"
9 "gorm.io/gorm" 13 "gorm.io/gorm"
10 "gorm.io/gorm/logger" 14 "gorm.io/gorm/logger"
11 - "log"  
12 - "os"  
13 - "time"  
14 ) 15 )
15 16
16 func OpenGormDB(source string) *gorm.DB { 17 func OpenGormDB(source string) *gorm.DB {
@@ -44,6 +45,7 @@ func OpenGormPGDB(source string, logMode string) *gorm.DB { @@ -44,6 +45,7 @@ func OpenGormPGDB(source string, logMode string) *gorm.DB {
44 if err != nil { 45 if err != nil {
45 panic(err) 46 panic(err)
46 } 47 }
  48 +
47 return db 49 return db
48 } 50 }
49 51