Commit 751d918be8757175d0435e89570bb5d02f512e18
1 parent
2ccc6a5480
Exists in
master
and in
6 other branches
优化增值服务统计模块
Showing 3 changed files with 32 additions and 22 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
View file @
751d918
| ... | ... | @@ -1037,7 +1037,7 @@ |
| 1037 | 1037 | * @param param |
| 1038 | 1038 | * @return |
| 1039 | 1039 | */ |
| 1040 | - public BaseResponse getServiceList(ServiceListQuery param) throws InterruptedException { | |
| 1040 | + public BaseResponse getServiceList(ServiceListQuery param) throws Exception { | |
| 1041 | 1041 | BaseResponse baseResponse = new BaseResponse(); |
| 1042 | 1042 | String string = param.toString(); |
| 1043 | 1043 | BaseResponse baseResponseVal = cacheGetServiceList.get(string); |
| 1044 | 1044 | |
| ... | ... | @@ -1047,8 +1047,8 @@ |
| 1047 | 1047 | setDefaultTime(param); |
| 1048 | 1048 | |
| 1049 | 1049 | HashMap<String, Object> objectHashMap = new HashMap<>(16); |
| 1050 | - CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList(); | |
| 1051 | 1050 | |
| 1051 | + | |
| 1052 | 1052 | String hospitalId = param.getHospitalId(); |
| 1053 | 1053 | String provinceId = param.getProvinceId(); |
| 1054 | 1054 | String cityId = param.getCityId(); |
| 1055 | 1055 | |
| 1056 | 1056 | |
| 1057 | 1057 | |
| ... | ... | @@ -1066,18 +1066,25 @@ |
| 1066 | 1066 | int size = hospitalIds.size(); |
| 1067 | 1067 | int batchSize = 2; |
| 1068 | 1068 | int end = 0; |
| 1069 | + List<Map<String, Object>> mapList = new ArrayList(size); | |
| 1070 | + List<Future> futureArrayList = new ArrayList<>(); | |
| 1069 | 1071 | for (int i = 0; i < size; i += batchSize){ |
| 1070 | 1072 | end = (end + batchSize); |
| 1071 | 1073 | if (end > hospitalIds.size()) { |
| 1072 | 1074 | end = hospitalIds.size(); |
| 1073 | 1075 | } |
| 1074 | - threadPool.submit(new ServiceListWorker(hospitalIds.subList(i, end), copyOnWriteArrayList, param, patientServiceService, basicConfigService)); | |
| 1076 | + Future<List<Map<String, Object>>> listFuture = threadPool.submit(new ServiceListWorker(hospitalIds.subList(i, end), param, patientServiceService, basicConfigService)); | |
| 1077 | + futureArrayList.add(listFuture); | |
| 1075 | 1078 | } |
| 1076 | 1079 | threadPool.shutdown(); |
| 1077 | 1080 | while (true){ |
| 1078 | 1081 | if (threadPool.isTerminated()){ |
| 1082 | + for (Future future : futureArrayList){ | |
| 1083 | + mapList.addAll((List)future.get()); | |
| 1084 | + } | |
| 1079 | 1085 | break; |
| 1080 | 1086 | } |
| 1087 | + Thread.sleep(1000); | |
| 1081 | 1088 | } |
| 1082 | 1089 | ArrayList<Object> statusNameList = new ArrayList<>(); |
| 1083 | 1090 | statusNameList.add("开通"); |
| 1084 | 1091 | |
| 1085 | 1092 | |
| 1086 | 1093 | |
| ... | ... | @@ -1085,18 +1092,17 @@ |
| 1085 | 1092 | statusNameList.add("过期"); |
| 1086 | 1093 | statusNameList.add("暂停"); |
| 1087 | 1094 | |
| 1088 | - CopyOnWriteArrayList statusValList = new CopyOnWriteArrayList(); | |
| 1089 | - param.setHospitalIds(hospitalIds); | |
| 1090 | 1095 | |
| 1091 | - ExecutorService service = new ThreadPoolExecutor(4, 4, 9000, TimeUnit.MILLISECONDS, | |
| 1096 | + param.setHospitalIds(hospitalIds); | |
| 1097 | + ExecutorService service = new ThreadPoolExecutor(1, 1, 90000, TimeUnit.MILLISECONDS, | |
| 1092 | 1098 | new ArrayBlockingQueue<Runnable>(1), |
| 1093 | 1099 | new RejectedExecutionHandler() { |
| 1094 | 1100 | @Override |
| 1095 | 1101 | public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { |
| 1096 | - // 异常抛出 | |
| 1097 | 1102 | throw new RuntimeException(); |
| 1098 | 1103 | } |
| 1099 | 1104 | }); |
| 1105 | + CopyOnWriteArrayList statusValList = new CopyOnWriteArrayList(); | |
| 1100 | 1106 | for (int i =1; i < 5; i ++){ |
| 1101 | 1107 | CountDownLatch cdl = new CountDownLatch(1); |
| 1102 | 1108 | String serStatus = i + "" ; |
| 1103 | 1109 | |
| 1104 | 1110 | |
| ... | ... | @@ -1107,11 +1113,11 @@ |
| 1107 | 1113 | |
| 1108 | 1114 | objectHashMap.put("statusNameList",statusNameList); |
| 1109 | 1115 | objectHashMap.put("statusValList", statusValList); |
| 1110 | - objectHashMap.put("serviceList", copyOnWriteArrayList); | |
| 1116 | + objectHashMap.put("serviceList", mapList); | |
| 1111 | 1117 | baseResponse.setObject(objectHashMap); |
| 1112 | 1118 | |
| 1113 | - | |
| 1114 | 1119 | cacheGetServiceList.put(string, baseResponse); |
| 1120 | + | |
| 1115 | 1121 | return baseResponse; |
| 1116 | 1122 | } |
| 1117 | 1123 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListBySerStatusWorker.java
View file @
751d918
| ... | ... | @@ -27,13 +27,16 @@ |
| 27 | 27 | } |
| 28 | 28 | @Override |
| 29 | 29 | public void run() { |
| 30 | - int number = 0; | |
| 31 | - if (!param.getHospitalIds().isEmpty()){ | |
| 32 | - param.setSerStatus(serStatus); | |
| 33 | - number = patientServiceService.countStatusInfo(param); | |
| 30 | + try { | |
| 31 | + int number = 0; | |
| 32 | + if (!param.getHospitalIds().isEmpty()){ | |
| 33 | + param.setSerStatus(serStatus); | |
| 34 | + number = patientServiceService.countStatusInfo(param); | |
| 35 | + } | |
| 36 | + statusValList.add(number); | |
| 37 | + }finally { | |
| 38 | + cdl.countDown(); | |
| 34 | 39 | } |
| 35 | - statusValList.add(number); | |
| 36 | - cdl.countDown(); | |
| 37 | 40 | } |
| 38 | 41 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListWorker.java
View file @
751d918
| ... | ... | @@ -5,9 +5,11 @@ |
| 5 | 5 | import com.lyms.platform.permission.service.PatientServiceService; |
| 6 | 6 | import com.lyms.platform.pojo.BasicConfig; |
| 7 | 7 | |
| 8 | +import java.util.ArrayList; | |
| 8 | 9 | import java.util.HashMap; |
| 9 | 10 | import java.util.List; |
| 10 | 11 | import java.util.Map; |
| 12 | +import java.util.concurrent.BlockingQueue; | |
| 11 | 13 | import java.util.concurrent.Callable; |
| 12 | 14 | import java.util.concurrent.CopyOnWriteArrayList; |
| 13 | 15 | |
| 14 | 16 | |
| 15 | 17 | |
| 16 | 18 | |
| 17 | 19 | |
| ... | ... | @@ -18,24 +20,23 @@ |
| 18 | 20 | * @Date 9:59 2019/5/18 |
| 19 | 21 | **/ |
| 20 | 22 | |
| 21 | -public class ServiceListWorker implements Callable<String> { | |
| 23 | +public class ServiceListWorker implements Callable< List<Map<String, Object>>> { | |
| 22 | 24 | private List<String> hospitals; |
| 23 | - private CopyOnWriteArrayList copyOnWriteArrayList; | |
| 24 | 25 | private ServiceListQuery param; |
| 25 | 26 | private PatientServiceService patientServiceService; |
| 26 | 27 | private BasicConfigService basicConfigService; |
| 27 | 28 | |
| 28 | - public ServiceListWorker(List<String> hospitals, CopyOnWriteArrayList copyOnWriteArrayList, ServiceListQuery param, | |
| 29 | + public ServiceListWorker(List<String> hospitals, ServiceListQuery param, | |
| 29 | 30 | PatientServiceService patientServiceService, BasicConfigService basicConfigService) { |
| 30 | 31 | this.hospitals = hospitals; |
| 31 | - this.copyOnWriteArrayList = copyOnWriteArrayList; | |
| 32 | 32 | this.param = param; |
| 33 | 33 | this.patientServiceService = patientServiceService; |
| 34 | 34 | this.basicConfigService = basicConfigService; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | @Override |
| 38 | - public String call() throws Exception { | |
| 38 | + public List<Map<String, Object>> call() throws Exception { | |
| 39 | + List<Map<String, Object>> mapList = new ArrayList<>(); | |
| 39 | 40 | for (String hospital : hospitals){ |
| 40 | 41 | param.setHospitalId(hospital); |
| 41 | 42 | |
| 42 | 43 | |
| ... | ... | @@ -59,10 +60,10 @@ |
| 59 | 60 | + Integer.parseInt(map.get("suspend").toString())); |
| 60 | 61 | |
| 61 | 62 | hashMap.putAll(map); |
| 62 | - copyOnWriteArrayList.add(hashMap); | |
| 63 | + mapList.add(hashMap); | |
| 63 | 64 | } |
| 64 | 65 | } |
| 65 | - return "SUCCESS"; | |
| 66 | + return mapList; | |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | } |