소스 검색

fixbug:报警策略,报警bug修复

zoie 2 년 전
부모
커밋
586a81038f
9개의 변경된 파일294개의 추가작업 그리고 125개의 파일을 삭제
  1. 2 1
      controllers/Data.go
  2. 108 26
      controllers/Device.go
  3. 17 0
      controllers/User.go
  4. 39 47
      controllers/lib/Onelink.go
  5. 17 7
      models/Account/Company.go
  6. 32 11
      models/Account/Menu.go
  7. 10 9
      models/Company/CompanyNotice.go
  8. 57 14
      models/Warning/Warning.go
  9. 12 10
      routers/router.go

+ 2 - 1
controllers/Data.go

@@ -777,7 +777,8 @@ func (c *DataController) Device_Sensor_Data_BackUp_PDF() {
 	}
 
 	deviceSensor, _ := Device.Read_DeviceSensor_ByT_sn(T_sn, T_id)
-	filenameStr := fmt.Sprintf("backup/sn/%s_%s_%s.pdf", lib.GetRandstring(8, "0123456789", 0), date.Format("2006_01_02"), deviceSensor.T_name)
+	rand_x := int64(lib.Random(0, 10000))
+	filenameStr := fmt.Sprintf("backup/sn/%s_%s_%s.pdf", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", rand_x), date.Format("2006_01_02"), deviceSensor.T_name)
 
 	err = pdf.WritePdf(filenameStr)
 	if err != nil {

+ 108 - 26
controllers/Device.go

@@ -1104,30 +1104,64 @@ func (c *DeviceController) DeviceWarning_List() {
 // 查询告警
 func (c *DeviceController) DeviceWarning_Get() {
 	id, _ := c.GetInt("T_id")
-	T := Warning.Read_Warning_ById(id)
+	T_history, _ := c.GetInt("T_history")
+	T := Warning.Read_Warning_ById(int64(id))
 
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Warning.WarningToWarning_R(T)}
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Warning.WarningToWarning_R(T_history, T)}
 	c.ServeJSON()
 	return
 }
 
 // 编辑告警(处理告警)
 func (c *DeviceController) DeviceWarning_Post() {
-	Id, _ := c.GetInt("T_id")
+	id, _ := c.GetInt("T_id")
 	T_Text := c.GetString("T_Text")
+	T_time := c.GetString("T_time")
+	T_history, _ := c.GetInt("T_history")
 
-	T := Warning.Read_Warning_ById(Id)
-	if T.Id == 0 {
-		c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
-		c.ServeJSON()
-		return
-	}
-	T.T_Text = T_Text
-	T.T_State = 2
+	var T_year, T_month string
+	var warning Warning.Warning
+	Wtab := "warning"
+	if T_history == 1 {
+		date, err := time.Parse("2006-01-02 15:04:05", T_time)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 200, Msg: "时间格式错误"}
+			c.ServeJSON()
+			return
+		}
+		T_year, T_month = date.Format("2006"), date.Format("01")
+		Wtab += "_" + T_year + "_" + T_month
+		warning, err = Warning.Read_Warning_ById_Backups(id, T_year, T_month)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
+			c.ServeJSON()
+			return
+		}
+		warning.T_Text = T_Text
+		warning.T_State = 2
+		if is := Warning.Update_Warning_Backups(warning, T_year, T_month); !is {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "修改失败!"}
+			c.ServeJSON()
+			return
+		}
 
-	Warning.Update_Warning(T, "T_Text", "T_State")
+	} else {
+		warning = Warning.Read_Warning_ById(int64(id))
+		if warning.Id == 0 {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
+			c.ServeJSON()
+			return
+		}
+		warning.T_Text = T_Text
+		warning.T_State = 2
+		if is := Warning.Update_Warning(warning, "T_Text", "T_State"); !is {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "修改失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
 
-	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
+	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "报警处理操作", Wtab+":"+strconv.Itoa(id)+"->"+T_Text)
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()
 	return
@@ -1135,19 +1169,52 @@ func (c *DeviceController) DeviceWarning_Post() {
 
 // 删除告警
 func (c *DeviceController) DeviceWarning_Del() {
-	Id, _ := c.GetInt("T_id")
+	id, _ := c.GetInt("T_id")
+	T_time := c.GetString("T_time")
+	T_history, _ := c.GetInt("T_history")
 
-	T := Warning.Read_Warning_ById(Id)
-	if T.Id == 0 {
-		c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
-		c.ServeJSON()
-		return
-	}
+	var T_year, T_month string
+	var warning Warning.Warning
+	Wtab := "warning"
+	if T_history == 1 {
+		date, err := time.Parse("2006-01-02 15:04:05", T_time)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 200, Msg: "时间格式错误"}
+			c.ServeJSON()
+			return
+		}
+		T_year, T_month = date.Format("2006"), date.Format("01")
+		Wtab += "_" + T_year + "_" + T_month
+
+		warning, err = Warning.Read_Warning_ById_Backups(id, T_year, T_month)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
+			c.ServeJSON()
+			return
+		}
+		warning.T_State = 0
+		if is := Warning.Update_Warning_Backups(warning, T_year, T_month); !is {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "删除失败!"}
+			c.ServeJSON()
+			return
+		}
 
-	T.T_State = 0
-	Warning.Update_Warning(T, "T_State")
+	} else {
+		warning = Warning.Read_Warning_ById(int64(id))
+		if warning.Id == 0 {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
+			c.ServeJSON()
+			return
+		}
+		warning.T_State = 0
+		if is := Warning.Update_Warning(warning, "T_Text", "T_State"); !is {
+			c.Data["json"] = lib.JSONS{Code: 206, Msg: "删除失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
 
-	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
+	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "报警删除操作", Wtab+":"+strconv.Itoa(id))
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()
 	return
@@ -1209,7 +1276,7 @@ func (c *DeviceController) DeviceWarning_Data_Excel() {
 	for _, v := range Device_data {
 		line++
 		f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), Warning.Read_WarningType_Get(v.T_tp))
-		f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.Id)+"]")
+		f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("%s[%d]", v.T_sn, v.Id))
 		f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_D_name)
 		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_DS_name)
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_Remark)
@@ -1674,25 +1741,40 @@ func (c *DeviceController) CompanyNotice_Edit() {
 		R_DeviceNotice.T_name = T_name
 	}
 	if len(T_Notice_wx) > 0 {
+		if T_Notice_wx == "-" {
+			T_Notice_wx = ""
+		}
 		R_DeviceNotice.T_Notice_wx = T_Notice_wx
 	}
 	if len(T_Notice_wx2) > 0 {
+		if T_Notice_wx2 == "-" {
+			T_Notice_wx2 = ""
+		}
 		R_DeviceNotice.T_Notice_wx2 = T_Notice_wx2
 	}
 	if len(T_Notice_phone) > 0 {
+		if T_Notice_phone == "-" {
+			T_Notice_phone = ""
+		}
 		R_DeviceNotice.T_Notice_phone = T_Notice_phone
 	}
 	if len(T_Notice_message) > 0 {
 		R_DeviceNotice.T_Notice_message = T_Notice_message
 	}
 	if len(T_Notice_mailbox) > 0 {
+		if T_Notice_mailbox == "-" {
+			T_Notice_mailbox = ""
+		}
 		R_DeviceNotice.T_Notice_mailbox = T_Notice_mailbox
 	}
 	if len(T_Notice_mechanism) > 0 {
+		if T_Notice_mechanism == "-" {
+			T_Notice_mechanism = ""
+		}
 		R_DeviceNotice.T_Notice_mechanism = T_Notice_mechanism
 	}
 
-	if is := Company.Update_CompanyNotice(R_DeviceNotice, "T_name", "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism"); !is {
+	if err = Company.Update_CompanyNotice(R_DeviceNotice, "T_name", "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism"); err != nil {
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
 		c.ServeJSON()
 		return
@@ -1721,7 +1803,7 @@ func (c *DeviceController) CompanyNotice_Reset_Mechanism() {
 
 	R_DeviceNotice.T_Notice_mechanism = Warning.Read_WarningType_All_T_Notice_mechanism()
 
-	if is := Company.Update_CompanyNotice(R_DeviceNotice, "T_Notice_mechanism"); !is {
+	if err = Company.Update_CompanyNotice(R_DeviceNotice, "T_Notice_mechanism"); err != nil {
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
 		c.ServeJSON()
 		return

+ 17 - 0
controllers/User.go

@@ -799,6 +799,12 @@ func (c *UserController) AdminCompanyBind_Add() {
 		return
 	}
 
+	if r.T_pids == "*" {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+		c.ServeJSON()
+		return
+	}
+
 	Company_r, err := Account.Read_Company_ById(T_pid)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_pid Err!"}
@@ -1106,3 +1112,14 @@ func (c *UserController) Menu_List_All() {
 	c.ServeJSON()
 	return
 }
+
+// 流量池
+func (c *UserController) Flow_Pool() {
+	var r_jsons lib.R_JSONS
+
+	r_jsons.Data, _ = lib.Yidong_group_data_margin()
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+	c.ServeJSON()
+	return
+}

+ 39 - 47
controllers/lib/Onelink.go

@@ -7,34 +7,32 @@ import (
 	"net/http"
 )
 
-func yidong_token() (string,bool) {
+func yidong_token() (string, bool) {
 
 	url := "https://api.iot.10086.cn/v5/ec/get/token?transid=851AIOT202204251553361888100000003&password=L44tB,J5EQhj&appid=851AIOT2022042515533618881&refresh=0"
 	method := "GET"
 
-	client := &http.Client {
-	}
+	client := &http.Client{}
 	req, err := http.NewRequest(method, url, nil)
 
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	res, err := client.Do(req)
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	defer res.Body.Close()
 
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	fmt.Println(string(body))
 
-
 	type Token struct {
 		Token string `json:"token"`
 	}
@@ -48,56 +46,54 @@ func yidong_token() (string,bool) {
 		fmt.Println("Error =", err)
 	}
 
-	fmt.Println("bodyjson:",c)
+	fmt.Println("bodyjson:", c)
 
 	//dd := c["result"]
-	if(len(c.Result) == 0){
-		return "",false
+	if len(c.Result) == 0 {
+		return "", false
 	}
-	fmt.Println("Token:",c.Result[0].Token)
+	fmt.Println("Token:", c.Result[0].Token)
 
-	return c.Result[0].Token,true
+	return c.Result[0].Token, true
 
 }
 
-
 // 实时查询群组本月套餐内GPRS流量使用量信息。
 type FlowPoolSharingInfo struct {
-	TotalAmount string `json:"totalAmount"`
+	TotalAmount  string `json:"totalAmount"`
 	RemainAmount string `json:"remainAmount"`
-	UseAmount string `json:"useAmount"`
+	UseAmount    string `json:"useAmount"`
 }
-func Yidong_group_data_margin() (FlowPoolSharingInfo,bool) {
-	token,token_is := yidong_token()
-	if !token_is{
-		return FlowPoolSharingInfo{},false
+
+func Yidong_group_data_margin() (FlowPoolSharingInfo, bool) {
+	token, token_is := yidong_token()
+	if !token_is {
+		return FlowPoolSharingInfo{}, false
 	}
-	url := "https://api.iot.10086.cn/v5/ec/query/group-data-margin?transid=851AIOT202204251553361888100000003&token="+token+"&groupId=9921000021089000"
+	url := "https://api.iot.10086.cn/v5/ec/query/group-data-margin?transid=851AIOT202204251553361888100000003&token=" + token + "&groupId=9921000021089000"
 	method := "GET"
 
-	client := &http.Client {
-	}
+	client := &http.Client{}
 	req, err := http.NewRequest(method, url, nil)
 
 	if err != nil {
 		fmt.Println(err)
-		return FlowPoolSharingInfo{},false
+		return FlowPoolSharingInfo{}, false
 	}
 	res, err := client.Do(req)
 	if err != nil {
 		fmt.Println(err)
-		return FlowPoolSharingInfo{},false
+		return FlowPoolSharingInfo{}, false
 	}
 	defer res.Body.Close()
 
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
 		fmt.Println(err)
-		return FlowPoolSharingInfo{},false
+		return FlowPoolSharingInfo{}, false
 	}
 	fmt.Println(string(body))
 
-
 	type List_data struct {
 		FlowPoolSharingInfo []FlowPoolSharingInfo `json:"flowPoolSharingInfo"`
 	}
@@ -111,50 +107,48 @@ func Yidong_group_data_margin() (FlowPoolSharingInfo,bool) {
 		fmt.Println("Error =", err)
 	}
 
-	fmt.Println("bodyjson:",c)
+	fmt.Println("bodyjson:", c)
 
 	//dd := c["result"]
-	if(len(c.Result) == 0){
-		return FlowPoolSharingInfo{},false
+	if len(c.Result) == 0 {
+		return FlowPoolSharingInfo{}, false
 	}
 	//fmt.Println("Token:",c.Result[0].UseAmount)
 
-	return c.Result[0].FlowPoolSharingInfo[0],true
+	return c.Result[0].FlowPoolSharingInfo[0], true
 
 }
 
 // 实时查询物联卡本月套餐内流量使用量。
-func yidong_sim_data_usage(msisdn string) (string,bool) {
-	token,token_is := yidong_token()
-	if !token_is{
-		return "",false
+func yidong_sim_data_usage(msisdn string) (string, bool) {
+	token, token_is := yidong_token()
+	if !token_is {
+		return "", false
 	}
-	url := "https://api.iot.10086.cn/v5/ec/query/sim-data-usage?transid=851AIOT202204251553361888100000003&token="+token+"&msisdn="+msisdn
+	url := "https://api.iot.10086.cn/v5/ec/query/sim-data-usage?transid=851AIOT202204251553361888100000003&token=" + token + "&msisdn=" + msisdn
 	method := "GET"
 
-	client := &http.Client {
-	}
+	client := &http.Client{}
 	req, err := http.NewRequest(method, url, nil)
 
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	res, err := client.Do(req)
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	defer res.Body.Close()
 
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
 		fmt.Println(err)
-		return "",false
+		return "", false
 	}
 	fmt.Println(string(body))
 
-
 	type List_data struct {
 		DataAmount string `json:"dataAmount"`
 	}
@@ -168,19 +162,18 @@ func yidong_sim_data_usage(msisdn string) (string,bool) {
 		fmt.Println("Error =", err)
 	}
 
-	fmt.Println("bodyjson:",c)
+	fmt.Println("bodyjson:", c)
 
 	//dd := c["result"]
-	if(len(c.Result) == 0){
-		return "",false
+	if len(c.Result) == 0 {
+		return "", false
 	}
 	//fmt.Println("Token:",c.Result[0].UseAmount)
 
-	return c.Result[0].DataAmount,true
+	return c.Result[0].DataAmount, true
 
 }
 
-
 //
 //
 //flowPoolSharingInfo,_ := yidong_group_data_margin()
@@ -190,4 +183,3 @@ func yidong_sim_data_usage(msisdn string) (string,bool) {
 //
 //sim_data_usage,_ := yidong_sim_data_usage("1440761145498")
 //println("单卡使用量:",sim_data_usage)
-

+ 17 - 7
models/Account/Company.go

@@ -434,15 +434,25 @@ func Read_Company_List_ByT_pids(T_pids string) (CompanyList []Company_R) {
 	var maps []Company
 	cond := orm.NewCondition()
 	cond1 := cond.And("T_State", 1)
-	if len(T_pids) >= 0 {
-		list := lib.SplitStringIds(T_pids, "P")
-		cond1 = cond1.And("Id__in", list)
+
+	if len(T_pids) == 0 {
+		return
 	}
 
-	_, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("Id").All(&maps)
-	if err != nil {
-		logs.Error(lib.FuncName(), err)
-		return CompanyList
+	if T_pids == "*" {
+		_, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
+		if err != nil {
+			logs.Error(lib.FuncName(), err)
+			return CompanyList
+		}
+	} else {
+		list := lib.SplitStringIds(T_pids, "P")
+		cond1 = cond1.And("Id__in", list)
+		_, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
+		if err != nil {
+			logs.Error(lib.FuncName(), err)
+			return CompanyList
+		}
 	}
 
 	parentMap, flag := getCompanyParent(maps)

+ 32 - 11
models/Account/Menu.go

@@ -11,16 +11,23 @@ import (
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	"strconv"
-	"strings"
 	"time"
 )
 
+const (
+	// Menu 菜单
+	MenuType string = "M"
+	// Button 按钮
+	ButtonType string = "B"
+)
+
 type Menu struct {
 	Id           int    `orm:"column(ID);size(11);auto;pk"`
 	T_mid        int    `orm:"size(200);null"`      // 上一级 ID
 	T_name       string `orm:"size(256);null"`      // 菜单标题
 	T_permission string `orm:"size(256);null"`      // 权限表示
 	T_icon       string `orm:"size(256);null"`      // 图标
+	T_type       string `orm:"size(2);null"`        // 菜单类型
 	T_sort       int    `orm:"size(11);default(0)"` // 排序 越小的越靠前,可以为负数
 	T_pid        int    `orm:"size(2);default(0)"`  // 1 进入公司后才能访问的菜单 0 公共菜单
 	T_State      int    `orm:"size(2);default(1)"`  // 0删除 1正常 2共有菜单
@@ -29,7 +36,7 @@ type Menu struct {
 
 type Menu_Permission struct {
 	Menu       []Menu
-	Permission map[string]bool
+	Permission []string
 }
 
 func (t *Menu) TableName() string {
@@ -233,7 +240,7 @@ func Read_Menu_Bind_List(Power_Id int, Bind_Menu string, T_pid int) (r Menu_Perm
 			logs.Error(lib.FuncName(), err)
 			return
 		}
-		m := Menu_Call(maps, 0)
+		m := Menu_Tree(maps, 0)
 		r.Menu = m
 		r.Permission = Get_Permission(maps)
 		Redis_Munu_Set(Power_Id, T_pid, r)
@@ -254,7 +261,7 @@ func Read_Menu_Bind_List(Power_Id int, Bind_Menu string, T_pid int) (r Menu_Perm
 		return
 	}
 
-	m := Menu_Call(maps, 0)
+	m := Menu_Tree(maps, 0)
 
 	r.Menu = m
 	r.Permission = Get_Permission(maps)
@@ -263,13 +270,10 @@ func Read_Menu_Bind_List(Power_Id int, Bind_Menu string, T_pid int) (r Menu_Perm
 	return r
 }
 
-func Get_Permission(menu []Menu) (permission map[string]bool) {
-	permission = make(map[string]bool)
+func Get_Permission(menu []Menu) (permission []string) {
 	for _, v := range menu {
-
-		if strings.Contains(v.T_permission, ":") {
-
-			permission[v.T_permission] = true
+		if v.T_type == ButtonType {
+			permission = append(permission, v.T_permission)
 		}
 	}
 	return
@@ -311,7 +315,7 @@ func Read_Menu_List_All() (maps []Menu, menu_ids []int) {
 	// 也可以直接使用 Model 结构体作为表名
 
 	qs := o.QueryTable(new(Menu))
-	_, err := qs.Filter("T_State", 1).OrderBy("Id", "-T_sort").All(&maps)
+	_, err := qs.Filter("T_State", 1).OrderBy("T_sort", "Id").All(&maps)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 		return
@@ -337,6 +341,23 @@ func Menu_Call(list []Menu, parentId int) []Menu {
 	return res
 }
 
+func Menu_Tree(list []Menu, parentId int) []Menu {
+	res := make([]Menu, 0)
+	for _, v := range list {
+		if v.T_type != MenuType {
+			continue
+		}
+		if v.T_name == "流量池" {
+			continue
+		}
+		if v.T_mid == parentId {
+			v.Children = Menu_Tree(list, v.Id)
+			res = append(res, v)
+		}
+	}
+	return res
+}
+
 // 添加
 func Add_API(m API) (id int64, err error) {
 	o := orm.NewOrm()

+ 10 - 9
models/Company/CompanyNotice.go

@@ -184,16 +184,16 @@ func Delete_CompanyNotice_ById(id int) bool {
 }
 
 // 修改
-func Update_CompanyNotice(m CompanyNotice, cols ...string) bool {
+func Update_CompanyNotice(m CompanyNotice, cols ...string) error {
 	o := orm.NewOrm()
 	num, err := o.Update(&m, cols...)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
-		return false
+		return err
 	}
 	fmt.Println("Number of records updated in database:", num)
 	Redis_CompanyNotice_Set(m)
-	return true
+	return nil
 }
 
 // 删除
@@ -280,7 +280,7 @@ func Add_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
 
 	o := orm.NewOrm()
 	v := CompanyNotice{Id: T_Notice_id}
-	T_Notice_bind := T_sn + strconv.Itoa(T_id) + "|"
+	T_Notice_bind := fmt.Sprintf("%s,%d|", T_sn, T_id)
 	err = o.Read(&v, "Id")
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -291,15 +291,16 @@ func Add_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
 	_, err = o.Update(&v, "T_Notice_bind")
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
-		return
+		return err
 	}
+	Redis_CompanyNotice_Set(v)
 	return nil
 }
 
 func Delete_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
 	o := orm.NewOrm()
 	v := CompanyNotice{Id: T_Notice_id}
-	T_Notice_bind := T_sn + strconv.Itoa(T_id) + "|"
+	T_Notice_bind := fmt.Sprintf("%s,%d|", T_sn, T_id)
 	err = o.Read(&v, "Id")
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -309,10 +310,10 @@ func Delete_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
 	_, err = o.Update(&v, "T_Notice_bind")
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
-		return
+		return err
 	}
-	return
-
+	Redis_CompanyNotice_Set(v)
+	return nil
 }
 
 // 修改用户同时修改报警策略绑定的用户信息

+ 57 - 14
models/Warning/Warning.go

@@ -15,7 +15,7 @@ import (
 
 // 模板
 type Warning struct {
-	Id        int       `orm:"column(ID);size(11);auto;pk"`
+	Id        int64     `orm:"column(ID);size(11);auto;pk"`
 	T_pid     int       `orm:"index;size(256);null"`        // Account.Company 绑定公司
 	T_tp      int       `orm:"index;size(200);null"`        // 报警类型   ->WarningList
 	T_sn      string    `orm:"index;size(256);null"`        // 设备序列号
@@ -46,7 +46,7 @@ type Warning struct {
 
 // 模板
 type Warning_R struct {
-	Id         int
+	Id         int64
 	T_pid      int      // Account.Company 绑定公司
 	T_tp       int      // 报警类型   ->WarningList
 	T_tp_name  string   // 报警类型名称
@@ -60,6 +60,7 @@ type Warning_R struct {
 	T_Log      []string // 处理日志
 	T_Msid     int64    // 消息ID
 	T_State    int      // 0 删除   1 未处理   2 已处理
+	T_history  int      // 0 40天 1 历史数据
 	CreateTime string   // 创建时间
 }
 
@@ -74,7 +75,7 @@ func init() {
 }
 
 // ---------------- 特殊方法 -------------------
-func WarningToWarning_R(t Warning) (r Warning_R) {
+func WarningToWarning_R(T_history int, t Warning) (r Warning_R) {
 	r.Id = t.Id
 	r.T_pid = t.T_pid
 	r.T_tp = t.T_tp
@@ -92,12 +93,13 @@ func WarningToWarning_R(t Warning) (r Warning_R) {
 
 	r.T_Msid = t.T_Msid
 	r.T_State = t.T_State
+	r.T_history = T_history
 	r.CreateTime = t.CreateTime.Format("2006-01-02 15:04:05")
 	return r
 }
 
 // 获取 ById
-func Read_Warning_ById(id int) (r Warning) {
+func Read_Warning_ById(id int64) (r Warning) {
 	o := orm.NewOrm()
 	r = Warning{Id: id}
 	err := o.Read(&r) // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
@@ -107,6 +109,31 @@ func Read_Warning_ById(id int) (r Warning) {
 	return r
 }
 
+// 获取 ById
+func Read_Warning_ById_Backups(id int, T_year string, T_month string) (r Warning, err error) {
+	o := orm.NewOrm()
+	var maps []Warning
+	// Warning_2022_07
+	Wtab := "warning_" + T_year + "_" + T_month
+
+	sql_WHERE := fmt.Sprintf(" t__state > 0 AND `ID`= %d", id)
+
+	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
+
+	fmt.Println(sql)
+	num, err := o.Raw(sql).QueryRows(&maps)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+	if num == 0 {
+		return r, orm.ErrNoRows
+	}
+
+	return maps[0], nil
+}
+
 // 添加
 func Add_Warning(m Warning) (id int64, err error) {
 	o := orm.NewOrm()
@@ -130,6 +157,22 @@ func Update_Warning(r Warning, cols ...string) bool {
 	return true
 }
 
+// 修改
+func Update_Warning_Backups(r Warning, T_year string, T_month string) bool {
+	o := orm.NewOrm()
+	Wtab := "warning_" + T_year + "_" + T_month
+
+	num, err := o.Raw("UPDATE "+Wtab+" SET `t__text` = ?,`t__state` = ? WHERE `ID` = ?", r.T_Text, r.T_State, r.Id).Exec()
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return false
+	}
+	fmt.Println("Number of records updated in database:", num)
+
+	return true
+}
+
 // 获取列表
 func Read_Warning_List(T_pid int, T_tp, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
 	o := orm.NewOrm()
@@ -177,7 +220,7 @@ func Read_Warning_List(T_pid int, T_tp, T_name string, T_handle int, Time_start_
 	var err error
 	if page_z == 9999 {
 		// 获取全部
-		_, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-CreateTime").All(&map_r)
+		_, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
 	} else {
 		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
 	}
@@ -193,7 +236,7 @@ func Read_Warning_List(T_pid int, T_tp, T_name string, T_handle int, Time_start_
 	}
 
 	for _, v := range map_r {
-		r = append(r, WarningToWarning_R(v))
+		r = append(r, WarningToWarning_R(0, v))
 	}
 
 	return r, cnt
@@ -252,7 +295,7 @@ func Read_Admin_Warning_List(T_pids, T_tp, T_name string, T_handle int, Time_sta
 		cond1 = cond1.And("T_State", 3)
 	}
 
-	_, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-CreateTime").All(&map_r)
+	_, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_Ut").All(&map_r)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 	}
@@ -263,7 +306,7 @@ func Read_Admin_Warning_List(T_pids, T_tp, T_name string, T_handle int, Time_sta
 	}
 
 	for _, v := range map_r {
-		r = append(r, WarningToWarning_R(v))
+		r = append(r, WarningToWarning_R(0, v))
 	}
 
 	return r, cnt
@@ -341,7 +384,7 @@ func Read_Warning_Backups(T_pid int, T_year string, T_month string, T_tp, T_name
 	}
 	//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 create_time DESC"
+		"FROM " + Wtab + " WHERE" + sql_WHERE + " ORDER BY t__ut DESC"
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
 	}
@@ -356,7 +399,7 @@ func Read_Warning_Backups(T_pid int, T_year string, T_month string, T_tp, T_name
 	key, _ := strconv.ParseInt(maps_z[0][0].(string), 10, 64)
 
 	for _, v := range maps {
-		r = append(r, WarningToWarning_R(v))
+		r = append(r, WarningToWarning_R(1, v))
 	}
 
 	return r, key
@@ -439,7 +482,7 @@ func Read_Admin_Warning_Backups(T_pids string, T_year string, T_month string, T_
 	}
 	//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 create_time DESC"
+		"FROM " + Wtab + " WHERE" + sql_WHERE + " ORDER BY t__ut DESC"
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
 	}
@@ -454,7 +497,7 @@ func Read_Admin_Warning_Backups(T_pids string, T_year string, T_month string, T_
 	key, _ := strconv.ParseInt(maps_z[0][0].(string), 10, 64)
 
 	for _, v := range maps {
-		r = append(r, WarningToWarning_R(v))
+		r = append(r, WarningToWarning_R(1, v))
 	}
 
 	return r, key
@@ -495,7 +538,7 @@ func Read_Warning_ALL_T_State_Count(T_pid, T_handle int, T_Warning string, Is_To
 
 // 设备日志
 type DeviceLogs struct {
-	Id         int
+	Id         int64
 	T_sn       string //
 	Logs_Txt   string // 详情
 	CreateTime string
@@ -529,7 +572,7 @@ func Read_DeviceLogs_List(T_sn string, page, page_z int) (r []DeviceLogs, cnt in
 		logs.Error(lib.FuncName(), err)
 		return
 	}
-	cnt, err = qs.Filter("T_sn", T_sn).Count()
+	cnt, err = qs.Filter("T_sn", T_sn).Filter("T_tp__in", DeviceLogType).Count()
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 		return

+ 12 - 10
routers/router.go

@@ -7,18 +7,20 @@ import (
 )
 
 func init() {
-	var version = conf.Version
+	ns := beego.NewNamespace(conf.Version,
 
-	// 公共
-	//beego.Router(version+"/UpFile", &controllers.UpFileController{}, "*:UpFile")
-	beego.Router(version+"/UpFileToken", &controllers.UpFileController{}, "*:ConfigUpFileToken")
+		beego.NSRouter("/UpFileToken", &controllers.UpFileController{}, "*:ConfigUpFileToken"),
+		beego.NSRouter("/Flow_Pool", &controllers.UserController{}, "*:Flow_Pool"), // 流量池
 
-	// 系统日志
-	beego.Router(version+"/System/LogsClass", &controllers.LogsController{}, "*:LogsClass") // 获取未读消息
-	beego.Router(version+"/System/LogsList", &controllers.LogsController{}, "*:LogsList")   // 获取未读消息
+		// 系统日志
+		beego.NSRouter("/System/LogsClass", &controllers.LogsController{}, "*:LogsClass"), // 获取未读消息
+		beego.NSRouter("/System/LogsList", &controllers.LogsController{}, "*:LogsList"),   // 获取未读消息
 
-	// 操作日志
-	beego.Router(version+"/System/UserLogsClass", &controllers.LogsController{}, "*:UserLogsClass") // 获取未读消息
-	beego.Router(version+"/System/UserLogsList", &controllers.LogsController{}, "*:UserLogsList")   // 获取未读消息
+		// 操作日志
+		beego.NSRouter("/System/UserLogsClass", &controllers.LogsController{}, "*:UserLogsClass"), // 获取未读消息
+		beego.NSRouter("/System/UserLogsList", &controllers.LogsController{}, "*:UserLogsList"),   // 获取未读消息
 
+	)
+
+	beego.AddNamespace(ns)
 }