package thyyxxk.webserver.utils;

import cn.hutool.core.lang.Pair;

import java.math.BigDecimal;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @ClassName YbReportUtil
 * @Description 医保报表工具类
 * @Author hsh
 * @Date 2022/9/8 16:32
 **/
public class YbReportUtil {

    /**
     *@Author hsh
     *@Description // 获取有效位数
     *@Date 2022/9/8 16:39
     *@Param [b]
     *@Return int
     **/
    public static int getYxws(BigDecimal b){
        String str = String.valueOf(b);
        int index = str.lastIndexOf(".");
        if(index < 0){
            return str.length();
        } else {
            return str.length() - 1;
        }
    }

    /**
     * 生成len个字符的唯一随机字符串，由数字大小写字母组成
     * @param increment 唯一数字
     * @param len 唯一随机字符长度
     * @return 字符串
     */
    public static String generateUkStr(long increment, int len) {
        char[] incrementArr = String.format("%0" + len + "d", increment).toCharArray();
        Pair<Integer, Integer> pairA = Pair.of(17, 33);
        Pair<Integer, Integer> pairB = Pair.of(49, 65);
        StringBuilder result = new StringBuilder(len);
        char s;
        for (char c : incrementArr) {
            int randomNum = ThreadLocalRandom.current().nextInt(0, 3);
            if (randomNum == 0) {
                s = c;
            } else if (randomNum == 1) {
                s = (char) (c + ThreadLocalRandom.current().nextInt(pairA.getKey(), pairA.getValue() + 1));
            } else {
                s = (char) (c + ThreadLocalRandom.current().nextInt(pairB.getKey(), pairB.getValue() + 1));
            }
            result.append(s);
        }
        return result.toString();
    }

}
