chore: refacto

This commit is contained in:
2026-03-27 22:23:46 +01:00
parent 75bf4caaa1
commit 5380abe8ed
67 changed files with 1751 additions and 2573 deletions
@@ -9,7 +9,6 @@ import (
)
// FindLeastLoadedDeliveryman trouve le livreur avec le moins de commandes ET qui peut accepter
// ✅ Respecte le statut BUSY (queue >= 10)
func (d *Database) FindLeastLoadedDeliveryman() (string, error) {
keys, err := Redis.Keys(RedisCtx, "delivery:status:*").Result()
if err != nil || len(keys) == 0 {
@@ -30,7 +29,6 @@ func (d *Database) FindLeastLoadedDeliveryman() (string, error) {
var status models.DeliveryPersonStatus
json.Unmarshal([]byte(data), &status)
// ✅ Ignorer les livreurs offline
if status.Status == "offline" {
continue
}
@@ -70,7 +68,6 @@ func (d *Database) FindLeastLoadedDeliveryman() (string, error) {
}
// FindAvailableOrLeastLoadedDeliveryman trouve un livreur disponible ou le moins chargé
// ✅ Respecte le statut BUSY
func (d *Database) FindAvailableOrLeastLoadedDeliveryman() (string, string, int, error) {
keys, err := Redis.Keys(RedisCtx, "delivery:status:*").Result()
if err != nil || len(keys) == 0 {
@@ -96,7 +93,6 @@ func (d *Database) FindAvailableOrLeastLoadedDeliveryman() (string, string, int,
continue
}
// ✅ NOUVEAU: Vérifier si le livreur peut accepter
if !d.CanDeliverymanAcceptCommands(username) {
continue
}
@@ -104,7 +100,6 @@ func (d *Database) FindAvailableOrLeastLoadedDeliveryman() (string, string, int,
queueKey := fmt.Sprintf("queue:deliveryman:%s", username)
queueSize, _ := Redis.ZCard(RedisCtx, queueKey).Result()
// Priorité: available > busy avec moins de commandes
if status.Status == "available" && queueSize == 0 {
return username, "available", 0, nil
}
@@ -124,7 +119,6 @@ func (d *Database) FindAvailableOrLeastLoadedDeliveryman() (string, string, int,
}
// GetLeastLoadedDeliverymanForced retourne le livreur avec le moins de commandes (SANS limite)
// ⚠️ À utiliser uniquement pour assignation forcée par admin
func (d *Database) GetLeastLoadedDeliverymanForced() (string, int64, error) {
activeUsernames, err := d.GetAllActiveDeliverymenUsernames()
if err != nil || len(activeUsernames) == 0 {
@@ -144,9 +138,6 @@ func (d *Database) GetLeastLoadedDeliverymanForced() (string, int64, error) {
}
}
log.Printf("⚠️ [FORCED] %s sélectionné (%d commandes - SANS LIMITE)",
leastLoaded, minQueueSize)
return leastLoaded, minQueueSize, nil
}
@@ -157,7 +148,6 @@ func (d *Database) AreAllDeliverymenAtCapacity() (bool, int, error) {
return false, 0, fmt.Errorf("aucun livreur actif")
}
// Si un seul livreur, jamais à capacité max
if len(activeUsernames) == 1 {
return false, 1, nil
}