SignJob.java 82 KB

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