From 8ed1e960d5b13822385ecb9fcbdd18807de701e4 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期一, 10 二月 2025 16:36:23 +0800
Subject: [PATCH] 完善出行规律模型内容
---
models/gather_model.go | 1
db/model.go | 2
models/accessRegularity.go | 72 ++++++++++++++++++++++--
models/common.go | 12 ++++
models/disappear.go | 11 ---
db/db.go | 78 ++++++++++++++++++++++++++
6 files changed, 158 insertions(+), 18 deletions(-)
diff --git a/db/db.go b/db/db.go
index 6ed04f8..34ab3bc 100644
--- a/db/db.go
+++ b/db/db.go
@@ -82,6 +82,14 @@
Description: "閫氱敤鍦烘墍鍒嗘瀽妯″瀷",
Version: "v1.0.0",
Enabled: false,
+ }, {
+ BaseModel: BaseModel{
+ ID: ModelIdAccessRegularity,
+ },
+ Name: "鍑鸿瑙勫緥鍒嗘瀽",
+ Description: "鍑鸿瑙勫緥鍒嗘瀽妯″瀷",
+ Version: "v1.0.0",
+ Enabled: false,
},
//{
// BaseModel: BaseModel{
@@ -278,6 +286,76 @@
Sort: 1,
},
},
+
+ // 鍑鸿瑙勫緥
+ {
+ Id: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
+ ModelId: ModelIdAccessRegularity,
+ Scope: "",
+ RuleArg: RuleArg{
+ Alias: "duration",
+ Name: "鐩戞帶鏃堕棿娈�",
+ Type: "input",
+ Must: true,
+ Unit: "澶╁唴",
+ Range: "1,60",
+ Value: "30",
+ ValType: "int",
+ Operator: ">=",
+ Sort: 0,
+ },
+ },
+ {
+ Id: "f47ac10b-58cc-4372-a567-0e02b2c3d479",
+ ModelId: ModelIdAccessRegularity,
+ Scope: "",
+ RuleArg: RuleArg{
+ Alias: "timeRange",
+ Name: "鍑鸿鏃堕棿娈�",
+ Type: "range",
+ Must: true,
+ Unit: "鐐�",
+ Range: "1,24",
+ Value: "21,3",
+ ValType: "int",
+ Operator: ">=",
+ Sort: 1,
+ },
+ },
+ {
+ Id: "c9bf9e57-1685-4c89-bafb-ff5af830be8a",
+ ModelId: ModelIdAccessRegularity,
+ Scope: "",
+ RuleArg: RuleArg{
+ Alias: "appearances",
+ Name: "鍑鸿娆℃暟",
+ Type: "input",
+ Must: false,
+ Unit: "娆�",
+ Range: "1,100",
+ Value: "2",
+ ValType: "int",
+ Operator: "==",
+ Sort: 2,
+ },
+ },
+ {
+ Id: "e4eaaaf2-d142-11e1-b3e4-080027620cdd",
+ ModelId: ModelIdAccessRegularity,
+ Scope: "",
+ RuleArg: RuleArg{
+ Alias: "direction",
+ Name: "杩涘嚭鏂瑰悜",
+ Type: "select",
+ Must: false,
+ Unit: "",
+ Range: "",
+ Value: "",
+ ValType: "[{\"label\":\"杩沑", \"value\":\"in\"},{\"label\":\"鍑篭", \"value\":\"out\"}]",
+ Operator: "==",
+ Sort: 3,
+ },
+ },
}
for i := range rules {
diff --git a/db/model.go b/db/model.go
index 157263b..dc1ca10 100644
--- a/db/model.go
+++ b/db/model.go
@@ -187,5 +187,5 @@
ModelIdGather = "gather" // 鑱氶泦
ModelIdDisappear = "disappear" // 澶辫釜
ModelIdLocationAnalysis = "locationAnalysis" // 鍦烘墍鍒嗘瀽
- //ModelIdNightAnalysis = "nightAnalysis" // 鏄间紡澶滃嚭鍒嗘瀽
+ ModelIdAccessRegularity = "accessRegularity" // 鍑鸿瑙勫緥鍒嗘瀽
)
diff --git a/models/accessRegularity.go b/models/accessRegularity.go
index 8e2d123..78274b8 100644
--- a/models/accessRegularity.go
+++ b/models/accessRegularity.go
@@ -15,16 +15,17 @@
type RegularityModel struct {
OrgIds []interface{} `json:"-"`
AreaIds []interface{} `json:"-"`
- IdentityType string // 浜哄憳韬唤绫诲瀷 闄岀敓浜�, 璁垮, 浣忔埛
+ IdentityType []string // 浜哄憳韬唤绫诲瀷 闄岀敓浜�, 璁垮, 浣忔埛
KeyPersonType string // 閲嶇偣浜哄憳绫诲瀷
PersonLabel string // 浜哄憳韬唤鏍囩
Task *db.ModelTask
AlarmType db.AlarmType // 棰勮鏂瑰紡
- Appearances int // 鍑虹幇娆℃暟
- Duration int // 鏃堕棿鑼冨洿, 鍗曚綅澶�
- StartHour int // 寮�濮嬭绠楃殑鏃堕棿 閰嶇疆涓哄皬鏃� 23 - 02 琛ㄧず绗竴澶�23鐐� - 绗簩澶╃殑2鐐�
- EndHour int // 缁撴潫鏃堕棿
+ Appearances int // 鍑虹幇娆℃暟
+ Duration int // 鏃堕棿鑼冨洿, 鍗曚綅澶�
+ LastDirection string // 鏈�鍚庝竴娆″嚭琛岀殑鏂瑰悜
+ StartHour int // 寮�濮嬭绠楃殑鏃堕棿 閰嶇疆涓哄皬鏃� 23 - 02 琛ㄧず绗竴澶�23鐐� - 绗簩澶╃殑2鐐�
+ EndHour int // 缁撴潫鏃堕棿
}
func (m *RegularityModel) Init(task *db.ModelTask) error {
@@ -42,7 +43,19 @@
m.AlarmType = task.AlarmType
m.KeyPersonType = task.PersonType
m.PersonLabel = task.PersonLabel
- m.IdentityType = task.IdentityType
+ m.LastDirection = "out"
+ if task.IdentityType != "" {
+ for _, t := range strings.Split(task.IdentityType, ",") {
+ if t == "all" {
+ m.IdentityType = []string{"stranger", "visitor", "resident"}
+ break
+ } else {
+ m.IdentityType = append(m.IdentityType, t)
+ }
+ }
+ } else {
+ m.IdentityType = []string{"stranger", "visitor", "resident"}
+ }
for _, v := range task.Rules {
if v.Alias == "timeRange" {
@@ -64,6 +77,12 @@
m.Duration = int(val)
}
}
+
+ if v.Alias == "direction" {
+ if val, ok := v.Value.(string); ok {
+ m.LastDirection = val
+ }
+ }
}
// 榛樿璁$畻30澶╃殑鏁版嵁
@@ -82,6 +101,47 @@
func (m *RegularityModel) Run() error {
results := make([]*db.ModelTaskResults, 0)
+ baseFilter := make([]PersonInfo, 0)
+
+ // 鏌ユ壘鎸囧畾鏃堕棿鑼冨洿鍐呭嚭琛岃繃鐨勬。妗堢紪鍙�
+ now := time.Now()
+ startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, -m.Duration).Unix()
+ err := db.GetDB().Raw(`
+ SELECT
+ document_number,
+ frequent_address,
+ FROM
+ snapshot_count_summary
+ WHERE
+ last_appearance_time > ? ""
+ AND (p.community_id IN ?
+ OR p.org_id IN ?)
+ AND p.status IN ?
+ `, startDate, m.AreaIds, m.OrgIds, m.IdentityType).Scan(&baseFilter).Error
+ if err != nil {
+ logger.Warnf(err.Error())
+ }
+
+ for _, p := range baseFilter {
+ // 璋冪敤es鍒嗘瀽姝や汉鐨勫嚭琛岃寰嬫槸鍚︾鍚堟潯浠讹紝 杩斿洖绗﹀悎鏉′欢鐨勬鏁板拰鏈�鍚庝竴娆$鍚堟潯浠剁殑鏃堕棿
+
+ // 鍐欐暟鎹簱
+ var hitCount int
+ result := &db.ModelTaskResults{
+ Title: m.Task.Name,
+ Event: fmt.Sprintf("%s %d娆�", m.Task.Name, hitCount),
+ ModelID: m.Task.ModelID,
+ ModelTaskID: m.Task.ID,
+ CommunityId: p.CommunityId,
+ OrgID: p.OrgId,
+ ObjectIds: p.DocumentNumber,
+ Location: p.FrequentAddress,
+ PicDate: time.Unix(p.LastAppearanceTime, 0).Format("2006-01-02 15:04:05"),
+ FirstPersonID: p.DocumentNumber,
+ }
+
+ results = append(results, result)
+ }
logger.Debugf("task %s last filter result %d", m.Task.Name, len(results))
return service.SaveTaskResults(results)
diff --git a/models/common.go b/models/common.go
index 879ea39..3ea65a4 100644
--- a/models/common.go
+++ b/models/common.go
@@ -1,5 +1,17 @@
package models
+type PersonInfo struct {
+ DocumentNumber string `json:"document_number"`
+ CommunityId string `json:"community_id"`
+ OrgId string `json:"org_id"`
+ PersonName string `json:"person_name"`
+ IdCard string `json:"id_card"`
+ FrequentAddress string `json:"frequent_address"`
+ LastAppearanceTime int64 `json:"last_appearance_time"`
+ LastDirection string `json:"last_direction"`
+ LastLocation string `json:"last_location"`
+}
+
func GetDomainFilters(orgIds, areaIds []interface{}) (filters []map[string]interface{}) {
filters = make([]map[string]interface{}, 0)
// 鏁版嵁鏉冮檺杩囨护
diff --git a/models/disappear.go b/models/disappear.go
index 3f09e2a..a7e0f9a 100644
--- a/models/disappear.go
+++ b/models/disappear.go
@@ -80,17 +80,6 @@
return nil
}
-type PersonInfo struct {
- DocumentNumber string `json:"document_number"`
- CommunityId string `json:"community_id"`
- OrgId string `json:"org_id"`
- PersonName string `json:"person_name"`
- IdCard string `json:"id_card"`
- LastAppearanceTime int64 `json:"last_appearance_time"`
- LastDirection string `json:"last_direction"`
- LastLocation string `json:"last_location"`
-}
-
func (m *DisappearModel) Run() error {
results := make([]*db.ModelTaskResults, 0)
var ageFilter, labelFilter, keyFilter, lastFilter []PersonInfo
diff --git a/models/gather_model.go b/models/gather_model.go
index 59fe8a4..d0c2756 100644
--- a/models/gather_model.go
+++ b/models/gather_model.go
@@ -185,6 +185,7 @@
PicDate: lt.Time,
FirstPersonID: personIds[0],
}
+
results = append(results, result)
}
return service.SaveTaskResults(results)
--
Gitblit v1.8.0