CurrentDayAllQuotaJob.java 78 KB

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