Commit 7abef6b49bb789527bec7ad7b40489c791008caf
1 parent
fbcb97c58b
Exists in
master
and in
8 other branches
commit
Showing 1 changed file with 158 additions and 114 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientFacade.java
View file @
7abef6b
| ... | ... | @@ -29,13 +29,14 @@ |
| 29 | 29 | import java.io.IOException; |
| 30 | 30 | import java.io.OutputStream; |
| 31 | 31 | import java.util.*; |
| 32 | +import java.util.concurrent.*; | |
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Created by Administrator on 2016/4/22 0022. |
| 35 | 36 | */ |
| 36 | 37 | @Component |
| 37 | 38 | public class PatientFacade { |
| 38 | - private Logger logger = LoggerFactory.getLogger(PatientFacade.class); | |
| 39 | + private static final Logger logger = LoggerFactory.getLogger(PatientFacade.class); | |
| 39 | 40 | @Autowired |
| 40 | 41 | private PatientsService patientsService; |
| 41 | 42 | @Autowired |
| ... | ... | @@ -62,6 +63,8 @@ |
| 62 | 63 | @Autowired |
| 63 | 64 | private MatDeliverService matDeliverService; |
| 64 | 65 | |
| 66 | + private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>()); | |
| 67 | + | |
| 65 | 68 | /** |
| 66 | 69 | * 修改产妇的社区 |
| 67 | 70 | * |
| 68 | 71 | |
| 69 | 72 | |
| 70 | 73 | |
| 71 | 74 | |
| 72 | 75 | |
| 73 | 76 | |
| 74 | 77 | |
| 75 | 78 | |
| 76 | 79 | |
| 77 | 80 | |
| 78 | 81 | |
| 79 | 82 | |
| 80 | 83 | |
| 81 | 84 | |
| 82 | 85 | |
| 83 | 86 | |
| 84 | 87 | |
| 85 | 88 | |
| 86 | 89 | |
| ... | ... | @@ -501,140 +504,181 @@ |
| 501 | 504 | return data; |
| 502 | 505 | } |
| 503 | 506 | |
| 504 | - /** | |
| 505 | - * 转换成高危产妇的返回对象 | |
| 506 | - * | |
| 507 | - * @param patientses | |
| 508 | - * @return | |
| 509 | - */ | |
| 510 | - private List convertToHighRisk(List<Patients> patientses, Integer userId, String hospital) { | |
| 511 | - AntExChuQuery antExChuQuery = new AntExChuQuery(); | |
| 512 | - AntExQuery antExQuery = new AntExQuery(); | |
| 513 | - List data = new ArrayList<>(); | |
| 514 | -// String hospital = autoMatchFacade.getHospitalId(userId); | |
| 515 | - for (Patients patients : patientses) { | |
| 516 | - StopWatch stopWatch = new StopWatch("convert -" + patients.getId()); | |
| 517 | - RiskPatientsResult riskPatientsResult = new RiskPatientsResult(); | |
| 518 | - riskPatientsResult.convertToResult(patients); | |
| 519 | - if (StringUtils.isNotEmpty(patients.getBookbuildingDoctor())) { | |
| 520 | - if (NumberUtils.isNumber(patients.getBookbuildingDoctor())) { | |
| 521 | - Users users = usersService.getUsers(NumberUtils.toInt(patients.getBookbuildingDoctor())); | |
| 522 | - if (null != users) { | |
| 523 | - riskPatientsResult.setlName(users.getName()); | |
| 507 | + private static class WorkHR implements Callable<List<RiskPatientsResult>> { | |
| 508 | + private List<Patients> patientses; | |
| 509 | + | |
| 510 | + private BasicConfigService basicConfigService; | |
| 511 | + private AntenatalExaminationService antExService; | |
| 512 | + private UsersService usersService; | |
| 513 | + private String hospital; | |
| 514 | + | |
| 515 | + public WorkHR(List<Patients> patientses, UsersService usersService, String hospital) { | |
| 516 | + this.patientses = patientses; | |
| 517 | + this.usersService = usersService; | |
| 518 | + this.hospital = hospital; | |
| 519 | + } | |
| 520 | + | |
| 521 | + public List<RiskPatientsResult> call() { | |
| 522 | + List<RiskPatientsResult> dataList = new ArrayList<>(); | |
| 523 | + for (Patients patients : patientses) { | |
| 524 | + StopWatch stopWatch = new StopWatch("convert -" + patients.getId()); | |
| 525 | + RiskPatientsResult riskPatientsResult = new RiskPatientsResult(); | |
| 526 | + riskPatientsResult.convertToResult(patients); | |
| 527 | + if (StringUtils.isNotEmpty(patients.getBookbuildingDoctor())) { | |
| 528 | + if (NumberUtils.isNumber(patients.getBookbuildingDoctor())) { | |
| 529 | + Users users = usersService.getUsers(NumberUtils.toInt(patients.getBookbuildingDoctor())); | |
| 530 | + if (null != users) { | |
| 531 | + riskPatientsResult.setlName(users.getName()); | |
| 532 | + } else { | |
| 533 | + riskPatientsResult.setlName(patients.getBookbuildingDoctor()); | |
| 534 | + } | |
| 524 | 535 | } else { |
| 525 | 536 | riskPatientsResult.setlName(patients.getBookbuildingDoctor()); |
| 526 | 537 | } |
| 527 | - } else { | |
| 528 | - riskPatientsResult.setlName(patients.getBookbuildingDoctor()); | |
| 529 | 538 | } |
| 530 | - } | |
| 531 | 539 | |
| 540 | + AntExChuQuery antExChuQuery = new AntExChuQuery(); | |
| 541 | + AntExQuery antExQuery = new AntExQuery(); | |
| 532 | 542 | |
| 533 | - antExQuery.setPid(patients.getPid()); | |
| 534 | - antExQuery.setYn(YnEnums.YES.getId()); | |
| 535 | - antExQuery.setHospitalId(null); | |
| 536 | - stopWatch.start("cap antex count"); | |
| 537 | - //复诊次数 | |
| 538 | - int i = antExService.queryAntenatalExaminationCount(antExQuery.convertToQuery()); | |
| 539 | - antExChuQuery.setPid(patients.getPid()); | |
| 540 | - antExChuQuery.setYn(YnEnums.YES.getId()); | |
| 541 | - //初诊次数 | |
| 542 | - antExChuQuery.setHospitalId(null); | |
| 543 | - int b = antExService.queryAntExChuCount(antExChuQuery.convertToQuery()); | |
| 544 | - antExQuery.setHospitalId(hospital); | |
| 545 | - //本院的复诊记录 | |
| 546 | - int chi = antExService.queryAntenatalExaminationCount(antExQuery.convertToQuery()); | |
| 547 | - antExChuQuery.setHospitalId(hospital); | |
| 548 | - //本院的初诊记录 | |
| 549 | - int chb = antExService.queryAntExChuCount(antExChuQuery.convertToQuery()); | |
| 550 | - riskPatientsResult.setcTimes(i + b); | |
| 551 | - riskPatientsResult.setcHTimes(chi + chb); | |
| 552 | - String nextCheckTime = ""; | |
| 553 | - stopWatch.stop(); | |
| 554 | - stopWatch.start("query antex count"); | |
| 543 | + antExQuery.setPid(patients.getPid()); | |
| 544 | + antExQuery.setYn(YnEnums.YES.getId()); | |
| 545 | + antExQuery.setHospitalId(null); | |
| 546 | + stopWatch.start("cap antex count"); | |
| 547 | + //复诊次数 | |
| 548 | + int i = antExService.queryAntenatalExaminationCount(antExQuery.convertToQuery()); | |
| 549 | + antExChuQuery.setPid(patients.getPid()); | |
| 550 | + antExChuQuery.setYn(YnEnums.YES.getId()); | |
| 551 | + //初诊次数 | |
| 552 | + antExChuQuery.setHospitalId(null); | |
| 553 | + int b = antExService.queryAntExChuCount(antExChuQuery.convertToQuery()); | |
| 554 | + antExQuery.setHospitalId(hospital); | |
| 555 | + //本院的复诊记录 | |
| 556 | + int chi = antExService.queryAntenatalExaminationCount(antExQuery.convertToQuery()); | |
| 557 | + antExChuQuery.setHospitalId(hospital); | |
| 558 | + //本院的初诊记录 | |
| 559 | + int chb = antExService.queryAntExChuCount(antExChuQuery.convertToQuery()); | |
| 560 | + riskPatientsResult.setcTimes(i + b); | |
| 561 | + riskPatientsResult.setcHTimes(chi + chb); | |
| 562 | + String nextCheckTime = ""; | |
| 563 | + stopWatch.stop(); | |
| 564 | + stopWatch.start("query antex count"); | |
| 555 | 565 | |
| 556 | - List<AntenatalExaminationModel> examinationModels = antExService.queryAntenatalExamination(antExQuery.convertToQuery().addOrder(Sort.Direction.DESC, "created")); | |
| 557 | - if (CollectionUtils.isNotEmpty(examinationModels)) { | |
| 558 | - if (NumberUtils.isNumber(examinationModels.get(0).getCheckDoctor())) { | |
| 559 | - Users users = usersService.getUsers(NumberUtils.toInt(examinationModels.get(0).getCheckDoctor())); | |
| 560 | - if (null != users) { | |
| 561 | - riskPatientsResult.setCheckDoctor(users.getName()); | |
| 562 | - } else { | |
| 563 | - riskPatientsResult.setCheckDoctor(examinationModels.get(0).getCheckDoctor()); | |
| 564 | - } | |
| 565 | - } | |
| 566 | - nextCheckTime = DateUtil.getyyyy_MM_dd(examinationModels.get(0).getNextCheckTime()); | |
| 567 | - } else { | |
| 568 | - List<AntExChuModel> list = antExService.queryAntExChu(antExChuQuery); | |
| 569 | - if (CollectionUtils.isNotEmpty(list)) { | |
| 570 | - nextCheckTime = DateUtil.getyyyy_MM_dd(list.get(0).getNextCheckTime()); | |
| 571 | - if (NumberUtils.isNumber(list.get(0).getProdDoctor())) { | |
| 572 | - Users users = usersService.getUsers(NumberUtils.toInt(list.get(0).getProdDoctor())); | |
| 566 | + List<AntenatalExaminationModel> examinationModels = antExService.queryAntenatalExamination(antExQuery.convertToQuery().addOrder(Sort.Direction.DESC, "created")); | |
| 567 | + if (CollectionUtils.isNotEmpty(examinationModels)) { | |
| 568 | + if (NumberUtils.isNumber(examinationModels.get(0).getCheckDoctor())) { | |
| 569 | + Users users = usersService.getUsers(NumberUtils.toInt(examinationModels.get(0).getCheckDoctor())); | |
| 573 | 570 | if (null != users) { |
| 574 | 571 | riskPatientsResult.setCheckDoctor(users.getName()); |
| 575 | 572 | } else { |
| 576 | - riskPatientsResult.setCheckDoctor(list.get(0).getProdDoctor()); | |
| 573 | + riskPatientsResult.setCheckDoctor(examinationModels.get(0).getCheckDoctor()); | |
| 577 | 574 | } |
| 578 | 575 | } |
| 576 | + nextCheckTime = DateUtil.getyyyy_MM_dd(examinationModels.get(0).getNextCheckTime()); | |
| 577 | + } else { | |
| 578 | + List<AntExChuModel> list = antExService.queryAntExChu(antExChuQuery); | |
| 579 | + if (CollectionUtils.isNotEmpty(list)) { | |
| 580 | + nextCheckTime = DateUtil.getyyyy_MM_dd(list.get(0).getNextCheckTime()); | |
| 581 | + if (NumberUtils.isNumber(list.get(0).getProdDoctor())) { | |
| 582 | + Users users = usersService.getUsers(NumberUtils.toInt(list.get(0).getProdDoctor())); | |
| 583 | + if (null != users) { | |
| 584 | + riskPatientsResult.setCheckDoctor(users.getName()); | |
| 585 | + } else { | |
| 586 | + riskPatientsResult.setCheckDoctor(list.get(0).getProdDoctor()); | |
| 587 | + } | |
| 588 | + } | |
| 589 | + } | |
| 579 | 590 | } |
| 580 | - } | |
| 581 | - stopWatch.stop(); | |
| 591 | + stopWatch.stop(); | |
| 582 | 592 | |
| 583 | - riskPatientsResult.setServiceType(ServiceTypeEnums.getTitleById(patients.getServiceType())); | |
| 584 | - riskPatientsResult.setServiceStatus(ServiceStatusEnums.getNameById(patients.getServiceStatus())); | |
| 585 | - riskPatientsResult.setcTime(nextCheckTime); | |
| 586 | - stopWatch.start("query findLastRisk"); | |
| 587 | - /* HighScoreResult highScoreResult = antenatalExaminationFacade.findLastRisk(patients.getPid(), true); | |
| 588 | - riskPatientsResult.setrFactor(highScoreResult.gethighRiskStr()); | |
| 589 | - riskPatientsResult.setrLevel(highScoreResult.filter(highScoreResult.getLevel())); | |
| 590 | - riskPatientsResult.sethScore(highScoreResult.getScore());*/ | |
| 591 | - HighScoreResult highScoreResult = new HighScoreResult(); | |
| 593 | + riskPatientsResult.setServiceType(ServiceTypeEnums.getTitleById(patients.getServiceType())); | |
| 594 | + riskPatientsResult.setServiceStatus(ServiceStatusEnums.getNameById(patients.getServiceStatus())); | |
| 595 | + riskPatientsResult.setcTime(nextCheckTime); | |
| 596 | + stopWatch.start("query findLastRisk"); | |
| 597 | + /* HighScoreResult highScoreResult = antenatalExaminationFacade.findLastRisk(patients.getPid(), true); | |
| 598 | + riskPatientsResult.setrFactor(highScoreResult.gethighRiskStr()); | |
| 599 | + riskPatientsResult.setrLevel(highScoreResult.filter(highScoreResult.getLevel())); | |
| 600 | + riskPatientsResult.sethScore(highScoreResult.getScore());*/ | |
| 601 | + HighScoreResult highScoreResult = new HighScoreResult(); | |
| 592 | 602 | |
| 593 | 603 | |
| 594 | - //高危因素 | |
| 595 | - List<String> factor = patients.getRiskFactorId(); | |
| 604 | + //高危因素 | |
| 605 | + List<String> factor = patients.getRiskFactorId(); | |
| 596 | 606 | |
| 597 | - if (CollectionUtils.isNotEmpty(factor)) { | |
| 598 | - StringBuilder sb = new StringBuilder(56); | |
| 599 | - for (String srt : factor) { | |
| 600 | - if (StringUtils.isNotEmpty(srt)) { | |
| 601 | - BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(srt); | |
| 602 | - if (null != basicConfig && sb.indexOf(basicConfig.getName()) > -1) { | |
| 603 | - sb.append(basicConfig.getName()).append(','); | |
| 607 | + if (CollectionUtils.isNotEmpty(factor)) { | |
| 608 | + StringBuilder sb = new StringBuilder(56); | |
| 609 | + for (String srt : factor) { | |
| 610 | + if (StringUtils.isNotEmpty(srt)) { | |
| 611 | + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(srt); | |
| 612 | + if (null != basicConfig && sb.indexOf(basicConfig.getName()) > -1) { | |
| 613 | + sb.append(basicConfig.getName()).append(','); | |
| 614 | + } | |
| 604 | 615 | } |
| 605 | 616 | } |
| 617 | + if (sb.toString().endsWith(",")) { | |
| 618 | + riskPatientsResult.setrFactor(sb.substring(0, sb.length() - 1)); | |
| 619 | + } else { | |
| 620 | + riskPatientsResult.setrFactor(sb.toString()); | |
| 621 | + } | |
| 606 | 622 | } |
| 607 | - if(sb.toString().endsWith(",")){ | |
| 608 | - riskPatientsResult.setrFactor(sb.substring(0,sb.length()-1)); | |
| 609 | - }else{ | |
| 610 | - riskPatientsResult.setrFactor(sb.toString()); | |
| 611 | - } | |
| 612 | - } | |
| 613 | - List level =new ArrayList(); | |
| 614 | - if(StringUtils.isNotEmpty(patients.getRiskLevelId())){ | |
| 615 | - try { | |
| 616 | - List<String> list = JsonUtil.jkstr2Obj(patients.getRiskLevelId(),List.class); | |
| 617 | - for(String str:list){ | |
| 618 | - BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(str); | |
| 619 | - if (null != basicConfig) { | |
| 620 | - Map map =new HashMap(); | |
| 621 | - String name = basicConfig.getName(); | |
| 622 | - if (name.indexOf("预警") > -1) { | |
| 623 | - name = name.replace("预警", ""); | |
| 623 | + List level = new ArrayList(); | |
| 624 | + if (StringUtils.isNotEmpty(patients.getRiskLevelId())) { | |
| 625 | + try { | |
| 626 | + List<String> list = JsonUtil.jkstr2Obj(patients.getRiskLevelId(), List.class); | |
| 627 | + for (String str : list) { | |
| 628 | + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(str); | |
| 629 | + if (null != basicConfig) { | |
| 630 | + Map map = new HashMap(); | |
| 631 | + String name = basicConfig.getName(); | |
| 632 | + if (name.indexOf("预警") > -1) { | |
| 633 | + name = name.replace("预警", ""); | |
| 634 | + } | |
| 635 | + map.put("color", "risk_" + RiskDefaultTypeEnum.getColor(name)); | |
| 636 | + level.add(map); | |
| 624 | 637 | } |
| 625 | - map.put("color", "risk_" + RiskDefaultTypeEnum.getColor(name)); | |
| 626 | - level.add(map); | |
| 627 | 638 | } |
| 639 | + } catch (Exception e) { | |
| 628 | 640 | } |
| 629 | - }catch (Exception e){ | |
| 641 | + riskPatientsResult.setrLevel(level); | |
| 630 | 642 | } |
| 631 | - riskPatientsResult.setrLevel(level); | |
| 643 | + | |
| 644 | + riskPatientsResult.sethScore(patients.getRiskScore()); | |
| 645 | + dataList.add(riskPatientsResult); | |
| 646 | + stopWatch.stop(); | |
| 647 | + logger.info(stopWatch.toString()); | |
| 632 | 648 | } |
| 649 | + return dataList; | |
| 650 | + } | |
| 651 | + } | |
| 633 | 652 | |
| 634 | - riskPatientsResult.sethScore(patients.getRiskScore()); | |
| 635 | - stopWatch.stop(); | |
| 636 | - logger.info(stopWatch.toString()); | |
| 637 | - data.add(riskPatientsResult); | |
| 653 | + /** | |
| 654 | + * 转换成高危产妇的返回对象 | |
| 655 | + * | |
| 656 | + * @param patientses | |
| 657 | + * @return | |
| 658 | + */ | |
| 659 | + private List convertToHighRisk(List<Patients> patientses, Integer userId, String hospital) { | |
| 660 | + AntExChuQuery antExChuQuery = new AntExChuQuery(); | |
| 661 | + AntExQuery antExQuery = new AntExQuery(); | |
| 662 | + List data = new ArrayList<>(); | |
| 663 | + //String hospital = autoMatchFacade.getHospitalId(userId); | |
| 664 | + | |
| 665 | + int batchSize = 5; | |
| 666 | + int start = 0, end = 0; | |
| 667 | + List<Future> listFuture = new ArrayList<>(); | |
| 668 | + for (int i = 0; i < patientses.size(); i += batchSize) { | |
| 669 | + end = (end + batchSize); | |
| 670 | + if (end > patientses.size()) { | |
| 671 | + end = patientses.size(); | |
| 672 | + } | |
| 673 | + System.out.println("start:" + i + ",end:" + end); | |
| 674 | + listFuture.add(threadPoolExecutor.submit(new WorkHR(patientses.subList(i, end), usersService, hospital))); | |
| 675 | + } | |
| 676 | + for (Future f : listFuture) { | |
| 677 | + try { | |
| 678 | + data.addAll((List) f.get(30, TimeUnit.SECONDS)); | |
| 679 | + } catch (Exception e) { | |
| 680 | + ExceptionUtils.catchException(e, "get result Future error."); | |
| 681 | + } | |
| 638 | 682 | } |
| 639 | 683 | return data; |
| 640 | 684 | } |