Commit 4e6e6656 by wutong

自动周转安全库存配置新增一种算法(优先级别最低的),直接配置仓库。根据历史销量加权计算。最后可以乘以一个倍数; 不考虑供应商逾期

parent b155490f
......@@ -41,7 +41,7 @@ public class DcAutoConfigSafeInventory {
*
* @mbg.generated
*/
private Integer param;
private BigDecimal param;
/**
*
......
......@@ -219,6 +219,36 @@ public class DcAutoConfigSafeInventoryExample {
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public DcAutoConfigSafeInventoryExample when(boolean condition, IExampleWhen then) {
if (condition) {
then.example(this);
}
return this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public DcAutoConfigSafeInventoryExample when(boolean condition, IExampleWhen then, IExampleWhen otherwise) {
if (condition) {
then.example(this);
} else {
otherwise.example(this);
}
return this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public void setOffset(Integer offset) {
this.offset = offset;
}
......@@ -531,52 +561,52 @@ public class DcAutoConfigSafeInventoryExample {
return (Criteria) this;
}
public Criteria andParamEqualTo(Integer value) {
public Criteria andParamEqualTo(BigDecimal value) {
addCriterion("param =", value, "param");
return (Criteria) this;
}
public Criteria andParamNotEqualTo(Integer value) {
public Criteria andParamNotEqualTo(BigDecimal value) {
addCriterion("param <>", value, "param");
return (Criteria) this;
}
public Criteria andParamGreaterThan(Integer value) {
public Criteria andParamGreaterThan(BigDecimal value) {
addCriterion("param >", value, "param");
return (Criteria) this;
}
public Criteria andParamGreaterThanOrEqualTo(Integer value) {
public Criteria andParamGreaterThanOrEqualTo(BigDecimal value) {
addCriterion("param >=", value, "param");
return (Criteria) this;
}
public Criteria andParamLessThan(Integer value) {
public Criteria andParamLessThan(BigDecimal value) {
addCriterion("param <", value, "param");
return (Criteria) this;
}
public Criteria andParamLessThanOrEqualTo(Integer value) {
public Criteria andParamLessThanOrEqualTo(BigDecimal value) {
addCriterion("param <=", value, "param");
return (Criteria) this;
}
public Criteria andParamIn(List<Integer> values) {
public Criteria andParamIn(List<BigDecimal> values) {
addCriterion("param in", values, "param");
return (Criteria) this;
}
public Criteria andParamNotIn(List<Integer> values) {
public Criteria andParamNotIn(List<BigDecimal> values) {
addCriterion("param not in", values, "param");
return (Criteria) this;
}
public Criteria andParamBetween(Integer value1, Integer value2) {
public Criteria andParamBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("param between", value1, value2, "param");
return (Criteria) this;
}
public Criteria andParamNotBetween(Integer value1, Integer value2) {
public Criteria andParamNotBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("param not between", value1, value2, "param");
return (Criteria) this;
}
......@@ -1348,6 +1378,7 @@ public class DcAutoConfigSafeInventoryExample {
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
@Deprecated
public Criteria andIf(boolean ifAdd, ICriteriaAdd add) {
if (ifAdd) {
add.add(this);
......@@ -1356,12 +1387,43 @@ public class DcAutoConfigSafeInventoryExample {
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria when(boolean condition, ICriteriaWhen then) {
if (condition) {
then.criteria(this);
}
return this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria when(boolean condition, ICriteriaWhen then, ICriteriaWhen otherwise) {
if (condition) {
then.criteria(this);
} else {
otherwise.criteria(this);
}
return this;
}
/**
* This interface was generated by MyBatis Generator.
* This interface corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
@Deprecated
public interface ICriteriaAdd {
/**
* This method was generated by MyBatis Generator.
......@@ -1465,4 +1527,40 @@ public class DcAutoConfigSafeInventoryExample {
this(condition, value, secondValue, null);
}
}
/**
* This interface was generated by MyBatis Generator.
* This interface corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public interface ICriteriaWhen {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
void criteria(Criteria criteria);
}
/**
* This interface was generated by MyBatis Generator.
* This interface corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public interface IExampleWhen {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_config_safe_inventory
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
void example(DcAutoConfigSafeInventoryExample example);
}
}
\ No newline at end of file
......@@ -291,19 +291,13 @@ public class AutoTurnoverJob extends PointJob {
* 通过SKU拿到供应商Id,
* 再去dc_average_purchase拿到平均交期
* 平均交期 - 供应商交期 > 0 就是平均逾期天数
*
* 平均逾期天数 * 加权平均销量(去最大值最小值)
* 为安全库存--即防止逾期缓冲所需库存
* 可以支持配置
* 2019-04-22更新 不管逾期
*/
BigDecimal safeInventory = calculateSafeInventory(bailunSku, warehouseCode, bailunFirstLevelCatagoryId, dcAutoSales, JSON.toJSONString(forecastSalesList));
//平均逾期 = 平均交期(dc_average_purchase) - 供应商交期(根据仓库判断, 非国内就取调拨交期) , 小于0的取0
BigDecimal overdue = BigDecimal.ZERO;
if (dcAveragePurchase != null && dcAveragePurchase.getDeliveryDays() >= 0) {
overdue = BigDecimal.valueOf((dcAveragePurchase.getDeliveryDays().longValue() - dcAutoTurnover.getSupplierDelivery().longValue()));
overdue = overdue.compareTo(BigDecimal.ZERO) == 1 ? overdue : BigDecimal.ZERO;
}
//安全库存 * 平均逾期
BigDecimal totalSafeInventory = safeInventory.multiply((overdue.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : overdue));
BigDecimal totalSafeInventory = calculateSafeInventory(bailunSku, warehouseCode, bailunFirstLevelCatagoryId, dcAutoSales, JSON.toJSONString(forecastSalesList));
Integer moq = turnoverSku.getMoq();
/*
......@@ -347,7 +341,7 @@ public class AutoTurnoverJob extends PointJob {
BigDecimal avgHistoryThreedaySales = BigDecimal.valueOf(historyThreeSales.longValue()).divide(Constant.BIGDECIMAL_THREE, 3, RoundingMode.HALF_EVEN);
BigDecimal avgHistorySevendaySales = BigDecimal.valueOf(historySevenSales.longValue()).divide(Constant.BIGDECIMAL_SEVEN, 3, RoundingMode.HALF_EVEN);
BigDecimal avgHistoryFourteendaySales = BigDecimal.valueOf(historyFourteenSales.longValue()).divide(Constant.BIGDECIMAL_FOURTEEN, 3, RoundingMode.HALF_EVEN);
BigDecimal avgHistoryThirtydaySales = BigDecimal.valueOf(historyFourteenSales.longValue()).divide(Constant.BIGDECIMAL_THIRTY, 3, RoundingMode.HALF_EVEN);
BigDecimal avgHistoryThirtydaySales = BigDecimal.valueOf(historyThirtySales.longValue()).divide(Constant.BIGDECIMAL_THIRTY, 3, RoundingMode.HALF_EVEN);
/*
* forecastFluctuationList 用于存放预计缺货 实际缺货 预计冗余 实际冗余的数据
* dcAutoConfigSkuWarehouse 看是否监控状态
......@@ -458,7 +452,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setSupplementarySales(forecastSalesList.get(turnoverDays));
dcAutoTurnover.setAverageSupplierDelivery(dcAutoTurnover.getSupplierDelivery());
dcAutoTurnover.setSalesUpperLimit(salesUpperLimit);
dcAutoTurnover.setAverageOverdue(overdue);
dcAutoTurnover.setAverageOverdue(BigDecimal.ZERO);
dcAutoTurnover.setAdvisedDetails(moqPurchaseAdvisedList.toString());
dcAutoTurnover.setSalesDetails(forecastSalesList.toString());
dcAutoTurnover.setInboundDetails(forecastInboundList.toString());
......@@ -485,7 +479,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setQuantityOutStock(outStock);
dcAutoTurnover.setStatus(forecastShortSupplyList.get(2 * turnoverDays.intValue()).intValue() > 0 ? 1 : 0);
dcAutoTurnover.setTurnoverDays(turnoverDays);
dcAutoTurnover.setQuantitySafeInventory(safeInventory);
dcAutoTurnover.setQuantitySafeInventory(totalSafeInventory);
dcBaseStock.setSkuTitleCn(turnoverSku.getSkuTitleCn());
dcBaseStock.setProductInnerCode(turnoverSku.getProductInnerCode());
......@@ -1007,6 +1001,8 @@ public class AutoTurnoverJob extends PointJob {
* 最终
* 平均交期 - 供应商交期 > 0 就是平均逾期天数
* 平均逾期天数 * 加权平均销量(去最大值最小值)
*
* 新增一种算法(优先级别最低的),直接配置仓库。根据历史销量加权计算。最后可以乘以一个倍数
*/
DcAutoConfigSafeInventoryMapper autoConfigSafeInventoryMapper = null;
DcAutoConfigSafeInventory dcAutoConfigSafeInventory = null;
......@@ -1036,12 +1032,20 @@ public class AutoTurnoverJob extends PointJob {
if (dcAutoConfigSafeInventory != null) {
weightingAvgSales = caculateWeightingAvgSales(dcAutoConfigSafeInventory.getWeightingCoefficientSeven(), dcAutoConfigSafeInventory.getWeightingCoefficientFourteen(), dcAutoConfigSafeInventory.getWeightingCoefficientThirty(), historyThirtySalesList);
} else {
weightingAvgSales = caculateWeightingAvgSales(BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.4), historyThirtySalesList);
//仓库。根据历史销量加权计算。最后可以乘以一个倍数
dcAutoConfigSafeInventory = autoConfigSafeInventoryMapper.selectOneByExample(DcAutoConfigSafeInventoryExample.newAndCreateCriteria().andVariableCodeEqualTo("").andWarehouseCodeEqualTo(warehouseCode).andStatusEqualTo(1).andTypeEqualTo(3).example());
if (dcAutoConfigSafeInventory != null) {
weightingAvgSales = caculateWeightingAvgSales(dcAutoConfigSafeInventory.getWeightingCoefficientSeven(), dcAutoConfigSafeInventory.getWeightingCoefficientFourteen(), dcAutoConfigSafeInventory.getWeightingCoefficientThirty(), historyThirtySalesList);
weightingAvgSales = weightingAvgSales.multiply(dcAutoConfigSafeInventory.getParam()).setScale(3, RoundingMode.HALF_EVEN);
} else {
//啥配置都没有就给个默认取值
weightingAvgSales = caculateWeightingAvgSales(BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.4), historyThirtySalesList);
}
}
}
return weightingAvgSales;
} else {
return BigDecimal.valueOf(dcAutoConfigSafeInventory.getParam().longValue());
return dcAutoConfigSafeInventory.getParam();
}
} catch (Exception e) {
e.printStackTrace();
......@@ -1223,7 +1227,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setTurnoverSales(totalSales);
}
//采购建议 = 安全库存缺少值 + 今日的实际缺货 + 本次采购到货日期前一天的累计销量 - 本次采购到货日期累计到货数量 + 预计销量 - 今日的实际库存
BigDecimal totalAdvised = totalSafeInventory.subtract(forecastInventoryList.get(j))//安全库存缺少值= 理论安全库存 - 预测库存
BigDecimal totalAdvised = totalSafeInventory.subtract(forecastInventoryList.get(j>0?j - 1:0))//安全库存缺少值= 理论安全库存 - 预测库存
.add(BigDecimal.valueOf(outStock.longValue()))//今天的实际缺货
.add(totalSales)//累计销量
.subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货
......@@ -1360,7 +1364,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setTurnoverSales(totalSales);
}
//采购建议 = 安全库存缺少值 + 今日的实际缺货 + 本次采购到货日期前一天的累计销量 - 本次采购到货日期累计到货数量 + 预计销量
BigDecimal totalAdvised = totalSafeInventory.subtract(forecastInventoryList.get(j))//安全库存缺少值= 理论安全库存 - 预测库存
BigDecimal totalAdvised = totalSafeInventory.subtract(forecastInventoryList.get(j>0?j - 1:0))//安全库存缺少值= 理论安全库存 - 预测库存
.add(BigDecimal.valueOf(outStock.longValue()))//今天的实际缺货
.add(totalSales)//累计销量
.subtract(BigDecimal.valueOf(totalInbound.doubleValue()))//累计到货
......
......@@ -9,7 +9,7 @@
<id column="id" jdbcType="INTEGER" property="id" />
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified" />
<result column="param" jdbcType="INTEGER" property="param" />
<result column="param" jdbcType="DECIMAL" property="param" />
<result column="variable_code" jdbcType="VARCHAR" property="variableCode" />
<result column="variable_name" jdbcType="VARCHAR" property="variableName" />
<result column="type" jdbcType="TINYINT" property="type" />
......@@ -162,8 +162,8 @@
bl_operator, remark, status,
weighting_coefficient_seven, weighting_coefficient_fourteen,
weighting_coefficient_thirty)
values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{param,jdbcType=INTEGER}, #{variableCode,jdbcType=VARCHAR}, #{variableName,jdbcType=VARCHAR},
values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{param,jdbcType=DECIMAL}, #{variableCode,jdbcType=VARCHAR}, #{variableName,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR},
#{blOperator,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
#{weightingCoefficientSeven,jdbcType=DECIMAL}, #{weightingCoefficientFourteen,jdbcType=DECIMAL},
......@@ -233,7 +233,7 @@
#{gmtModified,jdbcType=TIMESTAMP},
</if>
<if test="param != null">
#{param,jdbcType=INTEGER},
#{param,jdbcType=DECIMAL},
</if>
<if test="variableCode != null">
#{variableCode,jdbcType=VARCHAR},
......@@ -297,7 +297,7 @@
gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
</if>
<if test="record.param != null">
param = #{record.param,jdbcType=INTEGER},
param = #{record.param,jdbcType=DECIMAL},
</if>
<if test="record.variableCode != null">
variable_code = #{record.variableCode,jdbcType=VARCHAR},
......@@ -346,7 +346,7 @@
set id = #{record.id,jdbcType=INTEGER},
gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
param = #{record.param,jdbcType=INTEGER},
param = #{record.param,jdbcType=DECIMAL},
variable_code = #{record.variableCode,jdbcType=VARCHAR},
variable_name = #{record.variableName,jdbcType=VARCHAR},
type = #{record.type,jdbcType=TINYINT},
......@@ -376,7 +376,7 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
<if test="param != null">
param = #{param,jdbcType=INTEGER},
param = #{param,jdbcType=DECIMAL},
</if>
<if test="variableCode != null">
variable_code = #{variableCode,jdbcType=VARCHAR},
......@@ -422,7 +422,7 @@
update dc_auto_config_safe_inventory
set gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
param = #{param,jdbcType=INTEGER},
param = #{param,jdbcType=DECIMAL},
variable_code = #{variableCode,jdbcType=VARCHAR},
variable_name = #{variableName,jdbcType=VARCHAR},
type = #{type,jdbcType=TINYINT},
......@@ -502,7 +502,7 @@
#{gmtModified,jdbcType=TIMESTAMP},
</if>
<if test="param != null">
#{param,jdbcType=INTEGER},
#{param,jdbcType=DECIMAL},
</if>
<if test="variableCode != null">
#{variableCode,jdbcType=VARCHAR},
......@@ -550,7 +550,7 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
<if test="param != null">
param = #{param,jdbcType=INTEGER},
param = #{param,jdbcType=DECIMAL},
</if>
<if test="variableCode != null">
variable_code = #{variableCode,jdbcType=VARCHAR},
......@@ -598,17 +598,17 @@
warehouse_name, bl_operator, remark, status, weighting_coefficient_seven, weighting_coefficient_fourteen,
weighting_coefficient_thirty)
values
(#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{param,jdbcType=INTEGER}, #{variableCode,jdbcType=VARCHAR}, #{variableName,jdbcType=VARCHAR},
(#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{param,jdbcType=DECIMAL}, #{variableCode,jdbcType=VARCHAR}, #{variableName,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR},
#{blOperator,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
#{weightingCoefficientSeven,jdbcType=DECIMAL}, #{weightingCoefficientFourteen,jdbcType=DECIMAL},
#{weightingCoefficientThirty,jdbcType=DECIMAL})
on duplicate key update
id = #{id,jdbcType=INTEGER},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
param = #{param,jdbcType=INTEGER},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
param = #{param,jdbcType=DECIMAL},
variable_code = #{variableCode,jdbcType=VARCHAR},
variable_name = #{variableName,jdbcType=VARCHAR},
type = #{type,jdbcType=TINYINT},
......
......@@ -52,7 +52,7 @@ public class AutoTurnoverTest {
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("322572421").andWarehouseCodeEqualTo("QYBLZZ").example());
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("232232601").andWarehouseCodeEqualTo("CHUKFBA").example());
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("213789601").andWarehouseCodeEqualTo("GZBLWH").example());
dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("214625401").andWarehouseCodeEqualTo("GZBLWH").example());
dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("381757501").andWarehouseCodeEqualTo("GZBLWH").example());
} catch (Exception e) {
e.printStackTrace();
} finally {
......
table-name=dc_base_purchase_details
table-name=dc_auto_config_safe_inventory
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