添加功能
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("未知"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
155
ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/ParamUtil.java
Normal file
155
ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/ParamUtil.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package com.ruoyi.cms.util;
|
||||
|
||||
import com.ruoyi.cms.constant.CommonConstant;
|
||||
import com.ruoyi.cms.domain.dto.QueryParamDto;
|
||||
import com.ruoyi.cms.domain.vo.QueryResultVo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 参数工具类
|
||||
*
|
||||
* @author 马宝龙
|
||||
* @date 2026/6/27
|
||||
*/
|
||||
public class ParamUtil {
|
||||
private ParamUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理参数
|
||||
*
|
||||
* @param dto 参数
|
||||
*/
|
||||
public static void dealParam(QueryParamDto dto) {
|
||||
|
||||
if (Objects.isNull(dto)) {
|
||||
throw new ServiceException("参数不能为空");
|
||||
}
|
||||
if (Objects.isNull(dto.getQueryTimeType())) {
|
||||
throw new ServiceException("时间类型不能为空");
|
||||
}
|
||||
if (Objects.isNull(dto.getYear())) {
|
||||
throw new ServiceException("年份不能为空");
|
||||
}
|
||||
|
||||
LocalTime min = LocalTime.of(0, 0, 0);
|
||||
LocalTime max = LocalTime.of(23, 59, 59);
|
||||
|
||||
switch (dto.getQueryTimeType()) {
|
||||
case YEAR: {
|
||||
dto.setStartTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 1, 1), min));
|
||||
dto.setEndTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 12, 31), max));
|
||||
break;
|
||||
}
|
||||
case QUARTER: {
|
||||
if (Objects.isNull(dto.getQuarter())) {
|
||||
throw new ServiceException("季度不能为空");
|
||||
}
|
||||
switch (dto.getQuarter()) {
|
||||
case 1:
|
||||
dto.setStartTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 1, 1), min));
|
||||
dto.setEndTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 3, 31), max));
|
||||
break;
|
||||
case 2:
|
||||
dto.setStartTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 4, 1), min));
|
||||
dto.setEndTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 6, 30), max));
|
||||
break;
|
||||
case 3:
|
||||
dto.setStartTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 7, 1), min));
|
||||
dto.setEndTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 9, 30), max));
|
||||
break;
|
||||
case 4:
|
||||
dto.setStartTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 10, 1), min));
|
||||
dto.setEndTime(LocalDateTime.of(LocalDate.of(dto.getYear(), 12, 31), max));
|
||||
break;
|
||||
default:
|
||||
throw new ServiceException("季度错误");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MONTH: {
|
||||
if (Objects.isNull(dto.getMonth())) {
|
||||
throw new ServiceException("月份不能为空");
|
||||
}
|
||||
LocalDateTime startTime = LocalDateTime.of(LocalDate.of(dto.getYear(), dto.getMonth(), 1), min);
|
||||
dto.setStartTime(startTime);
|
||||
dto.setEndTime(startTime.plusMonths(1L).minusSeconds(1L));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ServiceException("时间类型错误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算上一时间段时间
|
||||
*
|
||||
* @param dto 参数
|
||||
*/
|
||||
public static void calculateLastTime(QueryParamDto dto) {
|
||||
|
||||
if (Objects.isNull(dto)) {
|
||||
throw new ServiceException("参数不能为空");
|
||||
}
|
||||
if (Objects.isNull(dto.getQueryTimeType())) {
|
||||
throw new ServiceException("时间类型不能为空");
|
||||
}
|
||||
if (Objects.isNull(dto.getStartTime()) || Objects.isNull(dto.getEndTime())) {
|
||||
throw new ServiceException("时间不能为空");
|
||||
}
|
||||
switch (dto.getQueryTimeType()) {
|
||||
case YEAR: {
|
||||
dto.setStartTime(dto.getStartTime().minusYears(1L));
|
||||
dto.setEndTime(dto.getEndTime().minusYears(1L));
|
||||
break;
|
||||
}
|
||||
case QUARTER: {
|
||||
dto.setStartTime(dto.getStartTime().minusMonths(3L));
|
||||
dto.setEndTime(dto.getEndTime().minusMonths(3L));
|
||||
break;
|
||||
}
|
||||
case MONTH: {
|
||||
dto.setStartTime(dto.getStartTime().minusMonths(1L));
|
||||
dto.setEndTime(dto.getEndTime().minusMonths(1L));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ServiceException("时间类型错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 填充字典名称
|
||||
*
|
||||
* @param list 列表
|
||||
* @param dictName 字典名称
|
||||
*/
|
||||
public static void fillDictName(List<QueryResultVo> list, String dictName) {
|
||||
|
||||
|
||||
if (CollectionUtils.isEmpty(list) || StringUtils.isBlank(dictName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (dictName) {
|
||||
case "industry": {
|
||||
for (QueryResultVo vo : list) {
|
||||
vo.setDesc(Optional.ofNullable(CommonConstant.INDUSTRY_MAP.get(vo.getCode())).orElse("未知"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ServiceException("字典名称错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user