Product Excel Validation
This commit is contained in:
parent
a3f7614979
commit
976aebec5b
@ -60,89 +60,92 @@ fun ExcelRead(): String{
|
|||||||
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx")
|
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx")
|
||||||
val workbook = WorkbookFactory.create(inputStream)
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
val workSheet = workbook.getSheetAt(0)
|
val workSheet = workbook.getSheetAt(0)
|
||||||
var h = false
|
var h = true
|
||||||
//Header check
|
//Header check
|
||||||
// if(workSheet.getRow(0).getCell(0).stringCellValue.equals("Name")){
|
if(workSheet.getRow(0).getCell(0).stringCellValue.equals("Name")) {
|
||||||
// if(workSheet.getRow(0).getCell(1).stringCellValue.equals("Description")){
|
if (workSheet.getRow(0).getCell(1).stringCellValue.equals("Description")) {
|
||||||
// if(workSheet.getRow(0).getCell(2).stringCellValue.equals("HSN")){
|
if (workSheet.getRow(0).getCell(2).stringCellValue.equals("HSN")) {
|
||||||
// if(workSheet.getRow(0).getCell(3).stringCellValue.equals("UOM")){
|
if (workSheet.getRow(0).getCell(3).stringCellValue.equals("UOM")) {
|
||||||
// return true
|
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<validateExcel>()
|
val resp = arrayListOf<validateExcel>()
|
||||||
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 {
|
if (h) {
|
||||||
when {
|
|
||||||
this == null -> ""
|
val pName = row.getCell(0).run {
|
||||||
this.cellType == CellType.STRING -> this.stringCellValue
|
when {
|
||||||
else -> ""
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
h = true
|
||||||
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
|
|
||||||
}
|
}
|
||||||
return app_common_om.writeValueAsString(resp)
|
return app_common_om.writeValueAsString(resp)
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user