From a36d93e531c292240dc59cb8e712b2eca21a4066 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 01 四月 2024 22:13:06 +0800
Subject: [PATCH] sync模块修复

---
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/sync/service/impl/DingSyncServiceImpl.java |  341 +++++++++++++++++++++++++-------------------------------
 1 files changed, 150 insertions(+), 191 deletions(-)

diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/sync/service/impl/DingSyncServiceImpl.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/sync/service/impl/DingSyncServiceImpl.java
index 9fe1ce5..4669c8d 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/sync/service/impl/DingSyncServiceImpl.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/sync/service/impl/DingSyncServiceImpl.java
@@ -1,7 +1,22 @@
 package com.qianwen.smartman.modules.sync.service.impl;
 
-import cn.hutool.core.lang.Snowflake;
-import cn.hutool.core.util.IdUtil;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.DefaultTransactionDefinition;
+
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.dingtalkcontact_1_0.models.GetUserHeaders;
@@ -9,45 +24,33 @@
 import com.aliyun.dingtalkoauth2_1_0.Client;
 import com.aliyun.teaopenapi.models.Config;
 import com.aliyun.teautil.models.RuntimeOptions;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.dingtalk.api.DefaultDingTalkClient;
 import com.dingtalk.api.request.OapiAuthScopesRequest;
+import com.dingtalk.api.request.OapiRoleListRequest;
 import com.dingtalk.api.request.OapiRoleSimplelistRequest;
 import com.dingtalk.api.request.OapiSnsGetuserinfoBycodeRequest;
 import com.dingtalk.api.request.OapiUserGetbyunionidRequest;
 import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
 import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
 import com.dingtalk.api.request.OapiV2UserGetRequest;
+import com.dingtalk.api.request.OapiV2UserListRequest;
 import com.dingtalk.api.response.OapiAuthScopesResponse;
+import com.dingtalk.api.response.OapiRoleListResponse;
 import com.dingtalk.api.response.OapiRoleSimplelistResponse;
 import com.dingtalk.api.response.OapiSnsGetuserinfoBycodeResponse;
 import com.dingtalk.api.response.OapiUserGetbyunionidResponse;
 import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
 import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.dingtalk.api.response.OapiV2UserGetResponse;
-import java.lang.invoke.SerializedLambda;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.qianwen.smartman.common.cache.RegionCache;
+import com.dingtalk.api.response.OapiV2UserListResponse;
+import com.qianwen.core.log.exception.ServiceException;
+import com.qianwen.core.tool.utils.Func;
+import com.qianwen.core.tool.utils.StringUtil;
 import com.qianwen.smartman.common.constant.CommonConstant;
 import com.qianwen.smartman.common.constant.CommonGroupConstant;
 import com.qianwen.smartman.common.enums.CommonGroupTypeEnum;
 import com.qianwen.smartman.common.utils.MessageUtils;
-import com.qianwen.core.log.exception.ServiceException;
-import com.qianwen.core.tool.utils.Func;
-import com.qianwen.core.tool.utils.StringUtil;
 import com.qianwen.smartman.modules.cps.entity.CommonGroup;
 import com.qianwen.smartman.modules.cps.entity.CommonGroupOfItem;
 import com.qianwen.smartman.modules.cps.entity.Employee;
@@ -73,11 +76,10 @@
 import com.qianwen.smartman.modules.system.service.IParamService;
 import com.qianwen.smartman.modules.system.service.IPostService;
 import com.qianwen.smartman.modules.system.service.IUserOauthService;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.TransactionStatus;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.transaction.support.DefaultTransactionDefinition;
+import com.taobao.api.TaobaoRequest;
+
+import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.util.IdUtil;
 
 @Service
 /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/DingSyncServiceImpl.class */
@@ -97,108 +99,6 @@
     private final IParamService paramService;
     private final IEmployeePostService employeePostService;
 
-    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
-        String implMethodName = lambda.getImplMethodName();
-        boolean z = true;
-        switch (implMethodName.hashCode()) {
-            case -75080655:
-                if (implMethodName.equals("getUuid")) {
-                    z = true;
-                    break;
-                }
-                break;
-            case 98245393:
-                if (implMethodName.equals("getId")) {
-                    z = true;
-                    break;
-                }
-                break;
-            case 242925765:
-                if (implMethodName.equals("getAppType")) {
-                    z = true;
-                    break;
-                }
-                break;
-            case 799509265:
-                if (implMethodName.equals("getSource")) {
-                    z = false;
-                    break;
-                }
-                break;
-            case 859984188:
-                if (implMethodName.equals("getUserId")) {
-                    z = true;
-                    break;
-                }
-                break;
-            case 1722789684:
-                if (implMethodName.equals("getLastSyncTime")) {
-                    z = true;
-                    break;
-                }
-                break;
-        }
-        switch (z) {
-            case false:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
-                    return (v0) -> {
-                        return v0.getSource();
-                    };
-                }
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
-                    return (v0) -> {
-                        return v0.getSource();
-                    };
-                }
-                break;
-            case true:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
-                    return (v0) -> {
-                        return v0.getUuid();
-                    };
-                }
-                break;
-            case true:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
-                    return (v0) -> {
-                        return v0.getId();
-                    };
-                }
-                break;
-            case true:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/sync/entity/OuterAppConfig") && lambda.getImplMethodSignature().equals("()Ljava/util/Date;")) {
-                    return (v0) -> {
-                        return v0.getLastSyncTime();
-                    };
-                }
-                break;
-            case true:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
-                    return (v0) -> {
-                        return v0.getUserId();
-                    };
-                }
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
-                    return (v0) -> {
-                        return v0.getUserId();
-                    };
-                }
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
-                    return (v0) -> {
-                        return v0.getUserId();
-                    };
-                }
-                break;
-            case RegionCache.VILLAGE_LEVEL /* 5 */:
-                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/sync/entity/OuterAppConfig") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
-                    return (v0) -> {
-                        return v0.getAppType();
-                    };
-                }
-                break;
-        }
-        throw new IllegalArgumentException("Invalid lambda deserialization");
-    }
 
     public DingSyncServiceImpl(final IUserOauthService userOauthService, final IEmployeeService employeeService, final IPostService postService, final ICommonGroupService groupService, final CommonGroupMapper commonGroupMapper, final IDingEventService dingEventService, final ICommonGroupOfItemService commonGroupOfItemService, final Map<String, Set<String>> userPostRelationMap, final DataSourceTransactionManager dataSourceTransactionManager, final PostMapper postMapper, final IOuterAppConfigService outerAppConfigService, final IParamService paramService, final IEmployeePostService employeePostService) {
         this.userOauthService = userOauthService;
@@ -218,36 +118,33 @@
 
     @Override // org.springblade.modules.sync.service.IDingSyncService
     public SyncResultVO syncImmediately() {
-        List<Post> posts;
-        List<DingOriDept> oriGroups;
-        List<DingOriUser> oriUsers;
-        List<Long> permissionGroups;
-        OuterAppConfig dingAppConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
+    	
+    	OuterAppConfig dingAppConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
         String appKey = dingAppConfig.getDingAppKey();
         String appSecret = dingAppConfig.getDingAppSecret();
         DefaultTransactionDefinition transDefinition = new DefaultTransactionDefinition();
+        
+    	List<Post> posts = new ArrayList<>();
+        List<DingOriDept> oriGroups = new ArrayList<>();
+        List<DingOriUser> oriUsers = new ArrayList<>();
+        
+        
+        
         TransactionStatus transStatus = this.dataSourceTransactionManager.getTransaction(transDefinition);
         SyncResultVO syncResultVO = new SyncResultVO();
         try {
-            try {
-                posts = new ArrayList<>();
-                oriGroups = new ArrayList<>();
-                oriUsers = new ArrayList<>();
-                getRoles(appKey, appSecret, posts, syncResultVO);
-                permissionGroups = getPermissionGroup(appKey, appSecret, syncResultVO);
-                if (Func.isEmpty(permissionGroups)) {
-                    syncResultVO.setGroupResult(false);
-                    syncResultVO.setUserReason("鏈幏鍙栧埌鏉冮檺鑼冨洿鍐呯殑缁勭粐鏈烘瀯锛�");
-                }
-                for (Long permissionGroup : permissionGroups) {
-                    SyncEmployee(permissionGroup, appKey, appSecret, oriUsers, syncResultVO);
-                    recursionGetGroup(permissionGroup, appKey, appSecret, oriGroups, oriUsers, syncResultVO, permissionGroups);
-                }
-            } catch (Exception e) {
-                log.error("鍚屾閽夐拤閫氳褰曞紓甯革紝寮傚父淇℃伅涓猴細", e);
-                this.dataSourceTransactionManager.rollback(transStatus);
-                this.userPostRelationMap.clear();
+            getRoles(appKey, appSecret, posts, syncResultVO);
+            
+            List<Long> permissionGroups = getPermissionGroup(appKey, appSecret, syncResultVO);
+            if (Func.isEmpty(permissionGroups)) {
+                syncResultVO.setGroupResult(false);
+                syncResultVO.setUserReason("鏈幏鍙栧埌鏉冮檺鑼冨洿鍐呯殑缁勭粐鏈烘瀯锛�");
             }
+            for (Long permissionGroup : permissionGroups) {
+                SyncEmployee(permissionGroup, appKey, appSecret, oriUsers, syncResultVO);
+                recursionGetGroup(permissionGroup, appKey, appSecret, oriGroups, oriUsers, syncResultVO, permissionGroups);
+            }
+           
             if (!syncResultVO.getGroupResult().booleanValue() || !syncResultVO.getPostResult().booleanValue() || !syncResultVO.getUserResult().booleanValue()) {
                 this.userPostRelationMap.clear();
                 return syncResultVO;
@@ -279,11 +176,13 @@
                 this.commonGroupMapper.removeOrgContact();
                 this.employeePostService.remove(Wrappers.lambdaQuery());
                 handleAuthAndEmployee(oriUsers, employees, userOauths, commonGroupOfItems, employeePosts, updateEmployees);
+                this.employeeService.remove(Wrappers.<Employee>lambdaQuery().notIn(Func.isNotEmpty(updateEmployees), Employee::getId, updateEmployees.stream().map(Employee::getId).collect(Collectors.toList())));
+                /*
                 this.employeeService.remove(Wrappers.lambdaQuery().notIn(Func.isNotEmpty(updateEmployees), (v0) -> {
                     return v0.getId();
                 }, (Collection) updateEmployees.stream().map((v0) -> {
                     return v0.getId();
-                }).collect(Collectors.toList())));
+                }).collect(Collectors.toList())));*/
                 this.employeeService.saveBatch(employees);
                 this.employeeService.updateBatchById(updateEmployees);
                 this.userOauthService.saveOrUpdateBatch(userOauths);
@@ -297,11 +196,14 @@
                 syncResultVO.setUserReason("鍚屾閽夐拤鍛樺伐鏁版嵁搴撻儴鍒嗘姤閿�:" + e4.toString());
             }
             if (syncResultVO.getGroupResult().booleanValue() && syncResultVO.getPostResult().booleanValue() && syncResultVO.getUserResult().booleanValue()) {
+            	this.outerAppConfigService.update(Wrappers.<OuterAppConfig>lambdaUpdate().eq(OuterAppConfig::getAppType, OuterAppConfigConstant.DING)
+            			.set(OuterAppConfig::getLastSyncTime, new Date())); 
+            	/*
                 this.outerAppConfigService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
                     return v0.getAppType();
                 }, OuterAppConfigConstant.DING)).set((v0) -> {
                     return v0.getLastSyncTime();
-                }, new Date()));
+                }, new Date()));*/
             }
             if (flag.booleanValue()) {
                 this.dataSourceTransactionManager.commit(transStatus);
@@ -310,10 +212,16 @@
             }
             this.userPostRelationMap.clear();
             return syncResultVO;
-        } catch (Throwable th) {
-            this.userPostRelationMap.clear();
-            throw th;
+        } catch (Exception th) {
+        	log.error("鍚屾閽夐拤閫氳褰曞紓甯革紝寮傚父淇℃伅涓猴細", th);
+        	this.dataSourceTransactionManager.rollback(transStatus);
+            
+            //throw th;
+        }finally {
+        	this.userPostRelationMap.clear();
         }
+        
+        return syncResultVO;
     }
 
     private List<Long> getPermissionGroup(String appKey, String appSecret, SyncResultVO syncResultVO) {
@@ -351,9 +259,11 @@
                 userObject = getDetailByUserId(userId, appKey, appSecret);
             }
             if (Func.isNotEmpty(userId) && Func.isNotEmpty(userObject)) {
+            	UserOauth userOauth = this.userOauthService.getOne(Wrappers.<UserOauth>lambdaQuery().eq(UserOauth::getUuid, userId), false);
+            	/*
                 UserOauth userOauth = (UserOauth) this.userOauthService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                     return v0.getUuid();
-                }, userId), false);
+                }, userId), false);*/
                 if (Func.isEmpty(userOauth)) {
                     throw new ServiceException(MessageUtils.message("sys.outer.user.not.exist", new Object[0]));
                 }
@@ -373,21 +283,27 @@
 
     @Override // org.springblade.modules.sync.service.IDingSyncService
     public Boolean unbind(Long id, String source) {
+    	UserOauth userOauth = this.userOauthService.getOne(Wrappers.<UserOauth>lambdaQuery().eq(UserOauth::getUserId, id).eq(UserOauth::getSource, source));
+    	/*
         UserOauth userOauth = (UserOauth) this.userOauthService.getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
             return v0.getUserId();
         }, id)).eq((v0) -> {
             return v0.getSource();
-        }, source));
+        }, source));*/
         if (Func.isEmpty(userOauth)) {
             throw new ServiceException(MessageUtils.message("cps.employee.not.band", new Object[0]));
         }
+        
+        return Boolean.valueOf(this.userOauthService.update(Wrappers.<UserOauth>lambdaUpdate()
+        		.set(UserOauth::getUserId, null).eq(UserOauth::getUserId, id).eq(UserOauth::getSource, source)));
+        /*
         return Boolean.valueOf(this.userOauthService.update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
             return v0.getUserId();
         }, (Object) null)).eq((v0) -> {
             return v0.getUserId();
         }, id)).eq((v0) -> {
             return v0.getSource();
-        }, source)));
+        }, source)));*/
     }
 
     @Override // org.springblade.modules.sync.service.IDingSyncService
@@ -467,13 +383,15 @@
         if (Func.isNotEmpty(oriUsers)) {
             String pinValue = this.paramService.getValue("employee.default.pin");
             List<Employee> dbEmployees = this.employeeService.list();
-            Map<String, Employee> employeeMap = (Map) dbEmployees.parallelStream().filter(o -> {
+            
+            
+            Map<String, Employee> employeeMap = dbEmployees.parallelStream().filter(o -> {
                 return Func.isNotEmpty(o.getTel());
             }).collect(Collectors.toMap((v0) -> {
                 return v0.getTel();
             }, e -> {
                 return e;
-            }, k1, k2 -> {
+            }, (k1, k2) -> {
                 return k1;
             }));
             Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
@@ -580,21 +498,47 @@
         }
     }
 
-    /* JADX WARN: Code restructure failed: missing block: B:20:0x0161, code lost:
-        r10.setPostResult(false);
-        r10.setPostReason("鍚屾閽夐拤瑙掕壊寮傚父锛岀粨鏋滀负锛�" + r0 + "---------鍙傛暟涓猴細" + r0);
-     */
-    /*
-        Code decompiled incorrectly, please refer to instructions dump.
-        To view partially-correct code enable 'Show inconsistent code' option in preferences
-    */
-    private void getRoles(java.lang.String r7, java.lang.String r8, java.util.List<org.springblade.modules.system.entity.Post> r9, org.springblade.modules.sync.vo.SyncResultVO r10) {
-        /*
-            Method dump skipped, instructions count: 448
-            To view this dump change 'Code comments level' option to 'DEBUG'
-        */
-        throw new UnsupportedOperationException("Method not decompiled: org.springblade.modules.sync.service.impl.DingSyncServiceImpl.getRoles(java.lang.String, java.lang.String, java.util.List, org.springblade.modules.sync.vo.SyncResultVO):void");
-    }
+    private void getRoles(String appKey, String appSecret, List<Post> postList, SyncResultVO syncResultVO) {
+        try {
+          DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list");
+          OapiRoleListRequest req = new OapiRoleListRequest();
+          req.setSize(DingConstant.ROLE_SIZE);
+          req.setOffset(DingConstant.START_OFFSET);
+          while (true) {
+            OapiRoleListResponse rsp = (OapiRoleListResponse)defaultDingTalkClient.execute((TaobaoRequest)req, this.dingEventService.getDingAccessToken(appKey, appSecret));
+            JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
+            if (jsonObject.getInteger("errcode").equals(DingConstant.SUCCESS)) {
+              Map<String, Object> resultMap = (Map<String, Object>)jsonObject.get("result");
+              List<Map<String, Object>> resultList = (List<Map<String, Object>>)resultMap.get("list");
+              if (Func.isNotEmpty(resultList))
+                for (Map<String, Object> roleGroupMap : resultList) {
+                  List<Map<String, Object>> roleList = (List<Map<String, Object>>)roleGroupMap.get("roles");
+                  if (Func.isNotEmpty(roleList))
+                    for (Map<String, Object> role : roleList) {
+                      Post post = new Post();
+                      post.setPostCode(String.valueOf(role.get("id")));
+                      post.setId(Long.valueOf(String.valueOf(role.get("id"))));
+                      post.setPostName(String.valueOf(role.get("name")));
+                      post.setStatus(CommonConstant.ENABLE);
+                      postList.add(post);
+                      getRoleContainsUser(post.getPostCode(), appKey, appSecret);
+                    }  
+                }  
+              if (((Boolean)resultMap.get("hasMore")).booleanValue()) {
+                req.setOffset(Long.valueOf(req.getOffset().longValue() + DingConstant.ROLE_SIZE.longValue()));
+                continue;
+              } 
+              break;
+            } 
+            syncResultVO.setPostResult(Boolean.valueOf(false));
+            syncResultVO.setPostReason("鍚屾閽夐拤瑙掕壊寮傚父锛岀粨鏋滀负锛�" + jsonObject + "---------鍙傛暟涓猴細" + req);
+            break;
+          } 
+        } catch (Exception e) {
+          syncResultVO.setPostResult(Boolean.valueOf(false));
+          syncResultVO.setPostReason("鍚屾閽夐拤瑙掕壊鎶ラ敊:" + e.toString());
+        } 
+      }
 
     private void getRoleContainsUser(String postCode, String appKey, String appSecret) throws Exception {
         DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/simplelist");
@@ -666,21 +610,36 @@
         }
     }
 
-    /* JADX WARN: Code restructure failed: missing block: B:15:0x00cb, code lost:
-        r11.setUserResult(false);
-        r11.setUserReason("鍚屾閽夐拤鐢ㄦ埛寮傚父锛岀粨鏋滀负锛�" + r0 + "---------鍙傛暟涓猴細" + r0);
-     */
-    /*
-        Code decompiled incorrectly, please refer to instructions dump.
-        To view partially-correct code enable 'Show inconsistent code' option in preferences
-    */
-    private void SyncEmployee(java.lang.Long r7, java.lang.String r8, java.lang.String r9, java.util.List<org.springblade.modules.sync.entity.DingOriUser> r10, org.springblade.modules.sync.vo.SyncResultVO r11) {
-        /*
-            Method dump skipped, instructions count: 298
-            To view this dump change 'Code comments level' option to 'DEBUG'
-        */
-        throw new UnsupportedOperationException("Method not decompiled: org.springblade.modules.sync.service.impl.DingSyncServiceImpl.SyncEmployee(java.lang.Long, java.lang.String, java.lang.String, java.util.List, org.springblade.modules.sync.vo.SyncResultVO):void");
-    }
+    private void SyncEmployee(Long deptId, String appKey, String appSecret, List<DingOriUser> oriUsers, SyncResultVO syncResultVO) {
+        try {
+          DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
+          OapiV2UserListRequest req = new OapiV2UserListRequest();
+          req.setSize(DingConstant.SIZE);
+          req.setDeptId(Long.valueOf(deptId.equals(Long.valueOf(3L)) ? 1L : deptId.longValue()));
+          req.setCursor(DingConstant.START_OFFSET);
+          while (true) {
+            OapiV2UserListResponse rsp = (OapiV2UserListResponse)defaultDingTalkClient.execute((TaobaoRequest)req, this.dingEventService.getDingAccessToken(appKey, appSecret));
+            JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
+            if (jsonObject.getInteger("errcode").equals(DingConstant.SUCCESS)) {
+              JSONObject resultMap = jsonObject.getJSONObject("result");
+              List<DingOriUser> resultList = resultMap.getJSONArray("list").toJavaList(DingOriUser.class);
+              if (Func.isNotEmpty(resultList))
+                resultList.forEach(userMap -> oriUsers.add(userMap)); 
+              if (((Boolean)resultMap.get("has_more")).booleanValue()) {
+                req.setCursor(Long.valueOf(String.valueOf(resultMap.get("next_cursor"))));
+                continue;
+              } 
+              break;
+            } 
+            syncResultVO.setUserResult(Boolean.valueOf(false));
+            syncResultVO.setUserReason("鍚屾閽夐拤鐢ㄦ埛寮傚父锛岀粨鏋滀负锛�" + jsonObject + "---------鍙傛暟涓猴細" + req);
+            break;
+          } 
+        } catch (Exception e) {
+          syncResultVO.setUserResult(Boolean.valueOf(false));
+          syncResultVO.setUserReason("鍚屾閽夐拤鐢ㄦ埛鎶ラ敊:" + e.toString());
+        } 
+      }
 
     public static Client authClient() throws Exception {
         Config config = new Config();

--
Gitblit v1.9.3