Java内部类使用

一、定义内部类

/**
 * @Description 月度布控分析DTO
 * @Author wpz
 * @Date 2024/06/28 11:28
 */
@Data
public class CaseCountAnalysisDTO {

    /**
     * 时间集合
     */
    private List<String> timeList;

    /**
     * 数据集合
     */
    private List<DataInfo> dataInfoList;


    //数据集合
    @Data
    public static class DataInfo {

        /**
         * 类型:查获总数;布控总数
         */
        private String name;

        /**
         * 数量
         */
        private List<Long> valueList;

    }

}

二、使用

  • controller层

/**
 * @Description 布控案件统计管理
 * @Author wpz
 * @Date 2024/4/20 9:24
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/case/count")
@Tag(name = "布控案件统计管理")
public class CaseCountController {


    @Resource
    private CaseCountService caseCountService;




    @Operation(summary = "一张图-月度布控分析")
    @GetMapping("/image/analysis")
    public CommonResult<CaseCountAnalysisDTO> analysis() {

        return caseCountService.analysis();
    }

}
  • service层

/**
 * @Description 案件统计服务
 * @Author wpz
 * @Date 2024/4/20 10:41
 */
@Slf4j
@Service
public class CaseCountService {


    @Resource
    private ControlCaseMapper controlCaseMapper;

    @Resource
    private DictDataMapper dictDataMapper;

    @Resource
    private IControlCaseService iControlCaseService;

    @Resource
    private PermissionService permissionService;

    @Resource
    private DeptMapper deptMapper;

    @Resource
    private ControlCarMapper controlCarMapper;

    @Resource
    private IWarnManageService iWarnManageService;

    @Resource
    private CheckpointService checkpointService;





    /**
     * 一张图-月度布控分析  最近一年数据
     *
     * @return 一张图-月度布控分析
     */
    public CommonResult<CaseCountAnalysisDTO> analysis() {

        CaseCountAnalysisDTO caseCountAnalysisDTO = new CaseCountAnalysisDTO();

        LocalDateTime endTime = LocalDateTime.now();
        LocalDateTime startTime = endTime.minusYears(1);

        // 创建一个存储月份字符串的列表
        List<String> timeList = new ArrayList<>();
        LocalDateTime currentMonth = startTime;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        while (currentMonth.isBefore(endTime) || currentMonth.equals(endTime)) {
            timeList.add(currentMonth.format(formatter));
            currentMonth = currentMonth.plusMonths(1);
        }
        caseCountAnalysisDTO.setTimeList(timeList);

        Map<String, Long> totalMap = controlCarMapper.total(startTime, endTime)
                .stream().collect(Collectors.toMap(TotalAndSeize::getMonth, TotalAndSeize::getCount, (n1, n2) -> n1));

        Map<String, Long> map = controlCarMapper.seize(startTime, endTime)
                .stream().collect(Collectors.toMap(TotalAndSeize::getMonth, TotalAndSeize::getCount, (n1, n2) -> n1));

        List<CaseCountAnalysisDTO.DataInfo> dataInfoList = CollUtil.newArrayList();
        CaseCountAnalysisDTO.DataInfo dataInfo = new CaseCountAnalysisDTO.DataInfo();
        dataInfo.setName("布控总数");

        CaseCountAnalysisDTO.DataInfo dataInfo2 = new CaseCountAnalysisDTO.DataInfo();
        dataInfo2.setName("查获总数");

        List<Long> valueList = CollUtil.newArrayList();
        List<Long> valueList2 = CollUtil.newArrayList();

        timeList.forEach(t -> {
            valueList.add(totalMap.getOrDefault(t, 0L));
            valueList2.add(map.getOrDefault(t, 0L));
        });

        dataInfo.setValueList(valueList);
        dataInfo2.setValueList(valueList2);

        dataInfoList.add(dataInfo);
        dataInfoList.add(dataInfo2);

        caseCountAnalysisDTO.setDataInfoList(dataInfoList);

        return CommonResult.success(caseCountAnalysisDTO);
    }

}
  • mapper层

/**
 * <p>
 * 布控车辆 Mapper 接口
 * </p>
 *
 * @author liubh
 * @since 2024-03-0
 */
public interface ControlCarMapper extends MPJBaseMapper<ControlCar> {


    @Select("SELECT TO_CHAR(gmt_create, 'YYYY-MM') AS month," +
            "COUNT(*) AS count " +
            "FROM control_car where status in (1,2,3,4) and gmt_create between #{startTime} and #{endTime} " +
            "GROUP BY TO_CHAR(gmt_create, 'YYYY-MM')")
    List<TotalAndSeize> total(@Param("startTime")LocalDateTime startTime, @Param("endTime")LocalDateTime endTime);

    @Select("SELECT TO_CHAR(control_time, 'YYYY-MM') AS month," +
            "COUNT(*) AS count " +
            "FROM control_car where status = 3 and control_time between #{startTime} and #{endTime} " +
            "GROUP BY TO_CHAR(control_time, 'YYYY-MM')")
    List<TotalAndSeize> seize(@Param("startTime")LocalDateTime startTime, @Param("endTime")LocalDateTime endTime);
}

三、效果

  • 页面

  • 响应信息 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值