Commit 224c00fd by wutong

OMS,SKUMS, 调拨数据分页查询修改, 避免漏数据.

parent 2c4348c4
...@@ -35,81 +35,62 @@ public class OrderSyncJob extends PointJob { ...@@ -35,81 +35,62 @@ public class OrderSyncJob extends PointJob {
@Override @Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) { public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
//如果页号为0, 就表示上次查完了, 这次要从总页数开始查, 如果页号 > 0, 就降序查, 防止漏单
if (jobPointLog.getPageIndex() == 0) {
jobPointLog.setPageIndex(requestBailunOrder(jobPointLog));
}
if (jobPointLog.getPageIndex() > 0) {
do {
requestBailunOrder(jobPointLog);
jobPointLog.setPageIndex(jobPointLog.getPageIndex() - 1);
if (jobPointLog.getPageIndex() % 10 == 0) {
try {
JobPointLogMapper mapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
mapper.upsertSelective(jobPointLog);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
}
} while (0 < jobPointLog.getPageIndex());
}
if (jobPointLog.getPageIndex() == 0) {
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()));
}
}
/**
* 请求OMS接口
*
* @param jobPointLog
* @return
*/
private Integer requestBailunOrder(JobPointLog jobPointLog) {
Integer totalPages = null;
LinkedHashMap<String, String> map = new LinkedHashMap<>(4); LinkedHashMap<String, String> map = new LinkedHashMap<>(4);
map.put("pageIndex", jobPointLog.getPageIndex() == 0 ? "1" : jobPointLog.getPageIndex().toString());
map.put("pageCount", jobPointLog.getPageSize().toString()); map.put("pageCount", jobPointLog.getPageSize().toString());
//时间回退一点, 避免服务器时间不一致而漏单 //时间回退一点, 避免服务器时间不一致而漏单
map.put("BailunLastUpdateTimeFrom", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getStartTime().minusMinutes(5))); map.put("BailunLastUpdateTimeFrom", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getStartTime().minusMinutes(3)));
map.put("BailunLastUpdateTimeTo", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getEndTime())); map.put("BailunLastUpdateTimeTo", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getEndTime()));
Response response = null; do {
String omsResultStr = null; map.put("pageIndex", jobPointLog.getPageIndex().equals(0) ? "1" : jobPointLog.getPageIndex().toString());
try { Response response = null;
Request request = new Request.Builder() String omsResultStr = null;
.get() try {
.url(OkHttpUtil.attachHttpGetParams(propertiesUtil.getPropertyAsString("BAILUNORDER_URL"), map)) Request request = new Request.Builder()
.addHeader("Content-Type", "application/json") .get()
.build(); .url(OkHttpUtil.attachHttpGetParams(propertiesUtil.getPropertyAsString("BAILUNORDER_URL"), map))
response = okHttpClient.newCall(request).execute(); .addHeader("Content-Type", "application/json")
omsResultStr = response.body().string(); .build();
} catch (IOException e) { response = okHttpClient.newCall(request).execute();
throw new RuntimeException(map + "请求OMS接口同步百伦接口失败" + response, e); omsResultStr = response.body().string();
} finally { } catch (IOException e) {
if (response != null) { throw new RuntimeException(map + "请求OMS接口同步百伦接口失败" + response, e);
response.close(); } finally {
if (response != null) {
response.close();
}
} }
} if (StringUtils.isNoneBlank(omsResultStr)) {
if (StringUtils.isNoneBlank(omsResultStr)) { OmsResultRoot omsResultRoot = JSON.parseObject(omsResultStr, OmsResultRoot.class);
OmsResultRoot omsResultRoot = JSON.parseObject(omsResultStr, OmsResultRoot.class); if (omsResultRoot != null && omsResultRoot.getSuccess().booleanValue()) {
if (omsResultRoot != null && omsResultRoot.getSuccess().booleanValue()) { OmsResultInfo omsResultInfo = omsResultRoot.getResult();
OmsResultInfo omsResultInfo = omsResultRoot.getResult(); if (jobPointLog.getPageIndex().equals(0)) {
totalPages = omsResultInfo.getTotalPages(); jobPointLog.setPageIndex(omsResultInfo.getTotalPages() + 1);
if (omsResultInfo.getResult() != null && omsResultInfo.getResult().size() > 0) { }
analyseOmsOrder(omsResultInfo.getResult()); if (omsResultInfo.getResult() != null && omsResultInfo.getResult().size() > 0) {
analyseOmsOrder(omsResultInfo.getResult());
}
} else {
throw new RuntimeException("调用OMS接口同步百伦订单失败, 响应200, 请求参数" + map.toString());
} }
} else { } else {
throw new RuntimeException("调用OMS接口同步百伦订单失败, 响应200, 请求参数" + map.toString()); throw new RuntimeException("调用OMS接口同步百伦订单失败, 响应为null, 请求参数" + map.toString());
} }
} else { if (jobPointLog.getPageIndex() % 10 == 0) {
throw new RuntimeException("调用OMS接口同步百伦订单失败, 响应为null, 请求参数" + map.toString()); try {
} JobPointLogMapper mapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
//如果PageIndex等于0取总页数, 否则取PageIndex mapper.upsertSelective(jobPointLog);
return jobPointLog.getPageIndex() == 0 ? totalPages : jobPointLog.getPageIndex(); } catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB插入任务记录失败", e);
} finally {
SessionUtil.closeSession();
}
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() - 1);
} while (0 < jobPointLog.getPageIndex());
jobPointLog.setPageIndex(0);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()));
} }
/** /**
......
...@@ -9,7 +9,7 @@ EVENT_RDB_STORAGE_USERNAME=root ...@@ -9,7 +9,7 @@ EVENT_RDB_STORAGE_USERNAME=root
EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf
ZOOKEEPER_SERVER=172.31.255.120:2181 ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center NAME_SPACE=data-center
JOB_NAME=base-sync-oms-order-coroutine #JOB_NAME=base-sync-oms-order-coroutine
#JOB_NAME=base-sync-oms-order JOB_NAME=base-sync-oms-order
JOB_CRON=0/1 * * * * ? * JOB_CRON=0/1 * * * * ? *
SHARDING_TOTAL_COUNT=1 SHARDING_TOTAL_COUNT=1
\ No newline at end of file
...@@ -68,7 +68,7 @@ public class SkuMSSyncJob extends PointJob { ...@@ -68,7 +68,7 @@ public class SkuMSSyncJob extends PointJob {
handleSkuMsJson(data,jobPointLog); handleSkuMsJson(data,jobPointLog);
} }
if (jobPointLog.getPageIndex().equals(0) && result.getTotalPage() != null) { if (jobPointLog.getPageIndex().equals(0) && result.getTotalPage() != null) {
jobPointLog.setPageIndex(result.getTotalPage()); jobPointLog.setPageIndex(result.getTotalPage() + 1);
} }
} }
} else { } else {
......
...@@ -8,9 +8,9 @@ public class TransferDetailsTest { ...@@ -8,9 +8,9 @@ public class TransferDetailsTest {
@Test @Test
public void test() { public void test() {
JobPointLog jobPointLog = new JobPointLog(); JobPointLog jobPointLog = new JobPointLog();
jobPointLog.setStartTime(LocalDateTime.of(2019,02,12,17,13,18)); jobPointLog.setStartTime(LocalDateTime.of(2019,04,17,14,53,14));
jobPointLog.setEndTime(LocalDateTime.of(2019,02,13,17,13,19)); jobPointLog.setEndTime(LocalDateTime.of(2019,04,17,14,53,15));
jobPointLog.setType(3); jobPointLog.setType(5);
jobPointLog.setIntervalTime(1); jobPointLog.setIntervalTime(1);
jobPointLog.setPageIndex(1); jobPointLog.setPageIndex(1);
jobPointLog.setPageSize(1000); jobPointLog.setPageSize(1000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment