Browse Source

ADD:设备管理复制粘贴

zoie 1 year ago
parent
commit
9dce0b52fe
2 changed files with 92 additions and 0 deletions
  1. 91 0
      controllers/DeviceClass.go
  2. 1 0
      routers/Device.go

+ 91 - 0
controllers/DeviceClass.go

@@ -7,6 +7,7 @@ import (
 	"ColdVerify_server/models/Certificate"
 	"ColdVerify_server/models/Device"
 	"ColdVerify_server/models/System"
+	"ColdVerify_server/models/Task"
 	"fmt"
 	beego "github.com/beego/beego/v2/server/web"
 	"math"
@@ -484,6 +485,96 @@ func (c *DeviceClassController) List_Add() {
 	c.ServeJSON()
 	return
 }
+func (c *DeviceClassController) List_Copy() {
+	// 验证登录 User_is, 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_copy_task_id := c.GetString("T_copy_task_id")
+	copy_task, is := Task.Read_Task(T_copy_task_id)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"}
+		c.ServeJSON()
+		return
+	}
+	T_paste_task_id := c.GetString("T_paste_task_id")
+	paste_task, is := Task.Read_Task(T_paste_task_id)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"}
+		c.ServeJSON()
+		return
+	}
+
+	copyList, cnt := Device.Read_DeviceClassList_OrderList(copy_task.T_class, "", 0, 9999)
+	var successNum int // 成功数量
+	errList := []string{}
+	for _, v := range copyList {
+		ds, is2 := Device.Read_DeviceClassList_T_class_T_id(paste_task.T_class, v.T_id)
+		// id存在 更新
+		if is2 {
+			ds.T_sn = v.T_sn
+			ds.T_remark = v.T_remark
+			if !Device.Update_DeviceClassList(ds, "T_sn", "T_remark") {
+				errList = append(errList, v.T_id)
+				continue
+			}
+		} else {
+			// 判断是否已存在sn
+			_, is3 := Device.Read_DeviceClassList_T_class_T_sn(paste_task.T_class, v.T_sn)
+			// 删除要粘贴的任务里重复的sn
+			if is3 {
+				if !Device.Delete_DeviceClassList_(ds) {
+					errList = append(errList, v.T_id)
+					continue
+				}
+			}
+			// 不存在则添加
+			var pdf Certificate.CertificatePdf
+			pdfList, _ := Certificate.Read_CertificatePdf_Newest(v.T_sn)
+			if len(pdfList) > 0 {
+				pdf = pdfList[0]
+			}
+
+			var_ := Device.DeviceClassList{
+				T_class:        paste_task.T_class,
+				T_id:           v.T_id,
+				T_sn:           v.T_sn,
+				T_failure_time: pdf.T_failure_time,
+				T_pdf:          pdf.T_pdf,
+				T_remark:       v.T_remark,
+				T_State:        1,
+			}
+
+			_, is = Device.Add_DeviceClassList(var_)
+			if !is {
+				errList = append(errList, v.T_id)
+				continue
+			}
+		}
+
+	}
+
+	if len(errList) == 0 {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: cnt}
+		c.ServeJSON()
+		return
+	}
+	var errStr string
+	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() {

+ 1 - 0
routers/Device.go

@@ -19,6 +19,7 @@ func init() {
 	beego.Router("/DeviceClassList/Add", &controllers.DeviceClassController{}, "*:List_Add")   // 添加设备分类列表
 	beego.Router("/DeviceClassList/Up", &controllers.DeviceClassController{}, "*:List_Up")     // 编辑设备分类列表
 	beego.Router("/DeviceClassList/Del", &controllers.DeviceClassController{}, "*:List_Del")   // 删除设备分类列表
+	beego.Router("/DeviceClassList/Copy", &controllers.DeviceClassController{}, "*:List_Copy") // 复制
 
 	// - 设备管理
 	beego.Router("/Device/List", &controllers.DeviceController{}, "*:List") // 设别列表