package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ThirdMapper;
import com.hc.business.model.Third;
import com.hc.business.service.ThirdService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 第三方用户表(Third)表服务实现类
 *
 * @author java
 * @since 2020-06-17 17:29:30
 */

@Service("thirdService")
public class ThirdServiceImpl implements ThirdService {

    private final ThirdMapper thirdMapper;

    public ThirdServiceImpl(ThirdMapper thirdMapper) {
        this.thirdMapper = thirdMapper;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param thirdId 主键
     * @return 实例对象
     */
    @Override
    public Third queryById(Integer thirdId) {
        return this.thirdMapper.selectByPrimaryKey(thirdId);
    }

    /**
     * 新增数据
     *
     * @param third 实例对象
     * @return 实例对象
     */
    @Override
    public Third insert(Third third) {
        this.thirdMapper.insert(third);
        return third;
    }

    /**
     * 修改数据
     *
     * @param third 实例对象
     * @return 实例对象
     */
    @Override
    public Third update(Third third) {
        this.thirdMapper.updateByPrimaryKeySelective(third);
        return this.queryById(third.getThirdId());
    }

    /**
     * 通过主键删除数据
     *
     * @param thirdId 主键
     * @return 是否成功
     */
    @Override
    public Boolean deleteById(Integer thirdId) {
        return this.thirdMapper.deleteByPrimaryKey(thirdId) > 0;
    }

    /**
     * 分页查询全部数据
     *
     * @param page
     * @param size
     * @return 实例对象数组
     */
    @Override
    public PageInfo queryPageAll(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Third> list = this.thirdMapper.selectAll();
        return new PageInfo(list);
    }

}