lxw
2022-08-13 1af35600ad339dabb4ae31acd7e6e882efffd189
图纸打包下载
2个文件已修改
56 ■■■■ 已修改文件
src/main/java/com/whyc/controller/ProductBomController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomService.java 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ProductBomController.java
@@ -36,8 +36,8 @@
    @ApiOperation("图纸文件打包下载")
    @PostMapping("downloadCadDrawer")
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp,@RequestBody ArrayList<String> pictureUrls){
        service.downloadCadDrawer(req,resp,pictureUrls);
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp,@RequestBody List<ProductBom> boms){
        service.downloadCadDrawer(req,resp,boms);
    }
    @ApiOperation(value = "根据子件code获取最终的信息")
    @GetMapping("getBomBySubcode")
src/main/java/com/whyc/service/ProductBomService.java
@@ -50,48 +50,18 @@
        return  new Response().setII(1,list.size()>0?true:false,pageInfo,"数据返回");
    }
    //图纸文件下载
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, ArrayList<String> pictureUrls) {
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace=fileDirName+ File.separator+"downLoad";
        String pictureName="";
        //将选中的文件存入指定目录下打包下载
        if(pictureUrls!=null&&pictureUrls.size()>0){
            for (int i=0;i<pictureUrls.size();i++) {
                String picUrl=pictureUrls.get(i);
                pictureName+=picUrl.substring(picUrl.lastIndexOf("\\")+1)+",";
                File sourceFile=new File(fileDirName+ File.separator+picUrl);
                copyFile(sourceFile,rootFace);
            }
        }
        String timeStr= ActionUtil.sdfwithFTP.format(new Date());
        try {
            File file=new File(rootFace+".zip");
            FileOutputStream forootFace = new FileOutputStream(file);
            ZipUtils.toZip(rootFace, forootFace,true);
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(timeStr.getBytes("UTF-8"), "ISO8859-1")
                    + ".zip");
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(rootFace+".zip");
            int len=0;
            byte[] buffer =new byte[1024];
            //7. 将缓冲区中的数据输出
            while ((len=in.read(buffer))>0){
                out.write(buffer,0,len);
            }
            in.close();
            out.close();
            file.delete();//删除压缩文件
            ZipUtils.delDir(rootFace);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, List<ProductBom> boms) {
        HSSFWorkbook wb = new HSSFWorkbook();
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,boms,wb);
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体图纸为:"+pictureName.substring(0,pictureName.lastIndexOf(","));
        String operationDetail="具体图纸为数量:"+boms.size();
        String opreationMsg="执行了文件打包下载操作";
        String terminalIp=req.getRemoteAddr();
        logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
@@ -247,7 +217,6 @@
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List list, HSSFWorkbook wb){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace="";
        String pictureName="";
        String excelName="";
        //创建单个sheet
        HSSFSheet sheet = wb.createSheet("bom信息");
@@ -295,7 +264,6 @@
                    }
                }
                if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){
                    pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+",";
                    File sourceFile=new File(fileDirName+ File.separator+dwgUrl);
                    copyFile(sourceFile,rootFace);
                }