Commit 39892e90 by huluobin

销量预测公式

parent 18e212c5
...@@ -14,6 +14,8 @@ import com.bailuntec.utils.OkHttpUtil; ...@@ -14,6 +14,8 @@ import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.PropertiesUtil; import com.bailuntec.utils.PropertiesUtil;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
...@@ -27,6 +29,7 @@ import java.time.format.DateTimeFormatter; ...@@ -27,6 +29,7 @@ import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@Slf4j
public class SyncCostFirstJob extends PointJob { public class SyncCostFirstJob extends PointJob {
private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const"); private PropertiesUtil propertiesUtil = PropertiesUtil.getInstance("const");
...@@ -46,43 +49,59 @@ public class SyncCostFirstJob extends PointJob { ...@@ -46,43 +49,59 @@ public class SyncCostFirstJob extends PointJob {
.addHeader("cache-control", "no-cache") .addHeader("cache-control", "no-cache")
.build(); .build();
Response response = null; Response response = null;
String result;
try { try {
log.info("调用头程费用接口 starting");
response = client.newCall(request).execute(); response = client.newCall(request).execute();
result = response.body().string();
String result = response.body().string();
if (StringUtils.isNotBlank(result)) {
log.info("序列化头程费用头程费用 starting");
CostFirstResult costFirstResult = JSON.parseObject(result, CostFirstResult.class);
log.info("序列化头程费用头程费用 end");
log.info("头程费用当前请求页数 :{}", jobPointLog.getPageIndex());
log.info("头程费用当前总页数 :{}", costFirstResult.getPageCount());
log.info("头程费用当前页码大小 :{}", costFirstResult.getData().size());
totalPage = costFirstResult.getPageCount();
if (costFirstResult.getData() != null && costFirstResult.getData().size() > 0) {
handleCostFirstData(costFirstResult.getData());
}
} else {
log.error("调用头程费接口失败,返回200,param:{}", new Gson().toJson(map));
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); log.error(e.getMessage(), e);
throw new RuntimeException("调用头程费接口失败", e); log.error("调用头程费接口失败,param:{}", new Gson().toJson(map));
} finally { } finally {
if (response != null) { if (response != null) {
response.close(); response.close();
} }
} }
if (StringUtils.isNotBlank(result)) { log.info("调用头程费用接口 end");
CostFirstResult costFirstResult = JSON.parseObject(result, CostFirstResult.class);
totalPage = costFirstResult.getPageCount();
if (costFirstResult.getData() != null && costFirstResult.getData().size() > 0) {
handleCostFirstData(costFirstResult.getData());
}
} else {
throw new RuntimeException("调用头程费接口失败,返回200");
}
jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1); jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1);
if (jobPointLog.getPageIndex() % 8 == 0) { if (jobPointLog.getPageIndex() % 8 == 0) {
JobPointLogMapper mapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class); JobPointLogMapper mapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
mapper.upsertSelective(jobPointLog); mapper.upsertSelective(jobPointLog);
} }
} while (jobPointLog.getPageIndex() <= totalPage); } while (jobPointLog.getPageIndex() <= totalPage);
jobPointLog.setPageIndex(1); jobPointLog.setPageIndex(1);
jobPointLog.setStartTime(jobPointLog.getEndTime()); jobPointLog.setStartTime(jobPointLog.getEndTime());
jobPointLog.setEndTime(jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()).isAfter(LocalDateTime.now()) ? LocalDateTime.now() : jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue())); jobPointLog.setEndTime(jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()).isAfter(LocalDateTime.now())
? LocalDateTime.now()
: jobPointLog.getStartTime().plusDays(jobPointLog.getIntervalTime().longValue()));
} }
private void handleCostFirstData(List<CostFirstData> costFirstDataList) { private void handleCostFirstData(List<CostFirstData> costFirstDataList) {
try { try {
DcBaseCostFirstMapper baseCostFirstMapper = SessionUtil.getSession().getMapper(DcBaseCostFirstMapper.class); DcBaseCostFirstMapper baseCostFirstMapper = SessionUtil.getSession().getMapper(DcBaseCostFirstMapper.class);
for (CostFirstData costFirstData : costFirstDataList) { //将费用处理一下, 给过来的数据很长的小数
//将费用处理一下, 给过来的数据很长的小数 costFirstDataList.forEach(costFirstData -> {
costFirstData.setCostDuty(costFirstData.getCostDuty().setScale(3, RoundingMode.HALF_EVEN)); costFirstData.setCostDuty(costFirstData.getCostDuty().setScale(3, RoundingMode.HALF_EVEN));
costFirstData.setCostCustomsClearance(costFirstData.getCostCustomsClearance().setScale(3, RoundingMode.HALF_EVEN)); costFirstData.setCostCustomsClearance(costFirstData.getCostCustomsClearance().setScale(3, RoundingMode.HALF_EVEN));
costFirstData.setCostGoodsClearance(costFirstData.getCostGoodsClearance().setScale(3, RoundingMode.HALF_EVEN)); costFirstData.setCostGoodsClearance(costFirstData.getCostGoodsClearance().setScale(3, RoundingMode.HALF_EVEN));
...@@ -101,16 +120,26 @@ public class SyncCostFirstJob extends PointJob { ...@@ -101,16 +120,26 @@ public class SyncCostFirstJob extends PointJob {
throw new RuntimeException("BeanUtils.copyProperties失败, ChannelId是" + costFirstData.getChannelId()); throw new RuntimeException("BeanUtils.copyProperties失败, ChannelId是" + costFirstData.getChannelId());
} }
if (StringUtils.isNotBlank(dcBaseCostFirst.getBailunSku()) && StringUtils.isNotBlank(dcBaseCostFirst.getChannelOrderId()) && StringUtils.isNotBlank(dcBaseCostFirst.getBoxId()) && StringUtils.isNotBlank(dcBaseCostFirst.getTransferOrderId()) && StringUtils.isNotBlank(dcBaseCostFirst.getWarehouseCode())) { if (StringUtils.isNotBlank(dcBaseCostFirst.getBailunSku()) && StringUtils.isNotBlank(dcBaseCostFirst.getChannelOrderId()) && StringUtils.isNotBlank(dcBaseCostFirst.getBoxId()) && StringUtils.isNotBlank(dcBaseCostFirst.getTransferOrderId()) && StringUtils.isNotBlank(dcBaseCostFirst.getWarehouseCode())) {
int i = baseCostFirstMapper.updateByExampleSelective(dcBaseCostFirst, DcBaseCostFirstExample.newAndCreateCriteria().andBailunSkuEqualTo(dcBaseCostFirst.getBailunSku()).andChannelOrderIdEqualTo(dcBaseCostFirst.getChannelOrderId()).andBoxIdEqualTo(dcBaseCostFirst.getBoxId()).andTransferOrderIdEqualTo(dcBaseCostFirst.getTransferOrderId()).andWarehouseCodeEqualTo(dcBaseCostFirst.getWarehouseCode()).example()); int i = baseCostFirstMapper.updateByExampleSelective(dcBaseCostFirst,
DcBaseCostFirstExample.newAndCreateCriteria()
.andBailunSkuEqualTo(dcBaseCostFirst.getBailunSku())
.andChannelOrderIdEqualTo(dcBaseCostFirst.getChannelOrderId())
.andBoxIdEqualTo(dcBaseCostFirst.getBoxId()).andTransferOrderIdEqualTo(dcBaseCostFirst.getTransferOrderId())
.andWarehouseCodeEqualTo(dcBaseCostFirst.getWarehouseCode())
.example());
if (i == 0) { if (i == 0) {
baseCostFirstMapper.upsertSelective(dcBaseCostFirst); baseCostFirstMapper.upsertSelective(dcBaseCostFirst);
log.info("百伦头程费信息, 是WMS根据线路估算而来 新增同步成功 ");
} else {
log.info("百伦头程费信息, 是WMS根据线路估算而来 更新同步成功 ");
} }
} }
} }
} }
} });
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new RuntimeException("MYBATIS操作DB更新插入数据失败", e); // throw new RuntimeException("MYBATIS操作DB更新插入数据失败", e);
log.error(e.getMessage(), e);
} finally { } finally {
SessionUtil.closeSession(); SessionUtil.closeSession();
} }
......
#EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver #EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
#EVENT_RDB_STORAGE_URL=jdbc:mysql://192.168.6.140:3306/bailun_datacenter?serverTimezone=GMT%2B8&characterEncoding=utf-8 EVENT_RDB_STORAGE_URL=jdbc:mysql://192.168.6.140:3306/bailun_datacenter?serverTimezone=GMT%2B8&characterEncoding=utf-8
#EVENT_RDB_STORAGE_USERNAME=root #EVENT_RDB_STORAGE_USERNAME=root
#EVENT_RDB_STORAGE_PASSWORD=123456 #EVENT_RDB_STORAGE_PASSWORD=123456
#ZOOKEEPER_SERVER=127.0.0.1:2181 ZOOKEEPER_SERVER=127.0.0.1:2181
EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver 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_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_USERNAME=root
EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf
ZOOKEEPER_SERVER=172.31.255.120:2181 #ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center NAME_SPACE=data-center
JOB_NAME=base-sync-cost-first JOB_NAME=base-sync-cost-first
JOB_CRON=0 10 0/1 * * ? * JOB_CRON=0 10 0/1 * * ? *
SHARDING_TOTAL_COUNT=1 SHARDING_TOTAL_COUNT=1
\ No newline at end of file
...@@ -9,9 +9,9 @@ public class SyncCostFirstTest { ...@@ -9,9 +9,9 @@ public class SyncCostFirstTest {
@Test @Test
public void test() { public void test() {
SyncCostFirstJob syncCostFirstJob = new SyncCostFirstJob(); SyncCostFirstJob syncCostFirstJob = new SyncCostFirstJob();
JobPointLog jobPointLog = new JobPointLog("base-sync-cost-first", 1, 1, 1, 1, JobPointLog jobPointLog = new JobPointLog("base-sync-cost-first", 101, 1, 1, 1,
LocalDateTime.of(2020,8,11,0,3,22), LocalDateTime.of(2020,5,1,0,0,0),
LocalDateTime.of(2020,8,12,16,3,22)); LocalDateTime.of(2020,8,14,9,0,0));
syncCostFirstJob.executeJob(null, jobPointLog); syncCostFirstJob.executeJob(null, jobPointLog);
} }
} }
...@@ -56,9 +56,9 @@ public class AutoSalesServiceImpl implements AutoSalesService { ...@@ -56,9 +56,9 @@ public class AutoSalesServiceImpl implements AutoSalesService {
dcAutoSales.setBVariable(beta); dcAutoSales.setBVariable(beta);
dcAutoSales.setRVariable(r2); dcAutoSales.setRVariable(r2);
dcAutoSales.setForecastFormula(formula); dcAutoSales.setForecastFormula(formula);
BeanUtils.copyProperties(dcAutoSales,salesVolumeDTO ); BeanUtils.copyProperties(dcAutoSales, salesVolumeDTO);
//将历史销量详细,存入销量表 //将历史销量详细,存入销量表
dcAutoSales.setHistorySalesDetails("["+ historySales+ "]"); dcAutoSales.setHistorySalesDetails("[" + historySales + "]");
dcAutoSales.setAverageSales(avgSales); dcAutoSales.setAverageSales(avgSales);
/* /*
* 根据不同的历史销量和趋势选择不同的预测算法 * 根据不同的历史销量和趋势选择不同的预测算法
......
...@@ -8,6 +8,7 @@ import com.bailuntec.mapper.DcBaseOmsSkuMapper; ...@@ -8,6 +8,7 @@ import com.bailuntec.mapper.DcBaseOmsSkuMapper;
import com.bailuntec.service.AutoTurnoverService; import com.bailuntec.service.AutoTurnoverService;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -53,6 +54,8 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -53,6 +54,8 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
String warehouseCode = dcAutoTurnover.getWarehouseCode(); String warehouseCode = dcAutoTurnover.getWarehouseCode();
Queue<BigDecimal> forecastSalesDetails = new LinkedList<>(); Queue<BigDecimal> forecastSalesDetails = new LinkedList<>();
//销量公式
Queue<String> forecastSalesDetailsFormula = new LinkedList<>();
//获取过去7天的销量 //获取过去7天的销量
BigDecimal last1DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(1), midNight, bailunSku, warehouseCode)).orElse(0)); BigDecimal last1DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(1), midNight, bailunSku, warehouseCode)).orElse(0));
...@@ -65,12 +68,20 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -65,12 +68,20 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
forecastSalesDetails.offer(last1DaySellerNum); forecastSalesDetails.offer(last1DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last2DaySellerNum); forecastSalesDetails.offer(last2DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last3DaySellerNum); forecastSalesDetails.offer(last3DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last4DaySellerNum); forecastSalesDetails.offer(last4DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last5DaySellerNum); forecastSalesDetails.offer(last5DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last6DaySellerNum); forecastSalesDetails.offer(last6DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
forecastSalesDetails.offer(last7DaySellerNum); forecastSalesDetails.offer(last7DaySellerNum);
forecastSalesDetailsFormula.offer(StringUtils.SPACE);
if (dcAutoSalesForecastStageConfig != null) { if (dcAutoSalesForecastStageConfig != null) {
int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue(); int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue();
...@@ -88,6 +99,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -88,6 +99,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration1; i++) { for (int i = 0; i < duration1; i++) {
forecastSalesDetails.offer(duration1ForecastSellerNum); forecastSalesDetails.offer(duration1ForecastSellerNum);
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN1().intValue()), midNight, bailunSku, warehouseCode) + "*" + dcAutoSalesForecastStageConfig.getOneN2() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN3().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getOneN4() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN5().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getOneN6() + ")");
} }
/*第二部分预测*/ /*第二部分预测*/
...@@ -100,6 +116,13 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -100,6 +116,13 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration2; i++) { for (int i = 0; i < duration2; i++) {
forecastSalesDetails.offer(duration2ForecastSellerNum); forecastSalesDetails.offer(duration2ForecastSellerNum);
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN1().intValue()), midNight, bailunSku, warehouseCode) + "*" + dcAutoSalesForecastStageConfig.getTwoN2() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN3().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getTwoN4() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN5().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getTwoN6() + ")");
} }
...@@ -113,14 +136,22 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -113,14 +136,22 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration3; i++) { for (int i = 0; i < duration3; i++) {
forecastSalesDetails.offer(duration3ForecastSellerNum); forecastSalesDetails.offer(duration3ForecastSellerNum);
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN1().intValue()), midNight, bailunSku, warehouseCode) + "*" + dcAutoSalesForecastStageConfig.getThreeN2() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN3().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getThreeN4() + ")"
+ "+"
+ "(" + BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN5().intValue()), midNight, bailunSku, warehouseCode)).orElse(0)) + "*" + dcAutoSalesForecastStageConfig.getThreeN6() + ")");
} }
dcAutoTurnover.setSalesDetails(new Gson().toJson(forecastSalesDetails)); dcAutoTurnover.setSalesDetails(new Gson().toJson(forecastSalesDetails));
dcAutoTurnover.setSalesDetailsFormula(new Gson().toJson(forecastSalesDetailsFormula));
// dcAutoTurnoverMapper.updateByPrimaryKey(dcAutoTurnover); // dcAutoTurnoverMapper.updateByPrimaryKey(dcAutoTurnover);
} else { } else {
for (int i = 0; i < turnoverDays; i++) { for (int i = 0; i < turnoverDays; i++) {
forecastSalesDetails.offer(dcAutoTurnover.getDailyWeightedSales()) forecastSalesDetails.offer(dcAutoTurnover.getDailyWeightedSales());
} }
} }
......
...@@ -29,6 +29,7 @@ class AutoTurnoverServiceImplTest { ...@@ -29,6 +29,7 @@ class AutoTurnoverServiceImplTest {
DcAutoTurnover dcAutoTurnover = dcAutoTurnoverMapper.selectByPrimaryKey(58845); DcAutoTurnover dcAutoTurnover = dcAutoTurnoverMapper.selectByPrimaryKey(58845);
autoTurnoverService.setAutoTurnoverSaleDetails(dcAutoTurnover); autoTurnoverService.setAutoTurnoverSaleDetails(dcAutoTurnover);
System.out.println(dcAutoTurnover.getSalesDetails()); System.out.println(dcAutoTurnover.getSalesDetails());
System.out.println(dcAutoTurnover.getSalesDetailsFormula());
} finally { } finally {
SessionUtil.closeSession(); SessionUtil.closeSession();
} }
......
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