package com.kingdee.eas.custom.recuritment.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.bsf.service.app.IHRMsfService; import com.kingdee.bos.dao.IObjectPK; import com.kingdee.bos.util.BOSUuid; import com.kingdee.eas.basedata.org.HROrgUnitInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.recuritment.ApplicantBeisenFactory; import com.kingdee.eas.custom.recuritment.ApplicantBeisenInfo; import com.kingdee.eas.custom.recuritment.IApplicantBeisen; import com.kingdee.eas.custom.recuritment.bizEnum.ExecuteResultEnum; import com.kingdee.util.StringUtils; import org.apache.log4j.Logger; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 同步北森简历:写入北森申请ID和应聘ID * * @author qingwu * @date 2025/6/25 * @apiNote */ public class SaveBeisenApplyIdService implements IHRMsfService { private static Logger logger = Logger.getLogger(SaveBeisenApplyIdService.class); private final String ERRORMSGTEMPLATE = "申请id[{0}]已经存在,请勿重复写入!"; @Override public Object process(Context ctx, Map map) throws EASBizException, BOSException { String array = (String) map.get("array"); Map mapMsg = new HashMap(); List listMsg = new ArrayList(); if (StringUtils.isEmpty(array)) { mapMsg.put("code", 500); mapMsg.put("message", "参数不能为空"); return mapMsg; } int errorSize = 0; int successSize = 0; String applyId = ""; JSONArray jsonArray = null; try { jsonArray = JSONArray.parseArray(array); logger.error("array--" + array); logger.error("jsonArray--" + jsonArray); } catch (Exception e) { mapMsg.put("code", 500); mapMsg.put("listMsg", listMsg); mapMsg.put("errorSize", errorSize); mapMsg.put("successSize", successSize); mapMsg.put("message", "请求失败:参数格式错误!"); return mapMsg; } try { for (int i = 0; i < jsonArray.size(); i++) { JSONObject data = jsonArray.getJSONObject(i); //申请id applyId = data.getString("applyId"); //应聘id String candidateId = data.getString("candidateId"); if (StringUtils.isEmpty(applyId)) { listMsg.add(packageResult(applyId, 500, "", "申请id不能为空!")); ++errorSize; continue; } IApplicantBeisen iApplicantBeisen = ApplicantBeisenFactory.getLocalInstance(ctx); boolean isExists = iApplicantBeisen.exists("where applyId='" + applyId + "' "); if (isExists) { String errorMsg = MessageFormat.format(ERRORMSGTEMPLATE, applyId, candidateId); listMsg.add(packageResult("applyId", 500, "", errorMsg)); ++errorSize; continue; } ApplicantBeisenInfo applicantBeisenInfo = new ApplicantBeisenInfo(); HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo(); hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4")); applicantBeisenInfo.setHrOrgUnit(hrOrgUnitInfo); applicantBeisenInfo.setApplyId(applyId); applicantBeisenInfo.setCandidateId(candidateId); applicantBeisenInfo.setSyncStatus(ExecuteResultEnum.UNEXECUTE); IObjectPK addnew = iApplicantBeisen.addnew(applicantBeisenInfo); listMsg.add(packageResult(applyId, 200, addnew.toString(), "成功")); successSize++; } } catch (Exception e) { e.printStackTrace(); ++errorSize; listMsg.add(packageResult(applyId, 500, "", e.getMessage())); } mapMsg.put("code", 200); mapMsg.put("listMsg", listMsg); mapMsg.put("errorSize", errorSize); mapMsg.put("successSize", successSize); mapMsg.put("message", "请求成功!"); return mapMsg; } ///** // * 通过申请ID获取需求管理 // * // * @param applyId // */ //public RecuritmentDemandInfo getRecuritmentByApplyId(Context ctx, String applyId) throws JSONException, IOException, URISyntaxException, BOSException, org.json.JSONException { // JSONObject pamas = new JSONObject(); // JSONArray applyIds = new JSONArray(); // applyIds.add(applyId); // pamas.put("applyIds", applyIds); // String jobId = ""; // //根据申请ID获取申请信息 // JSONObject applyJson = ItalentHelper.getApplyListByApplyId(pamas); // logger.error("applyJson--" + applyJson); // if (null != applyJson && applyJson.size() > 0 && "200".equals(applyJson.get("code") + "")) { // JSONArray data = applyJson.getJSONArray("data"); // for (int i = 0; i < data.size(); i++) { // JSONObject applyData = data.getJSONObject(0); // //职位ID // jobId = applyData.getString("jobId"); // } // } else { // logger.error("根据申请ID获取申请信息失败,原因:" + applyJson.get("message")); // } // logger.error("jobId--" + jobId); // //根据ID获取获取数据单条 // JSONObject entity = ItalentHelper.getEntity(jobId); // logger.error("entity--" + entity); // JSONObject entityData = entity.getJSONObject("data"); // //根据招聘需求ID获取招聘需求 // JSONObject columns = entityData.getJSONObject("columns"); // JSONObject recruit = columns.getJSONObject("RecruitRequirementIds"); // String recruitRequirementId = recruit.getString("value"); // JSONArray recruitRequirementIds = new JSONArray(); // recruitRequirementIds.add(recruitRequirementId); // //根据招聘需求ID获取招聘需求 // JSONObject requirements = ItalentHelper.getRequirements(recruitRequirementIds); // logger.error("requirements--" + requirements); // //一个职位可能关联多个招聘需求,建议校验需求状态,获取需求状态=进行中的招聘需求; // JSONArray data = requirements.getJSONArray("data"); // //需求Id // String requirementId = ""; // for (int i = 0; i < data.size(); i++) { // JSONObject requirementData = data.getJSONObject(i); // //需求状态 10=草稿,20=审批中,30=审批未通过,40=进行中,50=已关闭,60=已完成,70=已暂停,80=审批已终止 // String requirementStatus = requirementData.getString("requirementStatus"); // if ("40".equals(requirementStatus)) { // requirementId = requirementData.getString("requirementId"); // } // } // //招聘需求 // IRecuritmentDemand iRecuritmentDemand = RecuritmentDemandFactory.getLocalInstance(ctx); // //RecuritmentDemandCollection recuritmentDemandCollection = iRecuritmentDemand.getRecuritmentDemandCollection("where requirementId='" + requirementId + ""); // //if (recuritmentDemandCollection.size() > 0) { // // return recuritmentDemandCollection.get(0); // //} // return null; //} /** * 封装结果 * * @param applyId * @param code * @param number * @param msg * @return */ public Map packageResult(String applyId, int code, String number, String msg) { Map result = new HashMap(); result.put("applyId", applyId); result.put("code", code); result.put("number", number); result.put("message", msg); return result; } }