Commit bd72b641 by yinyong

Paypal流水同步

parent b33d5a31
FROM maven:3.6.0-alpine
RUN apk add ca-certificates && \
apk add tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# make source folder
RUN mkdir -p /usr/app
WORKDIR /usr/app
# install maven dependency packages (keep in image)
COPY data-parent /usr/app/data-parent
COPY data-common /usr/app/data-common
COPY data-base /usr/app/data-base
COPY data-mid /usr/app/data-mid
COPY data-show /usr/app/data-show
RUN cd /usr/app/data-parent && mvn -T 1C install -pl ../data-base/base-sync-paypal -am
#指定容器启动程序及参数 <ENTRYPOINT> "<CMD>"
EXPOSE 8080
ENTRYPOINT ["java","-Xms30m","-Xmx80m","-jar","/usr/app/data-base/base-sync-paypal/target/base-sync-paypal-1.0-SNAPSHOT.jar"]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>data-base</artifactId>
<groupId>com.bailuntec</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-sync-paypal</artifactId>
<dependencies>
<dependency>
<groupId>com.bailuntec</groupId>
<artifactId>data-common</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.bailuntec.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<!--默认是true-->
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
</project>
package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.PayPalSyncJob;
import com.bailuntec.listener.PayPalSyncJobListener;
import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.event.JobEventConfiguration;
import com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
@Slf4j
public class Application {
private static PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("job");
private static final String EVENT_RDB_STORAGE_DRIVER = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_DRIVER");
private static final String EVENT_RDB_STORAGE_URL = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_URL");
private static final String EVENT_RDB_STORAGE_USERNAME = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_USERNAME");
private static final String EVENT_RDB_STORAGE_PASSWORD = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_PASSWORD");
public static void main(String[] args) {
new JobScheduler(createRegistryCenter(), createJobConfiguration(),createJobEventConfiguration(), new PayPalSyncJobListener()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(propertiesUtil.getPropertyAsString("ZOOKEEPER_SERVER"), propertiesUtil.getPropertyAsString("NAME_SPACE")));
regCenter.init();
return regCenter;
}
private static LiteJobConfiguration createJobConfiguration() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME"), propertiesUtil.getPropertyAsString("JOB_CRON"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, PayPalSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
return jobEventRdbConfig;
}
private static DataSource setUpEventTraceDataSource() {
DruidDataSource result = new DruidDataSource();
result.setDriverClassName(EVENT_RDB_STORAGE_DRIVER);
result.setUrl(EVENT_RDB_STORAGE_URL);
result.setUsername(EVENT_RDB_STORAGE_USERNAME);
result.setPassword(EVENT_RDB_STORAGE_PASSWORD);
return result;
}
}
package com.bailuntec.domain.pojo;
import com.bailuntec.domain.entity.DcBaseFinancePaypal;
import lombok.Data;
@Data
public class PayPalResultInfo {
private Boolean success;
private ResultData<DcBaseFinancePaypal> data;
}
package com.bailuntec.domain.pojo;
import lombok.Data;
import java.util.List;
@Data
public class ResultData<T> {
private Integer currentPage;
private Integer totalPages;
private Integer totalItems;
private Integer itemsPerPage;
private List<T> items;
private String context;
}
package com.bailuntec.job;
import com.alibaba.fastjson.JSON;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.*;
import com.bailuntec.domain.pojo.PayPalResultInfo;
import com.bailuntec.domain.pojo.ResultData;
import com.bailuntec.domain.entity.DcBaseFinancePaypal;
import com.bailuntec.mapper.DcBaseFinancePaypalMapper;
import com.bailuntec.mapper.JobPointLogMapper;
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.lang3.StringUtils;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Slf4j
public class PayPalSyncJob extends PointJob {
private OkHttpClient okHttpClient = OkHttpUtil.getInstance();
private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(4);
map.put("rows", jobPointLog.getPageSize().toString());
map.put("btime", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getStartTime()));
map.put("etime", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getEndTime()));
do {
map.put("page", jobPointLog.getPageIndex().equals(0) ? "1" : jobPointLog.getPageIndex().toString());
Response response = null;
String palResultStr = null;
try {
Request request = new Request.Builder()
.get()
.url(OkHttpUtil.attachHttpGetParams(propertiesUtil.getPropertyAsString("PAYPAL_URL"), map))
.addHeader("Content-Type", "application/json")
.build();
response = okHttpClient.newCall(request).execute();
palResultStr = response.body().string();
} catch (IOException e) {
throw new RuntimeException(map + "请求流水接口同步百伦接口失败" + response, e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNoneBlank(palResultStr)) {
PayPalResultInfo palResultRoot = JSON.parseObject(palResultStr, PayPalResultInfo.class);
if (palResultRoot != null && palResultRoot.getSuccess().booleanValue()) {
ResultData<DcBaseFinancePaypal> resultData = palResultRoot.getData();
if (jobPointLog.getPageIndex().equals(0)) {
jobPointLog.setPageIndex(resultData.getTotalPages() + 1);
}
if (resultData.getItems() != null && resultData.getItems().size() > 0) {
handlePayPalJson(resultData.getItems(), jobPointLog);
}
} else {
throw new RuntimeException("调用流水接口同步百伦流水失败, 响应200, 请求参数" + map.toString());
}
} else {
throw new RuntimeException("调用流水接口同步百伦流水失败, 响应为null, 请求参数" + map.toString());
}
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();
}
}
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()));
}
private void handlePayPalJson(List<DcBaseFinancePaypal> data, JobPointLog jobPointLog) {
try{
DcBaseFinancePaypalMapper mapper = SessionUtil.getSession().getMapper(DcBaseFinancePaypalMapper.class);
for(DcBaseFinancePaypal paypal : data) {
paypal.setGmtCreateTime(LocalDateTime.now());
mapper.upsertSelective(paypal);
}
}catch (RuntimeException e) {
throw new RuntimeException("MYBATIS操作流水失败",e);
}finally {
SessionUtil.closeSession();
}
}
}
package com.bailuntec.listener;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
public class PayPalSyncJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
}
@Override
public void afterJobExecuted(ShardingContexts shardingContexts) {
}
}
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseFinancePaypal;
import com.bailuntec.domain.example.DcBaseFinancePaypalExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcBaseFinancePaypalMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
long countByExample(DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int deleteByExample(DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int insert(DcBaseFinancePaypal record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int insertSelective(DcBaseFinancePaypal record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBaseFinancePaypal selectOneByExample(DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
List<DcBaseFinancePaypal> selectByExample(DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
DcBaseFinancePaypal selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBaseFinancePaypal record, @Param("example") DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBaseFinancePaypal record, @Param("example") DcBaseFinancePaypalExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBaseFinancePaypal record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBaseFinancePaypal record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBaseFinancePaypal record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_finance_paypal
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseFinancePaypal record);
}
\ No newline at end of file
PAYPAL_URL=http://crm.bailuntec.com/api/PaypalLog
#EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
#EVENT_RDB_STORAGE_URL=jdbc:mysql://127.0.0.1:3306/bailun_datacenter?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=GMT&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
#EVENT_RDB_STORAGE_USERNAME=root
#EVENT_RDB_STORAGE_PASSWORD=root
#ZOOKEEPER_SERVER=94.191.111.219:2181
EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
EVENT_RDB_STORAGE_URL=jdbc:mysql://10.0.8.15:3306/bailun_datacenter?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
EVENT_RDB_STORAGE_USERNAME=root
EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf
ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center
JOB_NAME=base-sync-paypal
JOB_CRON=0/1 * * * * ? *
SHARDING_TOTAL_COUNT=1
\ No newline at end of file
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<module>base-sync-cost-first</module> <module>base-sync-cost-first</module>
<module>base-sync-company</module> <module>base-sync-company</module>
<module>base-sync-finance-ebay</module> <module>base-sync-finance-ebay</module>
<module>base-sync-paypal</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>
......
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