package com.whyc.util;
|
|
import com.whyc.constant.YamlProperties;
|
import com.whyc.pojo.plus_user.UserInf;
|
import com.whyc.service.OperationLogService;
|
import org.springframework.boot.system.ApplicationHome;
|
import org.springframework.stereotype.Component;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.File;
|
|
/**
|
* 通用工具列
|
*/
|
@Component
|
public class CommonUtil {
|
|
private static OperationLogService service;
|
//将数转换成二进制字符串并统计1的个数
|
public static int getIntToBinary(int switchState,int[] bit){
|
int count=0;
|
if(bit.length>0){
|
for (int i=0;i<bit.length;i++){
|
int ss=switchState&(1<<bit[i]);
|
if(ss>0){
|
count++;
|
}
|
}
|
}
|
return count;
|
}
|
|
/**
|
* 手动记录特定日志
|
*/
|
public static void record(int type1,int type2, String msg, String msgDetail) {
|
service.record(type1, type2, msg, msgDetail);
|
}
|
|
/**获取当前Session中的属性user*/
|
public static UserInf getUser(HttpServletRequest request) {
|
return (UserInf) request.getSession().getAttribute("user");
|
}
|
|
public static String classesPath(){
|
ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class);
|
File jarFile = applicationHome.getDir();
|
return jarFile.toString();
|
}
|
|
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+"fg_file"+File.separator;
|
}else {
|
//打包路径
|
baseDirPath = jarFile.toString()+File.separator+"fg_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;
|
}
|
|
|
|
}
|