Эх сурвалжийг харах

修改阅读消息返回类型

wangyc 7 жил өмнө
parent
commit
7c23fdc061

+ 2 - 1
src/main/java/com/uas/ps/message/api/MessageController.java

@@ -6,6 +6,7 @@ import com.uas.ps.message.domain.Message;
 import com.uas.ps.message.service.MessageService;
 import com.uas.ps.message.service.MessageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
+import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -89,7 +90,7 @@ public class MessageController {
      */
      */
     @HttpLog
     @HttpLog
     @RequestMapping(value = "/read", method = RequestMethod.POST, produces = "application/json")
     @RequestMapping(value = "/read", method = RequestMethod.POST, produces = "application/json")
-    public List<Message> read(@RequestBody String cousumer) {
+    public ModelMap read(@RequestBody String cousumer) {
         return messageService.readMessage(cousumer);
         return messageService.readMessage(cousumer);
     }
     }
 }
 }

+ 2 - 1
src/main/java/com/uas/ps/message/service/MessageService.java

@@ -5,6 +5,7 @@ import com.uas.ps.message.domain.Message;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
+import org.springframework.ui.ModelMap;
 
 
 /**
 /**
  * Created by wangyc on 2018/1/13.
  * Created by wangyc on 2018/1/13.
@@ -54,5 +55,5 @@ public interface MessageService {
      * @param consumer 消息接收者信息
      * @param consumer 消息接收者信息
      * @return
      * @return
      */
      */
-    List<Message> readMessage(String consumer);
+    ModelMap readMessage(String consumer);
 }
 }

+ 24 - 10
src/main/java/com/uas/ps/message/service/impl/MessageServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.ps.message.service.impl;
 package com.uas.ps.message.service.impl;
 
 
+import com.alibaba.druid.stat.TableStat.Mode;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.account.entity.User;
 import com.uas.account.entity.User;
 import com.uas.account.entity.UserView;
 import com.uas.account.entity.UserView;
@@ -44,6 +45,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 
 
@@ -198,7 +200,9 @@ public class MessageServiceImpl implements MessageService {
     }
     }
 
 
     @Override
     @Override
-    public List<Message> readMessage(String consumer) {
+    public ModelMap readMessage(String consumer) {
+        ModelMap map = new ModelMap();
+        map.put("success", "false");
         if (StringUtils.isEmpty(consumer)) {
         if (StringUtils.isEmpty(consumer)) {
             throw new ParameterMissingException("接收人信息为空,无法阅读消息");
             throw new ParameterMissingException("接收人信息为空,无法阅读消息");
         }
         }
@@ -211,41 +215,51 @@ public class MessageServiceImpl implements MessageService {
         Object receiverEnuu = jsonObject.get("receiverEnuu");
         Object receiverEnuu = jsonObject.get("receiverEnuu");
         Object consumerApp = jsonObject.get("consumerApp");
         Object consumerApp = jsonObject.get("consumerApp");
         if (StringUtils.isEmpty(messageId)) {
         if (StringUtils.isEmpty(messageId)) {
-            throw new ParameterMissingException("消息id为空,请重新确认消息信息");
+            map.put("data", "消息id为空,请重新确认消息信息");
+            return map;
         } else {
         } else {
             String[] messageIds = String.valueOf(messageId).split(SplitChar.COMMA);
             String[] messageIds = String.valueOf(messageId).split(SplitChar.COMMA);
             List<Message> messages = new ArrayList<>();
             List<Message> messages = new ArrayList<>();
 
 
             for (String id : messageIds) {
             for (String id : messageIds) {
-                Message message = messageDao.findOne(Long.valueOf(String.valueOf(messageId)));
+                Message message = messageDao.findOne(Long.valueOf(String.valueOf(id)));
                 if (message == null) {
                 if (message == null) {
-                    throw new IllegalOperatorException("消息不存在,请重新确认消息信息");
+                    map.put("data", "消息不存在,请重新确认消息信息");
+                    return map;
                 }
                 }
                 if (receiverUu == null || StringUtils.isEmpty(String.valueOf(receiverEnuu)) || receiverEnuu == null
                 if (receiverUu == null || StringUtils.isEmpty(String.valueOf(receiverEnuu)) || receiverEnuu == null
                     || StringUtils.isEmpty(String.valueOf(receiverUu))
                     || StringUtils.isEmpty(String.valueOf(receiverUu))
                     || StringUtils.isEmpty(String.valueOf(consumerApp))) {
                     || StringUtils.isEmpty(String.valueOf(consumerApp))) {
-                    throw new ParameterMissingException("用户信息为空,无法读取消息");
+                    map.put("data", "用户信息为空,无法读取消息");
+                    return map;
                 }
                 }
                 if (!Long.valueOf(String.valueOf(receiverEnuu)).equals(message.getReceiverEnuu())
                 if (!Long.valueOf(String.valueOf(receiverEnuu)).equals(message.getReceiverEnuu())
                     || !Long.valueOf(String.valueOf(receiverUu)).equals(message.getReceiverUu())) {
                     || !Long.valueOf(String.valueOf(receiverUu)).equals(message.getReceiverUu())) {
-                    throw new IllegalOperatorException("此消息不属于当前用户,请重新确认后读取");
+                    map.put("data", "此消息不属于当前用户,请重新确认后读取");
+                    return map;
                 }
                 }
                 if (Constant.YES.equals(message.getIsRead())) {
                 if (Constant.YES.equals(message.getIsRead())) {
-                    throw new IllegalOperatorException("消息已阅读");
+                    map.put("data", "消息已阅读");
+                    return map;
                 }
                 }
                 App app = appDao.findByName(String.valueOf(consumerApp));
                 App app = appDao.findByName(String.valueOf(consumerApp));
                 if (app == null) {
                 if (app == null) {
-                    throw new IllegalOperatorException("消费应用不存在,请重新确认用户信息");
+                    map.put("data", "消费应用不存在,请重新确认用户信息");
+                    return map;
                 }
                 }
                 if (!message.getConsumerApp().contains(app)) {
                 if (!message.getConsumerApp().contains(app)) {
-                    throw new IllegalOperatorException("消息不属于当前应用");
+                    map.put("data", "消息不属于当前应用");
+                    return map;
                 }
                 }
 
 
                 message.setIsRead(Constant.YES);
                 message.setIsRead(Constant.YES);
                 messages.add(message);
                 messages.add(message);
             }
             }
 
 
-            return messageDao.save(messages);
+            messages = messageDao.save(messages);
+            map.put("success", "success");
+            map.put("data", FastjsonUtils.toJson(messages));
+            return map;
         }
         }
     }
     }