Files
Agent-System/internal/app/instance_duty_adapter.go
T
weichenandCursor 750b904439 feat(app): wire projectinstance duties into bizdev
Composition-root adapter maps live instance DocTasks to bizdev's narrow
InstanceDutySource without crossing module boundaries.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 09:59:38 +00:00

47 lines
1.4 KiB
Go

package app
import (
"context"
"strings"
"chat-agent-system/internal/projectinstance"
)
// projectInstanceDutyAdapter 将活跃工作流实例的逐文档职责投影为 bizdev 窄接口,
// 避免 bizdev 导入 projectinstance。
type projectInstanceDutyAdapter struct {
inst *projectinstance.Service
}
func (a *projectInstanceDutyAdapter) ResolveGovernedDuty(ctx context.Context, projectID int64, taskKey string) (author, reviewer, approver int64, dutyPolicy string, governed bool, err error) {
if a == nil || a.inst == nil || projectID <= 0 {
return 0, 0, 0, "", false, nil
}
taskKey = strings.TrimSpace(taskKey)
if taskKey == "" {
return 0, 0, 0, "", false, nil
}
detail, _, derr := a.inst.GetLiveInstanceDetail(ctx, projectID)
if derr != nil || detail == nil {
// 无活跃实例(规划中/legacy)→ 不受治理,非错误
return 0, 0, 0, "", false, nil
}
for _, st := range detail.Instance.ConfigSnapshot.Stages {
for _, dt := range st.DocTasks {
if dt.TaskKey != taskKey || !dt.Enabled {
continue
}
mode, effective, isAuthorOnly := projectinstance.ResolveDocTaskDuty(dt)
if mode != projectinstance.DutyModeFull {
return 0, 0, 0, "", false, nil
}
policy := projectinstance.DutyPolicySeparated
if isAuthorOnly {
policy = projectinstance.DutyPolicyAuthorOnly
}
return effective.AuthorUserID, effective.ReviewerUserID, effective.ApproverUserID, policy, true, nil
}
}
return 0, 0, 0, "", false, nil
}