| | |
| | | return captureInfos, nil |
| | | } |
| | | |
| | | func QueryTimesByDocNumberDays(days int, docNumber string) (int, error) { |
| | | func QueryTimesByDocNumberDays(docNumber string, communityId string, cameraIds []string, days int) (int, error) { |
| | | cameraIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1) |
| | | esURL := "http://" + config.Elastic.Host + ":" + config.Elastic.Port + "/" + config.Elastic.Index + "/_search" |
| | | queryDSL := `{ |
| | | "query": { |
| | |
| | | { |
| | | "term": { |
| | | "documentNumber": "` + docNumber + `" |
| | | } |
| | | }, |
| | | { |
| | | "term": { |
| | | "communityId": "` + communityId + `" |
| | | } |
| | | }, |
| | | { |
| | | "terms": { |
| | | "cameraId": ["` + cameraIdsStr + `"] |
| | | } |
| | | } |
| | | ] |
| | |
| | | return total, nil |
| | | } |
| | | |
| | | func QueryLastIdByDayRange(dayGte, dayLt int) (map[string]string, error) { |
| | | func QueryLastIdByDayRange(communityId string, cameraIds []string, dayGte, dayLt int) (map[string]string, error) { |
| | | cameraIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1) |
| | | esURL := "http://" + config.Elastic.Host + ":" + config.Elastic.Port + "/" + config.Elastic.Index + "/_search" |
| | | queryDSL := `{ |
| | | "query": { |
| | |
| | | "lt": "now-` + strconv.Itoa(dayLt) + `d/d" |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | "term": { |
| | | "communityId": "` + communityId + `" |
| | | } |
| | | }, |
| | | { |
| | | "terms": { |
| | | "cameraId": ["` + cameraIdsStr + `"] |
| | | } |
| | | } |
| | | ] |
| | | } |
| | |
| | | |
| | | type Device struct { |
| | | DeviceCode string `gorm:"column:deviceCode" json:"deviceCode" example:"J83762"` //设备编码 |
| | | AreaID string `json:"areaID" gorm:"index;column:communityID;type:varchar(299);"` //常住小区 domain unit ID |
| | | BuildingType BuildingType `gorm:"column:building_type;type:tinyint(1);not null;default:0" json:"buildingType"` //楼宇类型 |
| | | MaxBuildingFloor int `gorm:"column:max_building_floor;type:tinyint(1);not null;default:0" json:"maxBuildingFloor"` //最高楼层号 |
| | | } |
| | |
| | | if result.Error != nil { |
| | | return nil, result.Error |
| | | } |
| | | |
| | | return device, nil |
| | | } |
| | | |
| | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "fmt" |
| | | "ruleModelEngine/cache" |
| | | "ruleModelEngine/config" |
| | | "ruleModelEngine/data" |
| | | "ruleModelEngine/db" |
| | |
| | | // return true |
| | | //} |
| | | |
| | | // 执行程序入口 |
| | | func ExecuteTask() { |
| | | func executeEnteringButNotLeaving(communityId string) { |
| | | //进出异常布控任务,暂时归类到标签计算部分 |
| | | //fmt.Println("进出异常开始入口!!!!!!") |
| | | tasks, err := db.GetAllTaskData() |
| | |
| | | tkInfo.Name = taskInfo.Name |
| | | } |
| | | } |
| | | |
| | | //fmt.Println("tkInfo: ", tkInfo) |
| | | //fmt.Println("docNumIdMap: ", len(docNumIdMap)) |
| | | //获取商住楼cameraid |
| | | |
| | | cameraIds := make([]string, 0) |
| | | for _, deviceInfo := range cache.Device { |
| | | if deviceInfo.AreaID == communityId && deviceInfo.BuildingType == db.BuildingTypeMixedUse { |
| | | cameraIds = append(cameraIds, deviceInfo.DeviceCode) |
| | | } |
| | | } |
| | | if len(cameraIds) == 0 { |
| | | logger.Info("不存在商住楼设备:", cameraIds) |
| | | return |
| | | } |
| | | //查询待判断进出异常预警档案 |
| | | days := config.Api.AInterval |
| | | docNumIdMap, err := db.QueryLastIdByDayRange(days, days-1) |
| | | docNumIdMap, err := db.QueryLastIdByDayRange(communityId, cameraIds, days, days-1) |
| | | if err != nil { |
| | | logger.Error("QueryByDayRange err: ", err) |
| | | } |
| | | //fmt.Println("docNumIdMap: ", len(docNumIdMap)) |
| | | for docNumber, id := range docNumIdMap { |
| | | //fmt.Println(docNumber, id) |
| | | alarmRules := make([]db.AlarmRule, 0) |
| | | flag := task.EnteringButNotLeaving(docNumber, days) |
| | | flag := task.EnteringButNotLeaving(docNumber, communityId, cameraIds, days) |
| | | if flag == true { |
| | | alarmRules = append(alarmRules, db.AlarmRule{RuleId: strconv.Itoa(tkInfo.Id), RuleText: tkInfo.Name, AlarmLevel: "0"}) |
| | | } |
| | |
| | | logger.Info("AddAlarmRules success: ", id) |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 执行程序入口 |
| | | func ExecuteTask() { |
| | | //return |
| | | ruleInfo, err := db.GetAllData() |
| | | if err != nil { |
| | |
| | | } |
| | | //fmt.Println(labeManage) |
| | | for _, communityID := range communityIDs { |
| | | executeEnteringButNotLeaving(communityID) |
| | | //万全社区 |
| | | //if communityID != "50010101010000001001" { |
| | | // continue |
| | | //} |
| | | fmt.Println("communityID: ", communityID) |
| | | //continue |
| | | //查询社区内人员档案,方便数据更新 |
| | | personStatusList, err := db.QueryPersonStatusWithPagination(communityID, 30) |
| | | if err != nil { |
| | |
| | | return false |
| | | } |
| | | |
| | | func EnteringButNotLeaving(docNumber string, days int) bool { |
| | | total, err := db.QueryTimesByDocNumberDays(days-1, docNumber) |
| | | func EnteringButNotLeaving(docNumber string, communityId string, cameraIds []string, days int) bool { |
| | | total, err := db.QueryTimesByDocNumberDays(docNumber, communityId, cameraIds, days-1) |
| | | if err != nil { |
| | | logger.Error("QueryTimesByDocNumberDays err: ", err) |
| | | } |