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
39892e90
Commit
39892e90
authored
Aug 14, 2020
by
huluobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
销量预测公式
parent
18e212c5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
91 additions
and
31 deletions
+91
-31
SyncCostFirstJob.java
...rst/src/main/java/com/bailuntec/job/SyncCostFirstJob.java
+48
-19
job.properties
...se/base-sync-cost-first/src/main/resources/job.properties
+5
-6
SyncCostFirstTest.java
...base-sync-cost-first/src/test/java/SyncCostFirstTest.java
+3
-3
DcAutoTurnover.java
...main/java/com/bailuntec/domain/entity/DcAutoTurnover.java
+0
-0
AutoTurnoverJob.java
...over/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
+0
-0
AutoSalesServiceImpl.java
...java/com/bailuntec/service/impl/AutoSalesServiceImpl.java
+2
-2
AutoTurnoverServiceImpl.java
...a/com/bailuntec/service/impl/AutoTurnoverServiceImpl.java
+32
-1
AutoTurnoverServiceImplTest.java
...m/bailuntec/service/impl/AutoTurnoverServiceImplTest.java
+1
-0
No files found.
data-base/base-sync-cost-first/src/main/java/com/bailuntec/job/SyncCostFirstJob.java
View file @
39892e90
...
...
@@ -14,6 +14,8 @@ import com.bailuntec.utils.OkHttpUtil;
import
com.bailuntec.utils.PropertiesUtil
;
import
com.bailuntec.utils.SessionUtil
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.google.gson.Gson
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
...
...
@@ -27,6 +29,7 @@ import java.time.format.DateTimeFormatter;
import
java.util.HashMap
;
import
java.util.List
;
@Slf4j
public
class
SyncCostFirstJob
extends
PointJob
{
private
PropertiesUtil
propertiesUtil
=
PropertiesUtil
.
getInstance
(
"const"
);
...
...
@@ -46,43 +49,59 @@ public class SyncCostFirstJob extends PointJob {
.
addHeader
(
"cache-control"
,
"no-cache"
)
.
build
();
Response
response
=
null
;
String
result
;
try
{
log
.
info
(
"调用头程费用接口 starting"
);
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
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"调用头程费接口失败"
,
e
);
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
"调用头程费接口失败,param:{}"
,
new
Gson
().
toJson
(
map
));
}
finally
{
if
(
response
!=
null
)
{
response
.
close
();
}
}
if
(
StringUtils
.
isNotBlank
(
result
))
{
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"
);
}
log
.
info
(
"调用头程费用接口 end"
);
jobPointLog
.
setPageIndex
(
jobPointLog
.
getPageIndex
()
+
1
);
if
(
jobPointLog
.
getPageIndex
()
%
8
==
0
)
{
JobPointLogMapper
mapper
=
SessionUtil
.
getSession
().
getMapper
(
JobPointLogMapper
.
class
);
mapper
.
upsertSelective
(
jobPointLog
);
}
}
while
(
jobPointLog
.
getPageIndex
()
<=
totalPage
);
jobPointLog
.
setPageIndex
(
1
);
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
)
{
try
{
DcBaseCostFirstMapper
baseCostFirstMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcBaseCostFirstMapper
.
class
);
for
(
CostFirstData
costFirstData
:
costFirstDataList
)
{
//将费用处理一下, 给过来的数据很长的小数
//将费用处理一下, 给过来的数据很长的小数
costFirstDataList
.
forEach
(
costFirstData
->
{
costFirstData
.
setCostDuty
(
costFirstData
.
getCostDuty
().
setScale
(
3
,
RoundingMode
.
HALF_EVEN
));
costFirstData
.
setCostCustomsClearance
(
costFirstData
.
getCostCustomsClearance
().
setScale
(
3
,
RoundingMode
.
HALF_EVEN
));
costFirstData
.
setCostGoodsClearance
(
costFirstData
.
getCostGoodsClearance
().
setScale
(
3
,
RoundingMode
.
HALF_EVEN
));
...
...
@@ -101,16 +120,26 @@ public class SyncCostFirstJob extends PointJob {
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
()))
{
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
)
{
baseCostFirstMapper
.
upsertSelective
(
dcBaseCostFirst
);
log
.
info
(
"百伦头程费信息, 是WMS根据线路估算而来 新增同步成功 "
);
}
else
{
log
.
info
(
"百伦头程费信息, 是WMS根据线路估算而来 更新同步成功 "
);
}
}
}
}
}
}
);
}
catch
(
RuntimeException
e
)
{
throw
new
RuntimeException
(
"MYBATIS操作DB更新插入数据失败"
,
e
);
// throw new RuntimeException("MYBATIS操作DB更新插入数据失败", e);
log
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
SessionUtil
.
closeSession
();
}
...
...
data-base/base-sync-cost-first/src/main/resources/job.properties
View file @
39892e90
#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_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_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_PASSWORD
=
#7kfnymAM$Y9-Ntf
ZOOKEEPER_SERVER=172.31.255.120:2181
#
ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center
JOB_NAME
=
base-sync-cost-first
JOB_CRON
=
0 10 0/1 * * ? *
SHARDING_TOTAL_COUNT
=
1
\ No newline at end of file
SHARDING_TOTAL_COUNT
=
1
data-base/base-sync-cost-first/src/test/java/SyncCostFirstTest.java
View file @
39892e90
...
...
@@ -9,9 +9,9 @@ public class SyncCostFirstTest {
@Test
public
void
test
()
{
SyncCostFirstJob
syncCostFirstJob
=
new
SyncCostFirstJob
();
JobPointLog
jobPointLog
=
new
JobPointLog
(
"base-sync-cost-first"
,
1
,
1
,
1
,
1
,
LocalDateTime
.
of
(
2020
,
8
,
11
,
0
,
3
,
22
),
LocalDateTime
.
of
(
2020
,
8
,
1
2
,
16
,
3
,
22
));
JobPointLog
jobPointLog
=
new
JobPointLog
(
"base-sync-cost-first"
,
1
01
,
1
,
1
,
1
,
LocalDateTime
.
of
(
2020
,
5
,
1
,
0
,
0
,
0
),
LocalDateTime
.
of
(
2020
,
8
,
1
4
,
9
,
0
,
0
));
syncCostFirstJob
.
executeJob
(
null
,
jobPointLog
);
}
}
data-common/src/main/java/com/bailuntec/domain/entity/DcAutoTurnover.java
View file @
39892e90
This diff is collapsed.
Click to expand it.
data-show/show-auto-turnover/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
View file @
39892e90
This diff is collapsed.
Click to expand it.
data-show/show-auto-turnover/src/main/java/com/bailuntec/service/impl/AutoSalesServiceImpl.java
View file @
39892e90
...
...
@@ -56,9 +56,9 @@ public class AutoSalesServiceImpl implements AutoSalesService {
dcAutoSales
.
setBVariable
(
beta
);
dcAutoSales
.
setRVariable
(
r2
);
dcAutoSales
.
setForecastFormula
(
formula
);
BeanUtils
.
copyProperties
(
dcAutoSales
,
salesVolumeDTO
);
BeanUtils
.
copyProperties
(
dcAutoSales
,
salesVolumeDTO
);
//将历史销量详细,存入销量表
dcAutoSales
.
setHistorySalesDetails
(
"["
+
historySales
+
"]"
);
dcAutoSales
.
setHistorySalesDetails
(
"["
+
historySales
+
"]"
);
dcAutoSales
.
setAverageSales
(
avgSales
);
/*
* 根据不同的历史销量和趋势选择不同的预测算法
...
...
data-show/show-auto-turnover/src/main/java/com/bailuntec/service/impl/AutoTurnoverServiceImpl.java
View file @
39892e90
...
...
@@ -8,6 +8,7 @@ import com.bailuntec.mapper.DcBaseOmsSkuMapper;
import
com.bailuntec.service.AutoTurnoverService
;
import
com.bailuntec.utils.SessionUtil
;
import
com.google.gson.Gson
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.ibatis.session.SqlSession
;
import
java.math.BigDecimal
;
...
...
@@ -53,6 +54,8 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
String
warehouseCode
=
dcAutoTurnover
.
getWarehouseCode
();
Queue
<
BigDecimal
>
forecastSalesDetails
=
new
LinkedList
<>();
//销量公式
Queue
<
String
>
forecastSalesDetailsFormula
=
new
LinkedList
<>();
//获取过去7天的销量
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 {
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
);
if
(
dcAutoSalesForecastStageConfig
!=
null
)
{
int
duration1
=
BigDecimal
.
valueOf
(
turnoverDays
).
multiply
(
dcAutoSalesForecastStageConfig
.
getOneRatio
()).
intValue
();
...
...
@@ -88,6 +99,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for
(
int
i
=
0
;
i
<
duration1
;
i
++)
{
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 {
for
(
int
i
=
0
;
i
<
duration2
;
i
++)
{
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 {
for
(
int
i
=
0
;
i
<
duration3
;
i
++)
{
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
.
setSalesDetailsFormula
(
new
Gson
().
toJson
(
forecastSalesDetailsFormula
));
// dcAutoTurnoverMapper.updateByPrimaryKey(dcAutoTurnover);
}
else
{
for
(
int
i
=
0
;
i
<
turnoverDays
;
i
++)
{
forecastSalesDetails
.
offer
(
dcAutoTurnover
.
getDailyWeightedSales
())
forecastSalesDetails
.
offer
(
dcAutoTurnover
.
getDailyWeightedSales
())
;
}
}
...
...
data-show/show-auto-turnover/src/test/java/com/bailuntec/service/impl/AutoTurnoverServiceImplTest.java
View file @
39892e90
...
...
@@ -29,6 +29,7 @@ class AutoTurnoverServiceImplTest {
DcAutoTurnover
dcAutoTurnover
=
dcAutoTurnoverMapper
.
selectByPrimaryKey
(
58845
);
autoTurnoverService
.
setAutoTurnoverSaleDetails
(
dcAutoTurnover
);
System
.
out
.
println
(
dcAutoTurnover
.
getSalesDetails
());
System
.
out
.
println
(
dcAutoTurnover
.
getSalesDetailsFormula
());
}
finally
{
SessionUtil
.
closeSession
();
}
...
...
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