| | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "fmt" |
| | | "ruleModelEngine/config" |
| | | "ruleModelEngine/data" |
| | | "ruleModelEngine/db" |
| | | "ruleModelEngine/task" |
| | | "strconv" |
| | | ) |
| | | |
| | | //func PrintFilteredPersonnelInfo(filteredPersonnelInfo []db.PersonnelInfo) { |
| | | // for _, pi := range filteredPersonnelInfo { |
| | | // fmt.Printf("DocumentNumber: %s\n", pi.DocumentNumber) |
| | | // fmt.Printf("TotalCaptureCount: %d\n", pi.TotalCaptureCount) |
| | | // fmt.Printf("TotalCaptureDays: %d\n", pi.TotalCaptureDays) |
| | | // fmt.Printf("PersonnelStatus: %s\n", pi.PersonnelStatus) |
| | | // |
| | | // fmt.Println("CaptureDetails:") |
| | | // for _, cd := range pi.CaptureDetails { |
| | | // fmt.Printf(" Date: %s\n", cd.Date) |
| | | // fmt.Printf(" TotalCaptureCount: %d\n", cd.TotalCaptureCount) |
| | | // fmt.Println(" Captures:") |
| | | // for _, c := range cd.Captures { |
| | | // fmt.Printf(" DataTime: %s\n", c.DataTime) |
| | | // fmt.Printf(" Location: %s\n", c.Location) |
| | | //// 检查规则表书否存在异常 |
| | | //func checkRuleValidity(rules []db.PersonnelStatusRule) bool { |
| | | // for i := 0; i < len(rules); i++ { |
| | | // for j := i + 1; j < len(rules); j++ { |
| | | // ruleI := rules[i] |
| | | // ruleJ := rules[j] |
| | | // //fmt.Println(ruleI.DetectionDaysStart,ruleI.DetectionDaysEnd) |
| | | // //fmt.Println(ruleJ.DetectionDaysStart,ruleJ.DetectionDaysEnd) |
| | | // if (ruleI.DetectionDaysStart <= ruleJ.DetectionDaysEnd && ruleI.DetectionDaysStart >= ruleJ.DetectionDaysStart) || |
| | | // (ruleI.DetectionDaysEnd <= ruleJ.DetectionDaysEnd && ruleI.DetectionDaysEnd >= ruleJ.DetectionDaysStart) || |
| | | // (ruleI.DetectionDaysStart <= ruleJ.DetectionDaysStart && ruleI.DetectionDaysEnd >= ruleJ.DetectionDaysEnd) { |
| | | // return false |
| | | // } |
| | | // } |
| | | // fmt.Println() |
| | | // } |
| | | // return true |
| | | //} |
| | | |
| | | // 计算常用地址 |
| | | //func assignFrequentAddress(personnelInfo []db.PersonnelInfo) []db.PersonnelInfo { |
| | | // for i := range personnelInfo { |
| | | // addressCounts := make(map[string]int) |
| | | // var maxAddress string |
| | | // maxCount := 0 |
| | | // for _, detail := range personnelInfo[i].CaptureDetails { |
| | | // for _, capture := range detail.Captures { |
| | | // addressCounts[capture.Location]++ |
| | | // if addressCounts[capture.Location] > maxCount { |
| | | // maxCount = addressCounts[capture.Location] |
| | | // maxAddress = capture.Location |
| | | // } |
| | | // } |
| | | // } |
| | | // personnelInfo[i].FrequentAddress = maxAddress |
| | | // } |
| | | // return personnelInfo |
| | | //} |
| | | |
| | | // 检查规则表书否存在异常 |
| | | func checkRuleValidity(rules []db.PersonnelStatusRule) bool { |
| | | for i := 0; i < len(rules); i++ { |
| | | for j := i + 1; j < len(rules); j++ { |
| | | ruleI := rules[i] |
| | | ruleJ := rules[j] |
| | | //fmt.Println(ruleI.DetectionDaysStart,ruleI.DetectionDaysEnd) |
| | | //fmt.Println(ruleJ.DetectionDaysStart,ruleJ.DetectionDaysEnd) |
| | | if (ruleI.DetectionDaysStart <= ruleJ.DetectionDaysEnd && ruleI.DetectionDaysStart >= ruleJ.DetectionDaysStart) || |
| | | (ruleI.DetectionDaysEnd <= ruleJ.DetectionDaysEnd && ruleI.DetectionDaysEnd >= ruleJ.DetectionDaysStart) || |
| | | (ruleI.DetectionDaysStart <= ruleJ.DetectionDaysStart && ruleI.DetectionDaysEnd >= ruleJ.DetectionDaysEnd) { |
| | | return false |
| | | } |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | |
| | | // 执行程序入口 |
| | | func ExecuteTask() { |
| | | //进出异常布控任务,暂时归类到标签计算部分 |
| | | fmt.Println("进出异常开始入口!!!!!!") |
| | | tasks, err := db.GetAllTaskData() |
| | | if err != nil { |
| | | logger.Error("GetAllTaskData Error", err) |
| | | } |
| | | var tkInfo db.Task |
| | | for _, taskInfo := range tasks { |
| | | if taskInfo.Name == "进出异常" { |
| | | tkInfo.Id = taskInfo.Id |
| | | tkInfo.Name = taskInfo.Name |
| | | } |
| | | } |
| | | fmt.Println("tkInfo: ", tkInfo) |
| | | days := config.Api.AInterval |
| | | docNumIdMap, err := db.QueryLastIdByDayRange(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, id, days) |
| | | if flag == true { |
| | | alarmRules = append(alarmRules, db.AlarmRule{RuleId: strconv.Itoa(tkInfo.Id), RuleText: tkInfo.Name, AlarmLevel: "0"}) |
| | | } |
| | | addFlag, err := db.AddAlarmRules(alarmRules, id) |
| | | if err != nil { |
| | | logger.Error("AddAlarmRules err: ", err) |
| | | } |
| | | if addFlag == true { |
| | | logger.Info("AddAlarmRules success: ", id) |
| | | } |
| | | } |
| | | |
| | | //return |
| | | ruleInfo, err := db.GetAllData() |
| | | if err != nil { |
| | | logger.Error("GetAllData Error", err) |
| | |
| | | if err != nil { |
| | | logger.Error("GetCommunityIDs Error", err) |
| | | } |
| | | labeManage, err := db.GetLabelManageIdentity(2) |
| | | if err != nil { |
| | | logger.Error("GetDBPersonStatusData Error", err) |
| | | } |
| | | //fmt.Println(labeManage) |
| | | for _, communityID := range communityIDs { |
| | | //万全社区 |
| | | //if communityID != "50010101010000001001" { |
| | | // continue |
| | | //} |
| | | //查询社区内人员档案,方便数据更新 |
| | | personStatus, err := db.GetDBPersonStatusData(communityID) |
| | | if err != nil { |
| | | logger.Error("GetDBPersonStatusData Error", err) |
| | | } |
| | | labeManage, err := db.GetLabelManageIdentity(2) |
| | | if err != nil { |
| | | logger.Error("GetDBPersonStatusData Error", err) |
| | | } |
| | |
| | | //按社区id查询近一个月es数据 |
| | | captureInfos, err := db.Query1MDataByCommunityId(communityID) |
| | | //fmt.Println("captureInfos: ", captureInfos) |
| | | //residentCount := 0 |
| | | for i := range captureInfos { |
| | | captureDays := data.CalculateCaptureDays(captureInfos[i].CaptureDetail) |
| | | //fmt.Println(captureInfos[i].DocumentNumber) |
| | | captureDays, overnightCount := data.CalculateCaptureDays(captureInfos[i].CaptureDetail) |
| | | captureInfos[i].CaptureDays = captureDays |
| | | //fmt.Println("该人员出现天数为", captureInfos[i].CaptureDays) |
| | | captureInfos[i].OvernightStays = overnightCount |
| | | |
| | | //if captureInfos[i].CaptureDays <= 10 && captureInfos[i].OvernightStays >= 1 { |
| | | // fmt.Println(captureInfos[i].DocumentNumber) |
| | | // fmt.Println("该人员出现天数为", captureInfos[i].CaptureDays) |
| | | // fmt.Println("该人员过夜天数为", captureInfos[i].OvernightStays) |
| | | //} |
| | | |
| | | captureInfos[i].Status = data.SetStatus(captureDays, ruleInfo) |
| | | if captureInfos[i].OvernightStays >= 5 && (captureInfos[i].CaptureDays <= 14 && captureInfos[i].CaptureDays >= 5) { |
| | | captureInfos[i].Status = "resident" |
| | | } |
| | | //if captureInfos[i].Status == "resident" { |
| | | // residentCount++ |
| | | //} |
| | | age, err := db.QueryAgeById(captureInfos[i].DocumentNumber) |
| | | if err != nil { |
| | | logger.Error("QueryAgeById ERROR", err) |
| | | } |
| | | captureInfos[i].Age = age |
| | | data.SetFrequentAddress(&captureInfos[i]) |
| | | //fmt.Println("captureInfos[i].Age: ", captureInfos[i].Age) |
| | | } |
| | | //fmt.Println("residentCount: ", residentCount) |
| | | if err != nil { |
| | | logger.Error("MatchAllTargets Error", err) |
| | | } |
| | |
| | | for _, identity := range labeManage { |
| | | switch identity.Name { |
| | | case "服务人员": |
| | | identity, attribute := CreateLinearModel(captureInfos, communityID, 2.68, identity.ValidDays) |
| | | identity, attribute := CreateLinearModel(captureInfos, communityID, 2.68, identity.ValidDays, identity.Id) |
| | | errIdentity := db.UpdateDBPersonLabel(identity) |
| | | if errIdentity != nil { |
| | | logger.Error("UpdateDBPersonLabel Error", errIdentity) |
| | |
| | | |
| | | } |
| | | } |
| | | //CreateProcessModel(captureInfos, 30) |
| | | identity := CreateProcessModel(captureInfos, 30, communityID, labeManage) |
| | | errIdentity := db.UpdateDBPersonLabel(identity) |
| | | if errIdentity != nil { |
| | | logger.Error("UpdateDBPersonLabel Error", errIdentity) |
| | | } |
| | | //continue |
| | | //fmt.Println("captureInfos: ", captureInfos) |
| | | postCaptureInfos := data.ProcessData(captureInfos, personStatus, ruleInfo, communityID) |
| | |
| | | } |
| | | |
| | | resident, DocNumberErr := db.GetResidentData("resident", communityID) |
| | | //fmt.Println(resident) |
| | | //return |
| | | if DocNumberErr != nil { |
| | | logger.Error("GetDocNumberFromPersonStatus Error: ", DocNumberErr) |
| | | } |
| | | |
| | | //fmt.Println(resident) |
| | | //fmt.Println("resident: ", resident) |
| | | mio := processResidentStatus(resident) |
| | | //fmt.Println("mip: ", mio) |
| | | UpdateMoveInoutErr := db.UpdateMoveInout(mio) |
| | |
| | | logger.Error("UpdateMoveInoutErr Error: ", UpdateMoveInoutErr) |
| | | } |
| | | } |
| | | |
| | | } |