Commit 54783cd5 by 杨林龙

优化定时任务 一次性统计并插入数据

1 parent e0939393
...@@ -2,16 +2,12 @@ package cn.com.glsx.schedulerjob.task.modules.service; ...@@ -2,16 +2,12 @@ package cn.com.glsx.schedulerjob.task.modules.service;
import cn.com.glsx.stdinterface.api.StatisticsDriveClient; import cn.com.glsx.stdinterface.api.StatisticsDriveClient;
import cn.com.glsx.stdinterface.dto.StatisticsDriveDto; import com.alibaba.fastjson.JSON;
import cn.hutool.core.collection.CollectionUtil;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author liuyf * @author liuyf
* @date 2021年01月26日 下午2:37:40 * @date 2021年01月26日 下午2:37:40
...@@ -23,39 +19,9 @@ public class MySimpleJobService { ...@@ -23,39 +19,9 @@ public class MySimpleJobService {
@Autowired @Autowired
private StatisticsDriveClient statisticsDriveClient; private StatisticsDriveClient statisticsDriveClient;
// 分批处理流程
private static final int BATCH_COUNT = 100;
public void statisticsDriveDataEveryDay() { public void statisticsDriveDataEveryDay() {
log.info("开始统计数据==="); log.info("开始统计并插入统计数据===");
R statisticsDriveR = statisticsDriveClient.statisticsDriveDataEveryDay(); R statisticsR = statisticsDriveClient.statisticsAndInsertDriveDataEveryDay();
if (statisticsDriveR == null) { log.info("统计的返回结果===" + JSON.toJSONString(statisticsR));
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);
}
} }
} }
...@@ -3,7 +3,9 @@ spring.application.name=ne-shield-task-scheduler ...@@ -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 #\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 logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
#nacos\u914D\u7F6E\u4E2D\u5FC3 #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} #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 #\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 spring.cloud.nacos.config.group=NESHIELD_DEV_GROUP
...@@ -22,4 +24,6 @@ spring.cloud.nacos.config.shared-configs[0].refresh=true ...@@ -22,4 +24,6 @@ spring.cloud.nacos.config.shared-configs[0].refresh=true
#\u6570\u636E\u5E93\u3001redis\u7B49\u516C\u5171\u914D\u7F6E #\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].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].data-id=glsx-ne-shield-share-dev.properties
spring.cloud.nacos.config.shared-configs[1].refresh=true
\ No newline at end of file \ 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 \ No newline at end of file
...@@ -35,9 +35,16 @@ class MySimpleJobServiceTest { ...@@ -35,9 +35,16 @@ class MySimpleJobServiceTest {
} }
@Test @Test
public void test02(){ public void test02() {
int size = 623 / 100; int size = 623 / 100;
System.out.println("size = " + size); 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 \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!