Browse Source

客户管理批量上传规则

wanghui 8 years ago
parent
commit
e0baebf8f6

+ 23 - 6
src/main/java/com/goafanti/customer/bo/CustomerExcelBo.java

@@ -1,5 +1,7 @@
 package com.goafanti.customer.bo;
 
+import com.goafanti.common.constant.AFTConstants;
+
 public class CustomerExcelBo {
 	/** 营销员ID **/
 	private String aid;
@@ -25,6 +27,8 @@ public class CustomerExcelBo {
 	private String mobile;
 	/** 行号 **/
 	private int rowNumber;
+	/** 是否新建 **/
+	private boolean newData;
 	
 	public String getAid() {
 		return aid;
@@ -98,19 +102,32 @@ public class CustomerExcelBo {
 	public void setRowNumber(int rowNumber) {
 		this.rowNumber = rowNumber;
 	}
-	
+	public boolean isNewData() {
+		return newData;
+	}
+	public void setNewData(boolean newData) {
+		this.newData = newData;
+	}
 	@Override
 	public boolean equals(Object obj) {
 		if(!(obj instanceof CustomerExcelBo)) return false;
 		CustomerExcelBo bo = (CustomerExcelBo)obj;
-		if(this.identifyName.equals(bo.getIdentifyName()) && this.businessGlossoryId.equals(bo.getBusinessGlossoryId()))
-			return true;
-		else 
-			return false;
+		if(!this.customerType.equals(bo.getCustomerType())) return false;
+		if(AFTConstants.USER_TYPE_PERSONAL.equals(this.customerType)){
+			if(this.mobile.equals(bo.getMobile()) && this.businessGlossoryId.equals(bo.getBusinessGlossoryId()))
+				return true;
+		}else if(AFTConstants.USER_TYPE_ORGANIZATION.equals(this.customerType)){
+			if(this.identifyName.equals(bo.getIdentifyName()) && this.businessGlossoryId.equals(bo.getBusinessGlossoryId()))
+				return true;
+		}
+		return false;
 	}
 	@Override
 	public int hashCode() {
-		return (this.identifyName+";"+this.businessGlossoryId).hashCode();
+		if(AFTConstants.USER_TYPE_PERSONAL.equals(this.customerType))
+			return (this.mobile+";"+this.mobile).hashCode();
+		else
+			return (this.identifyName+";"+this.businessGlossoryId).hashCode();
 	}
 	
 }

+ 8 - 2
src/main/java/com/goafanti/customer/controller/CustomerApiController.java

@@ -402,13 +402,19 @@ public class CustomerApiController extends BaseApiController{
 					res.getError().add(new Error(errorMessage));
 					return res;
 				}
-				Set<Integer> existRows = new TreeSet<Integer>();
-				customerService.checkCustomer(boSet,existRows);
+				Set<Integer> existRows = new TreeSet<Integer>(); //数据库已存在
+				Set<Integer> filterRows = new TreeSet<Integer>(); //过滤提示
+				customerService.checkCustomer(boSet,existRows,filterRows);
 				if(existRows.size()>0){
 					errorMessage = StringUtils.join(existRows.toArray(),",")+ " 行客户业务已存在;";
 					res.getError().add(new Error(errorMessage));
 					return res;
 				}
+				if(filterRows.size()>0){
+					errorMessage = StringUtils.join(filterRows.toArray(),",")+ " 行已经被系统过滤;";
+					res.getError().add(new Error(errorMessage));
+					return res;
+				}
 				customerService.saveUploadData(boSet);
 			} catch (IOException e) {
 				e.printStackTrace();

+ 1 - 1
src/main/java/com/goafanti/customer/service/CustomerService.java

@@ -209,7 +209,7 @@ public interface CustomerService {
 	 * @param boSet
 	 * @param existRows
 	 */
-	void checkCustomer(Set<CustomerExcelBo> boSet,Set<Integer> existRows);
+	void checkCustomer(Set<CustomerExcelBo> boSet,Set<Integer> existRows, Set<Integer> filterRows);
 	
 	/**
 	 * 保存上传数据

+ 41 - 10
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -515,18 +516,49 @@ public class CustomerServiceImpl  extends BaseMybatisDao<UserMapper> implements
 	}
 
 	@Override
-	public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows) {
+	public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
 		List<User> list = null;
-		User user = null;
 		for (CustomerExcelBo bo : boSet) {
-			list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()));
-			if (list.size() > 0) {
-				user = list.get(0);
-				bo.setUid(user.getId());
+			CustomerExcelBo ceb = null;
+			for(Iterator<CustomerExcelBo> it = boSet.iterator();it.hasNext();){ //先自检
+				ceb = it.next();
+				if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){ //个人
+					if(ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())){
+						bo.setUid(ceb.getUid());
+						bo.setNewData(false);
+						filterRows.add(bo.getRowNumber());
+						break;
+					}
+				}else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){ //单位
+					if(ceb.getIdentifyName().equals(bo.getIdentifyName()) && ceb.getCustomerType().equals(bo.getCustomerType())){
+						bo.setUid(ceb.getUid());
+						bo.setNewData(false);
+						filterRows.add(bo.getRowNumber());
+						break;
+					}
+				}	
+			}
+			if(StringUtils.isBlank(bo.getUid())){ //是否已经存在
+				if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){
+					list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()));
+				}else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){
+					list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()));
+				}			
+				if (list.size() > 0) {
+					bo.setUid(list.get(0).getId());
+					bo.setNewData(false);
+					if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
+						existRows.add(bo.getRowNumber());
+					}
+				}else{
+					bo.setUid(UUID.randomUUID().toString());
+					bo.setNewData(true);
+				}
+			}else{
 				if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
 					existRows.add(bo.getRowNumber());
 				}
-			}
+			}	
 		}
 	}
 
@@ -536,14 +568,13 @@ public class CustomerServiceImpl  extends BaseMybatisDao<UserMapper> implements
 		Date now = new Date();
 		String uid = "";
 		for(CustomerExcelBo bo : boSet){
-			if(StringUtils.isBlank(bo.getUid())){ //新建客户
-				uid = UUID.randomUUID().toString();
+			uid = bo.getUid();
+			if(bo.isNewData()){ //新建客户
 				createUser(bo, uid, now);
 				createIdentity(bo, bo.getCustomerType(), uid);
 				createBusiness(bo, uid, now);
 				createContacts(bo, uid);	
 			}else{ //新建业务
-				uid = bo.getUid();
 				createBusiness(bo, uid, now);
 				if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
 					createContacts(bo, uid);