diff --git a/pom.xml b/pom.xml
index de396bfa..c89bcee8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -241,6 +241,12 @@
1.7
+
+ taobao-sdk-java-auto_1479188381469
+ dingtalk
+ 20200811
+
+
diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java
new file mode 100644
index 00000000..3ac68039
--- /dev/null
+++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java
@@ -0,0 +1,123 @@
+package com.lz.modules.job.business;
+
+import com.google.common.collect.Lists;
+import com.lz.common.utils.DateUtils;
+import com.lz.common.utils.FeishuUtil;
+import com.lz.modules.app.entity.StaffEntity;
+import com.lz.modules.app.entity.StaffOccupationEntity;
+import com.lz.modules.app.service.DepartmentsService;
+import com.lz.modules.app.service.DepartmentsStaffRelateService;
+import com.lz.modules.app.service.StaffOccupationService;
+import com.lz.modules.app.service.StaffService;
+import com.lz.modules.job.model.responseBo.DepartmentInfosBo;
+import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author fumeiai
+ * @date 2019-05-29 17:06
+ * @Description 钉钉业务
+ * @注意 本内容仅限于杭州霖梓网络科技有限公司内部传阅,禁止外泄以及用于其他的商业目的
+ */
+@Component(value = "dingtalkBusiness")
+public class DingtalkBusiness {
+ protected final static org.slf4j.Logger logger = LoggerFactory.getLogger(DingtalkBusiness.class);
+
+ @Autowired
+ FeishuUtil feishuUtil;
+
+ @Resource
+ DepartmentsService departmentsService;
+
+ @Resource
+ DepartmentsStaffRelateService departmentsStaffRelateService;
+
+ @Resource
+ StaffService staffService;
+
+ @Resource
+ StaffOccupationService staffOccupationService;
+
+ /**
+ * 获取组织架构信息并录入到数据库
+ */
+// @DataSource(name = DataSourceNames.FOUR)
+ public void getFeishuDepartmentsIntoData() {
+ //获取Token
+ String token = feishuUtil.getAccessToken();
+
+ //获取通讯录授权范围:获取最高级架构的department_id
+ List departmentIds = feishuUtil.getDepartmentIds(token);
+
+ if (departmentIds == null || departmentIds.size() == 0) {
+ return;
+ }
+
+ //批量获取部门详情,根据详情填充部门信息
+ StringBuffer departmentIdSbs = new StringBuffer();
+ for (String departmentId : departmentIds) {
+ //获取子孙部门id列表
+ departmentIdSbs.append("department_ids=" + departmentId + "&");
+ List childDepartmentIds = feishuUtil.getChildDepartmentIds(token, departmentId);
+ for (String childDepartmentId : childDepartmentIds) {
+ departmentIdSbs.append("department_ids=" + childDepartmentId + "&");
+ }
+ }
+
+ String topDepartmentIds = departmentIdSbs.toString().substring(0, departmentIdSbs.toString().length() - 1);
+ //获取所有的部门详情
+ List departmentInfosBos = feishuUtil.getDepartmentDetails(token, topDepartmentIds);
+ //更新数据库中的部门相关信息
+ departmentsService.updateDepartmentInfos(departmentInfosBos);
+ departmentsStaffRelateService.deleteAllRelates();
+ //未在飞书组织架构里的成员,置为离职(全部置为离职,再把在职的恢复)
+ staffOccupationService.updateAllOccupation();
+ //获取飞书部门对应的用户详情
+ for (DepartmentInfosBo departmentInfo : departmentInfosBos) {
+ //获取部门用户详情
+ List staffs = feishuUtil.getDepartmentStaffDetails(token, departmentInfo.getId());
+ logger.info("=============================" + departmentInfo.getName() + "================================");
+// for (DepartmentStaffBo staff : staffs)
+// logger.info(staff.getName());
+ //循环录入到员工信息表中
+ List staffIds = staffService.updateStaffsInfo(staffs);
+
+ //加入到部门和员工关系表
+ departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);
+ //录入员工职业信息表
+ enterStaffOccupationInfos(staffs);
+
+ }
+
+ }
+
+ public void enterStaffOccupationInfos(List staffs) {
+ List StaffOccupations = Lists.newArrayList();
+ for (DepartmentStaffBo departmentStaffBo : staffs) {
+ StaffEntity staffEntity = staffService.getStaffInfoByOpenId(departmentStaffBo.getOpenId());
+ Long staffId = staffEntity.getId();
+ StaffOccupationEntity staffOccupationEntity = staffOccupationService.getStaffOccupationByStaffId(staffId);
+ if (staffOccupationEntity == null) {
+ StaffOccupationEntity staffOccupation = new StaffOccupationEntity();
+ staffOccupation.setStaffId(staffId);
+ staffOccupation.setEmployeeNo(departmentStaffBo.getEmployeeNo());
+ staffOccupation.setStaffType(departmentStaffBo.getEmployeeType());
+ staffOccupation.setStaffStatus(departmentStaffBo.getStatus());
+ staffOccupation.setEntryTime(DateUtils.getCurrentDate());
+ StaffOccupations.add(staffOccupation);
+ } else {
+ staffOccupationService.updateStatusByStaffId(staffId, departmentStaffBo.getStatus());
+ }
+ }
+ if (StaffOccupations.size() > 0) {
+ staffOccupationService.saveBatch(StaffOccupations);
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java b/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java
new file mode 100644
index 00000000..c92bd1c3
--- /dev/null
+++ b/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2020 fumeiai All rights reserved.
+ *
+ *
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.lz.modules.job.task;
+
+import com.lz.common.utils.DateUtils;
+import com.lz.modules.job.business.DingtalkBusiness;
+import com.lz.modules.job.business.FeishuBusiness;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 获取飞钉钉组织架构信息定时任务
+ *
+ * getFeishuDepartmentsJob为spring bean的名称
+ *
+ * @author fumeiai 20200429
+ */
+@Component("dingtalkSynDataJob")
+public class DingtalkSynDataJob implements ITask {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ DingtalkBusiness dingtalkBusiness;
+
+ @Override
+ public void run(String params) {
+
+ logger.info("dingtalkSynDataJob start date == {}", DateUtils.getCurrentDate());
+ dingtalkBusiness.getFeishuDepartmentsIntoData();
+ logger.info("dingtalkSynDataJob end date == {}", DateUtils.getCurrentDate());
+
+ }
+
+}