Excel to Db
This commit is contained in:
parent
d23ac5261d
commit
cfa3a7e289
14
api.http
14
api.http
@ -97,12 +97,16 @@ Authorization: {{auth-token}}
|
|||||||
GET http://localhost:9001/api/vendor/product
|
GET http://localhost:9001/api/vendor/product
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
|
### get products by hsn code
|
||||||
|
GET http://localhost:9001/api/vendor/product/#123
|
||||||
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
### create excel for products
|
### create excel for products
|
||||||
POST http://localhost:9001/api/vendor/product/product-excel
|
POST http://localhost:9001/api/vendor/product/product-excel
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
### get
|
### excel read
|
||||||
GET http://localhost:9001/api/vendor/product/product-import
|
GET http://localhost:9001/api/vendor/product/validation
|
||||||
Authorization: Bearer {{auth-token}}
|
Authorization: Bearer {{auth-token}}
|
||||||
|
|
||||||
### create product
|
### create product
|
||||||
@ -130,5 +134,9 @@ Authorization: {{auth-token}}
|
|||||||
|
|
||||||
|
|
||||||
### delete a row
|
### delete a row
|
||||||
DELETE http://localhost:9001/api/vendor/product/2
|
DELETE http://localhost:9001/api/vendor/product/#1
|
||||||
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
|
###
|
||||||
|
POST http://localhost:9001/api/vendor/product/import
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
@ -199,28 +199,13 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
path("/product") {
|
path("/product") {
|
||||||
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||||
//get("/{hsnCode}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
get("/{hsnCode}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
||||||
put(
|
patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
||||||
"/{id}",
|
put("/{id}", ProductCtrl::update, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
||||||
ProductCtrl::update,
|
delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN"))))
|
||||||
Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN")))
|
|
||||||
)
|
|
||||||
//patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
|
||||||
delete(
|
|
||||||
"/{id}",
|
|
||||||
ProductCtrl::delete,
|
|
||||||
Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN")))
|
|
||||||
)
|
|
||||||
get("", ProductCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
get("", ProductCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
||||||
post("/product-excel", ProductCtrl::prodExcel)
|
post("/product-excel", ProductCtrl::prodExcel)
|
||||||
get("/product-import") { ctx -> //ctx.json(ExcelRead())}
|
post("/import") {ctx -> ctx.json(excelToDb())}
|
||||||
val fileItem = ctx.uploadedFiles("file")
|
|
||||||
if (fileItem != null) {
|
|
||||||
ctx.result("Data imported successfully!")
|
|
||||||
} else {
|
|
||||||
ctx.result("No file uploaded")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
path("/doc") {
|
path("/doc") {
|
||||||
post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN"))))
|
post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN"))))
|
||||||
|
|||||||
@ -17,6 +17,8 @@ import com.restapi.integ.Scripting
|
|||||||
import io.ebean.CallableSql
|
import io.ebean.CallableSql
|
||||||
import io.ebean.RawSqlBuilder
|
import io.ebean.RawSqlBuilder
|
||||||
import io.javalin.http.*
|
import io.javalin.http.*
|
||||||
|
import org.apache.poi.ss.usermodel.Cell
|
||||||
|
import org.apache.poi.ss.usermodel.CellType
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory
|
import org.apache.poi.ss.usermodel.WorkbookFactory
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -457,33 +459,6 @@ object ProductCtrl {
|
|||||||
.header("Content-Disposition", "attachment; filename=\"product.xlsx\"")
|
.header("Content-Disposition", "attachment; filename=\"product.xlsx\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ProductList(
|
|
||||||
val name: String,
|
|
||||||
val description: String,
|
|
||||||
val hsnCode: String,
|
|
||||||
val uom: String?,
|
|
||||||
)
|
|
||||||
|
|
||||||
fun excelToDb(it: Context){
|
|
||||||
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx")
|
|
||||||
val workbook = WorkbookFactory.create(inputStream)
|
|
||||||
val workSheet = workbook.getSheetAt(0)
|
|
||||||
|
|
||||||
val dataList = mutableListOf<ProductList>()
|
|
||||||
|
|
||||||
for (row in workSheet) {
|
|
||||||
val cell1Value = row.getCell(0).stringCellValue
|
|
||||||
val cell2Value = row.getCell(1).stringCellValue
|
|
||||||
val cell3Value = row.getCell(2).stringCellValue
|
|
||||||
val cell4Value = row.getCell(3).stringCellValue
|
|
||||||
|
|
||||||
val data = ProductList(cell1Value, cell2Value, cell3Value, cell4Value)
|
|
||||||
dataList.add(data)
|
|
||||||
|
|
||||||
}
|
|
||||||
database.saveAll(dataList)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object Quotation {
|
object Quotation {
|
||||||
|
|||||||
@ -4,6 +4,11 @@ import com.fasterxml.jackson.databind.DeserializationFeature
|
|||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.restapi.domain.Product
|
import com.restapi.domain.Product
|
||||||
|
import com.restapi.domain.Session
|
||||||
|
import com.restapi.domain.Session.database
|
||||||
|
import com.restapi.domain.UOM
|
||||||
|
import io.ebean.text.json.JsonContext
|
||||||
|
import io.javalin.http.Context
|
||||||
import org.apache.poi.ss.usermodel.Cell
|
import org.apache.poi.ss.usermodel.Cell
|
||||||
import org.apache.poi.ss.usermodel.CellType
|
import org.apache.poi.ss.usermodel.CellType
|
||||||
import org.apache.poi.ss.usermodel.Row
|
import org.apache.poi.ss.usermodel.Row
|
||||||
@ -57,7 +62,7 @@ val app_common_om = jacksonObjectMapper().apply {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ExcelRead(): String{
|
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\\product-4.xlsx")
|
||||||
val workbook = WorkbookFactory.create(inputStream)
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
val workSheet = workbook.getSheetAt(0)
|
val workSheet = workbook.getSheetAt(0)
|
||||||
var h = true
|
var h = true
|
||||||
@ -149,3 +154,31 @@ fun ExcelRead(): String{
|
|||||||
}
|
}
|
||||||
return app_common_om.writeValueAsString(resp)
|
return app_common_om.writeValueAsString(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun excelToDb(): List<Product> {
|
||||||
|
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\product-4.xlsx")
|
||||||
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
|
val workSheet = workbook.getSheetAt(0)
|
||||||
|
|
||||||
|
for (row in workSheet) {
|
||||||
|
val cell1Value = row.getCell(0).stringCellValue
|
||||||
|
val cell2Value = row.getCell(1).stringCellValue
|
||||||
|
val cell3Value = row.getCell(2).stringCellValue
|
||||||
|
val cell4Value = row.getCell(3).stringCellValue
|
||||||
|
|
||||||
|
val prod = Product()
|
||||||
|
prod.name = cell1Value
|
||||||
|
prod.description = cell2Value
|
||||||
|
prod.hsnCode = cell3Value
|
||||||
|
prod.uom = when(cell4Value) {
|
||||||
|
"nos" -> UOM.NOS
|
||||||
|
"ltr" -> UOM.LTR
|
||||||
|
"mtr" -> UOM.MTR
|
||||||
|
else -> UOM.ALL
|
||||||
|
}
|
||||||
|
database.saveAll(prod)
|
||||||
|
}
|
||||||
|
val productList = Session.database.find(Product::class.java).findList()
|
||||||
|
return productList
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -325,10 +325,10 @@ open class ReqForQuote :BaseTenantModel() {
|
|||||||
var potentialVendors :List<Long>? = null
|
var potentialVendors :List<Long>? = null
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
var status :RFQStatus? = null
|
var status :RFQStatus? = null
|
||||||
// @DbArray
|
@DbArray
|
||||||
// var docs :List<Document>? = null
|
var docs :List<Document>? = null
|
||||||
@DbJsonB
|
@DbJsonB
|
||||||
var products :List<POProducts>? = null
|
var products :List<POProducts>? = null
|
||||||
var reqForQuoteNum: String? = null
|
var reqForQuoteNum: String = ""
|
||||||
var openTill: LocalDate? = null
|
var openTill: LocalDate? = null
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user