|
@@ -55,6 +55,8 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
ProjectUserMapper projectUserMapper;
|
|
|
@Resource
|
|
|
ProjectApproveMapper projectApproveMapper;
|
|
|
+ @Resource
|
|
|
+ PartMapper partMapper;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg addFile(UserVO userVO, Integer blongType, MultipartFile file, MultipartFile file2, String path) {
|
|
@@ -132,7 +134,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
}
|
|
|
}
|
|
|
//零件文档时存上零件id
|
|
|
- if(blongType == 1 && null != userVO.getPartId()){
|
|
|
+ if (blongType == 1 && null != userVO.getPartId()) {
|
|
|
projectFile.setPartId(userVO.getPartId());
|
|
|
}
|
|
|
//上传零件文档和上传模具文档的时候需要区分是否为2D或者3D
|
|
@@ -260,47 +262,47 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
if (currentUser != null) {
|
|
|
- if (Constant.SYS_ID == currentUser.getParentId()) {
|
|
|
- //此时是admin,查询他所创建的项目
|
|
|
- QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
- List<Project> projects = projectMapper.selectList(qw.eq("creator_id", currentUser.getId()));
|
|
|
- for (Project pro : projects) {
|
|
|
- proIds.add(pro.getId());
|
|
|
- }
|
|
|
- list = mouldFileMapper.getFileListByProjectId(userVO,proIds);
|
|
|
- } else if (Constant.SYS_PARENT_ID == currentUser.getParentId()) {
|
|
|
- //系统管理员
|
|
|
- List<Project> projects = projectMapper.selectList(new QueryWrapper<Project>());
|
|
|
- for (Project pro : projects) {
|
|
|
- proIds.add(pro.getId());
|
|
|
- }
|
|
|
- list = mouldFileMapper.getFileListByProjectId(userVO,proIds);
|
|
|
- } else {
|
|
|
- QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
- qw.eq("manager_id", userVO.getId());
|
|
|
- List<Project> projects = projectMapper.selectList(qw);
|
|
|
- if (projects.size() > 0) {
|
|
|
- for (Project project : projects) {
|
|
|
- proIds.add(project.getId());
|
|
|
+ if (Constant.SYS_ID == currentUser.getParentId()) {
|
|
|
+ //此时是admin,查询他所创建的项目
|
|
|
+ QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
+ List<Project> projects = projectMapper.selectList(qw.eq("creator_id", currentUser.getId()));
|
|
|
+ for (Project pro : projects) {
|
|
|
+ proIds.add(pro.getId());
|
|
|
+ }
|
|
|
+ list = mouldFileMapper.getFileListByProjectId(userVO, proIds);
|
|
|
+ } else if (Constant.SYS_PARENT_ID == currentUser.getParentId()) {
|
|
|
+ //系统管理员
|
|
|
+ List<Project> projects = projectMapper.selectList(new QueryWrapper<Project>());
|
|
|
+ for (Project pro : projects) {
|
|
|
+ proIds.add(pro.getId());
|
|
|
+ }
|
|
|
+ list = mouldFileMapper.getFileListByProjectId(userVO, proIds);
|
|
|
+ } else {
|
|
|
+ QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("manager_id", userVO.getId());
|
|
|
+ List<Project> projects = projectMapper.selectList(qw);
|
|
|
+ if (projects.size() > 0) {
|
|
|
+ for (Project project : projects) {
|
|
|
+ proIds.add(project.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
// //充当普通人员参与的项目
|
|
|
- List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id", userVO.getId()));
|
|
|
- if (projectUsers.size() > 0) {
|
|
|
- for (ProjectUser projectUser : projectUsers) {
|
|
|
- proIds.add(projectUser.getProjectId());
|
|
|
+ List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id", userVO.getId()));
|
|
|
+ if (projectUsers.size() > 0) {
|
|
|
+ for (ProjectUser projectUser : projectUsers) {
|
|
|
+ proIds.add(projectUser.getProjectId());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //充当审批人员参与的项目
|
|
|
- List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", userVO.getId()));
|
|
|
- if (projectss.size() > 0) {
|
|
|
- for (ProjectApprove projectUser : projectss) {
|
|
|
- proIds.add(projectUser.getProjectId());
|
|
|
+ //充当审批人员参与的项目
|
|
|
+ List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", userVO.getId()));
|
|
|
+ if (projectss.size() > 0) {
|
|
|
+ for (ProjectApprove projectUser : projectss) {
|
|
|
+ proIds.add(projectUser.getProjectId());
|
|
|
+ }
|
|
|
}
|
|
|
+ list = mouldFileMapper.getFileListByProjectId(userVO, proIds);
|
|
|
}
|
|
|
- list = mouldFileMapper.getFileListByProjectId(userVO,proIds);
|
|
|
- }
|
|
|
- PageInfo<MouldFileVO> pageInfos = new PageInfo<>(list);
|
|
|
+ PageInfo<MouldFileVO> pageInfos = new PageInfo<>(list);
|
|
|
msg.data = pageInfos;
|
|
|
} else {
|
|
|
msg.setError("用户不存在或者未登录");
|
|
@@ -309,30 +311,102 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg dowloadFileList(UserVO userVO, HttpServletRequest request, HttpServletResponse response,String downloadPath) throws IOException {
|
|
|
+ public HttpRespMsg dowloadFileList(UserVO userVO, HttpServletRequest request, HttpServletResponse response, String downloadPath) throws IOException {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- if(null != userVO.getIds()){
|
|
|
+ if (null != userVO.getIds()) {
|
|
|
List<Integer> ids = ListUtil.convertIntegerIdsArrayToList(userVO.getIds());
|
|
|
for (Integer id : ids) {
|
|
|
Mould mould = mouldMapper.selectById(id);
|
|
|
- List<MouldFile> mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state",3));
|
|
|
- feedBackDirectMultiDownload(request,response,downloadPath,mould,mouldFiles);
|
|
|
+ List<MouldFile> mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3));
|
|
|
+ feedBackDirectMultiDownload(request, response, downloadPath, mould, mouldFiles);
|
|
|
}
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
- public Map<String,Object> feedBackDirectMultiDownload(HttpServletRequest request, HttpServletResponse response,String downloadPath,Mould vo,List<MouldFile> mouldFiles) throws IOException {
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg addPartFile(UserVO userVO, String path, MultipartFile[] files) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+// User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
+// if (user != null) {
|
|
|
+// List<Part> partLists = partMapper.selectList(new QueryWrapper<Part>().eq("mould_id", userVO.getMouldId()));
|
|
|
+// if (files.length > 0) {
|
|
|
+// for (MultipartFile file : files) {
|
|
|
+// MouldFile partFile = new MouldFile();
|
|
|
+// partFile.setModelId(userVO.getMouldId());
|
|
|
+// partFile.setBlongType(1);
|
|
|
+// partFile.setUploaderId(user.getId());
|
|
|
+// projectFile.setUploader(user.getUsername());
|
|
|
+// projectFile.setProjectId(userVO.getProjectId());
|
|
|
+// File dir = null;
|
|
|
+// dir = new File(path);
|
|
|
+// // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+// if (!dir.exists()) {
|
|
|
+// dir.mkdirs();
|
|
|
+// }
|
|
|
+// String fileName = "";
|
|
|
+// if (file != null && !file.isEmpty()) {
|
|
|
+// fileName = file.getOriginalFilename();
|
|
|
+// String fileNamePrex = fileName.substring(0,fileName.lastIndexOf("."));
|
|
|
+// String[] split = fileNamePrex.split("\\+");
|
|
|
+// for (Part part : partLists) {
|
|
|
+// if(split[0] == part.getPartNo()) {
|
|
|
+// partFile.setPartId(part.getId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// projectFile.setFileName(fileName);
|
|
|
+// projectFile.setFileSize(FileUtil.getReadableFileSize(file.getSize()));
|
|
|
+// System.out.println("上传文件名称" + file.getName() + ", dir = " + dir.getAbsolutePath());
|
|
|
+// int pos = fileName.lastIndexOf(".");
|
|
|
+// String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+// String sufix = fileName.substring(pos);
|
|
|
+// fileName = rand + sufix;
|
|
|
+// projectFile.setFileType(sufix);//文件后缀
|
|
|
+// projectFile.setUrl("/upload/"+fileName);
|
|
|
+// File saveFile = new File(dir, fileName);
|
|
|
+// projectFileMapper.insert(projectFile);
|
|
|
+// try {
|
|
|
+// saveFile.createNewFile();
|
|
|
+// file.transferTo(saveFile);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// projectFile = null;
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// projectFile = null;
|
|
|
+// }
|
|
|
+// //添加上传记录
|
|
|
+// ProjectOperationDynamics dynamics = new ProjectOperationDynamics();
|
|
|
+// dynamics.setContent(Constant.UPLOAD);
|
|
|
+// dynamics.setFileName(file.getOriginalFilename());
|
|
|
+// dynamics.setOperatorId(user.getId());
|
|
|
+// dynamics.setOperator(user.getUsername());
|
|
|
+// dynamics.setProjectId(userVO.getProjectId());
|
|
|
+// projectOperationDynamicsMapper.insert(dynamics);
|
|
|
+// }
|
|
|
+// msg.data = projectFile;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// msg.setError("上传文件不可为空");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// msg.setError("用户不存在或者未登录");
|
|
|
+// }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> feedBackDirectMultiDownload(HttpServletRequest request, HttpServletResponse response, String downloadPath, Mould vo, List<MouldFile> mouldFiles) throws IOException {
|
|
|
//压缩文件初始设置
|
|
|
- String path= downloadPath;
|
|
|
- String base_name = vo.getModelNo()+vo.getModelName();
|
|
|
+ String path = downloadPath;
|
|
|
+ String base_name = vo.getModelNo() + vo.getModelName();
|
|
|
String fileZip = base_name + ".zip"; // 拼接zip文件
|
|
|
- String filePath = path+"\\" + fileZip;//之后用来生成zip文件
|
|
|
+ String filePath = path + "\\" + fileZip;//之后用来生成zip文件
|
|
|
|
|
|
//mouldFiles为根据前台传过来的信息,通过数据库查询所得出的pdf文件路径集合(具体到后缀),此处省略
|
|
|
File[] files = new File[mouldFiles.size()];//
|
|
|
- for(int i=0;i<mouldFiles.size();i++){
|
|
|
- files[i]=new File(mouldFiles.get(i).getFileUrl());//获取所有需要下载的pdf
|
|
|
+ for (int i = 0; i < mouldFiles.size(); i++) {
|
|
|
+ files[i] = new File(mouldFiles.get(i).getFileUrl());//获取所有需要下载的pdf
|
|
|
}
|
|
|
|
|
|
// 创建临时压缩文件
|
|
@@ -361,24 +435,24 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
final String userAgent = request.getHeader("USER-AGENT");
|
|
|
//判断浏览器代理并分别设置响应给浏览器的编码格式
|
|
|
String finalFileName = null;
|
|
|
- if(StringUtils.contains(userAgent, "MSIE")||StringUtils.contains(userAgent,"Trident")){//IE浏览器
|
|
|
- finalFileName = URLEncoder.encode(fileZip,"UTF8");
|
|
|
+ if (StringUtils.contains(userAgent, "MSIE") || StringUtils.contains(userAgent, "Trident")) {//IE浏览器
|
|
|
+ finalFileName = URLEncoder.encode(fileZip, "UTF8");
|
|
|
System.out.println("IE浏览器");
|
|
|
- }else if(StringUtils.contains(userAgent, "Mozilla")){//google,火狐浏览器
|
|
|
+ } else if (StringUtils.contains(userAgent, "Mozilla")) {//google,火狐浏览器
|
|
|
finalFileName = new String(fileZip.getBytes(), "ISO8859-1");
|
|
|
- }else{
|
|
|
- finalFileName = URLEncoder.encode(fileZip,"UTF8");//其他浏览器
|
|
|
+ } else {
|
|
|
+ finalFileName = URLEncoder.encode(fileZip, "UTF8");//其他浏览器
|
|
|
}
|
|
|
response.setContentType("application/x-download");//告知浏览器下载文件,而不是直接打开,浏览器默认为打开
|
|
|
- response.setHeader("Content-Disposition" ,"attachment;filename=\"" +finalFileName+ "\"");//下载文件的名称
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=\"" + finalFileName + "\"");//下载文件的名称
|
|
|
|
|
|
- ServletOutputStream servletOutputStream=response.getOutputStream();
|
|
|
+ ServletOutputStream servletOutputStream = response.getOutputStream();
|
|
|
DataOutputStream temps = new DataOutputStream(
|
|
|
servletOutputStream);
|
|
|
|
|
|
DataInputStream in = new DataInputStream(new FileInputStream(filePath));//浏览器下载文件的路径
|
|
|
byte[] b = new byte[2048];
|
|
|
- File reportZip=new File(filePath);//之后用来删除临时压缩文件
|
|
|
+ File reportZip = new File(filePath);//之后用来删除临时压缩文件
|
|
|
try {
|
|
|
while ((in.read(b)) != -1) {
|
|
|
temps.write(b);
|
|
@@ -386,10 +460,10 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
temps.flush();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }finally{
|
|
|
- if(temps!=null) temps.close();
|
|
|
- if(in!=null) in.close();
|
|
|
- if(reportZip!=null) reportZip.delete();//删除服务器本地产生的临时压缩文件
|
|
|
+ } finally {
|
|
|
+ if (temps != null) temps.close();
|
|
|
+ if (in != null) in.close();
|
|
|
+ if (reportZip != null) reportZip.delete();//删除服务器本地产生的临时压缩文件
|
|
|
servletOutputStream.close();
|
|
|
}
|
|
|
return null;
|