区域配置入口改为区域统计,五列表按当前通讯录整支人员去重;调岗依当前归属、零分母未知、最近真实提问时间和父行收起不重算。仅读治理正式总表,后台单并发/请求合并/60秒缓存,目录与配置版本隔离,客户端失败不伪零。 保留区域自定义目录与预览/双版本锁保存,父部门勾选联选全后代,取消子支清除祖先整支选择,避免隐式覆盖未选子级;允许删除无引用区域,已有引用不静默孤立。统计页与设置共享选择,统计支持累计与北京时间自然月;不新增迁移,不改DobotAI生产、代理、原问答、历史趋势或已有AI任务。 验证已执行:完整make verify退出0,705 Go/340前端通过、120项声明的可选集成跳过且必需0跳过;镜像全量隔离PG race退出0;新增去重/调岗/空分母、后台缓存/并发、HTTP授权/严格请求、真PG目录与配置失效、树选择/收起、五列与删除保护均先红后绿。旧导航测试按新名称更新后全量通过。上线前治理库备份与真实恢复72表/29张QA内容哈希一致,匹配独立主密钥受限备份。 当前尚待精确SHA CI、同镜像真实数据浏览器与正式读回,不把源码验证称为已上线。公司真实区域映射不在本轮擅改;只在隔离库验证保存。
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package qaopsmirror
|
||||
|
||||
import (
|
||||
"context"
|
||||
"knowledge-governance/internal/dobotaiops"
|
||||
"knowledge-governance/internal/qaopsorg"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DepartmentStatisticsQuery struct {
|
||||
Period string `json:"period"`
|
||||
Month string `json:"month,omitempty"`
|
||||
}
|
||||
type DepartmentStatisticsSnapshot struct {
|
||||
Regions []qaopsorg.RegionDefinition `json:"regions"`
|
||||
qaopsorg.DepartmentStatistics
|
||||
Organization dobotaiops.OrganizationVersion `json:"organization"`
|
||||
Period string `json:"period"`
|
||||
Month string `json:"month"`
|
||||
Start *time.Time `json:"start"`
|
||||
End time.Time `json:"end"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
}
|
||||
type DepartmentStatisticsResult struct {
|
||||
CacheKey string `json:"cache_key"`
|
||||
State string `json:"state"`
|
||||
CacheHit bool `json:"cache_hit"`
|
||||
RetryAfter int `json:"retry_after"`
|
||||
Snapshot *DepartmentStatisticsSnapshot `json:"snapshot"`
|
||||
}
|
||||
type departmentStatisticsEntry struct {
|
||||
snapshot *DepartmentStatisticsSnapshot
|
||||
err error
|
||||
done bool
|
||||
expires time.Time
|
||||
}
|
||||
type departmentStatisticsCache struct {
|
||||
mu sync.Mutex
|
||||
entries map[string]*departmentStatisticsEntry
|
||||
slots chan struct{}
|
||||
}
|
||||
|
||||
func (c *departmentStatisticsCache) get(key string, now time.Time, load func(context.Context) (DepartmentStatisticsSnapshot, error)) (DepartmentStatisticsResult, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.entries == nil {
|
||||
c.entries = map[string]*departmentStatisticsEntry{}
|
||||
c.slots = make(chan struct{}, 1)
|
||||
}
|
||||
if entry := c.entries[key]; entry != nil && (!entry.done || now.Before(entry.expires)) {
|
||||
if entry.err != nil {
|
||||
return DepartmentStatisticsResult{}, dobotaiops.ErrUnavailable
|
||||
}
|
||||
if entry.done {
|
||||
return DepartmentStatisticsResult{State: "ready", CacheKey: key, CacheHit: true, Snapshot: entry.snapshot}, nil
|
||||
}
|
||||
return DepartmentStatisticsResult{State: "pending", CacheKey: key, RetryAfter: 1}, nil
|
||||
}
|
||||
for k, v := range c.entries {
|
||||
if v.done && !now.Before(v.expires) {
|
||||
delete(c.entries, k)
|
||||
}
|
||||
}
|
||||
if len(c.entries) >= 32 {
|
||||
return DepartmentStatisticsResult{}, dobotaiops.ErrUnavailable
|
||||
}
|
||||
entry := &departmentStatisticsEntry{}
|
||||
c.entries[key] = entry
|
||||
go func() {
|
||||
started := time.Now()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
var data DepartmentStatisticsSnapshot
|
||||
var err error
|
||||
select {
|
||||
case c.slots <- struct{}{}:
|
||||
data, err = load(ctx)
|
||||
<-c.slots
|
||||
case <-ctx.Done():
|
||||
err = ctx.Err()
|
||||
}
|
||||
finished := now.Add(time.Since(started))
|
||||
data.GeneratedAt = finished
|
||||
data.ExpiresAt = finished.Add(time.Minute)
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
entry.done = true
|
||||
entry.err = err
|
||||
entry.expires = data.ExpiresAt
|
||||
if err != nil {
|
||||
entry.expires = finished.Add(5 * time.Second)
|
||||
} else {
|
||||
entry.snapshot = &data
|
||||
}
|
||||
}()
|
||||
return DepartmentStatisticsResult{State: "pending", CacheKey: key, RetryAfter: 1}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user