Commit aa919445 by wutong

优化任务处理

parent bc6a40b5
......@@ -2,10 +2,12 @@ package com.bailuntec.domain.pojo;
import lombok.Data;
import java.util.List;
@Data
public class AccountSummary {
private String accountState;
private AdditionalAccount additionalAccount;
private List<AdditionalAccount> additionalAccount;
private Currency amountPastDue;
private String billingCycleDate;
private Currency lastAmountPaid;
......
......@@ -55,6 +55,7 @@ public class EbayFinanceSyncJob extends PointJob {
List<JobAccountLog> listByPage = jobAccountLogMapper.getListByPage(12,page * jobPointLog.getPageSize(), jobPointLog.getPageSize());
if (listByPage != null && listByPage.size() > 0) {
for (JobAccountLog jobAccountLog : listByPage) {
log.warn("分片: " + shardingContext.getShardingItem() + " 账号: " + jobAccountLog);
if (jobAccountLog.getId() == null) { //在任务表无记录
BeanUtils.copyProperties(jobAccountLog, jobPointLog);
jobAccountLog.setId(null);
......@@ -85,7 +86,7 @@ public class EbayFinanceSyncJob extends PointJob {
return l % jobPointLog.getPageSize() == 0? l % jobPointLog.getPageSize() : l % jobPointLog.getPageSize() + 1;
}
private void callSaasApi(JobAccountLog job) {
public void callSaasApi(JobAccountLog job) {
HashMap<String, Object> map = new HashMap<>(5);
map.put("account_id",job.getAccountId());
map.put("AccountEntrySortType","AccountEntryItemNumberAscending");
......@@ -107,7 +108,9 @@ public class EbayFinanceSyncJob extends PointJob {
.build();
response = client.newCall(request).execute();
log.warn(JSON.toJSONString(map));
if (response.isSuccessful()) {
EbayResult ebayResult = JSON.parseObject(response.body().byteStream(), EbayResult.class);
if (ebayResult != null && ebayResult.getAck() != null && ebayResult.getAck().equals("Success")) {
AccountEntries accountEntries = ebayResult.getAccountEntries();
if (accountEntries != null) {
List<AccountEntry> accountEntryList = accountEntries.getAccountEntry();
......@@ -120,7 +123,7 @@ public class EbayFinanceSyncJob extends PointJob {
if (accountEntry.getGrossAmount_() != null) {
dcBaseFinanceEbay.setGrossAmount(accountEntry.getGrossAmount_().getValue());
dcBaseFinanceEbay.setCurrency(accountEntry.getGrossAmount_().getCurrency());
dcBaseFinanceEbay.setExchangeRate(CallBailunSystem.getExchangeRate(dcBaseFinanceEbay.getCurrency(),"CNY",dcBaseFinanceEbay.getBjDate()));
dcBaseFinanceEbay.setExchangeRate(CallBailunSystem.getExchangeRate(dcBaseFinanceEbay.getCurrency(), "CNY", dcBaseFinanceEbay.getBjDate()));
}
if (accountEntry.getGrossAmount_() != null) {
dcBaseFinanceEbay.setNetAmount(accountEntry.getNetAmount_().getValue());
......@@ -136,15 +139,20 @@ public class EbayFinanceSyncJob extends PointJob {
}
}
pageNumber = ebayResult.getPageNumber();
} else {
throw new RuntimeException("授权错误");
}
} else {
throw new RuntimeException("接口调用失败");
}
job.setPageIndex(job.getPageIndex() + 1);
} while (job.getPageIndex() <= pageNumber);
job.setPageIndex(1);
job.setStartTime(job.getEndTime());
job.setEndTime(job.getStartTime().plusDays(job.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : job.getEndTime().plusDays(job.getIntervalTime()));
job.setMessage("success");
job.setMessage("执行成功");
} catch (Exception e) {
e.printStackTrace();
job.setMessage(e.getCause().toString());
job.setMessage(e.getMessage());
} finally {
if (response != null) {
response.close();
......
import com.bailuntec.domain.entity.JobAccountLog;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.job.EbayFinanceSyncJob;
import com.dangdang.ddframe.job.api.ShardingContext;
......@@ -17,4 +18,20 @@ public class EbayFinanceSyncJobTest {
}
@Test
public void test1() {
EbayFinanceSyncJob skuSyncJob = new EbayFinanceSyncJob();
ShardingContext job = new ShardingContext(new ShardingContexts("1", "job", 3, "", new HashMap<>()), 1);
JobAccountLog jobAccountLog = new JobAccountLog();
jobAccountLog.setAccountId(1861);
jobAccountLog.setStartTime(LocalDateTime.of(2019,05,01,0,0));
jobAccountLog.setEndTime(LocalDateTime.of(2019,06,02,0,0));
jobAccountLog.setIntervalTime(1);
jobAccountLog.setPageIndex(1);
jobAccountLog.setPageSize(100);
skuSyncJob.callSaasApi(jobAccountLog);
}
}
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