Przeglądaj źródła

钉钉主动获取激活的企业授权

QuYueTing 7 miesięcy temu
rodzic
commit
c6191e399a

+ 11 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/DingDingController.java

@@ -163,6 +163,17 @@ public class DingDingController {
     public HttpRespMsg reAuthCorp(String corpid) {
         return dingDingService.reAuthCorp(corpid);
     }
+    @RequestMapping("/getAuthInfo")
+    public HttpRespMsg getAuthInfo(String corpid) {
+        try {
+            return dingDingService.getAuthInfo(corpid);
+        } catch (Exception e) {
+            e.printStackTrace();
+            HttpRespMsg msg = new HttpRespMsg();
+            msg.setError(e.getMessage());
+            return msg;
+        }
+    }
 
     @RequestMapping("/pushLeaveAuditAlert")
     public HttpRespMsg pushLeaveAuditAlert(String userId) {

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/DingDingService.java

@@ -58,4 +58,6 @@ public interface DingDingService {
     String syncTranslation(String mediaId,String fileName,String unionId,CompanyDingding dingding) throws Exception;
 
     String getSyncTranslationResult(String jobId,CompanyDingding dingding) throws Exception;
+
+    HttpRespMsg getAuthInfo(String corpid) throws Exception;
 }

+ 54 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -5,6 +5,10 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.dingtalkcontact_1_0.Client;
 import com.aliyun.dingtalkcontact_1_0.models.GetUserHeaders;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAuthInfoHeaders;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAuthInfoRequest;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAuthInfoResponse;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAuthInfoResponseBody;
 import com.aliyun.tea.TeaConverter;
 import com.aliyun.tea.TeaException;
 import com.aliyun.tea.TeaPair;
@@ -958,7 +962,6 @@ public class DingDingServiceImpl implements DingDingService {
                 User upUser = new User();
                 upUser.setId(oldUser.getId());
                 boolean changed = false;
-
                 if (dingding.getContactNeedTranslate() == 0 && duser.getName() != null && (oldUser.getName() == null || !oldUser.getName().equals(duser.getName()))) {
                     upUser.setName(duser.getName());
                     changed = true;
@@ -2660,6 +2663,56 @@ public class DingDingServiceImpl implements DingDingService {
         }
         return null;
     }
+    public static com.aliyun.dingtalkoauth2_1_0.Client createAuthClient() throws Exception {
+        Config config = new Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        return new com.aliyun.dingtalkoauth2_1_0.Client(config);
+    }
+
+    @Override
+    public HttpRespMsg getAuthInfo(String corpid) throws Exception {
+        HttpRespMsg msg = new HttpRespMsg();
+//        java.util.List<String> args = java.util.Arrays.asList(args_);
+        com.aliyun.dingtalkoauth2_1_0.Client client = createAuthClient();
+        GetAuthInfoHeaders getAuthInfoHeaders = new GetAuthInfoHeaders();
+        getAuthInfoHeaders.xAcsDingtalkAccessToken = getDDSuiteAccessToken();
+        GetAuthInfoRequest getAuthInfoRequest = new GetAuthInfoRequest()
+                .setAuthCorpId(corpid);
+        try {
+            GetAuthInfoResponse authInfoWithOptions = client.getAuthInfoWithOptions(getAuthInfoRequest, getAuthInfoHeaders, new RuntimeOptions());
+            GetAuthInfoResponseBody body = authInfoWithOptions.body;
+            System.out.println("获取授权信息body=========="+body);
+            String authUserId = body.getAuthUserInfo().getUserId();
+            try {
+                String corpName = body.getAuthCorpInfo().corpName;
+
+                body.getAuthAppInfo().getAgentList().stream().filter(agent -> agent.agentName.equals("工时管家")).forEach(agent -> {
+                    try {
+                        corpAuth(corpid, corpName, authUserId, agent.agentId);
+                    } catch (ApiException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+            } catch (Exception e) {
+                e.printStackTrace();
+                msg.setError(e.getMessage());
+            }
+        } catch (TeaException err) {
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+                msg.setError(err.code+": " +err.message);
+            }
+
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+                msg.setError(err.code+": " +err.message);
+            }
+        }
+        return msg;
+    }
 
     private boolean judgeIsLeader(String userId) {
         int cnt = projectAuditorMapper.selectCount(new QueryWrapper<ProjectAuditor>().eq("auditor_id", userId));

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -5198,7 +5198,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                                 if (company.getId() == 469) {
                                     report.setState(0);//待审核员审核
                                     //赛元都是非项目,直接取员工所属部门的主要负责人来审核
-                                    Department department = departmentMapper.selectById(user.getDepartmentId());
+                                    Department department = departmentMapper.selectById(reportCreator.getDepartmentId());
                                     if (department != null) {
                                         report.setProjectAuditorId(department.getManagerId());
                                     }