package com.jeeplus.modules.sg.audit.information.utils;

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

import static com.jeeplus.common.utils.FileUtils.deleteDirectory;
import static com.jeeplus.common.utils.FileUtils.deleteFile;

public class RandomUtil {
    /**
     * 生成随机文件名：当前年月日时分秒+五位随机数
     *
     * @return
     */
    public static String getRandomFileName() {

        SimpleDateFormat simpleDateFormat;

        simpleDateFormat = new SimpleDateFormat("yyyyMMdd");

        Date date = new Date();

        String str = simpleDateFormat.format(date);

        Random random = new Random();

        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数

        return rannum + str;// 当前时间
    }

    public static void delete(String fileName) {
        File file = new File(fileName);
        if (!file.exists()) {
            System.out.println("删除文件失败:" + fileName + "不存在！");
        } else {
            if (file.isFile())
                 deleteFile(fileName);
            else
                 deleteDirectory(fileName);
        }
    }
}
