Commit 1d8a624c by wutong

数据中心新增定时同步账号授权信息

parent f6c44f83
package com.bailuntec; package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
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.utils.PropertiesUtil; import com.bailuntec.utils.PropertiesUtil;
...@@ -27,6 +28,7 @@ public class Application { ...@@ -27,6 +28,7 @@ public class Application {
public static void main(String[] args) { public static void main(String[] args) {
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();
} }
private static CoordinatorRegistryCenter createRegistryCenter() { private static CoordinatorRegistryCenter createRegistryCenter() {
...@@ -47,6 +49,12 @@ public class Application { ...@@ -47,6 +49,12 @@ public class Application {
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build(); LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig; return simpleJobRootConfig;
} }
private static LiteJobConfiguration createJobConfiguration3() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME_COMPANY_ACCOUNT"), propertiesUtil.getPropertyAsString("JOB_CRON_COMPANY_ACCOUNT"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, CompanyAccountSyncJob.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.domain.pojo;
import lombok.Data;
import java.util.List;
@Data
public class AccountResult<T> {
private List<T> Data;
private Boolean Success;
private String Message;
}
package com.bailuntec.domain.pojo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class CompanyAccountInfo {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.company_id
*
* @mbg.generated
*/
@JSONField(name = "UserId")
private Integer companyId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.account_id
*
* @mbg.generated
*/
@JSONField(name = "Id")
private Integer accountId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.account_name
*
* @mbg.generated
*/
@JSONField(name = "Account")
private String accountName;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.account_email
*
* @mbg.generated
*/
@JSONField(name = "EmailAccount")
private String accountEmail;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.oms_code
*
* @mbg.generated
*/
@JSONField(name = "OmsCode")
private String omsCode;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.oms_account
*
* @mbg.generated
*/
@JSONField(name = "OmsAccount")
private String omsAccount;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.platform_id
*
* @mbg.generated
*/
@JSONField(name = "PlatformId")
private Integer platformId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.platform_cn
*
* @mbg.generated
*/
@JSONField(name = "Platform")
private String platformCn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.platform_en
*
* @mbg.generated
*/
@JSONField(name = "PlatformEn")
private String platformEn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.site_id
*
* @mbg.generated
*/
@JSONField(name = "SiteId")
private Integer siteId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.site_cn
*
* @mbg.generated
*/
@JSONField(name = "Site")
private String siteCn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.site_en
*
* @mbg.generated
*/
@JSONField(name = "SiteEn")
private String siteEn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.auth_json
*
* @mbg.generated
*/
@JSONField(name = "AuthJson")
private String authJson;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.status
*
* @mbg.generated
*/
@JSONField(name = "Status")
private Boolean status;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.status_cn
*
* @mbg.generated
*/
@JSONField(name = "StatusCn")
private String statusCn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.soap_auth_token
*
* @mbg.generated
*/
@JSONField(name = "SoapAuthToken")
private String soapAuthToken;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.soap_auth_status
*
* @mbg.generated
*/
@JSONField(name = "SoapAuthStatus")
private Integer soapAuthStatus;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.auth_status
*
* @mbg.generated
*/
@JSONField(name = "AuthStatus")
private Integer authStatus;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.extension_info
*
* @mbg.generated
*/
@JSONField(name = "ExtensionInfo")
private String extensionInfo;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.developer_json
*
* @mbg.generated
*/
@JSONField(name = "DeveloperJson")
private String developerJson;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.manager
*
* @mbg.generated
*/
@JSONField(name = "Manager")
private String manager;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.seller_id
*
* @mbg.generated
*/
@JSONField(name = "SellerId")
private String sellerId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_company_account.ebay_ad_auth_json
*
* @mbg.generated
*/
@JSONField(name = "EbayAdAuthJson")
private String ebayAdAuthJson;
}
\ No newline at end of file
package com.bailuntec.job;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.entity.DcBaseCompanyAccount;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseCompanyAccountExample;
import com.bailuntec.domain.pojo.AccountResult;
import com.bailuntec.domain.pojo.CompanyAccountInfo;
import com.bailuntec.mapper.DcBaseCompanyAccountMapper;
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.time.LocalDateTime;
import java.util.List;
@Slf4j
public class CompanyAccountSyncJob 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("COMPANY_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("调用公司账户授权信息接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(resultStr)) {
AccountResult<CompanyAccountInfo> companyAccountInfoResult = JSONObject.parseObject(resultStr, new TypeReference<AccountResult<CompanyAccountInfo>>(){});
if (companyAccountInfoResult.getSuccess()!= null && companyAccountInfoResult.getSuccess()) {
List<CompanyAccountInfo> result = companyAccountInfoResult.getData();
if (result != null && result.size() > 0) {
DcBaseCompanyAccountMapper mapper = SessionUtil.getSession().getMapper(DcBaseCompanyAccountMapper.class);
DcBaseCompanyAccount dcBaseCompanyAccount = new DcBaseCompanyAccount();
try {
for (CompanyAccountInfo companyAccountInfo : result) {
BeanUtils.copyProperties(dcBaseCompanyAccount, companyAccountInfo);
dcBaseCompanyAccount.setBjModified(LocalDateTime.now());
int i = mapper.updateByExampleSelective(dcBaseCompanyAccount, DcBaseCompanyAccountExample.newAndCreateCriteria().andCompanyIdEqualTo(companyAccountInfo.getCompanyId()).andAccountIdEqualTo(companyAccountInfo.getAccountId()).example());
if (i == 0) {
mapper.insertSelective(dcBaseCompanyAccount);
}
}
} catch (Exception e) {
throw new RuntimeException("Mybatis操作DB失败",e);
} finally {
SessionUtil.closeSession();
}
}
} else {
throw new RuntimeException("调用公司账户授权信息接口返回错误");
}
} else {
throw new RuntimeException("调用公司账户授权信息接口返回null");
}
}
}
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseCompanyAccount;
import com.bailuntec.domain.example.DcBaseCompanyAccountExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface DcBaseCompanyAccountMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
long countByExample(DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int deleteByExample(DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int insert(DcBaseCompanyAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int insertSelective(DcBaseCompanyAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBaseCompanyAccount selectOneByExample(DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
List<DcBaseCompanyAccount> selectByExample(DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
DcBaseCompanyAccount selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBaseCompanyAccount record, @Param("example") DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBaseCompanyAccount record, @Param("example") DcBaseCompanyAccountExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBaseCompanyAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBaseCompanyAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBaseCompanyAccount record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_company_account
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseCompanyAccount record);
}
\ No newline at end of file
COMPANY_INFO_URL=http://sso.bailuntec.com/GetCompanys COMPANY_INFO_URL=http://sso.bailuntec.com/GetCompanys
COMPANY_STAFF_URL=http://sso.bailuntec.com/GetUserByCompany COMPANY_STAFF_URL=http://sso.bailuntec.com/GetUserByCompany
COMPANY_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetAccountToken
...@@ -10,6 +10,8 @@ ZOOKEEPER_SERVER=172.31.255.120:2181 ...@@ -10,6 +10,8 @@ ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center 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_CRON_COMPANY_INFO=0 0 2/4 * * ? * JOB_CRON_COMPANY_INFO=0 0 2/4 * * ? *
JOB_CRON_COMPANY_STAFF=5 5 1/4 * * ? * JOB_CRON_COMPANY_STAFF=5 5 1/4 * * ? *
JOB_CRON_COMPANY_ACCOUNT=0 0 1/2 * * ? *
SHARDING_TOTAL_COUNT=1 SHARDING_TOTAL_COUNT=1
\ No newline at end of file
import com.bailuntec.domain.entity.JobPointLog; import com.bailuntec.domain.entity.JobPointLog;
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 org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -9,12 +10,18 @@ public class CompanyTest { ...@@ -9,12 +10,18 @@ public class CompanyTest {
@Test @Test
public void test() { public void test() {
CompanyInfoSyncJob skuSyncJob = new CompanyInfoSyncJob(); CompanyInfoSyncJob skuSyncJob = new CompanyInfoSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29))); skuSyncJob.executeJob(null, new JobPointLog("",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29)));
} }
@Test @Test
public void test2() { public void test2() {
CompanyStaffSyncJob skuSyncJob = new CompanyStaffSyncJob(); CompanyStaffSyncJob skuSyncJob = new CompanyStaffSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29))); skuSyncJob.executeJob(null, new JobPointLog("",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29)));
}
@Test
public void test3() {
CompanyAccountSyncJob skuSyncJob = new CompanyAccountSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29)));
} }
} }
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