Commit e837a85a6fc3708a913a593cc6bc2b18a7611020
Exists in
master
and in
6 other branches
Merge remote-tracking branch 'origin/master'
Showing 5 changed files
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/BuildSerToPatientSerWorker.java
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
View file @
e837a85
... | ... | @@ -42,7 +42,7 @@ |
42 | 42 | @ResponseBody |
43 | 43 | @TokenRequired |
44 | 44 | @RequestMapping(value = "/patients", method = RequestMethod.GET) |
45 | - public BaseObjectResponse patients(@RequestParam String provinceId, String cityId, String areaId, String streetId, @RequestParam Integer statistType, Integer statistVal, | |
45 | + public BaseObjectResponse patients(@RequestParam String provinceId, String cityId, String areaId, String streetId, Integer statistType, Integer statistVal, | |
46 | 46 | Integer ageType, Integer patientType, Date startDate, Date endDate, HttpServletRequest request) { |
47 | 47 | return reportService.patients(provinceId, cityId, areaId, streetId, statistType, statistVal, ageType, patientType, startDate, endDate, getUserId(request)); |
48 | 48 | } |
... | ... | @@ -57,7 +57,7 @@ |
57 | 57 | @ResponseBody |
58 | 58 | @TokenRequired |
59 | 59 | @RequestMapping(value = "/patients/export", method = RequestMethod.GET) |
60 | - public void patientsExport(String provinceId, String cityId, String areaId, String streetId, @RequestParam Integer statistType, | |
60 | + public void patientsExport(String provinceId, String cityId, String areaId, String streetId, Integer statistType, | |
61 | 61 | Integer ageType, Integer patientType, Date startDate, Date endDate, HttpServletRequest request, HttpServletResponse response) { |
62 | 62 | reportService.patientsExport(provinceId, cityId, areaId, streetId, statistType, ageType, patientType, startDate, endDate, getUserId(request), response); |
63 | 63 | // reportService.patientsExport(provinceId, cityId, aredId, streetId, statistType, ageType, patientType, startDate, endDate, 1000000185, response); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
View file @
e837a85
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | import com.lyms.platform.biz.service.*; |
9 | 9 | import com.lyms.platform.common.enums.SieveStatusEnums; |
10 | 10 | import com.lyms.platform.common.enums.YnEnums; |
11 | +import com.lyms.platform.common.result.BaseResponse; | |
11 | 12 | import com.lyms.platform.common.utils.CompressEncodeingUtil; |
12 | 13 | import com.lyms.platform.common.utils.DateUtil; |
13 | 14 | import com.lyms.platform.common.utils.ExceptionUtils; |
... | ... | @@ -45,7 +46,6 @@ |
45 | 46 | import java.io.File; |
46 | 47 | import java.io.IOException; |
47 | 48 | import java.util.*; |
48 | -import java.util.concurrent.Future; | |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Created by Zhang.Rui on 2016/4/8. |
... | ... | @@ -140,7 +140,7 @@ |
140 | 140 | */ |
141 | 141 | @RequestMapping(value = "/synBuildToPatientService", method = RequestMethod.GET) |
142 | 142 | @ResponseBody |
143 | - public String synBuildToPatientService( | |
143 | + public BaseResponse synBuildToPatientService( | |
144 | 144 | @RequestParam(value = "isSkip") boolean isSkip, |
145 | 145 | @RequestParam(value = "isZjzx") boolean isZjzx |
146 | 146 | ) { |
147 | 147 | |
148 | 148 | |
149 | 149 | |
150 | 150 | |
151 | 151 | |
... | ... | @@ -148,34 +148,31 @@ |
148 | 148 | //排查本院隐藏建档 |
149 | 149 | patientsQuery.setExtEnable(false); |
150 | 150 | patientsQuery.setBuildTypeNot(1); |
151 | + // patientsQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId()); | |
151 | 152 | patientsQuery.setYn(YnEnums.YES.getId()); |
152 | 153 | patientsQuery.setType(1); |
153 | 154 | |
154 | 155 | int patientCount = patientsService.queryPatientCount(patientsQuery); |
155 | 156 | System.out.println("一共需要处理数据量:"+patientCount); |
156 | 157 | |
157 | - //预计开启5个线程处理,计算每个线程需要处理的数据量 | |
158 | - int batchSize = patientCount/5; | |
158 | + //计算每个线程需要处理的数据量,默认1000,必须是分页条数的倍数,不然多线程处理的数据会重复 | |
159 | + int batchSize = 1000; | |
160 | + if(patientCount>10000){ | |
161 | + batchSize = 10000; | |
162 | + } | |
163 | + | |
159 | 164 | int end = 0; |
160 | - List<Future> listFuture = new ArrayList<>(); | |
161 | 165 | for (int i = 0; i < patientCount; i += batchSize) { |
162 | 166 | end = (end + batchSize); |
163 | 167 | if (end > patientCount) { |
164 | - end = patientCount+1; | |
168 | + end = patientCount; | |
165 | 169 | } |
166 | 170 | System.out.println("线程处理数据量:"+i+"--至--"+end); |
167 | - listFuture.add(commonThreadPool.submit(new BuildSerToPatientSerWorker(i, end,patientsService,patientServiceService,isSkip,isZjzx,batchSize,patientCount))); | |
171 | + commonThreadPool.submit(new BuildSerToPatientSerWorker(i, end,patientsService,patientServiceService,isSkip,isZjzx,batchSize,patientCount)); | |
168 | 172 | } |
169 | - | |
170 | - // for (Future f : listFuture) { | |
171 | - // try { | |
172 | - // f.get(30, TimeUnit.SECONDS); | |
173 | - // } catch (Exception e) { | |
174 | - // ExceptionUtils.catchException(e, "convertToQuanCPatient get result Future error."); | |
175 | - // } | |
176 | - // } | |
177 | - | |
178 | - return "success"; | |
173 | + BaseResponse baseResponse = new BaseResponse(); | |
174 | + baseResponse.setErrormsg("一共需要处理数据量:"+patientCount); | |
175 | + return baseResponse; | |
179 | 176 | } |
180 | 177 | |
181 | 178 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java
View file @
e837a85
... | ... | @@ -133,8 +133,8 @@ |
133 | 133 | BloodPressure bloodPressure = mongoTemplate.findById(id, BloodPressure.class); |
134 | 134 | List<Map<String, Object>> xyInfos = new ArrayList<>(); |
135 | 135 | List<Map<String, List<Object>>> lines = new ArrayList<>(); |
136 | - List<Integer> szyMin = Arrays.asList( 60, 60, 60, 60, 60, 60); | |
137 | - List<Integer> ssyMax = Arrays.asList(140, 140, 140, 140, 140, 140); | |
136 | + List<Integer> szyMin = Arrays.asList( 60, 60, 60, 60, 60, 60, 60); | |
137 | + List<Integer> ssyMax = Arrays.asList(140, 140, 140, 140, 140, 140, 140); | |
138 | 138 | List<Object> ssy = new ArrayList<>(); |
139 | 139 | List<Object> szy = new ArrayList<>(); |
140 | 140 | List<Integer> pulse = new ArrayList<>(); |
... | ... | @@ -157,7 +157,7 @@ |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - return RespBuilder.buildSuccess("xyInfos", xyInfos, "szyMin", szyMin, "ssyMax", ssyMax, "ssy", ssy, "szy", szy, pulse); | |
160 | + return RespBuilder.buildSuccess("xyInfos", xyInfos, "szyMin", szyMin, "ssyMax", ssyMax, "ssy", ssy, "szy", szy, "pulse", pulse); | |
161 | 161 | } |
162 | 162 | |
163 | 163 | private String getPulseStatus(String ssy, String szy) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
e837a85
... | ... | @@ -196,6 +196,7 @@ |
196 | 196 | Map<String, Object> restMap = new HashMap<>(); |
197 | 197 | List<List<String>> tabList = new ArrayList<>(); |
198 | 198 | List<String> titleList = new ArrayList<>(); |
199 | + List<String> countList = new ArrayList<>(); | |
199 | 200 | List<String> xDatas = new ArrayList<>(); |
200 | 201 | List<Map<String, Object>> series = new ArrayList<>(); |
201 | 202 | List<String> legend = Arrays.asList("建档总数"); |
... | ... | @@ -220,7 +221,6 @@ |
220 | 221 | bar.add((Integer) mappedResult.get("count")); |
221 | 222 | } |
222 | 223 | |
223 | - // 拼装tab数据 | |
224 | 224 | titleList.add("医院名称"); |
225 | 225 | titleList.add("统计指标(人)"); |
226 | 226 | for (Map<String, Date> map : range) { |
... | ... | @@ -350,6 +350,7 @@ |
350 | 350 | |
351 | 351 | tabList.add(0, titleList); |
352 | 352 | setTabListInfo(tabList, StringUtils.isNotEmpty(aredId) ? 2 : 3); |
353 | + setCountList(tabList, countList, StringUtils.isNotEmpty(aredId) ? 3 : 4); | |
353 | 354 | |
354 | 355 | barMap.put("data", bar); |
355 | 356 | barMap.put("type", "bar"); |
... | ... | @@ -364,7 +365,7 @@ |
364 | 365 | for (Integer num : bar) { |
365 | 366 | line.add(MathUtil.getProportion(num, count)); |
366 | 367 | } |
367 | - } else if(statistType == 2) { | |
368 | + }/* else if(statistType == 2) { | |
368 | 369 | Date start = null; |
369 | 370 | Date end = null; |
370 | 371 | Date beforeStart = null; |
371 | 372 | |
... | ... | @@ -395,14 +396,34 @@ |
395 | 396 | beforeEnd = DateUtil.getYear(startDate, -1, 0); |
396 | 397 | break; |
397 | 398 | } |
398 | - List<Map<String, Object>> hospitalInfos = mongoUtil.getHospitals(userId, provinceId, cityId, aredId, streetId); | |
399 | - List<String> hospitalIds = CollectionUtils.getListByKey(hospitalInfos, "id"); | |
400 | - Criteria c = new Criteria(); | |
401 | - c.and("hospitalId").in(hospitalIds).and("yn").ne(0).and("enable").ne("2").and("buildType").ne(1); | |
402 | - if(startDate != null && endDate != null) { | |
403 | - c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); | |
399 | + if(start != null && end != null && beforeStart != null && beforeEnd != null) { | |
400 | + List<Map<String, Object>> hospitalInfos = mongoUtil.getHospitals(userId, provinceId, cityId, aredId, streetId); | |
401 | + List<String> hospitalIds = CollectionUtils.getListByKey(hospitalInfos, "id"); | |
402 | + Criteria c = new Criteria(); | |
403 | + c.and("hospitalId").in(hospitalIds).and("yn").ne(0).and("enable").ne("2").and("buildType").ne(1); | |
404 | + if(startDate != null && endDate != null) { | |
405 | + c.and("bookbuildingDate").gte(start).lt(DateUtil.addDay(end, 1)); | |
406 | + } | |
407 | + | |
408 | + | |
409 | + Integer nowCount = 0; | |
410 | + Integer beforeCount = 0; | |
411 | + GroupOperation groupOperation = Aggregation.group("hospitalId").count().as("count"); | |
412 | + Aggregation agg = Aggregation.newAggregation(Patients.class, Aggregation.match(c), groupOperation); | |
413 | + AggregationResults<Map> results = mongoTemplate.aggregate(agg, Patients.class, Map.class); | |
414 | + List<Map> mappedResults = results.getMappedResults(); | |
415 | + for (Map mappedResult : mappedResults) { | |
416 | + xDatas.add(couponMapper.findHospitalNameById((String) mappedResult.get("_id"))); | |
417 | + bar.add((Integer) mappedResult.get("count")); | |
418 | + } | |
419 | + | |
420 | +// titleList.add("医院名称"); | |
421 | +// titleList.add("统计指标(人)"); | |
422 | +// for (Map<String, Date> map : range) { | |
423 | +// titleList.add(DateUtil.getyyyy_mm(map.get("cname"))); | |
424 | +// } | |
404 | 425 | } |
405 | - } | |
426 | + }*/ | |
406 | 427 | lineMap.put("data", line); |
407 | 428 | lineMap.put("type", "line"); |
408 | 429 | lineMap.put("name", "建档总数"); |
409 | 430 | |
410 | 431 | |
... | ... | @@ -417,11 +438,29 @@ |
417 | 438 | return RespBuilder.buildSuccess(restMap); |
418 | 439 | } |
419 | 440 | |
441 | + private void setCountList(List<List<String>> tabList, List<String> countList, int index) { | |
442 | + countList.add(tabList.size() + ""); | |
443 | + countList.add("合计"); | |
444 | + countList.add("建档总数"); | |
445 | + if(tabList.size() > 1) { | |
446 | + for (int i = index; i < tabList.get(0).size(); i++) { | |
447 | + int count = 0; | |
448 | + for (int j = 1; j < tabList.size(); j++) { | |
449 | + count += Integer.parseInt(tabList.get(j).get(i)); | |
450 | + } | |
451 | + countList.add(count + ""); | |
452 | + } | |
453 | + | |
454 | + } | |
455 | + tabList.add(countList); | |
456 | + | |
457 | + } | |
458 | + | |
420 | 459 | private void setTabListInfo(List<List<String>> tabList, int index) { |
421 | 460 | if(CollectionUtils.isNotEmpty(tabList)) { |
461 | + int seq = 0; | |
422 | 462 | for (int i = 0; i < tabList.size(); i++) { |
423 | 463 | List<String> list = tabList.get(i); |
424 | - int seq = 0; | |
425 | 464 | if(i == 0) { |
426 | 465 | list.add(0, "序号" ); |
427 | 466 | list.add("合计"); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/BuildSerToPatientSerWorker.java
View file @
e837a85
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | import com.lyms.platform.common.enums.ServiceStatusEnums; |
6 | 6 | import com.lyms.platform.common.enums.ServiceTypeEnums; |
7 | 7 | import com.lyms.platform.common.enums.YnEnums; |
8 | +import com.lyms.platform.common.utils.StringUtils; | |
8 | 9 | import com.lyms.platform.operate.web.utils.CollectionUtils; |
9 | 10 | import com.lyms.platform.permission.model.PatientService; |
10 | 11 | import com.lyms.platform.permission.model.PatientServiceQuery; |
11 | 12 | |
... | ... | @@ -12,7 +13,9 @@ |
12 | 13 | import com.lyms.platform.pojo.Patients; |
13 | 14 | import com.lyms.platform.query.PatientsQuery; |
14 | 15 | |
16 | +import java.util.HashMap; | |
15 | 17 | import java.util.List; |
18 | +import java.util.Map; | |
16 | 19 | import java.util.UUID; |
17 | 20 | import java.util.concurrent.Callable; |
18 | 21 | |
19 | 22 | |
20 | 23 | |
... | ... | @@ -54,16 +57,15 @@ |
54 | 57 | @Override |
55 | 58 | public Object call() { |
56 | 59 | try { |
60 | + Map<String,Integer> patientsMap = new HashMap<>(); | |
61 | + | |
57 | 62 | for (int i = startIndex; i < endIndex; i += batchSize) { |
58 | 63 | PatientsQuery patientsQuery = new PatientsQuery(); |
59 | - if(i+batchSize>endIndex){ | |
60 | - patientsQuery.setLimit(endIndex-i); | |
61 | - }else{ | |
62 | - patientsQuery.setLimit(batchSize); | |
63 | - } | |
64 | - System.out.println("总数据量:"+allCount+",正在处理第:" + i+"--到--"+(i+batchSize)+",limit:"+patientsQuery.getLimit()); | |
65 | - | |
64 | + patientsQuery.setLimit(batchSize); | |
66 | 65 | patientsQuery.setPage((i + batchSize) / batchSize); |
66 | + | |
67 | + System.out.println("总数据量:"+allCount+",正在处理第:" + i+"--到--"+(i+batchSize)+",page:"+patientsQuery.getPage()+",limit:"+patientsQuery.getLimit()); | |
68 | + | |
67 | 69 | //排查本院隐藏建档 |
68 | 70 | patientsQuery.setExtEnable(false); |
69 | 71 | patientsQuery.setBuildTypeNot(1); |
... | ... | @@ -73,6 +75,13 @@ |
73 | 75 | |
74 | 76 | List<Patients> patients = patientsService.queryPatient(patientsQuery); |
75 | 77 | for (Patients pt : patients) { |
78 | + if(StringUtils.isEmpty(pt.getId())){ | |
79 | + System.out.println("建档主键id为空:"+pt.getId()); | |
80 | + }else if(patientsMap.containsKey(pt.getId())){//存在 | |
81 | + System.out.println("重复的主键:"+pt.getId()); | |
82 | + }else{ | |
83 | + patientsMap.put(pt.getId(),1); | |
84 | + } | |
76 | 85 | if (pt.getServiceType() == null) { |
77 | 86 | System.out.println("跳过数据:"+pt.getId()); |
78 | 87 | continue; |
... | ... | @@ -134,6 +143,7 @@ |
134 | 143 | |
135 | 144 | List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery); |
136 | 145 | if (CollectionUtils.isNotEmpty(patientServices)) { |
146 | + System.out.println("增量查询数据存在:"+pt.getId()); | |
137 | 147 | continue; |
138 | 148 | } |
139 | 149 | } |
... | ... | @@ -142,6 +152,8 @@ |
142 | 152 | } |
143 | 153 | // System.out.println("endIndex:" + endIndex + "," + i + ":" + patients.size()); |
144 | 154 | } |
155 | + | |
156 | + System.out.println("线程处理数据完成,开始条数:"+startIndex+",结束条数:"+endIndex+",map:"+ patientsMap.size()); | |
145 | 157 | } catch (Exception e) { |
146 | 158 | e.printStackTrace(); |
147 | 159 | } |