java后台曲线动态数据获取

   废话不多说,直接上代码,实践过的代码,希望对看到的朋友有所帮助

1、后台部分关键代码:

一、日增长动态曲线(按月查询)

1)// 获取日增长数据集合
List<MonthIncrNumVO> gMonthList = productMapper.getGatewayMonthIncrNum(productQuery.getGyMonth(), productQuery.getProductSlug());
// 构建日增长数据
Map<Integer, Integer> gMonthMap = new HashMap<>(31);
if (!CollectionUtils.isEmpty(gMonthList)) {
    gatewayMap = buildMonthMap(gMonthList, productQuery);
}

2)// buildMonthMap方法

private Map<Integer, Integer> buildMonthMap(List<MonthIncrNumVO> gMonthList, ProductQuery productQuery) {
    Map<Integer, Integer> tempMap = new HashMap<>(31);
    gMonthList.forEach(g -> {
        int day = Integer.valueOf(g.getDay().substring(8));
        tempMap.put(day, g.getDayCount());
    });
    int year = Integer.valueOf(productQuery.getGyMonth().substring(0, 4));
    int month = Integer.valueOf(productQuery.getGyMonth().substring(5));
    int days = getDays(year, month);
    Map<Integer, Integer> monthMap = new HashMap<>(31);
    for (int i = 1; i <= days; i++) {
        if (tempMap.containsKey(i)) {
            monthMap.put(i, tempMap.get(i));
        } else {
            monthMap.put(i, 0);// 没有对应日期,数量补0
        }
    }
    return monthMap;
}

3)获取日增长动态数据SQL

SELECT
substr( t.create_date, 1, 10 ) AS day,
count( * ) AS dayCount
FROM tableA t  
WHERE  t.create_date like CONCAT('%', #{month}, '%')
GROUP BY
substr( t.create_date, 1, 10)

// tableA 为查询的主表,month为查询的月份

二、获取月增长曲线动态数据(按年查询)

1)后台部分代码:

List<YearIncrNumVO> gyList = productMapper.getGatewayYearIncrNum(productQuery.getGYear(), productQuery.getProductSlug());
// 构建网关月增长数据
if (!CollectionUtils.isEmpty(gyList)) {
    gatewayMap = buildYearMap(gyList);
}

2)// buildYearMap方法

private Map<Integer, Integer> buildYearMap(List<YearIncrNumVO> gyList) {
    Map<Integer, Integer> tempMap = new HashMap<>(12);
    gyList.forEach(g -> {
        int month = Integer.valueOf(g.getTime().substring(5));
        tempMap.put(month, g.getMonCount());
    });

    Map<Integer, Integer> yMap = new HashMap<>(12);
    for (int i = 1; i <= 12; i++) {
        if (tempMap.containsKey(i)) {
            yMap.put(i, tempMap.get(i));
        } else {
            yMap.put(i, 0);// 没有对应的月份,数量补0
        }
    }
    return yMap;
}

3)获取月增长动态数据SQL

SELECT
substr( t.join_time, 1, 7 ) AS time,
count( * ) AS monCount
FROM table t 
WHERE t.join_time LIKE CONCAT(#{year}, '%')
GROUP BY
substr( t.join_time, 1, 7 )

// table为查询的主表,year 为查询的年份

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值