package com.fzzy.api.timer;
|
|
import com.fzzy.api.data.ApiParam;
|
import com.fzzy.api.entity.ApiConfs;
|
import com.fzzy.api.service.*;
|
import com.fzzy.api.utils.ContextUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.time.DateUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author: andy.jia
|
* @description: 推送省平台数据定时任务
|
* @version:
|
*/
|
@Slf4j
|
@Component(PushDataScheduled.BEAN_ID)
|
public class PushDataScheduled {
|
|
public static final String BEAN_ID = "api.pushDataScheduled";
|
|
|
@Autowired
|
private ApiPushManager apiPushManager;
|
|
@Autowired
|
private ApiCommonService apiCommonService;
|
|
/**
|
* cron = "0 0,30 * * * ? "
|
* <p>
|
* 固定時間:0分鐘,30分鐘執行
|
*/
|
@Scheduled(cron = "0 0,30 * * * ? ")
|
public void scheduled() {
|
|
log.info("------->>>>>>>>>>系统执行定时推送省平台接口");
|
|
List<ApiConfs> list = apiCommonService.listCacheConf();
|
|
if (null == list || list.isEmpty()) return;
|
|
Date exeDate = new Date();
|
|
for (ApiConfs conf : list) {
|
|
exeByConf11(conf, exeDate);
|
|
exeByConf99(conf, exeDate);
|
}
|
|
}
|
|
|
/**
|
* 同步义务数据
|
*
|
* @param conf
|
* @param exeDate
|
*/
|
private void exeByConf99(ApiConfs conf, Date exeDate) {
|
if (null == conf.getPushType99() || conf.getPushType99().equals(ApiConfs.SYNC_PUSH_HAND)) {
|
|
log.info("------->>>>>>>>>> 业务接口数据,系统配置为手动模式,取消自动执行");
|
return;
|
}
|
|
|
Date start = exeDate;
|
|
//是否执行
|
boolean isExecute = false;
|
boolean isUpdateStart = false;
|
//核对天是否匹配
|
if (conf.getPushDay99().equals(ApiConfs.TIME_ALL)) {
|
isExecute = true;
|
} else {
|
int dayOfWeek = ContextUtil.getDayOfWeek(exeDate);
|
if (String.valueOf(dayOfWeek).equals(conf.getPushDay11())) {
|
isExecute = true;
|
|
//开始时间提前7天
|
start = DateUtils.addDays(start, -7);
|
isUpdateStart = true;
|
} else {
|
isExecute = false;
|
}
|
}
|
|
if (!isExecute) {
|
log.debug("------->>>>>>>>>> 业务数据推送---时间配置天不匹配");
|
return;
|
}
|
|
log.info("------->>>>>>>>>> 业务数据推送---开始查询相关业务数据进行推送");
|
ApiParam param = new ApiParam();
|
param.setPushProtocol(conf.getPushProtocol());
|
param.setKqdm(conf.getKqdm());
|
param.setStart(start);
|
param.setEnd(exeDate);
|
param.setDeptId(conf.getDeptId());
|
|
|
PushService12 pushService12 = apiPushManager.getPushService12(conf.getPushProtocol());
|
pushService12.pushData(param);
|
|
PushService13 pushService13 = apiPushManager.getPushService13(conf.getPushProtocol());
|
pushService13.pushData(param);
|
|
PushService14 pushService14 = apiPushManager.getPushService14(conf.getPushProtocol());
|
pushService14.pushData(param);
|
}
|
|
/**
|
* 推送基础信息
|
*
|
* @param conf
|
* @param exeDate
|
*/
|
private void exeByConf11(ApiConfs conf, Date exeDate) {
|
|
if (null == conf.getPushType11() || conf.getPushType11().equals(ApiConfs.SYNC_PUSH_HAND)) {
|
log.info("------->>>>>>>>>> 基础数据推送,系统配置为手动模式,取消自动执行");
|
return;
|
}
|
|
|
Date start = exeDate;
|
|
//是否执行
|
boolean isExecute;
|
boolean isUpdateStart = false;
|
//核对天是否匹配
|
if (conf.getPushDay11().equals(ApiConfs.TIME_ALL)) {
|
isExecute = true;
|
} else {
|
int dayOfWeek = ContextUtil.getDayOfWeek(exeDate);
|
if (String.valueOf(dayOfWeek).equals(conf.getPushDay11())) {
|
isExecute = true;
|
|
//开始时间提前7天
|
start = DateUtils.addDays(start, -7);
|
isUpdateStart = true;
|
} else {
|
isExecute = false;
|
}
|
}
|
|
if (!isExecute) {
|
log.debug("------->>>>>>>>>> 基础数据推送---时间配置天不匹配");
|
return;
|
}
|
|
//核对时间是否匹配
|
if (conf.getPushHour11().equals(ApiConfs.TIME_ALL)) {
|
isExecute = true;
|
} else {
|
int hourOfDay = ContextUtil.getHourOfDay(exeDate);
|
if (String.valueOf(hourOfDay).equals(conf.getPushHour11())) {
|
isExecute = true;
|
|
if (!isUpdateStart) {
|
start = DateUtils.addDays(start, -1);
|
isUpdateStart = true;
|
}
|
} else {
|
isExecute = false;
|
}
|
}
|
if (!isExecute) {
|
log.debug("------->>>>>>>>>> 基础数据推送---时间配置小时不匹配");
|
return;
|
}
|
|
//核对时间分钟是否匹配
|
int minute = ContextUtil.getMinuteOfHour(exeDate);
|
if (String.valueOf(minute).equals(conf.getPushMinute11())) {
|
isExecute = true;
|
if (!isUpdateStart) {
|
start = DateUtils.addHours(start, -1);
|
}
|
} else {
|
isExecute = false;
|
}
|
|
if (!isExecute) {
|
log.debug("------->>>>>>>>>> 基础数据推送---时间配置分钟不匹配");
|
return;
|
}
|
|
log.info("------->>>>>>>>>> 基础数据推送---开始查询相关基础数据进行推送");
|
|
ApiParam param = new ApiParam();
|
param.setPushProtocol(conf.getPushProtocol());
|
param.setKqdm(conf.getKqdm());
|
param.setStart(start);
|
param.setEnd(exeDate);
|
param.setDeptId(conf.getDeptId());
|
|
|
PushService11 pushService11 = apiPushManager.getPushService11(conf.getPushProtocol());
|
pushService11.pushData(param);
|
}
|
}
|