sunty
2024-05-27 8ad4f99e07fb2d4d5ad34aaf6ec9c593e1091417
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package rule
 
import (
    "basic.com/valib/logger.git"
    "fmt"
    "ruleModelEngine/config"
    "ruleModelEngine/data"
    "ruleModelEngine/db"
    "ruleModelEngine/task"
    "strconv"
)
 
//
//// 检查规则表书否存在异常
//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("进出异常开始入口!!!!!!")
    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)
    }
    fmt.Println("ruleInfo: ", ruleInfo)
    communityIDs, err := db.GetCommunityIDs()
    //fmt.Println("communityIDs:", communityIDs)
    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)
        }
        //fmt.Println(labeManage)
        //fmt.Println("personStatus: ", personStatus)
        //fmt.Println("CcmmunityIDs: ", cmmunityID)
        //按社区id查询近一个月es数据
        captureInfos, err := db.Query1MDataByCommunityId(communityID)
        //fmt.Println("captureInfos: ", captureInfos)
        //residentCount := 0
        for i := range captureInfos {
            //fmt.Println(captureInfos[i].DocumentNumber)
            captureDays, overnightCount := data.CalculateCaptureDays(captureInfos[i].CaptureDetail)
            captureInfos[i].CaptureDays = 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)
        }
        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, identity.Id)
                errIdentity := db.UpdateDBPersonLabel(identity)
                if errIdentity != nil {
                    logger.Error("UpdateDBPersonLabel Error", errIdentity)
                }
                captureInfos = attribute
 
            }
        }
        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)
        //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)
        //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)
        if UpdateMoveInoutErr != nil {
            logger.Error("UpdateMoveInoutErr Error: ", UpdateMoveInoutErr)
        }
    }
}