ChangeSignJob.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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.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.text.SimpleDateFormat;
  27. import java.util.*;
  28. /**
  29. * 已改簽的指标执行类
  30. */
  31. @Component
  32. public class ChangeSignJob implements Job {
  33. private WlyyQuotaVO wlyyQuota;//指标对象
  34. private WlyyJobConfigVO wlyyJobConfig;//配置对象
  35. @Autowired
  36. private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao
  37. @Autowired
  38. private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
  39. @Autowired
  40. private SignFamilyDao signFamilyDao;
  41. @Autowired
  42. private DoctorDao doctorDao;
  43. @Autowired
  44. private HospitalDao hospitalDao;
  45. @Autowired
  46. private TownDao townDao;
  47. @Autowired
  48. private JdbcTemplate jdbcTemplate;
  49. String yesterday;
  50. String now;
  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='"+10+"'");
  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.findByJiatingChaangeSignYesterday(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. String orgCodeTemp="";
  100. for (SignFamily signFamily : signFamilys) {
  101. String doctorCode = signFamily.getDoctor();//得到已改簽中全科医生的code
  102. //统计团队
  103. compute(tjQkdoctorMap, doctorCode);
  104. //判断医生属于哪个机构
  105. Doctor doctor = doctorsMap.get(doctorCode);
  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. //保存全科医生的改签统计
  128. for (Map.Entry<String, Doctor> entry : doctorsMap.entrySet()) {
  129. Doctor doctor = doctorsMap.get(entry.getKey());//得到全科医生
  130. orgCodeTemp=getOrg(doctor.getHospital());
  131. Hospital hospital = hospitalsMap.get(orgCodeTemp);//得到全科医生的机构
  132. if(hospital == null) continue;
  133. String city=Constant.city;
  134. String cityName=Constant.cityName;
  135. String town=hospital.getTown();
  136. String townName=hospital.getTownName();
  137. String org=hospital.getCode();
  138. if(!"00".equals(hospital.getCode().substring(hospital.getCode().length()-2,hospital.getCode().length()))){
  139. //统计站
  140. org=hospital.getCode().substring(0,hospital.getCode().length()-2)+"00";
  141. }
  142. String orgName=hospital.getName();
  143. String doctorCode=doctor.getCode();
  144. String doctorName=doctor.getName();
  145. String doctorJob=doctor.getJob();
  146. String level="1";
  147. String key=doctor.getCode();
  148. save(tjQkdoctorMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level);
  149. }
  150. //保存机构的改签统计
  151. for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
  152. Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生
  153. if(hospital == null) continue;
  154. String city=Constant.city;
  155. String cityName=Constant.cityName;
  156. String town=hospital.getTown();
  157. String townName=hospital.getTownName();
  158. String org=hospital.getCode();
  159. String orgName=hospital.getName();
  160. String doctorCode="";
  161. String doctorName="";
  162. String doctorJob="";
  163. String level="2";
  164. String key=hospital.getCode();
  165. save(tjOrgMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level);
  166. }
  167. //保存区级的改签统计
  168. for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
  169. Town townObj = townsMap.get(entry.getKey());//得到全科医生
  170. String city=Constant.city;
  171. String cityName=Constant.cityName;
  172. String town=townObj.getCode();
  173. String townName=townObj.getName();
  174. String org="";
  175. String orgName="";
  176. String doctorCode="";
  177. String doctorName="";
  178. String doctorJob="";
  179. String level="3";
  180. String key=townObj.getCode();
  181. save(tjTownMap, key, city, cityName, town, townName, org, orgName, doctorCode, doctorName, doctorJob, level);
  182. }
  183. //保存市级的统计
  184. {
  185. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  186. wlyyQuotaResult.setDel("1");
  187. wlyyQuotaResult.setCity(Constant.city);
  188. wlyyQuotaResult.setCityName(Constant.cityName);
  189. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  190. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  191. wlyyQuotaResult.setQuotaDate(getYesterday());
  192. wlyyQuotaResult.setCreateTime(new Date());
  193. wlyyQuotaResult.setLevel1Type("4");
  194. //判断全科医生是否有改签量
  195. if (cityCount > 0) {
  196. wlyyQuotaResult.setResult(cityCount + "");
  197. } else {
  198. wlyyQuotaResult.setResult("0");
  199. }
  200. wlyyQuotaResultDao.save(wlyyQuotaResult);
  201. }
  202. quartzJobLog.setJobEndTime(new Date());
  203. quartzJobLog.setJobContent("统计"+getYesterday()+" 的已改簽数据完成 ,得到改签数目:"+signFamilys.size());
  204. quartzJobLog.setJobType("1");
  205. quartzJobLogDao.save(quartzJobLog);
  206. }
  207. /**
  208. * 统计规则
  209. * @param tjQkdoctorMap
  210. * @param doctorCode
  211. */
  212. private void compute(Map<String, Long> tjQkdoctorMap, String doctorCode) {
  213. if (tjQkdoctorMap.containsKey(doctorCode)) {
  214. tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1);
  215. } else {
  216. tjQkdoctorMap.put(doctorCode, 1L);
  217. }
  218. }
  219. /**
  220. * 保存方案
  221. * @param countMap
  222. * @param key
  223. * @param city
  224. * @param cityName
  225. * @param town
  226. * @param townName
  227. * @param org
  228. * @param orgName
  229. * @param doctorCode
  230. * @param doctorName
  231. * @param doctorJob
  232. * @param level
  233. */
  234. private void save(Map<String, Long> countMap, String key, String city, String cityName, String town, String townName, String org, String orgName, String doctorCode, String doctorName, String doctorJob, String level) {
  235. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  236. wlyyQuotaResult.setDel("1");
  237. wlyyQuotaResult.setOrgCode(org);
  238. wlyyQuotaResult.setOrgName(orgName);
  239. wlyyQuotaResult.setCity(city);
  240. wlyyQuotaResult.setCityName(cityName);
  241. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  242. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  243. wlyyQuotaResult.setQuotaDate(getYesterday());
  244. wlyyQuotaResult.setCreateTime(new Date());
  245. wlyyQuotaResult.setQkdoctorJobName(doctorJob);
  246. wlyyQuotaResult.setQkdoctorName(doctorName);
  247. wlyyQuotaResult.setQkdoctorCode(doctorCode);
  248. wlyyQuotaResult.setTown(town);
  249. wlyyQuotaResult.setTownName(townName);
  250. wlyyQuotaResult.setLevel1Type(level);
  251. //判断全科医生是否有改签量
  252. if (countMap.containsKey(key)) {
  253. wlyyQuotaResult.setResult(countMap.get(key) + "");
  254. } else {
  255. wlyyQuotaResult.setResult("0");
  256. }
  257. wlyyQuotaResultDao.save(wlyyQuotaResult);
  258. }
  259. private String getOrg(String org){
  260. if(!"00".equals(org.substring(org.length()-2,org.length()))){
  261. return org.substring(0,org.length()-2)+"00";
  262. }else{
  263. return org;
  264. }
  265. }
  266. public String getYesterday() {
  267. Calendar cal = Calendar.getInstance();
  268. cal.add(Calendar.DATE, -1);
  269. String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
  270. return yesterday;
  271. }
  272. }