75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package projectinstance
|
|
|
|
import "chat-agent-system/internal/workflowdef"
|
|
|
|
func evaluateStageReadiness(
|
|
stagePlan StagePlan,
|
|
stageDef *workflowdef.StageDef,
|
|
docStates map[string]string,
|
|
) (bool, []GateIssue, []DocTaskReadiness) {
|
|
issues := make([]GateIssue, 0)
|
|
readiness := make([]DocTaskReadiness, 0)
|
|
if !stagePlan.Enabled {
|
|
return false, []GateIssue{{Code: "STAGE_DISABLED", Message: "阶段未启用"}}, readiness
|
|
}
|
|
|
|
taskDefMap := map[string]workflowdef.DocTaskDef{}
|
|
if stageDef != nil {
|
|
for _, dt := range stageDef.DocTasks {
|
|
taskDefMap[dt.Key] = dt
|
|
}
|
|
}
|
|
|
|
for _, dt := range stagePlan.DocTasks {
|
|
if !dt.Enabled {
|
|
continue
|
|
}
|
|
td, hasDef := taskDefMap[dt.TaskKey]
|
|
approvalManaged := classifyDocDuty(dt.Duties) != DutyModeNone
|
|
required := approvalManaged && (!hasDef || td.BlocksWhenEnabled())
|
|
state := docStates[dt.TaskKey]
|
|
if state == "" {
|
|
state = "missing"
|
|
}
|
|
approved := state == "approved"
|
|
item := DocTaskReadiness{
|
|
TaskKey: dt.TaskKey,
|
|
Required: required,
|
|
Enabled: true,
|
|
ApprovalManaged: approvalManaged,
|
|
DocState: state,
|
|
Approved: approved,
|
|
}
|
|
readiness = append(readiness, item)
|
|
if required && !approved {
|
|
msg := "必需文档尚未批准"
|
|
if state == "missing" {
|
|
msg = "必需文档尚未创建"
|
|
}
|
|
issues = append(issues, GateIssue{
|
|
Code: "DOC_NOT_APPROVED", TaskKey: dt.TaskKey, Message: msg,
|
|
})
|
|
}
|
|
}
|
|
|
|
return len(issues) == 0, issues, readiness
|
|
}
|
|
|
|
func findStagePlan(plan WorkflowPlan, stageKey string) *StagePlan {
|
|
for i := range plan.Stages {
|
|
if plan.Stages[i].StageKey == stageKey {
|
|
return &plan.Stages[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func findStageDef(def workflowdef.VersionDefinition, stageKey string) *workflowdef.StageDef {
|
|
for i := range def.Stages {
|
|
if def.Stages[i].Key == stageKey {
|
|
return &def.Stages[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|