WaitSignJob.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package com.yihu.wlyy.job;
  2. import com.yihu.wlyy.entity.address.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.SignFamily;
  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.SignFamilyDao;
  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 WaitSignJob 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 SignFamilyDao signFamilyDao;
  40. @Autowired
  41. private DoctorDao doctorDao;
  42. @Autowired
  43. private HospitalDao hospitalDao;
  44. @Autowired
  45. private TownDao townDao;
  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. /**
  64. * 计算指标
  65. */
  66. @Transactional
  67. private void computequota() {
  68. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+9+"'");
  69. //新建任务日志对象
  70. QuartzJobLog quartzJobLog = new QuartzJobLog();
  71. quartzJobLog.setJobStartTime(new Date());
  72. quartzJobLog.setJobId(wlyyJobConfig.getId());
  73. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  74. //查找出系统全部的全科医生
  75. List<Doctor> doctors = doctorDao.findAllQKDoctot();
  76. Map<String, Doctor> doctorsMap = new HashMap<String, Doctor>();
  77. for (Doctor doctor : doctors) {
  78. doctorsMap.put(doctor.getCode(), doctor);
  79. }
  80. //查找出系统全部的机构
  81. List<Hospital> hospitals = hospitalDao.findHospital2();
  82. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  83. for (Hospital hospital : hospitals) {
  84. hospitalsMap.put(hospital.getCode(), hospital);
  85. }
  86. //查找出厦门市全部的区
  87. List<Town> towns = townDao.findByCityCode(Constant.city);
  88. Map<String, Town> townsMap = new HashMap<String, Town>();
  89. for (Town town : towns) {
  90. townsMap.put(town.getCode(), town);
  91. }
  92. //找出今天的待签约信息
  93. List<SignFamily> signFamilys = signFamilyDao.findByJiatingWaitSignYesterday(yesterday,now);
  94. Map<String, Long> tjTownMap = new HashMap<String, Long>();//区级的统计map key 是区行政区划350200
  95. Map<String, Long> tjOrgMap = new HashMap<String, Long>();//机构的统计map key 是机构的code
  96. Map<String, Long> tjQkdoctorMap = new HashMap<String, Long>();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode
  97. Long cityCount = 0L;
  98. //统计有待签约的
  99. for (SignFamily signFamily : signFamilys) {
  100. String doctorCode = signFamily.getDoctor();//得到待签约中全科医生的code
  101. //统计团队
  102. if (tjQkdoctorMap.containsKey(doctorCode)) {
  103. tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1);
  104. } else {
  105. tjQkdoctorMap.put(doctorCode, 1L);
  106. }
  107. //判断医生属于哪个机构
  108. Doctor doctor = doctorsMap.get(doctorCode);
  109. if(doctor==null){
  110. continue;
  111. }
  112. String orgCode = doctor.getHospital();
  113. //统计机构
  114. if(!"00".equals(orgCode.substring(8))){
  115. //统计站
  116. String orgCodeTemp=orgCode.substring(0,8)+"00";
  117. if (tjOrgMap.containsKey(orgCodeTemp)) {
  118. tjOrgMap.put(orgCodeTemp, tjOrgMap.get(orgCodeTemp) + 1);
  119. } else {
  120. tjOrgMap.put(orgCodeTemp, 1L);
  121. }
  122. }else{
  123. //统计社区
  124. if (tjOrgMap.containsKey(orgCode)) {
  125. tjOrgMap.put(orgCode, tjOrgMap.get(orgCode) + 1);
  126. } else {
  127. tjOrgMap.put(orgCode, 1L);
  128. }
  129. }
  130. String townCode = doctor.getTown();
  131. //统计区
  132. if (tjTownMap.containsKey(townCode)) {
  133. tjTownMap.put(townCode, tjTownMap.get(townCode) + 1);
  134. } else {
  135. tjTownMap.put(townCode, 1L);
  136. }
  137. //统计市
  138. cityCount++;
  139. }
  140. //保存统计的结果
  141. //保存全科医生的待签约统计
  142. for (Map.Entry<String, Doctor> entry : doctorsMap.entrySet()) {
  143. Doctor doctor = doctorsMap.get(entry.getKey());//得到全科医生
  144. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  145. wlyyQuotaResult.setDel("1");
  146. wlyyQuotaResult.setOrgCode(doctor.getHospital());
  147. wlyyQuotaResult.setOrgName(doctor.getHosptialName());
  148. wlyyQuotaResult.setCity(doctor.getCity());
  149. wlyyQuotaResult.setCityName(doctor.getCityName());
  150. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  151. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  152. wlyyQuotaResult.setQuotaDate(getYesterday());
  153. wlyyQuotaResult.setCreateTime(new Date());
  154. wlyyQuotaResult.setQkdoctorJobName(doctor.getJobName());
  155. wlyyQuotaResult.setQkdoctorName(doctor.getName());
  156. wlyyQuotaResult.setQkdoctorCode(doctor.getCode());
  157. wlyyQuotaResult.setTown(doctor.getTown());
  158. wlyyQuotaResult.setTownName(doctor.getTownName());
  159. wlyyQuotaResult.setLevel1Type("1");
  160. //判断全科医生是否有待签约量
  161. if (tjQkdoctorMap.containsKey(doctor.getCode())) {
  162. wlyyQuotaResult.setResult(tjQkdoctorMap.get(doctor.getCode()) + "");
  163. } else {
  164. wlyyQuotaResult.setResult("0");
  165. }
  166. wlyyQuotaResultDao.save(wlyyQuotaResult);
  167. }
  168. //保存机构的待签约统计
  169. for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
  170. Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生
  171. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  172. wlyyQuotaResult.setDel("1");
  173. wlyyQuotaResult.setOrgCode(hospital.getCode());
  174. wlyyQuotaResult.setOrgName(hospital.getName());
  175. wlyyQuotaResult.setCity(hospital.getCity());
  176. wlyyQuotaResult.setCityName(hospital.getCityName());
  177. wlyyQuotaResult.setTown(hospital.getTown());
  178. wlyyQuotaResult.setTownName(hospital.getTownName());
  179. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  180. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  181. wlyyQuotaResult.setQuotaDate(getYesterday());
  182. wlyyQuotaResult.setCreateTime(new Date());
  183. wlyyQuotaResult.setLevel1Type("2");
  184. //判断全科医生是否有待签约量
  185. if (tjOrgMap.containsKey(hospital.getCode())) {
  186. wlyyQuotaResult.setResult(tjOrgMap.get(hospital.getCode()) + "");
  187. } else {
  188. wlyyQuotaResult.setResult("0");
  189. }
  190. wlyyQuotaResultDao.save(wlyyQuotaResult);
  191. }
  192. //保存区级的待签约统计
  193. for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
  194. Town town = townsMap.get(entry.getKey());//得到全科医生
  195. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  196. wlyyQuotaResult.setDel("1");
  197. wlyyQuotaResult.setCity(town.getCity());
  198. wlyyQuotaResult.setCityName(Constant.cityName);
  199. wlyyQuotaResult.setTown(town.getCode());
  200. wlyyQuotaResult.setTownName(town.getName());
  201. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  202. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  203. wlyyQuotaResult.setQuotaDate(getYesterday());
  204. wlyyQuotaResult.setCreateTime(new Date());
  205. wlyyQuotaResult.setLevel1Type("3");
  206. //判断全科医生是否有待签约量
  207. if (tjTownMap.containsKey(town.getCode())) {
  208. wlyyQuotaResult.setResult(tjTownMap.get(town.getCode()) + "");
  209. } else {
  210. wlyyQuotaResult.setResult("0");
  211. }
  212. wlyyQuotaResultDao.save(wlyyQuotaResult);
  213. }
  214. //保存市级的统计
  215. {
  216. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  217. wlyyQuotaResult.setDel("1");
  218. wlyyQuotaResult.setCity(Constant.city);
  219. wlyyQuotaResult.setCityName(Constant.cityName);
  220. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  221. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  222. wlyyQuotaResult.setQuotaDate(getYesterday());
  223. wlyyQuotaResult.setCreateTime(new Date());
  224. wlyyQuotaResult.setLevel1Type("4");
  225. //判断全科医生是否有待签约量
  226. if (cityCount > 0) {
  227. wlyyQuotaResult.setResult(cityCount + "");
  228. } else {
  229. wlyyQuotaResult.setResult("0");
  230. }
  231. wlyyQuotaResultDao.save(wlyyQuotaResult);
  232. }
  233. quartzJobLog.setJobEndTime(new Date());
  234. quartzJobLog.setJobContent("统计"+getYesterday()+" 的待签约数据完成 ");
  235. quartzJobLog.setJobType("1");
  236. quartzJobLogDao.save(quartzJobLog);
  237. }
  238. public String getYesterday() {
  239. return yesterday;
  240. }
  241. }