Commit 242d2acb5596513f40214ef4e563ede2ca519d7d
1 parent
695ad29856
Exists in
master
and in
6 other branches
优惠劵统计优化
Showing 1 changed file with 89 additions and 25 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
242d2ac
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | import com.lyms.platform.common.result.ResponseCode; |
13 | 13 | import com.lyms.platform.common.utils.DateUtil; |
14 | 14 | import com.lyms.platform.common.utils.EnumUtil; |
15 | +import com.lyms.platform.common.utils.ExceptionUtils; | |
15 | 16 | import com.lyms.platform.common.utils.PingYinUtil; |
16 | 17 | import com.lyms.platform.operate.web.dao.IReportDao; |
17 | 18 | import com.lyms.platform.operate.web.facade.AccessPermissionFacade; |
... | ... | @@ -19,6 +20,8 @@ |
19 | 20 | import com.lyms.platform.operate.web.service.IReportService; |
20 | 21 | import com.lyms.platform.operate.web.service.PatientWeightService; |
21 | 22 | import com.lyms.platform.operate.web.utils.*; |
23 | +import com.lyms.platform.operate.web.utils.CollectionUtils; | |
24 | +import com.lyms.platform.operate.web.worker.AntExRecordWorker; | |
22 | 25 | import com.lyms.platform.permission.dao.master.CouponMapper; |
23 | 26 | import com.lyms.platform.permission.model.Organization; |
24 | 27 | import com.lyms.platform.permission.model.Users; |
25 | 28 | |
... | ... | @@ -26,9 +29,10 @@ |
26 | 29 | import com.lyms.platform.permission.service.UsersService; |
27 | 30 | import com.lyms.platform.pojo.*; |
28 | 31 | import com.lymsh.platform.reportdata.model.echarts.Series; |
29 | -import org.apache.commons.collections.MapUtils; | |
32 | +import org.apache.commons.collections.*; | |
30 | 33 | import org.apache.commons.lang.StringUtils; |
31 | 34 | import org.springframework.beans.factory.annotation.Autowired; |
35 | +import org.springframework.beans.factory.annotation.Qualifier; | |
32 | 36 | import org.springframework.data.domain.Sort; |
33 | 37 | import org.springframework.data.mongodb.core.MongoTemplate; |
34 | 38 | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
... | ... | @@ -36,6 +40,7 @@ |
36 | 40 | import org.springframework.data.mongodb.core.aggregation.GroupOperation; |
37 | 41 | import org.springframework.data.mongodb.core.query.Criteria; |
38 | 42 | import org.springframework.data.mongodb.core.query.Query; |
43 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
39 | 44 | import org.springframework.stereotype.Service; |
40 | 45 | import org.springframework.util.Assert; |
41 | 46 | |
... | ... | @@ -44,9 +49,7 @@ |
44 | 49 | import java.sql.ResultSet; |
45 | 50 | import java.sql.SQLException; |
46 | 51 | import java.util.*; |
47 | -import java.util.concurrent.Callable; | |
48 | -import java.util.concurrent.ExecutorService; | |
49 | -import java.util.concurrent.Executors; | |
52 | +import java.util.concurrent.*; | |
50 | 53 | |
51 | 54 | /** |
52 | 55 | * @Author: litao |
... | ... | @@ -86,6 +89,10 @@ |
86 | 89 | @Autowired |
87 | 90 | private CommonService commonService; |
88 | 91 | |
92 | + @Autowired | |
93 | + @Qualifier("commonThreadPool") | |
94 | + private ThreadPoolTaskExecutor commonThreadPool; | |
95 | + | |
89 | 96 | private static final Map<String, String> colorMap = new HashMap<>(); |
90 | 97 | |
91 | 98 | /** |
92 | 99 | |
93 | 100 | |
94 | 101 | |
95 | 102 | |
96 | 103 | |
97 | 104 | |
98 | 105 | |
... | ... | @@ -2449,31 +2456,88 @@ |
2449 | 2456 | |
2450 | 2457 | List<Map<String, Object>> couponReport = new ArrayList<>(); |
2451 | 2458 | List<String> hospitalId = (List<String>) param.get("hospitalId"); |
2452 | - List<String> xAxis = new ArrayList<>(); | |
2453 | - Map<String, Object> hNameMap = new HashMap<>(); | |
2459 | + final List<String> xAxis = new ArrayList<>(); | |
2460 | + List<Map<String, Object>> hospitalNames = couponMapper.findHospitalNames(hospitalId); | |
2461 | + final Map<String, Object> hNameMap = CollectionUtils.coverListToMap(hospitalNames, "id", "name"); | |
2462 | + | |
2454 | 2463 | if(CollectionUtils.isNotEmpty(hospitalId)) { |
2455 | - List<Map<String, Object>> hospitalNames = couponMapper.findHospitalNames(hospitalId); | |
2456 | 2464 | if(CollectionUtils.isNotEmpty(hospitalNames)) { |
2457 | - hNameMap = CollectionUtils.coverListToMap(hospitalNames, "id", "name"); | |
2458 | - for (String hid : hospitalId) { | |
2459 | - param.put("hid", hid); | |
2460 | - Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo2(param); | |
2461 | - Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo2(param); | |
2462 | - Map<String, Object> allusedInfo = couponMapper.findHospitalAllused(param); | |
2465 | + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(hospitalId)) { | |
2466 | + int batchSize = 5; | |
2467 | + int end = 0; | |
2468 | + List<Future> listFuture = new ArrayList<>(); | |
2469 | + for (int i = 0; i < hospitalId.size(); i += batchSize) { | |
2470 | + end = (end + batchSize); | |
2471 | + if (end > hospitalId.size()) { | |
2472 | + end = hospitalId.size(); | |
2473 | + } | |
2474 | + final List<String> hospitalIds = hospitalId.subList(i, end); | |
2475 | + Map<String ,Object> qp = new HashMap<>(); | |
2476 | + for (String key : param.keySet()) | |
2477 | + { | |
2478 | + qp.put(key, param.get(key)); | |
2479 | + } | |
2480 | + final Map<String ,Object> queryParam = qp; | |
2463 | 2481 | |
2464 | - Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid, xAxis, param); | |
2482 | + listFuture.add(commonThreadPool.submit(new Callable() { | |
2483 | + @Override | |
2484 | + public List<Map<String, Object>> call() throws Exception { | |
2465 | 2485 | |
2466 | - if(MapUtils.isNotEmpty(tempMap)) { | |
2467 | - tempMap.put("allUserdCount",(allusedInfo == null || allusedInfo.get("allUserdCount") == null) ? 0 : allusedInfo.get("allUserdCount")); | |
2486 | + List<Map<String, Object>> couponReports = new ArrayList<>(); | |
2468 | 2487 | |
2469 | - /** 方法/使用人数id */ | |
2470 | - List<String> sendUserIds = couponMapper.findSendUserIds2(param); | |
2471 | - List<String> usedUserIds = couponMapper.findUsedUserIds2(param); | |
2472 | - tempMap.put("sendUserIds", sendUserIds); | |
2473 | - tempMap.put("usedUserIds", usedUserIds); | |
2474 | - couponReport.add(tempMap); | |
2488 | + for (String hid : hospitalIds) { | |
2489 | + queryParam.put("hid", hid); | |
2490 | + Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo2(queryParam); | |
2491 | + Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo2(queryParam); | |
2492 | + Map<String, Object> allusedInfo = couponMapper.findHospitalAllused(queryParam); | |
2493 | + | |
2494 | + Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid, xAxis, queryParam); | |
2495 | + | |
2496 | + if(MapUtils.isNotEmpty(tempMap)) { | |
2497 | + tempMap.put("allUserdCount",(allusedInfo == null || allusedInfo.get("allUserdCount") == null) ? 0 : allusedInfo.get("allUserdCount")); | |
2498 | + | |
2499 | + /** 方法/使用人数id */ | |
2500 | + List<String> sendUserIds = couponMapper.findSendUserIds2(queryParam); | |
2501 | + List<String> usedUserIds = couponMapper.findUsedUserIds2(queryParam); | |
2502 | + tempMap.put("sendUserIds", sendUserIds); | |
2503 | + tempMap.put("usedUserIds", usedUserIds); | |
2504 | + couponReports.add(tempMap); | |
2505 | + } | |
2506 | + } | |
2507 | + return couponReports; | |
2508 | + } | |
2509 | + })); | |
2475 | 2510 | } |
2511 | + for (Future f : listFuture) { | |
2512 | + try { | |
2513 | + couponReport.addAll((List) f.get(30, TimeUnit.SECONDS)); | |
2514 | + } catch (Exception e) { | |
2515 | + ExceptionUtils.catchException(e, "antexrecord findList get result future error."); | |
2516 | + } | |
2517 | + } | |
2476 | 2518 | } |
2519 | + | |
2520 | +// for (String hid : hospitalId) { | |
2521 | +// param.put("hid", hid); | |
2522 | +// Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo2(param); | |
2523 | +// Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo2(param); | |
2524 | +// Map<String, Object> allusedInfo = couponMapper.findHospitalAllused(param); | |
2525 | +// | |
2526 | +// Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid, xAxis, param); | |
2527 | +// | |
2528 | +// if(MapUtils.isNotEmpty(tempMap)) { | |
2529 | +// tempMap.put("allUserdCount",(allusedInfo == null || allusedInfo.get("allUserdCount") == null) ? 0 : allusedInfo.get("allUserdCount")); | |
2530 | +// | |
2531 | +// /** 方法/使用人数id */ | |
2532 | +// List<String> sendUserIds = couponMapper.findSendUserIds2(param); | |
2533 | +// List<String> usedUserIds = couponMapper.findUsedUserIds2(param); | |
2534 | +// tempMap.put("sendUserIds", sendUserIds); | |
2535 | +// tempMap.put("usedUserIds", usedUserIds); | |
2536 | +// couponReport.add(tempMap); | |
2537 | +// } | |
2538 | +// } | |
2539 | + | |
2540 | + | |
2477 | 2541 | } |
2478 | 2542 | |
2479 | 2543 | if(CollectionUtils.isNotEmpty(couponReport)) { |