oralce同步到influxDB
This commit is contained in:
@@ -21,5 +21,7 @@ public class DataAsynParam {
|
||||
//指标名,对应表映射后的实体名
|
||||
private List<String> tableNames;
|
||||
|
||||
//执行同步数据类型1:重网页端,2跑批处理
|
||||
private Integer excuteType=1;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.njcn.oracle.bo.param;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -11,6 +14,7 @@ import java.util.stream.Collectors;
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Getter
|
||||
public enum ServiceTypeEnum {
|
||||
DATAFLICKER("DataFlicker","电压闪变数据表"),
|
||||
DATAFLUC("DataFluc","电压波动数据表"),
|
||||
|
||||
@@ -16,8 +16,8 @@ public class LocalDateUtil {
|
||||
public static List<LocalDate> getDateList(LocalDate startDate, LocalDate endDate) {
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
|
||||
dateList.add(startDate);
|
||||
for (long i = 1; i < daysBetween; i++) {
|
||||
|
||||
for (long i = 0; i <= daysBetween; i++) {
|
||||
dateList.add(startDate.plusDays(i));
|
||||
}
|
||||
return dateList;
|
||||
|
||||
@@ -45,6 +45,7 @@ public class OracleToOralceJob {
|
||||
private String endtime;
|
||||
|
||||
@Scheduled(cron="0 5 0 * * ?")
|
||||
// @Scheduled(fixedDelay=3000000)
|
||||
public void execute() {
|
||||
QueryWrapper<JobHistoryLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("max(LAST_DATE) as LAST_DATE");
|
||||
@@ -53,11 +54,13 @@ public class OracleToOralceJob {
|
||||
JobHistoryLog one = jobHistoryLogService.getBaseMapper().selectOne(queryWrapper);
|
||||
if (Objects.isNull(one)){
|
||||
startDate =LocalDate.parse(startime);
|
||||
|
||||
}else {
|
||||
startDate = one.getLastDate();
|
||||
startDate = startDate.plusDays(1);
|
||||
}
|
||||
//获取配置的endtime。现在时间减1天,开始时间+时间间隔最小值当enddate
|
||||
List<LocalDate> dates = Arrays.asList(LocalDate.parse(endtime), LocalDate.now().plusDays(-1), startDate.plusDays(slice));
|
||||
List<LocalDate> dates = Arrays.asList(LocalDate.parse(endtime), LocalDate.now().plusDays(-1), startDate.plusDays(slice-1));
|
||||
|
||||
endDate = dates.stream().min(LocalDate::compareTo).get();
|
||||
|
||||
@@ -66,8 +69,8 @@ public class OracleToOralceJob {
|
||||
dataAsynParam.setStartTime(startDate);
|
||||
dataAsynParam.setEndTime(endDate);
|
||||
dataAsynParam.setTableNames(ServiceTypeEnum.getExecutableTypes());
|
||||
dataAsynParam.setExcuteType(2);
|
||||
oracleService.dataBacthSysc(dataAsynParam);
|
||||
jobHistoryLogService.save(new JobHistoryLog(endDate, LocalDateTime.now()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,13 @@ import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njcn.oracle.bo.param.DataAsynParam;
|
||||
import com.njcn.oracle.bo.param.MigrationParam;
|
||||
import com.njcn.oracle.bo.param.ServiceTypeEnum;
|
||||
import com.njcn.oracle.bo.po.JobDetail;
|
||||
import com.njcn.oracle.bo.po.JobHistoryLog;
|
||||
import com.njcn.oracle.mybatis.service.IReplenishMybatisService;
|
||||
import com.njcn.oracle.service.IOracleService;
|
||||
import com.njcn.oracle.service.JobDetailService;
|
||||
import com.njcn.oracle.service.JobHistoryLogService;
|
||||
import com.njcn.oracle.util.LocalDateUtil;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -34,6 +37,7 @@ public class OracleServiceImpl implements IOracleService {
|
||||
private final static String PACKAGE_SUFFIX = "ServiceImpl";
|
||||
|
||||
private final JobDetailService jobDetailService;
|
||||
private final JobHistoryLogService jobHistoryLogService;
|
||||
|
||||
@Value("${business.slice:2}")
|
||||
private int slice;
|
||||
@@ -62,6 +66,12 @@ public class OracleServiceImpl implements IOracleService {
|
||||
}
|
||||
List<LocalDate> dateList = LocalDateUtil.getDateList(dataAsynParam.getStartTime(), dataAsynParam.getEndTime());
|
||||
for (LocalDate date : dateList) {
|
||||
|
||||
//添加记录批处理日志,执行为批处理且最后一张表执行完记录
|
||||
if(dataAsynParam.getExcuteType()==2&&Objects.equals(tableName, ServiceTypeEnum.LIMITTARGET.getCode())){
|
||||
JobHistoryLog jobHistoryLog = new JobHistoryLog(date,LocalDateTime.now());
|
||||
jobHistoryLogService.save(jobHistoryLog);
|
||||
}
|
||||
//日志记录
|
||||
JobDetail jobDetail = jobDetailService.select(tableName, date);
|
||||
if (Objects.nonNull(jobDetail) && (jobDetail.getState() == 1 || jobDetail.getState() == 0)) {
|
||||
@@ -122,10 +132,14 @@ public class OracleServiceImpl implements IOracleService {
|
||||
jobDetail.setUpdateTime(LocalDateTime.now());
|
||||
jobDetailService.updateByMultiId(jobDetail);
|
||||
}
|
||||
|
||||
|
||||
System.out.println("执行后总堆内存为:" + runtime.totalMemory() / (1024 * 1024) + " MB");
|
||||
System.out.println("执行后已用堆内存为:" + (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024) + " MB");
|
||||
System.out.println("执行后空闲堆内存为:" + runtime.freeMemory() / (1024 * 1024) + " MB");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -90,5 +90,5 @@ business:
|
||||
job:
|
||||
startime: 2023-01-01
|
||||
endtime: 2023-04-01
|
||||
#每天执行数据量(天数)
|
||||
slice: 1
|
||||
#每天执行数据量(天数)大于1
|
||||
slice: 2
|
||||
|
||||
Reference in New Issue
Block a user