oralce同步到influxDB
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.njcn.influx.job;
|
||||
|
||||
import com.njcn.influx.bo.param.TableEnum;
|
||||
import com.njcn.influx.service.OracleToInfluxDBService;
|
||||
import com.njcn.oracle.bo.param.DataAsynParam;
|
||||
import com.njcn.oracle.bo.param.ServiceTypeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/1/18 10:15【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Component
|
||||
@EnableScheduling
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class OracleToInfluxDBJob {
|
||||
|
||||
|
||||
private final OracleToInfluxDBService oracleToInfluxDBService;
|
||||
@Scheduled(cron="0 0 1 * * ?")
|
||||
public void execute() {
|
||||
DataAsynParam dataAsynParam = new DataAsynParam();
|
||||
dataAsynParam.setStartTime(LocalDate.now().plusDays(-1));
|
||||
dataAsynParam.setEndTime(LocalDate.now().plusDays(-1));
|
||||
dataAsynParam.setTableNames(TableEnum.getExecutableTypes());
|
||||
oracleToInfluxDBService.dataBacthSysc(dataAsynParam);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.oracle.bo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2024/1/18 11:11【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@TableName(value = "JOB_HISTORY_LOG")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class JobHistoryLog {
|
||||
/**
|
||||
* 执行日期
|
||||
*/
|
||||
@TableId(value = "LAST_DATE", type = IdType.INPUT)
|
||||
private LocalDate lastDate;
|
||||
|
||||
@TableField(value = "UPDATE_TIME")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.oracle.mybatis.mapper.JobHistoryLogMapper">
|
||||
<resultMap id="BaseResultMap" type="com.njcn.oracle.bo.po.JobHistoryLog">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table JOB_HISTORY_LOG-->
|
||||
<id column="LAST_DATE" jdbcType="TIMESTAMP" property="lastDate" />
|
||||
<result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
LAST_DATE, UPDATE_TIME
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.njcn.oracle.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.oracle.bo.po.JobHistoryLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2024/1/18 11:11【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface JobHistoryLogMapper extends BaseMapper<JobHistoryLog> {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.oracle.service;
|
||||
|
||||
import com.njcn.oracle.bo.po.JobHistoryLog;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2024/1/18 11:11【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface JobHistoryLogService extends IService<JobHistoryLog>{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.oracle.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.oracle.bo.po.JobHistoryLog;
|
||||
import com.njcn.oracle.mybatis.mapper.JobHistoryLogMapper;
|
||||
import com.njcn.oracle.service.JobHistoryLogService;
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2024/1/18 11:11【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Service
|
||||
public class JobHistoryLogServiceImpl extends ServiceImpl<JobHistoryLogMapper, JobHistoryLog> implements JobHistoryLogService{
|
||||
|
||||
}
|
||||
@@ -16,9 +16,12 @@ public class LocalDateUtil {
|
||||
public static List<LocalDate> getDateList(LocalDate startDate, LocalDate endDate) {
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
|
||||
for (long i = 0; i <= daysBetween; i++) {
|
||||
dateList.add(startDate);
|
||||
for (long i = 1; i < daysBetween; i++) {
|
||||
dateList.add(startDate.plusDays(i));
|
||||
}
|
||||
return dateList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.njcn.oracle.job;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.njcn.oracle.bo.param.DataAsynParam;
|
||||
import com.njcn.oracle.bo.param.ServiceTypeEnum;
|
||||
import com.njcn.oracle.bo.po.JobHistoryLog;
|
||||
import com.njcn.oracle.service.IOracleService;
|
||||
import com.njcn.oracle.service.JobHistoryLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/1/18 10:08【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class OracleToOralceJob {
|
||||
private final IOracleService oracleService;
|
||||
|
||||
private final JobHistoryLogService jobHistoryLogService;
|
||||
|
||||
@Value("${job.slice:3}")
|
||||
private int slice;
|
||||
@Value("${job.startime}")
|
||||
private String startime;
|
||||
@Value("${job.endtime}")
|
||||
private String endtime;
|
||||
|
||||
@Scheduled(cron="0 5 0 * * ?")
|
||||
public void execute() {
|
||||
QueryWrapper<JobHistoryLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("max(LAST_DATE) as LAST_DATE");
|
||||
LocalDate startDate ;
|
||||
LocalDate endDate ;
|
||||
JobHistoryLog one = jobHistoryLogService.getBaseMapper().selectOne(queryWrapper);
|
||||
if (Objects.isNull(one)){
|
||||
startDate =LocalDate.parse(startime);
|
||||
}else {
|
||||
startDate = one.getLastDate();
|
||||
}
|
||||
//获取配置的endtime。现在时间减1天,开始时间+时间间隔最小值当enddate
|
||||
List<LocalDate> dates = Arrays.asList(LocalDate.parse(endtime), LocalDate.now().plusDays(-1), startDate.plusDays(slice));
|
||||
|
||||
endDate = dates.stream().min(LocalDate::compareTo).get();
|
||||
|
||||
|
||||
DataAsynParam dataAsynParam = new DataAsynParam();
|
||||
dataAsynParam.setStartTime(startDate);
|
||||
dataAsynParam.setEndTime(endDate);
|
||||
dataAsynParam.setTableNames(ServiceTypeEnum.getExecutableTypes());
|
||||
oracleService.dataBacthSysc(dataAsynParam);
|
||||
jobHistoryLogService.save(new JobHistoryLog(endDate, LocalDateTime.now()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,8 +62,8 @@ spring:
|
||||
driver-class-name: oracle.jdbc.driver.OracleDriver
|
||||
target:
|
||||
url: jdbc:oracle:thin:@192.168.1.51:1521:pqsbase
|
||||
username: pqsadmin_hn
|
||||
password: pqsadmin
|
||||
username: pqsadmin
|
||||
password: Pqsadmin123
|
||||
driver-class-name: oracle.jdbc.driver.OracleDriver
|
||||
#mybatis配置信息
|
||||
mybatis-plus:
|
||||
@@ -86,3 +86,9 @@ mybatis-plus:
|
||||
business:
|
||||
slice: 4
|
||||
|
||||
#配置job相关参数
|
||||
job:
|
||||
startime: 2023-01-01
|
||||
endtime: 2023-04-01
|
||||
#每天执行数据量(天数)
|
||||
slice: 1
|
||||
|
||||
Reference in New Issue
Block a user