| 12345678910111213141516171819202122232425262728293031323334353637 |
- package com.izouma.nineth.service;
- import com.izouma.nineth.domain.PurchaseLevel;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.dto.PageWrapper;
- import com.izouma.nineth.repo.PurchaseLevelRepo;
- import com.izouma.nineth.utils.JpaUtils;
- import lombok.AllArgsConstructor;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.data.domain.Page;
- import org.springframework.stereotype.Service;
- @Service
- @AllArgsConstructor
- public class PurchaseLevelService {
- private PurchaseLevelRepo purchaseLevelRepo;
- @Cacheable(value = "purchaseLevelList", key = "#pageQuery.hashCode()")
- public PageWrapper<PurchaseLevel> all(PageQuery pageQuery) {
- Page<PurchaseLevel> page = purchaseLevelRepo.findAll(JpaUtils.toSpecification(pageQuery, PurchaseLevel.class), JpaUtils.toPageRequest(pageQuery));
- return new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
- page.getPageable().getPageSize(), page.getTotalElements());
- }
- public PurchaseLevel findPurchaseLevelByLevel(int level) {
- int maxStartLevel = purchaseLevelRepo.findMaxStartLevel();
- PurchaseLevel purchaseLevel;
- if (level >= maxStartLevel) {
- purchaseLevel = purchaseLevelRepo.findByStartLevel(maxStartLevel);
- } else {
- purchaseLevel = purchaseLevelRepo.findByLevel(level);
- }
- return purchaseLevel;
- }
- }
|