package org.dromara.wflow.workflow.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Base64;

public class DeptIdUtil {
    public static String subDeptIdLastZero(String deptId){
        int index = findLastNonZeroIndex(deptId);
        boolean oushu = index % 2 == 0;
        if (oushu){
            return deptId.substring(0, index + 1);
        }else{
            return deptId.substring(0, index);
        }
    }

    private static int findLastNonZeroIndex(String str) {
        if (str == null || str.isEmpty()) {
            return -1;
        }

        for (int i = str.length() - 1; i >= 0; i--) {
            if (str.charAt(i) != '0') {
                return i;
            }
        }
        return -1;
    }

    public static byte[] base64ConvertToByte(String base64String) throws IOException {
        // 1. 移除Base64前缀（如存在）
        String base64Data = base64String.split(",")[1]; // 处理"data:image/png;base64,"格式

        // 2. 解码Base64数据
        return  Base64.getDecoder().decode(base64Data);

    }
}
