Browse Source

2023-11-06

zoie 1 year ago
parent
commit
6fc1deae20

+ 3 - 3
Nats/Nats.go

@@ -133,15 +133,15 @@ func NatsInit() {
 			return
 		}
 
-		Task.Add_TaskLogs_T("nats", t_Req.T_task_id, "任务管理", "修改", t_R)
-		System.Add_UserLogs_T("nats", "任务管理", "修改", t_R)
-
 		t_R.Code = 200
 		t_R.Msg = "ok"
 
 		b, _ := msgpack.Marshal(&t_R)
 		_ = lib.Nats.Publish(m.Reply, b)
 
+		Task.Add_TaskLogs_T("nats", t_Req.T_task_id, "任务管理", "修改", t_Req)
+		System.Add_UserLogs_T("nats", "任务管理", "修改", t_Req)
+
 	})
 
 	_, _ = lib.Nats.QueueSubscribe("ColdVerify_Server_Read_Task", "Read_Task", func(m *nats.Msg) {

+ 4 - 19
controllers/Certificate.go

@@ -38,7 +38,6 @@ func (c *CertificateController) List() {
 	T_layout_no := c.GetString("T_layout_no")
 	Time_start := c.GetString("Time_start")
 	Time_end := c.GetString("Time_end")
-	T_layout_no_sort, _ := c.GetInt("T_layout_no_sort")       // 1 升序 2 降序
 	T_release_time_sort, _ := c.GetInt("T_release_time_sort") // 1 升序 2 降序
 	T_failure_time_sort, _ := c.GetInt("T_failure_time_sort") // 1 升序 2 降序
 
@@ -55,7 +54,7 @@ func (c *CertificateController) List() {
 	}
 
 	var cnt int
-	List, cnt := Certificate.Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end, T_layout_no_sort, T_release_time_sort, T_failure_time_sort, page, page_z)
+	List, cnt := Certificate.Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end, T_release_time_sort, T_failure_time_sort, page, page_z)
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	r_jsons.List = List
 	r_jsons.Page = page
@@ -113,12 +112,10 @@ func (c *CertificateController) Add() {
 	}
 
 	T_sn := c.GetString("T_sn")
-	T_layout_no := c.GetString("T_layout_no")
 
 	var_ := Certificate.Certificate{
-		T_sn:        T_sn,
-		T_layout_no: T_layout_no,
-		T_State:     1,
+		T_sn:    T_sn,
+		T_State: 1,
 	}
 
 	if _, is := Certificate.Read_Certificate(T_sn); is {
@@ -126,11 +123,6 @@ func (c *CertificateController) Add() {
 		c.ServeJSON()
 		return
 	}
-	if _, is := Certificate.Read_Certificate_ByT_layout_no(T_layout_no); is {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号重复!"}
-		c.ServeJSON()
-		return
-	}
 
 	Id, is := Certificate.Add_Certificate(var_)
 	if !is {
@@ -170,21 +162,14 @@ func (c *CertificateController) Edit() {
 	}
 
 	T_sn := c.GetString("T_sn")
-	T_layout_no := c.GetString("T_layout_no")
 
 	if _, is = Certificate.Read_Certificate(T_sn); is && r.T_sn != T_sn {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "设备编号重复!"}
 		c.ServeJSON()
 		return
 	}
-	if _, is = Certificate.Read_Certificate_ByT_layout_no(T_layout_no); is && r.T_layout_no != T_layout_no {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号重复!"}
-		c.ServeJSON()
-		return
-	}
 	r.T_sn = T_sn
-	r.T_layout_no = T_layout_no
-	is = Certificate.Update_Certificate(r, "T_sn", "T_layout_no")
+	is = Certificate.Update_Certificate(r, "T_sn")
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
 		c.ServeJSON()

+ 1 - 1
controllers/Device.go

@@ -200,7 +200,7 @@ func (c *DeviceController) Device_Class() {
 	for _, v := range DeviceList {
 		Device_r, _ := Device.Read_Device(v.T_sn)
 		Device_r.T_note_file_num = Device.Read_DeviceSensorData_List_z(v.T_sn, r.CreateTime.Format("2006-01-02 15:04:05"))
-		r_jsons.List = append(r_jsons.List, Device_r)
+		r_jsons.List = append(r_jsons.List, Device.DeviceToDevice_R(Device_r, v.T_id))
 	}
 	page_size := math.Ceil(float64(cnt) / float64(page_z))
 	r_jsons.Page = page

+ 109 - 2
controllers/DeviceClass.go

@@ -239,8 +239,8 @@ func (c *DeviceClassController) List_List() {
 	return
 }
 
-// 添加-
-func (c *DeviceClassController) List_Add() {
+// 添加- 旧功能
+func (c *DeviceClassController) List_Add1() {
 	// 验证登录 User_is, User_r
 	User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
 	if !User_is {
@@ -384,6 +384,106 @@ func (c *DeviceClassController) List_Add() {
 	c.ServeJSON()
 	return
 }
+func (c *DeviceClassController) List_Add() {
+	// 验证登录 User_is, User_r
+	User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
+	if !User_is {
+		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
+		c.ServeJSON()
+		return
+	}
+
+	T_class, _ := c.GetInt("T_class")
+	T_sn_id_list := c.GetString("T_sn_id_list")
+
+	list := strings.Split(strings.TrimRight(T_sn_id_list, "|"), "|")
+	T_remark := c.GetString("T_remark")
+
+	_, is := Device.Read_DeviceClass_ById(T_class)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误"}
+		c.ServeJSON()
+		return
+	}
+
+	var successNum int // 成功数量
+	errList := []string{}
+	errList2 := []string{}
+	succesId := []string{}
+	for _, sn_id := range list {
+		T_sn := strings.Split(sn_id, ",")[0]
+		T_id := strings.Split(sn_id, ",")[1]
+		// 判断是否已存在sn
+		dc, is := Device.Read_DeviceClassList_T_class_T_sn(T_class, T_sn)
+		// 添加的id和数据库已存在id相同
+		if is && dc.T_id == T_id {
+			successNum += 1
+			continue
+		}
+		// 添加的id和数据库已存在id不同
+		if is && dc.T_id != T_id {
+			dc.T_id = T_id
+			dc.T_remark = T_remark
+			if !Device.Update_DeviceClassList(dc, "T_id", "T_remark") {
+				errList = append(errList, sn_id)
+			} else {
+				successNum += 1
+			}
+			continue
+		}
+
+		_, is = Device.Read_DeviceClassList_T_class_T_id(T_class, T_id)
+		if is {
+			errList2 = append(errList2, sn_id)
+			continue
+		}
+
+		var pdf Certificate.CertificatePdf
+		pdfList, _ := Certificate.Read_CertificatePdf_Newest(T_sn)
+		if len(pdfList) > 0 {
+			pdf = pdfList[0]
+		}
+
+		var_ := Device.DeviceClassList{
+			T_class:        T_class,
+			T_id:           T_id,
+			T_sn:           T_sn,
+			T_failure_time: pdf.T_failure_time,
+			T_pdf:          pdf.T_pdf,
+			T_remark:       T_remark,
+			T_State:        1,
+		}
+
+		_, is = Device.Add_DeviceClassList(var_)
+		if !is {
+			errList = append(errList, sn_id)
+			continue
+		}
+		successNum += 1
+		succesId = append(succesId, sn_id)
+		System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "添加", var_)
+	}
+
+	if len(errList) == 0 && len(errList2) == 0 {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: successNum}
+		c.ServeJSON()
+		return
+	}
+	var errStr string
+	if len(errList2) > 0 {
+		errStr += strings.Join(errList2, ",") + "编号已存在"
+	}
+	if len(errList) > 0 {
+		if len(errStr) > 0 {
+			errStr += ","
+		}
+		errStr += strings.Join(errList, ",") + "添加失败"
+	}
+
+	c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
+	c.ServeJSON()
+	return
+}
 
 // 修改-
 func (c *DeviceClassController) List_Up() {
@@ -419,6 +519,13 @@ func (c *DeviceClassController) List_Up() {
 		return
 	}
 
+	_, is = Device.Read_DeviceClassList_T_class_T_id(r.T_class, T_id)
+	if is && T_id != r.T_id {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: T_id + "编号已存在!"}
+		c.ServeJSON()
+		return
+	}
+
 	if len(T_id) > 0 {
 		r.T_id = T_id
 	}

+ 1 - 7
models/Certificate/Certificate.go

@@ -130,14 +130,13 @@ func Update_Certificate(m Certificate, cols ...string) bool {
 type Certificate_ struct {
 	Id             int    `orm:"column(ID)"`
 	T_sn           string // 编号
-	T_layout_no    string // 布局编号
 	T_release_time string `orm:"column(t_release_time)"` // 发布时间
 	T_failure_time string `orm:"column(t_failure_time)"` // 失效时间
 	T_pdf          string // pdf链接
 }
 
 // 获取列表
-func Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end string, T_layout_no_sort, T_release_time_sort, T_failure_time_sort, page int, page_z int) ([]Certificate_, int) {
+func Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end string, T_release_time_sort, T_failure_time_sort, page int, page_z int) ([]Certificate_, int) {
 
 	o := orm.NewOrm()
 	var offset int
@@ -180,11 +179,6 @@ func Read_Certificate_List(T_sn, T_layout_no, Time_start, Time_end string, T_lay
 
 	sql = sql + sqlWhere
 	sqlOrder := make([]string, 0)
-	if T_layout_no_sort == 1 {
-		sqlOrder = append(sqlOrder, "c.t_layout_no ASC")
-	} else if T_layout_no_sort == 2 {
-		sqlOrder = append(sqlOrder, "c.t_layout_no DESC")
-	}
 
 	if T_release_time_sort == 1 {
 		sqlOrder = append(sqlOrder, "pdf.t_release_time ASC")

+ 4 - 4
models/Device/Device.go

@@ -42,7 +42,7 @@ type Device struct {
 type Device_R struct {
 	Id                   int
 	T_sn                 string  // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_id                 int     // 编号
+	T_id                 string  // 编号
 	T_t                  float32 // 温度
 	T_rh                 float32 // 湿度
 	T_time               string  // 采集时间
@@ -56,10 +56,10 @@ type Device_R struct {
 	T_State              int     // 0 删除   1 正常
 }
 
-func DepotToDepot_R(t Device) (r Device_R) {
+func DeviceToDevice_R(t Device, T_id string) (r Device_R) {
 	r.Id = t.Id
 	r.T_sn = t.T_sn
-	r.T_id = t.T_id
+	r.T_id = T_id
 	r.T_t = t.T_t
 	r.T_rh = t.T_rh
 	if !t.T_time.IsZero() {
@@ -245,7 +245,7 @@ func Read_Device_List(T_sn string, T_MSISDN string, page int, page_z int) (r []D
 	cnt, _ = qs.SetCond((*orm2.Condition)(cond1)).Count()
 
 	for _, v := range map_r {
-		r = append(r, DepotToDepot_R(v))
+		r = append(r, DeviceToDevice_R(v, "0"))
 	}
 
 	return r, cnt

+ 10 - 0
models/Device/DeviceClassList.go

@@ -131,7 +131,17 @@ func Read_DeviceClassList_T_class_T_sn(T_class int, T_sn string) (r DeviceClassL
 		return r, false
 	}
 	return r, true
+}
 
+func Read_DeviceClassList_T_class_T_id(T_class int, T_id string) (r DeviceClassList, is bool) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(DeviceClassList))
+	err := qs.Filter("T_id", T_id).Filter("T_class", T_class).Filter("T_State", 1).One(&r)
+	if err != nil {
+		logs.Println(lib.FuncName(), err)
+		return r, false
+	}
+	return r, true
 }
 
 // 添加