SignJob.java 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694
  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.doctor.team.sign.DoctorPatientGroupInfo;
  6. import com.yihu.wlyy.entity.job.QuartzJobLog;
  7. import com.yihu.wlyy.entity.patient.Patient;
  8. import com.yihu.wlyy.entity.patient.SignFamily;
  9. import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
  10. import com.yihu.wlyy.repository.address.TownDao;
  11. import com.yihu.wlyy.repository.doctor.DoctorDao;
  12. import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
  13. import com.yihu.wlyy.repository.job.QuartzJobLogDao;
  14. import com.yihu.wlyy.repository.organization.HospitalDao;
  15. import com.yihu.wlyy.repository.patient.PatientDao;
  16. import com.yihu.wlyy.repository.patient.SignFamilyDao;
  17. import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao;
  18. import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
  19. import com.yihu.wlyy.util.IdCardUtil;
  20. import com.yihu.wlyy.web.quota.WlyyJobConfigVO;
  21. import com.yihu.wlyy.web.quota.WlyyQuotaVO;
  22. import org.json.JSONArray;
  23. import org.json.JSONObject;
  24. import org.quartz.Job;
  25. import org.quartz.JobDataMap;
  26. import org.quartz.JobExecutionContext;
  27. import org.quartz.JobExecutionException;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.data.redis.core.StringRedisTemplate;
  30. import org.springframework.jdbc.core.JdbcTemplate;
  31. import org.springframework.stereotype.Component;
  32. import org.springframework.transaction.annotation.Transactional;
  33. import org.springframework.util.StringUtils;
  34. import org.springframework.web.context.support.SpringBeanAutowiringSupport;
  35. import java.text.SimpleDateFormat;
  36. import java.util.*;
  37. /**
  38. * 签约的指标执行类
  39. */
  40. @Component
  41. public class SignJob implements Job {
  42. private WlyyQuotaVO wlyyQuota;//指标对象
  43. private WlyyJobConfigVO wlyyJobConfig;//配置对象
  44. @Autowired
  45. private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao
  46. @Autowired
  47. private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
  48. @Autowired
  49. private SignFamilyDao signFamilyDao;
  50. @Autowired
  51. private DoctorDao doctorDao;
  52. @Autowired
  53. private HospitalDao hospitalDao;
  54. @Autowired
  55. private TownDao townDao;
  56. @Autowired
  57. private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
  58. @Autowired
  59. private PatientDao patientDao;
  60. @Autowired
  61. private JdbcTemplate jdbcTemplate;
  62. @Autowired
  63. private PatientDiseaseService patientDiseaseService;
  64. @Autowired
  65. private StringRedisTemplate redisTemplate;
  66. String yesterday;
  67. String now;
  68. @Override
  69. public void execute(JobExecutionContext context)
  70. throws JobExecutionException {
  71. SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
  72. //初始化参数
  73. JobDataMap map = context.getJobDetail().getJobDataMap();
  74. wlyyQuota = (WlyyQuotaVO) map.get("quota");
  75. wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
  76. now = StringUtils.isEmpty(map.get("now")) ? SignJob.getDayString(0) : map.get("now").toString();
  77. yesterday = StringUtils.isEmpty(map.get("yesterday")) ? SignJob.getDayString(-1) : map.get("yesterday").toString();
  78. String level1 = wlyyQuota.getLevel1();//得到一级维度
  79. String level2 = wlyyQuota.getLevel2();//得到二级维度
  80. //如果一级维度为空 不进行统计
  81. if (!StringUtils.isEmpty(level1)) {
  82. if (StringUtils.isEmpty(level2)) {
  83. //線刪除今天的数据
  84. //2级维度是空按照一级的机构唯独计算指标
  85. computequota();
  86. } else {
  87. switch (level2) {
  88. case "1": {
  89. //線刪除今天的数据
  90. //患者性别
  91. computequotaByPatientSex();
  92. break;
  93. }
  94. case "2": {
  95. //患者分组
  96. computequotaByPatientGroup();
  97. break;
  98. }
  99. case "3": {
  100. //患者年龄
  101. computequotaByPatientAge();
  102. break;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. /**
  109. * 机构维度下患者性别维度计算指标
  110. */
  111. @Transactional
  112. private void computequotaByPatientSex() {
  113. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 6 + "'");
  114. try {
  115. //新建任务日志对象
  116. QuartzJobLog quartzJobLog = new QuartzJobLog();
  117. quartzJobLog.setJobStartTime(new Date());
  118. quartzJobLog.setJobId(wlyyJobConfig.getId());
  119. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  120. //查找出系统全部的机构
  121. List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
  122. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  123. for (Hospital hospital : hospitals) {
  124. hospitalsMap.put(hospital.getCode(), hospital);
  125. }
  126. //查找出厦门市全部的区
  127. List<Town> towns = townDao.findByCityCode(Constant.city);
  128. Map<String, Town> townsMap = new HashMap<String, Town>();
  129. for (Town town : towns) {
  130. townsMap.put(town.getCode(), town);
  131. }
  132. //找出今天的签约信息
  133. List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
  134. //数组里面第一个是女 第二个是男 第三个是未知
  135. Map<String, Map<String, Long>> citySexMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
  136. citySexMap.put(Constant.city, new HashMap<String, Long>());
  137. Map<String, Map<String, Long>> townSexMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
  138. Map<String, Map<String, Long>> orgSexMap = new HashMap<String, Map<String, Long>>();//key是机构代码
  139. //统计有签约的
  140. for (SignFamily signFamily : signFamilys) {
  141. String idcard = signFamily.getIdcard();//得到签约中患者的身份证号
  142. Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
  143. String town = hospital.getTown();//得到患者签约的机构的区号
  144. String hospitalCode = hospital.getCode();//得到患者签约的机构号
  145. String sex = IdCardUtil.getSexForIdcard(idcard);//根据身份证得到性别
  146. //统计市 目前只统计厦门市 所以先写死 后期再改造
  147. if (citySexMap.containsKey(Constant.city)) {
  148. Map<String, Long> sexMap = citySexMap.get(Constant.city);
  149. sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
  150. citySexMap.put(Constant.city, sexMap);
  151. } else {
  152. Map<String, Long> sexMap = new HashMap<String, Long>();
  153. sexMap.put(sex, 1L);
  154. citySexMap.put(Constant.city, sexMap);
  155. }
  156. //统计区
  157. if (townSexMap.containsKey(town)) {
  158. Map<String, Long> sexMap = townSexMap.get(town);
  159. sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
  160. townSexMap.put(town, sexMap);
  161. } else {
  162. Map<String, Long> sexMap = new HashMap<String, Long>();
  163. sexMap.put(sex, 1L);
  164. townSexMap.put(town, sexMap);
  165. }
  166. //统计机构
  167. //统计站
  168. if (!"00".equals(hospitalCode.substring(8))) {
  169. String orgCodeTemp = hospitalCode.substring(0, 8) + "00";
  170. if (orgSexMap.containsKey(orgCodeTemp)) {
  171. Map<String, Long> sexMap = orgSexMap.get(orgCodeTemp);
  172. sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
  173. orgSexMap.put(orgCodeTemp, sexMap);
  174. } else {
  175. Map<String, Long> sexMap = new HashMap<String, Long>();
  176. sexMap.put(sex, 1L);
  177. orgSexMap.put(orgCodeTemp, sexMap);
  178. }
  179. } else {
  180. //统计社区
  181. if (orgSexMap.containsKey(hospitalCode)) {
  182. Map<String, Long> sexMap = orgSexMap.get(hospitalCode);
  183. sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
  184. orgSexMap.put(hospitalCode, sexMap);
  185. } else {
  186. Map<String, Long> sexMap = new HashMap<String, Long>();
  187. sexMap.put(sex, 1L);
  188. orgSexMap.put(hospitalCode, sexMap);
  189. }
  190. }
  191. }
  192. //保存统计数据
  193. //保存市统计数据
  194. for (Map.Entry<String, Map<String, Long>> entry : citySexMap.entrySet()) {
  195. //保存女
  196. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  197. wlyyQuotaResult.setDel("1");
  198. wlyyQuotaResult.setCity(entry.getKey());
  199. wlyyQuotaResult.setCityName(Constant.cityName);
  200. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  201. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  202. wlyyQuotaResult.setQuotaDate(getYesterday());
  203. wlyyQuotaResult.setCreateTime(new Date());
  204. wlyyQuotaResult.setLevel1Type("4");//市级
  205. wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
  206. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
  207. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_1)) {
  208. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_1) + "");
  209. } else {
  210. wlyyQuotaResult.setResult("0");
  211. }
  212. wlyyQuotaResultDao.save(wlyyQuotaResult);
  213. //保存男
  214. wlyyQuotaResult = new WlyyQuotaResult();
  215. wlyyQuotaResult.setDel("1");
  216. wlyyQuotaResult.setCity(entry.getKey());
  217. wlyyQuotaResult.setCityName(Constant.cityName);
  218. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  219. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  220. wlyyQuotaResult.setQuotaDate(getYesterday());
  221. wlyyQuotaResult.setCreateTime(new Date());
  222. wlyyQuotaResult.setLevel1Type("4");//市级
  223. wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
  224. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
  225. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_2)) {
  226. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_2) + "");
  227. } else {
  228. wlyyQuotaResult.setResult("0");
  229. }
  230. wlyyQuotaResultDao.save(wlyyQuotaResult);
  231. //保存位置
  232. wlyyQuotaResult = new WlyyQuotaResult();
  233. wlyyQuotaResult.setDel("1");
  234. wlyyQuotaResult.setCity(entry.getKey());
  235. wlyyQuotaResult.setCityName(Constant.cityName);
  236. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  237. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  238. wlyyQuotaResult.setQuotaDate(getYesterday());
  239. wlyyQuotaResult.setCreateTime(new Date());
  240. wlyyQuotaResult.setLevel1Type("4");//市级
  241. wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
  242. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
  243. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_3)) {
  244. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_3) + "");
  245. } else {
  246. wlyyQuotaResult.setResult("0");
  247. }
  248. wlyyQuotaResultDao.save(wlyyQuotaResult);
  249. }
  250. //保存区的统计数据
  251. for (Map.Entry<String, Town> townEntry : townsMap.entrySet()) {
  252. //判断该区是否有统计数据
  253. Map<String, Long> oneTownSexMap = townSexMap.get(townEntry.getKey());//得到当个区的统计数据
  254. Town town = townEntry.getValue();//得到区级信息
  255. //保存女
  256. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  257. wlyyQuotaResult.setDel("1");
  258. wlyyQuotaResult.setCity(Constant.city);
  259. wlyyQuotaResult.setCityName(Constant.cityName);
  260. wlyyQuotaResult.setTown(town.getCode());
  261. wlyyQuotaResult.setTownName(town.getName());
  262. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  263. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  264. wlyyQuotaResult.setQuotaDate(getYesterday());
  265. wlyyQuotaResult.setCreateTime(new Date());
  266. wlyyQuotaResult.setLevel1Type("3");//区级
  267. wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
  268. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
  269. if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_1)) {
  270. wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_1) + "");
  271. } else {
  272. wlyyQuotaResult.setResult("0");
  273. }
  274. wlyyQuotaResultDao.save(wlyyQuotaResult);
  275. //保存男
  276. wlyyQuotaResult = new WlyyQuotaResult();
  277. wlyyQuotaResult.setDel("1");
  278. wlyyQuotaResult.setCity(Constant.city);
  279. wlyyQuotaResult.setCityName(Constant.cityName);
  280. wlyyQuotaResult.setTown(town.getCode());
  281. wlyyQuotaResult.setTownName(town.getName());
  282. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  283. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  284. wlyyQuotaResult.setQuotaDate(getYesterday());
  285. wlyyQuotaResult.setCreateTime(new Date());
  286. wlyyQuotaResult.setLevel1Type("3");//区级
  287. wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
  288. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
  289. if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_2)) {
  290. wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_2) + "");
  291. } else {
  292. wlyyQuotaResult.setResult("0");
  293. }
  294. wlyyQuotaResultDao.save(wlyyQuotaResult);
  295. //保存未知的统计信息
  296. wlyyQuotaResult = new WlyyQuotaResult();
  297. wlyyQuotaResult.setDel("1");
  298. wlyyQuotaResult.setCity(Constant.city);
  299. wlyyQuotaResult.setCityName(Constant.cityName);
  300. wlyyQuotaResult.setTown(town.getCode());
  301. wlyyQuotaResult.setTownName(town.getName());
  302. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  303. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  304. wlyyQuotaResult.setQuotaDate(getYesterday());
  305. wlyyQuotaResult.setCreateTime(new Date());
  306. wlyyQuotaResult.setLevel1Type("3");//区级
  307. wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
  308. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
  309. if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_3)) {
  310. wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_3) + "");
  311. } else {
  312. wlyyQuotaResult.setResult("0");
  313. }
  314. wlyyQuotaResultDao.save(wlyyQuotaResult);
  315. }
  316. //统计机构
  317. for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
  318. //判断该机构是否有统计数据
  319. Map<String, Long> oneorgSexMap = orgSexMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
  320. Hospital hospital = hospitalEntry.getValue();//得到区级信息
  321. //保存女
  322. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  323. wlyyQuotaResult.setDel("1");
  324. wlyyQuotaResult.setCity(Constant.city);
  325. wlyyQuotaResult.setCityName(Constant.cityName);
  326. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  327. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  328. wlyyQuotaResult.setTown(hospital.getTown());
  329. wlyyQuotaResult.setTownName(hospital.getTownName());
  330. wlyyQuotaResult.setOrgCode(hospital.getCode());
  331. wlyyQuotaResult.setOrgName(hospital.getName());
  332. wlyyQuotaResult.setQuotaDate(getYesterday());
  333. wlyyQuotaResult.setCreateTime(new Date());
  334. wlyyQuotaResult.setLevel1Type("2");//机构级
  335. wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
  336. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
  337. if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_1)) {
  338. wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_1) + "");
  339. } else {
  340. wlyyQuotaResult.setResult("0");
  341. }
  342. wlyyQuotaResultDao.save(wlyyQuotaResult);
  343. //保存男
  344. wlyyQuotaResult = new WlyyQuotaResult();
  345. wlyyQuotaResult.setDel("1");
  346. wlyyQuotaResult.setCity(Constant.city);
  347. wlyyQuotaResult.setCityName(Constant.cityName);
  348. wlyyQuotaResult.setTown(hospital.getTown());
  349. wlyyQuotaResult.setTownName(hospital.getTownName());
  350. wlyyQuotaResult.setOrgCode(hospital.getCode());
  351. wlyyQuotaResult.setOrgName(hospital.getName());
  352. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  353. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  354. wlyyQuotaResult.setQuotaDate(getYesterday());
  355. wlyyQuotaResult.setCreateTime(new Date());
  356. wlyyQuotaResult.setLevel1Type("2");//机构级
  357. wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
  358. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
  359. if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_2)) {
  360. wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_2) + "");
  361. } else {
  362. wlyyQuotaResult.setResult("0");
  363. }
  364. wlyyQuotaResultDao.save(wlyyQuotaResult);
  365. //保存未知
  366. wlyyQuotaResult = new WlyyQuotaResult();
  367. wlyyQuotaResult.setDel("1");
  368. wlyyQuotaResult.setCity(Constant.city);
  369. wlyyQuotaResult.setCityName(Constant.cityName);
  370. wlyyQuotaResult.setTown(hospital.getTown());
  371. wlyyQuotaResult.setTownName(hospital.getTownName());
  372. wlyyQuotaResult.setOrgCode(hospital.getCode());
  373. wlyyQuotaResult.setOrgName(hospital.getName());
  374. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  375. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  376. wlyyQuotaResult.setQuotaDate(getYesterday());
  377. wlyyQuotaResult.setCreateTime(new Date());
  378. wlyyQuotaResult.setLevel1Type("2");//机构级
  379. wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
  380. wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
  381. if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_3)) {
  382. wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_3) + "");
  383. } else {
  384. wlyyQuotaResult.setResult("0");
  385. }
  386. wlyyQuotaResultDao.save(wlyyQuotaResult);
  387. }
  388. quartzJobLog.setJobEndTime(new Date());
  389. quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约性别数据完成 ");
  390. quartzJobLog.setJobType("1");
  391. quartzJobLogDao.save(quartzJobLog);
  392. } catch (Exception e) {
  393. e.printStackTrace();
  394. }
  395. }
  396. /**
  397. * 机构维度患者分组维度计算指标
  398. */
  399. @Transactional
  400. private void computequotaByPatientGroup() {
  401. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 7 + "'");
  402. try {
  403. //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
  404. Map<String, Map<String, Long>> cityGroupMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
  405. cityGroupMap.put(Constant.city, new HashMap<String, Long>());
  406. Map<String, Map<String, Long>> townGroupMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
  407. Map<String, Map<String, Long>> orgGroupMap = new HashMap<String, Map<String, Long>>();//key是机构代码
  408. //新建任务日志对象
  409. QuartzJobLog quartzJobLog = new QuartzJobLog();
  410. quartzJobLog.setJobStartTime(new Date());
  411. quartzJobLog.setJobId(wlyyJobConfig.getId());
  412. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  413. //查找出系统全部的机构
  414. List<Hospital> hospitals = hospitalDao.findHospital2();
  415. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  416. for (Hospital hospital : hospitals) {
  417. hospitalsMap.put(hospital.getCode(), hospital);
  418. Map<String, Long> one = new HashMap<String, Long>();
  419. one.put("1", 0L);
  420. one.put("2", 0L);
  421. one.put("3", 0L);
  422. one.put("4", 0L);
  423. one.put("5", 0L);
  424. one.put("100", 0L);
  425. orgGroupMap.put(hospital.getCode(), one);
  426. }
  427. //查找出系统全部的患者
  428. List<Patient> patients = patientDao.findAllSignPatient();
  429. Map<String, Patient> patientsMap = new HashMap<String, Patient>();
  430. for (Patient patient : patients) {
  431. patientsMap.put(patient.getCode(), patient);
  432. }
  433. //查找出厦门市全部的区
  434. List<Town> towns = townDao.findByCityCode(Constant.city);
  435. Map<String, Town> townsMap = new HashMap<String, Town>();
  436. for (Town town : towns) {
  437. townsMap.put(town.getCode(), town);
  438. Map<String, Long> one = new HashMap<String, Long>();
  439. one.put("1", 0L);
  440. one.put("2", 0L);
  441. one.put("3", 0L);
  442. one.put("4", 0L);
  443. one.put("5", 0L);
  444. one.put("100", 0L);
  445. townGroupMap.put(town.getCode(), one);
  446. }
  447. //得到所有的签约病人的分组信息
  448. List<DoctorPatientGroupInfo> doctorPatientGroupInfos = doctorPatientGroupInfoDao.findAllPatient();
  449. Map<String, String> groupMap = new HashMap<String, String>();
  450. for (DoctorPatientGroupInfo doctorPatientGroupInfo : doctorPatientGroupInfos) {
  451. groupMap.put(doctorPatientGroupInfo.getPatient(), doctorPatientGroupInfo.getGroup());
  452. }
  453. //找出今天的签约信息
  454. List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
  455. //统计有签约的
  456. for (SignFamily signFamily : signFamilys) {
  457. String patient = signFamily.getPatient();
  458. String group = groupMap.get(patient);//得到该签约病人的所在分组 1 普通 2 慢病 3是 65岁以上人群 4是 高血压 5是糖尿病 100是高血压和糖尿病
  459. Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
  460. if (hospital == null) {
  461. continue;
  462. }
  463. String town = hospital.getTown();
  464. //统计市 现在只有厦门市 默认先写死 后面再改
  465. if (cityGroupMap.containsKey(Constant.city)) {
  466. Map<String, Long> groupMapTemp = cityGroupMap.get(Constant.city);
  467. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  468. cityGroupMap.put(Constant.city, groupMapTemp);
  469. } else {
  470. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  471. groupMapTemp.put(group, 1L);
  472. cityGroupMap.put(Constant.city, groupMapTemp);
  473. }
  474. //统计区
  475. if (townGroupMap.containsKey(town)) {
  476. Map<String, Long> groupMapTemp = townGroupMap.get(town);
  477. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  478. townGroupMap.put(town, groupMapTemp);
  479. } else {
  480. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  481. groupMapTemp.put(group, 1L);
  482. townGroupMap.put(town, groupMapTemp);
  483. }
  484. //统计站
  485. if (!"00".equals(hospital.getCode().substring(8))) {
  486. String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
  487. //统计机构
  488. if (orgGroupMap.containsKey(orgCodeTemp)) {
  489. Map<String, Long> groupMapTemp = orgGroupMap.get(orgCodeTemp);
  490. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  491. orgGroupMap.put(orgCodeTemp, groupMapTemp);
  492. } else {
  493. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  494. groupMapTemp.put(group, 1L);
  495. orgGroupMap.put(orgCodeTemp, groupMapTemp);
  496. }
  497. } else {
  498. //统计机构
  499. if (orgGroupMap.containsKey(hospital.getCode())) {
  500. Map<String, Long> groupMapTemp = orgGroupMap.get(hospital.getCode());
  501. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  502. orgGroupMap.put(hospital.getCode(), groupMapTemp);
  503. } else {
  504. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  505. groupMapTemp.put(group, 1L);
  506. orgGroupMap.put(hospital.getCode(), groupMapTemp);
  507. }
  508. }
  509. boolean hasGXY = false;//有高血压
  510. boolean hasTNB = false;//有糖尿病
  511. if ("2".equals(group)) {
  512. //如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病
  513. String jsonString = redisTemplate.opsForValue().get("disease:" + patient);
  514. if (StringUtils.isEmpty(jsonString)) {
  515. continue;
  516. }
  517. //排除数据 只留下高血压和糖尿病
  518. List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
  519. JSONArray redisValues = new JSONArray(jsonString);
  520. for (Object obj : redisValues) {
  521. JSONObject redisValue = new JSONObject(obj);
  522. //排除掉三师签约
  523. if ("1".equals(redisValue.get("signType").toString())) {
  524. continue;
  525. }
  526. String disease = redisValue.get("disease").toString();
  527. if (Integer.valueOf(disease).equals("1")) {
  528. jsonObjects.add(redisValue);
  529. hasGXY = true;//设置有高血压
  530. }
  531. if (Integer.valueOf(disease).equals("2")) {
  532. jsonObjects.add(redisValue);
  533. hasTNB = true;//设置有糖尿病
  534. }
  535. }
  536. if(jsonObjects.size()==0){
  537. continue;//如果没有高血压和糖尿病 不统计
  538. }
  539. if (hasGXY && hasTNB) {
  540. group = "100";//有高血压又有糖尿病
  541. } else {
  542. group = Integer.valueOf(jsonObjects.get(0).get("disease").toString()) + 3 + "";//4高血压,5糖尿病
  543. }
  544. if (cityGroupMap.containsKey(Constant.city)) {
  545. Map<String, Long> groupMapTemp = cityGroupMap.get(Constant.city);
  546. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  547. cityGroupMap.put(Constant.city, groupMapTemp);
  548. } else {
  549. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  550. groupMapTemp.put(group, 1L);
  551. cityGroupMap.put(Constant.city, groupMapTemp);
  552. }
  553. //统计区
  554. if (townGroupMap.containsKey(town)) {
  555. Map<String, Long> groupMapTemp = townGroupMap.get(town);
  556. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  557. townGroupMap.put(town, groupMapTemp);
  558. } else {
  559. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  560. groupMapTemp.put(group, 1L);
  561. townGroupMap.put(town, groupMapTemp);
  562. }
  563. //统计机构
  564. //统计站
  565. if (!"00".equals(hospital.getCode().substring(8))) {
  566. String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
  567. //统计机构
  568. if (orgGroupMap.containsKey(orgCodeTemp)) {
  569. Map<String, Long> groupMapTemp = orgGroupMap.get(orgCodeTemp);
  570. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  571. orgGroupMap.put(orgCodeTemp, groupMapTemp);
  572. } else {
  573. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  574. groupMapTemp.put(group, 1L);
  575. orgGroupMap.put(orgCodeTemp, groupMapTemp);
  576. }
  577. } else {
  578. //统计机构
  579. if (orgGroupMap.containsKey(hospital.getCode())) {
  580. Map<String, Long> groupMapTemp = orgGroupMap.get(hospital.getCode());
  581. groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
  582. orgGroupMap.put(hospital.getCode(), groupMapTemp);
  583. } else {
  584. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  585. groupMapTemp.put(group, 1L);
  586. orgGroupMap.put(hospital.getCode(), groupMapTemp);
  587. }
  588. }
  589. }
  590. }
  591. //保存统计数据
  592. //保存市的统计数据
  593. for (Map.Entry<String, Map<String, Long>> entry : cityGroupMap.entrySet()) {
  594. //保存健康人群
  595. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  596. wlyyQuotaResult.setDel("1");
  597. wlyyQuotaResult.setCity(entry.getKey());
  598. wlyyQuotaResult.setCityName(Constant.cityName);
  599. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  600. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  601. wlyyQuotaResult.setQuotaDate(getYesterday());
  602. wlyyQuotaResult.setCreateTime(new Date());
  603. wlyyQuotaResult.setLevel1Type("4");//市级
  604. wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
  605. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
  606. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_1)) {
  607. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_1) + "");
  608. } else {
  609. wlyyQuotaResult.setResult("0");
  610. }
  611. wlyyQuotaResultDao.save(wlyyQuotaResult);
  612. //保存慢病人群
  613. wlyyQuotaResult = new WlyyQuotaResult();
  614. wlyyQuotaResult.setDel("1");
  615. wlyyQuotaResult.setCity(entry.getKey());
  616. wlyyQuotaResult.setCityName(Constant.cityName);
  617. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  618. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  619. wlyyQuotaResult.setQuotaDate(getYesterday());
  620. wlyyQuotaResult.setCreateTime(new Date());
  621. wlyyQuotaResult.setLevel1Type("4");//市级
  622. wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
  623. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
  624. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_2)) {
  625. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_2) + "");
  626. } else {
  627. wlyyQuotaResult.setResult("0");
  628. }
  629. wlyyQuotaResultDao.save(wlyyQuotaResult);
  630. //保存65岁以上人群
  631. wlyyQuotaResult = new WlyyQuotaResult();
  632. wlyyQuotaResult.setDel("1");
  633. wlyyQuotaResult.setCity(entry.getKey());
  634. wlyyQuotaResult.setCityName(Constant.cityName);
  635. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  636. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  637. wlyyQuotaResult.setQuotaDate(getYesterday());
  638. wlyyQuotaResult.setCreateTime(new Date());
  639. wlyyQuotaResult.setLevel1Type("4");//市级
  640. wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
  641. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
  642. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_3)) {
  643. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_3) + "");
  644. } else {
  645. wlyyQuotaResult.setResult("0");
  646. }
  647. wlyyQuotaResultDao.save(wlyyQuotaResult);
  648. //保存高血压
  649. wlyyQuotaResult = new WlyyQuotaResult();
  650. wlyyQuotaResult.setDel("1");
  651. wlyyQuotaResult.setCity(entry.getKey());
  652. wlyyQuotaResult.setCityName(Constant.cityName);
  653. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  654. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  655. wlyyQuotaResult.setQuotaDate(getYesterday());
  656. wlyyQuotaResult.setCreateTime(new Date());
  657. wlyyQuotaResult.setLevel1Type("4");//市级
  658. wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
  659. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
  660. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_4)) {
  661. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_4) + "");
  662. } else {
  663. wlyyQuotaResult.setResult("0");
  664. }
  665. wlyyQuotaResultDao.save(wlyyQuotaResult);
  666. //保存糖尿病
  667. wlyyQuotaResult = new WlyyQuotaResult();
  668. wlyyQuotaResult.setDel("1");
  669. wlyyQuotaResult.setCity(entry.getKey());
  670. wlyyQuotaResult.setCityName(Constant.cityName);
  671. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  672. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  673. wlyyQuotaResult.setQuotaDate(getYesterday());
  674. wlyyQuotaResult.setCreateTime(new Date());
  675. wlyyQuotaResult.setLevel1Type("4");//市级
  676. wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
  677. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
  678. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_5)) {
  679. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_5) + "");
  680. } else {
  681. wlyyQuotaResult.setResult("0");
  682. }
  683. wlyyQuotaResultDao.save(wlyyQuotaResult);
  684. //保存糖尿病和高血压
  685. wlyyQuotaResult = new WlyyQuotaResult();
  686. wlyyQuotaResult.setDel("1");
  687. wlyyQuotaResult.setCity(entry.getKey());
  688. wlyyQuotaResult.setCityName(Constant.cityName);
  689. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  690. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  691. wlyyQuotaResult.setQuotaDate(getYesterday());
  692. wlyyQuotaResult.setCreateTime(new Date());
  693. wlyyQuotaResult.setLevel1Type("4");//市级
  694. wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
  695. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
  696. if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_100)) {
  697. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_100) + "");
  698. } else {
  699. wlyyQuotaResult.setResult("0");
  700. }
  701. wlyyQuotaResultDao.save(wlyyQuotaResult);
  702. }
  703. //保存区级
  704. //保存区的统计数据
  705. for (Map.Entry<String, Town> townEntry : townsMap.entrySet()) {
  706. //判断该区是否有统计数据
  707. Map<String, Long> oneTownGroupMap = townGroupMap.get(townEntry.getKey());//得到当个区的统计数据
  708. Town town = townEntry.getValue();//得到区级信息
  709. //保存健康人群
  710. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  711. wlyyQuotaResult.setDel("1");
  712. wlyyQuotaResult.setCity(Constant.city);
  713. wlyyQuotaResult.setCityName(Constant.cityName);
  714. wlyyQuotaResult.setTown(town.getCode());
  715. wlyyQuotaResult.setTownName(town.getName());
  716. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  717. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  718. wlyyQuotaResult.setQuotaDate(getYesterday());
  719. wlyyQuotaResult.setCreateTime(new Date());
  720. wlyyQuotaResult.setLevel1Type("3");//区级
  721. wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
  722. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
  723. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_1)) {
  724. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_1) + "");
  725. } else {
  726. wlyyQuotaResult.setResult("0");
  727. }
  728. wlyyQuotaResultDao.save(wlyyQuotaResult);
  729. //保存慢病人群
  730. wlyyQuotaResult = new WlyyQuotaResult();
  731. wlyyQuotaResult.setDel("1");
  732. wlyyQuotaResult.setCity(Constant.city);
  733. wlyyQuotaResult.setCityName(Constant.cityName);
  734. wlyyQuotaResult.setTown(town.getCode());
  735. wlyyQuotaResult.setTownName(town.getName());
  736. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  737. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  738. wlyyQuotaResult.setQuotaDate(getYesterday());
  739. wlyyQuotaResult.setCreateTime(new Date());
  740. wlyyQuotaResult.setLevel1Type("3");//区级
  741. wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
  742. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
  743. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_2)) {
  744. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_2) + "");
  745. } else {
  746. wlyyQuotaResult.setResult("0");
  747. }
  748. wlyyQuotaResultDao.save(wlyyQuotaResult);
  749. //保存65岁以上人群
  750. wlyyQuotaResult = new WlyyQuotaResult();
  751. wlyyQuotaResult.setDel("1");
  752. wlyyQuotaResult.setCity(Constant.city);
  753. wlyyQuotaResult.setCityName(Constant.cityName);
  754. wlyyQuotaResult.setTown(town.getCode());
  755. wlyyQuotaResult.setTownName(town.getName());
  756. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  757. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  758. wlyyQuotaResult.setQuotaDate(getYesterday());
  759. wlyyQuotaResult.setCreateTime(new Date());
  760. wlyyQuotaResult.setLevel1Type("3");//区级
  761. wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
  762. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
  763. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_3)) {
  764. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_3) + "");
  765. } else {
  766. wlyyQuotaResult.setResult("0");
  767. }
  768. wlyyQuotaResultDao.save(wlyyQuotaResult);
  769. //保存高血压
  770. wlyyQuotaResult = new WlyyQuotaResult();
  771. wlyyQuotaResult.setDel("1");
  772. wlyyQuotaResult.setCity(Constant.city);
  773. wlyyQuotaResult.setCityName(Constant.cityName);
  774. wlyyQuotaResult.setTown(town.getCode());
  775. wlyyQuotaResult.setTownName(town.getName());
  776. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  777. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  778. wlyyQuotaResult.setQuotaDate(getYesterday());
  779. wlyyQuotaResult.setCreateTime(new Date());
  780. wlyyQuotaResult.setLevel1Type("3");//区级
  781. wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
  782. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
  783. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_4)) {
  784. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_4) + "");
  785. } else {
  786. wlyyQuotaResult.setResult("0");
  787. }
  788. wlyyQuotaResultDao.save(wlyyQuotaResult);
  789. //保存糖尿病
  790. wlyyQuotaResult = new WlyyQuotaResult();
  791. wlyyQuotaResult.setDel("1");
  792. wlyyQuotaResult.setCity(Constant.city);
  793. wlyyQuotaResult.setCityName(Constant.cityName);
  794. wlyyQuotaResult.setTown(town.getCode());
  795. wlyyQuotaResult.setTownName(town.getName());
  796. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  797. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  798. wlyyQuotaResult.setQuotaDate(getYesterday());
  799. wlyyQuotaResult.setCreateTime(new Date());
  800. wlyyQuotaResult.setLevel1Type("3");//区级
  801. wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
  802. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
  803. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_5)) {
  804. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_5) + "");
  805. } else {
  806. wlyyQuotaResult.setResult("0");
  807. }
  808. wlyyQuotaResultDao.save(wlyyQuotaResult);
  809. //保存糖尿病
  810. wlyyQuotaResult = new WlyyQuotaResult();
  811. wlyyQuotaResult.setDel("1");
  812. wlyyQuotaResult.setCity(Constant.city);
  813. wlyyQuotaResult.setCityName(Constant.cityName);
  814. wlyyQuotaResult.setTown(town.getCode());
  815. wlyyQuotaResult.setTownName(town.getName());
  816. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  817. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  818. wlyyQuotaResult.setQuotaDate(getYesterday());
  819. wlyyQuotaResult.setCreateTime(new Date());
  820. wlyyQuotaResult.setLevel1Type("3");//区级
  821. wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
  822. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
  823. if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_100)) {
  824. wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_100) + "");
  825. } else {
  826. wlyyQuotaResult.setResult("0");
  827. }
  828. wlyyQuotaResultDao.save(wlyyQuotaResult);
  829. }
  830. //保存机构
  831. for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
  832. //判断该机构是否有统计数据
  833. Map<String, Long> oneOrgGroupMap = orgGroupMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
  834. Hospital hospital = hospitalEntry.getValue();//得到区级信息
  835. //保存健康人群
  836. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  837. wlyyQuotaResult.setDel("1");
  838. wlyyQuotaResult.setCity(Constant.city);
  839. wlyyQuotaResult.setCityName(Constant.cityName);
  840. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  841. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  842. wlyyQuotaResult.setTown(hospital.getTown());
  843. wlyyQuotaResult.setTownName(hospital.getTownName());
  844. wlyyQuotaResult.setOrgCode(hospital.getCode());
  845. wlyyQuotaResult.setOrgName(hospital.getName());
  846. wlyyQuotaResult.setQuotaDate(getYesterday());
  847. wlyyQuotaResult.setCreateTime(new Date());
  848. wlyyQuotaResult.setLevel1Type("2");//机构级
  849. wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
  850. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
  851. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_1)) {
  852. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_1) + "");
  853. } else {
  854. wlyyQuotaResult.setResult("0");
  855. }
  856. wlyyQuotaResultDao.save(wlyyQuotaResult);
  857. //保存慢病
  858. wlyyQuotaResult = new WlyyQuotaResult();
  859. wlyyQuotaResult.setDel("1");
  860. wlyyQuotaResult.setCity(Constant.city);
  861. wlyyQuotaResult.setCityName(Constant.cityName);
  862. wlyyQuotaResult.setTown(hospital.getTown());
  863. wlyyQuotaResult.setTownName(hospital.getTownName());
  864. wlyyQuotaResult.setOrgCode(hospital.getCode());
  865. wlyyQuotaResult.setOrgName(hospital.getName());
  866. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  867. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  868. wlyyQuotaResult.setQuotaDate(getYesterday());
  869. wlyyQuotaResult.setCreateTime(new Date());
  870. wlyyQuotaResult.setLevel1Type("2");//机构级
  871. wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
  872. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
  873. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_2)) {
  874. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_2) + "");
  875. } else {
  876. wlyyQuotaResult.setResult("0");
  877. }
  878. wlyyQuotaResultDao.save(wlyyQuotaResult);
  879. //保存65岁以上人群
  880. wlyyQuotaResult = new WlyyQuotaResult();
  881. wlyyQuotaResult.setDel("1");
  882. wlyyQuotaResult.setCity(Constant.city);
  883. wlyyQuotaResult.setCityName(Constant.cityName);
  884. wlyyQuotaResult.setTown(hospital.getTown());
  885. wlyyQuotaResult.setTownName(hospital.getTownName());
  886. wlyyQuotaResult.setOrgCode(hospital.getCode());
  887. wlyyQuotaResult.setOrgName(hospital.getName());
  888. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  889. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  890. wlyyQuotaResult.setQuotaDate(getYesterday());
  891. wlyyQuotaResult.setCreateTime(new Date());
  892. wlyyQuotaResult.setLevel1Type("2");//机构级
  893. wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
  894. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
  895. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_3)) {
  896. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_3) + "");
  897. } else {
  898. wlyyQuotaResult.setResult("0");
  899. }
  900. wlyyQuotaResultDao.save(wlyyQuotaResult);
  901. //保存高血压
  902. wlyyQuotaResult = new WlyyQuotaResult();
  903. wlyyQuotaResult.setDel("1");
  904. wlyyQuotaResult.setCity(Constant.city);
  905. wlyyQuotaResult.setCityName(Constant.cityName);
  906. wlyyQuotaResult.setTown(hospital.getTown());
  907. wlyyQuotaResult.setTownName(hospital.getTownName());
  908. wlyyQuotaResult.setOrgCode(hospital.getCode());
  909. wlyyQuotaResult.setOrgName(hospital.getName());
  910. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  911. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  912. wlyyQuotaResult.setQuotaDate(getYesterday());
  913. wlyyQuotaResult.setCreateTime(new Date());
  914. wlyyQuotaResult.setLevel1Type("2");//机构级
  915. wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
  916. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
  917. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_4)) {
  918. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_4) + "");
  919. } else {
  920. wlyyQuotaResult.setResult("0");
  921. }
  922. wlyyQuotaResultDao.save(wlyyQuotaResult);
  923. //保存糖尿病
  924. wlyyQuotaResult = new WlyyQuotaResult();
  925. wlyyQuotaResult.setDel("1");
  926. wlyyQuotaResult.setCity(Constant.city);
  927. wlyyQuotaResult.setCityName(Constant.cityName);
  928. wlyyQuotaResult.setTown(hospital.getTown());
  929. wlyyQuotaResult.setTownName(hospital.getTownName());
  930. wlyyQuotaResult.setOrgCode(hospital.getCode());
  931. wlyyQuotaResult.setOrgName(hospital.getName());
  932. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  933. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  934. wlyyQuotaResult.setQuotaDate(getYesterday());
  935. wlyyQuotaResult.setCreateTime(new Date());
  936. wlyyQuotaResult.setLevel1Type("2");//机构级
  937. wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
  938. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
  939. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_5)) {
  940. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_5) + "");
  941. } else {
  942. wlyyQuotaResult.setResult("0");
  943. }
  944. wlyyQuotaResultDao.save(wlyyQuotaResult);
  945. //保存糖尿病和高血压
  946. wlyyQuotaResult = new WlyyQuotaResult();
  947. wlyyQuotaResult.setDel("1");
  948. wlyyQuotaResult.setCity(Constant.city);
  949. wlyyQuotaResult.setCityName(Constant.cityName);
  950. wlyyQuotaResult.setTown(hospital.getTown());
  951. wlyyQuotaResult.setTownName(hospital.getTownName());
  952. wlyyQuotaResult.setOrgCode(hospital.getCode());
  953. wlyyQuotaResult.setOrgName(hospital.getName());
  954. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  955. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  956. wlyyQuotaResult.setQuotaDate(getYesterday());
  957. wlyyQuotaResult.setCreateTime(new Date());
  958. wlyyQuotaResult.setLevel1Type("2");//机构级
  959. wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
  960. wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
  961. if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_100)) {
  962. wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_100) + "");
  963. } else {
  964. wlyyQuotaResult.setResult("0");
  965. }
  966. wlyyQuotaResultDao.save(wlyyQuotaResult);
  967. }
  968. quartzJobLog.setJobEndTime(new Date());
  969. quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约病人分组数据完成 ");
  970. quartzJobLog.setJobType("1");
  971. quartzJobLogDao.save(quartzJobLog);
  972. } catch (Exception e) {
  973. e.printStackTrace();
  974. }
  975. }
  976. /**
  977. * 机构维度患者年龄维度计算指标
  978. */
  979. @Transactional
  980. private void computequotaByPatientAge() {
  981. try {
  982. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 8 + "'");
  983. //新建任务日志对象
  984. QuartzJobLog quartzJobLog = new QuartzJobLog();
  985. quartzJobLog.setJobStartTime(new Date());
  986. quartzJobLog.setJobId(wlyyJobConfig.getId());
  987. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  988. //查找出系统全部的机构
  989. List<Hospital> hospitals = hospitalDao.findHospital2();
  990. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  991. for (Hospital hospital : hospitals) {
  992. hospitalsMap.put(hospital.getCode(), hospital);
  993. }
  994. //查找出厦门市全部的区
  995. List<Town> towns = townDao.findByCityCode(Constant.city);
  996. Map<String, Town> townsMap = new HashMap<String, Town>();
  997. for (Town town : towns) {
  998. townsMap.put(town.getCode(), town);
  999. }
  1000. //找出今天的签约信息
  1001. List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
  1002. //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
  1003. Map<String, Map<String, Long>> cityAgeMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
  1004. cityAgeMap.put(Constant.city, new HashMap<String, Long>());
  1005. Map<String, Map<String, Long>> townAgeMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
  1006. Map<String, Map<String, Long>> orgAgeMap = new HashMap<String, Map<String, Long>>();//key是机构代码
  1007. //统计有签约的
  1008. for (SignFamily signFamily : signFamilys) {
  1009. Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
  1010. String town = hospital.getTown();
  1011. int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄
  1012. String ageCode = getAgeCode(age);//得到年龄的code
  1013. //统计市
  1014. if (cityAgeMap.containsKey(Constant.city)) {
  1015. Map<String, Long> groupMapTemp = cityAgeMap.get(Constant.city);
  1016. groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
  1017. cityAgeMap.put(Constant.city, groupMapTemp);
  1018. } else {
  1019. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  1020. groupMapTemp.put(ageCode, 1L);
  1021. cityAgeMap.put(Constant.city, groupMapTemp);
  1022. }
  1023. //统计区
  1024. if (townAgeMap.containsKey(town)) {
  1025. Map<String, Long> groupMapTemp = townAgeMap.get(town);
  1026. groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
  1027. townAgeMap.put(town, groupMapTemp);
  1028. } else {
  1029. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  1030. groupMapTemp.put(ageCode, 1L);
  1031. townAgeMap.put(town, groupMapTemp);
  1032. }
  1033. //统计机构
  1034. //统计站
  1035. if (!"00".equals(hospital.getCode().substring(8))) {
  1036. String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
  1037. //统计机构
  1038. if (orgAgeMap.containsKey(orgCodeTemp)) {
  1039. Map<String, Long> groupMapTemp = orgAgeMap.get(hospital.getCode());
  1040. groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
  1041. orgAgeMap.put(orgCodeTemp, groupMapTemp);
  1042. } else {
  1043. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  1044. groupMapTemp.put(ageCode, 1L);
  1045. orgAgeMap.put(orgCodeTemp, groupMapTemp);
  1046. }
  1047. } else {
  1048. //统计机构
  1049. if (orgAgeMap.containsKey(hospital.getCode())) {
  1050. Map<String, Long> groupMapTemp = orgAgeMap.get(hospital.getCode());
  1051. groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
  1052. orgAgeMap.put(hospital.getCode(), groupMapTemp);
  1053. } else {
  1054. Map<String, Long> groupMapTemp = new HashMap<String, Long>();
  1055. groupMapTemp.put(ageCode, 1L);
  1056. orgAgeMap.put(hospital.getCode(), groupMapTemp);
  1057. }
  1058. }
  1059. }
  1060. //保存统计数据
  1061. // 保存市的统计数据
  1062. for (Map.Entry<String, Map<String, Long>> entry : cityAgeMap.entrySet()) {
  1063. Map<String, Long> oneAgeMap = entry.getValue();
  1064. //保存0~6
  1065. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1066. wlyyQuotaResult.setDel("1");
  1067. wlyyQuotaResult.setCity(entry.getKey());
  1068. wlyyQuotaResult.setCityName(Constant.cityName);
  1069. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1070. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1071. wlyyQuotaResult.setQuotaDate(getYesterday());
  1072. wlyyQuotaResult.setCreateTime(new Date());
  1073. wlyyQuotaResult.setLevel1Type("4");//市级
  1074. wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
  1075. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
  1076. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
  1077. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_1) + "");
  1078. } else {
  1079. wlyyQuotaResult.setResult("0");
  1080. }
  1081. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1082. //保存7~18
  1083. wlyyQuotaResult = new WlyyQuotaResult();
  1084. wlyyQuotaResult.setDel("1");
  1085. wlyyQuotaResult.setCity(entry.getKey());
  1086. wlyyQuotaResult.setCityName(Constant.cityName);
  1087. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1088. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1089. wlyyQuotaResult.setQuotaDate(getYesterday());
  1090. wlyyQuotaResult.setCreateTime(new Date());
  1091. wlyyQuotaResult.setLevel1Type("4");//市级
  1092. wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
  1093. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
  1094. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
  1095. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_2) + "");
  1096. } else {
  1097. wlyyQuotaResult.setResult("0");
  1098. }
  1099. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1100. //保存18~30
  1101. wlyyQuotaResult = new WlyyQuotaResult();
  1102. wlyyQuotaResult.setDel("1");
  1103. wlyyQuotaResult.setCity(entry.getKey());
  1104. wlyyQuotaResult.setCityName(Constant.cityName);
  1105. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1106. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1107. wlyyQuotaResult.setQuotaDate(getYesterday());
  1108. wlyyQuotaResult.setCreateTime(new Date());
  1109. wlyyQuotaResult.setLevel1Type("4");//市级
  1110. wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
  1111. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
  1112. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
  1113. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_3) + "");
  1114. } else {
  1115. wlyyQuotaResult.setResult("0");
  1116. }
  1117. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1118. //保存30~50
  1119. wlyyQuotaResult = new WlyyQuotaResult();
  1120. wlyyQuotaResult.setDel("1");
  1121. wlyyQuotaResult.setCity(entry.getKey());
  1122. wlyyQuotaResult.setCityName(Constant.cityName);
  1123. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1124. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1125. wlyyQuotaResult.setQuotaDate(getYesterday());
  1126. wlyyQuotaResult.setCreateTime(new Date());
  1127. wlyyQuotaResult.setLevel1Type("4");//市级
  1128. wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
  1129. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
  1130. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
  1131. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_4) + "");
  1132. } else {
  1133. wlyyQuotaResult.setResult("0");
  1134. }
  1135. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1136. //保存50~65
  1137. wlyyQuotaResult = new WlyyQuotaResult();
  1138. wlyyQuotaResult.setDel("1");
  1139. wlyyQuotaResult.setCity(entry.getKey());
  1140. wlyyQuotaResult.setCityName(Constant.cityName);
  1141. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1142. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1143. wlyyQuotaResult.setQuotaDate(getYesterday());
  1144. wlyyQuotaResult.setCreateTime(new Date());
  1145. wlyyQuotaResult.setLevel1Type("4");//市级
  1146. wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
  1147. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
  1148. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
  1149. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_5) + "");
  1150. } else {
  1151. wlyyQuotaResult.setResult("0");
  1152. }
  1153. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1154. //保存18~30
  1155. wlyyQuotaResult = new WlyyQuotaResult();
  1156. wlyyQuotaResult.setDel("1");
  1157. wlyyQuotaResult.setCity(entry.getKey());
  1158. wlyyQuotaResult.setCityName(Constant.cityName);
  1159. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1160. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1161. wlyyQuotaResult.setQuotaDate(getYesterday());
  1162. wlyyQuotaResult.setCreateTime(new Date());
  1163. wlyyQuotaResult.setLevel1Type("4");//市级
  1164. wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
  1165. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
  1166. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
  1167. wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_6) + "");
  1168. } else {
  1169. wlyyQuotaResult.setResult("0");
  1170. }
  1171. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1172. }
  1173. //保存区级
  1174. for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
  1175. //判断该区是否有统计数据
  1176. Map<String, Long> oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据
  1177. Town town = entry.getValue();//得到区级信息
  1178. //保存0~6
  1179. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1180. wlyyQuotaResult.setDel("1");
  1181. wlyyQuotaResult.setCity(entry.getKey());
  1182. wlyyQuotaResult.setCityName(Constant.cityName);
  1183. wlyyQuotaResult.setTown(town.getCode());
  1184. wlyyQuotaResult.setTownName(town.getName());
  1185. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1186. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1187. wlyyQuotaResult.setQuotaDate(getYesterday());
  1188. wlyyQuotaResult.setCreateTime(new Date());
  1189. wlyyQuotaResult.setLevel1Type("3");//区级
  1190. wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
  1191. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
  1192. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
  1193. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_1) + "");
  1194. } else {
  1195. wlyyQuotaResult.setResult("0");
  1196. }
  1197. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1198. //保存7~18
  1199. wlyyQuotaResult = new WlyyQuotaResult();
  1200. wlyyQuotaResult.setDel("1");
  1201. wlyyQuotaResult.setCity(entry.getKey());
  1202. wlyyQuotaResult.setCityName(Constant.cityName);
  1203. wlyyQuotaResult.setTown(town.getCode());
  1204. wlyyQuotaResult.setTownName(town.getName());
  1205. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1206. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1207. wlyyQuotaResult.setQuotaDate(getYesterday());
  1208. wlyyQuotaResult.setCreateTime(new Date());
  1209. wlyyQuotaResult.setLevel1Type("3");//区级
  1210. wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
  1211. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
  1212. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
  1213. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_2) + "");
  1214. } else {
  1215. wlyyQuotaResult.setResult("0");
  1216. }
  1217. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1218. //保存18~30
  1219. wlyyQuotaResult = new WlyyQuotaResult();
  1220. wlyyQuotaResult.setDel("1");
  1221. wlyyQuotaResult.setCity(entry.getKey());
  1222. wlyyQuotaResult.setCityName(Constant.cityName);
  1223. wlyyQuotaResult.setTown(town.getCode());
  1224. wlyyQuotaResult.setTownName(town.getName());
  1225. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1226. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1227. wlyyQuotaResult.setQuotaDate(getYesterday());
  1228. wlyyQuotaResult.setCreateTime(new Date());
  1229. wlyyQuotaResult.setLevel1Type("3");//区级
  1230. wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
  1231. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
  1232. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
  1233. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_3) + "");
  1234. } else {
  1235. wlyyQuotaResult.setResult("0");
  1236. }
  1237. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1238. //保存30~50
  1239. wlyyQuotaResult = new WlyyQuotaResult();
  1240. wlyyQuotaResult.setDel("1");
  1241. wlyyQuotaResult.setCity(entry.getKey());
  1242. wlyyQuotaResult.setCityName(Constant.cityName);
  1243. wlyyQuotaResult.setTown(town.getCode());
  1244. wlyyQuotaResult.setTownName(town.getName());
  1245. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1246. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1247. wlyyQuotaResult.setQuotaDate(getYesterday());
  1248. wlyyQuotaResult.setCreateTime(new Date());
  1249. wlyyQuotaResult.setLevel1Type("3");//区级
  1250. wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
  1251. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
  1252. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
  1253. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_4) + "");
  1254. } else {
  1255. wlyyQuotaResult.setResult("0");
  1256. }
  1257. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1258. //保存50~65
  1259. wlyyQuotaResult = new WlyyQuotaResult();
  1260. wlyyQuotaResult.setDel("1");
  1261. wlyyQuotaResult.setCity(entry.getKey());
  1262. wlyyQuotaResult.setCityName(Constant.cityName);
  1263. wlyyQuotaResult.setTown(town.getCode());
  1264. wlyyQuotaResult.setTownName(town.getName());
  1265. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1266. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1267. wlyyQuotaResult.setQuotaDate(getYesterday());
  1268. wlyyQuotaResult.setCreateTime(new Date());
  1269. wlyyQuotaResult.setLevel1Type("3");//区级
  1270. wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
  1271. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
  1272. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
  1273. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_5) + "");
  1274. } else {
  1275. wlyyQuotaResult.setResult("0");
  1276. }
  1277. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1278. //保存18~30
  1279. wlyyQuotaResult = new WlyyQuotaResult();
  1280. wlyyQuotaResult.setDel("1");
  1281. wlyyQuotaResult.setCity(entry.getKey());
  1282. wlyyQuotaResult.setCityName(Constant.cityName);
  1283. wlyyQuotaResult.setTown(town.getCode());
  1284. wlyyQuotaResult.setTownName(town.getName());
  1285. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1286. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1287. wlyyQuotaResult.setQuotaDate(getYesterday());
  1288. wlyyQuotaResult.setCreateTime(new Date());
  1289. wlyyQuotaResult.setLevel1Type("3");//区级
  1290. wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
  1291. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
  1292. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
  1293. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_6) + "");
  1294. } else {
  1295. wlyyQuotaResult.setResult("0");
  1296. }
  1297. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1298. }
  1299. for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
  1300. //判断该机构是否有统计数据
  1301. Map<String, Long> oneAgeMap = orgAgeMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
  1302. Hospital hospital = hospitalEntry.getValue();//得到区级信息
  1303. //保存0~6
  1304. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1305. wlyyQuotaResult.setDel("1");
  1306. wlyyQuotaResult.setCity(hospital.getCity());
  1307. wlyyQuotaResult.setCityName(Constant.cityName);
  1308. wlyyQuotaResult.setTown(hospital.getTown());
  1309. wlyyQuotaResult.setTownName(hospital.getTownName());
  1310. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1311. wlyyQuotaResult.setOrgName(hospital.getName());
  1312. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1313. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1314. wlyyQuotaResult.setQuotaDate(getYesterday());
  1315. wlyyQuotaResult.setCreateTime(new Date());
  1316. wlyyQuotaResult.setLevel1Type("2");//区级
  1317. wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
  1318. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
  1319. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
  1320. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_1) + "");
  1321. } else {
  1322. wlyyQuotaResult.setResult("0");
  1323. }
  1324. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1325. //保存7~18
  1326. wlyyQuotaResult = new WlyyQuotaResult();
  1327. wlyyQuotaResult.setDel("1");
  1328. wlyyQuotaResult.setCity(hospital.getCity());
  1329. wlyyQuotaResult.setCityName(Constant.cityName);
  1330. wlyyQuotaResult.setTown(hospital.getTown());
  1331. wlyyQuotaResult.setTownName(hospital.getTownName());
  1332. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1333. wlyyQuotaResult.setOrgName(hospital.getName());
  1334. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1335. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1336. wlyyQuotaResult.setQuotaDate(getYesterday());
  1337. wlyyQuotaResult.setCreateTime(new Date());
  1338. wlyyQuotaResult.setLevel1Type("2");//机构级
  1339. wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
  1340. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
  1341. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
  1342. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_2) + "");
  1343. } else {
  1344. wlyyQuotaResult.setResult("0");
  1345. }
  1346. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1347. //保存18~30
  1348. wlyyQuotaResult = new WlyyQuotaResult();
  1349. wlyyQuotaResult.setDel("1");
  1350. wlyyQuotaResult.setCity(hospital.getCity());
  1351. wlyyQuotaResult.setCityName(Constant.cityName);
  1352. wlyyQuotaResult.setTown(hospital.getTown());
  1353. wlyyQuotaResult.setTownName(hospital.getTownName());
  1354. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1355. wlyyQuotaResult.setOrgName(hospital.getName());
  1356. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1357. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1358. wlyyQuotaResult.setQuotaDate(getYesterday());
  1359. wlyyQuotaResult.setCreateTime(new Date());
  1360. wlyyQuotaResult.setLevel1Type("2");//机构级
  1361. wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
  1362. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
  1363. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
  1364. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_3) + "");
  1365. } else {
  1366. wlyyQuotaResult.setResult("0");
  1367. }
  1368. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1369. //保存30~50
  1370. wlyyQuotaResult = new WlyyQuotaResult();
  1371. wlyyQuotaResult.setDel("1");
  1372. wlyyQuotaResult.setCity(hospital.getCity());
  1373. wlyyQuotaResult.setCityName(Constant.cityName);
  1374. wlyyQuotaResult.setTown(hospital.getTown());
  1375. wlyyQuotaResult.setTownName(hospital.getTownName());
  1376. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1377. wlyyQuotaResult.setOrgName(hospital.getName());
  1378. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1379. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1380. wlyyQuotaResult.setQuotaDate(getYesterday());
  1381. wlyyQuotaResult.setCreateTime(new Date());
  1382. wlyyQuotaResult.setLevel1Type("2");//机构级
  1383. wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
  1384. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
  1385. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
  1386. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_4) + "");
  1387. } else {
  1388. wlyyQuotaResult.setResult("0");
  1389. }
  1390. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1391. //保存50~65
  1392. wlyyQuotaResult = new WlyyQuotaResult();
  1393. wlyyQuotaResult.setDel("1");
  1394. wlyyQuotaResult.setCity(hospital.getCity());
  1395. wlyyQuotaResult.setCityName(Constant.cityName);
  1396. wlyyQuotaResult.setTown(hospital.getTown());
  1397. wlyyQuotaResult.setTownName(hospital.getTownName());
  1398. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1399. wlyyQuotaResult.setOrgName(hospital.getName());
  1400. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1401. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1402. wlyyQuotaResult.setQuotaDate(getYesterday());
  1403. wlyyQuotaResult.setCreateTime(new Date());
  1404. wlyyQuotaResult.setLevel1Type("2");//机构级
  1405. wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
  1406. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
  1407. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
  1408. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_5) + "");
  1409. } else {
  1410. wlyyQuotaResult.setResult("0");
  1411. }
  1412. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1413. //保存18~30
  1414. wlyyQuotaResult = new WlyyQuotaResult();
  1415. wlyyQuotaResult.setDel("1");
  1416. wlyyQuotaResult.setCity(hospital.getCity());
  1417. wlyyQuotaResult.setCityName(Constant.cityName);
  1418. wlyyQuotaResult.setTown(hospital.getTown());
  1419. wlyyQuotaResult.setTownName(hospital.getTownName());
  1420. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1421. wlyyQuotaResult.setOrgName(hospital.getName());
  1422. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1423. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1424. wlyyQuotaResult.setQuotaDate(getYesterday());
  1425. wlyyQuotaResult.setCreateTime(new Date());
  1426. wlyyQuotaResult.setLevel1Type("2");//机构级
  1427. wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
  1428. wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
  1429. if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
  1430. wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_6) + "");
  1431. } else {
  1432. wlyyQuotaResult.setResult("0");
  1433. }
  1434. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1435. }
  1436. quartzJobLog.setJobEndTime(new Date());
  1437. quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约患者年龄数据完成 ");
  1438. quartzJobLog.setJobType("1");
  1439. quartzJobLogDao.save(quartzJobLog);
  1440. } catch (Exception e) {
  1441. e.printStackTrace();
  1442. }
  1443. }
  1444. /**
  1445. * 机构维度计算指标
  1446. */
  1447. @Transactional
  1448. private void computequota() {
  1449. jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 1 + "'");
  1450. //新建任务日志对象
  1451. QuartzJobLog quartzJobLog = new QuartzJobLog();
  1452. quartzJobLog.setJobStartTime(new Date());
  1453. quartzJobLog.setJobId(wlyyJobConfig.getId());
  1454. quartzJobLog.setJobName(wlyyJobConfig.getJobName());
  1455. //查找出系统全部的全科医生
  1456. List<Doctor> doctors = doctorDao.findAllQKDoctot();
  1457. Map<String, Doctor> doctorsMap = new HashMap<String, Doctor>();
  1458. for (Doctor doctor : doctors) {
  1459. doctorsMap.put(doctor.getCode(), doctor);
  1460. }
  1461. //查找出系统全部的机构
  1462. List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
  1463. Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
  1464. for (Hospital hospital : hospitals) {
  1465. hospitalsMap.put(hospital.getCode(), hospital);
  1466. }
  1467. //查找出厦门市全部的区
  1468. List<Town> towns = townDao.findByCityCode(Constant.city);
  1469. Map<String, Town> townsMap = new HashMap<String, Town>();
  1470. for (Town town : towns) {
  1471. townsMap.put(town.getCode(), town);
  1472. }
  1473. //找出今天的签约信息 yesterday,now
  1474. List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
  1475. Map<String, Long> tjTownMap = new HashMap<String, Long>();//区级的统计map key 是区行政区划350200
  1476. Map<String, Long> tjOrgMap = new HashMap<String, Long>();//机构的统计map key 是机构的code
  1477. Map<String, Long> tjQkdoctorMap = new HashMap<String, Long>();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode
  1478. Long cityCount = 0L;
  1479. //统计有签约的
  1480. for (SignFamily signFamily : signFamilys) {
  1481. String doctorCode = signFamily.getDoctor();//得到签约中全科医生的code
  1482. //统计团队
  1483. if (tjQkdoctorMap.containsKey(doctorCode)) {
  1484. tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1);
  1485. } else {
  1486. tjQkdoctorMap.put(doctorCode, 1L);
  1487. }
  1488. //判断医生属于哪个机构
  1489. Doctor doctor = doctorsMap.get(doctorCode);
  1490. if (doctor == null) {
  1491. continue;
  1492. }
  1493. String orgCode = doctor.getHospital();
  1494. //统计机构
  1495. //统计站
  1496. if (!"00".equals(orgCode.substring(8))) {
  1497. String orgCodeTemp = orgCode.substring(0, 8) + "00";
  1498. if (tjOrgMap.containsKey(orgCodeTemp)) {
  1499. tjOrgMap.put(orgCodeTemp, tjOrgMap.get(orgCodeTemp) + 1);
  1500. } else {
  1501. tjOrgMap.put(orgCodeTemp, 1L);
  1502. }
  1503. } else {
  1504. //统计社区
  1505. if (tjOrgMap.containsKey(orgCode)) {
  1506. tjOrgMap.put(orgCode, tjOrgMap.get(orgCode) + 1);
  1507. } else {
  1508. tjOrgMap.put(orgCode, 1L);
  1509. }
  1510. }
  1511. String townCode = doctor.getTown();
  1512. //统计区
  1513. if (tjTownMap.containsKey(townCode)) {
  1514. tjTownMap.put(townCode, tjTownMap.get(townCode) + 1);
  1515. } else {
  1516. tjTownMap.put(townCode, 1L);
  1517. }
  1518. //统计市
  1519. cityCount++;
  1520. }
  1521. //保存统计的结果
  1522. //保存全科医生的签约统计
  1523. for (Map.Entry<String, Doctor> entry : doctorsMap.entrySet()) {
  1524. Doctor doctor = doctorsMap.get(entry.getKey());//得到全科医生
  1525. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1526. wlyyQuotaResult.setDel("1");
  1527. wlyyQuotaResult.setOrgCode(doctor.getHospital());
  1528. wlyyQuotaResult.setOrgName(doctor.getHosptialName());
  1529. wlyyQuotaResult.setCity(doctor.getCity());
  1530. wlyyQuotaResult.setCityName(doctor.getCityName());
  1531. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1532. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1533. wlyyQuotaResult.setQuotaDate(getYesterday());
  1534. wlyyQuotaResult.setCreateTime(new Date());
  1535. wlyyQuotaResult.setQkdoctorJobName(doctor.getJobName());
  1536. wlyyQuotaResult.setQkdoctorName(doctor.getName());
  1537. wlyyQuotaResult.setQkdoctorCode(doctor.getCode());
  1538. wlyyQuotaResult.setTown(doctor.getTown());
  1539. wlyyQuotaResult.setTownName(doctor.getTownName());
  1540. wlyyQuotaResult.setLevel1Type("1");
  1541. //判断全科医生是否有签约量
  1542. if (tjQkdoctorMap.containsKey(doctor.getCode())) {
  1543. wlyyQuotaResult.setResult(tjQkdoctorMap.get(doctor.getCode()) + "");
  1544. } else {
  1545. wlyyQuotaResult.setResult("0");
  1546. }
  1547. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1548. }
  1549. //保存机构的签约统计
  1550. for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
  1551. Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生
  1552. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1553. wlyyQuotaResult.setDel("1");
  1554. wlyyQuotaResult.setOrgCode(hospital.getCode());
  1555. wlyyQuotaResult.setOrgName(hospital.getName());
  1556. wlyyQuotaResult.setCity(hospital.getCity());
  1557. wlyyQuotaResult.setCityName(hospital.getCityName());
  1558. wlyyQuotaResult.setTown(hospital.getTown());
  1559. wlyyQuotaResult.setTownName(hospital.getTownName());
  1560. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1561. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1562. wlyyQuotaResult.setQuotaDate(getYesterday());
  1563. wlyyQuotaResult.setCreateTime(new Date());
  1564. wlyyQuotaResult.setLevel1Type("2");
  1565. //判断全科医生是否有签约量
  1566. if (tjOrgMap.containsKey(hospital.getCode())) {
  1567. wlyyQuotaResult.setResult(tjOrgMap.get(hospital.getCode()) + "");
  1568. } else {
  1569. wlyyQuotaResult.setResult("0");
  1570. }
  1571. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1572. }
  1573. //保存区级的签约统计
  1574. for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
  1575. Town town = townsMap.get(entry.getKey());//得到全科医生
  1576. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1577. wlyyQuotaResult.setDel("1");
  1578. wlyyQuotaResult.setCity(town.getCity());
  1579. wlyyQuotaResult.setCityName(Constant.cityName);
  1580. wlyyQuotaResult.setTown(town.getCode());
  1581. wlyyQuotaResult.setTownName(town.getName());
  1582. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1583. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1584. wlyyQuotaResult.setQuotaDate(getYesterday());
  1585. wlyyQuotaResult.setCreateTime(new Date());
  1586. wlyyQuotaResult.setLevel1Type("3");
  1587. //判断全科医生是否有签约量
  1588. if (tjTownMap.containsKey(town.getCode())) {
  1589. wlyyQuotaResult.setResult(tjTownMap.get(town.getCode()) + "");
  1590. } else {
  1591. wlyyQuotaResult.setResult("0");
  1592. }
  1593. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1594. }
  1595. //保存市级的统计
  1596. {
  1597. WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
  1598. wlyyQuotaResult.setDel("1");
  1599. wlyyQuotaResult.setCity(Constant.city);
  1600. wlyyQuotaResult.setCityName(Constant.cityName);
  1601. wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
  1602. wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
  1603. wlyyQuotaResult.setQuotaDate(getYesterday());
  1604. wlyyQuotaResult.setCreateTime(new Date());
  1605. wlyyQuotaResult.setLevel1Type("4");
  1606. //判断全科医生是否有签约量
  1607. if (cityCount > 0) {
  1608. wlyyQuotaResult.setResult(cityCount + "");
  1609. } else {
  1610. wlyyQuotaResult.setResult("0");
  1611. }
  1612. wlyyQuotaResultDao.save(wlyyQuotaResult);
  1613. }
  1614. quartzJobLog.setJobEndTime(new Date());
  1615. quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约数据完成 ");
  1616. quartzJobLog.setJobType("1");
  1617. quartzJobLogDao.save(quartzJobLog);
  1618. }
  1619. /*
  1620. 得到昨天的日期字符串 yyyy-MM-dd
  1621. */
  1622. public String getYesterday() {
  1623. return yesterday;
  1624. }
  1625. /**
  1626. * 根据年龄得到对应的code
  1627. *
  1628. * @param age
  1629. * @return
  1630. */
  1631. public String getAgeCode(int age) {
  1632. if (age < 7) {
  1633. return Constant.level_age_1;
  1634. } else if (age >= 7 && age < 18) {
  1635. return Constant.level_age_2;
  1636. } else if (age >= 18 && age < 30) {
  1637. return Constant.level_age_3;
  1638. } else if (age >= 30 && age < 50) {
  1639. return Constant.level_age_4;
  1640. } else if (age >= 50 && age < 65) {
  1641. return Constant.level_age_5;
  1642. } else {
  1643. return Constant.level_age_6;
  1644. }
  1645. }
  1646. public static String getDayString(Integer size) {
  1647. Date date = new Date();//取时间
  1648. Calendar calendar = new GregorianCalendar();
  1649. calendar.setTime(date);
  1650. calendar.add(calendar.DATE, size);//把日期往后增加一天.整数往后推,负数往前移动
  1651. date = calendar.getTime(); //这个时间就是日期往后推一天的结果
  1652. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  1653. String dateString = formatter.format(date);
  1654. return dateString;
  1655. }
  1656. public static void main(String[] args) {
  1657. getDayString(0);
  1658. }
  1659. }