| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | fIleSilkLock.setAttachLocks(attachLocks); |
| | | return new Response().setIIII(1,list.size()>0,list,listsoft,fIleSilkLock,"返回物料信息及关联物料"); |
| | | } |
| | | //历史产品信息查看(产品中有0120开头的物料其实是产品,查看产品信息) |
| | | public Response getBomHistoryAndMaterial_0120(String parentCode, String parentName, String parentModel) { |
| | | |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_code",parentCode); |
| | | wrapper.eq("parent_name",parentName); |
| | | wrapper.eq("parent_model",parentModel); |
| | | wrapper.eq("enabled",1); |
| | | wrapper.last("limit 1"); |
| | | ProductHistory pHistory=pHistoryMapper.selectOne(wrapper); |
| | | int productId =pHistory.getId(); |
| | | int version = pHistory.getVersion(); |
| | | List<ProductBomHistory> list=mapper.getBomHistoryAndMaterial(productId,pHistory.getSubVersionMax()); |
| | | if(list!=null&&list.size()>0){ |
| | | list.stream().forEach(bomH -> { |
| | | if(bomH.getDwgUrl()!=null){ |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("material_id",bomH.getMaterialId()); |
| | | qwrapper.eq("attach_name",bomH.getDwgUrl().substring(bomH.getDwgUrl().lastIndexOf("\\")+1)); |
| | | qwrapper.eq("lock_flag",1); |
| | | qwrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(qwrapper); |
| | | if(attachLock!=null){ |
| | | bomH.setDwgUrl(""); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | //查询产品的软件 |
| | | List<Software> listsoft=mapper.selectSoftware(pHistory.getParentCode()); |
| | | //将没有管理BOM的dwg文件 |
| | | String withOutDwg="doc_file/product"+File.separator+pHistory.getParentModel(); |
| | | if(pHistory.getCustomCode()!=null&&!pHistory.getCustomCode().isEmpty()){ |
| | | withOutDwg+=File.separator+pHistory.getCustomCode()+File.separator+version; |
| | | }else{ |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | //将没有管理BOM的dwg文件(丝印)拷贝下载 |
| | | fileDirName=fileDirName+File.separator+withOutDwg; |
| | | File start = new File(fileDirName); |
| | | FIleSilkLock fIleSilkLock=new FIleSilkLock(); |
| | | String[] files =new String[]{}; |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int i=0;i<files.length;i++) { |
| | | files[i]=withOutDwg+File.separator+files[i]; |
| | | fIleSilkLock.setFiles(files); |
| | | } |
| | | } |
| | | } |
| | | List<AttachLock> attachLocks=mapper.selectInAttachLock(productId); |
| | | fIleSilkLock.setAttachLocks(attachLocks); |
| | | return new Response().setIIII(1,list.size()>0,list,listsoft,fIleSilkLock,"返回物料信息及关联物料"); |
| | | } |
| | | //历史产品下载(产品id和版本<下载的版本>) |
| | | public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version) { |
| | | public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version |
| | | , String oprateReason, String oprateInfo) { |
| | | //读取产品信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("id",productId); |
| | |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | //生成excel并将dwg文件放在同一报下压缩 |
| | | creatBomHsitoryExcel(req,resp,pHistory,endList,withOutDwg); |
| | | //记录日志 |
| | | DocUser docUser= ActionUtil.getUser(); |
| | | String operationDetail="具体产品为:"+pHistory.toString(); |
| | | String opreationMsg="执行了"+pHistory.getVersion()+"版本产品的下载操作"; |
| | | String terminalIp=req.getRemoteAddr(); |
| | | logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); |
| | | creatBomHsitoryExcel(req,resp,pHistory,endList,withOutDwg,oprateReason,oprateInfo,ActionUtil.sdfwithALL.format(pHistory.getVersionTime())); |
| | | } |
| | | //根据产品信息创建excel表格并存放在指定目录 |
| | | public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,ProductHistory pHistory,List<ProductBomHistory> list,String withOutDwg){ |
| | | public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,ProductHistory pHistory,List<ProductBomHistory> list,String withOutDwg |
| | | , String oprateReason, String oprateInfo,String oprateVersion){ |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String rootFace=""; |
| | | String excelName=""; |
| | |
| | | FileOutputStream forootFace = new FileOutputStream(file); |
| | | 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); |
| | | } |
| | | |
| | | //将物料存放为一个bomHistory为下载做准备 |
| | |
| | | |
| | | } |
| | | //根据产品母料型号,定制单号,版本下载原始压缩包文件 |
| | | public Response getOriginalZip(String parentModel, String customCode, int version) { |
| | | public Response getOriginalZip(String parentCode,String parentModel, String customCode, int version) { |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String withOutDwg=fileDirName+File.separator+"doc_file"+File.separator+"product"+File.separator+parentModel; |
| | | if(customCode!=null&&!customCode.isEmpty()){ |
| | |
| | | String[] filePath = file.list();//获取该文件夹下的所有文件以及目录的名字 |
| | | if(filePath!=null&&filePath.length>0){ |
| | | for (String tmp:filePath) { |
| | | if(tmp.contains(".zip")){ |
| | | if((tmp.contains(parentCode)||tmp.contains(parentModel))&&tmp.contains(".zip")){ |
| | | bl=true; |
| | | withOutDwg=withOutDwg+File.separator+tmp; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,bl,withOutDwg.replace(fileDirName,""),"原始文件相对路径"); |
| | | } |
| | | |
| | | public void getFixItem() { |
| | | List<ProductBomHistory> bomHistoryList = mapper.selectList(null); |
| | | Map<Integer, List<ProductBomHistory>> productMap = bomHistoryList.stream().collect(Collectors.groupingBy(ProductBomHistory::getProductId)); |
| | | Set<Integer> productIdSet = productMap.keySet(); |
| | | List<ProductBomHistory> needToDealWith = new LinkedList<>(); |
| | | for (Integer productId : productIdSet) { |
| | | List<ProductBomHistory> bomList = productMap.get(productId); |
| | | Map<Integer, List<ProductBomHistory>> materialIdMap = bomList.stream().collect(Collectors.groupingBy(ProductBomHistory::getMaterialId)); |
| | | Set<Integer> materialIdSet = materialIdMap.keySet(); |
| | | for (Integer materialId : materialIdSet) { |
| | | List<ProductBomHistory> temp = materialIdMap.get(materialId); |
| | | if(temp.size()!=1){ |
| | | System.err.println("需要手动处理的productBomHistory和productBom:"+productId+",物料id:"+materialId); |
| | | needToDealWith.add(temp.get(0)); |
| | | } |
| | | } |
| | | } |
| | | System.err.println("可能需要处理的条数为:"+needToDealWith.size()); |
| | | } |
| | | } |