Browse Source

线索客户导入新增公共客户导入与数据修改

anderx 1 year ago
parent
commit
10e8837876

+ 49 - 12
src/main/java/com/goafanti/customer/service/impl/UserClueServiceImpl.java

@@ -76,9 +76,13 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         }
         return page;
     }
-
     @Override
     public Object add(InputUserClueBo in) throws BusinessException{
+        Admin admin = adminMapper.queryById(TokenManager.getAdminId());
+        return add(in,admin);
+    }
+
+    public Object add(InputUserClueBo in,Admin admin) throws BusinessException{
         User user = new User();
         Date now = new Date();
         String aid= TokenManager.getAdminId();
@@ -113,7 +117,6 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         user.setClueTime(now);
         user.setClueTransferTime(now);
         passwordUtil.encryptPassword(user);
-        String aname = adminMapper.queryById(TokenManager.getAdminId()).getName();
         UserMid um=new UserMid();
         um.setAid(user.getAid());
         um.setUid(uid);
@@ -137,7 +140,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         un.setName(user.getNickname());
         userNamesMapper.insertSelective(un);
         // 新增企业联系人
-        iterContactBook(in,aname,uid);
+        iterContactBook(in,admin.getName(),uid);
         addUserTransferLog(user,22,null);
         return 1;
     }
@@ -151,6 +154,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         cob.setName(in.getContacts());
         cob.setMobile(in.getContactMobile());
         cob.setMajor(AFTConstants.YES);
+        organizationContactBookMapper.updateSubContact(uid);
         organizationContactBookMapper.insert(cob);
         if (StringUtils.isNotBlank(in.getContactMobileMore())){
             String[] split = null;
@@ -183,20 +187,27 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
             try {
                 checkMobile(e.getContactMobile());
                 checkContacts(e.getContacts());
-                //判定客户名称
-                checkUserName(e.getNickname());
+                
             }catch (BusinessException ex){
                 size++;
                 msg.append("<br/>客户[").append(e.getNickname()).append("]导入失败,原因:").append(ex.getMessage()).append(" ");
                 continue;
             }
+            //判定客户名称
+            User user = checkUserName(e.getNickname());
+
             InputUserClueBo inUserClueBo = new InputUserClueBo();
             inUserClueBo.setUserName(e.getNickname());
             inUserClueBo.setContactMobile(e.getContactMobile());
             inUserClueBo.setContacts(e.getContacts());
             inUserClueBo.setContactMobileMore(e.getContactMobileMore());
             try {
-                add(inUserClueBo);
+                Admin admin = adminMapper.queryById(TokenManager.getAdminId());
+                if (user==null){
+                    add(inUserClueBo,admin);
+                }else {
+                    update(inUserClueBo,admin,user);
+                }
             }catch (Exception ex){
                 size++;
                 msg.append("<br/>客户[").append(e.getNickname()).append("]新增异常。 ");
@@ -212,6 +223,19 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         return map;
     }
 
+    private void update(InputUserClueBo inUserClueBo,Admin admin,User user) {
+        Date now = new Date();
+        User newUser =new User();
+        newUser.setId(user.getId());
+        newUser.setClueProcess(0);
+        newUser.setClueStatus(1);
+        newUser.setClueTime(now);
+        newUser.setClueTransferTime(now);
+        userMapper.update(newUser);
+        // 新增企业联系人
+        iterContactBook(inUserClueBo,admin.getName(),user.getId());
+    }
+
     private void checkContacts(String contacts) throws BusinessException {
         String nameReg="[\\u4e00-\\u9fa5]+.*";
         Pattern  pattern =Pattern.compile(nameReg);
@@ -307,18 +331,31 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
     }
 
 
-    private void checkUserName(String name) throws BusinessException{
-        if (!userMapper.checkUser("", name, "", 1, null, null).isEmpty())
-            throw new BusinessException("客户已经存在");
+    private User checkUserName(String name) throws BusinessException{
+//        if (!userMapper.checkUser("", name, "", 1, null, null).isEmpty())
+//            throw new BusinessException("客户已经存在");
         String name2=null;
         if (name.contains("(")){
             name2=name.replace("(","(").replace(")",")");
         }else if (name.contains("(")){
             name2=name.replace("(","(").replace(")",")");
         }
-        if (name2!=null){
-            if (!userMapper.checkUser("", name2, "", 1, null, null).isEmpty())
-                throw new BusinessException("客户已经存在");
+//        if (name2!=null){
+//            if (!userMapper.checkUser("", name2, "", 1, null, null).isEmpty())
+//                throw new BusinessException("客户已经存在");
+//        }
+        User user = userMapper.selectByName(name);
+        if (user==null){
+            user = userMapper.selectByName(name2);
+        }
+        if (user!=null){
+            if (user.getShareType()==0){
+                throw new BusinessException("客户已经存在私有");
+            }else if (user.getShareType()==2){
+                throw new BusinessException("客户已经存在签单");
+            }
+            return user;
         }
+        return null;
     }
 }