Browse Source

看板与资源点绑定;看板默认切换频率为10s

sunyj 8 years ago
parent
commit
a4436df914

+ 13 - 0
kanban-auth/src/main/java/com/uas/kanban/support/SystemSession.java

@@ -21,6 +21,19 @@ public class SystemSession {
 		return local.get();
 	}
 
+	/**
+	 * @return 登录信息
+	 * @throws IllegalStateException
+	 *             未登录
+	 */
+	public static ResourcePoint checkResourcePoint() throws IllegalStateException {
+		ResourcePoint resourcePoint = getResourcePoint();
+		if (resourcePoint == null) {
+			throw new IllegalStateException("未登陆");
+		}
+		return resourcePoint;
+	}
+
 	public static void clear() {
 		local.remove();
 	}

+ 12 - 1
kanban-common/src/main/java/com/uas/kanban/base/BaseDao.java

@@ -71,7 +71,18 @@ public class BaseDao<T extends BaseEntity> {
 	 * @return the query
 	 */
 	public Query<T> createQuery() {
-		return datastore.createQuery(entityClass);
+		Query<T> query = datastore.createQuery(entityClass);
+		globalFilter(query);
+		return query;
+	}
+
+	/**
+	 * 全局过滤,如有需要,可重写该方法
+	 * 
+	 * @param query
+	 */
+	protected void globalFilter(Query<T> query) {
+		// Default do nothing
 	}
 
 	/**

+ 10 - 0
kanban-console/src/main/java/com/uas/kanban/dao/KanbanDao.java

@@ -1,9 +1,12 @@
 package com.uas.kanban.dao;
 
+import org.mongodb.morphia.query.Query;
 import org.springframework.stereotype.Component;
 
 import com.uas.kanban.base.BaseDao;
 import com.uas.kanban.model.Kanban;
+import com.uas.kanban.model.ResourcePoint;
+import com.uas.kanban.support.SystemSession;
 
 /**
  * 看板
@@ -14,4 +17,11 @@ import com.uas.kanban.model.Kanban;
 @Component
 public class KanbanDao extends BaseDao<Kanban> {
 
+	@Override
+	protected void globalFilter(Query<Kanban> query) {
+		ResourcePoint resourcePoint = SystemSession.checkResourcePoint();
+		// 根据资源点过滤
+		query.field("resourcePointCode").equal(resourcePoint.getCode());
+	}
+
 }

+ 31 - 3
kanban-console/src/main/java/com/uas/kanban/model/Kanban.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
+import com.uas.kanban.support.SystemSession;
 
 /**
  * 看板
@@ -15,6 +16,17 @@ public class Kanban extends BaseEntity {
 
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * 默认切换频率为 10 s
+	 */
+	public static final double DEFAULT_SWITCH_FREQUENCY = 10;
+
+	/**
+	 * 资源点 code
+	 */
+	@FieldProperty(nullable = false)
+	private String resourcePointCode;
+
 	/**
 	 * 看板名称
 	 */
@@ -43,6 +55,21 @@ public class Kanban extends BaseEntity {
 	 */
 	private String iconCls;
 
+	@Override
+	public void init() {
+		ResourcePoint resourcePoint = SystemSession.checkResourcePoint();
+		resourcePointCode = resourcePoint.getCode();
+		super.init();
+	}
+
+	public String getResourcePointCode() {
+		return resourcePointCode;
+	}
+
+	public void setResourcePointCode(String resourcePointCode) {
+		this.resourcePointCode = resourcePointCode;
+	}
+
 	public String getName() {
 		return name;
 	}
@@ -85,9 +112,10 @@ public class Kanban extends BaseEntity {
 
 	@Override
 	public String toString() {
-		return "Kanban [name=" + name + ", templateCodes=" + templateCodes + ", display=" + display
-				+ ", switchFrequency=" + switchFrequency + ", iconCls=" + iconCls + ", id=" + id + ", createTime="
-				+ createTime + ", lastModified=" + lastModified + ", version=" + version + ", code=" + code + "]";
+		return "Kanban [resourcePointCode=" + resourcePointCode + ", name=" + name + ", templateCodes=" + templateCodes
+				+ ", display=" + display + ", switchFrequency=" + switchFrequency + ", iconCls=" + iconCls + ", id="
+				+ id + ", createTime=" + createTime + ", lastModified=" + lastModified + ", version=" + version
+				+ ", code=" + code + "]";
 	}
 
 	/**

+ 1 - 1
kanban-console/src/main/java/com/uas/kanban/service/impl/KanbanServiceImpl.java

@@ -93,7 +93,7 @@ public class KanbanServiceImpl extends BaseService<Kanban> {
 			switch (display) {
 			case AutoSwitch:
 				if (kanban.getSwitchFrequency() == null) {
-					throw new IllegalArgumentException("展示方式为“自动切换”时,请指定切换频率(秒)");
+					kanban.setSwitchFrequency(Kanban.DEFAULT_SWITCH_FREQUENCY);
 				}
 				break;
 			case SplitScreen: