From 1f5f3c84cb9b35d65caf576c0d46d26bda291875 Mon Sep 17 00:00:00 2001
From: huangh <hshgjzd5@163.com>
Date: Mon, 28 Oct 2024 16:32:11 +0800
Subject: [PATCH] feat:重复来访接口开发-接口开发完成-修改测试发现的bug
---
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java | 47 +++++++++++++++++++++++++++++------------------
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml | 12 ++++++++++--
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java
index 2507e44..97af59e 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java
@@ -106,36 +106,47 @@
@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));
- // }
+ 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("day");
+ countRepeateVo.setGroupByTime(dayTypeStr);
} else if ((daysBetween >= 15) && (daysBetween < 365)) {
- countRepeateVo.setGroupByTime("month");
+ countRepeateVo.setGroupByTime(monthTypeStr);
} else {
- countRepeateVo.setGroupByTime("year");
+ 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);
}catch (Exception e){
log.error("统计重复来访案件数量异常",e);
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml
index 20a82d1..57d00e0 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml
@@ -233,8 +233,16 @@
<if test="groupByRoad != null and groupByRoad != ''">
road_name as groupByType,
</if>
- <if test="groupByTime != null and groupByTime != '' and groupByTime == 'month'">
- DATE_FORMAT(ci.create_time, '%Y-%m') as groupByType,
+ <if test="groupByTime != null and groupByTime != ''">
+ <if test="groupByTime == 'day'">
+ DATE_FORMAT(ci.create_time, '%Y-%m-%d') as groupByType,
+ </if>
+ <if test="groupByTime == 'month'">
+ DATE_FORMAT(ci.create_time, '%Y-%m') as groupByType,
+ </if>
+ <if test="groupByTime == 'year'">
+ DATE_FORMAT(ci.create_time, '%Y') as groupByType,
+ </if>
</if>
COUNT(DISTINCT fc.case_id) as repeatCount
FROM FilteredCases fc
--
Gitblit v1.8.0