whycxzp
2022-08-08 090fc1f6d92f438ba2bd5c124ab0b9715bd3cbbb
src/main/java/com/whyc/service/ProductBomApprovingService.java
@@ -115,7 +115,7 @@
    public Response zipParse(MultipartFile file) throws IOException, InvalidFormatException {
        List<ProductBomApproving> list = new LinkedList<>();
        List<ProductBomApproving> referenceList = new LinkedList<>();
        List<ProductBomApproving> bomList = new LinkedList<>();
        Response response = new Response();
        //检查是否为zip
        boolean isZip = Zip4jUtil.checkZipFileParam(file);
@@ -145,12 +145,13 @@
        List<FileUrlDTO> dwgExistsList = getDwgList(fileList);
        for (int i = 0; i < fileList.size(); i++) {
            String fileTempUrl = fileList.get(i);
            //查询到主参考表的数据
            //查询到需上传的bom数据
            if(fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)-erp")){
                Workbook workbook = null;
                InputStream inputStream = new FileInputStream(new File(fileTempUrl));
                workbook = WorkbookFactory.create(inputStream);
                inputStream.close();
                List<? extends PictureData> allPictures = workbook.getAllPictures();
                //取第一个sheet表
                Sheet sheet = workbook.getSheetAt(0);
                int lastRowNum = sheet.getLastRowNum();
@@ -174,7 +175,21 @@
                            case 2:{bomApproving.setParentName(cellValue);}break;
                            case 3:{bomApproving.setParentModel(cellValue);}break;
                            case 4:{bomApproving.setCategory(cellValue);}break;
                            case 5:{bomApproving.setSubCode(cellValue);}break;
                            case 5:{
                                bomApproving.setSubCode(cellValue);
                                //判断图纸查看是否存在
                                bomApproving.setDwgExist(0);
                                String dwgFileName = cellValue+".dwg";
                                for (int n = 0; n < dwgExistsList.size(); n++) {
                                    FileUrlDTO fileUrlDTO = dwgExistsList.get(n);
                                    if(dwgFileName.equals(fileUrlDTO.getFileName())){
                                        //存在
                                        bomApproving.setDwgExist(1);
                                        bomApproving.setDwgUrl(fileUrlDTO.getHttpFileUrl());
                                        break;
                                    }
                                }
                            }break;
                            case 6:{bomApproving.setSubName(cellValue);}break;
                            case 7:{bomApproving.setSubModel(cellValue);}break;
                            case 8:{bomApproving.setUnit(cellValue);}break;
@@ -184,12 +199,35 @@
                            case 12:{bomApproving.setThickness(cellValue);}break;
                            case 13:{bomApproving.setSurfaceDetail(cellValue);}break;
                            case 14:{bomApproving.setNotes(cellValue);}break;
                            case 15:{
                                //图片,从0开始,到图片size为止
                                int m = i-2;
                                if(m<allPictures.size()){
                                    PictureData pictureData = allPictures.get(k);
                                    //图片存储 product_approving/username/2022-07/
                                    String approvingPath = rootFile + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat;
                                    File provingFile = new File(approvingPath);
                                    if(!provingFile.exists()){
                                        provingFile.mkdirs();
                                    }
                                    String suffix = pictureData.suggestFileExtension();
                                    String picturePath = approvingPath + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    byte[] data = pictureData.getData();
                                    FileOutputStream fileOutputStream = null;
                                    File pictureFile = new File(picturePath);
                                    fileOutputStream = new FileOutputStream(pictureFile);
                                    fileOutputStream.write(data);
                                    bomApproving.setPictureUrl(picturePathFront);
                                }
                            }break;
                        }
                    }
                    referenceList.add(bomApproving);
                    bomList.add(bomApproving);
                }
            }
            //这个是子表数据,需要提交审批
            //这个是子表数据,用做对比校验
            else if(fileTempUrl.contains(".xls")){
                File fileTemp = new File(fileTempUrl);
                Workbook workbook = null;
@@ -299,37 +337,33 @@
        //通过包名,查询工单流程审批标题
        //String nextTitle = mainService.getNextTitle(originalFilename);
        //需提交审批的记录,逐条对比参考表,子料编码/子料型号/子料数量
        //子表,逐条对比bom表,子料编码/子料型号/子料数量
        for (ProductBomApproving sub:list){
            String subCode = sub.getSubCode();
            String subModel = sub.getSubModel();
            Integer quantity = sub.getQuantity();
            String excelName = sub.getExcelName();
            boolean exists = false;
            for (ProductBomApproving reference:referenceList){
            for (ProductBomApproving reference:bomList){
                if(subCode.equals(reference.getSubCode())){
                    exists = true;
                    if(subModel.equals(reference.getSubModel())){
                        if(quantity.intValue() == reference.getQuantity()){
                            break;
                        }else{
                            return response.set(1,false,excelName+"中货品编码:"+subCode+"对应的数量:"+quantity+"在参考bom表中不正确");
                            return response.set(1,false,excelName+"中货品编码:"+subCode+"对应的数量:"+quantity+"在bom表中不正确");
                        }
                    }else{
                        return response.set(1,false,excelName+"中货品编码:"+subCode+"对应的规格型号:"+subModel+"在参考bom表中不正确");
                        return response.set(1,false,excelName+"中货品编码:"+subCode+"对应的规格型号:"+subModel+"在bom表中不正确");
                    }
                }
            }
            if(!exists){
                return response.set(1,false,excelName+"中货品编码:"+subCode+"在参考bom表中不存在");
                return response.set(1,false,excelName+"中货品编码:"+subCode+"在bom表中不存在");
            }
            ProductBomApproving reference = referenceList.get(0);
            sub.setParentCode(reference.getParentCode());
            sub.setParentModel(reference.getParentModel());
            sub.setParentName(reference.getParentName());
        };
        }
        String nextTitle = originalFilename.substring(0,originalFilename.lastIndexOf("."));
        return response.setIII(1,true,list,nextTitle,"解析完成");
        return response.setIII(1,true,bomList,nextTitle,"解析完成");
    }
    private List<FileUrlDTO> getDwgList(List<String> fileList) {