forked from gzzfw/backEnd/gz-dyh

huangh
2024-10-29 3c8b8029a94666ce55e38d1f11c0d1bb0330afa5
fix:统计重复案件,添加本级数据处理,修改请求方式
4 files modified
263 ■■■■ changed files
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java 158 ●●●● patch | view | raw | blame | history
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml 16 ●●●●● patch | view | raw | blame | history
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/domain/vo/CountRepeateVo.java 11 ●●●●● patch | view | raw | blame | history
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/service/AnalysisService.java 78 ●●●●● patch | view | raw | blame | history
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/controller/AnalysisWebController.java
@@ -19,6 +19,7 @@
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;
@@ -51,7 +52,7 @@
     * @param
     * @return Object
     */
    @GetMapping("/countRepeatedCasesByCaseType")
    @PostMapping("/countRepeatedCasesByCaseType")
    public ReturnBO countRepeatedCasesByCaseType(@RequestBody CountRepeateVo countRepeateVo) {
        try{
            countRepeateVo.setGroupByCaseType("true");
@@ -69,28 +70,18 @@
     * @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());
@@ -98,132 +89,25 @@
    }
    /**
     * 统计重复来访案件数量-根据案件类型分组
     * 统计重复来访案件数量-根据时间分组
     * @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());
    }
}
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/dao/mapper/xml/AnalysisMapper.xml
@@ -253,6 +253,12 @@
        <if test="createTimeStart != null and createTimeStart != '' and createTimeEnd != null and createTimeEnd != ''">
            AND ci.create_time BETWEEN #{createTimeStart} AND #{createTimeEnd}
        </if>
        <if test="finishTimeStart != null and finishTimeStart != '' and finishTimeEnd != null and finishTimeEnd != ''">
            AND cui.close_time BETWEEN #{finishTimeStart} AND #{finishTimeEnd}
        </if>
        <if test="caseType != null and caseType != ''">
            AND CI."case_type" = #{caseType}
        </if>
        <if test="queCity != null and queCity != ''">
            AND unit.city = #{queCity}
        </if>
@@ -262,13 +268,23 @@
        <if test="queRoad != null and queRoad != ''">
            AND unit.road = #{queRoad}
        </if>
        <if test="isFinish != null and isFinish != ''">
            <if test="isFinish == 'true'">
                AND CI."process" == '6'
            </if>
            <if test="isFinish == 'false'">
                AND CI."process" != '6'
            </if>
        </if>
        <if test="groupByCaseType != null and groupByCaseType != ''">
            GROUP BY case_type_first_name
        </if>
        <if test="groupByArea != null and groupByArea != ''">
<!--            AND road_name is not NULL-->
            GROUP BY area_name
        </if>
        <if test="groupByRoad != null and groupByRoad != ''">
<!--            AND road_name is not NULL-->
            GROUP BY road_name
        </if>
        <if test="groupByTime != null and groupByTime != ''">
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/domain/vo/CountRepeateVo.java
@@ -17,6 +17,12 @@
    private String createTimeEnd;
    /**
     * 办结时间区间
     */
    private String finishTimeStart;
    private String finishTimeEnd;
    /**
     * 案件案由类型
     */
    private String caseType;
@@ -55,4 +61,9 @@
     * 查询归属地-街道编码聚合标记
     */
    private String groupByRoad;
    /**
     * 查询是否办结标记
     */
    private String isFinish;
}
dyh-service/dyh-mediate/src/main/java/cn/huge/module/analysis/service/AnalysisService.java
@@ -1,5 +1,8 @@
package cn.huge.module.analysis.service;
import cn.huge.base.common.bo.ReturnBO;
import cn.huge.base.common.utils.ReturnFailUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
import cn.huge.module.analysis.dao.mapper.AnalysisMapper;
import cn.huge.module.analysis.domain.dto.CountRepeateDto;
import cn.huge.module.analysis.domain.vo.CountRepeateVo;
@@ -7,11 +10,15 @@
import cn.huge.module.cases.domain.po.CaseInfo;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dm.jdbc.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
@@ -36,10 +43,81 @@
    @Autowired
    private AnalysisMapper analysisMapper;
    // 统计重复来访案件数量
    public List<CountRepeateDto> countRepeatedCases(CountRepeateVo countRepeateVo) {
        return analysisMapper.countRepeatedCases(countRepeateVo);
    }
    public List<CountRepeateDto> countRepeatedCasesByTime(CountRepeateVo countRepeateVo){
        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 = this.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 countRepeateDtoList;
    }
    public List<CountRepeateDto> countRepeatedCasesByArea(CountRepeateVo countRepeateVo) {
        // 判断 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 = this.countRepeatedCases(countRepeateVo);
        // if (countRepeateDtoList.size() == 1 && StringUtil.isEmpty(countRepeateDtoList.get(0).getGroupByType())) {
        if (StringUtil.isEmpty(countRepeateDtoList.get(0).getGroupByType())) {
            countRepeateDtoList.get(0).setGroupByType("本级");
        }
        return countRepeateDtoList;
    }