48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"muyu-apiserver/pkg/tenantctx"
|
|
"muyu-apiserver/rpc/production/internal/svc"
|
|
"muyu-apiserver/rpc/production/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ConfirmPlanLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewConfirmPlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConfirmPlanLogic {
|
|
return &ConfirmPlanLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *ConfirmPlanLogic) ConfirmPlan(in *pb.ConfirmPlanReq) (*pb.Empty, error) {
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
|
|
plan, err := l.svcCtx.PlanModel.FindOneByPlanId(l.ctx, in.PlanId)
|
|
if err != nil {
|
|
return nil, ErrPlanNotFound
|
|
}
|
|
if plan.TenantId != tenantId {
|
|
return nil, ErrPermissionDenied
|
|
}
|
|
if plan.Status != 0 {
|
|
return nil, ErrPlanNotDraft
|
|
}
|
|
|
|
if err := l.svcCtx.PlanModel.UpdateStatus(l.ctx, in.PlanId, 1); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Mark confirm step as completed
|
|
if err := l.svcCtx.ProcessStepModel.UpdateStepStatus(l.ctx, in.PlanId, "confirm", 2, in.Operator); err != nil {
|
|
l.Errorf("update confirm step failed: %v", err)
|
|
}
|
|
|
|
return &pb.Empty{}, nil
|
|
}
|