Commit c1569b3e by huluobin

# update

parent 0fc1257d
...@@ -19,6 +19,14 @@ ...@@ -19,6 +19,14 @@
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format> <maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
</properties> </properties>
<dependencies>
<dependency>
<groupId>io.github.linus87</groupId>
<artifactId>ebaycalls</artifactId>
<version>1065</version>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
......
package com.bailuntec.job;
import com.bailuntec.common.ListUtil;
import com.bailuntec.domain.DcBaseCompanyAccount;
import com.bailuntec.domain.DcJobConfig;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.TimeFilter;
import com.ebay.sdk.call.GetAccountCall;
import com.ebay.soap.eBLBaseComponents.AccountEntryType;
import com.ebay.soap.eBLBaseComponents.AccountHistorySelectionCodeType;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.PaginationType;
import com.google.common.collect.Lists;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/18 5:23 下午
*/
public class EbayItemReader implements ItemReader<AccountEntryType> {
//剩余账户
private List<DcBaseCompanyAccount> dcBaseCompanyAccountList;
//剩余广告记录
private List<AccountEntryType> accountEntryTypeList;
//当前账户
private DcBaseCompanyAccount dcBaseCompanyAccount;
private GetAccountCall getAccountCall;
private Integer pageNum;
private Integer pageSize;
private DcJobConfig dcJobConfig;
@Override
public AccountEntryType read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
if (ListUtil.isNotEmpty(accountEntryTypeList)) {
return accountEntryTypeList.remove(0);
} else {
nextPage();
if (ListUtil.isNotEmpty(accountEntryTypeList)) {
return accountEntryTypeList.remove(0);
} else {
nextAccount();
if (ListUtil.isNotEmpty(accountEntryTypeList)) {
return accountEntryTypeList.remove(0);
} else {
return null;
}
}
}
}
private void nextPage() throws Exception {
this.pageNum++;
refreshPage();
}
private void nextAccount() {
this.pageNum = 1;
if (ListUtil.isNotEmpty(dcBaseCompanyAccountList)) {
dcBaseCompanyAccount = dcBaseCompanyAccountList.remove(0);
this.refreshAccountCall();
}
}
void refreshAccountCall() {
ApiContext apiContext = new ApiContext();
ApiCredential cred = apiContext.getApiCredential();
cred.seteBayToken(dcBaseCompanyAccount.getSoapAuthToken());
apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
GetAccountCall getAccountCall = new GetAccountCall(apiContext);
getAccountCall.setDetailLevel(new DetailLevelCodeType[]{DetailLevelCodeType.RETURN_ALL});
AccountHistorySelectionCodeType accountHistorySelectionCodeType = AccountHistorySelectionCodeType.BETWEEN_SPECIFIED_DATES;
getAccountCall.setViewType(accountHistorySelectionCodeType);
//开始时间
Calendar startCal = Calendar.getInstance();
startCal.setTime(Date.from(dcJobConfig.getStartTime().atZone(ZoneId.systemDefault()).toInstant()));
//结束时间
Calendar endCal = Calendar.getInstance();
endCal.setTime(Date.from(dcJobConfig.getEndTime().atZone(ZoneId.systemDefault()).toInstant()));
TimeFilter timeFilter = new TimeFilter(startCal, endCal);
getAccountCall.setViewPeriod(timeFilter);
getAccountCall.setInvoiceDate(endCal);
}
private void refreshPage() throws Exception {
PaginationType paginationType = new PaginationType();
paginationType.setPageNumber(pageNum);
getAccountCall.setPagination(new PaginationType());
accountEntryTypeList = Lists.newArrayList(getAccountCall.getAccount());
}
}
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
......
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