| | |
| | | package cn.huge.module.analysis.controller; |
| | | |
| | | import cn.huge.base.common.bo.ReturnBO; |
| | | import cn.huge.base.common.utils.ReturnFailUtils; |
| | | import cn.huge.base.common.utils.ReturnSucUtils; |
| | | import cn.huge.base.config.CurrentUser; |
| | | import cn.huge.module.analysis.domain.dto.CountRepeateDto; |
| | | import cn.huge.module.analysis.domain.vo.CountRepeateVo; |
| | | import cn.huge.module.analysis.service.AnalysisService; |
| | | import cn.huge.module.cases.domain.po.CaseInfo; |
| | | import cn.huge.module.cases.service.CaseInfoService; |
| | | import com.google.common.collect.Maps; |
| | | import cn.huge.module.client.api.impl.CustClientImpl; |
| | | import cn.huge.module.cust.dto.CtUnitDTO; |
| | | import cn.huge.module.cust.dto.CtUserDTO; |
| | | import dm.jdbc.util.StringUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.PageRequest; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @title: 纠纷信息主表接口api-web端 |
| | |
| | | |
| | | @Autowired |
| | | private AnalysisService service; |
| | | @Autowired |
| | | private CustClientImpl custClient; |
| | | |
| | | |
| | | /** |
| | | * 统计重复来访案件数量-根据案件类型分组 |
| | | * @url {ctx}/api/web/analysis/countRepeatedCasesByCaseType |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByCaseType") |
| | | public ReturnBO countRepeatedCasesByCaseType(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | countRepeateVo.setGroupByCaseType("true"); |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCases(countRepeateVo); |
| | | return ReturnSucUtils.getRepInfo("请求成功",countRepeateDtoList); |
| | | }catch (Exception e){ |
| | | log.error("统计重复来访案件数量异常",e); |
| | | return ReturnFailUtils.getRepInfo(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统计重复来访案件数量-根据地区分组 |
| | | * @url {ctx}/api/web/analysis/countRepeatedCasesByArea |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByArea") |
| | | public ReturnBO countRepeatedCasesByArea(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | |
| | | // 判断 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); |
| | | }catch (Exception e){ |
| | | log.error("统计重复来访案件数量异常",e); |
| | | return ReturnFailUtils.getRepInfo(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统计重复来访案件数量-根据案件类型分组 |
| | | * @url {ctx}/api/web/analysis/countRepeatedCasesByCaseType |
| | | * @param |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/countRepeatedCasesByTime") |
| | | public ReturnBO countRepeatedCasesByTime(@RequestBody CountRepeateVo countRepeateVo) { |
| | | try{ |
| | | // countRepeateVo.setGroupByCaseType("true"); |
| | | // List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCases(countRepeateVo); |
| | | // return ReturnSucUtils.getRepInfo("请求成功",countRepeateDtoList); |
| | | |
| | | DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // 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) { |
| | | // return Map.of("days", getDaysList(start, end)); |
| | | // } else if ((daysBetween >= 15) && (daysBetween < 365)) { |
| | | // return Map.of("months", getMonthsList(start, end)); |
| | | // } else { |
| | | // return Map.of("years", getYearsList(start, end)); |
| | | // } |
| | | |
| | | 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("day"); |
| | | } else if ((daysBetween >= 15) && (daysBetween < 365)) { |
| | | countRepeateVo.setGroupByTime("month"); |
| | | } else { |
| | | countRepeateVo.setGroupByTime("year"); |
| | | } |
| | | List<CountRepeateDto> countRepeateDtoList = service.countRepeatedCases(countRepeateVo); |
| | | return ReturnSucUtils.getRepInfo("请求成功",countRepeateDtoList); |
| | | }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()); |
| | | } |
| | | } |