|
|
|
@@ -108,7 +108,7 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka. |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
sendRestrictedZoneAlert(gw.ID, msg.ID, writer, ctx, allowedZones, db) |
|
|
|
sendRestrictedZoneAlert(gw.Zone, msg.ID, writer, ctx, allowedZones, db) |
|
|
|
} |
|
|
|
|
|
|
|
func LocationToBeaconServiceAI(msg model.HTTPLocation, db *gorm.DB, writer *kafka.Writer, ctx context.Context) { |
|
|
|
@@ -165,10 +165,10 @@ func LocationToBeaconServiceAI(msg model.HTTPLocation, db *gorm.DB, writer *kafk |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
sendRestrictedZoneAlert(gw.ID, tracker.ID, writer, ctx, allowedZones, db) |
|
|
|
sendRestrictedZoneAlert(gw.Zone, tracker.ID, writer, ctx, allowedZones, db) |
|
|
|
} |
|
|
|
|
|
|
|
func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) { |
|
|
|
func SendAlert(trackerId, alertType, zone string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) { |
|
|
|
var existingAlert model.Alert |
|
|
|
result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").Limit(1).Find(&existingAlert) |
|
|
|
|
|
|
|
@@ -179,6 +179,7 @@ func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Co |
|
|
|
Type: alertType, |
|
|
|
Status: "new", |
|
|
|
Timestamp: time.Now(), |
|
|
|
Zone: zone, |
|
|
|
} |
|
|
|
|
|
|
|
if err := InsertAlert(alert, db, ctx); err != nil { |
|
|
|
@@ -208,9 +209,9 @@ func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Co |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func sendRestrictedZoneAlert(gwId, trackerId string, writer *kafka.Writer, ctx context.Context, allowedZones []string, db *gorm.DB) { |
|
|
|
if len(allowedZones) != 0 && !slices.Contains(allowedZones, gwId) { |
|
|
|
SendAlert(trackerId, "Restricted zone", writer, ctx, db) |
|
|
|
func sendRestrictedZoneAlert(gwZone, trackerId string, writer *kafka.Writer, ctx context.Context, allowedZones []string, db *gorm.DB) { |
|
|
|
if len(allowedZones) != 0 && !slices.Contains(allowedZones, gwZone) { |
|
|
|
SendAlert(trackerId, "Restricted zone", gwZone, writer, ctx, db) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|