|
@@ -6,6 +6,7 @@ import (
|
|
"ColdVerify_server/lib"
|
|
"ColdVerify_server/lib"
|
|
"ColdVerify_server/logs"
|
|
"ColdVerify_server/logs"
|
|
"ColdVerify_server/models/Account"
|
|
"ColdVerify_server/models/Account"
|
|
|
|
+ "ColdVerify_server/models/Certificate"
|
|
"ColdVerify_server/models/Device"
|
|
"ColdVerify_server/models/Device"
|
|
"ColdVerify_server/models/System"
|
|
"ColdVerify_server/models/System"
|
|
"ColdVerify_server/models/Task"
|
|
"ColdVerify_server/models/Task"
|
|
@@ -63,6 +64,10 @@ func NatsInit() {
|
|
DeviceClassList := new(sync.Map)
|
|
DeviceClassList := new(sync.Map)
|
|
var count int
|
|
var count int
|
|
for _, v := range resp.DeviceClassList {
|
|
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)
|
|
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)
|
|
//err = Task.Import_TaskData_Back(v.T_sn, v.T_id, resp.Task.T_task_id, resp.Time_start, resp.Time_end)
|
|
//count++
|
|
//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)
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+
|
|
}
|
|
}
|