package com.bcxin.identify.util.file;

import cn.hutool.core.lang.Console;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.handler.RowHandler;
import com.google.common.io.Files;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

@Slf4j
public class BcxinStringUtils {

	/**
	 * 产生随机1-10 的 随机数
	 * @return String
	 */
	public static String random(int length){
		StringBuilder sb = new StringBuilder(length);
		for ( int i=0;i<length;i++ ) {
			sb.append(ThreadLocalRandom.current().nextInt(10));
		}
		return sb.toString();
	}

	public static void main2(String[] args) {
		File file = new File("d:/student.xls");
		if ("xls".equals(Files.getFileExtension(file.getName()))) {
			ExcelUtil.read03BySax(file, 0, createRowHandler());
		} else if ("xlsx".equals(Files.getFileExtension(file.getName()))) {
			ExcelUtil.read07BySax(file, 0, createRowHandler());
		}
	}

	/**
	 * 按字母顺序排序
	 *
	 * @param source
	 * @return
	 */
	public static String AbcSort(String source) {
		char[] c = source.toCharArray();// 将字符串转换成char数组
		Arrays.sort(c);// 对数组进行排序
		return String.valueOf(c);//
	}

	private static RowHandler createRowHandler() {
		return new RowHandler() {
			@Override
			public void handle(int sheetIndex, int rowIndex, List<Object> rowlist) {
				Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist);
			}
		};
	}

}
