75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"muyu-apiserver/pkg/tenantctx"
|
||
|
|
"muyu-apiserver/rpc/production/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/production/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListProductionPlanLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListProductionPlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListProductionPlanLogic {
|
||
|
|
return &ListProductionPlanLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListProductionPlanLogic) ListProductionPlan(in *pb.ListProductionPlanReq) (*pb.ListProductionPlanResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
|
||
|
|
page := in.Page
|
||
|
|
if page <= 0 {
|
||
|
|
page = 1
|
||
|
|
}
|
||
|
|
pageSize := in.PageSize
|
||
|
|
if pageSize <= 0 {
|
||
|
|
pageSize = 20
|
||
|
|
}
|
||
|
|
|
||
|
|
plans, total, err := l.svcCtx.PlanModel.FindList(l.ctx, tenantId, page, pageSize, in.Status, in.ProductName, in.PlanCode)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
list := make([]*pb.ProductionPlanInfo, 0, len(plans))
|
||
|
|
for _, p := range plans {
|
||
|
|
info := &pb.ProductionPlanInfo{
|
||
|
|
PlanId: p.PlanId,
|
||
|
|
TenantId: p.TenantId,
|
||
|
|
PlanCode: p.PlanCode,
|
||
|
|
ProductId: p.ProductId,
|
||
|
|
ProductName: p.ProductName,
|
||
|
|
Color: p.Color,
|
||
|
|
FabricCode: p.FabricCode,
|
||
|
|
ColorCode: p.ColorCode,
|
||
|
|
TargetQuantity: fmt.Sprintf("%.2f", p.TargetQuantity),
|
||
|
|
CompletedQuantity: fmt.Sprintf("%.2f", p.CompletedQuantity),
|
||
|
|
YarnUsagePerMeter: fmt.Sprintf("%.4f", p.YarnUsagePerMeter),
|
||
|
|
ProductionPrice: fmt.Sprintf("%.2f", p.ProductionPrice),
|
||
|
|
SupplierId: p.SupplierId,
|
||
|
|
Status: p.Status,
|
||
|
|
Remark: p.Remark.String,
|
||
|
|
Creator: p.Creator,
|
||
|
|
Operator: p.Operator,
|
||
|
|
CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
}
|
||
|
|
if p.StartTime.Valid {
|
||
|
|
info.StartTime = p.StartTime.Time.Format("2006-01-02")
|
||
|
|
}
|
||
|
|
list = append(list, info)
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.ListProductionPlanResp{
|
||
|
|
Total: total,
|
||
|
|
List: list,
|
||
|
|
}, nil
|
||
|
|
}
|