Files
lone-services/services/percutaneous/internal/logic/wsClientStatusLogic.go
T
gjs ddb4aa8b65
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / analysis (push) Successful in 0s
CI / bff (push) Successful in 1s
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 0s
CI / percutaneous (push) Successful in 30s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 1s
CI / task (push) Successful in 0s
CI / support (push) Successful in 0s
CI / user (push) Successful in 0s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
add and fix apis
2026-10-28 14:09:26 +08:00

79 lines
1.9 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}
ok := false
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)
ok = false
return l.fail(utils.Fail)
}
ok = true
}
if ok {
for _, k := range keys {
key = utils.MD5Encrypt(fmt.Sprintf("%s%s", dao.WsCode, k))
redisKey = pkgws.RedisKeyQRSession + key
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)
}