refactor: 后端仓库层收口(A1:课程/产品/素材)+ 收进工作区既有对象化重构

本提交含两部分。第一部分是本轮工作;第二部分是此前一直留在工作区、
从未提交的对象化重构,与第一部分在文件上互相咬合(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>
This commit is contained in:
eaiadmin
2026-09-19 01:23:51 +08:00
co-authored by Claude Code
parent ddd2d2cbd8
commit 14f303459e
448 changed files with 18792 additions and 17027 deletions
@@ -279,14 +279,14 @@
</main>
</div>
<AppChatRail
v-if="appChatContext"
:scope-key="appChatContext.scopeKey"
:title="appChatContext.title"
:subtitle="appChatContext.subtitle"
:placeholder="appChatContext.placeholder"
:empty-text="appChatContext.emptyText"
:starter-prompts="appChatContext.starterPrompts"
<SurfaceChatRail
v-if="surfaceChatContext"
:scope-key="surfaceChatContext.scopeKey"
:title="surfaceChatContext.title"
:subtitle="surfaceChatContext.subtitle"
:placeholder="surfaceChatContext.placeholder"
:empty-text="surfaceChatContext.emptyText"
:starter-prompts="surfaceChatContext.starterPrompts"
/>
<NavSearch v-model="searchOpen" :sections="visibleSections" :tabs="openTabs" />
@@ -348,17 +348,23 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Check, Delete, EditPen, Expand, Fold, FolderAdd, MoreFilled, Search, Top } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import AppChatRail from '@/components/chat/AppChatRail.vue'
import SurfaceChatRail from '@/components/chat/SurfaceChatRail.vue'
import SectionTabs from '@/components/SectionTabs.vue'
import NavSearch from '@/components/NavSearch.vue'
import { useAuthStore } from '@/store/auth'
import { useProjectStore } from '@/store/projectStore'
import { useSkillCatalogStore } from '@/store/skillCatalog'
import { useSpecialistCatalogStore } from '@/store/specialistCatalog'
import { useProjectStore } from '@/store/project'
import { useSkillCatalogStore } from '@/skills/store/skillCatalog'
import { useSpecialistCatalogStore } from '@/specialists/store/specialistCatalog'
import { useWorkbenchStore } from '@/store/workbench'
import { useWorkerRuntimeStore } from '@/store/workerRuntime'
import { getAppCases, getDefaultCaseId } from '@/config/workbench'
import { useTaskRuntimeStore } from '@/store/taskRuntime'
import { getDefaultWorkspaceCaseId, getWorkspaceCases } from '@/config/workbench'
import { relativeTime } from '@/config/projectTemplates'
import {
INTERNAL_EXAM_XAPP_ROOT,
INTERNAL_TRAINING_MODULE_ROUTES,
INTERNAL_TRAINING_XAPP_ROOT,
XAPP_DIRECTORY_ROUTE,
} from '@/xapps/config/xappRoutes'
import {
findGroupByPath,
findSectionByPath,
@@ -373,7 +379,7 @@ const projectStore = useProjectStore()
const skillCatalog = useSkillCatalogStore()
const specialistCatalog = useSpecialistCatalogStore()
const workbench = useWorkbenchStore()
const workerRuntime = useWorkerRuntimeStore()
const taskRuntime = useTaskRuntimeStore()
const isAdmin = computed(() => auth.isAdmin)
const username = computed(() => auth.username || '同事')
@@ -410,11 +416,11 @@ const activeGroup = computed(() => findGroupByPath(activeSection.value, route.pa
const openTabs = computed(() => workbench.openTabs)
// 侧边栏那一列「最近任务」。归属由后端按登录用户定,这里只负责显示。
const myTasks = computed(() => workerRuntime.myTasks)
const loadingMyTasks = computed(() => workerRuntime.loadingMyTasks)
const currentTaskId = computed(() => workerRuntime.currentTaskId)
const currentTask = computed(() => workerRuntime.currentTask)
const pendingTaskTitle = computed(() => String(workerRuntime.pendingTaskTitle || '').trim())
const myTasks = computed(() => taskRuntime.myTasks)
const loadingMyTasks = computed(() => taskRuntime.loadingMyTasks)
const currentTaskId = computed(() => taskRuntime.currentTaskId)
const currentTask = computed(() => taskRuntime.currentTask)
const pendingTaskTitle = computed(() => String(taskRuntime.pendingTaskTitle || '').trim())
const projectOptions = computed(() => projectStore.projects)
const collapsedProjectMap = ref({})
const currentTaskTitle = computed(() => (
@@ -425,15 +431,13 @@ const currentTaskDisplayTitle = computed(() =>
)
const shouldShowTaskTitlebar = computed(() => {
const path = route.path || ''
if (path === '/long-apps') return false
if (path.startsWith('/courses')) return false
if (path.startsWith('/products')) return false
if (path.startsWith('/company-train')) return false
if (path.startsWith('/exam')) return false
if (path === XAPP_DIRECTORY_ROUTE) return false
if (path.startsWith(INTERNAL_TRAINING_XAPP_ROOT)) return false
if (path.startsWith(INTERNAL_EXAM_XAPP_ROOT)) return false
if (path === '/knowledge-hub') return false
return true
})
const appChatContext = computed(() => resolveAppChatContext(route.path || ''))
const surfaceChatContext = computed(() => resolveSurfaceChatContext(route.path || ''))
const recentLooseTasks = computed(() => myTasks.value.filter((task) => !task?.project_id))
const recentProjectGroups = computed(() => {
const projectMap = new Map(
@@ -459,8 +463,8 @@ const recentProjectGroups = computed(() => {
})
// ===== Worker runtime context (used by workspace surfaces) =====
const appKey = computed(() => route.meta.workspaceKey || '')
const runtimeCases = computed(() => workerRuntime.tasksBySpecialist[appKey.value] || [])
const workspaceKey = computed(() => route.meta.workspaceKey || '')
const runtimeCases = computed(() => taskRuntime.tasksBySpecialist[workspaceKey.value] || [])
const currentCases = computed(() => {
if (runtimeCases.value.length) {
return runtimeCases.value.map(item => ({
@@ -473,11 +477,11 @@ const currentCases = computed(() => {
status: item.status || '待处理',
}))
}
return appKey.value ? getAppCases(appKey.value) : []
return workspaceKey.value ? getWorkspaceCases(workspaceKey.value) : []
})
const selectedCaseId = computed(() => {
if (!appKey.value) return ''
return workbench.selectedCases[appKey.value] || currentCases.value[0]?.id || getDefaultCaseId(appKey.value)
if (!workspaceKey.value) return ''
return workbench.selectedCases[workspaceKey.value] || currentCases.value[0]?.id || getDefaultWorkspaceCaseId(workspaceKey.value)
})
onMounted(() => {
@@ -503,11 +507,11 @@ function handleShortcut(event) {
}
watch(
appKey,
workspaceKey,
async (key) => {
if (!key) return
try {
await workerRuntime.loadTasks(key)
await taskRuntime.loadTasks(key)
} catch (error) {
console.warn('load worker tasks for shell failed', error)
}
@@ -518,10 +522,10 @@ watch(
watch(
() => currentCases.value.map(item => item.id).join(','),
(ids) => {
if (!appKey.value || !ids) return
const selected = workbench.selectedCases[appKey.value]
if (!workspaceKey.value || !ids) return
const selected = workbench.selectedCases[workspaceKey.value]
if (!selected || !currentCases.value.some(item => item.id === selected)) {
workbench.setSelectedCase(appKey.value, currentCases.value[0]?.id || getDefaultCaseId(appKey.value))
workbench.setSelectedCase(workspaceKey.value, currentCases.value[0]?.id || getDefaultWorkspaceCaseId(workspaceKey.value))
}
},
{ immediate: true }
@@ -532,7 +536,7 @@ watch(
async (id) => {
if (!id || !/^\d+$/.test(String(id))) return
try {
await workerRuntime.loadTaskDetail(id)
await taskRuntime.loadTaskDetail(id)
} catch (error) {
console.warn('load worker task detail for shell failed', error)
}
@@ -547,7 +551,7 @@ watch(
// (右侧工作台要用),以及把路由喂给 store —— 折算成哪个胶囊由 store 一处决定。
const specialist = specialistCatalog.getByPath(path)
if (specialist?.key && !workbench.selectedCases[specialist.key]) {
workbench.setSelectedCase(specialist.key, getDefaultCaseId(specialist.key))
workbench.setSelectedCase(specialist.key, getDefaultWorkspaceCaseId(specialist.key))
}
workbench.ensureTab({ pageRoute: path })
},
@@ -581,7 +585,7 @@ function openSection(section) {
// createTaskForFirstMessage),标题就是那句话,专员用 + 里先选的那个。
// 点一次建一条的话,连点几下就会在「最近任务」里堆出一列没聊过天的空任务。
function startNewTask() {
workerRuntime.startNewTask()
taskRuntime.startNewTask()
router.push('/home')
// 从别的页面过来时组件会重新挂载,画布本来就是干净的;已经停在 /home
// 时靠这个事件把当前对话清掉。两种情况都发一次,调用方不用自己判断。
@@ -590,7 +594,7 @@ function startNewTask() {
async function loadMyTasks() {
try {
await workerRuntime.loadMyTasks()
await taskRuntime.loadMyTasks()
} catch (error) {
console.warn('load my tasks for shell failed', error)
}
@@ -607,8 +611,8 @@ async function loadMyTasks() {
// 注意:对话内容目前没有按任务落库,所以重开一条旧任务时恢复的是「在哪做」
// 和「用哪个技能做」,不是完整消息历史。
async function openMyTask(task) {
workerRuntime.openTask(task.id, task.specialist_key)
const currentSkill = skillCatalog.getByKey(workerRuntime.skillKeyOfTask(task.id))
taskRuntime.openTask(task.id, task.specialist_key)
const currentSkill = skillCatalog.getByKey(taskRuntime.skillKeyOfTask(task.id))
const target = currentSkill?.objectEntryRoute || '/home'
if (route.path !== target) await router.push(target)
}
@@ -657,7 +661,7 @@ async function onTaskCommand(command, task) {
if (command === 'pin') {
try {
await workerRuntime.togglePinned(task.id)
await taskRuntime.togglePinned(task.id)
} catch (error) {
console.warn('toggle task pinned failed', error)
ElMessage.error(task.pinned ? '取消置顶失败,请稍后重试' : '置顶失败,请稍后重试')
@@ -683,7 +687,7 @@ async function onTaskCommand(command, task) {
return // 点了取消
}
try {
await workerRuntime.deleteMyTask(task.id)
await taskRuntime.deleteMyTask(task.id)
ElMessage.success('已删除')
} catch (error) {
console.warn('delete task failed', error)
@@ -727,7 +731,7 @@ async function confirmJoinProject() {
joiningProject.value = true
try {
const previousProjectId = task.project_id || 0
const updatedTask = await workerRuntime.assignTaskToProject(task.id, projectId)
const updatedTask = await taskRuntime.assignTaskToProject(task.id, projectId)
projectStore.syncProjectTask(updatedTask, previousProjectId)
const project = projectStore.projects.find((item) => String(item.id) === String(projectId))
ElMessage.success(`已加入项目${project?.name ? `「${project.name}」` : ''}`)
@@ -766,7 +770,7 @@ async function commitRename(task) {
renamingId.value = null
if (!title || title === task.title) return
try {
await workerRuntime.renameTask(task.id, title)
await taskRuntime.renameTask(task.id, title)
} catch (error) {
console.warn('rename task failed', error)
ElMessage.error('重命名失败,请稍后重试')
@@ -801,10 +805,10 @@ function formatDueAt(value) {
return `${month}-${day} ${hour}:${minute}`
}
function resolveAppChatContext(path) {
if (path.startsWith('/courses')) {
function resolveSurfaceChatContext(path) {
if (path.startsWith(INTERNAL_TRAINING_MODULE_ROUTES.courses)) {
return {
scopeKey: 'app-training',
scopeKey: 'surface-training',
title: '培训协作',
subtitle: '边看课程,边让 AI 帮你总结、提炼和辅导。',
placeholder: '例如:帮我总结这门课程的重点,并给出陪练建议',
@@ -815,9 +819,9 @@ function resolveAppChatContext(path) {
],
}
}
if (path.startsWith('/products')) {
if (path.startsWith(INTERNAL_TRAINING_MODULE_ROUTES.products)) {
return {
scopeKey: 'app-product',
scopeKey: 'surface-product',
title: '产品协作',
subtitle: '随时提问产品知识、收费结构和销售表达。',
placeholder: '例如:帮我解释这个产品的收费结构和销售话术',
@@ -828,9 +832,9 @@ function resolveAppChatContext(path) {
],
}
}
if (path.startsWith('/company-train')) {
if (path.startsWith(INTERNAL_TRAINING_MODULE_ROUTES.company)) {
return {
scopeKey: 'app-company-train',
scopeKey: 'surface-company-train',
title: '介绍协作',
subtitle: '结合公司介绍内容,随时生成摘要、讲解稿和问答。',
placeholder: '例如:把这段公司介绍整理成新人培训讲解稿',
@@ -841,9 +845,9 @@ function resolveAppChatContext(path) {
],
}
}
if (path.startsWith('/exam')) {
if (path.startsWith(INTERNAL_EXAM_XAPP_ROOT)) {
return {
scopeKey: 'app-exam',
scopeKey: 'surface-exam',
title: '考试协作',
subtitle: '边看考试页,边让 AI 帮你解释规则、复盘和出练习建议。',
placeholder: '例如:根据当前考试情况帮我做一版复盘建议',