package com.zy.asrs.common.utils;
|
|
import com.zy.asrs.framework.common.Cools;
|
|
import java.security.SecureRandom;
|
import java.text.DecimalFormat;
|
|
/**
|
* Created by vincent on 2020/8/27
|
*/
|
public class Utils {
|
|
private static final DecimalFormat fmt = new DecimalFormat("##0.00");
|
|
public static String zerofill(String msg, Integer count){
|
if (msg.length() == count){
|
return msg;
|
} else if (msg.length() > count){
|
return msg.substring(0, 16);
|
} else {
|
StringBuilder msgBuilder = new StringBuilder(msg);
|
for (int i = 0; i<count-msg.length(); i++){
|
msgBuilder.insert(0,"0");
|
}
|
return msgBuilder.toString();
|
}
|
}
|
|
/**
|
* 通过库位号获取 排
|
*/
|
public static int getRow(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(0, 2));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 列
|
*/
|
public static int getBay(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(2, 5));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 层
|
*/
|
public static int getLev(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(5, 7));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 生成随机字符串
|
*/
|
public static String generateString(int length) {
|
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // 可选的字符集合
|
SecureRandom random = new SecureRandom();
|
StringBuilder sb = new StringBuilder(length);
|
for (int i = 0; i < length; i++) {
|
int index = random.nextInt(characters.length());
|
char randomChar = characters.charAt(index);
|
sb.append(randomChar);
|
}
|
return sb.toString();
|
}
|
|
}
|