Sfoglia il codice sorgente

解决同步通讯录时单独授权人员无法同步的bug

seyason 1 anno fa
parent
commit
2b192c1495

+ 22 - 19
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -2116,6 +2116,8 @@ public class WeiXinCorpController {
             String accessToken = null;
             try {
                 accessToken = wxCorpInfoService.getCorpAgentAccessToken(wxCorpInfo);
+                //获取应用授权范围
+
                 //获取组织架构 同步部门
                 String departmentInfoResp = wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
                 JSONObject departmentInfoOb = JSONObject.parseObject(departmentInfoResp);
@@ -2234,16 +2236,11 @@ public class WeiXinCorpController {
                     JSONObject json = JSONObject.parseObject(resp);
                     if (json.getIntValue("errcode") == 0) {
                         System.out.println("this is agentinfo========"+resp);
-                        String allow_userinfos = json.getString("allow_userinfos");
-                        JSONObject jsonObject = JSONObject.parseObject(allow_userinfos);
-                        JSONArray userInfo = jsonObject.getJSONArray("user");
+                        JSONObject allow_userinfos = json.getJSONObject("allow_userinfos");
+                        JSONArray userInfo = allow_userinfos.getJSONArray("user");
                         for (int i = 0; i < userInfo.size(); i++) {
                             JSONObject object = userInfo.getJSONObject(i);
                             String corpWxuserid = object.getString("userid");
-                            int status = object.getIntValue("status");
-                            if(status!=1){
-                                continue;
-                            }
                             String userInfoResp=wxCorpInfoService.getUserInfoWithApplication(accessToken,corpWxuserid);
                             System.out.println("this is userinfo======="+userInfoResp);
                             JSONObject userInfoOb = JSONObject.parseObject(userInfoResp);
@@ -2252,24 +2249,30 @@ public class WeiXinCorpController {
                             String userName = String.valueOf(userInfoOb.get("name"));
                             String phone = String.valueOf(userInfoOb.get("phone"));
 
-                            String openUserid = userInfoOb.getString("open_userid");
-                            List<Integer> departments = (List<Integer>) userInfoOb.get("department");
-                            Integer deptId = departments.get(0);
+
+
                             User user=new User();
                             user.setId(String.valueOf(SnowFlake.nextId()));
                             user.setCompanyId(company.getId());
-                            System.out.println("now dept id is ==="+deptId);
-                            for (Integer department : departments) {
-                                Optional<DepartmentWx> first = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(department)).findFirst();
-                                if(first.isPresent()){
-                                    if(department.equals(deptId)){
-                                        user.setDepartmentId(first.get().getSysDeptid());
-                                        user.setDepartmentName(first.get().getName());
-                                        user.setCorpwxDeptid(first.get().getWxDeptid());
-                                        user.setDepartmentCascade(convertDepartmentIdToCascade(first.get().getSysDeptid(), departmentList));
+
+                            List<Integer> departments = (List<Integer>) userInfoOb.get("department");
+                            Integer deptId = null;
+                            if (departments.size() > 0) {
+                                deptId = departments.get(0);
+                                System.out.println("now dept id is ==="+deptId);
+                                for (Integer department : departments) {
+                                    Optional<DepartmentWx> first = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(department)).findFirst();
+                                    if(first.isPresent()){
+                                        if(department.equals(deptId)){
+                                            user.setDepartmentId(first.get().getSysDeptid());
+                                            user.setDepartmentName(first.get().getName());
+                                            user.setCorpwxDeptid(first.get().getWxDeptid());
+                                            user.setDepartmentCascade(convertDepartmentIdToCascade(first.get().getSysDeptid(), departmentList));
+                                        }
                                     }
                                 }
                             }
+
                             user.setCorpwxUserid(corpWxuserid)
                                 .setName(userName)
                                 .setRoleName(role.getRolename())