Commit 2cff326c by guanzhenshan

每日周转增加断货判断逻辑

parent e763f91f
...@@ -673,6 +673,8 @@ public class DcAutoTurnover { ...@@ -673,6 +673,8 @@ public class DcAutoTurnover {
*/ */
private BigDecimal historyThirtydaySalesAmazon; private BigDecimal historyThirtydaySalesAmazon;
private Integer is_out_stock;
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_auto_turnover * This method corresponds to the database table dc_auto_turnover
......
...@@ -121,4 +121,6 @@ public interface DcAutoForecastFluctuationMapper { ...@@ -121,4 +121,6 @@ public interface DcAutoForecastFluctuationMapper {
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
int upsertSelective(DcAutoForecastFluctuation record); int upsertSelective(DcAutoForecastFluctuation record);
Integer yesterdayStock(@Param("bailun_sku")String bailun_sku,@Param("warehouse_code") String warehouse_code);
} }
\ No newline at end of file
...@@ -688,4 +688,8 @@ ...@@ -688,4 +688,8 @@
</if> </if>
limit 1 limit 1
</select> </select>
<select id="yesterdayStock" resultType="java.lang.Integer">
select usable_stock from dc_daily_stock where bailun_sku=#{bailun_sku} and warehouse_code=#{warehouse_code} and record_time=DATE_SUB(curdate(),INTERVAL 2 DAY)
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -134,4 +134,6 @@ public interface DcAutoTurnoverMapper { ...@@ -134,4 +134,6 @@ public interface DcAutoTurnoverMapper {
void truncateAutoSalesTable(); void truncateAutoSalesTable();
void truncateAutoExceptionTable(); void truncateAutoExceptionTable();
Integer yesterdayStock(@Param("bailun_sku")String bailun_sku,@Param("warehouse_code") String warehouse_code);
} }
\ No newline at end of file
...@@ -80,6 +80,8 @@ ...@@ -80,6 +80,8 @@
<result column="history_sevenday_sales_amazon" jdbcType="DECIMAL" property="historySevendaySalesAmazon" /> <result column="history_sevenday_sales_amazon" jdbcType="DECIMAL" property="historySevendaySalesAmazon" />
<result column="history_fourteenday_sales_amazon" jdbcType="DECIMAL" property="historyFourteendaySalesAmazon" /> <result column="history_fourteenday_sales_amazon" jdbcType="DECIMAL" property="historyFourteendaySalesAmazon" />
<result column="history_thirtyday_sales_amazon" jdbcType="DECIMAL" property="historyThirtydaySalesAmazon" /> <result column="history_thirtyday_sales_amazon" jdbcType="DECIMAL" property="historyThirtydaySalesAmazon" />
<result column="is_out_stock" jdbcType="INTEGER" property="is_out_stock" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<!-- <!--
...@@ -519,6 +521,9 @@ ...@@ -519,6 +521,9 @@
<if test="historyThirtydaySalesAmazon != null"> <if test="historyThirtydaySalesAmazon != null">
history_thirtyday_sales_amazon, history_thirtyday_sales_amazon,
</if> </if>
<if test="is_out_stock != null">
is_out_stock,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
...@@ -743,6 +748,9 @@ ...@@ -743,6 +748,9 @@
<if test="historyThirtydaySalesAmazon != null"> <if test="historyThirtydaySalesAmazon != null">
#{historyThirtydaySalesAmazon,jdbcType=DECIMAL}, #{historyThirtydaySalesAmazon,jdbcType=DECIMAL},
</if> </if>
<if test="is_out_stock != null">
#{is_out_stock,jdbcType=INTEGER},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcAutoTurnoverExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.bailuntec.domain.example.DcAutoTurnoverExample" resultType="java.lang.Long">
...@@ -984,6 +992,9 @@ ...@@ -984,6 +992,9 @@
<if test="record.historyThirtydaySalesAmazon != null"> <if test="record.historyThirtydaySalesAmazon != null">
history_thirtyday_sales_amazon = #{record.historyThirtydaySalesAmazon,jdbcType=DECIMAL}, history_thirtyday_sales_amazon = #{record.historyThirtydaySalesAmazon,jdbcType=DECIMAL},
</if> </if>
<if test="record.is_out_stock != null">
is_out_stock = #{record.is_out_stock,jdbcType=INTEGER},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -2235,4 +2246,9 @@ ...@@ -2235,4 +2246,9 @@
<delete id="truncateAutoExceptionTable"> <delete id="truncateAutoExceptionTable">
TRUNCATE dc_auto_exception TRUNCATE dc_auto_exception
</delete> </delete>
<select id="yesterdayStock" resultType="java.lang.Integer">
select usable_stock from dc_daily_stock where bailun_sku=#{bailun_sku} and warehouse_code=#{warehouse_code} and record_time=DATE_SUB(curdate(),INTERVAL 2 DAY)
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -451,7 +451,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -451,7 +451,7 @@ public class AutoTurnoverJob extends PointJob {
* 自动下单管理的冗余-缺货等异常提醒 * 自动下单管理的冗余-缺货等异常提醒
*/ */
if (hasMonitorFluctuation) { if (hasMonitorFluctuation) {
unusualFluctuation(totalSafeInventory, turnoverDays, recordTime, dcAutoConfigSkuWarehouse, turnoverSku, warehouseCode, dcAutoTurnover, avgHistoryThreedaySales, forecastFluctuationList, forecastShortSupplyList, forecastInventoryList); unusualFluctuation(totalSafeInventory, turnoverDays, recordTime, dcAutoConfigSkuWarehouse, turnoverSku, warehouseCode, dcAutoTurnover, avgHistoryThreedaySales, forecastFluctuationList, forecastShortSupplyList, forecastInventoryList,dcBaseStock);
} }
//拿一下2倍周转期内的入库总数 //拿一下2倍周转期内的入库总数
...@@ -570,8 +570,28 @@ public class AutoTurnoverJob extends PointJob { ...@@ -570,8 +570,28 @@ public class AutoTurnoverJob extends PointJob {
/*dcBaseStock.setSkuTitleCn(turnoverSku.getSkuTitleCn()); /*dcBaseStock.setSkuTitleCn(turnoverSku.getSkuTitleCn());
dcBaseStock.setProductInnerCode(turnoverSku.getProductInnerCode()); dcBaseStock.setProductInnerCode(turnoverSku.getProductInnerCode());
dcBaseStock.setSuppliersName(turnoverSku.getSuppliersName());*/ dcBaseStock.setSuppliersName(turnoverSku.getSuppliersName());*/
try { try {
DcAutoTurnoverMapper autoTurnoverMapper = SessionUtil.getSession().getMapper(DcAutoTurnoverMapper.class); DcAutoTurnoverMapper autoTurnoverMapper = SessionUtil.getSession().getMapper(DcAutoTurnoverMapper.class);
/*
* 增加是否断货计算
* Add by Allan at 2020-07-22 15:47
* 断货=前一天还有库存,但是今天库存为0了则是已经断货
* */
dcAutoTurnover.setIs_out_stock(0);
// if(dcBaseStock.getUsableStock()==0)
// {
// //获取前一天库存
// Integer yesterdayStock = autoTurnoverMapper.yesterdayStock(dcAutoTurnover.getBailunSku(),dcAutoTurnover.getWarehouseCode());
// if(yesterdayStock!=null && yesterdayStock>0)
// {
// dcAutoTurnover.setIs_out_stock(1);
// }
// }
//End Add
// DcBaseStockMapper dcBaseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class); // DcBaseStockMapper dcBaseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
int i = autoTurnoverMapper.updateByExampleSelective(dcAutoTurnover, DcAutoTurnoverExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoTurnover.getBailunSku()).andWarehouseCodeEqualTo(dcAutoTurnover.getWarehouseCode()).example()); int i = autoTurnoverMapper.updateByExampleSelective(dcAutoTurnover, DcAutoTurnoverExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoTurnover.getBailunSku()).andWarehouseCodeEqualTo(dcAutoTurnover.getWarehouseCode()).example());
if (i == 0) { if (i == 0) {
...@@ -584,6 +604,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -584,6 +604,7 @@ public class AutoTurnoverJob extends PointJob {
} finally { } finally {
SessionUtil.closeSession(); SessionUtil.closeSession();
} }
} }
private void caculatePlatformAvgSales(DcAutoTurnover dcAutoTurnover) { private void caculatePlatformAvgSales(DcAutoTurnover dcAutoTurnover) {
...@@ -710,9 +731,9 @@ public class AutoTurnoverJob extends PointJob { ...@@ -710,9 +731,9 @@ public class AutoTurnoverJob extends PointJob {
* 不正常的波动 * 不正常的波动
* 实际缺货的,预计缺货 * 实际缺货的,预计缺货
* 实际冗余的,预计冗余(库存> 销量 + 安全库存) * 实际冗余的,预计冗余(库存> 销量 + 安全库存)
* 波动提醒优先级 --> 实际缺货-实际冗余-预计缺货-预计冗余 * 波动提醒优先级 --> 实际缺货-实际断货-实际冗余-预计缺货-预计冗余
*/ */
private void unusualFluctuation(BigDecimal totalSafeInventory, Integer turnoverDays, LocalDate recordTime, DcAutoConfigSkuWarehouse dcAutoConfigSkuWarehouse, DcBaseSku turnoverSku, String warehouseCode, DcAutoTurnover dcAutoTurnover, BigDecimal avgHistoryThreedaySales, List<DcAutoForecastFluctuation> forecastFluctuationList, List<BigDecimal> forecastShortSupplyList, List<BigDecimal> forecastInventoryList) { private void unusualFluctuation(BigDecimal totalSafeInventory, Integer turnoverDays, LocalDate recordTime, DcAutoConfigSkuWarehouse dcAutoConfigSkuWarehouse, DcBaseSku turnoverSku, String warehouseCode, DcAutoTurnover dcAutoTurnover, BigDecimal avgHistoryThreedaySales, List<DcAutoForecastFluctuation> forecastFluctuationList, List<BigDecimal> forecastShortSupplyList, List<BigDecimal> forecastInventoryList,DcBaseStock dcBaseStock) {
int days = 0;//连续冗余或缺货天数 int days = 0;//连续冗余或缺货天数
int index = -1;//冗余或缺货天数索引 int index = -1;//冗余或缺货天数索引
...@@ -761,6 +782,7 @@ public class AutoTurnoverJob extends PointJob { ...@@ -761,6 +782,7 @@ public class AutoTurnoverJob extends PointJob {
if (!warehouseCode.equals(Constant.WAREHOUSE_JIT) || !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_1) && !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2) && !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_3)) { if (!warehouseCode.equals(Constant.WAREHOUSE_JIT) || !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_1) && !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2) && !turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_3)) {
if (dcAutoConfigSkuWarehouse == null || dcAutoConfigSkuWarehouse.getStatus().equals(0)) { if (dcAutoConfigSkuWarehouse == null || dcAutoConfigSkuWarehouse.getStatus().equals(0)) {
if (forecastFluctuationList != null && forecastFluctuationList.size() > 0) { if (forecastFluctuationList != null && forecastFluctuationList.size() > 0) {
//拿最早的时间 + 最晚的时间, SKU-仓库维度只放一条 //拿最早的时间 + 最晚的时间, SKU-仓库维度只放一条
DcAutoForecastFluctuation dcAutoForecastFluctuation = forecastFluctuationList.get(0); DcAutoForecastFluctuation dcAutoForecastFluctuation = forecastFluctuationList.get(0);
dcAutoForecastFluctuation.setStartTime(forecastFluctuationList.get(0).getStartTime()); dcAutoForecastFluctuation.setStartTime(forecastFluctuationList.get(0).getStartTime());
...@@ -769,6 +791,26 @@ public class AutoTurnoverJob extends PointJob { ...@@ -769,6 +791,26 @@ public class AutoTurnoverJob extends PointJob {
dcAutoForecastFluctuation.setWarehouseCode(warehouseCode); dcAutoForecastFluctuation.setWarehouseCode(warehouseCode);
dcAutoForecastFluctuation.setWarehouseName(dcAutoTurnover.getWarehouseName()); dcAutoForecastFluctuation.setWarehouseName(dcAutoTurnover.getWarehouseName());
dcAutoForecastFluctuation.setAvgSalesThree(avgHistoryThreedaySales); dcAutoForecastFluctuation.setAvgSalesThree(avgHistoryThreedaySales);
/*
* 增加是否断货计算
* Add by Allan at 2020-07-23 10:58
* 断货=前一天还有库存,但是今天库存为0了则是已经断货
* */
if(forecastFluctuationList.get(0).getType()!=1 && dcBaseStock.getUsableStock()==0)
{
//获取前一天库存
Integer yesterdayStock = mapper.yesterdayStock(dcAutoTurnover.getBailunSku(),dcAutoTurnover.getWarehouseCode());
if(yesterdayStock!=null && yesterdayStock>0)
{
dcAutoForecastFluctuation.setType(5); //实际断货
dcAutoForecastFluctuation.setStartTime(LocalDate.now()); //保存当天日期
dcAutoForecastFluctuation.setEndTime(LocalDate.now()); //保存当天日期
}
}
//End Add
int i = mapper.updateByExampleSelective(dcAutoForecastFluctuation, DcAutoForecastFluctuationExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoForecastFluctuation.getBailunSku()).andWarehouseCodeEqualTo(dcAutoForecastFluctuation.getWarehouseCode()).example()); int i = mapper.updateByExampleSelective(dcAutoForecastFluctuation, DcAutoForecastFluctuationExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoForecastFluctuation.getBailunSku()).andWarehouseCodeEqualTo(dcAutoForecastFluctuation.getWarehouseCode()).example());
if (i == 0) { if (i == 0) {
mapper.insertSelective(dcAutoForecastFluctuation); mapper.insertSelective(dcAutoForecastFluctuation);
......
#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://gz-cdb-kp7s5i79.sql.tencentcdb.com:61691/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
......
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