package logic import ( "context" "strconv" "lone-services/pkg/modelbase" "lone-services/pkg/utils" equipment "lone-services/rpc/equipment/pb" "lone-services/services/equipment/internal/dao" "lone-services/services/equipment/internal/model" "lone-services/services/equipment/internal/svc" "lone-services/services/equipment/validator" "github.com/zeromicro/go-zero/core/logx" ) type InternalBindInfoLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger BaseLogic } func NewInternalBindInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InternalBindInfoLogic { return &InternalBindInfoLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *InternalBindInfoLogic) InternalBindInfo(in *equipment.InternalBindInfoRequest) (*equipment.Response, error) { var v validator.InternalBindInfoValidator if fail := l.checkParams(in, &v); fail != nil { return fail, nil } eq := map[string]string{ "status": utils.StringStatusOk, } if v.UserId > utils.NumberZero { eq["user_id"] = strconv.FormatInt(v.UserId, utils.NumberTen) } if v.SkinType > utils.NumberZero { eq["skin_type"] = strconv.Itoa(int(v.SkinType)) } if v.HostCode != utils.StringEmpty { eq["host_code"] = v.HostCode } if v.Type > utils.NumberZero { eq["type"] = strconv.Itoa(int(v.Type)) } if v.Id > utils.NumberZero { eq["id"] = strconv.FormatInt(v.Id, utils.NumberTen) } if len(eq) == utils.NumberOne { return l.out(utils.ErrorParams, "缺少查询条件") } var info dao.BindInfo err := model.BindModel{}.Init().GetOne(modelbase.Params{ Eq: eq, Order: "id desc", }, &info) if err != nil { l.Logger.Error(err) return l.fail(utils.Fail) } if info.Id < utils.NumberOne { return l.ok(nil) } return l.ok(info) }