Browse Source

销售用户拉取逻辑

qxp 4 years ago
parent
commit
5e7772f37d

+ 18 - 14
suishenbang-admin/src/main/resources/templates/system/user/add.html

@@ -131,19 +131,21 @@
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>
-                <div class="col-sm-4">
-                    <div class="form-group">
-                        <label class="col-sm-4 control-label">岗位名称:</label>
-                        <div class="col-sm-8">
-                            <input class="form-control" type="text" readonly="true" name="sysUserExt.postName" />
+                <div id="diyDiv">
+                    <div class="col-sm-4">
+                        <div class="form-group">
+                            <label class="col-sm-4 control-label">岗位名称:</label>
+                            <div class="col-sm-8">
+                                <input class="form-control" type="text" readonly="true" name="sysUserExt.postName" />
+                            </div>
                         </div>
                         </div>
                     </div>
                     </div>
-                </div>
-                <div class="col-sm-4">
-                    <div class="form-group">
-                        <label class="col-sm-4 control-label">组织Code:</label>
-                        <div class="col-sm-8">
-                            <input class="form-control" type="text" readonly="true" name="sysUserExt.orgCode" />
+                    <div class="col-sm-4">
+                        <div class="form-group">
+                            <label class="col-sm-4 control-label">组织Code:</label>
+                            <div class="col-sm-8">
+                                <input class="form-control" type="text" readonly="true" name="sysUserExt.orgCode" />
+                            </div>
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>
@@ -339,13 +341,15 @@
 		}function changeLevel(){
 		}function changeLevel(){
             var level = $("input[name='sysUserExt.salesLevel']").val();
             var level = $("input[name='sysUserExt.salesLevel']").val();
             if(level=="customer_level"){
             if(level=="customer_level"){
+                $("#diyDiv").show();
                 $("#customerDiv").show();
                 $("#customerDiv").show();
                 $("#salesDiv").hide();
                 $("#salesDiv").hide();
             }else if(level=="diy_level"){
             }else if(level=="diy_level"){
-
-                $("#customerDiv").show();
-                $("#salesDiv").show();
+                $("#diyDiv").hide();
+                $("#customerDiv").hide();
+                $("#salesDiv").hide();
             }else{
             }else{
+                $("#diyDiv").show();
                 $("#customerDiv").hide();
                 $("#customerDiv").hide();
                 $("#salesDiv").show();
                 $("#salesDiv").show();
             }
             }

+ 2 - 2
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/exception/OutOfDIYPostNameException.java

@@ -11,12 +11,12 @@ public class OutOfDIYPostNameException extends BaseException  {
      * 用户信息
      * 用户信息
      */
      */
     private MetaEmployeeDiy metaEmployeeDiy;
     private MetaEmployeeDiy metaEmployeeDiy;
-    public OutOfDIYPostNameException(MetaEmployeeDiy m,int i) {
+    public OutOfDIYPostNameException(MetaEmployeeDiy m) {
 
 
         super("sync","500",
         super("sync","500",
                 new Object[] { "用户:"+m.getName(),
                 new Object[] { "用户:"+m.getName(),
                         "packageId:"+m.getPackageId()},null);
                         "packageId:"+m.getPackageId()},null);
-        String s = "用户:"+m.getName()+"不在第"+i+"级部门岗位筛选列表中";
+        String s = "用户:"+m.getName()+"不在部门岗位筛选列表中";
         this.metaEmployeeDiy = m;
         this.metaEmployeeDiy = m;
         this.msg = s;
         this.msg = s;
 
 

BIN
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/DIY用户逻辑.jpg


+ 102 - 53
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/impl/AnalysisSysUserService.java

@@ -8,10 +8,7 @@ import com.dgtly.sync.domain.MetaDiySalesorgtree;
 import com.dgtly.sync.domain.MetaEmployeeDiy;
 import com.dgtly.sync.domain.MetaEmployeeDiy;
 import com.dgtly.sync.domain.SyncFailDetail;
 import com.dgtly.sync.domain.SyncFailDetail;
 import com.dgtly.sync.domain.SyncLog;
 import com.dgtly.sync.domain.SyncLog;
-import com.dgtly.sync.exception.NotFountOrgCodeException;
-import com.dgtly.sync.exception.OutOfDIYPostNameException;
-import com.dgtly.sync.exception.OutOfLeveLException;
-import com.dgtly.sync.exception.OutOfScopeDIYException;
+import com.dgtly.sync.exception.*;
 import com.dgtly.sync.mapper.MetaDiySalesorgtreeMapper;
 import com.dgtly.sync.mapper.MetaDiySalesorgtreeMapper;
 import com.dgtly.sync.mapper.MetaEmployeeDiyMapper;
 import com.dgtly.sync.mapper.MetaEmployeeDiyMapper;
 import com.dgtly.sync.mapper.SyncFailDetailMapper;
 import com.dgtly.sync.mapper.SyncFailDetailMapper;
@@ -142,6 +139,7 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
                     userExt.setPostCode(m.getEmployeePost());
                     userExt.setPostCode(m.getEmployeePost());
                     String postName = m.getEmployeePostName();
                     String postName = m.getEmployeePostName();
                     userExt.setPostName(postName);
                     userExt.setPostName(postName);
+
                     //判断用户所处销售层级
                     //判断用户所处销售层级
                     //先啊判断用户所属的岗位名称确定销售部门
                     //先啊判断用户所属的岗位名称确定销售部门
                     if(companySet.contains(postName)){
                     if(companySet.contains(postName)){
@@ -149,61 +147,47 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
                         userExt.setSalesLevel("company_level");
                         userExt.setSalesLevel("company_level");
                         userExt.setOrgName(m.getStext3());
                         userExt.setOrgName(m.getStext3());
                         setExtOrgCodeOn3(salesTreeMap,userExt);
                         setExtOrgCodeOn3(salesTreeMap,userExt);
-                    }else {
-                        if(m.getStext6()!=null){
-                            if(empSet.contains(m.getEmployeePostName())){
-                                userExt.setSalesLevel("emp_level");
-                                userExt.setOrgName(m.getStext6());
-                                setExtOrgCode(salesTreeMap,6,userExt);
-
-                            }else if(subofficeSet.contains(m.getEmployeePostName())){
-                                userExt.setSalesLevel("suboffice_level");
-                                userExt.setOrgName(m.getStext6());
-                                setExtOrgCode(salesTreeMap,6,userExt);
-
-                            }else{
-                                throw new OutOfDIYPostNameException(m,6);
-                            }
-                        }else if(m.getStext5()!=null){
-
-                            if(officeSet.contains(m.getEmployeePostName())){
-                                userExt.setSalesLevel("office_level");
-                                userExt.setOrgName(m.getStext5());
-                                setExtOrgCode(salesTreeMap,5,userExt);
 
 
-                            }else{
-                                throw new OutOfDIYPostNameException(m,5);
+                    }else {
+                        //判断用户u岗位是否在销售员敢为、销售分部岗位、销售部岗位、销售大区岗位中
+                        if(empSet.contains(postName)||subofficeSet.contains(postName)||officeSet.contains(postName)||saledeptSet.contains(postName)){
+                            //获取最后所属的部门名称
+                            String orgName = getStext(m);
+                            userExt.setOrgName(orgName);
+                            int i = getLevel(userExt,salesTreeMap);
+                            if (i==-1){
+                                throw new NotFountOrgCodeException(m);
                             }
                             }
-                        }else if(m.getStext4()!=null){
-                            if(saledeptSet.contains(m.getEmployeePostName())){
-                                userExt.setSalesLevel("saledept_level");
-                                userExt.setOrgName(m.getStext4());
-                                setExtOrgCode(salesTreeMap,4,userExt);
-
-                            } else{
-                                throw new OutOfDIYPostNameException(m,4);
+                            switch (i){
+                                case 6:
+                                    if(empSet.contains(m.getEmployeePostName())){
+                                        //等级6 销售员
+                                        userExt.setSalesLevel("emp_level");
+                                    }else if(subofficeSet.contains(m.getEmployeePostName())){
+                                        //等级6 销售分部
+                                        userExt.setSalesLevel("suboffice_level");
+                                    }
+                                    break;
+                                case 5:
+                                    userExt.setSalesLevel("office_level");
+                                    break;
+                                case 4:
+                                    userExt.setSalesLevel("saledept_level");
+                                    break;
+                                case 3:
+                                    userExt.setSalesLevel("company_level");
+                                    break;
                             }
                             }
                         }else{
                         }else{
-                            throw new OutOfLeveLException(m);
+                            throw new OutOfDIYPostNameException(m);
                         }
                         }
                     }
                     }
 
 
-
-
-
-//                    if(userExt.getOrgName()!=null){
-//                        Map<String,String> map=  metaDiySalesorgtreeMapper.selectSalesorgByName(fildName,fildCode,userExt.getOrgName());
-//                        if(map!=null && map.containsKey("orgcode")){
-//                            userExt.setOrgCode(map.get("orgcode"));
-//                        }
+//                    if(userExt.getOrgCode()==null){
+//                        throw new NotFountOrgCodeException(m);
 //                    }
 //                    }
-                    if(userExt.getOrgCode()==null){
-                        throw new NotFountOrgCodeException(m);
-                    }
-                    /**======== 构建diy用户扩展信息表 end===============*/
-
-
 
 
+                    /**======== 构建diy用户扩展信息表 end===============*/
                     if (loginNameList.contains(user.getLoginName())) {
                     if (loginNameList.contains(user.getLoginName())) {
                         /**  更新 */
                         /**  更新 */
                         SysUser userInDb =sysUserService.selectUserByLoginName(user.getLoginName());
                         SysUser userInDb =sysUserService.selectUserByLoginName(user.getLoginName());
@@ -221,7 +205,7 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
                         sysUserService.insertUserAndSalesExt(user);
                         sysUserService.insertUserAndSalesExt(user);
                         successCount++;
                         successCount++;
                     }
                     }
-                }catch (OutOfScopeDIYException|NotFountOrgCodeException|OutOfDIYPostNameException|OutOfLeveLException e){
+                }catch (OutOfScopeDIYException|NotFountOrgCodeException|OutOfDIYPostNameException|OutOfLeveLException|NotOrgNameException e){
                     /**
                     /**
                      * 警告类异常
                      * 警告类异常
                      */
                      */
@@ -286,6 +270,8 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
     }
     }
 
 
 
 
+
+
     /**
     /**
      * 获取销售组织架构树
      * 获取销售组织架构树
      * @return
      * @return
@@ -304,7 +290,30 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
     }
     }
 
 
     /**
     /**
-     * 根据销售的部门等级及销售组织名称获取销售的组织code
+     * 获取用户最后的stext
+     * @param m
+     * @return
+     */
+    public String getStext(MetaEmployeeDiy m){
+        if(m.getStext6()!=null&&!m.getStext6().trim().equals("")){
+            return m.getStext6();
+        }else if(m.getStext5()!=null&&!m.getStext5().trim().equals("")){
+            return m.getStext5();
+        }else if(m.getStext4()!=null&&!m.getStext4().trim().equals("")){
+            return m.getStext4();
+        }else if(m.getStext3()!=null&&!m.getStext3().trim().equals("")){
+            return m.getStext3();
+        }else if(m.getStext2()!=null&&!m.getStext2().trim().equals("")){
+            return m.getStext2();
+        }else if(m.getStext1()!=null&&!m.getStext1().trim().equals("")){
+            return m.getStext1();
+        }
+
+        throw  new NotOrgNameException(m);
+    }
+
+    /**
+     * 根据销售的部门等级及销售组织名称获取销售的组织code 向下兼容
      * @param salesTree
      * @param salesTree
      * @param level 销售登记
      * @param level 销售登记
      * @param userExt 用户扩展信息
      * @param userExt 用户扩展信息
@@ -327,9 +336,34 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
             }
             }
         }
         }
         return false;
         return false;
-
     }
     }
 
 
+
+    /**
+     * 根据销售的部门等级及销售组织名称获取销售的组织code 向上兼容
+     * @param salesTree
+     * @param level 销售登记
+     * @param userExt 用户扩展信息
+     * @return
+     */
+    public boolean setExtOrgCodeUp(Map<Integer,Map<String,Map<String,String>>> salesTree,int level,SysUserExt userExt){
+        if(userExt.getOrgName()==null||userExt.getOrgName().trim().equals("")){
+            return false;
+        }
+        String orgname = userExt.getOrgName();
+        for(;level>3;level--){
+            if(salesTree.containsKey(level)){
+                Map<String,Map<String,String>> temp = salesTree.get(level);
+                if(temp.containsKey(orgname)){
+                    userExt.setOrgCode(temp.get(orgname).get("orgcode"));
+                    return true;
+                }else{
+                    continue;
+                }
+            }
+        }
+        return false;
+    }
     /**
     /**
      * 根据用户所处部门是否包含第三等级区公司名称 来获取code特殊情况针对 第三级特殊情况
      * 根据用户所处部门是否包含第三等级区公司名称 来获取code特殊情况针对 第三级特殊情况
      * @param salesTree
      * @param salesTree
@@ -354,6 +388,21 @@ public class AnalysisSysUserService implements IAnalysisSysUserService {
 
 
     }
     }
 
 
+    public int getLevel(SysUserExt userExt,Map<Integer,Map<String,Map<String,String>>> salesTree){
+        String orgName = userExt.getOrgName();
+        for(int i =6;i>2;i--){
+            if(salesTree.containsKey(i)){
+                Map<String,Map<String,String>> temp = salesTree.get(i);
+                if(temp.containsKey(orgName)){
+                    userExt.setOrgCode(temp.get(orgName).get("orgcode"));
+                    return i;
+                }
+            }
+        }
+        return -1;
+
+    }
+
 
 
 
 
 }
 }

+ 1 - 1
suishenbang-sync/suishenbang-sync-manager/src/main/java/com/dgtly/sync/controller/SyncController.java

@@ -65,7 +65,7 @@ public class SyncController {
     @GetMapping("user")
     @GetMapping("user")
     public Object user(String packageId, String jobId, String message){
     public Object user(String packageId, String jobId, String message){
         try{
         try{
-            analysisSysUserService.analysisSysUser(packageId);
+            analysisSysUserService.analysisSysUser(null);
         }catch (Exception e){
         }catch (Exception e){
             log.error("解析用户出错",e);
             log.error("解析用户出错",e);
         }
         }