添加功能
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.ruoyi.cms.util;
|
||||
|
||||
import com.ruoyi.cms.constant.CommonConstant;
|
||||
import com.ruoyi.cms.constant.enums.QueryTimeTypeEnum;
|
||||
import com.ruoyi.cms.domain.vo.HeatmapVo;
|
||||
import com.ruoyi.cms.domain.vo.QueryResultVo;
|
||||
import com.ruoyi.cms.domain.vo.TreadVo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -92,10 +95,11 @@ public class MathUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算占比
|
||||
*
|
||||
* @param list 热力图数据
|
||||
* @param list 数据
|
||||
*/
|
||||
public static void calculatePercentage(List<QueryResultVo> list) {
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
@@ -111,6 +115,33 @@ public class MathUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算环比
|
||||
*
|
||||
* @param lastCount 上期数据
|
||||
* @param currentCount 本期数据
|
||||
* @return 环比
|
||||
*/
|
||||
public static BigDecimal calculatePercentageGrowthRate(Long lastCount, Long currentCount) {
|
||||
lastCount = Optional.ofNullable(lastCount).orElse(0L);
|
||||
currentCount = Optional.ofNullable(currentCount).orElse(0L);
|
||||
return calculatePercentage(lastCount, (currentCount - lastCount));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算环比
|
||||
*
|
||||
* @param lastBigDecimal 上期数据
|
||||
* @param currentBigDecimal 本期数据
|
||||
* @return 环比
|
||||
*/
|
||||
public static BigDecimal calculatePercentageGrowthRate(BigDecimal lastBigDecimal, BigDecimal currentBigDecimal) {
|
||||
lastBigDecimal = Optional.ofNullable(lastBigDecimal).orElse(BigDecimal.ZERO);
|
||||
currentBigDecimal = Optional.ofNullable(currentBigDecimal).orElse(BigDecimal.ZERO);
|
||||
|
||||
return calculatePercentage(lastBigDecimal, (currentBigDecimal.subtract(lastBigDecimal)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算同比和环比
|
||||
*
|
||||
@@ -189,6 +220,7 @@ public class MathUtil {
|
||||
|
||||
for (HeatmapVo vo : list) {
|
||||
vo.setPercentage(calculatePercentage(totalCount, vo.getCount()));
|
||||
vo.setAreaName(Optional.ofNullable(CommonConstant.AREA_MAP.get(vo.getAreaCode())).orElse("未知"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user