按已确认需求提供独立安全模型配置、真实探测、正式字典字段评估与原问题译中,持久批次支持只补空白、暂停恢复、有限重试、幂等和逐字段依据。覆盖固定规则、本地语言、组织关联与主表有效看板共用治理侧读模型,保留源生产和冻结历史。 验证:完整 make verify 退出0,702项Go与329项前端通过;默认118项外部/隔离集成明确跳过,另跑完整镜像及组织隔离PG竞态。12并发、输入漂移、过期租约、暂停/恢复及有限重试通过。用户授权的百炼 deepseek-v4.1-flash 完成真实后台与浏览器评估/翻译;552行、16列、11块看板及完整PNG、独立配置页测试/保存、重开恢复和零JS异常通过。仅非业务样本外发,自动处理关闭,原payload不变。 上线前治理库已做导出快照原生备份并真实恢复,60表行数与17个QA表内容哈希一致;不修改DobotAI生产或隧道。本提交时尚未部署,线上验收须独立完成。
This commit is contained in:
@@ -17,6 +17,8 @@ type dashboardRecord struct {
|
||||
id, hash string
|
||||
at time.Time
|
||||
identity dobotaiops.ActorIdentity
|
||||
fields map[string]string
|
||||
coverage dobotaiops.CoverageCheck
|
||||
}
|
||||
|
||||
func dashboardRate(n, d int) qaopsquality.Rate {
|
||||
@@ -50,6 +52,9 @@ func dashboardCategory(value string) string {
|
||||
// ReadDashboard never fetches answer payloads or opens a source connection. All
|
||||
// scopes, quality inputs and organizational attribution use ONE local snapshot.
|
||||
func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Dashboard, error) {
|
||||
return s.readDashboard(ctx, q, false)
|
||||
}
|
||||
func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, master bool) (Dashboard, error) {
|
||||
out := Dashboard{Start: q.Window.Start, End: q.Window.End, Keyword: q.Keyword, IssueTypes: []DashboardCount{}, Products: []DashboardCount{}, Daily: []DashboardDaily{}, Regions: []DashboardRegion{}, FrozenWeeks: []DashboardFrozen{}}
|
||||
if !s.valid() {
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
@@ -67,7 +72,15 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
defer func() { _ = tx.Rollback(context.Background()) }()
|
||||
state, e := s.readState(ctx, txQuery{tx})
|
||||
var state Status
|
||||
if master {
|
||||
state.Ready = true
|
||||
var observed time.Time
|
||||
e = tx.QueryRow(ctx, `SELECT COALESCE((SELECT revision FROM qa_ops_master_state WHERE tenant_key=$1),0),COALESCE((SELECT updated_at FROM qa_ops_master_state WHERE tenant_key=$1),transaction_timestamp())`, s.tenant).Scan(&state.Revision, &observed)
|
||||
state.SourceObservedAt = &observed
|
||||
} else {
|
||||
state, e = s.readState(ctx, txQuery{tx})
|
||||
}
|
||||
if e != nil {
|
||||
return out, e
|
||||
}
|
||||
@@ -87,7 +100,12 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
out.Organization = dobotaiops.OrganizationVersion{State: meta.State, DirectoryID: meta.DirectoryID, DirectorySource: meta.DirectorySource, SyncedAt: meta.DirectorySyncedAt, RevisionID: meta.RevisionID, Basis: "current_directory", RegionNames: meta.RegionLabels()}
|
||||
out.MonthStart, out.WeekStart = dashboardPeriods(q.Window.End)
|
||||
var first *time.Time
|
||||
if e = tx.QueryRow(ctx, `SELECT count(*),LEAST((SELECT min(asked_at) FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at<$2),(SELECT first_data_at FROM qa_ops_weekly_quality_tracking WHERE tenant_key=$1),(SELECT min(week_start) FROM qa_ops_weekly_quality_snapshots WHERE tenant_key=$1 AND week_start<$2)) FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at<$2 AND ($3='' OR position(lower($3) IN lower(question))>0)`, s.tenant, q.Window.End, q.Keyword).Scan(&out.TotalIssues, &first); e != nil {
|
||||
totalSQL := `SELECT count(*),LEAST((SELECT min(asked_at) FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at<$2),(SELECT first_data_at FROM qa_ops_weekly_quality_tracking WHERE tenant_key=$1),(SELECT min(week_start) FROM qa_ops_weekly_quality_snapshots WHERE tenant_key=$1 AND week_start<$2)) FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at<$2 AND ($3='' OR position(lower($3) IN lower(question))>0)`
|
||||
if master {
|
||||
totalSQL = strings.ReplaceAll(totalSQL, "qa_ops_mirror_records", "qa_ops_master_read_model")
|
||||
totalSQL = strings.ReplaceAll(totalSQL, "lower(question)", "lower(question||E'\\n'||chinese_question||E'\\n'||COALESCE(ai_fields->>'question_chinese',''))")
|
||||
}
|
||||
if e = tx.QueryRow(ctx, totalSQL, s.tenant, q.Window.End, q.Keyword).Scan(&out.TotalIssues, &first); e != nil {
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
lower := q.Window.Start
|
||||
@@ -97,7 +115,13 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
if out.WeekStart.Before(lower) {
|
||||
lower = out.WeekStart
|
||||
}
|
||||
rows, e := tx.Query(ctx, `SELECT id,asked_at,identity,quality_hash FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at>=$2 AND asked_at<$3 AND ($4='' OR position(lower($4) IN lower(question))>0) ORDER BY id LIMIT 100001`, s.tenant, lower, q.Window.End, q.Keyword)
|
||||
rowsSQL := `SELECT id,asked_at,identity,quality_hash FROM qa_ops_mirror_records WHERE tenant_key=$1 AND asked_at>=$2 AND asked_at<$3 AND ($4='' OR position(lower($4) IN lower(question))>0) ORDER BY id LIMIT 100001`
|
||||
if master {
|
||||
rowsSQL = strings.ReplaceAll(rowsSQL, "qa_ops_mirror_records", "qa_ops_master_read_model")
|
||||
rowsSQL = strings.ReplaceAll(rowsSQL, "SELECT id,asked_at,identity,quality_hash FROM", "SELECT id,asked_at,identity,quality_hash,effective_fields,coverage_result FROM")
|
||||
rowsSQL = strings.ReplaceAll(rowsSQL, "lower(question)", "lower(question||E'\\n'||chinese_question||E'\\n'||COALESCE(ai_fields->>'question_chinese',''))")
|
||||
}
|
||||
rows, e := tx.Query(ctx, rowsSQL, s.tenant, lower, q.Window.End, q.Keyword)
|
||||
if e != nil {
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
@@ -106,7 +130,20 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
for rows.Next() {
|
||||
var r dashboardRecord
|
||||
var identity []byte
|
||||
if rows.Scan(&r.id, &r.at, &identity, &r.hash) != nil || json.Unmarshal(identity, &r.identity) != nil {
|
||||
var scanErr error
|
||||
if master {
|
||||
var fields, coverage []byte
|
||||
scanErr = rows.Scan(&r.id, &r.at, &identity, &r.hash, &fields, &coverage)
|
||||
if scanErr == nil {
|
||||
scanErr = json.Unmarshal(fields, &r.fields)
|
||||
}
|
||||
if scanErr == nil {
|
||||
scanErr = json.Unmarshal(coverage, &r.coverage)
|
||||
}
|
||||
} else {
|
||||
scanErr = rows.Scan(&r.id, &r.at, &identity, &r.hash)
|
||||
}
|
||||
if scanErr != nil || json.Unmarshal(identity, &r.identity) != nil {
|
||||
rows.Close()
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
@@ -125,7 +162,11 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
return out, dobotaiops.ErrUnavailable
|
||||
}
|
||||
views := map[string]qaopsquality.View{}
|
||||
quality := qaopsquality.NewStore(s.pool, s.tenant)
|
||||
qualityTenant := s.tenant
|
||||
if master {
|
||||
qualityTenant += "::master"
|
||||
}
|
||||
quality := qaopsquality.NewStore(s.pool, qualityTenant)
|
||||
for begin := 0; begin < len(keys); begin += 5000 {
|
||||
end := begin + 5000
|
||||
if end > len(keys) {
|
||||
@@ -139,6 +180,13 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
views[id] = v
|
||||
}
|
||||
}
|
||||
if master {
|
||||
for _, r := range records {
|
||||
if v, ok := views[r.id]; ok {
|
||||
views[r.id] = qaopsquality.ProjectMaster(v, r.fields, r.coverage)
|
||||
}
|
||||
}
|
||||
}
|
||||
out.Quality = qaopsquality.Summarize(views)
|
||||
products, types, daily := map[string]int{}, map[string]int{}, map[string]int{}
|
||||
for day := out.WeekStart; day.Before(q.Window.End); day = day.AddDate(0, 0, 1) {
|
||||
@@ -171,7 +219,7 @@ func (s *Store) ReadDashboard(ctx context.Context, q dobotaiops.RecordQuery) (Da
|
||||
types[dashboardCategory(v.Effective.ProblemType)]++
|
||||
}
|
||||
if !r.at.Before(out.MonthStart) {
|
||||
person := attribution.Resolve(r.identity.StaffID, r.identity.UnionID)
|
||||
person := attribution.Resolve(r.identity.StaffID, r.identity.UnionID, r.fields["asker"], r.fields["trigger_person"])
|
||||
if index, ok := regionIndex[person.Region]; ok && person.PersonID != "" {
|
||||
out.Regions[index].Questions++
|
||||
users[person.Region][person.PersonID] = true
|
||||
|
||||
Reference in New Issue
Block a user