Browse Source

取消isSys忽略JSON注解

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@1242 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
suntg 10 years ago
parent
commit
8e77a38c85
1 changed files with 16 additions and 2 deletions
  1. 16 2
      src/main/java/com/uas/platform/b2b/model/User.java

+ 16 - 2
src/main/java/com/uas/platform/b2b/model/User.java

@@ -26,8 +26,10 @@ import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
 import org.hibernate.annotations.NotFound;
 import org.hibernate.annotations.NotFoundAction;
+import org.springframework.util.CollectionUtils;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.core.model.Constant;
 
 @Entity
@@ -241,6 +243,20 @@ public class User implements Serializable {
 		if (this.enterprise == null)
 			setCurrentEnterprise();
 	}
+	
+	public void setCurrentEnterprise(Enterprise enterprise) {
+		if(!CollectionUtils.isEmpty(SystemSession.getUser().getEnterprises())) {
+			Set<Enterprise> enterprises = new HashSet<Enterprise>();
+			for (Enterprise en : SystemSession.getUser().getEnterprises()) {
+				if (en.equals(enterprise)) {
+					enterprises.add(enterprise);
+				}
+				enterprises.add(en);
+			}
+			SystemSession.getUser().setEnterprises(enterprises);
+			SystemSession.getUser().setCurrentEnterprise(SystemSession.getUser().getEnterprise().getUu());
+		}
+	}
 
 	public Set<Role> getRoles() {
 		return roles;
@@ -268,8 +284,6 @@ public class User implements Serializable {
 		}
 	}
 
-	@JsonIgnore
-	@JSONField(serialize = false)
 	public boolean isSys() {
 		return getIssys() != null && getIssys() == Constant.YES;
 	}