增加同步离职人员信息
This commit is contained in:
parent
e6202146b0
commit
006bf38407
@ -280,7 +280,7 @@ public class DingTalkUtil {
|
||||
* @param accessToken
|
||||
* @return
|
||||
*/
|
||||
public List<DepartmentStaffBo> getDepartmentStaffDetailsV2(String accessToken, String departmentId) {
|
||||
public List<DepartmentStaffBo> getDepartmentStaffDetailsV2(String accessToken, String departmentId, Map<String, String> mapProbation) {
|
||||
try {
|
||||
long page = 0L;
|
||||
List<DepartmentStaffBo> list =new ArrayList<>();
|
||||
@ -324,6 +324,11 @@ public class DingTalkUtil {
|
||||
departmentStaffBo.setEmail(json.getString("email"));//邮箱,钉钉的企业邮箱才可以,需要单独授权手机权限
|
||||
departmentStaffBo.setAvatar(json.getString("avatar"));//头像
|
||||
departmentStaffBo.setPosition(json.getString("title"));
|
||||
if(mapProbation.containsKey(departmentStaffBo.getEmployeeId())){
|
||||
departmentStaffBo.setEmployeeType(2);
|
||||
}else{
|
||||
departmentStaffBo.setEmployeeType(1);
|
||||
}
|
||||
departmentStaffBo.setStatus(0);
|
||||
/*if(json.getBoolean("active")){
|
||||
//在职已激活
|
||||
|
||||
@ -6,8 +6,10 @@ import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiRoleListRequest;
|
||||
import com.dingtalk.api.request.OapiRoleSimplelistRequest;
|
||||
import com.dingtalk.api.request.OapiSmartworkHrmEmployeeQueryonjobRequest;
|
||||
import com.dingtalk.api.response.OapiRoleListResponse;
|
||||
import com.dingtalk.api.response.OapiRoleSimplelistResponse;
|
||||
import com.dingtalk.api.response.OapiSmartworkHrmEmployeeQueryonjobResponse;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.DateUtils;
|
||||
@ -47,10 +49,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -195,6 +194,9 @@ public class DingtalkBusiness {
|
||||
List<DepartmentInfosBo> departmentInfosBos = dingTalkUtil.getDepartmentDetailsV2(token, "1");
|
||||
|
||||
if(departmentInfosBos.size() > 0){
|
||||
List<String> probationUserIDS = getProbationStaff(token);//获取试用期人员信息
|
||||
Map<String, String> mapProbation =
|
||||
probationUserIDS.stream().collect(Collectors.toMap(String::toString, Function.identity(), (e, r) -> e));
|
||||
//获取原有部门信息
|
||||
Map<String, DepartmentInfosBo> mapDepartmentInfosBos
|
||||
= departmentInfosBos.stream().collect(Collectors.toMap(DepartmentInfosBo::getId, Function.identity(), (e, r) -> e));
|
||||
@ -251,7 +253,7 @@ public class DingtalkBusiness {
|
||||
}
|
||||
|
||||
//获取部门用户详情
|
||||
List<DepartmentStaffBo> staffs = dingTalkUtil.getDepartmentStaffDetailsV2(token, departmentInfo.getId());
|
||||
List<DepartmentStaffBo> staffs = dingTalkUtil.getDepartmentStaffDetailsV2(token, departmentInfo.getId(), mapProbation);
|
||||
logger.info("=============================" + departmentInfo.getName() + "================================");
|
||||
//设置本部门人数
|
||||
if(departmentInfo.getMemberCount() == null){
|
||||
@ -466,6 +468,7 @@ public class DingtalkBusiness {
|
||||
|
||||
if(addStaffs.size() > 0){//有新增部门
|
||||
logger.info("新增人员信息个数{}", addStaffs.size());
|
||||
|
||||
staffService.saveBatch(addStaffs);
|
||||
String key;
|
||||
for (StaffEntity entity:addStaffs
|
||||
@ -495,6 +498,8 @@ public class DingtalkBusiness {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(updateStaffs.size() > 0){//有新增部门
|
||||
logger.info("更新人员信息个数{}", updateStaffs.size());
|
||||
staffService.updateBatchById(updateStaffs);
|
||||
@ -559,6 +564,41 @@ public class DingtalkBusiness {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getProbationStaff(String token){
|
||||
//获取试用期员工信息
|
||||
|
||||
try {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob");
|
||||
OapiSmartworkHrmEmployeeQueryonjobRequest req = new OapiSmartworkHrmEmployeeQueryonjobRequest();
|
||||
Long offSet = 0L;
|
||||
req.setStatusList("2");
|
||||
req.setSize(50L);
|
||||
boolean isNext = false;
|
||||
List<String> ids = new ArrayList<>();
|
||||
{
|
||||
req.setOffset(offSet);
|
||||
OapiSmartworkHrmEmployeeQueryonjobResponse rsp = client.execute(req, token);
|
||||
logger.info("钉钉请求试用期员工返回信息{}", rsp.getBody());
|
||||
JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
|
||||
if(jsonObject.getIntValue("errcode") == 0){
|
||||
jsonObject = jsonObject.getJSONObject("result");
|
||||
offSet = jsonObject.getLong("next_cursor");
|
||||
if(offSet != null){
|
||||
isNext = true;
|
||||
}
|
||||
JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("data_list"));
|
||||
ids.addAll(Arrays.stream(jsonArray.toArray(new String[jsonArray.size()])).collect(Collectors.toList()));
|
||||
}else{
|
||||
logger.info("钉钉请求返回错误{}", jsonObject);
|
||||
}
|
||||
}while(isNext)
|
||||
return ids;
|
||||
|
||||
} catch (ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void enterStaffOccupationInfos(List<DepartmentStaffBo> staffs) {
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.lz.mysql;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lz.common.utils.StringUtil;
|
||||
import com.lz.modules.flow.entity.FlowChartRole;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
@ -65,51 +67,7 @@ public class MysqlMain {
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
/*Long a = 2l;
|
||||
Long b = 3l;
|
||||
String value = "aaa";
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start("测试静态方法");
|
||||
for(int i = 0; i < 10000; i++){
|
||||
if(TestStaticAndHuo.isEmpt(value)){
|
||||
|
||||
}
|
||||
}
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("测试对象方法");
|
||||
for(int i = 0; i < 10000; i++){
|
||||
if(value == null || value.length() == 0){
|
||||
|
||||
}
|
||||
}
|
||||
stopWatch.stop();
|
||||
|
||||
System.out.println(stopWatch.prettyPrint());*/
|
||||
|
||||
/*List<TestMap> testMaps = new ArrayList<>();
|
||||
TestMap test = new TestMap();
|
||||
test.setName("123");
|
||||
test.setMobile("18969093321");
|
||||
testMaps.add(test);
|
||||
|
||||
test = new TestMap();
|
||||
test.setName("123");
|
||||
test.setMobile("18969093321");
|
||||
testMaps.add(test);
|
||||
|
||||
Map<String, TestMap> t = testMaps.stream().collect(Collectors.toMap(TestMap::getName, testMap -> testMap));
|
||||
List<Long> flowChartRoles = new ArrayList<>();
|
||||
flowChartRoles.add(1L);
|
||||
flowChartRoles.add(2L);
|
||||
flowChartRoles.add(3L);
|
||||
flowChartRoles.add(4L);
|
||||
String roles = flowChartRoles.stream().map(new Function<Long, String>() {
|
||||
@Override
|
||||
public String apply(Long flowChartRole) {
|
||||
return flowChartRole.toString();
|
||||
}
|
||||
}).collect(Collectors.joining(","));*/
|
||||
|
||||
String path = ResourceUtils.getURL("classpath:").getPath();
|
||||
System.out.println(path);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user