6d861ef898
CI / changes (push) Successful in 1m56s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / analysis (push) Successful in 0s
CI / bff (push) Successful in 0s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 1s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 1s
CI / percutaneous (push) Successful in 33s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 1s
CI / task (push) Successful in 0s
CI / user (push) Successful in 1s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"lone-services/pkg/redis"
|
|
"lone-services/pkg/utils"
|
|
pkgws "lone-services/pkg/ws"
|
|
"lone-services/services/percutaneous/internal/dao"
|
|
|
|
"lone-services/rpc/percutaneous/pb"
|
|
"lone-services/services/percutaneous/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WsClientStatusLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewWsClientStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WsClientStatusLogic {
|
|
return &WsClientStatusLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *WsClientStatusLogic) WsClientStatus(in *percutaneous.GetWsCodeRequest) (*percutaneous.Response, error) {
|
|
Type := WsTypeApp
|
|
|
|
//1为web,2为设备
|
|
if in.Type == utils.NumberOne {
|
|
Type = WsTypeOperation
|
|
}
|
|
|
|
key := utils.MD5Encrypt(fmt.Sprintf("%s%s", dao.WsCode, Type))
|
|
redisKey := pkgws.RedisKeyQRSession + key
|
|
|
|
val, err := redis.Client.Get(l.ctx, redisKey).Result()
|
|
if err != nil && err.Error() != redis.Nil.Error() {
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
if len(val) > utils.NumberTen {
|
|
data := "ok"
|
|
keys := []string{WsTypeApp, WsTypeOperation}
|
|
|
|
for _, k := range keys {
|
|
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)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
redis.Client.Del(l.ctx, redisKey).Result()
|
|
}
|
|
return l.ok(utils.NumberOne)
|
|
}
|
|
|
|
if err := redis.Client.Set(l.ctx, redisKey, redisKey, pkgws.SessionTTL).Err(); err != nil {
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(utils.NumberOne)
|
|
}
|