qixiaoning
1 天以前 c3fd4effdef0cc5955f89b5df279b14841e857f5
push-service/controllers/eventPush.go
@@ -1,6 +1,9 @@
package controllers
import (
   "encoding/json"
   "vamicro/push-service/models"
   "vamicro/push-service/mqtt"
   "vamicro/push-service/service"
   "vamicro/push-service/vo"
@@ -127,6 +130,26 @@
   }
   sv := service.NewEventPushService(h.Bk)
   if sv.ChangeStatus(statusBody.Id, statusBody.Enable) {
      //消息提醒
      var epE models.EventPush
      epE.GetById(statusBody.Id)
      //udp推送
      if epE.PushType == 1 {
         msg := map[string]string{
            "type":   "change", // 注意逗号
            "status": "",       // 最后一个元素也需要逗号(Go 语法要求)
            "id":     statusBody.Id,
         }
         if statusBody.Enable {
            msg["status"] = "start"
         } else {
            msg["status"] = "stop"
         }
         jsonStr, _ := json.Marshal(msg)
         go mqtt.Client.Publish(mqtt.MQTT_CONFIG_TOPIC, jsonStr)
      }
      return &bhomeclient.Reply{Success: true, Msg: "修改成功"}
   } else {
      return &bhomeclient.Reply{Success: false, Msg: "修改失败"}