whyclxw
4 天以前 10c3d3300cce0ccef45b9db8865b61999385158b
src/main/java/com/whyc/service/ProductBomService.java
@@ -21,12 +21,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
@@ -191,7 +193,7 @@
        }
    }
    //文件夹的拷贝移除productId对应的多送项
    //文件夹的拷贝移除productId对应的被锁定的
    public  void copyDirWithOutProductId(String sourcePathDir, String newPathDir,int productId) {
        File start = new File(sourcePathDir);
        File end = new File(newPathDir);
@@ -219,7 +221,6 @@
                }
            }
        }
    }
    public void updateUrl(List<ProductBomApproving> fileBomApprovingList) {
        mapper.updateUrl(fileBomApprovingList);
@@ -244,7 +245,8 @@
        return new Response().setII(1,list!=null,pageInfo,"返回数据");
    }*/
    //产品下载(产品id和版本)
    public  void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version) {
    public  void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version
       , @RequestParam String oprateReason, @RequestParam String oprateInfo) {
        HSSFWorkbook wb = new HSSFWorkbook();
        //读取产品信息
        QueryWrapper wrapper=new QueryWrapper();
@@ -286,18 +288,13 @@
            withOutDwg+=File.separator+"standard"+File.separator+version;
        }
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,product,endList,wb,withOutDwg);
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体产品信息为:"+product.toString();
        String opreationMsg="执行了最新版产品下载操作";
        String terminalIp=req.getRemoteAddr();
        logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
        creatBomExcel(req,resp,product,endList,wb,withOutDwg,ActionUtil.sdfwithALL.format(product.getVersionTime()),oprateReason,oprateInfo);
    }
    //根据产品信息创建excel表格并存放在指定目录
    private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String withOutDwg){
    private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String withOutDwg
            , String oprateVersion, @RequestParam String oprateReason, @RequestParam String oprateInfo){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace="";
        String excelName="";
@@ -487,9 +484,10 @@
            ZipUtils.toZip(rootFace, forootFace,true);
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
            /*resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".zip");
                    + ".zip");*/
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (excelName+".zip", "utf-8"));
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(rootFace+".zip");
            int len=0;
@@ -507,6 +505,9 @@
        } catch (IOException e) {
            e.printStackTrace();
        }
        //记录日志
        logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD_PRODUCT.getType(),new Date(),req.getRemoteAddr()
                ,excelName+".zip",rootFace+".zip",oprateReason,oprateInfo,oprateVersion);
    }
    //查询所有产品中没有与指定散装件关联的子件
    public Response getAllSubWithOutMaterial(int materialId) {
@@ -560,17 +561,17 @@
    private ProductBom copyMaterialToBom(Material m) {
        ProductBom bom=new ProductBom();
        bom.setType(m.getType());
        bom.setCategory(m.getCategory());
        //bom.setCategory(m.getCategory());
        bom.setSubCode(m.getSubCode());
        bom.setSubName(m.getSubName());
        bom.setSubModel(m.getSubModel());
        bom.setUnit(m.getUnit());
        //bom.setQuantity(m.getQuantity());
        bom.setProducer(m.getProducer());
        bom.setMaterial(m.getMaterial());
        bom.setThickness(m.getThickness());
        bom.setSurfaceDetail(m.getSurfaceDetail());
        bom.setNotes(m.getNotes());
        //bom.setProducer(m.getProducer());
        //bom.setMaterial(m.getMaterial());
        //bom.setThickness(m.getThickness());
        //bom.setSurfaceDetail(m.getSurfaceDetail());
        //bom.setNotes(m.getNotes());
        bom.setPictureUrl(m.getPictureUrl());
        bom.setDwgUrl(m.getDwgUrl());
        bom.setFileUrl(m.getFileUrl());
@@ -603,4 +604,8 @@
        return mapper.getEnabledBomListByParentCodeAndCustomCode(parentCode,customCode);
    }
    public void updateMaterialField2Bom() {
        List<ProductBom> bomList = mapper.selectListWithMaterialField();
        mapper.updateMaterialField2BomBatch(bomList);
    }
}