|
@@ -4,6 +4,8 @@ import java.io.BufferedInputStream;
|
|
|
import java.io.BufferedOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.LinkedHashMap;
|
|
@@ -28,6 +30,9 @@ import com.fuzamei.constant.Role;
|
|
|
import com.fuzamei.entity.UserDetail;
|
|
|
import com.fuzamei.service.ProjectFileService;
|
|
|
import com.fuzamei.service.UserAuthoricationService;
|
|
|
+import com.fuzamei.utils.AbsolutePathUtil;
|
|
|
+import com.fuzamei.utils.AbsolutePathUtil;
|
|
|
+import com.fuzamei.utils.CalculateFileHashUtil;
|
|
|
import com.fuzamei.utils.HashXiZhiUtil;
|
|
|
import com.fuzamei.utils.JSONUtil;
|
|
|
import com.fuzamei.utils.PageDTO;
|
|
@@ -77,9 +82,10 @@ public class ProjectFileAction {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Map<String, String> map = JSON.parseObject(data, Map.class); //将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
|
|
|
int userId = ValidationUtil.checkAndAssignInt(map.get("userId")); //userId只要是一个int类型即可
|
|
|
+ userAuthoricationService.checkUserAuthority(userId);//校验并让所有人都能看
|
|
|
int page = ValidationUtil.checkMinAndAssignInt(map.get("page"), 1); // 默认页数是第一页
|
|
|
String projectName = ValidationUtil.checkBlankStringAndAssignEmptyIfIsBlank(map.get("projectName")); // 默认名称为空值
|
|
|
- long startTime = ValidationUtil.checkAndAssignDefaultLong(map.get("startTime"), 0); // 默认起始时间为0
|
|
|
+ long startTime = ValidationUtil.checkAndAssignDefaultLong(map.get("startTime"), 0L); // 默认起始时间为0
|
|
|
long endTime = ValidationUtil.checkAndAssignDefaultLong(map.get("endTime"), Long.MAX_VALUE); // 默认终止时间为Long最大值
|
|
|
Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
|
|
|
mapToService.put("userId", userId); //用户id用于查询权限或者角色信息
|
|
@@ -100,7 +106,6 @@ public class ProjectFileAction {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @Title: checkoutProjectFiles
|
|
|
* @Description: TODO--------------->>显示下载文件的提示框
|
|
|
* 以下为前端传递过来的参数
|
|
@@ -115,7 +120,6 @@ public class ProjectFileAction {
|
|
|
* @return Map<String,Object> 返回类型
|
|
|
* @author ylx
|
|
|
* @date 2017年12月15日 下午8:09:44
|
|
|
- * @throws
|
|
|
*/
|
|
|
@RequestMapping(value = "/checkoutProjectFiles")
|
|
|
private Map<String, Object> checkoutProjectFiles(@RequestBody String data){
|
|
@@ -124,7 +128,8 @@ public class ProjectFileAction {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Map<String, Object> map = JSON.parseObject(data, Map.class); // 将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
|
|
|
int userId = ValidationUtil.checkAndAssignInt(map.get("userId")); //userId只要是一个int类型即可
|
|
|
- Integer projectId = ValidationUtil.checkAndAssignDefaultInt(map.get("projectId"),0); //默认项目编号为空
|
|
|
+ userAuthoricationService.checkUserAuthority(userId); //所有人都能下载
|
|
|
+ Integer projectId = ValidationUtil.checkAndAssignInt(map.get("projectId"));
|
|
|
String projectName=ValidationUtil.checkBlankStringAndAssignEmptyIfIsBlank(map.get("projectName")); //默认项目名称为空值
|
|
|
Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
|
|
|
mapToService.put("userId", userId);
|
|
@@ -133,12 +138,11 @@ public class ProjectFileAction {
|
|
|
Map<String, Object> mapFromService = projectFileService.checkoutProjectFiles(mapToService); //由于这里不需要分页,只要service传过来一个map对象即可
|
|
|
return JSONUtil.getJsonMap(200, true, HintMSG.CHECK_SUCCESS, mapFromService); //将从service返回回来的map对象通过map对象直接返回给前端
|
|
|
} catch (Exception e) {
|
|
|
- return JSONUtil.getJsonMap(500, false, HintMSG.CHECK_FAIL+":"+e.getMessage(), null);
|
|
|
+ return JSONUtil.getJsonMap(500, false, HintMSG.CHECK_FAIL+":"+e.getMessage(), null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @Title: download
|
|
|
* @Description: TODO(项目文档中的文件下载功能实现)
|
|
|
* 前端传来一个get或post请求
|
|
@@ -147,15 +151,17 @@ public class ProjectFileAction {
|
|
|
* @return void 返回类型
|
|
|
* @author ylx
|
|
|
* @date 2017年12月15日 下午6:03:53
|
|
|
- * @throws
|
|
|
*/
|
|
|
@RequestMapping(value="/downloadProjectFile")
|
|
|
- private Map<String, Object> download(HttpServletRequest request,HttpServletResponse response,@RequestParam("url") String url,@RequestParam("userId") Object uId) {
|
|
|
+ private Map<String, Object> download(HttpServletRequest request,
|
|
|
+ HttpServletResponse response,
|
|
|
+ @RequestParam("url") String url,
|
|
|
+ @RequestParam("userId") Object uId) {
|
|
|
try {
|
|
|
int userId=ValidationUtil.checkAndAssignInt(uId);
|
|
|
// userAuthoricationService.checkUserAuthority(userId,Role.SUPERVISION_AGENCY,Role.ARCHIVE_KEEPING_POS_OF_PBBTBC);//查看用户是否为空及是否有权限下载项目文档文件
|
|
|
userAuthoricationService.checkUserAuthority(userId);//所有人都能下载
|
|
|
- String fileName = request.getServletContext().getRealPath("")+url; //SP是系统分隔符
|
|
|
+ String fileName = AbsolutePathUtil.getAbsolutePath(request)+SP+url; //SP是系统分隔符
|
|
|
//如果文件不存在直接抛出异常
|
|
|
if(!new File(fileName).exists()){
|
|
|
throw new RuntimeException(HintMSG.FILE_NOT_FOUND);
|
|
@@ -200,9 +206,9 @@ public class ProjectFileAction {
|
|
|
try {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Map<String,Object> map = JSON.parseObject(data, Map.class);
|
|
|
- int userId = ValidationUtil.checkAndAssignInt(map.get("userId")); //userId只要是一个int类型即可
|
|
|
- userAuthoricationService.checkUserAuthority(userId,Role.ARCHIVE_KEEPING_POS_OF_PBBTBC); //该权限只有 【省分行托管分中心档案保管岗】才能操作
|
|
|
- Integer projectId = ValidationUtil.checkAndAssignDefaultInt(map.get("projectId"),-1); //默认项目编号为-1,就是让你查不到
|
|
|
+ int userId = ValidationUtil.checkAndAssignInt(map.get("userId"));
|
|
|
+ userAuthoricationService.checkUserAuthority(userId,Role.ARCHIVE_KEEPING_POS_OF_PBBTBC); //该权限只有【省分行托管分中心档案保管岗】才能操作
|
|
|
+ Integer projectId = ValidationUtil.checkAndAssignInt(map.get("projectId"));
|
|
|
String projectName=ValidationUtil.checkBlankStringAndAssignEmptyIfIsBlank(map.get("projectName")); //默认项目名称为空值
|
|
|
Map<String, Object> mapToClient =new LinkedHashMap<String, Object>();
|
|
|
mapToClient.put("projectId", projectId);
|
|
@@ -238,39 +244,36 @@ public class ProjectFileAction {
|
|
|
HttpServletRequest request) {
|
|
|
try {
|
|
|
int userId=ValidationUtil.checkAndAssignInt(uId);
|
|
|
- UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.ARCHIVE_KEEPING_POS_OF_PBBTBC);//查看用户是否为空及是否有权限下载项目文档文件
|
|
|
- String projectId = ValidationUtil.checkBlankAndAssignString(pId); //校验projectId并赋值
|
|
|
- String projectName = ValidationUtil.checkBlankAndAssignString(pName); //校验projectName并赋值
|
|
|
+ UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.ARCHIVE_KEEPING_POS_OF_PBBTBC);//上传文件权限检测
|
|
|
+ String projectId = ValidationUtil.checkBlankAndAssignString(pId);
|
|
|
+ String projectName = ValidationUtil.checkBlankAndAssignString(pName);
|
|
|
if(file.isEmpty()){
|
|
|
- throw new RuntimeException(HintMSG.FILE_CANT_BE_NULL); //校验上传的文件是否为空
|
|
|
+ throw new RuntimeException(HintMSG.FILE_CANT_BE_NULL);
|
|
|
}
|
|
|
- String path = request.getServletContext().getRealPath("")+SP+"content"; //SP是系统分隔符,path是存放上传文件的父类文件夹绝对路径====>>这个路径要改TODO
|
|
|
+ String path = AbsolutePathUtil.getAbsolutePath(request);//==================================================>>这个路径要改TODO
|
|
|
File dir=new File(path);
|
|
|
if(!dir.exists()){
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- String filename = file.getOriginalFilename(); //filename是上传文件的真实文件名
|
|
|
- String pathFile=path+SP+filename; //pathFile是该文件在系统中的绝对路径
|
|
|
+ String filename = file.getOriginalFilename();//filename是上传文件的真实文件名
|
|
|
+ String pathFile=path+SP+filename;//pathFile是该文件在系统中的绝对路径
|
|
|
File newFile=new File(pathFile);
|
|
|
|
|
|
- String fileHash = HashXiZhiUtil.getMD5Checksum(filename); //文件上传后计算文件的hash值=============>>换hash算法这里直接换掉即可TODO
|
|
|
+ String fileHash = CalculateFileHashUtil.calculateHash(file);//传入MultiPartFile直接计算hash值
|
|
|
+
|
|
|
Map<String, Object> mapToService =new LinkedHashMap<String, Object>();
|
|
|
- mapToService.put("userDetail", userDetail); //将用户的信息传入
|
|
|
+ mapToService.put("userDetail", userDetail);
|
|
|
mapToService.put("projectId", projectId);
|
|
|
mapToService.put("projectName", projectName);
|
|
|
- mapToService.put("url", "/content/"+filename); //将文件下载路径url通过map传到service层进行校验
|
|
|
- mapToService.put("attachmentName", filename); //将文件以附件名的形式通过map传递到service层中进行校验
|
|
|
- mapToService.put("hash", fileHash); //将上传的文件hash值放入map
|
|
|
- projectFileService.insertInformationIntoTable(mapToService); //将获取到的数据插入到各类表中
|
|
|
-
|
|
|
+ mapToService.put("url", "/content/"+filename);
|
|
|
+ mapToService.put("attachmentName", filename);
|
|
|
+ mapToService.put("hash", fileHash);
|
|
|
+ projectFileService.insertInformationIntoTable(mapToService);
|
|
|
//文件最后上传,防止出现垃圾数据
|
|
|
- file.transferTo(newFile); //文件已经上传成功
|
|
|
-
|
|
|
- Map<String, Object> mapResult = JSONUtil.getJsonMap(200, true, HintMSG.UPLOAD_SUCCESS,null); //返回给前端一个map进行前段提示
|
|
|
- return mapResult;
|
|
|
+ file.transferTo(newFile);
|
|
|
+ return JSONUtil.getJsonMap(200, true, HintMSG.UPLOAD_SUCCESS,null);
|
|
|
} catch (Exception e) {
|
|
|
- Map<String, Object> mapResult = JSONUtil.getJsonMap(500, true, HintMSG.UPLOAD_FAIL+":"+e.getMessage(),null); //返回给前端一个map进行前段提示
|
|
|
- return mapResult;
|
|
|
+ return JSONUtil.getJsonMap(500, false, HintMSG.UPLOAD_FAIL+":"+e.getMessage(),null);
|
|
|
}
|
|
|
}
|
|
|
|