From 6597287fc412ce914aba41fe571ed05817cf371c Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期一, 27 五月 2024 11:34:58 +0800
Subject: [PATCH] fix script

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

diff --git a/rule/service.go b/rule/service.go
index 4de8888..c77e096 100644
--- a/rule/service.go
+++ b/rule/service.go
@@ -3,71 +3,71 @@
 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("杩涘嚭寮傚父寮�濮嬪叆鍙o紒锛侊紒锛侊紒锛�")
+	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)
@@ -78,13 +78,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 +99,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 +138,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 +147,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 +163,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 +178,4 @@
 			logger.Error("UpdateMoveInoutErr Error: ", UpdateMoveInoutErr)
 		}
 	}
-
 }

--
Gitblit v1.8.0