package com.ssj.service.sys.fx.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.fx.domain.MaterielHome;
import com.ssj.bean.sys.sort.domain.Sort;
import com.ssj.dao.sys.fx.dao.MaterielHomeDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.persistence.DynamicSpecifications;
import com.ssj.framework.core.persistence.SearchFilter;
import com.ssj.service.sys.fx.service.MaterielHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

@Service(version="1.0")
@Transactional
public class MaterielHomeServiceImpl extends BaseServiceImpl<MaterielHome,String> implements MaterielHomeService {

    @Autowired
    private MaterielHomeDao dao;

    @Override
    public PagingAndSortingRepository<MaterielHome, String> getDao() {
        return dao;
    }

    @Override
    public Page<MaterielHome> findByPage(Map<String, Object> params, Pageable sp) throws Exception {
        Map<String, SearchFilter> filters = SearchFilter.parse(params);
        Specification<MaterielHome> specification = DynamicSpecifications.bySearchFilter(filters.values(), MaterielHome.class);
        return dao.findAll(specification, sp);
    }

    @Override
    public List<MaterielHome> findByPid(String pid) {
        return dao.findByPid(pid);
    }
}
