引入dingtalk jar包

This commit is contained in:
wulin 2020-08-12 16:24:46 +08:00
parent 2bd3bb4262
commit 4aa869abc3
3 changed files with 171 additions and 0 deletions

View File

@ -241,6 +241,12 @@
<version>1.7</version>
</dependency>
<dependency>
<artifactId>taobao-sdk-java-auto_1479188381469</artifactId>
<groupId>dingtalk</groupId>
<version>20200811</version>
</dependency>

View File

@ -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<String> 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<String> 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<DepartmentInfosBo> departmentInfosBos = feishuUtil.getDepartmentDetails(token, topDepartmentIds);
//更新数据库中的部门相关信息
departmentsService.updateDepartmentInfos(departmentInfosBos);
departmentsStaffRelateService.deleteAllRelates();
//未在飞书组织架构里的成员置为离职(全部置为离职再把在职的恢复)
staffOccupationService.updateAllOccupation();
//获取飞书部门对应的用户详情
for (DepartmentInfosBo departmentInfo : departmentInfosBos) {
//获取部门用户详情
List<DepartmentStaffBo> staffs = feishuUtil.getDepartmentStaffDetails(token, departmentInfo.getId());
logger.info("=============================" + departmentInfo.getName() + "================================");
// for (DepartmentStaffBo staff : staffs)
// logger.info(staff.getName());
//循环录入到员工信息表中
List<Long> staffIds = staffService.updateStaffsInfo(staffs);
//加入到部门和员工关系表
departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);
//录入员工职业信息表
enterStaffOccupationInfos(staffs);
}
}
public void enterStaffOccupationInfos(List<DepartmentStaffBo> staffs) {
List<StaffOccupationEntity> 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);
}
}
}

View File

@ -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());
}
}