Pārlūkot izejas kodu

先离职变岗再更新和新增经销商人员信息

njs 3 mēneši atpakaļ
vecāks
revīzija
32ba8e4e23

+ 179 - 179
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/AnalysisDiyCustomerComponent.java

@@ -132,7 +132,7 @@ public class AnalysisDiyCustomerComponent {
             Long roleId = Long.parseLong(configService.selectConfigByKey("libang.storeCustomer.roleid"));
             roleStoreIds = new Long[]{roleId};
         }
-
+        Map<String,Customers> chainsMap = customersMapper.selectCustomerMapByChainsCode();
 
         List<SyncFailDetail> failDetails = new ArrayList<>();
         SyncLog syncLog = new SyncLog();
@@ -145,51 +145,6 @@ public class AnalysisDiyCustomerComponent {
         Set<String> diyNameSet = sysUserService.selectDiyUserLoginName();
 
 
-        //导购经销商
-        String guideJson ="";
-        try{
-            guideJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STOREGUIDE,null));
-        }catch (Exception e){
-            log.error("获取经销商导购接口错误!");
-            customerAccessTokenUtil.reSetToken();
-            throw e;
-        }
-        Map<String,Customers> codeMap = customersMapper.selectCustomerMapByCode();
-        JSONObject gjson = JSONObject.parseObject(guideJson);
-        int code = gjson.getInteger("code");
-        if(code==0){
-            JSONArray STOREGUIDE = new JSONArray();
-            STOREGUIDE.addAll(gjson.getJSONArray("userlist"));
-            success+=buildSysUser(STOREGUIDE,loginNameSet,diyNameSet,0,failDetails,packageId,codeMap);
-            total+=gjson.getJSONArray("userlist").size();
-        }
-
-        //经销商负责人
-        String managerJson ="";
-        try{
-            managerJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.MANAGER,null));
-        }catch (Exception e){
-            log.error("获取经销商经理接口错误!");
-            customerAccessTokenUtil.reSetToken();
-            throw e;
-        }
-
-        JSONObject mjson = JSONObject.parseObject(managerJson);
-
-
-        Map<String,Customers> chainsMap = customersMapper.selectCustomerMapByChainsCode();
-         code = mjson.getInteger("code");
-        if(code==0){
-            JSONArray MANAGER = new JSONArray();
-            MANAGER.addAll(mjson.getJSONArray("userlist"));
-           success+=buildSysUser(MANAGER,loginNameSet,diyNameSet,1,failDetails,packageId,chainsMap);
-            total+=mjson.getJSONArray("userlist").size();
-        }
-
-
-
-
-
         // 3.4、获取经销商分销业务员人员列表(分页)开始: ===================>
         log.info("3.4、获取经销商分销业务员人员列表(分页)开始: ===================>");
         String fxResellerJson ="";
@@ -219,7 +174,7 @@ public class AnalysisDiyCustomerComponent {
                     customerAccessTokenUtil.reSetToken();
                     throw e;
                 }
-                code = fxJson.getInteger("code");
+                int code = fxJson.getInteger("code");
                 if(code==0){
                     jsonArray.addAll( fxJson.getJSONArray("userlist"));
                 }
@@ -228,7 +183,7 @@ public class AnalysisDiyCustomerComponent {
             total+=jsonArray.size();
 
         }else{
-            code = fxJson.getInteger("code");
+            int code = fxJson.getInteger("code");
             if(code==0){
                 jsonArray.addAll( fxJson.getJSONArray("userlist"));
                 success+=buildSysUserFx(jsonArray,loginNameSet,6,failDetails,packageId,chainsMap);
@@ -238,6 +193,140 @@ public class AnalysisDiyCustomerComponent {
         log.info("3.4、获取经销商分销业务员人员列表(分页)结束: <========================");
         //3.4、获取经销商分销业务员人员列表(分页)结束: <========================
 
+        //3.6经销商经销人员列表
+        String staffListJson ="";
+        JSONArray STAFF = new JSONArray();
+        try {
+            staffListJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STAFF, 1+""));
+        } catch (Exception e) {
+            log.error("3.6经销商经销人员列表!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
+
+        JSONObject json = JSONObject.parseObject(staffListJson);
+        Integer Staffcount = json.getInteger("count");
+        if(Staffcount>100){
+            int co = 0;
+            if (Staffcount%100 != 0){
+                co = (Staffcount/100) +2;
+            }else{
+                co = (Staffcount/100) +1;
+            }
+            for (int i = 1; i < co; i++) {
+                try {
+                    json = JSONObject.parseObject(HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STAFF,i+"")));
+                } catch (Exception e) {
+                    log.error("循环获取3.6接口错误!第"+i+"页");
+                    customerAccessTokenUtil.reSetToken();
+                    throw e;
+                }
+                int code = json.getInteger("code");
+                if(code==0){
+                    STAFF.addAll(json.getJSONArray("data"));
+                }
+            }
+            success += buildSysUserStaff(STAFF, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,8);
+            total += STAFF.size();
+        }else{
+            int code = json.getInteger("code");
+            if(code==0){
+                STAFF.addAll(json.getJSONArray("data"));
+                success += buildSysUserStaff(STAFF, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,8);
+                total += STAFF.size();
+            }
+        }
+
+        //3.7经销商倍增人员人员(门店经销商)
+        String beizengJson ="";
+        JSONArray bz = new JSONArray();
+        try {
+            beizengJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.BZ, 1+""));
+        } catch (Exception e) {
+            log.error("3.7经销商倍增人员列表!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
+
+        JSONObject bzJson = JSONObject.parseObject(beizengJson);
+        Integer bzCount = bzJson.getInteger("count");
+        if(bzCount>100){
+            int co = 0;
+            if (bzCount%100 != 0){
+                co = (bzCount/100) +2;
+            }else{
+                co = (bzCount/100) +1;
+            }
+            for (int i = 1; i < co; i++) {
+                try {
+                    bzJson = JSONObject.parseObject(HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.BZ,i+"")));
+                } catch (Exception e) {
+                    log.error("循环获取3.7经销商倍增人员错误!第"+i+"页");
+                    customerAccessTokenUtil.reSetToken();
+                    throw e;
+                }
+                int code = bzJson.getInteger("code");
+                if(code==0){
+                    bz.addAll(bzJson.getJSONArray("data"));
+                }
+            }
+            success += buildSysUserBz(bz, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,5);
+            total += bz.size();
+        }else{
+            int code = bzJson.getInteger("code");
+            if(code==0){
+                bz.addAll(bzJson.getJSONArray("data"));
+                success += buildSysUserBz(bz, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,5);
+                total += bz.size();
+            }
+        }
+
+
+
+
+
+        //导购经销商
+        String guideJson ="";
+        try{
+            guideJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STOREGUIDE,null));
+        }catch (Exception e){
+            log.error("获取经销商导购接口错误!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
+        Map<String,Customers> codeMap = customersMapper.selectCustomerMapByCode();
+        JSONObject gjson = JSONObject.parseObject(guideJson);
+        int code = gjson.getInteger("code");
+        if(code==0){
+            JSONArray STOREGUIDE = new JSONArray();
+            STOREGUIDE.addAll(gjson.getJSONArray("userlist"));
+            success+=buildSysUser(STOREGUIDE,loginNameSet,diyNameSet,0,failDetails,packageId,codeMap);
+            total+=gjson.getJSONArray("userlist").size();
+        }
+
+        //经销商负责人
+        String managerJson ="";
+        try{
+            managerJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.MANAGER,null));
+        }catch (Exception e){
+            log.error("获取经销商经理接口错误!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
+
+        JSONObject mjson = JSONObject.parseObject(managerJson);
+
+
+        code = mjson.getInteger("code");
+        if(code==0){
+            JSONArray MANAGER = new JSONArray();
+            MANAGER.addAll(mjson.getJSONArray("userlist"));
+            success+=buildSysUser(MANAGER,loginNameSet,diyNameSet,1,failDetails,packageId,chainsMap);
+            total+=mjson.getJSONArray("userlist").size();
+        }
+
+
+
 //财务3.2
         String financeJson ="";
         try{
@@ -326,96 +415,6 @@ public class AnalysisDiyCustomerComponent {
             }
         }
 
-        //3.6经销商经销人员列表
-        String staffListJson ="";
-        JSONArray STAFF = new JSONArray();
-        try {
-            staffListJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STAFF, 1+""));
-        } catch (Exception e) {
-            log.error("3.6经销商经销人员列表!");
-            customerAccessTokenUtil.reSetToken();
-            throw e;
-        }
-
-        JSONObject json = JSONObject.parseObject(staffListJson);
-        Integer Staffcount = json.getInteger("count");
-        if(Staffcount>100){
-            int co = 0;
-            if (Staffcount%100 != 0){
-                co = (Staffcount/100) +2;
-            }else{
-                co = (Staffcount/100) +1;
-            }
-            for (int i = 1; i < co; i++) {
-                try {
-                    json = JSONObject.parseObject(HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STAFF,i+"")));
-                } catch (Exception e) {
-                    log.error("循环获取3.6接口错误!第"+i+"页");
-                    customerAccessTokenUtil.reSetToken();
-                    throw e;
-                }
-                code = json.getInteger("code");
-                if(code==0){
-                    STAFF.addAll(json.getJSONArray("data"));
-                }
-            }
-            success += buildSysUserStaff(STAFF, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,8);
-            total += STAFF.size();
-        }else{
-            code = json.getInteger("code");
-            if(code==0){
-                STAFF.addAll(json.getJSONArray("data"));
-                success += buildSysUserStaff(STAFF, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,8);
-                total += STAFF.size();
-            }
-        }
-
-        //3.7经销商倍增人员人员(门店经销商)
-        String beizengJson ="";
-        JSONArray bz = new JSONArray();
-        try {
-            beizengJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.BZ, 1+""));
-        } catch (Exception e) {
-            log.error("3.7经销商倍增人员列表!");
-            customerAccessTokenUtil.reSetToken();
-            throw e;
-        }
-
-        JSONObject bzJson = JSONObject.parseObject(beizengJson);
-        Integer bzCount = bzJson.getInteger("count");
-        if(bzCount>100){
-            int co = 0;
-            if (bzCount%100 != 0){
-                co = (bzCount/100) +2;
-            }else{
-                co = (bzCount/100) +1;
-            }
-            for (int i = 1; i < co; i++) {
-                try {
-                    bzJson = JSONObject.parseObject(HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.BZ,i+"")));
-                } catch (Exception e) {
-                    log.error("循环获取3.7经销商倍增人员错误!第"+i+"页");
-                    customerAccessTokenUtil.reSetToken();
-                    throw e;
-                }
-                code = bzJson.getInteger("code");
-                if(code==0){
-                    bz.addAll(bzJson.getJSONArray("data"));
-                }
-            }
-            success += buildSysUserBz(bz, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,5);
-            total += bz.size();
-        }else{
-            code = bzJson.getInteger("code");
-            if(code==0){
-                bz.addAll(bzJson.getJSONArray("data"));
-                success += buildSysUserBz(bz, loginNameSet, diyNameSet, failDetails, packageId, chainsMap,5);
-                total += bz.size();
-            }
-        }
-
-
-
 
         //13.1 新零售经销商人员列表
         String xlsCustomerJson ="";
@@ -651,6 +650,41 @@ public class AnalysisDiyCustomerComponent {
                 interfaceList.add(loginName);
             }
         }
+        List<String> loginNames = sysUserService.selectUserByIsManager(isManager);
+        List<String> collect =new ArrayList<>();
+        loginNames.removeAll(interfaceList);
+        collect.addAll(loginNames);
+        if (collect.size() > 0) {
+            for (String login : collect
+            ) {
+                SysUser u = sysUserService.selectUserByLoginName(login);
+                if (("0").equals(u.getIsSync())) {
+                    String CustomerManager = u.getSysUserExt().getIsCustomerManager();
+                    String[] manager = CustomerManager.split(",");
+                    if (manager.length > 1) {
+                        List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
+                        if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(),null);
+                        }
+                        List<String> resultList = new ArrayList<>(manager.length);
+                        Collections.addAll(resultList,manager);
+                        Object i=isManager;
+                        resultList.remove(i.toString());
+                        String IsManager = resultList.stream().map(String::valueOf).collect(Collectors.joining(","));
+                        u.getSysUserExt().setIsCustomerManager(IsManager);
+                        sysUserExtMapper.updateSysUserExt(u.getSysUserExt());
+                    } else {
+                        List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
+                        if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
+                        }else{
+                            u.setQuit("2");
+                            sysUserService.updateUserInfo(u);
+                        }
+                    }
+                }
+            }
+        }
         for (int i = 0; i < jsonArray.size(); i++) {
             JSONObject jo = jsonArray.getJSONObject(i);
 
@@ -870,41 +904,7 @@ public class AnalysisDiyCustomerComponent {
                 failDetails.add(syncFailDetail);
             }
         }
-        List<String> loginNames = sysUserService.selectUserByIsManager(isManager);
-        List<String> collect =new ArrayList<>();
-        loginNames.removeAll(interfaceList);
-        collect.addAll(loginNames);
-        if (collect.size() > 0) {
-            for (String login : collect
-            ) {
-                SysUser u = sysUserService.selectUserByLoginName(login);
-                if (("0").equals(u.getIsSync())) {
-                    String CustomerManager = u.getSysUserExt().getIsCustomerManager();
-                    String[] manager = CustomerManager.split(",");
-                    if (manager.length > 1) {
-                        List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
-                        if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
-                        }
-                        List<String> resultList = new ArrayList<>(manager.length);
-                        Collections.addAll(resultList,manager);
-                        Object i=isManager;
-                        resultList.remove(i.toString());
-                        String IsManager = resultList.stream().map(String::valueOf).collect(Collectors.joining(","));
-                        u.getSysUserExt().setIsCustomerManager(IsManager);
-                        sysUserExtMapper.updateSysUserExt(u.getSysUserExt());
-                    } else {
-                        List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
-                        if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
-                        }else{
-                            u.setQuit("2");
-                            sysUserService.updateUserInfo(u);
-                        }
-                    }
-                }
-            }
-        }
+
         return count;
     }
 
@@ -1361,7 +1361,7 @@ public class AnalysisDiyCustomerComponent {
                     if(manager.length >1){
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }
                         List<String> resultList = new ArrayList<>(manager.length);
                         Collections.addAll(resultList,manager);
@@ -1373,7 +1373,7 @@ public class AnalysisDiyCustomerComponent {
                     }else{
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }else{
                             u.setQuit("2");
                             sysUserService.updateUserInfo(u);
@@ -1552,7 +1552,7 @@ public class AnalysisDiyCustomerComponent {
                     if(manager.length >1){
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }
                         List<String> resultList = new ArrayList<>(manager.length);
                         Collections.addAll(resultList,manager);
@@ -1564,7 +1564,7 @@ public class AnalysisDiyCustomerComponent {
                     }else{
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }else{
                             u.setQuit("2");
                             sysUserService.updateUserInfo(u);
@@ -1759,7 +1759,7 @@ public class AnalysisDiyCustomerComponent {
                     if (manager.length > 1) {
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }
                         List<String> resultList = new ArrayList<>(manager.length);
                         Collections.addAll(resultList,manager);
@@ -1771,7 +1771,7 @@ public class AnalysisDiyCustomerComponent {
                     } else {
                         List<AssRelcustomerinfo> assRelcustomerinfoList = assRelcustomerinfoService.selectRelcustomerinfoByKunnr(null, String.valueOf(u.getUserId()));
                         if(assRelcustomerinfoList !=null && assRelcustomerinfoList.size()>0){
-                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), u.getSysUserExt().getOrgCode());
+                            assRelcustomerinfoService.deleteAssRelcustomerinfoByUserId(u.getUserId().toString(), null);
                         }else{
                             u.setQuit("2");
                             sysUserService.updateUserInfo(u);