From 76c501fe241c73a5b536a7f59aa705075ab39325 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Tue, 15 Mar 2022 16:58:16 +0900 Subject: [PATCH] =?UTF-8?q?querydsl=20=EC=A0=81=EC=9A=A9(rebuild=EC=8B=9C?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=8A=94?= =?UTF-8?q?=EA=B2=83=20fix)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xit/core/util/DateUtil.java | 24 +++++++ .../IMinSimsa680RepositoryTest.java | 66 +++++++++++++++++-- .../biz/ctgy/repository/RepositoryTest.java | 2 +- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xit/core/util/DateUtil.java b/src/main/java/com/xit/core/util/DateUtil.java index d62dd5c..81e6f1d 100644 --- a/src/main/java/com/xit/core/util/DateUtil.java +++ b/src/main/java/com/xit/core/util/DateUtil.java @@ -3,8 +3,10 @@ package com.xit.core.util; import org.apache.commons.lang3.StringUtils; import java.text.SimpleDateFormat; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.Date; @@ -18,6 +20,28 @@ import java.util.Date; public class DateUtil { + public static java.util.Date toDateFromLocalDate(LocalDate localDate){ + Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + //return java.sql.Date.valueOf(localDate); + } + + public static java.util.Date toDateFromLocalDateTime(LocalDateTime localDateTime){ + Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + //return java.sql.Timestamp.valueOf(localDateTime); + } + + public static LocalDate toLocalDateFromDate(Date date){ + return LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault()); + //return new java.sql.Date(date.getTime()).toLocalDate(); + } + + public static LocalDateTime toLocalDateTimeFromDate(Date date){ + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + //return new java.sql.Timestamp(date.getTime()).toLocalDateTime(); + } + /** * LocalDate 객체 반환 * diff --git a/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java b/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java index ea2feba..020d3be 100644 --- a/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java +++ b/src/test/java/com/xit/biz/ctgy/repository/IMinSimsa680RepositoryTest.java @@ -1,32 +1,80 @@ package com.xit.biz.ctgy.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.xit.core.util.DateUtil; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import javax.persistence.EntityManager; import javax.transaction.Transactional; +import java.sql.Date; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + import static com.xit.biz.ctgy.entity.QMinSimsa680.minSimsa680; +import static com.xit.biz.ctgy.entity.QMinSimsaUser680.minSimsaUser680; +import static com.xit.biz.ctgy.entity.QMinUserinfo.minUserinfo; import static org.junit.jupiter.api.Assertions.*; @SpringBootTest @Transactional +@ActiveProfiles({"dev"}) class IMinSimsa680RepositoryTest { @Autowired - private IMinSimsa680Repository iMinSimsa680Repository; + EntityManager em; + + private JPAQueryFactory queryFactory; @Autowired - private JPAQueryFactory jpaQueryFactory; + private IMinSimsa680Repository iMinSimsa680Repository; + + @BeforeEach + void beforeEach(){ + queryFactory = new JPAQueryFactory(em); + } + + @AfterEach + void afterEach(){ + } @Test - @DisplayName("wwwww") - void findMinSimsa680s2() { + @DisplayName("sim_result:심사목록에서 기간 클릭시") + void sim_result() { + + //LocalDate now = LocalDate.now(); + LocalDate now = LocalDate.of(2021, 12, 11); + LocalDate now2 = LocalDate.of(2021, 12, 12); + queryFactory + .select(minSimsa680.msSeq, + minSimsa680.msCarnum, + minSimsa680.msMaincode) + .from(minSimsaUser680) + .join(minSimsa680) + .on(minSimsa680.msMaincode.eq(minSimsaUser680.msuMaincode)) + .join(minUserinfo) + .on(minSimsaUser680.msuUserid.eq(minUserinfo.userid)) + .where(minSimsaUser680.msuTeam.eq(""), + minSimsa680.msChasu.eq(1L), + minSimsa680.msSdate.eq(java.sql.Date.valueOf(now)), + minSimsa680.msEdate.eq(java.sql.Date.valueOf(now2))) + .groupBy(minSimsa680.msCarnum, + minSimsa680.msSeq, + minSimsa680.msMaincode) + .orderBy(minSimsa680.msSeq.asc()) + .offset(0L) + .limit(10L) + //, minSimsa680.msSdate.eq(java.sql.Date.valueOf(now))) + .fetchResults(); // jpaQueryFactory.selectFrom(minSimsa680) // .leftJoin(minSimsa680.msMaincode, minSimsaUser680).fetchJoin() // .groupBy(minSimsa680.msEdate, minSimsaUser680.msuTeam, qMinUserinfo.name) @@ -36,4 +84,14 @@ class IMinSimsa680RepositoryTest { } + +// @BeforeAll +// void beforeAll(){ +// log.debug("initializing..."); +// } + +// @AfterAll +// void afterAll(){ +// log.debug("...shutdown"); +// } } \ No newline at end of file diff --git a/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java b/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java index 069ea25..4581f67 100644 --- a/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java +++ b/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java @@ -52,6 +52,6 @@ public class RepositoryTest { MinSimsa680 simsa680 = queryFactory.selectFrom(minSimsa680) .where(minSimsa680.msMaincode.eq(300297013L)) .fetchOne(); - log.debug("##################################{}",simsa680); + System.out.println("##################################"+simsa680); } }