lxw
2022-07-23 5861a692475b673389014dcd6073632f704ad004
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.FileDirPath;
import com.whyc.dto.Response;
import com.whyc.dto.ZipUtils;
import com.whyc.mapper.ProductBomMapper;
import com.whyc.pojo.ProductBom;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.List;
 
@Service
public class ProductBomService {
 
    @Autowired(required = false)
    private ProductBomMapper mapper;
    //图纸分类检索
    public Response searchCadDrawer(ProductBom productBom,int pageCurr,int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        List list=mapper.searchCadDrawer(productBom);
        PageInfo pageInfo=new PageInfo(list);
        return  new Response().setII(1,list.size()>0?true:false,pageInfo,"数据返回");
    }
    //图纸文件下载
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp) {
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace=fileDirName+ File.separator+"face";
        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();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //根据子件code获取最终的信息
    public Response getBomBySubcode(String scode) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("sub_code",scode);
        List list=mapper.selectList(wrapper);
        return new Response().setII(1,list.size()>0?true:false,list,"返回数据");
    }
}