SaveBeisenApplyIdService.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.metadata.entity.SelectorItemCollection;
  9. import com.kingdee.bos.util.BOSUuid;
  10. import com.kingdee.eas.basedata.org.HROrgUnitInfo;
  11. import com.kingdee.eas.common.EASBizException;
  12. import com.kingdee.eas.custom.recuritment.ApplicantBeisenCollection;
  13. import com.kingdee.eas.custom.recuritment.ApplicantBeisenFactory;
  14. import com.kingdee.eas.custom.recuritment.ApplicantBeisenInfo;
  15. import com.kingdee.eas.custom.recuritment.IApplicantBeisen;
  16. import com.kingdee.eas.custom.recuritment.bizEnum.ExecuteResultEnum;
  17. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  18. import com.kingdee.util.StringUtils;
  19. import org.apache.log4j.Logger;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * 同步北森简历:写入北森申请ID和应聘ID
  26. *
  27. * @author qingwu
  28. * @date 2025/6/25
  29. * @apiNote
  30. */
  31. public class SaveBeisenApplyIdService implements IHRMsfService {
  32. private static Logger logger = Logger.getLogger(SaveBeisenApplyIdService.class);
  33. private final String ERRORMSGTEMPLATE = "申请id[{0}]已经存在,请勿重复写入!";
  34. @Override
  35. public Object process(Context ctx, Map<String, Object> map) throws EASBizException, BOSException {
  36. String array = (String) map.get("array");
  37. logger.error("array--" + array);
  38. Map mapMsg = new HashMap();
  39. List listMsg = new ArrayList();
  40. if (StringUtils.isEmpty(array)) {
  41. mapMsg.put("code", 500);
  42. mapMsg.put("message", "参数不能为空!");
  43. return mapMsg;
  44. }
  45. int errorSize = 0;
  46. int successSize = 0;
  47. String applyId = "";
  48. JSONArray jsonArray = null;
  49. try {
  50. jsonArray = JSONArray.parseArray(array);
  51. logger.error("jsonArray--" + jsonArray);
  52. } catch (Exception e) {
  53. mapMsg.put("code", 500);
  54. mapMsg.put("listMsg", listMsg);
  55. mapMsg.put("errorSize", errorSize);
  56. mapMsg.put("successSize", successSize);
  57. mapMsg.put("message", "请求失败:参数格式错误!");
  58. return mapMsg;
  59. }
  60. try {
  61. for (int i = 0; i < jsonArray.size(); i++) {
  62. JSONObject data = jsonArray.getJSONObject(i);
  63. //申请id
  64. applyId = data.getString("applyId");
  65. //应聘id
  66. String candidateId = data.getString("candidateId");
  67. //需求名称
  68. String recuritmentName = data.getString("recuritmentName");
  69. //应聘者名称
  70. String candidateName = data.getString("candidateName");
  71. if (StringUtils.isEmpty(applyId)) {
  72. throw new ShrWebBizException("申请id不能为空!");
  73. }
  74. IApplicantBeisen iApplicantBeisen = ApplicantBeisenFactory.getLocalInstance(ctx);
  75. ApplicantBeisenCollection applicantBeisenCollection = iApplicantBeisen.getApplicantBeisenCollection("where applyId='" + applyId + "' ");
  76. if (!applicantBeisenCollection.isEmpty()) {
  77. ApplicantBeisenInfo applicantBeisenInfo = applicantBeisenCollection.get(0);
  78. ExecuteResultEnum syncStatus = applicantBeisenInfo.getSyncStatus();
  79. //同步状态为执行失败,则更新成未执行
  80. if (ExecuteResultEnum.ERROR.equals(syncStatus)) {
  81. SelectorItemCollection updateSic = new SelectorItemCollection();
  82. updateSic.add("syncStatus");
  83. updateSic.add("syncResult");
  84. applicantBeisenInfo.setSyncStatus(ExecuteResultEnum.UNEXECUTE);
  85. applicantBeisenInfo.setSyncResult("");
  86. iApplicantBeisen.updatePartial(applicantBeisenInfo, updateSic);
  87. }
  88. listMsg.add(packageResult(applyId, 200, applicantBeisenInfo.getId().toString(), "成功"));
  89. successSize++;
  90. //String errorMsg = MessageFormat.format(ERRORMSGTEMPLATE, applyId, candidateId);
  91. //throw new ShrWebBizException(errorMsg);
  92. } else {
  93. ApplicantBeisenInfo applicantBeisenInfo = new ApplicantBeisenInfo();
  94. HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo();
  95. hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4"));
  96. applicantBeisenInfo.setHrOrgUnit(hrOrgUnitInfo);
  97. applicantBeisenInfo.setApplyId(applyId);
  98. applicantBeisenInfo.setRecuritmentName(recuritmentName);
  99. applicantBeisenInfo.setCandidateId(candidateId);
  100. applicantBeisenInfo.setCandidateName(candidateName);
  101. applicantBeisenInfo.setSyncStatus(ExecuteResultEnum.UNEXECUTE);
  102. IObjectPK addnew = iApplicantBeisen.addnew(applicantBeisenInfo);
  103. listMsg.add(packageResult(applyId, 200, addnew.toString(), "成功"));
  104. successSize++;
  105. }
  106. }
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. ++errorSize;
  110. listMsg.add(packageResult(applyId, 500, "", e.getMessage()));
  111. }
  112. mapMsg.put("code", 200);
  113. mapMsg.put("listMsg", listMsg);
  114. mapMsg.put("errorSize", errorSize);
  115. mapMsg.put("successSize", successSize);
  116. mapMsg.put("message", "请求成功!");
  117. return mapMsg;
  118. }
  119. /**
  120. * 封装结果
  121. *
  122. * @param applyId
  123. * @param code
  124. * @param number
  125. * @param msg
  126. * @return
  127. */
  128. public Map packageResult(String applyId, int code, String number, String msg) {
  129. Map result = new HashMap();
  130. result.put("applyId", applyId);
  131. result.put("code", code);
  132. result.put("number", number);
  133. result.put("message", msg);
  134. return result;
  135. }
  136. }