fix: 上下线修复只处理mqtt协议

This commit is contained in:
godLei6
2025-03-08 15:10:20 +08:00
parent 0d1fc4fcc6
commit 1e4fbd62c8
8 changed files with 2104 additions and 2094 deletions

View File

@@ -5,8 +5,8 @@ RUN go env -w GOPROXY=https://goproxy.cn,direct
ENV GOPRIVATE=*.gitee.com,gitee.com/*
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add git
RUN go mod tidy
RUN cd ./service/apisvr && go build -tags no_k8s -ldflags="-s -w" .
RUN go mod download
RUN cd ./service/apisvr && go build -tags no_k8s -ldflags="-s -w" -o thingsvr .
FROM docker.unitedrhino.com/unitedrhino/alpine:3.20
LABEL homepage="https://gitee.com/unitedrhino"
@@ -14,7 +14,7 @@ ENV TZ Asia/Shanghai
RUN apk add tzdata
WORKDIR /unitedrhino/
COPY --from=go-builder /unitedrhino/service/apisvr/apisvr ./apisvr
COPY --from=go-builder /unitedrhino/service/apisvr/thingsvr ./thingsvr
COPY --from=go-builder /unitedrhino/service/apisvr/etc ./etc
ENTRYPOINT ["./apisvr"]
ENTRYPOINT ["./thingsvr"]

View File

@@ -7,13 +7,6 @@ import (
"github.com/zeromicro/go-zero/rest"
)
type Captcha struct {
KeyLong int `json:",default=6"`
ImgWidth int `json:",default=240"`
ImgHeight int `json:",default=80"`
KeepTime int64 `json:",default=180"`
}
type Config struct {
rest.RestConf
Etcd discov.EtcdConf `json:",optional,inherit"`
@@ -22,17 +15,7 @@ type Config struct {
DgRpc conf.RpcClientConf `json:",optional"`
DmRpc conf.RpcClientConf `json:",optional"`
UdRpc conf.RpcClientConf `json:",optional"`
VidRpc conf.RpcClientConf `json:",optional"`
VidSip conf.RpcClientConf `json:",optional"`
TimedJobRpc conf.RpcClientConf `json:",optional"`
Rej struct {
AccessSecret string
AccessExpire int64
} //注册token相关配置
Proxy conf.ProxyConf `json:",optional"`
Captcha Captcha
OssConf conf.OssConf `json:",optional"`
Map conf.MapConf `json:",optional"`
OpenAuth conf.AuthConf `json:",optional"`
Event conf.EventConf //和things内部交互的设置
OssConf conf.OssConf `json:",optional"`
Event conf.EventConf //和things内部交互的设置
}

View File

@@ -11,6 +11,7 @@ import (
"gitee.com/unitedrhino/things/service/dmsvr/pb/dm"
"gitee.com/unitedrhino/things/share/clients"
"gitee.com/unitedrhino/things/share/devices"
"gitee.com/unitedrhino/things/share/domain/protocols"
"github.com/zeromicro/go-zero/core/logx"
"go.uber.org/atomic"
)
@@ -77,6 +78,18 @@ func (o *CheckEvent) Check() error {
if err != nil {
continue
}
pi, err := o.svcCtx.ProductCache.GetData(o.ctx, di.ProductID)
if err != nil {
continue
}
if pi.Protocol != nil && pi.Protocol.TransProtocol != protocols.ProtocolMqtt {
delete(devs, c)
continue
}
if pi.SubProtocol != nil && pi.SubProtocol.TransProtocol != protocols.ProtocolMqtt {
delete(devs, c)
continue
}
delete(devs, c)
if di.IsOnline != def.True {
needOnlineDevices = append(needOnlineDevices, &dm.DeviceOnlineMultiFix{

View File

@@ -177,6 +177,8 @@ type DmProductInfo struct {
DeletedTime stores.DeletedTime `gorm:"column:deleted_time;uniqueIndex:pd"`
Category *DmProductCategory `gorm:"foreignKey:ID;references:CategoryID"` // 添加外键
Protocol *DmProtocolInfo `gorm:"foreignKey:Code;references:ProtocolCode"`
SubProtocol *DmProtocolInfo `gorm:"foreignKey:Code;references:SubProtocolCode"`
//Devices []*DmDeviceInfo `gorm:"foreignKey:ProductID;references:ProductID"` // 添加外键
CustomUi map[string]*ProductCustomUi `gorm:"column:customUi;type:json;serializer:json;NOT NULL;default:'{}'"`
}
@@ -273,11 +275,10 @@ type DmProtocolScript struct {
TriggerTimer protocol.TriggerTimer `gorm:"column:trigger_timer;"` //收到前处理before after
TriggerHandle devices.MsgHandle `gorm:"column:trigger_handle;type:varchar(100);default:''"` //对应 mqtt topic的第一个 thing ota config 等等
TriggerType string `gorm:"column:trigger_type;type:varchar(100);default:''"` // 操作类型 从topic中提取 物模型下就是 property属性 event事件 action行为
//TriggerMethod string //方法级触发
ScriptLang int64 `gorm:"column:script_lang;type:smallint;default:1"` // 脚本语言类型 1:go
Script string `gorm:"column:script;type:text"` // 协议转换脚本
Desc string `gorm:"column:desc;type:varchar(200)"` // 描述
Status def.Bool `gorm:"column:status;default:1"` //状态:是否启用
ScriptLang int64 `gorm:"column:script_lang;type:smallint;default:1"` // 脚本语言类型 1:go
Script string `gorm:"column:script;type:text"` // 协议转换脚本
Desc string `gorm:"column:desc;type:varchar(200)"` // 描述
Status def.Bool `gorm:"column:status;default:1"` //状态:是否启用
stores.NoDelTime
DeletedTime stores.DeletedTime `gorm:"column:deleted_time;default:0;uniqueIndex:name"`
}

View File

@@ -82,7 +82,7 @@ func (p ProductInfoRepo) fmtFilter(ctx context.Context, f ProductFilter) *gorm.D
db = db.Where("status in ?", f.Statuses)
}
if f.WithProtocol {
db = db.Preload("Protocol")
db = db.Preload("Protocol").Preload("subProtocol")
}
if f.WithCategory {
db = db.Preload("Category")

File diff suppressed because it is too large Load Diff

View File

@@ -1415,7 +1415,8 @@ message ProductInfo{
map<string, string> tags = 13; //产品标签
string productImg = 14; //产品图片
bool isUpdateProductImg = 15;//只有这个参数为true的时候才会更新产品图片,传参为产品图片的file path
ProtocolInfo protocol = 16;
ProtocolInfo protocol = 16; //主协议信息
ProtocolInfo subProtocol = 39;//子协议信息
ProductCategory category = 17;
map<string,string>protocolConf =18;
map<string,string>subProtocolConf =25;