Commit e1228acd by 张富康

整车分布

1 parent f1c161ea
......@@ -36,13 +36,13 @@ public class ReceivingCostDistributionRes implements Serializable {
* 整体收车成本分布 2万<X≤5万 车辆数
*/
@ApiModelProperty(notes = "整体收车成本分布 2万<X≤5万 车辆数")
private Integer receivingCostDistribution2WMore;
private Integer receivingCostDistribution2WMoreLess5W;
/**
* 整体收车成本分布 2万<X≤5万 占比
*/
@ApiModelProperty(notes = "整体收车成本分布 2万<X≤5万 占比")
private BigDecimal receivingCostDistribution2WMorePercent;
private BigDecimal receivingCostDistribution2WMoreLess5WPercent;
/**
* 整体收车成本分布 X≤2万 车辆数
......
......@@ -12,5 +12,5 @@ import java.util.List;
public interface CarManageInfoMapper extends OreMapper<CarManageInfo> {
List<CarManageInfoDTO> queryPurchasePrice(@Param("merchantIdList") List<Integer> merchantIdList)
List<CarManageInfoDTO> queryPurchasePrice(@Param("merchantIdList") List<Integer> merchantIdList);
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import cn.com.glsx.merchants.model.response.MerchantSimpleResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
......@@ -23,6 +24,8 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
......@@ -147,7 +150,37 @@ public class UsedCarDataStatsService {
// 查询vcp_car_manage_info
List<CarManageInfoDTO> carManageInfoList = carManageInfoMapper.queryPurchasePrice(merchantIdList);
return null;
// 如果为空则返回空结果
if (CollUtil.isEmpty(carManageInfoList)) {
return new ReceivingCostDistributionRes();
}
ReceivingCostDistributionRes result = new ReceivingCostDistributionRes();
// 统计个数
int carNumber = carManageInfoList.size();
BigDecimal purchasePrice2W = new BigDecimal("20000");
BigDecimal purchasePrice5W = new BigDecimal("50000");
// 统计 整体收车成本分布 X>5万 车辆数
Integer receivingCostDistribution5WMore = (int) carManageInfoList.stream()
.filter(x -> x.getPurchasePrice().compareTo(purchasePrice5W) > 0)
.count();
// 统计 整体收车成本分布 2万<X≤5万 车辆数
Integer receivingCostDistribution2WMoreLess5W = (int) carManageInfoList.stream()
.filter(x -> x.getPurchasePrice().compareTo(purchasePrice2W) > 0
&& x.getPurchasePrice().compareTo(purchasePrice5W) <= 0)
.count();
// 统计 整体收车成本分布 X≤2万 车辆数
Integer receivingCostDistributionLess2W = (int) carManageInfoList.stream()
.filter(x -> x.getPurchasePrice().compareTo(purchasePrice2W) <= 0)
.count();
// 计算占比 保留百分比两位小数,即xx.xx%
result.setReceivingCostDistribution5WMorePercent(calculateDiv(receivingCostDistribution5WMore, carNumber));
result.setReceivingCostDistribution2WMoreLess5WPercent(calculateDiv(receivingCostDistribution2WMoreLess5W, carNumber));
result.setReceivingCostDistributionLess2WPercent(calculateDiv(receivingCostDistributionLess2W, carNumber));
result.setReceivingCostDistribution5WMore(receivingCostDistribution5WMore);
result.setReceivingCostDistribution2WMoreLess5W(receivingCostDistribution2WMoreLess5W);
result.setReceivingCostDistributionLess2W(receivingCostDistributionLess2W);
return result;
}
......@@ -211,6 +244,10 @@ public class UsedCarDataStatsService {
return results;
}
private static BigDecimal calculateDiv(Number num1, Number num2) {
return NumberUtil.div(num1, num2, 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
}
}
......@@ -136,6 +136,8 @@
purchase_price as purchasePrice
from vcp_car_manage_info
where deleted_flag = 'N'
and source_store is not null
and purchase_price is not null
<if test="merchantIdList != null and merchantIdList.size > 0">
and source_store in
<foreach item="item" collection="merchantIdList" separator="," open="(" close=")" index="index">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!