返回单日期多条件时/多条件自动补充到单日期数据

/**
 * 组合单日期/状态与多维度条件
 *
 * @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;
}

 

posted on 2019-09-24 14:47  HuaChenYing  阅读(211)  评论(0编辑  收藏  举报

导航