瀏覽代碼

保存用户信息时,判断与企业的关联关系是否已存在

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@4325 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
yingp 10 年之前
父節點
當前提交
37eabb2902

+ 10 - 7
src/main/java/com/uas/platform/b2b/manage/model/AccountInfo.java

@@ -29,7 +29,7 @@ public class AccountInfo {
 	 * 密码(密文)
 	 */
 	private String password;
-	
+
 	private Long userIMId;
 
 	public Long getUserIMId() {
@@ -100,7 +100,7 @@ public class AccountInfo {
 		this.userUU = user.getUserUU();
 		this.userIMId = user.getUserIMId();
 	}
-	
+
 	public AccountInfo(UserBaseInfo user, long enUU) {
 		this.email = user.getUserEmail();
 		this.enUU = enUU;
@@ -119,11 +119,14 @@ public class AccountInfo {
 		user.setUserTel(this.tel);
 		user.setUserPwd(this.password);
 		user.setUserIMId(this.userIMId);
-		Enterprise enterprise = new Enterprise();
-		enterprise.setUu(this.enUU);
-		Set<Enterprise> enterprises = new HashSet<Enterprise>();
-		enterprises.add(enterprise);
-		user.setEnterprises(enterprises);
+		if (this.enUU != null) {
+			Enterprise enterprise = new Enterprise();
+			enterprise.setUu(this.enUU);
+			Set<Enterprise> enterprises = new HashSet<Enterprise>();
+			enterprises.add(enterprise);
+			user.setEnterprises(enterprises);
+			user.setEnterprise(enterprise);
+		}
 		return user;
 	}
 

+ 19 - 0
src/main/java/com/uas/platform/b2b/manage/service/impl/UserServiceImpl.java

@@ -1,9 +1,11 @@
 package com.uas.platform.b2b.manage.service.impl;
 
+import java.util.HashSet;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import com.uas.platform.b2b.dao.EnterpriseDao;
@@ -47,6 +49,23 @@ public class UserServiceImpl implements UserService {
 				}
 				oldUser.setUserTel(user.getUserTel());
 			}
+			// 添加个人-企业绑定关系
+			if (user.getEnterprise() != null) {
+				boolean bindEn = false;
+				if (!CollectionUtils.isEmpty(oldUser.getEnterprises())) {
+					for (Enterprise en : oldUser.getEnterprises()) {
+						if (en.getUu().equals(user.getEnterprise().getUu())) {
+							bindEn = true;
+							break;
+						}
+					}
+				} else {
+					oldUser.setEnterprises(new HashSet<Enterprise>());
+				}
+				if (!bindEn) {
+					oldUser.getEnterprises().add(user.getEnterprise());
+				}
+			}
 			user = userDao.save(oldUser);
 		} else {// 新增
 			if (StringUtils.hasText(user.getUserTel())) {