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>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/muyuqingfeng/iloom/textile-service/internal/repository"
|
|
)
|
|
|
|
type DashboardStats struct {
|
|
TotalPlans int `json:"total_plans"`
|
|
ActivePlans int `json:"active_plans"`
|
|
CompletedPlans int `json:"completed_plans"`
|
|
YarnStockCount int `json:"yarn_stock_count"`
|
|
LowStockCount int `json:"low_stock_count"`
|
|
PendingPayments int `json:"pending_payments"`
|
|
}
|
|
|
|
type DashboardService struct {
|
|
planRepo *repository.PlanRepo
|
|
yarnRepo *repository.YarnRepo
|
|
paymentRepo *repository.PaymentRepo
|
|
}
|
|
|
|
func NewDashboardService(planRepo *repository.PlanRepo, yarnRepo *repository.YarnRepo, paymentRepo *repository.PaymentRepo) *DashboardService {
|
|
return &DashboardService{
|
|
planRepo: planRepo,
|
|
yarnRepo: yarnRepo,
|
|
paymentRepo: paymentRepo,
|
|
}
|
|
}
|
|
|
|
func (s *DashboardService) Stats(ctx context.Context, companyID string) (*DashboardStats, error) {
|
|
total, active, completed, err := s.planRepo.CountByFactory(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
yarnCount, err := s.yarnRepo.Count(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lowStockCount, err := s.yarnRepo.CountLowStock(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pendingPayments, err := s.paymentRepo.CountPending(ctx, companyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &DashboardStats{
|
|
TotalPlans: total,
|
|
ActivePlans: active,
|
|
CompletedPlans: completed,
|
|
YarnStockCount: yarnCount,
|
|
LowStockCount: lowStockCount,
|
|
PendingPayments: pendingPayments,
|
|
}, nil
|
|
}
|