From 09d9e55aff63634c1ddf55fb296b09f2202b3d7f Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Sun, 3 Apr 2022 05:39:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B1=B0=EC=A3=BC=EC=9E=90=EC=8B=AC?= =?UTF-8?q?=EC=9D=98=EA=B4=80=EB=A6=AC=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xit/biz/ctgy/CtgyConstants.java | 10 + .../ctgy/controller/ResidentController.java | 6 +- .../com/xit/biz/ctgy/dto/GnRecallScDto.java | 12 ++ .../repository/IResidentRepositoryCustom.java | 2 + .../repository/IResidentRepositoryImpl.java | 186 +++++++++++++----- .../biz/ctgy/service/IResidentService.java | 4 +- .../ctgy/service/impl/ResidentService.java | 16 +- .../java/com/xit/core/api/RestResponse.java | 27 +-- .../ctgy/repository/RecallRepositoryTest.java | 33 +++- 9 files changed, 226 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/xit/biz/ctgy/CtgyConstants.java b/src/main/java/com/xit/biz/ctgy/CtgyConstants.java index 57eb576..694537f 100644 --- a/src/main/java/com/xit/biz/ctgy/CtgyConstants.java +++ b/src/main/java/com/xit/biz/ctgy/CtgyConstants.java @@ -75,6 +75,16 @@ public class CtgyConstants { private final String desc; } + @Getter + @AllArgsConstructor + public enum Resident { + DATAGB_1("1", ""), + DATAGB_2("2", "") + ; + private final String code; + private final String desc; + } + @Getter @AllArgsConstructor public enum PublicBoard { diff --git a/src/main/java/com/xit/biz/ctgy/controller/ResidentController.java b/src/main/java/com/xit/biz/ctgy/controller/ResidentController.java index 2759a54..153f3af 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/ResidentController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/ResidentController.java @@ -43,11 +43,11 @@ public class ResidentController { @Operation(summary = "거주자의견진술 상세" , description = "거주자의견진술 상세") @Parameters({ - @Parameter(in = ParameterIn.PATH, name = "scCode", description = "의견진술번호", required = true, example = "3326"), + @Parameter(in = ParameterIn.PATH, name = "scCode", description = "의견진술번호", required = true, example = "3778"), }) @GetMapping(value = "/{scCode}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity findByScCode(@PathVariable final Long scCode) { - return RestResponse.of(service.findByScCode(scCode)); + public ResponseEntity findResident(@PathVariable final Long scCode) { + return RestResponse.of(service.findResident(scCode)); } } diff --git a/src/main/java/com/xit/biz/ctgy/dto/GnRecallScDto.java b/src/main/java/com/xit/biz/ctgy/dto/GnRecallScDto.java index 0d09066..398197e 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/GnRecallScDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/GnRecallScDto.java @@ -117,4 +117,16 @@ public class GnRecallScDto { @Schema(title = " ", example = " ", description = " ") private String scBunji; + @Schema(required = true, title = " ", example = " ", description = " ") + private String scContDocNm; + + @Schema(required = true, title = " ", example = " ", description = " ") + private String scIngbNm; + + @Schema(required = true, title = " ", example = " ", description = " ") + private String scTransferNm; + + @Schema(required = true, title = " ", example = " ", description = " ") + private String scStateNm; + } diff --git a/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryCustom.java b/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryCustom.java index cb1de6a..02da500 100644 --- a/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryCustom.java +++ b/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryCustom.java @@ -13,4 +13,6 @@ import java.util.List; public interface IResidentRepositoryCustom { Page findResidents(Pageable pageable); + GnRecallScDto findResident(Long scCode); + } diff --git a/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryImpl.java b/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryImpl.java index d8dfe88..382cd2a 100644 --- a/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryImpl.java +++ b/src/main/java/com/xit/biz/ctgy/repository/IResidentRepositoryImpl.java @@ -1,16 +1,22 @@ package com.xit.biz.ctgy.repository; +import com.querydsl.core.BooleanBuilder; import com.querydsl.core.QueryResults; import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.Projections; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.xit.biz.ctgy.CtgyConstants; import com.xit.biz.ctgy.dto.GnRecallScDto; +import com.xit.core.util.Checks; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import java.util.ArrayList; +import java.util.List; + import static com.xit.biz.cmm.entity.QCmmCodeS.cmmCodeS; import static com.xit.biz.ctgy.entity.QGnRecallSc.gnRecallSc; @@ -22,50 +28,142 @@ public class IResidentRepositoryImpl implements IResidentRepositoryCustom { @Override public Page findResidents(Pageable pageable) { -// BooleanBuilder builder = new BooleanBuilder(); -// if (!Checks.isEmpty(pMinSimsa680GroupDto.getMsYear())) { -// builder.and(minSimsa680.msYear.eq(pMinSimsa680GroupDto.getMsYear())); -// } -// if (!Checks.isEmpty(pMinSimsa680GroupDto.getMsChasu())) { -// builder.and(minSimsa680.msChasu.like(String.valueOf(pMinSimsa680GroupDto.getMsChasu()))); -// } - QueryResults rslt = - queryFactory - .select(Projections.fields( - GnRecallScDto.class, - gnRecallSc.scCode, - gnRecallSc.scSeq, - gnRecallSc.scCarnum, - gnRecallSc.scDong, - gnRecallSc.scName, - gnRecallSc.scContDoc, - gnRecallSc.scIngb, - gnRecallSc.scDatagb, - gnRecallSc.scCdate, - ExpressionUtils.as( - JPAExpressions.select(cmmCodeS.codeNm) - .from(cmmCodeS) - .where(gnRecallSc.scContDoc.eq(cmmCodeS.codeCd),cmmCodeS.codeGrpId.eq("TRAFFIC"), - cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), - cmmCodeS.codeMcd.eq("SC_CONT_DOC")), - "scContDocNm"), - ExpressionUtils.as( - JPAExpressions.select(cmmCodeS.codeNm) - .from(cmmCodeS) - .where(gnRecallSc.scIngb.eq(cmmCodeS.codeCd),cmmCodeS.codeGrpId.eq("TRAFFIC"), - cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), - cmmCodeS.codeMcd.eq("RC_INGB")), - "scIngbNm") - )) - .from(gnRecallSc) - //.where(builder) - //.groupBy(minSimsa680.msYear, minSimsa680.msChasu, minSimsa680.msSdate, minSimsa680.msStartsi, minSimsa680.msEdate, minSimsa680.msCdate, minSimsa680.msClosesi) - //.orderBy(minSimsa680.msYear.desc(), minSimsa680.msChasu.desc()) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetchResults(); + // 커버링 인덱스로 대상 조회 + QueryResults scCodeList = queryFactory + .select(gnRecallSc.scCode) + .from(gnRecallSc) + .where(gnRecallSc.scDatagb.eq(CtgyConstants.Resident.DATAGB_1.getCode())) + .orderBy(gnRecallSc.scCode.desc()) + .offset(pageable.getPageSize()) + .limit(pageable.getPageSize()) + .fetchResults(); + + // 대상이 없을 경우 추가 쿼리 수행 할 필요 없이 바로 반환 + if (Checks.isEmpty(scCodeList)) { + new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + List rslt = queryFactory + .select(Projections.fields( + GnRecallScDto.class, + gnRecallSc.scCode, + gnRecallSc.scSeq, + gnRecallSc.scCarnum, + gnRecallSc.scDong, + gnRecallSc.scName, + gnRecallSc.scContDoc, + gnRecallSc.scIngb, + gnRecallSc.scDatagb, + gnRecallSc.scCdate, + ExpressionUtils.as( + JPAExpressions.select(cmmCodeS.codeNm) + .from(cmmCodeS) + .where(gnRecallSc.scContDoc.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), + cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), + cmmCodeS.codeMcd.eq("SC_CONT_DOC")), + "scContDocNm"), + ExpressionUtils.as( + JPAExpressions.select(cmmCodeS.codeNm) + .from(cmmCodeS) + .where(gnRecallSc.scIngb.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), + cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), + cmmCodeS.codeMcd.eq("RC_INGB")), + "scIngbNm") + )) + .from(gnRecallSc) + .where(gnRecallSc.scCode.in(scCodeList.getResults())) + .orderBy(gnRecallSc.scCode.desc()) + .fetch(); + return new PageImpl<>(rslt, pageable, scCodeList.getTotal()); + } + + @Override + public GnRecallScDto findResident(Long scCode) { + BooleanBuilder builder = new BooleanBuilder(); + builder.and(gnRecallSc.scDatagb.eq(CtgyConstants.Resident.DATAGB_1.getCode())); + builder.and(gnRecallSc.scCode.eq(scCode)); - return new PageImpl<>(rslt.getResults(), pageable, rslt.getTotal()); + return queryFactory + .select(Projections.fields( + GnRecallScDto.class, + gnRecallSc.scCode, + gnRecallSc.scSeq, + gnRecallSc.scCarnum, + gnRecallSc.scName, + gnRecallSc.scDong, + gnRecallSc.scContDoc, + gnRecallSc.scCdate, + gnRecallSc.scIngb, + gnRecallSc.scWdate, + gnRecallSc.scJbtime, + gnRecallSc.scPos, + gnRecallSc.scFrecad1, + gnRecallSc.scFrecad2, + gnRecallSc.scFrecad3, + gnRecallSc.scFrecad4, + gnRecallSc.scContad1, + gnRecallSc.scContad2, + gnRecallSc.scContad3, + gnRecallSc.scContad4, + gnRecallSc.scContad5, + gnRecallSc.scContad6, + gnRecallSc.scContad7, + gnRecallSc.scContad8, + gnRecallSc.scPicad1, + gnRecallSc.scPicad2, + gnRecallSc.scPicad3, + gnRecallSc.scPicad4, + gnRecallSc.scTransfer, + gnRecallSc.scAnswer, + gnRecallSc.scState, + gnRecallSc.zipcode1, + gnRecallSc.zipcode2, + gnRecallSc.scJuso, + gnRecallSc.scBunji, + ExpressionUtils.as( + JPAExpressions.select(cmmCodeS.codeNm) + .from(cmmCodeS) + .where(gnRecallSc.scContDoc.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), + cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), + cmmCodeS.codeMcd.eq("SC_CONT_DOC")), + "scContDocNm"), + ExpressionUtils.as( + JPAExpressions.select(cmmCodeS.codeNm) + .from(cmmCodeS) + .where(gnRecallSc.scIngb.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), + cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), + cmmCodeS.codeMcd.eq("RC_INGB")), + "scIngbNm") +// ExpressionUtils.as( +// JPAExpressions.select(cmmCodeS.codeNm) +// .from(cmmCodeS) +// .where(gnRecallSc.scIngb.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), +// cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), +// cmmCodeS.codeMcd.eq("SC_TRANSFER")), +// "scTransferNm"), +// ExpressionUtils.as( +// JPAExpressions.select(cmmCodeS.codeNm) +// .from(cmmCodeS) +// .where(gnRecallSc.scIngb.eq(cmmCodeS.codeCd), cmmCodeS.codeGrpId.eq("TRAFFIC"), +// cmmCodeS.codeLcd.eq("GANGNAM_SIMSA"), +// cmmCodeS.codeMcd.eq("SC_STATE")), +// "scStateNm") + )) + .from(gnRecallSc) + .where(builder) + .fetchOne(); +/* +SELECT SC_CODE, SC_SEQ, SC_CARNUM, SC_NAME, SC_DONG, +GET_RECALL_CONTID(SC_CONT_DOC) SC_CONT_DOC, SC_CDATE, GET_RECALL_INGB_STR(SC_INGB) SC_INGB, SC_WDATE, SC_JBTIME, +SC_POS, SC_FRECAD1, SC_FRECAD2, SC_FRECAD3, SC_FRECAD4, +SC_CONTAD1, SC_CONTAD2, SC_CONTAD3, SC_CONTAD4, SC_CONTAD5, +SC_CONTAD6, SC_CONTAD7, SC_CONTAD8, SC_PICAD1, SC_PICAD2, +SC_PICAD3, SC_PICAD4, (SELECT CDNAME FROM MIN_MAINCODE WHERE C2='6' AND C3=SC_TRANSFER) SC_TRANSFER, SC_ANSWER, +(SELECT CDNAME FROM MIN_MAINCODE WHERE C2='7' AND C3=SC_STATE) SC_STATE, ZIPCODE1, ZIPCODE2, SC_JUSO, SC_BUNJI +FROM GN_RECALL_SC +WHERE SC_DATAGB = '1' +AND SC_CODE = + */ } -} +} \ No newline at end of file diff --git a/src/main/java/com/xit/biz/ctgy/service/IResidentService.java b/src/main/java/com/xit/biz/ctgy/service/IResidentService.java index 27039e9..e8aa266 100644 --- a/src/main/java/com/xit/biz/ctgy/service/IResidentService.java +++ b/src/main/java/com/xit/biz/ctgy/service/IResidentService.java @@ -11,7 +11,7 @@ public interface IResidentService { Page findResidents(Pageable pageable); - Page findAll(GnRecallSc entity, Pageable pageable); + GnRecallScDto findResident(Long scCode); - GnRecallSc findByScCode(Long scCode); + Page findAll(GnRecallSc entity, Pageable pageable); } diff --git a/src/main/java/com/xit/biz/ctgy/service/impl/ResidentService.java b/src/main/java/com/xit/biz/ctgy/service/impl/ResidentService.java index 5a806f8..5ee145f 100644 --- a/src/main/java/com/xit/biz/ctgy/service/impl/ResidentService.java +++ b/src/main/java/com/xit/biz/ctgy/service/impl/ResidentService.java @@ -27,6 +27,12 @@ public class ResidentService implements IResidentService { return page; } + @Override + @Transactional(readOnly = true) + public GnRecallScDto findResident(Long scCode) { + return repository.findResident(scCode); + } + @Override @Transactional(readOnly = true) public Page findAll(GnRecallSc entity, Pageable pageable) { @@ -34,8 +40,8 @@ public class ResidentService implements IResidentService { pageable = JpaUtil.getPagingInfo(pageable); // pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("inCode").descending()) ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll(); - //.withMatcher("inTitle", contains()) - //.withMatcher("inName", contains()); + //.withMatcher("inTitle", contains()) + //.withMatcher("inName", contains()); Example example = Example.of(entity, exampleMatcher); Page page = repository.findAll( example, @@ -43,10 +49,4 @@ public class ResidentService implements IResidentService { // List userList = page.getContent(); return page; } - - @Override - @Transactional(readOnly = true) - public GnRecallSc findByScCode(Long scCode) { - return repository.findByScCode(scCode); - } } diff --git a/src/main/java/com/xit/core/api/RestResponse.java b/src/main/java/com/xit/core/api/RestResponse.java index cbe2047..d75b271 100644 --- a/src/main/java/com/xit/core/api/RestResponse.java +++ b/src/main/java/com/xit/core/api/RestResponse.java @@ -56,23 +56,28 @@ public class RestResponse implements IRestResponse, Serializable { this.message = new RestMessage(SUCCESS, SUCCESS_MESSAGE); this.data = data; - // Pageing 처리 - if(Page.class.isAssignableFrom(data.getClass())){ + if(data == null){ + this.count = 0; - Page page = (Page)data; + }else { + // Pageing 처리 + if (Page.class.isAssignableFrom(data.getClass())) { - //noinspection unchecked - this.data = (T) page.getContent(); - this.paginator = new Paginator(page.getPageable().getPageNumber(), page.getSize(), Integer.parseInt(String.valueOf(page.getTotalElements())));// paginator.getTotalPages + Page page = (Page) data; - this.count = paginator.getTotalCount(); + //noinspection unchecked + this.data = (T) page.getContent(); + this.paginator = new Paginator(page.getPageable().getPageNumber(), page.getSize(), Integer.parseInt(String.valueOf(page.getTotalElements())));// paginator.getTotalPages - }else { - if (Collection.class.isAssignableFrom(data.getClass())) { - this.count = (((Collection) data).size()); + this.count = paginator.getTotalCount(); } else { - this.count = 1; + if (Collection.class.isAssignableFrom(data.getClass())) { + this.count = (((Collection) data).size()); + + } else { + this.count = 1; + } } } } diff --git a/src/test/java/com/xit/biz/ctgy/repository/RecallRepositoryTest.java b/src/test/java/com/xit/biz/ctgy/repository/RecallRepositoryTest.java index d5d5593..16024f6 100644 --- a/src/test/java/com/xit/biz/ctgy/repository/RecallRepositoryTest.java +++ b/src/test/java/com/xit/biz/ctgy/repository/RecallRepositoryTest.java @@ -1,6 +1,9 @@ package com.xit.biz.ctgy.repository; +import com.querydsl.core.types.Expression; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.xit.biz.ctgy.entity.QGnRecallSc; +import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -10,11 +13,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import javax.persistence.EntityManager; -import javax.persistence.Tuple; import javax.transaction.Transactional; +import java.lang.reflect.Modifier; import java.sql.Date; import java.time.LocalDate; -import java.util.Map; +import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; import static com.xit.biz.ctgy.entity.QMinSimsa680.minSimsa680; @@ -24,6 +28,7 @@ import static com.xit.biz.ctgy.entity.QMinUserinfo.minUserinfo; @SpringBootTest @Transactional @ActiveProfiles({"dev"}) +@Slf4j class RecallRepositoryTest { @Autowired @@ -40,6 +45,30 @@ class RecallRepositoryTest { void afterEach(){ } + @Test + void dddd(){ + QGnRecallSc qGnRecallSc = QGnRecallSc.gnRecallSc; + final List> columns = Arrays.stream(QGnRecallSc.class.getDeclaredFields()) + .filter(field -> !Modifier.isStatic(field.getModifiers())) + .map(field -> { + try { + return (Expression) field.get(qGnRecallSc); + } + catch (final Exception e) { + log.trace("should never happen", e); + return null; + } + }) + .collect(Collectors.toList()); + + log.debug("{}", qGnRecallSc); + + + +// Adding transient fields + // CollectionUtils.addAll(columns, new Expression[] { qOtherBean, qStupidJoinBean }); + } + @Test @DisplayName("sim_result:심사목록에서 기간 클릭시") void sim_reg() {