package com.aegonthtf.fate.service.batch;
import com.aegonthtf.fate.constant.BatchConvertEnum;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.util.exception.SZException;
import com.alibaba.fastjson.JSON;
import org.joda.time.LocalDateTime;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
@Configuration
public abstract class AbsExportBatchJob {
@Autowired
public JobLauncher jobLauncher;
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
public JobBuilderFactory getJobBuilderFactory() {
return this.jobBuilderFactory;
}
public StepBuilderFactory getStepBuilderFactory() {
return this.stepBuilderFactory;
}
@Async("behaviorTaskExecutor")
public void asyncStart(JobBehaviorParamesDto jobParameters, BatchConvertEnum batchConvertEnum) {
try {
jobLauncher.run(this.itemReaderFromDBJob(jobParameters.getStaratDateTime(), batchConvertEnum),
new JobParametersBuilder()
.addString(CommonConstant.JOB_PARAMETERS, JSON.toJSONString(jobParameters))
.toJobParameters());
} catch (Exception e) {
e.printStackTrace();
}
}
public Job itemReaderFromDBJob(LocalDateTime staratDateTime, BatchConvertEnum batchConvertEnum) {
switch (batchConvertEnum) {
case ATH_ACT_EXPORT:
return this.athActExportSub(staratDateTime, batchConvertEnum);
case ESALES_ACT_EXPORT:
return this.esalesActExportSub(staratDateTime, batchConvertEnum);
case TU_D_SUBMISSION_DAILY:
break;
case APOLLO_ACT_EXPORT:
break;
}
throw new SZException("该Job启动器不存在!");
}
protected abstract Job athActExportSub(LocalDateTime staratDateTime, BatchConvertEnum batchConvertEnum);
protected abstract Job esalesActExportSub(LocalDateTime staratDateTime, BatchConvertEnum batchConvertEnum);
}
package com.aegonthtf.fate.service.batch;
import com.aegonthtf.fate.constant.BatchConvertEnum;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.entity.behavior.AthActExport;
import com.aegonthtf.fate.entity.behavior.EsalesActExport;
import com.aegonthtf.fate.entity.user.FateSalesAct;
import com.aegonthtf.fate.service.batch.listener.StartJobExecutionListener;
import com.aegonthtf.fate.service.batch.processor.AthActExportItemProcessor;
import com.aegonthtf.fate.service.batch.processor.EsalesActExportItemProcessor;
import com.aegonthtf.fate.service.batch.reader.AthActExportReader;
import com.aegonthtf.fate.service.batch.reader.EaalesActExportReader;
import com.aegonthtf.fate.service.batch.writer.FateSalesActWriter;
import org.joda.time.LocalDateTime;
import org.springframework.batch.core.Job;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ExportBatchRunJob extends AbsExportBatchJob {
@Autowired
private StartJobExecutionListener startJobExecutionListener;
@Autowired
private AthActExportReader athActExportReader;
@Autowired
private AthActExportItemProcessor athActExportItemProcessor;
@Autowired
private EaalesActExportReader eaalesActExportReader;
@Autowired
private EsalesActExportItemProcessor esalesActExportItemProcessor;
@Autowired
private FateSalesActWriter fateSalesActWriter;
@Override
protected Job athActExportSub(LocalDateTime staratDateTime, BatchConvertEnum batchConvertEnum) {
String date = staratDateTime.toString(CommonConstant.yyyyMMddHHmmss);
return this.getJobBuilderFactory().get(batchConvertEnum.getiTableName() + ":Job" + ":" + date)
.start(this.getStepBuilderFactory().get(batchConvertEnum.getiTableName() + ":Step" + date)
.<AthActExport, FateSalesAct>chunk(CommonConstant.BEHAVIOR_BATCH_SIZE)
.reader(athActExportReader.itemReaderFromDB(CommonConstant.NULL))
.processor(athActExportItemProcessor)
.writer(fateSalesActWriter.writer())
.build()
)
.listener(startJobExecutionListener)
.build();
}
@Override
protected Job esalesActExportSub(LocalDateTime staratDateTime, BatchConvertEnum batchConvertEnum) {
String date = staratDateTime.toString(CommonConstant.yyyyMMddHHmmss);
return this.getJobBuilderFactory().get(batchConvertEnum.getiTableName() + ":Job" + ":" + date)
.start(this.getStepBuilderFactory().get(batchConvertEnum.getiTableName() + ":Step" + date)
.<EsalesActExport, FateSalesAct>chunk(CommonConstant.BEHAVIOR_BATCH_SIZE)
.reader(eaalesActExportReader.itemReaderFromDB(CommonConstant.NULL))
.processor(esalesActExportItemProcessor)
.writer(fateSalesActWriter.writer())
.build()
)
.listener(startJobExecutionListener)
.build();
}
}
package com.aegonthtf.fate.service.batch.listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobInstance;
import org.springframework.stereotype.Component;
@Component
public class StartJobExecutionListener implements JobExecutionListener {
private static final Logger logger = LoggerFactory.getLogger(StartJobExecutionListener.class);
@Override
public void beforeJob(JobExecution jobExecution) {
JobInstance jobInstance = jobExecution.getJobInstance();
logger.info("job 开始, JOB_INSTANCE_ID={},JOB_EXECUTION_ID={}, jobName={}, parameters={}", jobInstance.getId(), jobExecution.getId(), jobInstance.getJobName(), jobExecution.getJobParameters());
}
@Override
public void afterJob(JobExecution jobExecution) {
JobInstance jobInstance = jobExecution.getJobInstance();
logger.info("job 结束, JOB_INSTANCE_ID={},JOB_EXECUTION_ID={}, jobName={}, parameters={}", jobInstance.getId(), jobExecution.getId(), jobInstance.getJobName(), jobExecution.getJobParameters());
}
}
package com.aegonthtf.fate.service.batch.reader;
import com.aegonthtf.fate.constant.BatchConvertEnum;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.constant.EventTypeEnum;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.entity.behavior.AthActExport;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.database.JdbcPagingItemReader;
import org.springframework.batch.item.database.Order;
import org.springframework.batch.item.database.PagingQueryProvider;
import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder;
import org.springframework.batch.item.database.support.MySqlPagingQueryProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.util.Date;
@Configuration
public class AthActExportReader {
@Autowired
@Qualifier("ThirdDataSource")
private DataSource dataSource;
private final BatchConvertEnum batchConvertEnum = BatchConvertEnum.ATH_ACT_EXPORT;
@Bean
@StepScope
public JdbcPagingItemReader<AthActExport> itemReaderFromDB(@Value("#{jobParameters[jobParameters]}") String jobParameters) {
JobBehaviorParamesDto paramesDto = JSON.parseObject(jobParameters, JobBehaviorParamesDto.class);
ImmutablePair<Date, Date> createTime = EventTypeEnum.getCreateTime(paramesDto.getStaratDateTime());
return new JdbcPagingItemReaderBuilder<AthActExport>()
.dataSource(dataSource)
.name(batchConvertEnum.getiTableName())
.fetchSize(CommonConstant.BEHAVIOR_BATCH_SIZE)
.parameterValues(ImmutableMap.of(
"delFlag", CommonConstant._1,
"startTime", createTime.left,
"endTime", createTime.right
))
.pageSize(CommonConstant.BEHAVIOR_BATCH_SIZE)
.rowMapper((resultSet, i) -> {
AthActExport entity = new AthActExport();
entity.setId(resultSet.getInt(CommonConstant._1));
entity.setInfoKind(resultSet.getString(CommonConstant._2));
entity.setEventType(resultSet.getString(CommonConstant._3));
entity.setTransId(resultSet.getString(CommonConstant._4));
entity.setTransDate(resultSet.getString(CommonConstant._5));
entity.setTransTime(resultSet.getDate(CommonConstant._6));
entity.setAgentCode(resultSet.getString(CommonConstant._7));
entity.setAgentName(resultSet.getString(CommonConstant._8));
entity.setCustOpenid(resultSet.getString(CommonConstant._9));
entity.setOpenTime(resultSet.getDate(CommonConstant._10));
entity.setSubTime(resultSet.getDate(CommonConstant._11));
entity.setAthId(resultSet.getString(CommonConstant._12));
entity.setCustName(resultSet.getString(CommonConstant._13));
entity.setCustPhone(resultSet.getString(CommonConstant._14));
entity.setCustGender(resultSet.getString(CommonConstant._15));
entity.setInfoTitle(resultSet.getString(CommonConstant._16));
entity.setInfoSource(resultSet.getString(CommonConstant._17));
entity.setCreatetime(resultSet.getDate(CommonConstant._18));
entity.setCreater(resultSet.getString(CommonConstant._19));
entity.setUpdatetime(resultSet.getDate(CommonConstant._20));
entity.setDelFlag(resultSet.getString(CommonConstant._21));
return entity;
}
)
.queryProvider(articleProvider())
.build();
}
private PagingQueryProvider articleProvider() {
MySqlPagingQueryProvider provider = new MySqlPagingQueryProvider();
provider.setSelectClause("ID, INFO_KIND, EVENT_TYPE, TRANS_ID, TRANS_DATE, TRANS_TIME, AGENT_CODE, AGENT_NAME, CUST_OPENID, OPEN_TIME, SUB_TIME, ATH_ID, CUST_NAME, CUST_PHONE, CUST_GENDER, INFO_TITLE, INFO_SOURCE, CREATETIME, CREATER, UPDATETIME, DEL_FLAG");
provider.setFromClause("FROM " + batchConvertEnum.getiTableName());
provider.setWhereClause("DEL_FLAG = :delFlag AND CREATETIME >= :startTime AND CREATETIME < :endTime");
provider.setSortKeys(ImmutableMap.of("ID", Order.ASCENDING));
return provider;
}
}
package com.aegonthtf.fate.service.batch.reader;
import com.aegonthtf.fate.constant.BatchConvertEnum;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.constant.EventTypeEnum;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.entity.behavior.EsalesActExport;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.database.JdbcPagingItemReader;
import org.springframework.batch.item.database.Order;
import org.springframework.batch.item.database.PagingQueryProvider;
import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder;
import org.springframework.batch.item.database.support.MySqlPagingQueryProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.util.Date;
@Configuration
public class EaalesActExportReader {
@Autowired
@Qualifier("ThirdDataSource")
private DataSource dataSource;
private final BatchConvertEnum batchConvertEnum = BatchConvertEnum.ESALES_ACT_EXPORT;
@Bean
@StepScope
public JdbcPagingItemReader<EsalesActExport> itemReaderFromDB(@Value("#{jobParameters[jobParameters]}") String jobParameters) {
JobBehaviorParamesDto paramesDto = JSON.parseObject(jobParameters, JobBehaviorParamesDto.class);
ImmutablePair<Date, Date> createTime = EventTypeEnum.getCreateTime(paramesDto.getStaratDateTime());
return new JdbcPagingItemReaderBuilder<EsalesActExport>()
.dataSource(dataSource)
.name(batchConvertEnum.getiTableName())
.fetchSize(CommonConstant.BEHAVIOR_BATCH_SIZE)
.parameterValues(ImmutableMap.of(
"delFlag", CommonConstant._1,
"startTime", createTime.left,
"endTime", createTime.right
))
.pageSize(CommonConstant.BEHAVIOR_BATCH_SIZE)
.rowMapper((resultSet, i) -> {
EsalesActExport entity = new EsalesActExport();
entity.setId(resultSet.getInt(CommonConstant._1));
entity.setInfoKind(resultSet.getString(CommonConstant._2));
entity.setEventType(resultSet.getString(CommonConstant._3));
entity.setTransId(resultSet.getString(CommonConstant._4));
entity.setTransDate(resultSet.getString(CommonConstant._5));
entity.setTransTime(resultSet.getDate(CommonConstant._6));
entity.setAgentCode(resultSet.getString(CommonConstant._7));
entity.setAgentName(resultSet.getString(CommonConstant._8));
entity.setAgentOpenid(resultSet.getString(CommonConstant._9));
entity.setCustOpenid(resultSet.getString(CommonConstant._10));
entity.setOpenTime(resultSet.getDate(CommonConstant._11));
entity.setInfoTitle(resultSet.getString(CommonConstant._12));
entity.setInfoSource(resultSet.getString(CommonConstant._13));
entity.setCreatetime(resultSet.getDate(CommonConstant._14));
entity.setCreater(resultSet.getString(CommonConstant._15));
entity.setUpdatetime(resultSet.getDate(CommonConstant._16));
entity.setDelFlag(resultSet.getString(CommonConstant._17));
return entity;
}
)
.queryProvider(articleProvider())
.build();
}
private PagingQueryProvider articleProvider() {
MySqlPagingQueryProvider provider = new MySqlPagingQueryProvider();
provider.setSelectClause("ID, INFO_KIND, EVENT_TYPE, TRANS_ID, TRANS_DATE, TRANS_TIME, AGENT_CODE, AGENT_NAME, CUST_OPENID, OPEN_TIME, SUB_TIME, ATH_ID, CUST_NAME, CUST_PHONE, CUST_GENDER, INFO_TITLE, INFO_SOURCE, CREATETIME, CREATER, UPDATETIME, DEL_FLAG");
provider.setFromClause("FROM " + batchConvertEnum.getiTableName());
provider.setWhereClause("DEL_FLAG = :delFlag AND CREATETIME >= :startTime AND CREATETIME < :endTime");
provider.setSortKeys(ImmutableMap.of("ID", Order.ASCENDING));
return provider;
}
}
package com.aegonthtf.fate.service.batch.processor;
import cn.com.common.util.util.StringUtils;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.constant.EventTypeEnum;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.entity.behavior.AthActExport;
import com.aegonthtf.fate.entity.user.FateSalesAct;
import com.alibaba.fastjson.JSON;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.BeforeStep;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;
import java.util.Objects;
import java.util.Optional;
/**
* 【 数据清洗 】
*
* @author yangjunxiong
* @date 2021/5/14 16:46
**/
@Component
public class AthActExportItemProcessor implements ItemProcessor<AthActExport, FateSalesAct> {
private static final Logger logger = LoggerFactory.getLogger(AthActExportItemProcessor.class);
JobParameters jobParameters;
@BeforeStep
public void beforeStep(final StepExecution stepExecution) {
jobParameters = stepExecution.getJobParameters();
logger.info("jobParameters: {}", jobParameters);
}
@Override
public FateSalesAct process(AthActExport item) throws Exception {
JobBehaviorParamesDto paramesDto = JSON.parseObject(jobParameters.getString(CommonConstant.JOB_PARAMETERS), JobBehaviorParamesDto.class);
if (Objects.isNull(item) || StringUtils.isBlank(item.getEventType())) {
return null;
}
EventTypeEnum eventTypeEnum = EventTypeEnum.toByCode(item.getEventType());
if (eventTypeEnum == null) {
return null;
}
FateSalesAct entity = new FateSalesAct();
Optional.ofNullable(item.getInfoKind()).ifPresent(entity::setInfoKind);
Optional.ofNullable(item.getEventType()).ifPresent(entity::setEventType);
Optional.ofNullable(item.getAgentCode()).ifPresent(entity::setAgentCode);
Optional.ofNullable(item.getAgentName()).ifPresent(entity::setAgentName);
Optional.ofNullable(item.getInfoTitle()).ifPresent(entity::setInfoTitle);
Optional.ofNullable(item.getInfoSource()).ifPresent(entity::setInfoSource);
Optional.ofNullable(item.getCreatetime()).ifPresent(entity::setCreatetime);
Optional.ofNullable(item.getCreater()).ifPresent(entity::setCreater);
Optional.ofNullable(item.getDelFlag()).ifPresent(entity::setDelFlag);
Optional.ofNullable(paramesDto.getStaratDateTime())
.map(LocalDateTime::toDate)
.ifPresent(entity::setUpdatatime);
switch (eventTypeEnum) {
case E1:
Optional.ofNullable(item.getTransId()).ifPresent(entity::setTransId);
Optional.ofNullable(item.getTransDate()).ifPresent(entity::setTransDate);
Optional.ofNullable(item.getTransTime()).ifPresent(entity::setTransTime);
break;
case E2:
Optional.ofNullable(item.getTransId()).ifPresent(entity::setTransId);
Optional.ofNullable(item.getTransDate()).ifPresent(entity::setTransDate);
Optional.ofNullable(item.getTransTime()).ifPresent(entity::setTransTime);
Optional.ofNullable(item.getCustOpenid()).ifPresent(entity::setCustOpenid);
Optional.ofNullable(item.getOpenTime()).ifPresent(entity::setOpenTime);
break;
case E3:
Optional.ofNullable(item.getTransId()).ifPresent(entity::setTransId);
Optional.ofNullable(item.getTransDate()).ifPresent(entity::setTransDate);
Optional.ofNullable(item.getTransTime()).ifPresent(entity::setTransTime);
Optional.ofNullable(item.getCustOpenid()).ifPresent(entity::setCustOpenid);
Optional.ofNullable(item.getOpenTime()).ifPresent(entity::setOpenTime);
Optional.ofNullable(item.getSubTime()).ifPresent(entity::setSubTime);
Optional.ofNullable(item.getCustName()).ifPresent(entity::setCustName);
Optional.ofNullable(item.getCustPhone()).ifPresent(entity::setCustPhone);
Optional.ofNullable(item.getCustGender()).ifPresent(entity::setCustGender);
break;
case E7:
Optional.ofNullable(item.getCustOpenid()).ifPresent(entity::setCustOpenid);
Optional.ofNullable(item.getSubTime()).ifPresent(entity::setSubTime);
Optional.ofNullable(item.getAthId()).ifPresent(entity::setAthId);
Optional.ofNullable(item.getCustName()).ifPresent(entity::setCustName);
Optional.ofNullable(item.getCustPhone()).ifPresent(entity::setCustPhone);
break;
default:
return null;
}
return entity;
}
}
package com.aegonthtf.fate.service.batch.processor;
import cn.com.common.util.util.StringUtils;
import com.aegonthtf.fate.constant.CommonConstant;
import com.aegonthtf.fate.constant.EventTypeEnum;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.entity.behavior.EsalesActExport;
import com.aegonthtf.fate.entity.user.FateSalesAct;
import com.alibaba.fastjson.JSON;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.BeforeStep;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;
import java.util.Objects;
import java.util.Optional;
/**
* 【 数据清洗 】
*
* @author yangjunxiong
* @date 2021/5/14 16:46
**/
@Component
public class EsalesActExportItemProcessor implements ItemProcessor<EsalesActExport, FateSalesAct> {
private static final Logger logger = LoggerFactory.getLogger(EsalesActExportItemProcessor.class);
JobParameters jobParameters;
@BeforeStep
public void beforeStep(final StepExecution stepExecution) {
jobParameters = stepExecution.getJobParameters();
logger.info("jobParameters: {}", jobParameters);
}
@Override
public FateSalesAct process(EsalesActExport item) throws Exception {
JobBehaviorParamesDto paramesDto = JSON.parseObject(jobParameters.getString(CommonConstant.JOB_PARAMETERS), JobBehaviorParamesDto.class);
if (Objects.isNull(item) || StringUtils.isBlank(item.getEventType())) {
return null;
}
EventTypeEnum eventTypeEnum = EventTypeEnum.toByCode(item.getEventType());
if (eventTypeEnum == null) {
return null;
}
FateSalesAct entity = new FateSalesAct();
Optional.ofNullable(item.getInfoKind()).ifPresent(entity::setInfoKind);
Optional.ofNullable(item.getEventType()).ifPresent(entity::setEventType);
Optional.ofNullable(item.getAgentCode()).ifPresent(entity::setAgentCode);
Optional.ofNullable(item.getAgentName()).ifPresent(entity::setAgentName);
Optional.ofNullable(item.getInfoTitle()).ifPresent(entity::setInfoTitle);
Optional.ofNullable(item.getInfoSource()).ifPresent(entity::setInfoSource);
Optional.ofNullable(item.getCreatetime()).ifPresent(entity::setCreatetime);
Optional.ofNullable(item.getCreater()).ifPresent(entity::setCreater);
Optional.ofNullable(item.getDelFlag()).ifPresent(entity::setDelFlag);
Optional.ofNullable(paramesDto.getStaratDateTime())
.map(LocalDateTime::toDate)
.ifPresent(entity::setUpdatatime);
switch (eventTypeEnum) {
case E1:
Optional.ofNullable(item.getTransId()).ifPresent(entity::setTransId);
Optional.ofNullable(item.getTransDate()).ifPresent(entity::setTransDate);
Optional.ofNullable(item.getTransTime()).ifPresent(entity::setTransTime);
break;
case E2:
Optional.ofNullable(item.getTransId()).ifPresent(entity::setTransId);
Optional.ofNullable(item.getTransDate()).ifPresent(entity::setTransDate);
Optional.ofNullable(item.getTransTime()).ifPresent(entity::setTransTime);
Optional.ofNullable(item.getCustOpenid()).ifPresent(entity::setCustOpenid);
Optional.ofNullable(item.getOpenTime()).ifPresent(entity::setOpenTime);
break;
default:
return null;
}
return entity;
}
}
package com.aegonthtf.fate.service.batch.writer;
import com.aegonthtf.fate.entity.user.FateSalesAct;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration
public class FateSalesActWriter {
@Autowired
@Qualifier("primaryDataSource")
private DataSource dataSource;
@Bean
public JdbcBatchItemWriter<FateSalesAct> writer() {
JdbcBatchItemWriter<FateSalesAct> writer = new JdbcBatchItemWriter<>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
writer.setSql("INSERT INTO fate_sales_act (ID, INFO_KIND, INFO_SOURCE, INFO_TITLE, EVENT_TYPE, TRANS_ID, TRANS_DATE, TRANS_TIME, AGENT_CODE, AGENT_NAME, AGENT_OPENID, CUST_OPENID, OPEN_DATE, OPEN_TIME, SUB_DATE, SUB_TIME, ATH_ID, SIS_ID, CUST_ID, CUST_NAME, CUST_PHONE, CUST_GENDER, CUST_AGE, CUST_OPR, CUST_EMAIL, RISK_NAME, FATE_APE, PAY_TIME, FATE_FYP, CREATEDATE, CREATETIME, CREATER, UPDATATIME, DEL_FLAG, POLICY_NO) VALUES (" +
":id ,\n" +
":infoKind ,\n" +
":infoSource ,\n" +
":infoTitle ,\n" +
":eventType ,\n" +
":transId ,\n" +
":transDate ,\n" +
":transTime ,\n" +
":agentCode ,\n" +
":agentName ,\n" +
":agentOpenid ,\n" +
":custOpenid ,\n" +
":openDate ,\n" +
":openTime ,\n" +
":subDate ,\n" +
":subTime ,\n" +
":athId ,\n" +
":sisId ,\n" +
":custId ,\n" +
":custName ,\n" +
":custPhone ,\n" +
":custGender ,\n" +
":custAge ,\n" +
":custOpr ,\n" +
":custEmail ,\n" +
":riskName ,\n" +
":fateApe ,\n" +
":payTime ,\n" +
":fateFyp ,\n" +
":createdate ,\n" +
":createtime ,\n" +
":creater ,\n" +
":updatatime,\n" +
":delFlag,\n" +
":policyNo\n)");
writer.setDataSource(dataSource);
return writer;
}
}
package com.aegonthtf.fate.constant;
import com.aegonthtf.fate.util.verify.Asserts;
import java.util.Arrays;
import java.util.stream.Collectors;
public enum BatchConvertEnum {
TU_D_SUBMISSION_DAILY(0, "tu_d_submission_daily", "fate_sales_act", null),
ATH_ACT_EXPORT(1, "ath_act_export", "fate_sales_act", InfoSourceEnum.Athena2_0),
ESALES_ACT_EXPORT(2, "esales_act_export", "fate_sales_act", InfoSourceEnum.ESales),
APOLLO_ACT_EXPORT(3, "apollo_act_export", "fate_sales_act", InfoSourceEnum.Apollo);
private final int value;
private final String iTableName;
private final String oTableName;
private final InfoSourceEnum infoSourceEnum;
static {
int size = Arrays.stream(BatchConvertEnum.values()).map(BatchConvertEnum::getValue).collect(Collectors.toSet()).size();
Asserts.state(size == BatchConvertEnum.values().length, "BatchConvertEnum.value 重复定义");
}
BatchConvertEnum(int value, String iTableName, String oTableName, InfoSourceEnum infoSourceEnum) {
this.value = value;
this.iTableName = iTableName;
this.oTableName = oTableName;
this.infoSourceEnum = infoSourceEnum;
}
public static BatchConvertEnum toByValue(int value) {
for (BatchConvertEnum item : BatchConvertEnum.values()) {
if (item.value == value) {
return item;
}
}
throw new IllegalStateException("枚举类型转换失败");
}
public int getValue() {
return value;
}
public String getiTableName() {
return iTableName;
}
public String getoTableName() {
return oTableName;
}
public InfoSourceEnum getInfoSourceEnum() {
return infoSourceEnum;
}
}
package com.aegonthtf.fate.constant;
import com.aegonthtf.fate.dto.JobBehaviorParamesDto;
import com.aegonthtf.fate.util.JodaTimeUtils;
import com.aegonthtf.fate.util.verify.Asserts;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.joda.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.stream.Collectors;
public enum EventTypeEnum {
E1(1, "E1", "", InfoSourceEnum.Athena2_0, "营销员转发页面链接"),
E2(2, "E2", "", InfoSourceEnum.Athena2_0, "客户打开页面"),
E3(3, "E3", "", InfoSourceEnum.Athena2_0, "客户留资后提交"),
E7(7, "E7", "", InfoSourceEnum.Athena2_0, "风险报告完成"),
E14(14, "E14", "", InfoSourceEnum.Athena2_0, "投保完成"),
E32(32, "E32", "", InfoSourceEnum.Athena2_0, "准增员完成签约"),
;
private final int value;
private final String code;
private final String select;
private final InfoSourceEnum infoSource;
private final String declare;
static {
int size = Arrays.stream(EventTypeEnum.values()).map(EventTypeEnum::getValue).collect(Collectors.toSet()).size();
Asserts.state(size == EventTypeEnum.values().length, "EventTypeEnum.value 重复定义");
}
EventTypeEnum(int value, String code, String select, InfoSourceEnum infoSource, String declare) {
this.value = value;
this.code = code;
this.select = select;
this.infoSource = infoSource;
this.declare = declare;
}
public static EventTypeEnum toByValue(int value) {
for (EventTypeEnum item : EventTypeEnum.values()) {
if (item.value == value) {
return item;
}
}
throw new IllegalStateException("枚举类型转换失败");
}
public static EventTypeEnum toByCode(String code) {
for (EventTypeEnum item : EventTypeEnum.values()) {
if (item.code.equals(code)) {
return item;
}
}
return null;
}
public int getValue() {
return value;
}
public String getCode() {
return code;
}
public String getDeclare() {
return declare;
}
public String getSelect() {
return select;
}
public InfoSourceEnum getInfoSource() {
return infoSource;
}
public JobBehaviorParamesDto getJobparames(LocalDateTime staratDateTime) {
JobBehaviorParamesDto paramesDto = new JobBehaviorParamesDto();
return paramesDto;
}
public static ImmutablePair<Date, Date> getCreateTime(LocalDateTime staratDateTime) {
Asserts.notNull(staratDateTime, "staratDateTime不能为空!");
Date startTime;
Date endTime;
if (CommonConstant.ZERO.equals(staratDateTime.toString("H"))) {
endTime = JodaTimeUtils.maxTime(staratDateTime.minusDays(CommonConstant._1).toLocalDate()).toDate();
startTime = new LocalDateTime(endTime).minusHours(CommonConstant._1).plusSeconds(CommonConstant._1).toDate();
}else {
startTime = JodaTimeUtils.toDate(staratDateTime.minusHours(CommonConstant._1).toString(CommonConstant.yyyy_MM_dd_HH));
endTime = JodaTimeUtils.toDate(staratDateTime.toString(CommonConstant.yyyy_MM_dd_HH));
}
return ImmutablePair.of(startTime, endTime);
}
}
package com.aegonthtf.fate.constant;
public class CommonConstant {
public static final String BASE_CONTROLLER_PACKAGE = "com.aegonthtf.fate.controller";
public static final String N = "N";
public static final String Y = "Y";
public static final String LIMIT1 = "LIMIT 1";
public static final String ZERO = "0";
public static final int BATCH_SIZE = 1000;
public static final int BEHAVIOR_BATCH_SIZE = 500;
public static final String NULL = null;
public static final String CREATERBATCH = "batch";
public static final String JOB_PARAMETERS = "jobParameters";
public static String yyyyMMdd = "yyyyMMdd";
public static String yyyyMM = "yyyyMM";
public static String yyyy_MM_dd = "yyyy-MM-dd";
public static String yyyyMMddHHmmss = "yyyyMMddHHmmss";
public static String yyyy_MM_dd_HH = "yyyyMMddHH";
public static String HHmm = "HHmm";
public static String AGENT_STATUS_ACTIVE = "Active";
public static final int _1 = 1;
public static final int _2 = 2;
public static final int _3 = 3;
public static final int _4 = 4;
public static final int _5 = 5;
public static final int _6 = 6;
public static final int _7 = 7;
public static final int _8 = 8;
public static final int _9 = 9;
public static final int _10 = 10;
public static final int _11 = 11;
public static final int _12 = 12;
public static final int _13 = 13;
public static final int _14 = 14;
public static final int _15 = 15;
public static final int _16 = 16;
public static final int _17 = 17;
public static final int _18 = 18;
public static final int _19 = 19;
public static final int _20 = 20;
public static final int _21 = 21;
public static final int _22 = 22;
public static final int _23 = 23;
public static final int _24 = 24;
public static final int _25 = 25;
public static final int _26 = 26;
public static final int _27 = 27;
public static final int _28 = 28;
public static final int _29 = 29;
public static final int _30 = 30;
public static final int _31 = 31;
public static final int _32 = 32;
public static final int _33 = 33;
public static final int _34 = 34;
public static final int _35 = 35;
public static final int _36 = 36;
public static final int _37 = 37;
public static final int _38 = 38;
public static final int _39 = 39;
public static final int _40 = 40;
public static final int _41 = 41;
public static final int _42 = 42;
public static final int _43 = 43;
public static final int _44 = 44;
public static final int _45 = 45;
public static final int _46 = 46;
public static final int _47 = 47;
public static final int _48 = 48;
public static final int _49 = 49;
public static final int _50 = 50;
}