forked from longtao.wu/droboticflow
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// Acceptance history is restricted to tasks embedded in this acceptance item.
|
|
// Return no reviewer identity or supplier metadata (three-role acceptance is anonymous).
|
|
func (s *server) acceptanceReviewSummaries(ctx context.Context, item domain.HumanItemRecord) ([]map[string]any, error) {
|
|
result := []map[string]any{}
|
|
if item.CurrentStageID != fanyuV5PrePackageAcceptanceStageID {
|
|
return result, nil
|
|
}
|
|
entries, _ := normalizeStructuredValue(item.Subject.Payload["items"]).([]any)
|
|
if len(entries) > 1000 {
|
|
return nil, fmt.Errorf("验收条目数量超出限制")
|
|
}
|
|
cutoff, _ := time.Parse(time.RFC3339Nano, item.UpdatedAt)
|
|
seen := map[string]bool{}
|
|
for _, raw := range entries {
|
|
entry, _ := raw.(map[string]any)
|
|
id := stringValue(entry["taskId"])
|
|
if id == "" || seen[id] {
|
|
continue
|
|
}
|
|
seen[id] = true
|
|
task, err := s.store.GetAnnotationTask(ctx, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if task == nil {
|
|
continue
|
|
}
|
|
if task.OrganizationID != item.OrganizationID || task.ProjectID != item.ProjectID || task.WorkflowID != item.WorkflowID || task.RunID != stringValue(entry["runId"]) {
|
|
return nil, fmt.Errorf("验收任务关联不一致")
|
|
}
|
|
reviews, err := s.store.ListAnnotationReviews(ctx, item.OrganizationID, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, review := range reviews {
|
|
if review.Stage != domain.AnnotationReviewStageQuality && review.Stage != domain.AnnotationReviewStageSplitQuality {
|
|
continue
|
|
}
|
|
created, _ := time.Parse(time.RFC3339Nano, review.CreatedAt)
|
|
if !cutoff.IsZero() && !created.IsZero() && created.After(cutoff) {
|
|
continue
|
|
}
|
|
result = append(result, map[string]any{"taskId": id, "revision": review.Revision, "decision": review.Decision, "comment": review.Comment, "createdAt": review.CreatedAt})
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|