Browse Source

按企业顺序排序优化2

wangdy 8 years ago
parent
commit
1d881dc4d7
1 changed files with 84 additions and 12 deletions
  1. 84 12
      src/main/java/com/uas/platform/b2c/common/account/model/UserInfo.java

+ 84 - 12
src/main/java/com/uas/platform/b2c/common/account/model/UserInfo.java

@@ -34,26 +34,34 @@ public class UserInfo {
 		}
 		if (!CollectionUtils.isEmpty(user.getEnterprises())) {
 			Enterprise current = user.getEnterprise();
-			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+			List<SimpleEnterpriseInfo> list = new ArrayList<SimpleEnterpriseInfo>();
 			for (Enterprise enterprise : user.getEnterprises()) {
-				Map<String, Object> map = new HashMap<String, Object>();
-				map.put("enName", enterprise.getEnName());
-				map.put("uu", enterprise.getUu());
-				map.put("isVendor",enterprise.getEnMallVendorStatus());
+				SimpleEnterpriseInfo simpleEnterpriseInfo= new SimpleEnterpriseInfo();
+				simpleEnterpriseInfo.setEnName(enterprise.getEnName());
+				simpleEnterpriseInfo.setUu(enterprise.getUu());
+				simpleEnterpriseInfo.setIsVendor(enterprise.getEnMallVendorStatus());
 				if(enterprise.getEnSaasStatus() != null && enterprise.getEnSaasStatus() == Status.ENABLED.value()) {
-					map.put("enSaasUrl", enterprise.getEnSaasUrl());
+					simpleEnterpriseInfo.setEnSaasUrl(enterprise.getEnSaasUrl());
 				}
 				if (enterprise.equals(current)){
-					map.put("current", true);
+					simpleEnterpriseInfo.setCurrent(true);
 				}
 				for (UserLoginTime userLoginTime : user.getUserLoginTimeSet()){
 					if (userLoginTime.getEnUU().equals(enterprise.getUu())){
-						map.put("lastLoginTime" , userLoginTime.getLoginTime());
+						simpleEnterpriseInfo.setLastLoginTime(userLoginTime.getLoginTime());
 					}
 				}
-				list.add(map);
+				list.add(simpleEnterpriseInfo);
 			}
 
+			Collections.sort(list,new Comparator(){
+				@Override
+				public int compare(Object o1, Object o2) {
+					SimpleEnterpriseInfo s1 = (SimpleEnterpriseInfo) o1;
+					SimpleEnterpriseInfo s2 = (SimpleEnterpriseInfo)o2;
+					return s1.getLastLoginTime().compareTo(s2.getLastLoginTime());
+				}
+			});
 			this.enterprises = list;
 		}
 		this.havePayPwd = user.getUserPay()==null || user.getUserPay().equals("") ?false:true;
@@ -114,7 +122,7 @@ public class UserInfo {
 
 	private Short idEnable;
 
-	private List<Map<String, Object>> enterprises;
+	private List<SimpleEnterpriseInfo> enterprises;
 
 	private boolean havePayPwd;
 
@@ -230,11 +238,11 @@ public class UserInfo {
 		this.userLoginTimeSet = userLoginTimeSet;
 	}
 
-	public List<Map<String, Object>> getEnterprises() {
+	public List<SimpleEnterpriseInfo> getEnterprises() {
 		return enterprises;
 	}
 
-	public void setEnterprises(List<Map<String, Object>> enterprises) {
+	public void setEnterprises(List<SimpleEnterpriseInfo> enterprises) {
 		this.enterprises = enterprises;
 	}
 
@@ -247,3 +255,67 @@ public class UserInfo {
 	}
 
 }
+
+/**
+ * 返回给前端的简单企业信息数据
+ */
+class SimpleEnterpriseInfo{
+	String enName;
+	Long uu;
+	Short isVendor;
+	String enSaasUrl;
+	boolean current;
+	Long lastLoginTime;
+
+	public SimpleEnterpriseInfo(){
+		this.setLastLoginTime(0L);
+	}
+
+	public String getEnName() {
+		return enName;
+	}
+
+	public void setEnName(String enName) {
+		this.enName = enName;
+	}
+
+	public Long getUu() {
+		return uu;
+	}
+
+	public void setUu(Long uu) {
+		this.uu = uu;
+	}
+
+	public Short getIsVendor() {
+		return isVendor;
+	}
+
+	public void setIsVendor(Short isVendor) {
+		this.isVendor = isVendor;
+	}
+
+	public String getEnSaasUrl() {
+		return enSaasUrl;
+	}
+
+	public void setEnSaasUrl(String enSaasUrl) {
+		this.enSaasUrl = enSaasUrl;
+	}
+
+	public boolean isCurrent() {
+		return current;
+	}
+
+	public void setCurrent(boolean current) {
+		this.current = current;
+	}
+
+	public Long getLastLoginTime() {
+		return lastLoginTime;
+	}
+
+	public void setLastLoginTime(Long lastLoginTime) {
+		this.lastLoginTime = lastLoginTime;
+	}
+}