package com.sysu.admin.controller.crop.images;


import com.querydsl.core.types.Predicate;
import com.sysu.admin.support.base.BaseService;
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CropImageService extends BaseService<CropImage, Long> {

    public List<CropImage> findByCropIds(List<Long> cropIds){
        QCropImage cropImage = QCropImage.cropImage;
        return mCropImageRepository.findAll(cropImage.cropId.in(cropIds), Sort.by(CropImage.FIELDS.cropId));
    }

    public List<CropImage> findByCropId(Long cropId){
        QCropImage cropImage = QCropImage.cropImage;
        Predicate predicate = cropImage.cropId.eq(cropId);
        return mCropImageRepository.findAll(predicate);
    }

    public List<CropImage> findByCropIdAndType(Long cropId, ImageType imageType){
        QCropImage cropImage = QCropImage.cropImage;
        Predicate predicate = cropImage.cropId.eq(cropId).and(cropImage.type.eq(imageType.ordinal()));
        return mCropImageRepository.findAll(predicate);
    }



    @Override
    public JpaPlusRepository<CropImage, Long> r() {
        return mCropImageRepository;
    }
}
