import { http } from './http' import { unwrap } from './envelope' /** 单条通知(后台铃铛)。 */ export interface AdminNotificationItem { id: number scene: string level: string title: string content: string read: boolean readAt: string | null createdAt: string | null } export interface AdminNotificationPage { items: AdminNotificationItem[] total: number page: number pageSize: number unreadCount: number } export interface AdminNotificationSummary { unreadCount: number /** 有未读的聚合组数;徽标用它。unreadCount 仍是"条数",给老明细视图与对账用。 */ unreadGroupCount?: number latestId: number } /** 聚合组:一个「场景 × 自然日 × 事件主体用户」折成的一行。 */ export interface AdminNotificationGroup { latestId: number scene: string category: string day: string subjectUserId: number | null rowCount: number unreadCount: number level: string title: string content: string createdAt: string | null } export interface AdminNotificationGroupPage { groups: AdminNotificationGroup[] /** 组数(分页分母)。 */ total: number /** 折叠前的明细条数——必须与 total 同屏,否则「共 12 条」会被读成只有 12 条通知。 */ rowCount: number page: number pageSize: number unreadGroupCount: number unreadCount: number } /** 铃铛轮询:未读数 + 最新通知 id。 */ export async function fetchNotificationSummary(): Promise { const { data } = await http.get('/api/admin/notifications/summary') return unwrap(data) } /** 列表查询参数:关键字匹配标题/内容;startDate/endDate 为年月日闭区间(yyyy-MM-dd)。 */ export interface AdminNotificationListParams { page?: number pageSize?: number onlyUnread?: boolean keyword?: string startDate?: string endDate?: string /** 展开聚合组:三个条件取自该组自己返回的值,原样回传。 */ scene?: string day?: string subjectUserId?: number | null /** true 表示展开「未区分用户」那一组(subject_user_id 为空的存量行)。 */ subjectUnlabelled?: boolean } /** 聚合列表(铃铛默认视图)。分页按组切。 */ export async function fetchNotificationGroups( params: AdminNotificationListParams = {}, ): Promise { const keyword = (params.keyword ?? '').trim() const { data } = await http.get('/api/admin/notifications/groups', { params: { page: params.page ?? 1, pageSize: params.pageSize ?? 20, onlyUnread: params.onlyUnread ? 'true' : 'false', keyword: keyword || undefined, startDate: params.startDate || undefined, endDate: params.endDate || undefined, }, }) return unwrap(data) } export async function fetchNotificationList( params: AdminNotificationListParams = {}, ): Promise { const keyword = (params.keyword ?? '').trim() const { data } = await http.get('/api/admin/notifications', { params: { page: params.page ?? 1, pageSize: params.pageSize ?? 20, onlyUnread: params.onlyUnread ? 'true' : 'false', keyword: keyword || undefined, startDate: params.startDate || undefined, endDate: params.endDate || undefined, scene: params.scene || undefined, day: params.day || undefined, subjectUserId: params.subjectUserId ?? undefined, subjectUnlabelled: params.subjectUnlabelled ? 'true' : undefined, }, }) return unwrap(data) } export async function markNotificationRead(id: number): Promise { const { data } = await http.post(`/api/admin/notifications/${id}/read`) return unwrap(data) } export async function markAllNotificationsRead(): Promise { const { data } = await http.post('/api/admin/notifications/read-all') return unwrap(data) }