|  | @ -1,114 +0,0 @@
 | 
	
		
			
				|  |  | 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.role.Level2Role;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.statistics.etl.storage.DBStorage;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.statistics.model.signfamily.SignFamily;
 | 
	
		
			
				|  |  | 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.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.Calendar;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 续签签约原因的指标执行类
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Component
 | 
	
		
			
				|  |  | @Scope("prototype")
 | 
	
		
			
				|  |  | @DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
 | 
	
		
			
				|  |  | public class RenewSignReasonJob implements Job {
 | 
	
		
			
				|  |  |     private WlyyQuotaVO wlyyQuota;//指标对象
 | 
	
		
			
				|  |  |     private WlyyJobConfigVO wlyyJobConfig;//配置对象
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Level1Role levelRole;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Level2Role level2Role;
 | 
	
		
			
				|  |  |     @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='"+30+"'");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //新建任务日志对象
 | 
	
		
			
				|  |  |             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,fr.renew_change_reason from wlyy_sign_family_renew_log fr where  fr.sign_year<'"+yesterday+Constant.quota_date_last+"'  and fr.sign_year ='"+Constant.getNowYear()+"'";
 | 
	
		
			
				|  |  |             //抽取數據
 | 
	
		
			
				|  |  |             List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
 | 
	
		
			
				|  |  |             //清洗數據
 | 
	
		
			
				|  |  |             FilterModel etlModels= signDataFilter.filter(signFamilies,"1",null,sql,yesterday);
 | 
	
		
			
				|  |  |             //统计数据
 | 
	
		
			
				|  |  |             List<Map<String, List<ETLModel>>>  returnDatas= levelRole.elt(etlModels.getEtlModelList());
 | 
	
		
			
				|  |  |             //统计数据 二级维度
 | 
	
		
			
				|  |  |             List<Map<String, Map<String, List<ETLModel>>>> level2Data= level2Role.elt(returnDatas);
 | 
	
		
			
				|  |  |             //数据转换
 | 
	
		
			
				|  |  |             dbStorage.saveByLevel2(level2Data,yesterday,wlyyQuota,6,9,1);
 | 
	
		
			
				|  |  |             //保存日志
 | 
	
		
			
				|  |  |             quartzJobLog.setJobEndTime(new Date());
 | 
	
		
			
				|  |  |             quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));
 | 
	
		
			
				|  |  |             quartzJobLog.setJobType(etlModels.getError()?"1":"0");
 | 
	
		
			
				|  |  |             quartzJobLogDao.save(quartzJobLog);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |