|
@@ -0,0 +1,149 @@
|
|
|
+package nckd.jimin.jyyy.hr.tsrsc.plugin.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.utils.ObjectUtils;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+import kd.bos.util.HttpClientUtils;
|
|
|
+import nckd.jimin.jyyy.hr.wtc.wtis.util.DingTalkSyncUtil;
|
|
|
+import org.apache.commons.net.util.Base64;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+ * Moka工具类
|
|
|
+ * @author :Tyx
|
|
|
+ * @since :2025-05-28
|
|
|
+ */
|
|
|
+public class MokaApiUtil {
|
|
|
+ private static Log logger = LogFactory.getLog(MokaApiUtil.class);
|
|
|
+
|
|
|
+ * 新增招聘需求
|
|
|
+ * @param recruitTypeFlag 招聘模式可选值:1:社招 2:校招
|
|
|
+ * @param bodyData 请求体
|
|
|
+ * @return 返回体
|
|
|
+ */
|
|
|
+ public static JSONObject addMokaCurrentHire(String recruitTypeFlag, JSONObject bodyData) throws IOException {
|
|
|
+ String url = getParamValue("moka_url")
|
|
|
+ + "/api-platform/v1/headcount"
|
|
|
+ + "?currentHireMode=" + recruitTypeFlag;
|
|
|
+ Map<String, String> headers = new HashMap();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Accept", "*/*");
|
|
|
+ headers.put("Authorization", "Basic " + Base64.encodeBase64String((getParamValue("moka_apikey") + ":").getBytes()));
|
|
|
+ logger.info(String.format("url[%s],data[%s]", url, bodyData.toJSONString()));
|
|
|
+ System.out.println(String.format("url[%s],data[%s]", url, bodyData.toJSONString()));
|
|
|
+ String responseEntify = HttpClientUtils.postjson(url, headers, bodyData.toJSONString(), 10000, 10000);
|
|
|
+
|
|
|
+ logger.info(responseEntify);
|
|
|
+ JSONObject result = (JSONObject)JSONObject.parse(responseEntify);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 调用Moka接口
|
|
|
+ * @param url
|
|
|
+ * @param bodyData
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static JSONObject doPostByHttpClient(String url, JSONObject bodyData) throws IOException {
|
|
|
+ Map<String, String> headers = new HashMap();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Accept", "*/*");
|
|
|
+ headers.put("Authorization", "Basic " + Base64.encodeBase64String((getParamValue("moka_apikey") + ":").getBytes()));
|
|
|
+ logger.info(String.format("url[%s],data[%s]", url, bodyData.toJSONString()));
|
|
|
+ System.out.println(String.format("url[%s],data[%s]", url, bodyData.toJSONString()));
|
|
|
+ String responseEntify = HttpClientUtils.postjson(url, headers, bodyData.toJSONString(), 10000, 10000);
|
|
|
+
|
|
|
+ logger.info(responseEntify);
|
|
|
+ JSONObject result = (JSONObject)JSONObject.parse(responseEntify);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 新增调用日志
|
|
|
+ *
|
|
|
+ * @param docNumber 调用单据标识
|
|
|
+ * @param docName 调用单据名称
|
|
|
+ * @param system 调用系统
|
|
|
+ * @param url 调用接口url
|
|
|
+ * @param request 请求报文
|
|
|
+ * @param response 返回报文
|
|
|
+ */
|
|
|
+ public static void newApiLog(String docNumber, String docName, String system, String url, String request, String response) {
|
|
|
+ DynamicObject apiLog = BusinessDataServiceHelper.newDynamicObject("nckd_mokaapilog");
|
|
|
+
|
|
|
+ apiLog.set("number", docNumber);
|
|
|
+
|
|
|
+ apiLog.set("name", docName);
|
|
|
+
|
|
|
+ apiLog.set("status", "C");
|
|
|
+
|
|
|
+ apiLog.set("creator", RequestContext.get().getCurrUserId());
|
|
|
+
|
|
|
+ apiLog.set("enable", "1");
|
|
|
+
|
|
|
+ apiLog.set("nckd_interfaceurl", url);
|
|
|
+
|
|
|
+ apiLog.set("createtime", new Date());
|
|
|
+ if (request.length() < 200) {
|
|
|
+ apiLog.set("nckd_request", request);
|
|
|
+ } else {
|
|
|
+ apiLog.set("nckd_request", request.substring(0, 200) + "...");
|
|
|
+ }
|
|
|
+ apiLog.set("nckd_request_tag", request);
|
|
|
+
|
|
|
+ if (response.length() < 200) {
|
|
|
+ apiLog.set("nckd_response", response);
|
|
|
+ } else {
|
|
|
+ apiLog.set("nckd_response", response.substring(0, 200) + "...");
|
|
|
+ }
|
|
|
+ apiLog.set("nckd_response_tag", response);
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{apiLog});
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取参数值
|
|
|
+ * @param key
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getParamValue(String key) {
|
|
|
+ QFilter filter = new QFilter("number", QCP.equals, "Moka");
|
|
|
+ filter.and("nckd_entryentity.nckd_key",QCP.equals, key);
|
|
|
+ DynamicObject bill = QueryServiceHelper.queryOne("nckd_commonparams", "nckd_entryentity.nckd_value", new QFilter[]{filter});
|
|
|
+ return bill.getString("nckd_entryentity.nckd_value");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取参数值,没找到返回默认值
|
|
|
+ * @param key
|
|
|
+ * @param def
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getParamValue(String key, String def) {
|
|
|
+ QFilter filter = new QFilter("number", QCP.equals, "Moka");
|
|
|
+ filter.and("nckd_entryentity.nckd_key",QCP.equals, key);
|
|
|
+ DynamicObject bill = QueryServiceHelper.queryOne("nckd_commonparams", "nckd_entryentity.nckd_value", new QFilter[]{filter});
|
|
|
+ if(ObjectUtils.isEmpty(bill)) {
|
|
|
+ return def;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return bill.getString("nckd_entryentity.nckd_value");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|