forked from longtao.wu/droboticflow
- GET /api/human-items/{id}/source-opinions: per-source projection of
rework baselines (round, frozen problems incl. timestamps, comment) and
formal quality reviews (round, decision, reviewer, frozen D7
confirmations); aggregate items only
- multi-source coordination detail: requireAcceptanceSourceReady and the
decision gate now name the pending sources (itemKey + stage + status)
instead of a generic message
- AcceptanceSourceOpinions panel in the final-acceptance workspace:
collapsible per-source history labelled who/which-round
- rework_review badge extends to prepackage_acceptance rounds
- tests: pending-gate names source then approves after ready; projection
carries baselines/reviews/confirmations and rejects non-aggregate items;
api failures identical to baseline (65), frontend zero new, tsc clean
104 lines
3.8 KiB
Go
104 lines
3.8 KiB
Go
package api
|
||
|
||
import (
|
||
"context"
|
||
"droboticflow/internal/domain"
|
||
"fmt"
|
||
"strings"
|
||
)
|
||
|
||
func (s *server) requireAcceptanceSourceReady(ctx context.Context, source *domain.HumanBatchRecord) error {
|
||
if source == nil {
|
||
return fmt.Errorf("当前数据尚未通过质检")
|
||
}
|
||
items, err := s.store.ListHumanItems(ctx, source.OrganizationID, domain.HumanItemQuery{BatchID: source.ID})
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if len(items) == 0 {
|
||
return fmt.Errorf("当前数据尚未通过质检")
|
||
}
|
||
// B04 多来源完成协调:明确列出未就绪来源,终审员可辨缺哪些再判定。
|
||
pending := make([]string, 0, len(items))
|
||
for _, item := range items {
|
||
if item.Status != domain.HumanItemAccepted {
|
||
pending = append(pending, fmt.Sprintf("%s(%s/%s)", item.Subject.ItemKey, item.CurrentStageID, string(item.Status)))
|
||
}
|
||
}
|
||
if len(pending) > 0 {
|
||
return fmt.Errorf("聚合源任务尚未全部重新质检通过,暂不能终审判定;待完成:%s", strings.Join(pending, "、"))
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// A rejected acceptance record is an audit record, not a new acceptance
|
||
// assignment. Project its current source data for read-only viewing only.
|
||
// Never persist this projection or alter its status/version/decision.
|
||
func (s *server) projectRejectedAcceptanceData(ctx context.Context, item *domain.HumanItemRecord) error {
|
||
if item == nil || item.CurrentStageID != fanyuV5PrePackageAcceptanceStageID || item.Status != domain.HumanItemRejected {
|
||
return nil
|
||
}
|
||
batch, err := s.store.GetHumanBatch(ctx, item.BatchID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if batch == nil || batch.SourceBatchID == "" {
|
||
return nil
|
||
}
|
||
source, err := s.store.GetHumanBatch(ctx, batch.SourceBatchID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if source == nil || source.OrganizationID != item.OrganizationID || source.ProjectID != item.ProjectID || source.WorkflowID != item.WorkflowID || source.RunID != item.RunID {
|
||
return fmt.Errorf("验收关联数据范围不一致")
|
||
}
|
||
sources, err := s.store.ListHumanItems(ctx, item.OrganizationID, domain.HumanItemQuery{BatchID: source.ID})
|
||
if err != nil {
|
||
return err
|
||
}
|
||
entries := make([]map[string]any, 0, len(sources))
|
||
status := "等待重新验收"
|
||
for _, current := range sources {
|
||
if current.OrganizationID != item.OrganizationID || current.ProjectID != item.ProjectID || current.WorkflowID != item.WorkflowID || current.RunID != item.RunID {
|
||
return fmt.Errorf("当前数据不属于此验收任务")
|
||
}
|
||
if current.Status != domain.HumanItemAccepted && status != "等待标注返工" {
|
||
status = "等待重新质检"
|
||
}
|
||
if current.CurrentStageID == domain.FanyuV58StageAnnotationCombined {
|
||
status = "等待标注返工"
|
||
}
|
||
task, err := s.store.GetAnnotationTask(ctx, current.LegacyTaskID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if task == nil {
|
||
continue
|
||
}
|
||
if task.OrganizationID != item.OrganizationID || task.ProjectID != item.ProjectID || task.WorkflowID != item.WorkflowID || task.RunID != item.RunID {
|
||
return fmt.Errorf("当前标注任务范围不一致")
|
||
}
|
||
materialization := mapValue(current.Subject.Payload["materialization"])
|
||
slices, err := s.store.ListSliceRevisions(ctx, item.OrganizationID, task.ID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
var selected []domain.SliceSegment
|
||
for _, r := range slices {
|
||
if r.Revision == intValue(materialization["revision"]) {
|
||
selected = r.Segments
|
||
}
|
||
}
|
||
entries = append(entries, map[string]any{"taskId": task.ID, "runId": task.RunID, "sourceHumanItemId": current.ID, "finalSlices": selected, "materialization": materialization, "poseSummary": task.PoseSummary})
|
||
}
|
||
payload := map[string]any{}
|
||
for k, v := range item.Subject.Payload {
|
||
payload[k] = v
|
||
}
|
||
payload["items"] = entries
|
||
payload["currentDataPreview"] = true
|
||
payload["currentDataStatus"] = status
|
||
item.Subject.Payload = payload
|
||
return nil
|
||
}
|