| 1 | import { AccountType, createZodDto } from '@yikart/common' |
| 2 | import { z } from 'zod' |
| 3 | |
| 4 | import { AccountStatus, PublishRecordLinkStatus, PublishRecordSource, PublishStatus, PublishType } from '../enums' |
| 5 | |
| 6 | // --------------------------------------------------------------------------- |
| 7 | // Account |
| 8 | // --------------------------------------------------------------------------- |
| 9 | |
| 10 | export const AccountSchema = z.object({ |
| 11 | id: z.string().describe('账号 ID'), |
| 12 | userId: z.string().describe('所属用户 ID'), |
| 13 | type: z.enum(AccountType).describe('账号平台类型'), |
| 14 | uid: z.string().describe('平台用户 UID'), |
| 15 | account: z.string().describe('账号名称'), |
| 16 | loginCookie: z.string().describe('登录 Cookie'), |
| 17 | access_token: z.string().optional().describe('Access Token'), |
| 18 | refresh_token: z.string().optional().describe('Refresh Token'), |
| 19 | groupId: z.string().describe('分组 ID'), |
| 20 | loginTime: z.coerce.date().optional().describe('登录时间'), |
| 21 | avatar: z.string().optional().describe('头像 URL'), |
| 22 | nickname: z.string().describe('昵称'), |
| 23 | status: z.enum(AccountStatus).describe('账号状态'), |
| 24 | }) |
| 25 | export interface Account extends z.infer<typeof AccountSchema> {} |
| 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | // NewAccount (kept as class for backward compatibility) |
| 29 | // --------------------------------------------------------------------------- |
| 30 | |
| 31 | export class NewAccount { |
| 32 | constructor( |
| 33 | data: { |
| 34 | userId: string |
| 35 | type: AccountType |
| 36 | uid: string |
| 37 | account: string |
| 38 | loginCookie?: string |
| 39 | access_token?: string |
| 40 | refresh_token?: string |
| 41 | token?: string |
| 42 | avatar?: string |
| 43 | nickname: string |
| 44 | lastStatsTime?: Date |
| 45 | loginTime?: Date |
| 46 | status?: AccountStatus |
| 47 | groupId?: string |
| 48 | }, |
| 49 | ) { |
| 50 | Object.assign(this, data) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // --------------------------------------------------------------------------- |
| 55 | // UpdateAccountStatisticsData |
| 56 | // --------------------------------------------------------------------------- |
| 57 | |
| 58 | export const UpdateAccountStatisticsDataSchema = z.object({ |
| 59 | workCount: z.number().optional().describe('作品数'), |
| 60 | fansCount: z.number().optional().describe('粉丝数'), |
| 61 | readCount: z.number().optional().describe('阅读/播放数'), |
| 62 | likeCount: z.number().optional().describe('点赞数'), |
| 63 | collectCount: z.number().optional().describe('收藏数'), |
| 64 | commentCount: z.number().optional().describe('评论数'), |
| 65 | income: z.number().optional().describe('收入'), |
| 66 | }) |
| 67 | export interface UpdateAccountStatisticsData extends z.infer<typeof UpdateAccountStatisticsDataSchema> {} |
| 68 | |
| 69 | // --------------------------------------------------------------------------- |
| 70 | // PublishRecord |
| 71 | // --------------------------------------------------------------------------- |
| 72 | |
| 73 | export const PublishRecordSchema = z.object({ |
| 74 | _id: z.any().describe('MongoDB _id'), |
| 75 | id: z.string().describe('记录 ID'), |
| 76 | userId: z.string().optional().describe('用户 ID'), |
| 77 | flowId: z.string().optional().describe('流程 ID'), |
| 78 | materialGroupId: z.string().optional().describe('素材组 ID'), |
| 79 | materialId: z.string().optional().describe('素材 ID'), |
| 80 | taskId: z.string().optional().describe('任务 ID'), |
| 81 | type: z.enum(PublishType).describe('发布类型'), |
| 82 | title: z.string().optional().describe('标题'), |
| 83 | desc: z.string().optional().describe('描述'), |
| 84 | accountId: z.string().describe('账号 ID'), |
| 85 | topics: z.array(z.string()).describe('话题列表'), |
| 86 | accountType: z.enum(AccountType).describe('账号平台类型'), |
| 87 | uid: z.string().describe('平台用户 UID'), |
| 88 | videoUrl: z.string().optional().describe('视频 URL'), |
| 89 | coverUrl: z.string().optional().describe('封面 URL'), |
| 90 | imgUrlList: z.array(z.string()).optional().describe('图片 URL 列表'), |
| 91 | publishTime: z.coerce.date().describe('发布时间'), |
| 92 | status: z.enum(PublishStatus).describe('发布状态'), |
| 93 | source: z.enum(PublishRecordSource).optional().describe('发布来源'), |
| 94 | errorMsg: z.string().optional().describe('错误信息'), |
| 95 | errorData: z.object({ |
| 96 | type: z.string(), |
| 97 | code: z.string(), |
| 98 | message: z.string(), |
| 99 | originalData: z.record(z.string(), z.any()).optional(), |
| 100 | }).optional().describe('结构化错误诊断信息'), |
| 101 | queueId: z.string().optional().describe('队列 ID'), |
| 102 | inQueue: z.boolean().describe('是否在队列中'), |
| 103 | option: z.any().optional().describe('额外选项'), |
| 104 | dataId: z.string().optional().describe('数据 ID'), |
| 105 | workLink: z.string().optional().describe('作品链接'), |
| 106 | platformWorkId: z.string().optional().describe('平台作品 ID'), |
| 107 | linkStatus: z.enum(PublishRecordLinkStatus).optional().describe('作品链接状态'), |
| 108 | linkError: z.string().optional().describe('作品链接获取错误'), |
| 109 | linkMeta: z.record(z.string(), z.any()).optional().describe('作品链接扩展信息'), |
| 110 | dataOption: z.record(z.string(), z.any()).optional().describe('数据选项'), |
| 111 | createdAt: z.coerce.date().describe('创建时间'), |
| 112 | updatedAt: z.coerce.date().describe('更新时间'), |
| 113 | }) |
| 114 | export interface PublishRecord extends z.infer<typeof PublishRecordSchema> {} |
| 115 | |
| 116 | // --------------------------------------------------------------------------- |
| 117 | // Existing VOs |
| 118 | // --------------------------------------------------------------------------- |
| 119 | |
| 120 | export const BatchAccountStatusVoSchema = z.object({ |
| 121 | statuses: z.record(z.string(), z.number()).describe('账号 ID → 状态映射'), |
| 122 | }) |
| 123 | export class BatchAccountStatusVo extends createZodDto(BatchAccountStatusVoSchema, 'BatchAccountStatusVo') {} |
| 124 | |
| 125 | export const AccountStatisticsRefreshVoSchema = z.object({ |
| 126 | fansCount: z.number().optional().describe('粉丝数'), |
| 127 | readCount: z.number().optional().describe('阅读/播放数'), |
| 128 | likeCount: z.number().optional().describe('点赞数'), |
| 129 | collectCount: z.number().optional().describe('收藏数'), |
| 130 | commentCount: z.number().optional().describe('评论数'), |
| 131 | workCount: z.number().optional().describe('作品数'), |
| 132 | lastStatsTime: z.coerce.date().describe('最后更新时间'), |
| 133 | }) |
| 134 | export class AccountStatisticsRefreshVo extends createZodDto(AccountStatisticsRefreshVoSchema, 'AccountStatisticsRefreshVo') {} |
| 135 | |
| 136 | export const AggregatedAccountStatisticsVoSchema = z.object({ |
| 137 | accountTotal: z.number().describe('账号总数'), |
| 138 | fansCount: z.number().describe('在线账号总粉丝数'), |
| 139 | readCount: z.number().describe('总阅读/播放数'), |
| 140 | likeCount: z.number().describe('总点赞数'), |
| 141 | collectCount: z.number().describe('总收藏数'), |
| 142 | commentCount: z.number().describe('总评论数'), |
| 143 | forwardCount: z.number().describe('总转发数'), |
| 144 | workCount: z.number().describe('总作品数'), |
| 145 | }) |
| 146 | export class AggregatedAccountStatisticsVo extends createZodDto( |
| 147 | AggregatedAccountStatisticsVoSchema, |
| 148 | 'AggregatedAccountStatisticsVo', |
| 149 | ) {} |
| 150 | |
| 151 | export const TotalFansCountVoSchema = z.object({ |
| 152 | totalFansCount: z.number().describe('在线账号总粉丝数:每个渠道取粉丝数最多的在线账号后求和'), |
| 153 | }) |
| 154 | export class TotalFansCountVo extends createZodDto(TotalFansCountVoSchema, 'TotalFansCountVo') {} |
| 155 |