Commit b7686bd9db86ad24096354d56d6a90deb121decb

Authored by wtt
1 parent 41a5aa195f
Exists in master and in 1 other branch dev

update

Showing 3 changed files with 325 additions and 15 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BabyStatisticsController.java View file @ b7686bd
... ... @@ -29,9 +29,20 @@
29 29 */
30 30 @ResponseBody
31 31 @TokenRequired
32   - @RequestMapping(value = "/matchpuerpera", method = RequestMethod.POST)
33   - public BaseResponse matchCommunity(@RequestBody BabyStatisticsQueryRequest babyStatisticsQueryRequest) {
  32 + @RequestMapping(value = "/statistics", method = RequestMethod.POST)
  33 + public BaseResponse statistics(@RequestBody BabyStatisticsQueryRequest babyStatisticsQueryRequest) {
34 34 return babyStatisticsFacade.statistics(babyStatisticsQueryRequest);
  35 + }
  36 + /**
  37 + 儿童统计
  38 + * @Author: 武涛涛
  39 + * @Date: 2021/3/20 13:55
  40 + */
  41 + @ResponseBody
  42 + @TokenRequired
  43 + @RequestMapping(value = "/statistics2", method = RequestMethod.POST)
  44 + public BaseResponse statistics2(@RequestBody BabyStatisticsQueryRequest babyStatisticsQueryRequest) {
  45 + return babyStatisticsFacade.statistics2(babyStatisticsQueryRequest);
35 46 }
36 47  
37 48  
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BabyStatisticsFacade.java View file @ b7686bd
... ... @@ -5,9 +5,16 @@
5 5 import com.lyms.platform.common.enums.YnEnums;
6 6 import com.lyms.platform.common.result.BaseObjectResponse;
7 7 import com.lyms.platform.common.result.BaseResponse;
  8 +import com.lyms.platform.common.utils.DateUtil;
  9 +import com.lyms.platform.common.utils.ExceptionUtils;
8 10 import com.lyms.platform.common.utils.StringUtils;
9 11 import com.lyms.platform.operate.web.request.BabyStatisticsQueryRequest;
10 12 import com.lyms.platform.operate.web.service.impl.BaseServiceImpl;
  13 +import com.lyms.platform.operate.web.worker.BabyStatisticsWorker;
  14 +import com.lyms.platform.permission.dao.master.BabyPatientExtendEarHearingDiagnoseMapper;
  15 +import com.lyms.platform.permission.dao.master.BabyPatientExtendEarScreenMapper;
  16 +import com.lyms.platform.permission.model.BabyPatientExtendEarHearingDiagnoseQuery;
  17 +import com.lyms.platform.permission.model.BabyPatientExtendEarScreenQuery;
11 18 import com.lyms.platform.permission.model.Organization;
12 19 import com.lyms.platform.permission.model.OrganizationQuery;
13 20 import com.lyms.platform.permission.service.OrganizationService;
14 21  
15 22  
16 23  
17 24  
18 25  
19 26  
20 27  
... ... @@ -17,39 +24,64 @@
17 24 import org.slf4j.Logger;
18 25 import org.slf4j.LoggerFactory;
19 26 import org.springframework.beans.factory.annotation.Autowired;
  27 +import org.springframework.beans.factory.annotation.Qualifier;
20 28 import org.springframework.data.mongodb.core.MongoTemplate;
21 29 import org.springframework.data.mongodb.core.aggregation.Aggregation;
22 30 import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
23 31 import org.springframework.data.mongodb.core.aggregation.AggregationResults;
24 32 import org.springframework.data.mongodb.core.query.Criteria;
25 33 import org.springframework.data.mongodb.core.query.Query;
  34 +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
26 35 import org.springframework.stereotype.Component;
27 36  
28 37 import java.text.DecimalFormat;
29 38 import java.util.*;
  39 +import java.util.concurrent.Future;
  40 +import java.util.concurrent.TimeUnit;
30 41  
31 42  
32 43 @Component
33 44 public class BabyStatisticsFacade extends BaseServiceImpl {
34 45 private static final Logger logger = LoggerFactory.getLogger(BabyStatisticsFacade.class);
35 46 // 儿童建册率分母
36   - private Long babyfm;
  47 + private Long babyfm = 0L;
37 48  
38 49 @Autowired
39 50 private OrganizationService organizationService;
  51 +
40 52 @Autowired
41 53 private MongoTemplate mongoTemplate;
42 54  
43 55 @Autowired
44 56 private IPatientDao iPatientDao;
45 57  
  58 + @Autowired
  59 + private BabyPatientExtendEarScreenMapper babyPatientExtendEarScreenMapper;
  60 +
  61 + @Autowired
  62 + private BabyPatientExtendEarHearingDiagnoseMapper babyPatientExtendEarHearingDiagnoseMapper;
  63 +
  64 + @Autowired
  65 + @Qualifier("commonThreadPool")
  66 + private ThreadPoolTaskExecutor commonThreadPool;
  67 +
  68 + public BaseResponse statistics2(BabyStatisticsQueryRequest queryRequest) {
  69 + List < Map<Integer,Statistic>> listMaps = init();
  70 + long startTime=System.currentTimeMillis(); //获取开始时间
  71 + List <Map> mapList = convertToHugeQuanWeight(listMaps,queryRequest);
  72 + long endTime=System.currentTimeMillis(); //获取结束时间
  73 + System.out.println("程序运行毫秒: "+(endTime-startTime)+"ms");
  74 + return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(mapList);
  75 + }
46 76 /*
47   - 儿童统计:
48   - 1:高危儿管理率、2:儿童建册率、3:低出生体重儿百分比、
49   - 4:3岁以下儿童系统管理率、5.1:中重度贫血率、5.2:5岁以下儿童肥胖率、6:听力确诊率、7:听力筛查率
50   - */
  77 + 儿童统计:
  78 + 1:高危儿管理率、2:儿童建册率、3:低出生体重儿百分比、
  79 + 4:3岁以下儿童系统管理率、5.1:中重度贫血率、5.2:5岁以下儿童肥胖率、6:听力确诊率、7:听力筛查率
  80 + */
51 81 public BaseResponse statistics(BabyStatisticsQueryRequest queryRequest) {
52 82 Map <String, Object> staMaps = new HashMap <>();
  83 + long startTime=System.currentTimeMillis(); //获取开始时间
  84 +
53 85 List <String> provinceCityAreaHid = getProvinceCityAreaHid(queryRequest);
54 86 //1:高危儿管理率
55 87 Map <String, String> gwMap = getGwMap(queryRequest, provinceCityAreaHid);
56 88  
57 89  
58 90  
59 91  
60 92  
... ... @@ -71,14 +103,194 @@
71 103 Map <String, String> fplMap = getFplMap(queryRequest, provinceCityAreaHid);
72 104 staMaps.put("fplMap", fplMap);
73 105  
  106 + //6:听力确诊率
  107 + Map <String, String> tlqzMap = getTlqzMap(queryRequest, provinceCityAreaHid);
  108 + staMaps.put("tlqzMap", tlqzMap);
74 109  
  110 + //7:听力筛查率
  111 + Map <String, String> tlscMap = getTlscMap(queryRequest, provinceCityAreaHid);
  112 + staMaps.put("tlscMap", tlscMap);
75 113  
76 114  
77   -
  115 + long endTime=System.currentTimeMillis(); //获取结束时间
  116 + System.out.println("程序运行毫秒: "+(endTime-startTime)+"ms");
78 117 return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(staMaps);
79 118 }
  119 + /*
  120 + 1 定义 接口 抽象方法
  121 + 2 实现 接口 抽象方法,不同对象的实现抽象方法,
  122 + 3 不同对象的实现抽象方法,存储在list<map>集合中。
  123 + 4 遍历list使用线程执集合元素
  124 + */
80 125  
  126 + private List <Map> convertToHugeQuanWeight( List< Map<Integer,Statistic>> listMaps,BabyStatisticsQueryRequest queryRequest) {
  127 + List <String> provinceCityAreaHid = getProvinceCityAreaHid(queryRequest);
  128 + List <Map> data = new ArrayList <>();
  129 + int batchSize = 2;
  130 + int end = 0;
  131 + List <Future> listFuture = new ArrayList <>();
  132 + for (int i = 0; i < listMaps.size(); i += batchSize) {
  133 + end = (end + batchSize);
  134 + if (end > listMaps.size()) {
  135 + end = listMaps.size();
  136 + }
  137 +// listFuture.add(commonThreadPool.submit(new BabyStatisticsWorker(listMaps.subList(i, end), mongoTemplate, commonService, basicConfigService)));
  138 + listFuture.add(commonThreadPool.submit(new BabyStatisticsWorker(listMaps.subList(i, end), queryRequest, provinceCityAreaHid)));
  139 + }
  140 + if(listFuture != null){
  141 + for (Future f : listFuture) {
  142 + try {
  143 + if(f!=null && f.get(30, TimeUnit.SECONDS)!=null){
  144 + data.addAll((List <Map>) f.get(300, TimeUnit.SECONDS));
  145 + }
  146 + } catch (Exception e) {
  147 + ExceptionUtils.catchException(e, "convertToQuanWeight get result Future error.");
  148 + }
  149 + }
  150 + }
  151 + return data;
  152 + }
  153 +
  154 +
  155 +
  156 +
  157 + public interface Statistic {
  158 + abstract Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid);
  159 + }
  160 + //1:高危儿管理率
  161 + class GwMap implements Statistic{
  162 + @Override
  163 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  164 + return getGwMap(queryRequest, provinceCityAreaHid);
  165 + }
  166 + }
  167 + //2:儿童建册率
  168 + class BabyMap implements Statistic{
  169 + @Override
  170 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  171 + return getBabyMap(queryRequest, provinceCityAreaHid);
  172 + }
  173 + }
  174 + //3:低出生体重儿百分比
  175 + class DtzMap implements Statistic{
  176 + @Override
  177 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  178 + return getDtzMap(queryRequest, provinceCityAreaHid);
  179 + }
  180 + }
  181 + //4 :中重度贫血率
  182 + class ZdpxMap implements Statistic{
  183 + @Override
  184 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  185 + return getZdpxMap(queryRequest, provinceCityAreaHid);
  186 + }
  187 + }
  188 + //5 :5岁以下儿童肥胖率
  189 + class FplMap implements Statistic{
  190 + @Override
  191 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  192 + return getFplMap(queryRequest, provinceCityAreaHid);
  193 + }
  194 + }
  195 + //6:听力确诊率
  196 + class TlqzMap implements Statistic{
  197 + @Override
  198 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  199 + return getTlqzMap(queryRequest, provinceCityAreaHid);
  200 + }
  201 + }
  202 + //7:听力筛查率
  203 + class TlscMap implements Statistic{
  204 + @Override
  205 + public Map <String, String> statisticMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  206 + return getTlscMap(queryRequest, provinceCityAreaHid);
  207 + }
  208 + }
  209 +
  210 +
  211 +
81 212 /**
  213 + 7:听力筛查率
  214 + * @Author: 武涛涛
  215 + * @Date: 2021/3/20 14:09
  216 + */
  217 + private Map <String, String> getTlscMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  218 + Map <String, String> map = new HashMap <>();
  219 +
  220 + try {
  221 + //分子 听筛管理的初筛条数
  222 + BabyPatientExtendEarScreenQuery screenQuery = new BabyPatientExtendEarScreenQuery();
  223 + screenQuery.setScreenType(1);// 1=初筛 2=复筛
  224 + String[] str2= (String[])provinceCityAreaHid.toArray(new String[provinceCityAreaHid.size()]);
  225 + screenQuery.setCheckHospitalIds(str2);
  226 + screenQuery.setScreenStartDate(DateUtil.getYmdhmDate(queryRequest.getTimeStart()));
  227 + screenQuery.setScreenEndDate(DateUtil.getYmdhmDate(queryRequest.getTimeEnd()));
  228 + Integer fz = babyPatientExtendEarScreenMapper.queryEarScreenListCount(screenQuery);
  229 + map.put("fz",fz.toString());
  230 +
  231 + //分母
  232 + Long fm = getBabyfm();
  233 + map.put("fm",fm.toString());
  234 +
  235 + //分率
  236 + if(fz !=null && fm !=null){
  237 + Double fld = (double)fz/fm * 100;
  238 + if(fld <=0.01 ){
  239 + fld = 0.01;
  240 + }
  241 + map.put("fl", new DecimalFormat("0.00").format(fld)+"%");
  242 + }
  243 +
  244 + } catch (Exception e) {
  245 + e.printStackTrace();
  246 + }
  247 + return map;
  248 + }
  249 + /**
  250 + 6:听力确诊率
  251 + * @Author: 武涛涛
  252 + * @Date: 2021/3/20 14:09
  253 + */
  254 + private Map <String, String> getTlqzMap(BabyStatisticsQueryRequest queryRequest, List <String> provinceCityAreaHid) {
  255 + Map <String, String> map = new HashMap <>();
  256 +
  257 + try {
  258 + String[] str2= (String[])provinceCityAreaHid.toArray(new String[provinceCityAreaHid.size()]);
  259 +
  260 + //分子 分子为确诊病历人数(诊断管理的已确诊条数)
  261 + BabyPatientExtendEarHearingDiagnoseQuery query = new BabyPatientExtendEarHearingDiagnoseQuery();
  262 + query.setCheckHospitalIds(str2);
  263 + query.setIsconfirm(1);//1-确诊
  264 + query.setDiagnoseStartTime(DateUtil.getYmdhmDate(queryRequest.getTimeStart()));
  265 + query.setDiagnoseEndTime(DateUtil.getYmdhmDate(queryRequest.getTimeEnd()));
  266 + Integer fz = babyPatientExtendEarHearingDiagnoseMapper.getHdAndScreenCount(query);
  267 + map.put("fz",fz.toString());
  268 +
  269 + //分母 听筛管理的初筛条数
  270 + BabyPatientExtendEarScreenQuery screenQuery = new BabyPatientExtendEarScreenQuery();
  271 + screenQuery.setScrIspass(2);//2-未通过
  272 + screenQuery.setCheckHospitalIds(str2);
  273 + screenQuery.setScreenStartDate(DateUtil.getYmdhmDate(queryRequest.getTimeStart()));
  274 + screenQuery.setScreenEndDate(DateUtil.getYmdhmDate(queryRequest.getTimeEnd()));
  275 + Integer fm = babyPatientExtendEarScreenMapper.queryEarScreenListCount(screenQuery);
  276 + map.put("fm",fm.toString());
  277 +
  278 + //分率
  279 + if(fz !=null && fm !=null){
  280 + Double fld = (double)fz/fm * 100;
  281 + if(fld <=0.01 ){
  282 + fld = 0.01;
  283 + }
  284 + map.put("fl", new DecimalFormat("0.00").format(fld)+"%");
  285 + }
  286 +
  287 + } catch (Exception e) {
  288 + e.printStackTrace();
  289 + }
  290 + return map;
  291 + }
  292 +
  293 + /**
82 294 5.2:5岁以下儿童肥胖率
83 295 * @Author: 武涛涛
84 296 * @Date: 2021/3/20 14:09
... ... @@ -95,7 +307,6 @@
95 307 }
96 308 Query queryZ = new Query();
97 309 queryZ.addCriteria(cz);
98   - System.out.println("5.2.1:5岁以下儿童肥胖率 -- 分子 "+queryZ);
99 310 Long countZ = mongoTemplate.count(queryZ, BabyCheckModel.class);
100 311 map.put("fz",countZ.toString());
101 312  
... ... @@ -107,7 +318,6 @@
107 318 }
108 319 Query queryM = new Query();
109 320 queryM.addCriteria(cm);
110   - System.out.println("5.2.2:5岁以下儿童肥胖率 -- 分母 "+queryZ);
111 321 Long countM = mongoTemplate.count(queryM, BabyCheckModel.class);
112 322 map.put("fm",countM.toString());
113 323  
... ... @@ -125,6 +335,7 @@
125 335 }
126 336 return map;
127 337 }
  338 +
128 339 /**
129 340 5.1:中重度贫血率
130 341 * @Author: 武涛涛
... ... @@ -142,7 +353,6 @@
142 353 }
143 354 Query queryZ = new Query();
144 355 queryZ.addCriteria(cz);
145   - System.out.println("5.1:中重度贫血率 -- 分子 "+queryZ);
146 356 Long countZ = mongoTemplate.count(queryZ, BabyCheckModel.class);
147 357 map.put("fz",countZ.toString());
148 358  
... ... @@ -178,7 +388,6 @@
178 388 cz.orOperator(criteria2z,criteria1z);
179 389 Query queryZ = new Query();
180 390 queryZ.addCriteria(cz);
181   - System.out.println("3 低出生体重儿百分比 -- 分子 "+queryZ);
182 391 Long countZ = mongoTemplate.count(queryZ, BabyModel.class);
183 392 map.put("fz",countZ.toString());
184 393  
... ... @@ -221,8 +430,6 @@
221 430 cz.orOperator(criteria2Z,criteria1Z);
222 431 Query queryZ = new Query();
223 432 queryZ.addCriteria(cz);
224   - System.out.println(queryZ);
225   - System.out.println("2 儿童建册率 -- 分子 "+queryZ);
226 433 Long countZ = mongoTemplate.count(queryZ, BabyModel.class);
227 434 map.put("fz",countZ.toString() );
228 435  
... ... @@ -233,7 +440,6 @@
233 440 }
234 441 Query queryM = new Query();
235 442 queryM.addCriteria(cm);
236   - System.out.println("2 儿童建册率 -- 分母 "+queryM);
237 443 Long countM = mongoTemplate.count(queryM, BabyModel.class);
238 444 setBabyfm(countM);//公共使用
239 445 map.put("fm",countM.toString());
... ... @@ -353,5 +559,35 @@
353 559 public void setBabyfm(Long babyfm) {
354 560 this.babyfm = babyfm;
355 561 }
  562 +
  563 + private List< Map<Integer,Statistic>> init() {
  564 + List< Map<Integer,Statistic>> listMaps = new ArrayList <>() ;
  565 + Map<Integer,Statistic> map0 = new HashMap();
  566 + map0.put(0, new GwMap());
  567 + listMaps.add(map0);
  568 + Map<Integer,Statistic> map1 = new HashMap();
  569 + map1.put(1, new BabyMap());
  570 + listMaps.add(map1);
  571 + Map<Integer,Statistic> map2 = new HashMap();
  572 + map2.put(2, new DtzMap());
  573 + listMaps.add(map2);
  574 + Map<Integer,Statistic> map3 = new HashMap();
  575 + map3.put(3, new ZdpxMap());
  576 + listMaps.add(map3);
  577 + Map<Integer,Statistic> map4 = new HashMap();
  578 + map4.put(4, new ZdpxMap());
  579 + listMaps.add(map4);
  580 + Map<Integer,Statistic> map5 = new HashMap();
  581 + map5.put(5, new FplMap());
  582 + listMaps.add(map5);
  583 + Map<Integer,Statistic> map6 = new HashMap();
  584 + map6.put(6, new TlqzMap());
  585 + listMaps.add(map6);
  586 + Map<Integer,Statistic> map7 = new HashMap();
  587 + map7.put(7, new TlscMap());
  588 + listMaps.add(map7);
  589 + return listMaps;
  590 + }
  591 +
356 592 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/BabyStatisticsWorker.java View file @ b7686bd
  1 +package com.lyms.platform.operate.web.worker;
  2 +
  3 +import com.lyms.platform.operate.web.facade.BabyStatisticsFacade.Statistic;
  4 +import com.lyms.platform.operate.web.facade.PatientFacade;
  5 +import com.lyms.platform.operate.web.request.BabyStatisticsQueryRequest;
  6 +import org.apache.commons.collections.CollectionUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +
  10 +import java.util.ArrayList;
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.concurrent.Callable;
  14 +
  15 +/**
  16 + *
  17 + 儿童统计
  18 + * @Author: 武涛涛
  19 + * @Date: 2021/3/21 11:11
  20 + */
  21 +public class BabyStatisticsWorker implements Callable<List<Map>> {
  22 +
  23 + public static final int i = 1;
  24 + private static final Logger logger = LoggerFactory.getLogger(PatientFacade.class);
  25 +
  26 + private List< Map<Integer,Statistic>> mapList;
  27 + private BabyStatisticsQueryRequest babyStatisticsQueryRequest;
  28 + private List <String> provinceCityAreaHid;
  29 +
  30 + public BabyStatisticsWorker(List< Map<Integer,Statistic>> mapList,
  31 + BabyStatisticsQueryRequest babyStatisticsQueryRequest,
  32 + List <String> provinceCityAreaHid
  33 + ) {
  34 + this.mapList = mapList;
  35 + this.babyStatisticsQueryRequest = babyStatisticsQueryRequest;
  36 + this.provinceCityAreaHid = provinceCityAreaHid;
  37 + }
  38 +
  39 + @Override
  40 + public List<Map> call() throws Exception {
  41 + List<Map> data = new ArrayList<>();
  42 + for (int i = 0; i < mapList.size(); i++) {
  43 + if(CollectionUtils.isEmpty(provinceCityAreaHid)){
  44 + continue;
  45 + }
  46 + Map<Integer,Statistic> integerStatisticMap = mapList.get(i);
  47 +
  48 + for (Map.Entry<Integer, Statistic> entry : integerStatisticMap.entrySet()) {
  49 + //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
  50 + Statistic statistic = integerStatisticMap.get(entry.getKey());
  51 + if(statistic == null){
  52 + continue;
  53 + }
  54 + Map <String, String> map = statistic.statisticMap(babyStatisticsQueryRequest, provinceCityAreaHid);
  55 + data.add(map);
  56 + }
  57 +
  58 + }
  59 + return data;
  60 + }
  61 +
  62 +
  63 +}