Commit a7310fd2 by huluobin

oms sku 同步

parent 83bfda2c
#COMPANY_INFO_URL=http://sso.bailuntec.com/GetCompanys #COMPANY_INFO_URL=http://sso.bailuntec.com/GetCompanys
#COMPANY_STAFF_URL=http://sso.bailuntec.com/GetUserByCompany #COMPANY_STAFF_URL=http://sso.bailuntec.com/GetUserByCompany
#COMPANY_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetAccountToken COMPANY_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetAccountToken
COMPANY_INFO_URL=http://172.31.255.10/GetCompanys COMPANY_INFO_URL=http://172.31.255.10/GetCompanys
COMPANY_STAFF_URL=http://172.31.255.10/GetUserByCompany COMPANY_STAFF_URL=http://172.31.255.10/GetUserByCompany
COMPANY_ACCOUNT_URL=http://10.0.6.17:8090/Api/GetAccountToken #COMPANY_ACCOUNT_URL=http://10.0.6.17:8090/Api/GetAccountToken
PAYPAL_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetPayPalAccounts PAYPAL_ACCOUNT_URL=http://pams.bailuntec.com/Api/GetPayPalAccounts
package com.bailuntec.job;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.JobPointLogExample;
import com.bailuntec.mapper.JobPointLogMapper;
import com.bailuntec.support.PointJob;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/8/26 10:21 上午
*/
public class OrderSyncJobTest {
@Test
public void execute() {
PointJob pointJob = new OrderSyncJob();
ShardingContext shardingContext = new ShardingContext(
new ShardingContexts("x", "base-sync-oms-order-coroutine", 1, null, new HashMap<>()), 0
);
pointJob.execute(shardingContext);
}
@Test
public void executeJob() {
OrderSyncJob orderSyncJob = new OrderSyncJob();
ShardingContext shardingContext = new ShardingContext(
new ShardingContexts("x", "base-sync-oms-order-coroutine", 1, null, new HashMap<>()), 0
);
SqlSession sqlSession = SessionUtil.getFactory().openSession(true);
JobPointLogMapper jobPointLogMapper = sqlSession.getMapper(JobPointLogMapper.class);
JobPointLog jobPointLog = jobPointLogMapper.selectOneByExample(JobPointLogExample
.newAndCreateCriteria()
.andJobNameEqualTo(shardingContext.getJobName()).example());
orderSyncJob.executeJob(shardingContext, jobPointLog);
sqlSession.close();
}
}
package com.bailuntec.domain.entity;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class DcBaseOmsSkuException {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_oms_sku_exception.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_oms_sku_exception.origin_order_id
*
* @mbg.generated
*/
private String originOrderId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_oms_sku_exception.create_time
*
* @mbg.generated
*/
private LocalDateTime createTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_oms_sku_exception.status
*
* @mbg.generated
*/
private Integer status;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", originOrderId=").append(originOrderId);
sb.append(", createTime=").append(createTime);
sb.append(", status=").append(status);
sb.append("]");
return sb.toString();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
DcBaseOmsSkuException other = (DcBaseOmsSkuException) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getOriginOrderId() == null ? other.getOriginOrderId() == null : this.getOriginOrderId().equals(other.getOriginOrderId()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()));
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getOriginOrderId() == null) ? 0 : getOriginOrderId().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
return result;
}
}
\ No newline at end of file
package com.bailuntec.mapper; package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcAutoSalesForecastStageConfig; import com.bailuntec.domain.entity.DcAutoSalesForecastStageConfig;
import com.bailuntec.domain.entity.DcAutoTurnover;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
* 销量预测阶段 Mapper 接口 * 销量预测阶段 Mapper 接口
...@@ -24,4 +27,15 @@ public interface DcAutoSalesForecastStageConfigMapper extends BaseMapper<DcAutoS ...@@ -24,4 +27,15 @@ public interface DcAutoSalesForecastStageConfigMapper extends BaseMapper<DcAutoS
* @return 命中的预测规则 * @return 命中的预测规则
*/ */
DcAutoSalesForecastStageConfig selectMatchStage(@Param("bailunSku") String bailunSku, @Param("warehouseCode") String warehouseCode); DcAutoSalesForecastStageConfig selectMatchStage(@Param("bailunSku") String bailunSku, @Param("warehouseCode") String warehouseCode);
/**
* <p>
* 根据测试条件查询灰度周转记录
* </p>
*
* @return
*/
List<DcAutoTurnover> selectTestSyncAutoTurnoverList();
} }
...@@ -3,25 +3,72 @@ ...@@ -3,25 +3,72 @@
<mapper namespace="com.bailuntec.mapper.DcAutoSalesForecastStageConfigMapper"> <mapper namespace="com.bailuntec.mapper.DcAutoSalesForecastStageConfigMapper">
<select id="selectMatchStage" resultType="com.bailuntec.domain.entity.DcAutoSalesForecastStageConfig"> <select id="selectMatchStage" resultType="com.bailuntec.domain.entity.DcAutoSalesForecastStageConfig">
SELECT t7.* from dc_auto_turnover t1 SELECT t7.*
LEFT JOIN dc_base_sku t2 on t1.bailun_sku =t2.bailun_sku from dc_auto_turnover t1
LEFT JOIN dc_base_stock t8 on t1.bailun_sku = t8.bailun_sku and t1.warehouse_code = t8.warehouse_code LEFT JOIN dc_base_sku t2 on t1.bailun_sku = t2.bailun_sku
LEFT JOIN dc_base_warehouse t6 on t1.warehouse_code = t6.warehouse_code LEFT JOIN dc_base_stock t8 on t1.bailun_sku = t8.bailun_sku and t1.warehouse_code = t8.warehouse_code
LEFT JOIN dc_auto_sales_forecast_sku_config t3 on t1.bailun_sku = t3.bailun_sku LEFT JOIN dc_base_warehouse t6 on t1.warehouse_code = t6.warehouse_code
LEFT JOIN dc_auto_sales_forecast_product_code_config t4 on t2.product_code = t4.product_code LEFT JOIN dc_auto_sales_forecast_sku_config t3 on t1.bailun_sku = t3.bailun_sku
LEFT JOIN dc_auto_sales_forecast_config t5 on (t3.config_id =t5.id or t5.id not in (select config_id from dc_auto_sales_forecast_sku_config)) LEFT JOIN dc_auto_sales_forecast_product_code_config t4 on t2.product_code = t4.product_code
and (t4.config_id = t5.id or t5.id not in (select config_id from dc_auto_sales_forecast_product_code_config)) LEFT JOIN dc_auto_sales_forecast_config t5 on (t3.config_id = t5.id or t5.id not in (select config_id
and (t6.warehouse_code = t5.warehouse_code or length(trim(t5.warehouse_code)) = 0) from dc_auto_sales_forecast_sku_config
and (t6.hq_type = t5.warehouse_type or length(trim(t5.warehouse_type)) = 0) where bailun_sku = t1.bailun_sku))
and (t2.product_type = t5.category or length(trim(t5.category)) = 0) and (t4.config_id = t5.id or t5.id not in (select config_id
and (t6.area_id = t5.warehouse_area_id or length(trim(t5.warehouse_area_id)) = 0) from dc_auto_sales_forecast_product_code_config
LEFT JOIN dc_auto_sales_forecast_stage_config t7 on t7.config_id =t5.id where product_code = t1.product_code))
and (IF(t5.screen_type =1, and (t6.warehouse_code = t5.warehouse_code or length(trim(t5.warehouse_code)) = 0)
t8.first_inbound_date &lt;= t7.duration_upper_limit or t8.first_inbound_date &gt;= t7.duration_lower_limit or t8.first_inbound_date is null or length(trim(t8.first_inbound_date)) = 0, and (t6.hq_type = t5.warehouse_type or length(trim(t5.warehouse_type)) = 0)
t1.daily_weighted_sales &lt;= t7.sales_upper_limit or t1.daily_weighted_sales &gt;= t7.sales_lower_limit or t1.daily_weighted_sales is null or length(trim(t1.daily_weighted_sales)) = 0)) and (t2.product_type = t5.category or length(trim(t5.category)) = 0)
where t1.bailun_sku =#{bailunSku} and t1.warehouse_code = #{warehouseCode} and (t6.area_id = t5.warehouse_area_id or length(trim(t5.warehouse_area_id)) = 0)
and t5.id is not null LEFT JOIN dc_auto_sales_forecast_stage_config t7 on t7.config_id = t5.id
and (IF(t5.screen_type = 1,
t8.first_inbound_date &lt;= t7.duration_upper_limit or
t8.first_inbound_date &gt;= t7.duration_lower_limit or t8.first_inbound_date is null or
length(trim(t8.first_inbound_date)) = 0,
t1.daily_weighted_sales &lt;= t7.sales_upper_limit or
t1.daily_weighted_sales &gt;= t7.sales_lower_limit or t1.daily_weighted_sales is null or
length(trim(t1.daily_weighted_sales)) = 0))
where t1.bailun_sku = #{bailunSku}
and t1.warehouse_code = #{warehouseCode}
and t5.id is not null
ORDER BY t5.`level` desc ORDER BY t5.`level` desc
limit 1 limit 1
</select> </select>
<select id="selectTestSyncAutoTurnoverList" resultType="com.bailuntec.domain.entity.DcAutoTurnover">
SELECT *
from (SELECT t1.*
from dc_auto_turnover t1
LEFT JOIN dc_base_sku t2 on t1.bailun_sku = t2.bailun_sku
LEFT JOIN dc_base_stock t8
on t1.bailun_sku = t8.bailun_sku and t1.warehouse_code = t8.warehouse_code
LEFT JOIN dc_base_warehouse t6 on t1.warehouse_code = t6.warehouse_code
LEFT JOIN dc_auto_sales_forecast_sku_config t3 on t1.bailun_sku = t3.bailun_sku
LEFT JOIN dc_auto_sales_forecast_product_code_config t4 on t2.product_code = t4.product_code
LEFT JOIN dc_auto_sales_forecast_config t5 on
(t3.config_id = t5.id or t5.id not in (select config_id
from dc_auto_sales_forecast_sku_config
where bailun_sku = t1.bailun_sku))
and (t4.config_id = t5.id or t5.id not in (select config_id
from dc_auto_sales_forecast_product_code_config
where product_code = t1.product_code))
and (t6.warehouse_code = t5.warehouse_code or length(trim(t5.warehouse_code)) = 0)
and (t6.hq_type = t5.warehouse_type or length(trim(t5.warehouse_type)) = 0)
and (t2.product_type = t5.category or length(trim(t5.category)) = 0)
and (t6.area_id = t5.warehouse_area_id or length(trim(t5.warehouse_area_id)) = 0)
and t5.id = 4
LEFT JOIN dc_auto_sales_forecast_stage_config t7 on t7.config_id = t5.id
and (IF(t5.screen_type = 1,
t8.first_inbound_date &lt;= t7.duration_upper_limit or
t8.first_inbound_date &gt;= t7.duration_lower_limit or t8.first_inbound_date is null or
length(trim(t8.first_inbound_date)) = 0,
t1.daily_weighted_sales &lt;= t7.sales_upper_limit or
t1.daily_weighted_sales &gt;= t7.sales_lower_limit or t1.daily_weighted_sales is null or
length(trim(t1.daily_weighted_sales)) = 0))
-- where t1.bailun_sku ='sku' and t1.warehouse_code = 'wa'
where t5.id is not null
ORDER BY t5.`level` desc) aaa
GROUP BY bailun_sku, warehouse_code;
</select>
</mapper> </mapper>
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseOmsSkuException;
import com.bailuntec.domain.example.DcBaseOmsSkuExceptionExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface DcBaseOmsSkuExceptionMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
long countByExample(DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int deleteByExample(DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int insert(DcBaseOmsSkuException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int insertSelective(DcBaseOmsSkuException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBaseOmsSkuException selectOneByExample(DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
List<DcBaseOmsSkuException> selectByExample(DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
DcBaseOmsSkuException selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBaseOmsSkuException record, @Param("example") DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBaseOmsSkuException record, @Param("example") DcBaseOmsSkuExceptionExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBaseOmsSkuException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBaseOmsSkuException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBaseOmsSkuException record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_oms_sku_exception
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseOmsSkuException record);
}
\ No newline at end of file
table-name=dc_auto_turnover table-name=dc_base_oms_sku_exception
...@@ -21,6 +21,7 @@ import com.bailuntec.utils.OkHttpUtil; ...@@ -21,6 +21,7 @@ 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 lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
...@@ -63,8 +64,6 @@ public class AutoTurnoverJob extends PointJob { ...@@ -63,8 +64,6 @@ public class AutoTurnoverJob extends PointJob {
ExecutorService executorService = new ThreadPoolExecutor(20, ExecutorService executorService = new ThreadPoolExecutor(20,
100, 100,
2, 2,
TimeUnit.MINUTES, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(), new LinkedBlockingQueue<>(),
Executors.defaultThreadFactory(), Executors.defaultThreadFactory(),
...@@ -391,10 +390,10 @@ public class AutoTurnoverJob extends PointJob { ...@@ -391,10 +390,10 @@ public class AutoTurnoverJob extends PointJob {
* 均值, 配置安全库存法: 销量上下限 根据过去30天销量,计算出合理的销量封顶值和销量最低值 * 均值, 配置安全库存法: 销量上下限 根据过去30天销量,计算出合理的销量封顶值和销量最低值
* 曲线拟合 :销量预测, 根据销量走势和上下限,计算出销量预测曲线, 如果历史销量包含0, 无法使用指数函数拟合 * 曲线拟合 :销量预测, 根据销量走势和上下限,计算出销量预测曲线, 如果历史销量包含0, 无法使用指数函数拟合
*/ */
// forecastSalesList = autoTurnoverService.getAutoTurnoverSaleDetails(dcAutoTurnover, turnoverDays, autoForecastDay); forecastSalesList = autoTurnoverService.getAutoTurnoverSaleDetails(dcAutoTurnover, turnoverDays, autoForecastDay);
calculateForecastSales(salesUpperLimit, autoForecastDay, dcAutoSales, forecastSalesList, turnoverSku, recordTime, bailunSku, warehouseCode, dcAutoWarehouseweekSales); // calculateForecastSales(salesUpperLimit, autoForecastDay, dcAutoSales, forecastSalesList, turnoverSku, recordTime, bailunSku, warehouseCode, dcAutoWarehouseweekSales);
// List<String> forecastSalesListFormula = autoTurnoverService.getAutoTurnoverSaleDetailsFormula(dcAutoTurnover, turnoverDays, autoForecastDay); List<String> forecastSalesListFormula = autoTurnoverService.getAutoTurnoverSaleDetailsFormula(dcAutoTurnover, turnoverDays, autoForecastDay);
/* /*
* 处理矫正信息 * 处理矫正信息
...@@ -668,7 +667,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -668,7 +667,7 @@ public class AutoTurnoverJob extends PointJob {
if (i < 7) { if (i < 7) {
avgForecastSevendaySales = avgForecastSevendaySales.add(forecastSalesList.get(i)); avgForecastSevendaySales = avgForecastSevendaySales.add(forecastSalesList.get(i));
forecastSalesList.add(i, BigDecimal.valueOf(historySalesList.get(23 + i))); forecastSalesList.add(i, BigDecimal.valueOf(historySalesList.get(23 + i)));
// forecastSalesListFormula.add(i, StringUtils.SPACE); forecastSalesListFormula.add(i, StringUtils.SPACE);
forecastSalesExplainList.add(i, "历史销量"); forecastSalesExplainList.add(i, "历史销量");
forecastInboundList.add(i, 0); forecastInboundList.add(i, 0);
forecastInventoryList.add(i, BigDecimal.ZERO); forecastInventoryList.add(i, BigDecimal.ZERO);
...@@ -744,7 +743,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -744,7 +743,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setTurnoverDays(turnoverDays); dcAutoTurnover.setTurnoverDays(turnoverDays);
dcAutoTurnover.setQuantitySafeInventory(totalSafeInventory); dcAutoTurnover.setQuantitySafeInventory(totalSafeInventory);
dcAutoTurnover.setHqType(dcBaseWarehouse.getHqType()); dcAutoTurnover.setHqType(dcBaseWarehouse.getHqType());
// dcAutoTurnover.setSalesDetailsFormula(new Gson().toJson(forecastSalesListFormula)); dcAutoTurnover.setSalesDetailsFormula(new Gson().toJson(forecastSalesListFormula));
/*dcBaseStock.setSkuTitleCn(turnoverSku.getSkuTitleCn()); /*dcBaseStock.setSkuTitleCn(turnoverSku.getSkuTitleCn());
dcBaseStock.setProductInnerCode(turnoverSku.getProductInnerCode()); dcBaseStock.setProductInnerCode(turnoverSku.getProductInnerCode());
......
...@@ -8,6 +8,7 @@ import com.bailuntec.domain.example.*; ...@@ -8,6 +8,7 @@ import com.bailuntec.domain.example.*;
import com.bailuntec.mapper.*; import com.bailuntec.mapper.*;
import com.bailuntec.service.AutoTurnoverService; import com.bailuntec.service.AutoTurnoverService;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -24,6 +25,7 @@ import java.util.*; ...@@ -24,6 +25,7 @@ import java.util.*;
* @author robbendev * @author robbendev
* @since 2020/8/13 2:09 下午 * @since 2020/8/13 2:09 下午
*/ */
@Slf4j
public class AutoTurnoverServiceImpl implements AutoTurnoverService { public class AutoTurnoverServiceImpl implements AutoTurnoverService {
@Override @Override
...@@ -40,14 +42,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -40,14 +42,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
DcAutoSalesForecastStageConfigMapper dcAutoSalesForecastStageConfigMapper = session.getMapper(DcAutoSalesForecastStageConfigMapper.class); DcAutoSalesForecastStageConfigMapper dcAutoSalesForecastStageConfigMapper = session.getMapper(DcAutoSalesForecastStageConfigMapper.class);
DcAutoTurnoverMapper dcAutoTurnoverMapper = session.getMapper(DcAutoTurnoverMapper.class);
DcBaseOmsSkuMapper dcBaseOmsSkuMapper = session.getMapper(DcBaseOmsSkuMapper.class); DcBaseOmsSkuMapper dcBaseOmsSkuMapper = session.getMapper(DcBaseOmsSkuMapper.class);
//命中的预测规则 //命中的预测规则
DcAutoSalesForecastStageConfig dcAutoSalesForecastStageConfig = dcAutoSalesForecastStageConfigMapper.selectMatchStage(dcAutoTurnover.getBailunSku(), dcAutoTurnover.getWarehouseCode()); DcAutoSalesForecastStageConfig dcAutoSalesForecastStageConfig = dcAutoSalesForecastStageConfigMapper.selectMatchStage(dcAutoTurnover.getBailunSku(), dcAutoTurnover.getWarehouseCode());
// if (dcAutoSalesForecastStageConfig == null) {
// return;
// }
//周转天数 //周转天数
/* /*
* 每个时间段的销量预测是dcAutoSalesForecastStageConfig对应时间段的三个参数对应的过去时间段的销量的加权平均*/ * 每个时间段的销量预测是dcAutoSalesForecastStageConfig对应时间段的三个参数对应的过去时间段的销量的加权平均*/
...@@ -58,33 +57,10 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -58,33 +57,10 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
String warehouseCode = dcAutoTurnover.getWarehouseCode(); String warehouseCode = dcAutoTurnover.getWarehouseCode();
//获取过去7天的销量 if (dcAutoSalesForecastStageConfig != null) {
BigDecimal last1DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(1), midNight, bailunSku, warehouseCode)).orElse(0));
BigDecimal last2DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(2), midNight.minusDays(1), bailunSku, warehouseCode)).orElse(0));
BigDecimal last3DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(3), midNight.minusDays(2), bailunSku, warehouseCode)).orElse(0));
BigDecimal last4DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(4), midNight.minusDays(3), bailunSku, warehouseCode)).orElse(0));
BigDecimal last5DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(5), midNight.minusDays(4), bailunSku, warehouseCode)).orElse(0));
BigDecimal last6DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(6), midNight.minusDays(5), bailunSku, warehouseCode)).orElse(0));
BigDecimal last7DaySellerNum = BigDecimal.valueOf(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(7), midNight.minusDays(6), bailunSku, warehouseCode)).orElse(0));
// forecastSalesDetails.offer(last1DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last2DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last3DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last4DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last5DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last6DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
// forecastSalesDetails.offer(last7DaySellerNum);
// forecastSalesDetailsFormula.offer(StringUtils.SPACE);
log.info("匹配到一条规则 id:{}", dcAutoSalesForecastStageConfig.getConfigId());
if (dcAutoSalesForecastStageConfig != null) {
int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue(); int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue();
int duration2 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getTwoRatio()).intValue(); int duration2 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getTwoRatio()).intValue();
int duration3 = turnoverDays - duration1 - duration2; int duration3 = turnoverDays - duration1 - duration2;
...@@ -154,14 +130,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -154,14 +130,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
} }
} }
// dcAutoTurnover.setSalesDetails(new Gson().toJson(forecastSalesDetails));
// dcAutoTurnover.setSalesDetailsFormula(new Gson().toJson(forecastSalesDetailsFormula));
// dcAutoTurnoverMapper.updateByPrimaryKey(dcAutoTurnover);
} else { } else {
log.info("没有匹配销量预测规则,采用平均销量");
for (int i = 0; i < turnoverDays; i++) { for (int i = 0; i < turnoverDays; i++) {
if (autoForecastDay >= forecastSalesDetails.size()) { if (autoForecastDay >= forecastSalesDetails.size()) {
forecastSalesDetails.offer(dcAutoTurnover.getDailyWeightedSales()); forecastSalesDetails.offer(dcAutoTurnover.getDailyWeightedSales());
} }
} }
......
package com.bailuntec.job;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcAutoTurnover;
import com.bailuntec.domain.entity.DcBaseStock;
import com.bailuntec.domain.example.DcBaseStockExample;
import com.bailuntec.mapper.DcAutoSalesForecastStageConfigMapper;
import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.utils.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/8/25 4:43 下午
*/
@Slf4j
public class AutoTurnoverJobTest {
@Test
public void syncPartAutoTurnover() {
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
try (SqlSession sqlSession = SessionUtil.getFactory().openSession(true)) {
DcAutoSalesForecastStageConfigMapper dcAutoSalesForecastStageConfigMapper = sqlSession.getMapper(DcAutoSalesForecastStageConfigMapper.class);
DcBaseStockMapper dcBaseStockMapper = sqlSession.getMapper(DcBaseStockMapper.class);
List<DcAutoTurnover> dcAutoTurnoverList = dcAutoSalesForecastStageConfigMapper.selectTestSyncAutoTurnoverList();
dcAutoTurnoverList.stream().parallel().forEach(dcAutoTurnover -> {
DcBaseStock dcBaseStock = dcBaseStockMapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria()
.andBailunSkuEqualTo(dcAutoTurnover.getBailunSku())
.andWarehouseCodeEqualTo(dcAutoTurnover.getWarehouseCode())
.example());
try {
if (dcBaseStock != null) {
log.info("计算周转开始 bailunSku:{} , warehouseCode:{}", dcBaseStock.getBailunSku(), dcBaseStock.getWarehouseCode());
autoTurnoverJob.autoTurnoverFromStock(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now()), dcBaseStock);
log.info("计算周转结束 bailunSku:{} , warehouseCode:{}", dcBaseStock.getBailunSku(), dcBaseStock.getWarehouseCode());
} else {
log.error("没有找到周转对应的baseStock");
}
} catch (Exception e) {
log.error("计算周转失败 :{}", e.getMessage(), e);
}
});
}
}
}
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