From de37adb6dec5e9da70f9cc11b234176ee6fda986 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期五, 24 五月 2024 21:04:39 +0800
Subject: [PATCH] 添加布控模块,合并person_status和snapshot_count_summary数据库等

---
 rule/service.go |  119 ++++++++++++++++++++++++++++-------------------------------
 1 files changed, 57 insertions(+), 62 deletions(-)

diff --git a/rule/service.go b/rule/service.go
index 4de8888..6294c83 100644
--- a/rule/service.go
+++ b/rule/service.go
@@ -7,67 +7,28 @@
 	"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)
+//// 妫�鏌ヨ鍒欒〃涔﹀惁瀛樺湪寮傚父
+//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() {
+	//return
 	ruleInfo, err := db.GetAllData()
 	if err != nil {
 		logger.Error("GetAllData Error", err)
@@ -78,13 +39,18 @@
 	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)
 		}
@@ -94,13 +60,35 @@
 		//鎸夌ぞ鍖篿d鏌ヨ杩戜竴涓湀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)
 		}
@@ -111,7 +99,7 @@
 		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)
@@ -120,7 +108,11 @@
 
 			}
 		}
-		//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)
@@ -132,10 +124,14 @@
 		}
 
 		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)
@@ -143,5 +139,4 @@
 			logger.Error("UpdateMoveInoutErr Error: ", UpdateMoveInoutErr)
 		}
 	}
-
 }

--
Gitblit v1.8.0