package com.yeejoin.amos.boot.module.hygf.api.util;

import net.sourceforge.pinyin4j.PinyinHelper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @description:
 * @author: tw
 * @createDate: 2023/12/12
 */
public class NumberUtil {

    private static java.util.LinkedHashMap<String, Integer> needQueryResProductList = new java.util.LinkedHashMap<String, Integer>();
    //年月日
    public static String dateFormat() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        return dateFormat.format(new Date());
    }
    //获取首字母
    public static String getChineseStr( String ChineseStr){
        StringBuilder sb = new StringBuilder();
        for (char c : ChineseStr.toCharArray()) {
            String[] pinyin = PinyinHelper.toHanyuPinyinStringArray(c);
            if (pinyin != null) {
                sb.append(pinyin[0].charAt(0));
            } else {
                sb.append(c);
            }
        }
        return sb.toString().toUpperCase();
    }
    //当天生成4位随机不重复数
    public static Integer getnum(){
        Random rand = new Random();
     if(needQueryResProductList.containsKey("num")&&needQueryResProductList.get("num")!=null&&needQueryResProductList.get("num")<9999){
         Integer num= needQueryResProductList.get("num")+rand.nextInt(100) + 1;
         needQueryResProductList.put("num",num);
         return num;
     }else{
         int num = rand.nextInt(9000) + 1;
        needQueryResProductList.put("num",num);


            return num;
        }
    }




    public static String getCode(String type,String code, String address ){



        code= code+ getChineseStr(address.replace("省","")
                .replace("市","")
                .replace("区","")
                .replace("县","")
                .replace(",",""));
        code= type+code+dateFormat()+getnum();

        return  code;
    }

}
