Browse Source

优化未查找到消息记录也进行更新操作的报错问题

wang-hai-cheng 5 years ago
parent
commit
1acea50272

+ 5 - 0
lift-push/src/main/java/cn/com/ty/lift/push/message/controller/TimeMessageController.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,6 +20,7 @@ import java.util.Collection;
 
 @RestController
 @AllArgsConstructor
+@Slf4j
 @RequestMapping("message")
 public class TimeMessageController {
     private final TimeMessageService timeMessageService;
@@ -69,6 +71,9 @@ public class TimeMessageController {
     @PostMapping("read")
     public RestResponse<Boolean> messages(@RequestBody MessageVo messageVo) {
         Collection<TimeMessage> timeMessages = timeMessageService.listByIds(messageVo.getIds());
+        if (timeMessages.isEmpty()) {
+            return RestResponse.success(true);
+        }
         timeMessages.forEach(timeMessage -> timeMessage.setViewFlag(1));
         return RestResponse.success(timeMessageService.updateBatchById(timeMessages));
     }