Commit dc705b417f508e0b6d3e04d75d4b51859e50cf6a
1 parent
440c8b597c
Exists in
master
and in
6 other branches
新增增值服务统计模块
Showing 8 changed files with 220 additions and 87 deletions
- platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/PatientServiceMapper.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/PatientServiceService.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/PatientServiceServiceImpl.java
- platform-biz-service/src/main/resources/mainOrm/master/PatientService.xml
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/AreaCountController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListBySerStatusWorker.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListWorker.java
platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/PatientServiceMapper.java
View file @
dc705b4
platform-biz-service/src/main/java/com/lyms/platform/permission/service/PatientServiceService.java
View file @
dc705b4
platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/PatientServiceServiceImpl.java
View file @
dc705b4
platform-biz-service/src/main/resources/mainOrm/master/PatientService.xml
View file @
dc705b4
... | ... | @@ -394,7 +394,6 @@ |
394 | 394 | <include refid="PatientServiceCondition"/> |
395 | 395 | </select> |
396 | 396 | <select id="getServiceList" parameterType="com.lyms.platform.permission.model.ServiceListQuery" resultType="java.util.Map" fetchSize="10000"> |
397 | - | |
398 | 397 | SELECT |
399 | 398 | o.name as "name", |
400 | 399 | o.province_id as "provinceId", |
... | ... | @@ -485,10 +484,10 @@ |
485 | 484 | and o.area_id = #{query.areaId} |
486 | 485 | </if> |
487 | 486 | ) as "suspend" |
488 | - FROM patient_service ps | |
489 | - JOIN organization o | |
490 | - ON o.id = ps.hospital_id | |
491 | - WHERE ps.hospital_id = #{query.hospitalId} | |
487 | + /*FROM patient_service ps*/ | |
488 | + /* JOIN organization o | |
489 | + ON o.id = ps.hospital_id*/ | |
490 | + <!--WHERE ps.hospital_id = #{query.hospitalId} | |
492 | 491 | <if test="query.startTime != null "> |
493 | 492 | AND ps.create_date >= #{query.startTime} |
494 | 493 | </if> |
... | ... | @@ -506,8 +505,12 @@ |
506 | 505 | </if> |
507 | 506 | GROUP BY o.name,o.province_id, |
508 | 507 | o.city_id, |
509 | - o.area_id | |
510 | - | |
508 | + o.area_id--> | |
509 | + FROM organization o | |
510 | + WHERE o.id = #{query.hospitalId} | |
511 | + GROUP BY o.name,o.province_id, | |
512 | + o.city_id, | |
513 | + o.area_id | |
511 | 514 | </select> |
512 | 515 | <select id="countStatusInfo" parameterType="com.lyms.platform.permission.model.ServiceListQuery" resultType="int"> |
513 | 516 | select count(1) |
... | ... | @@ -615,6 +618,34 @@ |
615 | 618 | <if test="param.endTime != null "> |
616 | 619 | AND ps.create_date <= #{param.endTime} |
617 | 620 | </if> |
621 | + </select> | |
622 | + <select id="getHospitalIds" parameterType="com.lyms.platform.permission.model.ServiceListQuery" resultType="java.lang.String"> | |
623 | + | |
624 | + SELECT | |
625 | + o.id as "hospitalId" | |
626 | + FROM patient_service ps | |
627 | + JOIN organization o | |
628 | + ON o.id = ps.hospital_id | |
629 | + WHERE ps.hospital_id in | |
630 | + <foreach collection="param.hospitalIds" item="item" open="(" close=")" separator=","> | |
631 | + #{item} | |
632 | + </foreach> | |
633 | + <if test="param.startTime != null "> | |
634 | + AND ps.create_date >= #{param.startTime} | |
635 | + </if> | |
636 | + <if test="param.endTime != null "> | |
637 | + AND ps.create_date <= #{param.endTime} | |
638 | + </if> | |
639 | + <if test="param.provinceId != null"> | |
640 | + and o.province_id = #{param.provinceId} | |
641 | + </if> | |
642 | + <if test="param.cityId != null"> | |
643 | + and o.city_id = #{param.cityId} | |
644 | + </if> | |
645 | + <if test="param.areaId != null"> | |
646 | + and o.area_id = #{param.areaId} | |
647 | + </if> | |
648 | + | |
618 | 649 | </select> |
619 | 650 | |
620 | 651 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/AreaCountController.java
View file @
dc705b4
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | import com.lyms.platform.common.annotation.TokenRequired; |
4 | 4 | import com.lyms.platform.common.base.BaseController; |
5 | 5 | import com.lyms.platform.common.base.LoginContext; |
6 | +import com.lyms.platform.common.constants.ErrorCodeConstants; | |
6 | 7 | import com.lyms.platform.common.result.BaseResponse; |
7 | 8 | import com.lyms.platform.operate.web.facade.AreaCountFacade; |
8 | 9 | import com.lyms.platform.permission.model.ServiceListQuery; |
... | ... | @@ -196,7 +197,14 @@ |
196 | 197 | public BaseResponse getServiceList(@RequestBody @Valid ServiceListQuery query, HttpServletRequest request){ |
197 | 198 | LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); |
198 | 199 | query.setUserId(loginState.getId()); |
199 | - return areaCountFacade.getServiceList(query); | |
200 | + try { | |
201 | + return areaCountFacade.getServiceList(query); | |
202 | + }catch (Exception e){ | |
203 | + BaseResponse baseResponse = new BaseResponse(); | |
204 | + baseResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
205 | + baseResponse.setErrormsg("增值服务统计失败"); | |
206 | + return baseResponse; | |
207 | + } | |
200 | 208 | } |
201 | 209 | |
202 | 210 | /** |
... | ... | @@ -210,7 +218,14 @@ |
210 | 218 | public BaseResponse getServiceDetailList(@RequestBody @Valid ServiceListQuery param, HttpServletRequest request){ |
211 | 219 | LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); |
212 | 220 | param.setUserId(loginState.getId()); |
213 | - return areaCountFacade.getServiceDetailList(param); | |
221 | + try { | |
222 | + return areaCountFacade.getServiceDetailList(param); | |
223 | + }catch (Exception e){ | |
224 | + BaseResponse baseResponse = new BaseResponse(); | |
225 | + baseResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
226 | + baseResponse.setErrormsg("增值服务详情统计失败"); | |
227 | + return baseResponse; | |
228 | + } | |
214 | 229 | } |
215 | 230 | |
216 | 231 | /** |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
View file @
dc705b4
... | ... | @@ -16,6 +16,8 @@ |
16 | 16 | import com.lyms.platform.operate.web.utils.MongoUtil; |
17 | 17 | import com.lyms.platform.operate.web.utils.ResponseUtil; |
18 | 18 | import com.lyms.platform.operate.web.worker.CheckPointCountWorker; |
19 | +import com.lyms.platform.operate.web.worker.ServiceListBySerStatusWorker; | |
20 | +import com.lyms.platform.operate.web.worker.ServiceListWorker; | |
19 | 21 | import com.lyms.platform.permission.model.Organization; |
20 | 22 | import com.lyms.platform.permission.model.OrganizationQuery; |
21 | 23 | import com.lyms.platform.permission.model.ServiceListQuery; |
... | ... | @@ -44,9 +46,7 @@ |
44 | 46 | import java.time.*; |
45 | 47 | import java.time.temporal.TemporalAdjusters; |
46 | 48 | import java.util.*; |
47 | -import java.util.concurrent.Callable; | |
48 | -import java.util.concurrent.ExecutionException; | |
49 | -import java.util.concurrent.Future; | |
49 | +import java.util.concurrent.*; | |
50 | 50 | |
51 | 51 | |
52 | 52 | /** |
53 | 53 | |
54 | 54 | |
... | ... | @@ -1035,16 +1035,12 @@ |
1035 | 1035 | * @param param |
1036 | 1036 | * @return |
1037 | 1037 | */ |
1038 | - public BaseResponse getServiceList(ServiceListQuery param) { | |
1038 | + public BaseResponse getServiceList(ServiceListQuery param) throws InterruptedException { | |
1039 | 1039 | BaseResponse baseResponse = new BaseResponse(); |
1040 | - if (param.getStartTime() == null){ | |
1041 | - Date startDate = getStartDate(); | |
1042 | - param.setStartTime(startDate); | |
1043 | - } | |
1044 | - long startTime = System.currentTimeMillis(); | |
1040 | + setDefaultTime(param); | |
1045 | 1041 | |
1046 | 1042 | HashMap<String, Object> objectHashMap = new HashMap<>(16); |
1047 | - LinkedList<Object> linkedList = new LinkedList<>(); | |
1043 | + CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList(); | |
1048 | 1044 | |
1049 | 1045 | String hospitalId = param.getHospitalId(); |
1050 | 1046 | String provinceId = param.getProvinceId(); |
1051 | 1047 | |
1052 | 1048 | |
1053 | 1049 | |
1054 | 1050 | |
1055 | 1051 | |
1056 | 1052 | |
... | ... | @@ -1052,72 +1048,58 @@ |
1052 | 1048 | String areaId = param.getAreaId(); |
1053 | 1049 | List<String> hospitalIds = new ArrayList<>(); |
1054 | 1050 | if (StringUtils.isEmpty(hospitalId)){ |
1055 | - /* hospitalIds = getCurrentUserHospPermissions(param.getUserId(), | |
1056 | - StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, StringUtils.isEmpty(areaId) ? null : areaId);*/ | |
1057 | - hospitalIds = getCurrentUserHospPermissions2(param.getUserId(), | |
1058 | - StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, StringUtils.isEmpty(areaId) ? null : areaId); | |
1051 | + hospitalIds = getCurrentUserHospPermissions(param.getUserId(), StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, | |
1052 | + StringUtils.isEmpty(areaId) ? null : areaId); | |
1059 | 1053 | } else { |
1060 | 1054 | hospitalIds.add(hospitalId); |
1061 | 1055 | } |
1062 | - long timeMillis = System.currentTimeMillis(); | |
1063 | - System.err.println(startTime - timeMillis); | |
1064 | - for (String hospital: hospitalIds){ | |
1065 | - System.err.print(hospital + ", "); | |
1066 | - param.setHospitalId(hospital); | |
1067 | - Map<String, Object> map = patientServiceService.getServiceList(param); | |
1068 | - System.err.println(System.currentTimeMillis() - timeMillis); | |
1069 | - if (map == null){ | |
1070 | - continue; | |
1056 | + ExecutorService threadPool = Executors.newFixedThreadPool(5); | |
1057 | + param.setHospitalIds(hospitalIds); | |
1058 | + List<String> ids = patientServiceService.getHospitalIds(param); | |
1059 | + int size = hospitalIds.size(); | |
1060 | + int batchSize = 2; | |
1061 | + int end = 0; | |
1062 | + for (int i = 0; i < size; i += batchSize){ | |
1063 | + end = (end + batchSize); | |
1064 | + if (end > hospitalIds.size()) { | |
1065 | + end = hospitalIds.size(); | |
1071 | 1066 | } |
1072 | - HashMap<String, Object> hashMap = new HashMap<>(16); | |
1073 | - String id = map.get("provinceId").toString(); | |
1074 | - BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(id); | |
1075 | - hashMap.put("provinceName", basicConfig.getName()); | |
1076 | - | |
1077 | - id = map.get("cityId").toString(); | |
1078 | - basicConfig = basicConfigService.getOneBasicConfigById(id); | |
1079 | - hashMap.put("cityName", basicConfig.getName()); | |
1080 | - | |
1081 | - id = map.get("areaId").toString(); | |
1082 | - basicConfig = basicConfigService.getOneBasicConfigById(id); | |
1083 | - hashMap.put("areaName", basicConfig.getName()); | |
1084 | - hashMap.put("total", Integer.parseInt(map.get("open").toString()) | |
1085 | - + Integer.parseInt(map.get("unsubscribe").toString()) | |
1086 | - + Integer.parseInt(map.get("expire").toString()) | |
1087 | - + Integer.parseInt(map.get("suspend").toString())); | |
1088 | - | |
1089 | - hashMap.putAll(map); | |
1090 | - | |
1091 | - | |
1092 | - linkedList.add(hashMap); | |
1067 | + threadPool.submit(new ServiceListWorker(hospitalIds.subList(i, end), copyOnWriteArrayList, param, patientServiceService, basicConfigService)); | |
1093 | 1068 | } |
1094 | - long ttt = System.currentTimeMillis(); | |
1095 | - System.err.println(timeMillis - ttt); | |
1069 | + threadPool.shutdown(); | |
1070 | + while (true){ | |
1071 | + if (threadPool.isTerminated()){ | |
1072 | + break; | |
1073 | + } | |
1074 | + } | |
1096 | 1075 | ArrayList<Object> statusNameList = new ArrayList<>(); |
1097 | 1076 | statusNameList.add("开通"); |
1098 | 1077 | statusNameList.add("退订"); |
1099 | 1078 | statusNameList.add("过期"); |
1100 | 1079 | statusNameList.add("暂停"); |
1101 | 1080 | |
1081 | + CopyOnWriteArrayList statusValList = new CopyOnWriteArrayList(); | |
1102 | 1082 | param.setHospitalIds(hospitalIds); |
1103 | - ArrayList<Object> statusValList = new ArrayList<>(); | |
1104 | - param.setSerStatus("1"); | |
1105 | - int number = patientServiceService.countStatusInfo(param); | |
1106 | - statusValList.add(number); | |
1107 | - param.setSerStatus("2"); | |
1108 | - number = patientServiceService.countStatusInfo(param); | |
1109 | - statusValList.add(number); | |
1110 | - param.setSerStatus("3"); | |
1111 | - number = patientServiceService.countStatusInfo(param); | |
1112 | - statusValList.add(number); | |
1113 | - param.setSerStatus("4"); | |
1114 | - number = patientServiceService.countStatusInfo(param); | |
1115 | - statusValList.add(number); | |
1083 | + CountDownLatch cdl=new CountDownLatch(4); | |
1084 | + ExecutorService service= new ThreadPoolExecutor(5, 10, 3000, TimeUnit.MILLISECONDS, | |
1085 | + new ArrayBlockingQueue<Runnable>(10), | |
1086 | + new RejectedExecutionHandler() { | |
1087 | + @Override | |
1088 | + public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { | |
1089 | + // 异常抛出 | |
1090 | + throw new RuntimeException(); | |
1091 | + } | |
1092 | + }); | |
1093 | + for (int i =1; i < 5; i ++){ | |
1094 | + String serStatus = i + "" ; | |
1095 | + service.execute(new ServiceListBySerStatusWorker(cdl, param, statusValList, serStatus, patientServiceService )); | |
1096 | + } | |
1097 | + cdl.await(); | |
1098 | + service.shutdown(); | |
1116 | 1099 | |
1117 | 1100 | objectHashMap.put("statusNameList",statusNameList); |
1118 | 1101 | objectHashMap.put("statusValList", statusValList); |
1119 | - objectHashMap.put("serviceList", linkedList); | |
1120 | - | |
1102 | + objectHashMap.put("serviceList", copyOnWriteArrayList); | |
1121 | 1103 | baseResponse.setObject(objectHashMap); |
1122 | 1104 | |
1123 | 1105 | return baseResponse; |
... | ... | @@ -1208,14 +1190,14 @@ |
1208 | 1190 | /*for (Map map : serviceDetailListMap){ |
1209 | 1191 | HashMap<Object, Object> result = new HashMap<>(16); |
1210 | 1192 | *//** |
1211 | - * "patientName": "王静洁", | |
1212 | - * "serTypeName": "精准指导", | |
1213 | - * "doctorName": "", | |
1214 | - * "opnYumSize": "", | |
1215 | - * "serviceWeek": "", | |
1216 | - * "createDate": 1480953600000, | |
1217 | - * "serStatus": "开通中" | |
1218 | - *//* | |
1193 | + * "patientName": "王静洁", | |
1194 | + * "serTypeName": "精准指导", | |
1195 | + * "doctorName": "", | |
1196 | + * "opnYumSize": "", | |
1197 | + * "serviceWeek": "", | |
1198 | + * "createDate": 1480953600000, | |
1199 | + * "serStatus": "开通中" | |
1200 | + *//* | |
1219 | 1201 | result.put("createDate",map.get("createDate")); |
1220 | 1202 | }*/ |
1221 | 1203 | Map<String, String> names = new LinkedHashMap<>(); |
... | ... | @@ -1319,6 +1301,5 @@ |
1319 | 1301 | return day2-day1; |
1320 | 1302 | } |
1321 | 1303 | } |
1322 | - | |
1323 | 1304 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListBySerStatusWorker.java
View file @
dc705b4
1 | +package com.lyms.platform.operate.web.worker; | |
2 | + | |
3 | +import com.lyms.platform.permission.model.ServiceListQuery; | |
4 | +import com.lyms.platform.permission.service.PatientServiceService; | |
5 | + | |
6 | +import java.util.concurrent.CopyOnWriteArrayList; | |
7 | +import java.util.concurrent.CountDownLatch; | |
8 | + | |
9 | + | |
10 | +/** | |
11 | + * @Author dongqin | |
12 | + * @Description 增值服务-柱状图 value list统计 | |
13 | + * @Date 10:58 2019/5/18 | |
14 | + */ | |
15 | +public class ServiceListBySerStatusWorker implements Runnable{ | |
16 | + private CountDownLatch cdl; | |
17 | + private ServiceListQuery param; | |
18 | + private CopyOnWriteArrayList statusValList; | |
19 | + private String serStatus; | |
20 | + private PatientServiceService patientServiceService; | |
21 | + public ServiceListBySerStatusWorker(CountDownLatch cdl, ServiceListQuery param, CopyOnWriteArrayList statusValList, String serStatus,PatientServiceService patientServiceService){ | |
22 | + this.cdl = cdl; | |
23 | + this.param = param; | |
24 | + this.statusValList = statusValList; | |
25 | + this.serStatus = serStatus; | |
26 | + this.patientServiceService = patientServiceService; | |
27 | + } | |
28 | + @Override | |
29 | + public void run() { | |
30 | + int number = 0; | |
31 | + if (!param.getHospitalIds().isEmpty()){ | |
32 | + param.setSerStatus(serStatus); | |
33 | + number = patientServiceService.countStatusInfo(param); | |
34 | + } | |
35 | + statusValList.add(number); | |
36 | + cdl.countDown(); | |
37 | + } | |
38 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/ServiceListWorker.java
View file @
dc705b4
1 | +package com.lyms.platform.operate.web.worker; | |
2 | + | |
3 | +import com.lyms.platform.biz.service.BasicConfigService; | |
4 | +import com.lyms.platform.permission.model.ServiceListQuery; | |
5 | +import com.lyms.platform.permission.service.PatientServiceService; | |
6 | +import com.lyms.platform.pojo.BasicConfig; | |
7 | + | |
8 | +import java.util.HashMap; | |
9 | +import java.util.List; | |
10 | +import java.util.Map; | |
11 | +import java.util.concurrent.Callable; | |
12 | +import java.util.concurrent.CopyOnWriteArrayList; | |
13 | + | |
14 | +/** | |
15 | + * | |
16 | + * @Author dongqin | |
17 | + * @Description 增值服务统计 | |
18 | + * @Date 9:59 2019/5/18 | |
19 | + **/ | |
20 | + | |
21 | +public class ServiceListWorker implements Callable<String> { | |
22 | + private List<String> hospitals; | |
23 | + private CopyOnWriteArrayList copyOnWriteArrayList; | |
24 | + private ServiceListQuery param; | |
25 | + private PatientServiceService patientServiceService; | |
26 | + private BasicConfigService basicConfigService; | |
27 | + | |
28 | + public ServiceListWorker(List<String> hospitals, CopyOnWriteArrayList copyOnWriteArrayList, ServiceListQuery param, | |
29 | + PatientServiceService patientServiceService, BasicConfigService basicConfigService) { | |
30 | + this.hospitals = hospitals; | |
31 | + this.copyOnWriteArrayList = copyOnWriteArrayList; | |
32 | + this.param = param; | |
33 | + this.patientServiceService = patientServiceService; | |
34 | + this.basicConfigService = basicConfigService; | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + public String call() throws Exception { | |
39 | + for (String hospital : hospitals){ | |
40 | + param.setHospitalId(hospital); | |
41 | + Map<String, Object> map = patientServiceService.getServiceList(param); | |
42 | + if (map != null){ | |
43 | + HashMap<String, Object> hashMap = new HashMap<>(16); | |
44 | + String id = map.get("provinceId").toString(); | |
45 | + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(id); | |
46 | + hashMap.put("provinceName", basicConfig.getName()); | |
47 | + | |
48 | + id = map.get("cityId").toString(); | |
49 | + basicConfig = basicConfigService.getOneBasicConfigById(id); | |
50 | + hashMap.put("cityName", basicConfig.getName()); | |
51 | + | |
52 | + id = map.get("areaId").toString(); | |
53 | + basicConfig = basicConfigService.getOneBasicConfigById(id); | |
54 | + hashMap.put("areaName", basicConfig.getName()); | |
55 | + hashMap.put("total", Integer.parseInt(map.get("open").toString()) | |
56 | + + Integer.parseInt(map.get("unsubscribe").toString()) | |
57 | + + Integer.parseInt(map.get("expire").toString()) | |
58 | + + Integer.parseInt(map.get("suspend").toString())); | |
59 | + | |
60 | + hashMap.putAll(map); | |
61 | + copyOnWriteArrayList.add(hashMap); | |
62 | + } | |
63 | + } | |
64 | + return "SUCCESS"; | |
65 | + } | |
66 | + | |
67 | +} |