package dashboard import ( "context" "wechat-api/ent/labelrelationship" "wechat-api/ent/predicate" "wechat-api/internal/utils/dberrorhandler" "wechat-api/internal/svc" "wechat-api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type GetLabelsLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetLabelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLabelsLogic { return &GetLabelsLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx} } func (l *GetLabelsLogic) GetLabels(req *types.LabelsReq) (resp *types.LabelsResp, err error) { // 获取组织id var organizationId uint64 = 0 isAdmin := l.ctx.Value("isAdmin").(bool) if isAdmin && req.OrganizationId != nil && *req.OrganizationId != 0 { organizationId = *req.OrganizationId } else { organizationId = l.ctx.Value("organizationId").(uint64) } var predicates []predicate.LabelRelationship predicates = append(predicates, labelrelationship.OrganizationIDEQ(organizationId)) data, err := l.svcCtx.DB.LabelRelationship.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize) if err != nil { return nil, dberrorhandler.DefaultEntError(l.Logger, err, req) } return }