import type { AuditRecordDTO, AuditRecordVO, } from '#/request/schema/audit-record'; import { z } from '#/adapter/form'; import { decodeList } from '#/request/schema'; import { decodeAuditRecord } from '#/request/schema/audit-record'; // --------------------------------------------------------------------------- // DTO // --------------------------------------------------------------------------- export interface ReadingNoteDTO extends AuditRecordDTO { id?: number | string; personalStudioId?: number | string; insightTitle?: string; bookName?: string; authorName?: string; noteDate?: string; noteContent?: string; agreeCount?: number; } export interface ReadingNoteQueryDTO { mixture?: string; personalStudioId?: number | string; pageNum?: number; pageSize?: number; } // --------------------------------------------------------------------------- // VO // --------------------------------------------------------------------------- export interface ReadingNoteVO extends AuditRecordVO { id?: string; workroomId: string; title: string; bookName: string; author: string; noteDate: string; content: string; likeCount?: number; } export type ReadingNoteSubmitVO = ReadingNoteVO; export interface ReadingNoteQueryVO { keyword?: string; workroomId?: string; } // --------------------------------------------------------------------------- // Schema // --------------------------------------------------------------------------- export const ReadingNoteVOSchema = z.object({ id: z.string().optional(), workroomId: z.string().min(1, '工作室不能为空'), title: z.string().min(1, '请输入心得标题'), bookName: z.string().min(1, '请输入书名'), author: z.string().min(1, '请输入心得作者'), noteDate: z.string().min(1, '请选择日期'), content: z.string().min(1, '请输入心得'), }); // --------------------------------------------------------------------------- // 编解码 // --------------------------------------------------------------------------- export function decodeReadingNote(dto: ReadingNoteDTO): ReadingNoteVO { return { ...decodeAuditRecord(dto), id: dto.id?.toString(), workroomId: dto.personalStudioId?.toString() ?? '', title: dto.insightTitle ?? '', bookName: dto.bookName ?? '', author: dto.authorName ?? '', noteDate: dto.noteDate ?? '', content: dto.noteContent ?? '', likeCount: dto.agreeCount ?? 0, }; } export function encodeReadingNoteQuery( query: Partial, ): ReadingNoteQueryDTO { return { mixture: query.keyword, personalStudioId: query.workroomId, }; } export function encodeReadingNote(vo: ReadingNoteSubmitVO): ReadingNoteDTO { return { id: vo.id, personalStudioId: vo.workroomId, insightTitle: vo.title, bookName: vo.bookName, authorName: vo.author, noteDate: vo.noteDate, noteContent: vo.content, }; } export function decodeReadingNoteList(dto: ReadingNoteDTO[]) { return decodeList(dto, decodeReadingNote); }