|
@@ -2,11 +2,13 @@ package com.hssx.cloudmodel.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.hssx.cloudmodel.constant.Constant;
|
|
|
+import com.hssx.cloudmodel.entity.Project;
|
|
|
import com.hssx.cloudmodel.entity.ProjectFile;
|
|
|
import com.hssx.cloudmodel.entity.ProjectOperationDynamics;
|
|
|
import com.hssx.cloudmodel.entity.User;
|
|
|
import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
import com.hssx.cloudmodel.mapper.ProjectFileMapper;
|
|
|
+import com.hssx.cloudmodel.mapper.ProjectMapper;
|
|
|
import com.hssx.cloudmodel.mapper.ProjectOperationDynamicsMapper;
|
|
|
import com.hssx.cloudmodel.mapper.UserMapper;
|
|
|
import com.hssx.cloudmodel.service.ProjectFileService;
|
|
@@ -42,6 +44,8 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
ProjectFileMapper projectFileMapper;
|
|
|
@Resource
|
|
|
ProjectOperationDynamicsMapper projectOperationDynamicsMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectMapper projectMapper;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path) {
|
|
@@ -118,7 +122,6 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
}
|
|
|
|
|
|
public void downloadLocal(HttpServletResponse response, String downLoadpath, ProjectFile file, String path) throws FileNotFoundException, UnsupportedEncodingException {
|
|
|
- System.out.println("123123");
|
|
|
// // 下载本地文件
|
|
|
// String fileName = file.getFileName().toString(); // 文件的默认保存名
|
|
|
// // 读到流中
|
|
@@ -147,62 +150,62 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
|
|
|
|
|
|
// public static void downloadFile (HttpServletResponse response, String fileName, String path){
|
|
|
- //下载本地文件
|
|
|
- String fileName = file.getFileName().toString(); // 文件的默认保存名
|
|
|
- // 读到流中
|
|
|
- File dir = null;
|
|
|
- dir = new File(downLoadpath);
|
|
|
- // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
- }
|
|
|
- if (fileName != null) {
|
|
|
- //设置文件路径
|
|
|
- File file1 = new File(path.substring(0, path.length() - "/upload/".length()) + file.getUrl());
|
|
|
- if (file1.exists()) {
|
|
|
- response.setHeader("content-type", "application/octet-stream");
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
- try {
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1"));
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ //下载本地文件
|
|
|
+ String fileName = file.getFileName().toString(); // 文件的默认保存名
|
|
|
+ // 读到流中
|
|
|
+ File dir = null;
|
|
|
+ dir = new File(downLoadpath);
|
|
|
+ // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ if (fileName != null) {
|
|
|
+ //设置文件路径
|
|
|
+ File file1 = new File(path.substring(0, path.length() - "/upload/".length()) + file.getUrl());
|
|
|
+ if (file1.exists()) {
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ try {
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1"));
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ FileInputStream fis = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ try {
|
|
|
+ fis = new FileInputStream(file1);
|
|
|
+ bis = new BufferedInputStream(fis);
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ int i = bis.read(buffer);
|
|
|
+ while (i != -1) {
|
|
|
+ os.write(buffer, 0, i);
|
|
|
+ i = bis.read(buffer);
|
|
|
}
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- FileInputStream fis = null;
|
|
|
- BufferedInputStream bis = null;
|
|
|
- try {
|
|
|
- fis = new FileInputStream(file1);
|
|
|
- bis = new BufferedInputStream(fis);
|
|
|
- OutputStream os = response.getOutputStream();
|
|
|
- int i = bis.read(buffer);
|
|
|
- while (i != -1) {
|
|
|
- os.write(buffer, 0, i);
|
|
|
- i = bis.read(buffer);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (bis != null) {
|
|
|
+ try {
|
|
|
+ bis.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (bis != null) {
|
|
|
- try {
|
|
|
- bis.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- if (fis != null) {
|
|
|
- try {
|
|
|
- fis.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (fis != null) {
|
|
|
+ try {
|
|
|
+ fis.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getFileList(UserVO userVO,String path) {
|
|
|
+ public HttpRespMsg getFileList(UserVO userVO, String path) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
List<ProjectFile> list = projectFileMapper.selectList(new QueryWrapper<ProjectFile>().eq("project_id", userVO.getProjectId()).orderByDesc("id"));
|
|
@@ -214,9 +217,21 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg delFile(ProjectFile projectFile) {
|
|
|
+ public HttpRespMsg delFile(ProjectFile projectFile, String token) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- msg.data = projectFileMapper.deleteById(projectFile.getId());
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
+ Project project = projectMapper.selectById(projectFileMapper.selectById(projectFile.getId()).getProjectId());
|
|
|
+ if (user == null) {
|
|
|
+ msg.setError("当前用户不存在或者未登录");
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ if((Constant.SYS_ID == user.getParentId() && user.getSubordinateType()==0)||project.getManagerId().equals(user.getId())){
|
|
|
+ msg.data = projectFileMapper.deleteById(projectFile.getId());
|
|
|
+ }else{
|
|
|
+ msg.setError("当前用户不存在或者未登录");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
return msg;
|
|
|
}
|
|
|
}
|