123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package edbmonitor
- import (
- "errors"
- edbmonitor "eta/eta_api/models/edb_monitor"
- "eta/eta_api/models/edb_monitor/response"
- "eta/eta_api/utils"
- "time"
- "github.com/gorilla/websocket"
- )
- var (
- EDB_MONITOR_MESSAGE_CONNECT_CACHE = "edb_monitor_message_cache:"
- )
- func ReadEdbMonitorMessage(messageId, adminId int) (msg string, err error) {
- message, err := edbmonitor.GetEdbMonitorMessageById(messageId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- msg = "消息不存在"
- return
- }
- msg = "获取消息失败"
- return
- }
- if message.AdminId != adminId {
- msg = "您没有权限查看该消息"
- err = errors.New("no permission")
- return
- }
- message.IsRead = 1
- err = message.Update([]string{"IsRead"})
- if err != nil {
- msg = "已读失败"
- return
- }
- return
- }
- func LogMessage(content string, triggerTime time.Time, edbInfoId, edbInfoType, adminId int) (err error) {
- message := &edbmonitor.EdbMonitorMessage{
- EdbInfoId: edbInfoId,
- EdbInfoType: edbInfoType,
- AdminId: adminId,
- IsRead: 0,
- Message: content,
- MonitorTriggerTime: triggerTime,
- CreateTime: time.Now(),
- }
- _, err = message.Insert()
- return err
- }
- func SendMessages(conn *websocket.Conn, adminId int) (err error) {
- message, err := edbmonitor.GetEdbMonitorMessageByAdminId(adminId)
- if err != nil {
- return
- }
- msg := response.EdbMonitorMessageResp{
- EdbMonitorMessageId: message.EdbMonitorMessageId,
- EdbInfoId: message.EdbInfoId,
- EdbInfoType: message.EdbInfoType,
- Message: message.Message,
- TriggerTime: utils.TimeTransferString(utils.FormatDateTime, message.MonitorTriggerTime),
- }
- return conn.WriteJSON(msg)
- }
|