package com.hfkj.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Random;

public class CommonUtil {

    public static String unitLengthTransform(BigDecimal length){

        if(length==null){
            return null;
        }
        if (length.compareTo(new BigDecimal(1000)) > 0) {
            return length.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP) + "千米";
        }

        return length + "米";
    }

    public static Integer saleNumRandom(BigDecimal price){


        if (price.compareTo(new BigDecimal(41)) < 0) {
            return randomNumberGenerator(3000 , 15000);
        }
        if (price.compareTo(new BigDecimal(40)) > 0 && price.compareTo(new BigDecimal(200)) < 0) {
            return randomNumberGenerator( 500, 3000);
        }
        if (price.compareTo(new BigDecimal(201)) > 0 && price.compareTo(new BigDecimal(400)) < 0) {
            return randomNumberGenerator( 200, 500);
        }
        if (price.compareTo(new BigDecimal(401)) > 0) {
            return randomNumberGenerator( 10, 200);
        }

        return 0;
    }

    /**
     * @MethodName RandomNumberGenerator
     * @Description: 获取区间随机数
     * @param min
     * @param max
     * @return: java.lang.Integer
     * @Author: Sum1Dream
     * @Date: 2024/9/2 下午4:02
     */
    public static Integer randomNumberGenerator(Integer min , Integer max){

        Random random = new Random();

        return random.nextInt(max - min + 1) + min;
    }
}
