1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package utils
- import (
- "smart-alarm/model"
- "github.com/jaryhe/gopkgs/database"
- )
- /*
- var AlarmContactMap = map[int64]model.TAlarmContact{}
- var mutex sync.Mutex
- // 初始化告警联系人
- func InitAlarmContact() {
- contact := &model.TAlarmContact{}
- //where := map[string]interface{}{}
- contactList, err := contact.QueryAll(database.DB(), nil)
- if err == nil {
- for k, _ := range contactList {
- AlarmContactMap[contactList[k].ProjectId] = contactList[k]
- }
- }
- }
- // 获取告警联系人
- func GetAlarmContact(projectId int64) *model.TAlarmContact {
- mutex.Lock()
- defer mutex.Unlock()
- if value, ok := AlarmContactMap[projectId]; ok {
- return &value
- } else {
- return nil
- }
- }
- // 设置告警联系人
- func SetAlarmContact(contact *model.TAlarmContact) {
- mutex.Lock()
- defer mutex.Unlock()
- AlarmContactMap[contact.ProjectId] = *contact
- }
- func DeleteAlarmContact(projectId int64) {
- mutex.Lock()
- defer mutex.Unlock()
- delete(AlarmContactMap, projectId)
- }*/
- // 获取告警联系人
- func GetAlarmContact(projectId int64) []model.TAlarmContact {
- // TODO 从redis里面获取
- contact := &model.TAlarmContact{}
- filter := map[string]interface{}{"project_id": projectId}
- list, err := contact.QueryAll(database.DB(), filter)
- if err != nil {
- return nil
- }
- return list
- }
|