Commit d77fc722 by yinyong

同步半成品总库存流水报表

parent 71251015
......@@ -2,6 +2,7 @@ package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.SemiOrderSyncJob;
import com.bailuntec.job.SemiStockReportSyncJob;
import com.bailuntec.listener.SemiOrderSyncJobListener;
import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
......@@ -26,6 +27,7 @@ public class Application {
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 SemiOrderSyncJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration1(), createJobEventConfiguration()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
......@@ -41,6 +43,13 @@ public class Application {
return simpleJobRootConfig;
}
private static LiteJobConfiguration createJobConfiguration1() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_STOCK_NAME"), propertiesUtil.getPropertyAsString("JOB_STOCK_CRON"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SemiStockReportSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
return jobEventRdbConfig;
......
......@@ -7,9 +7,9 @@ import lombok.Data;
import java.util.List;
@Data
public class SemiOrderResultInfo {
public class SemiResultInfo<T> {
private Boolean success;
private List<DcSemiOrder> data;
private List<T> data;
}
package com.bailuntec.job;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcSemiOrder;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.pojo.SemiOrderResultInfo;
import com.bailuntec.domain.pojo.ResultData;
import com.bailuntec.domain.pojo.SemiResultInfo;
import com.bailuntec.mapper.DcSemiOrderMapper;
import com.bailuntec.mapper.JobPointLogMapper;
import com.bailuntec.support.PointJob;
import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.PropertiesUtil;
......@@ -56,7 +56,7 @@ public class SemiOrderSyncJob extends PointJob {
}
}
if (StringUtils.isNoneBlank(palResultStr)) {
SemiOrderResultInfo palResultRoot = JSON.parseObject(palResultStr, SemiOrderResultInfo.class);
SemiResultInfo<DcSemiOrder> palResultRoot = JSONObject.parseObject(palResultStr, new TypeReference<SemiResultInfo<DcSemiOrder>>(){});
if (palResultRoot != null && palResultRoot.getSuccess().booleanValue()) {
List<DcSemiOrder> resultData = palResultRoot.getData();
if (resultData != null && resultData.size() > 0) {
......
package com.bailuntec.job;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcSemiStockReport;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.pojo.SemiResultInfo;
import com.bailuntec.mapper.DcSemiStockReportMapper;
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 com.google.gson.JsonObject;
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.LinkedHashMap;
import java.util.List;
@Slf4j
public class SemiStockReportSyncJob 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("SEMI_STOCK_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)) {
SemiResultInfo<DcSemiStockReport> palResultRoot = JSONObject.parseObject(palResultStr, new TypeReference<SemiResultInfo<DcSemiStockReport>>(){});
if (palResultRoot != null && palResultRoot.getSuccess().booleanValue()) {
List<DcSemiStockReport> resultData = palResultRoot.getData();
if (resultData != null && resultData.size() > 0) {
for(DcSemiStockReport semiStockReport : resultData) {
semiStockReport.setId(null);
DcSemiStockReportMapper mapper = SessionUtil.getSession().getMapper(DcSemiStockReportMapper.class);
mapper.upsertSelective(semiStockReport);
}
}else{
break;
}
} else {
throw new RuntimeException("调用库存流水报表接口同步百伦库存流水失败, 响应200, 请求参数" + map.toString());
}
} else {
throw new RuntimeException("调用库存流水报表接口同步百伦库存流水失败, 响应为null, 请求参数" + map.toString());
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1);
} while (true);
jobPointLog.setPageIndex(0);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()));
}
}
SEMI_ORDER_URL=http://mjzz.bailuntec.com/api/ApiOrderApply
SEMI_STOCK_URL=http://mjzz.bailuntec.com/Material/FullStockLogPage
\ No newline at end of file
......@@ -11,4 +11,6 @@ ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center
JOB_NAME=base-sync-semi-order
JOB_CRON=0/1 * * * * ? *
JOB_STOCK_NAME=base_sync_semi_stock
JOB_STOCK_CRON=0/10 * * * * ? *
SHARDING_TOTAL_COUNT=1
\ No newline at end of file
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcSemiStockReport;
import com.bailuntec.domain.example.DcSemiStockReportExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcSemiStockReportMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
long countByExample(DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int deleteByExample(DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int insert(DcSemiStockReport record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int insertSelective(DcSemiStockReport record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcSemiStockReport selectOneByExample(DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
List<DcSemiStockReport> selectByExample(DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
DcSemiStockReport selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcSemiStockReport record, @Param("example") DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcSemiStockReport record, @Param("example") DcSemiStockReportExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcSemiStockReport record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
*/
int updateByPrimaryKey(DcSemiStockReport record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcSemiStockReport record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_stock_report
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcSemiStockReport 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