现有过车记录集合ListAnalysisJudgmentVehicleVOAnalysisJudgmentVehicleVO属性有hpzlhphmgcsj均为String类型。参数ListAnalysisJudgmentVehicleVOksrqjsrq格式yyyy-MM-dd String类型。hpzl=小型汽车xxsl数量+1hpzl=大型汽车dxsl+1。hphm已新J开头bdcsl数量+1
/**
-
统计过车数量及类型
-
@param list 过车记录集合
-
@param ksrq 开始日期,格式yyyy-MM-dd
-
@param jsrq 结束日期,格式yyyy-MM-dd
-
@return Map<String, Object> 返回包含日期集合和各数量数据数组的Map */ public Map<String, Object> countVehicle(List
list, String ksrq, String jsrq) { //初始化返回结果 Map<String, Object> result = new HashMap<>(); List dateList = new ArrayList<>(); //日期集合 List<Map<String, Object>> countList = new ArrayList<>(); //各数量数据数组 Map<String, Object> xxslMap = new HashMap<>(); //小型汽车数量数据 xxslMap.put("name", "xxsl"); xxslMap.put("data", new ArrayList ()); Map<String, Object> dxslMap = new HashMap<>(); //大型汽车数量数据 dxslMap.put("name", "dxsl"); dxslMap.put("data", new ArrayList ()); Map<String, Object> bdcslMap = new HashMap<>(); //新J开头号牌数量数据 bdcslMap.put("name", "bdcsl"); bdcslMap.put("data", new ArrayList ()); Map<String, Object> wdcslMap = new HashMap<>(); //其他号牌数量数据 wdcslMap.put("name", "wdcsl"); wdcslMap.put("data", new ArrayList ()); countList.add(xxslMap); countList.add(dxslMap); countList.add(bdcslMap); countList.add(wdcslMap); //转换日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date startDate = null; Date endDate = null; try { startDate = sdf.parse(ksrq); endDate = sdf.parse(jsrq); } catch (ParseException e) { e.printStackTrace(); }
//按日期统计过车数量及类型 Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); while (calendar.getTime().before(endDate) || calendar.getTime().equals(endDate)) { //遍历日期范围内的每一天 String currentDate = sdf.format(calendar.getTime()); dateList.add(currentDate); int xxslCount = 0; //小型汽车数量 int dxslCount = 0; //大型汽车数量 int bdcslCount = 0; //新J开头号牌数量 int wdcslCount = 0; //其他号牌数量 int totalCount = 0; //过车总数 for (AnalysisJudgmentVehicleVO vo : list) { //遍历过车记录集合 String gcsj = vo.getGcsj(); if (gcsj.startsWith(currentDate)) { //过车时间在当天内 totalCount++; String hpzl = vo.getHpzl(); String hphm = vo.getHphm(); if (hpzl.equals("小型汽车")) { xxslCount++; } else if (hpzl.equals("大型汽车")) { dxslCount++; } if (hphm.startsWith("新J")) { bdcslCount++; } else { wdcslCount++; } } } //将当天统计结果加入数量数据数组 ((List
) xxslMap.get("data")).add(xxslCount); ((List ) dxslMap.get("data")).add(dxslCount); ((List ) bdcslMap.get("data")).add(bdcslCount); ((List ) wdcslMap.get("data")).add(wdcslCount); } //将日期集合和各数量数据数组加入返回结果 result.put("date", dateList); result.put("count", countList);
return result;
原文地址: https://www.cveoy.top/t/topic/eGbB 著作权归作者所有。请勿转载和采集!