|
@ -1,112 +1,112 @@
|
|
|
package com.yihu.wlyy.statistics.job.business;
|
|
|
|
|
|
import com.yihu.wlyy.statistics.dao.QuartzJobLogDao;
|
|
|
import com.yihu.wlyy.statistics.etl.dataFilter.RenewSignDataFilter;
|
|
|
import com.yihu.wlyy.statistics.etl.extract.DBExtract;
|
|
|
import com.yihu.wlyy.statistics.etl.model.ETLModel;
|
|
|
import com.yihu.wlyy.statistics.etl.model.FilterModel;
|
|
|
import com.yihu.wlyy.statistics.etl.role.Level1Role;
|
|
|
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
|
|
|
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
|
|
|
import com.yihu.wlyy.statistics.model.signfamily.SignFamilyRenew;
|
|
|
import com.yihu.wlyy.statistics.util.JsonUtil;
|
|
|
import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
|
|
|
import com.yihu.wlyy.statistics.vo.WlyyQuotaVO;
|
|
|
import org.quartz.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 团转签的指标执行类
|
|
|
*/
|
|
|
@Component
|
|
|
@Scope("prototype")
|
|
|
@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
|
|
|
public class SwitchTownSignJob implements Job {
|
|
|
private WlyyQuotaVO wlyyQuota;//指标对象
|
|
|
private WlyyJobConfigVO wlyyJobConfig;//配置对象
|
|
|
@Autowired
|
|
|
private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private Level1Role levelRole;
|
|
|
@Autowired
|
|
|
private DBStorage dbStorage;
|
|
|
@Autowired
|
|
|
private DBExtract dbExtract;
|
|
|
@Autowired
|
|
|
private RenewSignDataFilter signDataFilter;
|
|
|
|
|
|
String yesterday;
|
|
|
String daybefore;
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext context)
|
|
|
throws JobExecutionException {
|
|
|
try{
|
|
|
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
|
|
|
//初始化参数
|
|
|
JobDataMap map = context.getJobDetail().getJobDataMap();
|
|
|
wlyyQuota = (WlyyQuotaVO) map.get("quota");
|
|
|
wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
|
|
|
daybefore= StringUtils.isEmpty(map.get("daybefore"))?SignJob.getDayString(-2):map.get("daybefore").toString();
|
|
|
yesterday= StringUtils.isEmpty(map.get("yesterday"))?SignJob.getDayString(-1):map.get("yesterday").toString();
|
|
|
//计算指标
|
|
|
computequota();
|
|
|
}catch (Exception e){
|
|
|
//如果出錯立即重新執行
|
|
|
JobExecutionException e2 =new JobExecutionException(e);
|
|
|
e2.setRefireImmediately(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算指标
|
|
|
*/
|
|
|
@Transactional
|
|
|
private void computequota() {
|
|
|
try{
|
|
|
jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+46+"'");
|
|
|
|
|
|
//新建任务日志对象
|
|
|
QuartzJobLog quartzJobLog = new QuartzJobLog();
|
|
|
quartzJobLog.setJobStartTime(new Date());
|
|
|
quartzJobLog.setJobId(wlyyJobConfig.getId());
|
|
|
quartzJobLog.setJobName(wlyyJobConfig.getJobName());
|
|
|
|
|
|
String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where " +
|
|
|
" fr.old_admin_team_id!=fr.admin_team_id " +
|
|
|
" and fr.hospital!=fr.old_hospital " +
|
|
|
" and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) " +
|
|
|
" and LENGTH(fr.hospital)=10 " +
|
|
|
" and LENGTH(fr.old_hospital)=10 " +
|
|
|
" and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'" +
|
|
|
" and fr.sign_year ='"+Constant.getNowYearByDate(yesterday)+"'";
|
|
|
//抽取數據
|
|
|
List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
|
|
|
//清洗數據
|
|
|
FilterModel etlModels= signDataFilter.filter(signFamilies,null,null,sql,yesterday);
|
|
|
//统计数据
|
|
|
List<Map<String, List<ETLModel>>> returnDatas= levelRole.elt(etlModels.getEtlModelList());
|
|
|
//保存数据
|
|
|
dbStorage.saveByLevel1(returnDatas,yesterday,wlyyQuota);
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
|
quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));
|
|
|
quartzJobLog.setJobType(etlModels.getError()?"1":"0");
|
|
|
quartzJobLogDao.save(quartzJobLog);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//package com.yihu.wlyy.statistics.job.business;
|
|
|
//
|
|
|
//import com.yihu.wlyy.statistics.dao.QuartzJobLogDao;
|
|
|
//import com.yihu.wlyy.statistics.etl.dataFilter.RenewSignDataFilter;
|
|
|
//import com.yihu.wlyy.statistics.etl.extract.DBExtract;
|
|
|
//import com.yihu.wlyy.statistics.etl.model.ETLModel;
|
|
|
//import com.yihu.wlyy.statistics.etl.model.FilterModel;
|
|
|
//import com.yihu.wlyy.statistics.etl.role.Level1Role;
|
|
|
//import com.yihu.wlyy.statistics.etl.storage.DBStorage;
|
|
|
//import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
|
|
|
//import com.yihu.wlyy.statistics.model.signfamily.SignFamilyRenew;
|
|
|
//import com.yihu.wlyy.statistics.util.JsonUtil;
|
|
|
//import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
|
|
|
//import com.yihu.wlyy.statistics.vo.WlyyQuotaVO;
|
|
|
//import org.quartz.*;
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
//import org.springframework.context.annotation.Scope;
|
|
|
//import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
//import org.springframework.stereotype.Component;
|
|
|
//import org.springframework.transaction.annotation.Transactional;
|
|
|
//import org.springframework.util.StringUtils;
|
|
|
//import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
|
|
//
|
|
|
//import java.util.Date;
|
|
|
//import java.util.List;
|
|
|
//import java.util.Map;
|
|
|
//
|
|
|
///**
|
|
|
// * 团转签的指标执行类
|
|
|
// */
|
|
|
//@Component
|
|
|
//@Scope("prototype")
|
|
|
//@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
|
|
|
//public class SwitchTownSignJob implements Job {
|
|
|
// private WlyyQuotaVO wlyyQuota;//指标对象
|
|
|
// private WlyyJobConfigVO wlyyJobConfig;//配置对象
|
|
|
// @Autowired
|
|
|
// private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
|
|
|
// @Autowired
|
|
|
// private JdbcTemplate jdbcTemplate;
|
|
|
// @Autowired
|
|
|
// private Level1Role levelRole;
|
|
|
// @Autowired
|
|
|
// private DBStorage dbStorage;
|
|
|
// @Autowired
|
|
|
// private DBExtract dbExtract;
|
|
|
// @Autowired
|
|
|
// private RenewSignDataFilter signDataFilter;
|
|
|
//
|
|
|
// String yesterday;
|
|
|
// String daybefore;
|
|
|
// @Override
|
|
|
// public void execute(JobExecutionContext context)
|
|
|
// throws JobExecutionException {
|
|
|
// try{
|
|
|
// SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
|
|
|
// //初始化参数
|
|
|
// JobDataMap map = context.getJobDetail().getJobDataMap();
|
|
|
// wlyyQuota = (WlyyQuotaVO) map.get("quota");
|
|
|
// wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
|
|
|
// daybefore= StringUtils.isEmpty(map.get("daybefore"))?SignJob.getDayString(-2):map.get("daybefore").toString();
|
|
|
// yesterday= StringUtils.isEmpty(map.get("yesterday"))?SignJob.getDayString(-1):map.get("yesterday").toString();
|
|
|
// //计算指标
|
|
|
// computequota();
|
|
|
// }catch (Exception e){
|
|
|
// //如果出錯立即重新執行
|
|
|
// JobExecutionException e2 =new JobExecutionException(e);
|
|
|
// e2.setRefireImmediately(true);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// /**
|
|
|
// * 计算指标
|
|
|
// */
|
|
|
// @Transactional
|
|
|
// private void computequota() {
|
|
|
// try{
|
|
|
// jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+46+"'");
|
|
|
//
|
|
|
// //新建任务日志对象
|
|
|
// QuartzJobLog quartzJobLog = new QuartzJobLog();
|
|
|
// quartzJobLog.setJobStartTime(new Date());
|
|
|
// quartzJobLog.setJobId(wlyyJobConfig.getId());
|
|
|
// quartzJobLog.setJobName(wlyyJobConfig.getJobName());
|
|
|
//
|
|
|
// String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where " +
|
|
|
// " fr.old_admin_team_id!=fr.admin_team_id " +
|
|
|
// " and fr.hospital!=fr.old_hospital " +
|
|
|
// " and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) " +
|
|
|
// " and LENGTH(fr.hospital)=10 " +
|
|
|
// " and LENGTH(fr.old_hospital)=10 " +
|
|
|
// " and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'" +
|
|
|
// " and fr.sign_year ='"+Constant.getNowYearByDate(yesterday)+"'";
|
|
|
// //抽取數據
|
|
|
// List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
|
|
|
// //清洗數據
|
|
|
// FilterModel etlModels= signDataFilter.filter(signFamilies,null,null,sql,yesterday);
|
|
|
// //统计数据
|
|
|
// List<Map<String, List<ETLModel>>> returnDatas= levelRole.elt(etlModels.getEtlModelList());
|
|
|
// //保存数据
|
|
|
// dbStorage.saveByLevel1(returnDatas,yesterday,wlyyQuota);
|
|
|
// //保存日志
|
|
|
// quartzJobLog.setJobEndTime(new Date());
|
|
|
// quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));
|
|
|
// quartzJobLog.setJobType(etlModels.getError()?"1":"0");
|
|
|
// quartzJobLogDao.save(quartzJobLog);
|
|
|
// }catch (Exception e){
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
//}
|