📄 searchdaoimpl.java
字号:
return map;
} else {
for (int j = 0; j < vt.size(); j++) {
Vector row = (Vector) vt.get(j);
int ID = Integer.valueOf(row.get(0).toString());
map.put((fileArray[0] + j).trim(), ID);
for (int c = 1; c < fileArray.length; c++) {
String path = "";
if (row.get(c) != null) {
if (c == 3) {
String p = String
.valueOf(row.get(c).toString());
double d = Double.parseDouble(p);
path = String.valueOf(div(d, 1048576, 3));
} else {
path = String.valueOf(row.get(c).toString());
}
}
map.put((fileArray[c] + j).trim(), path.trim());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* 查询文件路径信息
*
* @param filename,id
* 文件名,文件ID
* @return 文件信息
* @throws Exception
*/
public HashMap searchFilePath(String filename, Integer id) {
System.out.println("filename+id=" + filename + "/" + id);
// 存放文件夹信息的哈希表,哈希表的key为文件夹的名称,value为文件夹名称所对应的id
HashMap folderMap = new HashMap();
// 首先把跟文件夹信息放入folderMap
folderMap.put(filename, id);
// 调用递归方法,把文件夹信息放入hashmap
getChildFolder(folderMap, filename, id, filename);
return folderMap;
}
// 递归某用户下的所有文件夹信息。
public void getChildFolder(HashMap folderMap, String userName,
Integer fileParent, String parentFolder) {
Vector vt = new Vector();
// 把获得的文件夹信息放入fileList中
final List fileList = new ArrayList();
// SQL
String sql = new Tool().getProperties("searchfilepath");
System.out.println("sql+=[]" + sql);
// 参数列表
Vector arg = new Vector();
arg.add("0");
arg.add(userName);
arg.add(fileParent);
try {
vt = DataAdapter.getData(sql, arg);
if (vt == null) {
return;
} else {
System.out.println("vtsize=" + vt.get(0));
for (int i = 0; i < vt.size(); i++) {
FileDTO dto = new FileDTO();
Vector row = (Vector) vt.get(i);
int ID = Integer.valueOf(row.get(0).toString());
String filename = String.valueOf(row.get(1).toString());
System.out.println("ID+filename=[]" + ID + "[]" + filename);
dto.setId(ID);
dto.setFileName(filename);
fileList.add(dto);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// 遍历获得的子文件夹信息
if (fileList.size() == 0) {
return;
} else {
Iterator it = fileList.iterator();
while (it.hasNext()) {
// 获得每个文件夹
FileDTO dto = (FileDTO) it.next();
String folderExpName = parentFolder + "/" + dto.getFileName();
System.out.println("folderExpName=" + folderExpName);
System.out.println("dto.getId()=" + dto.getId());
folderMap.put(folderExpName, dto.getId());
getChildFolder(folderMap, userName, dto.getId(), folderExpName);
}
}
}
/**
* 搜索父文件ID为所传id的文件信息
*
* @param id
* 文件ID
* @return 文件信息
* @throws Exception
*/
public HashMap searchFName(Integer id) {
// 定义返回值
Vector vt = new Vector();
HashMap map = new HashMap();
// 从配置文件中读取sql语句
String sql_searchfilepath = new Tool().getProperties("searchfname");
Vector arg = new Vector();
arg.add(id);
arg.add("0");
// 接受返回信息
try {
vt = DataAdapter.getData(sql_searchfilepath, arg);
if (vt == null) {
return map;
} else {
String fid = "fid";
String fname = "fname";
for (int j = 0; j < vt.size(); j++) {
Vector row = (Vector) vt.get(j);
int ID = Integer.valueOf(row.get(0).toString());
System.out.println("IDDDD>=" + ID);
map.put((fid + j).trim(), ID);
String name = String.valueOf(row.get(1).toString());
map.put((fname + j).trim(), name.trim());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* 定位文件位置
*
* @param id
* 文件ID
* @return 文件信息
* @throws Exception
*/
public HashMap filePosition(Integer id) {
// 定义返回值
Vector vt = new Vector();
HashMap map = new HashMap();
// 从配置文件中读取sql语句
String sql_fileposition = new Tool().getProperties("fileposition");
String file = new Tool().getProperties("fileArray");
String[] fileArray = file.split(",");
Vector arg = new Vector();
arg.add(id);
// 接受返回信息
try {
vt = DataAdapter.getData(sql_fileposition, arg);
if (vt == null) {
return map;
} else {
for (int j = 0; j < vt.size(); j++) {
Vector row = (Vector) vt.get(j);
int ID = Integer.valueOf(row.get(0).toString());
map.put((fileArray[0] + j).trim(), ID);
for (int c = 1; c < fileArray.length; c++) {
String path = "";
if (row.get(c) != null) {
path = String.valueOf(row.get(c).toString());
}
map.put((fileArray[c] + j).trim(), path.trim());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* 文件移动
*
* @param id,cid[]
* 要移动到的文件夹ID,所要移动的文件ID数组
* @return 文件信息
* @throws Exception
*/
public int fileRemove(Integer id, Integer[] cid) {
// 定义返回值
int i = 0;
// 从配置文件中读取sql语句
String sql_fileremove = new Tool().getProperties("fileremove");
Vector arg = new Vector();
for (int j = 0; j < cid.length; j++) {
int m = cid[j];
arg.add(id);
arg.add(m);
// 接受返回信息
try {
i = DataAdapter.update(sql_fileremove, arg);
} catch (Exception e) {
e.printStackTrace();
}
}
return i;
}
/**
* 查询文件已用容量
*
* @param username
* 用户名
* @return 文件容量大小
* @throws Exception
*/
public double content(String username) {
// 定义返回值
double cont = 0.0f;
Vector vt = new Vector();
// 从配置文件中读取sql语句
String sql_filecontent = new Tool().getProperties("filecontent");
Vector arg = new Vector();
arg.add(username);
// 接受返回信息
try {
vt = DataAdapter.getData(sql_filecontent, arg);
if (vt == null) {
return cont;
} else {
double number = 0.0;
for (int i = 0; i < vt.size(); i++) {
Vector res = (Vector) vt.get(i);
if (res != null) {
number = Double.parseDouble(res.get(0).toString());
cont = div(number, 1048576, 2);
// Iterator it=res.iterator();
// while(it.hasNext()){
// System.out.println("~~~~"+it.next());
// }
} else {
cont = 0;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return cont;
}
/**
* 查询文件已用容量的比例
*
* @param cont
* 文件容量大小
* @return 文件容量比例大小
* @throws Exception
*/
public double precent(double cont) {
// 定义返回值
double precent = 0.0f;
precent = div(cont, 100, 4);
double pre = mul(precent, 100);
return pre;
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @param scale
* 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public static double div(double v1, double v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/**
* 提供精确的乘法运算。
*
* @param v1
* 被乘数
* @param v2
* 乘数
* @return 两个参数的积
*/
public static double mul(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.multiply(b2).doubleValue();
}
/**
* 查询文件名
*
* @param id
* 文件ID
* @return 文件名
* @throws Exception
*/
public String searchfilename(Integer id) {
// 定义返回值
String filename = "";
Vector vt = new Vector();
// 从配置文件中读取sql语句
String sql_searchfilename = new Tool().getProperties("findfname");
Vector arg = new Vector();
arg.add(id);
// 接受返回信息
try {
vt = DataAdapter.getData(sql_searchfilename, arg);
if (vt == null) {
return filename;
} else {
Vector res = (Vector) vt.get(0);
filename = res.get(0).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return filename;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -