|
@@ -14,9 +14,9 @@ import (
|
|
|
)
|
|
|
|
|
|
func DealWebSocketMsg(adminId int) {
|
|
|
+ DealEdbInspectionMessageTest(adminId)
|
|
|
|
|
|
-
|
|
|
- go DealEdbInspectionMessage(adminId)
|
|
|
+ //go DealEdbInspectionMessage(adminId)
|
|
|
}
|
|
|
|
|
|
// 处理巡检消息
|
|
@@ -164,4 +164,57 @@ func WriteWebSocketMessageAsync(ctx context.Context, adminId int, resp interface
|
|
|
utils.FileLog.Error("WriteWebSocketMessageAsync ctx.Done(): %v", ctx.Err())
|
|
|
return ctx.Err(), isClose
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+func DealEdbInspectionMessageTest(adminId int) {
|
|
|
+ messageList, err := data.GetHistoryInspectionMessages(adminId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("获取巡检信息历史失败,err:%s, adminId:%d", err.Error(), adminId)
|
|
|
+ }
|
|
|
+ success := make(chan int64, 10)
|
|
|
+ go func() {
|
|
|
+ defer close(success)
|
|
|
+ for i, msg := range messageList {
|
|
|
+ if i == 0 {
|
|
|
+ // 多条消息仅发送最新一条
|
|
|
+ respData, err := data.SendInspectionMessages(adminId, msg)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("巡检信息发送失败,err:%s, adminId:%d", err.Error(), adminId)
|
|
|
+ } else {
|
|
|
+ resp := models.WebsocketMessageResponse{
|
|
|
+ MessageType: 1,
|
|
|
+ Data: respData,
|
|
|
+ }
|
|
|
+ conn := global.MonitorMessageConn[adminId]
|
|
|
+ if conn == nil {
|
|
|
+ utils.FileLog.Error("巡检信息发送失败,连接已断开, adminId:%d", adminId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = conn.WriteJSON(resp)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("巡检信息发送失败,err:%s, adminId:%d", err.Error(), adminId)
|
|
|
+ } else {
|
|
|
+ utils.FileLog.Info("巡检信息发送成功,adminId:%d, messageId:%d", adminId, msg.MessageId)
|
|
|
+ success <- msg.MessageId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ success <- msg.MessageId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ go func() {
|
|
|
+ readList := make([]int64, 0)
|
|
|
+ for {
|
|
|
+ msgId, ok := <-success
|
|
|
+ if !ok {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ readList = append(readList, msgId)
|
|
|
+ }
|
|
|
+ _, err = data.ReadEdbInspectionMessageList(readList, adminId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("巡检信息已读失败,err:%s, adminId:%d", err.Error(), adminId)
|
|
|
+ }
|
|
|
+ }()
|
|
|
}
|