본문 바로가기

카테고리 없음

24.02.21 대용량

 

 

 

 

 

 

fun loadCsvFile(): Unit
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestMapping


@RestController
@RequestMapping("/api")
class StoreController(private val storeService: StoreService) {

    @PostMapping("/collection")
    fun loadCsvIntoDatabase() {
        storeService.loadCsvFile()
    }
}

 

override fun loadCsvFile() {
    val path = "C:/Users/asdf/Desktop/대용량 보조/서울시 간략.csv"
    val rows: List<Map<String, String>> = csvReader().readAllWithHeader(path)

    rows.map { row ->
        Store(
            id = row["id"]!!.toInt(),
            createdAt = row["created_at"]!!,
            shopName = row["shop_name"]!!,
            mallName = row["mall_name"]!!,
            domain = row["domain"]!!,
            email = row["email"]!!,
            phoneNumber = row["phone_number"]!!,
            businessType = row["business_type"]!!,
            address = row["address"]!!,
            saleNumber = row["sale_number"]!!,
            firstReportDate = row["first_report_date"]!!,
            situation = row["situation"]!!,
            totalEvaluation = row["total_evaluation"]?.toInt(),
            withdrawalEvaluation = row["withdrawal_evaluation"]?.toInt(),
            businessInformationEvaluation = row["business_information_evaluation"]?.toInt(),
            approvalEvaluation = row["approval_evaluation"]?.toInt(),
            termsEvaluation = row["terms_evaluation"]?.toInt(),
            privacyEvaluation = row["privacy_evaluation"]?.toInt(),
            mainItem = row["main_item"]!!,
            withdrawPossible = row["withdraw_possible"]!!,
            initialScreen = row["initial_screen"]!!,
            payment = row["payment"]!!,
            termCompliance = row["term_compliance"]!!,
            privacyStatement = row["privacy_statement"]!!,
            requestTermOver = row["request_term_over"]!!,
            safetyService = row["safety_service"]!!,
            securityServer = row["security_server"]!!,
            certificationMark = row["certification_mark"]!!,
            deliveryDate = row["delivery_date"]!!,
            refundDeliveryFee = row["refund_delivery_fee"]!!,
            customerComplaintBoard = row["customer_complaint_board"]!!,
            cancelMembership = row["cancel_membership"]!!,
            siteOpening = row["site_opening"]!!,
            monitoringDate = row["monitoring_date"]!!
        )
    }.forEach { store ->
        storeRepository.save(store)
    }
}

이것들을 넣어서 작동이 되나 시도해 봤는데, 전혀 작동이 안됬다. 

 

오늘도 많은 시도를 해봤는데, 쿼리 dsl을 써보자는 시도는 우선 뭐리를 어떻게 쓰는지에 대해 많은 시간을 소모하고 검색을 통해서

LOAD DATA INFILE 'C:/Users/asdf/Desktop/대용량 보조/서울시 인터넷 쇼핑몰.csv'
INTO TABLE store
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(shop_name, mall_name, domain, phone_number, email, sale_number, business_type, first_report_date, address, situation, total_evaluation, business_information_evaluation, withdrawal_evaluation, approval_evaluation, terms_evaluation, privacy_evaluation, main_item, withdraw_possible, initial_screen, payment, term_compliance, privacy_statement, request_term_over, safety_service, security_server, certification_mark, delivery_date, refund_delivery_fee, customer_complaint_board, cancel_membership, site_opening, monitoring_date);

 이걸 쓰면 될거 같다는 생각을 했는데, 이걸 어디에 어떻게 쓰는지를 모르겠어섯 시간을 낭비하다

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    val kotlinVersion = "1.6.21" // 최신 버전으로 업데이트

    id("org.springframework.boot") version "2.7.0"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion
    kotlin("plugin.jpa") version kotlinVersion
    kotlin("kapt") version kotlinVersion
    idea
}

//여기부터 추가


//여기부터
group = "me.leedo"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}
repositories {
    mavenCentral()
}
//여기까지도 추가


noArg {
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Embeddable")
}

allOpen {
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Embeddable")
}

group = "com.sparta"
version = "0.0.1-SNAPSHOT"

java {
    sourceCompatibility = JavaVersion.VERSION_17
}

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.13.0")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    implementation ("org.springframework.boot:spring-boot-starter-validation")

    implementation("org.springframework.boot:spring-boot-starter-aop")

    runtimeOnly("org.postgresql:postgresql")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")

    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("io.jsonwebtoken:jjwt-api:0.12.3")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.3")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.3")
    //implementation("com.h2database:h2")
    implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")

    implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta")
    kapt("com.querydsl:querydsl-apt:5.0.0:jakarta")

//여기부터 추가
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    // ✅ querydsl을 설치합니다
    implementation("com.querydsl:querydsl-jpa:5.0.0")
    // ✅ KAPT(Kotlin Annotation Processing Tool)를 설정합니다
    //    kotlin 코드가 아니라면 kapt 대신 annotationProcessor를 사용합니다
    //    JPAAnnotationProcessor를 사용하기 위해 마지막에 :jpa를 붙입니다
    kapt("com.querydsl:querydsl-apt:5.0.0:jpa")

    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.springframework.security:spring-security-test")
//여기까지



}
//여기부터
tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs += "-Xjsr305=strict"
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.getByName<Jar>("jar") {
    enabled = false
}

// ✅ QClass를 Intellij가 사용할 수 있도록 경로에 추가합니다
idea {
    module {
        val kaptMain = file("build/generated/source/kapt/main")
        sourceDirs.add(kaptMain)
        generatedSourceDirs.add(kaptMain)
    }
}

 

이렇게 바꿔 봤는데, 왠지 store 엔티티가 크게 오류가나며 빨간색의 덩어리로 전락해버려서 

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
    id("org.springframework.boot") version "3.1.6"
    id("io.spring.dependency-management") version "1.1.4"
    kotlin("jvm") version "1.8.22"
    kotlin("plugin.spring") version "1.8.22"
    kotlin("plugin.noarg") version "1.8.22"
    kotlin("plugin.allopen") version "1.8.22"
    kotlin("kapt") version "1.8.22" // 추가!
}


group = "com.teamsparta"
version = "0.0.1-SNAPSHOT"

java {
    sourceCompatibility = JavaVersion.VERSION_17
}

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
}

val queryDslVersion = "5.0.0"

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("io.jsonwebtoken:jjwt-api:0.12.3")
    implementation("org.springframework.boot:spring-boot-starter-aop")
    implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") // 추가!
    kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") // 추가!


    runtimeOnly("org.postgresql:postgresql")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.3")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.3")

    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test")

}

allOpen {
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Embeddable")
}

noArg {
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Embeddable")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs += "-Xjsr305=strict"
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.bootBuildImage {
    builder.set("paketobuildpacks/builder-jammy-base:latest")
}

// IntelliJ가 생성한 Q 클래스를 인식할 수 있도록 설정
//5.0.0

다시 ㅇ예전으로 돌아왔다. 아무래도 쿼리는 못쓸거같다.

 

외부라이브러리

    implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.15.0")

이게 있으면 된다고 들었었는데!!!