增加画轨迹的接口
parent
74aeed3b7e
commit
8bc015a856
|
@ -6,7 +6,6 @@ import (
|
|||
"go_backend/internal/dbs"
|
||||
"go_backend/internal/model"
|
||||
"go_backend/internal/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CameraVO struct {
|
||||
|
@ -19,9 +18,9 @@ type CameraVO struct {
|
|||
Type string `json:"type"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
DeletedTime time.Time `json:"deleted_time"`
|
||||
UpdateTime time.Time `json:"update_time"`
|
||||
CreateTime string `json:"create_time"`
|
||||
DeletedTime string `json:"deleted_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
ChildVO []*CameraVO `json:"child"`
|
||||
}
|
||||
|
||||
|
@ -95,16 +94,14 @@ func CreateNode(router *gin.RouterGroup) {
|
|||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
println("nihao", req.ParentID)
|
||||
newNode := model.Camera{
|
||||
ParentCategoryID: int32(req.ParentID),
|
||||
DisplayName: req.DisplayName,
|
||||
IPAddress: req.Ip,
|
||||
}
|
||||
db := dbs.GetGormDB()
|
||||
result := db.Create(&newNode)
|
||||
|
||||
Success(c, result)
|
||||
db.Create(&newNode)
|
||||
Success(c, "success")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ type detectionReturnParam struct {
|
|||
DetectionRecord []DetectionVO `json:"detectionRecord"`
|
||||
}
|
||||
|
||||
// Camera2AddressMap 记录cameraid:address的Map
|
||||
var Camera2AddressMap = map[int]string{}
|
||||
|
||||
func GetDetectionRecord(router *gin.RouterGroup) {
|
||||
router.GET("/detection/List", func(c *gin.Context) {
|
||||
limit, _ := strconv.Atoi(c.Query("limit"))
|
||||
|
@ -41,8 +44,9 @@ func GetDetectionRecord(router *gin.RouterGroup) {
|
|||
// 根据每条记录搜索对应的摄像头
|
||||
for _, record := range detectionRecords {
|
||||
var cameras []model.Camera
|
||||
cameraId, _ := strconv.Atoi(record.CameraID)
|
||||
result := db.Model(model.Camera{}).
|
||||
Where("camera_id = ?", record.CameraID).
|
||||
Where("camera_id = ?", cameraId).
|
||||
Find(&cameras)
|
||||
if result.Error != nil {
|
||||
fmt.Println(result.Error)
|
||||
|
@ -51,7 +55,14 @@ func GetDetectionRecord(router *gin.RouterGroup) {
|
|||
if len(cameras) > 1 {
|
||||
fmt.Println("对应摄像头id ", record.CameraID, " 超过一个")
|
||||
}
|
||||
address := mergeAddress(cameras[0], db)
|
||||
// 查看缓存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))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go_backend/internal/dbs"
|
||||
"go_backend/internal/model"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetTrajectoryRecordList(router *gin.RouterGroup) {
|
||||
|
@ -17,14 +21,76 @@ func GetTrajectoryRecordList(router *gin.RouterGroup) {
|
|||
})
|
||||
}
|
||||
|
||||
type TrajectoryVO struct {
|
||||
Id string `json:"id"`
|
||||
CameraArray []cameraNode `json:"cameraArray"`
|
||||
}
|
||||
|
||||
type cameraNode struct {
|
||||
Ip string `json:"ip"`
|
||||
Address string `json:"address"`
|
||||
Lat string `json:"lat"`
|
||||
Lng string `json:"lng"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
func GetTargetTrajectory(router *gin.RouterGroup) {
|
||||
router.GET("/trajectory", func(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
var tra model.TrajectoryDetectionRecord
|
||||
db := dbs.GetGormDB()
|
||||
db.Where("id = ? ", id).
|
||||
db.Model(model.TrajectoryDetectionRecord{}).
|
||||
Where("id = ? ", id).
|
||||
Find(&tra)
|
||||
|
||||
Success(c, tra)
|
||||
var trajectoryVO TrajectoryVO
|
||||
trajectoryVO.Id = id
|
||||
|
||||
// 序列化摄像头的id数组
|
||||
var cameraIds []int
|
||||
err := json.Unmarshal([]byte(tra.Trajectory), &cameraIds)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing JSON:", err)
|
||||
return
|
||||
}
|
||||
// 序列化记录的id数组
|
||||
var recordIds []int
|
||||
err = json.Unmarshal([]byte(tra.PersonDetectionRecordIds), &recordIds)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing JSON:", err)
|
||||
return
|
||||
}
|
||||
for index, id := range cameraIds {
|
||||
var camera model.Camera
|
||||
db.Where("camera_id = ?", id).
|
||||
Find(&camera)
|
||||
var address string
|
||||
cameraId, _ := strconv.Atoi(camera.CameraID)
|
||||
// 从已读取过的address map读取,如果没有就重新获取
|
||||
if _, exists := Camera2AddressMap[cameraId]; exists {
|
||||
address = Camera2AddressMap[cameraId]
|
||||
} else {
|
||||
address = mergeAddress(camera, db)
|
||||
Camera2AddressMap[cameraId] = address
|
||||
}
|
||||
var record model.PersonDetectionRecord
|
||||
db.Where("id = ?", recordIds[index]).Find(&record)
|
||||
|
||||
parsedUrl, err := url.Parse(record.Address)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing URL:", err)
|
||||
}
|
||||
ip := parsedUrl.Path
|
||||
|
||||
cameraNode := cameraNode{
|
||||
Ip: ip,
|
||||
Address: address,
|
||||
Lat: camera.Latitude,
|
||||
Lng: camera.Longitude,
|
||||
Time: record.DetectTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
trajectoryVO.CameraArray = append(trajectoryVO.CameraArray, cameraNode)
|
||||
}
|
||||
Success(c, trajectoryVO)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const TableNameCamera = "cameras"
|
||||
|
||||
// Camera mapped from table <cameras>
|
||||
|
@ -23,9 +19,9 @@ type Camera struct {
|
|||
Latitude string `gorm:"column:latitude;comment:纬度" json:"latitude"` // 纬度
|
||||
Longitude string `gorm:"column:longitude;comment:经度" json:"longitude"` // 经度
|
||||
IsDeleted bool `gorm:"column:is_deleted" json:"is_deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
|
||||
DeletedTime time.Time `gorm:"column:deleted_time" json:"deleted_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time" json:"update_time"`
|
||||
CreateTime string `gorm:"column:create_time" json:"create_time"`
|
||||
DeletedTime string `gorm:"column:deleted_time" json:"deleted_time"`
|
||||
UpdateTime string `gorm:"column:update_time" json:"update_time"`
|
||||
}
|
||||
|
||||
// TableName Camera's table name
|
||||
|
|
|
@ -38,9 +38,9 @@ func newCamera(db *gorm.DB, opts ...gen.DOOption) camera {
|
|||
_camera.Latitude = field.NewString(tableName, "latitude")
|
||||
_camera.Longitude = field.NewString(tableName, "longitude")
|
||||
_camera.IsDeleted = field.NewBool(tableName, "is_deleted")
|
||||
_camera.CreateTime = field.NewTime(tableName, "create_time")
|
||||
_camera.DeletedTime = field.NewTime(tableName, "deleted_time")
|
||||
_camera.UpdateTime = field.NewTime(tableName, "update_time")
|
||||
_camera.CreateTime = field.NewString(tableName, "create_time")
|
||||
_camera.DeletedTime = field.NewString(tableName, "deleted_time")
|
||||
_camera.UpdateTime = field.NewString(tableName, "update_time")
|
||||
|
||||
_camera.fillFieldMap()
|
||||
|
||||
|
@ -62,9 +62,9 @@ type camera struct {
|
|||
Latitude field.String // 纬度
|
||||
Longitude field.String // 经度
|
||||
IsDeleted field.Bool
|
||||
CreateTime field.Time
|
||||
DeletedTime field.Time
|
||||
UpdateTime field.Time
|
||||
CreateTime field.String
|
||||
DeletedTime field.String
|
||||
UpdateTime field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ func (c *camera) updateTableName(table string) *camera {
|
|||
c.Latitude = field.NewString(table, "latitude")
|
||||
c.Longitude = field.NewString(table, "longitude")
|
||||
c.IsDeleted = field.NewBool(table, "is_deleted")
|
||||
c.CreateTime = field.NewTime(table, "create_time")
|
||||
c.DeletedTime = field.NewTime(table, "deleted_time")
|
||||
c.UpdateTime = field.NewTime(table, "update_time")
|
||||
c.CreateTime = field.NewString(table, "create_time")
|
||||
c.DeletedTime = field.NewString(table, "deleted_time")
|
||||
c.UpdateTime = field.NewString(table, "update_time")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
|
|
Loading…
Reference in New Issue