Quellcode durchsuchen

新增律师端消息未读接口

zhangchen vor 3 Wochen
Ursprung
Commit
70c3124507

+ 22 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/controller/LawyerNoticeController.java

@@ -71,4 +71,26 @@ public class LawyerNoticeController {
         return lawyerNoticeService.getLawyerNoticeList(pageNum, pageSize, receiverId, noticeType);
     }
 
+    /**
+     * 查询接收人是否有未读通知
+     *
+     * @param receiverId 接收人ID,不能为空
+     * @return 是否有未读通知,true-有未读,false-无未读
+     */
+    @GetMapping("/hasUnread")
+    @ApiOperation("查询是否有未读通知")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParam(name = "receiverId", value = "接收人ID", dataType = "String", paramType = "query", required = true)
+    public R<Boolean> hasUnreadNotice(@RequestParam String receiverId) {
+        log.info("LawyerNoticeController.hasUnreadNotice, receiverId={}", receiverId);
+        
+        // 参数校验
+        if (StringUtils.isBlank(receiverId)) {
+            log.warn("接收人ID为空");
+            return R.fail("接收人ID不能为空");
+        }
+        
+        return lawyerNoticeService.hasUnreadNotice(receiverId);
+    }
+
 }

+ 8 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/LawyerNoticeService.java

@@ -24,4 +24,12 @@ public interface LawyerNoticeService extends IService<LifeNotice> {
      */
     R<IPage<LifeNoticeVo>> getLawyerNoticeList(Integer pageNum, Integer pageSize, String receiverId, Integer noticeType);
 
+    /**
+     * 查询接收人是否有未读通知
+     *
+     * @param receiverId 接收人ID,不能为空
+     * @return 是否有未读通知,true-有未读,false-无未读
+     */
+    R<Boolean> hasUnreadNotice(String receiverId);
+
 }

+ 30 - 2
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerNoticeServiceImpl.java

@@ -13,14 +13,12 @@ import org.springframework.stereotype.Service;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LawyerUserViolation;
 import shop.alien.entity.store.LifeNotice;
-import shop.alien.entity.store.LifeUserViolation;
 import shop.alien.entity.store.vo.LifeMessageVo;
 import shop.alien.entity.store.vo.LifeNoticeVo;
 import shop.alien.lawyer.service.LawyerNoticeService;
 import shop.alien.mapper.LawyerUserViolationMapper;
 import shop.alien.mapper.LifeMessageMapper;
 import shop.alien.mapper.LifeNoticeMapper;
-import shop.alien.mapper.LifeUserViolationMapper;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -56,6 +54,11 @@ public class LawyerNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeN
     private static final Integer DELETE_FLAG_NOT_DELETED = 0;
 
     /**
+     * 未读标识:0-未读
+     */
+    private static final Integer IS_READ_UNREAD = 0;
+
+    /**
      * 发送者ID分隔符
      */
     private static final String SENDER_ID_SEPARATOR = "_";
@@ -319,4 +322,29 @@ public class LawyerNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeN
             }
         }
     }
+
+    @Override
+    public R<Boolean> hasUnreadNotice(String receiverId) {
+        log.info("LawyerNoticeServiceImpl.hasUnreadNotice, receiverId={}", receiverId);
+        
+        // 参数校验
+        if (StringUtils.isBlank(receiverId)) {
+            log.warn("接收人ID为空");
+            return R.fail("接收人ID不能为空");
+        }
+        
+        // 构建查询条件:查询未读且未删除的通知,使用LIMIT 1优化性能
+        LambdaQueryWrapper<LifeNotice> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(LifeNotice::getReceiverId, receiverId)
+                .eq(LifeNotice::getIsRead, IS_READ_UNREAD)
+                .eq(LifeNotice::getDeleteFlag, DELETE_FLAG_NOT_DELETED)
+                .last("LIMIT 1");
+        
+        // 使用selectOne判断是否存在,数据库找到一条记录即返回,比selectCount更高效
+        LifeNotice notice = lifeNoticeMapper.selectOne(queryWrapper);
+        boolean hasUnread = notice != null;
+        
+        log.debug("LawyerNoticeServiceImpl.hasUnreadNotice, receiverId={}, hasUnread={}", receiverId, hasUnread);
+        return R.data(hasUnread);
+    }
 }