HealthGuideJob.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package com.yihu.wlyy.job;
  2. import com.yihu.wlyy.entity.organization.Hospital;
  3. import com.yihu.wlyy.entity.address.Town;
  4. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  5. import com.yihu.wlyy.entity.job.QuartzJobLog;
  6. import com.yihu.wlyy.entity.patient.PatientHealthGuidance;
  7. import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
  8. import com.yihu.wlyy.repository.address.TownDao;
  9. import com.yihu.wlyy.repository.doctor.DoctorDao;
  10. import com.yihu.wlyy.repository.job.QuartzJobLogDao;
  11. import com.yihu.wlyy.repository.organization.HospitalDao;
  12. import com.yihu.wlyy.repository.patient.PatientHealthGuidanceDao;
  13. import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao;
  14. import com.yihu.wlyy.web.quota.WlyyJobConfigVO;
  15. import com.yihu.wlyy.web.quota.WlyyQuotaVO;
  16. import org.quartz.Job;
  17. import org.quartz.JobDataMap;
  18. import org.quartz.JobExecutionContext;
  19. import org.quartz.JobExecutionException;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.jdbc.core.JdbcTemplate;
  22. import org.springframework.stereotype.Component;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.util.StringUtils;
  25. import org.springframework.web.context.support.SpringBeanAutowiringSupport;
  26. import java.util.*;
  27. /**
  28. * 健康指导的指标执行类
  29. */
  30. @Component
  31. public class HealthGuideJob implements Job {
  32. private WlyyQuotaVO wlyyQuota;//指标对象
  33. private WlyyJobConfigVO wlyyJobConfig;//配置对象
  34. @Autowired
  35. private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao
  36. @Autowired
  37. private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
  38. @Autowired
  39. private DoctorDao doctorDao;
  40. @Autowired
  41. private HospitalDao hospitalDao;
  42. @Autowired
  43. private TownDao townDao;
  44. @Autowired
  45. private PatientHealthGuidanceDao patientHealthGuidanceDao;
  46. @Autowired
  47. private JdbcTemplate jdbcTemplate;
  48. String yesterday;
  49. String now;
  50. @Override
  51. public void execute(JobExecutionContext context)
  52. throws JobExecutionException {
  53. SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
  54. //初始化参数
  55. JobDataMap map = context.getJobDetail().getJobDataMap();
  56. wlyyQuota = (WlyyQuotaVO) map.get("quota");
  57. wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
  58. now= StringUtils.isEmpty(map.get("now"))?SignJob.getDayString(0):map.get("now").toString();
  59. yesterday= StringUtils.isEmpty(map.get("yesterday"))?SignJob.getDayString(-1):map.get("yesterday").toString();
  60. //计算指标
  61. computequota();
  62. }
  63. @Transactional
  64. private void computequota() {
  65. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+3+"'");
  66. //新建任务日志对象
  67. QuartzJobLog quartzJobLog = new QuartzJobLog();
  68. quartzJobLog.setJobStartTime(new Date());
  69. quartzJobLog.setJobId(wlyyJobConfig.getId());
  70. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  71. //查找出系统全部的全科医生和健康管理师
  72. List<Doctor> doctors = doctorDao.findAllQKDoctotAndJKDoctor();
  73. Map<String, Doctor> doctorsMap = new HashMap<String, Doctor>();
  74. for (Doctor doctor : doctors) {
  75. doctorsMap.put(doctor.getCode(), doctor);
  76. }
  77. //查找出系统全部的机构
  78. List<Hospital> hospitals = hospitalDao.findHospital2();
  79. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  80. for (Hospital hospital : hospitals) {
  81. hospitalsMap.put(hospital.getCode(), hospital);
  82. }
  83. //查找出厦门市全部的区
  84. List<Town> towns = townDao.findByCityCode(Constant.city);
  85. Map<String, Town> townsMap = new HashMap<String, Town>();
  86. for (Town town : towns) {
  87. townsMap.put(town.getCode(), town);
  88. }
  89. //找出今天的健康指导信息
  90. List<PatientHealthGuidance> patientHealthGuidances = patientHealthGuidanceDao.findByCzrqyYesterday(yesterday,now);
  91. Map<String, Long> tjTownMap = new HashMap<String, Long>();//区级的统计map key 是区行政区划350200
  92. Map<String, Long> tjOrgMap = new HashMap<String, Long>();//机构的统计map key 是机构的code
  93. Map<String, Long> tjdoctorMap = new HashMap<String, Long>();//团队级的统计map 目前没有团队 先用医生和健康管理师统一 key doctorCode
  94. Long cityCount = 0L;
  95. //统计有健康指导的
  96. String orgCodeTemp="";
  97. for (PatientHealthGuidance patientHealthGuidance : patientHealthGuidances) {
  98. String doctorCode = patientHealthGuidance.getDoctor();//得到健康指导中健康医生的code
  99. //统计团队
  100. compute(tjdoctorMap, doctorCode);
  101. //判断医生属于哪个机构
  102. Doctor doctor = doctorsMap.get(doctorCode);
  103. if(doctor==null){
  104. continue;
  105. }
  106. String orgCode = doctor.getHospital();
  107. //统计机构
  108. if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
  109. //统计站
  110. orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
  111. compute(tjOrgMap, orgCodeTemp);
  112. }else{
  113. //统计社区
  114. orgCodeTemp=orgCode;
  115. compute(tjOrgMap, orgCode);
  116. }
  117. Hospital hospital=hospitalsMap.get(orgCodeTemp);
  118. if(hospital == null) continue;
  119. String townCode = hospital.getTown();
  120. //统计区
  121. compute(tjTownMap, townCode);
  122. //统计市
  123. cityCount++;
  124. }
  125. //保存统计的结果
  126. //保存全科医生和健康管理师的健康指导统计
  127. for (Map.Entry<String, Doctor> entry : doctorsMap.entrySet()) {
  128. Doctor doctor = doctorsMap.get(entry.getKey());//得到健康管理师
  129. orgCodeTemp=getOrg(doctor.getHospital());
  130. Hospital hospital = hospitalsMap.get(orgCodeTemp);//得到全科医生的机构
  131. if(hospital == null) continue;
  132. String city=Constant.city;
  133. String cityName=Constant.cityName;
  134. String town=hospital.getTown();
  135. String townName=hospital.getTownName();
  136. String org=hospital.getCode();
  137. String orgName=hospital.getName();
  138. String doctorCode=doctor.getCode();
  139. String doctorName=doctor.getName();
  140. String doctorJob=doctor.getJob();
  141. String level="1";
  142. String key=doctor.getCode();
  143. save(tjdoctorMap, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level, key);
  144. }
  145. //保存机构的咨询统计
  146. for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
  147. Hospital hospital = hospitalsMap.get(entry.getKey());
  148. if(hospital == null) continue;
  149. String city=Constant.city;
  150. String cityName=Constant.cityName;
  151. String town=hospital.getTown();
  152. String townName=hospital.getTownName();
  153. String org=hospital.getCode();
  154. String orgName=hospital.getName();
  155. String doctorCode="";
  156. String doctorName="";
  157. String doctorJob="";
  158. String level="2";
  159. String key=hospital.getCode();
  160. save(tjOrgMap, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level, key);
  161. }
  162. //保存区级的咨询统计
  163. for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
  164. Town townObj = townsMap.get(entry.getKey());
  165. String city=Constant.city;
  166. String cityName=Constant.cityName;
  167. String town=townObj.getCode();
  168. String townName=townObj.getName();
  169. String org="";
  170. String orgName="";
  171. String doctorCode="";
  172. String doctorName="";
  173. String doctorJob="";
  174. String level="3";
  175. String key=townObj.getCode();
  176. save(tjTownMap, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level, key);
  177. }
  178. //保存市级的统计
  179. {
  180. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  181. wlyyQuotaResult.setDel("1");
  182. wlyyQuotaResult.setCity(Constant.city);
  183. wlyyQuotaResult.setCityName(Constant.cityName);
  184. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  185. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  186. wlyyQuotaResult.setQuotaDate(getYesterday());
  187. wlyyQuotaResult.setCreateTime(new Date());
  188. wlyyQuotaResult.setLevel1Type("4");
  189. //判断全科医生是否有咨询量
  190. if (cityCount > 0) {
  191. wlyyQuotaResult.setResult(cityCount + "");
  192. } else {
  193. wlyyQuotaResult.setResult("0");
  194. }
  195. wlyyQuotaResultDao.save(wlyyQuotaResult);
  196. }
  197. quartzJobLog.setJobEndTime(new Date());
  198. quartzJobLog.setJobContent("统计" + getYesterday() + " 的健康指导数据完成 ,得到健康指导数目:"+patientHealthGuidances.size());
  199. quartzJobLog.setJobType("1");
  200. quartzJobLogDao.save(quartzJobLog);
  201. }
  202. /**
  203. * 统计方案
  204. * @param tjdoctorMap
  205. * @param doctorCode
  206. */
  207. private void compute(Map<String, Long> tjdoctorMap, String doctorCode) {
  208. if (tjdoctorMap.containsKey(doctorCode)) {
  209. tjdoctorMap.put(doctorCode, tjdoctorMap.get(doctorCode) + 1);
  210. } else {
  211. tjdoctorMap.put(doctorCode, 1L);
  212. }
  213. }
  214. private void save(Map<String, Long> tjTownMap, String city, String cityName, String town, String townName, String org, String orgName, String doctorCode, String doctorName, String doctorJob, String level, String key) {
  215. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  216. wlyyQuotaResult.setDel("1");
  217. wlyyQuotaResult.setCity(city);
  218. wlyyQuotaResult.setCityName(cityName);
  219. wlyyQuotaResult.setTown(town);
  220. wlyyQuotaResult.setTownName(townName);
  221. wlyyQuotaResult.setOrgCode(org);
  222. wlyyQuotaResult.setOrgName(orgName);
  223. wlyyQuotaResult.setQkdoctorJobName(doctorJob);
  224. wlyyQuotaResult.setQkdoctorName(doctorName);
  225. wlyyQuotaResult.setQkdoctorCode(doctorCode);
  226. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  227. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  228. wlyyQuotaResult.setQuotaDate(getYesterday());
  229. wlyyQuotaResult.setCreateTime(new Date());
  230. wlyyQuotaResult.setLevel1Type(level);
  231. //判断全科医生是否有随访量
  232. if (tjTownMap.containsKey(key)) {
  233. wlyyQuotaResult.setResult(tjTownMap.get(key) + "");
  234. } else {
  235. wlyyQuotaResult.setResult("0");
  236. }
  237. wlyyQuotaResultDao.save(wlyyQuotaResult);
  238. }
  239. private String getOrg(String org){
  240. if(!"00".equals(org.substring(org.length()-2,org.length()))){
  241. return org.substring(0,org.length()-2)+"00";
  242. }else{
  243. return org;
  244. }
  245. }
  246. public String getYesterday() {
  247. return yesterday;
  248. }
  249. }