diff --git a/src/main/java/com/eactive/eai/rms/data/entity/onl/inflow/InflowControlService.java b/src/main/java/com/eactive/eai/rms/data/entity/onl/inflow/InflowControlService.java index 9c1284f..d68c379 100644 --- a/src/main/java/com/eactive/eai/rms/data/entity/onl/inflow/InflowControlService.java +++ b/src/main/java/com/eactive/eai/rms/data/entity/onl/inflow/InflowControlService.java @@ -1,9 +1,6 @@ package com.eactive.eai.rms.data.entity.onl.inflow; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import javax.persistence.EntityManager; @@ -18,6 +15,7 @@ import org.springframework.stereotype.Service; import com.eactive.apim.portal.app.entity.QCredential; import com.eactive.eai.data.entity.onl.adapter.QAdapterGroup; +import com.eactive.eai.data.entity.onl.authserver.QClientEntity; import com.eactive.eai.data.entity.onl.inflow.InflowControl; import com.eactive.eai.data.entity.onl.inflow.InflowControlId; import com.eactive.eai.data.entity.onl.inflow.QInflowControl; @@ -29,7 +27,6 @@ import com.eactive.eai.rms.onl.manage.inflow.history.InflowControlHistoryManUISe import com.eactive.eai.rms.onl.manage.inflow.inflow.InflowControlManMapper; import com.querydsl.core.BooleanBuilder; import com.querydsl.core.Tuple; -import com.querydsl.core.types.OrderSpecifier; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -186,101 +183,67 @@ public class InflowControlService extends AbstractDataService findAllForClient(Pageable pageable, String searchName) { - QCredential qCredential = QCredential.credential; + + JPAQueryFactory jpaQueryFactory = new JPAQueryFactory(entityManager); QInflowControl qInflowControl = QInflowControl.inflowControl; + QClientEntity qClientEntity = QClientEntity.clientEntity; - // EMSADM: Credential 목록 및 건수 조회 - JPAQueryFactory emsFactory = new JPAQueryFactory(entityManagerForEMS); - BooleanBuilder credPredicate = new BooleanBuilder(); - if (!StringUtils.isEmpty(searchName)) { - credPredicate.and(qCredential.clientname.contains(searchName)); - } - - long totalCount = emsFactory - .select(qCredential.clientid.count()) - .from(qCredential) - .where(credPredicate) - .fetchOne(); - - List credList = emsFactory - .select(qCredential.clientid, qCredential.clientname) - .from(qCredential) - .where(credPredicate) - .orderBy(qCredential.clientname.asc()) + List tupleList = jpaQueryFactory + .select(qInflowControl, qClientEntity.clientid, qClientEntity.clientname) + .from(qClientEntity) + .leftJoin(qInflowControl) + .on(qInflowControl.id.type.eq(CLIENT_TYPE_INFLOW) + .and(qInflowControl.id.name.eq(qClientEntity.clientid))) + .where(qClientEntity.clientname.contains(searchName)) + .orderBy(qClientEntity.clientname.asc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); - if (credList.isEmpty()) { - return new PageImpl<>(Collections.emptyList(), pageable, totalCount); - } - - // AGWADM: 해당 clientId의 InflowControl 일괄 조회 - List clientIds = credList.stream() - .map(t -> t.get(qCredential.clientid)) - .collect(Collectors.toList()); - - Map inflowMap = new JPAQueryFactory(entityManager) - .selectFrom(qInflowControl) - .where(qInflowControl.id.type.eq(CLIENT_TYPE_INFLOW) - .and(qInflowControl.id.name.in(clientIds))) - .fetch() + List dtoList = tupleList .stream() - .collect(Collectors.toMap(ic -> ic.getId().getName(), ic -> ic)); - - // Java에서 병합 - List dtoList = credList.stream() - .map(tuple -> { - String clientId = tuple.get(qCredential.clientid); - InflowControl inflowControl = inflowMap.get(clientId); - InflowControlServiceDto dto; - if (inflowControl != null) { - dto = mapper.toDto(inflowControl); - } else { - dto = new InflowControlServiceDto(); - dto.setName(clientId); - dto.setType(CLIENT_TYPE_INFLOW); - } - dto.setDesc(tuple.get(qCredential.clientname)); - return dto; - }) + .map(tuple -> toDto(qClientEntity, qInflowControl, tuple)) .collect(Collectors.toList()); + long totalCount = jpaQueryFactory + .select(qClientEntity.clientname.count()) + .from(qClientEntity) + .where(qClientEntity.clientname.contains(searchName)) + .fetchOne(); return new PageImpl<>(dtoList, pageable, totalCount); } + private InflowControlServiceDto toDto(QClientEntity qClientEntity, QInflowControl qInflowControl, + Tuple tuple) { + InflowControlServiceDto dto = null; + if (tuple.get(qInflowControl) != null) + dto = mapper.toDto(tuple.get(qInflowControl)); + else { + dto = new InflowControlServiceDto(); + dto.setName(tuple.get(qClientEntity.clientid)); + dto.setType(CLIENT_TYPE_INFLOW); + } + dto.setDesc(tuple.get(qClientEntity.clientname)); + return dto; + } + public Page selectLogList(Pageable pageable, InflowControlHistoryManUISearch uiSearch) { QInflowControlLog qlog = QInflowControlLog.inflowControlLog; QInflowControlGroup qgroup = QInflowControlGroup.inflowControlGroup;