package com.panzhihua.sangeshenbian.api; import com.baomidou.mybatisplus.core.metadata.IPage; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.interfaces.OperLog; import com.panzhihua.common.model.vos.R; import com.panzhihua.sangeshenbian.model.MessageNotification; import com.panzhihua.sangeshenbian.model.SystemUser; import com.panzhihua.sangeshenbian.service.IMessageNotificationService; import com.panzhihua.sangeshenbian.service.ISystemUserService; import com.panzhihua.sangeshenbian.warpper.MessageNotificationList; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * @author zhibing.pu * @Date 2025/2/23 3:05 */ @Api @RestController @RequestMapping("/messageNotification") public class MessageNotificationController extends BaseController { @Resource private IMessageNotificationService messageNotificationService; @Resource private ISystemUserService systemUserService; @GetMapping("/list") @ApiOperation(value = "获取消息通知列表", tags = {"三个身边后台-消息通知"}) @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取消息通知列表") public R> list(MessageNotificationList query) { Integer id = this.getLoginUserInfoSanGeShenBian().getId(); SystemUser systemUser = systemUserService.getById(id); switch (systemUser.getAccountLevel()){ case 1: query.setUserId("510400"); break; case 2: query.setUserId(systemUser.getDistrictsCode()); break; case 3: query.setUserId(systemUser.getStreetId().toString()); break; case 4: query.setUserId(systemUser.getCommunityId().toString()); break; case 5: query.setUserId(id.toString()); break; } query.setUndertakerType(systemUser.getAccountLevel()); IPage page = messageNotificationService.list(query); return R.ok(page); } @PutMapping("/read/{id}") @ApiOperation(value = "标记为已读", tags = {"三个身边后台-消息通知"}) @OperLog(operModul = "三个身边后台",operType = 2, businessType = "标记为已读") public R read(@PathVariable("id") Integer id) { MessageNotification messageNotification = messageNotificationService.getById(id); if(messageNotification.getReadStatus()==1){ return R.fail("不能重复操作"); } messageNotification.setReadStatus(1); messageNotificationService.updateById(messageNotification); return R.ok(); } @GetMapping("/unreadCount") @ApiOperation(value = "获取未读数量", tags = {"三个身边后台-消息通知"}) @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取未读数量") public R unreadCount() { Integer id = this.getLoginUserInfoSanGeShenBian().getId(); SystemUser systemUser = systemUserService.getById(id); String userId = null; switch (systemUser.getAccountLevel()){ case 1: userId = "510400"; break; case 2: userId = systemUser.getDistrictsCode(); break; case 3: userId = systemUser.getStreetId().toString(); break; case 4: userId = systemUser.getCommunityId().toString(); break; case 5: userId = id.toString(); break; } Integer count = messageNotificationService.lambdaQuery() .eq(MessageNotification::getReadStatus, 0) .eq(MessageNotification::getUndertakerType, systemUser.getAccountLevel()) .eq(MessageNotification::getUndertakerUserId, userId) .count(); return R.ok(count); } }