Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dc-java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bltdc
dc-java
Commits
d07f3236
Commit
d07f3236
authored
Aug 06, 2019
by
yinyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
供应链长度修改
parent
8dc25197
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
159 additions
and
118 deletions
+159
-118
AutoTurnoverJob.java
...over/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
+159
-118
No files found.
data-show/show-auto-turnover/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
View file @
d07f3236
...
@@ -233,7 +233,15 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -233,7 +233,15 @@ public class AutoTurnoverJob extends PointJob {
* 所以预测2倍周转期长度
* 所以预测2倍周转期长度
* 2倍周转期长度 < 31 的, 默认算31天, 但是生成的采购建议不拿2倍周转期以外的
* 2倍周转期长度 < 31 的, 默认算31天, 但是生成的采购建议不拿2倍周转期以外的
*/
*/
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
)))
{
BigDecimal
saveDays
=
getSaveDays
(
dcAutoSales
,
dcAutoTurnover
,
bailunSku
,
"autoForecastDay"
);
if
(
saveDays
.
compareTo
(
new
BigDecimal
(
4
))
>
-
1
)
{
saveDays
=
BigDecimal
.
valueOf
(
4
);
}
turnoverDays
=
saveDays
.
intValue
();
}
Integer
autoForecastDay
=
turnoverDays
*
Constant
.
TURNOVER_MULTIPLE
<
Constant
.
MIN_AUTO_FORECAST_DAY
?
Constant
.
MIN_AUTO_FORECAST_DAY
:
turnoverDays
*
2
;
Integer
autoForecastDay
=
turnoverDays
*
Constant
.
TURNOVER_MULTIPLE
<
Constant
.
MIN_AUTO_FORECAST_DAY
?
Constant
.
MIN_AUTO_FORECAST_DAY
:
turnoverDays
*
2
;
/*
/*
* 初始化预测容器, 用来存放预测销量, 库存等数据
* 初始化预测容器, 用来存放预测销量, 库存等数据
* forecastInventoryList
* forecastInventoryList
...
@@ -319,12 +327,33 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -319,12 +327,33 @@ public class AutoTurnoverJob extends PointJob {
//通过SKU和仓库拿到实际库存
//通过SKU和仓库拿到实际库存
Integer
realInventory
=
(
dcBaseStock
!=
null
&&
dcBaseStock
.
getUsableStock
()
!=
null
)
?
dcBaseStock
.
getUsableStock
()
:
0
;
Integer
realInventory
=
(
dcBaseStock
!=
null
&&
dcBaseStock
.
getUsableStock
()
!=
null
)
?
dcBaseStock
.
getUsableStock
()
:
0
;
/*
* 通过SKU拿到供应商Id,
* 再去dc_average_purchase拿到平均交期
* 平均交期 - 供应商交期 > 0 就是平均逾期天数
*
* 平均逾期天数 * 加权平均销量(去最大值最小值)
* 为安全库存--即防止逾期缓冲所需库存
* 可以支持配置
* 2019-04-22更新 不管逾期
*/
BigDecimal
totalSafeInventory
=
calculateSafeInventory
(
turnoverSku
,
bailunSku
,
warehouseCode
,
bailunFirstLevelCatagoryId
,
dcAutoSales
,
JSON
.
toJSONString
(
forecastSalesList
),
dcAutoTurnover
);
Integer
moq
=
turnoverSku
.
getMoq
();
/*
* 预测库存 = 前一日库存 - 前一日销量(没有考虑实际缺货)
*
* 采购建议为周转期后那一天的销量 + 安全库存 - 预测库存 + 累计断货
* 如果有库存, 优先抵消断货数, 再去跟销量对比
*/
//通过SKU和仓库取预测销量
Integer
inventoryAvailableDays
=
0
;
BigDecimal
totalSales
=
BigDecimal
.
ZERO
;
//周转期总销量
BigDecimal
totalInbound
=
BigDecimal
.
ZERO
;
//周转期总预计入库
BigDecimal
moqDecimal
=
BigDecimal
.
valueOf
(
moq
.
longValue
());
List
<
Integer
>
historySalesList
=
JSON
.
parseObject
(
dcAutoSales
.
getHistorySalesDetails
(),
new
TypeReference
<
List
<
Integer
>>()
{
List
<
Integer
>
historySalesList
=
JSON
.
parseObject
(
dcAutoSales
.
getHistorySalesDetails
(),
new
TypeReference
<
List
<
Integer
>>()
{
});
});
/*
/*
* dcAutoConfigSkuWarehouse不存在或者其status=0都是监控状态
* dcAutoConfigSkuWarehouse不存在或者其status=0都是监控状态
* 库存为0 并且 最近14天日均销量为0
* 库存为0 并且 最近14天日均销量为0
...
@@ -353,32 +382,6 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -353,32 +382,6 @@ public class AutoTurnoverJob extends PointJob {
BigDecimal
avgHistoryFourteendaySales
=
BigDecimal
.
valueOf
(
historyFourteenSales
.
longValue
()).
divide
(
Constant
.
BIGDECIMAL_FOURTEEN
,
3
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
avgHistoryFourteendaySales
=
BigDecimal
.
valueOf
(
historyFourteenSales
.
longValue
()).
divide
(
Constant
.
BIGDECIMAL_FOURTEEN
,
3
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
avgHistoryThirtydaySales
=
BigDecimal
.
valueOf
(
historyThirtySales
.
longValue
()).
divide
(
Constant
.
BIGDECIMAL_THIRTY
,
3
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
avgHistoryThirtydaySales
=
BigDecimal
.
valueOf
(
historyThirtySales
.
longValue
()).
divide
(
Constant
.
BIGDECIMAL_THIRTY
,
3
,
RoundingMode
.
HALF_EVEN
);
/*
* 通过SKU拿到供应商Id,
* 再去dc_average_purchase拿到平均交期
* 平均交期 - 供应商交期 > 0 就是平均逾期天数
*
* 平均逾期天数 * 加权平均销量(去最大值最小值)
* 为安全库存--即防止逾期缓冲所需库存
* 可以支持配置
* 2019-04-22更新 不管逾期
*/
BigDecimal
totalSafeInventory
=
calculateSafeInventory
(
avgHistorySevendaySales
,
avgHistoryFourteendaySales
,
turnoverSku
,
bailunSku
,
warehouseCode
,
bailunFirstLevelCatagoryId
,
dcAutoSales
,
JSON
.
toJSONString
(
forecastSalesList
),
dcAutoTurnover
);
Integer
moq
=
turnoverSku
.
getMoq
();
/*
* 预测库存 = 前一日库存 - 前一日销量(没有考虑实际缺货)
*
* 采购建议为周转期后那一天的销量 + 安全库存 - 预测库存 + 累计断货
* 如果有库存, 优先抵消断货数, 再去跟销量对比
*/
//通过SKU和仓库取预测销量
Integer
inventoryAvailableDays
=
0
;
BigDecimal
totalSales
=
BigDecimal
.
ZERO
;
//周转期总销量
BigDecimal
totalInbound
=
BigDecimal
.
ZERO
;
//周转期总预计入库
BigDecimal
moqDecimal
=
BigDecimal
.
valueOf
(
moq
.
longValue
());
/*
/*
* forecastFluctuationList 用于存放预计缺货 实际缺货 预计冗余 实际冗余的数据
* forecastFluctuationList 用于存放预计缺货 实际缺货 预计冗余 实际冗余的数据
* dcAutoConfigSkuWarehouse 看是否监控状态
* dcAutoConfigSkuWarehouse 看是否监控状态
...
@@ -1082,7 +1085,7 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -1082,7 +1085,7 @@ public class AutoTurnoverJob extends PointJob {
}
}
}
}
private
BigDecimal
calculateSafeInventory
(
BigDecimal
avgHistorySevendaySales
,
BigDecimal
avgHistoryFourteendaySales
,
DcBaseSku
turnoverSku
,
String
bailunSku
,
String
warehouseCode
,
Integer
private
BigDecimal
calculateSafeInventory
(
DcBaseSku
turnoverSku
,
String
bailunSku
,
String
warehouseCode
,
Integer
bailunFirstLevelCatagoryId
,
DcAutoSales
dcAutoSales
,
String
forecastSalesListJson
,
DcAutoTurnover
dcAutoTurnover
)
{
bailunFirstLevelCatagoryId
,
DcAutoSales
dcAutoSales
,
String
forecastSalesListJson
,
DcAutoTurnover
dcAutoTurnover
)
{
/*
/*
* 先判断是否JIT 仓库是广州01 warehouse_code 且是那三个销售员 turnoversku
* 先判断是否JIT 仓库是广州01 warehouse_code 且是那三个销售员 turnoversku
...
@@ -1092,95 +1095,8 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -1092,95 +1095,8 @@ public class AutoTurnoverJob extends PointJob {
List
<
BigDecimal
>
historyThirtySalesList
=
JSON
.
parseObject
(
dcAutoSales
.
getHistorySalesDetails
(),
new
TypeReference
<
List
<
BigDecimal
>>()
{
List
<
BigDecimal
>
historyThirtySalesList
=
JSON
.
parseObject
(
dcAutoSales
.
getHistorySalesDetails
(),
new
TypeReference
<
List
<
BigDecimal
>>()
{
});
});
BigDecimal
weightingAvgSales
=
caculateWeightingAvgSales
(
BigDecimal
.
valueOf
(
0.3
),
BigDecimal
.
valueOf
(
0.3
),
BigDecimal
.
valueOf
(
0.4
),
historyThirtySalesList
);
BigDecimal
weightingAvgSales
=
caculateWeightingAvgSales
(
BigDecimal
.
valueOf
(
0.3
),
BigDecimal
.
valueOf
(
0.3
),
BigDecimal
.
valueOf
(
0.4
),
historyThirtySalesList
);
DcAutoJitTagMapper
dcAutoJitTagMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcAutoJitTagMapper
.
class
);
List
<
DcAutoJitTag
>
dcAutoJitTags
=
dcAutoJitTagMapper
.
selectByExample
(
DcAutoJitTagExample
.
newAndCreateCriteria
().
example
());
BigDecimal
saveDays
=
getSaveDays
(
dcAutoSales
,
dcAutoTurnover
,
bailunSku
,
"weightingAvgSales"
);
BigDecimal
saveDays
=
BigDecimal
.
ZERO
;
for
(
DcAutoJitTag
dcAutoJitTag
:
dcAutoJitTags
)
{
if
(
dcAutoJitTag
.
getEnable7
()
==
1
)
{
switch
(
dcAutoJitTag
.
getIsGt7
()){
case
1
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
1
)
{
break
;
}
else
{
continue
;
}
case
2
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
0
)
{
break
;
}
else
{
continue
;
}
case
3
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
-
1
)
{
break
;
}
else
{
continue
;
}
case
4
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
>
-
1
)
{
break
;
}
else
{
continue
;
}
case
5
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
<
1
)
{
break
;
}
else
{
continue
;
}
default
:
continue
;
}
}
if
(
dcAutoJitTag
.
getEnable14
()
==
1
)
{
switch
(
dcAutoJitTag
.
getIsGt14
()){
case
1
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
1
)
{
break
;
}
else
{
continue
;
}
case
2
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
0
)
{
break
;
}
else
{
continue
;
}
case
3
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
-
1
)
{
break
;
}
else
{
continue
;
}
case
4
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
>
-
1
)
{
break
;
}
else
{
continue
;
}
case
5
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
<
1
)
{
break
;
}
else
{
continue
;
}
default
:
continue
;
}
}
saveDays
=
dcAutoJitTag
.
getQuantitySafeInventory
();
DcAutoJitTagLogMapper
dcAutoJitTagLogMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcAutoJitTagLogMapper
.
class
);
DcAutoJitTagLog
dcAutoJitTagLog
=
new
DcAutoJitTagLog
();
dcAutoJitTagLog
.
setBailunSku
(
bailunSku
);
dcAutoJitTagLog
.
setDate
(
LocalDate
.
now
());
dcAutoJitTagLog
.
setQuantitySales7
(
avgHistorySevendaySales
);
dcAutoJitTagLog
.
setQuantitySales14
(
avgHistoryFourteendaySales
);
dcAutoJitTagLog
.
setTagId
(
dcAutoJitTag
.
getId
());
dcAutoJitTagLog
.
setTagJson
(
JSONObject
.
toJSONString
(
dcAutoJitTag
));
dcAutoJitTagLogMapper
.
upsertSelective
(
dcAutoJitTagLog
);
dcAutoTurnover
.
setTagId
(
dcAutoJitTag
.
getId
());
break
;
}
dcAutoTurnover
.
setDailyWeightedSales
(
weightingAvgSales
);
dcAutoTurnover
.
setDailyWeightedSales
(
weightingAvgSales
);
weightingAvgSales
=
weightingAvgSales
.
multiply
(
saveDays
);
weightingAvgSales
=
weightingAvgSales
.
multiply
(
saveDays
);
return
weightingAvgSales
;
return
weightingAvgSales
;
...
@@ -1881,4 +1797,129 @@ public class AutoTurnoverJob extends PointJob {
...
@@ -1881,4 +1797,129 @@ public class AutoTurnoverJob extends PointJob {
}
}
return
(
int
)
totalPage
;
return
(
int
)
totalPage
;
}
}
public
BigDecimal
getSaveDays
(
DcAutoSales
dcAutoSales
,
DcAutoTurnover
dcAutoTurnover
,
String
bailunSku
,
String
autoForecastDay
)
{
List
<
Integer
>
historySalesList
=
JSON
.
parseObject
(
dcAutoSales
.
getHistorySalesDetails
(),
new
TypeReference
<
List
<
Integer
>>()
{
});
/*
* dcAutoConfigSkuWarehouse不存在或者其status=0都是监控状态
* 库存为0 并且 最近14天日均销量为0
* 已经提醒实际缺货的,预计缺货就不提醒了
* 已经提醒实际冗余的,预计冗余就不提醒了
* 停止监控的不提醒
*/
Integer
historyFourteenSales
=
0
;
Integer
historySevenSales
=
0
;
Integer
historyThreeSales
=
0
;
Integer
historyThirtySales
=
0
;
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
if
(
i
<
3
)
{
historyThreeSales
+=
historySalesList
.
get
(
27
+
i
);
}
if
(
i
<
7
)
{
historySevenSales
+=
historySalesList
.
get
(
23
+
i
);
}
if
(
i
<
14
)
{
historyFourteenSales
+=
historySalesList
.
get
(
16
+
i
);
}
historyThirtySales
+=
historySalesList
.
get
(
i
);
}
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
(
historyThirtySales
.
longValue
()).
divide
(
Constant
.
BIGDECIMAL_THIRTY
,
3
,
RoundingMode
.
HALF_EVEN
);
DcAutoJitTagMapper
dcAutoJitTagMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcAutoJitTagMapper
.
class
);
List
<
DcAutoJitTag
>
dcAutoJitTags
=
dcAutoJitTagMapper
.
selectByExample
(
DcAutoJitTagExample
.
newAndCreateCriteria
().
example
());
BigDecimal
saveDays
=
BigDecimal
.
ZERO
;
for
(
DcAutoJitTag
dcAutoJitTag
:
dcAutoJitTags
)
{
if
(
dcAutoJitTag
.
getEnable7
()
==
1
)
{
switch
(
dcAutoJitTag
.
getIsGt7
()){
case
1
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
1
)
{
break
;
}
else
{
continue
;
}
case
2
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
0
)
{
break
;
}
else
{
continue
;
}
case
3
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
==
-
1
)
{
break
;
}
else
{
continue
;
}
case
4
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
>
-
1
)
{
break
;
}
else
{
continue
;
}
case
5
:
if
(
avgHistorySevendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales7
())
<
1
)
{
break
;
}
else
{
continue
;
}
default
:
continue
;
}
}
if
(
dcAutoJitTag
.
getEnable14
()
==
1
)
{
switch
(
dcAutoJitTag
.
getIsGt14
()){
case
1
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
1
)
{
break
;
}
else
{
continue
;
}
case
2
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
0
)
{
break
;
}
else
{
continue
;
}
case
3
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
==
-
1
)
{
break
;
}
else
{
continue
;
}
case
4
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
>
-
1
)
{
break
;
}
else
{
continue
;
}
case
5
:
if
(
avgHistoryFourteendaySales
.
compareTo
(
dcAutoJitTag
.
getQuantitySales14
())
<
1
)
{
break
;
}
else
{
continue
;
}
default
:
continue
;
}
}
saveDays
=
dcAutoJitTag
.
getQuantitySafeInventory
();
if
(
"weightingAvgSales"
.
equals
(
autoForecastDay
))
{
DcAutoJitTagLogMapper
dcAutoJitTagLogMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcAutoJitTagLogMapper
.
class
);
DcAutoJitTagLog
dcAutoJitTagLog
=
new
DcAutoJitTagLog
();
dcAutoJitTagLog
.
setBailunSku
(
bailunSku
);
dcAutoJitTagLog
.
setDate
(
LocalDate
.
now
());
dcAutoJitTagLog
.
setQuantitySales7
(
avgHistorySevendaySales
);
dcAutoJitTagLog
.
setQuantitySales14
(
avgHistoryFourteendaySales
);
dcAutoJitTagLog
.
setTagId
(
dcAutoJitTag
.
getId
());
dcAutoJitTagLog
.
setTagJson
(
JSONObject
.
toJSONString
(
dcAutoJitTag
));
dcAutoJitTagLogMapper
.
upsertSelective
(
dcAutoJitTagLog
);
dcAutoTurnover
.
setTagId
(
dcAutoJitTag
.
getId
());
}
break
;
}
return
saveDays
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment