package dictionary import ( "context" "fmt" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type ListDictLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewListDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictLogic { return &ListDictLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.Dicts, err error) { resp = &types.Dicts{} sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc" if req.DictName != "" { sqlStr = fmt.Sprintf("select * from t_dict where `deleted_at` IS NULL and dict_name like '%%%s%%' ORDER BY create_time Desc", req.DictName) } tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List) if tx.Error != nil { logx.Errorf(tx.Error.Error()) return nil, tx.Error } return resp, nil }