lxw
2022-09-01 b848451e8889fea12ce40b7818c1b8d84b50ea02
src/main/java/com/whyc/service/ProductBomService.java
@@ -165,7 +165,28 @@
            e.printStackTrace();
        }
    }
    //文件夹的拷贝
    public  void copyDir(String sourcePathDir, String newPathDir) {
        File start = new File(sourcePathDir);
        File end = new File(newPathDir);
        if(!start.exists()) {
            return;
        }
        String[] filePath = start.list();//获取该文件夹下的所有文件以及目录的名字
        if(!end.exists()) {
            end.mkdir();
        }
        if(filePath.length>=0){
            for(String temp : filePath) {
                //添加满足情况的条件
                if(new File(sourcePathDir + File.separator + temp ).isFile()) {
                    //为文件则进行拷贝
                    copyFile(new File(sourcePathDir + File.separator + temp ), newPathDir );
                }
            }
        }
    }
    public void updateUrl(List<ProductBomApproving> fileBomApprovingList) {
        mapper.updateUrl(fileBomApprovingList);
    }
@@ -191,14 +212,10 @@
    //产品下载(产品id和版本)
    public  void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version) {
        HSSFWorkbook wb = new HSSFWorkbook();
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        //读取产品信息
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("id",productId);
        wrapper.eq("version",version);
        wrapper.last("limit 1");
        Product product=productMapper.selectOne(wrapper);
        //读取产品的子件和关联的物料信息
@@ -215,8 +232,15 @@
                }
            }
        });
        //将没有管理BOM的dwg文件拷贝下载
        String withOutDwg="doc_file/product"+File.separator+product.getParentModel();
        if(product.getCustomCode()!=null&&!product.getCustomCode().isEmpty()){
            withOutDwg+=File.separator+product.getCustomCode()+File.separator+version;
        }else{
            withOutDwg+=File.separator+"standard"+File.separator+version;
        }
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,product,endList,wb,"bom");
        creatBomExcel(req,resp,product,endList,wb,"bom",withOutDwg);
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体产品信息为:"+product.toString();
@@ -227,10 +251,16 @@
    //根据产品信息创建excel表格并存放在指定目录
    private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String type){
    private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String type,String withOutDwg){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace="";
        String excelName="";
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        font.setColor(HSSFFont.COLOR_RED);
        cellStyle.setFont(font);
        //创建单个sheet
        HSSFSheet sheet = wb.createSheet("产品信息");
        sheet.setColumnWidth(1,5000);
@@ -273,6 +303,9 @@
        if(!destfile.exists()) {
            destfile.mkdir();
        }
        //将没有管理BOM的dwg文件拷贝下载
        withOutDwg=fileDirName+File.separator+withOutDwg;
        copyDir(withOutDwg,rootFace);
        //将选中的文件存入指定目录下打包下载
        if(list!=null&&list.size()>0){
            for (int i=0;i<list.size();i++) {
@@ -282,23 +315,23 @@
                    File sourceFile=new File(fileDirName+ File.separator+dwgUrl);
                    copyFile(sourceFile,rootFace);
                }
                rownum=rownum+i+1;
                Row row=sheet.createRow(rownum);
                sheet.getRow(rownum).createCell(1).setCellValue(i+1);
                sheet.getRow(rownum).createCell(2).setCellValue(product.getParentCode());
                sheet.getRow(rownum).createCell(3).setCellValue(product.getParentName());
                sheet.getRow(rownum).createCell(4).setCellValue(product.getParentModel());
                sheet.getRow(rownum).createCell(5).setCellValue(bom.getCategory());
                sheet.getRow(rownum).createCell(6).setCellValue(bom.getSubCode());
                sheet.getRow(rownum).createCell(7).setCellValue(bom.getSubName());
                sheet.getRow(rownum).createCell(8).setCellValue(bom.getSubModel());
                sheet.getRow(rownum).createCell(9).setCellValue(bom.getUnit()==null?"":bom.getUnit());
                sheet.getRow(rownum).createCell(10).setCellValue(bom.getQuantity());
                sheet.getRow(rownum).createCell(11).setCellValue(bom.getProducer()==null?"":bom.getProducer());
                sheet.getRow(rownum).createCell(12).setCellValue(bom.getMaterial());
                sheet.getRow(rownum).createCell(13).setCellValue(bom.getThickness());
                sheet.getRow(rownum).createCell(14).setCellValue(bom.getSurfaceDetail());
                sheet.getRow(rownum).createCell(15).setCellValue(bom.getNotes());
                Row row=sheet.createRow(rownum+i+1);
                row.setRowStyle(cellStyle);
                sheet.getRow(rownum+i+1).createCell(1).setCellValue(i+1);
                sheet.getRow(rownum+i+1).createCell(2).setCellValue(product.getParentCode());
                sheet.getRow(rownum+i+1).createCell(3).setCellValue(product.getParentName());
                sheet.getRow(rownum+i+1).createCell(4).setCellValue(product.getParentModel());
                sheet.getRow(rownum+i+1).createCell(5).setCellValue(bom.getCategory());
                sheet.getRow(rownum+i+1).createCell(6).setCellValue(bom.getSubCode());
                sheet.getRow(rownum+i+1).createCell(7).setCellValue(bom.getSubName());
                sheet.getRow(rownum+i+1).createCell(8).setCellValue(bom.getSubModel());
                sheet.getRow(rownum+i+1).createCell(9).setCellValue(bom.getUnit()==null?"":bom.getUnit());
                sheet.getRow(rownum+i+1).createCell(10).setCellValue(bom.getQuantity());
                sheet.getRow(rownum+i+1).createCell(11).setCellValue(bom.getProducer()==null?"":bom.getProducer());
                sheet.getRow(rownum+i+1).createCell(12).setCellValue(bom.getMaterial());
                sheet.getRow(rownum+i+1).createCell(13).setCellValue(bom.getThickness());
                sheet.getRow(rownum+i+1).createCell(14).setCellValue(bom.getSurfaceDetail());
                sheet.getRow(rownum+i+1).createCell(15).setCellValue(bom.getNotes());
                if((bom.getPictureUrl()!=null)&&(!bom.getPictureUrl().isEmpty())){
                    ByteArrayOutputStream byteArrayOut = null;
                    try {
@@ -306,7 +339,7 @@
                        BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(fileDirName+File.separator+bom.getPictureUrl())));
                        ImageIO.write(bufferImg, "png", byteArrayOut);
                        //anchor主要用于设置图片的属性
                        HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) 16, rownum, (short) 16, rownum);
                        HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) 16, rownum+i+1, (short) 16, rownum+i+1);
                        anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
                        //插入图片
                        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
@@ -368,12 +401,12 @@
        }
    }
    //查询所有产品中没有与指定散装件关联的子件
    public Response getAllSubWithOutMaterial(int MaterialId) {
        List<ProductBom> list=mapper.getAllSubWithOutMaterial(MaterialId);
    public Response getAllSubWithOutMaterial(int materialId) {
        List<ProductBom> list=mapper.getAllSubWithOutMaterial(materialId);
        return new Response().setII(1,list.size()>0?true:false,list,"返回数据");
    }
    /*//根据母料型号查询子件信息及有最新版本关联的散装件信息
    public Response getSubByMaterialProduct(String parentModel) {
   //根据母料型号查询子件信息及有最新版本关联的散装件信息
     /*public Response getSubByMaterialProduct(String parentModel) {
        List<ProductBom> list=mapper.getSubByMaterialProduct(parentModel);
        //查询出存在替换关系得散装件
        List<ProductBom> replaceBoms=cponentMapper.getReplaceMaterial(parentModel);
@@ -422,4 +455,20 @@
        bom.setCreateDate(m.getCreateDate());
        return  bom;
    }
    public void insertBatch(List<ProductBom> productBomList) {
        mapper.insertBatchSomeColumn(productBomList);
    }
    public List<ProductBom> getBomByProductId(Integer productId) {
        QueryWrapper<ProductBom> query = Wrappers.query();
        query.eq("product_id",productId);
        return mapper.selectList(query);
    }
    public void deleteByProductId(Integer productId) {
        UpdateWrapper<ProductBom> update = Wrappers.update();
        update.eq("product_id",productId);
        mapper.delete(update);
    }
}