package WarningNotice import ( "Cold_DeductionNotice/Nats/NatsServer" "Cold_DeductionNotice/lib" "Cold_DeductionNotice/logs" "Cold_DeductionNotice/models/Account" "Cold_DeductionNotice/models/Warning" "encoding/json" "strconv" "strings" ) // 报警发送给用户表 func WarningToUser(Warning_r *Warning.Warning, T_pid int) { logs.Println("==>WarningToUserId ", "Msid", Warning_r.T_Msid, " T_pid:", T_pid) Warning_r.T_pid = T_pid var T_Admin_list []int Tpid := Account.Read_Admin_Tpid_List(Warning_r.T_pid) for _, v := range Tpid { T_Admin_list = append(T_Admin_list, v.Id) } if len(T_Admin_list) == 0 { Warning.Add_Warning_Log(Warning_r, "!!!没有要通知的用户!!!\n") return } T_Admin_list_str := "" for _, T_Admin_list_r := range T_Admin_list { T_Admin_list_str += strconv.Itoa(T_Admin_list_r) + "|" } Warning.Add_Warning_Log(Warning_r, "通知 用户ID列表 -> ["+T_Admin_list_str+"]\n") // 通知策略 for _, T_Admin_list_r := range T_Admin_list { logs.Println("==> WarningToAdminId T_Admin_id:", T_Admin_list_r) Admin_r, err := Account.Read_Admin_Byid(T_Admin_list_r) if err != nil { logs.Println("==> WarningToAdminId 没找到 T_Admin_id:", err) Warning.Add_Warning_Log(Warning_r, "没找到 T_Admin_id:-> "+strconv.Itoa(T_Admin_list_r)+"\n") continue } Warning.Add_Warning_Log(Warning_r, "通知-> ["+strconv.Itoa(Admin_r.Id)+"|"+Admin_r.T_name+"]\n") // 累积报警记录数 key_Warning_num := "A" + strconv.Itoa(Admin_r.Id) + "|" + Warning_r.T_sn + "|" + strconv.Itoa(Warning_r.T_tp) // 用户+报警类型 if !Warning.Redis_WarningToAdmin_Num(key_Warning_num) { Warning.Add_Warning_Log(Warning_r, "-> "+Admin_r.T_name+"["+strconv.Itoa(Admin_r.Id)+"]"+"相同报警(30分钟内),跳过该用户通知\n") continue } // 获取公司名称 _, Company_r := Account.Read_Company_id(Warning_r.T_pid) if Company_r.Id == 0 { Company_r.T_name = "冷链系统" } // 微信通知 if len(Admin_r.T_wx) > 3 { data_json_t := Wx_d_struct{ Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 10)}, Type: Wx_struct{Value: Warning.Read_WarningType_Get(Warning_r.T_tp)}, Name: Wx_struct{Value: lib.Limit_len(Warning_r.T_D_name, 20)}, Time: Wx_struct{Value: Warning_r.T_Ut.Format("2006-01-02 15:04:05")}, Remark: Wx_struct{Value: lib.Limit_len(Warning_r.T_Remark, 20)}, } data_json_str, _ := json.Marshal(data_json_t) logs.Println("==> WarningToAdminId 通知内容:", string(data_json_str)) // 用户下 多个微信 arr_b := strings.Split(Admin_r.T_wx, "|") for _, v_b := range arr_b { v_b_l := strings.Split(v_b, "/") if len(v_b_l) != 2 { logs.Println("==> WarningToAdminId 推送 T_Notice_wx:", v_b, " len(v_b_l) != 2") continue } if len(v_b_l[0]) == 0 { logs.Println("==> WarningToAdminId 推送 T_Notice_wx:", v_b, " len(v_b_l[0]) == 0") continue } NatsServer.Wx_MessageTemplate(Warning_r, v_b_l[0], "gnpERD6ilOQK6zvp1W_Pmae-to4wEqXmHrM0poN7IoY", string(data_json_str)) } //Warning.Add_Warning_Log(Warning_r, "微信-> "+Admin_r.T_name+"\n") } // 短信通知 //if len(Admin_r.T_phone) > 3 { // reqdata_Message := "" // NatsServer.Ali_Message(Warning_r, Admin_r.T_phone, "SMS_232170337", reqdata_Message) // Warning.Add_Warning_Log(Warning_r, "微信-> "+Admin_r.T_name+"\n") //} } defer func() { if Warning_r.Id > 0 { Warning.Update_Warning(*Warning_r, "T_Log") } }() } // 报警发送给用户表 //func WarningToUser(Warning_r *Warning.Warning, T_pid int) { // logs.Println("==>WarningToUserId ", "Msid", Warning_r.T_Msid, " T_pid:", T_pid) // // var T_Admin_list []int // // Tpid := Account.Read_Admin_Tpid_List(Warning_r.T_pid) // for _, v := range Tpid { // T_Admin_list = append(T_Admin_list, v.Id) // } // // if len(T_Admin_list) == 0 { // Warning.Add_Warning_Log(Warning_r, "!!!没有要通知的用户!!!\n") // return // } // // T_Admin_list_str := "" // for _, T_Admin_list_r := range T_Admin_list { // T_Admin_list_str += strconv.Itoa(T_Admin_list_r) + "|" // } // Warning.Add_Warning_Log(Warning_r, "通知 用户ID列表 -> ["+T_Admin_list_str+"]\n") // // 通知策略 // for _, T_Admin_list_r := range T_Admin_list { // // logs.Println("T_Admin_id:", T_Admin_list_r) // Admin_r, err := Account.Read_Admin_Byid(T_Admin_list_r) // if err != nil { // logs.Println("没找到 T_Admin_id:", err) // Warning.Add_Warning_Log(Warning_r, "没找到 T_Admin_id:-> "+strconv.Itoa(T_Admin_list_r)+"\n") // continue // } // Warning.Add_Warning_Log(Warning_r, "通知-> ["+strconv.Itoa(Admin_r.Id)+"|"+Admin_r.T_name+"]\n") // // 累积报警记录数 // key_Warning_num := "A" + strconv.Itoa(Admin_r.Id) + "|" + strconv.Itoa(Warning_r.T_tp) // 用户+报警类型 // if !Warning.Redis_WarningToAdmin_Num(key_Warning_num) { // Warning.Add_Warning_Log(Warning_r, "-> "+Admin_r.T_name+"["+strconv.Itoa(Admin_r.Id)+"]"+"相同报警(30分钟内),跳过该用户通知\n") // continue // } // // 获取公司名称 // _, Company_r := Account.Read_Company_id(Warning_r.T_pid) // if Company_r.Id == 0 { // Company_r.T_name = "冷链系统" // } // // 微信通知 // if len(Admin_r.T_wx) > 3 { // // data_json_t := Wx_d_struct{ // Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 10)}, // Type: Wx_struct{Value: Warning.Read_WarningType_Get(Warning_r.T_tp)}, // Name: Wx_struct{Value: lib.Limit_len(Warning_r.T_D_name, 20)}, // Time: Wx_struct{Value: Warning_r.T_Ut.Format("2006-01-02 15:04:05")}, // Remark: Wx_struct{Value: lib.Limit_len(Warning_r.T_Remark, 20)}, // } // data_json_str, _ := json.Marshal(data_json_t) // logs.Println("通知内容:", string(data_json_str)) // // // 用户下 多个微信 // arr_b := strings.Split(Admin_r.T_wx, "|") // for _, v_b := range arr_b { // v_b_l := strings.Split(v_b, "/") // if len(v_b_l) != 2 { // logs.Println("推送 T_Notice_wx:", v_b, " len(v_b_l) != 2") // continue // } // if len(v_b_l[0]) == 0 { // logs.Println("推送 T_Notice_wx:", v_b, " len(v_b_l[0]) == 0") // continue // } // NatsServer.Wx_MessageTemplate(Warning_r, v_b_l[0], "gnpERD6ilOQK6zvp1W_Pmae-to4wEqXmHrM0poN7IoY", string(data_json_str)) // // } // // //Warning.Add_Warning_Log(Warning_r, "微信-> "+Admin_r.T_name+"\n") // } // // // 短信通知 // //if len(Admin_r.T_phone) > 3 { // // reqdata_Message := "" // // NatsServer.Ali_Message(Warning_r, Admin_r.T_phone, "SMS_232170337", reqdata_Message) // // Warning.Add_Warning_Log(Warning_r, "微信-> "+Admin_r.T_name+"\n") // //} // // } // // defer func() { // if Warning_r.Id > 0 { // Warning.Update_Warning(*Warning_r, "T_Log") // } // }() // //} //