package com.ruoyi.web.controller.tool;

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

public class Moneytarnfrom {
    public static String digitUppercase(String b){
        float n= Float.valueOf(b)*10000;
        String[] fraction = {"角", "分"};
        String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
        String[][] unit = {{"元", "万", "亿"},
                {"", "拾", "佰", "仟"}};

        String head = n < 0? "负": "";
        n = Math.abs(n);

        String s = "";
        for (int i = 0; i < fraction.length; i++) {
            s += (digit[(int)(Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
        }
        if(s.length()<1){
            s = "整";
        }
        int integerPart = (int)Math.floor(n);

        for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
            String p ="";
            for (int j = 0; j < unit[1].length && n > 0; j++) {
                p = digit[integerPart%10]+unit[1][j] + p;
                integerPart = integerPart/10;
            }
            s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
        }
        return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
    }

    /**将时间分成两个时间段
     *
     */
    //将时间分成两个时间段

    //将时间分成两个时间段

    public static String  Buildtime(int d,Date date) {
        String  result, month, day;
        int dd=d;
        String date1=dateToStr(date);
       int year = Integer.parseInt(date1.substring(0,4));
        int year1=year+dd;
        int tty = Integer.parseInt(date1.substring(5,7));
        if(tty<10){
            month=date1.substring(6,7);
        }else{
            month= String.valueOf(tty);
        }
        int tty1 = Integer.parseInt(date1.substring(8,10));
        if(tty1<10){
            day=date1.substring(9,10);
        }else{
            day= String.valueOf(tty1);
        }
        result = year + "年" + month + "月" + day + "日至"+year1+"年"+month + "月" + day + "日";
        return result;
    }
    /**
     * 将短时间格式时间转换为字符串 yyyy-MM-dd
     *
     * @param dateDate
     * @return
     */
    public static String dateToStr(Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
        String dateString = formatter.format(dateDate);
        return dateString;
    }
    /**
     * 将短时间格式字符串转换为时间 yyyy-MM-dd
     *
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

}
