diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index 1478b08..89bce83 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -60,89 +60,92 @@ fun ExcelRead(): String{ val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx") val workbook = WorkbookFactory.create(inputStream) val workSheet = workbook.getSheetAt(0) - var h = false + var h = true //Header check -// if(workSheet.getRow(0).getCell(0).stringCellValue.equals("Name")){ -// if(workSheet.getRow(0).getCell(1).stringCellValue.equals("Description")){ -// if(workSheet.getRow(0).getCell(2).stringCellValue.equals("HSN")){ -// if(workSheet.getRow(0).getCell(3).stringCellValue.equals("UOM")){ -// return true -// } -// } -// } -// } + if(workSheet.getRow(0).getCell(0).stringCellValue.equals("Name")) { + if (workSheet.getRow(0).getCell(1).stringCellValue.equals("Description")) { + if (workSheet.getRow(0).getCell(2).stringCellValue.equals("HSN")) { + if (workSheet.getRow(0).getCell(3).stringCellValue.equals("UOM")) { + h = false + }else return "Header UOM mismatch" + }else return "Header-HSN mismatch" + }else return "Header-Desc mismatch" + }else return "Header-Name mismatch" val resp = arrayListOf() - workSheet.rowIterator().forEach { row -> - if (row == null) return@forEach + if(h==false) { + workSheet.rowIterator().forEach { row -> - if (h) { + if (row == null) return@forEach - val pName = row.getCell(0).run { - when { - this == null -> "" - this.cellType == CellType.STRING -> this.stringCellValue - else -> "" + if (h) { + + val pName = row.getCell(0).run { + when { + this == null -> "" + this.cellType == CellType.STRING -> this.stringCellValue + else -> "" + } + } + + val pDesc = row.getCell(1).run { + when { + this == null -> "" + this.cellType == CellType.STRING -> this.stringCellValue + else -> "" + } + } + val pHsn = row.getCell(2).run { + when { + this == null -> "" + this.cellType == CellType.STRING -> this.stringCellValue + else -> "" + } + } + + if (pName.isEmpty() && pDesc.isEmpty() && pHsn.isEmpty()) { + return@forEach + } + if (pName.isEmpty()) { + resp.add( + validateExcel( + name = pName, + description = pDesc, + hsnCode = pHsn, + ok = false, + err = "Product name is required" + ) + ) + return@forEach + } + if (pDesc.isEmpty()) { + resp.add( + validateExcel( + name = pName, + description = pDesc, + hsnCode = pHsn, + ok = false, + err = "Product description is required" + ) + ) + return@forEach + } + if (pHsn.isEmpty()) { + resp.add( + validateExcel( + name = pName, + description = pDesc, + hsnCode = pHsn, + ok = false, + err = "Product HSN is required" + ) + ) + return@forEach } } - - val pDesc = row.getCell(1).run { - when { - this == null -> "" - this.cellType == CellType.STRING -> this.stringCellValue - else -> "" - } - } - val pHsn = row.getCell(2).run { - when { - this == null -> "" - this.cellType == CellType.STRING -> this.stringCellValue - else -> "" - } - } - - if (pName.isEmpty() && pDesc.isEmpty() && pHsn.isEmpty()) { - return@forEach - } - if (pName.isEmpty()) { - resp.add( - validateExcel( - name = pName, - description = pDesc, - hsnCode = pHsn, - ok = false, - err = "Product name is required" - ) - ) - return@forEach - } - if (pDesc.isEmpty()) { - resp.add( - validateExcel( - name = pName, - description = pDesc, - hsnCode = pHsn, - ok = false, - err = "Product description is required" - ) - ) - return@forEach - } - if (pHsn.isEmpty()) { - resp.add( - validateExcel( - name = pName, - description = pDesc, - hsnCode = pHsn, - ok = false, - err = "Product HSN is required" - ) - ) - return@forEach - } + h = true } - h = true } return app_common_om.writeValueAsString(resp) } \ No newline at end of file