feat(desktop): ✨ 实现一些功能
1. 实现了用户阅读画像 2. 实现了全局检索功能
This commit is contained in:
30
src/rpc/router/persona.router.ts
Normal file
30
src/rpc/router/persona.router.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ReadingPersona } from '@main/db/entities/ReadingPersona'
|
||||
import { router, t } from '@rpc/index'
|
||||
import { entityToUserReadingPersona, PersonaService } from '@main/services/persona.service'
|
||||
import { ReadingReflectionTaskBatch } from '@main/db/entities/ReadingReflectionTaskBatch'
|
||||
import { ReadingReflectionTaskItem } from '@main/db/entities/ReadingReflectionTaskItem'
|
||||
|
||||
export const personaRouter = router({
|
||||
// 获取用户画像:直接从数据库读取缓存结果,极快
|
||||
getUserPersona: t.procedure.query(async ({ ctx }) => {
|
||||
const entity = await ctx.db.getRepository(ReadingPersona).findOneBy({
|
||||
id: 'current_user_persona'
|
||||
})
|
||||
|
||||
if (!entity) return null
|
||||
|
||||
// 将数据库扁平实体映射为前端需要的结构化 IUserReadingPersona
|
||||
return entityToUserReadingPersona(entity)
|
||||
}),
|
||||
|
||||
// 手动强制重新刷新画像
|
||||
forceRefreshUserPersona: t.procedure.mutation(async ({ ctx }) => {
|
||||
const items = await ctx.db
|
||||
.getRepository(ReadingReflectionTaskItem)
|
||||
.find({ where: { status: 'COMPLETED' } })
|
||||
const batches = await ctx.db.getRepository(ReadingReflectionTaskBatch).find()
|
||||
|
||||
const personaService = new PersonaService(ctx.db.getRepository(ReadingPersona))
|
||||
return await personaService.refreshPersona(items, batches)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user