weaver-hrm-recruit/src/weaver/formmode/recruit/modeexpand/position/ReleasePositionModeExpand.java

148 lines
7.3 KiB
Java
Raw Normal View History

2023-10-09 10:31:12 +08:00
package weaver.formmode.recruit.modeexpand.position;
2023-10-10 11:06:31 +08:00
import com.alibaba.fastjson.JSON;
2023-10-27 09:27:47 +08:00
import com.engine.recruit.thread.SdkResumeSavedThread;
2023-10-09 10:31:12 +08:00
import com.weaver.rpa.sdk.clients.application.resume.ERPAResumeSDKClient;
2024-03-04 14:07:46 +08:00
import com.weaver.rpa.sdk.clients.application.resume.entity.ResumeJobV2Dto;
2023-10-09 10:31:12 +08:00
import com.weaver.rpa.sdk.clients.core.ERPASDKClients;
2023-10-10 09:28:13 +08:00
import org.apache.commons.lang3.StringUtils;
2024-03-04 14:07:46 +08:00
import org.springframework.beans.BeanUtils;
2023-10-09 10:31:12 +08:00
import weaver.conn.RecordSet;
2023-10-10 16:14:49 +08:00
import weaver.erpa.apps.entity.application.resume.dto.ResumeTaskResult;
import weaver.erpa.apps.entity.application.resume.enums.TaskResult;
2023-10-09 10:31:12 +08:00
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.formmode.recruit.modeexpand.util.RecruitPositionUtil;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2023/10/07
* @version: 1.0
*/
public class ReleasePositionModeExpand extends AbstractModeExpandJavaCodeNew {
@Override
public Map<String, String> doModeExpand(Map<String, Object> param) {
String tableName = "uf_jcl_zp_zpzw";
2023-10-10 09:28:13 +08:00
Map<String, String> resultMap = new HashMap<>(16);
BaseBean baseBean = new BaseBean();
2023-10-09 10:31:12 +08:00
try {
User user = (User) param.get("user");
int billId;
int modeId;
RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
if (requestInfo != null) {
billId = Util.getIntValue(requestInfo.getRequestid());
modeId = Util.getIntValue(requestInfo.getWorkflowid());
if (billId > 0 && modeId > 0) {
long jobId = -1;
RecordSet rs = new RecordSet();
rs.executeQuery("select qllgwid from " + tableName + " where id = ?", billId);
if (rs.next()) {
2023-10-10 09:28:13 +08:00
String qllgwid = rs.getString("qllgwid");
if (StringUtils.isNotBlank(qllgwid)) {
jobId = Long.parseLong(qllgwid);
}
2023-10-09 10:31:12 +08:00
}
ERPAResumeSDKClient client = ERPASDKClients.getResumeSDKClient();
Map<String, Object> map = new HashMap<>(16);
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
Property[] properties = mainTableInfo.getProperty();
for (Property property : properties) {
map.put(property.getName(), property.getValue());
}
2024-04-07 11:24:52 +08:00
ResumeJobV2Dto resumeJobDto = RecruitPositionUtil.convertMap2ResumeJobV2Dto(user,map);
2023-10-09 10:31:12 +08:00
// 发布千里聆职位
if (!RecruitPositionUtil.checkAvailable(client)) {
baseBean.writeLog("千里聆未开通简历应用。");
2023-10-10 09:28:13 +08:00
resultMap.put("errmsg", "千里聆未开通简历应用。");
resultMap.put("flag", "false");
return resultMap;
2023-10-09 10:31:12 +08:00
}
String userId = String.valueOf(user.getUID());
// 未创建职位,则先创建职位
if (jobId == -1) {
baseBean.writeLog("【创建职位】,[id=" + billId + "],resumeJobDto=" + JSON.toJSONString(resumeJobDto));
2023-10-09 10:31:12 +08:00
// 创建千里聆职位
2024-03-04 14:07:46 +08:00
jobId = client.addResumeJobV2(userId, resumeJobDto);
2023-10-09 10:31:12 +08:00
// 更新千里聆ID到建模表单
rs.executeUpdate("update " + tableName + " set qllgwid = ? where id = ?", jobId, billId);
} else {
2024-03-04 14:07:46 +08:00
baseBean.writeLog("【更新职位】,[id=" + billId + "],[qllgwid=" + jobId + "],resumeJobDto=" + JSON.toJSONString(resumeJobDto));
// 已发布的职位,更新职位信息
client.editResumeJobV2(userId, jobId, jobDto -> {
new BaseBean().writeLog("职位更新前:" + JSON.toJSONString(jobDto));
2024-03-06 18:43:37 +08:00
BeanUtils.copyProperties(resumeJobDto,jobDto);
2024-03-04 14:07:46 +08:00
new BaseBean().writeLog("职位更新后:" + JSON.toJSONString(jobDto));
});
2023-10-09 10:31:12 +08:00
}
2023-10-10 11:06:31 +08:00
// 在启动监听前需要配置好简历接收回调
client.addResumeSavedListener(resumeMqMessage -> {
2023-10-17 15:18:53 +08:00
// 处理获取到的简历信息
baseBean.writeLog("【简历接收回调】:" + JSON.toJSONString(resumeMqMessage));
2023-10-27 09:27:47 +08:00
Thread thread = new Thread(new SdkResumeSavedThread(resumeMqMessage));
2023-10-17 15:18:53 +08:00
thread.start();
2023-10-10 11:06:31 +08:00
});
2023-10-17 15:18:53 +08:00
2023-10-09 10:31:12 +08:00
client.start();
2023-10-10 16:14:49 +08:00
List<Integer> platformIds;
2024-03-04 14:07:46 +08:00
platformIds = resumeJobDto.getPlatformList();
2023-10-10 16:14:49 +08:00
String errorMsg = "";
2023-10-09 10:31:12 +08:00
for (Integer platformId : platformIds) {
2023-10-10 16:14:49 +08:00
ResumeTaskResult result = client.releaseResumeJob(userId, jobId, platformId);
// 直接查看结果正在执行中会返回PENGING成功后会返回SUCCEED失败后会返回FAILED
TaskResult current = result.getResult();
baseBean.writeLog(current);
2023-10-10 16:14:49 +08:00
// 使用回调函数获取成功或者失败时的消息
result.onResult(() -> {
baseBean.writeLog("执行成功回调");
2023-10-10 16:14:49 +08:00
}, (reason) -> {
baseBean.writeLog("执行失败回调,原因:" + reason);
2023-10-10 16:14:49 +08:00
});
// 等待直到状态不再是PENDING
TaskResult taskResult = result.waitResult();
baseBean.writeLog(taskResult);
2023-10-10 16:14:49 +08:00
if (taskResult == TaskResult.SUCCEED) {
baseBean.writeLog("执行成功");
2023-10-10 16:14:49 +08:00
} else {
errorMsg = "执行失败,原因:" + result.getFailReason();
baseBean.writeLog(errorMsg);
2023-10-10 16:14:49 +08:00
break;
}
}
if (StringUtils.isNotBlank(errorMsg)) {
// 发布失败,下架职位
client.closeResumeJob(userId, jobId);
// 更新状态为发布失败
rs.executeUpdate("update " + tableName + " set qdfbzt = ? where id = ?", 3, billId);
resultMap.put("errmsg", errorMsg);
resultMap.put("flag", "false");
return resultMap;
2023-10-09 10:31:12 +08:00
}
// 更新状态为已发布
rs.executeUpdate("update " + tableName + " set qdfbzt = ? where id = ?", 2, billId);
}
}
} catch (Exception e) {
baseBean.writeLog(e);
2023-10-10 09:28:13 +08:00
resultMap.put("errmsg", e.getMessage());
resultMap.put("flag", "false");
2023-10-09 10:31:12 +08:00
}
2023-10-10 09:28:13 +08:00
return resultMap;
2023-10-09 10:31:12 +08:00
}
}