更新小细节的适配
This commit is contained in:
		
							parent
							
								
									8bc015a856
								
							
						
					
					
						commit
						5b6c7ec8a4
					
				| @ -2,5 +2,5 @@ | ||||
|     "backendport": 8080, | ||||
|     "name": "node1", | ||||
|     "database": "initqwe", | ||||
|     "picPath": "/home/backend/picture" | ||||
|     "picturePath": "D:/intelligent/intelligent_backend/public/images" | ||||
| } | ||||
| @ -4,12 +4,10 @@ import ( | ||||
| 	"go_backend/cmd/config" | ||||
| 	"go_backend/internal/api" | ||||
| 	"go_backend/internal/dbs" | ||||
| 	scheduledtask "go_backend/internal/scheduled_task" | ||||
| 	"go_backend/internal/utils" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"github.com/robfig/cron/v3" | ||||
| ) | ||||
| 
 | ||||
| func main() { | ||||
| @ -31,11 +29,14 @@ func main() { | ||||
| 	api.CreateDetectionRecord(r.Group("")) | ||||
| 	api.GetDetectionRecord(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() | ||||
| 	c.AddFunc("@every 1m", scheduledtask.MergeTrajectory) | ||||
| 	c.Start() | ||||
| 	r.Static("/images", config.AllConfig.PicturePath) | ||||
| 	//c := cron.New() | ||||
| 	//c.AddFunc("@every 1m", scheduledtask.MergeTrajectory) | ||||
| 	//c.Start() | ||||
| 
 | ||||
| 	// _ = r.Run(":" + strconv.Itoa(config.AllConfig.Port)) | ||||
| 	_ = r.Run(":" + strconv.Itoa(8080)) | ||||
|  | ||||
| @ -5,7 +5,8 @@ import ( | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"go_backend/internal/dbs" | ||||
| 	"go_backend/internal/model" | ||||
| 	"go_backend/internal/utils" | ||||
| 	"gorm.io/gorm" | ||||
| 	"strconv" | ||||
| ) | ||||
| 
 | ||||
| type CameraVO struct { | ||||
| @ -24,61 +25,99 @@ type CameraVO struct { | ||||
| 	ChildVO          []*CameraVO `json:"child"` | ||||
| } | ||||
| 
 | ||||
| func GetAllCameras(router *gin.RouterGroup) { | ||||
| func GetAllCamerasIncludeFolder(router *gin.RouterGroup) { | ||||
| 	router.GET("/camerasList", func(c *gin.Context) { | ||||
| 		cameras := make([]model.Camera, 0) | ||||
| 		db := dbs.GetGormDB() | ||||
| 		db.Find(&cameras) | ||||
| 
 | ||||
| 		cameraMap := make(map[int][]model.Camera) | ||||
| 
 | ||||
| 		for _, camera := range cameras { | ||||
| 			cameraMap[int(camera.ViewPriority)] = append(cameraMap[(int(camera.ViewPriority))], camera) | ||||
| 		} | ||||
| 		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) | ||||
| 		level := 0 | ||||
| 
 | ||||
| 		cameraRecord := make(map[int]*CameraVO) | ||||
| 
 | ||||
| 		for priority, cameraArray := range cameraMap { | ||||
| 			if priority == 0 { | ||||
| 				for _, camera := range cameraArray { | ||||
| 					vo := transVO(camera) | ||||
| 					cameraVOList = append(cameraVOList, &vo) | ||||
| 					cameraRecord[int(camera.ID)] = &vo | ||||
| 				} | ||||
| 				level += 1 | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			if priority == level { | ||||
| 				tempRecord := make(map[int]*CameraVO) | ||||
| 
 | ||||
| 				for _, camera := range cameraArray { | ||||
| 					vo := transVO(camera) | ||||
| 					parentId := vo.ParentCategoryID[len(vo.ParentCategoryID)-1] | ||||
| 					if pointer, exists := cameraRecord[parentId]; exists { | ||||
| 						pointer.ChildVO = append(pointer.ChildVO, &vo) | ||||
| 						utils.PrintSlice(vo.ParentCategoryID) | ||||
| 						newParent := make([]int, 0) | ||||
| 						utils.PrintSlice(pointer.ParentCategoryID) | ||||
| 						for _, id := range pointer.ParentCategoryID { | ||||
| 							newParent = append(newParent, id) | ||||
| 						} | ||||
| 						newParent = append(newParent, parentId) | ||||
| 						vo.ParentCategoryID = newParent | ||||
| 						tempRecord[int(vo.ID)] = &vo | ||||
| 					} | ||||
| 				} | ||||
| 				cameraRecord = tempRecord | ||||
| 				level += 1 | ||||
| 		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) | ||||
| 
 | ||||
| 	cameraMap := make(map[int][]model.Camera) | ||||
| 
 | ||||
| 	for _, camera := range cameras { | ||||
| 		cameraMap[int(camera.ViewPriority)] = append(cameraMap[(int(camera.ViewPriority))], camera) | ||||
| 	} | ||||
| 
 | ||||
| 	cameraList := make([]*model.Camera, 0) | ||||
| 	cameraVOList := make([]*CameraVO, 0) | ||||
| 	level := 0 | ||||
| 
 | ||||
| 	cameraRecord := make(map[int]*CameraVO) | ||||
| 
 | ||||
| 	for priority, cameraArray := range cameraMap { | ||||
| 		if priority == 0 { | ||||
| 			for _, camera := range cameraArray { | ||||
| 				vo := transVO(camera) | ||||
| 				if isCameraOnly { | ||||
| 					if camera.Type == "camera" { | ||||
| 						cameraList = append(cameraList, &camera) | ||||
| 					} | ||||
| 				} else { | ||||
| 					cameraVOList = append(cameraVOList, &vo) | ||||
| 				} | ||||
| 				cameraRecord[int(camera.ID)] = &vo | ||||
| 			} | ||||
| 			level += 1 | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if priority == level { | ||||
| 			tempRecord := make(map[int]*CameraVO) | ||||
| 
 | ||||
| 			for _, camera := range cameraArray { | ||||
| 				vo := transVO(camera) | ||||
| 				parentId := vo.ParentCategoryID[len(vo.ParentCategoryID)-1] | ||||
| 				if pointer, exists := cameraRecord[parentId]; exists { | ||||
| 					if isCameraOnly { | ||||
| 						if camera.Type == "camera" { | ||||
| 							cameraList = append(cameraList, &camera) | ||||
| 						} | ||||
| 					} | ||||
| 					pointer.ChildVO = append(pointer.ChildVO, &vo) | ||||
| 					newParent := make([]int, 0) | ||||
| 					for _, id := range pointer.ParentCategoryID { | ||||
| 						newParent = append(newParent, id) | ||||
| 					} | ||||
| 					newParent = append(newParent, parentId) | ||||
| 					vo.ParentCategoryID = newParent | ||||
| 					tempRecord[int(vo.ID)] = &vo | ||||
| 				} | ||||
| 			} | ||||
| 			cameraRecord = tempRecord | ||||
| 			level += 1 | ||||
| 		} | ||||
| 	} | ||||
| 	return cameraVOList, cameraList | ||||
| } | ||||
| 
 | ||||
| type Node struct { | ||||
| 	ParentID    int    `json:"parent_id"` | ||||
| 	DisplayName string `json:"display_name"` | ||||
|  | ||||
| @ -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 { | ||||
| 	var addressArray []string | ||||
| 	var address string | ||||
|  | ||||
| @ -14,6 +14,7 @@ const TableNamePersonDetectionRecord = "person_detection_record" | ||||
| type PersonDetectionRecord struct { | ||||
| 	ID                    int64     `gorm:"column:id;primaryKey;autoIncrement:true" json:"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"` | ||||
| 	PersonType            string    `gorm:"column:person_type" json:"person_type"` | ||||
| 	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.ID = field.NewInt64(tableName, "id") | ||||
| 	_personDetectionRecord.EventID = field.NewString(tableName, "event_id") | ||||
| 	_personDetectionRecord.DetectionPicURL = field.NewString(tableName, "detection_pic_url") | ||||
| 	_personDetectionRecord.AlarmType = field.NewString(tableName, "alarm_type") | ||||
| 	_personDetectionRecord.PersonType = field.NewString(tableName, "person_type") | ||||
| 	_personDetectionRecord.CameraID = field.NewString(tableName, "camera_id") | ||||
| @ -51,6 +52,7 @@ type personDetectionRecord struct { | ||||
| 	ALL                   field.Asterisk | ||||
| 	ID                    field.Int64 | ||||
| 	EventID               field.String | ||||
| 	DetectionPicURL       field.String | ||||
| 	AlarmType             field.String | ||||
| 	PersonType            field.String | ||||
| 	CameraID              field.String | ||||
| @ -79,6 +81,7 @@ func (p *personDetectionRecord) updateTableName(table string) *personDetectionRe | ||||
| 	p.ALL = field.NewAsterisk(table) | ||||
| 	p.ID = field.NewInt64(table, "id") | ||||
| 	p.EventID = field.NewString(table, "event_id") | ||||
| 	p.DetectionPicURL = field.NewString(table, "detection_pic_url") | ||||
| 	p.AlarmType = field.NewString(table, "alarm_type") | ||||
| 	p.PersonType = field.NewString(table, "person_type") | ||||
| 	p.CameraID = field.NewString(table, "camera_id") | ||||
| @ -117,9 +120,10 @@ func (p *personDetectionRecord) GetFieldByName(fieldName string) (field.OrderExp | ||||
| } | ||||
| 
 | ||||
| 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["event_id"] = p.EventID | ||||
| 	p.fieldMap["detection_pic_url"] = p.DetectionPicURL | ||||
| 	p.fieldMap["alarm_type"] = p.AlarmType | ||||
| 	p.fieldMap["person_type"] = p.PersonType | ||||
| 	p.fieldMap["camera_id"] = p.CameraID | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 42 KiB | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user