/** * 组合单日期/状态与多维度条件 * * @param xxDTO * @return */ public Map<String, Object> xxMethod(XxDTO xxDTO) { // 返回结果集 Map<String, Object> resultMap = new HashMap<>(); // 数据库结果集 List<XxVO> vOList = mapper.getByCalendar(xxDTO); // 日期SET集合 Set<String> dateSet = new LinkedHashSet<>(); // 条件SET集合 Set<String> conditionSet = new HashSet<>(); // 日期-条件,值MAP集合 Map<String, String> datas = new HashMap<>(); // 组合日期与条件集合 vOList.forEach(vo -> { dateSet.add(vo.getDate()); datas.put(vo.getDate() + "-" + vo.getCondition(), vo.getValue()); conditionSet.add(vo.getCondition() == null ? "" : vo.getCondition()); }); List<Map<String, Object>> resultList = new ArrayList<>(); for (String condition : conditionSet) { Map<String, Object> conditionMap = new HashMap<>(); conditionMap.put("name", condition); List<String> valueList = new ArrayList<>(); for (String date : dateSet) { if (datas.containsKey(date + "-" + condition)) { valueList.add(datas.get(date + "-" + condition)); } else { valueList.add("0"); } } conditionMap.put("data", valueList); resultList.add(conditionMap); } resultMap.put("date", dateSet); resultMap.put("datas", resultList); return resultMap; }