Pārlūkot izejas kodu

优化买卖家中心消息数量获取速度

liusw 7 gadi atpakaļ
vecāks
revīzija
81ab272fd8

+ 18 - 0
src/main/java/com/uas/platform/b2c/common/message/controller/InternalMessageController.java

@@ -3,6 +3,7 @@ package com.uas.platform.b2c.common.message.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.alibaba.fastjson.parser.Feature;
+import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.message.service.InternalMessageService;
 import com.uas.platform.b2c.core.config.MessageConf;
 import com.uas.platform.b2c.core.support.SystemSession;
@@ -10,6 +11,7 @@ import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.model.Status;
 import com.uas.platform.core.util.HttpUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.http.HttpStatus;
 import org.springframework.ui.ModelMap;
@@ -30,6 +32,9 @@ public class InternalMessageController {
 
     private final InternalMessageService internalMessageService;
 
+    @Value("#{message.messagePublicServiceDevUrl}")
+    private String messageServiceUrl;
+
     @Autowired
     public  InternalMessageController(InternalMessageService internalMessageService) {
         this.internalMessageService = internalMessageService;
@@ -47,6 +52,19 @@ public class InternalMessageController {
         return map;
     }
 
+    /**
+     * 获取url
+     */
+    @RequestMapping(value = "/getUrl",method = RequestMethod.GET)
+    public ModelMap getUrl() {
+        ModelMap map = new ModelMap();
+        User user = SystemSession.getUser();
+        map.put("url", messageServiceUrl);
+        map.put("userUU", user.getUserUU());
+        map.put("enUU", user.getEnterprise().getUu());
+        return map;
+    }
+
 
 /*    *//**
      * 分页获取消息 (用户)

+ 4 - 0
src/main/webapp/resources/js/common/query/internalMessage.js

@@ -51,6 +51,10 @@ define([ 'ngResource' ], function() {
             getUnread: {
                 url: 'internalmessage-service/count',
                 method: 'GET'
+            },
+            getUrl: {
+                url: 'internalmessage-service/getUrl',
+                method: 'GET'
             }
         });
     }])

+ 29 - 6
src/main/webapp/resources/js/usercenter/app.js

@@ -713,13 +713,36 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'commo
     /**
      * 卖家中心头部
      */
-    app.controller('UserCenterHeaderCtrl', ['$scope', '$rootScope', 'BaseService', 'InternalMessage', function ($scope, $rootScope, BaseService, InternalMessage) {
+    app.controller('UserCenterHeaderCtrl', ['$scope', '$rootScope', 'BaseService', 'InternalMessage', '$http', function ($scope, $rootScope, BaseService, InternalMessage, $http) {
         $scope.homeUrl = BaseService.getRootPath();
-        InternalMessage.getUnread({isRead: 0}, function (data) {
-            $rootScope.unReadMessCount = data.toRead;
-        }, function (err) {
-            toaster.pop('error', err || '获取未读消息数量失败');
-        })
+        console.info($rootScope.userInfo);
+        InternalMessage.getUrl({}, function(data) {
+            var url = data.url;
+            if (url == "http://218.17.158.219:24000/message") {
+				url = 'http://192.168.253.6:24000/message';
+			}
+            var param = {
+                'receiverUu': data.userUU,
+                'receiverEnuu': data.enUU,
+                'consumerApp': 'MALL',
+                'isRead': 0
+            };
+            $http({
+                method: 'get',
+                dataType: 'json',
+                url: url + '/messages/count',
+                params: param
+            }).success(function (data) {
+                $rootScope.unReadMessCount = data.toRead;
+            }).error(function (response) {
+                toaster.pop('error', err || '获取未读消息数量失败');
+            });
+        });
+        // InternalMessage.getUnread({isRead: 0}, function (data) {
+        //     $rootScope.unReadMessCount = data.toRead;
+        // }, function (err) {
+        //     toaster.pop('error', err || '获取未读消息数量失败');
+        // })
     }]);
 	/**
 	 * 采购单状态

+ 29 - 6
src/main/webapp/resources/js/vendor/app.js

@@ -954,13 +954,36 @@ define([ 'angularAMD', 'ngLocal', 'common/services', 'common/directives', 'commo
 	/**
 	 * 卖家中心头部
 	 */
-	app.controller('VendorCenterHeaderCtrl', ['$scope', '$rootScope', 'BaseService', 'InternalMessage', function ($scope, $rootScope, BaseService, InternalMessage) {
+	app.controller('VendorCenterHeaderCtrl', ['$scope', '$rootScope', 'BaseService', 'InternalMessage', '$http',function ($scope, $rootScope, BaseService, InternalMessage, $http) {
 		$scope.homeUrl = BaseService.getRootPath();
-        InternalMessage.getUnread({isRead: 0}, function (data) {
-            $rootScope.unReadMessCount = data.toRead;
-        }, function (err) {
-            toaster.pop('error', err || '获取未读消息数量失败');
-        })
+		console.info($rootScope.userInfo);
+        InternalMessage.getUrl({}, function(data) {
+            var url = data.url;
+            if (url == "http://218.17.158.219:24000/message") {
+                url = 'http://192.168.253.6:24000/message';
+            }
+            var param = {
+                'receiverUu': data.userUU,
+                'receiverEnuu': data.enUU,
+                'consumerApp': 'MALL',
+                'isRead': 0
+            };
+            $http({
+                method: 'get',
+                dataType: 'json',
+                url: url + '/messages/count',
+                params: param
+            }).success(function (data) {
+                $rootScope.unReadMessCount = data.toRead;
+            }).error(function (response) {
+                toaster.pop('error', err || '获取未读消息数量失败');
+            });
+        });
+        // InternalMessage.getUnread({isRead: 0}, function (data) {
+        //     $rootScope.unReadMessCount = data.toRead;
+        // }, function (err) {
+        //     toaster.pop('error', err || '获取未读消息数量失败');
+        // })
 	}]);
 
 	/**