Переглянути джерело

修复修改设备布局编号校准证书不同步问题

zoie 4 місяців тому
батько
коміт
5f67892518
3 змінених файлів з 211 додано та 8 видалено
  1. 200 0
      Nats/Nats.go
  2. 10 7
      controllers/DeviceClass.go
  3. 1 1
      controllers/TaskData.go

+ 200 - 0
Nats/Nats.go

@@ -6,6 +6,7 @@ import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
 	"ColdVerify_server/models/Account"
+	"ColdVerify_server/models/Certificate"
 	"ColdVerify_server/models/Device"
 	"ColdVerify_server/models/System"
 	"ColdVerify_server/models/Task"
@@ -63,6 +64,10 @@ func NatsInit() {
 		DeviceClassList := new(sync.Map)
 		var count int
 		for _, v := range resp.DeviceClassList {
+			if strings.Contains(v.T_sn, "-") || len(v.T_sn) == 0 {
+				// 从3.0平台导入
+				continue
+			}
 			DeviceClassList.Store(fmt.Sprintf("%s|%s", v.T_sn, v.T_id), 5)
 			//err = Task.Import_TaskData_Back(v.T_sn, v.T_id, resp.Task.T_task_id, resp.Time_start, resp.Time_end)
 			//count++
@@ -220,4 +225,199 @@ func NatsInit() {
 
 	})
 
+	_, _ = lib.Nats.QueueSubscribe("ColdVerify_Server_Add_DeviceClassList", "Add_DeviceClassList", func(m *nats.Msg) {
+
+		type T_Req struct {
+			T_task_id string `xml:"T_task_id"` // 任务主键id
+			T_sn      string `xml:"T_sn"`
+			T_id      string `xml:"T_id"`
+		}
+
+		var t_Req T_Req
+		var t_R lib.JSONS
+		err := msgpack.Unmarshal(m.Data, &t_Req)
+		if err != nil {
+			logs.Error("Mats", lib.FuncName(), err)
+			t_R.Code = 202
+			t_R.Msg = err.Error()
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		fmt.Printf("ColdVerify_Server_Add_DeviceClassList message: %+v\n", t_Req)
+
+		Task_r, is := Task.Read_Task(t_Req.T_task_id)
+		if !is {
+			logs.Error("Mats", lib.FuncName())
+			t_R.Code = 202
+			t_R.Msg = "T_task_id 错误!"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		// 判断是否已存在sn
+		dc, is := Device.Read_DeviceClassList_T_class_T_sn(Task_r.T_class, t_Req.T_sn)
+		// 添加的id和数据库已存在id相同
+		if is && dc.T_id == t_Req.T_id {
+			t_R.Code = 200
+			t_R.Msg = "ok"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+
+		var pdf Certificate.CertificatePdf
+		//pdfList, _ := Certificate.Read_CertificatePdf_Newest(T_sn)
+		pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(t_Req.T_id, "")
+		if len(pdfList) > 0 {
+			pdf = pdfList[0]
+		}
+		// 相同sn 添加的id和数据库已存在id不同
+		if is && dc.T_id != t_Req.T_id {
+			dc2, is := Device.Read_DeviceClassList_T_class_T_id(Task_r.T_class, t_Req.T_id)
+			if is {
+				logs.Error("Mats", lib.FuncName())
+				t_R.Code = 202
+				t_R.Msg = fmt.Sprintf("编号[%s]已被[%s]关联,请重试", t_Req.T_id, dc2.T_sn)
+				b, _ := msgpack.Marshal(&t_R)
+				_ = lib.Nats.Publish(m.Reply, b)
+				return
+			}
+			dc.T_id = t_Req.T_id
+			dc.T_failure_time = pdf.T_failure_time
+			dc.T_pdf = pdf.T_pdf
+			dc.T_Certificate_sn = pdf.T_Certificate_sn
+			if !Device.Update_DeviceClassList(dc, "T_id", "T_failure_time", "T_pdf", "T_Certificate_sn") {
+				logs.Error("Mats", lib.FuncName())
+				t_R.Code = 202
+				t_R.Msg = "修改编号失败!"
+				b, _ := msgpack.Marshal(&t_R)
+				_ = lib.Nats.Publish(m.Reply, b)
+				return
+			} else {
+				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)
+				return
+			}
+		}
+
+		var_ := Device.DeviceClassList{
+			T_class:          Task_r.T_class,
+			T_id:             t_Req.T_id,
+			T_sn:             t_Req.T_sn,
+			T_failure_time:   pdf.T_failure_time,
+			T_pdf:            pdf.T_pdf,
+			T_Certificate_sn: pdf.T_Certificate_sn,
+			T_remark:         "",
+			T_State:          1,
+		}
+
+		_, is = Device.Add_DeviceClassList(var_)
+
+		if !is {
+			logs.Error("Mats", lib.FuncName(), err)
+			t_R.Code = 202
+			t_R.Msg = err.Error()
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+
+		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_Edit_DeviceClassList", "Edit_DeviceClassList", func(m *nats.Msg) {
+
+		type T_Req struct {
+			T_task_id string `xml:"T_task_id"` // 任务主键id
+			T_sn      string `xml:"T_sn"`
+			T_id      string `xml:"T_id"`
+		}
+
+		var t_Req T_Req
+		var t_R lib.JSONS
+		err := msgpack.Unmarshal(m.Data, &t_Req)
+		if err != nil {
+			logs.Error("Mats", lib.FuncName(), err)
+			t_R.Code = 202
+			t_R.Msg = err.Error()
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		fmt.Printf("ColdVerify_Server_Edit_DeviceClassList message: %+v\n", t_Req)
+
+		Task_r, is := Task.Read_Task(t_Req.T_task_id)
+		if !is {
+			logs.Error("Mats", lib.FuncName())
+			t_R.Code = 202
+			t_R.Msg = "T_task_id 错误!"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		// 判断是否已存在sn
+		dc, is := Device.Read_DeviceClassList_T_class_T_sn(Task_r.T_class, t_Req.T_sn)
+		// 添加的id和数据库已存在id相同
+		if is && dc.T_id == t_Req.T_id {
+			t_R.Code = 200
+			t_R.Msg = "ok"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		// 相同sn 添加的id和数据库已存在id不同
+		if is && dc.T_id != t_Req.T_id {
+			dc2, is := Device.Read_DeviceClassList_T_class_T_id(Task_r.T_class, t_Req.T_id)
+			if is {
+				logs.Error("Mats", lib.FuncName())
+				t_R.Code = 202
+				t_R.Msg = fmt.Sprintf("编号[%s]已被[%s]关联,请重试", t_Req.T_id, dc2.T_sn)
+				b, _ := msgpack.Marshal(&t_R)
+				_ = lib.Nats.Publish(m.Reply, b)
+				return
+			}
+			var pdf Certificate.CertificatePdf
+			pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(t_Req.T_id, "")
+			if len(pdfList) > 0 {
+				pdf = pdfList[0]
+			}
+			dc.T_id = t_Req.T_id
+			dc.T_failure_time = pdf.T_failure_time
+			dc.T_pdf = pdf.T_pdf
+			dc.T_Certificate_sn = pdf.T_Certificate_sn
+			if !Device.Update_DeviceClassList(dc, "T_id", "T_failure_time", "T_pdf", "T_Certificate_sn") {
+				logs.Error("Mats", lib.FuncName())
+				t_R.Code = 202
+				t_R.Msg = "修改编号失败!"
+				b, _ := msgpack.Marshal(&t_R)
+				_ = lib.Nats.Publish(m.Reply, b)
+				return
+			}
+		}
+
+		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)
+
+	})
+
 }

+ 10 - 7
controllers/DeviceClass.go

@@ -415,6 +415,10 @@ func (c *DeviceClassController) List_Add() {
 	for _, sn_id := range list {
 		T_sn := strings.Split(sn_id, ",")[0]
 		T_id := strings.Split(sn_id, ",")[1]
+		if len(T_sn) == 0 || len(T_id) == 0 {
+			errList = append(errList, sn_id)
+			continue
+		}
 		// 判断是否已存在sn
 		dc, is := Device.Read_DeviceClassList_T_class_T_sn(T_class, T_sn)
 		// 添加的id和数据库已存在id相同
@@ -424,6 +428,11 @@ func (c *DeviceClassController) List_Add() {
 		}
 		// 添加的id和数据库已存在id不同
 		if is && dc.T_id != T_id {
+			_, is = Device.Read_DeviceClassList_T_class_T_id(T_class, T_id)
+			if is {
+				errList2 = append(errList2, sn_id)
+				continue
+			}
 			dc.T_id = T_id
 			dc.T_remark = T_remark
 			if !Device.Update_DeviceClassList(dc, "T_id", "T_remark") {
@@ -434,12 +443,6 @@ func (c *DeviceClassController) List_Add() {
 			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)
 		pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(T_id, "")
@@ -637,7 +640,7 @@ func (c *DeviceClassController) List_Up() {
 		r.T_remark = T_remark
 	}
 
-	if !Device.Update_DeviceClassList(r, "T_id", "T_remark") {
+	if !Device.Update_DeviceClassList(r, "T_id", "T_remark", "T_failure_time", "T_pdf", "T_Certificate_sn") {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.ServeJSON()
 		return

+ 1 - 1
controllers/TaskData.go

@@ -98,7 +98,7 @@ func (c *TaskDataController) Extract_TaskData_Back() {
 
 	// 采集中
 	if Task_r.T_collection_state == 2 {
-		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据正采集中,请勿重复提交!"}
 		c.ServeJSON()
 		return
 	}