Commit 84b99ed9 by yinyong

半成品信息同步

parent 5576d623
......@@ -25,6 +25,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()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration1()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
......@@ -40,6 +41,13 @@ public class Application {
return simpleJobRootConfig;
}
private static LiteJobConfiguration createJobConfiguration1() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("SEMI_JOB_NAME"), propertiesUtil.getPropertyAsString("SEMI_JOB_CRON"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SyncSemiPurchaseDetailsJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
}
private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
return jobEventRdbConfig;
......
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.dto.PurchaseDetailDTO;
import com.bailuntec.domain.entity.DcSemiPurchaseInfo;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcSemiPurchaseInfoExample;
import com.bailuntec.mapper.DcSemiPurchaseInfoMapper;
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.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.List;
@Slf4j
public class SyncSemiPurchaseDetailsJob extends PointJob {
private static PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
private static OkHttpClient client = OkHttpUtil.getInstance();
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
MediaType mediaType = MediaType.parse("application/json");
LinkedHashMap<String, Object> map = new LinkedHashMap<>(4);
map.put("start", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getStartTime().minusMinutes(1L)));
map.put("end", DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT).format(jobPointLog.getEndTime()));
map.put("pagesize", jobPointLog.getPageSize());
List<PurchaseDetailDTO> purchaseDetailDTOList = null;
do {
map.put("page", jobPointLog.getPageIndex());
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
String purchaseStr = null;
Response response = null;
if (purchaseDetailDTOList != null) purchaseDetailDTOList = null;
try {
Request request = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("SEMI_PURCHASE_DETAILS_URL"))
.post(body)
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request).execute();
purchaseStr = response.body().string();
} catch (IOException e) {
log.error("调用半成品采购单sku详细信息接口失败", e);
throw new RuntimeException("调用半成品采购单sku详细信息接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(purchaseStr)) {
JSONObject jsonObject = JSON.parseObject(purchaseStr);
if (jsonObject != null) {
purchaseDetailDTOList = jsonObject.getObject("data", new TypeReference<List<PurchaseDetailDTO>>() {
});
if (purchaseDetailDTOList != null && purchaseDetailDTOList.size() > 0) {
try {
DcSemiPurchaseInfoMapper mapper = SessionUtil.getSession().getMapper(DcSemiPurchaseInfoMapper.class);
if (jobPointLog.getPageIndex() % 10 == 0) {
JobPointLogMapper pointLogMapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
pointLogMapper.upsertSelective(jobPointLog);
}
purchaseDetailDTOList.forEach(purchaseDetail -> {
log.warn(purchaseDetail.getBailunSku() + "&" + purchaseDetail.getPurchaseId());
DcSemiPurchaseInfo dcSemiPurchaseInfo = new DcSemiPurchaseInfo();
try {
BeanUtils.copyProperties(dcSemiPurchaseInfo, purchaseDetail);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("BeanUtils.copyProperties采购单sku详细信息异常");
}
dcSemiPurchaseInfo.setQuantityNotInbound(purchaseDetail.getQuantityPurchase() - purchaseDetail.getQuantityInbound());
dcSemiPurchaseInfo.setCreateTime(LocalDateTime.parse(purchaseDetail.getCreateTimed(), DateTimeFormatter.ofPattern("yyyy/M/d H:m:s")));
dcSemiPurchaseInfo.setUpdateTime(LocalDateTime.parse(purchaseDetail.getUpdateTimed(), DateTimeFormatter.ofPattern("yyyy/M/d H:m:s")));
dcSemiPurchaseInfo.setGmtModified(LocalDateTime.now());
int i = mapper.updateByExampleSelective(dcSemiPurchaseInfo, DcSemiPurchaseInfoExample.newAndCreateCriteria().andBailunSkuEqualTo(dcSemiPurchaseInfo.getBailunSku()).andPurchaseIdEqualTo(dcSemiPurchaseInfo.getPurchaseId()).example());
if (i == 0) {
mapper.insertSelective(dcSemiPurchaseInfo);
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("MYBATIS操作DB失败");
} finally {
SessionUtil.closeSession();
}
}else {
break;
}
} else {
throw new RuntimeException("调用采购单sku详细信息接口失败");
}
} else {
throw new RuntimeException("调用采购单sku详细信息接口失败");
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1);
} while (true);
jobPointLog.setPageIndex(1);
jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()));
}
}
#PURCHASE_DETAILS_URL=http://purchase.bailuntec.com/api/GetPagePurchaseSkuInfo
PURCHASE_DETAILS_URL=http://10.0.6.15:3333/api/GetPagePurchaseSkuInfo
PURCHASE_DETAILS_URL=http://purchase.bailuntec.com/api/GetPagePurchaseSkuInfo
SEMI_PURCHASE_DETAILS_URL=http://mjcg.bailuntec.com/Api/GetPagePurchaseSkuInfo
#PURCHASE_DETAILS_URL=http://10.0.6.15:3333/api/GetPagePurchaseSkuInfo
......@@ -10,4 +10,6 @@ ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center
JOB_NAME=base-purchase-details
JOB_CRON=0/3 * * * * ? *
SEMI_JOB_NAME=semi-purchase-details-info
SEMI_JOB_CRON=0/3 * * * * ? *
SHARDING_TOTAL_COUNT=1
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcSemiPurchaseInfo;
import com.bailuntec.domain.example.DcSemiPurchaseInfoExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcSemiPurchaseInfoMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
long countByExample(DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int deleteByExample(DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int insert(DcSemiPurchaseInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int insertSelective(DcSemiPurchaseInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcSemiPurchaseInfo selectOneByExample(DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
List<DcSemiPurchaseInfo> selectByExample(DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
DcSemiPurchaseInfo selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcSemiPurchaseInfo record, @Param("example") DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcSemiPurchaseInfo record, @Param("example") DcSemiPurchaseInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcSemiPurchaseInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
*/
int updateByPrimaryKey(DcSemiPurchaseInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcSemiPurchaseInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_semi_purchase_info
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcSemiPurchaseInfo 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