Commit 2c4348c4 by wutong

修改SKUMS同步为新的增量接口

parent 6e07ebbd
package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.SkuSyncByCreateTimeJob;
import com.bailuntec.job.SkuSyncJob;
import com.bailuntec.listener.SkuSyncByCreateTimeJobListener;
import com.bailuntec.listener.SkuSyncByUpdateTimeJobListener;
import com.bailuntec.listener.SkuSyncJobListener;
import com.bailuntec.job.SkuMSSyncJob;
import com.bailuntec.listener.SkuMSSyncJobListener;
import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
......@@ -28,9 +25,7 @@ public class Application {
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 SkuSyncJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration1(),createJobEventConfiguration(), new SkuSyncByCreateTimeJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration2(),createJobEventConfiguration(), new SkuSyncByUpdateTimeJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration(),createJobEventConfiguration(), new SkuMSSyncJobListener()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
......@@ -41,20 +36,7 @@ public class Application {
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, SkuSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static LiteJobConfiguration createJobConfiguration1() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME_CREATE"), propertiesUtil.getPropertyAsString("JOB_CRON_CREATE"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SkuSyncByCreateTimeJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static LiteJobConfiguration createJobConfiguration2() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME_UPDATE"), propertiesUtil.getPropertyAsString("JOB_CRON_UPDATE"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).misfire(false).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SkuSyncByCreateTimeJob.class.getCanonicalName());
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SkuMSSyncJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
......
package com.bailuntec.domain.pojo;
import java.math.BigDecimal;
public class GetSupplierInfo {
/// <summary>
/// 标识主键
/// </summary>
public Integer id;
/// <summary>
/// 关系表主键
/// </summary>
public Integer relationId;
/// <summary>
/// 商品主键
/// </summary>
public Integer mainId;
/// <summary>
/// sku主键
/// </summary>
public Integer sId;
/// <summary>
/// sku
/// </summary>
public String sku;
/// <summary>
/// 询价员Id
/// </summary>
public Integer enquiryId;
/// <summary>
/// 询价员
/// </summary>
public String enquiryName;
/// <summary>
/// 供应商Id
/// </summary>
public Integer deliverId;
/// <summary>
/// 供应商
/// </summary>
public String deliverName;
/// <summary>
/// 供应商链接
/// </summary>
public String link;
/// <summary>
/// 供应商报价
/// </summary>
public BigDecimal price;
/// <summary>
/// 交期(天)
/// </summary>
public Integer delivery;
/// <summary>
/// 最小订单量
/// </summary>
public Integer moq;
/// <summary>
/// 内部moq
/// </summary>
public Integer IntegerernalMoq;
/// <summary>
/// 是否默认供应商1是,0否
/// </summary>
public Integer isDefault;
/// <summary>
/// 备注
/// </summary>
public String remark;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getRelationId() {
return relationId;
}
public void setRelationId(Integer relationId) {
this.relationId = relationId;
}
public Integer getMainId() {
return mainId;
}
public void setMainId(Integer mainId) {
this.mainId = mainId;
}
public Integer getsId() {
return sId;
}
public void setsId(Integer sId) {
this.sId = sId;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public Integer getEnquiryId() {
return enquiryId;
}
public void setEnquiryId(Integer enquiryId) {
this.enquiryId = enquiryId;
}
public String getEnquiryName() {
return enquiryName;
}
public void setEnquiryName(String enquiryName) {
this.enquiryName = enquiryName;
}
public Integer getDeliverId() {
return deliverId;
}
public void setDeliverId(Integer deliverId) {
this.deliverId = deliverId;
}
public String getDeliverName() {
return deliverName;
}
public void setDeliverName(String deliverName) {
this.deliverName = deliverName;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public Integer getDelivery() {
return delivery;
}
public void setDelivery(Integer delivery) {
this.delivery = delivery;
}
public Integer getMoq() {
return moq;
}
public void setMoq(Integer moq) {
this.moq = moq;
}
public Integer getIntegerernalMoq() {
return IntegerernalMoq;
}
public void setIntegerernalMoq(Integer integerernalMoq) {
IntegerernalMoq = integerernalMoq;
}
public Integer getIsDefault() {
return isDefault;
}
public void setIsDefault(Integer isDefault) {
this.isDefault = isDefault;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
package com.bailuntec.domain.pojo;
import lombok.Data;
@Data
public class GetWareAreaInfo {
/// <summary>
/// 标识主键
/// </summary>
public Integer id;
/// <summary>
/// sku主键
/// </summary>
public Integer sId;
/// <summary>
/// sku
/// </summary>
public String sku;
/// <summary>
/// 区域Id
/// </summary>
public Integer areaId;
/// <summary>
/// 仓库Code
/// </summary>
public String wareCode;
}
package com.bailuntec.domain.pojo;
import lombok.Data;
@Data
public class SkuMsResponse {
private SkuMsResult result;
private Integer statusCode;
private String message;
}
package com.bailuntec.domain.pojo;
import lombok.Data;
import java.util.List;
@Data
public class SkuMsResult {
private Integer rows;
private String costtime;
private List<SkuInfo> data;
private Integer pageIndex;
private Integer total;
private Integer totalPage;
}
package com.bailuntec.domain.request;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class SkuCondition {
private LocalDateTime startime;
private LocalDateTime endtime;
public SkuCondition() {
}
public SkuCondition(LocalDateTime startime, LocalDateTime endtime) {
this.startime = startime;
this.endtime = endtime;
}
}
package com.bailuntec.domain.request;
import lombok.Data;
@Data
public class SkumsRequest {
private Integer pageIndex;
private Integer pageNumber;
private String sortField;
private String sort;
private Integer total;
private String conditionJson;
private String searchKeyWord;
}
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.DcBaseSku;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseSkuExample;
import com.bailuntec.domain.pojo.CommonSkuCondition;
import com.bailuntec.domain.pojo.CommonSkuProductInfo;
import com.bailuntec.domain.pojo.SkuData;
import com.bailuntec.mapper.DcBaseSkuMapper;
import com.bailuntec.mapper.DcBaseWarehouseMapper;
import com.bailuntec.mapper.JobPointLogMapper;
import com.bailuntec.utils.DigestUtils;
import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.PropertiesUtil;
import com.bailuntec.utils.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
@Slf4j
public class SkuJsonHandle {
private static PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
/**
* 给SKUMS发请求, 请求需加密
*
* @param skuConditionDto
* @return
* @throws Exception
*/
static void skuMSRequest(CommonSkuCondition skuConditionDto, JobPointLog jobPointLog) {
OkHttpClient client = OkHttpUtil.getInstance();
do {
skuConditionDto.setPage(jobPointLog.getPageIndex() > 0 ? jobPointLog.getPageIndex() : 1);
SkuData skuDataDto = new SkuData();
skuDataDto.setCode(CommonConstant.OBJPRO_CODE);
skuDataDto.setKey(CommonConstant.ALL_OBJPRO_KEY);
String data = null;
try {
skuDataDto.setData(URLEncoder.encode(JSON.toJSONString(skuConditionDto), "utf8"));//将请求参数转为JSON 再Url编码
data = URLEncoder.encode(JSON.toJSONString(skuDataDto), "utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException("同步SKU信息JSON解析失败", e);
}
//第一次MD5加密
String str = DigestUtils.md5DigestAsHex((CommonConstant.ALL_OBJPRO_KEY + skuDataDto.getData()).getBytes());
//第二次MD5加密
String sign = DigestUtils.md5DigestAsHex((CommonConstant.SKU_APPKEY + CommonConstant.OBJPRO_CODE + str).getBytes());
//真正请求的参数
LinkedHashMap<String, String> map = new LinkedHashMap<>(3);
map.put("data", data);
map.put("appId", CommonConstant.SKU_APPID);
map.put("sign", sign);
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Response response = null;
String skuStr = null;
try {
Request request = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("SKU_URL"))
.post(body)
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request).execute();
skuStr = response.body().string();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("调用同步SKU信息接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(skuStr)) {
JSONObject jsonNode = JSON.parseObject(skuStr);
Integer resultCode = jsonNode.getIntValue("result_code");
if (resultCode != null && resultCode == 1) {
String resultUrlSku = jsonNode.getString("data");
JSONObject jsonObject1 = null;
try {
jsonObject1 = JSON.parseObject(URLDecoder.decode(resultUrlSku, "utf8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("同步SKU信息JSON解URL编码失败", e);
}
//如果是0, 则保存总页数, 降序查
if (jobPointLog.getPageIndex().equals(0)) {
jobPointLog.setPageIndex(jsonObject1.getIntValue("TotalPages") + 1);
}
/*
* 转化JSON,
* 去处理SKU信息
*/
List<CommonSkuProductInfo> allSkuProductInfoList = jsonObject1.getObject("Items", new TypeReference<List<CommonSkuProductInfo>>() {
});
if (allSkuProductInfoList != null && allSkuProductInfoList.size() > 0) {
handleSkuResultJSON(allSkuProductInfoList);
}
} else {
throw new RuntimeException("调用同步SKU信息接口失败" + skuStr);
}
} else {
throw new RuntimeException("调用同步SKU信息接口失败");
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() - 1);
if (jobPointLog.getPageIndex() % 5 == 0) {
try {
JobPointLogMapper jobPointLogMapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
jobPointLogMapper.upsertSelective(jobPointLog);
} catch (Exception e) {
throw new RuntimeException("MYBATIS操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
}
} while (jobPointLog.getPageIndex() > 0);
jobPointLog.setPageIndex(0);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getEndTime().plusDays(jobPointLog.getIntervalTime()));
}
static void handleSkuResultJSON(List<CommonSkuProductInfo> allSkuProductInfoList) {
try {
DcBaseSkuMapper dcBaseSkuMapper = SessionUtil.getSession().getMapper(DcBaseSkuMapper.class);
for (CommonSkuProductInfo skuProductInfo : allSkuProductInfoList) {
log.warn(skuProductInfo.getBailunSku());
DcBaseSku dcBaseSku = new DcBaseSku();
try {
BeanUtils.copyProperties(dcBaseSku, skuProductInfo);
} catch (Exception e) {
throw new RuntimeException("BeanUtils.copyProperties失败");
}
if (StringUtils.isNotBlank(dcBaseSku.getWarehouseCode())) {
DcBaseWarehouseMapper dcBaseWarehouseMapper = SessionUtil.getSession().getMapper(DcBaseWarehouseMapper.class);
dcBaseSku.setWarehouseName(dcBaseWarehouseMapper.getWarehouseName(dcBaseSku.getWarehouseCode()));
}
String[] split = null;
if (skuProductInfo.getPackingSize() != null) {
split = skuProductInfo.getPackingSize().split(",");
}
dcBaseSku.setBussinessId(dcBaseSku.getSellerId());
dcBaseSku.setBussinessName(dcBaseSku.getSellerName());
dcBaseSku.setLength((split != null && split.length > 0 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[0]).matches()) ? new BigDecimal(split[0]).setScale(3, RoundingMode.HALF_EVEN) : BigDecimal.ZERO);
dcBaseSku.setWidth((split != null && split.length > 1 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[1]).matches()) ? new BigDecimal(split[1]).setScale(3, RoundingMode.HALF_EVEN) : BigDecimal.ZERO);
dcBaseSku.setHeight((split != null && split.length > 2 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[2]).matches()) ? new BigDecimal(split[2]).setScale(3, RoundingMode.HALF_EVEN) : BigDecimal.ZERO);
dcBaseSku.setWeight(skuProductInfo.getWeight() != null ? skuProductInfo.getWeight() : BigDecimal.ZERO.add(skuProductInfo.getPackingWeight() != null ? skuProductInfo.getPackingWeight() : BigDecimal.ZERO));
dcBaseSku.setGmtModified(LocalDateTime.now());
int i = dcBaseSkuMapper.updateByExampleSelective(dcBaseSku, DcBaseSkuExample.newAndCreateCriteria().andBailunSkuEqualTo(dcBaseSku.getBailunSku()).example());
if (i == 0) {
dcBaseSkuMapper.insertSelective(dcBaseSku);
}
}
} catch (Exception e) {
throw new RuntimeException("MYBATIS操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
}
}
package com.bailuntec.job;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bailuntec.domain.entity.DcBaseSkuTemp;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseSkuTempExample;
import com.bailuntec.domain.pojo.SkuInfo;
import com.bailuntec.domain.pojo.SkuMsResponse;
import com.bailuntec.domain.pojo.SkuMsResult;
import com.bailuntec.domain.request.SkuCondition;
import com.bailuntec.domain.request.SkumsRequest;
import com.bailuntec.mapper.DcBaseSkuTempMapper;
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.*;
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 SkuMSSyncJob extends PointJob {
private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
private OkHttpClient client = OkHttpUtil.getInstance();
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
SkumsRequest skumsRequest = new SkumsRequest();
skumsRequest.setConditionJson(JSON.toJSONString(new SkuCondition(jobPointLog.getStartTime().minusMinutes(3), jobPointLog.getEndTime())));
skumsRequest.setPageNumber(jobPointLog.getPageSize());
do {
MediaType mediaType = MediaType.parse("application/json");
skumsRequest.setPageIndex(jobPointLog.getPageIndex() > 0?jobPointLog.getPageIndex() : 1);
log.warn(JSON.toJSONString(skumsRequest));
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(skumsRequest));
Request request = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("SKU_URL"))
.post(body)
.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("调用SKUMS系统接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(resultStr)) {
SkuMsResponse skuMsResponse = JSONObject.parseObject(resultStr, SkuMsResponse.class);
if (skuMsResponse.getStatusCode()!= null && skuMsResponse.getStatusCode().equals(200)) {
SkuMsResult result = skuMsResponse.getResult();
if (result != null) {
List<SkuInfo> data = result.getData();
if (data != null && data.size() > 0) {
handleSkuMsJson(data,jobPointLog);
}
if (jobPointLog.getPageIndex().equals(0) && result.getTotalPage() != null) {
jobPointLog.setPageIndex(result.getTotalPage());
}
}
} else {
throw new RuntimeException("调用SKUMS系统接口返回错误");
}
} else {
throw new RuntimeException("调用SKUMS系统接口返回null");
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() - 1);
} while (jobPointLog.getPageIndex() > 0);
jobPointLog.setPageIndex(0);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()));
}
private void handleSkuMsJson(List<SkuInfo> data,JobPointLog jobPointLog) {
DcBaseSkuTemp dcBaseSku = new DcBaseSkuTemp();
try {
DcBaseSkuTempMapper mapper = SessionUtil.getSession().getMapper(DcBaseSkuTempMapper.class);
for (SkuInfo skuInfo : data) {
try {
BeanUtils.copyProperties(dcBaseSku,skuInfo);
} catch (Exception e) {
throw new RuntimeException("BeanUtils.copyProperties失败");
}
dcBaseSku.setGmtModified(LocalDateTime.now());
int v = mapper.updateByExampleSelective(dcBaseSku, DcBaseSkuTempExample.newAndCreateCriteria().andBailunSkuEqualTo(skuInfo.getBailunSku()).example());
if (v == 0) {
mapper.insertSelective(dcBaseSku);
}
}
if (jobPointLog.getPageIndex() % 10 == 0) {
JobPointLogMapper jobPointLogMapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
jobPointLogMapper.upsertSelective(jobPointLog);
}
} catch (RuntimeException e) {
throw new RuntimeException("MYBATIS操作SKU失败",e);
} finally {
SessionUtil.closeSession();
}
}
}
package com.bailuntec.job;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.pojo.CommonSkuCondition;
import com.bailuntec.support.PointJob;
import com.dangdang.ddframe.job.api.ShardingContext;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class SkuSyncByCreateTimeJob extends PointJob {
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
//SKUMS接口需要的请求参数
CommonSkuCondition skuConditionDto = new CommonSkuCondition();
skuConditionDto.setResultType(2);//分页
skuConditionDto.setPageSize(jobPointLog.getPageSize());
skuConditionDto.setStatus(-1);
//传这个所有上传状态都能拿
skuConditionDto.setIsUpApi("");
skuConditionDto.setIsFinish(-1);
//有ResultWare返回发货仓库信息
skuConditionDto.setIsResultWare(1);
//有UpdateDate只查当天更新的数据-增量更新
skuConditionDto.setBeginCT(jobPointLog.getStartTime().minusMinutes(10).format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)));
jobPointLog.setEndTime(LocalDateTime.now());
skuConditionDto.setEndCT(jobPointLog.getEndTime().format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)));
SkuJsonHandle.skuMSRequest(skuConditionDto, jobPointLog);
}
}
package com.bailuntec.job;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.pojo.CommonSkuCondition;
import com.bailuntec.support.PointJob;
import com.dangdang.ddframe.job.api.ShardingContext;
import java.time.format.DateTimeFormatter;
public class SkuSyncByUpdateTimeJob extends PointJob {
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
//SKUMS接口需要的请求参数
CommonSkuCondition skuConditionDto = new CommonSkuCondition();
skuConditionDto.setResultType(2);//分页
skuConditionDto.setPageSize(jobPointLog.getPageSize());
skuConditionDto.setStatus(-1);
skuConditionDto.setIsFinish(-1);
//有ResultWare返回发货仓库信息
skuConditionDto.setIsResultWare(1);
//传这个所有上传状态都能拿
skuConditionDto.setIsUpApi("");
//有UpdateDate只查当天更新的数据-增量更新
skuConditionDto.setUpdateDate(jobPointLog.getStartTime().format(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT)));
SkuJsonHandle.skuMSRequest(skuConditionDto, jobPointLog);
}
}
package com.bailuntec.job;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.pojo.CommonSkuCondition;
import com.bailuntec.support.PointJob;
import com.dangdang.ddframe.job.api.ShardingContext;
public class SkuSyncJob extends PointJob {
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
//SKUMS接口需要的请求参数
CommonSkuCondition skuConditionDto = new CommonSkuCondition();
skuConditionDto.setResultType(2);//分页
skuConditionDto.setPageSize(jobPointLog.getPageSize());
skuConditionDto.setStatus(-1);
skuConditionDto.setIsFinish(-1);
//传这个所有上传状态都能拿
skuConditionDto.setIsUpApi("");
//有ResultWare返回发货仓库信息
skuConditionDto.setIsResultWare(1);
//有SKU只查提供的SKU
// skuConditionDto.setSkus("909117825");
//有UpdateDate只查当天更新的数据-增量更新
SkuJsonHandle.skuMSRequest(skuConditionDto, jobPointLog);
}
}
......@@ -3,7 +3,7 @@ package com.bailuntec.listener;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
public class SkuSyncByCreateTimeJobListener implements ElasticJobListener {
public class SkuMSSyncJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
......
package com.bailuntec.listener;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
public class SkuSyncByUpdateTimeJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
}
@Override
public void afterJobExecuted(ShardingContexts shardingContexts) {
}
}
package com.bailuntec.listener;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
public class SkuSyncJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
}
@Override
public void afterJobExecuted(ShardingContexts shardingContexts) {
}
}
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseSkuTemp;
import com.bailuntec.domain.example.DcBaseSkuTempExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcBaseSkuTempMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
long countByExample(DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int deleteByExample(DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int insert(DcBaseSkuTemp record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int insertSelective(DcBaseSkuTemp record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBaseSkuTemp selectOneByExample(DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
List<DcBaseSkuTemp> selectByExample(DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
DcBaseSkuTemp selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBaseSkuTemp record, @Param("example") DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBaseSkuTemp record, @Param("example") DcBaseSkuTempExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBaseSkuTemp record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBaseSkuTemp record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBaseSkuTemp record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_sku_temp
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseSkuTemp record);
}
\ No newline at end of file
# \u751F\u4EA7\u73AF\u5883
SKU_URL=http://10.0.6.13:8001/api/ApiCenter/SetData
SKU_URL=http://10.0.8.13:8000/api/sku/productsku/gmtproductskus
# \u7EBF\u4E0B\u73AF\u5883
#SKU_URL=http://api.sku.bailuntec.com/api/ApiCenter/SetData
# \u672C\u5730\u8C03\u8BD5
#SKU_URL=http://192.168.6.226:8014/api/ApiCenter/SetData
\ No newline at end of file
#SKU_URL=http://api.skums.bailuntec.com/api/sku/productsku/gmtproductskus
......@@ -8,10 +8,6 @@ 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-sku
JOB_NAME_CREATE=base-sku-create-time
JOB_NAME_UPDATE=base-sku-update-time
JOB_CRON=0 10 0 * * ? 2022
JOB_CRON_UPDATE=0 0/20 6-22 * * ? *
JOB_CRON_CREATE=0 0 22 * * ? *
JOB_NAME=base-sync-sku
JOB_CRON=0/10 * * * * ? *
SHARDING_TOTAL_COUNT=1
\ No newline at end of file
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.job.SkuSyncByCreateTimeJob;
import com.bailuntec.job.SkuSyncByUpdateTimeJob;
import com.bailuntec.job.SkuSyncJob;
import com.bailuntec.job.SkuMSSyncJob;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
public class SyncSkuTest {
@Test
public void test() {
SkuSyncJob skuSyncJob = new SkuSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,25,1,1, LocalDateTime.now(),LocalDateTime.now()));
SkuMSSyncJob skuSyncJob = new SkuMSSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,100,1,1, LocalDateTime.now().minusMonths(1),LocalDateTime.now().minusDays(29)));
}
@Test
public void tes1() {
SkuSyncByCreateTimeJob skuSyncJob = new SkuSyncByCreateTimeJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,100,1,1,
LocalDateTime.of(2019,03,01,0,0),
LocalDateTime.now()));
}
@Test
public void tes2() {
SkuSyncByUpdateTimeJob skuSyncJob = new SkuSyncByUpdateTimeJob();
skuSyncJob.executeJob(null, new JobPointLog("base-sku",0 ,100,1,1,
LocalDateTime.of(2019,03,30,0,0),
LocalDateTime.now()));
}
@Test
public void tes3() {
}
}
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