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>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/muyuqingfeng/iloom/purchaser-service/internal/model"
|
|
"github.com/muyuqingfeng/iloom/purchaser-service/internal/repository"
|
|
)
|
|
|
|
type DashboardStats struct {
|
|
TotalPlans int `json:"total_plans"`
|
|
ProducingPlans int `json:"producing_plans"`
|
|
CompletedPlans int `json:"completed_plans"`
|
|
TotalProducts int `json:"total_products"`
|
|
TotalStock float64 `json:"total_stock"`
|
|
UnpaidAmount float64 `json:"unpaid_amount"`
|
|
RecentPlans []model.ProductionPlan `json:"recent_plans"`
|
|
}
|
|
|
|
type DashboardService struct {
|
|
planRepo *repository.PlanRepo
|
|
productRepo *repository.ProductRepo
|
|
apRepo *repository.APRepo
|
|
}
|
|
|
|
func NewDashboardService(planRepo *repository.PlanRepo, productRepo *repository.ProductRepo, apRepo *repository.APRepo) *DashboardService {
|
|
return &DashboardService{
|
|
planRepo: planRepo,
|
|
productRepo: productRepo,
|
|
apRepo: apRepo,
|
|
}
|
|
}
|
|
|
|
func (s *DashboardService) Stats(ctx context.Context, companyID string) (*DashboardStats, error) {
|
|
total, producing, completed, err := s.planRepo.CountByStatus(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
productCount, err := s.productRepo.Count(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
totalStock, err := s.productRepo.TotalStock(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
unpaid, err := s.apRepo.TotalUnpaid(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
recentPlans, err := s.planRepo.Recent(ctx, companyID, 5)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &DashboardStats{
|
|
TotalPlans: total,
|
|
ProducingPlans: producing,
|
|
CompletedPlans: completed,
|
|
TotalProducts: productCount,
|
|
TotalStock: totalStock,
|
|
UnpaidAmount: unpaid,
|
|
RecentPlans: recentPlans,
|
|
}, nil
|
|
}
|