67 lines
1.5 KiB
Go
67 lines
1.5 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 CompleteStepLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCompleteStepLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CompleteStepLogic {
|
||
|
|
return &CompleteStepLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CompleteStepLogic) CompleteStep(in *pb.CompleteStepReq) (*pb.Empty, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
|
||
|
|
// Validate plan exists and belongs to tenant
|
||
|
|
plan, err := l.svcCtx.PlanModel.FindOneByPlanId(l.ctx, in.PlanId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, ErrPlanNotFound
|
||
|
|
}
|
||
|
|
if plan.TenantId != tenantId {
|
||
|
|
return nil, ErrPermissionDenied
|
||
|
|
}
|
||
|
|
|
||
|
|
// Find steps for this plan and check the target step
|
||
|
|
steps, err := l.svcCtx.ProcessStepModel.FindByPlanId(l.ctx, in.PlanId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, ErrStepNotFound
|
||
|
|
}
|
||
|
|
|
||
|
|
found := false
|
||
|
|
for _, s := range steps {
|
||
|
|
if s.StepType == in.StepType {
|
||
|
|
found = true
|
||
|
|
if s.Status == 2 {
|
||
|
|
return nil, ErrStepAlreadyComplete
|
||
|
|
}
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if !found {
|
||
|
|
return nil, ErrStepNotFound
|
||
|
|
}
|
||
|
|
|
||
|
|
operatorId := in.OperatorId
|
||
|
|
if operatorId == "" {
|
||
|
|
operatorId = tenantId
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update step status to 2 (completed)
|
||
|
|
if err := l.svcCtx.ProcessStepModel.UpdateStepStatus(l.ctx, in.PlanId, in.StepType, 2, operatorId); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.Empty{}, nil
|
||
|
|
}
|