实现 pc 服务端数据上传处理

This commit is contained in:
2025-07-05 10:59:23 +08:00
parent 0c6de3db61
commit 357ada8455
7 changed files with 252 additions and 173 deletions

15
internal/consts/emqx.go Normal file
View File

@ -0,0 +1,15 @@
package consts
// UP 上行消息 cmd 常量
const (
CmdMemberLevels = 1 // 会员等级数据
CmdClientList = 2 // 客户机列表数据
CmdClientUp = 104 // 上机记录
CmdClientDown = 106 // 下机记录
)
// DOWN 下行消息 cmd 常量
const (
CmdDesktopSetting = 10001 // 桌面组件显示设置
CmdUserFee = 10002 // 用户网费下发
)

View File

@ -33,6 +33,7 @@ type StoreClientSessionsColumns struct {
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间戳
AreaName string //
}
// storeClientSessionsColumns holds the columns for the table store_client_sessions.
@ -50,6 +51,7 @@ var storeClientSessionsColumns = StoreClientSessionsColumns{
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
AreaName: "area_name",
}
// NewStoreClientSessionsDao creates and returns a new DAO object for table data access.

View File

@ -5,11 +5,13 @@ import (
"encoding/json"
"fmt"
"github.com/gogf/gf/v2/errors/gerror"
"server/internal/consts"
"server/internal/dao"
"server/internal/model"
"server/internal/model/do"
"server/internal/service"
"server/utility/mqtt"
"server/utility/mqtt/emqx"
)
type sStoreDesktopSetting struct {
@ -63,15 +65,26 @@ func (s *sStoreDesktopSetting) Save(ctx context.Context, in model.SaveDesktopSet
if err != nil {
return nil, err
}
marshal, err := json.Marshal(in)
if err != nil {
return nil, err
}
client, b := mqtt.GetClient("emqx")
if !b {
return nil, gerror.New("获取MQTT客户端失败")
}
err = client.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal)
downData := emqx.DownData{
CMD: consts.CmdDesktopSetting,
StoreId: int(in.StoreId),
Data: struct {
RightComponentVisible int `json:"rightComponentVisible"`
TopComponentVisible int `json:"topComponentVisible"`
}{
RightComponentVisible: in.RightComponentVisible,
TopComponentVisible: in.TopComponentVisible,
},
}
marshal, err := json.Marshal(downData)
if err != nil {
return nil, err
}
err = client.Publish(fmt.Sprintf("/%d/down", in.StoreId), marshal)
if err != nil {
return nil, err
}

View File

@ -25,4 +25,5 @@ type StoreClientSessions struct {
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间戳
AreaName interface{} //
}

View File

@ -23,4 +23,5 @@ type StoreClientSessions struct {
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳
AreaName string `json:"areaName" orm:"area_name" description:""` //
}

View File

@ -4,7 +4,7 @@ import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
_ "server/utility/gamelife"
//_ "server/utility/mqtt/emqx"
_ "server/utility/mqtt/emqx"
_ "server/utility/myCasbin"
_ "server/utility/oss/aliyun"
_ "server/utility/rsa"