|
@@ -2,20 +2,28 @@ package com.fjhx.dingding.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
|
|
import com.fjhx.dingding.entity.suite.po.SuiteTicketInfo;
|
|
|
import com.fjhx.dingding.service.DingService;
|
|
|
import com.fjhx.dingding.service.suite.SuiteTicketInfoService;
|
|
|
+import com.fjhx.dingding.utils.DingUtil;
|
|
|
import com.fjhx.tenant.entity.tenant.po.TenantInfo;
|
|
|
import com.fjhx.tenant.service.tenant.impl.TenantInfoServiceImpl;
|
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -35,6 +43,9 @@ public class DingServiceImpl implements DingService {
|
|
|
@Autowired
|
|
|
private TransactionDefinition transactionDefinition;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+
|
|
|
/**
|
|
|
* https://open.dingtalk.com/document/isvapp/data-formats
|
|
|
*/
|
|
@@ -58,6 +69,24 @@ public class DingServiceImpl implements DingService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void pushHigh(JSONObject callBackContent) {
|
|
|
+ JSONArray bizData = callBackContent.getJSONArray("bizData");
|
|
|
+
|
|
|
+ for (JSONObject jsonObject : bizData.toJavaList(JSONObject.class)) {
|
|
|
+
|
|
|
+ switch (jsonObject.getInteger("biz_type")) {
|
|
|
+
|
|
|
+ case 2:
|
|
|
+ saveSuiteTicketInfo(jsonObject);
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 企业授权
|
|
@@ -144,6 +173,7 @@ public class DingServiceImpl implements DingService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // 创建租户
|
|
|
TenantInfo tenantInfo = new TenantInfo();
|
|
|
tenantInfo.setTenantId(tenantId);
|
|
|
tenantInfo.setEnterpriseName(corpName);
|
|
@@ -151,15 +181,16 @@ public class DingServiceImpl implements DingService {
|
|
|
tenantInfo.setFlowStatus(2);
|
|
|
tenantInfo.setCorpid(corpid);
|
|
|
|
|
|
- TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ // 创建部门
|
|
|
+ ArrayList<SysDept> deptList = new ArrayList<>();
|
|
|
+ addDeptList(corpid, deptList, tenantId, 1L, 0L);
|
|
|
|
|
|
+ TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
|
// 保存租户
|
|
|
tenantInfoService.save(tenantInfo);
|
|
|
-
|
|
|
+ // 保存部门
|
|
|
+ sysDeptService.saveBatch(deptList);
|
|
|
// 提交事务
|
|
|
platformTransactionManager.commit(transactionStatus);
|
|
|
} catch (Exception e) {
|
|
@@ -167,7 +198,35 @@ public class DingServiceImpl implements DingService {
|
|
|
platformTransactionManager.rollback(transactionStatus);
|
|
|
throw new ServiceException("保存数据失败");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加部门列表
|
|
|
+ */
|
|
|
+ private void addDeptList(String corpid, List<SysDept> deptList, String tenantId, Long dingParentId, Long myParentId) {
|
|
|
+
|
|
|
+ List<OapiV2DepartmentListsubResponse.DeptBaseResponse> tempDeptList = DingUtil.getDeptList(corpid, dingParentId);
|
|
|
+
|
|
|
+ if (tempDeptList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OapiV2DepartmentListsubResponse.DeptBaseResponse deptBaseResponse : tempDeptList) {
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
+ sysDept.setDeptId(IdWorker.getId());
|
|
|
+ sysDept.setParentId(myParentId);
|
|
|
+ sysDept.setDeptName(deptBaseResponse.getName());
|
|
|
+ sysDept.setOrderNum(1);
|
|
|
+ sysDept.setStatus("0");
|
|
|
+ sysDept.setType(0);
|
|
|
+ sysDept.setTenantId(tenantId);
|
|
|
+ sysDept.setCreateTime(new Date());
|
|
|
+ sysDept.setDingDeptId(deptBaseResponse.getDeptId());
|
|
|
+
|
|
|
+ deptList.add(sysDept);
|
|
|
+
|
|
|
+ addDeptList(corpid, deptList, tenantId, deptBaseResponse.getDeptId(), sysDept.getDeptId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|