package com.whyc.util;
|
|
import com.whyc.constant.YamlProperties;
|
import org.springframework.boot.system.ApplicationHome;
|
import org.springframework.stereotype.Component;
|
|
import java.io.File;
|
|
/**
|
* 通用工具列
|
*/
|
@Component
|
public class CommonUtil {
|
|
|
public static String classesPath(){
|
ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class);
|
File jarFile = applicationHome.getDir();
|
return jarFile.toString();
|
}
|
|
/**
|
* 获取存放文件的根路径
|
* @return 返回存放文件的根路径
|
*/
|
public static String getRootFile(){
|
ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class);
|
File jarFile = applicationHome.getDir();
|
String baseDirPath;
|
if(YamlProperties.runModel == 1) {
|
//开发路径
|
baseDirPath = jarFile.getParentFile().toString()+File.separator+"battery_gwm_file"+File.separator;
|
}else {
|
//打包路径
|
baseDirPath = jarFile.toString()+File.separator+"battery_gwm_file"+File.separator;
|
}
|
return baseDirPath;
|
}
|
|
/**
|
* 获取项目所在文件夹路径
|
* @return 获取项目所在文件夹路径
|
*/
|
public static String getProjectDir(){
|
ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class);
|
File jarFile = applicationHome.getDir();
|
String baseDirPath;
|
if(YamlProperties.runModel == 1) {
|
//开发路径
|
baseDirPath = jarFile.getParentFile().toString();
|
}else {
|
//打包路径
|
baseDirPath = jarFile.toString();
|
}
|
return baseDirPath;
|
}
|
|
|
/**
|
* 物料编码自动填充补齐
|
* @param code
|
* @return
|
*/
|
public static String codeAutoFill(String code){
|
int length = code.length();
|
if (length == 9) {
|
code = "0" + code;
|
} else if (length < 9) {
|
int centerZeroNum = 10 - length - 1;
|
StringBuilder centerZeroStr = new StringBuilder();
|
for (int j = 0; j < centerZeroNum; j++) {
|
centerZeroStr.append("0");
|
}
|
String strFront = code.substring(0, 3);
|
String strBehind = code.substring(3);
|
code = "0" + strFront + centerZeroStr + strBehind;
|
}
|
return code;
|
}
|
|
}
|