Przeglądaj źródła

新增消息接口

zhangchen 2 miesięcy temu
rodzic
commit
5178dcf615

+ 15 - 2
alien-store/src/main/java/shop/alien/store/controller/LifeNoticeController.java

@@ -51,9 +51,22 @@ public class LifeNoticeController {
         return R.data(lifeNoticeService.getSystemAndOrderNoticeSum(receiverId));
     }
 
+    @GetMapping("/countUnreadByType")
+    @ApiOperation("按通知类型和接收人查询未读消息数量")
+    @ApiOperationSupport(order = 3)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "receiverId", value = "接收人ID", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "noticeType", value = "通知类型 0-系统通知和订单提醒之外 1-系统通知 2-订单提醒", dataType = "Integer", paramType = "query", required = true)
+    })
+    public R<Long> countUnreadByReceiverIdAndNoticeType(@RequestParam String receiverId,
+                                                        @RequestParam Integer noticeType) {
+        log.info("LifeNoticeController.countUnreadByReceiverIdAndNoticeType?receiverId={}, noticeType={}", receiverId, noticeType);
+        return R.data(lifeNoticeService.countUnreadByReceiverIdAndNoticeType(receiverId, noticeType));
+    }
+
     @GetMapping("/deleteNoticeById")
     @ApiOperation("删除通知")
-    @ApiOperationSupport(order = 3)
+    @ApiOperationSupport(order = 4)
     @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query")})
     public R<Boolean> deleteNoticeById(Integer id) {
         log.info("LifeNoticeController.deleteNoticeById?receiverId={}", id);
@@ -65,7 +78,7 @@ public class LifeNoticeController {
 
     @GetMapping("/readNoticeById")
     @ApiOperation("通知已读")
-    @ApiOperationSupport(order = 4)
+    @ApiOperationSupport(order = 5)
     @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query")})
     public R<Boolean> readNoticeById(Integer id) {
         log.info("LifeNoticeController.readNoticeById?receiverId={}", id);

+ 9 - 0
alien-store/src/main/java/shop/alien/store/service/LifeNoticeService.java

@@ -17,4 +17,13 @@ public interface LifeNoticeService extends IService<LifeNotice> {
 
     int readNoticeById(Integer id);
 
+    /**
+     * 根据接收人ID和通知类型查询未读消息数量
+     *
+     * @param receiverId 接收人ID
+     * @param noticeType 通知类型 0-系统通知和订单提醒之外 1-系统通知 2-订单提醒
+     * @return 未读数量
+     */
+    long countUnreadByReceiverIdAndNoticeType(String receiverId, Integer noticeType);
+
 }

+ 9 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeNoticeServiceImpl.java

@@ -171,4 +171,13 @@ public class LifeNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeNot
         wrapper.set(LifeNotice::getIsRead, 1);
         return lifeNoticeMapper.update(null, wrapper);
     }
+
+    @Override
+    public long countUnreadByReceiverIdAndNoticeType(String receiverId, Integer noticeType) {
+        LambdaQueryWrapper<LifeNotice> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(LifeNotice::getReceiverId, receiverId);
+        queryWrapper.eq(LifeNotice::getNoticeType, noticeType);
+        queryWrapper.eq(LifeNotice::getIsRead, 0);
+        return lifeNoticeMapper.selectCount(queryWrapper);
+    }
 }