public static void printBar(int total, int now, String elapse) {
check(total, now);
double percent = (double) now / total * 100;
int fillNum = (int) percent;
String bar = generateBar(fillNum);
System.out.printf("\r 进度: [%s] %.2f%% | 说明: %s", bar, percent, elapse);
if (fillNum == 100) System.out.print('\n');
}
public static BigDecimal getRenMinBi(StringRedisTemplate stringRedisTemplate, BigDecimal yen) {
String exchangeRate = stringRedisTemplate.opsForValue().get("ExchangeRate");
if (exchangeRate != null) {
return yen.multiply(new BigDecimal(exchangeRate.replaceAll("\"", ""))).divide(new BigDecimal("100"), 2, RoundingMode.DOWN);
} else {
throw new RuntimeException("找不到汇率!");
}
}
private static String generateBar(int total, int fillNum, char c) {
char[] chars = new char[total];
Arrays.fill(chars, 0, fillNum, c);
Arrays.fill(chars, fillNum, total, '░');
return String.valueOf(chars);
}
private static String generateBar(int fillNum) {
return generateBar(100, fillNum, '█');
}
private static void check(int total, int now) {
if (total < now) throw new IllegalArgumentException("总数不能小于当前");
if (total < 1) throw new IllegalArgumentException("总数不能小于1");
if (now < 0) throw new IllegalArgumentException("当前不能小于0");
}