|
|
@@ -17,6 +17,23 @@ export type MonographCategory =
|
|
|
| 'reference'
|
|
|
| 'textbook';
|
|
|
|
|
|
+/** 后端 `type` 字段,对应字典:智慧传承系统-论著类别 */
|
|
|
+export type MonographTypeDTO = '0' | '1' | '2' | '3';
|
|
|
+
|
|
|
+const MONOGRAPH_TYPE_TO_DTO: Record<MonographCategory, MonographTypeDTO> = {
|
|
|
+ textbook: '0',
|
|
|
+ academic: '1',
|
|
|
+ popular_science: '2',
|
|
|
+ reference: '3',
|
|
|
+};
|
|
|
+
|
|
|
+const MONOGRAPH_TYPE_FROM_DTO: Record<MonographTypeDTO, MonographCategory> = {
|
|
|
+ '0': 'textbook',
|
|
|
+ '1': 'academic',
|
|
|
+ '2': 'popular_science',
|
|
|
+ '3': 'reference',
|
|
|
+};
|
|
|
+
|
|
|
export const MONOGRAPH_CATEGORY_OPTIONS = [
|
|
|
{ label: '教材', value: 'textbook' },
|
|
|
{ label: '学术专著', value: 'academic' },
|
|
|
@@ -34,29 +51,75 @@ export function getMonographCategoryLabel(category?: MonographCategory) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+export function decodeMonographType(type?: number | string): MonographCategory {
|
|
|
+ const normalized = type?.toString();
|
|
|
+ if (
|
|
|
+ normalized === '0' ||
|
|
|
+ normalized === '1' ||
|
|
|
+ normalized === '2' ||
|
|
|
+ normalized === '3'
|
|
|
+ ) {
|
|
|
+ return MONOGRAPH_TYPE_FROM_DTO[normalized];
|
|
|
+ }
|
|
|
+ return 'textbook';
|
|
|
+}
|
|
|
+
|
|
|
+/** 按类别过滤分页结果(后端未按 type 过滤时的兜底) */
|
|
|
+export function filterMonographPageByCategory<
|
|
|
+ T extends { items: MonographVO[]; total: number },
|
|
|
+>(page: T, category?: MonographCategory): T {
|
|
|
+ if (!category) return page;
|
|
|
+ const items = page.items.filter((item) => item.category === category);
|
|
|
+ return { ...page, items };
|
|
|
+}
|
|
|
+
|
|
|
+function encodeMonographType(category: MonographCategory): MonographTypeDTO {
|
|
|
+ return MONOGRAPH_TYPE_TO_DTO[category];
|
|
|
+}
|
|
|
+
|
|
|
+function formatPublishTime(publishDate: string) {
|
|
|
+ if (!publishDate) return publishDate;
|
|
|
+ if (/^\d{4}-\d{2}$/.test(publishDate)) {
|
|
|
+ return `${publishDate}-01T00:00:00`;
|
|
|
+ }
|
|
|
+ return publishDate;
|
|
|
+}
|
|
|
+
|
|
|
+function formatPublishDate(publishTime?: string) {
|
|
|
+ if (!publishTime) return '';
|
|
|
+ return publishTime.slice(0, 7);
|
|
|
+}
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------
|
|
|
// DTO
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
+/** 论著 DTO,对应 `OutcomeTreatiseDetail` */
|
|
|
export interface MonographDTO extends AuditRecordDTO {
|
|
|
id?: number | string;
|
|
|
+ status?: string;
|
|
|
+ remark?: string;
|
|
|
personalStudioId?: number | string;
|
|
|
- category?: MonographCategory;
|
|
|
+ fileUrl?: string;
|
|
|
+ downloadCount?: number;
|
|
|
+ browseCount?: number;
|
|
|
+ commentCount?: number;
|
|
|
+ praiseCount?: number;
|
|
|
+ /** 论著类别,详见字典:智慧传承系统-论著类别 */
|
|
|
+ type?: MonographTypeDTO | string;
|
|
|
title?: string;
|
|
|
author?: string;
|
|
|
- publisher?: string;
|
|
|
- publishDate?: string;
|
|
|
+ publishHouse?: string;
|
|
|
+ publishTime?: string;
|
|
|
isbn?: string;
|
|
|
- description?: string;
|
|
|
- fileUrl?: string;
|
|
|
- viewCount?: number;
|
|
|
- commentCount?: number;
|
|
|
+ profile?: string;
|
|
|
}
|
|
|
|
|
|
export interface MonographQueryDTO {
|
|
|
mixture?: string;
|
|
|
personalStudioId?: number | string;
|
|
|
- category?: MonographCategory;
|
|
|
+ type?: MonographTypeDTO | string;
|
|
|
+ status?: string;
|
|
|
pageNum?: number;
|
|
|
pageSize?: number;
|
|
|
}
|
|
|
@@ -115,15 +178,15 @@ export function decodeMonograph(dto: MonographDTO): MonographVO {
|
|
|
...decodeAuditRecord(dto),
|
|
|
id: dto.id?.toString(),
|
|
|
workroomId: dto.personalStudioId?.toString() ?? '',
|
|
|
- category: dto.category ?? 'textbook',
|
|
|
+ category: decodeMonographType(dto.type),
|
|
|
title: dto.title ?? '',
|
|
|
author: dto.author ?? '',
|
|
|
- publisher: dto.publisher ?? '',
|
|
|
- publishDate: dto.publishDate ?? '',
|
|
|
+ publisher: dto.publishHouse ?? '',
|
|
|
+ publishDate: formatPublishDate(dto.publishTime),
|
|
|
isbn: dto.isbn ?? '',
|
|
|
- description: dto.description,
|
|
|
+ description: dto.profile,
|
|
|
pdfUrl: dto.fileUrl,
|
|
|
- viewCount: dto.viewCount ?? 0,
|
|
|
+ viewCount: dto.browseCount ?? 0,
|
|
|
commentCount: dto.commentCount ?? 0,
|
|
|
};
|
|
|
}
|
|
|
@@ -134,7 +197,7 @@ export function encodeMonographQuery(
|
|
|
return {
|
|
|
mixture: query.keyword,
|
|
|
personalStudioId: query.workroomId,
|
|
|
- category: query.category,
|
|
|
+ type: query.category ? encodeMonographType(query.category) : undefined,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -142,14 +205,14 @@ export function encodeMonograph(vo: MonographSubmitVO): MonographDTO {
|
|
|
return {
|
|
|
id: vo.id,
|
|
|
personalStudioId: vo.workroomId,
|
|
|
- category: vo.category,
|
|
|
+ fileUrl: vo.pdfUrl,
|
|
|
+ type: encodeMonographType(vo.category),
|
|
|
title: vo.title,
|
|
|
author: vo.author,
|
|
|
- publisher: vo.publisher,
|
|
|
- publishDate: vo.publishDate,
|
|
|
+ publishHouse: vo.publisher,
|
|
|
+ publishTime: formatPublishTime(vo.publishDate),
|
|
|
isbn: vo.isbn,
|
|
|
- description: vo.description,
|
|
|
- fileUrl: vo.pdfUrl,
|
|
|
+ profile: vo.description,
|
|
|
};
|
|
|
}
|
|
|
|