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
@@ -3,27 +3,27 @@ package api
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"
)
var (
positionRepo repository.PositionRepo
courseRepo repository.CourseRepo // productRepo 定义在 products.go
positionDAO dal.PositionDAO
courseDAO dal.CourseDAO // productDAO 定义在 products.go
)
func init() {
positionRepo = repository.PositionRepo{}
courseRepo = repository.CourseRepo{}
positionDAO = dal.PositionDAO{}
courseDAO = dal.CourseDAO{}
}
// ============ 岗位 CRUD(管理员) ============
// ListPositions GET /api/positions?status= —— 岗位列表
func ListPositions(c *gin.Context) {
items := positionRepo.List(c.Query("status"))
items := positionDAO.List(c.Query("status"))
web.OK(c, items)
}
@@ -41,11 +41,11 @@ func CreatePosition(c *gin.Context) {
if p.Status == "" {
p.Status = "active"
}
if positionRepo.CountByName(p.Code, nil) > 0 {
if positionDAO.CountByName(p.Code, nil) > 0 {
web.Fail(c, web.NewConflictError("岗位编号已存在"))
return
}
if !positionRepo.Insert(&p) {
if !positionDAO.Insert(&p) {
web.Fail(c, web.NewBadRequest("创建岗位失败"))
return
}
@@ -58,7 +58,7 @@ func UpdatePosition(c *gin.Context) {
if !ok {
return
}
p, found := positionRepo.GetByID(id)
p, found := positionDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("岗位不存在"))
return
@@ -76,7 +76,7 @@ func UpdatePosition(c *gin.Context) {
req.Status = "active"
}
if req.Code != "" && req.Code != p.Code {
if positionRepo.CountByName(req.Code, &id) > 0 {
if positionDAO.CountByName(req.Code, &id) > 0 {
web.Fail(c, web.NewConflictError("岗位编号已存在"))
return
}
@@ -85,7 +85,7 @@ func UpdatePosition(c *gin.Context) {
p.Name = req.Name
p.Description = req.Description
p.Status = req.Status
if !positionRepo.Update(&p) {
if !positionDAO.Update(&p) {
web.Fail(c, web.NewBadRequest("更新岗位失败"))
return
}
@@ -98,7 +98,7 @@ func DeletePosition(c *gin.Context) {
if !ok {
return
}
if !positionRepo.Delete(id) {
if !positionDAO.Delete(id) {
web.Fail(c, web.NewBadRequest("停用岗位失败"))
return
}
@@ -138,7 +138,7 @@ func ListPositionKnowledge(c *gin.Context) {
if !ok {
return
}
items := positionRepo.Knowledge(id)
items := positionDAO.Knowledge(id)
if items == nil {
items = []model.PositionKnowledge{}
}
@@ -151,7 +151,7 @@ func SavePositionKnowledge(c *gin.Context) {
if !ok {
return
}
_, found := positionRepo.GetByID(id)
_, found := positionDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("岗位不存在"))
return
@@ -191,11 +191,11 @@ func SavePositionKnowledge(c *gin.Context) {
})
}
// 整表覆盖:先删旧,再批量插入
if !positionRepo.ReplaceKnowledge(id, rows) {
if !positionDAO.ReplaceKnowledge(id, rows) {
web.Fail(c, web.NewBadRequest("保存岗位知识映射失败"))
return
}
out := positionRepo.Knowledge(id)
out := positionDAO.Knowledge(id)
if out == nil {
out = []model.PositionKnowledge{}
}
@@ -210,7 +210,7 @@ func SetUserPosition(c *gin.Context) {
if !ok {
return
}
u, found := userRepo.GetByID(id)
u, found := userDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("用户不存在"))
return
@@ -223,14 +223,14 @@ func SetUserPosition(c *gin.Context) {
return
}
if req.PositionID != nil {
_, found := positionRepo.GetByID(*req.PositionID)
_, found := positionDAO.GetByID(*req.PositionID)
if !found {
web.Fail(c, web.NewBadRequest("岗位不存在或已停用"))
return
}
}
u.PositionID = req.PositionID
if !userRepo.Update(&u) {
if !userDAO.Update(&u) {
web.Fail(c, web.NewBadRequest("设置用户岗位失败"))
return
}
@@ -246,13 +246,13 @@ func MyPosition(c *gin.Context) {
web.OK(c, gin.H{"position": nil, "knowledge": []gin.H{}, "count": 0})
return
}
pos, found := positionRepo.GetByID(*u.PositionID)
pos, found := positionDAO.GetByID(*u.PositionID)
if !found || pos.Status != "active" {
web.OK(c, gin.H{"position": nil, "knowledge": []gin.H{}, "count": 0})
return
}
pks := positionRepo.Knowledge(pos.ID)
pks := positionDAO.Knowledge(pos.ID)
// 批量解析课程/产品名称
courseIDs := make([]uint, 0, len(pks))
@@ -265,8 +265,8 @@ func MyPosition(c *gin.Context) {
productIDs = append(productIDs, *pk.ProductID)
}
}
courseName := courseRepo.NamesByIDs(courseIDs)
productName := productRepo.NamesByIDs(productIDs)
courseName := courseDAO.NamesByIDs(courseIDs)
productName := productDAO.NamesByIDs(productIDs)
list := make([]gin.H, 0, len(pks))
for _, pk := range pks {
@@ -303,7 +303,7 @@ func ListPositionBlueprint(c *gin.Context) {
if !ok {
return
}
items := positionRepo.Blueprints(id)
items := positionDAO.Blueprints(id)
if items == nil {
items = []model.PositionExamBlueprint{}
}
@@ -316,7 +316,7 @@ func SavePositionBlueprint(c *gin.Context) {
if !ok {
return
}
_, found := positionRepo.GetByID(id)
_, found := positionDAO.GetByID(id)
if !found {
web.Fail(c, web.NewNotFoundError("岗位不存在"))
return
@@ -346,11 +346,11 @@ func SavePositionBlueprint(c *gin.Context) {
PositionID: id, Domain: it.Domain, Type: it.Type, Count: it.Count,
})
}
if !positionRepo.ReplaceBlueprints(id, rows) {
if !positionDAO.ReplaceBlueprints(id, rows) {
web.Fail(c, web.NewBadRequest("保存岗位考试蓝图失败"))
return
}
out := positionRepo.Blueprints(id)
out := positionDAO.Blueprints(id)
if out == nil {
out = []model.PositionExamBlueprint{}
}