Commit 8338d080205aa01e4f6fbd9601b1f5a0a75204b1
1 parent
570b44c2ad
Exists in
master
and in
6 other branches
逗号改括号
Showing 3 changed files with 70 additions and 14 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
View file @
8338d08
| ... | ... | @@ -42,7 +42,7 @@ |
| 42 | 42 | @ResponseBody |
| 43 | 43 | @TokenRequired |
| 44 | 44 | @RequestMapping(value = "/patients", method = RequestMethod.GET) |
| 45 | - public BaseObjectResponse patients(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, @RequestParam 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 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
8338d08
| ... | ... | @@ -203,6 +203,7 @@ |
| 203 | 203 | List<Object> line = new ArrayList<>(); |
| 204 | 204 | Map<String, Object> barMap = new HashMap<>(); |
| 205 | 205 | Map<String, Object> lineMap = new HashMap<>(); |
| 206 | + List<Map<String, Date>> range = DateUtil.getRange(startDate, endDate); | |
| 206 | 207 | |
| 207 | 208 | if(StringUtils.isNotEmpty(aredId)) { // 按照医院统计 |
| 208 | 209 | List<String> patientIds = new ArrayList<>(); |
| ... | ... | @@ -217,6 +218,47 @@ |
| 217 | 218 | xDatas.add(couponMapper.findHospitalNameById((String) mappedResult.get("_id"))); |
| 218 | 219 | bar.add((Integer) mappedResult.get("count")); |
| 219 | 220 | } |
| 221 | + | |
| 222 | + // 拼装tab数据 | |
| 223 | + titleList.add("医院名称"); | |
| 224 | + titleList.add("统计指标(人)"); | |
| 225 | + for (Map<String, Date> map : range) { | |
| 226 | + titleList.add(DateUtil.getyyyy_mm(map.get("cname"))); | |
| 227 | + } | |
| 228 | + Map<String, Map<String, Integer>> tempMap = new HashMap<>(); | |
| 229 | + for (Patients patient : patients) { | |
| 230 | + if(tempMap.containsKey(patient.getHospitalId())) { | |
| 231 | + Map<String, Integer> map = tempMap.get(patient.getHospitalId()); | |
| 232 | + for (Map<String, Date> dateMap : range) { | |
| 233 | + String cname = DateUtil.getyyyy_mm(dateMap.get("cname")); | |
| 234 | + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() | |
| 235 | + && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) { | |
| 236 | + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1); | |
| 237 | + break; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } else { | |
| 241 | + Map<String, Integer> temp = new HashMap<>(); | |
| 242 | + for (Map<String, Date> dateMap : range) { | |
| 243 | + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() | |
| 244 | + && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) { | |
| 245 | + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1); | |
| 246 | + break; | |
| 247 | + } | |
| 248 | + } | |
| 249 | + tempMap.put(patient.getHospitalId(), temp); | |
| 250 | + } | |
| 251 | + } | |
| 252 | + for (Map.Entry<String, Map<String, Integer>> entry : tempMap.entrySet()) { | |
| 253 | + List<String> tempList = new ArrayList<>(); | |
| 254 | + tempList.add(couponMapper.findHospitalNameById(entry.getKey())); | |
| 255 | + tempList.add("建档人数"); | |
| 256 | + for (Map<String, Date> map : range) { | |
| 257 | + tempList.add(entry.getValue().containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ? | |
| 258 | + entry.getValue().get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0"); | |
| 259 | + } | |
| 260 | + tabList.add(tempList); | |
| 261 | + } | |
| 220 | 262 | } else { |
| 221 | 263 | Map<Integer, Integer> areaCountMap = new HashMap<>(); |
| 222 | 264 | String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计 |
| 223 | 265 | |
| ... | ... | @@ -242,14 +284,12 @@ |
| 242 | 284 | } |
| 243 | 285 | |
| 244 | 286 | // 拼装tab数据 |
| 245 | - List<Map<String, Date>> range = DateUtil.getRange(startDate, endDate); | |
| 246 | 287 | titleList.add((StringUtils.isNotEmpty(cityId) ? "区县" : "城市") + "名称"); |
| 247 | 288 | titleList.add("机构数"); |
| 248 | 289 | titleList.add("统计指标(人)"); |
| 249 | 290 | for (Map<String, Date> map : range) { |
| 250 | 291 | titleList.add(DateUtil.getyyyy_mm(map.get("cname"))); |
| 251 | 292 | } |
| 252 | - tabList.add(titleList); | |
| 253 | 293 | |
| 254 | 294 | List<Map<String, Object>> infos = new ArrayList<>(); |
| 255 | 295 | for (Patients patient : patients) { |
| ... | ... | @@ -257,7 +297,7 @@ |
| 257 | 297 | if(patient.getHospitalId().equals(map.get("id").toString())) { |
| 258 | 298 | boolean flag = true; |
| 259 | 299 | for (Map<String, Object> info : infos) { |
| 260 | - if(map.get("cityId").equals(info.get("id"))) { | |
| 300 | + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) { | |
| 261 | 301 | Set<String> hids = (Set<String>) info.get("hids"); |
| 262 | 302 | hids.add(patient.getHospitalId()); |
| 263 | 303 | for (Map<String, Date> dateMap : range) { |
| ... | ... | @@ -284,7 +324,6 @@ |
| 284 | 324 | Set<String> hids = new HashSet<>(); |
| 285 | 325 | hids.add(patient.getHospitalId()); |
| 286 | 326 | info.put(monthKey, 1); |
| 287 | -// info.put("id", map.get("cityId")); | |
| 288 | 327 | info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"))); |
| 289 | 328 | info.put("hids", hids); |
| 290 | 329 | infos.add(info); |
| 291 | 330 | |
| ... | ... | @@ -308,14 +347,9 @@ |
| 308 | 347 | } |
| 309 | 348 | System.out.println(tabList); |
| 310 | 349 | } |
| 311 | -// | |
| 312 | -// if(StringUtils.isNotEmpty(cityId)) { // 按照区县来 对应孕妇建档统计-市 | |
| 313 | -// | |
| 314 | -// } else { // 按照城市来 对应孕妇建档统计-省 | |
| 315 | -// | |
| 316 | -// } | |
| 317 | 350 | |
| 318 | - setTabListInfo(tabList); | |
| 351 | + tabList.add(0, titleList); | |
| 352 | + setTabListInfo(tabList, StringUtils.isNotEmpty(aredId) ? 2 : 3); | |
| 319 | 353 | |
| 320 | 354 | barMap.put("data", bar); |
| 321 | 355 | barMap.put("type", "bar"); |
| ... | ... | @@ -347,7 +381,7 @@ |
| 347 | 381 | return RespBuilder.buildSuccess(restMap); |
| 348 | 382 | } |
| 349 | 383 | |
| 350 | - private void setTabListInfo(List<List<String>> tabList) { | |
| 384 | + private void setTabListInfo(List<List<String>> tabList, int index) { | |
| 351 | 385 | if(CollectionUtils.isNotEmpty(tabList)) { |
| 352 | 386 | for (int i = 0; i < tabList.size(); i++) { |
| 353 | 387 | List<String> list = tabList.get(i); |
| ... | ... | @@ -357,7 +391,7 @@ |
| 357 | 391 | list.add("合计"); |
| 358 | 392 | } else { |
| 359 | 393 | int count = 0; |
| 360 | - for (int j = 3; j < list.size(); j++) { | |
| 394 | + for (int j = index; j < list.size(); j++) { | |
| 361 | 395 | count += Integer.parseInt(list.get(j)); |
| 362 | 396 | } |
| 363 | 397 | list.add(0, ++seq + ""); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java
View file @
8338d08
| ... | ... | @@ -77,6 +77,24 @@ |
| 77 | 77 | return "0.00%"; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | + public static String getProportion(Integer num, Integer count) { | |
| 81 | + if(num != null && StringUtils.isNumeric(num.toString()) && count != null && count != 0) { | |
| 82 | + Double division = Double.parseDouble(division(Integer.parseInt(num.toString()), count)) * 100; | |
| 83 | + String s = doubleFormat(division); | |
| 84 | + s = removeZero(s); | |
| 85 | + return s; | |
| 86 | + } | |
| 87 | + return "0"; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public static String removeZero(String s) { | |
| 91 | + if(StringUtils.isNotEmpty(s) && ((s.endsWith("0") && s.contains(".")) || s.endsWith("."))) { | |
| 92 | + s = s.substring(0, s.length() - 1); | |
| 93 | + return removeZero(s); | |
| 94 | + } | |
| 95 | + return s; | |
| 96 | + } | |
| 97 | + | |
| 80 | 98 | public static String getProportion(Object obj, Object count) { |
| 81 | 99 | if(StringUtils.isNotBlank("count") && StringUtils.isNumeric(count.toString())) |
| 82 | 100 | return getProportion(obj, Integer.parseInt(count.toString())); |
| ... | ... | @@ -92,6 +110,10 @@ |
| 92 | 110 | */ |
| 93 | 111 | public static Double division(Double a, Double b, Integer digit) { |
| 94 | 112 | return new BigDecimal(a / b).setScale(digit, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| 113 | + } | |
| 114 | + | |
| 115 | + public static void main(String[] args) { | |
| 116 | + System.out.println(getProportion(30, 100)); | |
| 95 | 117 | } |
| 96 | 118 | |
| 97 | 119 |