Go workspace (go.work) with 5 microservices + shared library: - gateway (8080), auth-service (8081), purchaser-service (8082) - textile-service (8083), washing-service (8084) - shared: proto definitions, common packages Infrastructure: docker-compose for local dev, K8s manifests for K3s cluster deployment (mysql/redis/etcd + traefik ingress). Frontend (iloom-flatten) added as git submodule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/muyuqingfeng/iloom/washing-service/internal/repository"
|
|
)
|
|
|
|
type DashboardStats struct {
|
|
TotalPlans int `json:"total_plans"`
|
|
PendingPlans int `json:"pending_plans"`
|
|
CompletedPlans int `json:"completed_plans"`
|
|
FinishedProducts int `json:"finished_products"`
|
|
TotalStockMeters float64 `json:"total_stock_meters"`
|
|
PendingPayments int `json:"pending_payments"`
|
|
}
|
|
|
|
type DashboardService struct {
|
|
planRepo *repository.PlanRepo
|
|
fpRepo *repository.FinishedProductRepo
|
|
payRepo *repository.PaymentRepo
|
|
}
|
|
|
|
func NewDashboardService(
|
|
pr *repository.PlanRepo,
|
|
fpr *repository.FinishedProductRepo,
|
|
payr *repository.PaymentRepo,
|
|
) *DashboardService {
|
|
return &DashboardService{
|
|
planRepo: pr,
|
|
fpRepo: fpr,
|
|
payRepo: payr,
|
|
}
|
|
}
|
|
|
|
func (s *DashboardService) Stats(ctx context.Context, companyID string) (*DashboardStats, error) {
|
|
total, pending, completed, err := s.planRepo.CountByStatus(ctx, companyID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count plans: %w", err)
|
|
}
|
|
|
|
fpCount, err := s.fpRepo.Count(ctx, companyID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count finished products: %w", err)
|
|
}
|
|
|
|
stockMeters, err := s.fpRepo.TotalStock(ctx, companyID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("total stock: %w", err)
|
|
}
|
|
|
|
pendingPay, err := s.payRepo.CountPending(ctx, companyID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count pending payments: %w", err)
|
|
}
|
|
|
|
return &DashboardStats{
|
|
TotalPlans: total,
|
|
PendingPlans: pending,
|
|
CompletedPlans: completed,
|
|
FinishedProducts: fpCount,
|
|
TotalStockMeters: stockMeters,
|
|
PendingPayments: pendingPay,
|
|
}, nil
|
|
}
|