Files
smart_grid_iot/server/src/controller/notice.controller.ts
T
andyesfly 6cf6a3d5b9 feat: 新增可配置通知中心,支持扫描式/埋点式通知规则与手动群发
新增通知规则实体、扫描任务、API与管理界面,重构站内通知支持用户/电工双类型,移除硬编码的证照到期提醒,新增工单派单、电工审核结果等通知触发场景,调整菜单与数据库结构适配新通知体系。
2026-10-06 11:53:02 +08:00

37 lines
996 B
TypeScript

import { Controller, Get, Put, Inject, Query, Param } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { NoticeService } from "../service/notice.service";
@Controller("/api/notices")
export class NoticeController {
@Inject()
ctx!: Context;
@Inject()
noticeService!: NoticeService;
@Get("/")
async list(@Query() query: any) {
return await this.noticeService.listMy("user", this.currentUserId(), query);
}
// 注意:静态路径必须注册在动态路径 /:id/read 之前
@Get("/unread-count")
async unreadCount() {
return await this.noticeService.unreadCount("user", this.currentUserId());
}
@Put("/read-all")
async markAllRead() {
return await this.noticeService.markAllRead("user", this.currentUserId());
}
@Put("/:id/read")
async markRead(@Param("id") id: string) {
return await this.noticeService.markRead("user", this.currentUserId(), Number(id));
}
private currentUserId(): number {
return Number(this.ctx.state.user?.userId);
}
}