| | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByCaseType") |
| | | @PostMapping("/countRepeatedCasesByCaseType") |
| | | public ReturnBO countRepeatedCasesByCaseType(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | countRepeateVo.setGroupByCaseType("true"); |
| | |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByArea") |
| | | @PostMapping("/countRepeatedCasesByArea") |
| | | public ReturnBO countRepeatedCasesByArea(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | countRepeateVo.setIsFinish("false"); |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCasesByArea(countRepeateVo); |
| | | countRepeateVo.setIsFinish("true"); |
| | | List<CountRepeateDto> countRepeateDtoListIsFinish = service.countRepeatedCasesByArea(countRepeateVo); |
| | | Map<String, List<CountRepeateDto>> collect = new HashMap<>(); |
| | | collect.put("未办结",countRepeateDtoList); |
| | | collect.put("已办结",countRepeateDtoListIsFinish); |
| | | |
| | | // 判断 countRepeateVo 的 queRoad 是否为空 |
| | | // 如果 queRoad 和 queArea 都为空且 queCity 不为空,则设置 groupByArea 为 true 根据 区 聚合 |
| | | if (StringUtil.isEmpty(countRepeateVo.getQueRoad()) && |
| | | StringUtil.isEmpty(countRepeateVo.getQueArea()) && |
| | | ! StringUtil.isEmpty(countRepeateVo.getQueCity())) { |
| | | countRepeateVo.setGroupByArea("true"); |
| | | } |
| | | // 如果 queRoad 为空且 queCity 和 queArea 不为空,则设置 groupByRoad 为 true 根据 街道 聚合 |
| | | else if (StringUtil.isEmpty(countRepeateVo.getQueRoad()) && |
| | | ! StringUtil.isEmpty(countRepeateVo.getQueArea()) && |
| | | ! StringUtil.isEmpty(countRepeateVo.getQueCity())) { |
| | | countRepeateVo.setGroupByRoad("true"); |
| | | } |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCases(countRepeateVo); |
| | | if (countRepeateDtoList.size() == 1 && StringUtil.isEmpty(countRepeateDtoList.get(0).getGroupByType())) { |
| | | countRepeateDtoList.get(0).setGroupByType("本级"); |
| | | } |
| | | return ReturnSucUtils.getRepInfo("请求成功",countRepeateDtoList); |
| | | return ReturnSucUtils.getRepInfo("请求成功",collect); |
| | | }catch (Exception e){ |
| | | log.error("统计重复来访案件数量异常",e); |
| | | return ReturnFailUtils.getRepInfo(e.getMessage()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 统计重复来访案件数量-根据案件类型分组 |
| | | * 统计重复来访案件数量-根据时间分组 |
| | | * @url {ctx}/api/web/analysis/countRepeatedCasesByCaseType |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByTime") |
| | | @PostMapping("/countRepeatedCasesByTime") |
| | | public ReturnBO countRepeatedCasesByTime(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | |
| | | DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | String dayTypeStr = "day"; |
| | | String monthTypeStr = "month"; |
| | | String yearTypeStr = "year"; |
| | | |
| | | LocalDate start = LocalDate.parse(countRepeateVo.getCreateTimeStart(), DATE_TIME_FORMATTER); |
| | | LocalDate end = LocalDate.parse(countRepeateVo.getCreateTimeEnd(), DATE_TIME_FORMATTER); |
| | | |
| | | long daysBetween = java.time.temporal.ChronoUnit.DAYS.between(start, end); |
| | | if (daysBetween < 15) { |
| | | countRepeateVo.setGroupByTime(dayTypeStr); |
| | | } else if ((daysBetween >= 15) && (daysBetween < 365)) { |
| | | countRepeateVo.setGroupByTime(monthTypeStr); |
| | | } else { |
| | | countRepeateVo.setGroupByTime(yearTypeStr); |
| | | } |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCases(countRepeateVo); |
| | | if (!countRepeateDtoList.isEmpty()){ |
| | | String timeFormatter = ""; |
| | | if (dayTypeStr.equals(countRepeateVo.getGroupByTime())){ |
| | | timeFormatter = "日"; |
| | | } |
| | | else if (monthTypeStr.equals(countRepeateVo.getGroupByTime())) { |
| | | timeFormatter = "月"; |
| | | } |
| | | else if (yearTypeStr.equals(countRepeateVo.getGroupByTime())) { |
| | | timeFormatter = "年"; |
| | | } |
| | | for (CountRepeateDto countRepeateDto : countRepeateDtoList) { |
| | | // 按 “-”切割字符串,获取最后一个元素 |
| | | String[] split = countRepeateDto.getGroupByType().split("-"); |
| | | String lastElement = split[split.length - 1]; |
| | | // 判断 lastElement 是否为小于 13 的数字,如果是,则将类型转换为int |
| | | if (lastElement.matches("^\\d+$")) { |
| | | lastElement = String.valueOf(Integer.parseInt(lastElement)); |
| | | } |
| | | countRepeateDto.setGroupByType(lastElement + timeFormatter); |
| | | } |
| | | |
| | | } |
| | | return ReturnSucUtils.getRepInfo("请求成功",countRepeateDtoList); |
| | | countRepeateVo.setIsFinish("false"); |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCasesByTime(countRepeateVo); |
| | | countRepeateVo.setIsFinish("true"); |
| | | List<CountRepeateDto> countRepeateDtoListIsFinish = service.countRepeatedCasesByTime(countRepeateVo); |
| | | Map<String, List<CountRepeateDto>> collect = new HashMap<>(); |
| | | collect.put("未办结",countRepeateDtoList); |
| | | collect.put("已办结",countRepeateDtoListIsFinish); |
| | | return ReturnSucUtils.getRepInfo("请求成功",collect); |
| | | }catch (Exception e){ |
| | | log.error("统计重复来访案件数量异常",e); |
| | | return ReturnFailUtils.getRepInfo(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private List<String> getDaysList(LocalDate start, LocalDate end) { |
| | | List<String> days = new ArrayList<>(); |
| | | while (!start.isAfter(end)) { |
| | | days.add(start.toString()); |
| | | start = start.plusDays(1); |
| | | } |
| | | return days; |
| | | } |
| | | |
| | | private List<String> getMonthsList(LocalDate start, LocalDate end) { |
| | | List<String> months = new ArrayList<>(); |
| | | while (!start.isAfter(end)) { |
| | | String month = start.getMonth().name().substring(0, 3); // 例如 "JAN" |
| | | // 获取中文月份 |
| | | switch (month) { |
| | | case "JAN": |
| | | month = "一月"; |
| | | break; |
| | | case "FEB": |
| | | month = "二月"; |
| | | break; |
| | | case "MAR": |
| | | month = "三月"; |
| | | break; |
| | | case "APR": |
| | | month = "四月"; |
| | | break; |
| | | case "MAY": |
| | | month = "五月"; |
| | | break; |
| | | case "JUN": |
| | | month = "六月"; |
| | | break; |
| | | case "JUL": |
| | | month = "七月"; |
| | | break; |
| | | case "AUG": |
| | | month = "八月"; |
| | | break; |
| | | case "SEP": |
| | | month = "九月"; |
| | | break; |
| | | case "OCT": |
| | | month = "十月"; |
| | | break; |
| | | case "NOV": |
| | | month = "十一月"; |
| | | break; |
| | | case "DEC": |
| | | month = "十二月"; |
| | | break; |
| | | } |
| | | if (!months.contains(month)) { |
| | | months.add(month); |
| | | } |
| | | start = start.plusMonths(1); |
| | | } |
| | | // return months.stream().map(m -> m + "月").collect(Collectors.toList()); |
| | | return months; |
| | | } |
| | | |
| | | private List<String> getYearsList(LocalDate start, LocalDate end) { |
| | | List<String> years = new ArrayList<>(); |
| | | while (!start.isAfter(end)) { |
| | | String year = Integer.toString(start.getYear()); |
| | | if (!years.contains(year)) { |
| | | years.add(year); |
| | | } |
| | | start = start.plusYears(1); |
| | | } |
| | | return years.stream().map(y -> y + "年").collect(Collectors.toList()); |
| | | } |
| | | } |