package com.hzs.common.core.utils;

import cn.hutool.core.util.RandomUtil;
import com.hzs.common.core.enums.EOrderPrefix;
import org.apache.commons.lang3.RandomUtils;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;

/**
 * Description:
 * Author: sui q
 * Time: 2022/9/8 13:44
 * Classname: CommonUtil
 * PackageName: com.hzs.common.core.utils
 */
public class CommonUtil {

    /**
     * 获取流水编号
     *
     * @return string
     */
    public static String createSerialNumber() {
        return createSerialNumber(EOrderPrefix.DEFAULT);
    }

    /**
     * 获取流水编号
     *
     * @param prefix 前缀，EOrderPrefix 枚举获取
     * @return string
     */
    public static String createSerialNumber(String prefix) {
        return prefix + System.currentTimeMillis() + RandomUtils.nextInt(100, 999);
    }

    /**
     * 获取流水编号
     *
     * @param eOrderPrefix EOrderPrefix 枚举获取
     * @return string
     */
    public static String createSerialNumber(EOrderPrefix eOrderPrefix) {
        return createSerialNumber(eOrderPrefix.getValue());
    }

    /**
     * 获取批次
     *
     * @return String
     */
    public static String createBatchNum() {
        //时间转字符串格式化
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
        return LocalDateTime.now(ZoneOffset.of("+8")).format(formatter) + RandomUtils.nextInt(100, 999);
    }

    public static String createSelfCode(){
        long number = System.currentTimeMillis()/1000 +RandomUtils.nextInt(1000, 9999);
        return Long.toString(number);
    }

    /**
     * 返回删除用户编号
     *
     * @param memberCode
     * @return
     */
    public static String deleteMemberCode(String memberCode) {
        return memberCode + "-" + RandomUtil.randomInt(100, 999);
    }

}
