本提交含两部分。第一部分是本轮工作;第二部分是此前一直留在工作区、
从未提交的对象化重构,与第一部分在文件上互相咬合(internal/repository
整个包都是未跟踪状态,且 api 层已有文件引用它),无法拆成两个可编译的提交。
一、仓库层收口 A1 批(本轮工作)
把 api 层手写的 store.DB 查询收进具名仓库方法,只给真正获益的对象做方法,
不机械包裹全量。本批迁移 22 处裸查询(courses.go 9 / media.go 12 / products.go 1),
新增方法:
- MediaFileRepo.ListByBind / ListForAudit / MarkExtracted
- KnowledgeChunkRepo.CountByMediaFile
- ProductRepo.GetVisibleByID
两条业务口径改由仓库单点持有,避免各处手写漂移:
「只有 approved 素材出现在课程详情」与「已停用产品不在课程详情露出」。
修掉两个真实缺陷:
- ProductRepo.GetByID 缺 Where 条件。此前 GET /api/products/{id} 对任意 id 都返回
第一条产品、对不存在的 id 返回 200,且 PUT /api/products/{id} 会覆盖第一条产品
—— 数据损坏级。全仓扫描确认这是唯一一处同型写法。
- ProductRepo.Delete 写 status="deleted",而 DELETE 处理器文档与回包都声称
"inactive",接口在说谎;管理员用 status=all 拉列表会看到前端不认识的状态。
已对齐为 inactive(与 CourseRepo.Delete 一致)。
删除 8 个零调用且列名不存在的死方法(一调即 SQL 报错):
- media_file 上的 file_path / file_type / approval_status 三列并不存在,
GetByPath / ListByType / UpdateStatus 全废
- knowledge_chunk 上的 space_id 列不存在(模型早已改为 knowledge_space_key),
List / Total / ListBySpaceIDs / DeleteBySpace / SearchByVector 全废
取舍边界:能对当前 schema 跑通的死方法保留,跑不通的删或修。
CourseRepo.List 补齐 status=all 档(此前传给它会当作 status='all' 过滤出空列表)。
该方法此前零调用,现与产品列表语义对齐。
验证:go build ./... 与 go test ./... 全绿;另用真实 HTTP 请求验证 34 项
(课程 17 / 产品 3 / 素材 14),跑在数据库副本与独立 KB_DATA_DIR 上,
含 multipart 真上传 → 审批 → pdftotext 提取 → 分片入库的完整链路。
二、此前未提交的对象化重构(非本轮工作)
- 新增 internal/repository 仓库层、connectors、skills、specialists、xapps、jsonutil,
model/task_record|task_run|task_artifact、api/task_runtime|action_definition|chat_message
- 删除 api/app_definition、connectors、my_app_center、notification、office_skill、
export_docx|pptx|xlsx、official_account_* 等,随 XApp/Skill/Specialist/Connector
可插拔打包方向(AR10/AR11)调整
- 资产目录归位:backend-go/knowledge_source → assets/knowledge/source、
training_materials → assets/training/materials;README 内相对路径同步加深两级;
deploy env 补 ASSET_ROOT_DIR 并改 KNOWLEDGE_SOURCE_DIR / TRAINING_MATERIALS_DIR
- 前端新增 skills/ specialists/ connectors/ xapps/ 目录与对应页面
验证:前端 npm run build 通过(7.26s)。
Co-Authored-By: Claude Code <noreply@anthropic.com>
162 lines
4.0 KiB
Go
162 lines
4.0 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"eai_agentplatform/backend/internal/middleware"
|
|
"eai_agentplatform/backend/internal/model"
|
|
"eai_agentplatform/backend/internal/store"
|
|
"eai_agentplatform/backend/internal/web"
|
|
)
|
|
|
|
// domainLabels 能力雷达维度(正式考试按域聚合的掌握度)。
|
|
var domainLabels = map[string]string{
|
|
"company": "公司认知",
|
|
"product": "产品知识",
|
|
"sales": "销售能力",
|
|
}
|
|
|
|
// domainOrder 雷达图固定排序。
|
|
var domainOrder = []string{"company", "product", "sales"}
|
|
|
|
// detailWrap 正式考试答题明细(与 ExamSubmit 持久化的 detail_json 结构对齐)。
|
|
type detailWrap struct {
|
|
Questions []struct {
|
|
QuestionID uint `json:"question_id"`
|
|
IsCorrect bool `json:"is_correct"`
|
|
} `json:"questions"`
|
|
}
|
|
|
|
// MyProfile GET /api/my/profile —— 学员学习档案:能力雷达 + 学习统计 + 成绩趋势 + 积分。
|
|
func MyProfile(c *gin.Context) {
|
|
u := middleware.CurrentUser(c)
|
|
if u == nil {
|
|
web.Fail(c, web.NewAuthError("未登录"))
|
|
return
|
|
}
|
|
|
|
// 学习进度(公司/产品/课程浏览)
|
|
var lps []model.LearningProgress
|
|
store.DB.Where("user_id = ?", u.ID).Find(&lps)
|
|
companyViewed := false
|
|
productViewed, courseViewed := 0, 0
|
|
for _, lp := range lps {
|
|
switch lp.ItemType {
|
|
case "company":
|
|
companyViewed = true
|
|
case "product":
|
|
productViewed++
|
|
case "course":
|
|
courseViewed++
|
|
}
|
|
}
|
|
|
|
// 错题统计
|
|
mistakeTotal := mistakeRepo.CountByUser(u.ID)
|
|
mistakeResolved := mistakeRepo.CountResolvedByUser(u.ID)
|
|
|
|
// 自测次数(自测不落 exam_record,改由积分流水统计)
|
|
var selfTestCount int64
|
|
store.DB.Model(&model.PointEvent{}).Where("user_id = ? AND event_type = ?", u.ID, "self_test").Count(&selfTestCount)
|
|
|
|
// 正式考试记录 + 按域能力聚合
|
|
var recs []model.ExamRecord
|
|
store.DB.Where("user_id = ?", u.ID).Order("submitted_at ASC").Find(&recs)
|
|
|
|
// 题目 → 域映射(用于从答题明细反推各域掌握度)
|
|
var questions []model.Question
|
|
store.DB.Select("id", "domain").Find(&questions)
|
|
qDomain := map[uint]string{}
|
|
for _, q := range questions {
|
|
qDomain[q.ID] = q.Domain
|
|
}
|
|
|
|
type domainAgg struct {
|
|
Correct int `json:"correct"`
|
|
Total int `json:"total"`
|
|
}
|
|
perDomain := map[string]*domainAgg{}
|
|
formalPassed := 0
|
|
trend := make([]gin.H, 0, len(recs))
|
|
for _, r := range recs {
|
|
if r.Passed {
|
|
formalPassed++
|
|
}
|
|
trend = append(trend, gin.H{
|
|
"exam_name": r.ExamName,
|
|
"score": r.Score,
|
|
"total_score": r.TotalScore,
|
|
"passed": r.Passed,
|
|
"submitted_at": r.SubmittedAt,
|
|
})
|
|
|
|
var dw detailWrap
|
|
if err := json.Unmarshal([]byte(r.DetailJSON), &dw); err != nil {
|
|
continue
|
|
}
|
|
for _, qd := range dw.Questions {
|
|
domain := qDomain[qd.QuestionID]
|
|
if domain == "" {
|
|
continue
|
|
}
|
|
a := perDomain[domain]
|
|
if a == nil {
|
|
a = &domainAgg{}
|
|
perDomain[domain] = a
|
|
}
|
|
a.Total++
|
|
if qd.IsCorrect {
|
|
a.Correct++
|
|
}
|
|
}
|
|
}
|
|
|
|
domains := make([]gin.H, 0, len(domainOrder))
|
|
for _, d := range domainOrder {
|
|
a := perDomain[d]
|
|
if a == nil {
|
|
a = &domainAgg{}
|
|
}
|
|
mastery := 0.0
|
|
if a.Total > 0 {
|
|
mastery = round1(float64(a.Correct) * 100 / float64(a.Total))
|
|
}
|
|
domains = append(domains, gin.H{
|
|
"domain": d,
|
|
"label": domainLabels[d],
|
|
"correct": a.Correct,
|
|
"total": a.Total,
|
|
"mastery": mastery,
|
|
})
|
|
}
|
|
|
|
// 薄弱点:有作答记录中掌握度最低的域
|
|
weakDomain := ""
|
|
weakMastery := 100.0
|
|
for _, d := range domains {
|
|
if d["total"].(int) > 0 && d["mastery"].(float64) < weakMastery {
|
|
weakMastery = d["mastery"].(float64)
|
|
weakDomain = d["domain"].(string)
|
|
}
|
|
}
|
|
|
|
web.OK(c, gin.H{
|
|
"learning_points": u.LearningPoints,
|
|
"stats": gin.H{
|
|
"company_viewed": companyViewed,
|
|
"product_viewed": productViewed,
|
|
"course_viewed": courseViewed,
|
|
"self_test_count": selfTestCount,
|
|
"formal_count": len(recs),
|
|
"formal_passed": formalPassed,
|
|
"mistake_count": mistakeTotal,
|
|
"mistake_resolved": mistakeResolved,
|
|
},
|
|
"domains": domains,
|
|
"weak_domain": weakDomain,
|
|
"recent_scores": trend,
|
|
})
|
|
}
|