123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- package WarningNotice
- import (
- "Cold_mqtt/Nats/NatsServer"
- "Cold_mqtt/conf"
- "Cold_mqtt/lib"
- "Cold_mqtt/logs"
- "Cold_mqtt/models/Account"
- "Cold_mqtt/models/Company"
- "Cold_mqtt/models/Device"
- "Cold_mqtt/models/Warning"
- "encoding/json"
- "fmt"
- "time"
- "strconv"
- "strings"
- )
- // 报警策略通知 fut 持续时间间隔 秒
- func WarningCompanyNotice(Warning_r *Warning.Warning, T, HR float32) {
- defer func() {
- if Warning_r.Id > 0 {
- Warning.Update_Warning(*Warning_r, "T_Log")
- }
- }()
- if Warning_r.T_State == 0 {
- logs.Println("Warning_r.T_State == 0", Warning_r.T_State)
- return
- }
- logs.Println("==>WarningCompanyNotice Msid", Warning_r.T_Msid)
- CompanyNotice_List := Company.Read_CompanyNotice_List(Warning_r.T_pid)
- CompanyNotice_List_is := true
- logs.Println("==>WarningCompanyNotice CompanyNotice_List.len", len(CompanyNotice_List))
- // 通知策略
- for _, CompanyNotice_v := range CompanyNotice_List {
- if Warning_r.T_id == -1 {
- // 主机 通知
- if !strings.Contains(CompanyNotice_v.T_Notice_bind, Warning_r.T_sn) {
- logs.Println("==>WarningCompanyNotice 不匹配!", CompanyNotice_v.T_Notice_bind, Warning_r.T_sn)
- continue
- }
- } else {
- // 传感器 通知
- if !strings.Contains(CompanyNotice_v.T_Notice_bind, Warning_r.T_sn+","+strconv.Itoa(Warning_r.T_id)) {
- logs.Println("==>WarningCompanyNotice 不匹配!", CompanyNotice_v.T_Notice_bind, Warning_r.T_sn+","+strconv.Itoa(Warning_r.T_id))
- continue
- }
- }
- CompanyNotice_List_is = false
- WarningCompanyNotice_CompanyNotice(Warning_r, CompanyNotice_v, T, HR)
- }
- if CompanyNotice_List_is {
- // 策略 有问题
- Warning.Add_Warning_Log(Warning_r, "!!!没有报警策略,请及时去添加!!!\n")
- return
- }
- }
- // 处理分类
- func WarningCompanyNotice_CompanyNotice(Warning_r *Warning.Warning, CompanyNotice_r Company.CompanyNotice, T, HR float32) {
- logs.Println("==>WarningCompanyNotice_CompanyNotice", "Msid", Warning_r.T_Msid, " CompanyNotice:", CompanyNotice_r.Id, " T_name:", CompanyNotice_r.T_name, " T_Notice_mechanism:", CompanyNotice_r.T_Notice_mechanism)
- cx_time := time.Now().Unix() - Warning_r.T_fUt.Unix() // 持续时间 s
- Warning.Add_Warning_Log(Warning_r, "执行通知策略 ->["+CompanyNotice_r.T_name+"] ["+time.Now().Format("15:04:05")+"]\n")
- // 遍历 所有绑定策略
- // W报警编号,记录,处理,w启用,数量,上限,~|
- // W15,1,1,0,1,0,9999,0,0,0,0,0,0,0,0,0|
- T_Notice_mechanism_list := strings.Split(CompanyNotice_r.T_Notice_mechanism, "|")
- if len(T_Notice_mechanism_list) == 0 {
- // 策略 有问题 !!!!
- Warning.Add_Warning_Log(Warning_r, " !!!策略规则错误!!!\n"+CompanyNotice_r.T_Notice_mechanism+" , 内容:"+Warning_r.T_Remark)
- }
- for _, v := range T_Notice_mechanism_list {
- if len(v) == 0 {
- continue
- }
- //T_nm_list W报警编号-0,处理-1,w启用-2,持续秒-3,间隔秒-4,发送条数-5,d启用-6,持续秒-7,间隔秒-8,发送条数-9,p启用-10,持续秒-11,间隔秒-12,发送条数-13|
- // 解析策略
- T_nm_list := strings.Split(v, ",")
- //if len(T_nm_list) != 14 {
- // logs.Println("==>WarningCompanyNotice_CompanyNotice 策略 ->", v, " 策略下标长度 != 15 ->", len(T_nm_list))
- // continue
- //}
- // 判断符合 报警类型
- T_tp_str := Warning.Read_WarningType_Get(Warning_r.T_tp)
- if !strings.Contains(T_tp_str, T_nm_list[0]) {
- logs.Println("==>WarningCompanyNotice_CompanyNotice 不符合 报警类型!!", T_tp_str, T_nm_list[0])
- continue
- }
- logs.Println("执行策略 ->", v)
- // 是否绑定 SN,ID
- if Warning_r.T_id == -1 {
- if !strings.Contains(CompanyNotice_r.T_Notice_bind, Warning_r.T_sn) {
- logs.Println("==>WarningCompanyNotice_CompanyNotice !!!没有绑定设备,跳过", CompanyNotice_r.T_Notice_bind, Warning_r.T_sn+",")
- Warning.Add_Warning_Log(Warning_r, " !!!没有绑定设备,跳过\n")
- continue
- }
- } else {
- if !strings.Contains(CompanyNotice_r.T_Notice_bind, Warning_r.T_sn+","+strconv.Itoa(Warning_r.T_id)+"|") {
- logs.Println("!!!没有绑定设备,跳过", CompanyNotice_r.T_Notice_bind, Warning_r.T_sn+","+strconv.Itoa(Warning_r.T_id)+"|")
- Warning.Add_Warning_Log(Warning_r, " !!!没有绑定设备传感器,跳过\n")
- continue
- }
- }
- // 是否处理
- if T_nm_list[1] == "1" {
- logs.Println("==>WarningCompanyNotice_CompanyNotice 策略结果 ->", "要 处理")
- Warning_r.T_State = 3
- }
- WarningCompanyNotice_CompanyNotice_Send(Warning_r, CompanyNotice_r, T_nm_list, T, HR, cx_time)
- return
- }
- }
- // 发送报警信息
- func WarningCompanyNotice_CompanyNotice_Send(Warning_r *Warning.Warning, CompanyNotice_r Company.CompanyNotice, T_nm_list []string, T, HR float32, cx_time int64) {
- logs.Println("==>WarningDeviceHandle_CompanyNotice_Send ", "T_Msid", Warning_r.T_Msid, " T_nm_list:", T_nm_list)
- //T_nm_list W报警编号-0,处理-1,w启用-2,持续秒-3,间隔秒-4,发送条数-5,d启用-6,持续秒-7,间隔秒-8,发送条数-9,p启用-10,持续秒-11,间隔秒-12,发送条数-13|
- _, Company_r := Account.Read_Company_id(Warning_r.T_pid)
- Company_Charging_r := Company_r
- //记账扣费
- if Company_r.T_Charging > 0 {
- _, Company_Charging_r = Account.Read_Company_id(Company_r.T_Charging)
- }
- // 微信
- N_index := 2
- if T_nm_list[N_index] == "1" { // 是否开启
- Warning_num, Warning_sUt := Warning.Redis_Warning_Num(Warning_r.T_sn + "|" + strconv.Itoa(Warning_r.T_id) + "|" + strconv.Itoa(Warning_r.T_tp) + "|wx")
- Warning.Add_Warning_Log(Warning_r, fmt.Sprintf("[微信]持续时间:%d秒, 间隔时间:%s秒, 内发送次数:%d次, 间隔还剩时间:%d秒\n", cx_time, T_nm_list[N_index+2], Warning_num, Warning_sUt))
- if int_x, _ := strconv.Atoi(T_nm_list[N_index+1]); int64(int_x) <= cx_time { // 是否满足 持续时间 秒
- if int_u, _ := strconv.Atoi(T_nm_list[N_index+3]); (int64(int_u) > Warning_num) || int_u == 0 { //是否 间隔时间内 超过发送条数
- Warning.Redis_Warning_Num_W(Warning_r.T_sn+"|"+strconv.Itoa(Warning_r.T_id)+"|"+strconv.Itoa(Warning_r.T_tp)+"|wx", T_nm_list[N_index+2])
- // 开始推送
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", CompanyNotice_r.T_Notice_wx)
- //reqdata_wx := "{\"first\":{\"value\":\"" + Warning_r.T_Ut.Format("2006-01-02 15:04:05") + "\", \"color\":\"#ff450a\"}, \"keyword1\":{\"value\":\"" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\", \"color\":\"#ff450a\"}, \"keyword2\":{\"value\":\"" + Warning_r.T_D_name + "[" + Warning_r.T_DS_name + "] " + "\", \"color\":\"#056cff\"}, \"remark\":{\"value\":\"" + Warning_r.T_Remark + "\", \"color\":\"#ffcb0a\"}}"
- arr_c := strings.Split(CompanyNotice_r.T_Notice_wx, "|")
- for _, v_c := range arr_c {
- if len(v_c) == 0 {
- continue
- }
- v_c_l := strings.Split(v_c, "/")
- if len(v_c_l) != 2 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l) != 2")
- continue
- }
- if len(v_c_l[0]) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l[0]) == 0")
- continue
- }
- admin_r, err := Account.Read_Admin_ByUuid(v_c_l[0])
- if err != nil {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " Read_Admin_ByUuid!!")
- continue
- }
- if len(admin_r.T_wx) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " admin_r.T_wx!!")
- continue
- }
- // 用户下 多个微信
- 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("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_b, " len(v_b_l) != 2")
- continue
- }
- if len(v_b_l[0]) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_b, " len(v_b_l[0]) == 0")
- continue
- }
- // 微信
- Warning.Add_Warning_Log(Warning_r, "----> "+v_b)
- var data_json_str []byte
- switch Warning_r.T_tp {
- case 1, 2, 3, 7, 8, 9: //温度
- data_json_t := Wx_t_struct{
- Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 20)},
- Type: Wx_struct{Value: Warning.Read_WarningType_Get(Warning_r.T_tp)},
- Name: Wx_struct{Value: lib.Limit_len(Warning_r.T_DS_name, 20)},
- Time: Wx_struct{Value: Warning_r.T_Ut.Format("2006-01-02 15:04:05")},
- //T: Wx_struct{Value: fmt.Sprintf("%.1f℃", T), Color: "#ff0099"},
- Remark: Wx_struct{Value: lib.Limit_len("当前:"+fmt.Sprintf("%.1f℃", T)+Warning_r.T_Remark, 20)},
- }
- data_json_str, _ = json.Marshal(data_json_t)
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 通知内容:", string(data_json_str))
- NatsServer.Wx_MessageTemplate(Company_Charging_r, Warning_r, v_b_l[0], "8bPXmJwtd7RnbI2iVNatxez9Vby_0Y-69ggN57_-Sh8", string(data_json_str))
- break
- case 4, 5, 6, 10, 11, 12: //湿度
- data_json_t := Wx_h_struct{
- Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 20)},
- Type: Wx_struct{Value: Warning.Read_WarningType_Get(Warning_r.T_tp)},
- Name: Wx_struct{Value: lib.Limit_len(Warning_r.T_DS_name, 20)},
- Time: Wx_struct{Value: Warning_r.T_Ut.Format("2006-01-02 15:04:05")},
- //H: Wx_struct{Value: },
- Remark: Wx_struct{Value: lib.Limit_len("当前:"+fmt.Sprintf("%.1f", HR)+"%"+Warning_r.T_Remark, 20)},
- }
- data_json_str, _ = json.Marshal(data_json_t)
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 通知内容:", string(data_json_str))
- NatsServer.Wx_MessageTemplate(Company_Charging_r, Warning_r, v_b_l[0], "833Kd1-zaQJ5sOJ9F2I1RzSNS249KU_t3L7610cbgaw", string(data_json_str))
- break
- default:
- data_json_t := Wx_d_struct{
- Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 20)},
- 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("==> WarningCompanyNotice_CompanyNotice_Send 通知内容:", string(data_json_str))
- NatsServer.Wx_MessageTemplate(Company_Charging_r, Warning_r, v_b_l[0], "gnpERD6ilOQK6zvp1W_PmY5SEDOcSxiHh_KJbCdeAqw", string(data_json_str))
- }
- }
- }
- } else { // 间隔时间内 超过发送条数
- int_x, _ := strconv.Atoi(T_nm_list[N_index+3])
- Warning.Add_Warning_Log(Warning_r, "!微信-> 间隔时间内 超过发送条数,当期值:"+strconv.Itoa(int_x)+"\n")
- }
- } else { // 未达到 持续时间 秒
- int_x, _ := strconv.Atoi(T_nm_list[N_index+1])
- Warning.Add_Warning_Log(Warning_r, "!微信-> 未达到持续时间:"+strconv.Itoa(int_x)+"\n")
- }
- }
- // 短信
- N_index = 6
- if T_nm_list[N_index] == "1" { // 是否开启
- Warning_num, Warning_sUt := Warning.Redis_Warning_Num(Warning_r.T_sn + "|" + strconv.Itoa(Warning_r.T_id) + "|" + strconv.Itoa(Warning_r.T_tp) + "|dx")
- Warning.Add_Warning_Log(Warning_r, fmt.Sprintf("[短信]持续时间:%d秒, 间隔时间:%s秒, 内发送次数:%d次, 间隔还剩时间:%d秒\n", cx_time, T_nm_list[N_index+2], Warning_num, Warning_sUt))
- if int_x, _ := strconv.Atoi(T_nm_list[N_index+1]); int64(int_x) <= cx_time { // 是否满足 持续时间 秒
- if int_u, _ := strconv.Atoi(T_nm_list[N_index+3]); (int64(int_u) > Warning_num) || int_u == 0 { //是否 间隔时间内 超过发送条数
- Warning.Redis_Warning_Num_W(Warning_r.T_sn+"|"+strconv.Itoa(Warning_r.T_id)+"|"+strconv.Itoa(Warning_r.T_tp)+"|dx", T_nm_list[N_index+2])
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_message:", CompanyNotice_r.T_Notice_message)
- arr_c := strings.Split(CompanyNotice_r.T_Notice_message, "|")
- for _, v_c := range arr_c {
- if len(v_c) == 0 {
- continue
- }
- v_c_l := strings.Split(v_c, "/")
- if len(v_c_l) != 2 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l) != 2")
- continue
- }
- if len(v_c_l[0]) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l[0]) == 0")
- continue
- }
- admin_r, err := Account.Read_Admin_ByUuid(v_c_l[0])
- if err != nil {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " Read_Admin_ByUuid!!")
- continue
- }
- if len(admin_r.T_phone) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " admin_r.T_wx!!")
- continue
- }
- v_c_l[0] = admin_r.T_phone
- if len("18777951277") != len(v_c_l[0]) {
- Warning.Add_Warning_Log(Warning_r, "----> "+v_c_l[0]+" 号码异常! \n")
- continue
- }
- //电话
- Warning.Add_Warning_Log(Warning_r, "----> "+v_c_l[0])
- // 查看余额是否有钱
- if Company_Charging_r.T_money <= 0 {
- Warning.Add_Warning_Log(Warning_r, "["+Company_Charging_r.T_name+"]余额不足,请及时联系管理员充值!!!\n")
- continue
- }
- // 发送模板
- switch Warning_r.T_tp {
- case 1, 2, 3, 7, 8, 9: //温度
- reqdata_Message := "{\"name1\":\"" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\",\"name2\":\"" + Warning_r.T_Ut.Format("2006-01-02 15:04:05") + "\",\"name3\":\"" + Warning_r.T_DS_name + "\",\"name4\":\"" + Warning_r.T_Remark + "\",\"T_T\":\"" + strconv.FormatFloat(float64(T), 'f', -1, 32) + "\"}"
- NatsServer.Sb_Message(Company_Charging_r, Warning_r, v_c_l[0], "dks8a", reqdata_Message)
- break
- case 4, 5, 6, 10, 11, 12: //湿度
- reqdata_Message := "{\"name1\":\"" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\",\"name2\":\"" + Warning_r.T_Ut.Format("2006-01-02 15:04:05") + "\",\"name3\":\"" + Warning_r.T_DS_name + "\",\"name4\":\"" + Warning_r.T_Remark + "\",\"T_RH\":\"" + strconv.FormatFloat(float64(HR), 'f', -1, 32) + "\"}"
- NatsServer.Sb_Message(Company_Charging_r, Warning_r, v_c_l[0], "JDHNV4", reqdata_Message)
- break
- default: // 通知
- reqdata_Message := "{\"name1\":\"" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\",\"name2\":\"" + Warning_r.T_Ut.Format("2006-01-02 15:04:05") + "\",\"name3\":\"" + Warning_r.T_DS_name + "\",\"name4\":\"" + Warning_r.T_Remark + "\"}"
- NatsServer.Sb_Message(Company_Charging_r, Warning_r, v_c_l[0], "HeWYR3", reqdata_Message)
- }
- }
- } else { // 间隔时间内 超过发送条数
- int_x, _ := strconv.Atoi(T_nm_list[N_index+3])
- Warning.Add_Warning_Log(Warning_r, "--!短信-> 间隔时间内 超过发送条数,当期值:"+strconv.Itoa(int_x)+"\n")
- }
- } else { // 未达到 持续时间 秒
- int_x, _ := strconv.Atoi(T_nm_list[N_index+1])
- Warning.Add_Warning_Log(Warning_r, "--!短信-> 未达到持续时间:"+strconv.Itoa(int_x)+"\n")
- }
- }
- // 电话
- N_index = 10
- if T_nm_list[N_index] == "1" { // 是否开启
- Warning_num, Warning_sUt := Warning.Redis_Warning_Num(Warning_r.T_sn + "|" + strconv.Itoa(Warning_r.T_id) + "|" + strconv.Itoa(Warning_r.T_tp) + "|dh")
- Warning.Add_Warning_Log(Warning_r, fmt.Sprintf("[电话]持续时间:%d秒, 间隔时间:%s秒, 内发送次数:%d次, 间隔还剩时间:%d秒\n", cx_time, T_nm_list[N_index+2], Warning_num, Warning_sUt))
- if int_x, _ := strconv.Atoi(T_nm_list[N_index+1]); int64(int_x) <= cx_time { // 是否满足 持续时间 秒
- if int_u, _ := strconv.Atoi(T_nm_list[N_index+3]); (int64(int_u) > Warning_num) || int_u == 0 { //是否 间隔时间内 超过发送条数
- Warning.Redis_Warning_Num_W(Warning_r.T_sn+"|"+strconv.Itoa(Warning_r.T_id)+"|"+strconv.Itoa(Warning_r.T_tp)+"|dh", T_nm_list[N_index+2])
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_phone:", CompanyNotice_r.T_Notice_phone)
- arr_c := strings.Split(CompanyNotice_r.T_Notice_phone, "|")
- for _, v_c := range arr_c {
- if len(v_c) == 0 {
- continue
- }
- v_c_l := strings.Split(v_c, "/")
- if len(v_c_l) != 2 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l) != 2")
- continue
- }
- if len(v_c_l[0]) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " len(v_c_l[0]) == 0")
- continue
- }
- admin_r, err := Account.Read_Admin_ByUuid(v_c_l[0])
- if err != nil {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " Read_Admin_ByUuid!!")
- continue
- }
- if len(admin_r.T_phone) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_wx:", v_c, " admin_r.T_wx!!")
- continue
- }
- v_c_l[0] = admin_r.T_phone
- if len("18777951277") != len(v_c_l[0]) {
- Warning.Add_Warning_Log(Warning_r, "----> "+v_c_l[0]+" 号码异常! \n")
- continue
- }
- //电话
- Warning.Add_Warning_Log(Warning_r, "---->"+v_c_l[0])
- // 查看余额是否有钱
- if Company_Charging_r.T_money <= 0 {
- Warning.Add_Warning_Log(Warning_r, "["+Company_Charging_r.T_name+"] 余额不足,请及时联系管理员充值!!!\n")
- continue
- }
- // 语音实体
- Hw_VoiceNotice_is := NatsServer.Hw_VoiceNotice(Company_Charging_r, Warning_r, v_c_l[0], []byte(fmt.Sprintf(`{"displayNbr":"+862022509874","calleeNbr":"%s","playInfoList":[{"templateId":"03bf51a5d8094db8ab1001aaa426ac60","templateParas":["%s","%s","%s"]}],"userData":"testUserData"}`, v_c_l[0], lib.Limit_len(Company_r.T_name, 29), lib.Limit_len(Warning_r.T_DS_name, 29), Warning.Read_WarningType_Get(Warning_r.T_tp))))
- if Hw_VoiceNotice_is {
- type V_struct struct {
- Corporate string `json:"company"`
- Device string `json:"device"`
- Name string `json:"name"`
- }
- Warning.Add_Warning_Log(Warning_r, "--!电话-> 华为云 通知失败,切换为 赛邮云"+"\n")
- V_struct_r := V_struct{Corporate: Company_r.T_name, Device: Warning_r.T_DS_name, Name: Warning.Read_WarningType_Get(Warning_r.T_tp)}
- V_struct_str, _ := json.Marshal(V_struct_r)
- NatsServer.Submail_Voice(Company_Charging_r, Warning_r, v_c_l[0], "i2ixE1", string(V_struct_str))
- }
- }
- } else { // 间隔时间内 超过发送条数
- int_x, _ := strconv.Atoi(T_nm_list[N_index+3])
- Warning.Add_Warning_Log(Warning_r, "--!电话-> 间隔时间内 超过发送条数,当期值:"+strconv.Itoa(int_x)+"\n")
- }
- } else { // 未达到 持续时间 秒
- int_x, _ := strconv.Atoi(T_nm_list[N_index+1])
- Warning.Add_Warning_Log(Warning_r, "--!电话-> 未达到持续时间:"+strconv.Itoa(int_x)+"\n")
- }
- }
- // APP
- N_index = 14
- if len(T_nm_list) > 14 { // 兼容后加的APP ,防止数组 溢出
- if T_nm_list[N_index] == "1" { // 是否开启
- Warning_num, Warning_sUt := Warning.Redis_Warning_Num(Warning_r.T_sn + "|" + strconv.Itoa(Warning_r.T_id) + "|" + strconv.Itoa(Warning_r.T_tp) + "|app")
- Warning.Add_Warning_Log(Warning_r, fmt.Sprintf("[APP]持续时间:%d秒, 间隔时间:%s秒, 内发送次数:%d次, 间隔还剩时间:%d秒\n", cx_time, T_nm_list[N_index+2], Warning_num, Warning_sUt))
- if int_x, _ := strconv.Atoi(T_nm_list[N_index+1]); int64(int_x) <= cx_time { // 是否满足 持续时间 秒
- if int_u, _ := strconv.Atoi(T_nm_list[N_index+3]); (int64(int_u) > Warning_num) || int_u == 0 { //是否 间隔时间内 超过发送条数
- Warning.Redis_Warning_Num_W(Warning_r.T_sn+"|"+strconv.Itoa(Warning_r.T_id)+"|"+strconv.Itoa(Warning_r.T_tp)+"|app", T_nm_list[N_index+2])
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_APP:", CompanyNotice_r.T_Notice_app)
- arr_c := strings.Split(CompanyNotice_r.T_Notice_app, "|")
- for _, v_c := range arr_c {
- if len(v_c) == 0 {
- continue
- }
- v_c_l := strings.Split(v_c, "/")
- if len(v_c_l) != 2 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_app:", v_c, " len(v_c_l) != 2")
- continue
- }
- if len(v_c_l[0]) == 0 {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_app:", v_c, " len(v_c_l[0]) == 0")
- continue
- }
- admin_r, err := Account.Read_Admin_ByUuid(v_c_l[0])
- if err != nil {
- logs.Println("==> WarningCompanyNotice_CompanyNotice_Send 推送 T_Notice_app:", v_c, " Read_Admin_ByUuid!!")
- continue
- }
- //APP
- Warning.Add_Warning_Log(Warning_r, "---->"+admin_r.T_uuid+"/"+admin_r.T_name)
- reqdata_Message := "{\"WarningType\":\"" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\",\"T_Ut\":\"" + Warning_r.T_Ut.Format("2006-01-02 15:04:05") + "\",\"T_DS_name\":\"" + Warning_r.T_DS_name + "\",\"T_Remark\":\"" + Warning_r.T_Remark + "\",\"T_T\":\"" + strconv.FormatFloat(float64(T), 'f', -1, 32) + "\"}"
- NatsServer.App_Warn(Company_Charging_r, Warning_r, admin_r.T_uuid, reqdata_Message)
- }
- } else { // 间隔时间内 超过发送条数
- int_x, _ := strconv.Atoi(T_nm_list[N_index+3])
- Warning.Add_Warning_Log(Warning_r, "--!APP-> 间隔时间内 超过发送条数,当期值:"+strconv.Itoa(int_x)+"\n")
- }
- } else { // 未达到 持续时间 秒
- int_x, _ := strconv.Atoi(T_nm_list[N_index+1])
- Warning.Add_Warning_Log(Warning_r, "--!APP-> 未达到持续时间:"+strconv.Itoa(int_x)+"\n")
- }
- }
- }
- }
- // 报警发送给用户表
- func WarningToAdminId(Warning_r *Warning.Warning, T_Admin_list []int) {
- logs.Println("==>WarningToAdmin ", "Msid", Warning_r.T_Msid, " T_Admin_list:", T_Admin_list)
- // 查看 sn 是否有归属
- if Warning_r.T_pid == 0 { // 寻找报警归属
- if len(Warning_r.T_sn) > 10 {
- r_Device, err := Device.Read_Device_ByT_sn(Warning_r.T_sn)
- if err != nil {
- logs.Println("==> WarningToAdminId MessageDisconnected 没有该设备:", Warning_r.T_sn)
- }
- Warning_r.T_pid = r_Device.T_pid
- Warning_r.T_D_name = r_Device.T_devName
- }
- }
- // 补齐公司归属
- var Company_r Account.Company
- if Warning_r.T_pid != 0 {
- _, Company_r = Account.Read_Company_id(Warning_r.T_pid)
- }
- // 如果 还是为空
- if len(Company_r.T_name) == 0 {
- Company_r.T_name = "未知公司"
- }
- // 补齐传感器名称
- if len(Warning_r.T_DS_name) == 0 {
- DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(Warning_r.T_sn, Warning_r.T_id)
- if is {
- Warning_r.T_DS_name = DeviceSensor_r.T_name
- }
- }
- // 如果 还是为空 就等于 SN
- if len(Warning_r.T_DS_name) == 0 {
- Warning_r.T_DS_name = Warning_r.T_sn
- }
- // 选择相关 管理员
- if len(T_Admin_list) == 0 {
- if Warning_r.T_pid > 0 {
- // 有绑定公司的 管理员
- Warning.Add_Warning_Log(Warning_r, "有绑定公司ID -> ["+strconv.Itoa(Warning_r.T_pid)+"]\n")
- Tpids := Account.Read_Admin_Tpids_List(Warning_r.T_pid)
- for _, v := range Tpids {
- T_Admin_list = append(T_Admin_list, v.Id)
- }
- } else {
- // 默认发给管理员
- Warning.Add_Warning_Log(Warning_r, "默认发给管理员 -> [conf.EWarningAdmin]\n")
- T_Admin_list = conf.EWarningAdmin
- }
- }
- 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
- }
- // 微信通知
- if len(Admin_r.T_wx) > 3 {
- data_json_t := Wx_d_struct{
- Corporate: Wx_struct{Value: lib.Limit_len(Company_r.T_name, 20)},
- Type: Wx_struct{Value: Warning.Read_WarningType_Get(Warning_r.T_tp)},
- Name: Wx_struct{Value: lib.Limit_len(Warning_r.T_DS_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(Account.Company{Id: Warning_r.T_pid}, Warning_r, v_b_l[0], "gnpERD6ilOQK6zvp1W_PmY5SEDOcSxiHh_KJbCdeAqw", 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)
- 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, 20)},
- 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(Account.Company{Id: Warning_r.T_pid}, Warning_r, v_b_l[0], "gnpERD6ilOQK6zvp1W_PmY5SEDOcSxiHh_KJbCdeAqw", 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")
- }
- }()
- }
|