From ef51da5404827e826e979ad614950a9e0192f4c6 Mon Sep 17 00:00:00 2001
From: qixiaoning <jony.kee@outlook.com>
Date: 星期五, 08 八月 2025 09:15:26 +0800
Subject: [PATCH] 调整数据推送相关接口
---
camera-common/models/task.go | 15
camera-service/controllers/camera.go | 11
push-service/service/eventPushService.go | 9
system-service/controllers/dictionary.go | 118 +-
camera-common/models/Record.go | 1024 ++++++++++++++--------------
push-service/vo/eventPush.go | 86 +-
push-service/controllers/pushSet.go | 142 ++-
chanmanage-service/models/camera.go | 152 ++--
search-service/main.go | 13
api-gateway/models/base.go | 78 +-
api-gateway/auth/auth.go | 276 +++---
push-service/models/eventPush.go | 1
camera-service/models/milvus.go | 126 +-
camera-service/main.go | 2
14 files changed, 1,051 insertions(+), 1,002 deletions(-)
diff --git a/api-gateway/auth/auth.go b/api-gateway/auth/auth.go
index 27c39a6..659f667 100644
--- a/api-gateway/auth/auth.go
+++ b/api-gateway/auth/auth.go
@@ -1,138 +1,138 @@
-package auth
-
-import (
- "github.com/gin-gonic/gin"
- "net/http"
- "strings"
- "sync"
- "vamicro/extend/util"
-)
-
-const (
- TokenKey = "abc123456789"
-)
-
-type Auth interface {
- Check(c *gin.Context)bool
- User(c *gin.Context)map[string]interface{}
- Login(http *http.Request,w http.ResponseWriter,user map[string]interface{})interface{}
- Logout(http *http.Request,w http.ResponseWriter) bool
-}
-
-func GenerateAuthDriver() *Auth {
- var authDriver Auth
- authDriver = NewJwtAuthDriver()
- return &authDriver
-}
-
-var outUserM = make(map[string]string,0)
-var lock sync.RWMutex
-
-func SetOutUser(userId string) {
- lock.Lock()
- defer lock.Unlock()
- outUserM[userId] = userId
-}
-
-func OutUser(userId string) bool {
- lock.Lock()
- defer lock.Unlock()
- if _,ok := outUserM[userId];ok{
- return true
- }
- return false
-}
-
-func RemoveOutUser(userId string) {
- lock.Lock()
- defer lock.Unlock()
- if _,ok := outUserM[userId];ok{
- delete(outUserM,userId)
- }
-}
-
-var noTokenUrls = []string{
- "/data/api-v/gb28181/findAreaByParentId",
- "/data/api-v/sysinit/getInitInfo",
- "/data/api-v/sysinit/savePassword",
- "/data/api-v/sysinit/networkList",
- "/data/api-v/sysinit/initNetwork",
- "/data/api-v/sysinit/saveRegInfo",
- "/data/api-v/sysinit/getRegInfo",
- "/data/api-u/sys/logout",
-}
-
-func AuthHandler() gin.HandlerFunc {
- return func(c *gin.Context) {
- urlPath := c.Request.URL.Path
-
- if strings.Contains(urlPath,"/data/api-") &&
- !strings.Contains(urlPath,"login") &&
- !strings.Contains(urlPath, "/data/api-v/license") &&
- !strings.Contains(urlPath, "/data/api-v/info/") &&
- !util.ArrayContains(noTokenUrls, urlPath) &&
- !strings.Contains(urlPath, "/data/api-v/token") {
- //Oauth2妫�鏌�
- token,err := Oauth2Serv.ValidationBearerToken(c.Request)
- if nil == err {
- if !CheckAcl(urlPath) {
- c.JSON(401, gin.H{
- "code": 401,
- "success": false,
- "msg": "鎺ュ彛鏆傛湭寮�鏀�",
- "data": "",
- })
- c.Abort()
- return
- }
- c.Request.Header.Set("Login_user_id", token.GetUserID())
- c.Next()
- //fmt.Print(token.GetUserID())
- return
- } else {
- //fmt.Println(err.Error())
- }
- jwtDriver :=NewJwtAuthDriver()
- if !jwtDriver.Check(c) {
- c.JSON(401, gin.H{
- "code": 401,
- "success": false,
- "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
- "data": "",
- })
- c.Abort()
- return
- }
- userM := (*jwtDriver).User(c)
- if userM == nil {
- c.JSON(401, gin.H{
- "code": 401,
- "success": false,
- "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
- "data": "",
- })
- c.Abort()
- return
- }
- userId := userM["id"].(string)
- if OutUser(userId) {
- c.JSON(401, gin.H{
- "code": 401,
- "success": false,
- "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
- "data": "",
- })
- c.Abort()
- return
- }
- c.Request.Header.Set("Login_user_id", userId)
- c.Next()
- } else {
- c.Next()
- }
- }
-}
-
-func GetCurUser(c *gin.Context)map[string]interface{}{
- return (*GenerateAuthDriver()).User(c)
-}
+package auth
+
+import (
+ "github.com/gin-gonic/gin"
+ "net/http"
+ "strings"
+ "sync"
+ "vamicro/extend/util"
+)
+
+const (
+ TokenKey = "abc123456789"
+)
+
+type Auth interface {
+ Check(c *gin.Context)bool
+ User(c *gin.Context)map[string]interface{}
+ Login(http *http.Request,w http.ResponseWriter,user map[string]interface{})interface{}
+ Logout(http *http.Request,w http.ResponseWriter) bool
+}
+
+func GenerateAuthDriver() *Auth {
+ var authDriver Auth
+ authDriver = NewJwtAuthDriver()
+ return &authDriver
+}
+
+var outUserM = make(map[string]string,0)
+var lock sync.RWMutex
+
+func SetOutUser(userId string) {
+ lock.Lock()
+ defer lock.Unlock()
+ outUserM[userId] = userId
+}
+
+func OutUser(userId string) bool {
+ lock.Lock()
+ defer lock.Unlock()
+ if _,ok := outUserM[userId];ok{
+ return true
+ }
+ return false
+}
+
+func RemoveOutUser(userId string) {
+ lock.Lock()
+ defer lock.Unlock()
+ if _,ok := outUserM[userId];ok{
+ delete(outUserM,userId)
+ }
+}
+
+var noTokenUrls = []string{
+ "/data/api-v/gb28181/findAreaByParentId",
+ "/data/api-v/sysinit/getInitInfo",
+ "/data/api-v/sysinit/savePassword",
+ "/data/api-v/sysinit/networkList",
+ "/data/api-v/sysinit/initNetwork",
+ "/data/api-v/sysinit/saveRegInfo",
+ "/data/api-v/sysinit/getRegInfo",
+ "/data/api-u/sys/logout",
+}
+
+func AuthHandler() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ urlPath := c.Request.URL.Path
+
+ if strings.Contains(urlPath,"/data/api-") &&
+ !strings.Contains(urlPath,"login") &&
+ !strings.Contains(urlPath, "/data/api-v/license") &&
+ !strings.Contains(urlPath, "/data/api-v/info/") &&
+ !util.ArrayContains(noTokenUrls, urlPath) &&
+ !strings.Contains(urlPath, "/data/api-v/token") {
+ //Oauth2妫�鏌�
+ token,err := Oauth2Serv.ValidationBearerToken(c.Request)
+ if nil == err {
+ if !CheckAcl(urlPath) {
+ c.JSON(401, gin.H{
+ "code": 401,
+ "success": false,
+ "msg": "鎺ュ彛鏆傛湭寮�鏀�",
+ "data": "",
+ })
+ c.Abort()
+ return
+ }
+ c.Request.Header.Set("Login_user_id", token.GetUserID())
+ c.Next()
+ //fmt.Print(token.GetUserID())
+ return
+ } else {
+ //fmt.Println(err.Error())
+ }
+ jwtDriver :=NewJwtAuthDriver()
+ if !jwtDriver.Check(c) {
+ c.JSON(401, gin.H{
+ "code": 401,
+ "success": false,
+ "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
+ "data": "",
+ })
+ c.Abort()
+ return
+ }
+ userM := (*jwtDriver).User(c)
+ if userM == nil {
+ c.JSON(401, gin.H{
+ "code": 401,
+ "success": false,
+ "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
+ "data": "",
+ })
+ c.Abort()
+ return
+ }
+ userId := userM["id"].(string)
+ if OutUser(userId) {
+ c.JSON(401, gin.H{
+ "code": 401,
+ "success": false,
+ "msg": "璇锋眰鏈惡甯oken,鏃犳潈璁块棶",
+ "data": "",
+ })
+ c.Abort()
+ return
+ }
+ c.Request.Header.Set("Login_user_id", userId)
+ c.Next()
+ } else {
+ c.Next()
+ }
+ }
+}
+
+func GetCurUser(c *gin.Context)map[string]interface{}{
+ return (*GenerateAuthDriver()).User(c)
+}
diff --git a/api-gateway/models/base.go b/api-gateway/models/base.go
index 7e896cc..a2176e4 100644
--- a/api-gateway/models/base.go
+++ b/api-gateway/models/base.go
@@ -1,39 +1,39 @@
-package models
-
-import (
- "gopkg.in/ini.v1"
-)
-
-type PathConfig struct {
- BasePath string `json:"basePath"`
- DecodeUrl string `json:"decodeUrl"`
- SmartUrl string `json:"smartUrl"`
- MilvusUrl string `json:"milvusUrl"`
- WvpToken string `json:"wvpToken"`
- WvpUrl string `json:"wvpUrl"`
- ZlmediaKitUrl string `json:"zlmediaKitUrl"`
- SqlitePath string `json:"sqlitePath"`
-}
-
-func GetBasePath() string {
- cfg, _ := ini.Load("config.ini")
- // 璇诲彇榛樿鍒嗗尯
- basePath := cfg.Section("setting").Key("basepath").String()
- return basePath
-}
-
-func GetConfig() PathConfig {
- config := PathConfig{}
- cfg, _ := ini.Load("config.ini")
- // 璇诲彇榛樿鍒嗗尯
- config.DecodeUrl = cfg.Section("setting").Key("decodeBaseUrl").String()
-
- config.BasePath = cfg.Section("setting").Key("basepath").String()
- config.SmartUrl = cfg.Section("setting").Key("smartUrl").String()
- config.MilvusUrl = cfg.Section("setting").Key("milvusUrl").String()
- config.WvpToken = cfg.Section("setting").Key("wvpToken").String()
- config.WvpUrl = cfg.Section("setting").Key("wvpUrl").String()
- config.ZlmediaKitUrl = cfg.Section("setting").Key("zlmediaKitUrl").String()
- config.SqlitePath = cfg.Section("setting").Key("sqlitePath").String()
- return config
-}
+package models
+
+import (
+ "gopkg.in/ini.v1"
+)
+
+type PathConfig struct {
+ BasePath string `json:"basePath"`
+ DecodeUrl string `json:"decodeUrl"`
+ SmartUrl string `json:"smartUrl"`
+ MilvusUrl string `json:"milvusUrl"`
+ WvpToken string `json:"wvpToken"`
+ WvpUrl string `json:"wvpUrl"`
+ ZlmediaKitUrl string `json:"zlmediaKitUrl"`
+ SqlitePath string `json:"sqlitePath"`
+}
+
+func GetBasePath() string {
+ cfg, _ := ini.Load("config.ini")
+ // 璇诲彇榛樿鍒嗗尯
+ basePath := cfg.Section("setting").Key("basepath").String()
+ return basePath
+}
+
+func GetConfig() PathConfig {
+ config := PathConfig{}
+ cfg, _ := ini.Load("config.ini")
+ // 璇诲彇榛樿鍒嗗尯
+ config.DecodeUrl = cfg.Section("setting").Key("decodeBaseUrl").String()
+
+ config.BasePath = cfg.Section("setting").Key("basepath").String()
+ config.SmartUrl = cfg.Section("setting").Key("smartUrl").String()
+ config.MilvusUrl = cfg.Section("setting").Key("milvusUrl").String()
+ config.WvpToken = cfg.Section("setting").Key("wvpToken").String()
+ config.WvpUrl = cfg.Section("setting").Key("wvpUrl").String()
+ config.ZlmediaKitUrl = cfg.Section("setting").Key("zlmediaKitUrl").String()
+ config.SqlitePath = cfg.Section("setting").Key("sqlitePath").String()
+ return config
+}
diff --git a/camera-common/models/Record.go b/camera-common/models/Record.go
index 6901768..6c8012c 100644
--- a/camera-common/models/Record.go
+++ b/camera-common/models/Record.go
@@ -1,512 +1,512 @@
-package models
-
-import (
- "context"
- "fmt"
- "math"
- "sort"
- "strconv"
- "strings"
- "time"
-
- "github.com/milvus-io/milvus-sdk-go/v2/entity"
-)
-
-// DataOperator 鏁版嵁鎿嶄綔鐩稿叧鏂规硶
-type DataOperator struct {
- client *MilvusClient
-}
-
-// NewDataOperator 鍒涘缓鏁版嵁鎿嶄綔鍣�
-func NewDataOperator(client *MilvusClient) *DataOperator {
- return &DataOperator{client: client}
-}
-
-type PicWidHei struct {
- PicW int `json:"picW"`
- PicH int `json:"picH"`
-}
-
-// 缁熻鏌ヨ
-type StaticRecord struct {
- Id string `json:"id"`
- TaskId []int64 `json:"task_id"`
- RuleId []int64 `json:"rule_id"`
- EventLevelId []int64 `json:"event_level_id"`
- VideoPointId int64 `json:"video_point_id"`
- DetectId []int64 `json:"detect_id"`
- VideoName string `json:"video_name"`
- TaskNames []TaskOption `json:"task_names"`
- CheckNames []CheckOption `json:"check_names"`
- RuleNames []RuleOption `json:"rule_names"`
- EventLevels []DictOption `json:"event_levels"`
- KnowledgeDocuments []KnowledgeDocumentOption `json:"knowledge_documents"`
- ImagePath string `json:"image_path"`
- VideoPath string `json:"video_path"`
- DetectTime string `json:"detect_time"`
- IsWarning int64 `json:"is_warning"`
- ZhDescClass string `json:"zh_desc_class"`
- TaskName string `json:"task_name"`
- EventLevelName string `json:"event_level_name"`
- DetectNum int64 `json:"detect_num"`
- Suggestion string `json:"suggestion"`
- RiskDescription string `json:"risk_description"`
- KnowledgeId []int64 `json:"knowledge_id"`
- IsDesc int64 `json:"is_desc"`
- CameraId string `json:"cameraId"`
- CameraName string `json:"cameraName"`
- CameraAddr string `json:"cameraAddr"`
- PicDate string `json:"picDate"`
- PicId int64 `json:"picId"`
- PicMaxUrl []string `json:"picMaxUrl"`
- PicSrcUrl []string `json:"picSrcUrl"`
- PicWH PicWidHei `json:"picWH"`
- SdkName string `json:"sdkName"`
- Content string `json:"content"`
- AlarmRules []AlarmRule `json:"alarmRules"`
- LikeDate string `json:"likeDate"`
- ShowLabels string `json:"showLabels"`
- OtherLabels string `json:"otherLabels"`
- VideoUrl string `json:"videoUrl"`
- AnalyServerId string `json:"analyServerId"`
- AnalyServerName string `json:"analyServerName"`
- AnalyServerIp string `json:"analyServerIp"`
- ClusterId string `json:"clusterId"`
- IsAlarm bool `json:"isAlarm"`
- IsAckAlarm bool `json:"isAckAlarm"`
- IsCollect bool `json:"isCollect"`
- IsDelete bool `json:"isDelete"`
- BaseInfo []*BaseCompareInfo `json:"baseInfo"`
- TargetInfo []TargetInfo `json:"targetInfo"`
- FileId string `json:"fileId"` // 鏁版嵁鏍堟枃浠秈d
- DataSource string `json:"dataSource"` // 鏁版嵁鏉ユ簮:鎽勫儚鏈�, 鏁版嵁鏍�
-}
-
-type Point struct {
- X float64 `json:"x"`
- Y float64 `json:"y"`
-}
-
-type Points struct {
- TopLeft Point `json:"topLeft"`
- BottomRight Point `json:"bottomRight"`
-}
-
-type BaseCompareInfo struct {
- TableId string `json:"tableId"`
- TableName string `json:"tableName"`
- BwType string `json:"bwType"`
- CompareScore float64 `json:"compareScore"`
- TargetId string `json:"targetId"`
- TargetName string `json:"targetName"`
- TargetPicUrl string `json:"targetPicUrl"`
- MonitorLevel string `json:"monitorLevel"`
- Content string `json:"content"`
- DbLabel string `json:"labels"`
-}
-
-type TargetInfo struct {
- TargetId string `json:"targetId"`
- AreaId string `json:"areaId"`
- AreaName string `json:"areaName"`
- TargetScore float64 `json:"targetScore"`
- TargetType string `json:"targetType"`
- Feature string `json:"feature"`
- PicSmUrl string `json:"picSmUrl"`
- TargetLocation Points `json:"targetLocation"`
- BelongsTargetID string `json:"belongsTargetId"`
- Attribute string `json:"attribute"`
-}
-
-type AlarmRule struct {
- AlarmLevel string `db:"alarmLevel" json:"alarmLevel"`
- DefenceState bool `db:"defenceState" json:"defenceState"`
- GroupId string `db:"groupId" json:"groupId"`
- LinkInfo string `db:"linkInfo" json:"linkInfo"`
- RuleText string `db:"ruleText" json:"ruleText"`
-}
-
-type TaskOption struct {
- TaskId int64 `db:"task_id" json:"taskId"`
- TaskName string `db:"task_name" json:"taskName"`
-}
-
-type CheckOption struct {
- TaskId int64 `db:"task_id" json:"taskId,omitempty"`
- CheckId int64 `db:"check_id" json:"checkId"`
- FileName string `db:"file_name" json:"fileName"`
-}
-
-type RuleOption struct {
- TaskId int64 `db:"task_id" json:"taskId,omitempty"`
- RuleId int64 `db:"rule_id" json:"ruleId"`
- FileName string `db:"file_name" json:"fileName"`
-}
-
-// 瀛楀吀
-type DictOption struct {
- DictId int64 `db:"dict_id" json:"dictId"`
- DictName string `db:"dict_name" json:"dictName"`
- DictValue string `db:"dict_value" json:"dictValue"`
- DictType string `db:"dict_type" json:"dictType"`
-}
-
-// 鐭ヨ瘑搴�
-type KnowledgeDocumentOption struct {
- Id string `db:"id" json:"id"`
- Title string `db:"title" json:"title"`
- KnowId int64 `db:"know_id" json:"know_id"`
- FileUrl string `db:"title" json:"file_url"`
-}
-
-// Pagination 鍒嗛〉淇℃伅
-type Pagination struct {
- Page int `json:"page"` // 褰撳墠椤电爜
- PageSize int `json:"pageSize"` // 姣忛〉澶у皬
- Total int `json:"total"` // 鎬昏褰曟暟
- TotalPage int `json:"totalPage"` // 鎬婚〉鏁�
-}
-
-// PaginatedResult 鍒嗛〉缁撴灉
-type PaginatedResult struct {
- Items []StaticRecord `json:"list"`
- Pagination Pagination `json:"pagination"`
-}
-
-type PaginatedResult2 struct {
- Items map[string]interface{} `json:"list"`
- Pagination Pagination `json:"pagination"`
-}
-
-// 璁板綍
-type RecordReq struct {
- Ids []string `json:"ids"`
- VideoIds []string `json:"treeNodes"`
- TaskIds []int64 `json:"taskIds`
- TaskName []string `json:"taskName"`
- Warning int64 `json:"warning`
- Page int64 `json:"page"`
- PageSize int64 `json:"pageSize"`
-}
-
-// 鏍规嵁鍒嗛〉鍙栨暟鎹�
-func GetWithPage(collectionName string, pageNum int64, pageSize int64, filter string) (*PaginatedResult, error) {
-
- if pageNum < 1 {
- pageNum = 1
- }
- if pageSize < 1 {
- pageSize = 10
- }
-
- if dbClient == nil {
- return nil, nil
- }
-
- dataOp := &DataOperator{client: dbClient}
-
- fmt.Println(filter)
- records, err := dataOp.queryWithPagination(collectionName, filter, pageNum, pageSize)
- if err != nil {
- return nil, err
- }
-
- return records, nil
-}
-
-// 杞崲鏁版嵁
-func convertResultToMap(result []entity.Column) []StaticRecord {
- if len(result) == 0 {
- return nil
- }
- count := result[0].Len()
- var records []StaticRecord
- for i := 0; i < count; i++ {
- record := StaticRecord{}
- for _, field := range result {
- switch field.Name() {
- case "id":
- IdColumn := field.(*entity.ColumnInt64).Data()
- if len(IdColumn) > 0 {
- record.Id = strconv.FormatInt(IdColumn[i], 10)
- }
- case "task_id":
- TaskIdColumn := field.(*entity.ColumnInt64Array).Data()
- if len(TaskIdColumn) > 0 {
- record.TaskId = TaskIdColumn[i]
- }
- case "rule_id":
- RuleIdColumn := field.(*entity.ColumnInt64Array).Data()
- if len(RuleIdColumn) > 0 {
- record.RuleId = RuleIdColumn[i]
- }
- case "event_level_id":
- EventLevelIdColumn := field.(*entity.ColumnInt64Array).Data()
- if len(EventLevelIdColumn) > 0 {
- record.EventLevelId = EventLevelIdColumn[i]
- }
- case "video_point_id":
- VideoPointIdColumn := field.(*entity.ColumnInt64).Data()
- if len(VideoPointIdColumn) > 0 {
- record.VideoPointId = VideoPointIdColumn[i]
- }
- case "detect_id":
- DetectIdColumn := field.(*entity.ColumnInt64Array).Data()
- if len(DetectIdColumn) > 0 {
- record.DetectId = DetectIdColumn[i]
- }
- case "image_path":
- ImagePathColumn := field.(*entity.ColumnVarChar).Data()
- if len(ImagePathColumn) > 0 {
- record.ImagePath = ImagePathColumn[i]
- }
- case "video_path":
- VideoPathColumn := field.(*entity.ColumnVarChar).Data()
- if len(VideoPathColumn) > 0 {
- record.VideoPath = VideoPathColumn[i]
- }
- case "zh_desc_class":
- zhColumn := field.(*entity.ColumnVarChar).Data()
- if len(zhColumn) > 0 {
- record.ZhDescClass = zhColumn[i]
- }
- case "task_name":
- TNColumn := field.(*entity.ColumnVarChar).Data()
- if len(TNColumn) > 0 {
- record.TaskName = TNColumn[i]
- }
- case "event_level_name":
- EVColumn := field.(*entity.ColumnVarChar).Data()
- if len(EVColumn) > 0 {
- record.EventLevelName = EVColumn[i]
- }
- case "is_desc":
- descColumn := field.(*entity.ColumnInt64).Data()
- if len(descColumn) > 0 {
- record.IsDesc = descColumn[i]
- }
- case "detect_num":
- DEColumn := field.(*entity.ColumnInt64).Data()
- if len(DEColumn) > 0 {
- record.DetectNum = DEColumn[i]
- }
- case "is_waning":
- warnColumn := field.(*entity.ColumnInt64).Data()
- if len(warnColumn) > 0 {
- record.IsWarning = warnColumn[i]
- }
- case "detect_time":
- DetectTimeColumn := field.(*entity.ColumnVarChar).Data()
- if len(DetectTimeColumn) > 0 {
- record.DetectTime = DetectTimeColumn[i]
- }
- case "knowledge_id":
- KnowledgeIdColumn := field.(*entity.ColumnInt64Array).Data()
- if len(KnowledgeIdColumn) > 0 {
- record.KnowledgeId = KnowledgeIdColumn[i]
- }
- case "suggestion":
- SuggestionColumn := field.(*entity.ColumnVarChar).Data()
- if len(SuggestionColumn) > 0 {
- record.Suggestion = SuggestionColumn[i]
- }
- case "risk_description":
- RiskDescriptionColumn := field.(*entity.ColumnVarChar).Data()
- if len(RiskDescriptionColumn) > 0 {
- record.RiskDescription = RiskDescriptionColumn[i]
- }
- }
- }
- records = append(records, record)
- }
- return records
-}
-
-// 鍒嗛〉鏌ヨ
-func (do *DataOperator) queryWithPagination(collectionName string, filterExpr string, pageNum int64, pageSize int64) (*PaginatedResult, error) {
- ctx := context.Background()
-
- // 璁$畻鍋忕Щ閲�
- //offset := (pageNum - 1) * pageSize
-
- // 鏋勫缓鏌ヨ琛ㄨ揪寮忥紙Milvus 2.1+ 鏀寔 limit/offset锛�
- //queryExpr := fmt.Sprintf("%s limit %d offset %d", filterExpr, pageSize, offset)
-
- total, err := do.getTotalCount(collectionName, filterExpr)
- if err != nil {
- return nil, err
- }
-
- // 璁$畻鎬婚〉鏁�
- totalPages := int(math.Ceil(float64(total) / float64(pageSize)))
-
- // 鎵ц鏌ヨ
- result, err := do.client.client.Query(
- ctx,
- collectionName,
- []string{}, // 鎵�鏈夊垎鍖�
- filterExpr,
- []string{"rule_id", "task_id", "is_waning", "zh_desc_class", "task_name", "event_level_name", "detect_num",
- "event_level_id", "video_point_id", "detect_id", "image_path",
- "video_path", "detect_time", "knowledge_id", "risk_description", "suggestion", "id", "is_desc"}, // 杩斿洖鎵�鏈夊瓧娈�
- // client.WithLimit(pageSize),
- // client.WithOffset(offset),
- )
- if err != nil {
- return nil, fmt.Errorf("鍒嗛〉鏌ヨ澶辫触: %v", err)
- }
- lists := convertResultToMap(result)
- layout := "2006-01-02 15:04:05.999999"
-
- var temp1 time.Time
- var temp2 time.Time
-
- //鎺掑簭
- sort.Slice(lists, func(i, j int) bool {
- //return lists[i].DetectTime > lists[j].:DetectTime
- temp1, _ = time.Parse(layout, lists[i].DetectTime)
- temp2, _ = time.Parse(layout, lists[j].DetectTime)
- return temp1.After(temp2)
- })
-
- items := Paginate(lists, int(pageNum), int(pageSize))
- return &PaginatedResult{
- Items: items,
- Pagination: Pagination{
- Page: int(pageNum),
- PageSize: int(pageSize),
- Total: int(total),
- TotalPage: totalPages,
- },
- }, nil
-}
-
-// 鍒嗛〉鏁版嵁
-func Paginate(data []StaticRecord, page, pageSize int) []StaticRecord {
- start := (page - 1) * pageSize
- if start >= len(data) {
- return nil
- }
- end := start + pageSize
- if end > len(data) {
- end = len(data)
- }
- return data[start:end]
-}
-
-// 缁熻鏁伴噺
-func (do *DataOperator) getTotalCount(collectionName string, filterExpr string) (int64, error) {
- result, err := do.client.client.Query(
- context.Background(),
- collectionName,
- []string{},
- filterExpr,
- []string{"count(*)"},
- )
- if err != nil {
- return 0, err
- }
- return result[0].(*entity.ColumnInt64).Data()[0], nil
-}
-
-// 鏍规嵁id鑾峰彇浠诲姟
-func GetTaskByIds(ids []int64) (items []TaskOption, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `select task_id,task_name from mal_smart_task where task_id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr).Scan(&items).Error; err != nil {
- return nil, err
- }
- return
-}
-
-// 鏍规嵁id鑾峰彇瑙嗛
-func GetVideoById(vid int64) (video Camera, err error) {
- // 濡傛灉杩斿洖鐨勬槸鎸囬拡,闇�瑕佸垵濮嬪寲
- sqlStr := "select id,name,alias,type,addr,rtsp,is_running,run_type,run_enable FROM cameras where video_id=?"
- if err := db.Raw(sqlStr, vid).Scan(&video).Error; err != nil {
- return Camera{}, err
- }
- return
-}
-
-// 鏍规嵁id鑾峰彇妫�娴嬪唴瀹�
-func GetCheckByIds(ids []int64) (items []CheckOption, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `select check_id,file_name from mal_check_content where check_id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
- return nil, err
- }
- return
-}
-
-// 鏍规嵁id鑾峰彇瑙勫垯
-func GetRuleByIds(ids []int64) (items []RuleOption, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `select rule_id,file_name from mal_warning_rule where rule_id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
- return nil, err
- }
- return
-}
-
-// 鑾峰彇浜嬩欢
-func GetEventByIds(ids []int64) (items []DictOption, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `select dict_id,dict_name,dict_value from mal_dict_type where dict_id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
- return nil, err
- }
-
- return
-
-}
-
-// 鏍规嵁鐭ヨ瘑搴搃d鏌ユ暟鎹�
-func GetKnowledgeDocumentByIds(ids []int64) (items []KnowledgeDocumentOption, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `SELECT id, know_id, file_name as title FROM mal_knowledge_document where id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
- return nil, err
- }
- return
-}
-
-// 鏍规嵁鐭ヨ瘑搴搃d鏌ユ暟鎹�
-func GetCameraIds(ids []string) (items []CameraDto, err error) {
- placeholders := make([]string, len(ids))
- args := make([]interface{}, len(ids))
- for i, id := range ids {
- placeholders[i] = "?"
- args[i] = id
- }
- sqlStr := `select id,name,alias,type,addr,rtsp,is_running,run_type,run_enable,video_id FROM cameras where id in (` + strings.Join(placeholders, ",") + `)`
- if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
- return nil, err
- }
- return
-}
+package models
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/milvus-io/milvus-sdk-go/v2/entity"
+)
+
+// DataOperator 鏁版嵁鎿嶄綔鐩稿叧鏂规硶
+type DataOperator struct {
+ client *MilvusClient
+}
+
+// NewDataOperator 鍒涘缓鏁版嵁鎿嶄綔鍣�
+func NewDataOperator(client *MilvusClient) *DataOperator {
+ return &DataOperator{client: client}
+}
+
+type PicWidHei struct {
+ PicW int `json:"picW"`
+ PicH int `json:"picH"`
+}
+
+// 缁熻鏌ヨ
+type StaticRecord struct {
+ Id string `json:"id"`
+ TaskId []int64 `json:"task_id"`
+ RuleId []int64 `json:"rule_id"`
+ EventLevelId []int64 `json:"event_level_id"`
+ VideoPointId int64 `json:"video_point_id"`
+ DetectId []int64 `json:"detect_id"`
+ VideoName string `json:"video_name"`
+ TaskNames []TaskOption `json:"task_names"`
+ CheckNames []CheckOption `json:"check_names"`
+ RuleNames []RuleOption `json:"rule_names"`
+ EventLevels []DictOption `json:"event_levels"`
+ KnowledgeDocuments []KnowledgeDocumentOption `json:"knowledge_documents"`
+ ImagePath string `json:"image_path"`
+ VideoPath string `json:"video_path"`
+ DetectTime string `json:"detect_time"`
+ IsWarning int64 `json:"is_warning"`
+ ZhDescClass string `json:"zh_desc_class"`
+ TaskName string `json:"task_name"`
+ EventLevelName string `json:"event_level_name"`
+ DetectNum int64 `json:"detect_num"`
+ Suggestion string `json:"suggestion"`
+ RiskDescription string `json:"risk_description"`
+ KnowledgeId []int64 `json:"knowledge_id"`
+ IsDesc int64 `json:"is_desc"`
+ CameraId string `json:"cameraId"`
+ CameraName string `json:"cameraName"`
+ CameraAddr string `json:"cameraAddr"`
+ PicDate string `json:"picDate"`
+ PicId int64 `json:"picId"`
+ PicMaxUrl []string `json:"picMaxUrl"`
+ PicSrcUrl []string `json:"picSrcUrl"`
+ PicWH PicWidHei `json:"picWH"`
+ SdkName string `json:"sdkName"`
+ Content string `json:"content"`
+ AlarmRules []AlarmRule `json:"alarmRules"`
+ LikeDate string `json:"likeDate"`
+ ShowLabels string `json:"showLabels"`
+ OtherLabels string `json:"otherLabels"`
+ VideoUrl string `json:"videoUrl"`
+ AnalyServerId string `json:"analyServerId"`
+ AnalyServerName string `json:"analyServerName"`
+ AnalyServerIp string `json:"analyServerIp"`
+ ClusterId string `json:"clusterId"`
+ IsAlarm bool `json:"isAlarm"`
+ IsAckAlarm bool `json:"isAckAlarm"`
+ IsCollect bool `json:"isCollect"`
+ IsDelete bool `json:"isDelete"`
+ BaseInfo []*BaseCompareInfo `json:"baseInfo"`
+ TargetInfo []TargetInfo `json:"targetInfo"`
+ FileId string `json:"fileId"` // 鏁版嵁鏍堟枃浠秈d
+ DataSource string `json:"dataSource"` // 鏁版嵁鏉ユ簮:鎽勫儚鏈�, 鏁版嵁鏍�
+}
+
+type Point struct {
+ X float64 `json:"x"`
+ Y float64 `json:"y"`
+}
+
+type Points struct {
+ TopLeft Point `json:"topLeft"`
+ BottomRight Point `json:"bottomRight"`
+}
+
+type BaseCompareInfo struct {
+ TableId string `json:"tableId"`
+ TableName string `json:"tableName"`
+ BwType string `json:"bwType"`
+ CompareScore float64 `json:"compareScore"`
+ TargetId string `json:"targetId"`
+ TargetName string `json:"targetName"`
+ TargetPicUrl string `json:"targetPicUrl"`
+ MonitorLevel string `json:"monitorLevel"`
+ Content string `json:"content"`
+ DbLabel string `json:"labels"`
+}
+
+type TargetInfo struct {
+ TargetId string `json:"targetId"`
+ AreaId string `json:"areaId"`
+ AreaName string `json:"areaName"`
+ TargetScore float64 `json:"targetScore"`
+ TargetType string `json:"targetType"`
+ Feature string `json:"feature"`
+ PicSmUrl string `json:"picSmUrl"`
+ TargetLocation Points `json:"targetLocation"`
+ BelongsTargetID string `json:"belongsTargetId"`
+ Attribute string `json:"attribute"`
+}
+
+type AlarmRule struct {
+ AlarmLevel string `db:"alarmLevel" json:"alarmLevel"`
+ DefenceState bool `db:"defenceState" json:"defenceState"`
+ GroupId string `db:"groupId" json:"groupId"`
+ LinkInfo string `db:"linkInfo" json:"linkInfo"`
+ RuleText string `db:"ruleText" json:"ruleText"`
+}
+
+type TaskOption struct {
+ TaskId int64 `db:"task_id" json:"taskId"`
+ TaskName string `db:"task_name" json:"taskName"`
+}
+
+type CheckOption struct {
+ TaskId int64 `db:"task_id" json:"taskId,omitempty"`
+ CheckId int64 `db:"check_id" json:"checkId"`
+ FileName string `db:"file_name" json:"fileName"`
+}
+
+type RuleOption struct {
+ TaskId int64 `db:"task_id" json:"taskId,omitempty"`
+ RuleId int64 `db:"rule_id" json:"ruleId"`
+ FileName string `db:"file_name" json:"fileName"`
+}
+
+// 瀛楀吀
+type DictOption struct {
+ DictId int64 `db:"dict_id" json:"dictId"`
+ DictName string `db:"dict_name" json:"dictName"`
+ DictValue string `db:"dict_value" json:"dictValue"`
+ DictType string `db:"dict_type" json:"dictType"`
+}
+
+// 鐭ヨ瘑搴�
+type KnowledgeDocumentOption struct {
+ Id string `db:"id" json:"id"`
+ Title string `db:"title" json:"title"`
+ KnowId int64 `db:"know_id" json:"know_id"`
+ FileUrl string `db:"title" json:"file_url"`
+}
+
+// Pagination 鍒嗛〉淇℃伅
+type Pagination struct {
+ Page int `json:"page"` // 褰撳墠椤电爜
+ PageSize int `json:"pageSize"` // 姣忛〉澶у皬
+ Total int `json:"total"` // 鎬昏褰曟暟
+ TotalPage int `json:"totalPage"` // 鎬婚〉鏁�
+}
+
+// PaginatedResult 鍒嗛〉缁撴灉
+type PaginatedResult struct {
+ Items []StaticRecord `json:"list"`
+ Pagination Pagination `json:"pagination"`
+}
+
+type PaginatedResult2 struct {
+ Items map[string]interface{} `json:"list"`
+ Pagination Pagination `json:"pagination"`
+}
+
+// 璁板綍
+type RecordReq struct {
+ Ids []string `json:"ids"`
+ VideoIds []string `json:"treeNodes"`
+ TaskIds []int64 `json:"taskIds`
+ TaskName []string `json:"taskName"`
+ Warning int64 `json:"warning`
+ Page int64 `json:"page"`
+ PageSize int64 `json:"pageSize"`
+}
+
+// 鏍规嵁鍒嗛〉鍙栨暟鎹�
+func GetWithPage(collectionName string, pageNum int64, pageSize int64, filter string) (*PaginatedResult, error) {
+
+ if pageNum < 1 {
+ pageNum = 1
+ }
+ if pageSize < 1 {
+ pageSize = 10
+ }
+
+ if dbClient == nil {
+ return nil, nil
+ }
+
+ dataOp := &DataOperator{client: dbClient}
+
+ fmt.Println(filter)
+ records, err := dataOp.queryWithPagination(collectionName, filter, pageNum, pageSize)
+ if err != nil {
+ return nil, err
+ }
+
+ return records, nil
+}
+
+// 杞崲鏁版嵁
+func convertResultToMap(result []entity.Column) []StaticRecord {
+ if len(result) == 0 {
+ return nil
+ }
+ count := result[0].Len()
+ var records []StaticRecord
+ for i := 0; i < count; i++ {
+ record := StaticRecord{}
+ for _, field := range result {
+ switch field.Name() {
+ case "id":
+ IdColumn := field.(*entity.ColumnInt64).Data()
+ if len(IdColumn) > 0 {
+ record.Id = strconv.FormatInt(IdColumn[i], 10)
+ }
+ case "task_id":
+ TaskIdColumn := field.(*entity.ColumnInt64Array).Data()
+ if len(TaskIdColumn) > 0 {
+ record.TaskId = TaskIdColumn[i]
+ }
+ case "rule_id":
+ RuleIdColumn := field.(*entity.ColumnInt64Array).Data()
+ if len(RuleIdColumn) > 0 {
+ record.RuleId = RuleIdColumn[i]
+ }
+ case "event_level_id":
+ EventLevelIdColumn := field.(*entity.ColumnInt64Array).Data()
+ if len(EventLevelIdColumn) > 0 {
+ record.EventLevelId = EventLevelIdColumn[i]
+ }
+ case "video_point_id":
+ VideoPointIdColumn := field.(*entity.ColumnInt64).Data()
+ if len(VideoPointIdColumn) > 0 {
+ record.VideoPointId = VideoPointIdColumn[i]
+ }
+ case "detect_id":
+ DetectIdColumn := field.(*entity.ColumnInt64Array).Data()
+ if len(DetectIdColumn) > 0 {
+ record.DetectId = DetectIdColumn[i]
+ }
+ case "image_path":
+ ImagePathColumn := field.(*entity.ColumnVarChar).Data()
+ if len(ImagePathColumn) > 0 {
+ record.ImagePath = ImagePathColumn[i]
+ }
+ case "video_path":
+ VideoPathColumn := field.(*entity.ColumnVarChar).Data()
+ if len(VideoPathColumn) > 0 {
+ record.VideoPath = VideoPathColumn[i]
+ }
+ case "zh_desc_class":
+ zhColumn := field.(*entity.ColumnVarChar).Data()
+ if len(zhColumn) > 0 {
+ record.ZhDescClass = zhColumn[i]
+ }
+ case "task_name":
+ TNColumn := field.(*entity.ColumnVarChar).Data()
+ if len(TNColumn) > 0 {
+ record.TaskName = TNColumn[i]
+ }
+ case "event_level_name":
+ EVColumn := field.(*entity.ColumnVarChar).Data()
+ if len(EVColumn) > 0 {
+ record.EventLevelName = EVColumn[i]
+ }
+ case "is_desc":
+ descColumn := field.(*entity.ColumnInt64).Data()
+ if len(descColumn) > 0 {
+ record.IsDesc = descColumn[i]
+ }
+ case "detect_num":
+ DEColumn := field.(*entity.ColumnInt64).Data()
+ if len(DEColumn) > 0 {
+ record.DetectNum = DEColumn[i]
+ }
+ case "is_waning":
+ warnColumn := field.(*entity.ColumnInt64).Data()
+ if len(warnColumn) > 0 {
+ record.IsWarning = warnColumn[i]
+ }
+ case "detect_time":
+ DetectTimeColumn := field.(*entity.ColumnVarChar).Data()
+ if len(DetectTimeColumn) > 0 {
+ record.DetectTime = DetectTimeColumn[i]
+ }
+ case "knowledge_id":
+ KnowledgeIdColumn := field.(*entity.ColumnInt64Array).Data()
+ if len(KnowledgeIdColumn) > 0 {
+ record.KnowledgeId = KnowledgeIdColumn[i]
+ }
+ case "suggestion":
+ SuggestionColumn := field.(*entity.ColumnVarChar).Data()
+ if len(SuggestionColumn) > 0 {
+ record.Suggestion = SuggestionColumn[i]
+ }
+ case "risk_description":
+ RiskDescriptionColumn := field.(*entity.ColumnVarChar).Data()
+ if len(RiskDescriptionColumn) > 0 {
+ record.RiskDescription = RiskDescriptionColumn[i]
+ }
+ }
+ }
+ records = append(records, record)
+ }
+ return records
+}
+
+// 鍒嗛〉鏌ヨ
+func (do *DataOperator) queryWithPagination(collectionName string, filterExpr string, pageNum int64, pageSize int64) (*PaginatedResult, error) {
+ ctx := context.Background()
+
+ // 璁$畻鍋忕Щ閲�
+ //offset := (pageNum - 1) * pageSize
+
+ // 鏋勫缓鏌ヨ琛ㄨ揪寮忥紙Milvus 2.1+ 鏀寔 limit/offset锛�
+ //queryExpr := fmt.Sprintf("%s limit %d offset %d", filterExpr, pageSize, offset)
+
+ total, err := do.getTotalCount(collectionName, filterExpr)
+ if err != nil {
+ return nil, err
+ }
+
+ // 璁$畻鎬婚〉鏁�
+ totalPages := int(math.Ceil(float64(total) / float64(pageSize)))
+
+ // 鎵ц鏌ヨ
+ result, err := do.client.client.Query(
+ ctx,
+ collectionName,
+ []string{}, // 鎵�鏈夊垎鍖�
+ filterExpr,
+ []string{"rule_id", "task_id", "is_waning", "zh_desc_class", "task_name", "event_level_name", "detect_num",
+ "event_level_id", "video_point_id", "detect_id", "image_path",
+ "video_path", "detect_time", "knowledge_id", "risk_description", "suggestion", "id", "is_desc"}, // 杩斿洖鎵�鏈夊瓧娈�
+ // client.WithLimit(pageSize),
+ // client.WithOffset(offset),
+ )
+ if err != nil {
+ return nil, fmt.Errorf("鍒嗛〉鏌ヨ澶辫触: %v", err)
+ }
+ lists := convertResultToMap(result)
+ layout := "2006-01-02 15:04:05.999999"
+
+ var temp1 time.Time
+ var temp2 time.Time
+
+ //鎺掑簭
+ sort.Slice(lists, func(i, j int) bool {
+ //return lists[i].DetectTime > lists[j].:DetectTime
+ temp1, _ = time.Parse(layout, lists[i].DetectTime)
+ temp2, _ = time.Parse(layout, lists[j].DetectTime)
+ return temp1.After(temp2)
+ })
+
+ items := Paginate(lists, int(pageNum), int(pageSize))
+ return &PaginatedResult{
+ Items: items,
+ Pagination: Pagination{
+ Page: int(pageNum),
+ PageSize: int(pageSize),
+ Total: int(total),
+ TotalPage: totalPages,
+ },
+ }, nil
+}
+
+// 鍒嗛〉鏁版嵁
+func Paginate(data []StaticRecord, page, pageSize int) []StaticRecord {
+ start := (page - 1) * pageSize
+ if start >= len(data) {
+ return nil
+ }
+ end := start + pageSize
+ if end > len(data) {
+ end = len(data)
+ }
+ return data[start:end]
+}
+
+// 缁熻鏁伴噺
+func (do *DataOperator) getTotalCount(collectionName string, filterExpr string) (int64, error) {
+ result, err := do.client.client.Query(
+ context.Background(),
+ collectionName,
+ []string{},
+ filterExpr,
+ []string{"count(*)"},
+ )
+ if err != nil {
+ return 0, err
+ }
+ return result[0].(*entity.ColumnInt64).Data()[0], nil
+}
+
+// 鏍规嵁id鑾峰彇浠诲姟
+func GetTaskByIds(ids []int64) (items []TaskOption, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `select task_id,task_name from mal_smart_task where task_id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+ return
+}
+
+// 鏍规嵁id鑾峰彇瑙嗛
+func GetVideoById(vid int64) (video Camera, err error) {
+ // 濡傛灉杩斿洖鐨勬槸鎸囬拡,闇�瑕佸垵濮嬪寲
+ sqlStr := "select id,name,alias,type,addr,rtsp,is_running,run_type,run_enable FROM cameras where video_id=?"
+ if err := db.Raw(sqlStr, vid).Scan(&video).Error; err != nil {
+ return Camera{}, err
+ }
+ return
+}
+
+// 鏍规嵁id鑾峰彇妫�娴嬪唴瀹�
+func GetCheckByIds(ids []int64) (items []CheckOption, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `select check_id,file_name from mal_check_content where check_id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+ return
+}
+
+// 鏍规嵁id鑾峰彇瑙勫垯
+func GetRuleByIds(ids []int64) (items []RuleOption, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `select rule_id,file_name from mal_warning_rule where rule_id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+ return
+}
+
+// 鑾峰彇浜嬩欢
+func GetEventByIds(ids []int64) (items []DictOption, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `select dict_id,dict_name,dict_value from mal_dict_type where dict_id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+
+ return
+
+}
+
+// 鏍规嵁鐭ヨ瘑搴搃d鏌ユ暟鎹�
+func GetKnowledgeDocumentByIds(ids []int64) (items []KnowledgeDocumentOption, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `SELECT id, know_id, file_name as title FROM mal_knowledge_document where id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+ return
+}
+
+// 鏍规嵁鐭ヨ瘑搴搃d鏌ユ暟鎹�
+func GetCameraIds(ids []string) (items []CameraDto, err error) {
+ placeholders := make([]string, len(ids))
+ args := make([]interface{}, len(ids))
+ for i, id := range ids {
+ placeholders[i] = "?"
+ args[i] = id
+ }
+ sqlStr := `select id,name,alias,type,addr,rtsp,is_running,run_type,run_enable,video_id FROM cameras where id in (` + strings.Join(placeholders, ",") + `)`
+ if err := db.Raw(sqlStr, args...).Scan(&items).Error; err != nil {
+ return nil, err
+ }
+ return
+}
diff --git a/camera-common/models/task.go b/camera-common/models/task.go
index 7c2bfc7..125a838 100644
--- a/camera-common/models/task.go
+++ b/camera-common/models/task.go
@@ -44,3 +44,18 @@
}
return
}
+
+// 鏌ヨ鍒楄〃鏁版嵁
+func GetAllTask() (items []Task, err error) {
+ // 涓绘煡璇QL
+ sqlStr := fmt.Sprintf(`
+ SELECT task_id, task_name
+ FROM mal_smart_task
+ ORDER BY task_id DESC
+ `)
+ if err := db.Raw(sqlStr).Scan(&items).Error; err != nil {
+ fmt.Println(err.Error())
+ return nil, err
+ }
+ return
+}
diff --git a/camera-service/controllers/camera.go b/camera-service/controllers/camera.go
index fe88085..ab1785d 100644
--- a/camera-service/controllers/camera.go
+++ b/camera-service/controllers/camera.go
@@ -1211,3 +1211,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.Task
+ tasks, _ = models.GetAllTask()
+
+ return &bhomeclient.Reply{Success: true, Msg: "鑾峰彇鎴愬姛", Data: tasks}
+
+}
diff --git a/camera-service/main.go b/camera-service/main.go
index 7f75991..63b71ca 100644
--- a/camera-service/main.go
+++ b/camera-service/main.go
@@ -133,6 +133,8 @@
//鑾峰彇浠诲姟鏍规嵁鎽勫儚鏈篿ds
funcMap[urlPrefix+"/camera/getTasks"] = cc.GetTasks
+ funcMap[urlPrefix+"/task/aggregateTaskList"] = cc.GetAllTasks
+
var pubTopics []string
for key, _ := range funcMap {
pubTopics = append(pubTopics, key)
diff --git a/camera-service/models/milvus.go b/camera-service/models/milvus.go
index 40f72de..0122ec7 100644
--- a/camera-service/models/milvus.go
+++ b/camera-service/models/milvus.go
@@ -1,63 +1,63 @@
-package models
-
-import (
- "context"
- "fmt"
- "log"
- "vamicro/api-gateway/models"
- commonModels "vamicro/camera-common/models"
-
- "github.com/milvus-io/milvus-sdk-go/v2/client"
-)
-
-var dbClient *MilvusClient
-
-// MilvusClient 灏佽Milvus鎿嶄綔鐨勭粨鏋勪綋
-type MilvusClient struct {
- client client.Client
-}
-
-// NewMilvusClient 鍒涘缓Milvus瀹㈡埛绔�
-func NewMilvusClient(ctx context.Context, addr string) (*MilvusClient, error) {
- milvusClient, err := client.NewGrpcClient(ctx, addr)
- if err != nil {
- return nil, fmt.Errorf("failed to connect to Milvus: %v", err)
- }
- return &MilvusClient{client: milvusClient}, nil
-}
-
-// Close 鍏抽棴杩炴帴
-func (m *MilvusClient) Close() error {
- return m.client.Close()
-}
-
-// 鍒濆鍖杕ilvus
-func InitVectorDb() {
- // 杩炴帴鍒癕ilvus鏈嶅姟鍣�
- ctx := context.Background()
- //milvusClient, err := NewMilvusClient(ctx, "192.168.1.232:19530")
-
- config := models.GetConfig()
- url := config.MilvusUrl
-
- milvusClient, err := NewMilvusClient(ctx, url)
- if err != nil {
- log.Fatal("Failed to connect to Milvus:", err)
- }
- //defer milvusClient.client.Close()
-
- fmt.Println("Successfully connected to Milvus")
-
- //鍒濆鍖�
- dbClient = milvusClient
- commonModels.SetClientDB(dbClient.client)
-}
-
-// GetDB ...
-func GetDBCient() *MilvusClient {
- return dbClient
-}
-
-func CloseDBClient() {
- dbClient.Close()
-}
+package models
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "vamicro/api-gateway/models"
+ commonModels "vamicro/camera-common/models"
+
+ "github.com/milvus-io/milvus-sdk-go/v2/client"
+)
+
+var dbClient *MilvusClient
+
+// MilvusClient 灏佽Milvus鎿嶄綔鐨勭粨鏋勪綋
+type MilvusClient struct {
+ client client.Client
+}
+
+// NewMilvusClient 鍒涘缓Milvus瀹㈡埛绔�
+func NewMilvusClient(ctx context.Context, addr string) (*MilvusClient, error) {
+ milvusClient, err := client.NewGrpcClient(ctx, addr)
+ if err != nil {
+ return nil, fmt.Errorf("failed to connect to Milvus: %v", err)
+ }
+ return &MilvusClient{client: milvusClient}, nil
+}
+
+// Close 鍏抽棴杩炴帴
+func (m *MilvusClient) Close() error {
+ return m.client.Close()
+}
+
+// 鍒濆鍖杕ilvus
+func InitVectorDb() {
+ // 杩炴帴鍒癕ilvus鏈嶅姟鍣�
+ ctx := context.Background()
+ //milvusClient, err := NewMilvusClient(ctx, "192.168.1.232:19530")
+
+ config := models.GetConfig()
+ url := config.MilvusUrl
+
+ milvusClient, err := NewMilvusClient(ctx, url)
+ if err != nil {
+ log.Fatal("Failed to connect to Milvus:", err)
+ }
+ //defer milvusClient.client.Close()
+
+ fmt.Println("Successfully connected to Milvus")
+
+ //鍒濆鍖�
+ dbClient = milvusClient
+ commonModels.SetClientDB(dbClient.client)
+}
+
+// GetDB ...
+func GetDBCient() *MilvusClient {
+ return dbClient
+}
+
+func CloseDBClient() {
+ dbClient.Close()
+}
diff --git a/chanmanage-service/models/camera.go b/chanmanage-service/models/camera.go
index 5b77606..cf6ea4e 100644
--- a/chanmanage-service/models/camera.go
+++ b/chanmanage-service/models/camera.go
@@ -1,76 +1,76 @@
-package models
-
-import (
- "fmt"
- "strings"
- "vamicro/camera-common/models"
-)
-
-// 鏌ヨ鍒楄〃鏁版嵁
-func GetListTask(ids []string) (items []models.TaskM, err error) {
-
- //idList := strings.Join(ids, ",")
- idList := "'" + strings.Join(ids, "','") + "'"
- // 涓绘煡璇QL
- //sqlStr := `select c.task_id, c.task_name from mal_task_video_link a left join mal_smart_task c on a.task_id = c.task_id where a.video_id in(?) ORDER BY a.task_id desc`
- sqlStr := fmt.Sprintf(`
- SELECT c.task_id, c.task_name,c.task_description,b.dict_value as event_name
- FROM mal_task_video_link a
- LEFT JOIN mal_smart_task c ON a.task_id = c.task_id
- LEFT JOIN mal_dict_type b ON b.dict_id = c.event_level
- WHERE a.video_id IN (%s)
- ORDER BY a.task_id DESC
- `, idList)
- if err := db2.Raw(sqlStr).Scan(&items).Error; err != nil {
- fmt.Println(err.Error())
- return nil, err
- }
- return
-}
-
-func GetAllRule() map[int64]string {
- var items []models.RuleOption
- sqlStr := `
- SELECT a.file_name,a.rule_id,b.task_id
- FROM mal_warning_rule a
- LEFT JOIN mal_task_rule_link b ON a.rule_id = b.rule_id
- WHERE task_id>0
- group BY a.rule_id
- `
- if err := db2.Raw(sqlStr).Scan(&items).Error; err != nil {
- fmt.Println(err.Error())
- return nil
- }
-
- ruleMap := make(map[int64]string)
- for _, d2 := range items {
- if d2.TaskId > 0 {
- ruleMap[d2.TaskId] = d2.FileName
- }
- }
- return ruleMap
-}
-
-type VideoLink struct {
- ID int `gorm:"column:id" json:"id"`
- VideoId string `gorm:"column:video_id" json:"videoId"`
- TaskId int `gorm:"column:task_id" json:"taskId"`
-}
-
-func GetTasks() map[string][]interface{} {
-
- var lists []VideoLink
- sqlStr := `select id,video_id,task_id from mal_task_video_link`
- if err := db2.Raw(sqlStr).Scan(&lists).Error; err != nil {
- fmt.Println(err.Error())
- return nil
- }
-
- checkMap := make(map[string][]interface{})
- for _, d2 := range lists {
- if d2.VideoId != "" {
- checkMap[d2.VideoId] = append(checkMap[d2.VideoId], d2)
- }
- }
- return checkMap
-}
+package models
+
+import (
+ "fmt"
+ "strings"
+ "vamicro/camera-common/models"
+)
+
+// 鏌ヨ鍒楄〃鏁版嵁
+func GetListTask(ids []string) (items []models.TaskM, err error) {
+
+ //idList := strings.Join(ids, ",")
+ idList := "'" + strings.Join(ids, "','") + "'"
+ // 涓绘煡璇QL
+ //sqlStr := `select c.task_id, c.task_name from mal_task_video_link a left join mal_smart_task c on a.task_id = c.task_id where a.video_id in(?) ORDER BY a.task_id desc`
+ sqlStr := fmt.Sprintf(`
+ SELECT c.task_id, c.task_name,c.task_description,b.dict_value as event_name
+ FROM mal_task_video_link a
+ LEFT JOIN mal_smart_task c ON a.task_id = c.task_id
+ LEFT JOIN mal_dict_type b ON b.dict_id = c.event_level
+ WHERE a.video_id IN (%s)
+ ORDER BY a.task_id DESC
+ `, idList)
+ if err := db2.Raw(sqlStr).Scan(&items).Error; err != nil {
+ fmt.Println(err.Error())
+ return nil, err
+ }
+ return
+}
+
+func GetAllRule() map[int64]string {
+ var items []models.RuleOption
+ sqlStr := `
+ SELECT a.file_name,a.rule_id,b.task_id
+ FROM mal_warning_rule a
+ LEFT JOIN mal_task_rule_link b ON a.rule_id = b.rule_id
+ WHERE task_id>0
+ group BY a.rule_id
+ `
+ if err := db2.Raw(sqlStr).Scan(&items).Error; err != nil {
+ fmt.Println(err.Error())
+ return nil
+ }
+
+ ruleMap := make(map[int64]string)
+ for _, d2 := range items {
+ if d2.TaskId > 0 {
+ ruleMap[d2.TaskId] = d2.FileName
+ }
+ }
+ return ruleMap
+}
+
+type VideoLink struct {
+ ID int `gorm:"column:id" json:"id"`
+ VideoId string `gorm:"column:video_id" json:"videoId"`
+ TaskId int `gorm:"column:task_id" json:"taskId"`
+}
+
+func GetTasks() map[string][]interface{} {
+
+ var lists []VideoLink
+ sqlStr := `select id,video_id,task_id from mal_task_video_link`
+ if err := db2.Raw(sqlStr).Scan(&lists).Error; err != nil {
+ fmt.Println(err.Error())
+ return nil
+ }
+
+ checkMap := make(map[string][]interface{})
+ for _, d2 := range lists {
+ if d2.VideoId != "" {
+ checkMap[d2.VideoId] = append(checkMap[d2.VideoId], d2)
+ }
+ }
+ return checkMap
+}
diff --git a/push-service/controllers/pushSet.go b/push-service/controllers/pushSet.go
index a7c59a8..1387a8e 100644
--- a/push-service/controllers/pushSet.go
+++ b/push-service/controllers/pushSet.go
@@ -1,10 +1,11 @@
package controllers
import (
- "basic.com/valib/bhomeclient.git"
- "basic.com/valib/logger.git"
"vamicro/config"
"vamicro/push-service/vo"
+
+ "basic.com/valib/bhomeclient.git"
+ "basic.com/valib/logger.git"
)
type PushSetController struct {
@@ -36,18 +37,32 @@
{Checked: true, Id: "cameraAddr", Name: "鎽勫儚鏈哄湴鍧�", Alias: "cameraAddr"},
},
}
- sceneInfoSet := vo.PushSetMenu{
- Id: "alarmRules", //鎶ヨ瑙勫垯
- Name: "鍦烘櫙淇℃伅",
- Alias: "alarmRules",
+ // sceneInfoSet := vo.PushSetMenu{
+ // Id: "alarmRules", //鎶ヨ瑙勫垯
+ // Name: "鍦烘櫙淇℃伅",
+ // Alias: "alarmRules",
+ // Checked: true,
+ // Children: []vo.PushSetMenu{
+ // {Checked: true, Id: "taskId", Name: "鍦烘櫙ID", Alias: "taskId"},
+ // {Checked: true, Id: "taskName", Name: "鍦烘櫙鍚嶇О", Alias: "taskName"},
+ // {Checked: true, Id: "alarmRules.#.alarmLevel", Name: "浜嬩欢绛夌骇", Alias: "alarmLevel"},
+ // {Checked: true, Id: "alarmRules.#.ruleText", Name: "鍦烘櫙鎻忚堪", Alias: "groupText"},
+ // {Checked: true, Id: "alarmRules.#.linkInfo", Name: "鑱斿姩淇℃伅", Alias: "linkInfo"},
+ // {Checked: true, Id: "alarmRules.#.groupId", Name: "鎶ヨ瑙勫垯缁刬d", Alias: "groupId"},
+ // },
+ // }
+ taskInfoSet := vo.PushSetMenu{
+ Id: "aiTasks", //ai浠诲姟
+ Name: "浠诲姟淇℃伅",
+ Alias: "aiTasks",
Checked: true,
Children: []vo.PushSetMenu{
- {Checked: true, Id: "taskId", Name: "鍦烘櫙ID", Alias: "taskId"},
- {Checked: true, Id: "taskName", Name: "鍦烘櫙鍚嶇О", Alias: "taskName"},
- {Checked: true, Id: "alarmRules.#.alarmLevel", Name: "浜嬩欢绛夌骇", Alias: "alarmLevel"},
- {Checked: true, Id: "alarmRules.#.ruleText", Name: "鍦烘櫙鎻忚堪", Alias: "groupText"},
- {Checked: true, Id: "alarmRules.#.linkInfo", Name: "鑱斿姩淇℃伅", Alias: "linkInfo"},
- {Checked: true, Id: "alarmRules.#.groupId", Name: "鎶ヨ瑙勫垯缁刬d", Alias: "groupId"},
+ {Checked: true, Id: "taskId", Name: "浠诲姟id", Alias: "taskId"},
+ {Checked: true, Id: "taskName", Name: "浠诲姟鍚嶇О", Alias: "taskName"},
+ {Checked: true, Id: "aiTasks.#.eventLevel", Name: "浜嬩欢绛夌骇", Alias: "eventLevel"},
+ {Checked: true, Id: "aiTasks.#.workingTime", Name: "鏃堕棿娈�", Alias: "workingTime"},
+ {Checked: true, Id: "aiTasks.#.rules", Name: "浠诲姟鎻忚堪", Alias: "rules"},
+ {Checked: true, Id: "aiTasks.#.taskDescription", Name: "澶囨敞", Alias: "taskDescription"},
},
}
serverSet := vo.PushSetMenu{
@@ -87,57 +102,58 @@
{Checked: true, Id: "isAlarm", Name: "鏄惁鎶ヨ", Alias: "isAlarm"},
},
}
- detectAreaSet := vo.PushSetMenu{
- Id: "detectAreaInfo",
- Name: "妫�娴嬪尯鍩�",
- Alias: "detectAreaInfo",
- Checked: true,
- Children: []vo.PushSetMenu{
- {Checked: true, Id: "targetInfo.#.areaId", Name: "妫�娴嬪尯鍩焛d", Alias: "areaId"},
- {Checked: true, Id: "targetInfo.#.areaName", Name: "妫�娴嬪尯鍩熷悕绉�", Alias: "areaName"},
- },
- }
- targetSet := vo.PushSetMenu{
- Id: "targetInfo",
- Name: "鐩爣",
- Alias: "targetInfo",
- Checked: true,
- Children: []vo.PushSetMenu{
- {Checked: true, Id: "targetInfo.#.attribute", Name: "绠楁硶灞炴��", Alias: "attribute"},
- {Checked: true, Id: "targetInfo.#.targetLocation", Name: "鐩爣鍧愭爣", Alias: "targetLocation"},
- {Checked: true, Id: "targetInfo.#.targetScore", Name: "鐩爣缃俊搴�", Alias: "targetScore"},
- {Checked: true, Id: "targetInfo.#.targetType", Name: "鐩爣绫诲埆", Alias: "targetType"},
- },
- }
- dtSet := vo.PushSetMenu{
- Id: "tableInfo",
- Name: "搴曞簱淇℃伅",
- Alias: "tableInfo",
- Checked: true,
- Children: []vo.PushSetMenu{
- {Checked: true, Id: "baseInfo.#.tableId", Name: "搴曞簱ID", Alias: "tableId"},
- {Checked: true, Id: "baseInfo.#.tableName", Name: "搴曞簱鍚嶇О", Alias: "tableName"},
- {Checked: true, Id: "baseInfo.#.bwType", Name: "榛戠櫧鍚嶅崟", Alias: "bwType"},
- {Checked: true, Id: "baseInfo.#.targetPicUrl", Name: "鐩爣鎶撴媿鍥剧墖", Alias: "targetPicUrl"},
- {Checked: true, Id: "baseInfo.#.compareScore", Name: "鐩镐技搴�", Alias: "compareScore"},
- {Checked: true, Id: "baseInfo.#.content", Name: "鍐呭", Alias: "content"},
- },
- }
- dbpInfo := vo.PushSetMenu{
- Id: "baseInfo",
- Name: "搴曞簱浜哄憳淇℃伅",
- Alias: "baseInfo",
- Checked: true,
- Children: []vo.PushSetMenu{
- {Checked: true, Id: "baseInfo.#.targetId", Name: "鐩爣ID", Alias: "targetId"},
- {Checked: true, Id: "baseInfo.#.targetName", Name: "濮撳悕", Alias: "targetName"},
- {Checked: true, Id: "baseInfo.#.sex", Name: "鎬у埆", Alias: "sex"},
- {Checked: true, Id: "baseInfo.#.idCard", Name: "韬唤璇佸彿", Alias: "idCard"},
- {Checked: true, Id: "baseInfo.#.phoneNum", Name: "鎵嬫満鍙�", Alias: "phoneNum"},
- {Checked: true, Id: "baseInfo.#.monitorLevel", Name: "浜哄憳绛夌骇", Alias: "monitorLevel"},
- },
- }
- set = append(set, camInfoSet, sceneInfoSet, serverSet, dataSet, detectAreaSet, targetSet, dtSet, dbpInfo)
+ // detectAreaSet := vo.PushSetMenu{
+ // Id: "detectAreaInfo",
+ // Name: "妫�娴嬪尯鍩�",
+ // Alias: "detectAreaInfo",
+ // Checked: true,
+ // Children: []vo.PushSetMenu{
+ // {Checked: true, Id: "targetInfo.#.areaId", Name: "妫�娴嬪尯鍩焛d", Alias: "areaId"},
+ // {Checked: true, Id: "targetInfo.#.areaName", Name: "妫�娴嬪尯鍩熷悕绉�", Alias: "areaName"},
+ // },
+ // }
+ // targetSet := vo.PushSetMenu{
+ // Id: "targetInfo",
+ // Name: "鐩爣",
+ // Alias: "targetInfo",
+ // Checked: true,
+ // Children: []vo.PushSetMenu{
+ // {Checked: true, Id: "targetInfo.#.attribute", Name: "绠楁硶灞炴��", Alias: "attribute"},
+ // {Checked: true, Id: "targetInfo.#.targetLocation", Name: "鐩爣鍧愭爣", Alias: "targetLocation"},
+ // {Checked: true, Id: "targetInfo.#.targetScore", Name: "鐩爣缃俊搴�", Alias: "targetScore"},
+ // {Checked: true, Id: "targetInfo.#.targetType", Name: "鐩爣绫诲埆", Alias: "targetType"},
+ // },
+ // }
+ // dtSet := vo.PushSetMenu{
+ // Id: "tableInfo",
+ // Name: "搴曞簱淇℃伅",
+ // Alias: "tableInfo",
+ // Checked: true,
+ // Children: []vo.PushSetMenu{
+ // {Checked: true, Id: "baseInfo.#.tableId", Name: "搴曞簱ID", Alias: "tableId"},
+ // {Checked: true, Id: "baseInfo.#.tableName", Name: "搴曞簱鍚嶇О", Alias: "tableName"},
+ // {Checked: true, Id: "baseInfo.#.bwType", Name: "榛戠櫧鍚嶅崟", Alias: "bwType"},
+ // {Checked: true, Id: "baseInfo.#.targetPicUrl", Name: "鐩爣鎶撴媿鍥剧墖", Alias: "targetPicUrl"},
+ // {Checked: true, Id: "baseInfo.#.compareScore", Name: "鐩镐技搴�", Alias: "compareScore"},
+ // {Checked: true, Id: "baseInfo.#.content", Name: "鍐呭", Alias: "content"},
+ // },
+ // }
+ // dbpInfo := vo.PushSetMenu{
+ // Id: "baseInfo",
+ // Name: "搴曞簱浜哄憳淇℃伅",
+ // Alias: "baseInfo",
+ // Checked: true,
+ // Children: []vo.PushSetMenu{
+ // {Checked: true, Id: "baseInfo.#.targetId", Name: "鐩爣ID", Alias: "targetId"},
+ // {Checked: true, Id: "baseInfo.#.targetName", Name: "濮撳悕", Alias: "targetName"},
+ // {Checked: true, Id: "baseInfo.#.sex", Name: "鎬у埆", Alias: "sex"},
+ // {Checked: true, Id: "baseInfo.#.idCard", Name: "韬唤璇佸彿", Alias: "idCard"},
+ // {Checked: true, Id: "baseInfo.#.phoneNum", Name: "鎵嬫満鍙�", Alias: "phoneNum"},
+ // {Checked: true, Id: "baseInfo.#.monitorLevel", Name: "浜哄憳绛夌骇", Alias: "monitorLevel"},
+ // },
+ // }
+ // set = append(set, camInfoSet, sceneInfoSet, serverSet, dataSet, detectAreaSet, targetSet, dtSet, dbpInfo)
+ set = append(set, camInfoSet, taskInfoSet, serverSet, dataSet)
return &bhomeclient.Reply{Success: true, Data: set}
}
diff --git a/push-service/models/eventPush.go b/push-service/models/eventPush.go
index 05e6975..406c69b 100644
--- a/push-service/models/eventPush.go
+++ b/push-service/models/eventPush.go
@@ -3,6 +3,7 @@
type EventPush struct {
Id string `gorm:"primary_key;column:id" json:"id"`
Name string `gorm:"column:name" json:"name"`
+ PushType int `gorm:"column:push_type" json:"push_type"`
TimeStart string `gorm:"column:time_start" json:"time_start"`
TimeEnd string `gorm:"column:time_end" json:"time_end"`
IsSatisfyAll bool `gorm:"column:is_satisfy_all" json:"is_satisfy_all"`
diff --git a/push-service/service/eventPushService.go b/push-service/service/eventPushService.go
index c36b6b9..ce7fccb 100644
--- a/push-service/service/eventPushService.go
+++ b/push-service/service/eventPushService.go
@@ -1,16 +1,17 @@
package service
import (
- "basic.com/pubsub/protomsg.git"
- "basic.com/valib/bhomeclient.git"
- "basic.com/valib/bhomedbapi.git"
"encoding/json"
"errors"
- "github.com/satori/go.uuid"
"vamicro/extend/util"
"vamicro/push-service/models"
"vamicro/push-service/vo"
sysModel "vamicro/system-service/models"
+
+ "basic.com/pubsub/protomsg.git"
+ "basic.com/valib/bhomeclient.git"
+ "basic.com/valib/bhomedbapi.git"
+ uuid "github.com/satori/go.uuid"
)
type EventPushService struct {
diff --git a/push-service/vo/eventPush.go b/push-service/vo/eventPush.go
index 9e14072..95e3628 100644
--- a/push-service/vo/eventPush.go
+++ b/push-service/vo/eventPush.go
@@ -7,49 +7,50 @@
)
type EventPushVo struct {
- Id string `json:"id"`
- Name string `json:"name"`
- TimeStart string `json:"time_start"`
- TimeEnd string `json:"time_end"`
- IsSatisfyAll bool `json:"is_satisfy_all"`
- RuleText string `json:"rule_text"`
- Enable bool `json:"enable"`
- LinkType string `json:"link_type"`
- LinkDevice string `json:"link_device"`
+ Id string `json:"id"`
+ Name string `json:"name"`
+ PushType int `json:"push_type"`
+ TimeStart string `json:"time_start"`
+ TimeEnd string `json:"time_end"`
+ IsSatisfyAll bool `json:"is_satisfy_all"`
+ RuleText string `json:"rule_text"`
+ Enable bool `json:"enable"`
+ LinkType string `json:"link_type"`
+ LinkDevice string `json:"link_device"`
- IpPorts []EventPushServerPortVo `json:"ip_ports"`
- Urls []EventUrlVo `json:"urls"`
- Rules []models.EventPushRule `json:"rules"`
+ IpPorts []EventPushServerPortVo `json:"ip_ports"`
+ Urls []EventUrlVo `json:"urls"`
+ Rules []models.EventPushRule `json:"rules"`
- FiltRename map[string]string `json:"filtRename"`
- PushSet []PushSetMenu `json:"push_set"`
+ FiltRename map[string]string `json:"filtRename"`
+ PushSet []PushSetMenu `json:"push_set"`
}
type PushSetMenu struct {
- Id string `json:"id"`
- Name string `json:"name"`
- Checked bool `json:"checked"`
- Alias string `json:"alias"`
- Children []PushSetMenu `json:"children"`
+ Id string `json:"id"`
+ Name string `json:"name"`
+ Checked bool `json:"checked"`
+ Alias string `json:"alias"`
+ Children []PushSetMenu `json:"children"`
}
type EventPushServerPortVo struct {
ServerIp string `json:"server_ip"`
- Port int `json:"port"`
- Enable bool `json:"enable"`
+ Port int `json:"port"`
+ Enable bool `json:"enable"`
}
type EventUrlVo struct {
- Url string `json:"url"`
- Enable bool `json:"enable"`
+ Url string `json:"url"`
+ Enable bool `json:"enable"`
}
func (epv *EventPushVo) SetFiltRename() {
epv.FiltRename = make(map[string]string)
if epv.PushSet != nil {
- for _,set := range epv.PushSet {
- if set.Children !=nil {
- for _,child := range set.Children {
+ for _, set := range epv.PushSet {
+ if set.Children != nil {
+ for _, child := range set.Children {
if child.Checked {
prefix := ""
idx := strings.LastIndex(child.Id, ".")
@@ -65,34 +66,36 @@
}
func (epv *EventPushVo) CopyToEventPush() models.EventPush {
- d,_ := json.Marshal(epv.PushSet)
+ d, _ := json.Marshal(epv.PushSet)
return models.EventPush{
- Id:epv.Id,
- Name:epv.Name,
- TimeStart:epv.TimeStart,
- TimeEnd:epv.TimeEnd,
- IsSatisfyAll:epv.IsSatisfyAll,
- RuleText:epv.RuleText,
- Enable:epv.Enable,
- LinkType:epv.LinkType,
- LinkDevice:epv.LinkDevice,
- PushSet: string(d),
+ Id: epv.Id,
+ Name: epv.Name,
+ TimeStart: epv.TimeStart,
+ TimeEnd: epv.TimeEnd,
+ IsSatisfyAll: epv.IsSatisfyAll,
+ RuleText: epv.RuleText,
+ Enable: epv.Enable,
+ PushType: epv.PushType,
+ LinkType: epv.LinkType,
+ LinkDevice: epv.LinkDevice,
+ PushSet: string(d),
}
}
-func (epv *EventPushVo) CopyFromEventPush(epE *models.EventPush){
+func (epv *EventPushVo) CopyFromEventPush(epE *models.EventPush) {
epv.Id = epE.Id
epv.Name = epE.Name
epv.TimeStart = epE.TimeStart
epv.TimeEnd = epE.TimeEnd
epv.IsSatisfyAll = epE.IsSatisfyAll
+ epv.PushType = epE.PushType
epv.RuleText = epE.RuleText
epv.Enable = epE.Enable
epv.LinkType = epE.LinkType
epv.LinkDevice = epE.LinkDevice
if epE.PushSet != "" {
var set []PushSetMenu
- if err := json.Unmarshal([]byte(epE.PushSet), &set);err == nil {
+ if err := json.Unmarshal([]byte(epE.PushSet), &set); err == nil {
epv.PushSet = set
} else {
epv.PushSet = make([]PushSetMenu, 0)
@@ -102,8 +105,7 @@
}
}
-
type KeyValueVo struct {
Value string `json:"value"`
- Name string `json:"name"`
-}
\ No newline at end of file
+ Name string `json:"name"`
+}
diff --git a/search-service/main.go b/search-service/main.go
index 0b429d0..9c0c8a5 100644
--- a/search-service/main.go
+++ b/search-service/main.go
@@ -1,10 +1,6 @@
package main
import (
- "basic.com/valib/bhomeclient.git"
- "basic.com/valib/bhomedbapi.git"
- "basic.com/valib/logger.git"
- "basic.com/valib/version.git"
"context"
"flag"
"os"
@@ -12,6 +8,11 @@
"syscall"
"vamicro/config"
"vamicro/search-service/controllers"
+
+ "basic.com/valib/bhomeclient.git"
+ "basic.com/valib/bhomedbapi.git"
+ "basic.com/valib/logger.git"
+ vaversion "basic.com/valib/version.git"
)
var (
@@ -71,7 +72,7 @@
func initFuncMap() (map[string]bhomeclient.MicroFunc, []string) {
funcMap := make(map[string]bhomeclient.MicroFunc)
sc := new(controllers.EsSearchController)
- tc := new(controllers.TaskController)
+ // tc := new(controllers.TaskController)
funcMap[urlPrefix+"/dbperson/faceExtract"] = sc.FaceExtract
funcMap[urlPrefix+"/dbperson/searchByPhoto"] = sc.SearchByPhoto
@@ -79,7 +80,7 @@
funcMap[urlPrefix+"/es/esSearch"] = sc.PostEsSearch
funcMap[urlPrefix+"/es/tagList"] = sc.PostEsTagList
funcMap[urlPrefix+"/es/taskList"] = sc.PostEsTaskList
- funcMap[urlPrefix+"/task/aggregateTaskList"] = tc.AggregateTaskList
+ // funcMap[urlPrefix+"/task/aggregateTaskList"] = tc.AggregateTaskList
funcMap[urlPrefix+"/es/collect"] = sc.Collect
funcMap[urlPrefix+"/es/deleteById"] = sc.PostEsDelete
funcMap[urlPrefix+"/es/signMisreport"] = sc.SignMisreport
diff --git a/system-service/controllers/dictionary.go b/system-service/controllers/dictionary.go
index 416f211..a670cc7 100644
--- a/system-service/controllers/dictionary.go
+++ b/system-service/controllers/dictionary.go
@@ -8,36 +8,37 @@
"basic.com/valib/bhomeclient.git"
"basic.com/valib/bhomedbapi.git"
"basic.com/valib/logger.git"
- "github.com/satori/go.uuid"
+ uuid "github.com/satori/go.uuid"
)
type DictionaryController struct {
}
type DicTypeVo struct {
- Type string `json:"type"`
- Dics []DicWithChildren `json:"dics"`
+ Type string `json:"type"`
+ Dics []DicWithChildren `json:"dics"`
}
type DicWithChildren struct {
models.Dictionary
- Children []DicWithChildren `json:"children"`
+ Children []DicWithChildren `json:"children"`
}
type DicList []DicWithChildren
-func (dl DicList) Len()int {
+
+func (dl DicList) Len() int {
return len(dl)
}
-func (dl DicList) Swap(i,j int) {
- dl[i],dl[j] = dl[j],dl[i]
+func (dl DicList) Swap(i, j int) {
+ dl[i], dl[j] = dl[j], dl[i]
}
-func (dl DicList) Less(i,j int) bool {
+func (dl DicList) Less(i, j int) bool {
return dl[i].Sort < dl[j].Sort
}
func recursiveChildren(parentId string, allList *[]models.Dictionary) []DicWithChildren {
var children = make([]DicWithChildren, 0)
- for _,d := range *allList {
+ for _, d := range *allList {
if d.ParentId == parentId {
dwc := DicWithChildren{}
dwc.Dictionary = d
@@ -70,7 +71,7 @@
resMap := make(map[string]DicList, 0)
wg := &sync.WaitGroup{}
- wg.Add(4)
+ wg.Add(2)
go func() {
defer wg.Done()
for _, dic := range allDics {
@@ -102,47 +103,47 @@
}
}
}()
- //浜哄憳搴曞簱
- personTableList := make(DicList, 0)
- var tableApi bhomedbapi.DbTableApi
- go func() {
- defer wg.Done()
- personTables, dtErr := tableApi.FindAllDbTablesByType("0", "person")
- if dtErr == nil && personTables != nil {
- for idx, t := range personTables {
- dwc := DicWithChildren{}
- dwc.Dictionary = models.Dictionary{
- Value: t.Id,
- Name: t.TableName,
- Sort: idx + 1,
- }
- personTableList = append(personTableList, dwc)
- }
- }
- }()
- // 杞﹁締搴曞簱
- carTableList := make(DicList, 0)
- go func() {
- defer wg.Done()
- carTables, _ := tableApi.FindAllDbTablesByType("0", "car")
- if carTables != nil {
- for idx, t := range carTables {
- dwc := DicWithChildren{}
- dwc.Dictionary = models.Dictionary{
- Value: t.Id,
- Name: t.TableName,
- Sort: idx + 1,
- }
- carTableList = append(carTableList, dwc)
- }
- }
- }()
+ // //浜哄憳搴曞簱
+ // personTableList := make(DicList, 0)
+ // var tableApi bhomedbapi.DbTableApi
+ // go func() {
+ // defer wg.Done()
+ // personTables, dtErr := tableApi.FindAllDbTablesByType("0", "person")
+ // if dtErr == nil && personTables != nil {
+ // for idx, t := range personTables {
+ // dwc := DicWithChildren{}
+ // dwc.Dictionary = models.Dictionary{
+ // Value: t.Id,
+ // Name: t.TableName,
+ // Sort: idx + 1,
+ // }
+ // personTableList = append(personTableList, dwc)
+ // }
+ // }
+ // }()
+ // // 杞﹁締搴曞簱
+ // carTableList := make(DicList, 0)
+ // go func() {
+ // defer wg.Done()
+ // carTables, _ := tableApi.FindAllDbTablesByType("0", "car")
+ // if carTables != nil {
+ // for idx, t := range carTables {
+ // dwc := DicWithChildren{}
+ // dwc.Dictionary = models.Dictionary{
+ // Value: t.Id,
+ // Name: t.TableName,
+ // Sort: idx + 1,
+ // }
+ // carTableList = append(carTableList, dwc)
+ // }
+ // }
+ // }()
wg.Wait()
resMap["time_rule"] = timeList
- resMap["compareBase"] = personTableList
- resMap["compareCarBase"] = carTableList
+ // resMap["compareBase"] = personTableList
+ // resMap["compareCarBase"] = carTableList
for k, dList := range resMap {
v := dList
@@ -164,7 +165,7 @@
func (controller DictionaryController) FindByParentId(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
parentId := c.Query("parentId")
if parentId == "" {
- return &bhomeclient.Reply{ Msg: "鍙傛暟鏈夎"}
+ return &bhomeclient.Reply{Msg: "鍙傛暟鏈夎"}
}
var model models.Dictionary
if flag, err := model.SelectById(parentId); !flag && err == nil {
@@ -174,20 +175,19 @@
Value: "",
Name: "绌�",
}
- return &bhomeclient.Reply{ Success: true, Data: []models.Dictionary{empty} }
+ return &bhomeclient.Reply{Success: true, Data: []models.Dictionary{empty}}
} else {
dics, err := model.FindByParentId(parentId)
if err != nil {
- return &bhomeclient.Reply{ Msg: "鏌ヨ澶辫触"}
+ return &bhomeclient.Reply{Msg: "鏌ヨ澶辫触"}
} else {
- return &bhomeclient.Reply{ Success:true, Data: dics }
+ return &bhomeclient.Reply{Success: true, Data: dics}
}
}
} else {
- return &bhomeclient.Reply{ Msg: "鏌ヨ澶辫触"}
+ return &bhomeclient.Reply{Msg: "鏌ヨ澶辫触"}
}
}
-
// @Summary 鏍规嵁type鏌ユ壘瀛楀吀鍒楄〃
// @Description 鏍规嵁type鏌ユ壘瀛楀吀鍒楄〃
@@ -200,14 +200,14 @@
func (controller DictionaryController) ListByType(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
typ := c.Query("type")
if typ == "" {
- return &bhomeclient.Reply{ Msg: "鍙傛暟鏈夎"}
+ return &bhomeclient.Reply{Msg: "鍙傛暟鏈夎"}
}
var model models.Dictionary
dics, err := model.FindByType(typ)
if err == nil {
- return &bhomeclient.Reply{ Success:true, Data: dics }
+ return &bhomeclient.Reply{Success: true, Data: dics}
} else {
- return &bhomeclient.Reply{ Msg: "鏌ヨ澶辫触"}
+ return &bhomeclient.Reply{Msg: "鏌ヨ澶辫触"}
}
}
@@ -223,7 +223,7 @@
func (controller DictionaryController) Save(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
var model models.Dictionary
if err := c.BindJSON(&model); err != nil {
- return &bhomeclient.Reply{ Msg: "鍙傛暟鏈夎"}
+ return &bhomeclient.Reply{Msg: "鍙傛暟鏈夎"}
}
var flag bool
if model.Id == "" {
@@ -234,8 +234,8 @@
}
if !flag {
- return &bhomeclient.Reply{ Msg: "淇濆瓨澶辫触"}
+ return &bhomeclient.Reply{Msg: "淇濆瓨澶辫触"}
} else {
- return &bhomeclient.Reply{ Success:true, Msg: "淇濆瓨鎴愬姛"}
+ return &bhomeclient.Reply{Success: true, Msg: "淇濆瓨鎴愬姛"}
}
}
--
Gitblit v1.8.0