From 20bbbcc1d14536ddaa498ac84a6008828df8dc1c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 13 十二月 2023 20:23:11 +0800 Subject: [PATCH] 往plc写目标数时,优先往写入地址写,没有写入地址再往读取地址写 --- nsq/msg_handler.go | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/nsq/msg_handler.go b/nsq/msg_handler.go index a45aed8..0a1fc03 100644 --- a/nsq/msg_handler.go +++ b/nsq/msg_handler.go @@ -433,3 +433,29 @@ } return nil } + +type Dashboard struct { + Topic string +} + +func (slf *Dashboard) HandleMessage(data []byte) (err error) { + logx.Infof("dashboard message: %s", data) + var dashboard model.Dashboard + err = json.Unmarshal(data, &dashboard) + if err != nil { + logx.Infof("unmarshal msg err :%s", err) + return err + } + old, err := model.NewDashboardSearch(nil).SetVersion(dashboard.Version).First() + if err == gorm.ErrRecordNotFound { + err = model.NewDashboardSearch(nil).SetVersion(dashboard.Version).Create(&dashboard) + } else { + dashboard.ID = old.ID + err = model.NewDashboardSearch(nil).Save(&dashboard) + } + if err != nil { + logx.Infof("process pull data err :%s", err) + return err + } + return nil +} -- Gitblit v1.8.0