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/engine.go |  122 +++++++++++++++++++++++++++++++---------
 1 files changed, 93 insertions(+), 29 deletions(-)

diff --git a/rule/engine.go b/rule/engine.go
index 9409760..8bbb953 100644
--- a/rule/engine.go
+++ b/rule/engine.go
@@ -2,7 +2,6 @@
 
 import (
 	"basic.com/valib/logger.git"
-	"errors"
 	"fmt"
 	"math"
 	"ruleModelEngine/db"
@@ -56,11 +55,13 @@
 				status = "Confirmed"
 			}
 		}
-
+		if status == "" {
+			continue
+		}
 		//fmt.Println("status: ", status)
 		moveInout = append(moveInout, db.MoveInout{
 			DocumentNumber: resident.DocumentNumber,
-			CommunityID:    resident.CommunityID,
+			CommunityID:    resident.CommunityId,
 			MoveInDate:     createdAt,           // 瀛樺偍骞存湀鏃�
 			MoveOutDate:    &lastAppearanceDate, // 瀛樺偍骞存湀鏃�
 			MoveType:       moveType,
@@ -71,18 +72,18 @@
 	return moveInout
 }
 
-func ProcessRuleEngine(personInfos []db.CaptureInfo, ruleInfo []db.PersonnelStatusRule, cmmunityID string) (bool, error) {
-	ruleInfoCheck := checkRuleValidity(ruleInfo)
-	if ruleInfoCheck == false {
-		logger.Error("瑙勫垯搴撴暟鎹紓甯�")
-		return false, errors.New("瑙勫垯搴撴暟鎹紓甯�")
-	}
-	fmt.Println("娓呮礂鍓嶏細 ", len(personInfos))
-	logger.Info("瑙勫垯绠楁硶鎵ц瀹屾瘯锛侊紒锛�")
-	return true, nil
-}
+//func ProcessRuleEngine(personInfos []db.CaptureInfo, ruleInfo []db.PersonnelStatusRule, cmmunityID string) (bool, error) {
+//	ruleInfoCheck := checkRuleValidity(ruleInfo)
+//	if ruleInfoCheck == false {
+//		logger.Error("瑙勫垯搴撴暟鎹紓甯�")
+//		return false, errors.New("瑙勫垯搴撴暟鎹紓甯�")
+//	}
+//	fmt.Println("娓呮礂鍓嶏細 ", len(personInfos))
+//	logger.Info("瑙勫垯绠楁硶鎵ц瀹屾瘯锛侊紒锛�")
+//	return true, nil
+//}
 
-func CreateLinearModel(personInfos []db.CaptureInfo, communityID string, threshold float64, validDays int) ([]db.Identity, []db.CaptureInfo) {
+func CreateLinearModel(personInfos []db.CaptureInfo, communityID string, threshold float64, validDays int, labelId int) ([]db.Identity, []db.CaptureInfo) {
 	identity := make([]db.Identity, 0)
 	captureInfo := make([]db.CaptureInfo, 0)
 	for _, info := range personInfos {
@@ -116,7 +117,7 @@
 				identity = append(identity, db.Identity{
 					CommunityID:    communityID,
 					DocumentNumber: info.DocumentNumber,
-					LabelId:        3,
+					LabelId:        labelId,
 					ExpireTime:     GetCurrentDateAddDaysTimestamp(validDays)})
 				continue
 			}
@@ -149,26 +150,32 @@
 	fmt.Println(addrData)
 }
 
-func CreateProcessModel(personInfos []db.CaptureInfo, days int) {
-	timeTOIndex := getIndexForTime(24 * 60)
-	dateTOIndex := getIndexForDate(days)
-	//fmt.Println(dateTOIndex)
-	inModelMatrix := make([][]int, days)
-	for i := range inModelMatrix {
-		inModelMatrix[i] = make([]int, 24*60)
+func CreateProcessModel(personInfos []db.CaptureInfo, days int, communityID string, labelManage []db.LabelManage) []db.Identity {
+	labelIndexMap := make(map[string]int)
+	for index, labelManageInfo := range labelManage {
+		labelIndexMap[labelManageInfo.Name] = index
 	}
-	outModelMatrix := make([][]int, days)
-	for i := range outModelMatrix {
-		outModelMatrix[i] = make([]int, 24*60)
-	}
+	identity := make([]db.Identity, 0)
 	for _, info := range personInfos {
+		timeTOIndex := getIndexForTime(24 * 60)
+		dateTOIndex := getIndexForDate(days)
+		//fmt.Println(dateTOIndex)
+		inModelMatrix := make([][]int, days)
+		for i := range inModelMatrix {
+			inModelMatrix[i] = make([]int, 24*60)
+		}
+		outModelMatrix := make([][]int, days)
+		for i := range outModelMatrix {
+			outModelMatrix[i] = make([]int, 24*60)
+		}
 		//fmt.Println("info: ", info)
 		for _, captureInfo := range info.CaptureDetail {
 			captrueDateTime := captureInfo.CaptureDate
 			dateTimeObj, err := time.Parse("2006-01-02 15:04:05", captrueDateTime)
 			if err != nil {
 				logger.Error("Parse time error", err)
-				return
+				continue
+				//return n/**/il, err
 			}
 			if isWeekend(dateTimeObj) {
 				continue
@@ -184,9 +191,66 @@
 				continue
 			}
 		}
+		countMaxRows, colS, colE := CountMaxRows(outModelMatrix, 30, 30)
+		logger.Info("瑙勫緥鍑哄嫟鏃堕棿娈碉細", colS, colE, "\t娆℃暟: ", countMaxRows)
+		if countMaxRows >= 10 {
+			if info.Age <= 22 && info.Age >= 7 {
+				lIndex := labelIndexMap["瀛︾敓"]
+				identity = append(identity, db.Identity{
+					CommunityID:    communityID,
+					DocumentNumber: info.DocumentNumber,
+					LabelId:        labelManage[lIndex].Id,
+					ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+			} else if info.Age >= 23 && info.Age <= 60 {
+				lIndex := labelIndexMap["涓婄彮鏃�"]
+				identity = append(identity, db.Identity{
+					CommunityID:    communityID,
+					DocumentNumber: info.DocumentNumber,
+					LabelId:        labelManage[lIndex].Id,
+					ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+			} else if info.Age > 60 {
+				lIndex := labelIndexMap["绂婚��浼戜汉鍛�"]
+				identity = append(identity, db.Identity{
+					CommunityID:    communityID,
+					DocumentNumber: info.DocumentNumber,
+					LabelId:        labelManage[lIndex].Id,
+					ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+			}
+			//fmt.Println("涓婄彮鏃�", info.DocumentNumber, info.Age, countMaxRows, colS, colE)
+		} else {
+			countMaxRows, colS, colE := CountMaxRows(inModelMatrix, 30, 30)
+			logger.Info("瑙勫緥鍑哄嫟鏃堕棿娈碉細", colS, colE, "\t娆℃暟: ", countMaxRows)
+			if countMaxRows >= 10 {
+				if info.Age <= 22 && info.Age >= 7 {
+					lIndex := labelIndexMap["瀛︾敓"]
+					identity = append(identity, db.Identity{
+						CommunityID:    communityID,
+						DocumentNumber: info.DocumentNumber,
+						LabelId:        labelManage[lIndex].Id,
+						ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+				} else if info.Age >= 23 && info.Age <= 60 {
+					lIndex := labelIndexMap["涓婄彮鏃�"]
+					identity = append(identity, db.Identity{
+						CommunityID:    communityID,
+						DocumentNumber: info.DocumentNumber,
+						LabelId:        labelManage[lIndex].Id,
+						ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+				} else if info.Age > 60 {
+					lIndex := labelIndexMap["绂婚��浼戜汉鍛�"]
+					identity = append(identity, db.Identity{
+						CommunityID:    communityID,
+						DocumentNumber: info.DocumentNumber,
+						LabelId:        labelManage[lIndex].Id,
+						ExpireTime:     GetCurrentDateAddDaysTimestamp(labelManage[lIndex].ValidDays)})
+				}
+				//fmt.Println("涓婄彮鏃�", info.DocumentNumber, info.Age, countMaxRows, colS, colE)
+			}
+		}
+
+		//fmt.Println("outModelMatrix: ", outModelMatrix)
+		//fmt.Println("inModelMatrix: ", inModelMatrix)
 	}
-	fmt.Println(outModelMatrix)
-	fmt.Println(inModelMatrix)
+	return identity
 }
 
 // 璁$畻涓�闃跺鏁�

--
Gitblit v1.8.0