Kaynağa Gözat

首页消息增加阅读状态

hejq 8 yıl önce
ebeveyn
işleme
b53d9b6657

+ 14 - 2
src/main/java/com/uas/platform/b2b/controller/NoticeController.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2b.controller;
 
+import com.uas.platform.b2b.support.SystemSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort.Direction;
@@ -35,10 +36,10 @@ public class NoticeController {
 	 */
 	@RequestMapping(method = RequestMethod.GET)
 	@ResponseBody
-	public Page<Notice> getNotices(PageParams params) {
+	public Page<Notice> getNotices(PageParams params, Long useruu) {
 		PageInfo info = new PageInfo(params);
 		info.sorting("date", Direction.DESC);
-		return noticeService.findAllByPageInfo(info);
+        return noticeService.findAllByPageInfo(info, useruu);
 	}
 	
 	/**
@@ -51,4 +52,15 @@ public class NoticeController {
 		return noticeService.findNoticeBody(noticeId);
 	}
 
+    /**
+     * 设置公告的阅读状态
+     *
+     * @param id
+     */
+	@RequestMapping(value = "/setReadStatus", method = RequestMethod.POST)
+    @ResponseBody
+    public void setReadStauts(Long id, Long useruu) {
+        noticeService.setReadStatus(id, useruu);
+    }
+
 }

+ 9 - 0
src/main/java/com/uas/platform/b2b/dao/NoticeDao.java

@@ -29,5 +29,14 @@ public interface NoticeDao extends JpaSpecificationExecutor<Notice>, JpaReposito
 	 */
 	@Procedure(procedureName = "PURC$ERP_SEND_EMAIL")
 	void saveErpLog(String username,String userip, Long enuu, Long useruu, String title, String message);
+
+    /**
+     * 通过公告id和个人uu设置公告的阅读状态
+     *
+     * @param id
+     * @param useruu
+     */
+	@Procedure(procedureName = "notice_readstatus")
+	void setReadStatus(Long id, Long useruu);
 	
 }

+ 16 - 9
src/main/java/com/uas/platform/b2b/model/Notice.java

@@ -2,14 +2,7 @@ package com.uas.platform.b2b.model;
 
 import java.util.Date;
 
-import javax.persistence.Cacheable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
@@ -49,7 +42,13 @@ public class Notice {
 	 */
 	@Column(name = "no_writer")
 	private String writer;
-	
+
+    /**
+     * 当前人的阅读状态
+     */
+	@Transient
+    private Short readStatus;
+
 	public Long getId() {
 		return id;
 	}
@@ -81,4 +80,12 @@ public class Notice {
 	public void setWriter(String writer) {
 		this.writer = writer;
 	}
+
+    public Short getReadStatus() {
+        return readStatus;
+    }
+
+    public void setReadStatus(Short readStatus) {
+        this.readStatus = readStatus;
+    }
 }

+ 8 - 2
src/main/java/com/uas/platform/b2b/service/NoticeService.java

@@ -27,7 +27,7 @@ public interface NoticeService {
 	 * @param pageInfo
 	 * @return
 	 */
-	public Page<Notice> findAllByPageInfo(PageInfo pageInfo);
+	public Page<Notice> findAllByPageInfo(PageInfo pageInfo, Long useruu);
 	
 	/**
 	 * 公告ID查找公告内容
@@ -36,5 +36,11 @@ public interface NoticeService {
 	 * @return
 	 */
 	public NoticeBody findNoticeBody(Long noticeId);
-	
+
+    /**
+     * 通过id设置公告阅读状态
+     *
+     * @param id
+     */
+    void setReadStatus(Long id, Long useruu);
 }

+ 21 - 5
src/main/java/com/uas/platform/b2b/service/impl/NoticeServiceImpl.java

@@ -7,6 +7,9 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
+import com.uas.platform.b2b.dao.CommonDao;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.core.model.Constant;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
@@ -30,15 +33,26 @@ public class NoticeServiceImpl implements NoticeService {
 	@Autowired
 	private NoticeBodyDao noticeBodyDao;
 
+	@Autowired
+    private CommonDao commonDao;
+
 	@Override
-	public Page<Notice> findAllByPageInfo(final PageInfo pageInfo) {
-		return noticeDao.findAll(new Specification<Notice>() {
+	public Page<Notice> findAllByPageInfo(final PageInfo pageInfo, final Long useruu) {
+        Page<Notice> notices =  noticeDao.findAll(new Specification<Notice>() {
 
 			public Predicate toPredicate(Root<Notice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
 				query.where(pageInfo.getPredicates(root, query, builder));
 				return null;
 			}
 		}, pageInfo);
+        if(!CollectionUtils.isEmpty(notices.getContent())) {
+            for(Notice notice : notices.getContent()) {
+                String sql = "select count(1) from notice$readstatus where no_id = " + notice.getId() + " and no_useruu = " + useruu;
+                Integer count = commonDao.getJdbcTemplate().queryForObject(sql, Integer.class);
+                notice.setReadStatus(count > 0 ? Constant.YES : null);
+            }
+        }
+        return notices;
 	}
 
 	@Override
@@ -49,7 +63,7 @@ public class NoticeServiceImpl implements NoticeService {
 		return null;
 	}
 
-	@Override
+    @Override
 	public Notice save(NoticeBody noticeBody) {
 		noticeBody = noticeBodyDao.save(noticeBody);
 		return noticeBody.getNotice();
@@ -66,7 +80,9 @@ public class NoticeServiceImpl implements NoticeService {
 			throw new IllegalOperatorException("没有找到您要删除的公告");
 		}
 	}
-	
-	
 
+    @Override
+    public void setReadStatus(Long id, Long useruu) {
+        noticeDao.setReadStatus(id, useruu);
+    }
 }

+ 8 - 2
src/main/webapp/resources/js/common/services.js

@@ -175,8 +175,8 @@ define(['angular', 'toaster', 'big'], function(angular, big) {
                     success.call(null, data);
                 });
             },
-            getNotice: function(count, success) {
-                var request = $http.get(rootPath + '/public/notice?page=1&count=' + count); // NoticeController.java
+            getNotice: function(count, useruu, success) {
+                var request = $http.get(rootPath + '/public/notice?page=1&count=' + count + '&useruu=' + useruu); // NoticeController.java
                 request.success(function(data) {
                     success.call(null, data.content);
                 });
@@ -192,6 +192,12 @@ define(['angular', 'toaster', 'big'], function(angular, big) {
                 request.success(function(data) {
                     success.call(null, data);
                 });
+            },
+            setNoticeStatusAfterRead: function (id, useruu, success) {
+                var request = $http.post(rootPath + '/public/notice/setReadStatus?id=' + id + '&useruu=' + useruu);
+                request.success(function() {
+                    success.call(null);
+                });
             }
         };
     }]).factory('SerializerUtil', function() {

+ 17 - 3
src/main/webapp/resources/js/index/app.js

@@ -1820,9 +1820,23 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
             };
         });
     }]);
-    app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
-        SnapshotService.getNotice(7, function (data) {	//5表示首页显示的公告条数
-            $scope.notices = data;
+    app.controller('NoticeCtrl', ['$scope', 'SnapshotService', 'AuthenticationService', function ($scope, SnapshotService, AuthenticationService) {
+        AuthenticationService.getAuthentication().success(function (data) {
+            $scope.loading = false;
+            $scope.useruu = data.userUU;
+
+            SnapshotService.getNotice(7, $scope.useruu, function (data) {	//5表示首页显示的公告条数
+                $scope.notices = data;
+            });
+
+            /**
+             * 设置单据阅读状态
+             * @param id
+             */
+            $scope.setReadStatus = function(id) {
+                SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
+            }
+            
         });
 
         $scope.dateTime = new Date();

+ 25 - 8
src/main/webapp/resources/js/public/app.js

@@ -20,7 +20,7 @@ define([ 'toaster', 'ngTable', 'common/services', 'service/Info', 'ui.router', '
 			controller: 'ServeCtrl'
 		});
 	}]);
-	app.controller('NoticeCtrl', ['$scope', 'ngTableParams', 'Notice', 'BaseService', function($scope, ngTableParams, Notice, BaseService){
+	app.controller('NoticeCtrl', ['$scope', 'ngTableParams', 'Notice', 'BaseService', 'AuthenticationService', function($scope, ngTableParams, Notice, BaseService, AuthenticationService){
 		$scope.tableParams = new ngTableParams({
 			page : 1,
 			count : 20,
@@ -41,14 +41,31 @@ define([ 'toaster', 'ngTable', 'common/services', 'service/Info', 'ui.router', '
 				});
 			}
 		});
+
+        AuthenticationService.getAuthentication().success(function (data) {
+            $scope.loading = false;
+            $scope.useruu = data.userUU;
+            /**
+             * 设置单据阅读状态
+             * @param id
+             */
+            $scope.setReadStatus = function (id) {
+                SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
+            }
+        });
 	}]);
-	app.controller('NoticeDetailCtrl', ['$scope', 'Notice', '$stateParams','SnapshotService', function($scope, Notice, $stateParams,SnapshotService){
-		Notice.get({id: $stateParams.id}, function(data){
-			$scope.noticeBody = data;
-		});
-		SnapshotService.getNotice(5, function(data){
-			$scope.notices = data;
-		});
+	app.controller('NoticeDetailCtrl', ['$scope', 'Notice', '$stateParams','SnapshotService', 'AuthenticationService', function($scope, Notice, $stateParams,SnapshotService, AuthenticationService){
+        AuthenticationService.getAuthentication().success(function (data) {
+            $scope.loading = false;
+            $scope.useruu = data.userUU;
+            Notice.get({id: $stateParams.id}, function(data){
+                $scope.noticeBody = data;
+            });
+            SnapshotService.getNotice(5, $scope.useruu, function(data){
+                $scope.notices = data;
+            });
+        });
+
 	}]);
 	return app;
 });

+ 2 - 3
src/main/webapp/resources/tpl/index/home/left.html

@@ -131,9 +131,8 @@
 		</div>
 		<div class="pane-body">
 			<ul class="list-unstyled detail details">
-				<li ng-repeat="notice in notices"><a
-					href="public#/notice/{{notice.id}}" class=""
-					ng-bind="::notice.title" target="_blank"></a></li>
+				<li ng-repeat="notice in notices">
+                    <a ng-click="setReadStatus(notice.id)" href="public#/notice/{{notice.id}}" class="" ng-bind="::notice.title" target="_blank"></a></li>
 			</ul>
 		</div>
 	</div>

+ 1 - 1
src/main/webapp/resources/tpl/public/info/notice.html

@@ -41,7 +41,7 @@
 			<table class="table table-default table-striped table-hover"
 				ng-table="tableParams">
 				<tr ng-repeat="notice in $data track by notice.id">
-					<td><a ui-sref="notice_detail({id:notice.id})" ng-bind="::notice.title" target="_blank"></a></td>
+					<td><a ng-click="setReadStatus(notice.id)" ui-sref="notice_detail({id:notice.id})" ng-bind="::notice.title" target="_blank"></a></td>
 					<td class="text-center text-muted" ng-bind="::notice.date | date:'yyyy-MM-dd'" width="100"></td>
 				</tr>
 			</table>