Prechádzať zdrojové kódy

add:用户名可修改、弃用设备报禁管理

zoie 3 mesiacov pred
rodič
commit
c89a64afbb
4 zmenil súbory, kde vykonal 49 pridanie a 42 odobranie
  1. 0 1
      Nats/Nats.go
  2. 12 2
      controllers/User.go
  3. 29 29
      controllers/Warning.go
  4. 8 10
      models/Warning/Warning.go

+ 0 - 1
Nats/Nats.go

@@ -571,5 +571,4 @@ func NatsInit() {
 		b, _ := msgpack.Marshal(&t_R)
 		_ = lib.Nats.Publish(m.Reply, b)
 	})
-
 }

+ 12 - 2
controllers/User.go

@@ -948,6 +948,7 @@ func (c *UserController) Admin_Edit() {
 	}
 
 	T_power, T_power_err := c.GetInt("T_power")
+	T_user := c.GetString("T_user")
 	T_name := c.GetString("T_name")
 	T_pass := c.GetString("T_pass")
 	T_phone := c.GetString("T_phone")
@@ -962,7 +963,16 @@ func (c *UserController) Admin_Edit() {
 		c.ServeJSON()
 		return
 	}
-
+	if len(T_user) > 0 {
+		var admin Account.Admin
+		admin, err = Account.Read_Admin_T_user(T_user)
+		if err == nil && admin.T_uuid != T_uuid {
+			c.Data["json"] = lib.JSONS{Code: 302, Msg: "用户名重复!"}
+			c.ServeJSON()
+			return
+		}
+		r.T_user = T_user
+	}
 	if len(T_name) > 0 {
 		r.T_name = T_name
 	}
@@ -979,7 +989,7 @@ func (c *UserController) Admin_Edit() {
 		r.T_wx = T_wx
 	}
 
-	is := Account.Update_Admin(r, "T_power", "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
+	is := Account.Update_Admin(r, "T_user", "T_power", "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.ServeJSON()

+ 29 - 29
controllers/Warning.go

@@ -541,7 +541,7 @@ func (c *DeviceController) DeviceWarning_Post() {
 	T_Text := c.GetString("T_Text")
 	T_time := c.GetString("T_time")
 	T_history, _ := c.GetInt("T_history") // TODO 后期废弃
-	if len(T_time) == 0 && conf.UseNewWarningQuery {
+	if len(T_time) == 0 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误"}
 		c.ServeJSON()
 		return
@@ -560,8 +560,8 @@ 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 && err.Error() != "<QuerySeter> no row found"{
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		if err != nil && err.Error() != "<QuerySeter> no row found" {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 			c.ServeJSON()
 			return
 		}
@@ -574,20 +574,18 @@ func (c *DeviceController) DeviceWarning_Post() {
 			return
 		}
 
-
 		warning = Warning.Read_Warning_ById(int64(id))
 		if warning.Id > 0 {
 			warning.T_Text = T_Text
 			warning.T_State = 2
 			warning.UpdateTime = time.Now()
 			if is := Warning.Update_Warning(warning, "T_Text", "T_State", "UpdateTime"); !is {
-				c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+				c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 				c.ServeJSON()
 				return
 			}
 		}
 
-
 	} else {
 		// 使用新的查询方式后 warning表不做更新
 
@@ -609,7 +607,7 @@ func (c *DeviceController) DeviceWarning_Post() {
 		Wtab += "_" + T_year + "_" + T_month
 		warningBackups, err := Warning.Read_Warning_ById_Backups(id, T_year, T_month)
 		if err != nil && err.Error() != "<QuerySeter> no row found" {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 			c.ServeJSON()
 			return
 		}
@@ -640,7 +638,7 @@ func (c *DeviceController) DeviceWarning_Del() {
 	id, _ := c.GetInt("T_id")
 	T_time := c.GetString("T_time")
 	T_history, _ := c.GetInt("T_history") // TODO 后期废弃
-	if len(T_time) == 0 && conf.UseNewWarningQuery {
+	if len(T_time) == 0 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误"}
 		c.ServeJSON()
 		return
@@ -658,19 +656,22 @@ func (c *DeviceController) DeviceWarning_Del() {
 		T_year, T_month = date.Format("2006"), date.Format("01")
 		Wtab += "_" + T_year + "_" + T_month
 
-		warning, err = Warning.Read_Warning_ById_Backups(id, T_year, T_month)
-		if err != nil {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		warningBackups, err := Warning.Read_Warning_ById_Backups(id, T_year, T_month)
+		if err != nil && err.Error() != "<QuerySeter> no row found" {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 			c.ServeJSON()
 			return
 		}
-		warning.T_State = 0
-		warning.UpdateTime = time.Now()
-		if is := Warning.Update_Warning_Backups(warning, T_year, T_month); !is {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
-			c.ServeJSON()
-			return
+		if warningBackups.Id > 0 {
+			warning.T_State = 0
+			warning.UpdateTime = time.Now()
+			if is := Warning.Update_Warning_Backups(warning, T_year, T_month); !is {
+				c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+				c.ServeJSON()
+				return
+			}
 		}
+
 		warning = Warning.Read_Warning_ById(int64(id))
 		if warning.Id > 0 {
 			warning.T_State = 0
@@ -681,25 +682,24 @@ func (c *DeviceController) DeviceWarning_Del() {
 			}
 		}
 	} else {
+		// 删除主表
 		warning = Warning.Read_Warning_ById(int64(id))
 		if warning.Id > 0 {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
-			c.ServeJSON()
-			return
-		}
-		warning.T_State = 0
-		if is := Warning.Update_Warning(warning, "T_State"); !is {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
-			c.ServeJSON()
-			return
+			warning.T_State = 0
+			if is := Warning.Update_Warning(warning, "T_State"); !is {
+				c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+				c.ServeJSON()
+				return
+			}
 		}
 
-		date := warning.T_Ut
+		// 删除分表
+		date, err := time.Parse("2006-01-02 15:04:05", T_time)
 		T_year, T_month = date.Format("2006"), date.Format("01")
 		Wtab += "_" + T_year + "_" + T_month
 		warningBackups, err := Warning.Read_Warning_ById_Backups(id, T_year, T_month)
 		if err != nil && err.Error() != "<QuerySeter> no row found" {
-			c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
 			c.ServeJSON()
 			return
 		}
@@ -707,7 +707,7 @@ func (c *DeviceController) DeviceWarning_Del() {
 			warningBackups.T_State = 0
 			warningBackups.UpdateTime = time.Now()
 			if is := Warning.Update_Warning_Backups(warningBackups, T_year, T_month); !is {
-				c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
+				c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
 				c.ServeJSON()
 				return
 			}

+ 8 - 10
models/Warning/Warning.go

@@ -817,13 +817,11 @@ func Read_Warning_ALL_T_State_Count2(T_pid int, T_pids []int, T_handle int, bind
 	return cnt
 }
 
-// 用户首页统计,使用gorm查询
+// 用户首页统计(查询最近40天),使用gorm查询
 func Read_Warning_ALL_T_State_Count(T_pid int, T_pids []int, T_handle int, bindSN []string, T_Warning string, Is_Today bool) (cnt int64) {
 
 	tableName := "warning"
-	if conf.UseNewWarningQuery {
-		tableName = fmt.Sprintf("warning_%s_%s", time.Now().Format("2006"), time.Now().Format("01"))
-	}
+
 	gormDB := db.DB.Table(tableName)
 	daysAgo40 := time.Now().AddDate(0, 0, -40).Format("2006-01-02")
 
@@ -1213,6 +1211,7 @@ func GormReadWarningListScopes(T_pid int, bindSN, tpList []string, T_name string
 		if T_pid > 0 {
 			db.Where("t_pid = ?", T_pid)
 		}
+
 		if T_abandon == 1 {
 			// 弃用
 			if len(abandonSN) > 0 {
@@ -1221,8 +1220,7 @@ func GormReadWarningListScopes(T_pid int, bindSN, tpList []string, T_name string
 				db.Where("1=0")
 				return db
 			}
-
-		} else {
+		} else if conf.UseNewWarningQuery {
 			if len(bindSN) > 0 {
 				// 将绑定sn内非弃用sn筛选出来
 				bindSNWithOutAbandon := lib.FindUniqueElements(bindSN, abandonSN)
@@ -1297,9 +1295,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
@@ -1419,7 +1417,7 @@ func GormReadAdminWarningListScopes(admin Account.Admin, T_tp []string, T_name s
 				db.Where("1=0")
 				return db
 			}
-		} else {
+		} else if conf.UseNewWarningQuery {
 			if len(abandonSN) > 0 {
 				db.Where("t_sn not in (?)", abandonSN)
 			}