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

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.wallet.domain.Wallet;
import com.ssj.dao.sys.wallet.dao.WalletDao;
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.wallet.service.WalletService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author Mount Liu
 * @date 2018/11/19
 */
@Service(version ="1.0")
@Transactional
public class WalletServiceImpl extends BaseServiceImpl<Wallet, String> implements WalletService {

    private   Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WalletDao dao;

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

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

    @Override
    public Wallet findByUserId(String userId) {
        return dao.findByUserId(userId);
    }
}
