From fd31206bcb8b084720291a53c986db771d8f5975 Mon Sep 17 00:00:00 2001
From: qixiaoning <jony.kee@outlook.com>
Date: 星期四, 18 九月 2025 13:58:16 +0800
Subject: [PATCH] 抓拍预警记录查询修改,备份还原接口问题修复,应用安装接口调试
---
camera-service/controllers/camera.go | 147 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 136 insertions(+), 11 deletions(-)
diff --git a/camera-service/controllers/camera.go b/camera-service/controllers/camera.go
index a4764fd..e90ed77 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,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()}
@@ -109,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: "璁板綍涓嶅瓨鍦�"}
@@ -166,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 {
@@ -323,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: "鏇存柊澶辫触"}
@@ -1006,6 +1037,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 +1075,7 @@
pageSize := info.PageSize
idsStr := info.Ids
TaskIds := info.TaskIds
+ TaskName := info.TaskName
videoIdStr := info.VideoIds
Warning := info.Warning
@@ -1045,7 +1102,7 @@
}
}
//鏍规嵁id鏌ヨ瑙嗛id
- var vids []int
+ var vids []int64
cameras, _ := models.GetCameraIds(videoIds)
for _, camera := range cameras {
if len(camera.Id) > 0 {
@@ -1054,7 +1111,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 +1119,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] = "'" + 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}
+ }
}
//鏄惁棰勮
@@ -1107,6 +1177,7 @@
IsWarning: v.IsWarning,
DetectNum: v.DetectNum,
TaskName: v.TaskName,
+ WarnTaskName: v.WarnTaskName,
ZhDescClass: v.ZhDescClass,
EventLevelName: v.EventLevelName,
KnowledgeId: v.KnowledgeId,
@@ -1121,16 +1192,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 +1245,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 +1307,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