Pārlūkot izejas kodu

add:弃用设备管理

zoie 3 mēneši atpakaļ
vecāks
revīzija
da3e944b37

+ 4 - 2
Nats/Nats.go

@@ -30,7 +30,9 @@ func init() {
 	}
 	logs.Info("nats OK!")
 
-	go NatsInit()
+	if conf.RunMode == "prod" {
+		go NatsInit()
+	}
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 		"redisCache_NatsServer", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
@@ -559,7 +561,7 @@ func NatsInit() {
 			_ = lib.Nats.Publish(m.Reply, b)
 			return
 		}
-		deviceList, count := Device.Read_Device_List(&Account.Admin{T_pid: Company_r.Id}, []string{}, Company_r.Id, t_Req.Name, "", "", t_Req.Page, t_Req.Page_z)
+		deviceList, count := Device.Read_Device_List(&Account.Admin{T_pid: Company_r.Id}, []string{}, Company_r.Id, t_Req.Name, "", "", 0, t_Req.Page, t_Req.Page_z)
 
 		t_R.Code = 200
 		t_R.Msg = "ok"

+ 1 - 1
conf/app.conf

@@ -79,7 +79,7 @@ Weixin_Notify = "https://cold.coldbaozhida.com/api/WxPay/Notify"
 
 # 日志配置
 # 0-控制台输出 1-文件输出 2-文件和控制台输出
-adapter_type = 1
+adapter_type = 0
 # 文件最多保存多少天
 maxdays = 7
 # 日志级别 (0-紧急 1-报警 2-严重错误 3-错误 4-警告 5-注意 6-信息 7-调试)

+ 3 - 1
controllers/Data.go

@@ -105,6 +105,8 @@ func (c *DataController) Device_Sensor_List() {
 		T_MapShow = 0
 	}
 
+	T_abandon, _ := c.GetInt("T_abandon")
+
 	var cnt int64
 	//Device.Read_DeviceSensorParameter_All_Map("", 0)
 	bindSN, err := Account.Read_UserDevice_List(c.Admin_r)
@@ -113,7 +115,7 @@ func (c *DataController) Device_Sensor_List() {
 		c.ServeJSON()
 		return
 	}
-	r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_List_For_Data(bindSN, c.T_pid, T_name, T_Class_id, T_type, T_RealTime, T_MapShow, page, page_z)
+	r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_List_For_Data(bindSN, c.T_pid, T_name, T_Class_id, T_type, T_RealTime, T_MapShow, T_abandon, page, page_z)
 
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	r_jsons.Page = page

+ 10 - 2
controllers/Device.go

@@ -66,6 +66,7 @@ func (c *DeviceController) Device_List() {
 	}
 
 	Name := c.GetString("T_name")
+	T_abandon, _ := c.GetInt("T_abandon")
 	T_online := c.GetString("T_online")
 	T_monitor := c.GetString("T_monitor")
 	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
@@ -75,7 +76,7 @@ func (c *DeviceController) Device_List() {
 		return
 	}
 
-	r_jsons.Device_lite, r_jsons.Num = Device.Read_Device_List(c.Admin_r, bindSN, c.T_pid, Name, T_monitor, T_online, page, page_z)
+	r_jsons.Device_lite, r_jsons.Num = Device.Read_Device_List(c.Admin_r, bindSN, c.T_pid, Name, T_monitor, T_online, T_abandon, page, page_z)
 
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
@@ -198,6 +199,11 @@ func (c *DeviceController) Device_Edit() {
 	T_State, T_State_err := c.GetInt("T_State")
 	if T_State_err == nil {
 		Device_r.T_State = T_State
+		if T_State == 0 {
+			Device_r.T_abandonTime = time.Now()
+			clos = append(clos, "T_abandonTime")
+
+		}
 		clos = append(clos, "T_State")
 	}
 
@@ -1064,13 +1070,15 @@ func (c *DeviceController) DeviceSensor_Manage_List() {
 		T_sort = -1
 	}
 
+	T_abandon, _ := c.GetInt("T_abandon")
+
 	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 		c.ServeJSON()
 		return
 	}
-	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorManageList(c.Admin_r, bindSN, 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, bindSN, c.T_pid, T_name, T_calss_id, T_en, T_free, T_datashow, T_sort, T_abandon, page, page_z)
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 

+ 1 - 1
controllers/User.go

@@ -1908,7 +1908,7 @@ func (c *UserController) UserDeviceBind_List() {
 		return
 	}
 
-	r_jsons.Data, r_jsons.Num = Device.Read_Device_List(&c.Admin_r, bindSN, c.T_pid, T_name, "", "", page, page_z)
+	r_jsons.Data, r_jsons.Num = Device.Read_Device_List(&c.Admin_r, bindSN, c.T_pid, T_name, "", "", -1, page, page_z)
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
 

+ 32 - 12
controllers/Warning.go

@@ -141,6 +141,7 @@ func (c *DeviceController) DeviceWarning_List2() {
 
 	T_admin, _ := c.GetInt("T_admin")
 	T_history, _ := c.GetInt("T_history")
+	T_abandon, _ := c.GetInt("T_abandon") // 1 弃用设备
 	if len(Time_start) == 0 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "开始时间不能为空!"}
 		c.ServeJSON()
@@ -165,24 +166,29 @@ func (c *DeviceController) DeviceWarning_List2() {
 			tpList = lib.SplitStringIds(power.T_warning, "W")
 		}
 	}
-	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, T_admin, T_history)
+	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, T_admin, T_history, T_abandon)
 	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 		c.ServeJSON()
 		return
 	}
-
+	// 查询弃用设备
+	abandonDeviceList, _ := Device.Read_Device_List_ByT_State(bindSN, c.T_pid, 0)
+	abandonSN := make([]string, 0)
+	for _, r := range abandonDeviceList {
+		abandonSN = append(abandonSN, r.T_sn)
+	}
 	// 管理员界面
 	if T_admin == 1 {
-		// 获取最新
-		r_jsons.Data, r_jsons.Num = Warning.Gorm_Read_Admin_Warning_List(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, page, page_z, countRedisKey)
+		// 获取最新 获取绑定的sn 如果未绑定则获取全部
+		r_jsons.Data, r_jsons.Num = Warning.Gorm_Read_Admin_Warning_List(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN, page, page_z, countRedisKey)
 		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
 		c.ServeJSON()
 		return
 	}
 
-	r_jsons.Data, r_jsons.Num = Warning.Gorm_Read_Warning_List(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, page, page_z, countRedisKey)
+	r_jsons.Data, r_jsons.Num = Warning.Gorm_Read_Warning_List(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN, page, page_z, countRedisKey)
 
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
@@ -207,6 +213,7 @@ func (c *DeviceController) DeviceWarning_List_Sse() {
 	T_handle, _ := c.GetInt("T_handle")
 
 	T_admin, _ := c.GetInt("T_admin")
+	T_abandon, _ := c.GetInt("T_abandon") // 1 弃用设备
 	tpCount := Warning.Read_WarningType_Count()
 	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
 	if err != nil {
@@ -214,6 +221,12 @@ func (c *DeviceController) DeviceWarning_List_Sse() {
 		c.ServeJSON()
 		return
 	}
+	// 查询弃用设备
+	abandonDeviceList, _ := Device.Read_Device_List_ByT_State(bindSN, c.T_pid, 0)
+	abandonSN := make([]string, 0)
+	for _, r := range abandonDeviceList {
+		abandonSN = append(abandonSN, r.T_sn)
+	}
 	var tpList []string
 	if len(T_tp) > 0 {
 		tpList = lib.SplitStringIds(T_tp, "T")
@@ -227,7 +240,7 @@ func (c *DeviceController) DeviceWarning_List_Sse() {
 			tpList = lib.SplitStringIds(power.T_warning, "W")
 		}
 	}
-	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, T_admin, 0)
+	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, T_admin, 0, T_abandon)
 	tableNames := Warning.GenerateWarningTableNames(Time_start, Time_end)
 
 	// 设置响应头
@@ -239,7 +252,7 @@ func (c *DeviceController) DeviceWarning_List_Sse() {
 	tableCount := make(map[string]int64)
 	// 管理员界面
 	if T_admin == 1 {
-		gormReadWarningListScopes := Warning.GormReadAdminWarningListScopes(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end)
+		gormReadWarningListScopes := Warning.GormReadAdminWarningListScopes(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN)
 		cnt, tableCount, err = Warning.Redis_WarningCount_GetOne(c.Admin_r.Id, countRedisKey)
 
 		offset := (page - 1) * page_z
@@ -298,7 +311,7 @@ func (c *DeviceController) DeviceWarning_List_Sse() {
 		return
 	}
 	//从redis获取报警统计数量
-	gormReadWarningListScopes := Warning.GormReadWarningListScopes(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end)
+	gormReadWarningListScopes := Warning.GormReadWarningListScopes(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN)
 	cnt, tableCount, err = Warning.Redis_WarningCount_GetOne(c.T_pid, countRedisKey)
 
 	offset := (page - 1) * page_z
@@ -547,7 +560,7 @@ func (c *DeviceController) DeviceWarning_Post() {
 		T_year, T_month = date.Format("2006"), date.Format("01")
 		Wtab += "_" + T_year + "_" + T_month
 		warning, err = Warning.Read_Warning_ById_Backups(id, T_year, T_month)
-		if err != nil {
+		if err != nil && err.Error() != "<QuerySeter> no row found" {
 			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
 			c.ServeJSON()
 			return
@@ -853,6 +866,7 @@ func (c *DeviceController) DeviceWarning_Data_Excel2() {
 		return
 	}
 	T_admin, _ := c.GetInt("T_admin")
+	T_abandon, _ := c.GetInt("T_abandon") // 1 弃用设备
 	tpCount := Warning.Read_WarningType_Count()
 	var tpList []string
 	if len(T_tp) > 0 {
@@ -867,7 +881,7 @@ func (c *DeviceController) DeviceWarning_Data_Excel2() {
 			tpList = lib.SplitStringIds(power.T_warning, "W")
 		}
 	}
-	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, 0)
+	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, 0, T_abandon)
 
 	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
 	if err != nil {
@@ -875,6 +889,12 @@ func (c *DeviceController) DeviceWarning_Data_Excel2() {
 		c.ServeJSON()
 		return
 	}
+	// 查询弃用设备
+	abandonDeviceList, _ := Device.Read_Device_List_ByT_State(bindSN, c.T_pid, 0)
+	abandonSN := make([]string, 0)
+	for _, r := range abandonDeviceList {
+		abandonSN = append(abandonSN, r.T_sn)
+	}
 
 	var Device_data []Warning.Warning_R
 
@@ -882,11 +902,11 @@ func (c *DeviceController) DeviceWarning_Data_Excel2() {
 	if T_admin == 1 {
 		// 获取最新
 		//Device_data, _ = Warning.Gorm_Read_Admin_Warning_List(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
-		Device_data, _ = Warning.Gorm_Read_Admin_Warning_List_Excel(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
+		Device_data, _ = Warning.Gorm_Read_Admin_Warning_List_Excel(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN, 0, 9999, countRedisKey)
 	} else {
 		// 获取最新
 		//Device_data, _ = Warning.Gorm_Read_Warning_List(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
-		Device_data, _ = Warning.Gorm_Read_Warning_List_Excel(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
+		Device_data, _ = Warning.Gorm_Read_Warning_List_Excel(c.T_pid, bindSN, tpList, T_name, T_handle, Time_start, Time_end, T_abandon, abandonSN, 0, 9999, countRedisKey)
 	}
 
 	f := excelize.NewFile() // 设置单元格的值

+ 37 - 0
controllers/lib/lib.go

@@ -426,3 +426,40 @@ func GetDiffDays(t1, t2 time.Time) int {
 
 	return int(t1.Sub(t2).Hours() / 24)
 }
+
+func FindCommonElements(list1, list2 []string) []string {
+	// 使用 map 来存储第一个列表中的元素
+	elementMap := make(map[string]bool)
+	for _, item := range list1 {
+		elementMap[item] = true
+	}
+
+	// 查找第二个列表中与第一个列表相同的元素
+	var commonElements []string
+	for _, item := range list2 {
+		if elementMap[item] {
+			commonElements = append(commonElements, item)
+		}
+	}
+
+	return commonElements
+}
+
+// 查询仅存在于第一个列表数据
+func FindUniqueElements(list1, list2 []string) []string {
+	// 使用 map 来存储第二个列表中的元素
+	elementMap := make(map[string]bool)
+	for _, item := range list2 {
+		elementMap[item] = true
+	}
+
+	// 查找第一个列表中在第二个列表中不存在的元素
+	var uniqueElements []string
+	for _, item := range list1 {
+		if !elementMap[item] {
+			uniqueElements = append(uniqueElements, item)
+		}
+	}
+
+	return uniqueElements
+}

+ 66 - 15
models/Device/Device.go

@@ -27,6 +27,7 @@ type Device struct {
 	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_abandonTime     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关闭
 
@@ -58,6 +59,7 @@ type Device_R struct {
 	T_VerifyTime      string // 验证时间
 	T_CalibrationTime string // 校准时间
 	T_PatrolTime      string // 巡检时间
+	T_abandonTime     string // 弃用时间
 	T_ist             int    // 温度   1开启   2关闭
 	T_ish             int    // 湿度   1开启   2关闭
 	T_Dattery         int    // 电量
@@ -122,6 +124,9 @@ func DeviceToDevice_R(r Device) (t Device_R) {
 	if !r.T_PatrolTime.IsZero() {
 		t.T_PatrolTime = r.T_PatrolTime.Format("2006-01-02 15:04:05")
 	}
+	if !r.T_abandonTime.IsZero() {
+		t.T_abandonTime = r.T_abandonTime.Format("2006-01-02 15:04:05")
+	}
 
 	t.T_ist = r.T_ist
 	t.T_ish = r.T_ish
@@ -249,7 +254,7 @@ func Update_Device(r Device, cols ...string) bool {
 }
 
 // 获取列表
-func Read_Device_List(admin *Account.Admin, bindSN []string, T_pid int, T_name string, T_monitor string, T_online string, page int, page_z int) (r []Device_R, cnt int64) {
+func Read_Device_List(admin *Account.Admin, bindSN []string, T_pid int, T_name string, T_monitor string, T_online string, T_abandon int, page int, page_z int) (r []Device_R, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -268,22 +273,35 @@ func Read_Device_List(admin *Account.Admin, bindSN []string, T_pid int, T_name s
 	if len(bindSN) > 0 {
 		cond1 = cond1.And("T_sn__in", bindSN)
 	}
+	//T_abandon  1-查询弃用设备 -1-查询全部 其他-查询全部
+
+	if T_abandon == 1 {
+		cond1 = cond1.And("T_State", 0)
+	} else if T_abandon != -1 {
+		cond1 = cond1.And("T_State", 1)
+	}
 
 	// 非内部权限 - 不可查看屏蔽数据
-	if admin != nil && admin.T_pid > 0 {
-		if len(T_name) >= 16 {
-			cond1 = cond1.And("T_sn", T_name)
-		} else if len(T_name) > 0 && len(T_name) < 16 {
-			cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name)).And("T_State", 1)
-		} else {
-			cond1 = cond1.And("T_State", 1)
-		}
-	} else {
-		if len(T_name) >= 16 {
-			cond1 = cond1.And("T_sn", T_name)
-		} else if len(T_name) > 0 && len(T_name) < 16 {
-			cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name))
-		}
+	//if admin != nil && admin.T_pid > 0 {
+	//	if len(T_name) >= 16 {
+	//		cond1 = cond1.And("T_sn", T_name)
+	//	} else if len(T_name) > 0 && len(T_name) < 16 {
+	//		cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name)).And("T_State", 1)
+	//	} else {
+	//		cond1 = cond1.And("T_State", 1)
+	//	}
+	//} else {
+	//	if len(T_name) >= 16 {
+	//		cond1 = cond1.And("T_sn", T_name)
+	//	} else if len(T_name) > 0 && len(T_name) < 16 {
+	//		cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name))
+	//	}
+	//}
+
+	if len(T_name) >= 16 {
+		cond1 = cond1.And("T_sn", T_name)
+	} else if len(T_name) > 0 && len(T_name) < 16 {
+		cond1 = cond1.AndCond(cond.Or("T_sn__icontains", T_name).Or("T_devName__icontains", T_name))
 	}
 
 	// 0 未监控 1 监控  2 未知状态
@@ -474,3 +492,36 @@ func Read_User_Unbind_Device_List(admin *Account.Admin, bindSN []string, T_pid i
 
 	return r, cnt
 }
+
+func Read_Device_List_ByT_State(bindSN []string, T_pid int, T_State int) (r []Device, cnt int64) {
+
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+
+	qs := o.QueryTable(new(Device))
+
+	cond := orm.NewCondition()
+	cond1 := cond.And("T_pid", T_pid).And("T_State", T_State)
+
+	if len(bindSN) > 0 {
+		cond1 = cond1.And("T_sn__in", bindSN)
+	}
+
+	var rx []Device
+
+	var err error
+
+	cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	_, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("CreateTime").All(&rx)
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+	return rx, cnt
+}

+ 24 - 5
models/Device/DeviceSensor.go

@@ -964,7 +964,7 @@ func Read_DeviceSensorManageList1(admin_r *Account.Admin, bindSN []string, T_pid
 }
 
 // 使用联表查询
-func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, 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, bindSN []string, T_pid int, T_name string, T_calss_id, T_en, T_free, T_datashow, T_sort, T_abandon, page, page_z int) (DeviceSensor_p []DeviceSensor_P, cnt int64) {
 	o := orm.NewOrm()
 	var maps []DeviceSensor_P
 	var maps_z []orm2.ParamsList
@@ -982,7 +982,13 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, T_pid
 		sql_WHERE += fmt.Sprintf(" AND ds.t_sn in (%s)", lib.StringListToQuotesDotStr(bindSN))
 	}
 
-	if admin_r.T_pid > 0 {
+	//if admin_r.T_pid > 0 {
+	//	sql_WHERE += " AND ds.t__state = 1"
+	//}
+
+	if T_abandon == 1 {
+		sql_WHERE += " AND ds.t__state = 0"
+	} else {
 		sql_WHERE += " AND ds.t__state = 1"
 	}
 
@@ -1054,7 +1060,7 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, T_pid
 // 数据展示菜单下 传感器参数列表
 // 实时数据页面 温湿度异常数据往前排
 // 轨迹展示页面
-func Read_DeviceSensor_List_For_Data(bindSN []string, T_pid int, T_name string, T_Class_id, T_type, T_RealTime, T_MapShow int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+func Read_DeviceSensor_List_For_Data(bindSN []string, T_pid int, T_name string, T_Class_id, T_type, T_RealTime, T_MapShow, T_abandon int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 
@@ -1083,12 +1089,25 @@ func Read_DeviceSensor_List_For_Data(bindSN []string, T_pid int, T_name string,
 		cond1 = cond1.And("T_type", T_type)
 	}
 
+	if T_abandon == 1 {
+		cond1 = cond1.And("T_State", 0)
+	} else {
+		cond1 = cond1.And("T_State", 1)
+	}
+
+	//if len(T_name) >= 16 {
+	//	cond1 = cond1.And("T_sn", T_name)
+	//} else if len(T_name) > 0 && len(T_name) < 16 {
+	//	cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
+	//} else {
+	//	cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
+	//}
 	if len(T_name) >= 16 {
 		cond1 = cond1.And("T_sn", T_name)
 	} else if len(T_name) > 0 && len(T_name) < 16 {
-		cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
+		cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_datashow", 1)
 	} else {
-		cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
+		cond1 = cond1.And("T_datashow", 1)
 	}
 
 	if T_MapShow == 1 {

+ 57 - 20
models/Warning/Warning.go

@@ -1208,15 +1208,37 @@ func Read_Company_Warning_Backups(T_pids []int, T_year string, T_month string, T
 
 }
 
-func GormReadWarningListScopes(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string) func(db *gorm.DB) *gorm.DB {
+func GormReadWarningListScopes(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string) func(db *gorm.DB) *gorm.DB {
 	return func(db *gorm.DB) *gorm.DB {
-		if len(bindSN) > 0 {
-			db.Where("t_sn in (?)", bindSN)
-		}
-
 		if T_pid > 0 {
 			db.Where("t_pid = ?", T_pid)
 		}
+		if T_abandon == 1 {
+			// 弃用
+			if len(abandonSN) > 0 {
+				db.Where("t_sn in (?)", abandonSN)
+			} else {
+				db.Where("1=0")
+				return db
+			}
+
+		} else {
+			if len(bindSN) > 0 {
+				// 将绑定sn内非弃用sn筛选出来
+				bindSNWithOutAbandon := lib.FindUniqueElements(bindSN, abandonSN)
+				if len(bindSNWithOutAbandon) > 0 {
+					db.Where("t_sn in (?)", bindSNWithOutAbandon)
+				} else {
+					db.Where("1=0")
+					return db
+				}
+			} else {
+				if len(abandonSN) > 0 {
+					db.Where("t_sn not in (?)", abandonSN)
+				}
+			}
+		}
+
 		if len(tpList) > 0 {
 			min, max, is := checkStringListContinuous(tpList)
 			if is {
@@ -1254,13 +1276,13 @@ func GormReadWarningListScopes(T_pid int, bindSN, tpList []string, T_name string
 }
 
 // 获取列表
-func Gorm_Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
+func Gorm_Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string, page int, page_z int,
 	countRedisKey string) (r []Warning_R, cnt int64) {
 	tableNames := GenerateWarningTableNames(Time_start_, Time_end_)
 	var err error
 	var warnings []Warning
 	tableCount := make(map[string]int64)
-	gormReadWarningListScopes := GormReadWarningListScopes(T_pid, bindSN, tpList, T_name, T_handle, Time_start_, Time_end_)
+	gormReadWarningListScopes := GormReadWarningListScopes(T_pid, bindSN, tpList, T_name, T_handle, Time_start_, Time_end_, T_abandon, abandonSN)
 	// 从redis获取报警统计数量
 	cnt, tableCount, err = Redis_WarningCount_GetOne(T_pid, countRedisKey)
 	if err != nil {
@@ -1275,9 +1297,9 @@ func Gorm_Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T
 		Redis_WarningCount_Set(T_pid, countRedisKey, cnt, tableCount)
 	}
 
-	if cnt == 0 {
-		return r, 0
-	}
+	//if cnt == 0 {
+	//	return r, 0
+	//}
 	if page_z == 9999 {
 		for _, tableName := range tableNames {
 			var tableWarning []Warning
@@ -1322,9 +1344,8 @@ func Gorm_Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T
 			remaining -= int(count)
 			continue
 		}
-
-		tableDB.Scopes(gormReadWarningListScopes).
-			Order("t__ut desc").Offset(remaining).Limit(page_z - len(warnings)).Find(&tableWarning)
+		tableDB2 := db.DB.Table(tableName)
+		tableDB2.Scopes(gormReadWarningListScopes).Order("t__ut desc").Offset(remaining).Limit(page_z - len(warnings)).Find(&tableWarning)
 
 		warnings = append(warnings, tableWarning...)
 		if len(warnings) >= page_z {
@@ -1338,10 +1359,10 @@ func Gorm_Read_Warning_List(T_pid int, bindSN, tpList []string, T_name string, T
 	return r, cnt
 }
 
-func Gorm_Read_Warning_List_Excel(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
+func Gorm_Read_Warning_List_Excel(T_pid int, bindSN, tpList []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string, page int, page_z int,
 	countRedisKey string) (r []Warning_R, cnt int64) {
 	tableNames := GenerateWarningTableNames(Time_start_, Time_end_)
-	gormReadWarningListScopes := GormReadWarningListScopes(T_pid, bindSN, tpList, T_name, T_handle, Time_start_, Time_end_)
+	gormReadWarningListScopes := GormReadWarningListScopes(T_pid, bindSN, tpList, T_name, T_handle, Time_start_, Time_end_, T_abandon, abandonSN)
 
 	var warnings []Warning
 	var wg sync.WaitGroup
@@ -1382,12 +1403,28 @@ func Gorm_Read_Warning_List_Excel(T_pid int, bindSN, tpList []string, T_name str
 
 }
 
-func GormReadAdminWarningListScopes(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string) func(db *gorm.DB) *gorm.DB {
+func GormReadAdminWarningListScopes(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string) func(db *gorm.DB) *gorm.DB {
 	return func(db *gorm.DB) *gorm.DB {
+
 		if admin.T_pids != "*" && len(admin.T_pids) > 0 {
 			list := lib.SplitStringIds(admin.T_pids, "P")
 			db.Where("t_pid in (?)", list)
 		}
+
+		if T_abandon == 1 {
+			// 查询弃用设备
+			if len(abandonSN) > 0 {
+				db.Where("t_sn in (?)", abandonSN)
+			} else {
+				db.Where("1=0")
+				return db
+			}
+		} else {
+			if len(abandonSN) > 0 {
+				db.Where("t_sn not in (?)", abandonSN)
+			}
+		}
+
 		if len(T_tp) > 0 {
 			min, max, is := checkStringListContinuous(T_tp)
 			if is {
@@ -1426,13 +1463,13 @@ func GormReadAdminWarningListScopes(admin Account.Admin, T_tp []string, T_name s
 }
 
 // 管理员报警列表
-func Gorm_Read_Admin_Warning_List(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
+func Gorm_Read_Admin_Warning_List(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string, page int, page_z int,
 	countRedisKey string) (r []Warning_R, cnt int64) {
 
 	if len(admin.T_pids) == 0 {
 		return r, cnt
 	}
-	gormReadAdminWarningListScopes := GormReadAdminWarningListScopes(admin, T_tp, T_name, T_handle, Time_start_, Time_end_)
+	gormReadAdminWarningListScopes := GormReadAdminWarningListScopes(admin, T_tp, T_name, T_handle, Time_start_, Time_end_, T_abandon, abandonSN)
 	tableNames := GenerateWarningTableNames(Time_start_, Time_end_)
 	var err error
 	var warnings []Warning
@@ -1495,13 +1532,13 @@ func Gorm_Read_Admin_Warning_List(admin Account.Admin, T_tp []string, T_name str
 	}
 	return r, cnt
 }
-func Gorm_Read_Admin_Warning_List_Excel(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, page int, page_z int,
+func Gorm_Read_Admin_Warning_List_Excel(admin Account.Admin, T_tp []string, T_name string, T_handle int, Time_start_ string, Time_end_ string, T_abandon int, abandonSN []string, page int, page_z int,
 	countRedisKey string) (r []Warning_R, cnt int64) {
 
 	if len(admin.T_pids) == 0 {
 		return r, cnt
 	}
-	gormReadAdminWarningListScopes := GormReadAdminWarningListScopes(admin, T_tp, T_name, T_handle, Time_start_, Time_end_)
+	gormReadAdminWarningListScopes := GormReadAdminWarningListScopes(admin, T_tp, T_name, T_handle, Time_start_, Time_end_, T_abandon, abandonSN)
 	tableNames := GenerateWarningTableNames(Time_start_, Time_end_)
 	var warnings []Warning
 	var wg sync.WaitGroup