Commit 80d62430ed8f1e6d52fa3f08d25c831e6026a052
1 parent
d275f199da
Exists in
master
and in
1 other branch
高危统计
Showing 1 changed file with 66 additions and 26 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/HiskCountTask.java
View file @
80d6243
| ... | ... | @@ -4,8 +4,10 @@ |
| 4 | 4 | import com.lyms.platform.biz.service.PatientsService; |
| 5 | 5 | import com.lyms.platform.common.enums.RiskDefaultTypeEnum; |
| 6 | 6 | import com.lyms.platform.common.enums.YnEnums; |
| 7 | +import com.lyms.platform.common.utils.ExceptionUtils; | |
| 7 | 8 | import com.lyms.platform.common.utils.SystemConfig; |
| 8 | 9 | import com.lyms.platform.operate.web.result.RiskReportResult; |
| 10 | +import com.lyms.platform.operate.web.worker.WorkHR; | |
| 9 | 11 | import com.lyms.platform.pojo.BasicConfig; |
| 10 | 12 | import com.lyms.platform.query.BasicConfigQuery; |
| 11 | 13 | import com.lyms.platform.query.PatientsQuery; |
| 12 | 14 | |
| ... | ... | @@ -16,13 +18,15 @@ |
| 16 | 18 | import java.util.HashMap; |
| 17 | 19 | import java.util.List; |
| 18 | 20 | import java.util.Map; |
| 19 | -import java.util.concurrent.Callable; | |
| 21 | +import java.util.concurrent.*; | |
| 20 | 22 | |
| 21 | 23 | /** |
| 22 | 24 | * Created by Administrator on 2016/11/30. |
| 23 | 25 | */ |
| 24 | 26 | public class HiskCountTask implements Callable { |
| 25 | 27 | |
| 28 | + private static ExecutorService pool = Executors.newFixedThreadPool(4); | |
| 29 | + | |
| 26 | 30 | private PatientsService patientsService; |
| 27 | 31 | private BasicConfigService basicConfigService; |
| 28 | 32 | private BasicConfig levelConfig; |
| 29 | 33 | |
| 30 | 34 | |
| 31 | 35 | |
| 32 | 36 | |
| 33 | 37 | |
| 34 | 38 | |
| 35 | 39 | |
| ... | ... | @@ -52,39 +56,73 @@ |
| 52 | 56 | List<BasicConfig> riskConfig = basicConfigService.queryBasicConfig(basicConfigQuery); |
| 53 | 57 | |
| 54 | 58 | if (CollectionUtils.isNotEmpty(riskConfig)) { |
| 55 | - for (BasicConfig config : riskConfig) { | |
| 56 | - patientsQuery.setrFactor(config.getId()); | |
| 57 | - //单个高危因素孕产妇条数 | |
| 58 | - int riskPatientCount = patientsService.queryPatientCount(patientsQuery); | |
| 59 | - if (riskPatientCount > 0) | |
| 59 | + | |
| 60 | + int batchSize = 3; | |
| 61 | + int end = 0; | |
| 62 | + List<Future> futures = new ArrayList<>(); | |
| 63 | + for (int i = 0; i < riskConfig.size(); i += batchSize) { | |
| 64 | + end = (end + batchSize); | |
| 65 | + if (end > riskConfig.size()) { | |
| 66 | + end = riskConfig.size(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + final List<BasicConfig> configs = riskConfig.subList(i, end); | |
| 70 | + Callable c = new Callable() | |
| 60 | 71 | { |
| 61 | - RiskReportResult risk = new RiskReportResult(); | |
| 62 | - risk.setHighRiskId(config.getId()); | |
| 63 | - risk.setHighRisk(config.getName()); | |
| 64 | - risk.setRiskCount(String.valueOf(riskPatientCount)); | |
| 72 | + @Override | |
| 73 | + public List<RiskReportResult> call() throws Exception { | |
| 74 | + List<RiskReportResult> datas = new ArrayList<>(); | |
| 65 | 75 | |
| 66 | - DecimalFormat df = new DecimalFormat("0.00"); | |
| 67 | - String percent = df.format((double)riskPatientCount/allPatientCount*100)+"%"; | |
| 68 | - risk.setPercent(percent); | |
| 76 | + for (BasicConfig config : configs) { | |
| 77 | + patientsQuery.setrFactor(config.getId()); | |
| 78 | + //单个高危因素孕产妇条数 | |
| 79 | + int riskPatientCount = patientsService.queryPatientCount(patientsQuery); | |
| 80 | + if (riskPatientCount > 0) | |
| 81 | + { | |
| 82 | + RiskReportResult risk = new RiskReportResult(); | |
| 83 | + risk.setHighRiskId(config.getId()); | |
| 84 | + risk.setHighRisk(config.getName()); | |
| 85 | + risk.setRiskCount(String.valueOf(riskPatientCount)); | |
| 69 | 86 | |
| 70 | - if (null != levelConfig) { | |
| 71 | - List level = new ArrayList(); | |
| 72 | - Map map = new HashMap(); | |
| 73 | - String name = levelConfig.getName(); | |
| 74 | - if (name.indexOf("预警") > -1) { | |
| 75 | - name = name.replace("预警", ""); | |
| 87 | + DecimalFormat df = new DecimalFormat("0.00"); | |
| 88 | + String percent = df.format((double)riskPatientCount/allPatientCount*100)+"%"; | |
| 89 | + risk.setPercent(percent); | |
| 90 | + | |
| 91 | + if (null != levelConfig) { | |
| 92 | + List level = new ArrayList(); | |
| 93 | + Map map = new HashMap(); | |
| 94 | + String name = levelConfig.getName(); | |
| 95 | + if (name.indexOf("预警") > -1) { | |
| 96 | + name = name.replace("预警", ""); | |
| 97 | + } | |
| 98 | + map.put("name", name); | |
| 99 | + map.put("color", "risk_" + RiskDefaultTypeEnum.getColor(name)); | |
| 100 | + level.add(map); | |
| 101 | + risk.setHighLevel(level); | |
| 102 | + } | |
| 103 | + | |
| 104 | + datas.add(risk); | |
| 105 | + } | |
| 76 | 106 | } |
| 77 | - map.put("name", name); | |
| 78 | - map.put("color", "risk_" + RiskDefaultTypeEnum.getColor(name)); | |
| 79 | - level.add(map); | |
| 80 | - risk.setHighLevel(level); | |
| 107 | + | |
| 108 | + return datas; | |
| 81 | 109 | } |
| 110 | + }; | |
| 82 | 111 | |
| 83 | - results.add(risk); | |
| 112 | + Future f = pool.submit(c); | |
| 113 | + futures.add(f); | |
| 114 | + } | |
| 115 | + for (Future f : futures) { | |
| 116 | + try { | |
| 117 | + results.addAll((List) f.get(30, TimeUnit.SECONDS)); | |
| 118 | + } catch (Exception e) { | |
| 119 | + ExceptionUtils.catchException(e, "patient hisk count."); | |
| 84 | 120 | } |
| 85 | 121 | } |
| 86 | 122 | } |
| 87 | 123 | return results; |
| 88 | 124 | } |
| 125 | + | |
| 126 | + | |
| 89 | 127 | } |