package com.mmc.iuav.general;

import java.util.Random;

/**
 * @author: zj
 * @Date: 2023/5/16 20:01
 */
public class CodeUtil {
    private static Random random = new Random();

    public static String getRandomNum(int length) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(String.valueOf(random.nextInt(10)));
        }
        return sb.toString();
    }

    public static String generateUserUID() {
        return CodeUtil.getRandomNum(9);
    }

    public static String randomCode(int i) {
        return CodeUtil.getRandomNum(i);
    }

    public static String removeUserAccount() {
        return "DELETE" + CodeUtil.getRandomNum(15);
    }

    public static String createRoleNo(String roleNo) {
        return getNewEquipmentNo("A", roleNo);
    }

    public static String getNewEquipmentNo(String equipmentType, String equipmentNo) {
        String newEquipmentNo = "A" + "0001";
        if (equipmentNo != null && !equipmentNo.isEmpty()) {
            int newEquipment = Integer.parseInt(equipmentNo.substring(1)) + 1;
            newEquipmentNo = String.format(equipmentType + "%04d", newEquipment);
        }
        return newEquipmentNo;
    }
}
