|
@@ -189,6 +189,51 @@ public class SyncUtil {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分批调用MDM接口
|
|
|
+ * @param url 接口地址
|
|
|
+ * @param bodyData 入参
|
|
|
+ * @param type 同步类型
|
|
|
+ * @param startTime 变动开始时间
|
|
|
+ * @param endTime 变动结束时间
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static void batchPost(String url, JSONObject bodyData, String type, String startTime, String endTime) throws IOException {
|
|
|
+ int size = getBatchSize();
|
|
|
+ JSONArray oldArr = bodyData.getJSONArray("obj");
|
|
|
+ int totalSize = bodyData.getJSONArray("obj").size(); //总条数
|
|
|
+ JSONObject newOb = new JSONObject();
|
|
|
+ int totalPage = totalSize % size == 0 ? totalSize / size : totalSize / size + 1; //总页数
|
|
|
+ for (int i = 1; i <= totalPage; i++) {
|
|
|
+ int startIndex = (i - 1) * size;
|
|
|
+ int endIndex = Math.min(startIndex + size, totalSize);
|
|
|
+ JSONArray newArr = new JSONArray();
|
|
|
+ for (int m = startIndex; m < endIndex; m++) {
|
|
|
+ newArr.add(oldArr.get(m));
|
|
|
+ }
|
|
|
+ newOb.put("obj", newArr);
|
|
|
+ //调用接口
|
|
|
+ JSONObject response = SyncUtil.doPostByHttpClient(url, newOb);
|
|
|
+ //处理返回结果
|
|
|
+ String status = SyncUtil.dealResponseStatus(response);
|
|
|
+ //记录日志
|
|
|
+ SyncUtil.createLog(status, startTime, endTime, newOb.toJSONString(), response.toJSONString(), type);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分页条数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static int getBatchSize () {
|
|
|
+ QFilter filter = new QFilter("number", QCP.equals, "MDM");
|
|
|
+ filter.and("nckd_entryentity.nckd_key",QCP.equals, "size");
|
|
|
+ DynamicObject bill = QueryServiceHelper.queryOne("nckd_commonparams", "nckd_entryentity.nckd_value", new QFilter[]{filter});
|
|
|
+ return Integer.valueOf(bill.getString("nckd_entryentity.nckd_value"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
* @param url
|
|
@@ -201,8 +246,7 @@ public class SyncUtil {
|
|
|
headers.put("Accept", "*/*");
|
|
|
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());
|
|
|
+ String responseEntify = HttpClientUtils.postjson(url, headers, bodyData.toJSONString(), 10000, 10000);
|
|
|
|
|
|
logger.info(responseEntify);
|
|
|
JSONObject result = (JSONObject)JSONObject.parse(responseEntify);
|