package org.springblade.modules.order.utils;

import com.google.common.collect.Lists;
import org.springblade.core.tool.utils.DigestUtil;

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

public class PlantformUtils {
	public static String getPositiveRandomWithRang(int max, int min) {
		String r = "1234";
		if (max > 0 && min > 0 && max >= min) {
			Random random = new Random();
			int s = random.nextInt(max) % (max - min + 1) + min;
			r = String.valueOf(s);
		}
		return r;
	}
	public static String getPositiveRandomWithRang(int count) {
		StringBuffer sb = new StringBuffer();
		String str = "0123456789";
		Random r = new Random();
		for (int i = 0; i < count; i++) {
			int num = r.nextInt(str.length());
			sb.append(str.charAt(num));
			str = str.replace((str.charAt(num) + ""), "");
		}
		return sb.toString();
	}
    /**
     * 生成随机数
     * @return
     */
    public static synchronized String getSiteNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return sdf.format(new Date()) + getPositiveRandomWithRang(4);
    }

    /**
     * 生成随机数--工单编号
     * @return
     */
    public static synchronized String getOrderNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmm");
        return sdf.format(new Date()) + getPositiveRandomWithRang(4);
    }

    /**
     * 根据指定规则生成单号
    */
    public static synchronized String findOrderNumber(String start){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmm");
        return start+sdf.format(new Date()) + getPositiveRandomWithRang(4);
    }

    public static synchronized String findMateialNumber(String start){
        SimpleDateFormat sdf = new SimpleDateFormat("yyHHmmss");
        return start+sdf.format(new Date()) + getPositiveRandomWithRang(4);
    }

    public static synchronized String getFittingApplyNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        return sdf.format(new Date()) + getPositiveRandomWithRang(3);
    }
	/**
	 *
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static String  pastHour(Date date1,Date date2) {
		long hour= 0;
		long day = 0;
		String phour = "0";
		long nd = 1000 * 24 * 60 * 60;
		long nh = 1000 * 60 * 60;
		long nm = 1000 * 60;
		try
		{
			long diff = date1.getTime() - date2.getTime();
			day = diff / nd; //天数
			hour = diff % nd / nh;
			long min = diff % nd % nh / nm;
			float price = (day*24) +(float)hour+((float) min/60f);
			DecimalFormat decimalFormat=new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
			phour=decimalFormat.format(price);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return phour;
	}
    /**
     * 生成合同编号
     *
     * @return
     */
    public static synchronized String getContractNumber(String profix, int index) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyHHmmss");
        StringBuilder s = new StringBuilder(String.valueOf(index));
        while (s.toString().length() < 4) {
            s.insert(0, "0");
        }
        return profix + sdf.format(new Date()) + s.toString();
    }


    public static List<String> getPromiseLimit(){
        List<String> list = Lists.newArrayList();
        list.add("6:00-8:00");
        list.add("8:00-10:00");
        list.add("10:00-12:00");
        list.add("12:00-14:00");
        list.add("14:00-16:00");
        list.add("16:00-18:00");
        list.add("18:00-20:00");
        list.add("20:00-22:00");
        return list;
    }

	public static void main(String[] args) {
		System.out.println(DigestUtil.encrypt("123456"));
	}

}
