/**

  • 统计过车数量

  • @param list 过车记录集合

  • @param ksrq 开始日期,格式为yyyy-MM-dd

  • @param jsrq 结束日期,格式为yyyy-MM-dd

  • @return 返回一个包含日期数组和数量数据数组的Map对象,格式为:

  • {

  • dates: ['2019-01-01', '2019-01-02', ...],
    
  • numbers: [
    
  •     { name: 'xxsl', data: [120, 132, 101, ...]}, // 小型汽车数量
    
  •     { name: 'dxsl', data: [30, 43, 50, ...]}, // 大型汽车数量
    
  •     { name: 'bdcsl', data: [5, 2, 8, ...]}, // 特定号牌车数量
    
  •     { name: 'wdcsl', data: [65, 71, 49, ...]}, // 其他车辆数量
    
  •     { name: 'bdcwdcsl', data: [10, 5, 3, ...]}, // 本地特定号牌车数量
    
  •     { name: 'wddwdcsl', data: [5, 3, 2, ...]} // 外地特定号牌车数量
    
  • ]
    
  • } */ public Map<String, Object> statVehicleNumbers(List list, String ksrq, String jsrq) {

    // 日期格式化器 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    // 将开始日期和结束日期转换为Calendar对象 Calendar calStart = Calendar.getInstance(); Calendar calEnd = Calendar.getInstance(); try { calStart.setTime(sdf.parse(ksrq)); calEnd.setTime(sdf.parse(jsrq)); } catch (ParseException e) { e.printStackTrace(); }

    // 定义结果集合 List xxslList = new ArrayList<>(); // 小型汽车数量 List dxslList = new ArrayList<>(); // 大型汽车数量 List bdcslList = new ArrayList<>(); // 特定号牌车数量 List wdcslList = new ArrayList<>(); // 其他车辆数量 List bdcwdcslList = new ArrayList<>(); // 本地特定号牌车数量 List wddwdcslList = new ArrayList<>(); // 外地特定号牌车数量 List datesList = new ArrayList<>(); // 日期列表

    // 遍历每一天并统计过车数量 while (!calStart.after(calEnd)) { int xxsl = 0; int dxsl = 0; int bdcsl = 0; int wdcsl = 0; int bdcwdcsl = 0; int wddwdcsl = 0; String dateStr = sdf.format(calStart.getTime()); for (AnalysisJudgmentVehicleVO vo : list) { String hphm = vo.getHphm(); String hpzl = vo.getHpzl(); String gcsj = vo.getGcsj(); if (gcsj.startsWith(dateStr)) { if ('小型汽车'.equals(hpzl)) { xxsl++; } else if ('大型汽车'.equals(hpzl)) { dxsl++; } else if (hphm.startsWith('新J')) { bdcsl++; if (hphm.startsWith('新J粤')) { bdcwdcsl++; } else { wddwdcsl++; } } else { wdcsl++; if (hphm.startsWith('粤')) { bdcwdcsl++; } else { wddwdcsl++; } } } } xxslList.add(xxsl); dxslList.add(dxsl); bdcslList.add(bdcsl); wdcslList.add(wdcsl); bdcwdcslList.add(bdcwdcsl); wddwdcslList.add(wddwdcsl); datesList.add(dateStr); calStart.add(Calendar.DATE, 1); }

    // 构造结果Map Map<String, Object> resultMap = new HashMap<>(); resultMap.put('dates', datesList); List<Map<String, Object>> numbersList = new ArrayList<>(); numbersList.add(buildDataMap('xxsl', xxslList)); numbersList.add(buildDataMap('dxsl', dxslList)); numbersList.add(buildDataMap('bdcsl', bdcslList)); numbersList.add(buildDataMap('wdcsl', wdcslList)); numbersList.add(buildDataMap('bdcwdcsl', bdcwdcslList)); numbersList.add(buildDataMap('wddwdcsl', wddwdcslList)); resultMap.put('numbers', numbersList);

    return resultMap; }

/**

  • 构造指定名称和数据列表的数据Map对象
  • @param name 名称
  • @param dataList 数据列表
  • @return 数据Map对象 */ private Map<String, Object> buildDataMap(String name, List dataList) { Map<String, Object> dataMap = new HashMap<>(); dataMap.put('name', name); dataMap.put('data', dataList); return dataMap; }
统计过车数量 - Java 代码实现

原文地址: https://www.cveoy.top/t/topic/nW02 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录