package com.kingdee.eas.custom.recuritment.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.kingdee.eas.custom.beisen.utils.BeisenApiClient; import com.kingdee.eas.custom.beisen.utils.BeisenParam; import com.kingdee.util.StringUtils; import org.apache.log4j.Logger; import java.io.IOException; import java.util.List; /** * 北森招聘负责人相关接口封装。 * HTTP 与 Token 由 {@link BeisenApiClient} 统一处理。 * * @author qingwu */ public class BeisenRecruitOwnerApiHelper { private static final Logger logger = Logger.getLogger(BeisenRecruitOwnerApiHelper.class); /** 根据职位Id获取职位列表 */ private static final String GET_JOB_LIST_BY_IDS = "https://openapi.italent.cn/RecruitV6/api/v1/Job/GetJobListByIds"; /** 根据originalId获取员工信息 */ private static final String GET_STAFF_BY_ORIGINAL_ID = "https://openapi.italent.cn/UserFrameworkApiV3/api/v1/staffs/Get"; /** * 批量根据申请ID获取申请信息。 * * @param applyIds 北森申请ID列表 */ public JSONObject getApplyListByApplyIds(List applyIds) throws IOException { JSONObject params = new JSONObject(); JSONArray ids = new JSONArray(); ids.addAll(applyIds); params.put("applyIds", ids); logger.error("getApplyListByApplyIds params:" + params); JSONObject result = BeisenApiClient.getInstance().callApi(BeisenParam.GET_APPLYLIST_APPLYID, params); logger.error("getApplyListByApplyIds result:" + result); return result; } /** * 批量根据职位Id获取职位列表。 * * @param jobIds 职位Id列表(GUID) */ public JSONObject getJobListByIds(List jobIds) throws IOException { JSONObject params = new JSONObject(); JSONArray ids = new JSONArray(); ids.addAll(jobIds); params.put("jobIds", ids); logger.error("getJobListByIds params:" + params); JSONObject result = BeisenApiClient.getInstance().callApi(GET_JOB_LIST_BY_IDS, params); logger.error("getJobListByIds result:" + result); return result; } /** * 根据北森用户originalId获取员工,返回 data.staffCode。 * @param originalId 北森用户originalId(字符串) */ public JSONObject getStaffByOriginalId(String originalId) throws IOException { String url = GET_STAFF_BY_ORIGINAL_ID + "?originalId=" + originalId; logger.error("getStaffByOriginalId url:" + url); JSONObject result = BeisenApiClient.getInstance().callGetApi(url, new JSONObject()); logger.error("getStaffByOriginalId result:" + result); return result; } /** * 从员工接口响应解析 staffCode。 * 北森返回结构:items[0].staffDto.staffCode */ public static String parseStaffCode(JSONObject staffJson) { if (staffJson == null) { return null; } JSONArray items = staffJson.getJSONArray("items"); if (items != null && !items.isEmpty()) { JSONObject first = items.getJSONObject(0); if (first != null) { JSONObject staffDto = first.getJSONObject("staffDto"); if (staffDto != null && !StringUtils.isEmpty(staffDto.getString("staffCode"))) { return staffDto.getString("staffCode"); } } } JSONObject data = staffJson.getJSONObject("data"); if (data != null && !StringUtils.isEmpty(data.getString("staffCode"))) { return data.getString("staffCode"); } return null; } }