Commit ddaebc7e by yinyong

paypal帐号信息同步

parent de61d944
...@@ -4,6 +4,7 @@ import com.alibaba.druid.pool.DruidDataSource; ...@@ -4,6 +4,7 @@ import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.CompanyAccountSyncJob; import com.bailuntec.job.CompanyAccountSyncJob;
import com.bailuntec.job.CompanyInfoSyncJob; import com.bailuntec.job.CompanyInfoSyncJob;
import com.bailuntec.job.CompanyStaffSyncJob; import com.bailuntec.job.CompanyStaffSyncJob;
import com.bailuntec.job.PaypalAccountSyncJob;
import com.bailuntec.utils.PropertiesUtil; import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration; import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration; import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
...@@ -29,6 +30,7 @@ public class Application { ...@@ -29,6 +30,7 @@ public class Application {
new JobScheduler(createRegistryCenter(), createJobConfiguration1()).init(); new JobScheduler(createRegistryCenter(), createJobConfiguration1()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init(); new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration3()).init(); new JobScheduler(createRegistryCenter(), createJobConfiguration3()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration4()).init();
} }
private static CoordinatorRegistryCenter createRegistryCenter() { private static CoordinatorRegistryCenter createRegistryCenter() {
...@@ -55,6 +57,12 @@ public class Application { ...@@ -55,6 +57,12 @@ public class Application {
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build(); LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig; return simpleJobRootConfig;
} }
private static LiteJobConfiguration createJobConfiguration4() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME_PAYPAL_ACCOUNT"), propertiesUtil.getPropertyAsString("JOB_CRON_PAYPAL_ACCOUNT"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, PaypalAccountSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static JobEventConfiguration createJobEventConfiguration() { private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource()); JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
......
package com.bailuntec.job;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.entity.DcBasePaypalAccount;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBasePaypalAccountExample;
import com.bailuntec.domain.pojo.AccountResult;
import com.bailuntec.domain.pojo.PaypalAccountInfo;
import com.bailuntec.mapper.DcBasePaypalAccountMapper;
import com.bailuntec.support.PointJob;
import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.PropertiesUtil;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.List;
@Slf4j
public class PaypalAccountSyncJob extends PointJob {
private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
private OkHttpClient client = OkHttpUtil.getInstance();
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
Request request = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("PAYPAL_ACCOUNT_URL"))
.get()
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String resultStr = null;
try {
response = client.newCall(request).execute();
resultStr = response.body().string();
} catch (IOException e) {
throw new RuntimeException("调用paypal账户授权信息接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(resultStr)) {
AccountResult<PaypalAccountInfo> paypalAccountInfoResult = JSONObject.parseObject(resultStr, new TypeReference<AccountResult<PaypalAccountInfo>>(){});
if (paypalAccountInfoResult.getSuccess()!= null && paypalAccountInfoResult.getSuccess()) {
List<PaypalAccountInfo> result = paypalAccountInfoResult.getData();
if (result != null && result.size() > 0) {
DcBasePaypalAccountMapper mapper = SessionUtil.getSession().getMapper(DcBasePaypalAccountMapper.class);
DcBasePaypalAccount dcBasePaypalAccount = new DcBasePaypalAccount();
try {
for (PaypalAccountInfo paypalAccountInfo : result) {
BeanUtils.copyProperties(paypalAccountInfo, dcBasePaypalAccount);
dcBasePaypalAccount.setId(null);
int i = mapper.updateByExampleSelective(dcBasePaypalAccount, DcBasePaypalAccountExample.newAndCreateCriteria().andPaypalIdEqualTo(dcBasePaypalAccount.getPaypalId()).example());
if (i == 0) {
mapper.insertSelective(dcBasePaypalAccount);
}
}
} catch (Exception e) {
throw new RuntimeException("Mybatis操作DB失败",e);
} finally {
SessionUtil.closeSession();
}
}
} else {
throw new RuntimeException("调用公司账户授权信息接口返回错误");
}
} else {
throw new RuntimeException("调用公司账户授权信息接口返回null");
}
}
}
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
COMPANY_INFO_URL=http://172.31.255.10/GetCompanys COMPANY_INFO_URL=http://172.31.255.10/GetCompanys
COMPANY_STAFF_URL=http://172.31.255.10/GetUserByCompany COMPANY_STAFF_URL=http://172.31.255.10/GetUserByCompany
COMPANY_ACCOUNT_URL=http://10.0.6.17:8090/Api/GetAccountToken COMPANY_ACCOUNT_URL=http://10.0.6.17:8090/Api/GetAccountToken
PAYPAL_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetPayPalAccounts
...@@ -11,7 +11,9 @@ NAME_SPACE=data-center ...@@ -11,7 +11,9 @@ NAME_SPACE=data-center
JOB_NAME_COMPANY_INFO=base-sync-company-info JOB_NAME_COMPANY_INFO=base-sync-company-info
JOB_NAME_COMPANY_STAFF=base-sync-company-staff JOB_NAME_COMPANY_STAFF=base-sync-company-staff
JOB_NAME_COMPANY_ACCOUNT=base-sync-company-account JOB_NAME_COMPANY_ACCOUNT=base-sync-company-account
JOB_NAME_PAYPAL_ACCOUNT=base-sync-paypal-account
JOB_CRON_COMPANY_INFO=0 0 2/2 * * ? * JOB_CRON_COMPANY_INFO=0 0 2/2 * * ? *
JOB_CRON_COMPANY_STAFF=5 5 1/2 * * ? * JOB_CRON_COMPANY_STAFF=5 5 1/2 * * ? *
JOB_CRON_COMPANY_ACCOUNT=0 0/3 * * * ? * JOB_CRON_COMPANY_ACCOUNT=0 0/3 * * * ? *
JOB_CRON_PAYPAL_ACCOUNT=0 0/3 * * * ? *
SHARDING_TOTAL_COUNT=1 SHARDING_TOTAL_COUNT=1
\ No newline at end of file
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBasePaypalAccount;
import com.bailuntec.domain.example.DcBasePaypalAccountExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcBasePaypalAccountMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
long countByExample(DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int deleteByExample(DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int insert(DcBasePaypalAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int insertSelective(DcBasePaypalAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBasePaypalAccount selectOneByExample(DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
List<DcBasePaypalAccount> selectByExample(DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
DcBasePaypalAccount selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBasePaypalAccount record, @Param("example") DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBasePaypalAccount record, @Param("example") DcBasePaypalAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBasePaypalAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBasePaypalAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBasePaypalAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_paypal_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBasePaypalAccount record);
}
\ No newline at end of file
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