diff --git a/src/main/java/com/biutag/supervision/constants/enums/MailTrendSourcesEnum.java b/src/main/java/com/biutag/supervision/constants/enums/MailTrendSourcesEnum.java new file mode 100644 index 0000000..3718bbf --- /dev/null +++ b/src/main/java/com/biutag/supervision/constants/enums/MailTrendSourcesEnum.java @@ -0,0 +1,25 @@ +package com.biutag.supervision.constants.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum MailTrendSourcesEnum { + ONE(1, 21), + TWO(2, 22), + THREE(3, 23), + FOUR(4, 24); + + private final int code; // 前端传来的code + private final int mappedCode; // 后端需要用到的code + + public static int getMappedCodeByCode(int code) { + for (MailTrendSourcesEnum value : MailTrendSourcesEnum.values()) { + if (value.code == code) { + return value.getMappedCode(); + } + } + throw new IllegalArgumentException("Invalid sourcesCode: " + code); + } +} diff --git a/src/main/java/com/biutag/supervision/controller/datav/DataPetitionComplaintViewController.java b/src/main/java/com/biutag/supervision/controller/datav/DataPetitionComplaintViewController.java index ff0bbdf..d2769f0 100644 --- a/src/main/java/com/biutag/supervision/controller/datav/DataPetitionComplaintViewController.java +++ b/src/main/java/com/biutag/supervision/controller/datav/DataPetitionComplaintViewController.java @@ -11,15 +11,17 @@ import com.biutag.supervision.mapper.DataPetitionComplaintMapper; import com.biutag.supervision.pojo.Result; import com.biutag.supervision.pojo.dto.CaseVerifDepart; import com.biutag.supervision.pojo.entity.DataPetitionComplaint; +import com.biutag.supervision.pojo.vo.RecentMailTrendVo; import com.biutag.supervision.service.DataPetitionComplaintService; import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -75,5 +77,42 @@ public class DataPetitionComplaintViewController { return Result.success(data); } + /** + * 信访数据大屏信访趋势统计 + */ + @GetMapping("/getRecentlyMailTrend") + public Result getRecentlyMailTrend(@RequestParam Integer sourcesCode, + @RequestParam Integer days, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime + ) { + JSONObject jsonObject = new JSONObject(); + // 库中的数据 2024/10/24 22 + List recentMailTrendVoList = dataPetitionComplaintService.getRecentlyMailTrend(sourcesCode, days, endTime); + ArrayList dayList = new ArrayList<>(); + ArrayList totalList = new ArrayList<>(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + LocalDate previousDate = null; + for (RecentMailTrendVo recentMailTrendVo : recentMailTrendVoList) { + // 获取当前日期 + LocalDate currentDate = LocalDate.parse(recentMailTrendVo.getDayTime(), formatter); + if (previousDate != null) { + while (ChronoUnit.DAYS.between(previousDate, currentDate) > 1) { + previousDate = previousDate.plusDays(1); // 日期加1 + String res = previousDate.format(formatter); // 格式化日期 + dayList.add(res.substring(res.indexOf('/') + 1)); // 添加到dayList + totalList.add("0"); // 插入没有数据的日期,总数为0 + } + } + String res = currentDate.format(formatter); + dayList.add(res.substring(res.indexOf('/') + 1)); + totalList.add(recentMailTrendVo.getTotal()); + previousDate = currentDate; + } + jsonObject.fluentPut("dayList", dayList); + jsonObject.fluentPut("totalList", totalList); + return Result.success(jsonObject); + } + } diff --git a/src/main/java/com/biutag/supervision/mapper/DataPetitionComplaintMapper.java b/src/main/java/com/biutag/supervision/mapper/DataPetitionComplaintMapper.java index b45bd53..96eb1c0 100644 --- a/src/main/java/com/biutag/supervision/mapper/DataPetitionComplaintMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/DataPetitionComplaintMapper.java @@ -3,6 +3,7 @@ package com.biutag.supervision.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.biutag.supervision.pojo.dto.CaseVerifDepart; import com.biutag.supervision.pojo.entity.DataPetitionComplaint; +import com.biutag.supervision.pojo.vo.RecentMailTrendVo; import org.apache.ibatis.annotations.Select; import java.util.Date; @@ -71,4 +72,13 @@ public interface DataPetitionComplaintMapper extends BaseMapper selectMassMail(Integer id, int isMass, Date beginTime, Date endTime); + + @Select("SELECT DATE_FORMAT(dpc.discovery_time, '%Y/%m/%d') AS dayTime, COUNT(*) total " + + "FROM data_petition_complaint dpc " + + "WHERE dpc.discovery_time BETWEEN #{frontDay} AND #{currentDay} " + + "AND problem_sources_code = #{sourcesCode} " + + "GROUP BY dayTime " + + "ORDER BY dpc.discovery_time asc;") + List selectRecentlyMailTrend(Integer sourcesCode, String frontDay, String currentDay); + } diff --git a/src/main/java/com/biutag/supervision/pojo/vo/RecentMailTrendVo.java b/src/main/java/com/biutag/supervision/pojo/vo/RecentMailTrendVo.java new file mode 100644 index 0000000..6d8598a --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/vo/RecentMailTrendVo.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.pojo.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class RecentMailTrendVo { + private String dayTime; // 10/01 + private String total; // 10 +} diff --git a/src/main/java/com/biutag/supervision/service/DataPetitionComplaintService.java b/src/main/java/com/biutag/supervision/service/DataPetitionComplaintService.java index 713cfdf..3676f3d 100644 --- a/src/main/java/com/biutag/supervision/service/DataPetitionComplaintService.java +++ b/src/main/java/com/biutag/supervision/service/DataPetitionComplaintService.java @@ -13,12 +13,16 @@ import com.biutag.supervision.mapper.DataPetitionComplaintMapper; import com.biutag.supervision.pojo.dto.*; import com.biutag.supervision.pojo.entity.DataPetitionComplaint; import com.biutag.supervision.pojo.param.DataPetitionComplaintQueryParam; +import com.biutag.supervision.pojo.vo.RecentMailTrendVo; import lombok.RequiredArgsConstructor; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; @@ -202,5 +206,15 @@ public class DataPetitionComplaintService extends ServiceImpl getRecentlyMailTrend(Integer sourcesCode, Integer days, Date endTime) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + // 将 endTime 转换为 LocalDate + LocalDate endLocalDate = endTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String currentDay = endLocalDate.format(formatter); // 前端页面的最后查询日期 + LocalDate frontDateDay = endLocalDate.minusDays(days); // days天前 + String frontDay = frontDateDay.format(formatter); + List recentMailTrendVos = + dataPetitionComplaintMapper.selectRecentlyMailTrend(MailTrendSourcesEnum.getMappedCodeByCode(sourcesCode), frontDay, currentDay); + return recentMailTrendVos; + } }