AdItemQueryRepository { @Transactional(readOnly = true) public List<AdBondDto> createAdBondDto(LocalDate startDate, LocalDate endDate, List<String> orderTypes) { if(CollectionUtils.isEmpty(orderTypes)) { return new ArrayList<>(); } return queryFactory .select(Projections.fields(AdBondDto.class, adItem.amount.sum().as("amount"), adItem.txDate, adItem.orderType, adItem.customer.id.as("customerId")) ) .from(adItem) .where(adItem.orderType.in(orderTypes) .and(adItem.txDate.between(startDate, endDate))) .groupBy(adItem.orderType, adItem.txDate, adItem.customer) .fetch(); }  @Transactional(readOnly = true) List<AdBond> createAdBond(LocalDate startDate, LocalDate endDate, List<String> orderTypes); @Transactional(readOnly = true) List<AdBondDto> createAdBondDto(LocalDate startDate, LocalDate endDate, List<String> orderTypes);  }
@Test void ad_item을_통해_ad_bond를_생성한다2() throws Exception { Shop shop = shopRepository.save(new Shop("no", "name")); Customer customer = customerRepository.save(new Customer("no", "name", "bizNo", "ceo", shop)); LocalDate startDate = LocalDate.of(2020,8,11); LocalDate endDate = LocalDate.of(2020,8,12); String orderType1 = "a"; String orderType2 = "b"; adItemRepository.save(new AdItem(orderType1, startDate, "1", 1000L, customer)); adItemRepository.save(new AdItem(orderType2, endDate, "2", 2000L, customer)); List<AdBondDto> adBondDtos = queryRepository.createAdBondDto(startDate, endDate, Arrays.asList(orderType1, orderType2)); assertThat(adBondDtos).hasSize(2); }