From 9b17a8dcbc1f94eb117a37b3b24ca9dae0d2d588 Mon Sep 17 00:00:00 2001
From: qixiaoning <jony.kee@outlook.com>
Date: 星期三, 29 十月 2025 09:40:54 +0800
Subject: [PATCH] 摄像机相关接口跳转,推送配置修改,系统权限菜单修改

---
 camera-service/controllers/camera.go |  169 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 158 insertions(+), 11 deletions(-)

diff --git a/camera-service/controllers/camera.go b/camera-service/controllers/camera.go
index a4764fd..2029bfc 100644
--- a/camera-service/controllers/camera.go
+++ b/camera-service/controllers/camera.go
@@ -7,6 +7,7 @@
 	"fmt"
 	"image"
 	"path/filepath"
+	"time"
 
 	// "fmt"
 	// "io/ioutil"
@@ -85,7 +86,39 @@
 	}
 	logger.Debug("update sensors:", camVo.Sensors)
 	sv := service.CameraService{}
+	ok, cam := sv.GetById(camVo.Id)
 	if b, err := sv.CameraUpdate(camVo); b {
+		//鏇存柊鍒嗚鲸鐜�
+		if ok {
+			//
+			logger.Debug("DoPostRequest:", camVo)
+			if cam.IsRunning && (cam.ResolutionWidth != camVo.ResolutionWidth && cam.ResolutionHeight != camVo.ResolutionHeight) {
+				header := map[string]string{}
+				paramBody := map[string]interface{}{
+					"isOpen":    1,
+					"videoId":   camVo.Id,
+					"videoType": 0,
+				}
+				res, err := util.DoPostRequest("http://127.0.0.1:8088/v1/task/openAnalysis", util.CONTENT_TYPE_JSON, paramBody, nil, header, time.Second*10)
+				if err != nil {
+					logger.Debug("DoPostRequest err:", err)
+				}
+				logger.Debug("DoPostRequest:", res)
+			}
+			//鏇存柊鐘舵��
+			if cam.IsRunning {
+				header := map[string]string{}
+				paramBody := map[string]interface{}{
+					"state": 1,
+				}
+				res, err := util.DoPostRequest("http://127.0.0.1:8088/v1/task/updateAllStatus?state=1", util.CONTENT_TYPE_JSON, paramBody, nil, header, time.Second*10)
+				if err != nil {
+					logger.Debug("DoPostRequest err:", err)
+				}
+				logger.Debug("DoPostRequest:", res)
+			}
+		}
+
 		cc.addDbChangeMsg(h.Bk, protomsg.TableChanged_T_Camera, camVo.Id, protomsg.DbAction_Update, "")
 		_, _ = service2.DoBusReq("/data/api-v/saas/syncCamera", config.Server.AnalyServerId, aiot.RequestMethod_Post, aiot.RequestContentType_ApplicationJson, map[string]interface{}{})
 		return &bhomeclient.Reply{Success: true, Data: camVo.Copy2Camera()}
@@ -109,10 +142,26 @@
 	if cid == "" {
 		return &bhomeclient.Reply{Msg: "鍙傛暟鏈夎锛屾憚鍍忔満id涓嶈兘涓虹┖"}
 	}
+
+	//鍒ゆ柇鏄惁鏈夐厤缃换鍔�
+	// total, _ := models.GetTaskTotal(cid)
+	// if total > 0 {
+	// 	return &bhomeclient.Reply{Success: false, Msg: "璇峰厛鍒犻櫎閰嶇疆鐨勪换鍔�"}
+	// }
+
 	rows, _ := cam.Delete(cid)
 	if rows == 0 {
 		return &bhomeclient.Reply{Success: true, Msg: "璁板綍涓嶅瓨鍦�"}
 	}
+
+	//鍒犻櫎浠诲姟
+	items, _ := models.GetTaskTotal(cid)
+	if len(items) > 0 {
+		for _, item := range items {
+			cam.DelLink(item.ID)
+		}
+	}
+
 	pMsg := protomsg.DbChangeMessage{ //闇�瑕侀噸鏂拌绠楃畻鍔涘崰鐢ㄦ儏鍐�
 		Table:  protomsg.TableChanged_T_Camera,
 		Action: protomsg.DbAction_Delete,
@@ -166,10 +215,14 @@
 	}
 
 	m["resolutions"] = []models.Resolution{dRe0, dRe1, dRe2}
+
+	//鑾峰彇鐫f煡浠诲姟
+	tasks := models.GetTasks()
 	//澶勭悊鎽勫儚鏈虹殑鐘舵��
-	var crApi bhomedbapi.CameraRuleApi
+	//var crApi bhomedbapi.CameraRuleApi
 	if cam.RunType == models.TYPE_RUNTYPE_POLL || cam.RunType == models.TYPE_RUNTYPE_REALTIME {
-		if crApi.ExistRunningTask(cam.Id) {
+		//if crApi.ExistRunningTask(cam.Id) {
+		if taskInfo, ok := tasks[cam.Id]; ok && taskInfo != nil && len(taskInfo) > 0 {
 			if cam.IsRunning {
 				m["status"] = models.Camera_Status_Doing
 			} else {
@@ -323,9 +376,9 @@
 
 	sv := service.CameraService{}
 	if sv.ChangeRunType(ccrVo) {
-		cIds := strings.Join(ccrVo.CameraIds, ",")
-		cc.addDbChangeMsg(h.Bk, protomsg.TableChanged_T_Camera, cIds, protomsg.DbAction_Update, "")
-		_, _ = service2.DoBusReq("/data/api-v/saas/syncCamera", config.Server.AnalyServerId, aiot.RequestMethod_Post, aiot.RequestContentType_ApplicationJson, map[string]interface{}{})
+		//cIds := strings.Join(ccrVo.CameraIds, ",")
+		//cc.addDbChangeMsg(h.Bk, protomsg.TableChanged_T_Camera, cIds, protomsg.DbAction_Update, "")
+		//	_, _ = service2.DoBusReq("/data/api-v/saas/syncCamera", config.Server.AnalyServerId, aiot.RequestMethod_Post, aiot.RequestContentType_ApplicationJson, map[string]interface{}{})
 		return &bhomeclient.Reply{Success: true, Msg: "鏇存柊鎴愬姛"}
 	} else {
 		return &bhomeclient.Reply{Success: false, Msg: "鏇存柊澶辫触"}
@@ -1006,6 +1059,31 @@
 }
 
 /**
+ *  鍒犻櫎璁板綍
+ */
+func (cc CameraController) DelRecord(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
+	filter := " id > 0 "
+	info := models.TimeRange{}
+	if err := c.BindJSON(&info); err != nil {
+		return &bhomeclient.Reply{Success: false, Msg: "鍙傛暟鏈夎"}
+	}
+	startTime := info.StartTime
+	endTime := info.EndTime
+	if len(startTime) > 0 && len(endTime) > 0 {
+		filter += fmt.Sprintf(" and detect_time > '%s'", startTime)
+		filter += fmt.Sprintf(" and detect_time < '%s'", endTime)
+		deleteRecord, err := models.DeleteRecord("smartobject", filter)
+		if err != nil {
+			return &bhomeclient.Reply{Success: false, Msg: "鍒犻櫎澶辫触" + err.Error(), Data: nil}
+		} else {
+			return &bhomeclient.Reply{Success: true, Msg: "鍒犻櫎鎴愬姛", Data: deleteRecord}
+		}
+	} else {
+		return &bhomeclient.Reply{Success: false, Msg: "鍒犻櫎澶辫触", Data: nil}
+	}
+}
+
+/**
  *  鑾峰彇鎶撴媿璁板綍
  */
 func (cc CameraController) GetRecord(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
@@ -1019,6 +1097,7 @@
 	pageSize := info.PageSize
 	idsStr := info.Ids
 	TaskIds := info.TaskIds
+	TaskName := info.TaskName
 	videoIdStr := info.VideoIds
 	Warning := info.Warning
 
@@ -1045,7 +1124,7 @@
 			}
 		}
 		//鏍规嵁id鏌ヨ瑙嗛id
-		var vids []int
+		var vids []int64
 		cameras, _ := models.GetCameraIds(videoIds)
 		for _, camera := range cameras {
 			if len(camera.Id) > 0 {
@@ -1054,7 +1133,7 @@
 		}
 		idStr := make([]string, len(vids))
 		for i, id := range vids {
-			idStr[i] = strconv.Itoa(id)
+			idStr[i] = strconv.FormatInt(id, 10)
 		}
 		filter += fmt.Sprintf(" and %s in [%s]", "video_point_id", strings.Join(idStr, ","))
 	}
@@ -1062,6 +1141,19 @@
 	//鏍规嵁浠诲姟鏌ヨ
 	if len(TaskIds) > 0 {
 		filter += fmt.Sprintf(" and array_contains(task_id, %d)", TaskIds[0])
+	}
+
+	//鏍规嵁浠诲姟鍚嶇О
+	if len(TaskName) > 0 {
+		quotedNames := make([]string, len(TaskName))
+		for i, name := range TaskName {
+			quotedNames[i] = " task_name like '%%" + name + "%%' " // 姣忎釜鍏冪礌鍔犲崟寮曞彿
+		}
+		filter += " and (" + strings.Join(quotedNames, "or") + ")"
+	} else {
+		if Warning > 0 {
+			return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: nil}
+		}
 	}
 
 	//鏄惁棰勮
@@ -1107,6 +1199,7 @@
 			IsWarning:       v.IsWarning,
 			DetectNum:       v.DetectNum,
 			TaskName:        v.TaskName,
+			WarnTaskName:    v.WarnTaskName,
 			ZhDescClass:     v.ZhDescClass,
 			EventLevelName:  v.EventLevelName,
 			KnowledgeId:     v.KnowledgeId,
@@ -1121,16 +1214,47 @@
 			Content:         v.CameraName,
 			PicDate:         v.PicDate,
 			LikeDate:        v.LikeDate,
+			VideoName:       v.CameraName,
+			CameraAddr:      v.CameraName,
+			CameraName:      v.CameraName,
 		}
+		var taskId []int64
 
-		//浠诲姟鍚嶇О
+		//浠诲姟id閲嶆柊璧嬪��
+		if len(v.WarnTaskName) > 0 {
+			v.TaskId = []int64{}
+			taskId = []int64{}
+			arr := strings.Split(v.WarnTaskName, ";")
+			for _, temp := range arr {
+				if len(temp) > 0 {
+
+					tempId, _ := strconv.ParseInt(strings.TrimSpace(temp), 10, 64)
+
+					taskId = append(taskId, tempId)
+				}
+			}
+			v.TaskId = taskId
+		}
 		items, _ := models.GetTaskByIds(v.TaskId)
 		temp.TaskNames = items
+		//浠诲姟鍚嶇О閲嶆柊璧嬪��
+		var result string
+		if len(taskId) > 0 && len(items) > 0 {
+			v.EventLevelId = []int64{}
+			for index, item := range items {
+				v.EventLevelId = append(v.EventLevelId, item.EventLevel)
+				if index > 0 {
+					result += ","
+				}
+				result += item.TaskName
+			}
+			temp.TaskName = result
+		}
 
 		//瑙嗛鍐呭
-		items4, _ := models.GetVideoById(v.VideoPointId)
-		temp.VideoName = items4.Name
-		temp.CameraAddr = items4.Addr
+		// items4, _ := models.GetVideoById(v.VideoPointId)
+		// temp.VideoName = items4.Name
+		// temp.CameraAddr = items4.Addr
 
 		//妫�鏌ュ唴瀹�
 		items2, _ := models.GetCheckByIds(v.DetectId)
@@ -1143,6 +1267,18 @@
 		//浜嬩欢
 		items5, _ := models.GetEventByIds(v.EventLevelId)
 		temp.EventLevels = items5
+
+		//浜嬩欢绛夌骇閲嶆柊璧嬪��
+		var result2 string
+		if len(taskId) > 0 && len(items5) > 0 {
+			for i, item5 := range items5 {
+				if i > 0 {
+					result2 += ","
+				}
+				result2 += item5.DictValue
+			}
+			temp.EventLevelName = result2
+		}
 
 		//鐭ヨ瘑搴�
 		items6, _ := models.GetKnowledgeDocumentByIds(v.KnowledgeId)
@@ -1193,3 +1329,14 @@
 	return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: tasks}
 
 }
+
+// 鑾峰彇鎵�鏈�
+func (cc CameraController) GetAllTasks(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
+	//缁戝畾json鍜岀粨鏋勪綋
+
+	var tasks []models.TaskAggregate
+	tasks, _ = models.GetAllTask()
+
+	return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: tasks}
+
+}

--
Gitblit v1.8.0