Przeglądaj źródła

增加阅读消息接口

wangyc 7 lat temu
rodzic
commit
175526ac96

+ 10 - 0
src/main/java/com/uas/ps/message/api/MessageController.java

@@ -63,4 +63,14 @@ public class MessageController {
     public Map<String, Object> sendMessage(@RequestBody String consumerApp) {
         return messageService.sendMessage(consumerApp);
     }
+
+    /**
+     * 阅读消息
+     * @param cousumer 消息接收者信息
+     * @return
+     */
+    @RequestMapping(value = "/read", method = RequestMethod.POST, produces = "application/json")
+    public Message read(@RequestBody String cousumer) {
+        return messageService.readMessage(cousumer);
+    }
 }

+ 7 - 0
src/main/java/com/uas/ps/message/service/MessageService.java

@@ -36,4 +36,11 @@ public interface MessageService {
      * @return
      */
     Map<String, Object> sendMessage(String consumerApp);
+
+    /**
+     * 阅读消息
+     * @param consumer 消息接收者信息
+     * @return
+     */
+    Message readMessage(String consumer);
 }

+ 35 - 0
src/main/java/com/uas/ps/message/service/impl/MessageServiceImpl.java

@@ -159,6 +159,41 @@ public class MessageServiceImpl implements MessageService {
         }
     }
 
+    @Override
+    public Message readMessage(String consumer) {
+        if (StringUtils.isEmpty(consumer)) {
+            throw new ParameterMissingException("接收人信息为空,无法阅读消息");
+        }
+
+        JSONObject jsonObject = FastjsonUtils.parseObject(consumer);
+
+        // 消息id
+        Object messageId = jsonObject.get("messageId");
+        Object receiverUu = jsonObject.get("receiverUu");
+        Object receiverEnuu = jsonObject.get("receiverEnuu");
+        if (StringUtils.isEmpty(messageId)) {
+            throw new ParameterMissingException("消息id为空,请重新确认消息信息");
+        } else {
+            Message message = messageDao.findOne(Long.valueOf(String.valueOf(messageId)));
+            if (message == null) {
+                throw new IllegalOperatorException("消息不存在,请重新确认消息信息");
+            }
+            if (receiverUu == null || StringUtils.isEmpty(String.valueOf(receiverEnuu)) || receiverEnuu == null
+                || StringUtils.isEmpty(String.valueOf(receiverUu))) {
+                throw new ParameterMissingException("用户信息为空,无法读取消息");
+            }
+            if (!Long.valueOf(String.valueOf(receiverEnuu)).equals(message.getReceiverEnuu())
+                || !Long.valueOf(String.valueOf(receiverUu)).equals(message.getReceiverUu())) {
+                throw new IllegalOperatorException("此消息不属于当前用户,请重新确认后读取");
+            }
+            if (Constant.YES.equals(message.getIsRead())) {
+                throw new IllegalOperatorException("消息已阅读");
+            }
+            message.setIsRead(Constant.YES);
+            return messageDao.save(message);
+        }
+    }
+
     /**
      * jsonObject转换为Message
      * @param jsonObjects jsonObjects