|
@@ -5,10 +5,14 @@ import (
|
|
|
"Cold_Api/controllers/lib"
|
|
|
"Cold_Api/logs"
|
|
|
"Cold_Api/models/Account"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/astaxie/beego/cache"
|
|
|
+ _ "github.com/astaxie/beego/cache/redis"
|
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
|
orm2 "github.com/beego/beego/v2/client/orm"
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
+ "github.com/gomodule/redigo/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -117,13 +121,104 @@ type Warning_Applet struct {
|
|
|
CreateTime string // 创建时间
|
|
|
}
|
|
|
|
|
|
+type Warning_Count struct {
|
|
|
+ Key string
|
|
|
+ Count int64
|
|
|
+}
|
|
|
+
|
|
|
func (t *Warning) TableName() string {
|
|
|
return "warning" // 数据库名称 // ************** 替换 FormulaList **************
|
|
|
}
|
|
|
|
|
|
+var redis_Warning_Count cache.Cache
|
|
|
+
|
|
|
func init() {
|
|
|
//注册模型
|
|
|
orm.RegisterModel(new(Warning))
|
|
|
+
|
|
|
+ config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
|
|
|
+ "redis_Warning_Count", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
|
|
|
+ fmt.Println(config)
|
|
|
+ var err error
|
|
|
+ redis_Warning_Count, err = cache.NewCache("redis", config)
|
|
|
+ if err != nil || redis_Warning_Count == nil {
|
|
|
+ errMsg := "failed to init redis"
|
|
|
+ logs.Error(errMsg, err)
|
|
|
+ panic(errMsg)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func Redis_WarningCount_Set(id int, key string, count int64) (err error) {
|
|
|
+ //json序列化
|
|
|
+ idKey := strconv.Itoa(id)
|
|
|
+
|
|
|
+ warningCount, err := Redis_WarningCount_Get(idKey)
|
|
|
+ warningCount = append(warningCount, Warning_Count{
|
|
|
+ Key: key,
|
|
|
+ Count: count,
|
|
|
+ })
|
|
|
+
|
|
|
+ str, err := json.Marshal(warningCount)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = redis_Warning_Count.Put(idKey, str, 30*time.Minute)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Redis_Admin_Set", "set key:", idKey, ",value:", str, err)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// if r,is :=Redis_Get(T_sn);is{
|
|
|
+// return r,nil
|
|
|
+// }
|
|
|
+func Redis_WarningCount_Get(userId string) (count []Warning_Count, err error) {
|
|
|
+ if redis_Warning_Count.IsExist(userId) {
|
|
|
+ //println("找到key:",key)
|
|
|
+ v := redis_Warning_Count.Get(userId)
|
|
|
+
|
|
|
+ err = json.Unmarshal(v.([]byte), &count)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return count, err
|
|
|
+ }
|
|
|
+ return count, nil
|
|
|
+ }
|
|
|
+ return count, redis.ErrNil
|
|
|
+}
|
|
|
+func Redis_WarningCount_GetOne(id int, key string) (count int64, err error) {
|
|
|
+ countList := []Warning_Count{}
|
|
|
+ idKey := strconv.Itoa(id)
|
|
|
+ if !redis_Warning_Count.IsExist(idKey) {
|
|
|
+ return count, redis.ErrNil
|
|
|
+ }
|
|
|
+ //println("找到key:",key)
|
|
|
+ v := redis_Warning_Count.Get(idKey)
|
|
|
+
|
|
|
+ err = json.Unmarshal(v.([]byte), &countList)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return count, err
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, c := range countList {
|
|
|
+ if c.Key == key {
|
|
|
+ return c.Count, nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count, redis.ErrNil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func Redis_WarningCount_DelK(id int) (err error) {
|
|
|
+ idKey := strconv.Itoa(id)
|
|
|
+ err = redis_Warning_Count.Delete(idKey)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// ---------------- 特殊方法 -------------------
|
|
@@ -283,7 +378,8 @@ func Update_Warning_Backups(r Warning, T_year string, T_month string) bool {
|
|
|
}
|
|
|
|
|
|
// 获取列表
|
|
|
-func Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
|
|
|
+func Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
|
|
|
+ countRedisKey string) (r []Warning_R, cnt int64) {
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
|
var map_r []Warning
|
|
@@ -331,15 +427,28 @@ func Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_hand
|
|
|
// T_handle 1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
cond1 = cond1.And("T_State__gt", 1)
|
|
|
- }
|
|
|
- if T_handle == 2 {
|
|
|
- cond1 = cond1.And("T_State__gt", 0)
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
+ } else if T_handle == 3 {
|
|
|
cond1 = cond1.And("T_State", 3)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State__gt", 0)
|
|
|
}
|
|
|
|
|
|
var err error
|
|
|
+
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err = Redis_WarningCount_GetOne(T_pid, countRedisKey)
|
|
|
+ if err != nil {
|
|
|
+ cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Redis_WarningCount_Set(T_pid, countRedisKey, cnt)
|
|
|
+ }
|
|
|
+ if cnt == 0 {
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+
|
|
|
if page_z == 9999 {
|
|
|
// 获取全部
|
|
|
_, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
|
|
@@ -351,12 +460,6 @@ func Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_hand
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
- if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
for _, v := range map_r {
|
|
|
r = append(r, WarningToWarning_R(0, v))
|
|
|
}
|
|
@@ -366,9 +469,10 @@ func Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_hand
|
|
|
}
|
|
|
|
|
|
// 管理员报警列表
|
|
|
-func Read_Admin_Warning_List(T_pids string, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
|
|
|
+func Read_Admin_Warning_List(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
|
|
|
+ countRedisKey string) (r []Warning_R, cnt int64) {
|
|
|
|
|
|
- if len(T_pids) == 0 {
|
|
|
+ if len(admin.T_pids) == 0 {
|
|
|
return r, cnt
|
|
|
}
|
|
|
|
|
@@ -389,13 +493,12 @@ func Read_Admin_Warning_List(T_pids string, T_tp []string, T_name string, T_hand
|
|
|
cond := orm.NewCondition()
|
|
|
cond1 := orm.NewCondition()
|
|
|
|
|
|
- if T_pids != "*" && len(T_pids) > 0 {
|
|
|
- list := lib.SplitStringIds(T_pids, "P")
|
|
|
+ if admin.T_pids != "*" && len(admin.T_pids) > 0 {
|
|
|
+ list := lib.SplitStringIds(admin.T_pids, "P")
|
|
|
cond1 = cond1.And("T_pid__in", list)
|
|
|
}
|
|
|
if len(T_tp) > 0 {
|
|
|
cond1 = cond1.And("T_tp__in", T_tp)
|
|
|
-
|
|
|
}
|
|
|
if len(T_name) > 0 {
|
|
|
if len(T_name) == 16 {
|
|
@@ -417,22 +520,29 @@ func Read_Admin_Warning_List(T_pids string, T_tp []string, T_name string, T_hand
|
|
|
//1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
cond1 = cond1.And("T_State__gt", 1)
|
|
|
- }
|
|
|
- if T_handle == 2 {
|
|
|
- cond1 = cond1.And("T_State__gt", 0)
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
+ } else if T_handle == 3 {
|
|
|
cond1 = cond1.And("T_State", 3)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State__gt", 0)
|
|
|
}
|
|
|
-
|
|
|
- _, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
|
|
|
+ var err error
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err = Redis_WarningCount_GetOne(admin.Id, countRedisKey)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
+ cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Redis_WarningCount_Set(admin.Id, countRedisKey, cnt)
|
|
|
}
|
|
|
- cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if cnt == 0 {
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
for _, v := range map_r {
|
|
@@ -444,7 +554,8 @@ func Read_Admin_Warning_List(T_pids string, T_tp []string, T_name string, T_hand
|
|
|
}
|
|
|
|
|
|
// 获取列表备份
|
|
|
-func Read_Warning_Backups(T_pid int, bindSN []string, T_year string, T_month string, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
|
|
|
+func Read_Warning_Backups(T_pid int, bindSN []string, T_year string, T_month string, tpList []string, T_name string, T_handle int, Time_start_ string,
|
|
|
+ Time_end_ string, page int, page_z int, countRedisKey string) (r []Warning_R, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
var maps []Warning
|
|
@@ -462,11 +573,6 @@ func Read_Warning_Backups(T_pid int, bindSN []string, T_year string, T_month str
|
|
|
|
|
|
sql_WHERE := ""
|
|
|
|
|
|
- //cond := orm.NewCondition()
|
|
|
- //
|
|
|
- //cond1 := cond.And("T_State__gt", 0)
|
|
|
- sql_WHERE += " t__state > 0"
|
|
|
-
|
|
|
if len(bindSN) > 0 {
|
|
|
sql_WHERE += fmt.Sprintf(" AND t_sn in (%s)", lib.StringListToQuotesDotStr(bindSN))
|
|
|
}
|
|
@@ -494,30 +600,40 @@ func Read_Warning_Backups(T_pid int, bindSN []string, T_year string, T_month str
|
|
|
Time_end_ = lib.ReplaceSQL(Time_end_)
|
|
|
sql_WHERE += fmt.Sprintf(" AND t__ut <= '%s'", Time_end_)
|
|
|
}
|
|
|
- //不填或0:所有 1:已处理 2:未处理
|
|
|
+ //1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", true)
|
|
|
sql_WHERE += " AND t__state > 1"
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", false).And("T_State", 2)
|
|
|
+ } else if T_handle == 3 {
|
|
|
sql_WHERE += " AND t__state = 3"
|
|
|
+ } else {
|
|
|
+ sql_WHERE += " AND t__state > 0"
|
|
|
}
|
|
|
|
|
|
// -------------
|
|
|
|
|
|
- sql := "SELECT COUNT(ID) FROM " + Wtab + " WHERE " + sql_WHERE
|
|
|
- fmt.Println(sql)
|
|
|
- _, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err := Redis_WarningCount_GetOne(T_pid, countRedisKey)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return r, 0
|
|
|
+ sql := "SELECT COUNT(*) FROM " + Wtab + " WHERE " + sql_WHERE
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err = o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ if len(maps_z) == 0 {
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ cnt, _ = strconv.ParseInt(maps_z[0][0].(string), 10, 64)
|
|
|
+
|
|
|
+ Redis_WarningCount_Set(T_pid, countRedisKey, cnt)
|
|
|
}
|
|
|
- if len(maps_z) == 0 {
|
|
|
+ if cnt == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
+
|
|
|
//fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- sql = "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
+ sql := "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
"FROM " + Wtab + " WHERE" + sql_WHERE + " ORDER BY t__ut DESC"
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
@@ -530,20 +646,19 @@ func Read_Warning_Backups(T_pid int, bindSN []string, T_year string, T_month str
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- key, _ := strconv.ParseInt(maps_z[0][0].(string), 10, 64)
|
|
|
-
|
|
|
for _, v := range maps {
|
|
|
r = append(r, WarningToWarning_R(1, v))
|
|
|
}
|
|
|
|
|
|
- return r, key
|
|
|
+ return r, cnt
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取管理员列表备份
|
|
|
-func Read_Admin_Warning_Backups(T_pids string, T_year string, T_month string, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
|
|
|
+func Read_Admin_Warning_Backups(admin Account.Admin, T_year string, T_month string, T_tp []string, T_name string, T_handle int,
|
|
|
+ Time_start_ string, Time_end_ string, page int, page_z int, countRedisKey string) (r []Warning_R, cnt int64) {
|
|
|
|
|
|
- if len(T_pids) == 0 {
|
|
|
+ if len(admin.T_pids) == 0 {
|
|
|
return r, cnt
|
|
|
}
|
|
|
|
|
@@ -566,10 +681,8 @@ func Read_Admin_Warning_Backups(T_pids string, T_year string, T_month string, T_
|
|
|
|
|
|
sql_WHERE := ""
|
|
|
|
|
|
- sql_WHERE += " t__state > 0"
|
|
|
-
|
|
|
- if T_pids != "*" {
|
|
|
- list := lib.SplitStringToDotStr(T_pids, "P")
|
|
|
+ if admin.T_pids != "*" {
|
|
|
+ list := lib.SplitStringToDotStr(admin.T_pids, "P")
|
|
|
sql_WHERE += fmt.Sprintf(" AND t_pid in (%s)", list)
|
|
|
}
|
|
|
|
|
@@ -594,29 +707,38 @@ func Read_Admin_Warning_Backups(T_pids string, T_year string, T_month string, T_
|
|
|
}
|
|
|
//1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", true)
|
|
|
sql_WHERE += " AND t__state > 1"
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", false).And("T_State", 2)
|
|
|
+ } else if T_handle == 3 {
|
|
|
sql_WHERE += " AND t__state = 3"
|
|
|
+ } else {
|
|
|
+ sql_WHERE += " AND t__state > 0"
|
|
|
}
|
|
|
+ sql_WHERE = strings.TrimLeft(sql_WHERE, " AND")
|
|
|
|
|
|
- // -------------
|
|
|
-
|
|
|
- sql := "SELECT COUNT(ID) FROM " + Wtab + " WHERE" + sql_WHERE
|
|
|
- fmt.Println(sql)
|
|
|
- _, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err := Redis_WarningCount_GetOne(admin.Id, countRedisKey)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return r, 0
|
|
|
+ sql := "SELECT COUNT(*) FROM " + Wtab + " WHERE " + sql_WHERE
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err = o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ if len(maps_z) == 0 {
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ cnt, _ = strconv.ParseInt(maps_z[0][0].(string), 10, 64)
|
|
|
+
|
|
|
+ Redis_WarningCount_Set(admin.Id, countRedisKey, cnt)
|
|
|
}
|
|
|
- if len(maps_z) == 0 {
|
|
|
+ if cnt == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
+
|
|
|
//fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- sql = "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
- "FROM " + Wtab + " WHERE" + sql_WHERE + " ORDER BY t__ut DESC"
|
|
|
+ sql := "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
+ "FROM " + Wtab + " WHERE " + sql_WHERE + " ORDER BY t__ut DESC"
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
@@ -804,8 +926,12 @@ func Read_WarningCount_byDay(T_pids []int) (cnt int64) {
|
|
|
qs := o.QueryTable(new(Warning))
|
|
|
cond := orm.NewCondition()
|
|
|
yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
|
|
|
- cond = cond.And("T_State__gt", 0).And("T_pid__in", T_pids).And("T_tp__in", RateType).And("CreateTime__gte", yesterday+" 00:00:00").And("CreateTime__lte", yesterday+" 23:59:59")
|
|
|
-
|
|
|
+ cond = cond.And("T_State__gt", 0).And("T_tp__in", RateType).And("CreateTime__gte", yesterday+" 00:00:00").And("CreateTime__lte", yesterday+" 23:59:59")
|
|
|
+ if len(T_pids) == 1 {
|
|
|
+ cond = cond.And("T_pid", T_pids[0])
|
|
|
+ } else if len(T_pids) > 1 {
|
|
|
+ cond = cond.And("T_pid__in", T_pids)
|
|
|
+ }
|
|
|
cnt, err := qs.SetCond((*orm2.Condition)(cond)).Count()
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -816,7 +942,8 @@ func Read_WarningCount_byDay(T_pids []int) (cnt int64) {
|
|
|
}
|
|
|
|
|
|
// 公司管理报警列表
|
|
|
-func Read_Company_Warning_List(T_pids []int, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []CompanyWarning_R, cnt int64) {
|
|
|
+func Read_Company_Warning_List(T_pids []int, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
|
|
|
+ T_pid int, countRedisKey string) (r []CompanyWarning_R, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -834,7 +961,11 @@ func Read_Company_Warning_List(T_pids []int, T_tp []string, T_name string, T_han
|
|
|
|
|
|
cond := orm.NewCondition()
|
|
|
cond1 := orm.NewCondition()
|
|
|
- cond1 = cond1.And("T_pid__in", T_pids)
|
|
|
+ if len(T_pids) == 1 {
|
|
|
+ cond1 = cond1.And("T_pid", T_pids[0])
|
|
|
+ } else if len(T_pids) > 1 {
|
|
|
+ cond1 = cond1.And("T_pid__in", T_pids)
|
|
|
+ }
|
|
|
|
|
|
if len(T_tp) > 0 {
|
|
|
cond1 = cond1.And("T_tp__in", T_tp)
|
|
@@ -859,22 +990,30 @@ func Read_Company_Warning_List(T_pids []int, T_tp []string, T_name string, T_han
|
|
|
//1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
cond1 = cond1.And("T_State__gt", 1)
|
|
|
- }
|
|
|
- if T_handle == 2 {
|
|
|
- cond1 = cond1.And("T_State__gt", 0)
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
+ } else if T_handle == 3 {
|
|
|
cond1 = cond1.And("T_State", 3)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State__gt", 0)
|
|
|
}
|
|
|
|
|
|
- _, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
|
|
|
+ var err error
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err = Redis_WarningCount_GetOne(T_pid, countRedisKey)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
+ cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Redis_WarningCount_Set(T_pid, countRedisKey, cnt)
|
|
|
+ }
|
|
|
+ if cnt == 0 {
|
|
|
+ return r, 0
|
|
|
}
|
|
|
- cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+
|
|
|
+ _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
for _, v := range map_r {
|
|
@@ -886,7 +1025,8 @@ func Read_Company_Warning_List(T_pids []int, T_tp []string, T_name string, T_han
|
|
|
}
|
|
|
|
|
|
// 获取公司管理列表备份
|
|
|
-func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []CompanyWarning_R, cnt int64) {
|
|
|
+func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string,
|
|
|
+ page int, page_z int, T_pid int, countRedisKey string) (r []CompanyWarning_R, cnt int64) {
|
|
|
|
|
|
if len(T_pids) == 0 {
|
|
|
return r, cnt
|
|
@@ -910,10 +1050,9 @@ func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T
|
|
|
}
|
|
|
|
|
|
sql_WHERE := ""
|
|
|
-
|
|
|
- sql_WHERE += " t__state > 0"
|
|
|
-
|
|
|
- if len(T_pids) > 0 {
|
|
|
+ if len(T_pids) == 1 {
|
|
|
+ sql_WHERE += fmt.Sprintf(" AND t_pid = %d", T_pids[0])
|
|
|
+ } else if len(T_pids) > 1 {
|
|
|
sql_WHERE += fmt.Sprintf(" AND t_pid in (%s)", lib.IntListToDotStr(T_pids))
|
|
|
}
|
|
|
|
|
@@ -938,29 +1077,36 @@ func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T
|
|
|
}
|
|
|
//1:默认 2:全部记录 3 未处理
|
|
|
if T_handle == 1 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", true)
|
|
|
sql_WHERE += " AND t__state > 1"
|
|
|
- }
|
|
|
- if T_handle == 3 {
|
|
|
- //cond1 = cond1.And("T_Text__isnull", false).And("T_State", 2)
|
|
|
+ } else if T_handle == 3 {
|
|
|
sql_WHERE += " AND t__state = 3"
|
|
|
+ } else {
|
|
|
+ sql_WHERE += " AND t__state > 0"
|
|
|
}
|
|
|
+ sql_WHERE = strings.TrimLeft(sql_WHERE, " AND")
|
|
|
|
|
|
- // -------------
|
|
|
-
|
|
|
- sql := "SELECT COUNT(ID) FROM " + Wtab + " WHERE" + sql_WHERE
|
|
|
- fmt.Println(sql)
|
|
|
- _, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ // 从redis获取报警统计数量
|
|
|
+ cnt, err := Redis_WarningCount_GetOne(T_pid, countRedisKey)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), err)
|
|
|
- return r, 0
|
|
|
+ sql := "SELECT COUNT(*) FROM " + Wtab + " WHERE " + sql_WHERE
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err = o.Raw(sql).ValuesList(&maps_z)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ if len(maps_z) == 0 {
|
|
|
+ return r, 0
|
|
|
+ }
|
|
|
+ cnt, _ = strconv.ParseInt(maps_z[0][0].(string), 10, 64)
|
|
|
+
|
|
|
+ Redis_WarningCount_Set(T_pid, countRedisKey, cnt)
|
|
|
}
|
|
|
- if len(maps_z) == 0 {
|
|
|
+ if cnt == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
- //fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- sql = "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
- "FROM " + Wtab + " WHERE" + sql_WHERE + " ORDER BY t__ut DESC"
|
|
|
+ sql := "SELECT ID,t_pid,t_tp,t_sn,t__d_name,t_id,t__d_s_name,t__remark,t__ut,t__text,t__log,t__msid,t__state,create_time,update_time " +
|
|
|
+ "FROM " + Wtab + " WHERE " + sql_WHERE + " ORDER BY t__ut DESC"
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
@@ -972,12 +1118,10 @@ func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- key, _ := strconv.ParseInt(maps_z[0][0].(string), 10, 64)
|
|
|
-
|
|
|
for _, v := range maps {
|
|
|
r = append(r, WarningToCompanyWarning_R(1, v))
|
|
|
}
|
|
|
|
|
|
- return r, key
|
|
|
+ return r, cnt
|
|
|
|
|
|
}
|