From 03880bf61cf059f063e252ef17dfea50c932c9dc Mon Sep 17 00:00:00 2001
From: qixiaoning <jony.kee@outlook.com>
Date: 星期三, 12 十一月 2025 09:11:03 +0800
Subject: [PATCH] 清理数据接口修改
---
camera-service/controllers/camera.go | 144 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 138 insertions(+), 6 deletions(-)
diff --git a/camera-service/controllers/camera.go b/camera-service/controllers/camera.go
index 51aa2cd..ed927d8 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,
@@ -1010,6 +1059,45 @@
}
/**
+ * 鍒犻櫎璁板綍
+ */
+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
+ if len(startTime) > 0 && len(info.EndTime) > 0 {
+ endTime, err1 := addDaySimple(info.EndTime)
+ if err1 != nil {
+ endTime = info.EndTime
+ }
+
+ 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 addDaySimple(dateStr string) (string, error) {
+ // 鍋囪鏍煎紡涓� "2006-01-02"
+ t, err := time.Parse("2006-01-02", dateStr)
+ if err != nil {
+ return "", err
+ }
+ t = t.AddDate(0, 0, 1)
+ return t.Format("2006-01-02"), nil
+}
+
+/**
* 鑾峰彇鎶撴媿璁板綍
*/
func (cc CameraController) GetRecord(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
@@ -1073,9 +1161,9 @@
if len(TaskName) > 0 {
quotedNames := make([]string, len(TaskName))
for i, name := range TaskName {
- quotedNames[i] = "'" + name + "'" // 姣忎釜鍏冪礌鍔犲崟寮曞彿
+ quotedNames[i] = " task_name like '%%" + name + "%%' " // 姣忎釜鍏冪礌鍔犲崟寮曞彿
}
- filter += fmt.Sprintf(" and %s in [%s]", "task_name", strings.Join(quotedNames, ","))
+ filter += " and (" + strings.Join(quotedNames, "or") + ")"
} else {
if Warning > 0 {
return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: nil}
@@ -1125,6 +1213,7 @@
IsWarning: v.IsWarning,
DetectNum: v.DetectNum,
TaskName: v.TaskName,
+ WarnTaskName: v.WarnTaskName,
ZhDescClass: v.ZhDescClass,
EventLevelName: v.EventLevelName,
KnowledgeId: v.KnowledgeId,
@@ -1139,16 +1228,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)
@@ -1162,6 +1282,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)
// 鐭ヨ瘑搴撹矾寰�
--
Gitblit v1.8.0