From c7ec5e7a2762eb9cd2c9d2a23fc1de4677161a30 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 11 二月 2025 10:14:08 +0800
Subject: [PATCH] 完善参数
---
models/accessRegularity.go | 29 ++++++++++++++++++++++-------
models/model.go | 9 +++++----
db/db.go | 3 ++-
db/model_rule.go | 5 +++--
4 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/db/db.go b/db/db.go
index 34ab3bc..6e78684 100644
--- a/db/db.go
+++ b/db/db.go
@@ -351,8 +351,9 @@
Unit: "",
Range: "",
Value: "",
- ValType: "[{\"label\":\"杩沑", \"value\":\"in\"},{\"label\":\"鍑篭", \"value\":\"out\"}]",
+ ValType: "string",
Operator: "==",
+ Options: "[{\"label\":\"杩沑", \"value\":\"in\"},{\"label\":\"鍑篭", \"value\":\"out\"}]",
Sort: 3,
},
},
diff --git a/db/model_rule.go b/db/model_rule.go
index a6aab41..9244338 100644
--- a/db/model_rule.go
+++ b/db/model_rule.go
@@ -17,19 +17,20 @@
RuleArg struct {
Alias string `gorm:"column:alias" json:"alias"` // 鍙傛暟鐨勫埆鍚�
Name string `gorm:"column:name" json:"name"` // 鍙傛暟鍚嶇О
- Type string `gorm:"column:type" json:"type"` // 鍙傛暟绫诲瀷: input, option, range, image
+ Type string `gorm:"column:type" json:"type"` // 鍙傛暟绫诲瀷: input, select, range, image
Must bool `gorm:"column:must" json:"must"` // 鏄惁蹇呭~
Unit string `gorm:"column:unit" json:"unit"` // 鍗曚綅
Range string `gorm:"column:range" json:"range"` // 鍊肩殑鑼冨洿锛宔g锛�0,100琛ㄧず浠�0鍒�100
Value string `gorm:"column:value" json:"value"` // 鍙傛暟鍊�
ValType string `gorm:"column:val_type" json:"valType"` // 鍙傛暟鍊肩被鍨� int, string, bool
Operator string `gorm:"column:operator" json:"operator"` // 杩愮畻绗�
+ Options string `gorm:"column:options" json:"options"` // 閫夐」鐨勫閫夊弬鏁�
Sort int `gorm:"column:sort;default:0" json:"sort"` // 鍙傛暟椤哄簭
}
ModelRuleSet struct {
Alias string `json:"alias"` // 鍙傛暟鐨勫埆鍚�
- Type string `json:"type"` // 鍙傛暟绫诲瀷: input, option, range, image
+ Type string `json:"type"` // 鍙傛暟绫诲瀷: input, select, range, image
Name string `json:"name"` // 鍙傛暟鍚嶇О
Value interface{} `json:"value"` // 鍙傛暟鍊�
ValType string `json:"valType"` // 鍊肩被鍨�
diff --git a/models/accessRegularity.go b/models/accessRegularity.go
index 5d1b59b..301ac5d 100644
--- a/models/accessRegularity.go
+++ b/models/accessRegularity.go
@@ -174,10 +174,16 @@
return ""
}
-func countValidDays(records []*service.ESRecordInfo, startHour, endHort int, direction string) int {
+func countValidDays(records []*service.ESRecordInfo, startHour, endHour int, direction string) int {
layout := "2006-01-02 15:04:05" // 鏃堕棿鏍煎紡
lastDirectionMap := make(map[string]string) // 璁板綍鏈�鍚庝竴鏉� Direction
lastTimeMap := make(map[string]time.Time) // 璁板綍鏈�鍚庝竴鏉℃椂闂�
+
+ // 鍒ゆ柇鏄惁璺ㄥぉ
+ var isCrossDay bool
+ if endHour < startHour {
+ isCrossDay = true
+ }
for _, record := range records {
// 瑙f瀽鏃堕棿
@@ -191,13 +197,22 @@
hour := t.Hour()
var key string
- // 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
- if hour >= startHour { // 21:00-23:59 褰掑睘褰撳ぉ
- key = t.Format("2006-01-02")
- } else if hour < endHort { // 00:00-02:59 褰掑睘鍓嶄竴澶�
- key = t.AddDate(0, 0, -1).Format("2006-01-02")
+ if !isCrossDay {
+ // 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
+ if hour >= startHour && hour < endHour {
+ key = t.Format("2006-01-02")
+ } else {
+ continue // 涓嶅湪缁熻鑼冨洿鍐�
+ }
} else {
- continue // 涓嶅湪缁熻鑼冨洿鍐�
+ // 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
+ if hour >= startHour { // 21:00-23:59 褰掑睘褰撳ぉ
+ key = t.Format("2006-01-02")
+ } else if hour < endHour { // 00:00-02:59 褰掑睘鍓嶄竴澶�
+ key = t.AddDate(0, 0, -1).Format("2006-01-02")
+ } else {
+ continue // 涓嶅湪缁熻鑼冨洿鍐�
+ }
}
// 璁板綍璇ユ椂闂存鍐呯殑鏈�鍚庝竴鏉℃暟鎹�
diff --git a/models/model.go b/models/model.go
index 7d9d983..4b1a51a 100644
--- a/models/model.go
+++ b/models/model.go
@@ -14,10 +14,11 @@
}
var modelRegistry = map[string]func() Model{
- "gather": func() Model { return &GatherModel{} },
- "disappear": func() Model { return &DisappearModel{} },
- "location": func() Model { return &LocationModel{} },
- "night": func() Model { return &nightModel{} },
+ "gather": func() Model { return &GatherModel{} },
+ "disappear": func() Model { return &DisappearModel{} },
+ "location": func() Model { return &LocationModel{} },
+ "night": func() Model { return &nightModel{} },
+ "accessRegularity": func() Model { return &RegularityModel{} },
// 娣诲姞鍏朵粬妯″瀷
}
--
Gitblit v1.8.0