更新小细节的适配
parent
8bc015a856
commit
5b6c7ec8a4
|
@ -2,5 +2,5 @@
|
||||||
"backendport": 8080,
|
"backendport": 8080,
|
||||||
"name": "node1",
|
"name": "node1",
|
||||||
"database": "initqwe",
|
"database": "initqwe",
|
||||||
"picPath": "/home/backend/picture"
|
"picturePath": "D:/intelligent/intelligent_backend/public/images"
|
||||||
}
|
}
|
|
@ -4,12 +4,10 @@ import (
|
||||||
"go_backend/cmd/config"
|
"go_backend/cmd/config"
|
||||||
"go_backend/internal/api"
|
"go_backend/internal/api"
|
||||||
"go_backend/internal/dbs"
|
"go_backend/internal/dbs"
|
||||||
scheduledtask "go_backend/internal/scheduled_task"
|
|
||||||
"go_backend/internal/utils"
|
"go_backend/internal/utils"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -31,11 +29,14 @@ func main() {
|
||||||
api.CreateDetectionRecord(r.Group(""))
|
api.CreateDetectionRecord(r.Group(""))
|
||||||
api.GetDetectionRecord(r.Group(""))
|
api.GetDetectionRecord(r.Group(""))
|
||||||
api.GetTrajectoryRecordList(r.Group(""))
|
api.GetTrajectoryRecordList(r.Group(""))
|
||||||
println(config.AllConfig.Port)
|
api.GetTargetTrajectory(r.Group(""))
|
||||||
|
api.GetSingleDetectionRecord(r.Group(""))
|
||||||
|
api.GetAllCamerasIncludeFolder(r.Group(""))
|
||||||
|
|
||||||
c := cron.New()
|
r.Static("/images", config.AllConfig.PicturePath)
|
||||||
c.AddFunc("@every 1m", scheduledtask.MergeTrajectory)
|
//c := cron.New()
|
||||||
c.Start()
|
//c.AddFunc("@every 1m", scheduledtask.MergeTrajectory)
|
||||||
|
//c.Start()
|
||||||
|
|
||||||
// _ = r.Run(":" + strconv.Itoa(config.AllConfig.Port))
|
// _ = r.Run(":" + strconv.Itoa(config.AllConfig.Port))
|
||||||
_ = r.Run(":" + strconv.Itoa(8080))
|
_ = r.Run(":" + strconv.Itoa(8080))
|
||||||
|
|
|
@ -5,7 +5,8 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go_backend/internal/dbs"
|
"go_backend/internal/dbs"
|
||||||
"go_backend/internal/model"
|
"go_backend/internal/model"
|
||||||
"go_backend/internal/utils"
|
"gorm.io/gorm"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CameraVO struct {
|
type CameraVO struct {
|
||||||
|
@ -24,10 +25,39 @@ type CameraVO struct {
|
||||||
ChildVO []*CameraVO `json:"child"`
|
ChildVO []*CameraVO `json:"child"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllCameras(router *gin.RouterGroup) {
|
func GetAllCamerasIncludeFolder(router *gin.RouterGroup) {
|
||||||
router.GET("/camerasList", func(c *gin.Context) {
|
router.GET("/camerasList", func(c *gin.Context) {
|
||||||
cameras := make([]model.Camera, 0)
|
|
||||||
db := dbs.GetGormDB()
|
db := dbs.GetGormDB()
|
||||||
|
cameraVOList, _ := getCameraListMethod(false, db)
|
||||||
|
Success(c, cameraVOList)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllCameras(router *gin.RouterGroup) {
|
||||||
|
router.GET("/camerasOnly", func(c *gin.Context) {
|
||||||
|
db := dbs.GetGormDB()
|
||||||
|
_, cameraList := getCameraListMethod(true, db)
|
||||||
|
cameraVOList := make([]*CameraVO, 0)
|
||||||
|
for _, camera := range cameraList {
|
||||||
|
// 查看缓存Map中有无对应address,有的话直接读取
|
||||||
|
var address string
|
||||||
|
cameraId, _ := strconv.Atoi(camera.CameraID)
|
||||||
|
if _, exists := Camera2AddressMap[cameraId]; exists {
|
||||||
|
address = Camera2AddressMap[cameraId]
|
||||||
|
} else {
|
||||||
|
address = mergeAddress(*camera, db)
|
||||||
|
Camera2AddressMap[cameraId] = address
|
||||||
|
}
|
||||||
|
vo := transVO(*camera)
|
||||||
|
vo.DisplayName = address
|
||||||
|
cameraVOList = append(cameraVOList, &vo)
|
||||||
|
}
|
||||||
|
Success(c, cameraVOList)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCameraListMethod(isCameraOnly bool, db *gorm.DB) ([]*CameraVO, []*model.Camera) {
|
||||||
|
cameras := make([]model.Camera, 0)
|
||||||
db.Find(&cameras)
|
db.Find(&cameras)
|
||||||
|
|
||||||
cameraMap := make(map[int][]model.Camera)
|
cameraMap := make(map[int][]model.Camera)
|
||||||
|
@ -36,6 +66,7 @@ func GetAllCameras(router *gin.RouterGroup) {
|
||||||
cameraMap[int(camera.ViewPriority)] = append(cameraMap[(int(camera.ViewPriority))], camera)
|
cameraMap[int(camera.ViewPriority)] = append(cameraMap[(int(camera.ViewPriority))], camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cameraList := make([]*model.Camera, 0)
|
||||||
cameraVOList := make([]*CameraVO, 0)
|
cameraVOList := make([]*CameraVO, 0)
|
||||||
level := 0
|
level := 0
|
||||||
|
|
||||||
|
@ -45,7 +76,13 @@ func GetAllCameras(router *gin.RouterGroup) {
|
||||||
if priority == 0 {
|
if priority == 0 {
|
||||||
for _, camera := range cameraArray {
|
for _, camera := range cameraArray {
|
||||||
vo := transVO(camera)
|
vo := transVO(camera)
|
||||||
|
if isCameraOnly {
|
||||||
|
if camera.Type == "camera" {
|
||||||
|
cameraList = append(cameraList, &camera)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
cameraVOList = append(cameraVOList, &vo)
|
cameraVOList = append(cameraVOList, &vo)
|
||||||
|
}
|
||||||
cameraRecord[int(camera.ID)] = &vo
|
cameraRecord[int(camera.ID)] = &vo
|
||||||
}
|
}
|
||||||
level += 1
|
level += 1
|
||||||
|
@ -59,10 +96,13 @@ func GetAllCameras(router *gin.RouterGroup) {
|
||||||
vo := transVO(camera)
|
vo := transVO(camera)
|
||||||
parentId := vo.ParentCategoryID[len(vo.ParentCategoryID)-1]
|
parentId := vo.ParentCategoryID[len(vo.ParentCategoryID)-1]
|
||||||
if pointer, exists := cameraRecord[parentId]; exists {
|
if pointer, exists := cameraRecord[parentId]; exists {
|
||||||
|
if isCameraOnly {
|
||||||
|
if camera.Type == "camera" {
|
||||||
|
cameraList = append(cameraList, &camera)
|
||||||
|
}
|
||||||
|
}
|
||||||
pointer.ChildVO = append(pointer.ChildVO, &vo)
|
pointer.ChildVO = append(pointer.ChildVO, &vo)
|
||||||
utils.PrintSlice(vo.ParentCategoryID)
|
|
||||||
newParent := make([]int, 0)
|
newParent := make([]int, 0)
|
||||||
utils.PrintSlice(pointer.ParentCategoryID)
|
|
||||||
for _, id := range pointer.ParentCategoryID {
|
for _, id := range pointer.ParentCategoryID {
|
||||||
newParent = append(newParent, id)
|
newParent = append(newParent, id)
|
||||||
}
|
}
|
||||||
|
@ -75,8 +115,7 @@ func GetAllCameras(router *gin.RouterGroup) {
|
||||||
level += 1
|
level += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Success(c, cameraVOList)
|
return cameraVOList, cameraList
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
|
|
|
@ -75,6 +75,42 @@ func GetDetectionRecord(router *gin.RouterGroup) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSingleDetectionRecord(router *gin.RouterGroup) {
|
||||||
|
router.GET("/detection/single", func(c *gin.Context) {
|
||||||
|
detectionRecords := make([]model.PersonDetectionRecord, 0)
|
||||||
|
db := dbs.GetGormDB()
|
||||||
|
db.Limit(1).Find(&detectionRecords)
|
||||||
|
detectionVOS := make([]DetectionVO, 0)
|
||||||
|
// 搜索对应的摄像头
|
||||||
|
record := detectionRecords[0]
|
||||||
|
var cameras []model.Camera
|
||||||
|
cameraId, _ := strconv.Atoi(record.CameraID)
|
||||||
|
result := db.Model(model.Camera{}).
|
||||||
|
Where("camera_id = ?", cameraId).
|
||||||
|
Find(&cameras)
|
||||||
|
if result.Error != nil {
|
||||||
|
fmt.Println(result.Error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(cameras) > 1 {
|
||||||
|
fmt.Println("对应摄像头id ", record.CameraID, " 超过一个")
|
||||||
|
}
|
||||||
|
// 查看缓存Map中有无对应address,有的话直接读取
|
||||||
|
var address string
|
||||||
|
if _, exists := Camera2AddressMap[cameraId]; exists {
|
||||||
|
address = Camera2AddressMap[cameraId]
|
||||||
|
} else {
|
||||||
|
address = mergeAddress(cameras[0], db)
|
||||||
|
Camera2AddressMap[cameraId] = address
|
||||||
|
}
|
||||||
|
detectionVOS = append(detectionVOS, transToDetectionVO(record, address))
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
db.Model(model.PersonDetectionRecord{}).Count(&count)
|
||||||
|
Success(c, detectionVOS[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func mergeAddress(cameraTarget model.Camera, db *gorm.DB) string {
|
func mergeAddress(cameraTarget model.Camera, db *gorm.DB) string {
|
||||||
var addressArray []string
|
var addressArray []string
|
||||||
var address string
|
var address string
|
||||||
|
|
|
@ -14,6 +14,7 @@ const TableNamePersonDetectionRecord = "person_detection_record"
|
||||||
type PersonDetectionRecord struct {
|
type PersonDetectionRecord struct {
|
||||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
EventID string `gorm:"column:event_id" json:"event_id"`
|
EventID string `gorm:"column:event_id" json:"event_id"`
|
||||||
|
DetectionPicURL string `gorm:"column:detection_pic_url" json:"detection_pic_url"`
|
||||||
AlarmType string `gorm:"column:alarm_type" json:"alarm_type"`
|
AlarmType string `gorm:"column:alarm_type" json:"alarm_type"`
|
||||||
PersonType string `gorm:"column:person_type" json:"person_type"`
|
PersonType string `gorm:"column:person_type" json:"person_type"`
|
||||||
CameraID string `gorm:"column:camera_id" json:"camera_id"`
|
CameraID string `gorm:"column:camera_id" json:"camera_id"`
|
||||||
|
|
|
@ -29,6 +29,7 @@ func newPersonDetectionRecord(db *gorm.DB, opts ...gen.DOOption) personDetection
|
||||||
_personDetectionRecord.ALL = field.NewAsterisk(tableName)
|
_personDetectionRecord.ALL = field.NewAsterisk(tableName)
|
||||||
_personDetectionRecord.ID = field.NewInt64(tableName, "id")
|
_personDetectionRecord.ID = field.NewInt64(tableName, "id")
|
||||||
_personDetectionRecord.EventID = field.NewString(tableName, "event_id")
|
_personDetectionRecord.EventID = field.NewString(tableName, "event_id")
|
||||||
|
_personDetectionRecord.DetectionPicURL = field.NewString(tableName, "detection_pic_url")
|
||||||
_personDetectionRecord.AlarmType = field.NewString(tableName, "alarm_type")
|
_personDetectionRecord.AlarmType = field.NewString(tableName, "alarm_type")
|
||||||
_personDetectionRecord.PersonType = field.NewString(tableName, "person_type")
|
_personDetectionRecord.PersonType = field.NewString(tableName, "person_type")
|
||||||
_personDetectionRecord.CameraID = field.NewString(tableName, "camera_id")
|
_personDetectionRecord.CameraID = field.NewString(tableName, "camera_id")
|
||||||
|
@ -51,6 +52,7 @@ type personDetectionRecord struct {
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Int64
|
ID field.Int64
|
||||||
EventID field.String
|
EventID field.String
|
||||||
|
DetectionPicURL field.String
|
||||||
AlarmType field.String
|
AlarmType field.String
|
||||||
PersonType field.String
|
PersonType field.String
|
||||||
CameraID field.String
|
CameraID field.String
|
||||||
|
@ -79,6 +81,7 @@ func (p *personDetectionRecord) updateTableName(table string) *personDetectionRe
|
||||||
p.ALL = field.NewAsterisk(table)
|
p.ALL = field.NewAsterisk(table)
|
||||||
p.ID = field.NewInt64(table, "id")
|
p.ID = field.NewInt64(table, "id")
|
||||||
p.EventID = field.NewString(table, "event_id")
|
p.EventID = field.NewString(table, "event_id")
|
||||||
|
p.DetectionPicURL = field.NewString(table, "detection_pic_url")
|
||||||
p.AlarmType = field.NewString(table, "alarm_type")
|
p.AlarmType = field.NewString(table, "alarm_type")
|
||||||
p.PersonType = field.NewString(table, "person_type")
|
p.PersonType = field.NewString(table, "person_type")
|
||||||
p.CameraID = field.NewString(table, "camera_id")
|
p.CameraID = field.NewString(table, "camera_id")
|
||||||
|
@ -117,9 +120,10 @@ func (p *personDetectionRecord) GetFieldByName(fieldName string) (field.OrderExp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *personDetectionRecord) fillFieldMap() {
|
func (p *personDetectionRecord) fillFieldMap() {
|
||||||
p.fieldMap = make(map[string]field.Expr, 12)
|
p.fieldMap = make(map[string]field.Expr, 13)
|
||||||
p.fieldMap["id"] = p.ID
|
p.fieldMap["id"] = p.ID
|
||||||
p.fieldMap["event_id"] = p.EventID
|
p.fieldMap["event_id"] = p.EventID
|
||||||
|
p.fieldMap["detection_pic_url"] = p.DetectionPicURL
|
||||||
p.fieldMap["alarm_type"] = p.AlarmType
|
p.fieldMap["alarm_type"] = p.AlarmType
|
||||||
p.fieldMap["person_type"] = p.PersonType
|
p.fieldMap["person_type"] = p.PersonType
|
||||||
p.fieldMap["camera_id"] = p.CameraID
|
p.fieldMap["camera_id"] = p.CameraID
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Loading…
Reference in New Issue