package com.yihu.wlyy.job; import com.yihu.wlyy.entity.address.Hospital; import com.yihu.wlyy.entity.address.Town; import com.yihu.wlyy.entity.consult.ConsultTeam; import com.yihu.wlyy.entity.doctor.profile.Doctor; import com.yihu.wlyy.entity.job.QuartzJobLog; import com.yihu.wlyy.entity.statistics.WlyyQuotaResult; import com.yihu.wlyy.repository.address.TownDao; import com.yihu.wlyy.repository.consult.ConsultTeamDao; 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.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 ConsultJob implements Job { private WlyyQuotaVO wlyyQuota;//指标对象 private WlyyJobConfigVO wlyyJobConfig;//配置对象 @Autowired private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao @Autowired private QuartzJobLogDao quartzJobLogDao;//执行日志Dao @Autowired private DoctorDao doctorDao; @Autowired private HospitalDao hospitalDao; @Autowired private TownDao townDao; @Autowired private ConsultTeamDao consultTeamDao; @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='"+3+"'"); //新建任务日志对象 QuartzJobLog quartzJobLog = new QuartzJobLog(); quartzJobLog.setJobStartTime(new Date()); quartzJobLog.setJobId(wlyyJobConfig.getId()); quartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的健康医生 List doctors = doctorDao.findAllZKDoctot(); 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 consultTeams = consultTeamDao.findByCzrqyYesterday(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 (ConsultTeam consultTeam : consultTeams) { String doctorCode = consultTeam.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 (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.setQkdoctorJobName(doctor.getJobName()); wlyyQuotaResult.setQkdoctorName(doctor.getName()); wlyyQuotaResult.setQkdoctorCode(doctor.getCode()); wlyyQuotaResult.setTown(doctor.getTown()); wlyyQuotaResult.setTownName(doctor.getTownName()); wlyyQuotaResult.setLevel1Type("1"); wlyyQuotaResult.setCreateTime(new Date()); //判断全科医生是否有咨询量 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("厦门市"); 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; } }