SignJob.java 83 KB

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