package com.yihu.wlyy.job; import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam; import com.yihu.wlyy.entity.organization.Hospital; import com.yihu.wlyy.entity.address.Town; import com.yihu.wlyy.entity.doctor.profile.Doctor; import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo; 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.DoctorAdminTeamDao; import com.yihu.wlyy.repository.doctor.DoctorDao; import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao; 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.util.IdCardUtil; import com.yihu.wlyy.web.quota.WlyyJobConfigVO; import com.yihu.wlyy.web.quota.WlyyQuotaVO; import org.json.JSONArray; import org.json.JSONObject; 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.data.redis.core.StringRedisTemplate; 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.*; /** * 签约的指标执行类 */ @Component public class SignJob 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 DoctorPatientGroupInfoDao doctorPatientGroupInfoDao; @Autowired private JdbcTemplate jdbcTemplate; @Autowired private StringRedisTemplate redisTemplate; @Autowired private DoctorAdminTeamDao doctorAdminTeamDao; 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(); String level1 = wlyyQuota.getLevel1();//得到一级维度 String level2 = wlyyQuota.getLevel2();//得到二级维度 //如果一级维度为空 不进行统计 if (!StringUtils.isEmpty(level1)) { if (StringUtils.isEmpty(level2)) { //線刪除今天的数据 //2级维度是空按照一级的机构唯独计算指标 computequota(); } else { switch (level2) { case "1": { //線刪除今天的数据 //患者性别 computequotaByPatientSex(); break; } case "2": { //患者分组 computequotaByPatientGroup(); break; } case "3": { //患者年龄 computequotaByPatientAge(); break; } } } } } /** * 机构维度下患者性别维度计算指标 */ @Transactional private void computequotaByPatientSex() { jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 6 + "'"); try { //新建任务日志对象 QuartzJobLog QuartzJobLog = new QuartzJobLog(); QuartzJobLog.setJobStartTime(new Date()); QuartzJobLog.setJobId(wlyyJobConfig.getId()); QuartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的机构 List hospitals = hospitalDao.findHospitalzxFWZ(); 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.findByJiatingSignYesterday(yesterday, now); //数组里面第一个是女 第二个是男 第三个是未知 Map> citySexMap = new HashMap>();//key是市行政代码 目前只有厦门市 citySexMap.put(Constant.city, new HashMap()); Map> townSexMap = new HashMap>();//key是区行政代码 Map> orgSexMap = new HashMap>();//key是机构代码 //统计有签约的 Long cityCount = 0L; //统计到市的数目 Long townCount = 0L; //统计到所有区的数目 Long orgCount = 0L;//统计到所有机构的数目 Long qkCount = 0L;//统计到所有全科医生的数目 boolean isAll=true;//是否统计失败 StringBuffer errorContent=new StringBuffer(); for (SignFamily signFamily : signFamilys) { String idcard = signFamily.getIdcard();//得到签约中患者的身份证号 String orgCodeTemp=getOrg(signFamily.getHospital()); Hospital hospital = hospitalsMap.get(orgCodeTemp);//得到患者签约的机构 if(hospital == null) { errorContent.append("签约code:"+signFamily.getCode()+",签约的全科医生(doctor字段)的所属机构(wlyy_doctor表中的hospital字段)为空或者所属的机构数据有问题"); isAll=false; continue; } String town = hospital.getTown();//得到患者签约的机构的区号 String hospitalCode = hospital.getCode();//得到患者签约的机构号 String sex = IdCardUtil.getSexForIdcard(idcard);//根据身份证得到性别 //统计市 目前只统计厦门市 所以先写死 后期再改造 compute_level2_1(citySexMap,Constant.city, sex); cityCount++; //统计区 compute_level2_1(townSexMap,town, sex); townCount++; //统计机构 //统计站 String orgCode=hospital.getCode(); if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){ //统计站 orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00"; compute_level2_1(orgSexMap,orgCodeTemp, sex); } else { //统计社区 compute_level2_1(orgSexMap,hospitalCode, sex); } orgCount++; } //保存统计数据 //保存市统计数据 for (Map.Entry> entry : citySexMap.entrySet()) { for(int i=1;i<4;i++){ String key=i+""; String city=Constant.city; String cityName=Constant.cityName; String town=""; String townName=""; String org=""; String orgName=""; String level="4"; save_level2_1(entry.getValue(), key, city, cityName, town, townName, org, orgName, level); } } //保存区的统计数据 for (Map.Entry townEntry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneTownSexMap = townSexMap.get(townEntry.getKey());//得到当个区的统计数据 Town townObj = townEntry.getValue();//得到区级信息 for(int i=1;i<4;i++){ String key=i+""; String city=Constant.city; String cityName=Constant.cityName; String town=townObj.getCode(); String townName=townObj.getName(); String org=""; String orgName=""; String level="3"; save_level2_1(oneTownSexMap, key, city, cityName, town, townName, org, orgName, level); } } //统计机构 for (Map.Entry hospitalEntry : hospitalsMap.entrySet()) { //判断该机构是否有统计数据 Map oneorgSexMap = orgSexMap.get(hospitalEntry.getKey());//得到当个机构的统计数据 Hospital hospital = hospitalEntry.getValue();//得到区级信息 for(int i=1;i<4;i++){ String key=i+""; String city=Constant.city; String cityName=Constant.cityName; String town=hospital.getTown(); String townName=hospital.getTownName(); String org=hospital.getCode(); String orgName=hospital.getName(); String level="2"; save_level2_1(oneorgSexMap, key, city, cityName, town, townName, org, orgName, level); } } QuartzJobLog.setJobEndTime(new Date()); QuartzJobLog.setJobContent(saveContent(signFamilys,qkCount,orgCount,townCount,cityCount,isAll,errorContent)); QuartzJobLog.setJobType(isAll?"1":"0"); quartzJobLogDao.save(QuartzJobLog); } catch (Exception e) { e.printStackTrace(); } } /** * 机构维度下患者性别维度计算指标 公用保存方法 * @param oneorgSexMap * @param key * @param city * @param cityName * @param town * @param townName * @param org * @param orgName * @param level */ private void save_level2_1(Map oneorgSexMap, String key, String city, String cityName, String town, String townName, String org, String orgName, String level) { WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setCity(city); wlyyQuotaResult.setCityName(cityName); wlyyQuotaResult.setTown(town); wlyyQuotaResult.setTownName(townName); wlyyQuotaResult.setOrgCode(org); wlyyQuotaResult.setOrgName(orgName); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type(level);//机构级 wlyyQuotaResult.setLevel2Type(key); wlyyQuotaResult.setLevel2TypeName(Constant.getLevelSexName(key)); if (oneorgSexMap != null && oneorgSexMap.containsKey(key)) { wlyyQuotaResult.setResult(oneorgSexMap.get(key) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } private void compute_level2_1(Map> citySexMap,String key, String sex) { if (citySexMap.containsKey(key)) { Map sexMap = citySexMap.get(key); sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1); citySexMap.put(key, sexMap); } else { Map sexMap = new HashMap(); sexMap.put(sex, 1L); citySexMap.put(key, sexMap); } } /** * 机构维度患者分组维度计算指标 */ @Transactional private void computequotaByPatientGroup() { jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 7 + "'"); try { //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群 Map> cityGroupMap = new HashMap>();//key是市行政代码 目前只有厦门市 cityGroupMap.put(Constant.city, new HashMap()); Map> townGroupMap = new HashMap>();//key是区行政代码 Map> orgGroupMap = new HashMap>();//key是机构代码 //新建任务日志对象 QuartzJobLog QuartzJobLog = new QuartzJobLog(); QuartzJobLog.setJobStartTime(new Date()); QuartzJobLog.setJobId(wlyyJobConfig.getId()); QuartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的机构 List hospitals = hospitalDao.findHospital2(); Map hospitalsMap = new HashMap(); for (Hospital hospital : hospitals) { hospitalsMap.put(hospital.getCode(), hospital); Map one = new HashMap(); one.put("1", 0L); one.put("2", 0L); one.put("3", 0L); one.put("4", 0L); one.put("5", 0L); one.put("100", 0L); orgGroupMap.put(hospital.getCode(), one); } //查找出厦门市全部的区 List towns = townDao.findByCityCode(Constant.city); Map townsMap = new HashMap(); for (Town town : towns) { townsMap.put(town.getCode(), town); Map one = new HashMap(); one.put("1", 0L); one.put("2", 0L); one.put("3", 0L); one.put("4", 0L); one.put("5", 0L); one.put("100", 0L); townGroupMap.put(town.getCode(), one); } //找出今天的签约信息 List signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now); Long cityCount = 0L; //统计到市的数目 Long townCount = 0L; //统计到所有区的数目 Long orgCount = 0L;//统计到所有机构的数目 Long qkCount = 0L;//统计到所有全科医生的数目 boolean isAll=true;//是否统计失败 StringBuffer errorContent=new StringBuffer(); //统计有签约的 for (SignFamily signFamily : signFamilys) { String patient = signFamily.getPatient(); //设置查看病人所在分组 List dctorPatientGroupInfo = doctorPatientGroupInfoDao.findByMorenPatient(patient); String group ="";//得到该签约病人的所在分组 1 普通 2 慢病 3是 65岁以上人群 4是 高血压 5是糖尿病 100是高血压和糖尿病 if (dctorPatientGroupInfo != null && dctorPatientGroupInfo.size() > 0) { group=dctorPatientGroupInfo.get(0).getGroup(); } else { group="1"; } Hospital hospital = hospitalsMap.get(getOrg(signFamily.getHospital()));//得到患者签约的机构 if(hospital == null) { errorContent.append("签约code:"+signFamily.getCode()+",签约的全科医生(doctor字段)的所属机构(wlyy_doctor表中的hospital字段)为空或者所属的机构数据有问题"); isAll=false; continue; } String town = hospital.getTown(); //统计市 现在只有厦门市 默认先写死 后面再改 compute_level2_2(cityGroupMap, group,Constant.city); cityCount++; //统计区 compute_level2_2(townGroupMap, group,town); townCount++; //统计站 String orgCode=hospital.getCode(); if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){ //统计站 String orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00"; //统计机构 compute_level2_2(orgGroupMap, group,orgCodeTemp); } else { //统计机构 compute_level2_2(orgGroupMap, group,hospital.getCode()); } orgCount++; boolean hasGXY = false;//有高血压 boolean hasTNB = false;//有糖尿病 if ("2".equals(group)) { //如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病 String jsonString = redisTemplate.opsForValue().get("disease:" + patient); if (StringUtils.isEmpty(jsonString)) { continue; } //排除数据 只留下高血压和糖尿病 List jsonObjects = new ArrayList(); JSONArray redisValues = new JSONArray(jsonString); for (Object obj : redisValues) { JSONObject redisValue = (JSONObject)(obj); if(!redisValue.has("signType")){ continue; } //排除掉三师签约 if ("1".equals(redisValue.get("signType").toString())) { continue; } String disease = redisValue.getString("disease"); if ("1".equals(disease)) { jsonObjects.add(redisValue); hasGXY = true;//设置有高血压 } if ("2".equals(disease)) { jsonObjects.add(redisValue); hasTNB = true;//设置有糖尿病 } } if(jsonObjects.size()==0){ continue;//如果没有高血压和糖尿病 不统计 } if (hasGXY && hasTNB) { group = "100";//有高血压又有糖尿病 } else if(hasGXY){ group = 4 + "";//4高血压,5糖尿病 }else if(hasTNB){ group = 5 + "";//4高血压,5糖尿病 } //统计市 现在只有厦门市 默认先写死 后面再改 compute_level2_2(cityGroupMap, group,Constant.city); //统计区 compute_level2_2(townGroupMap, group,town); //统计站 orgCode=hospital.getCode(); if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){ //统计站 String orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00"; //统计机构 compute_level2_2(orgGroupMap, group,orgCodeTemp); } else { //统计机构 compute_level2_2(orgGroupMap, group,hospital.getCode()); } } } //保存统计数据 //保存市的统计数据 for (Map.Entry> entry : cityGroupMap.entrySet()) { //保存健康人群 Map oneMap=entry.getValue(); for(Map.Entry entryCh: oneMap.entrySet()){ String city=entry.getKey(); String cityName=Constant.cityName; String town=""; String townName=""; String org=""; String orgName=""; String level="4"; String key=entryCh.getKey(); save_level2_2(oneMap, city, cityName, town, townName, org, orgName, level, key); } } //保存区级 //保存区的统计数据 for (Map.Entry townEntry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneTownGroupMap = townGroupMap.get(townEntry.getKey());//得到当个区的统计数据 Town townObj = townEntry.getValue();//得到区级信息 for(Map.Entry entryCh: oneTownGroupMap.entrySet()){ String city=entryCh.getKey(); String cityName=Constant.cityName; String town=townObj.getCode(); String townName=townObj.getName(); String org=""; String orgName=""; String level="3"; String key=entryCh.getKey(); save_level2_2(oneTownGroupMap, city, cityName, town, townName, org, orgName, level, key); } } //保存机构 for (Map.Entry hospitalEntry : hospitalsMap.entrySet()) { //判断该机构是否有统计数据 Map oneOrgGroupMap = orgGroupMap.get(hospitalEntry.getKey());//得到当个机构的统计数据 Hospital hospital = hospitalEntry.getValue();//得到区级信息 for(Map.Entry entryCh: oneOrgGroupMap.entrySet()){ String city=entryCh.getKey(); String cityName=Constant.cityName; String town=hospital.getTown(); String townName=hospital.getTownName(); String org=hospital.getCode(); String orgName=hospital.getName(); String level="2"; String key=entryCh.getKey(); save_level2_2(oneOrgGroupMap, city, cityName, town, townName, org, orgName, level, key); } } QuartzJobLog.setJobEndTime(new Date()); QuartzJobLog.setJobContent(saveContent(signFamilys,qkCount,orgCount,townCount,cityCount,isAll,errorContent)); QuartzJobLog.setJobType(isAll?"1":"0"); quartzJobLogDao.save(QuartzJobLog); } catch (Exception e) { e.printStackTrace(); } } private void save_level2_2(Map oneMap, String city, String cityName, String town, String townName, String org, String orgName, String level, String key) { WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setCity(city); wlyyQuotaResult.setCityName(cityName); wlyyQuotaResult.setTown(town); wlyyQuotaResult.setTownName(townName); wlyyQuotaResult.setOrgCode(org); wlyyQuotaResult.setOrgName(orgName); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type(level);//市级 wlyyQuotaResult.setLevel2Type(key); wlyyQuotaResult.setLevel2TypeName(Constant.getLevelGroupName(key)); if (oneMap != null && oneMap.containsKey(key)) { wlyyQuotaResult.setResult(oneMap.get(key) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } private void compute_level2_2(Map> cityGroupMap, String group,String key) { if (cityGroupMap.containsKey(key)) { Map groupMapTemp = cityGroupMap.get(key); groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1); cityGroupMap.put(key, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); cityGroupMap.put(key, groupMapTemp); } } /** * 机构维度患者年龄维度计算指标 */ @Transactional private void computequotaByPatientAge() { try { jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 8 + "'"); //新建任务日志对象 QuartzJobLog QuartzJobLog = new QuartzJobLog(); QuartzJobLog.setJobStartTime(new Date()); QuartzJobLog.setJobId(wlyyJobConfig.getId()); QuartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的机构 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.findByJiatingSignYesterday(yesterday, now); //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群 Map> cityAgeMap = new HashMap>();//key是市行政代码 目前只有厦门市 cityAgeMap.put(Constant.city, new HashMap()); Map> townAgeMap = new HashMap>();//key是区行政代码 Map> orgAgeMap = new HashMap>();//key是机构代码 //统计有签约的 Long cityCount = 0L; //统计到市的数目 Long townCount = 0L; //统计到所有区的数目 Long orgCount = 0L;//统计到所有机构的数目 Long qkCount = 0L;//统计到所有全科医生的数目 boolean isAll=true;//是否统计失败 StringBuffer errorContent=new StringBuffer(); //统计有签约的 for (SignFamily signFamily : signFamilys) { String orgCodeTemp=getOrg(signFamily.getHospital()); Hospital hospital = hospitalsMap.get(orgCodeTemp);//得到患者签约的机构 if(hospital == null) { errorContent.append("签约code:"+signFamily.getCode()+",签约的全科医生(doctor字段)的所属机构(wlyy_doctor表中的hospital字段)为空或者所属的机构数据有问题"); isAll=false; continue; } String town = hospital.getTown(); int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄 String ageCode = getAgeCode(age);//得到年龄的code //统计市 compute_level2_3(cityAgeMap, ageCode,Constant.city); cityCount++; //统计区 compute_level2_3(townAgeMap, ageCode,town); townCount++; //统计站 String orgCode=hospital.getCode(); if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){ //统计站 orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00"; //统计机构 compute_level2_3(orgAgeMap, ageCode,orgCodeTemp); } else { //统计机构 compute_level2_3(orgAgeMap, ageCode,hospital.getCode()); } orgCount++; } //保存统计数据 // 保存市的统计数据 for (Map.Entry> entry : cityAgeMap.entrySet()) { Map oneAgeMap = entry.getValue(); for(int i=1;i<7;i++){ String city=Constant.city; String cityName=Constant.cityName; String town=""; String townName=""; String org=""; String orgName=""; String level="4"; String key=i+""; save_level2_3(oneAgeMap, city, cityName, town, townName, org, orgName, level, key); } } //保存区级 for (Map.Entry entry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据 Town townObj = entry.getValue();//得到区级信息 for(int i=1;i<7;i++){ String city=Constant.city; String cityName=Constant.cityName; String town=townObj.getCode(); String townName=townObj.getName(); String org=""; String orgName=""; String level="3"; String key=i+""; save_level2_3(oneAgeMap, city, cityName, town, townName, org, orgName, level, key); } } //保存机构 for (Map.Entry hospitalEntry : hospitalsMap.entrySet()) { //判断该机构是否有统计数据 Map oneAgeMap = orgAgeMap.get(hospitalEntry.getKey());//得到当个机构的统计数据 Hospital hospital = hospitalEntry.getValue();//得到区级信息 for(int i=1;i<7;i++){ String city=Constant.city; String cityName=Constant.cityName; String town=hospital.getTown(); String townName=hospital.getTownName(); String org=hospital.getCode(); String orgName=hospital.getName(); String level="2"; String key=i+""; save_level2_3(oneAgeMap, city, cityName, town, townName, org, orgName, level, key); } } QuartzJobLog.setJobEndTime(new Date()); QuartzJobLog.setJobContent(saveContent(signFamilys,qkCount,orgCount,townCount,cityCount,isAll,errorContent)); QuartzJobLog.setJobType(isAll?"1":"0"); quartzJobLogDao.save(QuartzJobLog); } catch (Exception e) { e.printStackTrace(); } } private void save_level2_3(Map oneAgeMap, String city, String cityName, String town, String townName, String org, String orgName, String level, String key) { WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setCity(city); wlyyQuotaResult.setCityName(cityName); wlyyQuotaResult.setTown(town); wlyyQuotaResult.setTownName(townName); wlyyQuotaResult.setOrgCode(org); wlyyQuotaResult.setOrgName(orgName); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setLevel1Type(level);//市级 wlyyQuotaResult.setLevel2Type(key); wlyyQuotaResult.setLevel2TypeName(Constant.getLevelAgeName(key)); if (oneAgeMap != null && oneAgeMap.containsKey(key)) { wlyyQuotaResult.setResult(oneAgeMap.get(key) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } private void compute_level2_3(Map> cityAgeMap, String ageCode,String key) { if (cityAgeMap.containsKey(key)) { Map groupMapTemp = cityAgeMap.get(key); groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1); cityAgeMap.put(key, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(ageCode, 1L); cityAgeMap.put(key, groupMapTemp); } } /** * 机构维度计算指标 */ @Transactional private void computequota() { jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 1 + "'"); //新建任务日志对象 QuartzJobLog QuartzJobLog = new QuartzJobLog(); QuartzJobLog.setJobStartTime(new Date()); QuartzJobLog.setJobId(wlyyJobConfig.getId()); QuartzJobLog.setJobName(wlyyJobConfig.getJobName()); //查找出系统全部的全科医生 List adminTeams=doctorAdminTeamDao.findAllTeam(); Map adminTeamMap = new HashMap(); for (AdminTeam adminTeam : adminTeams) { adminTeamMap.put(adminTeam.getId()+"", adminTeam); } //查找出系统全部的机构 List hospitals = hospitalDao.findHospitalzxFWZ(); 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); } //找出今天的签约信息 yesterday,now List signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now); Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjAdminTeamMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode Long cityCount = 0L; //统计到市的数目 Long townCount = 0L; //统计到所有区的数目 Long orgCount = 0L;//统计到所有机构的数目 Long qkCount = 0L;//统计到所有全科医生的数目 boolean isAll=true;//是否统计失败 StringBuffer errorContent=new StringBuffer(); //统计有签约的 for (SignFamily signFamily : signFamilys) { String orgCode = signFamily.getHospital(); String orgCodeTemp=""; if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){ //站 orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00"; }else{ //社区 orgCodeTemp=orgCode; } Hospital hospital=hospitalsMap.get(orgCodeTemp); if(hospital == null) { errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的hospital数据异常"); isAll=false; continue; } AdminTeam adminTeam=adminTeamMap.get(signFamily.getAdminTeamId()+""); if(adminTeam == null) { errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的Admin_Team_Id数据异常"); isAll=false; continue; } //统计市 ---------------start-------------- cityCount++; //统计区 ---------------start-------------- String townCode = hospital.getTown(); compute_level1(tjTownMap, townCode); townCount++; //统计机构---------------start-------------- compute_level1(tjOrgMap, orgCodeTemp); orgCount++; //统计团队 ---------------start-------------- String adminTeamId = signFamily.getAdminTeamId()+""; compute_level1(tjAdminTeamMap, adminTeamId); qkCount++; } //保存统计的结果 for (Map.Entry entry : adminTeamMap.entrySet()) { AdminTeam adminTeam = adminTeamMap.get(entry.getKey());//得到全科医生 String orgCodeTemp=getOrg(adminTeam.getOrgCode()); Hospital hospital = hospitalsMap.get(orgCodeTemp);//得到全科医生的机构 if(hospital == null) continue; String city=Constant.city; String cityName=Constant.cityName; String town=hospital.getTown(); String townName=hospital.getTownName(); String org=hospital.getCode(); if(!"00".equals(hospital.getCode().substring(hospital.getCode().length()-2,hospital.getCode().length()))){ //统计站 org=hospital.getCode().substring(0,hospital.getCode().length()-2)+"00"; } String orgName=hospital.getName(); String doctorCode=adminTeam.getId()+""; String doctorName=adminTeam.getName(); String doctorJob=""; String level="1"; String key=adminTeam.getId()+""; save_level1(tjAdminTeamMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level); } //保存机构的签约统计 for (Map.Entry entry : hospitalsMap.entrySet()) { Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生 if(hospital == null) continue; String city=Constant.city; String cityName=Constant.cityName; String town=hospital.getTown(); String townName=hospital.getTownName(); String org=hospital.getCode(); String orgName=hospital.getName(); String doctorCode=""; String doctorName=""; String doctorJob=""; String level="2"; String key=hospital.getCode(); save_level1(tjOrgMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level); } //保存区级的签约统计 for (Map.Entry entry : townsMap.entrySet()) { Town townObj = townsMap.get(entry.getKey());//得到全科医生 String city=Constant.city; String cityName=Constant.cityName; String town=townObj.getCode(); String townName=townObj.getName(); String org=""; String orgName=""; String doctorCode=""; String doctorName=""; String doctorJob=""; String level="3"; String key=townObj.getCode(); save_level1(tjTownMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level); } //保存市级的统计 { 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(saveContent(signFamilys,qkCount,orgCount,townCount,cityCount,isAll,errorContent)); QuartzJobLog.setJobType(isAll?"1":"0"); quartzJobLogDao.save(QuartzJobLog); } /** * 统计签约的公用保存方案 * */ private void save_level1(Map countMap, String key, String city, String cityName, String town, String townName, String org, String orgName, String doctorCode, String doctorName, String doctorJob, String level) { WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult(); wlyyQuotaResult.setDel("1"); wlyyQuotaResult.setOrgCode(org); wlyyQuotaResult.setOrgName(orgName); wlyyQuotaResult.setCity(city); wlyyQuotaResult.setCityName(cityName); wlyyQuotaResult.setQuatoCode(wlyyQuota.getId()); wlyyQuotaResult.setQuatoName(wlyyQuota.getName()); wlyyQuotaResult.setQuotaDate(getYesterday()); wlyyQuotaResult.setCreateTime(new Date()); wlyyQuotaResult.setQkdoctorJobName(doctorJob); wlyyQuotaResult.setQkdoctorName(doctorName); wlyyQuotaResult.setQkdoctorCode(doctorCode); wlyyQuotaResult.setTown(town); wlyyQuotaResult.setTownName(townName); wlyyQuotaResult.setLevel1Type(level); //判断全科医生是否有解约量 if (countMap.containsKey(key)) { wlyyQuotaResult.setResult(countMap.get(key) + ""); } else { wlyyQuotaResult.setResult("0"); } wlyyQuotaResultDao.save(wlyyQuotaResult); } /** * 统计签约的公用统计方案 * @param tjQkdoctorMap * @param doctorCode */ private void compute_level1(Map tjQkdoctorMap, String doctorCode) { if (tjQkdoctorMap.containsKey(doctorCode)) { tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1); } else { tjQkdoctorMap.put(doctorCode, 1L); } } /* 得到昨天的日期字符串 yyyy-MM-dd */ public String getYesterday() { return yesterday; } /** * 根据年龄得到对应的code * * @param age * @return */ public String getAgeCode(int age) { if (age < 7) { return Constant.level_age_1; } else if (age >= 7 && age < 18) { return Constant.level_age_2; } else if (age >= 18 && age < 30) { return Constant.level_age_3; } else if (age >= 30 && age < 50) { return Constant.level_age_4; } else if (age >= 50 && age < 65) { return Constant.level_age_5; } else { return Constant.level_age_6; } } public static String getDayString(Integer size) { Date date = new Date();//取时间 Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(calendar.DATE, size);//把日期往后增加一天.整数往后推,负数往前移动 date = calendar.getTime(); //这个时间就是日期往后推一天的结果 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String dateString = formatter.format(date); return dateString; } private String getOrg(String org){ //if(!"00".equals(org.substring(org.length()-2,org.length()))){ if(org.length() == 10 && !org.endsWith("00")){ return org.substring(0,org.length()-2)+"00"; }else{ return org; } } private String saveContent(List signFamilys, Long qkCount, Long orgCount, Long townCount, Long cityCount, boolean isAll, StringBuffer errorContent) { StringBuffer string=new StringBuffer("统计"+getYesterday()+" 的待签约数据完成 ,数据库查询到待签约数目:"+signFamilys.size()); string.append(",统计到市的数据总数:"+cityCount); string.append(",统计到区的数据总数:"+townCount); string.append(",统计到机构的数据总数:"+orgCount); string.append(",统计到团队的数据总数:"+qkCount); string.append(",是否统计成功:"+isAll); if(!isAll){ string.append(",失败原因:"+errorContent); } return string.toString(); } }