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
huluobin
dc-java
Commits
9fe13f32
Commit
9fe13f32
authored
Apr 01, 2019
by
wutong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动周转修改分片分页,计算时不漏SKU.
parent
e89eca99
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
48 deletions
+58
-48
AutoTurnoverJob.java
...over/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
+21
-41
AutoTurnoverJobListener.java
.../java/com/bailuntec/listener/AutoTurnoverJobListener.java
+4
-2
DcBaseStockMapper.java
...src/main/java/com/bailuntec/mapper/DcBaseStockMapper.java
+4
-0
DcBaseStockMapper.xml
.../src/main/java/com/bailuntec/mapper/DcBaseStockMapper.xml
+5
-0
const.properties
...ow/show-auto-turnover/src/main/resources/const.properties
+3
-2
AutoTurnoverTest.java
...ow/show-auto-turnover/src/test/java/AutoTurnoverTest.java
+21
-3
No files found.
data-show/show-auto-turnover/src/main/java/com/bailuntec/job/AutoTurnoverJob.java
View file @
9fe13f32
...
...
@@ -43,51 +43,20 @@ public class AutoTurnoverJob extends PointJob {
@Override
public
void
executeJob
(
ShardingContext
shardingContext
,
JobPointLog
jobPointLog
)
{
long
count
=
0
;
try
{
DcBaseStockMapper
baseStockMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcBaseStockMapper
.
class
);
count
=
baseStockMapper
.
countByExample
(
DcBaseStockExample
.
newAndCreateCriteria
().
example
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"Mybatis操作DB查询总页数失败"
,
e
);
}
finally
{
SessionUtil
.
closeSession
();
}
long
count
=
getTotalCount
();
int
totalPage
=
getTotalPage
(
count
,
jobPointLog
.
getPageSize
());
switch
(
shardingContext
.
getShardingItem
())
{
case
0
:
if
(
shardingContext
.
getShardingItem
()
+
1
<
shardingContext
.
getShardingTotalCount
())
{
totalPage
=
totalPage
/
shardingContext
.
getShardingTotalCount
()
*
(
shardingContext
.
getShardingItem
()
+
1
);
}
break
;
case
1
:
if
(
shardingContext
.
getShardingItem
()
+
1
<
shardingContext
.
getShardingTotalCount
())
{
totalPage
=
(
totalPage
/
shardingContext
.
getShardingTotalCount
())
*
(
shardingContext
.
getShardingItem
()
+
1
);
}
break
;
case
2
:
if
(
shardingContext
.
getShardingItem
()
+
1
<
shardingContext
.
getShardingTotalCount
())
{
totalPage
=
(
totalPage
/
shardingContext
.
getShardingTotalCount
())
*
(
shardingContext
.
getShardingItem
()
+
1
);
}
break
;
case
3
:
break
;
/*
* 根据不同分片
* 再分页去处理数据
*/
int
shardingSize
=
totalPage
%
shardingContext
.
getShardingTotalCount
()
==
0
?
totalPage
/
shardingContext
.
getShardingTotalCount
()
:
totalPage
/
shardingContext
.
getShardingTotalCount
()
+
1
;
if
(
shardingContext
.
getShardingItem
()
+
1
<
shardingContext
.
getShardingTotalCount
())
{
totalPage
=
shardingSize
*
(
shardingContext
.
getShardingItem
()
+
1
);
}
if
(
totalPage
>
0
)
{
int
page
=
0
;
switch
(
shardingContext
.
getShardingItem
())
{
case
0
:
break
;
case
1
:
page
=
totalPage
/
shardingContext
.
getShardingTotalCount
()
*
shardingContext
.
getShardingItem
();
break
;
case
2
:
page
=
(
totalPage
/
shardingContext
.
getShardingTotalCount
())
*
shardingContext
.
getShardingItem
();
break
;
case
3
:
page
=
(
totalPage
/
shardingContext
.
getShardingTotalCount
())
*
shardingContext
.
getShardingItem
();
break
;
if
(
shardingContext
.
getShardingItem
()
>
0
)
{
page
=
shardingSize
*
shardingContext
.
getShardingItem
();
}
String
queryTime
=
DateTimeFormatter
.
ofPattern
(
CommonConstant
.
DATE_FORMAT
).
format
(
LocalDate
.
now
());
do
{
...
...
@@ -125,6 +94,17 @@ public class AutoTurnoverJob extends PointJob {
}
private
long
getTotalCount
()
{
try
{
DcBaseStockMapper
baseStockMapper
=
SessionUtil
.
getSession
().
getMapper
(
DcBaseStockMapper
.
class
);
return
baseStockMapper
.
countByExample
(
DcBaseStockExample
.
newAndCreateCriteria
().
example
());
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Mybatis操作DB查询总页数失败"
,
e
);
}
finally
{
SessionUtil
.
closeSession
();
}
}
/**
* 基于库存
* 计算自动周转
...
...
data-show/show-auto-turnover/src/main/java/com/bailuntec/listener/AutoTurnoverJobListener.java
View file @
9fe13f32
...
...
@@ -12,12 +12,14 @@ import com.bailuntec.mapper.DcBaseStockMapper;
import
com.bailuntec.utils.SessionUtil
;
import
com.dangdang.ddframe.job.executor.ShardingContexts
;
import
com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.session.SqlSession
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
@Slf4j
public
class
AutoTurnoverJobListener
implements
ElasticJobListener
{
@Override
public
void
beforeJobExecuted
(
ShardingContexts
shardingContexts
)
{
...
...
@@ -57,7 +59,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
try
{
autoTurnoverJob
.
autoTurnoverFromStock
(
queryTime
,
dcBaseStock
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Mybatis操作自动周转异常数据再次计算失败SKU="
+
dcAutoException
.
getBailunSku
()
+
",仓库编码="
+
dcAutoException
.
getWarehouseCode
(),
e
);
log
.
error
(
"Mybatis操作自动周转异常数据再次计算失败SKU="
+
dcAutoException
.
getBailunSku
()
+
",仓库编码="
+
dcAutoException
.
getWarehouseCode
()
);
}
mapper
.
deleteByPrimaryKey
(
dcAutoException
.
getId
());
}
...
...
@@ -65,7 +67,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
pageIndex
++;
}
while
(
dcAutoExceptions
!=
null
&&
dcAutoExceptions
.
size
()
==
pageSize
);
}
catch
(
RuntimeException
e
)
{
throw
new
RuntimeException
(
"Mybatis操作自动周转异常数据再次计算失败"
,
e
);
throw
new
RuntimeException
(
"Mybatis操作自动周转异常数据再次计算失败"
);
}
finally
{
if
(
sqlSession
!=
null
)
{
sqlSession
.
close
();
...
...
data-show/show-auto-turnover/src/main/java/com/bailuntec/mapper/DcBaseStockMapper.java
View file @
9fe13f32
...
...
@@ -125,4 +125,7 @@ public interface DcBaseStockMapper {
List
<
DcBaseStock
>
listNoChinaWarehouse
(
@Param
(
"v1"
)
int
v1
,
@Param
(
"v2"
)
int
v2
);
List
<
DcBaseStock
>
listOrderByFba
(
@Param
(
"v1"
)
int
v1
,
@Param
(
"v2"
)
int
v2
);
List
<
DcBaseStock
>
listInStockNotInAutoTurnover
();
}
\ No newline at end of file
data-show/show-auto-turnover/src/main/java/com/bailuntec/mapper/DcBaseStockMapper.xml
View file @
9fe13f32
...
...
@@ -1092,4 +1092,8 @@
<select
id=
"listOrderByFba"
resultType=
"com.bailuntec.domain.entity.DcBaseStock"
>
SELECT * FROM dc_base_stock order by id asc limit #{v1}, #{v2}
</select>
<select
id=
"listInStockNotInAutoTurnover"
resultType=
"com.bailuntec.domain.entity.DcBaseStock"
>
SELECT tb1.* FROM dc_base_stock tb1 LEFT JOIN dc_auto_turnover tb2 ON tb1.bailun_sku = tb2.bailun_sku and tb1.warehouse_code = tb2.warehouse_code WHERE tb2.bailun_sku is null;
</select>
</mapper>
\ No newline at end of file
data-show/show-auto-turnover/src/main/resources/const.properties
View file @
9fe13f32
SKUMS_PARENT_CATEGORIES_URL
=
http://10.0.6.13:8001/api/BailunCateData/GetMyParentCategories
#
SKUMS_PARENT_CATEGORIES_URL=http://api.sku.bailuntec.com/api/BailunCateData/GetMyParentCategories
#
SKUMS_PARENT_CATEGORIES_URL=http://10.0.6.13:8001/api/BailunCateData/GetMyParentCategories
SKUMS_PARENT_CATEGORIES_URL
=
http://api.sku.bailuntec.com/api/BailunCateData/GetMyParentCategories
TJ_OUT_STOCK_URL
=
http://tj.bailuntec.com/ApiService/GetNoStockForDataCenter
\ No newline at end of file
data-show/show-auto-turnover/src/test/java/AutoTurnoverTest.java
View file @
9fe13f32
...
...
@@ -50,7 +50,7 @@ public class AutoTurnoverTest {
try
{
DcBaseStockMapper
mapper
=
SessionUtil
.
getSession
().
getMapper
(
DcBaseStockMapper
.
class
);
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("322572421").andWarehouseCodeEqualTo("QYBLZZ").example());
dcBaseStock
=
mapper
.
selectOneByExample
(
DcBaseStockExample
.
newAndCreateCriteria
().
andBailunSkuEqualTo
(
"27
3129601"
).
andWarehouseCodeEqualTo
(
"GZBLWH
"
).
example
());
dcBaseStock
=
mapper
.
selectOneByExample
(
DcBaseStockExample
.
newAndCreateCriteria
().
andBailunSkuEqualTo
(
"27
8308409"
).
andWarehouseCodeEqualTo
(
"GZBLYS
"
).
example
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
@@ -58,6 +58,24 @@ public class AutoTurnoverTest {
}
autoTurnoverJob
.
autoTurnoverFromStock
(
queryTime
,
dcBaseStock
);
}
@Test
public
void
test22
()
throws
Exception
{
String
queryTime
=
DateTimeFormatter
.
ofPattern
(
CommonConstant
.
DATE_FORMAT
).
format
(
LocalDate
.
now
());
AutoTurnoverJob
autoTurnoverJob
=
new
AutoTurnoverJob
();
List
<
DcBaseStock
>
dcBaseStockList
=
null
;
try
{
DcBaseStockMapper
mapper
=
SessionUtil
.
getSession
().
getMapper
(
DcBaseStockMapper
.
class
);
dcBaseStockList
=
mapper
.
listInStockNotInAutoTurnover
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
SessionUtil
.
closeSession
();
}
for
(
DcBaseStock
dcBaseStock
:
dcBaseStockList
)
{
autoTurnoverJob
.
autoTurnoverFromStock
(
queryTime
,
dcBaseStock
);
}
}
@Test
public
void
test3
()
throws
Exception
{
String
queryTime
=
DateTimeFormatter
.
ofPattern
(
CommonConstant
.
DATE_FORMAT
).
format
(
LocalDate
.
now
());
...
...
@@ -80,8 +98,8 @@ public class AutoTurnoverTest {
AutoTurnoverJob
autoTurnoverJob
=
new
AutoTurnoverJob
();
HashMap
<
Integer
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
1
,
""
);
ShardingContext
shardingContext
=
new
ShardingContext
(
new
ShardingContexts
(
""
,
""
,
1
,
""
,
map
),
0
);
JobPointLog
jobPointLog
=
new
JobPointLog
(
""
,
1
,
1
,
1
,
1
,
LocalDateTime
.
now
().
minusSeconds
(
1
),
LocalDateTime
.
now
());
ShardingContext
shardingContext
=
new
ShardingContext
(
new
ShardingContexts
(
""
,
""
,
4
,
""
,
map
),
3
);
JobPointLog
jobPointLog
=
new
JobPointLog
(
""
,
1
,
2000
,
1
,
1
,
LocalDateTime
.
now
().
minusSeconds
(
1
),
LocalDateTime
.
now
());
autoTurnoverJob
.
executeJob
(
shardingContext
,
jobPointLog
);
}
...
...
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