ContinuousPushOfOfflineDeviceWarning.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package Plugins
  2. import (
  3. "Cold_mqtt/MqttServer/WarningNotice"
  4. "Cold_mqtt/lib"
  5. "Cold_mqtt/logs"
  6. "Cold_mqtt/models/Device"
  7. "Cold_mqtt/models/Warning"
  8. "time"
  9. )
  10. // 设备离线报警连续推送 冰箱采集器(wifi版) BX100W
  11. func ContinuousPushOfOfflineDeviceWarning() {
  12. ContinuousPushOfOfflineDeviceWarningTOGO:
  13. DeviceList := Device.Read_获取BX100W离线设备()
  14. logs.Println("======设备离线报警连续推送========")
  15. for _, r_Device := range DeviceList {
  16. DeviceParameter_r, is := Device.Read_DeviceParameter(r_Device.T_sn)
  17. if !is {
  18. logs.Println(r_Device.T_sn + " 没有设备参数,跳过")
  19. continue
  20. }
  21. Warningr_new := Warning.Read_T_snT_tp(r_Device.T_sn, 1001)
  22. if Warningr_new.Id == 0 {
  23. logs.Println(r_Device.T_sn + " 没有触发过离线,跳过")
  24. continue
  25. }
  26. duration := time.Now().Sub(Warningr_new.T_Ut)
  27. // 将时间差表示为秒
  28. seconds := int(duration.Seconds())
  29. if DeviceParameter_r.T_outA > seconds {
  30. logs.Println(r_Device.T_sn+" 未满足触发条件,跳过,已经持续", seconds, "秒,配置", DeviceParameter_r.T_outA)
  31. continue
  32. }
  33. Warningr_fUt := Warning.Read_T_snT_tpT_Msid(r_Device.T_sn, 1001, 0)
  34. if Warningr_fUt.Id == 0 {
  35. logs.Println(r_Device.T_sn + " 没有触发过初次离线,跳过")
  36. continue
  37. }
  38. Warning_r := Warning.Add_DeviceLogs(1001, r_Device, "设备离线报警,已经持续 "+lib.TimeSinceToString(Warningr_fUt.T_Ut, time.Now()))
  39. Warning_r.T_fUt = Warningr_fUt.T_Ut
  40. Warning_r.T_Msid = 1
  41. Warning.Update_Warning(Warning_r, "T_Msid", "T_fUt")
  42. WarningNotice.WarningCompanyNotice(&Warning_r, 0, 0)
  43. }
  44. time.Sleep(time.Second * 30)
  45. goto ContinuousPushOfOfflineDeviceWarningTOGO
  46. }