SignJob.java 83 KB

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