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.doctor.team.sign.DoctorPatientGroupInfo; import com.yihu.wlyy.entity.job.QuartzJobLog; import com.yihu.wlyy.entity.patient.Patient; import com.yihu.wlyy.entity.patient.PatientHealthGuidance; import com.yihu.wlyy.entity.patient.SignFamily; 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.doctor.DoctorPatientGroupInfoDao; import com.yihu.wlyy.repository.job.QuartzJobLogDao; import com.yihu.wlyy.repository.organization.HospitalDao; import com.yihu.wlyy.repository.patient.PatientDao; import com.yihu.wlyy.repository.patient.PatientHealthGuidanceDao; import com.yihu.wlyy.repository.patient.SignFamilyDao; import com.yihu.wlyy.util.DateUtil; import com.yihu.wlyy.util.IdCardUtil; import org.json.JSONArray; import org.json.JSONObject; import org.quartz.Job; 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.util.StringUtils; import org.springframework.web.context.support.SpringBeanAutowiringSupport; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.*; /** * 实时统计今天的数据 */ @Component public class CurrentDayAllQuotaJob implements Job { @Autowired private SignFamilyDao signFamilyDao; @Autowired private DoctorDao doctorDao; @Autowired private HospitalDao hospitalDao; @Autowired private TownDao townDao; @Autowired private StringRedisTemplate redisTemplate; @Autowired private ConsultTeamDao consultTeamDao; @Autowired private PatientHealthGuidanceDao patientHealthGuidanceDao; @Autowired private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao; @Autowired private PatientDao patientDao; @Autowired private QuartzJobLogDao quartzJobLogDao;//执行日志Dao private org.apache.tomcat.jdbc.pool.DataSource fvdataSource = new org.apache.tomcat.jdbc.pool.DataSource();//随访数据源 private JdbcTemplate jdbcTemplate = new JdbcTemplate(); private Properties systemProperties; List towns = null;//厦门市全部的区 List hospitals = null;//系统全部的机构 List qkdoctors = null;//系统全部的全科医生 List jkglsdoctors = null;//系统全部的健康管理师 Map hospitalsMap = new HashMap(); Map jkglsdoctorsMap = new HashMap(); Map qkdoctorsMap = new HashMap(); Map townsMap = new HashMap(); @Override public void execute(JobExecutionContext context) throws JobExecutionException { try { SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); getSystemProperties(); fvdataSource.setDriverClassName(systemProperties.get("fv.jdbc.driver").toString()); fvdataSource.setUrl(systemProperties.get("fv.jdbc.url").toString()); fvdataSource.setUsername(systemProperties.get("fv.jdbc.username").toString()); fvdataSource.setPassword(systemProperties.get("fv.jdbc.password").toString()); jdbcTemplate.setDataSource(fvdataSource);//初始化随访的数据源 towns = townDao.findByCityCode(Constant.city); //查找出厦门市全部的区 hospitals = hospitalDao.findHospitalzxFWZ(); //查找出系统全部的机构 for (Hospital hospital : hospitals) { hospitalsMap.put(hospital.getCode(), hospital); } qkdoctors = doctorDao.findAllQKDoctot();//查找出系统全部的全科医生 for (Doctor doctor : qkdoctors) { qkdoctorsMap.put(doctor.getCode(), doctor); } jkglsdoctors = doctorDao.findAllZKDoctot();//查找出系统全部的全科医生 for (Doctor doctor : jkglsdoctors) { jkglsdoctorsMap.put(doctor.getCode(), doctor); } for (Town town : towns) { townsMap.put(town.getCode(), town); } //计算指标 computequota(); }catch (Exception e){ e.printStackTrace(); } } //统计 private void computequota() throws Exception { QuartzJobLog quartzJobLog =new QuartzJobLog(); quartzJobLog.setJobStartTime(new Date()); computequota_1(); //统计今天的签约 computequota_2(); //统计今天的解约 computequota_3(); //统计今天的健康咨询量 computequota_4(); //统计今天的随访量 computequota_5(); //统计今天的健康指导 computequota_6(); //统计今天的签约患者性别 computequota_7();//统计今天的签约患者分组 computequota_8();//统计今天的签约患者年龄 computequota_9();//统计今天的待签约 computequota_10();//统计今天的改签 computequota_12();//统计今天的签约下按年龄分组后再 quartzJobLog.setJobContent("开始实时统计查询"); quartzJobLog.setJobName("实时统计"); quartzJobLog.setJobId("11"); quartzJobLog.setJobType("1"); quartzJobLog.setJobEndTime(new Date()); quartzJobLogDao.save(quartzJobLog); } private void computequota_12() throws Exception{ String now = getDayString(0); String tomorrow = getDayString(1); //找出今天的签约信息 yesterday,now //查找出系统全部的机构 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(now, tomorrow); //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群 Map> cityAgeMap = new HashMap>();//key是市行政代码 目前只有厦门市 Map temp =new HashMap(); cityAgeMap.put(Constant.city, temp); Map> townAgeMap = new HashMap>();//key是区行政代码 Map> orgAgeMap = new HashMap>();//key是机构代码 //统计有签约的 for (SignFamily signFamily : signFamilys) { Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构 String town = hospital.getTown(); int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄 String ageCode = getAgeCode(age);//得到年龄的code boolean hasGXY = false;//有高血压 boolean hasTNB = false;//有糖尿病 //如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病 糖尿病和高血压是100 String diseaseType=""; String jsonString = redisTemplate.opsForValue().get("disease:" + signFamily.getPatient()); if (StringUtils.isEmpty(jsonString)) { continue; } //排除数据 只留下高血压和糖尿病 List jsonObjects = new ArrayList(); JSONArray redisValues = new JSONArray(jsonString); for (Object obj : redisValues) { JSONObject redisValue = new JSONObject(obj); //排除掉三师签约 if ("1".equals(redisValue.get("signType").toString())) { continue; } String disease = redisValue.get("disease").toString(); if (Integer.valueOf(disease).equals("1")) { jsonObjects.add(redisValue); hasGXY = true;//设置有高血压 diseaseType="1"; } if (Integer.valueOf(disease).equals("2")) { jsonObjects.add(redisValue); hasTNB = true;//设置有糖尿病 diseaseType="2"; } } if(hasGXY&&hasTNB){ diseaseType="100"; } //统计市 compute(cityAgeMap, Constant.city, ageCode, diseaseType); //统计区 compute(townAgeMap, town, ageCode, diseaseType); //统计机构 //统计站 if (!"00".equals(hospital.getCode().substring(8))) { String orgCodeTemp = hospital.getCode().substring(0, 8) + "00"; //统计机构 compute(orgAgeMap, orgCodeTemp, ageCode, diseaseType); } else { compute(orgAgeMap, hospital.getCode(), ageCode, diseaseType); } } //保存市级数据 for (Map.Entry> entry : cityAgeMap.entrySet()) { Map oneAgeMap = entry.getValue(); for(int i=1;i<7;i++){ for(int j=1;j<4;j++){ String key_2=i+""; String key_3=j+""; String name=Constant.cityName; JSONObject jsonObject=new JSONObject(); if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) { Map key3Map=oneAgeMap.get(key_2); if(key3Map!=null&&key3Map.containsKey(key_3)){ jsonObject.put("num",entry.getValue().get((key3Map.get(key_3) + ""))); }else{ jsonObject.put("num",0); } } else { jsonObject.put("num",0); } jsonObject.put("name",name); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:12:4:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString()); } } } //保存区级 for (Map.Entry entry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据 Town townObj = entry.getValue();//得到区级信息 for(int i=1;i<7;i++){ for(int j=1;j<4;j++){ String key_2=i+""; String key_3=j+""; String name=townObj.getName(); JSONObject jsonObject=new JSONObject(); if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) { Map key3Map=oneAgeMap.get(key_2); if(key3Map!=null&&key3Map.containsKey(key_3)){ jsonObject.put("num",(key3Map.get(key_3) + "")); }else{ jsonObject.put("num",0); } } else { jsonObject.put("num",0); } jsonObject.put("name",townObj.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:12:3:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString()); } } } //保存机构级 for (Map.Entry entry : hospitalsMap.entrySet()) { //判断该机构是否有统计数据 Map oneAgeMap = orgAgeMap.get(entry.getKey());//得到当个机构的统计数据 Hospital hospital = entry.getValue();//得到机构信息 for(int i=1;i<7;i++){ for(int j=1;j<4;j++){ String key_2=i+""; String key_3=j+""; String name=hospital.getName(); JSONObject jsonObject=new JSONObject(); if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) { Map key3Map=oneAgeMap.get(key_2); if(key3Map!=null&&key3Map.containsKey(key_3)){ jsonObject.put("num",(key3Map.get(key_3) + "")); }else{ jsonObject.put("num",0); } } else { jsonObject.put("num",0); } jsonObject.put("name",name); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:12:2:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString()); } } } } private void compute(Map> rootMap, String rootKey, String ageCode, String diseaseType) { if (rootMap.containsKey(rootKey)) { //得到市下面的所有的年龄map Map groupMapTemp = rootMap.get(rootKey); if(groupMapTemp.containsKey(ageCode)){ //得到这个年龄下的患者map Map mape= groupMapTemp.get(ageCode); if(mape.containsKey(diseaseType)){ mape.put(diseaseType,mape.get(diseaseType)+1L); }else{ mape.put(diseaseType,1L); } }else{ //新增疾病的统计map Map groupMapTemp1 = new HashMap(); groupMapTemp1.put(diseaseType, 1L); groupMapTemp.put(ageCode,groupMapTemp1); } } else { //没有就新建统计数据 新增疾病的统计map Map groupMapTemp = new HashMap(); groupMapTemp.put(diseaseType, 1L); //把统计疾病的map放入对应的年龄组map中 Map groupMapTemp2 = new HashMap(); groupMapTemp2.put(ageCode,groupMapTemp); //把年龄组map放入市的map里面 rootMap.put(rootKey, groupMapTemp2); } } private void computequota_1() { //签约需要的统计map Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode initMap(tjCityMap, tjTownMap, tjOrgMap, tjQkdoctorMap, null); //找出今天的签约信息 yesterday,now String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingSignYesterday(now, tomorrow); //统计有签约的 for (SignFamily signFamily : signFamilys) { String hospitalCode=signFamily.getHospital(); Hospital hospital=hospitalsMap.get(hospitalCode); //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(hospital.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 //判断是中心还是服务站 服务站的话添加到中心去 if(!"00".equals(hospital.getCode().substring(8))){ String orgCodeTemp=hospital.getCode().substring(0,8)+"00"; JSONObject orgjo=tjOrgMap.get(orgCodeTemp); orgjo.put("num",((int)orgjo.get("num"))+1); }else{ JSONObject orgjo=tjOrgMap.get(hospital.getCode()); orgjo.put("num",((int)orgjo.get("num"))+1); } //统计全科医生 JSONObject qkjo=tjQkdoctorMap.get(signFamily.getDoctor()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //数据保存到redis //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:1:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:1:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:1:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjQkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:1:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void initMap(Map tjCityMap, Map tjTownMap, Map tjOrgMap, Map tjQkdoctorMap, Map tjJKdoctorMap) { JSONObject jo=new JSONObject(); jo.put("name", Constant.cityName); jo.put("num",0); tjCityMap.put(Constant.city,jo); for(Town town:towns){ jo=new JSONObject(); jo.put("name",town.getName()); jo.put("num",0); jo.put("date", DateUtil.dateToStrLong(new Date())); tjTownMap.put(town.getCode(),jo); } for(Hospital hospital:hospitals){ jo=new JSONObject(); jo.put("name",hospital.getName()); jo.put("num",0); jo.put("date", DateUtil.dateToStrLong(new Date())); tjOrgMap.put(hospital.getCode(),jo); } if (tjQkdoctorMap!=null){ for(Doctor doctor:qkdoctors){ jo=new JSONObject(); jo.put("name",doctor.getName()); jo.put("num",0); jo.put("date", DateUtil.dateToStrLong(new Date())); tjQkdoctorMap.put(doctor.getCode(),jo); } } if(tjJKdoctorMap!=null){ for(Doctor doctor:jkglsdoctors){ jo=new JSONObject(); jo.put("name",doctor.getName()); jo.put("num",0); jo.put("date", DateUtil.dateToStrLong(new Date())); tjJKdoctorMap.put(doctor.getCode(),jo); } } } private void computequota_2() { //签约需要的统计map Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode initMap(tjCityMap, tjTownMap, tjOrgMap, tjQkdoctorMap, null); String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingUnSignYesterday(now, tomorrow); //统计有签约的 for (SignFamily signFamily : signFamilys) { String hospitalCode=signFamily.getHospital(); Hospital hospital=hospitalsMap.get(hospitalCode); //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(hospital.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 //判断是中心还是服务站 服务站的话添加到中心去 if(!"00".equals(hospital.getCode().substring(8))){ String orgCodeTemp=hospital.getCode().substring(0,8)+"00"; JSONObject orgjo=tjOrgMap.get(orgCodeTemp); orgjo.put("num",((int)orgjo.get("num"))+1); }else{ JSONObject orgjo=tjOrgMap.get(hospital.getCode()); orgjo.put("num",((int)orgjo.get("num"))+1); } //统计全科医生 JSONObject qkjo=tjQkdoctorMap.get(signFamily.getDoctor()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //数据保存到redis //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:2:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:2:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:2:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjQkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:2:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void computequota_3() { //签约需要的统计map Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjJkdoctorMap = new HashMap();//全部的健康管理师 initMap(tjCityMap, tjTownMap, tjOrgMap, null, tjJkdoctorMap); String now = getDayString(0); String tomorrow = getDayString(1); List consultTeams = consultTeamDao.findByCzrqyYesterday(now,tomorrow); //统计 for (ConsultTeam consultTeam : consultTeams) { String doctorCode=consultTeam.getDoctor(); Doctor doctor=jkglsdoctorsMap.get(doctorCode);//得到健康管理师 if(doctor==null){ continue; } //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(doctor.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 JSONObject orgjo=tjOrgMap.get(doctor.getHospital()); orgjo.put("num",((int)orgjo.get("num"))+1); //统计全科医生 JSONObject qkjo=tjJkdoctorMap.get(doctor.getCode()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //数据保存到redis //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:3:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:3:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:3:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjJkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:3:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void computequota_4() { Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjJkdoctorMap = new HashMap();//全部的健康管理师 initMap(tjCityMap, tjTownMap, tjOrgMap, null, tjJkdoctorMap); //找出今天的随访信息 List> plans = getFvYesterday(); //统计有随访的 for (Map plan : plans) { String doctorCode = (String) plan.get("doctor_uid");//得到随访中健康医生的code Doctor doctor=jkglsdoctorsMap.get(doctorCode);//得到健康管理师 if(doctor==null){ continue; } //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(doctor.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 JSONObject orgjo=tjOrgMap.get(doctor.getHospital()); orgjo.put("num",((int)orgjo.get("num"))+1); //统计全科医生 JSONObject qkjo=tjJkdoctorMap.get(doctor.getCode()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:4:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:4:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:4:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjJkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:4:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void computequota_5() { Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode Map tjJkdoctorMap = new HashMap();//全部的健康管理师 initMap(tjCityMap, tjTownMap, tjOrgMap, tjQkdoctorMap, tjJkdoctorMap); //找出今天的健康指导信息 String now = getDayString(0); String tomorrow = getDayString(1); List patientHealthGuidances = patientHealthGuidanceDao.findByCzrqyYesterday(now,tomorrow); for (PatientHealthGuidance patientHealthGuidance: patientHealthGuidances) { String doctorCode =patientHealthGuidance.getDoctor(); Doctor doctor=jkglsdoctorsMap.get(doctorCode);//得到健康管理师 if(doctor==null){ doctor=qkdoctorsMap.get(doctorCode);//得到全科医生 if(doctor==null){ continue; } } //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(doctor.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 JSONObject orgjo=tjOrgMap.get(doctor.getHospital()); orgjo.put("num",((int)orgjo.get("num"))+1); //统计全科医生 JSONObject qkjo=tjQkdoctorMap.get(doctor.getCode()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:5:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:5:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:5:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjQkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:5:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void computequota_6() throws Exception { String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingSignYesterday(now, tomorrow); //统计有签约的 Map> citySexMap = new HashMap>();//key是市行政代码 目前只有厦门市 citySexMap.put(Constant.city,new HashMap()); Map> townSexMap = new HashMap>();//key是区行政代码 Map> orgSexMap = new HashMap>();//key是机构代码 for (SignFamily signFamily : signFamilys) { String idcard = signFamily.getIdcard();//得到签约中患者的身份证号 Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构 if(hospital==null){ continue; } String town = hospital.getTown();//得到患者签约的机构的区号 String hospitalCode = hospital.getCode();//得到患者签约的机构号 String sex = IdCardUtil.getSexForIdcard(idcard);//根据身份证得到性别 //统计市 目前只统计厦门市 所以先写死 后期再改造 if (citySexMap.containsKey(Constant.city)) { Map sexMap = citySexMap.get(Constant.city); sexMap.put(sex, (sexMap.get(sex)==null?0l:sexMap.get(sex)) + 1); citySexMap.put(Constant.city, sexMap); } else { Map sexMap = new HashMap(); sexMap.put(sex, 1L); citySexMap.put(Constant.city, sexMap); } //统计区 if (townSexMap.containsKey(town)) { Map sexMap = townSexMap.get(town); sexMap.put(sex, (sexMap.get(sex)==null?0l:sexMap.get(sex)) + 1); townSexMap.put(town, sexMap); } else { Map sexMap = new HashMap(); sexMap.put(sex, 1L); townSexMap.put(town, sexMap); } //统计机构 if (orgSexMap.containsKey(hospitalCode)) { Map sexMap = orgSexMap.get(hospitalCode); sexMap.put(sex, (sexMap.get(sex)==null?0l:sexMap.get(sex)) + 1); orgSexMap.put(hospitalCode, sexMap); } else { Map sexMap = new HashMap(); sexMap.put(sex, 1L); orgSexMap.put(hospitalCode, sexMap); } } //保存统计数据 //保存市统计数据 for (Map.Entry> entry : citySexMap.entrySet()) { //保存女 JSONObject jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_1)) { jsonObject.put("num",entry.getValue().get(Constant.level_sex_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:4:1:"+entry.getKey()).toString(),jsonObject.toString()); //保存男 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_2)) { jsonObject.put("num",entry.getValue().get(Constant.level_sex_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:4:2:"+entry.getKey()).toString(),jsonObject.toString()); //保存未知 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_3)) { jsonObject.put("num",entry.getValue().get(Constant.level_sex_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:4:3:"+entry.getKey()).toString(),jsonObject.toString()); } //保存区的统计数据 for (Map.Entry townEntry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneTownSexMap = townSexMap.get(townEntry.getKey());//得到当个区的统计数据 Town town = townEntry.getValue();//得到区级信息 //保存女 JSONObject jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_1)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:3:1:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存男 jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_2)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:3:2:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存未知 jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_3)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:3:3:"+townEntry.getKey()).toString(),jsonObject.toString()); } //统计机构 for (Map.Entry hospitalEntry : hospitalsMap.entrySet()) { //判断该区是否有统计数据 Map oneTownSexMap = orgSexMap.get(hospitalEntry.getKey());//得到当个区的统计数据 Hospital town = hospitalEntry.getValue();//得到区级信息 //保存女 JSONObject jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_1)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:2:1:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存男 jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_2)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:2:2:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存未知 jsonObject=new JSONObject(); if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_3)) { jsonObject.put("num",oneTownSexMap.get(Constant.level_sex_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:6:2:3:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); } } private void computequota_7() { String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingSignYesterday(now, tomorrow); //查找出系统全部的患者 List patients = patientDao.findAllSignPatient(); Map patientsMap = new HashMap(); for (Patient patient : patients) { patientsMap.put(patient.getCode(), patient); } Map> cityGroupMap = new HashMap>();//key是市行政代码 目前只有厦门市 cityGroupMap.put(Constant.city,new HashMap()); Map> townGroupMap = new HashMap>();//key是区行政代码 Map> orgGroupMap = new HashMap>();//key是机构代码 //得到所有的签约病人的分组信息 List doctorPatientGroupInfos = doctorPatientGroupInfoDao.findAllPatient(); Map groupMap = new HashMap(); for (DoctorPatientGroupInfo doctorPatientGroupInfo : doctorPatientGroupInfos) { groupMap.put(doctorPatientGroupInfo.getPatient(), doctorPatientGroupInfo.getGroup()); } //统计有签约的 for (SignFamily signFamily : signFamilys) { String patient=signFamily.getPatient(); String group = groupMap.get(patient);//得到该签约病人的所在分组 1 普通 2 慢病 3是 65岁以上人群 Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构 if(hospital==null){ continue; } String town = hospital.getTown(); //统计市 现在只有厦门市 默认先写死 后面再改 if (cityGroupMap.containsKey(Constant.city)) { Map groupMapTemp = cityGroupMap.get(Constant.city); groupMapTemp.put(group,(groupMapTemp.get(group)==null?0l:groupMapTemp.get(group)) + 1); cityGroupMap.put(Constant.city, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); cityGroupMap.put(Constant.city, groupMapTemp); } //统计区 if (townGroupMap.containsKey(town)) { Map groupMapTemp = townGroupMap.get(town); groupMapTemp.put(group, (groupMapTemp.get(group)==null?0l:groupMapTemp.get(group))+ 1); townGroupMap.put(town, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); townGroupMap.put(town, groupMapTemp); } //统计机构 if (orgGroupMap.containsKey(hospital.getCode())) { Map groupMapTemp = orgGroupMap.get(hospital.getCode()); groupMapTemp.put(group, (groupMapTemp.get(group)==null?0l:groupMapTemp.get(group)) + 1); orgGroupMap.put(hospital.getCode(), groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); orgGroupMap.put(hospital.getCode(), groupMapTemp); } 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 = new JSONObject(obj); //排除掉三师签约 if ("1".equals(redisValue.get("signType").toString())) { continue; } String disease = redisValue.get("disease").toString(); if (Integer.valueOf(disease).equals("1")) { jsonObjects.add(redisValue); hasGXY = true;//设置有高血压 } if (Integer.valueOf(disease).equals("2")) { jsonObjects.add(redisValue); hasTNB = true;//设置有糖尿病 } } if(jsonObjects.size()==0){ continue;//如果没有高血压和糖尿病 不统计 } if (hasGXY && hasTNB) { group = "100";//有高血压又有糖尿病 } else { group = Integer.valueOf(jsonObjects.get(0).get("disease").toString()) + 3 + "";//4高血压,5糖尿病 } if (cityGroupMap.containsKey(Constant.city)) { Map groupMapTemp = cityGroupMap.get(Constant.city); groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1); cityGroupMap.put(Constant.city, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); cityGroupMap.put(Constant.city, groupMapTemp); } //统计区 if (townGroupMap.containsKey(town)) { Map groupMapTemp = townGroupMap.get(town); groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1); townGroupMap.put(town, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); townGroupMap.put(town, groupMapTemp); } //统计机构 //统计站 if (!"00".equals(hospital.getCode().substring(8))) { String orgCodeTemp = hospital.getCode().substring(0, 8) + "00"; //统计机构 if (orgGroupMap.containsKey(orgCodeTemp)) { Map groupMapTemp = orgGroupMap.get(orgCodeTemp); groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1); orgGroupMap.put(orgCodeTemp, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); orgGroupMap.put(orgCodeTemp, groupMapTemp); } } else { //统计机构 if (orgGroupMap.containsKey(hospital.getCode())) { Map groupMapTemp = orgGroupMap.get(hospital.getCode()); groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1); orgGroupMap.put(hospital.getCode(), groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(group, 1L); orgGroupMap.put(hospital.getCode(), groupMapTemp); } } } } //保存统计数据 //保存市的统计数据 for (Map.Entry> entry : cityGroupMap.entrySet()) { //保存健康人群 JSONObject jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_1)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:1:"+entry.getKey()).toString(),jsonObject.toString()); //保存慢病人群 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_2)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:2:"+entry.getKey()).toString(),jsonObject.toString()); //保存65岁以上人群 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_3)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:3:"+entry.getKey()).toString(),jsonObject.toString()); //保存高血压 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_4)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:4:"+entry.getKey()).toString(),jsonObject.toString()); //保存糖尿病 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_5)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:5:"+entry.getKey()).toString(),jsonObject.toString()); //保存糖尿病和高血压 jsonObject=new JSONObject(); if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_100)) { jsonObject.put("num",entry.getValue().get(Constant.level_group_100)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:4:100:"+entry.getKey()).toString(),jsonObject.toString()); } //保存区级 //保存区的统计数据 for (Map.Entry townEntry : townsMap.entrySet()) {//保存健康人群 JSONObject jsonObject=new JSONObject(); Town town=townsMap.get(townEntry.getKey()); Map oneTown= townGroupMap.get(townEntry.getKey()); if (oneTown != null && oneTown.containsKey(Constant.level_group_1)) { jsonObject.put("num",oneTown.get(Constant.level_group_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:1:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存慢病人群 jsonObject=new JSONObject(); if (oneTown != null && oneTown.containsKey(Constant.level_group_2)) { jsonObject.put("num",oneTown.get(Constant.level_group_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:2:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存65岁以上人群 jsonObject=new JSONObject(); if (oneTown != null && oneTown.containsKey(Constant.level_group_3)) { jsonObject.put("num",oneTown.get(Constant.level_group_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:3:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存高血压 jsonObject=new JSONObject(); if (oneTown != null && oneTown.containsKey(Constant.level_group_4)) { jsonObject.put("num",oneTown.get(Constant.level_group_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:4:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存糖尿病 jsonObject=new JSONObject(); if (oneTown != null && oneTown.containsKey(Constant.level_group_5)) { jsonObject.put("num",oneTown.get(Constant.level_group_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:5:"+townEntry.getKey()).toString(),jsonObject.toString()); //保存糖尿病和高血压 jsonObject=new JSONObject(); if (oneTown != null && oneTown.containsKey(Constant.level_group_100)) { jsonObject.put("num",oneTown.get(Constant.level_group_100)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:3:100:"+townEntry.getKey()).toString(),jsonObject.toString()); } //保存机构 for (Map.Entry hospitalEntry : hospitalsMap.entrySet()) { //保存健康人群 Hospital hospital=hospitalsMap.get(hospitalEntry.getKey()); JSONObject jsonObject=new JSONObject(); Map oneOrg= orgGroupMap.get(hospitalEntry.getKey()); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_1)) { jsonObject.put("num",oneOrg.get(Constant.level_group_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:1:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存慢病人群 jsonObject=new JSONObject(); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_2)) { jsonObject.put("num",oneOrg.get(Constant.level_group_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:2:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存65岁以上人群 jsonObject=new JSONObject(); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_3)) { jsonObject.put("num",oneOrg.get(Constant.level_group_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:3:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存高血压 jsonObject=new JSONObject(); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_4)) { jsonObject.put("num",oneOrg.get(Constant.level_group_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:4:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存糖尿病 jsonObject=new JSONObject(); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_5)) { jsonObject.put("num",oneOrg.get(Constant.level_group_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:5:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); //保存糖尿病和高血压 jsonObject=new JSONObject(); if (oneOrg != null && oneOrg.containsKey(Constant.level_group_100)) { jsonObject.put("num",oneOrg.get(Constant.level_group_100)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:7:2:100:"+hospitalEntry.getKey()).toString(),jsonObject.toString()); } } private void computequota_8()throws Exception { //查找出系统全部的机构 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); } //找出今天的签约信息 String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingSignYesterday(now,tomorrow); //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群 Map> cityAgeMap = new HashMap>();//key是市行政代码 目前只有厦门市 cityAgeMap.put(Constant.city,new HashMap()); Map> townAgeMap = new HashMap>();//key是区行政代码 Map> orgAgeMap = new HashMap>();//key是机构代码 //统计有签约的 for (SignFamily signFamily : signFamilys) { Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构 if(hospital==null){ continue; } String town = hospital.getTown(); int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄 String ageCode =getAgeCode(age);//得到年龄的code //统计市 if (cityAgeMap.containsKey(Constant.city)) { Map groupMapTemp = cityAgeMap.get(Constant.city); groupMapTemp.put(ageCode,(groupMapTemp.get(ageCode)==null?0l:groupMapTemp.get(ageCode)) + 1); cityAgeMap.put(Constant.city, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(ageCode, 1L); cityAgeMap.put(Constant.city, groupMapTemp); } //统计区 if (townAgeMap.containsKey(town)) { Map groupMapTemp = townAgeMap.get(town); groupMapTemp.put(ageCode,(groupMapTemp.get(ageCode)==null?0l:groupMapTemp.get(ageCode)) + 1); townAgeMap.put(town, groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(ageCode, 1L); townAgeMap.put(town, groupMapTemp); } //统计机构 if (orgAgeMap.containsKey(hospital.getCode())) { Map groupMapTemp = orgAgeMap.get(hospital.getCode()); groupMapTemp.put(ageCode,(groupMapTemp.get(ageCode)==null?0l:groupMapTemp.get(ageCode))+ 1); orgAgeMap.put(hospital.getCode(), groupMapTemp); } else { Map groupMapTemp = new HashMap(); groupMapTemp.put(ageCode, 1L); orgAgeMap.put(hospital.getCode(), groupMapTemp); } } // 保存市的统计数据 for (Map.Entry> entry : cityAgeMap.entrySet()) { Map oneAgeMap=entry.getValue(); //保存0~6 JSONObject jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_1)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:1:"+entry.getKey()).toString(),jsonObject.toString()); //保存7~18 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_2)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:2:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_3)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:3:"+entry.getKey()).toString(),jsonObject.toString()); //保存30~50 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_4)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:4:"+entry.getKey()).toString(),jsonObject.toString()); //保存50~65 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_5)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:5:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_6)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_6)); } else { jsonObject.put("num",0); } jsonObject.put("name",Constant.cityName); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:4:6:"+entry.getKey()).toString(),jsonObject.toString()); } //保存区级 for (Map.Entry entry : townsMap.entrySet()) { //判断该区是否有统计数据 Map oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据 Town town = entry.getValue();//得到区级信息 JSONObject jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_1)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:1:"+entry.getKey()).toString(),jsonObject.toString()); //保存7~18 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_2)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:2:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_3)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:3:"+entry.getKey()).toString(),jsonObject.toString()); //保存30~50 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_4)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:4:"+entry.getKey()).toString(),jsonObject.toString()); //保存50~65 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_5)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:5:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_6)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_6)); } else { jsonObject.put("num",0); } jsonObject.put("name",town.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:3:6:"+entry.getKey()).toString(),jsonObject.toString()); } for (Map.Entry entry : hospitalsMap.entrySet()) { //判断该机构是否有统计数据 Map oneAgeMap = orgAgeMap.get(entry.getKey());//得到当个机构的统计数据 Hospital hospital = entry.getValue();//得到区级信息 //保存0~6 JSONObject jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_1)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_1)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:1:"+entry.getKey()).toString(),jsonObject.toString()); //保存7~18 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_2)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_2)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:2:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_3)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_3)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:3:"+entry.getKey()).toString(),jsonObject.toString()); //保存30~50 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_4)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_4)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:4"+entry.getKey()).toString(),jsonObject.toString()); //保存50~65 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_5)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_5)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:5:"+entry.getKey()).toString(),jsonObject.toString()); //保存18~30 jsonObject=new JSONObject(); if (oneAgeMap!=null&&oneAgeMap.containsKey(Constant.level_age_6)) { jsonObject.put("num",oneAgeMap.get(Constant.level_age_6)); } else { jsonObject.put("num",0); } jsonObject.put("name",hospital.getName()); jsonObject.put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:8:2:6:"+entry.getKey()).toString(),jsonObject.toString()); } } private void computequota_9() { Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode initMap(tjCityMap, tjTownMap, tjOrgMap, tjQkdoctorMap, null); String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingWaitSignYesterday(now, tomorrow); //统计有签约的 for (SignFamily signFamily : signFamilys) { String hospitalCode=signFamily.getHospital(); Hospital hospital=hospitalsMap.get(hospitalCode); //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(hospital.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 //判断是中心还是服务站 服务站的话添加到中心去 if(!"00".equals(hospital.getCode().substring(8))){ String orgCodeTemp=hospital.getCode().substring(0,8)+"00"; JSONObject orgjo=tjOrgMap.get(orgCodeTemp); orgjo.put("num",((int)orgjo.get("num"))+1); }else{ JSONObject orgjo=tjOrgMap.get(hospital.getCode()); orgjo.put("num",((int)orgjo.get("num"))+1); } //统计全科医生 JSONObject qkjo=tjQkdoctorMap.get(signFamily.getDoctor()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:9:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:9:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:9:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjQkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:9:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } private void computequota_10() { Map tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200 Map tjTownMap = new HashMap();//区级的统计map key 是区行政区划350200 Map tjOrgMap = new HashMap();//机构的统计map key 是机构的code Map tjQkdoctorMap = new HashMap();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode initMap(tjCityMap, tjTownMap, tjOrgMap, tjQkdoctorMap, null); String now = getDayString(0); String tomorrow = getDayString(1); List signFamilys = signFamilyDao.findByJiatingChaangeSignYesterday(now, tomorrow); //统计有签约的 for (SignFamily signFamily : signFamilys) { String hospitalCode=signFamily.getHospital(); Hospital hospital=hospitalsMap.get(hospitalCode); //统计市 JSONObject cityjo=tjCityMap.get(Constant.city); cityjo.put("num",((int)cityjo.get("num"))+1); //统计区 JSONObject townjo=tjTownMap.get(hospital.getTown()); townjo.put("num",((int)townjo.get("num"))+1); //统计机构 JSONObject orgjo=tjOrgMap.get(hospital.getCode()); orgjo.put("num",((int)orgjo.get("num"))+1); //统计全科医生 JSONObject qkjo=tjQkdoctorMap.get(signFamily.getDoctor()); if(qkjo!=null){ qkjo.put("num",((int)qkjo.get("num"))+1); } } //统计市 for(Map.Entry entry:tjCityMap.entrySet()){ entry.getValue().put("date", DateUtil.dateToStrLong(new Date())); redisTemplate.opsForValue().set(new StringBuffer("quota:10:4:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存区 for(Map.Entry entry:tjTownMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:10:3:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存机构 for(Map.Entry entry:tjOrgMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:10:2:"+entry.getKey()).toString(), entry.getValue().toString()); } //保存全科医生 for(Map.Entry entry:tjQkdoctorMap.entrySet()){ redisTemplate.opsForValue().set(new StringBuffer("quota:10:1:"+entry.getKey()).toString(), entry.getValue().toString()); } } public Properties getSystemProperties() { if (systemProperties == null) { InputStream is = null; try { is = this.getClass().getResourceAsStream("/application.properties"); systemProperties = new Properties(); systemProperties.load(is); } catch (IOException e1) { e1.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } return systemProperties; } 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; } public List> getFvYesterday() { String now = getDayString(0); String tomorrow = getDayString(1); String sql=" select * from fv_plan a where unix_timestamp(a.update_time)>=unix_timestamp('"+now+"') and unix_timestamp(a.update_time)< unix_timestamp('"+tomorrow+"') "; return jdbcTemplate.queryForList(sql); } /** * 根据年龄得到对应的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 void main(String[] args) { MyHashMap tjCityMap = new MyHashMap();//区级的统计map key 是区行政区划350200 tjCityMap.put("1","1"); tjCityMap.put("2","2"); tjCityMap.put("4","4"); Map tjCityMap_1 =tjCityMap.clone(); Map tjCityMap_2 = tjCityMap.clone(); tjCityMap.put("3","3"); tjCityMap.remove("1"); tjCityMap_1.put("33","33"); tjCityMap_1.remove("2"); tjCityMap_2.put("333","333"); tjCityMap_2.remove("4"); System.out.println(tjCityMap); System.out.println(tjCityMap_1); System.out.println(tjCityMap_2); } }