productListLogic.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package product
  2. import (
  3. "context"
  4. "perms-system-server/internal/middleware"
  5. "perms-system-server/internal/svc"
  6. "perms-system-server/internal/types"
  7. "perms-system-server/internal/util"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type ProductListLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
  16. return &ProductListLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. // ProductList 产品列表。分页查询系统中所有产品的基本信息,超管可见全部产品的 appKey。
  23. func (l *ProductListLogic) ProductList(req *types.ProductListReq) (resp *types.PageResp, err error) {
  24. page, pageSize := util.NormalizePage(req.Page, req.PageSize)
  25. list, total, err := l.svcCtx.SysProductModel.FindList(l.ctx, page, pageSize)
  26. if err != nil {
  27. return nil, err
  28. }
  29. caller := middleware.GetUserDetails(l.ctx)
  30. items := make([]types.ProductItem, 0, len(list))
  31. for _, p := range list {
  32. item := types.ProductItem{
  33. Id: p.Id,
  34. Code: p.Code,
  35. Name: p.Name,
  36. Remark: p.Remark,
  37. Status: p.Status,
  38. CreateTime: p.CreateTime,
  39. }
  40. if caller != nil && caller.IsSuperAdmin {
  41. item.AppKey = p.AppKey
  42. }
  43. items = append(items, item)
  44. }
  45. return &types.PageResp{
  46. Total: total,
  47. List: items,
  48. }, nil
  49. }