Align origin/main with upstream/main (GitHub). The two branches diverged due to pre-rebase vs post-rebase merge commits for the k8s-amd64-dockerfiles feature. Includes: multi-stage Go compilation Dockerfiles, pan-bolt inventory features, CRM relations, Excel import tooling, proto/gRPC updates, migration scripts, and tools/ directory. Excludes deploy/bin/ pre-compiled binaries (arm64, not needed for amd64 K3s cluster; builds use multi-stage Dockerfiles now).
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"muyu-apiserver/pkg/tenantctx"
|
|
"muyu-apiserver/rpc/inventory/internal/svc"
|
|
"muyu-apiserver/rpc/inventory/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type GetStockSummaryLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetStockSummaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockSummaryLogic {
|
|
return &GetStockSummaryLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetStockSummaryLogic) GetStockSummary(in *pb.StockSummaryReq) (*pb.StockSummaryResp, error) {
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
summaries, err := l.svcCtx.ProductModel.FindProductSummary(l.ctx, tenantId)
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
var productCount, totalPieces, totalPans int64
|
|
var totalLengthM, totalSalesValue float64
|
|
for _, s := range summaries {
|
|
productCount += s.ColorCount
|
|
totalPieces += s.TotalBoltCount
|
|
totalPans += s.TotalPanCount
|
|
totalLengthM += s.TotalLengthM
|
|
}
|
|
_ = totalSalesValue
|
|
|
|
return &pb.StockSummaryResp{
|
|
ProductCount: productCount,
|
|
TotalPieces: totalPieces,
|
|
TotalPans: totalPans,
|
|
TotalLengthM: fmt.Sprintf("%.2f", totalLengthM),
|
|
TotalSalesValue: "0.00",
|
|
}, nil
|
|
}
|