package com.yihu.wlyy.job; import com.yihu.wlyy.entity.address.Hospital; import com.yihu.wlyy.entity.address.Town; import com.yihu.wlyy.entity.doctor.profile.Doctor; import com.yihu.wlyy.entity.job.QuartzJobLog; import com.yihu.wlyy.entity.patient.SignFamily; import com.yihu.wlyy.entity.statistics.WlyyQuotaResult; import com.yihu.wlyy.repository.address.TownDao; import com.yihu.wlyy.repository.doctor.DoctorDao; import com.yihu.wlyy.repository.job.QuartzJobLogDao; import com.yihu.wlyy.repository.organization.HospitalDao; import com.yihu.wlyy.repository.patient.SignFamilyDao; import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao; import com.yihu.wlyy.web.quota.WlyyJobConfigVO; import com.yihu.wlyy.web.quota.WlyyQuotaVO; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.beans.factory.annotation.Autowired; 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.*; /** * 待签约的指标执行类 */ @Component public class WaitSignJob implements Job { private WlyyQuotaVO wlyyQuota;//指标对象 private WlyyJobConfigVO wlyyJobConfig;//配置对象 @Autowired private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao @Autowired private QuartzJobLogDao quartzJobLogDao;//执行日志Dao @Autowired private SignFamilyDao signFamilyDao; @Autowired private DoctorDao doctorDao; @Autowired private HospitalDao hospitalDao; @Autowired private TownDao townDao; @Autowired private JdbcTemplate jdbcTemplate; String yesterday; String now; @Override public void execute(JobExecutionContext context) throws JobExecutionException { SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); //初始化参数 JobDataMap map = context.getJobDetail().getJobDataMap(); wlyyQuota = (WlyyQuotaVO) map.get("quota"); wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig"); now= StringUtils.isEmpty(map.get("now"))?SignJob.getDayString(0):map.get("now").toString(); yesterday= StringUtils.isEmpty(map.get("yesterday"))?SignJob.getDayString(-1):map.get("yesterday").toString(); //计算指标 computequota(); } /** * 计算指标 */ @Transactional private void computequota() { jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+9+"'"); //新建任务日志对象 QuartzJobLog quartzJobLog = new QuartzJobLog(); quartzJobLog.setJobStartTime(new Date()); quartzJobLog.setJobId(wlyyJobConfig.getId()); quartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的全科医生 List doctors = doctorDao.findAllQKDoctot(); Map doctorsMap = new HashMap(); for (Doctor doctor : doctors) { doctorsMap.put(doctor.getCode(), doctor); } //查找出系统全部的机构 List hospitals = hospitalDao.findHospital2(); Map hospitalsMap = new HashMap(); for (Hospital hospital : hospitals) { hospitalsMap.put(hospital.getCode(), hospital); } //查找出厦门市全部的区 List towns = townDao.findByCityCode(Constant.city); Map townsMap = new HashMap(); for (Town town : towns) { townsMap.put(town.getCode(), town); } //找出今天的待签约信息 List signFamilys = signFamilyDao.findByJiatingWaitSignYesterday(yesterday,now); Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode Long cityCount = 0L; //统计有待签约的 for (SignFamily signFamily : signFamilys) { String doctorCode = signFamily.getDoctor();//得到待签约中全科医生的code //统计团队 if (tjQkdoctorMap.containsKey(doctorCode)) { tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1); } else { tjQkdoctorMap.put(doctorCode, 1L); } //判断医生属于哪个机构 Doctor doctor = doctorsMap.get(doctorCode); if(doctor==null){ continue; } String orgCode = doctor.getHospital(); //统计机构 if(!"00".equals(orgCode.substring(8))){ //统计站 String orgCodeTemp=orgCode.substring(0,8)+"00"; if (tjOrgMap.containsKey(orgCodeTemp)) { tjOrgMap.put(orgCodeTemp, tjOrgMap.get(orgCodeTemp) + 1); } else { tjOrgMap.put(orgCodeTemp, 1L); } }else{ //统计社区 if (tjOrgMap.containsKey(orgCode)) { tjOrgMap.put(orgCode, tjOrgMap.get(orgCode) + 1); } else { tjOrgMap.put(orgCode, 1L); } } String townCode = doctor.getTown(); //统计区 if (tjTownMap.containsKey(townCode)) { tjTownMap.put(townCode, tjTownMap.get(townCode) + 1); } else { tjTownMap.put(townCode, 1L); } //统计市 cityCount++; } //保存统计的结果 //保存全科医生的待签约统计 for (Map.Entry entry : doctorsMap.entrySet()) { Doctor doctor = doctorsMap.get(entry.getKey());//得到全科医生 WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setOrgCode(doctor.getHospital()); wlyyQuotaResult.setOrgName(doctor.getHosptialName()); wlyyQuotaResult.setCity(doctor.getCity()); wlyyQuotaResult.setCityName(doctor.getCityName()); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setQkdoctorJobName(doctor.getJobName()); wlyyQuotaResult.setQkdoctorName(doctor.getName()); wlyyQuotaResult.setQkdoctorCode(doctor.getCode()); wlyyQuotaResult.setTown(doctor.getTown()); wlyyQuotaResult.setTownName(doctor.getTownName()); wlyyQuotaResult.setLevel1Type("1"); //判断全科医生是否有待签约量 if (tjQkdoctorMap.containsKey(doctor.getCode())) { wlyyQuotaResult.setResult(tjQkdoctorMap.get(doctor.getCode()) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } //保存机构的待签约统计 for (Map.Entry entry : hospitalsMap.entrySet()) { Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生 WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setOrgCode(hospital.getCode()); wlyyQuotaResult.setOrgName(hospital.getName()); wlyyQuotaResult.setCity(hospital.getCity()); wlyyQuotaResult.setCityName(hospital.getCityName()); wlyyQuotaResult.setTown(hospital.getTown()); wlyyQuotaResult.setTownName(hospital.getTownName()); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type("2"); //判断全科医生是否有待签约量 if (tjOrgMap.containsKey(hospital.getCode())) { wlyyQuotaResult.setResult(tjOrgMap.get(hospital.getCode()) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } //保存区级的待签约统计 for (Map.Entry entry : townsMap.entrySet()) { Town town = townsMap.get(entry.getKey());//得到全科医生 WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setCity(town.getCity()); wlyyQuotaResult.setCityName(Constant.cityName); wlyyQuotaResult.setTown(town.getCode()); wlyyQuotaResult.setTownName(town.getName()); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type("3"); //判断全科医生是否有待签约量 if (tjTownMap.containsKey(town.getCode())) { wlyyQuotaResult.setResult(tjTownMap.get(town.getCode()) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } //保存市级的统计 { WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setCity(Constant.city); wlyyQuotaResult.setCityName(Constant.cityName); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type("4"); //判断全科医生是否有待签约量 if (cityCount > 0) { wlyyQuotaResult.setResult(cityCount + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } quartzJobLog.setJobEndTime(new Date()); quartzJobLog.setJobContent("统计"+getYesterday()+" 的待签约数据完成 "); quartzJobLog.setJobType("1"); quartzJobLogDao.save(quartzJobLog); } public String getYesterday() { return yesterday; } }