| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | |
| | | //读取产品信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("id",productId); |
| | | wrapper.eq("version",version); |
| | | wrapper.last("limit 1"); |
| | | Product product=productMapper.selectOne(wrapper); |
| | | //读取产品的子件和关联的物料信息 |
| | | List<ProductBom> list=mapper.getBomAndMaterial(productId,version); |
| | | //处理 |
| | | //处理存在关联关系的物料 |
| | | List<ProductBom> endList=new ArrayList<>(); |
| | | list.stream().forEach(bom -> { |
| | | endList.add(bom); |
| | | if(bom.getMaterials()!=null&&bom.getMaterials().size()>0){ |
| | | for (Material m:bom.getMaterials()) { |
| | | //将物料存放为一个bom为下载做准备 |
| | | ProductBom copyBom=copyMaterialToBom(m); |
| | | endList.add(copyBom); |
| | | } |
| | | } |
| | | }); |
| | | //生成excel并将dwg文件放在同一报下压缩 |
| | | creatBomExcel(req,resp,product,list,wb,"bom"); |
| | | creatBomExcel(req,resp,product,endList,wb,"bom"); |
| | | //记录日志 |
| | | DocUser docUser= ActionUtil.getUser(); |
| | | String operationDetail="具体产品信息为:"+product.toString(); |
| | |
| | | String terminalIp=req.getRemoteAddr(); |
| | | logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); |
| | | } |
| | | |
| | | |
| | | //根据产品信息创建excel表格并存放在指定目录 |
| | | public 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 fileDirName = FileDirPath.getFileDirName(); |
| | | String rootFace=""; |
| | | String excelName=""; |
| | |
| | | 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); |
| | | 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 { |
| | |
| | | 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)); |
| | |
| | | } |
| | | } |
| | | //查询所有产品中没有与指定散装件关联的子件 |
| | | 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); |
| | |
| | | List<ProductBom> list=mapper.getBomAndMaterial(productId,version); |
| | | return new Response().setII(1,list.size()>0?true:false,list,"返回物料信息及关联物料"); |
| | | } |
| | | |
| | | //将物料存放为一个bom为下载做准备 |
| | | private ProductBom copyMaterialToBom(Material m) { |
| | | ProductBom bom=new ProductBom(); |
| | | bom.setType(m.getType()); |
| | | 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.setPictureUrl(m.getPictureUrl()); |
| | | bom.setDwgUrl(m.getDwgUrl()); |
| | | bom.setFileUrl(m.getFileUrl()); |
| | | 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); |
| | | } |
| | | |
| | | } |