| | |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ZipUtils; |
| | | import com.whyc.mapper.AttachLockMapper; |
| | | import com.whyc.mapper.MaterialMapper; |
| | | import com.whyc.mapper.ProductBomMapper; |
| | | import com.whyc.mapper.ProductMapper; |
| | |
| | | import com.whyc.util.ActionUtil; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | 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; |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private ProductMapper productMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private AttachLockMapper attachLockMapper; |
| | | |
| | | @Autowired |
| | | private DocLogService logService; |
| | |
| | | } |
| | | |
| | | } |
| | | //文件夹的拷贝移除productId对应的被锁定的 |
| | | public void copyDirWithOutProductId(String sourcePathDir, String newPathDir,int productId) { |
| | | 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()) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("product_id",productId); |
| | | wrapper.eq("attach_name",temp); |
| | | wrapper.eq("lock_flag",1); |
| | | wrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(wrapper); |
| | | if(attachLock==null){ |
| | | //为文件则进行拷贝 |
| | | copyFile(new File(sourcePathDir + File.separator + temp ), newPathDir ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | public void updateUrl(List<ProductBomApproving> fileBomApprovingList) { |
| | | mapper.updateUrl(fileBomApprovingList); |
| | | } |
| | |
| | | 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(); |
| | |
| | | List<ProductBom> endList=new ArrayList<>(); |
| | | list.stream().forEach(bom -> { |
| | | bom.setConnFlag(0); |
| | | if(bom.getDwgUrl()!=null){ |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("material_id",bom.getMaterialId()); |
| | | qwrapper.eq("attach_name",bom.getDwgUrl().substring(bom.getDwgUrl().lastIndexOf("\\")+1)); |
| | | qwrapper.eq("lock_flag",1); |
| | | qwrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(qwrapper); |
| | | if(attachLock!=null){ |
| | | bom.setDwgUrl(""); |
| | | } |
| | | } |
| | | endList.add(bom); |
| | | if(bom.getMaterials()!=null&&bom.getMaterials().size()>0){ |
| | | for (Material m:bom.getMaterials()) { |
| | |
| | | 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=""; |
| | |
| | | ,"基本单位","子件数量","生产商","封装类型/材质","元件编号/料厚","表面处理/物料详情","备注","图片"}; |
| | | //字体格式-加粗 |
| | | HSSFCellStyle cellStyle = wb.createCellStyle(); |
| | | cellStyle.setFillForegroundColor(IndexedColors.GOLD.getIndex());//添加前景色,内容看的清楚 |
| | | cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); |
| | | HSSFFont font = wb.createFont(); |
| | | font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
| | | font.setColor(HSSFFont.COLOR_RED); |
| | | //font.setColor(HSSFFont.COLOR_RED); |
| | | cellStyle.setFont(font); |
| | | //创建单个sheet |
| | | HSSFSheet sheet = wb.createSheet("产品信息"); |
| | |
| | | } |
| | | //将没有管理BOM的dwg文件拷贝下载 |
| | | withOutDwg=fileDirName+File.separator+withOutDwg; |
| | | copyDir(withOutDwg,rootFace); |
| | | copyDirWithOutProductId(withOutDwg,rootFace,product.getId()); |
| | | //将选中的文件存入指定目录下打包下载 |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | |
| | | 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+i+1, (short) 16, rownum+i+1); |
| | | HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) 16, rownum, (short) 16, rownum); |
| | | anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE); |
| | | //插入图片 |
| | | patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG)); |
| | |
| | | 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; |
| | |
| | | } 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) { |
| | |
| | | //根据产品id查询子件及其关联的物料信息 |
| | | public Response getBomAndMaterial(int productId,int version) { |
| | | List<ProductBom> list=mapper.getBomAndMaterial(productId,version); |
| | | if(list!=null&&list.size()>0){ |
| | | list.stream().forEach(bom -> { |
| | | if(bom.getDwgUrl()!=null){ |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("material_id",bom.getMaterialId()); |
| | | wrapper.eq("attach_name",bom.getDwgUrl().substring(bom.getDwgUrl().lastIndexOf("\\")+1)); |
| | | wrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(wrapper); |
| | | if(attachLock!=null){ |
| | | bom.setDwgUrl(""); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return new Response().setII(1,list.size()>0,list,"返回物料信息及关联物料"); |
| | | } |
| | | |
| | |
| | | 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()); |
| | |
| | | public List<ProductBom> getEnabledBomListByParentCodeAndCustomCode(String parentCode, String customCode) { |
| | | return mapper.getEnabledBomListByParentCodeAndCustomCode(parentCode,customCode); |
| | | } |
| | | |
| | | public void updateMaterialField2Bom() { |
| | | List<ProductBom> bomList = mapper.selectListWithMaterialField(); |
| | | mapper.updateMaterialField2BomBatch(bomList); |
| | | } |
| | | } |