5 anni fa
parent
commit
08ba88f9ed

+ 78 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldFileController.java

@@ -131,7 +131,7 @@ public class MouldFileController {
 
     /**
      * 文档批量下载列表
-     * 参数: token 用户身份凭证,projectId 项目id,pageSize ,pageNum
+     * 参数: token 用户身份凭证,pageSize ,pageNum
      *
      * @return
      */
@@ -157,5 +157,82 @@ public class MouldFileController {
         msg = mouldFileService.dowloadFileList(userVO);
         return msg;
     }
+
+//    @RequestMapping(value = "xxx/xxx",method = RequestMethod.POST)
+//    @ResponseBody
+//    public Map<String,Object> feedBackDirectMultiDownload(HttpServletRequest request,HttpServletResponse response) throws IOException{
+//        //压缩文件初始设置
+//        String path="压缩文件想要放置的路径";
+//        base_name = "zip文件名";
+//        fileZip = base_name + ".zip"; // 拼接zip文件
+//        filePath = path+"\\" + fileZip;//之后用来生成zip文件
+//
+//        //filePathArr为根据前台传过来的信息,通过数据库查询所得出的pdf文件路径集合(具体到后缀),此处省略
+//        files = new File[fileNameArr.size()];//
+//        for(int i=0;i<fileNameArr.size();i++){
+//            files[i]=new File(fileNameArr.get(i).get("filePath"));//获取所有需要下载的pdf
+//        }
+//
+//        // 创建临时压缩文件
+//        try {
+//            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
+//            ZipOutputStream zos = new ZipOutputStream(bos);
+//            ZipEntry ze = null;
+//            for (int i = 0; i < files.length; i++) {//将所有需要下载的pdf文件都写入临时zip文件
+//                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(files[i]));
+//                ze = new ZipEntry(files[i].getName());
+//                zos.putNextEntry(ze);
+//                int s = -1;
+//                while ((s = bis.read()) != -1) {
+//                    zos.write(s);
+//                }
+//                bis.close();
+//            }
+//            zos.flush();
+//            zos.close();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//        //以上,临时压缩文件创建完成
+//
+//        //进行浏览器下载
+//        //获得浏览器代理信息
+//        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");
+//            System.out.println("IE浏览器");
+//        }else if(StringUtils.contains(userAgent, "Mozilla")){//google,火狐浏览器
+//            finalFileName = new String(fileZip.getBytes(), "ISO8859-1");
+//        }else{
+//            finalFileName = URLEncoder.encode(fileZip,"UTF8");//其他浏览器
+//        }
+//        response.setContentType("application/x-download");//告知浏览器下载文件,而不是直接打开,浏览器默认为打开
+//        response.setHeader("Content-Disposition" ,"attachment;filename=\"" +finalFileName+ "\"");//下载文件的名称
+//
+//        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);//之后用来删除临时压缩文件
+//        try {
+//            while ((in.read(b)) != -1) {
+//                temps.write(b);
+//            }
+//            temps.flush();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }finally{
+//            if(temps!=null) temps.close();
+//            if(in!=null) in.close();
+//            if(reportZip!=null) reportZip.delete();//删除服务器本地产生的临时压缩文件
+//            servletOutputStream.close();
+//        }
+//        return null;
+//    }
 }
 

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldFileMapper.java

@@ -18,5 +18,5 @@ import java.util.List;
  */
 public interface MouldFileMapper extends BaseMapper<MouldFile> {
 
-    List<MouldFileVO> getFileListByProjectId(@Param("userVO") UserVO userVO);
+    List<MouldFileVO> getFileListByProjectId(@Param("userVO") UserVO userVO,@Param("list")List<Integer> proIds);
 }

+ 42 - 41
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -44,6 +44,10 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
     MouldOperationDynamicsMapper mouldOperationDynamicsMapper;
     @Resource
     ProjectMapper projectMapper;
+    @Resource
+    MouldMapper mouldMapper;
+    @Resource
+    ProjectUserMapper projectUserMapper;
 
     @Override
     public HttpRespMsg addFile(UserVO userVO, Integer blongType, MultipartFile file, MultipartFile file2, String path) {
@@ -239,11 +243,46 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
     @Override
     public HttpRespMsg getListByUserAndProjectId(UserVO userVO, PageUtil page) {
         HttpRespMsg msg = new HttpRespMsg();
+        List<Integer> proIds = new ArrayList<>();
+        proIds.add(-1);
+        List<MouldFileVO> list = new ArrayList<>();
         User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
+        PageHelper.startPage(page.getPageNum(), page.getPageSize());
         if (currentUser != null) {
-            PageHelper.startPage(page.getPageNum(), page.getPageSize());
-            List<MouldFileVO> list = mouldFileMapper.getFileListByProjectId(userVO);
-            PageInfo<MouldFileVO> pageInfos = new PageInfo<>(list);
+        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 = mouldFileMapper.getFileListByProjectId(userVO,proIds);
+        }
+        PageInfo<MouldFileVO> pageInfos = new PageInfo<>(list);
             msg.data = pageInfos;
         } else {
             msg.setError("用户不存在或者未登录");
@@ -253,44 +292,6 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
 
     @Override
     public HttpRespMsg dowloadFileList(UserVO userVO) {
-        byte[] buffer = new byte[1024];
-        Date date=new Date();
-////生成zip文件存放位置
-//        String strZipPath = Constant.exportAddress +loginname+date.getTime()+".zip";
-//        File file=new File(Constant.exportAddress);
-//        if(!file.isDirectory() && !file.exists()){
-////创建单层目录
-//// f.mkdir();
-//// 创建多层目录
-//            file.mkdirs();
-//        }
-//        try {
-//            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(strZipPath));
-//// 需要同时下载的多个文件
-//            for (int i = 0; i < filepath.length; i++) {
-//                File f=new File(filepath[i]);
-//                FileInputStream fis = new FileInputStream(f);
-//                System.out.println(documentname[i]);
-//                out.putNextEntry(new ZipEntry(documentname[i]));
-////设置压缩文件内的字符编码,不然会变成乱码
-//                out.setEncoding("GBK");
-//                int len;
-//// 读入需要下载的文件的内容,打包到zip文件
-//                while ((len = fis.read(buffer)) > 0) {
-//                    out.write(buffer, 0, len);
-//                }
-//                out.closeEntry();
-//                fis.close();
-//            }
-//            out.close();
-//            PublicMethod.downLoadFile(request, response, strZipPath, filename+".zip");
-//            File temp=new File(strZipPath);
-//            if(temp.exists()){
-//                temp.delete();
-//            }
-//        } catch (Exception e) {
-//            System.out.println("文件下载错误");
-//        }
         return null;
     }
 }

+ 9 - 2
cloud-model/src/main/resources/mapper/MouldFileMapper.xml

@@ -56,8 +56,15 @@
             id,model_no,model_name
         from
             tb_mould
-        where
-            project_id = #{userVO.projectId}
+        <where>
+            project_id in
+        <foreach collection="list" index="index" open="(" item="item" close=")" separator=",">
+            #{item}
+        </foreach>
+            <if test="userVO.keyName != null and userVO.keyName != ''">
+                and model_name like concat('%',#{userVO.keyName},'%')
+            </if>
+        </where>
     </select>
     <select id="querySparepart3DFilesByMouldId" resultMap="BaseResultMap">
         select