forked from longtao.wu/droboticflow
R1-Q8/R2-Q7 (spec slice-edit-ux-rework, seam ②): - planQualityReviewDecision now builds the next rework baseline as unresolved prior opinions (same entry IDs, QC still-problem notes merged into the original text) followed by this round's new opinions; resolved opinions never enter the new baseline - rework-baseline reads (any round) and the acceptance source-opinions baseline projection narrow to unresolved-only via the frozen round's review confirmations; frozen records stay untouched (B02) - legacy fallback: missing confirmations mean unresolved and opinions keep carrying (documented + tested); missing prior baseline keeps the first-round fresh-only behavior - ADR 0008 records the decision, consequences and the rejected collapsed-display alternative
83 lines
3.2 KiB
Go
83 lines
3.2 KiB
Go
package api
|
||
|
||
import (
|
||
"droboticflow/internal/domain"
|
||
"droboticflow/internal/store"
|
||
"net/http"
|
||
)
|
||
|
||
// B04 意见来源投影:终审视图按来源聚合质检/返工复审意见,标注来源(谁、哪一轮),
|
||
// 不解析 comment 文本猜绑定(spec §6)。只读;不改冻结抽样与共享授权合同。
|
||
|
||
func (s *server) handleAcceptanceSourceOpinions(w http.ResponseWriter, r *http.Request) {
|
||
item, ok := s.loadHumanItemForRequest(w, r)
|
||
if !ok {
|
||
return
|
||
}
|
||
if item.CurrentStageID != fanyuV5PrePackageAcceptanceStageID {
|
||
renderJSON(w, http.StatusConflict, map[string]string{"error": "only aggregate acceptance items expose source opinions"})
|
||
return
|
||
}
|
||
batch, e := s.store.GetHumanBatch(r.Context(), item.BatchID)
|
||
if e != nil || batch == nil {
|
||
renderError(w, http.StatusInternalServerError, e)
|
||
return
|
||
}
|
||
sourceBatch, supported, e := v58AggregateSourceBatch(r.Context(), s, batch)
|
||
if e != nil {
|
||
renderError(w, http.StatusInternalServerError, e)
|
||
return
|
||
}
|
||
if !supported || sourceBatch == nil {
|
||
renderJSON(w, http.StatusOK, map[string]any{"opinions": []any{}})
|
||
return
|
||
}
|
||
sources, e := s.store.ListHumanItems(r.Context(), sourceBatch.OrganizationID, domain.HumanItemQuery{BatchID: sourceBatch.ID})
|
||
if e != nil {
|
||
renderError(w, http.StatusInternalServerError, e)
|
||
return
|
||
}
|
||
opinions := make([]map[string]any, 0, len(sources))
|
||
for _, source := range sources {
|
||
entry := map[string]any{
|
||
"sourceItemId": source.ID,
|
||
"itemKey": source.Subject.ItemKey,
|
||
"status": string(source.Status),
|
||
"stageId": source.CurrentStageID,
|
||
"reviewRound": source.ReviewRound,
|
||
"baselines": []map[string]any{},
|
||
"reviews": []map[string]any{},
|
||
}
|
||
// 质检正式判定(含 D7 核对结论冻结)——先加载:基线投影要用它收窄。
|
||
var reviews []domain.AnnotationReviewRecord
|
||
if source.LegacyTaskID != "" {
|
||
list, re := s.store.ListAnnotationReviews(r.Context(), source.OrganizationID, source.LegacyTaskID)
|
||
if re == nil {
|
||
reviews = list
|
||
projection := make([]map[string]any, 0, len(reviews))
|
||
for _, review := range reviews {
|
||
projection = append(projection, map[string]any{
|
||
"round": review.ReviewRound, "decision": string(review.Decision), "reviewerUserId": review.ReviewerUserID,
|
||
"comment": review.Comment, "confirmations": review.Confirmations, "createdAt": review.CreatedAt,
|
||
})
|
||
}
|
||
entry["reviews"] = projection
|
||
}
|
||
}
|
||
// 每轮退回基线(原正式意见 + 说明)。R1-Q8(ADR 0008):已判解决的
|
||
// 历史意见在任何基线查询接口都不再返回;解决轨迹走上方 reviews 投影。
|
||
for round := 1; round <= source.ReviewRound; round++ {
|
||
baseline, be := s.store.GetReworkBaseline(r.Context(), store.ReworkBaselineID(source.ID, round))
|
||
if be != nil || baseline == nil {
|
||
continue
|
||
}
|
||
entry["baselines"] = append(entry["baselines"].([]map[string]any), map[string]any{
|
||
"round": baseline.Round, "problems": visibleReworkBaselineProblems(baseline, reviews), "comment": baseline.Comment,
|
||
"reviewerOperationId": baseline.ReviewOperationID, "createdAt": baseline.CreatedAt,
|
||
})
|
||
}
|
||
opinions = append(opinions, entry)
|
||
}
|
||
renderJSON(w, http.StatusOK, map[string]any{"opinions": opinions})
|
||
}
|