| | |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | |
| | | String numberCellValue = sheet.getRow(1).getCell(5).getStringCellValue(); |
| | | String number = numberCellValue.substring(numberCellValue.indexOf("BG")); |
| | | |
| | | String codeCellValue = sheet.getRow(2).getCell(0).getStringCellValue(); |
| | | Cell codeCell = sheet.getRow(2).getCell(0); |
| | | if(codeCell == null){ |
| | | return new Response().set(1,false,"变更料号不能为空!"); |
| | | } |
| | | String codeCellValue = codeCell.getStringCellValue(); |
| | | //变更料号:xxx |
| | | String codeStr = codeCellValue.substring(5).trim(); |
| | | String[] codeSplit; |
| | | if(codeStr == null || codeStr.equals("")){ |
| | | if(codeStr.equals("")){ |
| | | return new Response().set(1,false,"变更料号不能为空!"); |
| | | }else{ |
| | | codeSplit = codeStr.split("/"); |
| | | } |
| | | |
| | | String modelCellValue = sheet.getRow(2).getCell(5).getStringCellValue(); |
| | | Cell modelCell = sheet.getRow(2).getCell(5); |
| | | if(modelCell == null){ |
| | | return new Response().set(1,false,"变更型号不能为空!"); |
| | | } |
| | | String modelCellValue = modelCell.getStringCellValue(); |
| | | //变更名称/型号:xxx |
| | | String modelStr = modelCellValue.substring(8).trim(); |
| | | String[] modelSplit; |
| | | if(modelStr == null || modelStr.equals("")){ |
| | | if(modelStr.equals("")){ |
| | | return new Response().set(1,false,"变更型号不能为空!"); |
| | | }else{ |
| | | modelSplit = modelStr.split("/"); |
| | |
| | | ecr.setCreateTime(date); |
| | | ecr.setExcelFile(excelHttpUrl); |
| | | ecr.setParentModel(parentModel); |
| | | |
| | | //校验料号和型号必须数量一致 |
| | | if(codeSplit.length!=modelSplit.length){ |
| | | return new Response().set(1,false,"变更料号与型号对应数量不一致!"); |
| | | } |
| | | //赋值给具体对象 |
| | | for (int i = 0; i < codeSplit.length; i++) { |
| | | ECR ecrTemp = new ECR(); |
| | |
| | | |
| | | return new Response().set(1,true,"导入完成"); |
| | | } |
| | | |
| | | public Response ecrImport(ECR ecr) { |
| | | List<ECR> ecrList = new LinkedList<>(); |
| | | String subCode = ecr.getSubCode(); |
| | | String subModel = ecr.getSubModel(); |
| | | |
| | | //校验料号和型号不能为空 |
| | | if(subCode == null ||subCode.isEmpty() |
| | | || subModel == null ||subModel.isEmpty()){ |
| | | return new Response().set(1,false,"变更料号及型号不能为空!"); |
| | | } |
| | | |
| | | String[] subCodeSplit = subCode.split("/"); |
| | | String[] subModelSplit = subModel.split("/"); |
| | | |
| | | ecr.setCreateTime(new Date()); |
| | | //校验料号和型号必须数量一致 |
| | | if(subCodeSplit.length!=subModelSplit.length){ |
| | | return new Response().set(1,false,"变更料号与型号对应数量不一致!"); |
| | | } |
| | | for (int i = 0; i < subCodeSplit.length; i++) { |
| | | ECR ecrTemp = new ECR(); |
| | | BeanUtils.copyProperties(ecr,ecrTemp); |
| | | ecrTemp.setSubCode(subCodeSplit[i]); |
| | | ecrTemp.setSubModel(subModelSplit[i]); |
| | | ecrList.add(ecrTemp); |
| | | } |
| | | mapper.insertBatchSomeColumn(ecrList); |
| | | return new Response().set(1,true,"导入完成"); |
| | | } |
| | | } |