Browse Source

线索客户导入修改

anderx 1 year ago
parent
commit
d58750c97a

+ 73 - 40
src/main/java/com/goafanti/customer/service/impl/UserClueServiceImpl.java

@@ -77,10 +77,29 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
     @Override
     public Object add(InputUserClueBo in) throws BusinessException{
         Admin admin = adminMapper.queryById(TokenManager.getAdminId());
-        return add(in,admin);
+        String mobile = "";
+        List<String> mobileList = new ArrayList<>();
+        if (in.getContactMobile().equals("-")){
+            if (in.getContactMobileMore().equals("-")){
+                throw new BusinessException("手机号不能为空");
+            }else {
+                String[] split = in.getContactMobileMore().split(";");
+                mobile=split[0];
+                mobileList.addAll(Arrays.asList(split));
+            }
+        }else {
+            String[] split = in.getContactMobile().split(";");
+            mobile=split[0];
+            mobileList.addAll(Arrays.asList(split));
+            if (!in.getContactMobileMore().equals("-")){
+                String[] split2 = in.getContactMobile().split(";");
+                mobileList.addAll(Arrays.asList(split2));
+            }
+        }
+        return add(in,admin,mobileList,mobile);
     }
 
-    public Object add(InputUserClueBo in,Admin admin) throws BusinessException{
+    public Object add(InputUserClueBo in,Admin admin,List<String> mobileList,String mobile) throws BusinessException{
         User user = new User();
         Date now = new Date();
         String aid= TokenManager.getAdminId();
@@ -103,7 +122,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         user.setUpdateTime(now);
         user.setSignBills(0);
         user.setNewChannel(0);
-        user.setMobile(in.getContactMobile());
+        user.setMobile(mobile);
         user.setPassword(AFTConstants.INITIALPASSWORD);
         user.setInformationMaintainer(TokenManager.getAdminId());
         double f = 0;
@@ -125,7 +144,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         oi.setId(identifyId);
         oi.setUid(uid);
         oi.setContacts(in.getContacts());
-        oi.setContactMobile(in.getContactMobile());
+        oi.setContactMobile(mobile);
         oi.setHighTechZone(AFTConstants.NO);
         oi.setInternational(AFTConstants.NO);
         oi.setListed(AFTConstants.NO);
@@ -138,44 +157,31 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         un.setName(user.getNickname());
         userNamesMapper.insertSelective(un);
         // 新增企业联系人
-        iterContactBook(in,admin.getName(),uid);
+        iterContactBook(in.getContacts(),mobileList,admin.getName(),uid,mobile);
         addUserTransferLog(user,22,null);
         return 1;
     }
 
-    private void iterContactBook(InputUserClueBo in, String aname, String uid) {
-        OrganizationContactBook cob = new OrganizationContactBook();
-        cob.setAid(TokenManager.getAdminId());
-        cob.setAname(aname);
-        cob.setId(UUID.randomUUID().toString());
-        cob.setUid(uid);
-        cob.setName(in.getContacts());
-        cob.setMobile(in.getContactMobile());
-        cob.setMajor(AFTConstants.YES);
+    private void iterContactBook(String name,List<String> mobileList, String aname, String uid,String mobile) {
         organizationContactBookMapper.updateSubContact(uid);
-        organizationContactBookMapper.insert(cob);
-        if (StringUtils.isNotBlank(in.getContactMobileMore())){
-            String[] split = null;
-            if (in.getContactMobileMore().contains(";")){
-                split = in.getContactMobileMore().split(";");
-            } else if (in.getContactMobileMore().contains(";")) {
-                split = in.getContactMobileMore().split(";");
-            }
-            for (String s : split) {
+            for (String s : mobileList) {
                 if (StringUtils.isNotBlank(s)) {
                     OrganizationContactBook cob2 = new OrganizationContactBook();
                     cob2.setAid(TokenManager.getAdminId());
                     cob2.setAname(aname);
                     cob2.setId(UUID.randomUUID().toString());
                     cob2.setUid(uid);
-                    cob2.setName(in.getContacts());
+                    cob2.setName(name);
                     cob2.setMobile(s);
-                    cob2.setMajor(AFTConstants.NO);
+                    if (s.equals(mobile)){
+                        cob2.setMajor(AFTConstants.YES);
+                    }else {
+                        cob2.setMajor(AFTConstants.NO);
+                    }
                     organizationContactBookMapper.insert(cob2);
                 }
             }
         }
-    }
 
     @Override
     public Map<String, Object> pushImportUserClue(List<OutUserClueExcel> list) {
@@ -184,6 +190,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         for (OutUserClueExcel e : list) {
             try {
                 checkMobile(e.getContactMobile());
+                checkMobile(e.getContactMobileMore());
                 checkContacts(e.getContacts());
                 
             }catch (BusinessException ex){
@@ -196,15 +203,15 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
 
             InputUserClueBo inUserClueBo = new InputUserClueBo();
             inUserClueBo.setUserName(e.getNickname());
+
             inUserClueBo.setContactMobile(e.getContactMobile());
             inUserClueBo.setContacts(e.getContacts());
             inUserClueBo.setContactMobileMore(e.getContactMobileMore());
             try {
-                Admin admin = adminMapper.queryById(TokenManager.getAdminId());
                 if (user==null){
-                    add(inUserClueBo,admin);
+                    add(inUserClueBo);
                 }else {
-                    update(inUserClueBo,admin,user);
+                    update(inUserClueBo,user);
                 }
             }catch (Exception ex){
                 size++;
@@ -221,7 +228,27 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         return map;
     }
 
-    private void update(InputUserClueBo inUserClueBo,Admin admin,User user) {
+    private void update(InputUserClueBo in,User user) {
+        Admin admin = adminMapper.queryById(TokenManager.getAdminId());
+        String mobile = "";
+        List<String> mobileList = new ArrayList<>();
+        if (in.getContactMobile().equals("-")){
+            if (in.getContactMobileMore().equals("-")){
+                throw new BusinessException("手机号不能为空");
+            }else {
+                String[] split = in.getContactMobileMore().split(";");
+                mobile=split[0];
+                mobileList.addAll(Arrays.asList(split));
+            }
+        }else {
+            String[] split = in.getContactMobile().split(";");
+            mobile=split[0];
+            mobileList.addAll(Arrays.asList(split));
+            if (!in.getContactMobileMore().equals("-")){
+                String[] split2 = in.getContactMobile().split(";");
+                mobileList.addAll(Arrays.asList(split2));
+            }
+        }
         Date now = new Date();
         User newUser =new User();
         newUser.setId(user.getId());
@@ -235,7 +262,7 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         newUser.setClueTransferTime(now);
         userMapper.update(newUser);
         // 新增企业联系人
-        iterContactBook(inUserClueBo,admin.getName(),user.getId());
+        iterContactBook(in.getContacts(),mobileList,admin.getName(),user.getId(),mobile);
     }
 
     private void checkContacts(String contacts) throws BusinessException {
@@ -248,18 +275,24 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
     }
 
     private void checkMobile(String contactMobile) throws BusinessException{
-        String mobileReg="[1-9]\\d{10}";
-        String mobileReg2="^0\\d{2,3}-?\\d{7,8}$";
-        Pattern  pattern =Pattern.compile(mobileReg);
-        Matcher matcher = pattern.matcher(contactMobile);
-        if (!matcher.matches()){
-            Pattern  pattern2 =Pattern.compile(mobileReg2);
-            Matcher matcher2 = pattern2.matcher(contactMobile);
-            if (!matcher2.matches()){
-                throw new BusinessException("手机号格式不正确");
+        if (!contactMobile.equals("-")){
+            String[] split = contactMobile.split(";");
+            for (String s : split) {
+                String mobileReg="[1-9]\\d{10}";
+                String mobileReg2="^0\\d{2,3}-?\\d{7,8}$";
+                Pattern  pattern =Pattern.compile(mobileReg);
+                Matcher matcher = pattern.matcher(s);
+                if (!matcher.matches()){
+                    Pattern  pattern2 =Pattern.compile(mobileReg2);
+                    Matcher matcher2 = pattern2.matcher(s);
+                    if (!matcher2.matches()){
+                        throw new BusinessException("手机号格式不正确");
+                    }
+                }
             }
         }
 
+
     }