package rule import ( "basic.com/valib/logger.git" "fmt" "ruleModelEngine/data" "ruleModelEngine/db" ) //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) // } // } // fmt.Println() // } //} // 计算常用地址 //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() { ruleInfo, err := db.GetAllData() if err != nil { logger.Error("GetAllData Error", err) } fmt.Println("ruleInfo: ", ruleInfo) communityIDs, err := db.GetCommunityIDs() //fmt.Println("communityIDs:", communityIDs) if err != nil { logger.Error("GetCommunityIDs Error", err) } for _, communityID := range communityIDs { //查询社区内人员档案,方便数据更新 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) } //fmt.Println(labeManage) //fmt.Println("personStatus: ", personStatus) //fmt.Println("CcmmunityIDs: ", cmmunityID) //按社区id查询近一个月es数据 captureInfos, err := db.Query1MDataByCommunityId(communityID) //fmt.Println("captureInfos: ", captureInfos) for i := range captureInfos { captureDays := data.CalculateCaptureDays(captureInfos[i].CaptureDetail) captureInfos[i].CaptureDays = captureDays //fmt.Println("该人员出现天数为", captureInfos[i].CaptureDays) captureInfos[i].Status = data.SetStatus(captureDays, ruleInfo) data.SetFrequentAddress(&captureInfos[i]) } if err != nil { logger.Error("MatchAllTargets Error", err) } if len(captureInfos) == 0 { continue } //fmt.Println("captureInfosQ: ", captureInfos) for _, identity := range labeManage { switch identity.Name { case "服务人员": identity, attribute := CreateLinearModel(captureInfos, communityID, 2.68, identity.ValidDays) errIdentity := db.UpdateDBPersonLabel(identity) if errIdentity != nil { logger.Error("UpdateDBPersonLabel Error", errIdentity) } captureInfos = attribute } } //CreateProcessModel(captureInfos, 30) //continue //fmt.Println("captureInfos: ", captureInfos) postCaptureInfos := data.ProcessData(captureInfos, personStatus, ruleInfo, communityID) //fmt.Println("postCaptureInfos: ", postCaptureInfos) //fmt.Println("共过滤条数:", len(captureInfos)-len(postCaptureInfos)) UpdatePersonInfoErr := db.UpdatePersonInfo(postCaptureInfos, communityID) if UpdatePersonInfoErr != nil { logger.Error("MatchPermanentResidentTargets Error: ", UpdatePersonInfoErr) } resident, DocNumberErr := db.GetResidentData("resident", communityID) if DocNumberErr != nil { logger.Error("GetDocNumberFromPersonStatus Error: ", DocNumberErr) } //fmt.Println(resident) mio := processResidentStatus(resident) //fmt.Println("mip: ", mio) UpdateMoveInoutErr := db.UpdateMoveInout(mio) if UpdateMoveInoutErr != nil { logger.Error("UpdateMoveInoutErr Error: ", UpdateMoveInoutErr) } } }