|
@@ -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
|
|
|
+}
|