|
@@ -2,10 +2,13 @@ package com.fjhx.dingding.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.dingding.entity.suite.po.SuiteTicketInfo;
|
|
|
import com.fjhx.dingding.service.DingService;
|
|
|
import com.fjhx.dingding.service.suite.SuiteTicketInfoService;
|
|
@@ -16,6 +19,7 @@ import com.ruoyi.common.constant.StatusConstant;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
@@ -27,10 +31,10 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DingServiceImpl implements DingService {
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
private SuiteTicketInfoService suiteTicketInfoService;
|
|
|
|
|
@@ -54,19 +58,6 @@ public class DingServiceImpl implements DingService {
|
|
|
|
|
|
JSONObject bizData = callBackContent.getJSONObject("bizData");
|
|
|
|
|
|
- switch (bizData.getInteger("biz_type")) {
|
|
|
-
|
|
|
- case 2:
|
|
|
- saveSuiteTicketInfo(bizData);
|
|
|
- break;
|
|
|
-
|
|
|
- case 4:
|
|
|
- corpAuthorization(bizData);
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -81,12 +72,19 @@ public class DingServiceImpl implements DingService {
|
|
|
saveSuiteTicketInfo(jsonObject);
|
|
|
break;
|
|
|
|
|
|
+ case 4:
|
|
|
+ corpAuthorization(jsonObject);
|
|
|
+ break;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println("{\"auth_user_info\":{\"userId\":\"manager7560\"},\"eventId\":\"b542e727bad741d6b16de878676c363e\",\"auth_corp_info\":{\"corp_type\":0,\"corpid\":\"ding3f327504d104ac1cf2c783f7214b6d69\",\"auth_level\":0,\"corp_city\":\"福州\",\"auth_channel\":\"4\",\"industry\":\"计算机软件\",\"full_corp_name\":\"hf测试\",\"corp_name\":\"hf测试\",\"corp_province\":\"福建\",\"is_ecological_corp\":false,\"invite_url\":\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&corpId=ding3f327504d104ac1cf2c783f7214b6d69&inviteCode=i8yWYDEytZJIkIa\",\"auth_channel_type\":\"\",\"corp_type_v2\":0,\"invite_code\":\"\",\"is_authenticated\":false,\"license_code\":\"\",\"corp_logo_url\":\"\"},\"syncAction\":\"org_suite_auth\",\"auth_scope\":{\"errcode\":0,\"condition_field\":[],\"auth_user_field\":[\"jobnumber\",\"isLeader\",\"name\",\"isAdmin\",\"avatar\",\"position\",\"department\",\"userid\",\"deviceId\",\"isHide\"],\"auth_org_scopes\":{\"authed_user\":[],\"authed_dept\":[1]},\"errmsg\":\"ok\"},\"auth_info\":{\"agent\":[{\"agentid\":2581273014,\"agent_name\":\"byteSailing_test\",\"logo_url\":\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\",\"appid\":131175,\"use_app_role\":false,\"admin_list\":[\"manager7560\"]}]},\"permanent_code\":\"caY2fuNclujXwRXlDOuctE-4HlOY6hWfgBTnMDbOaCPGQ-yzWQBxE6-axKq9XSJy\",\"syncSeq\":\"8F4DD3DFE04AA32FF1E6B2AE55\"}");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 企业授权
|
|
@@ -95,14 +93,17 @@ public class DingServiceImpl implements DingService {
|
|
|
*/
|
|
|
private void corpAuthorization(JSONObject bizData) {
|
|
|
|
|
|
- String syncAction = bizData.getString("syncAction");
|
|
|
+ String itemBizDataStr = bizData.getString("biz_data");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(itemBizDataStr);
|
|
|
+
|
|
|
+ String syncAction = jsonObject.getString("syncAction");
|
|
|
|
|
|
switch (syncAction) {
|
|
|
|
|
|
// 企业授权
|
|
|
case "org_suite_auth":
|
|
|
|
|
|
- orgSuiteAuth(bizData);
|
|
|
+ orgSuiteAuth(jsonObject);
|
|
|
break;
|
|
|
|
|
|
// 企业变更授权范围
|
|
@@ -142,6 +143,8 @@ public class DingServiceImpl implements DingService {
|
|
|
* 企业授权
|
|
|
*/
|
|
|
private void orgSuiteAuth(JSONObject bizData) {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+
|
|
|
JSONObject authCorpInfo = bizData.getJSONObject("auth_corp_info");
|
|
|
|
|
|
// 企业id
|
|
@@ -186,14 +189,20 @@ public class DingServiceImpl implements DingService {
|
|
|
ArrayList<SysDept> deptList = new ArrayList<>();
|
|
|
addDeptList(corpid, deptList, tenantId, 1L, 0L);
|
|
|
|
|
|
+ log.info("钉钉回调创建租户,tenantInfo:{}", JSON.toJSONString(tenantInfo));
|
|
|
+ log.info("钉钉回调创建部门,deptList:{}", JSON.toJSONString(deptList));
|
|
|
+
|
|
|
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
|
+
|
|
|
// 保存租户
|
|
|
tenantInfoService.save(tenantInfo);
|
|
|
// 保存部门
|
|
|
sysDeptService.saveBatch(deptList);
|
|
|
// 提交事务
|
|
|
platformTransactionManager.commit(transactionStatus);
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
} catch (Exception e) {
|
|
|
// 回滚事务
|
|
|
platformTransactionManager.rollback(transactionStatus);
|