package com.wuban.tron.explore.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.dao.AddressRepository;
import com.wuban.tron.explore.entity.Address;
import com.wuban.tron.explore.entity.example.AddressExample;
import com.wuban.tron.explore.service.AddressService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <core>账户服务接口实现类</core>
 *
 * @author sky
 * @date 2020/11/02
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AddressServiceImpl implements AddressService {

    private final AddressRepository addressRepository;

    @Override
    public void batchInsertOnDuplicateKey(List<Address> records) {
        this.addressRepository.batchInsertOnDuplicateKey(records);
    }

    @Override
    public void updateById(Address record) {
        this.addressRepository.updateById(record);
    }

    /**
     * 获取账户地址信息
     *
     * @param example 查询条件参数
     * @return 记录
     */
    @Override
    public Address selectOneByExample(AddressExample example) {
        return this.addressRepository.selectOneByExample(example);
    }

    /**
     * 分页查询
     *
     * @param example 查询条件参数
     * @return 分页记录列表
     */
    @Override
    public PageInfo<Address> selectByPager(Integer startIndex,Integer pageSize, AddressExample example) {
        PageHelper.startPage(startIndex, pageSize);
        List<Address> list = this.addressRepository.selectByPager(example);
        PageInfo<Address> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Address> selectByExample(AddressExample example) {
        return this.addressRepository.selectByExample(example);
    }

    @Override
    public Integer countByPager() {
        return this.addressRepository.countByPager(null);
    }

}
