Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-task-scheduler
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 54783cd5
authored
Sep 27, 2021
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化定时任务 一次性统计并插入数据
1 parent
e0939393
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
41 deletions
src/main/java/cn/com/glsx/schedulerjob/task/modules/service/MySimpleJobService.java
src/main/resources/bootstrap.properties
src/test/java/cn/com/glsx/schedulerjob/task/modules/service/MySimpleJobServiceTest.java
src/main/java/cn/com/glsx/schedulerjob/task/modules/service/MySimpleJobService.java
View file @
54783cd
...
...
@@ -2,16 +2,12 @@ package cn.com.glsx.schedulerjob.task.modules.service;
import
cn.com.glsx.stdinterface.api.StatisticsDriveClient
;
import
cn.com.glsx.stdinterface.dto.StatisticsDriveDto
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.core.web.R
;
import
com.google.gson.reflect.TypeToken
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* @author liuyf
* @date 2021年01月26日 下午2:37:40
...
...
@@ -23,39 +19,9 @@ public class MySimpleJobService {
@Autowired
private
StatisticsDriveClient
statisticsDriveClient
;
// 分批处理流程
private
static
final
int
BATCH_COUNT
=
100
;
public
void
statisticsDriveDataEveryDay
()
{
log
.
info
(
"开始统计数据==="
);
R
statisticsDriveR
=
statisticsDriveClient
.
statisticsDriveDataEveryDay
();
if
(
statisticsDriveR
==
null
)
{
log
.
info
(
"statisticsDriveR is null"
);
return
;
}
List
<
StatisticsDriveDto
>
statisticsDriveDtoList
=
(
List
<
StatisticsDriveDto
>)
statisticsDriveR
.
getDataList
(
new
TypeToken
<
List
<
StatisticsDriveDto
>>()
{
}.
getType
());
// 调用标准接口 将数据入库
if
(
CollectionUtil
.
isEmpty
(
statisticsDriveDtoList
))
{
log
.
info
(
"statisticsDriveDtoList is null"
);
return
;
}
log
.
info
(
"开始保存数据===,数据集合的大小为"
+
statisticsDriveDtoList
.
size
());
// 分批保存数据
int
fragSize
=
statisticsDriveDtoList
.
size
()
/
BATCH_COUNT
;
log
.
info
(
"开始分批保存,有"
+
fragSize
+
"个分片==="
);
for
(
int
i
=
0
;
i
<
fragSize
;
i
++)
{
List
<
StatisticsDriveDto
>
fragStatisticsDriveDtoList
;
if
(
i
!=
fragSize
-
1
)
{
fragStatisticsDriveDtoList
=
statisticsDriveDtoList
.
subList
(
i
*
BATCH_COUNT
,
(
i
+
1
)
*
BATCH_COUNT
);
}
else
{
fragStatisticsDriveDtoList
=
statisticsDriveDtoList
.
subList
(
i
*
BATCH_COUNT
,
statisticsDriveDtoList
.
size
());
}
statisticsDriveClient
.
insertStatisticsDriveList
(
fragStatisticsDriveDtoList
);
}
log
.
info
(
"开始统计并插入统计数据==="
);
R
statisticsR
=
statisticsDriveClient
.
statisticsAndInsertDriveDataEveryDay
();
log
.
info
(
"统计的返回结果==="
+
JSON
.
toJSONString
(
statisticsR
));
}
}
src/main/resources/bootstrap.properties
View file @
54783cd
...
...
@@ -3,7 +3,9 @@ spring.application.name=ne-shield-task-scheduler
#\u65E5\u5FD7\u8DEF\u5F84\uFF08logback-spring.xml\u8BFB\u53D6\uFF0C\u4E0D\u8981\u52A0\u5165\u914D\u7F6E\u4E2D\u5FC3\uFF09
logging.path
=
/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
#nacos\u914D\u7F6E\u4E2D\u5FC3
spring.cloud.nacos.config.server-
addr
=
192.168.0.63:8848
spring.cloud.nacos.config.server-
addr
=
192.168.3.206:8848
#\u8054\u8C03\u6D4B\u8BD5\u7684\u65F6\u5019\u4F7F\u7528
#spring.cloud.nacos.config.server-addr=192.168.0.63:8848
#nacos\u914D\u7F6Eid\uFF0C\u5B8C\u6574dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension\uFF08\u7531\u65B0\u589E\u914D\u7F6E\u65F6\u9009\u7684\u6587\u4EF6\u7C7B\u578B\u51B3\u5B9A\uFF09}
#\u793A\u4F8B\uFF1Ahttp://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP
spring.cloud.nacos.config.group
=
NESHIELD_DEV_GROUP
...
...
@@ -22,4 +24,6 @@ spring.cloud.nacos.config.shared-configs[0].refresh=true
#\u6570\u636E\u5E93\u3001redis\u7B49\u516C\u5171\u914D\u7F6E
spring.cloud.nacos.config.shared-configs[1]
.group
=
NESHIELD_DEV_GROUP
spring.cloud.nacos.config.shared-configs[1].data-
id
=
glsx-ne-shield-share-dev.properties
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
\ No newline at end of file
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
spring.main.allow-bean-definition-
overriding
=
true
\ No newline at end of file
src/test/java/cn/com/glsx/schedulerjob/task/modules/service/MySimpleJobServiceTest.java
View file @
54783cd
...
...
@@ -35,9 +35,16 @@ class MySimpleJobServiceTest {
}
@Test
public
void
test02
(){
public
void
test02
()
{
int
size
=
623
/
100
;
System
.
out
.
println
(
"size = "
+
size
);
}
@Test
public
void
test03
()
{
System
.
out
.
println
(
"开始调用 ==== "
+
JSON
.
toJSONString
(
statisticsDriveClient
));
R
statisticsDriveR
=
statisticsDriveClient
.
statisticsAndInsertDriveDataEveryDay
();
System
.
out
.
println
(
"statisticsDriveR = "
+
JSON
.
toJSONString
(
statisticsDriveR
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment