| @@ -19,6 +19,7 @@ import ( | |||||
| "github.com/AFASystems/presence/internal/pkg/model" | "github.com/AFASystems/presence/internal/pkg/model" | ||||
| "github.com/AFASystems/presence/internal/pkg/service" | "github.com/AFASystems/presence/internal/pkg/service" | ||||
| "gorm.io/gorm" | "gorm.io/gorm" | ||||
| "gorm.io/gorm/clause" | |||||
| ) | ) | ||||
| // ServerApp holds dependencies and state for the server service. | // ServerApp holds dependencies and state for the server service. | ||||
| @@ -87,7 +88,7 @@ func (a *ServerApp) Init(ctx context.Context) error { | |||||
| } | } | ||||
| for _, c := range configs { | for _, c := range configs { | ||||
| a.DB.Create(&c) | |||||
| a.DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&c) | |||||
| } | } | ||||
| a.DB.Find(&configs) | a.DB.Find(&configs) | ||||
| for _, c := range configs { | for _, c := range configs { | ||||
| @@ -151,9 +151,9 @@ func LocationToBeaconServiceAI(msg model.HTTPLocation, db *gorm.DB, writer *kafk | |||||
| func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) { | func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) { | ||||
| var existingAlert model.Alert | var existingAlert model.Alert | ||||
| result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").First(&existingAlert) | |||||
| result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").Limit(1).Find(&existingAlert) | |||||
| if result.Error == gorm.ErrRecordNotFound || existingAlert.Status == "resolved" { | |||||
| if result.RowsAffected == 0 || existingAlert.Status == "resolved" { | |||||
| alert := model.Alert{ | alert := model.Alert{ | ||||
| ID: uuid.New().String(), | ID: uuid.New().String(), | ||||
| TrackerID: trackerId, | TrackerID: trackerId, | ||||
| @@ -7,7 +7,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |||||
| curl -s -X PATCH "${BASE_URL}/reslevis/settings" \ | curl -s -X PATCH "${BASE_URL}/reslevis/settings" \ | ||||
| -H "Content-Type: application/json" \ | -H "Content-Type: application/json" \ | ||||
| -d '{ | -d '{ | ||||
| "current_algorithm": "filter", | |||||
| "current_algorithm": "ai", | |||||
| "last_seen_threshold": 310, | "last_seen_threshold": 310, | ||||
| "beacon_metric_size": 100, | "beacon_metric_size": 100, | ||||
| "HA_send_interval": 60, | "HA_send_interval": 60, | ||||