| | |
| | | ) |
| | | |
| | | // 计算抓拍天数 |
| | | func CalculateCaptureDays(details []db.CaptureDetail) int { |
| | | func CalculateCaptureDays(details []db.CaptureDetail) (int, int) { |
| | | // 使用 map 来存储每天是否有抓拍记录 |
| | | captureMap := make(map[string]bool) |
| | | for _, detail := range details { |
| | | //pointDate := "" |
| | | //pointTime := "" |
| | | //pointDirection := "" |
| | | overnightCount := 0 |
| | | for i, detail := range details { |
| | | // 解析抓拍日期 |
| | | layout := "2006-01-02 15:04:05" |
| | | captureTime, err := time.Parse(layout, detail.CaptureDate) |
| | |
| | | fmt.Println("解析抓拍日期时出错:", err) |
| | | continue |
| | | } |
| | | //fmt.Println(captureTime, detail.Direction) |
| | | // 获取日期部分 |
| | | date := captureTime.Format("2006-01-02") |
| | | //time := captureTime.Format("15:04:05") |
| | | // 在 map 中标记这一天有抓拍记录 |
| | | captureMap[date] = true |
| | | if i == len(details)-1 { |
| | | break |
| | | } |
| | | |
| | | // 第一个验证条件:当前为 in,时间在下午 16 点以后 |
| | | currTime, _ := time.Parse("2006-01-02 15:04:05", detail.CaptureDate) |
| | | if detail.Direction == "in" && currTime.Hour() >= 16 { |
| | | // 第二个验证条件:下一个为 out,时间在上午 5 点之后 12 点之前 |
| | | nextDetail := details[i+1] |
| | | nextTime, _ := time.Parse("2006-01-02 15:04:05", nextDetail.CaptureDate) |
| | | nextDay := nextTime.AddDate(0, 0, -1).Format("2006-01-02") |
| | | if nextDetail.Direction == "out" && nextTime.Hour() >= 5 && nextTime.Hour() < 12 && nextDay == detail.CaptureDate[:10] { |
| | | overnightCount++ |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 统计有抓拍记录的天数 |
| | |
| | | captureDays++ |
| | | } |
| | | |
| | | return captureDays |
| | | return captureDays, overnightCount |
| | | } |
| | | |
| | | // 设置状态 |
| | |
| | | person, ok := statusIndex[info.DocumentNumber] |
| | | if !ok { |
| | | // 不存在对应的人员状态为新数据 |
| | | filteredInfos = append(filteredInfos, db.PersonStatus{CommunityID: communityID, DocumentNumber: info.DocumentNumber, Status: info.Status, FrequentAddress: info.FrequentAddress}) |
| | | filteredInfos = append(filteredInfos, db.PersonStatus{OrgId: info.OrgId, CommunityID: communityID, DocumentNumber: info.DocumentNumber, Status: info.Status, FrequentAddress: info.FrequentAddress}) |
| | | continue |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 更新过滤后的信息列表 |
| | | filteredInfos = append(filteredInfos, db.PersonStatus{CommunityID: communityID, DocumentNumber: info.DocumentNumber, Status: info.Status, FrequentAddress: info.FrequentAddress}) |
| | | filteredInfos = append(filteredInfos, db.PersonStatus{OrgId: info.OrgId, CommunityID: communityID, DocumentNumber: info.DocumentNumber, Status: info.Status, FrequentAddress: info.FrequentAddress}) |
| | | |
| | | } |
| | | |