SaveBeisenApplyIdService.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package com.kingdee.eas.custom.recuritment.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.Context;
  6. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  7. import com.kingdee.bos.dao.IObjectPK;
  8. import com.kingdee.bos.util.BOSUuid;
  9. import com.kingdee.eas.basedata.org.HROrgUnitInfo;
  10. import com.kingdee.eas.common.EASBizException;
  11. import com.kingdee.eas.custom.recuritment.ApplicantBeisenFactory;
  12. import com.kingdee.eas.custom.recuritment.ApplicantBeisenInfo;
  13. import com.kingdee.eas.custom.recuritment.IApplicantBeisen;
  14. import com.kingdee.eas.custom.recuritment.bizEnum.ExecuteResultEnum;
  15. import com.kingdee.util.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import java.text.MessageFormat;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. /**
  23. * 同步北森简历:写入北森申请ID和应聘ID
  24. *
  25. * @author qingwu
  26. * @date 2025/6/25
  27. * @apiNote
  28. */
  29. public class SaveBeisenApplyIdService implements IHRMsfService {
  30. private static Logger logger = Logger.getLogger(SaveBeisenApplyIdService.class);
  31. private final String ERRORMSGTEMPLATE = "申请id[{0}]已经存在,请勿重复写入!";
  32. @Override
  33. public Object process(Context ctx, Map<String, Object> map) throws EASBizException, BOSException {
  34. String array = (String) map.get("array");
  35. Map mapMsg = new HashMap();
  36. List listMsg = new ArrayList();
  37. if (StringUtils.isEmpty(array)) {
  38. mapMsg.put("code", 500);
  39. mapMsg.put("message", "参数不能为空");
  40. return mapMsg;
  41. }
  42. int errorSize = 0;
  43. int successSize = 0;
  44. String applyId = "";
  45. JSONArray jsonArray = null;
  46. try {
  47. jsonArray = JSONArray.parseArray(array);
  48. logger.error("array--" + array);
  49. logger.error("jsonArray--" + jsonArray);
  50. } catch (Exception e) {
  51. mapMsg.put("code", 500);
  52. mapMsg.put("listMsg", listMsg);
  53. mapMsg.put("errorSize", errorSize);
  54. mapMsg.put("successSize", successSize);
  55. mapMsg.put("message", "请求失败:参数格式错误!");
  56. return mapMsg;
  57. }
  58. try {
  59. for (int i = 0; i < jsonArray.size(); i++) {
  60. JSONObject data = jsonArray.getJSONObject(i);
  61. //申请id
  62. applyId = data.getString("applyId");
  63. //应聘id
  64. String candidateId = data.getString("candidateId");
  65. if (StringUtils.isEmpty(applyId)) {
  66. listMsg.add(packageResult(applyId, 500, "", "申请id不能为空!"));
  67. ++errorSize;
  68. continue;
  69. }
  70. IApplicantBeisen iApplicantBeisen = ApplicantBeisenFactory.getLocalInstance(ctx);
  71. boolean isExists = iApplicantBeisen.exists("where applyId='" + applyId + "' ");
  72. if (isExists) {
  73. String errorMsg = MessageFormat.format(ERRORMSGTEMPLATE, applyId, candidateId);
  74. listMsg.add(packageResult("applyId", 500, "", errorMsg));
  75. ++errorSize;
  76. continue;
  77. }
  78. ApplicantBeisenInfo applicantBeisenInfo = new ApplicantBeisenInfo();
  79. HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo();
  80. hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4"));
  81. applicantBeisenInfo.setHrOrgUnit(hrOrgUnitInfo);
  82. applicantBeisenInfo.setApplyId(applyId);
  83. applicantBeisenInfo.setCandidateId(candidateId);
  84. applicantBeisenInfo.setSyncStatus(ExecuteResultEnum.UNEXECUTE);
  85. IObjectPK addnew = iApplicantBeisen.addnew(applicantBeisenInfo);
  86. listMsg.add(packageResult(applyId, 200, addnew.toString(), "成功"));
  87. successSize++;
  88. }
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91. ++errorSize;
  92. listMsg.add(packageResult(applyId, 500, "", e.getMessage()));
  93. }
  94. mapMsg.put("code", 200);
  95. mapMsg.put("listMsg", listMsg);
  96. mapMsg.put("errorSize", errorSize);
  97. mapMsg.put("successSize", successSize);
  98. mapMsg.put("message", "请求成功!");
  99. return mapMsg;
  100. }
  101. ///**
  102. // * 通过申请ID获取需求管理
  103. // *
  104. // * @param applyId
  105. // */
  106. //public RecuritmentDemandInfo getRecuritmentByApplyId(Context ctx, String applyId) throws JSONException, IOException, URISyntaxException, BOSException, org.json.JSONException {
  107. // JSONObject pamas = new JSONObject();
  108. // JSONArray applyIds = new JSONArray();
  109. // applyIds.add(applyId);
  110. // pamas.put("applyIds", applyIds);
  111. // String jobId = "";
  112. // //根据申请ID获取申请信息
  113. // JSONObject applyJson = ItalentHelper.getApplyListByApplyId(pamas);
  114. // logger.error("applyJson--" + applyJson);
  115. // if (null != applyJson && applyJson.size() > 0 && "200".equals(applyJson.get("code") + "")) {
  116. // JSONArray data = applyJson.getJSONArray("data");
  117. // for (int i = 0; i < data.size(); i++) {
  118. // JSONObject applyData = data.getJSONObject(0);
  119. // //职位ID
  120. // jobId = applyData.getString("jobId");
  121. // }
  122. // } else {
  123. // logger.error("根据申请ID获取申请信息失败,原因:" + applyJson.get("message"));
  124. // }
  125. // logger.error("jobId--" + jobId);
  126. // //根据ID获取获取数据单条
  127. // JSONObject entity = ItalentHelper.getEntity(jobId);
  128. // logger.error("entity--" + entity);
  129. // JSONObject entityData = entity.getJSONObject("data");
  130. // //根据招聘需求ID获取招聘需求
  131. // JSONObject columns = entityData.getJSONObject("columns");
  132. // JSONObject recruit = columns.getJSONObject("RecruitRequirementIds");
  133. // String recruitRequirementId = recruit.getString("value");
  134. // JSONArray recruitRequirementIds = new JSONArray();
  135. // recruitRequirementIds.add(recruitRequirementId);
  136. // //根据招聘需求ID获取招聘需求
  137. // JSONObject requirements = ItalentHelper.getRequirements(recruitRequirementIds);
  138. // logger.error("requirements--" + requirements);
  139. // //一个职位可能关联多个招聘需求,建议校验需求状态,获取需求状态=进行中的招聘需求;
  140. // JSONArray data = requirements.getJSONArray("data");
  141. // //需求Id
  142. // String requirementId = "";
  143. // for (int i = 0; i < data.size(); i++) {
  144. // JSONObject requirementData = data.getJSONObject(i);
  145. // //需求状态 10=草稿,20=审批中,30=审批未通过,40=进行中,50=已关闭,60=已完成,70=已暂停,80=审批已终止
  146. // String requirementStatus = requirementData.getString("requirementStatus");
  147. // if ("40".equals(requirementStatus)) {
  148. // requirementId = requirementData.getString("requirementId");
  149. // }
  150. // }
  151. // //招聘需求
  152. // IRecuritmentDemand iRecuritmentDemand = RecuritmentDemandFactory.getLocalInstance(ctx);
  153. // //RecuritmentDemandCollection recuritmentDemandCollection = iRecuritmentDemand.getRecuritmentDemandCollection("where requirementId='" + requirementId + "");
  154. // //if (recuritmentDemandCollection.size() > 0) {
  155. // // return recuritmentDemandCollection.get(0);
  156. // //}
  157. // return null;
  158. //}
  159. /**
  160. * 封装结果
  161. *
  162. * @param applyId
  163. * @param code
  164. * @param number
  165. * @param msg
  166. * @return
  167. */
  168. public Map packageResult(String applyId, int code, String number, String msg) {
  169. Map result = new HashMap();
  170. result.put("applyId", applyId);
  171. result.put("code", code);
  172. result.put("number", number);
  173. result.put("message", msg);
  174. return result;
  175. }
  176. }