add and fix apis
This commit is contained in:
@@ -60,6 +60,13 @@ func (l *AddUserLogic) AddUser(in *percutaneous.AddUserRequest) (*percutaneous.R
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
} else {
|
||||
info.Status = utils.StatusOk
|
||||
_, err = model.GroupModel{}.Init().Edit(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
}
|
||||
|
||||
sess := l.svcCtx.SessionMgr.Pop(in.HostCode)
|
||||
|
||||
@@ -30,21 +30,12 @@ func NewGetWsCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWsCo
|
||||
}
|
||||
|
||||
func (l *GetWsCodeLogic) GetWsCode(in *percutaneous.GetWsCodeRequest) (*percutaneous.Response, error) {
|
||||
id := in.UserId
|
||||
if id < utils.NumberOne {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
id = adminInfo.ID
|
||||
}
|
||||
|
||||
Type := WsTypeApp
|
||||
if in.Type == utils.NumberTwo {
|
||||
Type = WsTypeOperation
|
||||
}
|
||||
|
||||
key := utils.MD5Encrypt(fmt.Sprintf("%d%s%s", id, dao.WsCode, Type))
|
||||
key := utils.MD5Encrypt(fmt.Sprintf("%s%s", dao.WsCode, Type))
|
||||
redisKey := pkgws.RedisKeyQRSession + key
|
||||
|
||||
payload, err := jsoniter.MarshalToString(pkgws.Session{
|
||||
|
||||
@@ -2,9 +2,9 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lone-services/pkg/utils"
|
||||
pkgws "lone-services/pkg/ws"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
@@ -38,7 +38,7 @@ func (l *SetPositionLogic) SetPosition(in *percutaneous.SetPositionRequest) (*pe
|
||||
return l.fail(utils.ErrorQRcodeExp)
|
||||
}
|
||||
|
||||
data := in.Position
|
||||
data := fmt.Sprintf("%d,%d", in.Position, adminInfo.ID)
|
||||
if err := pkgws.Publish(l.ctx, in.SessionId, pkgws.Success(data)); err != nil {
|
||||
l.Errorf("set position publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ func (l *UsedLogLogic) UsedLog(in *percutaneous.UsedLogRequest) (*percutaneous.R
|
||||
"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
||||
},
|
||||
}
|
||||
if len(in.Time) > utils.NumberOne {
|
||||
w.Between = map[string][2]string{"create_time": {
|
||||
in.Time[utils.NumberZero], in.Time[utils.NumberOne]}}
|
||||
}
|
||||
err := model.UsedLogModel{}.Init().Items(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
@@ -55,6 +59,10 @@ func (l *UsedLogLogic) UsedLog(in *percutaneous.UsedLogRequest) (*percutaneous.R
|
||||
Order: "id desc",
|
||||
Eq: map[string]string{"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)},
|
||||
}
|
||||
if len(in.Time) > utils.NumberOne {
|
||||
w.Between = map[string][2]string{"create_time": {
|
||||
in.Time[utils.NumberZero], in.Time[utils.NumberOne]}}
|
||||
}
|
||||
|
||||
items, err := model.UsedLogModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/percutaneous/internal/dao"
|
||||
"lone-services/services/percutaneous/internal/model"
|
||||
"lone-services/services/percutaneous/validator"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserDeleteLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewUserDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDeleteLogic {
|
||||
return &UserDeleteLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserDeleteLogic) UserDelete(in *percutaneous.AddUserRequest) (*percutaneous.Response, error) {
|
||||
var v validator.GroupValidator
|
||||
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)
|
||||
}
|
||||
w := modelbase.Params{Eq: map[string]string{
|
||||
"host_code": in.HostCode,
|
||||
"host_user_id": strconv.FormatInt(in.UserId, utils.NumberTen),
|
||||
"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
||||
}}
|
||||
|
||||
var info dao.Group
|
||||
err := model.GroupModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
info.HostCode = in.HostCode
|
||||
info.HostUserId = in.UserId
|
||||
info.UserId = adminInfo.ID
|
||||
info.Status = utils.StatusFail
|
||||
_, err = model.GroupModel{}.Init().Edit(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
}
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
@@ -30,22 +30,13 @@ func NewWsClientStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ws
|
||||
}
|
||||
|
||||
func (l *WsClientStatusLogic) WsClientStatus(in *percutaneous.GetWsCodeRequest) (*percutaneous.Response, error) {
|
||||
id := in.UserId
|
||||
if id < utils.NumberOne {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
id = adminInfo.ID
|
||||
}
|
||||
|
||||
Type := WsTypeApp
|
||||
//1为web,2为设备
|
||||
if in.Type == utils.NumberOne {
|
||||
Type = WsTypeOperation
|
||||
}
|
||||
|
||||
key := utils.MD5Encrypt(fmt.Sprintf("%d%s%s", id, dao.WsCode, Type))
|
||||
key := utils.MD5Encrypt(fmt.Sprintf("%s%s", dao.WsCode, Type))
|
||||
redisKey := pkgws.RedisKeyQRSession + key
|
||||
|
||||
val, err := redis.Client.Get(l.ctx, redisKey).Result()
|
||||
@@ -58,7 +49,7 @@ func (l *WsClientStatusLogic) WsClientStatus(in *percutaneous.GetWsCodeRequest)
|
||||
keys := []string{WsTypeApp, WsTypeOperation}
|
||||
|
||||
for _, k := range keys {
|
||||
key = utils.MD5Encrypt(fmt.Sprintf("%d%s%s", id, dao.WsCode, k))
|
||||
key = utils.MD5Encrypt(fmt.Sprintf("%s%s", dao.WsCode, k))
|
||||
redisKey = pkgws.RedisKeyQRSession + key
|
||||
if err = pkgws.Publish(l.ctx, redisKey, pkgws.Success(data)); err != nil {
|
||||
l.Errorf("ws client publish: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user