chore: refacto
This commit is contained in:
@@ -8,27 +8,22 @@ import (
|
||||
)
|
||||
|
||||
// GetDeliverymanQueueInfo récupère les infos de queue d'un livreur
|
||||
func (d *Database) GetDeliverymanQueueInfo(deliveryman string) (map[string]interface{}, error) {
|
||||
func (d *Database) GetDeliverymanQueueInfo(deliveryman string) (map[string]any, error) {
|
||||
queueKey := fmt.Sprintf("queue:deliveryman:%s", deliveryman)
|
||||
|
||||
// Nombre de commandes dans la queue
|
||||
queueSize, _ := Redis.ZCard(RedisCtx, queueKey).Result()
|
||||
|
||||
// Récupérer toutes les commandes
|
||||
commandIDs, _ := Redis.ZRange(RedisCtx, queueKey, 0, -1).Result()
|
||||
|
||||
// Vérifier le nombre de livreurs actifs pour déterminer la limite
|
||||
activeCount, _ := d.CountActiveDeliverymen()
|
||||
|
||||
// Récupérer les détails de chaque commande
|
||||
var commands []map[string]interface{}
|
||||
var commands []map[string]any
|
||||
for i, cmdIDStr := range commandIDs {
|
||||
commandID := extractCommandID(cmdIDStr)
|
||||
if commandID <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Récupérer les données de la commande
|
||||
commandKey := fmt.Sprintf("queue:pending:%d", commandID)
|
||||
data, err := Redis.Get(RedisCtx, commandKey).Result()
|
||||
if err != nil {
|
||||
@@ -40,7 +35,7 @@ func (d *Database) GetDeliverymanQueueInfo(deliveryman string) (map[string]inter
|
||||
continue
|
||||
}
|
||||
|
||||
commands = append(commands, map[string]interface{}{
|
||||
commands = append(commands, map[string]any{
|
||||
"position": i + 1,
|
||||
"command_id": commandID,
|
||||
"address": queueItem.Address,
|
||||
@@ -51,15 +46,12 @@ func (d *Database) GetDeliverymanQueueInfo(deliveryman string) (map[string]inter
|
||||
})
|
||||
}
|
||||
|
||||
// Déterminer si le livreur peut accepter plus de commandes
|
||||
canAcceptMore := true
|
||||
if activeCount > 1 {
|
||||
// Plusieurs livreurs: limite de 10
|
||||
canAcceptMore = queueSize < MAX_COMMANDS_PER_DELIVERYMAN
|
||||
}
|
||||
// Si un seul livreur: pas de limite (canAcceptMore reste true)
|
||||
|
||||
return map[string]interface{}{
|
||||
return map[string]any{
|
||||
"deliveryman": deliveryman,
|
||||
"queue_size": queueSize,
|
||||
"commands": commands,
|
||||
@@ -69,15 +61,13 @@ func (d *Database) GetDeliverymanQueueInfo(deliveryman string) (map[string]inter
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *Database) GetAllQueuesOverview() (map[string]interface{}, error) {
|
||||
overview := make(map[string]interface{})
|
||||
func (d *Database) GetAllQueuesOverview() (map[string]any, error) {
|
||||
overview := make(map[string]any)
|
||||
|
||||
// Queue générale
|
||||
generalQueueSize, _ := Redis.ZCard(RedisCtx, "queue:pending:sorted").Result()
|
||||
overview["general_queue"] = generalQueueSize
|
||||
|
||||
// Queues par livreur avec détails
|
||||
deliverymanQueues := make(map[string]interface{})
|
||||
deliverymanQueues := make(map[string]any)
|
||||
keys, _ := Redis.Keys(RedisCtx, "queue:deliveryman:*").Result()
|
||||
|
||||
for _, key := range keys {
|
||||
@@ -88,7 +78,7 @@ func (d *Database) GetAllQueuesOverview() (map[string]interface{}, error) {
|
||||
username := key[len("queue:deliveryman:"):]
|
||||
queueSize, _ := Redis.ZCard(RedisCtx, key).Result()
|
||||
|
||||
deliverymanQueues[username] = map[string]interface{}{
|
||||
deliverymanQueues[username] = map[string]any{
|
||||
"queue_size": queueSize,
|
||||
"can_accept_more": queueSize < MAX_COMMANDS_PER_DELIVERYMAN,
|
||||
"capacity": fmt.Sprintf("%d/%d", queueSize, MAX_COMMANDS_PER_DELIVERYMAN),
|
||||
@@ -96,8 +86,6 @@ func (d *Database) GetAllQueuesOverview() (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
overview["deliveryman_queues"] = deliverymanQueues
|
||||
|
||||
// Total
|
||||
var totalPending int64 = generalQueueSize
|
||||
for _, key := range keys {
|
||||
if len(key) > 6 && key[len(key)-6:] == ":count" {
|
||||
@@ -112,11 +100,10 @@ func (d *Database) GetAllQueuesOverview() (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
// GetQueueStats - Statistiques détaillées
|
||||
func (d *Database) GetQueueStats() (map[string]interface{}, error) {
|
||||
func (d *Database) GetQueueStats() (map[string]any, error) {
|
||||
normalCount, _ := Redis.ZCard(RedisCtx, "queue:pending:sorted").Result()
|
||||
priorityCount, _ := Redis.ZCard(RedisCtx, "queue:priority:sorted").Result()
|
||||
|
||||
// Compter les commandes dans les queues des livreurs
|
||||
var deliverymanQueueCount int64
|
||||
keys, _ := Redis.Keys(RedisCtx, "queue:deliveryman:*").Result()
|
||||
for _, key := range keys {
|
||||
@@ -127,7 +114,6 @@ func (d *Database) GetQueueStats() (map[string]interface{}, error) {
|
||||
deliverymanQueueCount += count
|
||||
}
|
||||
|
||||
// Calculer temps d'attente moyen
|
||||
var totalWaitTime int64
|
||||
var commandCount int64
|
||||
|
||||
@@ -154,7 +140,7 @@ func (d *Database) GetQueueStats() (map[string]interface{}, error) {
|
||||
avgWaitTime = int(totalWaitTime / commandCount)
|
||||
}
|
||||
|
||||
stats := map[string]interface{}{
|
||||
stats := map[string]any{
|
||||
"total_pending": normalCount + priorityCount,
|
||||
"general_queue": normalCount,
|
||||
"priority_queue": priorityCount,
|
||||
|
||||
Reference in New Issue
Block a user