143 lines
4.5 KiB
Plaintext
143 lines
4.5 KiB
Plaintext
package com.sercurityControl.proteam.util;
|
|
|
|
|
|
|
|
import com.sercurityControl.proteam.domain.LoginLogBean;
|
|
import com.sercurityControl.proteam.domain.OperateLogBean;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 文件读写类
|
|
*/
|
|
public class FileHelper {
|
|
/**
|
|
* 判断文件是否存在
|
|
* @param fileName
|
|
* @throws IOException
|
|
*/
|
|
public static boolean fileIsExists(String fileName) {
|
|
File file=new File(fileName);
|
|
try {
|
|
if(!file.exists()){
|
|
// file.createNewFile();
|
|
return false;
|
|
}else{
|
|
return true;
|
|
}
|
|
}catch (Exception e){
|
|
System.err.println(e.toString());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**'
|
|
* 向登录日志文件中写入数据
|
|
* @param fileName
|
|
* @param list
|
|
* @return
|
|
*/
|
|
public static boolean fileWriteLoginLogData(String fileName, List<LoginLogBean> list){
|
|
try {
|
|
String data = "";
|
|
for (LoginLogBean FileLogDTO : list) {
|
|
data += loginLogDataHandler(FileLogDTO) + "\n";
|
|
}
|
|
FileWriter writer = new FileWriter(fileName, true);
|
|
writer.write(data);
|
|
writer.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 解析登录日志数据
|
|
* @param bean
|
|
* @return
|
|
*/
|
|
private static String loginLogDataHandler(LoginLogBean bean){
|
|
String systemId="aqzljczx55a580ac6bbf643854c928d4d5b5ff71s5v3g5h6k8h2g4d3s4g5d";
|
|
return bean.getUserId()+"\t"+bean.getUserName()+"\t"+bean.getLoginName()+"\t"+bean.getUserIp()+"\t"+bean.getLoginTime()+"\t"+systemId+"\t"+bean.getSystemName()+"\t"+bean.getOrgId()+"\t"+bean.getOrgName()+"\n";
|
|
}
|
|
|
|
/**'
|
|
* 向菜单日志文件中写入数据
|
|
* @param fileName
|
|
* @param list
|
|
* @return
|
|
*/
|
|
public static boolean fileWriteOperateLogData(String fileName, List<OperateLogBean> list){
|
|
try {
|
|
String data = "";
|
|
for (OperateLogBean FileLogDTO : list) {
|
|
data += operateLogDataHandler(FileLogDTO) + "\n";
|
|
}
|
|
FileWriter writer = new FileWriter(fileName, true);
|
|
writer.write(data);
|
|
writer.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 解析菜单日志数据
|
|
* @param bean
|
|
* @return
|
|
*/
|
|
private static String operateLogDataHandler(OperateLogBean bean){
|
|
String systemId="aqzljczx55a580ac6bbf643854c928d4d5b5ff71s5v3g5h6k8h2g4d3s4g5d";
|
|
return bean.getUserId()+"\t"+bean.getUserName()+"\t"+bean.getLoginName()+"\t"+bean.getVisitTime()+"\t"+systemId+"\t"+bean.getSystemName()+"\t"+bean.getResourceId()+"\t"+bean.getResourceName()+"\t"+bean.getUrl()+"\t"+bean.getOrgId()+"\t"+bean.getOrgName()+"\n";
|
|
}
|
|
|
|
|
|
/**
|
|
* 删除某个文件夹下的所有文件夹和文件
|
|
*
|
|
* @param delpath
|
|
* String
|
|
* @throws FileNotFoundException
|
|
* @throws IOException
|
|
* @return boolean
|
|
*/
|
|
public static boolean deletefile(String delpath) throws Exception {
|
|
try {
|
|
|
|
File file = new File(delpath);
|
|
// 当且仅当此抽象路径名表示的文件存在且 是一个目录时,返回 true
|
|
if (!file.isDirectory()) {
|
|
file.delete();
|
|
} else if (file.isDirectory()) {
|
|
String[] filelist = file.list();
|
|
for (int i = 0; i < filelist.length; i++) {
|
|
File delfile = new File(delpath + "\\" + filelist[i]);
|
|
if (!delfile.isDirectory()) {
|
|
delfile.delete();
|
|
System.out.println(delfile.getAbsolutePath() + "删除文件成功");
|
|
} else if (delfile.isDirectory()) {
|
|
deletefile(delpath + "\\" + filelist[i]);
|
|
System.out.println(file + "ssss");
|
|
}
|
|
}
|
|
/*if (!file.toString().equals("D:\\file")) { //选择不删除自身文件夹
|
|
System.out.println(file.toString() + "lllllll");
|
|
file.delete();
|
|
}*/
|
|
}
|
|
|
|
} catch (FileNotFoundException e) {
|
|
System.out.println("deletefile() Exception:" + e.getMessage());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|