Bladeren bron

add:自动填写备注

zoie 1 maand geleden
bovenliggende
commit
8a5f16e07e
6 gewijzigde bestanden met toevoegingen van 208 en 1 verwijderingen
  1. 109 1
      controllers/DeviceClass.go
  2. 79 0
      controllers/Task.go
  3. 17 0
      models/Device/DeviceClassList.go
  4. 1 0
      models/Device/DeviceData.go
  5. 1 0
      routers/Device.go
  6. 1 0
      routers/Task.go

+ 109 - 1
controllers/DeviceClass.go

@@ -8,9 +8,11 @@ import (
 	"ColdVerify_server/models/Device"
 	"ColdVerify_server/models/System"
 	"ColdVerify_server/models/Task"
+	"ColdVerify_server/models/VerifyTemplate"
 	"fmt"
 	beego "github.com/beego/beego/v2/server/web"
 	"math"
+	"strconv"
 	"strings"
 )
 
@@ -712,7 +714,7 @@ func (c *DeviceClassController) List_Up_terminal() {
 		c.ServeJSON()
 		return
 	}
-	
+
 	if T_terminal > 0 {
 		r.T_terminal = T_terminal
 	}
@@ -836,3 +838,109 @@ func (c *DeviceClassController) Sync_CertificatePdf_ToList() {
 	c.ServeJSON()
 	return
 }
+
+// 自动填写设备备注
+func (c *DeviceClassController) Auto_fill_Remark() {
+	// 验证登录 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_task_id := c.GetString("T_task_id")
+	task, is := Task.Read_Task(T_task_id)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
+		c.ServeJSON()
+		return
+	}
+
+	verifyTemplate, is := VerifyTemplate.Read_VerifyTemplate(task.T_VerifyTemplate_id)
+	verifyTemplate_R := VerifyTemplate.VerifyTemplateToVerifyTemplate_R(verifyTemplate)
+	T_deploy_list := verifyTemplate_R.T_deploy_list
+
+	// 循环查询布点
+	deviceClassRemarkMap := make(map[int][]string)
+	deviceClassList := Device.Read_DeviceClassList_List_id_By_Terminal(task.T_class, false)
+	for _, deploy := range T_deploy_list {
+		if len(deploy.T_scope) > 0 {
+			dcl := FilterByRange(deviceClassList, deploy.T_scope)
+			for _, dc := range dcl {
+				deviceClassRemarkMap[dc.Id] = append(deviceClassRemarkMap[dc.Id], deploy.T_name)
+
+			}
+		}
+	}
+
+	for _, deviceClass := range deviceClassList {
+		if remark, ok := deviceClassRemarkMap[deviceClass.Id]; ok {
+			deviceClass.T_remark = strings.Join(remark, "|")
+			if !Device.Update_DeviceClassList(deviceClass, "T_remark") {
+				c.Data["json"] = lib.JSONS{Code: 200, Msg: "修改备注失败!"}
+				c.ServeJSON()
+				return
+			}
+
+		}
+	}
+
+	System.Add_UserLogs_T(User_r.T_uuid, "设备备注", "自动填写", T_task_id)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}
+
+func FilterByRange(data []Device.DeviceClassList, condition string) []Device.DeviceClassList {
+	var result []Device.DeviceClassList
+	parts := strings.Split(condition, ",")
+
+	for _, part := range parts {
+		if strings.Contains(part, "-") {
+			// 处理范围 如1-16
+			rangeParts := strings.Split(part, "-")
+			if len(rangeParts) != 2 {
+				continue
+			}
+			start, err1 := strconv.Atoi(rangeParts[0])
+			end, err2 := strconv.Atoi(rangeParts[1])
+			if err1 != nil || err2 != nil || start > end {
+				continue
+			}
+
+			// 转换为0-based索引
+			startIdx := start - 1
+			endIdx := end - 1
+
+			// 确保索引在有效范围内
+			if startIdx < 0 {
+				startIdx = 0
+			}
+			if endIdx >= len(data) {
+				endIdx = len(data) - 1
+			}
+
+			for i := startIdx; i <= endIdx; i++ {
+				result = append(result, data[i])
+			}
+		} else {
+			// 处理单个数字 如2,5
+			num, err := strconv.Atoi(part)
+			if err != nil {
+				continue
+			}
+
+			// 转换为0-based索引
+			idx := num - 1
+
+			// 确保索引在有效范围内
+			if idx >= 0 && idx < len(data) {
+				result = append(result, data[idx])
+			}
+		}
+	}
+
+	return result
+}

+ 79 - 0
controllers/Task.go

@@ -2100,6 +2100,7 @@ func DeviceDataJPG(StartTime, EndTime, T_task_id, T_remark string, deviceList []
 			r_maps, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
 			device[index] = Device.DeviceCount{
 				T_id: id,
+				T_sn: sn,
 				Num:  r_maps_num,
 			}
 			if r_maps_num == 0 {
@@ -2863,3 +2864,81 @@ func (c *TaskController) SyncVerifyTemplateMapData() {
 	c.ServeJSON()
 	return
 }
+func (c *TaskController) TaskData_Stat() {
+	StartTime := c.GetString("StartTime")
+	if len(StartTime) > 0 {
+		_, ok := lib.TimeStrToTime(StartTime)
+		if !ok {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
+			c.ServeJSON()
+			return
+		}
+	}
+
+	EndTime := c.GetString("EndTime")
+	if len(EndTime) > 0 {
+		_, ok := lib.TimeStrToTime(EndTime)
+		if !ok {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
+			c.ServeJSON()
+			return
+		}
+	} else {
+		EndTime = time.Now().Format("2006-01-02 15:04:05")
+	}
+	T_remark := c.GetString("T_remark")
+
+	T_task_id := c.GetString("T_task_id")
+	Task_r, is := Task.Read_Task(T_task_id)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
+		c.ServeJSON()
+		return
+	}
+	if Task_r.T_collection_state == 2 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
+		c.ServeJSON()
+		return
+	}
+
+	deviceList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", T_remark, 0, 9999)
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
+		c.ServeJSON()
+		return
+	}
+
+	var chData = make(chan int, 10)
+	var jobGroup sync.WaitGroup
+	var device = make([]Device.DeviceCount, len(deviceList))
+
+	// 创建温度线
+	for i := 0; i < len(deviceList); i++ {
+		chData <- 1
+		jobGroup.Add(1)
+		go func(index int) {
+			//go func(index int, wg *sync.WaitGroup, p *plot.Plot) {
+			defer func() {
+				<-chData        // 完成时chan取出1个
+				jobGroup.Done() // 完成时将等待组值减1
+			}()
+			sn, id := deviceList[index].T_sn, deviceList[index].T_id
+
+			_, r_maps_num := Device.Read_DeviceSensorData_ById_List(sn, StartTime, EndTime, 0, 9999)
+			device[index] = Device.DeviceCount{
+				T_id: id,
+				T_sn: sn,
+				Num:  r_maps_num,
+			}
+			if r_maps_num == 0 {
+				return
+			}
+
+		}(i)
+	}
+	jobGroup.Wait()
+
+	c.Data["json"] = lib.JSONS{Data: device, Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}

+ 17 - 0
models/Device/DeviceClassList.go

@@ -346,3 +346,20 @@ func Read_DeviceClassList_List_ByT_Certificate_sn_null(CreateTime string) (r []D
 
 	return r
 }
+
+// 排除终端
+func Read_DeviceClassList_List_id_By_Terminal(T_class_Id int, T_Terminal bool) (r []DeviceClassList) {
+
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+
+	qs := o.QueryTable(new(DeviceClassList))
+
+	if T_Terminal == true {
+		qs.Filter("T_class", T_class_Id).Filter("T_State", 1).Filter("T_terminal", 2).All(&r)
+		return r
+	}
+	// T_terminal = 1,0 测点
+	qs.Filter("T_class", T_class_Id).Filter("T_State", 1).Filter("T_terminal__lt", 2).All(&r)
+	return r
+}

+ 1 - 0
models/Device/DeviceData.go

@@ -96,6 +96,7 @@ func RedisDeviceData_Get(key string) (r DeviceData_New, is bool) {
 
 type DeviceCount struct {
 	T_id string `json:"T_id"`
+	T_sn string `json:"T_sn"`
 	Num  int    `json:"Num"`
 }
 

+ 1 - 0
routers/Device.go

@@ -24,6 +24,7 @@ func init() {
 	beego.Router("/DeviceClassList/Template_Download", &controllers.DeviceClassController{}, "*:List_Template_Download")              // 添加设备列表模版
 	beego.Router("/DeviceClassList/Del_Duplication", &controllers.DeviceClassController{}, "*:List_Del_Duplication")                  // 删除重复设备列表
 	beego.Router("/DeviceClassList/Sync_CertificatePdf_ToList", &controllers.DeviceClassController{}, "*:Sync_CertificatePdf_ToList") // 删除重复设备列表
+	beego.Router("/DeviceClassList/Auto_fill_Remark", &controllers.DeviceClassController{}, "*:Auto_fill_Remark")                     // 通过模版布点自动填写到设备备注
 
 	// - 设备管理
 	beego.Router("/Device/List", &controllers.DeviceController{}, "*:List") // 设别列表

+ 1 - 0
routers/Task.go

@@ -62,6 +62,7 @@ func init() {
 
 	beego.Router("/Task/jpg", &controllers.TaskController{}, "*:DeviceData_JPG")            // 任务生成图片
 	beego.Router("/Task/JPG/State", &controllers.TaskController{}, "*:DeviceData_JPGState") // 任务 图片生成状态
+	beego.Router("/Task/TaskData/Stat", &controllers.TaskController{}, "*:TaskData_Stat")   // 统计任务数据
 
 	// 暂停申请
 	beego.Router("/TaskTime/Get", &controllers.TaskController{}, "*:TaskTimeList")              // 任务列表