46d3f672bf
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 31s
CI / admin (push) Successful in 24s
CI / bff (push) Successful in 31s
CI / chore (push) Successful in 27s
CI / equipment (push) Successful in 21s
CI / express (push) Successful in 23s
CI / factory (push) Successful in 21s
CI / message (push) Successful in 21s
CI / order (push) Successful in 22s
CI / payment (push) Successful in 20s
CI / percutaneous (push) Successful in 20s
CI / product (push) Successful in 20s
CI / record (push) Successful in 19s
CI / sale (push) Successful in 19s
CI / support (push) Successful in 20s
CI / task (push) Successful in 19s
CI / user (push) Successful in 21s
CI / wecom (push) Successful in 22s
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
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 ApiBindInfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewApiBindInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiBindInfoLogic {
|
|
return &ApiBindInfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ApiBindInfoLogic) ApiBindInfo(in *equipment.ApiBindInfoRequest) (*equipment.Response, error) {
|
|
var v validator.ApiBindInfoValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
eq := map[string]string{
|
|
"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
|
"status": utils.StringStatusOk,
|
|
}
|
|
if v.Id > utils.NumberZero {
|
|
eq["id"] = strconv.FormatInt(v.Id, utils.NumberTen)
|
|
}
|
|
if v.HostCode != utils.StringEmpty {
|
|
eq["host_code"] = v.HostCode
|
|
}
|
|
if v.Type > utils.NumberZero {
|
|
eq["type"] = strconv.Itoa(int(v.Type))
|
|
}
|
|
|
|
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)
|
|
}
|