Browse Source

fixbug:修复map并发读写问题,修复服务天数在一天内会变化问题,修复策略提示

zoie 2 years ago
parent
commit
6c2435b7cc

+ 1 - 1
conf/app.conf

@@ -39,4 +39,4 @@ Qiniu_Url = "https://coldoss.coldbaozhida.com/"
 Panel_url = "http://127.0.0.1:6204/Cold_Panel"
 
 FilterExcludeURL = /Login_verification
-FilterOnlyLoginCheckURL = /Menu/List,/User/Info,/User/Home,/UpFileToken,/User/WxQRCode
+FilterOnlyLoginCheckURL = /Menu/List,/User/Info,/User/Home,/User/Post,/UpFileToken,/User/WxQRCode

+ 145 - 79
controllers/Device.go

@@ -7,13 +7,13 @@ import (
 	"Cold_Api/models/Account"
 	"Cold_Api/models/Company"
 	"Cold_Api/models/Device"
-	"Cold_Api/models/Product"
 	"Cold_Api/models/System"
 	"Cold_Api/models/Warning"
 	"fmt"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/xuri/excelize/v2"
 	"math"
+	"os"
 	"strconv"
 	"time"
 )
@@ -67,7 +67,6 @@ func (c *DeviceController) Device_List() {
 	T_online := c.GetString("T_online")
 	T_monitor := c.GetString("T_monitor")
 
-	Product.Read_ProductType_All_Map()
 	r_jsons.Device_lite, r_jsons.Num = Device.Read_Device_List(c.Admin_r, c.T_pid, Name, T_monitor, T_online, page, page_z)
 
 	r_jsons.Page = page
@@ -321,24 +320,65 @@ func (c *DeviceController) Device_Parameter_List() {
 
 // 修改设备参数
 func (c *DeviceController) Device_Parameter_Pu() {
-	T_SN := c.GetString("T_sn")
-	T_name := c.GetString("T_name")
-
-	T_saveT, _ := c.GetInt("T_saveT")
-	T_overA, _ := c.GetInt("T_overA")
-	T_outA, _ := c.GetInt("T_outA")
-	T_lostA, _ := c.GetInt("T_lostA")
-	T_bat, _ := c.GetInt("T_bat")
-
-	T_warn, _ := c.GetInt("T_warn")
-	T_warnD, _ := c.GetInt("T_warnD")
-
-	T_btname := c.GetString("T_btname")
-	T_btsid, _ := c.GetInt("T_btsid")
-	T_btchar, _ := c.GetInt("T_btchar")
+	//T_SN := c.GetString("T_sn")
+	//T_name := c.GetString("T_name")
+	//
+	//T_saveT, _ := c.GetInt("T_saveT")
+	//T_overA, _ := c.GetInt("T_overA")
+	//T_outA, _ := c.GetInt("T_outA")
+	//T_lostA, _ := c.GetInt("T_lostA")
+	//T_bat, _ := c.GetInt("T_bat")
+	//
+	//T_warn, _ := c.GetInt("T_warn")
+	//T_warnD, _ := c.GetInt("T_warnD")
+	//
+	//T_btname := c.GetString("T_btname")
+	//T_btsid, _ := c.GetInt("T_btsid")
+	//T_btchar, _ := c.GetInt("T_btchar")
+	//
+	//T_Msid, _ := c.GetInt("T_Msid")
+	//T_State, _ := c.GetInt("T_State")
+	//
+	//Device_r, err := Device.Read_Device_ByT_sn(T_SN)
+	//if err != nil {
+	//	c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
+	//	c.ServeJSON()
+	//	return
+	//}
+	//
+	//Deviceparameter := Device.DeviceParameter{
+	//	T_sn:        T_SN,
+	//	T_name:      T_name,
+	//	T_saveT:     T_saveT,
+	//	T_overA:     T_overA,
+	//	T_outA:      T_outA,
+	//	T_lostA:     T_lostA,
+	//	T_bat:       T_bat,
+	//	T_warn:      T_warn,
+	//	T_warnD:     T_warnD,
+	//	T_btname:    T_btname,
+	//	T_btsid:     T_btsid,
+	//	T_btchar:    T_btchar,
+	//	T_Msid:      int64(T_Msid),
+	//	T_uuid:      c.Admin_r.T_uuid,
+	//	T_SendState: 0,
+	//	T_State:     T_State,
+	//}
+	//Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
+	//if !is {
+	//	c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
+	//	c.ServeJSON()
+	//	return
+	//}
+	//System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "设备参数操作", Deviceparameter)
+	//NatsServer.Pu_DeviceParameter(Deviceparameter)
+	//
+	//// 更新名称
+	//Device_r.T_devName = Deviceparameter.T_name
+	//Device.Update_Device(Device_r, "T_devName")
+	//System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "修改", Device_r)
 
-	T_Msid, _ := c.GetInt("T_Msid")
-	T_State, _ := c.GetInt("T_State")
+	T_SN := c.GetString("T_sn")
 
 	Device_r, err := Device.Read_Device_ByT_sn(T_SN)
 	if err != nil {
@@ -346,26 +386,60 @@ func (c *DeviceController) Device_Parameter_Pu() {
 		c.ServeJSON()
 		return
 	}
+	DeviceParameter_lite := Device.Read_DeviceParameter_SN_List(T_SN)
+	if len(DeviceParameter_lite) == 0 {
+		c.Data["json"] = lib.JSONS{Code: 203, Msg: "未同步参数,请检查设备是否正常!"}
+		c.ServeJSON()
+		return
+	}
 
-	Deviceparameter := Device.DeviceParameter{
-		T_sn:        T_SN,
-		T_name:      T_name,
-		T_saveT:     T_saveT,
-		T_overA:     T_overA,
-		T_outA:      T_outA,
-		T_lostA:     T_lostA,
-		T_bat:       T_bat,
-		T_warn:      T_warn,
-		T_warnD:     T_warnD,
-		T_btname:    T_btname,
-		T_btsid:     T_btsid,
-		T_btchar:    T_btchar,
-		T_Msid:      int64(T_Msid),
-		T_uuid:      c.Admin_r.T_uuid,
-		T_SendState: 0,
-		T_State:     T_State,
+	DeviceParameter := DeviceParameter_lite[0]
+
+	if v, err := c.GetInt("T_saveT"); err == nil {
+		DeviceParameter.T_saveT = v
+	}
+	if v, err := c.GetInt("T_overA"); err == nil {
+		DeviceParameter.T_overA = v
+	}
+	if v, err := c.GetInt("T_outA"); err == nil {
+		DeviceParameter.T_outA = v
+	}
+	if v, err := c.GetInt("T_lostA"); err == nil {
+		DeviceParameter.T_lostA = v
+	}
+	if v, err := c.GetInt("T_bat"); err == nil {
+		DeviceParameter.T_bat = v
+	}
+
+	if v, err := c.GetInt("T_warn"); err == nil {
+		DeviceParameter.T_warn = v
 	}
-	Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
+	if v, err := c.GetInt("T_warnD"); err == nil {
+		DeviceParameter.T_warnD = v
+	}
+	if v := c.GetString("T_btname"); len(v) > 0 {
+		DeviceParameter.T_btname = v
+	}
+	if v, err := c.GetInt("T_btsid"); err == nil {
+		DeviceParameter.T_btsid = v
+	}
+	if v, err := c.GetInt("T_btchar"); err == nil {
+		DeviceParameter.T_btchar = v
+	}
+	if v, err := c.GetInt("T_Msid"); err == nil {
+		DeviceParameter.T_Msid = int64(v)
+	}
+	if v, err := c.GetInt("T_State"); err == nil {
+		DeviceParameter.T_State = v
+	}
+
+	if v := c.GetString("T_name"); len(v) > 0 {
+		DeviceParameter.T_name = v
+	}
+	DeviceParameter.T_uuid = c.Admin_r.T_uuid
+	DeviceParameter.T_SendState = 0
+
+	Deviceparameter, is := Device.Add_DeviceParameter(DeviceParameter)
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
 		c.ServeJSON()
@@ -374,10 +448,12 @@ func (c *DeviceController) Device_Parameter_Pu() {
 	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "设备参数操作", Deviceparameter)
 	NatsServer.Pu_DeviceParameter(Deviceparameter)
 
-	// 更新名称
-	Device_r.T_devName = Deviceparameter.T_name
-	Device.Update_Device(Device_r, "T_devName")
-	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "修改", Device_r)
+	if v := c.GetString("T_name"); len(v) > 0 {
+		// 更新名称
+		Device_r.T_devName = Deviceparameter.T_name
+		Device.Update_Device(Device_r, "T_devName")
+		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "修改设备名称", Device_r)
+	}
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()
@@ -386,7 +462,7 @@ func (c *DeviceController) Device_Parameter_Pu() {
 }
 
 // 删除设备 传感器
-// fixme 没有检查
+// 2023-02-02 弃用
 func (c *DeviceController) Device_Parameter_Del_Device() {
 
 	Sn := c.GetString("Sn")
@@ -435,6 +511,10 @@ func (c *DeviceController) DeviceSensor_List() {
 	if T_type_err != nil {
 		T_type = -1
 	}
+	T_State, T_State_err := c.GetInt("T_state")
+	if T_State_err != nil {
+		T_State = -1
+	}
 	T_datashow, T_datashow_err := c.GetInt("T_datashow") //0 屏蔽数据展示  1 正常数据展示
 	if T_datashow_err != nil {
 		T_datashow = -1
@@ -453,7 +533,7 @@ func (c *DeviceController) DeviceSensor_List() {
 		}
 	}
 	Device.Read_DeviceSensorParameter_All_Map(T_sn, 0)
-	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorList(c.Admin_r, c.T_pid, T_sn, Name, T_calss_id, T_datashow, T_type, page, page_z)
+	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorList(c.Admin_r, c.T_pid, T_sn, Name, T_calss_id, T_datashow, T_type, T_State, page, page_z)
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 
@@ -585,7 +665,10 @@ func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 		return
 	}
 
-	T_name := c.GetString("T_name")
+	T_name := DeviceSensor.T_name
+	if v := c.GetString("T_name"); len(v) > 0 {
+		T_name = v
+	}
 
 	T_Tlower := DeviceSensorParameter.T_Tlower
 	if v, T_Tlower_err := c.GetFloat("T_Tlower"); T_Tlower_err == nil {
@@ -655,9 +738,6 @@ func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 		T_SendState: 0,
 		T_State:     2, // 用户提交
 	}
-	if len(T_name) == 0 {
-		Devicesensorparameter.T_name = DeviceSensor.T_name
-	}
 
 	Devicesensorparameter, is = Device.Add_DeviceSensorParameter(Devicesensorparameter)
 	if !is {
@@ -670,14 +750,13 @@ func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 	// 更新名称
 	if len(T_name) > 0 {
 		DeviceSensor.T_name = T_name
+		if is = Device.Update_DeviceSensor(DeviceSensor, "T_name"); !is {
+			c.Data["json"] = lib.JSONS{Code: 209, Msg: "Update_DeviceSensor Err!"}
+			c.ServeJSON()
+			return
+		}
+		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "修改传感器名称", DeviceSensor)
 	}
-	if is = Device.Update_DeviceSensor(DeviceSensor, "T_name"); !is {
-		c.Data["json"] = lib.JSONS{Code: 209, Msg: "Update_DeviceSensor Err!"}
-		c.ServeJSON()
-		return
-	}
-
-	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器操作", DeviceSensor)
 
 	NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
 
@@ -920,8 +999,6 @@ func (c *DeviceController) DeviceWarning_List() {
 		T_year, T_month = date.Format("2006"), date.Format("01")
 	}
 
-	Warning.Read_WarningType_All_Maps()
-
 	if T_admin == 1 {
 		if T_history == 1 {
 			// 获取备份
@@ -961,7 +1038,7 @@ func (c *DeviceController) DeviceWarning_Get() {
 	return
 }
 
-// 编辑告警
+// 编辑告警(处理告警)
 func (c *DeviceController) DeviceWarning_Post() {
 	Id, _ := c.GetInt("T_id")
 	T_Text := c.GetString("T_Text")
@@ -1062,10 +1139,10 @@ func (c *DeviceController) DeviceWarning_Data_Excel() {
 		return
 	}
 	//删除文件
-	//err := os.Remove("ofile/" + timeStr + ".xlsx")
-	//if err != nil {
-	//	fmt.Println(err)
-	//}
+	err := os.Remove("ofile/" + timeStr + ".xlsx")
+	if err != nil {
+		fmt.Println(err)
+	}
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
 	c.ServeJSON()
@@ -1086,7 +1163,7 @@ func (c *DeviceController) WarningType_List_All() {
 	return
 }
 
-// 告警类型列表
+// 告警类型列表 - 权限关联列表
 func (c *DeviceController) WarningType_Power_List_All() {
 
 	power, err := Account.Read_Power_ById(c.Admin_r.T_power)
@@ -1285,7 +1362,7 @@ func (c *DeviceController) DeviceClassBind_List() {
 		return
 	}
 	var cnt int64
-	Device_lite, cnt := Device.Read_DeviceSensor_List_T_Class(c.Admin_r, c.T_pid, T_class_id, T_sn, T_name, T_type, page, page_z)
+	Device_lite, cnt := Device.Read_DeviceSensor_List_T_Class(c.T_pid, T_class_id, T_sn, T_name, T_type, page, page_z)
 
 	r_jsons.DeviceSensor_lite = Device_lite
 
@@ -1327,7 +1404,7 @@ func (c *DeviceController) ClassBind_Add() {
 		return
 	}
 
-	DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
+	DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_T_Class(T_sn, T_id, T_class_id)
 	if len(DeviceSensor_class_list) > 0 {
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "重复绑定!"}
 		c.ServeJSON()
@@ -1371,7 +1448,7 @@ func (c *DeviceController) ClassBind_Del() {
 		return
 	}
 
-	DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
+	DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_T_Class(T_sn, T_id, T_class_id)
 	if len(DeviceSensor_class_list) == 0 {
 		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 		c.ServeJSON()
@@ -1459,21 +1536,10 @@ func (c *DeviceController) CompanyNotice_Get() {
 }
 func (c *DeviceController) CompanyNotice_Add() {
 	T_name := c.GetString("T_name")
-	T_Notice_wx := c.GetString("T_Notice_wx")
-	T_Notice_wx2 := c.GetString("T_Notice_wx2")
-	T_Notice_phone := c.GetString("T_Notice_phone")
-	T_Notice_message := c.GetString("T_Notice_message")
-	T_Notice_mailbox := c.GetString("T_Notice_mailbox")
-	T_Notice_mechanism := c.GetString("T_Notice_mechanism")
 	t_c := Company.CompanyNotice{
 		T_pid:              c.T_pid,
 		T_name:             T_name,
-		T_Notice_wx:        T_Notice_wx,
-		T_Notice_wx2:       T_Notice_wx2,
-		T_Notice_phone:     T_Notice_phone,
-		T_Notice_message:   T_Notice_message,
-		T_Notice_mailbox:   T_Notice_mailbox,
-		T_Notice_mechanism: T_Notice_mechanism,
+		T_Notice_mechanism: Warning.Read_WarningType_All_T_Notice_mechanism(),
 		T_State:            1,
 	}
 
@@ -1611,7 +1677,7 @@ func (c *DeviceController) DeviceNoticeBind_List() {
 		return
 	}
 	var cnt int64
-	Device_lite, cnt := Device.Read_DeviceSensor_List_T_Notice(c.Admin_r, c.T_pid, T_notice_id, page, page_z, T_sn, T_name, T_type)
+	Device_lite, cnt := Device.Read_DeviceSensor_List_T_Notice(c.T_pid, T_notice_id, page, page_z, T_sn, T_name, T_type)
 
 	r_jsons.DeviceSensor_lite = Device_lite
 
@@ -1741,7 +1807,7 @@ func (c *DeviceController) DeviceType_List_All() {
 
 	var r_jsons R_JSONS
 
-	r_jsons.Data = Device.Read_DeviceType_List_All()
+	r_jsons.Data = Device.Read_DeviceSensorType_List_All()
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
 	c.ServeJSON()

+ 22 - 34
controllers/Product.go

@@ -4,6 +4,7 @@ import (
 	"Cold_Api/Nats/NatsServer"
 	"Cold_Api/conf"
 	"Cold_Api/controllers/lib"
+	"Cold_Api/models/Account"
 	"Cold_Api/models/Device"
 	"Cold_Api/models/Product"
 	"Cold_Api/models/System"
@@ -14,16 +15,28 @@ import (
 
 type ProductController struct {
 	beego.Controller
+	Admin_r Account.Admin // 登陆的用户
+	T_pid   int           // 公司id
+}
+
+func (c *ProductController) Prepare() {
+	GetCookie := c.Ctx.GetCookie("User_tokey")
+	GetString := c.GetString("User_tokey")
+
+	User_tokey := GetCookie
+	if len(User_tokey) == 0 {
+		User_tokey = GetString
+	}
+
+	c.Admin_r = lib.Admin_r
+	T_pid := c.Admin_r.T_pid
+	if T_pid == 0 {
+		T_pid, _ = Account.Redis_Tokey_T_pid_Get(User_tokey)
+	}
+	c.T_pid = T_pid
 }
 
 func (c *ProductController) ProductUpgrade_List() {
-	// 验证登录
-	//b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
-	//if !b_ {
-	//	c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
-	//	c.ServeJSON()
-	//	return
-	//}
 	type R_JSONS struct {
 		//必须的大写开头
 		Data      []Product.ProductUpgrade_R
@@ -54,27 +67,11 @@ func (c *ProductController) ProductUpgrade_List() {
 	return
 }
 func (c *ProductController) ProductUpgrade_T_model_List() {
-	// 验证登录
-	b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
-	if !b_ {
-		c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
-		c.ServeJSON()
-		return
-	}
-
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Product.Read_ProductUpgrade_T_model()}
 	c.ServeJSON()
 	return
 }
 func (c *ProductController) ProductUpgrade_Add() {
-	// 验证登录
-	b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
-	if !b_ {
-		c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
-		c.ServeJSON()
-		return
-	}
-
 	T_model := c.GetString("T_model")
 	T_version := c.GetString("T_version")
 	T_file := c.GetString("T_file")
@@ -100,24 +97,15 @@ func (c *ProductController) ProductUpgrade_Add() {
 
 	for _, v := range deviceList {
 		NatsServer.Up_ProductUpgrade(v.T_sn, T_version, T_file)
-		System.Add_UserLogs_T(admin_r.T_uuid, "设备版本升级", "同步", "SN:"+v.T_sn+T_version+T_file)
 	}
 
-	System.Add_UserLogs_T(admin_r.T_uuid, "设备版本升级管理", "添加", var_)
+	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备版本升级管理", "添加", var_)
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
 	c.ServeJSON()
 	return
 }
 func (c *ProductController) ProductUpgrade_Del() {
-	// 验证登录
-	b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
-	if !b_ {
-		c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
-		c.ServeJSON()
-		return
-	}
-
 	id, _ := c.GetInt("T_id")
 
 	_, err := Product.Read_ProductUpgrade_ById(id)
@@ -133,7 +121,7 @@ func (c *ProductController) ProductUpgrade_Del() {
 		return
 	}
 
-	System.Add_UserLogs(admin_r.T_uuid, "设备版本升级管理", "删除", strconv.Itoa(id))
+	System.Add_UserLogs(c.Admin_r.T_uuid, "设备版本升级管理", "删除", strconv.Itoa(id))
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()

+ 6 - 1
controllers/User.go

@@ -467,7 +467,7 @@ func (c *UserController) User_Home() {
 	if admin_r.T_pid > 0 {
 		power, _ := Account.Read_Power_ById(admin_r.T_power)
 		company, _ := Account.Read_Company_ById(admin_r.T_pid)
-		info.T_Days = int(time.Now().Sub(company.CreateTime).Hours() / 24)
+		info.T_Days = lib.GetDiffDays(time.Now(), company.CreateTime)
 		AdminList := Account.Read_Admin_List_T_pids(admin_r.T_pid)
 		var Admin_ []Account.Admin_
 		for _, v := range AdminList {
@@ -653,6 +653,11 @@ func (c *UserController) Admin_Del() {
 		c.ServeJSON()
 		return
 	}
+	if admin_r_lod.Id == 1 {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "无权删除!"}
+		c.ServeJSON()
+		return
+	}
 	if is := Account.Delete_Admin(admin_r_lod); !is {
 		c.Data["json"] = lib.JSONS{Code: 200, Msg: "删除失败!"}
 		c.ServeJSON()

+ 1 - 1
controllers/lib/Qiniu.go

@@ -85,7 +85,7 @@ func UploadToken(T_suffix string) string {
 		ForceSaveKey: true,
 		SaveKey:      "UpImage/" + Tokey + "." + T_suffix,
 		//FsizeLimit:   1024 * 1024 * 1,
-		MimeLimit: "image/*;application/pdf;application/bin",
+		MimeLimit: "image/*;application/pdf;application/octet-stream",
 	}
 
 	upToken := putPolicy.UploadToken(Qiniu)

+ 8 - 0
controllers/lib/lib.go

@@ -435,3 +435,11 @@ func FuncName() string {
 	f := runtime.FuncForPC(pc[0])
 	return f.Name()
 }
+
+// 获取两个时间相差的天数,0表同一天,正数表t1>t2,负数表t1<t2
+func GetDiffDays(t1, t2 time.Time) int {
+	t1 = time.Date(t1.Year(), t1.Month(), t1.Day(), 0, 0, 0, 0, time.Local)
+	t2 = time.Date(t2.Year(), t2.Month(), t2.Day(), 0, 0, 0, 0, time.Local)
+
+	return int(t1.Sub(t2).Hours() / 24)
+}

+ 1 - 0
main.go

@@ -5,6 +5,7 @@ import (
 	"Cold_Api/conf"
 	"Cold_Api/controllers"
 	"Cold_Api/models/Device"
+	_ "Cold_Api/models/Product"
 	"Cold_Api/routers"
 	_ "Cold_Api/routers"
 	"fmt"

+ 2 - 4
models/Account/Menu.go

@@ -139,8 +139,8 @@ func Redis_Menu_Get(Power_Id, T_pid int) (r []Menu, is bool) {
 }
 
 func Redis_Menu_DelK(Power_Id int) (err error) {
-	err = redisCache_API.Delete(strconv.Itoa(Power_Id))
-	err = redisCache_API.Delete(strconv.Itoa(Power_Id) + "-Pid")
+	err = redisCache_Menu.Delete(strconv.Itoa(Power_Id))
+	err = redisCache_Menu.Delete(strconv.Itoa(Power_Id) + "-Pid")
 	return
 }
 
@@ -198,7 +198,6 @@ func Read_Menu_Bind_List(Power_Id int, Bind_Menu string, T_pid int) (maps []Menu
 
 	qs := o.QueryTable(new(Menu))
 	cond := orm.NewCondition()
-	// fixme 测试先不屏蔽
 	if T_pid == 0 {
 		cond = cond.And("T_pid", 0)
 	}
@@ -234,7 +233,6 @@ func recursiveMenu(T_pid int, MenuIds []int, AllIds *[]int) error {
 	o := orm.NewOrm()
 	qs := o.QueryTable(new(Menu))
 	cond := orm.NewCondition()
-	// fixme 测试先不屏蔽
 	if T_pid == 0 {
 		cond = cond.And("T_pid", 0)
 	}

+ 1 - 0
models/Device/DeviceData.go

@@ -432,6 +432,7 @@ func Read_DeviceData(T_sn string, T_id int) (t DeviceData_R) {
 	_, err := o.Raw(sql).QueryRows(&maps)
 
 	if err != nil {
+		logs.Println("Read_DeviceData: ", err)
 		return t
 	}
 

+ 10 - 37
models/Device/DeviceSensor.go

@@ -203,7 +203,7 @@ func Read_DeviceSensor_Num_ByT_sn(T_sn string) int {
 }
 
 // 获取列表
-func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name string, T_Class_id, T_datashow, T_type int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name string, T_Class_id, T_datashow, T_type, T_State int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -239,7 +239,7 @@ func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name
 	}
 
 	// 不是内部权限(T_pid>0),T_State=1 0 屏蔽  1 正常
-	if admin_r.T_pid > 0 {
+	if admin_r.T_pid > 0 || T_State == 1 {
 		cond1 = cond1.And("T_State", 1)
 	}
 
@@ -420,7 +420,7 @@ func Read_DeviceSensor_ALL_T_sn(T_sn string, page int, page_z int) (DeviceSensor
 }
 
 // 获取列表
-func Read_DeviceSensor_List_T_Class(admin Account.Admin, T_pid int, T_Class_id int, T_sn string, T_name string, T_type int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+func Read_DeviceSensor_List_T_Class(T_pid int, T_Class_id int, T_sn string, T_name string, T_type int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -442,37 +442,14 @@ func Read_DeviceSensor_List_T_Class(admin Account.Admin, T_pid int, T_Class_id i
 
 	var r []DeviceSensor
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_pid", T_pid).And("T_Class__icontains", T_Class).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
+	cond1 := cond.And("T_pid", T_pid).And("T_State", 1).And("T_Class__icontains", T_Class).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
 	if T_type > 0 {
 		cond1 = cond1.AndCond(cond.And("T_type", T_type))
 	}
 
-	if admin.T_pid > 0 {
-		cond1 = cond1.AndCond(cond1.And("T_State", 1))
-	}
-
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
 	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
 
-	//
-	//qs.Limit(page_z, offset).Filter("T_Bind__icontains", T_Bind).Filter("T_Class__icontains", T_Class).Filter("T_sn__icontains", SN_type).Filter("T_sn__icontains", T_sn).Filter("T_name__icontains", T_name).OrderBy("T_sort").All(&r)
-	//cnt, _ = qs.Filter("T_Bind__icontains", T_Bind).Filter("T_Class__icontains", T_Class).Filter("T_sn__icontains", T_sn).Filter("T_sn__icontains", SN_type).Filter("T_name__icontains", T_name).Count()
-
-	//for i, v := range r {
-	//
-	//	// 提前最新数据
-	//	DeviceSensorData, is := Read_DeviceSensorData_ById_New(v.T_sn, v.T_id)
-	//	if !is {
-	//		continue
-	//	}
-	//	if DeviceSensorData.T_time.After(v.T_time) {
-	//		//fmt.Println(v.T_sn, v.T_id, DeviceSensorData.T_time)
-	//		r[i].T_t = DeviceSensorData.T_t
-	//		r[i].T_rh = DeviceSensorData.T_rh
-	//		r[i].T_time = DeviceSensorData.T_time
-	//	}
-	//
-	//}
 	for _, v := range r {
 		DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_R(v))
 	}
@@ -504,7 +481,7 @@ func Read_DeviceSensor_Map_ALL_1(T_pid int, T_Class_id int, T_sn string, T_name
 }
 
 // 获取列表
-func Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn string, T_id int, T_Class_id int) (r []DeviceSensor) {
+func Read_DeviceSensor_ALL_T_sn_T_id_T_Class(T_sn string, T_id int, T_Class_id int) (r []DeviceSensor) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -541,6 +518,7 @@ func Read_DeviceSensor_ALL_Class_Id(T_Class_id int) (r []DeviceSensor) {
 
 	return r
 }
+
 func DELETE_DeviceSensor(SN string) bool {
 
 	sql := "DELETE FROM `cold`.`device_sensor` WHERE `t_sn` = '" + SN + "' "
@@ -611,7 +589,7 @@ func Read_DeviceSensor_ALL_Notice_Id(T_Notice_id int) (r []DeviceSensor) {
 }
 
 // 获取列表
-func Read_DeviceSensor_List_T_Notice(admin Account.Admin, T_pid int, T_Notice_id int, page int, page_z int, T_sn string, T_name string, T_type int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+func Read_DeviceSensor_List_T_Notice(T_pid int, T_Notice_id int, page int, page_z int, T_sn string, T_name string, T_type int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -633,14 +611,9 @@ func Read_DeviceSensor_List_T_Notice(admin Account.Admin, T_pid int, T_Notice_id
 
 	var r []DeviceSensor
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_pid", T_pid).And("T_Notice__icontains", T_Notice).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
+	cond1 := cond.And("T_pid", T_pid).And("T_State", 1).And("T_Notice__icontains", T_Notice).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
 	if T_type > 0 {
 		cond1 = cond1.AndCond(cond.And("T_type", T_type))
-
-	}
-
-	if admin.T_pid > 0 {
-		cond1 = cond1.AndCond(cond1.And("T_State", 1))
 	}
 
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
@@ -715,7 +688,7 @@ func Read_DeviceSensorManageList(admin_r Account.Admin, T_pid int, T_name string
 
 	// -------------
 	sql := "SELECT COUNT(ds.ID) FROM " + "device_sensor ds " +
-		"LEFT JOIN ( SELECT t_sn AS tsn,t_id AS tid,t_en " +
+		"LEFT JOIN ( SELECT t_sn AS tsn,t_id AS tid,t_en,t_free " +
 		"FROM device_sensor_parameter WHERE id IN (SELECT MAX(id) FROM device_sensor_parameter GROUP BY t_sn,t_id)) AS dsp " +
 		"ON ds.t_sn = dsp.tsn AND ds.t_id = dsp.tid" + " WHERE " + sql_WHERE
 	fmt.Println(sql)
@@ -745,7 +718,7 @@ func Read_DeviceSensorManageList(admin_r Account.Admin, T_pid int, T_name string
 	return maps, key
 }
 
-// 数据展示 传感器参数列表
+// 数据展示菜单下 传感器参数列表
 func Read_DeviceSensor_List_For_Data(T_pid int, T_sn string, T_name string, T_Class_id, T_type int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 	o := orm.NewOrm()

+ 9 - 5
models/Device/DeviceSensorParameter.go

@@ -11,6 +11,7 @@ import (
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
 	"strconv"
+	"sync"
 	"time"
 )
 
@@ -105,12 +106,15 @@ func (t *DeviceSensorParameter) TableName() string {
 }
 
 var redisCache_DeviceSensorParameter cache.Cache
-var DeviceSensorParameter_list map[int]DeviceSensorParameter_M // 泛型
+
+// var DeviceSensorParameter_list map[int]DeviceSensorParameter_M // 泛型
+var DeviceSensorParameter_list *sync.Map
+
 func init() {
 	//注册模型
 	orm.RegisterModel(new(DeviceSensorParameter))
 
-	DeviceSensorParameter_list = make(map[int]DeviceSensorParameter_M)
+	DeviceSensorParameter_list = new(sync.Map)
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 		"redis_DeviceSensorParameter", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
@@ -253,16 +257,16 @@ func Read_DeviceSensorParameter_All_Map(T_sn string, T_id int) {
 	qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&list)
 
 	for _, v := range list {
-		DeviceSensorParameter_list[v.Id] = DeviceSensorParameterToDeviceSensorParameter_M(v)
+		DeviceSensorParameter_list.Store(v.Id, DeviceSensorParameterToDeviceSensorParameter_M(v))
 	}
 
 }
 
 func Read_DeviceSensorParameter_Map_Get(id int) DeviceSensorParameter_M {
 	// 有先加入 给全部人发消息
-	v, ok := DeviceSensorParameter_list[id] /*如果确定是真实的,则存在,否则不存在 */
+	v, ok := DeviceSensorParameter_list.Load(id) /*如果确定是真实的,则存在,否则不存在 */
 	if ok {
-		return v
+		return v.(DeviceSensorParameter_M)
 	} else {
 		return DeviceSensorParameter_M{}
 	}

+ 1 - 1
models/Device/DeviceSensorType.go

@@ -25,7 +25,7 @@ func init() {
 	orm.RegisterModel(new(DeviceSensorType))
 }
 
-func Read_DeviceType_List_All() (r []DeviceSensorType) {
+func Read_DeviceSensorType_List_All() (r []DeviceSensorType) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名

+ 15 - 23
models/Product/ProductType.go

@@ -5,6 +5,7 @@ import (
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
 	_ "github.com/go-sql-driver/mysql"
+	"sync"
 	"time"
 )
 
@@ -31,21 +32,20 @@ type ProductType struct {
 // 新管理主机	MD100	TCP/4G/WiFi
 // 小管理主机	MD200G	4G-Cat.1/RS485
 
-var ProductType_list map[string]string // 泛型
-
 func (t *ProductType) TableName() string {
 	return "product_type" // 数据库名称   // ************** 替换 FormulaList **************
 }
 
-//var redisCache_WarningType cache.Cache
+// var redisCache_WarningType cache.Cache
+var ProductType_list *sync.Map
 
 func init() {
 	//注册模型
 	orm.RegisterModel(new(ProductType))
 
-	ProductType_list = make(map[string]string)
+	ProductType_list = new(sync.Map)
 
-	//go Read_WarningType_All()
+	go Read_ProductType_All_Map()
 }
 
 // 获取全部
@@ -55,30 +55,22 @@ func Read_ProductType_All_Map() {
 	logs.Println("=========== 初始化产品类型 =========")
 
 	o := orm.NewOrm()
-	//for true {
-	//	var r []ProductType
-	//	qs := o.QueryTable(new(ProductType))
-	//	qs.All(&r)
-	//
-	//	for _, v := range r {
-	//		ProductType_list[v.T_model] = v.T_name
-	//	}
-	//	time.Sleep(1 * time.Hour)
-	//}
-	var r []ProductType
-	qs := o.QueryTable(new(ProductType))
-	qs.All(&r)
+	for true {
+		var r []ProductType
+		qs := o.QueryTable(new(ProductType))
+		qs.All(&r)
 
-	for _, v := range r {
-		ProductType_list[v.T_model] = v.T_name
+		for _, v := range r {
+			ProductType_list.Store(v.T_model, v.T_name)
+		}
+		time.Sleep(1 * time.Hour)
 	}
-
 }
 func Read_ProductType_Get(T_model string) string {
 	// 有先加入 给全部人发消息
-	v, ok := ProductType_list[T_model] /*如果确定是真实的,则存在,否则不存在 */
+	v, ok := ProductType_list.Load(T_model) /*如果确定是真实的,则存在,否则不存在 */
 	if ok {
-		return v
+		return v.(string)
 	} else {
 		return "未知类型"
 	}

+ 14 - 14
models/Product/ProductUpgrade.go

@@ -52,16 +52,16 @@ func init() {
 	//注册模型
 	orm.RegisterModel(new(ProductUpgrade))
 
-	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-		"redis_ProductUpgrade", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
-	fmt.Println(config)
-	var err error
-	redisCache_ProductUpgrade, err = cache.NewCache("redis", config)
-	if err != nil || redisCache_ProductUpgrade == nil {
-		errMsg := "failed to init redis"
-		fmt.Println(errMsg, err)
-		panic(errMsg)
-	}
+	//config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
+	//	"redis_ProductUpgrade", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+	//fmt.Println(config)
+	//var err error
+	//redisCache_ProductUpgrade, err = cache.NewCache("redis", config)
+	//if err != nil || redisCache_ProductUpgrade == nil {
+	//	errMsg := "failed to init redis"
+	//	fmt.Println(errMsg, err)
+	//	panic(errMsg)
+	//}
 }
 
 // Redis_Set(m.T_sn,m) // Redis 更新缓存
@@ -118,10 +118,10 @@ func ProductUpgradeToProductUpgrade_R(t ProductUpgrade) (r ProductUpgrade_R) {
 
 // 获取 ById
 func Read_ProductUpgrade_ById(id int) (r ProductUpgrade, err error) {
-	key := strconv.Itoa(id)
-	if r, is := Redis_ProductUpgrade_Get(key); is {
-		return r, nil
-	}
+	//key := strconv.Itoa(id)
+	//if r, is := Redis_ProductUpgrade_Get(key); is {
+	//	return r, nil
+	//}
 	o := orm.NewOrm()
 	r = ProductUpgrade{Id: id}
 	err = o.Read(&r)

+ 15 - 9
models/Warning/WarningType.go

@@ -8,6 +8,7 @@ import (
 	_ "github.com/go-sql-driver/mysql"
 	"strconv"
 	"strings"
+	"sync"
 	"time"
 )
 
@@ -61,11 +62,12 @@ func (t *WarningType) TableName() string {
 }
 
 // var redisCache_WarningType cache.Cache
-var WarningType_list map[int]string // 泛型
+var WarningType_list *sync.Map // 泛型
 func init() {
 	//注册模型
-	WarningType_list = make(map[int]string)
+	WarningType_list = new(sync.Map)
 	orm.RegisterModel(new(WarningType))
+	go Read_WarningType_All_Maps()
 
 }
 
@@ -162,20 +164,24 @@ func Read_WarningType_All_Maps() {
 	logs.Println("=========== 初始化报警类型 =========")
 
 	o := orm.NewOrm()
-	var r []WarningType
-	qs := o.QueryTable(new(WarningType))
-	qs.All(&r)
 
-	for _, v := range r {
-		WarningType_list[v.Id] = v.T_name
+	for true {
+		var r []WarningType
+		qs := o.QueryTable(new(WarningType))
+		qs.All(&r)
+
+		for _, v := range r {
+			WarningType_list.Store(v.Id, v.T_name)
+		}
+		time.Sleep(1 * time.Hour)
 	}
 
 }
 func Read_WarningType_Get(id int) string {
 	// 有先加入 给全部人发消息
-	v, ok := WarningType_list[id] /*如果确定是真实的,则存在,否则不存在 */
+	v, ok := WarningType_list.Load(id) /*如果确定是真实的,则存在,否则不存在 */
 	if ok {
-		return v
+		return v.(string)
 	} else {
 		return "未知类型"
 	}

+ 6 - 0
routers/filter.go

@@ -74,6 +74,12 @@ func RBACFilter(ctx *context.Context) {
 
 // 验证需要T_pid访问的接口
 func T_pidFilter(ctx *context.Context) {
+
+	//判断是否只验证登录的URL
+	if _, ok := filterOnlyLoginCheckURLMap[ctx.Request.URL.Path]; ok {
+		return
+	}
+
 	GetCookie := ctx.GetCookie("User_tokey")
 	GetString := ctx.Input.Query("User_tokey")
 

+ 4 - 4
routers/v3.go

@@ -18,9 +18,9 @@ func init() {
 			beego.NSRouter("/RestartShutdown", &controllers.DeviceController{}, "*:Device_RestartShutdown"), // 重启/关机
 			beego.NSRouter("/ProductUpgrade", &controllers.DeviceController{}, "*:Device_ProductUpgrade"),   // 版本升级
 
-			beego.NSRouter("/Parameter_List", &controllers.DeviceController{}, "*:Device_Parameter_List"),                    // 设备参数列表
-			beego.NSRouter("/Parameter_Pu", &controllers.DeviceController{}, "*:Device_Parameter_Pu"),                        // 修改设备参数
-			beego.NSRouter("/Device_Parameter_Del_Device", &controllers.DeviceController{}, "*:Device_Parameter_Del_Device"), // 删除此设备
+			beego.NSRouter("/Parameter_List", &controllers.DeviceController{}, "*:Device_Parameter_List"), // 设备参数列表
+			beego.NSRouter("/Parameter_Pu", &controllers.DeviceController{}, "*:Device_Parameter_Pu"),     // 修改设备参数
+			//beego.NSRouter("/Device_Parameter_Del_Device", &controllers.DeviceController{}, "*:Device_Parameter_Del_Device"), // 删除此设备
 			// 设备日志
 			beego.NSRouter("/Log", &controllers.DeviceController{}, "*:DeviceLogs"), // 日志
 
@@ -98,7 +98,7 @@ func init() {
 
 		// 设备类型
 		beego.NSNamespace("/DeviceType",
-			beego.NSRouter("Type/List_All", &controllers.DeviceController{}, "*:DeviceType_List_All"), // 传感器设备类型列表
+			beego.NSRouter("/List_All", &controllers.DeviceController{}, "*:DeviceType_List_All"), // 传感器设备类型列表
 		),
 	)