|
@@ -3,16 +3,18 @@
|
|
*/
|
|
*/
|
|
package com.jeeplus.human.enrollment.enrollmentRegistration.utils;
|
|
package com.jeeplus.human.enrollment.enrollmentRegistration.utils;
|
|
|
|
|
|
|
|
+import com.aliyun.dingtalkhrm_1_0.models.GetAllDismissionReasonsResponse;
|
|
|
|
+import com.aliyun.dingtalkhrm_1_0.models.GetAllDismissionReasonsResponseBody;
|
|
|
|
+import com.aliyun.tea.TeaException;
|
|
|
|
+import com.aliyun.teautil.models.RuntimeOptions;
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
import com.dingtalk.api.DingTalkClient;
|
|
import com.dingtalk.api.DingTalkClient;
|
|
import com.dingtalk.api.request.*;
|
|
import com.dingtalk.api.request.*;
|
|
import com.dingtalk.api.response.*;
|
|
import com.dingtalk.api.response.*;
|
|
import com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.DingTalkUserDTO;
|
|
import com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.DingTalkUserDTO;
|
|
-
|
|
|
|
import com.taobao.api.ApiException;
|
|
import com.taobao.api.ApiException;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
-
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -39,6 +41,15 @@ public class DingTalkUtils {
|
|
@Value("${dingtalk.assessAppSecret}")
|
|
@Value("${dingtalk.assessAppSecret}")
|
|
private String assessAppSecret;
|
|
private String assessAppSecret;
|
|
|
|
|
|
|
|
+ @Value("${dingtalk.dingAdminId}")
|
|
|
|
+ private String dingAdminId;//钉钉管理员ID
|
|
|
|
+
|
|
|
|
+ public static com.aliyun.dingtalkhrm_1_0.Client createClient() throws Exception {
|
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
|
+ config.protocol = "https";
|
|
|
|
+ config.regionId = "central";
|
|
|
|
+ return new com.aliyun.dingtalkhrm_1_0.Client(config);
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 获取钉钉token
|
|
* 获取钉钉token
|
|
*/
|
|
*/
|
|
@@ -191,5 +202,129 @@ public class DingTalkUtils {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 将钉钉用户添加至待离职状态
|
|
|
|
+ * @param userDTO
|
|
|
|
+ * @param tenantId
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public Boolean userPendingResignation(DingTalkUserDTO userDTO,Long lastWorkDate,String tenantId) throws Exception {
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.Client client = DingTalkUtils.createClient();
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.EmpStartDismissionHeaders empStartDismissionHeaders = new com.aliyun.dingtalkhrm_1_0.models.EmpStartDismissionHeaders();
|
|
|
|
+ empStartDismissionHeaders.xAcsDingtalkAccessToken = getToken(tenantId);
|
|
|
|
+ //获取离职原因
|
|
|
|
+ String reasonLeaving = getReasonLeaving(tenantId);
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.EmpStartDismissionRequest empStartDismissionRequest = new com.aliyun.dingtalkhrm_1_0.models.EmpStartDismissionRequest()
|
|
|
|
+ .setTerminationReasonVoluntary(java.util.Arrays.asList(
|
|
|
|
+ reasonLeaving
|
|
|
|
+ )) // 离职原因 默认其他
|
|
|
|
+ .setPartner(false) //是否不计入人事统计
|
|
|
|
+ .setLastWorkDate(lastWorkDate)//离职日期
|
|
|
|
+ .setToHireDismissionTalent(false) //是否保存至招聘人才库
|
|
|
|
+ .setToHireBlackList(false) //是否加入招聘黑名单
|
|
|
|
+ .setUserId(userDTO.getUserid()) // 离职员工的id
|
|
|
|
+ .setToHrmBlackList(false);//是否加入人事黑名单
|
|
|
|
+ try {
|
|
|
|
+ client.empStartDismissionWithOptions(empStartDismissionRequest, empStartDismissionHeaders, new com.aliyun.teautil.models.RuntimeOptions());
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 撤销用户待离职状态
|
|
|
|
+ * @param userDTO
|
|
|
|
+ * @param tenantId
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public Boolean revokeUserPendingResignation(DingTalkUserDTO userDTO,String tenantId) throws Exception {
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.Client client = DingTalkUtils.createClient();
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.RevokeTerminationHeaders revokeTerminationHeaders = new com.aliyun.dingtalkhrm_1_0.models.RevokeTerminationHeaders();
|
|
|
|
+ revokeTerminationHeaders.xAcsDingtalkAccessToken = getToken(tenantId);
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.RevokeTerminationRequest revokeTerminationRequest = new com.aliyun.dingtalkhrm_1_0.models.RevokeTerminationRequest()
|
|
|
|
+ .setUserId(userDTO.getUserid());
|
|
|
|
+ try {
|
|
|
|
+ client.revokeTerminationWithOptions(revokeTerminationRequest, revokeTerminationHeaders, new com.aliyun.teautil.models.RuntimeOptions());
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取离职原因(默认返回 其他 )
|
|
|
|
+ * @param tenantId
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public String getReasonLeaving(String tenantId) throws Exception {
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.Client client = DingTalkUtils.createClient();
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.GetAllDismissionReasonsHeaders getAllDismissionReasonsHeaders = new com.aliyun.dingtalkhrm_1_0.models.GetAllDismissionReasonsHeaders();
|
|
|
|
+ getAllDismissionReasonsHeaders.xAcsDingtalkAccessToken = getToken(tenantId);
|
|
|
|
+ GetAllDismissionReasonsResponseBody.GetAllDismissionReasonsResponseBodyResult result = null;
|
|
|
|
+ try {
|
|
|
|
+ GetAllDismissionReasonsResponse allDismissionReasonsWithOptions = client.getAllDismissionReasonsWithOptions(getAllDismissionReasonsHeaders, new RuntimeOptions());
|
|
|
|
+ result = allDismissionReasonsWithOptions.getBody().getResult();
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<GetAllDismissionReasonsResponseBody.GetAllDismissionReasonsResponseBodyResultVoluntaryList> voluntaryList = result.getVoluntaryList();
|
|
|
|
+ GetAllDismissionReasonsResponseBody.GetAllDismissionReasonsResponseBodyResultVoluntaryList getAllDismissionReasonsResponseBodyResultVoluntaryList = voluntaryList.get(4);
|
|
|
|
+ String id = getAllDismissionReasonsResponseBodyResultVoluntaryList.getId();//获取 其他原因的 id
|
|
|
|
+ return id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 确认离职并删除员工
|
|
|
|
+ * @param dingUserDTO
|
|
|
|
+ * @param tenantId
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public void confirmRe(DingTalkUserDTO dingUserDTO,String tenantId) throws Exception {
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.Client client = DingTalkUtils.createClient();
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.HrmProcessTerminationAndHandoverHeaders hrmProcessTerminationAndHandoverHeaders = new com.aliyun.dingtalkhrm_1_0.models.HrmProcessTerminationAndHandoverHeaders();
|
|
|
|
+ hrmProcessTerminationAndHandoverHeaders.xAcsDingtalkAccessToken = getToken(tenantId);
|
|
|
|
+ long yesterdayTimestamp = System.currentTimeMillis() - 24 * 60 * 60 * 1000;
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.HrmProcessTerminationAndHandoverRequest hrmProcessTerminationAndHandoverRequest = new com.aliyun.dingtalkhrm_1_0.models.HrmProcessTerminationAndHandoverRequest()
|
|
|
|
+ .setUserId(dingUserDTO.getUserid())
|
|
|
|
+ .setLastWorkDate(yesterdayTimestamp)
|
|
|
|
+ .setOptUserId(dingAdminId)//操作者的id,是本组织的并且非离职员工本人
|
|
|
|
+ .setDismissionMemo("");
|
|
|
|
+ try {
|
|
|
|
+ client.hrmProcessTerminationAndHandoverWithOptions(hrmProcessTerminationAndHandoverRequest, hrmProcessTerminationAndHandoverHeaders, new com.aliyun.teautil.models.RuntimeOptions());
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|