pcm-coordinator/internal/logic/dictionary/getdictlogic.go

39 lines
937 B
Go

package dictionary
import (
"context"
"github.com/pkg/errors"
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictLogic {
return &GetDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetDictLogic) GetDict(req *types.CId) (resp *types.DictResp, err error) {
resp = &types.DictResp{}
dict := &types.DictInfo{}
db := l.svcCtx.DbEngin.Table("t_dict").Where("id = ?", req.Id).First(&dict)
if db.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Dictionary does not exist")
}
tool.Convert(dict, &resp)
return
}