refactor: 后端仓库层更名为数据访问层(internal/repository → internal/dal)

「仓库层」是 repository 的直译,中文里与「代码仓库 / git 仓库」同词,
而这一层做的事就是数据访问。名字改成它实际在做的事。

改名口径(纯机械替换,无逻辑改动):
- 包:internal/repository → internal/dal(package repository → package dal)
- 类型:XxxRepo → XxxDAO(TaskRecordDAO / SpecialistDAO / PositionDAO …)
- 变量:xxxRepo → xxxDAO
- import 路径、包限定符、日志前缀 [repository] → [dal] 同步
- 注释里的「仓库层」→「数据访问层」;core.go 包注释补上 DAL/DAO 全称

命名规范补登(AR09 是命名问题的最高依据,改了名就得回去登记):
- AR09 §3.1 术语表新增「数据访问层 dal / DAO」一行
- AR09 §5.6 缩写表新增 DAO / dal —— 原文是「只有下表内的缩写允许使用」,
  不登记就是自己破自己的规矩
- PROJECT_STATE.md 新增 D27 记录本次更名决策

验证:全部在 db 副本上做,生产库 data/eai_agentplatform.db 未触碰。
- 等价性对照:拿 HEAD 源码 + 仅改名 造出第二棵树,两棵树各自起
  httptest 服务跑同一份探针(60 个 GET + 13 个写/回读,覆盖专员/技能/应用/
  任务/交付物/项目/岗位/考试/知识/积分/管理端只读等),逐端点比对响应体:
  73 项里 52 项字节完全一致、21 项仅运行期时间戳不同、内容差异 0。
- 探针非空:往改名后的树注入「SpecialistDAO.List 限 3 条」变异,
  /api/specialists 立刻被抓出 —— 证明上面那个 0 不是没测到。
- 暂存区自洽:把索引整个导出成源码树,go build / go vet / go test ./... 全绿。
- gofmt:因 import 排序变化而错位的 19 个文件已修;另 2 个文件(skill_definition.go、
  seed.go)的格式问题是工作区里别人的在制品带来的,未替其改动。

未纳入本次提交:工作区里正在进行中的「文生语音技能 + 技能展示色/交互卡」
(tts_handlers.go、text_to_speech/manifest.go、skillCatalog.js 等),
以及 router.go / skill_definition.go / seed.go 三个文件里属于该在制品的改动 ——
这三个文件只把「改名那一版」放进索引,工作区原样保留。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
eaiadmin
2026-09-19 09:19:21 +08:00
co-authored by Claude Code
parent 1875e7dd4c
commit e8aedd50d2
70 changed files with 738 additions and 733 deletions
@@ -11,17 +11,17 @@ import (
"github.com/gin-gonic/gin"
"eai_agentplatform/backend/internal/dal"
"eai_agentplatform/backend/internal/middleware"
"eai_agentplatform/backend/internal/model"
"eai_agentplatform/backend/internal/repository"
"eai_agentplatform/backend/internal/web"
)
// sourceRepo 知识源仓库(便于测试时覆写),包内共享。
var sourceRepo repository.KnowledgeSourceRepo
// sourceDAO 知识源仓库(便于测试时覆写),包内共享。
var sourceDAO dal.KnowledgeSourceDAO
func init() {
sourceRepo = repository.KnowledgeSourceRepo{}
sourceDAO = dal.KnowledgeSourceDAO{}
}
// ============ 扫描 ============
@@ -51,7 +51,7 @@ func KnowledgeScan(c *gin.Context) {
continue // 非知识源文档,跳过
}
if existing, found := sourceRepo.GetByFilePath(e.Name()); found {
if existing, found := sourceDAO.GetByFilePath(e.Name()); found {
results = append(results, gin.H{"file_path": e.Name(), "status": "skipped", "title": existing.Title})
continue
}
@@ -64,7 +64,7 @@ func KnowledgeScan(c *gin.Context) {
AuditStatus: "pending",
KnowledgeSpaceKey: ensureKnowledgeSpaceKeyOrDefault(orDefault(fm["knowledge_space_key"], inferKnowledgeSpaceKey(parseTitle(string(data)), fm["domain"], fm["category"]+" "+e.Name()))),
}
if !sourceRepo.Insert(&src) {
if !sourceDAO.Insert(&src) {
results = append(results, gin.H{"file_path": e.Name(), "status": "error", "title": src.Title})
continue
}
@@ -83,7 +83,7 @@ func KnowledgeAuditList(c *gin.Context) {
if size < 1 || size > 100 {
size = 20
}
total, items := sourceRepo.ListForAudit(
total, items := sourceDAO.ListForAudit(
c.Query("status"), sanitizeSpaceKey(c.Query("knowledge_space_key")), page, size)
web.OK(c, gin.H{"total": total, "items": items})
}
@@ -95,7 +95,7 @@ func KnowledgeAudit(c *gin.Context) {
if !ok {
return
}
src, found := sourceRepo.GetByID(id)
src, found := sourceDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("知识源不存在"))
return
@@ -126,7 +126,7 @@ func KnowledgeAudit(c *gin.Context) {
src.AuditAt = &now
src.RejectReason = ""
src.Ingested = true
if !sourceRepo.Update(&src) {
if !sourceDAO.Update(&src) {
web.Fail(c, web.NewBadRequest("审批失败"))
return
}
@@ -144,7 +144,7 @@ func KnowledgeAudit(c *gin.Context) {
src.RejectReason = req.RejectReason
src.AuditBy = &auditBy
src.AuditAt = &now
if !sourceRepo.Update(&src) {
if !sourceDAO.Update(&src) {
web.Fail(c, web.NewBadRequest("审批失败"))
return
}
@@ -160,7 +160,7 @@ func KnowledgeStatus(c *gin.Context) {
if !ok {
return
}
src, found := sourceRepo.GetByID(id)
src, found := sourceDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("知识源不存在"))
return
@@ -335,12 +335,12 @@ func ingestSource(src *model.KnowledgeSource) ([3]int, error) {
ReportRules: kv["report_rules"],
Status: "active",
}
if existing, found := productRepo.GetByCode(p.Code); found {
if existing, found := productDAO.GetByCode(p.Code); found {
p.ID = existing.ID
p.CreatedAt = existing.CreatedAt // Save 整字段覆盖,不回填会把创建时间写成零值
productRepo.Update(&p)
productDAO.Update(&p)
} else {
productRepo.Insert(&p)
productDAO.Insert(&p)
}
counts[0]++
}
@@ -351,7 +351,7 @@ func ingestSource(src *model.KnowledgeSource) ([3]int, error) {
if text == "" {
continue
}
chunkRepo.Insert(&model.KnowledgeChunk{
chunkDAO.Insert(&model.KnowledgeChunk{
KnowledgeSourceID: &src.ID,
SourceType: "md",
SourceID: strconv.FormatUint(uint64(src.ID), 10),
@@ -383,7 +383,7 @@ func ingestSource(src *model.KnowledgeSource) ([3]int, error) {
Explanation: kv["explanation"],
Status: "active",
}
questionRepo.Insert(&q)
questionDAO.Insert(&q)
counts[2]++
}