新增通知规则实体、扫描任务、API与管理界面,重构站内通知支持用户/电工双类型,移除硬编码的证照到期提醒,新增工单派单、电工审核结果等通知触发场景,调整菜单与数据库结构适配新通知体系。
37 lines
996 B
TypeScript
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);
|
|
}
|
|
} |