alarm_contact.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package utils
  4. import (
  5. "smart-alarm/model"
  6. "github.com/jaryhe/gopkgs/database"
  7. )
  8. /*
  9. var AlarmContactMap = map[int64]model.TAlarmContact{}
  10. var mutex sync.Mutex
  11. // 初始化告警联系人
  12. func InitAlarmContact() {
  13. contact := &model.TAlarmContact{}
  14. //where := map[string]interface{}{}
  15. contactList, err := contact.QueryAll(database.DB(), nil)
  16. if err == nil {
  17. for k, _ := range contactList {
  18. AlarmContactMap[contactList[k].ProjectId] = contactList[k]
  19. }
  20. }
  21. }
  22. // 获取告警联系人
  23. func GetAlarmContact(projectId int64) *model.TAlarmContact {
  24. mutex.Lock()
  25. defer mutex.Unlock()
  26. if value, ok := AlarmContactMap[projectId]; ok {
  27. return &value
  28. } else {
  29. return nil
  30. }
  31. }
  32. // 设置告警联系人
  33. func SetAlarmContact(contact *model.TAlarmContact) {
  34. mutex.Lock()
  35. defer mutex.Unlock()
  36. AlarmContactMap[contact.ProjectId] = *contact
  37. }
  38. func DeleteAlarmContact(projectId int64) {
  39. mutex.Lock()
  40. defer mutex.Unlock()
  41. delete(AlarmContactMap, projectId)
  42. }*/
  43. // 获取告警联系人
  44. func GetAlarmContact(projectId int64) []model.TAlarmContact {
  45. // TODO 从redis里面获取
  46. contact := &model.TAlarmContact{}
  47. filter := map[string]interface{}{"project_id": projectId}
  48. list, err := contact.QueryAll(database.DB(), filter)
  49. if err != nil {
  50. return nil
  51. }
  52. return list
  53. }