You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

1 month ago
  1. package logic
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/errors/gcode"
  5. "github.com/gogf/gf/v2/errors/gerror"
  6. "github.com/gogf/gf/v2/frame/g"
  7. v1 "practice_Go/api/v1/shows"
  8. "practice_Go/internal/dao"
  9. "practice_Go/internal/model/entity"
  10. show "practice_Go/internal/service"
  11. )
  12. type sShows struct{}
  13. func init() {
  14. show.RegisterShows(NewShows())
  15. }
  16. func NewShows() *sShows {
  17. return &sShows{}
  18. }
  19. const (
  20. QueryRecommend = iota + 1 // 推荐界面
  21. QueryVideo // 精选视频
  22. QueryClub // 博股俱乐部
  23. QueryChannel // homilyLink频道
  24. )
  25. // 实现 IShows 接口中的 GetShowsList 方法
  26. func (s *sShows) GetShowsList(ctx context.Context, req *v1.ShowReq) (res v1.GetShowsListRes, err error) {
  27. model := dao.Shows.Ctx(ctx)
  28. // 根据请求类型动态调整查询条件
  29. switch req.QueryType {
  30. case QueryVideo:
  31. model = model.Where("type", 2).OrderAsc("publish_time") // 视频类型正序
  32. case QueryClub:
  33. model = model.Where("club_id", 1).OrderDesc("publish_time") // 俱乐部倒序
  34. case QueryChannel:
  35. model = model.Where("publisher_name", "homilyLink").OrderDesc("publish_time")
  36. default:
  37. model = model.OrderDesc("publish_time") // 默认推荐倒序
  38. }
  39. // 查询数据并填充到结果列表
  40. var list []*entity.Shows
  41. if err := model.Scan(&list); err != nil {
  42. g.Log().Errorf(ctx, "内容查询异常|类型:%d|错误:%v", req.QueryType, err)
  43. return res, gerror.WrapCode(gcode.CodeDbOperationError, err, "数据获取失败")
  44. }
  45. // 将查询结果赋值给返回值
  46. res.List = list
  47. return res, nil
  48. }