SaveBeisenApplyIdService.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.shr.base.syssetting.exception.ShrWebBizException;
  16. import com.kingdee.util.StringUtils;
  17. import org.apache.log4j.Logger;
  18. import java.text.MessageFormat;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * 同步北森简历:写入北森申请ID和应聘ID
  25. *
  26. * @author qingwu
  27. * @date 2025/6/25
  28. * @apiNote
  29. */
  30. public class SaveBeisenApplyIdService implements IHRMsfService {
  31. private static Logger logger = Logger.getLogger(SaveBeisenApplyIdService.class);
  32. private final String ERRORMSGTEMPLATE = "申请id[{0}]已经存在,请勿重复写入!";
  33. @Override
  34. public Object process(Context ctx, Map<String, Object> map) throws EASBizException, BOSException {
  35. String array = (String) map.get("array");
  36. logger.error("array--" + array);
  37. Map mapMsg = new HashMap();
  38. List listMsg = new ArrayList();
  39. if (StringUtils.isEmpty(array)) {
  40. mapMsg.put("code", 500);
  41. mapMsg.put("message", "参数不能为空!");
  42. return mapMsg;
  43. }
  44. int errorSize = 0;
  45. int successSize = 0;
  46. String applyId = "";
  47. JSONArray jsonArray = null;
  48. try {
  49. jsonArray = JSONArray.parseArray(array);
  50. logger.error("jsonArray--" + jsonArray);
  51. } catch (Exception e) {
  52. mapMsg.put("code", 500);
  53. mapMsg.put("listMsg", listMsg);
  54. mapMsg.put("errorSize", errorSize);
  55. mapMsg.put("successSize", successSize);
  56. mapMsg.put("message", "请求失败:参数格式错误!");
  57. return mapMsg;
  58. }
  59. try {
  60. for (int i = 0; i < jsonArray.size(); i++) {
  61. JSONObject data = jsonArray.getJSONObject(i);
  62. //申请id
  63. applyId = data.getString("applyId");
  64. //应聘id
  65. String candidateId = data.getString("candidateId");
  66. if (StringUtils.isEmpty(applyId)) {
  67. throw new ShrWebBizException("申请id不能为空!");
  68. }
  69. IApplicantBeisen iApplicantBeisen = ApplicantBeisenFactory.getLocalInstance(ctx);
  70. boolean isExists = iApplicantBeisen.exists("where applyId='" + applyId + "' ");
  71. if (isExists) {
  72. String errorMsg = MessageFormat.format(ERRORMSGTEMPLATE, applyId, candidateId);
  73. throw new ShrWebBizException(errorMsg);
  74. }
  75. ApplicantBeisenInfo applicantBeisenInfo = new ApplicantBeisenInfo();
  76. HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo();
  77. hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4"));
  78. applicantBeisenInfo.setHrOrgUnit(hrOrgUnitInfo);
  79. applicantBeisenInfo.setApplyId(applyId);
  80. applicantBeisenInfo.setCandidateId(candidateId);
  81. applicantBeisenInfo.setSyncStatus(ExecuteResultEnum.UNEXECUTE);
  82. IObjectPK addnew = iApplicantBeisen.addnew(applicantBeisenInfo);
  83. listMsg.add(packageResult(applyId, 200, addnew.toString(), "成功"));
  84. successSize++;
  85. }
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. ++errorSize;
  89. listMsg.add(packageResult(applyId, 500, "", e.getMessage()));
  90. }
  91. mapMsg.put("code", 200);
  92. mapMsg.put("listMsg", listMsg);
  93. mapMsg.put("errorSize", errorSize);
  94. mapMsg.put("successSize", successSize);
  95. mapMsg.put("message", "请求成功!");
  96. return mapMsg;
  97. }
  98. /**
  99. * 封装结果
  100. *
  101. * @param applyId
  102. * @param code
  103. * @param number
  104. * @param msg
  105. * @return
  106. */
  107. public Map packageResult(String applyId, int code, String number, String msg) {
  108. Map result = new HashMap();
  109. result.put("applyId", applyId);
  110. result.put("code", code);
  111. result.put("number", number);
  112. result.put("message", msg);
  113. return result;
  114. }
  115. }