SignJob.java 82 KB

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