正在显示
6 个修改的文件
包含
96 行增加
和
7 行删除
| @@ -492,10 +492,10 @@ type ( | @@ -492,10 +492,10 @@ type ( | ||
| 492 | Size int `json:"size"` | 492 | Size int `json:"size"` |
| 493 | CompanyId int64 `json:",optional"` | 493 | CompanyId int64 `json:",optional"` |
| 494 | UserId int64 `json:",optional"` | 494 | UserId int64 `json:",optional"` |
| 495 | - TagGroup string `json:"tagGroup"` | 495 | + TagCategory string `json:"tagCategory"` |
| 496 | TagId int64 `json:"tagId"` | 496 | TagId int64 `json:"tagId"` |
| 497 | BeginTime int64 `json:"beginTime"` | 497 | BeginTime int64 `json:"beginTime"` |
| 498 | - EndTime int `json:"endTime"` | 498 | + EndTime int64 `json:"endTime"` |
| 499 | SearchWord string `json:"searchWord"` | 499 | SearchWord string `json:"searchWord"` |
| 500 | } | 500 | } |
| 501 | // | 501 | // |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | 5 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 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/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 8 | 9 | ||
| 9 | "github.com/zeromicro/go-zero/core/logx" | 10 | "github.com/zeromicro/go-zero/core/logx" |
| 10 | ) | 11 | ) |
| @@ -23,8 +24,24 @@ func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceConte | @@ -23,8 +24,24 @@ func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceConte | ||
| 23 | } | 24 | } |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 27 | +// 小程序端搜索展示文章列表 | ||
| 26 | func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) { | 28 | func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) { |
| 27 | - // todo: add your logic here and delete this line | ||
| 28 | 29 | ||
| 30 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 31 | + | ||
| 32 | + cnt, articleList, err := l.svcCtx.ArticleRepository.CustomSearchBy(l.ctx, conn, req.UserId, req.CompanyId, | ||
| 33 | + req.TagCategory, req.TagId, [2]int64{req.BeginTime, req.EndTime}, req.SearchWord, req.Page, req.Size) | ||
| 34 | + if err != nil { | ||
| 35 | + return nil, xerr.NewErrMsgErr("获取文章列表", err) | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + articleIds := []int64{} | ||
| 39 | + for _, val := range articleList { | ||
| 40 | + articleIds = append(articleIds, val.Id) | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + resp = &types.MiniSearchArticleResponse{ | ||
| 44 | + Total: int(cnt), | ||
| 45 | + } | ||
| 29 | return | 46 | return |
| 30 | } | 47 | } |
| @@ -1031,10 +1031,10 @@ type MiniSearchArticleRequest struct { | @@ -1031,10 +1031,10 @@ type MiniSearchArticleRequest struct { | ||
| 1031 | Size int `json:"size"` | 1031 | Size int `json:"size"` |
| 1032 | CompanyId int64 `json:",optional"` | 1032 | CompanyId int64 `json:",optional"` |
| 1033 | UserId int64 `json:",optional"` | 1033 | UserId int64 `json:",optional"` |
| 1034 | - TagGroup string `json:"tagGroup"` | 1034 | + TagCategory string `json:"tagCategory"` |
| 1035 | TagId int64 `json:"tagId"` | 1035 | TagId int64 `json:"tagId"` |
| 1036 | BeginTime int64 `json:"beginTime"` | 1036 | BeginTime int64 `json:"beginTime"` |
| 1037 | - EndTime int `json:"endTime"` | 1037 | + EndTime int64 `json:"endTime"` |
| 1038 | SearchWord string `json:"searchWord"` | 1038 | SearchWord string `json:"searchWord"` |
| 1039 | } | 1039 | } |
| 1040 | 1040 |
| @@ -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/pkg/errors" | 7 | "github.com/pkg/errors" |
| 7 | "github.com/tiptok/gocomm/pkg/cache" | 8 | "github.com/tiptok/gocomm/pkg/cache" |
| @@ -279,9 +280,67 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | @@ -279,9 +280,67 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | ||
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | // 小程序端搜索查询文章 | 282 | // 小程序端搜索查询文章 |
| 282 | -func (repository *ArticleRepository) SearchBy(ctx context.Context, conn transaction.Conn, userId int64, companyId int64, | ||
| 283 | - tagCategory string, tagId int64, createdAt [2]int) { | 283 | +// userId 人员id,谁查看文章 |
| 284 | +// companyId 公司id | ||
| 285 | +// tagCategory 标签分类 | ||
| 286 | +// tagId 标签id | ||
| 287 | +// createdAt 文章的发布时间,按范围查询 [开始时间,结束时间] | ||
| 288 | +// titleLike 搜索标题 | ||
| 289 | +func (repository *ArticleRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, userId int64, companyId int64, | ||
| 290 | + tagCategory string, tagId int64, createdAt [2]int64, titleLike string, page int, size int) (int64, []*domain.Article, error) { | ||
| 291 | + var ( | ||
| 292 | + tx = conn.DB() | ||
| 293 | + ms []*models.Article | ||
| 294 | + dms = make([]*domain.Article, 0) | ||
| 295 | + total int64 | ||
| 296 | + ) | ||
| 297 | + tx = tx.Model(&ms). | ||
| 298 | + Where(`article."show" =?`, domain.ArticleShowEnable). | ||
| 299 | + Where(`article."deleted_at" = 0`). | ||
| 300 | + Where(`article."company_id"=?`, companyId). | ||
| 301 | + Where( | ||
| 302 | + fmt.Sprintf(`(article.target_user = 0 or article.who_read @> '[%d]' )`, userId), | ||
| 303 | + ) | ||
| 304 | + if createdAt[0] > 0 { | ||
| 305 | + tx = tx.Where("article.created_at >=?", createdAt[0]) | ||
| 306 | + } | ||
| 307 | + if createdAt[1] > 0 { | ||
| 308 | + tx = tx.Where("article.created_at <=?", createdAt[1]) | ||
| 309 | + } | ||
| 310 | + if tagId > 0 { | ||
| 311 | + tx = tx.Joins(`join article_and_tag on article.id = article_and_tag.article_id`) | ||
| 312 | + tx = tx.Where("article_and_tag.tag_id=?", tagId) | ||
| 313 | + } else if len(tagCategory) > 0 { | ||
| 314 | + tx = tx.Joins(`join article_and_tag on article.id = article_and_tag.article_id`) | ||
| 315 | + tx = tx.Where(`article_and_tag.tag_id =any(select article_tag.id from article_tag where category =%s )`, tagCategory) | ||
| 316 | + } | ||
| 317 | + if len(titleLike) > 0 { | ||
| 318 | + tx = tx.Where("article.title like ?", "%"+titleLike+"%") | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + result := tx.Count(&total) | ||
| 322 | + if result.Error != nil { | ||
| 323 | + return 0, nil, result.Error | ||
| 324 | + } | ||
| 325 | + if size <= 0 { | ||
| 326 | + size = 20 | ||
| 284 | 327 | ||
| 328 | + } | ||
| 329 | + if page <= 0 { | ||
| 330 | + page = 1 | ||
| 331 | + } | ||
| 332 | + result = tx.Limit(size).Offset((page - 1) * size).Order("id desc").Find(&ms) | ||
| 333 | + if result.Error != nil { | ||
| 334 | + return 0, nil, result.Error | ||
| 335 | + } | ||
| 336 | + for _, item := range ms { | ||
| 337 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
| 338 | + return 0, dms, err | ||
| 339 | + } else { | ||
| 340 | + dms = append(dms, dm) | ||
| 341 | + } | ||
| 342 | + } | ||
| 343 | + return total, dms, nil | ||
| 285 | } | 344 | } |
| 286 | 345 | ||
| 287 | // select * | 346 | // select * |
| @@ -127,6 +127,9 @@ func (repository *UserReadArticleRepository) Find(ctx context.Context, conn tran | @@ -127,6 +127,9 @@ func (repository *UserReadArticleRepository) Find(ctx context.Context, conn tran | ||
| 127 | if v, ok := queryOptions["articleId"]; ok { | 127 | if v, ok := queryOptions["articleId"]; ok { |
| 128 | tx = tx.Where("article_id=?", v) | 128 | tx = tx.Where("article_id=?", v) |
| 129 | } | 129 | } |
| 130 | + if v, ok := queryOptions["articleIds"]; ok { | ||
| 131 | + tx = tx.Where("article_id in (?)", v) | ||
| 132 | + } | ||
| 130 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 133 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 131 | return dms, tx.Error | 134 | return dms, tx.Error |
| 132 | } | 135 | } |
| @@ -41,6 +41,16 @@ type ArticleRepository interface { | @@ -41,6 +41,16 @@ type ArticleRepository interface { | ||
| 41 | IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动 | 41 | IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动 |
| 42 | IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动 | 42 | IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动 |
| 43 | IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动 | 43 | IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动 |
| 44 | + | ||
| 45 | + // 小程序端搜索查询文章 | ||
| 46 | + // userId 人员id,谁查看文章 | ||
| 47 | + // companyId 公司id | ||
| 48 | + // tagCategory 标签分类 | ||
| 49 | + // tagId 标签id | ||
| 50 | + // createdAt 文章的发布时间,按范围查询 [开始时间,结束时间] | ||
| 51 | + // titleLike 搜索标题 | ||
| 52 | + CustomSearchBy(ctx context.Context, conn transaction.Conn, userId int64, companyId int64, | ||
| 53 | + tagCategory string, tagId int64, createdAt [2]int64, titleLike string, page int, size int) (int64, []*Article, error) | ||
| 44 | } | 54 | } |
| 45 | 55 | ||
| 46 | type ArticleTarget int | 56 | type ArticleTarget int |
-
请 注册 或 登录 后发表评论