package com.ecep.contract.service;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.PermissionViewModel;
import com.ecep.contract.vo.PermissionVo;

@Service
@CacheConfig(cacheNames = "permission")
public class PermissionService extends QueryService<PermissionVo, PermissionViewModel> {

    @Cacheable(key = "#p0")
    @Override
    public PermissionVo findById(Integer id) {
        return super.findById(id);
    }

    @Caching(evict = { @CacheEvict(key = "#p0.id") })
    @Override
    public PermissionVo save(PermissionVo entity) {
        return super.save(entity);
    }

    @Caching(evict = { @CacheEvict(key = "#p0.id") })
    @Override
    public void delete(PermissionVo entity) {
        super.delete(entity);
    }

    public List<PermissionVo> findByFunctionId(int functionId) {
        return findAll(ParamUtils.builder().equals("null", functionId).build(), Pageable.unpaged()).getContent();
    }

}
