sunty
2024-04-30 a1fdc969dd20a97087e986c69fdfd25ffe115368
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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)
        }
    }
 
}