chore: refacto
This commit is contained in:
@@ -3,7 +3,6 @@ package db
|
||||
import (
|
||||
"fmt"
|
||||
"gestion/services"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -16,7 +15,7 @@ func (d *Database) SetCommandETA(commandID, minutes int) error {
|
||||
now := time.Now()
|
||||
arrivalTime := now.Add(time.Duration(minutes) * time.Minute)
|
||||
|
||||
eta := map[string]interface{}{
|
||||
eta := map[string]any{
|
||||
"command_id": commandID,
|
||||
"total_eta_minutes": minutes,
|
||||
"eta_minutes": minutes,
|
||||
@@ -37,9 +36,6 @@ func (d *Database) SetCommandETA(commandID, minutes int) error {
|
||||
|
||||
d.ScheduleETANotifications(commandID, minutes)
|
||||
|
||||
log.Printf("✅ ETA défini pour commande %d: %d minutes (arrivée: %s)",
|
||||
commandID, minutes, arrivalTime.Format("15:04"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -86,7 +82,6 @@ func (d *Database) ScheduleETANotifications(commandID, etaMinutes int) error {
|
||||
})
|
||||
}
|
||||
|
||||
log.Printf("✅ Notifications programmées pour commande %d (ETA: %d min)", commandID, etaMinutes)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -121,15 +116,12 @@ func (d *Database) SendETANotification(commandID int, notifType string) {
|
||||
|
||||
channel := fmt.Sprintf("notifications:command:%d", commandID)
|
||||
Redis.Publish(RedisCtx, channel, message)
|
||||
|
||||
log.Printf("📢 Notification envoyée: %s", message)
|
||||
}
|
||||
|
||||
// CalculateETAForDeliveryman calcule l'ETA entre un livreur et une destination
|
||||
func (d *Database) CalculateETAForDeliveryman(deliveryman string, destLat, destLng float64) int {
|
||||
livreurLat, livreurLng, err := d.GetDeliveryPersonLocation(deliveryman)
|
||||
if err != nil {
|
||||
log.Printf("⚠️ Position livreur %s non trouvée, utilisation ETA par défaut", deliveryman)
|
||||
return services.MinETA
|
||||
}
|
||||
|
||||
@@ -145,8 +137,6 @@ func (d *Database) CalculateETAForDeliveryman(deliveryman string, destLat, destL
|
||||
distance := services.CalculateDistance(from, to)
|
||||
eta := services.CalculateETA(distance)
|
||||
|
||||
log.Printf("📍 ETA calculé pour %s: %.2f km -> %d min", deliveryman, distance, eta)
|
||||
|
||||
return eta
|
||||
}
|
||||
|
||||
@@ -163,7 +153,7 @@ func (d *Database) CalculateETABetweenPoints(lat1, lng1, lat2, lng2 float64) int
|
||||
return services.CalculateETA(distance)
|
||||
}
|
||||
|
||||
func (d *Database) GetDeliverymanQueueStats(deliveryman string) (map[string]interface{}, error) {
|
||||
func (d *Database) GetDeliverymanQueueStats(deliveryman string) (map[string]any, error) {
|
||||
return d.GetDeliverymanQueueInfo(deliveryman)
|
||||
}
|
||||
|
||||
@@ -173,7 +163,7 @@ func (d *Database) SetCommandETAWithDetails(commandID, totalETA, queuePosition i
|
||||
now := time.Now()
|
||||
arrivalTime := now.Add(time.Duration(totalETA) * time.Minute)
|
||||
|
||||
eta := map[string]interface{}{
|
||||
eta := map[string]any{
|
||||
"command_id": commandID,
|
||||
"total_eta_minutes": totalETA,
|
||||
"queue_position": queuePosition,
|
||||
@@ -189,8 +179,5 @@ func (d *Database) SetCommandETAWithDetails(commandID, totalETA, queuePosition i
|
||||
|
||||
Redis.Expire(RedisCtx, key, 4*time.Hour)
|
||||
|
||||
log.Printf("✅ ETA détaillé pour commande %d: Total=%dmin Position=%d",
|
||||
commandID, totalETA, queuePosition)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user