package com.iailab.module.system.controller.admin.notify; import com.iailab.framework.apilog.core.annotation.ApiAccessLog; import com.iailab.framework.common.enums.UserTypeEnum; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO; import com.iailab.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import com.iailab.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; import com.iailab.module.system.dal.dataobject.notify.NotifyMessageDO; import com.iailab.module.system.service.notify.NotifyMessageService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; import static com.iailab.framework.common.pojo.CommonResult.success; import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - 我的站内信") @RestController @RequestMapping("/system/notify-message") @Validated public class NotifyMessageController { @Resource private NotifyMessageService notifyMessageService; // ========== 管理所有的站内信 ========== @GetMapping("/get") @Operation(summary = "获得站内信") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult getNotifyMessage(@RequestParam("id") Long id) { NotifyMessageDO message = notifyMessageService.getNotifyMessage(id); return success(BeanUtils.toBean(message, NotifyMessageRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得站内信分页") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class)); } // ========== 查看自己的站内信 ========== @GetMapping("/my-page") @Operation(summary = "获得我的站内信分页") public CommonResult> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) { PageResult pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class)); } @PutMapping("/update-read") @Operation(summary = "标记站内信为已读") @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") public CommonResult updateNotifyMessageRead(@RequestParam("ids") List ids) { notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(Boolean.TRUE); } @PutMapping("/update-all-read") @Operation(summary = "标记所有站内信为已读") public CommonResult updateAllNotifyMessageRead() { notifyMessageService.updateAllNotifyMessageRead(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(Boolean.TRUE); } @GetMapping("/get-unread-list") @Operation(summary = "获取当前用户的最新站内信列表,默认 10 条") @Parameter(name = "size", description = "10") public CommonResult> getUnreadNotifyMessageList( @RequestParam(name = "size", defaultValue = "10") Integer size) { List list = notifyMessageService.getUnreadNotifyMessageList( getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size); return success(BeanUtils.toBean(list, NotifyMessageRespVO.class)); } @GetMapping("/get-unread-count") @Operation(summary = "获得当前用户的未读站内信数量") @ApiAccessLog(enable = false) // 由于前端会不断轮询该接口,记录日志没有意义 public CommonResult getUnreadNotifyMessageCount() { return success(notifyMessageService.getUnreadNotifyMessageCount( getLoginUserId(), UserTypeEnum.ADMIN.getValue())); } }