|
123456789101112131415161718192021222324252627282930313233343536373839 |
- 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 ListDictItemLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
-
- func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictItemLogic {
- return &ListDictItemLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
-
- func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.DictItems, err error) {
- resp = &types.DictItems{}
- sql := fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null ORDER BY create_time Desc`)
- if req.ItemText != "" {
- sql = fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null and c.item_text like '%%%s%%'`, req.ItemText)
- }
- tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List)
- if tx.Error != nil {
- logx.Errorf(tx.Error.Error())
- return nil, tx.Error
- }
- return resp, nil
- }
|