Bladeren bron

update:设备,传感器model调整,修复删除权限,公司,设备列表bug

zoie 2 jaren geleden
bovenliggende
commit
1310660b5b

+ 10 - 1
Nats/Nats.go

@@ -94,11 +94,19 @@ func NatsInit() {
 		type T_R struct {
 		type T_R struct {
 			Code int16           `xml:"Code"`
 			Code int16           `xml:"Code"`
 			Msg  string          `xml:"Msg"`
 			Msg  string          `xml:"Msg"`
+			Pid  int             `xml:"Pid"`  // 公司id
 			Data Account.Admin_R `xml:"Data"` // 泛型
 			Data Account.Admin_R `xml:"Data"` // 泛型
 		}
 		}
 
 
 		var t_R T_R
 		var t_R T_R
-
+		T_pid, is := Account.Redis_Tokey_T_pid_Get(string(m.Data))
+		if !is {
+			t_R.Code = 201
+			t_R.Msg = "User_tokey Err!"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
 		// 验证登录
 		// 验证登录
 		b_, admin_r := lib.Verification(string(m.Data), "")
 		b_, admin_r := lib.Verification(string(m.Data), "")
 		if !b_ {
 		if !b_ {
@@ -110,6 +118,7 @@ func NatsInit() {
 			return
 			return
 		}
 		}
 
 
+		t_R.Pid = T_pid
 		t_R.Code = 200
 		t_R.Code = 200
 		t_R.Msg = "ok"
 		t_R.Msg = "ok"
 		t_R.Data = Account.AdminToAdmin_R(admin_r)
 		t_R.Data = Account.AdminToAdmin_R(admin_r)

+ 10 - 8
controllers/Data.go

@@ -72,23 +72,25 @@ func (c *DataController) Device_Sensor_List() {
 	}
 	}
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
 	page_z, _ := c.GetInt("page_z")
 	page_z, _ := c.GetInt("page_z")
-	println(page_z)
+
 	if page_z == 0 {
 	if page_z == 0 {
 		page_z = conf.Page_size
 		page_z = conf.Page_size
 	}
 	}
 
 
 	T_sn := c.GetString("T_sn")
 	T_sn := c.GetString("T_sn")
-	T_Calss_id, _ := c.GetInt("T_class_id")
+	T_Class_id, _ := c.GetInt("T_class_id")
+	T_type, T_type_err := c.GetInt("T_type")
+	if T_type_err != nil {
+		T_type = -1
+	}
 	T_name := c.GetString("T_name")
 	T_name := c.GetString("T_name")
-	SN_type := c.GetString("SN_type")
 
 
 	var cnt int64
 	var cnt int64
-	r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_class_ALL_1(c.Admin_r, c.T_pid, T_Calss_id, page, page_z, T_sn, T_name, SN_type)
+	r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_List_For_Data(c.T_pid, T_sn, T_name, T_Class_id, T_type, page, page_z)
 
 
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	r_jsons.Page = int(page)
 	r_jsons.Page = int(page)
@@ -121,7 +123,7 @@ func (c *DataController) Device_Sensor_Data() {
 	}
 	}
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 	var cnt int
 	var cnt int
-	Device.Read_DeviceSensorParameter_Map_All(SN, T_id)
+	Device.Read_DeviceSensorParameter_All_Map(SN, T_id)
 	r_jsons.DeviceSensor_data, cnt = Device.Read_DeviceData_ById_List(SN, T_id, Time_start, Time_end, page, page_z)
 	r_jsons.DeviceSensor_data, cnt = Device.Read_DeviceData_ById_List(SN, T_id, Time_start, Time_end, page, page_z)
 
 
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
@@ -138,7 +140,7 @@ func (c *DataController) Device_Sensor_Data() {
 // 设备数据
 // 设备数据
 func (c *DataController) Device_Sensor_Data_More() {
 func (c *DataController) Device_Sensor_Data_More() {
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -407,7 +409,7 @@ func (c *DataController) DeviceSensor_Data_Print() {
 		r_jsons[tt] = R_JSONS{T_time: tt, T1: nil, T2: nil, T3: nil, T4: nil}
 		r_jsons[tt] = R_JSONS{T_time: tt, T1: nil, T2: nil, T3: nil, T4: nil}
 	}
 	}
 	// 记录传感器
 	// 记录传感器
-	Device.Read_DeviceSensorParameter_Map_All(SN, T_id)
+	Device.Read_DeviceSensorParameter_All_Map(SN, T_id)
 	maps, num := Device.Read_DeviceData_ById_List(SN, T_id, Time_start, Time_end, 1, 9999)
 	maps, num := Device.Read_DeviceData_ById_List(SN, T_id, Time_start, Time_end, 1, 9999)
 	if num > 0 {
 	if num > 0 {
 		for _, v_map := range maps {
 		for _, v_map := range maps {

+ 236 - 171
controllers/Device.go

@@ -55,7 +55,6 @@ func (c *DeviceController) Device_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -83,14 +82,11 @@ func (c *DeviceController) Device_List() {
 func (c *DeviceController) Device_Add() {
 func (c *DeviceController) Device_Add() {
 	var err error
 	var err error
 	T_sn := c.GetString("T_sn")
 	T_sn := c.GetString("T_sn")
-	T_MSISDN := c.GetString("T_MSISDN")
 	T_type, _ := c.GetInt("T_type")
 	T_type, _ := c.GetInt("T_type")
 	var_ := Device.Device{
 	var_ := Device.Device{
 		T_pid:     c.T_pid,
 		T_pid:     c.T_pid,
 		T_sn:      T_sn,
 		T_sn:      T_sn,
-		T_MSISDN:  T_MSISDN,
 		T_type:    T_type,
 		T_type:    T_type,
-		T_give:    1,
 		T_monitor: 1,
 		T_monitor: 1,
 		T_State:   1,
 		T_State:   1,
 	}
 	}
@@ -139,34 +135,72 @@ func (c *DeviceController) Device_Edit() {
 		c.ServeJSON()
 		c.ServeJSON()
 		return
 		return
 	}
 	}
+	clos := make([]string, 0)
 
 
-	T_VerifyTime := c.GetString("T_VerifyTime")
-	if len(T_VerifyTime) > 5 {
-		stamp, err := time.ParseInLocation("2006-01-02 15:04:05", T_VerifyTime, time.Local)
-		if err == nil {
-			Device_r.T_VerifyTime = stamp
-			Device.Update_Device(Device_r, "T_VerifyTime")
-			System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "验证时间操作", "验证时间:"+T_VerifyTime)
-		} else {
-			c.Data["json"] = lib.JSONS{Code: 203, Msg: "时间解析错误!" + T_VerifyTime}
-			c.ServeJSON()
-			return
-		}
+	// 监控状态 0 未监控 1 监控
+	T_monitor, T_monitor_err := c.GetInt("T_monitor")
+	if T_monitor_err == nil {
+		Device_r.T_monitor = T_monitor
+		clos = append(clos, "T_monitor")
+	}
+	// 设备类型
+	T_type, T_type_err := c.GetInt("T_type")
+	if T_type_err == nil {
+		Device_r.T_type = T_type
+		clos = append(clos, "T_type")
+	}
+	// 温度显示
+	T_ist, T_ist_err := c.GetInt("T_ist")
+	if T_ist_err == nil {
+		Device_r.T_ist = T_ist
+		clos = append(clos, "T_ist")
+	}
+	// 适度显示
+	T_ish, T_ish_err := c.GetInt("T_ish")
+	if T_ish_err == nil {
+		Device_r.T_ish = T_ish
+		clos = append(clos, "T_ish")
+	}
+	// 是否弃用
+	T_State, T_State_err := c.GetInt("T_State")
+	if T_State_err == nil {
+		Device_r.T_State = T_State
+		clos = append(clos, "T_State")
+	}
 
 
+	// 验证时间
+	T_VerifyTime := c.GetString("T_VerifyTime")
+	VerifyTime, VerifyTime_is := lib.TimeStrToTime(T_VerifyTime)
+	if VerifyTime_is {
+		Device_r.T_VerifyTime = VerifyTime
+		clos = append(clos, "T_VerifyTime")
 	}
 	}
 
 
+	// 校准时间
 	T_CalibrationTime := c.GetString("T_CalibrationTime")
 	T_CalibrationTime := c.GetString("T_CalibrationTime")
-	if len(T_CalibrationTime) > 5 {
-		stamp, err := time.ParseInLocation("2006-01-02 15:04:05", T_CalibrationTime, time.Local)
-		if err == nil {
-			Device_r.T_CalibrationTime = stamp
-			Device.Update_Device(Device_r, "T_CalibrationTime")
-			System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "校准时间操作", "校准时间:"+T_CalibrationTime)
-		} else {
-			c.Data["json"] = lib.JSONS{Code: 204, Msg: "时间解析错误!" + T_CalibrationTime}
-			c.ServeJSON()
-			return
-		}
+	CalibrationTime, CalibrationTime_is := lib.TimeStrToTime(T_CalibrationTime)
+	if CalibrationTime_is {
+		Device_r.T_CalibrationTime = CalibrationTime
+		clos = append(clos, "T_CalibrationTime")
+	}
+
+	// 巡检时间
+	T_PatrolTime := c.GetString("T_PatrolTime")
+	PatrolTime, PatrolTime_is := lib.TimeStrToTime(T_PatrolTime)
+	if PatrolTime_is {
+		Device_r.T_PatrolTime = PatrolTime
+		clos = append(clos, "T_PatrolTime")
+	}
+
+	if is := Device.Update_Device(Device_r, clos...); !is {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "修改失败!"}
+		c.ServeJSON()
+		return
+	}
+	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "修改", Device_r)
+
+	if is := Device.Update_Device_To_DeviceSensor(Device_r); is {
+		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器修改", Device_r)
 	}
 	}
 
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
@@ -192,6 +226,21 @@ func (c *DeviceController) Device_RestartShutdown() {
 
 
 }
 }
 
 
+// 版本升级
+func (c *DeviceController) Device_ProductUpgrade() {
+	T_sn := c.GetString("T_sn")
+	T_version := c.GetString("T_version")
+	T_file := c.GetString("T_file")
+
+	NatsServer.Up_ProductUpgrade(T_sn, T_version, T_file)
+	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "版本升级", T_sn+"-"+T_version+"-"+T_file)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+
+}
+
 // 2023-02-02 弃用
 // 2023-02-02 弃用
 //func (c *DeviceController) Device_Del() {
 //func (c *DeviceController) Device_Del() {
 //	if admin_r.Id != 1 {
 //	if admin_r.Id != 1 {
@@ -239,7 +288,7 @@ func (c *DeviceController) DeviceLogs() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -282,24 +331,23 @@ func (c *DeviceController) Device_Parameter_List() {
 // 修改设备参数
 // 修改设备参数
 func (c *DeviceController) Device_Parameter_Pu() {
 func (c *DeviceController) Device_Parameter_Pu() {
 	T_SN := c.GetString("T_sn")
 	T_SN := c.GetString("T_sn")
-	T_devName := c.GetString("T_devName")
-	T_uploadTime, _ := c.GetInt("T_uploadTime")
-	T_saveTime, _ := c.GetInt("T_saveTime")
-	T_overrunSave, _ := c.GetInt("T_overrunSave")
-	T_overrunAlarm, _ := c.GetInt("T_overrunAlarm")
-	T_outageAlarm, _ := c.GetInt("T_outageAlarm")
-	T_warningDelay, _ := c.GetInt("T_warningDelay")
-	T_lostAlarm, _ := c.GetInt("T_lostAlarm")
-	T_batteryLimit, _ := c.GetInt("T_batteryLimit")
-	T_warningTime, _ := c.GetInt("T_warningTime")
-	T_enwarning, _ := c.GetInt("T_enwarning")
-	T_decTotal, _ := c.GetInt("T_decTotal")
-	T_chDecTotal := c.GetString("T_chDecTotal")
-	T_company := c.GetString("T_company")
+	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_btname := c.GetString("T_btname")
-	T_btserverID, _ := c.GetInt("T_btserverID")
+	T_btsid, _ := c.GetInt("T_btsid")
 	T_btchar, _ := c.GetInt("T_btchar")
 	T_btchar, _ := c.GetInt("T_btchar")
+
 	T_Msid, _ := c.GetInt("T_Msid")
 	T_Msid, _ := c.GetInt("T_Msid")
+	T_State, _ := c.GetInt("T_State")
 
 
 	Device_r, err := Device.Read_Device_ByT_sn(T_SN)
 	Device_r, err := Device.Read_Device_ByT_sn(T_SN)
 	if err != nil {
 	if err != nil {
@@ -309,28 +357,22 @@ func (c *DeviceController) Device_Parameter_Pu() {
 	}
 	}
 
 
 	Deviceparameter := Device.DeviceParameter{
 	Deviceparameter := Device.DeviceParameter{
-		T_uuid:         c.Admin_r.T_uuid,
-		T_uploadTime:   T_uploadTime,
-		T_SendState:    0,
-		T_State:        2,
-		T_sn:           T_SN,
-		T_devName:      T_devName,
-		T_saveTime:     T_saveTime,
-		T_overrunSave:  T_overrunSave,
-		T_overrunAlarm: T_overrunAlarm,
-		T_outageAlarm:  T_outageAlarm,
-		T_lostAlarm:    T_lostAlarm,
-		T_warningTime:  T_warningTime,
-		T_warningDelay: T_warningDelay,
-		T_batteryLimit: T_batteryLimit,
-		T_chDecTotal:   T_chDecTotal,
-		T_decTotal:     strconv.Itoa(T_decTotal),
-		T_enwarning:    T_enwarning,
-		T_company:      T_company,
-		T_btname:       T_btname,
-		T_btserverID:   strconv.Itoa(T_btserverID),
-		T_btchar:       strconv.Itoa(T_btchar),
-		T_Msid:         T_Msid,
+		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)
 	Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
 	if !is {
 	if !is {
@@ -341,8 +383,10 @@ func (c *DeviceController) Device_Parameter_Pu() {
 	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "设备参数操作", Deviceparameter)
 	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "设备参数操作", Deviceparameter)
 	NatsServer.Pu_DeviceParameter(Deviceparameter)
 	NatsServer.Pu_DeviceParameter(Deviceparameter)
 
 
-	Device_r.T_devName = Deviceparameter.T_devName
+	// 更新名称
+	Device_r.T_devName = Deviceparameter.T_name
 	Device.Update_Device(Device_r, "T_devName")
 	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.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()
 	c.ServeJSON()
@@ -371,56 +415,6 @@ func (c *DeviceController) Device_Parameter_Del_Device() {
 	return
 	return
 }
 }
 
 
-// 设备参数 1库房 2移动
-// fixme 没有检查
-func (c *DeviceController) Pu_DeviceParameter_T_type() {
-
-	T_SN := c.GetString("SN")
-	T_type, _ := c.GetInt("T_l_p")
-
-	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
-	}
-
-	Device_r.T_type = T_type
-	Device.Update_Device(Device_r, "T_l_p")
-	Device.DeviceSensor_T_type_ALL(T_SN, T_type)
-	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "设备参数操作", "类型选择(1库房 2移动):"+string(T_type))
-
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
-	c.ServeJSON()
-	return
-
-}
-
-// 设备是否弃用 0屏蔽 1正常
-// fixme 没有检查
-func (c *DeviceController) Pu_DeviceParameter_T_give() {
-	T_SN := c.GetString("SN")
-	T_give, _ := c.GetInt("T_give")
-
-	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
-	}
-
-	//  // 1物流端   2药店端
-	Device_r.T_give = T_give
-	Device.Update_Device(Device_r, "T_give")
-	Device.DeviceSensor_t_give_ALL(T_SN, T_give)
-	System.Add_UserLogs(c.Admin_r.T_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃  1 正常):"+string(T_give))
-
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
-	c.ServeJSON()
-	return
-
-}
-
 // 设备-传感器 ------------------------------------------
 // 设备-传感器 ------------------------------------------
 
 
 // 传感器列表
 // 传感器列表
@@ -435,7 +429,6 @@ func (c *DeviceController) DeviceSensor_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -447,13 +440,11 @@ func (c *DeviceController) DeviceSensor_List() {
 	T_sn := c.GetString("T_sn")
 	T_sn := c.GetString("T_sn")
 	Name := c.GetString("T_name") //  包含 T_name、T_sn
 	Name := c.GetString("T_name") //  包含 T_name、T_sn
 	T_calss_id, _ := c.GetInt("T_calssid")
 	T_calss_id, _ := c.GetInt("T_calssid")
-	T_notice_id, _ := c.GetInt("T_noticeid")
-
-	T_give, T_give_err := c.GetInt("T_give") //0 :丢弃  1:正常    空:所有
-	if T_give_err != nil {
-		T_give = -1
+	T_type, T_type_err := c.GetInt("T_type")
+	if T_type_err != nil {
+		T_type = -1
 	}
 	}
-	T_datashow, T_datashow_err := c.GetInt("T_datashow") //空:正常显示   1:强制显示 屏蔽数据展示
+	T_datashow, T_datashow_err := c.GetInt("T_datashow") //0 屏蔽数据展示  1 正常数据展示
 	if T_datashow_err != nil {
 	if T_datashow_err != nil {
 		T_datashow = -1
 		T_datashow = -1
 	}
 	}
@@ -470,8 +461,8 @@ func (c *DeviceController) DeviceSensor_List() {
 			return
 			return
 		}
 		}
 	}
 	}
-	Device.Read_DeviceSensorParameter_Map_All(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_notice_id, T_give, T_datashow, page, page_z)
+	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.Page = page
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 
 
@@ -500,6 +491,20 @@ func (c *DeviceController) DeviceSensor_Edit() {
 		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
 		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
 	}
 	}
 
 
+	// 屏蔽数据展示
+	if v, err := c.GetInt("T_datashow"); err == nil {
+		DeviceSensor.T_datashow = v
+		Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
+		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器 数据展示", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
+	}
+
+	// 数据视图3D视图订阅
+	if v := c.GetString("T_3dview"); len(v) > 0 {
+		DeviceSensor.T_3dview = v
+		Device.Update_DeviceSensor(DeviceSensor, "T_3dview")
+		System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器 3D视图订阅", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+v)
+	}
+
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
 	c.ServeJSON()
 	c.ServeJSON()
 	return
 	return
@@ -560,21 +565,7 @@ func (c *DeviceController) DeviceSensor_Parameter_List() {
 func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 
 
 	T_SN := c.GetString("T_sn")
 	T_SN := c.GetString("T_sn")
-	T_name := c.GetString("T_name")
 	T_id, _ := c.GetInt("T_id")
 	T_id, _ := c.GetInt("T_id")
-	T_Tlower, _ := c.GetFloat("T_Tlower")
-	T_Tupper, _ := c.GetFloat("T_Tupper")
-	T_RHlower, _ := c.GetFloat("T_RHlower")
-	T_RHupper, _ := c.GetFloat("T_RHupper")
-	T_en, _ := c.GetInt("T_en")
-	T_free, _ := c.GetInt("T_free")
-
-	T_enprel, _ := c.GetInt("T_enprel")
-	T_tprel, _ := c.GetFloat("T_tprel")
-	T_tpreu, _ := c.GetFloat("T_tpreu")
-	T_hprel, _ := c.GetFloat("T_hprel")
-	T_hpreu, _ := c.GetFloat("T_hpreu")
-
 	_, err := Device.Read_Device_ByT_sn(T_SN)
 	_, err := Device.Read_Device_ByT_sn(T_SN)
 	if err != nil {
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
 		c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
@@ -589,39 +580,106 @@ func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 		return
 		return
 	}
 	}
 
 
+	DeviceSensorParameter, is := Device.Read_DeviceSensorParameter(T_SN, T_id)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+
+	T_name := c.GetString("T_name")
+
+	T_Tlower := DeviceSensorParameter.T_Tlower
+	if v, T_Tlower_err := c.GetFloat("T_Tlower"); T_Tlower_err == nil {
+		T_Tlower = float32(v)
+	}
+	T_Tupper := DeviceSensorParameter.T_Tupper
+	if v, T_Tupper_err := c.GetFloat("T_Tupper"); T_Tupper_err == nil {
+		T_Tupper = float32(v)
+	}
+	T_RHlower := DeviceSensorParameter.T_RHlower
+	if v, T_RHlower_err := c.GetFloat("T_RHlower"); T_RHlower_err == nil {
+		T_RHlower = float32(v)
+	}
+	T_RHupper := DeviceSensorParameter.T_RHupper
+	if v, T_RHupper_err := c.GetFloat("T_RHupper"); T_RHupper_err == nil {
+		T_RHupper = float32(v)
+	}
+
+	T_en := DeviceSensorParameter.T_en
+	if v, T_en_err := c.GetInt("T_en"); T_en_err == nil {
+		T_en = v
+	}
+
+	T_free := DeviceSensorParameter.T_free
+	if v, T_free_err := c.GetInt("T_free"); T_free_err == nil {
+		T_free = v
+	}
+	T_enprel := DeviceSensorParameter.T_enprel
+	if v, T_enprel_err := c.GetInt("T_enprel"); T_enprel_err == nil {
+		T_enprel = v
+	}
+	T_tprel := DeviceSensorParameter.T_tprel
+	if v, T_tprel_err := c.GetInt("T_tprel_err"); T_tprel_err == nil {
+		T_tprel = float32(v)
+	}
+	T_tpreu := DeviceSensorParameter.T_tpreu
+	if v, T_tpreu_err := c.GetInt("T_tpreu"); T_tpreu_err == nil {
+		T_tpreu = float32(v)
+	}
+	T_hprel := DeviceSensorParameter.T_hprel
+	if v, T_hprel_err := c.GetInt("T_hprel"); T_hprel_err == nil {
+		T_hprel = float32(v)
+	}
+	T_hpreu := DeviceSensorParameter.T_hpreu
+	if v, T_hpreu_err := c.GetInt("T_hpreu"); T_hpreu_err == nil {
+		T_hpreu = float32(v)
+	}
+
 	Devicesensorparameter := Device.DeviceSensorParameter{
 	Devicesensorparameter := Device.DeviceSensorParameter{
 		T_sn:      T_SN,
 		T_sn:      T_SN,
 		T_id:      T_id,
 		T_id:      T_id,
-		T_Tlower:  float32(T_Tlower),
-		T_Tupper:  float32(T_Tupper),
-		T_RHlower: float32(T_RHlower),
-		T_RHupper: float32(T_RHupper),
+		T_name:    T_name,
+		T_Tlower:  T_Tlower,
+		T_Tupper:  T_Tupper,
+		T_RHlower: T_RHlower,
+		T_RHupper: T_RHupper,
 		T_en:      T_en,
 		T_en:      T_en,
 		T_free:    T_free,
 		T_free:    T_free,
 
 
 		T_enprel: T_enprel,
 		T_enprel: T_enprel,
-		T_tprel:  float32(T_tprel),
-		T_tpreu:  float32(T_tpreu),
-		T_hprel:  float32(T_hprel),
-		T_hpreu:  float32(T_hpreu),
+		T_tprel:  T_tprel,
+		T_tpreu:  T_tpreu,
+		T_hprel:  T_hprel,
+		T_hpreu:  T_hpreu,
 
 
 		T_uuid:      c.Admin_r.T_uuid,
 		T_uuid:      c.Admin_r.T_uuid,
 		T_SendState: 0,
 		T_SendState: 0,
-		T_State:     2,
+		T_State:     2, // 用户提交
+	}
+	if len(T_name) == 0 {
+		Devicesensorparameter.T_name = DeviceSensor.T_name
 	}
 	}
-	dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
+
+	Devicesensorparameter, is = Device.Add_DeviceSensorParameter(Devicesensorparameter)
 	if !is {
 	if !is {
-		c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
+		c.Data["json"] = lib.JSONS{Code: 209, Msg: "Add_DeviceSensorParameter Err!"}
 		c.ServeJSON()
 		c.ServeJSON()
 		return
 		return
 	}
 	}
-	Devicesensorparameter.Id = int(dsp_id)
+	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
 
 
 	// 更新名称
 	// 更新名称
-	DeviceSensor.T_name = T_name
-	Device.Update_DeviceSensor(DeviceSensor, "T_name")
+	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, "设备管理", "传感器参数操作", Devicesensorparameter)
+	System.Add_UserLogs_T(c.Admin_r.T_uuid, "设备管理", "传感器操作", DeviceSensor)
 
 
 	NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
 	NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
 
 
@@ -631,8 +689,7 @@ func (c *DeviceController) DeviceSensor_Parameter_Pu() {
 
 
 }
 }
 
 
-// 传感器 实时数据显示排序
-// fixme 没有检查
+// 传感器 实时数据显示排序(未使用)
 func (c *DeviceController) UpDeviceSensor_Tsort() {
 func (c *DeviceController) UpDeviceSensor_Tsort() {
 
 
 	Sn := c.GetString("Sn")
 	Sn := c.GetString("Sn")
@@ -655,8 +712,7 @@ func (c *DeviceController) UpDeviceSensor_Tsort() {
 	return
 	return
 }
 }
 
 
-// 传感器 3D视图
-// fixme 没有检查
+// 传感器 3D视图 (未使用)
 func (c *DeviceController) UpDeviceSensor_T3dview() {
 func (c *DeviceController) UpDeviceSensor_T3dview() {
 
 
 	Sn := c.GetString("Sn")
 	Sn := c.GetString("Sn")
@@ -679,8 +735,7 @@ func (c *DeviceController) UpDeviceSensor_T3dview() {
 	return
 	return
 }
 }
 
 
-// 传感器 屏蔽数据展示 0 屏蔽数据展示  1 正常数据展示
-// fixme 没有检查
+// 传感器 屏蔽数据展示 0 屏蔽数据展示  1 正常数据展示 (未使用)
 func (c *DeviceController) UpDeviceSensor_T_datashow() {
 func (c *DeviceController) UpDeviceSensor_T_datashow() {
 	Sn := c.GetString("Sn")
 	Sn := c.GetString("Sn")
 	Id, _ := c.GetInt("Id")
 	Id, _ := c.GetInt("Id")
@@ -715,7 +770,6 @@ func (c *DeviceController) DeviceSensor_Manage_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -758,7 +812,7 @@ func (c *DeviceController) DeviceSensor_Manage_List() {
 		T_sort = -1
 		T_sort = -1
 	}
 	}
 
 
-	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorManageList(c.T_pid, T_name, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z)
+	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorManageList(c.Admin_r, c.T_pid, T_name, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z)
 	r_jsons.Page = page
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 
 
@@ -781,7 +835,6 @@ func (c *DeviceController) DeviceTask_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -842,7 +895,6 @@ func (c *DeviceController) DeviceWarning_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -1064,7 +1116,6 @@ func (c *DeviceController) CompanyClass_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -1213,10 +1264,17 @@ func (c *DeviceController) DeviceClassBind_List() {
 	}
 	}
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	Name := c.GetString("Name")
+	if page < 1 {
+		page = 1
+	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
+	T_name := c.GetString("T_name")
 	T_sn := c.GetString("T_sn")
 	T_sn := c.GetString("T_sn")
 	T_class_id, _ := c.GetInt("T_class_id")
 	T_class_id, _ := c.GetInt("T_class_id")
-	page_z, _ := c.GetInt("page_z")
+	T_type, _ := c.GetInt("T_type")
 	R_DeviceClass, err := Company.Read_CompanyClass_ById(T_class_id)
 	R_DeviceClass, err := Company.Read_CompanyClass_ById(T_class_id)
 	if err != nil {
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
 		c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
@@ -1229,7 +1287,7 @@ func (c *DeviceController) DeviceClassBind_List() {
 		return
 		return
 	}
 	}
 	var cnt int64
 	var cnt int64
-	Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(c.Admin_r, c.T_pid, T_class_id, page, page_z, T_sn, Name, "")
+	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)
 
 
 	r_jsons.DeviceSensor_lite = Device_lite
 	r_jsons.DeviceSensor_lite = Device_lite
 
 
@@ -1347,7 +1405,6 @@ func (c *DeviceController) CompanyNotice_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -1532,10 +1589,18 @@ func (c *DeviceController) DeviceNoticeBind_List() {
 	}
 	}
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
+	if page < 1 {
+		page = 1
+	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
 	T_name := c.GetString("T_name")
 	T_name := c.GetString("T_name")
 	T_sn := c.GetString("T_sn")
 	T_sn := c.GetString("T_sn")
 	T_notice_id, _ := c.GetInt("T_notice_id")
 	T_notice_id, _ := c.GetInt("T_notice_id")
-	page_z, _ := c.GetInt("page_z")
+	T_type, _ := c.GetInt("T_type")
+
 	R_DeviceNotice, err := Company.Read_CompanyNotice_ById(T_notice_id)
 	R_DeviceNotice, err := Company.Read_CompanyNotice_ById(T_notice_id)
 	if err != nil {
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
 		c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
@@ -1548,7 +1613,7 @@ func (c *DeviceController) DeviceNoticeBind_List() {
 		return
 		return
 	}
 	}
 	var cnt int64
 	var cnt int64
-	Device_lite, cnt := Device.Read_DeviceSensor_Notice_ALL_1(c.T_pid, T_notice_id, page, page_z, T_sn, T_name, "")
+	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)
 
 
 	r_jsons.DeviceSensor_lite = Device_lite
 	r_jsons.DeviceSensor_lite = Device_lite
 
 

+ 1 - 1
controllers/GoodsOrder.go

@@ -40,7 +40,7 @@ func (c *GoodsOrderController) GoodsOrder_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}

+ 2 - 2
controllers/Logs.go

@@ -48,7 +48,7 @@ func (c *LogsController) UserLogsList() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -104,7 +104,7 @@ func (c *LogsController) LogsList() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}

+ 2 - 2
controllers/Product.go

@@ -35,7 +35,7 @@ func (c *ProductController) ProductUpgrade_List() {
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -96,7 +96,7 @@ func (c *ProductController) ProductUpgrade_Add() {
 		return
 		return
 	}
 	}
 
 
-	deviceList := Device.Read_Device_List_T_model(T_model)
+	deviceList := Device.Read_Device_List_ByT_model(T_model)
 
 
 	for _, v := range deviceList {
 	for _, v := range deviceList {
 		NatsServer.Up_ProductUpgrade(v.T_sn, T_version, T_file)
 		NatsServer.Up_ProductUpgrade(v.T_sn, T_version, T_file)

+ 55 - 27
controllers/User.go

@@ -8,6 +8,7 @@ import (
 	"Cold_Api/models/Account"
 	"Cold_Api/models/Account"
 	"Cold_Api/models/System"
 	"Cold_Api/models/System"
 	"Cold_Api/models/Warning"
 	"Cold_Api/models/Warning"
+	"github.com/beego/beego/v2/adapter/orm"
 	beego "github.com/beego/beego/v2/server/web"
 	beego "github.com/beego/beego/v2/server/web"
 	uuid "github.com/satori/go.uuid"
 	uuid "github.com/satori/go.uuid"
 	"log"
 	"log"
@@ -111,6 +112,29 @@ func (c *UserController) Company_Add() {
 		return
 		return
 	}
 	}
 
 
+	var_.Id = int(id)
+	T_Path := strconv.Itoa(int(id)) + "/"
+	if var_.T_mid != 0 {
+		Company_r, err := Account.Read_Company_ById(T_mid)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 301, Msg: "T_mid Err !"}
+			c.ServeJSON()
+			return
+		}
+		T_Path = Company_r.T_path + T_Path
+
+	} else {
+		T_Path = "/0/" + T_Path
+	}
+
+	var_.T_path = T_Path
+	is := Account.Update_Company(var_, "T_path")
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
+		c.ServeJSON()
+		return
+	}
+
 	System.Add_UserLogs_T(c.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.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
 	c.ServeJSON()
 	c.ServeJSON()
@@ -133,17 +157,13 @@ func (c *UserController) Company_Edit() {
 		return
 		return
 	}
 	}
 
 
-	T_mid, T_mid_err := c.GetInt("T_mid")
 	T_name := c.GetString("T_name")
 	T_name := c.GetString("T_name")
 
 
 	if len(T_name) > 0 {
 	if len(T_name) > 0 {
 		Company_r.T_name = T_name
 		Company_r.T_name = T_name
 	}
 	}
-	if T_mid_err == nil {
-		Company_r.T_mid = T_mid
-	}
 
 
-	is := Account.Update_Company(Company_r, "T_mid", "T_name")
+	is := Account.Update_Company(Company_r, "T_name")
 	if !is {
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.ServeJSON()
 		c.ServeJSON()
@@ -172,12 +192,30 @@ func (c *UserController) Company_Del() {
 		return
 		return
 	}
 	}
 
 
-	is := Account.Delete_Company(Company_r)
-	if !is {
-		c.Data["json"] = lib.JSONS{Code: 204, Msg: "删除失败!"}
+	ids := Account.ReadCompanyIds_T_path(Company_r.T_path)
+
+	if cnt := Account.Read_Admin_Num_ByT_pid(ids); cnt > 0 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "有关联用户,禁止删除!"}
 		c.ServeJSON()
 		c.ServeJSON()
 		return
 		return
 	}
 	}
+	o := orm.NewOrm()
+	o.Begin()
+	for _, id := range ids {
+		if is := Account.Delete_Company(o, id); !is {
+			o.Rollback()
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+			c.ServeJSON()
+			return
+		}
+		if err = Account.Delete_Company_bind_T_pids(o, id); err != nil {
+			o.Rollback()
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
+	o.Commit()
 
 
 	System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "删除", Company_r)
 	System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "删除", Company_r)
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
@@ -218,7 +256,7 @@ func (c *UserController) User_List() {
 	var r_jsons lib.R_JSONS
 	var r_jsons lib.R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
+
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -282,7 +320,6 @@ func (c *UserController) User_Post() {
 	T_pass := c.GetString("T_pass")
 	T_pass := c.GetString("T_pass")
 	T_phone := c.GetString("T_phone")
 	T_phone := c.GetString("T_phone")
 	T_mail := c.GetString("T_mail")
 	T_mail := c.GetString("T_mail")
-	T_wx := c.GetString("T_wx")
 	if len(T_pass) < 8 && len(T_pass) > 0 {
 	if len(T_pass) < 8 && len(T_pass) > 0 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
 		c.ServeJSON()
 		c.ServeJSON()
@@ -300,11 +337,7 @@ func (c *UserController) User_Post() {
 	if len(T_mail) > 0 {
 	if len(T_mail) > 0 {
 		admin_r.T_mail = T_mail
 		admin_r.T_mail = T_mail
 	}
 	}
-	if len(T_wx) > 0 {
-		admin_r.T_wx = T_wx
-	}
-
-	is := Account.Update_Admin(admin_r, "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
+	is := Account.Update_Admin(admin_r, "T_name", "T_pass", "T_phone", "T_mail")
 	if !is {
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
 		c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
 		c.ServeJSON()
 		c.ServeJSON()
@@ -386,7 +419,6 @@ func (c *UserController) User_Edit() {
 	T_pass := c.GetString("T_pass")
 	T_pass := c.GetString("T_pass")
 	T_phone := c.GetString("T_phone")
 	T_phone := c.GetString("T_phone")
 	T_mail := c.GetString("T_mail")
 	T_mail := c.GetString("T_mail")
-	T_wx := c.GetString("T_wx")
 	if T_power_err == nil {
 	if T_power_err == nil {
 		r.T_power = T_power
 		r.T_power = T_power
 	}
 	}
@@ -409,11 +441,8 @@ func (c *UserController) User_Edit() {
 	if len(T_mail) > 0 {
 	if len(T_mail) > 0 {
 		r.T_mail = T_mail
 		r.T_mail = T_mail
 	}
 	}
-	if len(T_wx) > 0 {
-		r.T_wx = T_wx
-	}
 
 
-	is := Account.Update_Admin(r, "T_power", "T_pid", "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
+	is := Account.Update_Admin(r, "T_power", "T_pid", "T_name", "T_pass", "T_phone", "T_mail")
 	if !is {
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
 		c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
 		c.ServeJSON()
 		c.ServeJSON()
@@ -682,12 +711,6 @@ func (c *UserController) User_Notice_List() {
 
 
 	var r_jsons R_JSONS
 	var r_jsons R_JSONS
 
 
-	if c.T_pid == 0 {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
-		c.ServeJSON()
-		return
-	}
-
 	// 绑定公司id的内部用户列表
 	// 绑定公司id的内部用户列表
 	r_jsons.AdminList = Account.Read_Admin_List_T_pids(c.T_pid)
 	r_jsons.AdminList = Account.Read_Admin_List_T_pids(c.T_pid)
 	// 绑定公司id的公司用户列表
 	// 绑定公司id的公司用户列表
@@ -818,7 +841,6 @@ func (c *UserController) Power_List() {
 	var r_jsons lib.R_JSONS
 	var r_jsons lib.R_JSONS
 
 
 	page, _ := c.GetInt("page")
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 	if page < 1 {
 		page = 1
 		page = 1
 	}
 	}
@@ -1007,6 +1029,12 @@ func (c *UserController) Power_Del() {
 		return
 		return
 	}
 	}
 
 
+	if cnt := Account.Read_Admin_Num_ByT_power(id); cnt > 0 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "有关联用户,禁止删除!"}
+		c.ServeJSON()
+		return
+	}
+
 	is := Account.Delete_Power(r)
 	is := Account.Delete_Power(r)
 	if !is {
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 302, Msg: "删除失败!"}
 		c.Data["json"] = lib.JSONS{Code: 302, Msg: "删除失败!"}

+ 51 - 4
models/Account/Admin.go

@@ -85,7 +85,7 @@ func init() {
 	orm.RegisterModel(new(Admin))
 	orm.RegisterModel(new(Admin))
 
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-		"redis_Cold_User_Admin", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+		"redis_User_Admin", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
 	fmt.Println(config)
 	fmt.Println(config)
 	var err error
 	var err error
 	redisCache_Admin, err = cache.NewCache("redis", config)
 	redisCache_Admin, err = cache.NewCache("redis", config)
@@ -248,9 +248,6 @@ func Read_Admin_List(T_pid int, T_name string, page int, page_z int) (AdminList
 	var maps []Admin
 	var maps []Admin
 
 
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -317,6 +314,25 @@ func Read_Admin_List_T_pid(T_pid int) (AdminList []Admin_R) {
 	return AdminList
 	return AdminList
 }
 }
 
 
+func Read_Admin_Num_ByT_power(T_power int) int {
+
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(Admin))
+	cnt, _ := qs.Filter("T_State", 1).Filter("T_power", T_power).Count()
+	return int(cnt)
+}
+
+// 查询 用户关联的公司总数
+func Read_Admin_Num_ByT_pid(T_pids []int) int {
+
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(Admin))
+	cnt, _ := qs.Filter("T_State", 1).Filter("T_pid__in", T_pids).Count()
+	return int(cnt)
+}
+
 // 获取列表
 // 获取列表
 func Read_Admin_List_All() (AdminList []Admin_R) {
 func Read_Admin_List_All() (AdminList []Admin_R) {
 
 
@@ -368,3 +384,34 @@ func Delete_Company_bind(Admin_id, T_pid int) (err error) {
 	return err
 	return err
 
 
 }
 }
+
+// 删除公司后将管理员绑定的公司删除
+func Delete_Company_bind_T_pids(o orm.Ormer, T_pid int) (err error) {
+
+	qs := o.QueryTable(new(Admin))
+	var maps []Admin
+	T_Pid_bind := "P" + strconv.Itoa(T_pid) + "|"
+	cnt, err := qs.Filter("T_State", 1).Filter("T_pids__icontains", T_Pid_bind).All(&maps)
+	if err != nil {
+		return err
+	}
+	if cnt == 0 {
+		return nil
+	}
+
+	for _, v := range maps {
+		o := orm.NewOrm()
+		v := Admin{Id: v.Id}
+		if err = o.Read(&v, "Id"); err == nil {
+			v.T_pids = strings.Replace(v.T_pids, T_Pid_bind, "", -1)
+			if num, err := o.Update(&v, "T_pids"); err == nil {
+				fmt.Println("Number of records updated in database:", num)
+				Redis_Admin_Set(v) // Redis 更新缓存
+				return err
+			}
+		}
+	}
+
+	return err
+
+}

+ 44 - 16
models/Account/Company.go

@@ -19,6 +19,8 @@ type Company struct {
 	T_mid  int    `orm:"size(200);null"` //  上一级 ID
 	T_mid  int    `orm:"size(200);null"` //  上一级 ID
 	T_name string `orm:"size(256);null"` // 公司名称
 	T_name string `orm:"size(256);null"` // 公司名称
 
 
+	T_path string // 公司路径
+
 	T_State    int       `orm:"size(200);default(1)"`                                  //  0删除  1 正常
 	T_State    int       `orm:"size(200);default(1)"`                                  //  0删除  1 正常
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
@@ -122,10 +124,12 @@ func Update_Company(m Company, cols ...string) bool {
 }
 }
 
 
 // 删除
 // 删除
-func Delete_Company(m Company) bool {
-	o := orm.NewOrm()
-	m.T_State = 0
-	if num, err := o.Update(&m, "T_State"); err == nil {
+func Delete_Company(orm orm.Ormer, id int) bool {
+	var m = Company{
+		Id:      id,
+		T_State: 0,
+	}
+	if num, err := orm.Update(&m, "T_State"); err == nil {
 		fmt.Println("Number of records updated in database:", num)
 		fmt.Println("Number of records updated in database:", num)
 	} else {
 	} else {
 		return false
 		return false
@@ -150,6 +154,11 @@ func Read_Company_ById(Id int) (r Company, e error) {
 // 获取列表
 // 获取列表
 func Read_Company_Tree(admin_r Admin, Company_name string) (CompanyList []Company_R, cnt int64) {
 func Read_Company_Tree(admin_r Admin, Company_name string) (CompanyList []Company_R, cnt int64) {
 
 
+	// 内部用户未绑定公司
+	if admin_r.T_pid > 0 || len(admin_r.T_pids) == 0 {
+		return CompanyList, cnt
+	}
+
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 
 
@@ -163,15 +172,10 @@ func Read_Company_Tree(admin_r Admin, Company_name string) (CompanyList []Compan
 		cond1 = cond1.And("Id", admin_r.T_pid)
 		cond1 = cond1.And("Id", admin_r.T_pid)
 	}
 	}
 
 
-	// 内部用户未绑定公司
-	if admin_r.T_pid == 0 && len(admin_r.T_pids) == 0 {
-		return CompanyList, cnt
-	}
-
 	// 内部用户已绑定公司,* 绑定所有公司
 	// 内部用户已绑定公司,* 绑定所有公司
-	if len(admin_r.T_pids) > 0 && admin_r.T_pids != "*" {
-		T_pids := models.SplitStringIds(admin_r.T_pids, "P")
-		cond1 = cond1.AndCond(cond.Or("Id__in", T_pids).Or("T_mid__in", T_pids))
+	if admin_r.T_pids != "*" {
+		T_pids := models.SplitStringToIntIds(admin_r.T_pids, "P")
+		cond1 = cond1.And("Id__in", ReadCompanyIds_T_pids(T_pids))
 	}
 	}
 
 
 	if len(Company_name) > 0 {
 	if len(Company_name) > 0 {
@@ -212,6 +216,33 @@ func Read_Company_Tree(admin_r Admin, Company_name string) (CompanyList []Compan
 	return CompanyList, cnt
 	return CompanyList, cnt
 }
 }
 
 
+func ReadCompanyIds_T_pids(T_pids []int) []int {
+
+	var companyList []Company
+	var companyIds []int
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(Company))
+	qs.Filter("Id__in", T_pids).Filter("T_State", 1).All(&companyList)
+	for _, company := range companyList {
+		subIds := ReadCompanyIds_T_path(company.T_path)
+		companyIds = append(companyIds, subIds...)
+	}
+
+	return models.IntIdsDistinct(companyIds)
+}
+
+// 通过T_pid查询所有子id
+func ReadCompanyIds_T_path(T_path string) (companyIds []int) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(Company))
+	var CompanyList []Company
+	qs.Filter("T_path__startswith", T_path).Filter("T_State", 1).All(&CompanyList)
+	for _, v := range CompanyList {
+		companyIds = append(companyIds, v.Id)
+	}
+	return companyIds
+}
+
 func Read_Company_List(page, page_z int) (CompanyList []Company_R, cnt int64) {
 func Read_Company_List(page, page_z int) (CompanyList []Company_R, cnt int64) {
 
 
 	var offset int64
 	var offset int64
@@ -305,7 +336,7 @@ func Read_Company_List_All_ByT_name(T_name string) (maps []Company) {
 	return maps
 	return maps
 }
 }
 
 
-// 获取列表
+// 获取铜壶绑定的公司列表
 func Read_Company_List_ByT_pids(T_pids string, page int, page_z int) (Company_r []Company_R, cnt int64) {
 func Read_Company_List_ByT_pids(T_pids string, page int, page_z int) (Company_r []Company_R, cnt int64) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
@@ -313,9 +344,6 @@ func Read_Company_List_ByT_pids(T_pids string, page int, page_z int) (Company_r
 
 
 	qs := o.QueryTable(new(Company))
 	qs := o.QueryTable(new(Company))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {

+ 103 - 20
models/Account/Menu.go

@@ -43,26 +43,25 @@ func (t *API) TableName() string {
 
 
 // var redisCache_Menu cache.Cache
 // var redisCache_Menu cache.Cache
 var redisCache_API cache.Cache
 var redisCache_API cache.Cache
+var redisCache_Menu cache.Cache
 
 
 func init() {
 func init() {
 	//注册模型
 	//注册模型
 	orm.RegisterModel(new(Menu))
 	orm.RegisterModel(new(Menu))
 	orm.RegisterModel(new(API))
 	orm.RegisterModel(new(API))
-
-	//menuConfig := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-	//	"redis_Cold_User_Menu", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
-	//fmt.Println(menuConfig)
-	//var err error
-	//redisCache_Menu, err = cache.NewCache("redis", menuConfig)
-	//if err != nil || redisCache_Menu == nil {
-	//	errMsg := "failed to init redis"
-	//	fmt.Println(errMsg, err)
-	//}
+	var err error
+	menuConfig := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
+		"redis_User_Menu", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+	fmt.Println(menuConfig)
+	redisCache_Menu, err = cache.NewCache("redis", menuConfig)
+	if err != nil || redisCache_Menu == nil {
+		errMsg := "failed to init redis"
+		fmt.Println(errMsg, err)
+	}
 
 
 	apiConfig := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 	apiConfig := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-		"redis_Cold_User_API", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+		"redis_User_API", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
 	fmt.Println(apiConfig)
 	fmt.Println(apiConfig)
-	var err error
 	redisCache_API, err = cache.NewCache("redis", apiConfig)
 	redisCache_API, err = cache.NewCache("redis", apiConfig)
 	if err != nil || redisCache_API == nil {
 	if err != nil || redisCache_API == nil {
 		errMsg := "failed to init redis"
 		errMsg := "failed to init redis"
@@ -103,6 +102,47 @@ func Redis_API_DelK(key string) (err error) {
 	return
 	return
 }
 }
 
 
+func Redis_Munu_Set(Power_Id, T_pid int, r []Menu) (err error) {
+	//json序列化
+	str, err := json.Marshal(r)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	keys := strconv.Itoa(Power_Id) + "-Pid"
+	if T_pid == 0 {
+		keys = strconv.Itoa(Power_Id)
+	}
+
+	err = redisCache_Menu.Put(keys, str, 30*24*time.Hour)
+	if err != nil {
+		fmt.Println("set key:", strconv.Itoa(Power_Id)+"|"+strconv.Itoa(T_pid), ",value:", str, err)
+	}
+	return
+}
+
+func Redis_Menu_Get(Power_Id, T_pid int) (r []Menu, is bool) {
+	key := strconv.Itoa(Power_Id) + "-Pid"
+	if T_pid == 0 {
+		key = strconv.Itoa(Power_Id)
+	}
+	if redisCache_Menu.IsExist(key) {
+		//println("找到key:",key)
+		v := redisCache_Menu.Get(key)
+
+		json.Unmarshal(v.([]byte), &r)
+		return r, true
+	}
+	//println("没有 找到key:",key)
+	return []Menu{}, false
+}
+
+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")
+	return
+}
+
 // ---------------- 特殊方法 -------------------
 // ---------------- 特殊方法 -------------------
 
 
 // 添加
 // 添加
@@ -146,7 +186,11 @@ func Read_Menu_ById(Id int) (r Menu, e error) {
 }
 }
 
 
 // 获取列表
 // 获取列表
-func Read_Menu_Bind_List(Bind_Menu string, T_pid int) (maps []Menu) {
+func Read_Menu_Bind_List(Power_Id int, Bind_Menu string, T_pid int) (maps []Menu) {
+
+	if r, is := Redis_Menu_Get(Power_Id, T_pid); is {
+		return r
+	}
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
@@ -154,20 +198,59 @@ func Read_Menu_Bind_List(Bind_Menu string, T_pid int) (maps []Menu) {
 	qs := o.QueryTable(new(Menu))
 	qs := o.QueryTable(new(Menu))
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
 	// fixme 测试先不屏蔽
 	// fixme 测试先不屏蔽
-	//if T_pid == 0 {
-	//	cond = cond.And("T_pid", 0)
-	//}
-	if Bind_Menu != "*" {
-		list := models.SplitStringIds(Bind_Menu, "M")
-		cond = cond.And("Id__in", list)
+	if T_pid == 0 {
+		cond = cond.And("T_pid", 0)
+	}
+	if Bind_Menu == "*" {
+		qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_sort").All(&maps)
+		m := Menu_Call(maps, 0)
+		Redis_Munu_Set(Power_Id, T_pid, m)
+		return m
+	}
+
+	list := models.SplitStringToIntIds(Bind_Menu, "M")
+	AllIds := list
+	if err := recursiveMenu(T_pid, list, &AllIds); err != nil {
+		return maps
 	}
 	}
 
 
-	qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_sort").All(&maps)
+	cond = cond.And("Id__in", models.IntIdsDistinct(AllIds))
+
+	qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_sort", "Id").All(&maps)
 
 
 	m := Menu_Call(maps, 0)
 	m := Menu_Call(maps, 0)
+
+	Redis_Munu_Set(Power_Id, T_pid, m)
 	return m
 	return m
 }
 }
 
 
+// 获取MenuIds下父id
+func recursiveMenu(T_pid int, MenuIds []int, AllIds *[]int) error {
+	if len(MenuIds) == 0 {
+		return nil
+	}
+	var subMenus []Menu
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(Menu))
+	cond := orm.NewCondition()
+	// fixme 测试先不屏蔽
+	if T_pid == 0 {
+		cond = cond.And("T_pid", 0)
+	}
+	cond = cond.And("Id__in", MenuIds)
+
+	qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_sort", "Id").All(&subMenus)
+
+	subIds := make([]int, 0)
+	for _, menu := range subMenus {
+		if menu.T_mid != 0 {
+			subIds = append(subIds, menu.T_mid)
+			*AllIds = append(*AllIds, menu.T_mid)
+		}
+	}
+	return recursiveMenu(T_pid, subIds, AllIds)
+}
+
 func Read_Menu_List_All() (maps []Menu, menu_ids []int) {
 func Read_Menu_List_All() (maps []Menu, menu_ids []int) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()

+ 4 - 2
models/Account/Power.go

@@ -68,7 +68,7 @@ func init() {
 	Power_list = make(map[int]string)
 	Power_list = make(map[int]string)
 
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-		"redis_Cold_User_Power", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+		"redis_User_Power", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
 	fmt.Println(config)
 	fmt.Println(config)
 	var err error
 	var err error
 	redisCache_Power, err = cache.NewCache("redis", config)
 	redisCache_Power, err = cache.NewCache("redis", config)
@@ -242,7 +242,8 @@ func Update_Power(v Power, cols ...string) bool {
 	if num, err := o.Update(&v, cols...); err == nil {
 	if num, err := o.Update(&v, cols...); err == nil {
 		fmt.Println("Number of records updated in database:", num)
 		fmt.Println("Number of records updated in database:", num)
 		Redis_API_Set(v.Id, Read_API_List_By_Menu_Bind(v.T_menu))
 		Redis_API_Set(v.Id, Read_API_List_By_Menu_Bind(v.T_menu))
-		Redis_Power_Set(v) // Redis 更新缓存
+		Redis_Power_Set(v)    // Redis 更新缓存
+		Redis_Menu_DelK(v.Id) // 删除菜单缓存
 		return true
 		return true
 	}
 	}
 	return false
 	return false
@@ -257,6 +258,7 @@ func Delete_Power(v Power) bool {
 	} else {
 	} else {
 		return false
 		return false
 	}
 	}
+	Redis_Menu_DelK(v.Id)                // 删除菜单缓存
 	Redis_API_DelK(strconv.Itoa(v.Id))   // Redis 删除API缓存
 	Redis_API_DelK(strconv.Itoa(v.Id))   // Redis 删除API缓存
 	Redis_Power_DelK(strconv.Itoa(v.Id)) // Redis 删除缓存
 	Redis_Power_DelK(strconv.Itoa(v.Id)) // Redis 删除缓存
 	return true
 	return true

+ 1 - 1
models/Account/Tokey.go

@@ -18,7 +18,7 @@ func init() {
 	//orm.RegisterModel(new(Tokey))
 	//orm.RegisterModel(new(Tokey))
 
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
-		"redis_Cold_User_Tokey", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+		"redis_User_Tokey", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
 	fmt.Println(config)
 	fmt.Println(config)
 	var err error
 	var err error
 	redisCache_Tokey, err = cache.NewCache("redis", config)
 	redisCache_Tokey, err = cache.NewCache("redis", config)

+ 0 - 3
models/Company/CompanyClass.go

@@ -164,9 +164,6 @@ func Read_CompanyClass_List(T_pid int, T_name string, page int, page_z int) (r [
 	var map_r []CompanyClass
 	var map_r []CompanyClass
 	qs := o.QueryTable(new(CompanyClass))
 	qs := o.QueryTable(new(CompanyClass))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {

+ 0 - 3
models/Company/CompanyNotice.go

@@ -212,9 +212,6 @@ func Read_CompanyNotice_List(T_pid int, T_name string, page int, page_z int) (r
 	qs := o.QueryTable(new(CompanyNotice))
 	qs := o.QueryTable(new(CompanyNotice))
 	var maps []CompanyNotice
 	var maps []CompanyNotice
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {

+ 40 - 35
models/Device/Device.go

@@ -16,26 +16,26 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// 模板
+// 设备
 type Device struct {
 type Device struct {
-	T_sn              string    `orm:"pk;size(256);null"`    // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_pid             int       `orm:"index;size(256);null"` // Account.Company 绑定公司
-	T_MSISDN          string    `orm:"size(256);null"`       // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_devName         string    `orm:"size(256);null"`       // 设备名称
-	T_protocol        int       `orm:"size(2);default(1)"`   // 冷链通讯协议 1 :1.0协议   2 :2.0协议    3 :3.0协议
-	T_VerifyTime      time.Time `orm:"type(timestamp);null"` // 验证时间
-	T_CalibrationTime time.Time `orm:"type(timestamp);null"` // 校准时间
-	T_ist             int       `orm:"size(2);default(1)"`   // 温度   1开启   2关闭
-	T_ish             int       `orm:"size(2);default(1)"`   // 湿度   1开启   2关闭
+	T_sn              string    `orm:"pk;size(256);null"`     // 设备序列号
+	T_pid             int       `orm:"index;size(256);null"`  // Account.Company 绑定公司
+	T_devName         string    `orm:"size(256);null"`        // 设备名称  20字
+	T_protocol        int       `orm:"size(2);default(1)"`    // 冷链通讯协议 1 :1.0协议   2 :2.0协议    3 :3.0协议
+	T_VerifyTime      time.Time `orm:"type(timestamp);null""` // 验证时间
+	T_CalibrationTime time.Time `orm:"type(timestamp);null"`  // 校准时间
+	T_PatrolTime      time.Time `orm:"type(timestamp);null"`  // 巡检时间
+	T_ist             int       `orm:"size(2);default(1)"`    // 温度   1开启   2关闭
+	T_ish             int       `orm:"size(2);default(1)"`    // 湿度   1开启   2关闭
 
 
 	// 设备同步参数
 	// 设备同步参数
 	T_Dattery  int    `orm:"size(4);null"`             // 电量
 	T_Dattery  int    `orm:"size(4);null"`             // 电量
 	T_Site     string `orm:"size(200);null"`           // GPS
 	T_Site     string `orm:"size(200);null"`           // GPS
-	T_type     int    `orm:"index;size(4);null"`       // Device.DeviceType  1库房   2移动
-	T_give     int    `orm:"index;size(2);default(1)"` // 屏蔽状态 0 屏蔽  1 正常
-	T_monitor  int    `orm:"index;size(2);null"`       // 监控状态 0 未监控 1 监控
+	T_type     int    `orm:"index;size(4);null"`       // Device.DeviceType  1库房   2移动  ......
+	T_monitor  int    `orm:"index;size(2);null"`       // 监控状态 0 未监控 1 监控  停止记录
 	T_online   int    `orm:"index;size(2);default(1)"` // 在线状态 0 未启用  1 在线  2 离线
 	T_online   int    `orm:"index;size(2);default(1)"` // 在线状态 0 未启用  1 在线  2 离线
 	T_online_s int    `orm:"index;size(2);default(0)"` // 在线状态-备用  0 未启用  1 在线  2 离线
 	T_online_s int    `orm:"index;size(2);default(0)"` // 在线状态-备用  0 未启用  1 在线  2 离线
+	T_State    int    `orm:"index;size(2);default(1)"` // 0 屏蔽   1 正常  (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
 
 
 	// 硬件信息
 	// 硬件信息
 	T_model string `orm:"size(200);null"` // KF200BG  设备型号
 	T_model string `orm:"size(200);null"` // KF200BG  设备型号
@@ -43,28 +43,29 @@ type Device struct {
 	T_hver  string `orm:"size(200);null"` // "1.0.0",//硬件版本
 	T_hver  string `orm:"size(200);null"` // "1.0.0",//硬件版本
 	T_imei  string `orm:"size(200);null"` // "867387060327718",//模组imei
 	T_imei  string `orm:"size(200);null"` // "867387060327718",//模组imei
 	T_iccid string `orm:"size(200);null"` // "89860477102170049750",//sim卡号
 	T_iccid string `orm:"size(200);null"` // "89860477102170049750",//sim卡号
+	T_rssi  string `orm:"size(200);null"` // "80",//信号强度
 
 
-	T_State    int       `orm:"index;size(2);default(1)"`                              // 0 删除   1 正常
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 }
 }
 
 
 type Device_R struct {
 type Device_R struct {
 	T_sn              string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
 	T_sn              string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_MSISDN          string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
 	T_devName         string // 设备名称
 	T_devName         string // 设备名称
 	T_protocol        int    // 1 1.0协议  2 2.0协议
 	T_protocol        int    // 1 1.0协议  2 2.0协议
 	T_VerifyTime      string // 验证时间
 	T_VerifyTime      string // 验证时间
 	T_CalibrationTime string // 校准时间
 	T_CalibrationTime string // 校准时间
+	T_PatrolTime      string // 巡检时间
 	T_ist             int    // 温度   1开启   2关闭
 	T_ist             int    // 温度   1开启   2关闭
 	T_ish             int    // 湿度   1开启   2关闭
 	T_ish             int    // 湿度   1开启   2关闭
 	T_Dattery         int    // 电量
 	T_Dattery         int    // 电量
 	T_Site            string // GPS
 	T_Site            string // GPS
 	T_type            int    // 1库房  2移动
 	T_type            int    // 1库房  2移动
 	T_give            int    // 屏蔽状态 0 屏蔽  1 正常
 	T_give            int    // 屏蔽状态 0 屏蔽  1 正常
-	T_monitor         int    // 监控状态 0 未监控 1 监控
+	T_monitor         int    // 监控状态 0 未监控 1 监控 停止记录
 	T_online          int    // 在线状态 0 未启用  1 在线  2 离线
 	T_online          int    // 在线状态 0 未启用  1 在线  2 离线
 	T_online_s        int    // 在线状态-备用  0 未启用  1 在线  2 离线
 	T_online_s        int    // 在线状态-备用  0 未启用  1 在线  2 离线
+	T_State           int    // 0 屏蔽   1 正常
 	// 硬件信息
 	// 硬件信息
 	T_model           string // KF200BG  产品型号
 	T_model           string // KF200BG  产品型号
 	T_ProductTypeName string // 验证工具LoRa  产品统称 + 类型
 	T_ProductTypeName string // 验证工具LoRa  产品统称 + 类型
@@ -72,9 +73,12 @@ type Device_R struct {
 	T_hver            string // "1.0.0",//硬件版本
 	T_hver            string // "1.0.0",//硬件版本
 	T_imei            string // "867387060327718",//模组imei
 	T_imei            string // "867387060327718",//模组imei
 	T_iccid           string // "89860477102170049750",//sim卡号
 	T_iccid           string // "89860477102170049750",//sim卡号
+	T_rssi            string // "80",//信号强度
 	CreateTime        string //auto_now_add 第一次保存时才设置时间
 	CreateTime        string //auto_now_add 第一次保存时才设置时间
 	UpdateTime        string //auto_now 每次 model 保存时都会对时间自动更新
 	UpdateTime        string //auto_now 每次 model 保存时都会对时间自动更新
 
 
+	T_DeviceSensor_Num int // 传感器数量
+
 }
 }
 
 
 type Device_task struct {
 type Device_task struct {
@@ -106,29 +110,34 @@ func init() {
 
 
 func DeviceToDevice_R(r Device) (t Device_R) {
 func DeviceToDevice_R(r Device) (t Device_R) {
 	t.T_sn = r.T_sn
 	t.T_sn = r.T_sn
-	t.T_MSISDN = r.T_MSISDN
 	t.T_devName = r.T_devName
 	t.T_devName = r.T_devName
 	t.T_protocol = r.T_protocol
 	t.T_protocol = r.T_protocol
 	t.T_VerifyTime = r.T_VerifyTime.Format("2006-01-02 15:04:05")
 	t.T_VerifyTime = r.T_VerifyTime.Format("2006-01-02 15:04:05")
 	t.T_CalibrationTime = r.T_CalibrationTime.Format("2006-01-02 15:04:05")
 	t.T_CalibrationTime = r.T_CalibrationTime.Format("2006-01-02 15:04:05")
+	t.T_PatrolTime = r.T_PatrolTime.Format("2006-01-02 15:04:05")
 	t.T_ist = r.T_ist
 	t.T_ist = r.T_ist
 	t.T_ish = r.T_ish
 	t.T_ish = r.T_ish
 	t.T_Dattery = r.T_Dattery
 	t.T_Dattery = r.T_Dattery
 	t.T_Site = r.T_Site
 	t.T_Site = r.T_Site
 	t.T_type = r.T_type
 	t.T_type = r.T_type
-	t.T_give = r.T_give
 	t.T_monitor = r.T_monitor
 	t.T_monitor = r.T_monitor
 	t.T_online = r.T_online
 	t.T_online = r.T_online
 	t.T_online_s = r.T_online_s
 	t.T_online_s = r.T_online_s
+	if r.T_online == 2 && (r.T_online_s == 0 || r.T_online_s == 2) && r.T_monitor == 1 {
+		t.T_monitor = 2
+	}
+	t.T_State = r.T_State
+
 	t.T_model = r.T_model
 	t.T_model = r.T_model
 	t.T_ProductTypeName = Product.Read_ProductType_Get(r.T_model)
 	t.T_ProductTypeName = Product.Read_ProductType_Get(r.T_model)
 	t.T_sver = r.T_sver
 	t.T_sver = r.T_sver
 	t.T_hver = r.T_hver
 	t.T_hver = r.T_hver
 	t.T_imei = r.T_imei
 	t.T_imei = r.T_imei
 	t.T_iccid = r.T_iccid
 	t.T_iccid = r.T_iccid
+	t.T_rssi = r.T_rssi
 	t.CreateTime = r.CreateTime.Format("2006-01-02 15:04:05")
 	t.CreateTime = r.CreateTime.Format("2006-01-02 15:04:05")
 	t.UpdateTime = r.UpdateTime.Format("2006-01-02 15:04:05")
 	t.UpdateTime = r.UpdateTime.Format("2006-01-02 15:04:05")
-
+	t.T_DeviceSensor_Num = Read_DeviceSensor_Num_ByT_sn(r.T_sn)
 	return
 	return
 }
 }
 
 
@@ -178,8 +187,8 @@ func Read_Device_ByT_sn(T_sn string) (r Device, err error) {
 	}
 	}
 	//println("没有 Redis_Get SN")
 	//println("没有 Redis_Get SN")
 	o := orm.NewOrm()
 	o := orm.NewOrm()
-	r = Device{T_sn: T_sn, T_State: 1}
-	err = o.Read(&r, "T_sn", "T_State") // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
+	r = Device{T_sn: T_sn}
+	err = o.Read(&r, "T_sn") // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
 	if err != nil {
 	if err != nil {
 		fmt.Println(err)
 		fmt.Println(err)
 	} else {
 	} else {
@@ -195,8 +204,9 @@ func Add_Device(m Device) (err error) {
 	_, err = o.Insert(&m)
 	_, err = o.Insert(&m)
 	if err != nil {
 	if err != nil {
 		fmt.Println(err)
 		fmt.Println(err)
+	} else {
+		Redis_Set(m) // Redis 更新缓存
 	}
 	}
-	Redis_Set(m) // Redis 更新缓存
 	return err
 	return err
 }
 }
 
 
@@ -229,10 +239,6 @@ func Read_Device_List(admin Account.Admin, T_pid int, T_name string, T_monitor s
 
 
 	qs := o.QueryTable(new(Device))
 	qs := o.QueryTable(new(Device))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
-
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -240,7 +246,11 @@ func Read_Device_List(admin Account.Admin, T_pid int, T_name string, T_monitor s
 	}
 	}
 
 
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_State", 1).And("T_pid", T_pid)
+	cond1 := cond.And("T_pid", T_pid)
+	// 非内部权限 - 不可查看屏蔽数据
+	if admin.T_pid > 0 {
+		cond1 = cond1.And("T_State", 1)
+	}
 
 
 	if len(T_name) > 0 {
 	if len(T_name) > 0 {
 		cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name).Or("T_MSISDN__icontains", T_name))
 		cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name).Or("T_MSISDN__icontains", T_name))
@@ -266,14 +276,9 @@ func Read_Device_List(admin Account.Admin, T_pid int, T_name string, T_monitor s
 		cond1 = cond1.AndCond(cond.And("T_online", 0).Or("T_online", 2))
 		cond1 = cond1.AndCond(cond.And("T_online", 0).Or("T_online", 2))
 	}
 	}
 
 
-	// 非内部权限 - 丢弃
-	if admin.T_pid > 0 {
-		cond1 = cond1.AndCond(cond.And("T_give", 1))
-	}
-
 	var rx []Device
 	var rx []Device
 
 
-	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("Id").OrderBy("-T_give").All(&rx)
+	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("CreateTime").All(&rx)
 	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
 	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
 
 
 	for _, v := range rx {
 	for _, v := range rx {
@@ -290,12 +295,12 @@ func Read_Device_ALL_T_Type_Count(T_pid int, T_type int) (cnt int64) {
 	return cnt
 	return cnt
 }
 }
 
 
-func Read_Device_List_T_model(T_model string) (r []Device) {
+func Read_Device_List_ByT_model(T_model string) (r []Device) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 	qs := o.QueryTable(new(Device))
 	qs := o.QueryTable(new(Device))
-	qs.Filter("T_State", 1).Filter("T_model", T_model).All(&r)
+	qs.Filter("T_model", T_model).All(&r)
 
 
 	return r
 	return r
 }
 }

+ 1 - 1
models/Device/DeviceData.go

@@ -320,7 +320,7 @@ func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_
 		sn_id := strings.Split(v, ",")
 		sn_id := strings.Split(v, ",")
 
 
 		if len(sn_id) == 2 {
 		if len(sn_id) == 2 {
-			Read_DeviceSensorParameter_Map_All(sn_id[0], lib.To_int(sn_id[1]))
+			Read_DeviceSensorParameter_All_Map(sn_id[0], lib.To_int(sn_id[1]))
 			r_maps, r_maps_num := Read_DeviceData_ById_List(sn_id[0], lib.To_int(sn_id[1]), Time_start_, Time_end_, 0, 9999)
 			r_maps, r_maps_num := Read_DeviceData_ById_List(sn_id[0], lib.To_int(sn_id[1]), Time_start_, Time_end_, 0, 9999)
 			//for i, _ := range r_maps {
 			//for i, _ := range r_maps {
 			//	r_maps[i].T_sn = sn_id[0]
 			//	r_maps[i].T_sn = sn_id[0]

+ 40 - 26
models/Device/DeviceParameter.go

@@ -12,37 +12,51 @@ import (
 type DeviceParameter struct {
 type DeviceParameter struct {
 	Id int `orm:"column(ID);size(11);auto;pk"`
 	Id int `orm:"column(ID);size(11);auto;pk"`
 
 
-	T_sn           string `orm:"index;size(256);null"` //设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_devName      string `orm:"size(256);null"`       //设备名称
-	T_uploadTime   int    `orm:"size(200);null"`       //实时数据上传间隔
-	T_saveTime     int    `orm:"size(200);null"`       //数据保存间隔
-	T_overrunSave  int    `orm:"size(200);null"`       //数据超限保存间隔
-	T_overrunAlarm int    `orm:"size(200);null"`       //超限报警触发间隔
-	T_outageAlarm  int    `orm:"size(200);null"`       //断电报警触发间隔
-	T_lostAlarm    int    `orm:"size(200);null"`       //传感器掉线报警触发间隔
-	T_warningTime  int    `orm:"size(200);null"`       //超限预警触发间隔
-	T_warningDelay int    `orm:"size(200);null"`       //超限预警延时
-	T_batteryLimit int    `orm:"size(200);null"`       //电池电量下限
-	T_enwarning    int    `orm:"size(2);null"`         //是否启动超限预警
-	T_company      string `orm:"size(256);''"`         //公司名称
-	T_btname       string `orm:"size(256);''"`         //蓝牙打印机名称
-	T_btserverID   string `orm:"size(256);''"`         //打印机服务号
-	T_btchar       string `orm:"size(256);''"`         //蓝牙特征码
-	T_decTotal     string `orm:"size(256);''"`         ////配置管理主机总终端数量
-	T_chDecTotal   string `orm:"size(256);''"`         //[18,19,21,12,30,0,0,0,0,0]  //配置每个通道数量[第1通道,第2通道…第10通道]
-
-	T_uuid      string    `orm:"size(256);null"`                                        // 处理 人员
-	T_Msid      int       `orm:"size(50);0"`                                            // 消息识别ID
-	T_SendState int       `orm:"size(2);0"`                                             // 发送状态  0 待发送   1 发送成功  2 发送失败  3 丢弃
-	T_State     int       `orm:"size(2);default(1)"`                                    //  1 系统获取   2 用户提交
-	CreateTime  time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
-	UpdateTime  time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
+	T_sn string `orm:"size(256);null"` // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
+
+	T_name string `orm:"size(256);null"` //设备名称 (传 * 代表托管给平台处理) *
+
+	T_saveT int `orm:"size(5);null"` //数据保存间隔 s(60~3600) 默认:60 *
+	T_overA int `orm:"size(5);null"` //数据保存间隔 超限报警触发间隔 s(60~600) 默认:60  *
+	T_outA  int `orm:"size(5);null"` //超限报警触发间隔 s(0,60~600)  为0时只触发一次 默认:60 *
+	T_lostA int `orm:"size(5);null"` //传感器掉线报警触发间隔  s(0,60~600) 为0时只触发一次 默认:60  *
+	T_bat   int `orm:"size(5);null"` // 电池电量下限   %(0~30) 默认:20 *
+
+	T_warn  int `orm:"size(5);null"` // 超限预警触发间隔 s(0,60~600)为0时只触发一次 默认:60  *
+	T_warnD int `orm:"size(5);null"` // 超限预警延时   s(0~600) 默认:0 *
+
+	T_btname string `orm:"size(256);''"` //蓝牙打印机名称
+	T_btsid  int    `orm:"size(256);''"` //打印机服务号
+	T_btchar int    `orm:"size(256);''"` //蓝牙特征码
+
+	T_uuid      string `orm:"size(256);null"` // 处理 人员
+	T_Msid      int64  `orm:"size(50);0"`     // 消息识别ID
+	T_SendState int    `orm:"size(2);1"`      // 发送状态  0 待发送   1 发送成功  2 发送失败  3 丢弃
+	T_State     int    `orm:"size(2);1"`      //  1 系统获取   2 用户提交
+
+	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
+	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 }
 }
 
 
 func (t *DeviceParameter) TableName() string {
 func (t *DeviceParameter) TableName() string {
 	return "device_parameter" // 数据库名称   // ************** 替换 FormulaList **************
 	return "device_parameter" // 数据库名称   // ************** 替换 FormulaList **************
 }
 }
 
 
+type DeviceParameter_R struct {
+	T_sn     string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
+	T_name   string // 设备名称 (传 * 代表托管给平台处理) *
+	T_saveT  int    // 数据保存间隔 s(60~3600) 默认:60 *
+	T_overA  int    // 数据保存间隔 超限报警触发间隔 s(60~600) 默认:60  *
+	T_outA   int    // 超限报警触发间隔 s(0,60~600)  为0时只触发一次 默认:60 *
+	T_lostA  int    // 传感器掉线报警触发间隔  s(0,60~600) 为0时只触发一次 默认:60  *
+	T_bat    int    // 电池电量下限   %(0~30) 默认:20 *
+	T_warn   int    // 超限预警触发间隔 s(0,60~600)为0时只触发一次 默认:60  *
+	T_warnD  int    // 超限预警延时   s(0~600) 默认:0 *
+	T_btname string // 蓝牙打印机名称
+	T_btsid  int    // 打印机服务号
+	T_btchar int    // 蓝牙特征码
+}
+
 func init() {
 func init() {
 	//注册模型
 	//注册模型
 	orm.RegisterModel(new(DeviceParameter))
 	orm.RegisterModel(new(DeviceParameter))
@@ -145,7 +159,7 @@ func Read_DeviceParameter_SN_List(T_sn string) (r []DeviceParameter) {
 
 
 	qs := o.QueryTable(new(DeviceParameter))
 	qs := o.QueryTable(new(DeviceParameter))
 
 
-	qs.Limit(10, 0).Filter("T_sn", T_sn).OrderBy("-Id").All(&r)
+	qs.Limit(10, 0).Filter("T_sn", T_sn).Filter("T_State", 1).OrderBy("-Id").All(&r)
 
 
 	return r
 	return r
 }
 }

+ 102 - 108
models/Device/DeviceSensor.go

@@ -23,21 +23,21 @@ type DeviceSensor struct {
 	T_id   int    `orm:"index;size(11);null"`  // 传感器编号
 	T_id   int    `orm:"index;size(11);null"`  // 传感器编号
 	T_name string `orm:"size(256);null"`       // 标题
 	T_name string `orm:"size(256);null"`       // 标题
 
 
-	T_pid      int    `orm:"index;size(256);null"`     // Account.Company 绑定公司
-	T_Class    string `orm:"size(256);null"`           // Device.DeviceClass.Id 设备分类  C1|C2|
-	T_Notice   string `orm:"size(256);null"`           // Device.DeviceNotice.Id 设备通知策略  N1|N2|
-	T_datashow int    `orm:"index;size(2);default(1)"` // 0 屏蔽数据展示  1 正常数据展示
-	T_sort     int    `orm:"index;size(200);1"`        // 排序
-	T_3dview   string `orm:"size(256);null"`           // 3D 视图ID
+	T_pid      int    `orm:"index;size(256);null"`       // Account.Company 绑定公司
+	T_Class    string `orm:"size(256);null"`             // Device.DeviceClass.Id 设备分类  C1|C2|
+	T_Notice   string `orm:"size(256);null"`             // 通知绑定
+	T_datashow int    `orm:"index;size(2);default(1)"`   // 0 屏蔽数据展示  1 正常数据展示   (屏蔽后 数据展示无法看到,设备管理中 不受影响)
+	T_sort     int    `orm:"index;size(200);default(1)"` // 排序
+	T_3dview   string `orm:"size(256);null"`             // 3D 视图ID
 
 
 	// 设备同步参数
 	// 设备同步参数
 	T_Dattery  int    `orm:"size(4);null"`             // 电量
 	T_Dattery  int    `orm:"size(4);null"`             // 电量
 	T_Site     string `orm:"size(200);null"`           // GPS
 	T_Site     string `orm:"size(200);null"`           // GPS
 	T_type     int    `orm:"index;size(4);null"`       // Device.DeviceType  1库房   2移动
 	T_type     int    `orm:"index;size(4);null"`       // Device.DeviceType  1库房   2移动
-	T_give     int    `orm:"index;size(2);default(1)"` // 屏蔽状态 0 屏蔽  1 正常
 	T_monitor  int    `orm:"index;size(2);null"`       // 监控状态 0 未监控 1 监控
 	T_monitor  int    `orm:"index;size(2);null"`       // 监控状态 0 未监控 1 监控
 	T_online   int    `orm:"index;size(2);default(1)"` // 在线状态 0 未启用  1 在线  2 离线
 	T_online   int    `orm:"index;size(2);default(1)"` // 在线状态 0 未启用  1 在线  2 离线
 	T_online_s int    `orm:"index;size(2);default(0)"` // 在线状态-备用  0 未启用  1 在线  2 离线
 	T_online_s int    `orm:"index;size(2);default(0)"` // 在线状态-备用  0 未启用  1 在线  2 离线
+	T_State    int    `orm:"index;size(2);default(1)"` // 0 屏蔽   1 正常  (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
 
 
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
@@ -79,15 +79,17 @@ type DeviceSensor_P struct {
 
 
 	T_sort     int // 排序
 	T_sort     int // 排序
 	T_datashow int // 0 屏蔽数据展示  1 正常数据展示
 	T_datashow int // 0 屏蔽数据展示  1 正常数据展示
+	T_State    int // 0 屏蔽   1 正常
 
 
 	// DeviceSensorParameter
 	// DeviceSensorParameter
-	T_Tlower  float32 //  温度下限
-	T_Tupper  float32 //  温度上限
-	T_RHlower float32 //  湿度下限
-	T_RHupper float32 //  湿度上限
+	T_Tlower  *float32 //  温度下限
+	T_Tupper  *float32 //  温度上限
+	T_RHlower *float32 //  湿度下限
+	T_RHupper *float32 //  湿度上限
+
+	T_en   *int // en:是否启用传感器,
+	T_free *int // free:监测点是否为闲置状态(空库,只监测不报警)
 
 
-	T_en   int // en:是否启用传感器,
-	T_free int // free:监测点是否为闲置状态(空库,只监测不报警)
 }
 }
 
 
 var redisCache_DeviceSensor cache.Cache
 var redisCache_DeviceSensor cache.Cache
@@ -178,7 +180,7 @@ func DeviceSensorToDeviceSensor_R(DeviceSensor_ DeviceSensor) (DeviceSensor_r De
 // ----------------------------------- v2 -------------------------------------------------------------
 // ----------------------------------- v2 -------------------------------------------------------------
 
 
 // 获取列表 - 总数
 // 获取列表 - 总数
-func Read_V2_DeviceSensor_ByTsn_num(T_sn string) int {
+func Read_DeviceSensor_Num_ByT_sn(T_sn string) int {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 	qs := o.QueryTable(new(DeviceSensor))
 	qs := o.QueryTable(new(DeviceSensor))
@@ -187,16 +189,13 @@ func Read_V2_DeviceSensor_ByTsn_num(T_sn string) int {
 }
 }
 
 
 // 获取列表
 // 获取列表
-func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name string, T_Class_id, T_Notice_id int, T_give int, T_datashow 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 int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 
 
 	qs := o.QueryTable(new(DeviceSensor))
 	qs := o.QueryTable(new(DeviceSensor))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -213,10 +212,8 @@ func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name
 		cond1 = cond1.And("T_Class__icontains", T_Class)
 		cond1 = cond1.And("T_Class__icontains", T_Class)
 	}
 	}
 
 
-	if T_Notice_id > 0 {
-		T_Notice := "N" + strconv.Itoa(T_Notice_id) + "|"
-		fmt.Println("T_Class:", T_Notice)
-		cond1 = cond1.And("T_Notice__icontains", T_Notice)
+	if T_type > 0 {
+		cond1 = cond1.And("T_type", T_type)
 	}
 	}
 
 
 	if len(T_sn) > 0 {
 	if len(T_sn) > 0 {
@@ -227,39 +224,18 @@ func Read_DeviceSensorList(admin_r Account.Admin, T_pid int, T_sn string, T_name
 		cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name))
 		cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name))
 	}
 	}
 
 
-	// 不是内部权限(T_pid>0),只显示T_give=1 0 屏蔽  1 正常
+	// 不是内部权限(T_pid>0),T_State=1 0 屏蔽  1 正常
 	if admin_r.T_pid > 0 {
 	if admin_r.T_pid > 0 {
-		cond1 = cond1.And("T_give", 1)
-	} else if T_give != -1 {
-		cond1 = cond1.And("T_give", T_give)
+		cond1 = cond1.And("T_State", 1)
 	}
 	}
 
 
-	if T_datashow != -1 { // 空:正常显示   1:强制显示 屏蔽数据展示
+	if T_datashow == 1 { // 0 屏蔽数据展示  1 正常数据展示
 		cond1 = cond1.And("T_datashow", 1)
 		cond1 = cond1.And("T_datashow", 1)
 	}
 	}
 
 
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
 	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
 	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 {
 	for _, v := range r {
 		DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_R(v))
 		DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_R(v))
 	}
 	}
@@ -323,7 +299,10 @@ func DeviceSensor_Bind_T_Class_Del(T_sn string, T_id int, T_Class_id int) (err e
 	T_Class := "C" + strconv.Itoa(T_Class_id) + "|"
 	T_Class := "C" + strconv.Itoa(T_Class_id) + "|"
 	if err = o.Read(&v, "T_sn", "T_id"); err == nil {
 	if err = o.Read(&v, "T_sn", "T_id"); err == nil {
 		v.T_Class = strings.Replace(v.T_Class, T_Class, "", -1)
 		v.T_Class = strings.Replace(v.T_Class, T_Class, "", -1)
-		o.Update(&v, "T_Class")
+		if _, err := o.Update(&v, "T_Class"); err == nil {
+			Redis_DeviceSensor_Set(v)
+		}
+
 	}
 	}
 	return err
 	return err
 
 
@@ -337,7 +316,9 @@ func DeviceSensor_T_Class_Add(T_sn string, T_id int, T_Class_id int) (err error)
 	if err = o.Read(&v, "T_sn", "T_id"); err == nil {
 	if err = o.Read(&v, "T_sn", "T_id"); err == nil {
 		v.T_Class = strings.Replace(v.T_Class, T_Class, "", -1)
 		v.T_Class = strings.Replace(v.T_Class, T_Class, "", -1)
 		v.T_Class = v.T_Class + T_Class
 		v.T_Class = v.T_Class + T_Class
-		o.Update(&v, "T_Class")
+		if _, err := o.Update(&v, "T_Class"); err == nil {
+			Redis_DeviceSensor_Set(v)
+		}
 	}
 	}
 	return err
 	return err
 }
 }
@@ -372,41 +353,6 @@ func DeviceSensor_T_Class_ALL_Del(T_Class_id int) {
 //	return err
 //	return err
 //}
 //}
 
 
-// 获取最新数据
-func DeviceSensor_T_Bind_ALL(T_sn string, T_Bind string) {
-	o := orm.NewOrm()
-
-	res, err := o.Raw("UPDATE DeviceSensor SET `t__bind` = '" + T_Bind + "' WHERE `t_sn` = '" + T_sn + "' ").Exec()
-	if err == nil {
-		num, _ := res.RowsAffected()
-		fmt.Println("mysql row affected nums: ", num)
-	}
-
-}
-
-// 获取最新数据
-func DeviceSensor_T_type_ALL(T_sn string, T_type int) {
-	o := orm.NewOrm()
-
-	res, err := o.Raw("UPDATE DeviceSensor SET `t_type` = " + strconv.Itoa(T_type) + " WHERE `t_sn` = '" + T_sn + "' ").Exec()
-	if err == nil {
-		num, _ := res.RowsAffected()
-		fmt.Println("mysql row affected nums: ", num)
-	}
-
-}
-
-// 获取最新数据
-func DeviceSensor_t_give_ALL(T_sn string, t_give int) {
-	o := orm.NewOrm()
-
-	res, err := o.Raw("UPDATE DeviceSensor SET `t_give` = " + strconv.Itoa(t_give) + " WHERE `t_sn` = '" + T_sn + "' ").Exec()
-	if err == nil {
-		num, _ := res.RowsAffected()
-		fmt.Println("mysql row affected nums: ", num)
-	}
-}
-
 // 获取 ById
 // 获取 ById
 func Read_DeviceSensor_ByTsn_Tid(T_sn string, T_id int) (r DeviceSensor, err error) {
 func Read_DeviceSensor_ByTsn_Tid(T_sn string, T_id int) (r DeviceSensor, err error) {
 
 
@@ -460,16 +406,13 @@ func Read_DeviceSensor_ALL_T_sn(T_sn string, page int, page_z int) (DeviceSensor
 }
 }
 
 
 // 获取列表
 // 获取列表
-func Read_DeviceSensor_class_ALL_1(admin Account.Admin, T_pid int, T_Class_id int, page int, page_z int, T_sn string, T_name string, SN_type string) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+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) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 
 
 	qs := o.QueryTable(new(DeviceSensor))
 	qs := o.QueryTable(new(DeviceSensor))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -485,13 +428,13 @@ func Read_DeviceSensor_class_ALL_1(admin Account.Admin, T_pid int, T_Class_id in
 
 
 	var r []DeviceSensor
 	var r []DeviceSensor
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_pid", T_pid).And("T_Class__icontains", T_Class).And("T_sn__icontains", SN_type).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name).And("T_datashow", 1) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
-	if len(T_sn) < 6 {
-		cond1 = cond1.AndCond(cond.And("T_give", 1))
+	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)
+	if T_type > 0 {
+		cond1 = cond1.AndCond(cond.And("T_type", T_type))
 	}
 	}
 
 
 	if admin.T_pid > 0 {
 	if admin.T_pid > 0 {
-		cond1 = cond1.AndCond(cond.And("T_give", 1))
+		cond1 = cond1.AndCond(cond1.And("T_State", 1))
 	}
 	}
 
 
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
@@ -654,16 +597,13 @@ func Read_DeviceSensor_ALL_Notice_Id(T_Notice_id int) (r []DeviceSensor) {
 }
 }
 
 
 // 获取列表
 // 获取列表
-func Read_DeviceSensor_Notice_ALL_1(T_pid int, T_Notice_id int, page int, page_z int, T_sn string, T_name string, SN_type string) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+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) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 
 
 	qs := o.QueryTable(new(DeviceSensor))
 	qs := o.QueryTable(new(DeviceSensor))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -679,9 +619,14 @@ func Read_DeviceSensor_Notice_ALL_1(T_pid int, T_Notice_id int, page int, page_z
 
 
 	var r []DeviceSensor
 	var r []DeviceSensor
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_pid", T_pid).And("T_Notice__icontains", T_Notice).And("T_sn__icontains", SN_type).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name).And("T_datashow", 1) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
-	if len(T_sn) < 6 {
-		cond1 = cond1.AndCond(cond.And("T_give", 1))
+	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)
+	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)
 	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
@@ -702,19 +647,19 @@ func Update_Device_To_DeviceSensor(r_Device Device) bool {
 		v.T_Dattery = r_Device.T_Dattery   // 电量
 		v.T_Dattery = r_Device.T_Dattery   // 电量
 		v.T_Site = r_Device.T_Site         // GPS
 		v.T_Site = r_Device.T_Site         // GPS
 		v.T_type = r_Device.T_type         // 1库房   2移动
 		v.T_type = r_Device.T_type         // 1库房   2移动
-		v.T_give = r_Device.T_give         // 屏蔽状态 0 屏蔽  1 正常
 		v.T_monitor = r_Device.T_monitor   // 监控状态 0 未监控 1 监控
 		v.T_monitor = r_Device.T_monitor   // 监控状态 0 未监控 1 监控
 		v.T_online = r_Device.T_online     // 在线状态 0 未启用  1 在线  2 离线
 		v.T_online = r_Device.T_online     // 在线状态 0 未启用  1 在线  2 离线
 		v.T_online_s = r_Device.T_online_s // 在线状态-备用  0 未启用  1 在线  2 离线
 		v.T_online_s = r_Device.T_online_s // 在线状态-备用  0 未启用  1 在线  2 离线
+		v.T_State = r_Device.T_State       // 0 屏蔽   1 正常  (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
 
 
-		Update_DeviceSensor(v, "T_Dattery", "T_Site", "T_type", "T_give", "T_monitor", "T_online", "T_online_s")
+		Update_DeviceSensor(v, "T_Dattery", "T_Site", "T_type", "T_State", "T_monitor", "T_online", "T_online_s")
 	}
 	}
 
 
 	return true
 	return true
 }
 }
 
 
 // 传感器管理列列表 -------------------
 // 传感器管理列列表 -------------------
-func Read_DeviceSensorManageList(T_pid int, T_name string, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z int) (DeviceSensor_p []DeviceSensor_P, cnt int64) {
+func Read_DeviceSensorManageList(admin_r Account.Admin, T_pid int, T_name string, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z int) (DeviceSensor_p []DeviceSensor_P, cnt int64) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	var maps []DeviceSensor_P
 	var maps []DeviceSensor_P
 	var maps_z []orm2.ParamsList
 	var maps_z []orm2.ParamsList
@@ -728,6 +673,10 @@ func Read_DeviceSensorManageList(T_pid int, T_name string, T_calss_id, T_en, T_f
 
 
 	sql_WHERE := "t_pid = " + strconv.Itoa(T_pid)
 	sql_WHERE := "t_pid = " + strconv.Itoa(T_pid)
 
 
+	if admin_r.T_pid > 0 {
+		sql_WHERE += " AND t__state = 1"
+	}
+
 	if len(T_name) > 0 {
 	if len(T_name) > 0 {
 		sql_WHERE += " AND (ds.t_sn like '%" + T_name + "%' OR t_name like '%" + T_name + "%')"
 		sql_WHERE += " AND (ds.t_sn like '%" + T_name + "%' OR t_name like '%" + T_name + "%')"
 	}
 	}
@@ -752,11 +701,10 @@ func Read_DeviceSensorManageList(T_pid int, T_name string, T_calss_id, T_en, T_f
 	}
 	}
 
 
 	// -------------
 	// -------------
-
 	sql := "SELECT COUNT(ds.ID) FROM " + "device_sensor ds " +
 	sql := "SELECT COUNT(ds.ID) FROM " + "device_sensor ds " +
-		"LEFT JOIN ( SELECT tsn,tid,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper " +
-		"FROM (SELECT DISTINCT t_sn AS tsn,t_id AS tid,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper FROM `device_sensor_parameter` ORDER BY id DESC) f GROUP BY tsn,tid) AS dsp " +
-		"ON ds.t_sn = dsp.tsn AND ds.t_id = dsp.tid" + " WHERE " + sql_WHERE
+		"LEFT JOIN ( SELECT t_sn,t_id,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper " +
+		"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.t_sn AND ds.t_id = dsp.t_id" + " WHERE " + sql_WHERE
 	fmt.Println(sql)
 	fmt.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 	if err != nil {
@@ -767,9 +715,9 @@ func Read_DeviceSensorManageList(T_pid int, T_name string, T_calss_id, T_en, T_f
 	}
 	}
 	//fmt.Println("maps_z;",maps_z[0][0])
 	//fmt.Println("maps_z;",maps_z[0][0])
 	sql = "SELECT * FROM device_sensor ds " +
 	sql = "SELECT * FROM device_sensor ds " +
-		"LEFT JOIN ( SELECT tsn,tid,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper " +
-		"FROM (SELECT DISTINCT t_sn AS tsn,t_id AS tid,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper FROM `device_sensor_parameter` ORDER BY id DESC) f GROUP BY tsn,tid) AS dsp " +
-		"ON ds.t_sn = dsp.tsn AND ds.t_id = dsp.tid " +
+		"LEFT JOIN ( SELECT t_sn,t_id,t_en,t_free,t__tlower,t__tupper,t__r_hlower,t__r_hupper " +
+		"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.t_sn AND ds.t_id = dsp.t_id " +
 		"WHERE " + sql_WHERE + sql_ORDER
 		"WHERE " + sql_WHERE + sql_ORDER
 
 
 	if page_z != 9999 {
 	if page_z != 9999 {
@@ -783,3 +731,49 @@ func Read_DeviceSensorManageList(T_pid int, T_name string, T_calss_id, T_en, T_f
 
 
 	return maps, key
 	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()
+	// 也可以直接使用 Model 结构体作为表名
+
+	qs := o.QueryTable(new(DeviceSensor))
+	var offset int64
+	if page <= 1 {
+		offset = 0
+	} else {
+		offset = int64((page - 1) * page_z)
+	}
+
+	var r []DeviceSensor
+	cond := orm.NewCondition()
+	cond1 := cond.And("T_pid", T_pid).And("T_State", 1).And("T_datashow", 1)
+
+	if T_Class_id > 0 {
+		T_Class := "C" + strconv.Itoa(T_Class_id) + "|"
+		fmt.Println("T_Class:", T_Class)
+		cond1 = cond1.And("T_Class__icontains", T_Class)
+	}
+
+	if T_type > 0 {
+		cond1 = cond1.And("T_type", T_type)
+	}
+
+	if len(T_sn) > 0 {
+		cond1 = cond1.And("T_sn__icontains", T_sn)
+	}
+
+	if len(T_name) > 0 {
+		cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name))
+	}
+
+	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
+	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
+
+	for _, v := range r {
+		DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_R(v))
+	}
+	return DeviceSensor_r, cnt
+	//return r, cnt
+}

+ 13 - 10
models/Device/DeviceSensorParameter.go

@@ -27,13 +27,13 @@ type DeviceSensorParameter struct {
 	T_RHlower float32 `orm:"size(200);null"` //  湿度下限
 	T_RHlower float32 `orm:"size(200);null"` //  湿度下限
 	T_RHupper float32 `orm:"size(200);null"` //  湿度上限
 	T_RHupper float32 `orm:"size(200);null"` //  湿度上限
 	// 预警
 	// 预警
-	T_enprel int     `orm:"size(2);default(1)"` //  是否启用预警
+	T_enprel int     `orm:"size(2);default(1)"` //  是否启用预警 1开启  0 关闭
 	T_tprel  float32 `orm:"size(200);null"`     //  温度预警下限
 	T_tprel  float32 `orm:"size(200);null"`     //  温度预警下限
 	T_tpreu  float32 `orm:"size(200);null"`     //  温度预警上限
 	T_tpreu  float32 `orm:"size(200);null"`     //  温度预警上限
 	T_hprel  float32 `orm:"size(200);null"`     //  湿度预警下限
 	T_hprel  float32 `orm:"size(200);null"`     //  湿度预警下限
 	T_hpreu  float32 `orm:"size(200);null"`     //  温度预警上限
 	T_hpreu  float32 `orm:"size(200);null"`     //  温度预警上限
 
 
-	T_en   int `orm:"size(2);default(1)"` // en:是否启用传感器,   0 停用   1 启用
+	T_en   int `orm:"size(2);default(1)"` // en:是否启用传感器,   0 停用  1 启用
 	T_free int `orm:"size(2);default(1)"` // free:监测点是否为闲置状态(空库,只监测不报警)    0 正常   1 空库
 	T_free int `orm:"size(2);default(1)"` // free:监测点是否为闲置状态(空库,只监测不报警)    0 正常   1 空库
 
 
 	// 逻辑字段
 	// 逻辑字段
@@ -177,7 +177,10 @@ func Read_DeviceSensorParameter(T_sn string, T_id int) (t DeviceSensorParameter_
 		return t, false
 		return t, false
 	}
 	}
 
 
-	return DeviceSensorParameterToDeviceSensorParameter_R(r[0]), true
+	t = DeviceSensorParameterToDeviceSensorParameter_R(r[0])
+	Redis_DeviceSensorParameter_Set(key, t)
+
+	return t, true
 }
 }
 
 
 // 获取列表  T_State  1 系统获取   2 用户提交
 // 获取列表  T_State  1 系统获取   2 用户提交
@@ -199,14 +202,15 @@ func Read_DeviceSensorParameter_List(T_sn string, T_id int, T_State int, page_z
 }
 }
 
 
 // 添加
 // 添加
-func Add_DeviceSensorParameter(m DeviceSensorParameter) (int64, bool) {
+func Add_DeviceSensorParameter(m DeviceSensorParameter) (DeviceSensorParameter, bool) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	id, err := o.Insert(&m)
 	id, err := o.Insert(&m)
 	if err != nil {
 	if err != nil {
 		fmt.Println(err)
 		fmt.Println(err)
-		return 0, false
+		return m, false
 	}
 	}
-	return id, true
+	m.Id = int(id)
+	return m, true
 }
 }
 
 
 // 修改
 // 修改
@@ -231,7 +235,7 @@ func DELETE_DeviceSensorParameter(SN string) bool {
 }
 }
 
 
 // 获取列表  T_State  1 系统获取   2 用户提交
 // 获取列表  T_State  1 系统获取   2 用户提交
-func Read_DeviceSensorParameter_Map_All(T_sn string, T_id int) {
+func Read_DeviceSensorParameter_All_Map(T_sn string, T_id int) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
 	var list []DeviceSensorParameter
 	var list []DeviceSensorParameter
@@ -239,12 +243,11 @@ func Read_DeviceSensorParameter_Map_All(T_sn string, T_id int) {
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
 
 
 	//cond = cond.And("T_sn", T_sn).And("T_id", T_id).AndCond(cond.And("T_State", 1).OrCond(cond.And("T_State", 2).And("T_SendState", 1)))
 	//cond = cond.And("T_sn", T_sn).And("T_id", T_id).AndCond(cond.And("T_State", 1).OrCond(cond.And("T_State", 2).And("T_SendState", 1)))
-	cond1 := cond.And("T_State", 1)
 	if len(T_sn) > 0 {
 	if len(T_sn) > 0 {
-		cond1 = cond1.And("T_sn", T_sn)
+		cond = cond.And("T_sn", T_sn)
 	}
 	}
 	if T_id > 0 {
 	if T_id > 0 {
-		cond1 = cond1.And("T_id", T_id)
+		cond = cond.And("T_id", T_id)
 	}
 	}
 
 
 	qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&list)
 	qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&list)

+ 0 - 5
models/Device/DeviceTask.go

@@ -1,7 +1,6 @@
 package Device
 package Device
 
 
 import (
 import (
-	"Cold_Api/conf"
 	"github.com/beego/beego/v2/adapter/orm"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
 	_ "github.com/go-sql-driver/mysql"
@@ -48,10 +47,6 @@ func Read_DeviceTask_All(T_sn string, Time_start string, Time_end string, page i
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	qs := o.QueryTable(new(DeviceTask))
 	qs := o.QueryTable(new(DeviceTask))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
-
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {

+ 1 - 1
models/Product/ProductType.go

@@ -49,7 +49,7 @@ func init() {
 }
 }
 
 
 // 获取全部
 // 获取全部
-func Read_ProductType_All() {
+func Read_ProductType_All_Map() {
 	time.Sleep(time.Second)
 	time.Sleep(time.Second)
 
 
 	logs.Println("=========== 初始化产品类型 =========")
 	logs.Println("=========== 初始化产品类型 =========")

+ 0 - 6
models/Warning/Warning.go

@@ -229,9 +229,6 @@ func Read_Warning(T_pid int, T_tp, T_name string, T_handle int, Time_start_ stri
 	var map_r []Warning
 	var map_r []Warning
 	qs := o.QueryTable(new(Warning))
 	qs := o.QueryTable(new(Warning))
 	var offset int64
 	var offset int64
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {
@@ -354,9 +351,6 @@ func Read_Warning_Backups(T_pid int, T_year string, T_month string, T_tp, T_name
 	Wtab := "warning_" + T_year + "_" + T_month
 	Wtab := "warning_" + T_year + "_" + T_month
 
 
 	var offset int
 	var offset int
-	if page_z == 0 {
-		page_z = conf.Page_size
-	}
 	if page <= 1 {
 	if page <= 1 {
 		offset = 0
 		offset = 0
 	} else {
 	} else {

+ 11 - 0
models/SplitString.go → models/tools.go

@@ -33,3 +33,14 @@ func SplitStringToIntIds(str string, prefix string) (r []int) {
 	}
 	}
 	return r
 	return r
 }
 }
+
+func IntIdsDistinct(Ids []int) (result []int) {
+	distinctMap := make(map[int]int, len(Ids))
+	for _, Id := range Ids {
+		if _, ok := distinctMap[Id]; !ok {
+			distinctMap[Id] = 1
+			result = append(result, Id)
+		}
+	}
+	return result
+}

+ 5 - 7
routers/v3.go

@@ -14,17 +14,15 @@ func init() {
 			beego.NSRouter("/List", &controllers.DeviceController{}, "*:Device_List"), // 设备列表
 			beego.NSRouter("/List", &controllers.DeviceController{}, "*:Device_List"), // 设备列表
 			beego.NSRouter("/Add", &controllers.DeviceController{}, "*:Device_Add"),   // 添加设备
 			beego.NSRouter("/Add", &controllers.DeviceController{}, "*:Device_Add"),   // 添加设备
 			//beego.NSRouter("/Del", &controllers.DeviceController{}, "*:Device_Del"),                                          // 删除设备
 			//beego.NSRouter("/Del", &controllers.DeviceController{}, "*:Device_Del"),                                          // 删除设备
-			beego.NSRouter("/Edit", &controllers.DeviceController{}, "*:Device_Edit"),                                        // 修改设备
-			beego.NSRouter("/RestartShutdown", &controllers.DeviceController{}, "*:Device_RestartShutdown"),                  // 重启/关机
+			beego.NSRouter("/Edit", &controllers.DeviceController{}, "*:Device_Edit"),                       // 修改设备
+			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_List", &controllers.DeviceController{}, "*:Device_Parameter_List"),                    // 设备参数列表
 			beego.NSRouter("/Parameter_Pu", &controllers.DeviceController{}, "*:Device_Parameter_Pu"),                        // 修改设备参数
 			beego.NSRouter("/Parameter_Pu", &controllers.DeviceController{}, "*:Device_Parameter_Pu"),                        // 修改设备参数
 			beego.NSRouter("/Device_Parameter_Del_Device", &controllers.DeviceController{}, "*:Device_Parameter_Del_Device"), // 删除此设备
 			beego.NSRouter("/Device_Parameter_Del_Device", &controllers.DeviceController{}, "*:Device_Parameter_Del_Device"), // 删除此设备
 			// 设备日志
 			// 设备日志
-			beego.NSRouter("/Log", &controllers.DeviceController{}, "*:DeviceLogs"), // 获取未读消息
-
-			// 修改设备参数
-			beego.NSRouter("/Pu_DeviceParameter_T_l_p", &controllers.DeviceController{}, "*:Pu_DeviceParameter_T_type"),  // 设置设备参数
-			beego.NSRouter("/Pu_DeviceParameter_T_give", &controllers.DeviceController{}, "*:Pu_DeviceParameter_T_give"), // 设备是否弃用
+			beego.NSRouter("/Log", &controllers.DeviceController{}, "*:DeviceLogs"), // 日志
 
 
 			// 设备任务
 			// 设备任务
 			beego.NSRouter("/DeviceTask_List", &controllers.DeviceController{}, "*:DeviceTask_List"), // 任务列表
 			beego.NSRouter("/DeviceTask_List", &controllers.DeviceController{}, "*:DeviceTask_List"), // 任务列表