Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Feb 11, 2024
1 parent 1372dde commit 8349b0c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import javax.servlet.http.HttpServletResponse
import org.springframework.web.bind.annotation.RequestParam

@RestController
@RequestMapping("/excel")
Expand All @@ -23,10 +24,10 @@ class ExcelController(
createExcelSheetService.execute(httpServletResponse)

@PostMapping
fun saveExcelInfo(file: MultipartFile) =
getExcelSheetService.execute(file)
fun saveExcelInfo(@RequestParam(name = "scheme")scheme: String, @RequestParam(name = "host")host: String, @RequestParam(name = "port")port: Int, @RequestParam(name = "database")database: String, @RequestParam(name = "username")username: String, @RequestParam(name = "password")password: String, file: MultipartFile) =
getExcelSheetService.execute(scheme, host, port, database, username, password, file)

@GetMapping("/userInfo")
fun createExcelSheetAsDD(httpServletResponse: HttpServletResponse) =
createExcelSheetAsDB.execute(httpServletResponse)
fun createExcelSheetAsDD(@RequestParam(name = "scheme")scheme: String, @RequestParam(name = "host")host: String, @RequestParam(name = "port")port: Int, @RequestParam(name = "database")database: String, @RequestParam(name = "username")username: String, @RequestParam(name = "password")password: String, httpServletResponse: HttpServletResponse) =
createExcelSheetAsDB.execute(scheme, host, port, database, username, password, httpServletResponse)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.service

import com.xaquare.xquarebackoffice.infrastructure.excel.ExcelProperties
import com.xaquare.xquarebackoffice.infrastructure.excel.dto.ExcelData
import com.xaquare.xquarebackoffice.infrastructure.excel.service.query.ExcelQuery
import org.apache.poi.ss.usermodel.*
Expand All @@ -14,11 +13,9 @@ import javax.servlet.http.HttpServletResponse

@Service
class CreateExcelSheetAsDB(
private val properties: ExcelProperties,
private val query: ExcelQuery

) {
fun execute(response: HttpServletResponse) {
fun execute(scheme: String, host: String, port: Int, database: String, username: String, password: String, response: HttpServletResponse) {

val workbook: Workbook = XSSFWorkbook()
val sheet: Sheet = workbook.createSheet("xquare_userInfo").apply {
Expand Down Expand Up @@ -64,16 +61,16 @@ class CreateExcelSheetAsDB(
}

val dataList: MutableList<ExcelData> = ArrayList()
val jdbcUrl = "jdbc:mysql://${properties.host}:${properties.port}/${properties.database}"
val username = properties.username
val password = properties.password
val jdbcUrl = "jdbc:mysql://$host:$port/$database"
val username = username
val password = password

var connection: Connection? = null

try {
connection = DriverManager.getConnection(jdbcUrl, username, password)

val query = "${query.selectQuery()} ${properties.database}"
val query = "${query.selectQuery()} $database"
val statement = connection.createStatement()
val sqlResult = statement.executeQuery(query)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.service

import com.xaquare.xquarebackoffice.infrastructure.excel.ExcelProperties
import com.xaquare.xquarebackoffice.infrastructure.excel.dto.ExcelData
import com.xaquare.xquarebackoffice.infrastructure.excel.exception.DBAccessException
import com.xaquare.xquarebackoffice.infrastructure.excel.exception.DataFormatException
Expand All @@ -18,11 +17,10 @@ import java.time.format.DateTimeFormatter

@Service
class GetExcelSheetService(
private val properties: ExcelProperties,
private val excelQuery: ExcelQuery
) {

fun execute(file: MultipartFile) {
fun execute(scheme: String, host: String, port: Int, database: String, username: String, password: String, file: MultipartFile) {
val dataList: MutableList<ExcelData> = ArrayList()

val extension = FilenameUtils.getExtension(file.originalFilename)
Expand Down Expand Up @@ -55,16 +53,14 @@ class GetExcelSheetService(
)
dataList.add(excelData)
}
saveExcelDataToDB(dataList)
saveExcelDataToDB(scheme, host, port, database, username, password, dataList)
} finally {
excel?.close()
}
}

private fun saveExcelDataToDB(dataList: List<ExcelData>) {
val jdbcUrl = "${properties.scheme}://${properties.host}:${properties.port}/${properties.database}"
val username = properties.username
val password = properties.password
private fun saveExcelDataToDB(scheme: String, host: String, port: Int, database: String, username: String, password: String, dataList: List<ExcelData>) {
val jdbcUrl = "$scheme://$host:$port/$database"

var connection: Connection? = null
var preparedSql: PreparedStatement? = null
Expand Down

0 comments on commit 8349b0c

Please sign in to comment.