productDetailLogic.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package product
  2. import (
  3. "context"
  4. "perms-system-server/internal/middleware"
  5. "perms-system-server/internal/response"
  6. "perms-system-server/internal/svc"
  7. "perms-system-server/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type ProductDetailLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic {
  16. return &ProductDetailLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *ProductDetailLogic) ProductDetail(req *types.ProductDetailReq) (resp *types.ProductItem, err error) {
  23. product, err := l.svcCtx.SysProductModel.FindOne(l.ctx, req.Id)
  24. if err != nil {
  25. return nil, response.ErrNotFound("产品不存在")
  26. }
  27. caller := middleware.GetUserDetails(l.ctx)
  28. item := &types.ProductItem{
  29. Id: product.Id,
  30. Code: product.Code,
  31. Name: product.Name,
  32. Remark: product.Remark,
  33. Status: product.Status,
  34. CreateTime: product.CreateTime,
  35. }
  36. if caller != nil && caller.IsSuperAdmin {
  37. item.AppKey = product.AppKey
  38. }
  39. return item, nil
  40. }