From 397468ddc1191bf0ce9339e544ff345d1d4e6786 Mon Sep 17 00:00:00 2001
From: qixiaoning <jony.kee@outlook.com>
Date: 星期四, 11 九月 2025 11:33:10 +0800
Subject: [PATCH] 删除摄像机增加限制
---
camera-service/controllers/camera.go | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 257 insertions(+), 5 deletions(-)
diff --git a/camera-service/controllers/camera.go b/camera-service/controllers/camera.go
index 4f9c380..c71d8f0 100644
--- a/camera-service/controllers/camera.go
+++ b/camera-service/controllers/camera.go
@@ -2,8 +2,12 @@
import (
"bytes"
+ "database/sql"
"encoding/json"
+ "fmt"
"image"
+ "path/filepath"
+ "time"
// "fmt"
// "io/ioutil"
@@ -27,6 +31,7 @@
"basic.com/valib/logger.git"
//"vamicro/camera-common/service/uniquelCoordinate"
+ commonModel "vamicro/api-gateway/models"
"vamicro/config"
"vamicro/extend/util"
scs "vamicro/scene-service/controllers"
@@ -81,7 +86,26 @@
}
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)
+ }
+ }
+
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()}
@@ -105,6 +129,13 @@
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: "璁板綍涓嶅瓨鍦�"}
@@ -162,10 +193,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 {
@@ -319,9 +354,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: "鏇存柊澶辫触"}
@@ -1000,3 +1035,220 @@
_, _ = 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: "淇濆瓨鎴愬姛"}
}
+
+/**
+ * 鑾峰彇鎶撴媿璁板綍
+ */
+func (cc CameraController) GetRecord(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
+
+ //缁戝畾json鍜岀粨鏋勪綋
+ info := models.RecordReq{}
+ if err := c.BindJSON(&info); err != nil {
+ return &bhomeclient.Reply{Success: false, Msg: "鍙傛暟鏈夎"}
+ }
+ page := info.Page
+ pageSize := info.PageSize
+ idsStr := info.Ids
+ TaskIds := info.TaskIds
+ TaskName := info.TaskName
+ videoIdStr := info.VideoIds
+ Warning := info.Warning
+
+ filter := "zh_desc_class != '' "
+
+ //鏍规嵁id鑾峰彇璁板綍
+ var ids []string
+ if len(idsStr) > 0 {
+ for _, tmp := range idsStr {
+ id, _ := strconv.ParseInt(tmp, 10, 64)
+ if id > 0 {
+ ids = append(ids, tmp)
+ }
+ }
+ filter += fmt.Sprintf(" and %s in [%s]", "id", strings.Join(ids, ","))
+ }
+
+ //鏍规嵁瑙嗛id鏌ヨ
+ var videoIds []string
+ if len(videoIdStr) > 0 {
+ for _, tmp := range videoIdStr {
+ if len(tmp) > 0 {
+ videoIds = append(videoIds, tmp)
+ }
+ }
+ //鏍规嵁id鏌ヨ瑙嗛id
+ var vids []int64
+ cameras, _ := models.GetCameraIds(videoIds)
+ for _, camera := range cameras {
+ if len(camera.Id) > 0 {
+ vids = append(vids, camera.VideoId)
+ }
+ }
+ idStr := make([]string, len(vids))
+ for i, id := range vids {
+ idStr[i] = strconv.FormatInt(id, 10)
+ }
+ filter += fmt.Sprintf(" and %s in [%s]", "video_point_id", strings.Join(idStr, ","))
+ }
+
+ //鏍规嵁浠诲姟鏌ヨ
+ 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] = "'" + name + "'" // 姣忎釜鍏冪礌鍔犲崟寮曞彿
+ }
+ filter += fmt.Sprintf(" and %s in [%s]", "task_name", strings.Join(quotedNames, ","))
+ } else {
+ if Warning > 0 {
+ return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: nil}
+ }
+ }
+
+ //鏄惁棰勮
+ if Warning > 0 {
+ filter += fmt.Sprintf(" and is_waning == %d", Warning)
+ }
+
+ //filter += " ORDER BY detect_time DESC"
+ if len(filter) > 0 {
+ logger.Error("filter err:", filter)
+ }
+
+ result, err := models.GetWithPage("smartobject", int64(page), int64(pageSize), filter)
+ // 閫氱敤鍝嶅簲
+ if err != nil {
+ if err == sql.ErrNoRows {
+ return &bhomeclient.Reply{Success: false, Msg: "鏁版嵁涓虹┖"}
+ } else {
+ return &bhomeclient.Reply{Success: false, Msg: "鑾峰彇鍒楄〃澶辫触"}
+ }
+ }
+ //缁勭粐鏁版嵁
+ //閲嶆柊缁勭粐鏁版嵁
+ basePath := commonModel.GetBasePath()
+
+ tmpAllDate := make(map[string]interface{})
+ tmpDate := make(map[string][]interface{})
+
+ for _, v := range result.Items {
+
+ sources := make(map[string]interface{}, 0)
+
+ temp := models.StaticRecord{
+ Id: v.Id,
+ TaskId: v.TaskId,
+ RuleId: v.RuleId,
+ EventLevelId: v.EventLevelId,
+ VideoPointId: v.VideoPointId,
+ DetectId: v.DetectId,
+ ImagePath: v.ImagePath,
+ VideoPath: v.VideoPath,
+ DetectTime: v.DetectTime,
+ IsWarning: v.IsWarning,
+ DetectNum: v.DetectNum,
+ TaskName: v.TaskName,
+ ZhDescClass: v.ZhDescClass,
+ EventLevelName: v.EventLevelName,
+ KnowledgeId: v.KnowledgeId,
+ Suggestion: v.Suggestion,
+ RiskDescription: v.RiskDescription,
+ IsDesc: v.IsDesc,
+ PicMaxUrl: []string{v.ImagePath},
+ PicSrcUrl: []string{v.ImagePath},
+ PicWH: models.PicWidHei{PicH: 720, PicW: 1280},
+ VideoUrl: v.VideoPath,
+ AnalyServerName: "鏅鸿兘鏈嶅姟鑺傜偣",
+ Content: v.CameraName,
+ PicDate: v.PicDate,
+ LikeDate: v.LikeDate,
+ VideoName: v.CameraName,
+ CameraAddr: v.CameraName,
+ CameraName: v.CameraName,
+ }
+
+ //浠诲姟鍚嶇О
+ items, _ := models.GetTaskByIds(v.TaskId)
+ temp.TaskNames = items
+
+ //瑙嗛鍐呭
+ // items4, _ := models.GetVideoById(v.VideoPointId)
+ // temp.VideoName = items4.Name
+ // temp.CameraAddr = items4.Addr
+
+ //妫�鏌ュ唴瀹�
+ items2, _ := models.GetCheckByIds(v.DetectId)
+ temp.CheckNames = items2
+
+ //瑙勫垯鍐呭
+ items3, _ := models.GetRuleByIds(v.RuleId)
+ temp.RuleNames = items3
+
+ //浜嬩欢
+ items5, _ := models.GetEventByIds(v.EventLevelId)
+ temp.EventLevels = items5
+
+ //鐭ヨ瘑搴�
+ items6, _ := models.GetKnowledgeDocumentByIds(v.KnowledgeId)
+ // 鐭ヨ瘑搴撹矾寰�
+ var KnowledgePath = "/txt/zs/"
+ for i := range items6 {
+ filePath := filepath.Join(basePath + KnowledgePath + items6[i].Title)
+ newPath := filepath.ToSlash(filePath)
+ items6[i].FileUrl = newPath
+ }
+ temp.KnowledgeDocuments = items6
+
+ sources["list"] = []interface{}{
+ temp,
+ }
+
+ sources["activeObject"] = temp
+
+ tmpDate["datalist"] = append(tmpDate["datalist"], sources)
+
+ }
+ tmpAllDate["datalist"] = tmpDate["datalist"]
+
+ var pageRes = &models.PaginatedResult2{
+ Pagination: result.Pagination,
+ Items: tmpAllDate,
+ }
+ return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: pageRes}
+}
+
+/**
+ *鑾峰彇鐫f煡浠诲姟
+ */
+func (cc CameraController) GetTasks(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
+ //缁戝畾json鍜岀粨鏋勪綋
+
+ info := models.Video{}
+ if err := c.BindJSON(&info); err != nil {
+ return &bhomeclient.Reply{Success: false, Msg: "鍙傛暟鏈夎"}
+ }
+
+ var tasks []models.Task
+
+ if len(info.VideoIds) > 0 {
+ tasks, _ = models.GetListTask(info.VideoIds)
+ }
+
+ 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