| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.crypto.Data; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.*; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | |
| | | public Response zipParse(MultipartFile file) throws IOException, InvalidFormatException { |
| | | List<ProductBomApproving> list = new LinkedList<>(); |
| | | List<ProductBomApproving> referenceList = new LinkedList<>(); |
| | | Response response = new Response(); |
| | | //检查是否为zip |
| | | boolean isZip = Zip4jUtil.checkZipFileParam(file); |
| | |
| | | List<FileUrlDTO> dwgExistsList = getDwgList(fileList); |
| | | for (int i = 0; i < fileList.size(); i++) { |
| | | String fileTempUrl = fileList.get(i); |
| | | if(fileTempUrl.contains(".xls")){ |
| | | //查询到主参考表的数据 |
| | | if(fileTempUrl.contains(".xls") && fileTempUrl.contains("BOM-erp")){ |
| | | Workbook workbook = null; |
| | | InputStream inputStream = new FileInputStream(new File(fileTempUrl)); |
| | | workbook = WorkbookFactory.create(inputStream); |
| | | inputStream.close(); |
| | | //取第一个sheet表 |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | //取第三行,并以第三行开始 |
| | | Row row2 = sheet.getRow(1); |
| | | short lastCellNum = row2.getLastCellNum(); |
| | | for (int k = 2; k < lastRowNum+1; k++) { |
| | | ProductBomApproving bomApproving = new ProductBomApproving(); |
| | | for (int j = 1; j < lastCellNum; j++) { |
| | | Row row = sheet.getRow(k); |
| | | Cell cell = row.getCell(j); |
| | | String cellValue = null; |
| | | Double cellValueInt = 0d; |
| | | if(j == 9){ |
| | | cellValueInt = cell.getNumericCellValue(); |
| | | }else if(j!=15){ |
| | | cellValue = cell.getStringCellValue(); |
| | | } |
| | | switch (j){ |
| | | case 1:{bomApproving.setParentCode(cellValue);}break; |
| | | 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 6:{bomApproving.setSubName(cellValue);}break; |
| | | case 7:{bomApproving.setSubModel(cellValue);}break; |
| | | case 8:{bomApproving.setUnit(cellValue);}break; |
| | | case 9:{bomApproving.setQuantity(cellValueInt.intValue());}break; |
| | | case 10:{bomApproving.setProducer(cellValue);}break; |
| | | case 11:{bomApproving.setMaterial(cellValue);}break; |
| | | case 12:{bomApproving.setThickness(cellValue);}break; |
| | | case 13:{bomApproving.setSurfaceDetail(cellValue);}break; |
| | | case 14:{bomApproving.setNotes(cellValue);}break; |
| | | case 15:{ |
| | | |
| | | } |
| | | }break; |
| | | } |
| | | referenceList.add(bomApproving); |
| | | } |
| | | } |
| | | //这个是子表数据,需要提交审批 |
| | | else if(fileTempUrl.contains(".xls")){ |
| | | File fileTemp = new File(fileTempUrl); |
| | | Workbook workbook = null; |
| | | workbook = WorkbookFactory.create(fileTemp); |
| | |
| | | } |
| | | } |
| | | } |
| | | String parentModel = list.get(0).getParentModel(); |
| | | /*String parentModel = list.get(0).getParentModel(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if(!parentModel.equals(list.get(i).getParentModel())){ |
| | | return new Response().set(1,false,"拒绝解析,一次审批包含不同的产品修改"); |
| | | } |
| | | } |
| | | }*/ |
| | | //通过包名,查询工单流程审批标题 |
| | | //String nextTitle = mainService.getNextTitle(originalFilename); |
| | | |
| | | //需提交审批的记录,逐条对比参考表,子料编码/子料型号/子料数量 |
| | | for (ProductBomApproving sub:list){ |
| | | String subCode = sub.getSubCode(); |
| | | String subModel = sub.getSubModel(); |
| | | Integer quantity = sub.getQuantity(); |
| | | boolean exists = false; |
| | | for (ProductBomApproving reference:referenceList){ |
| | | if(subCode.equals(reference.getSubCode())){ |
| | | exists = true; |
| | | if(subModel.equals(reference.getSubModel())){ |
| | | if(quantity.intValue() == reference.getQuantity()){ |
| | | break; |
| | | }else{ |
| | | return response.set(1,false,"结构件审批提交中列中货品编码:"+subCode+"对应的数量:"+quantity+"在参考bom表中不正确"); |
| | | } |
| | | }else{ |
| | | return response.set(1,false,"结构件审批提交中列中货品编码:"+subCode+"对应的规格型号:"+subModel+"在参考bom表中不正确"); |
| | | } |
| | | } |
| | | } |
| | | if(!exists){ |
| | | return response.set(1,false,"结构件审批提交中列中货品编码:"+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,"解析完成"); |
| | | } |