package com.gic.haoban.manage.service.service.impl;

import com.gic.haoban.manage.service.entity.TabHaobanRenewalUser;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanRenewalUserDao;
import com.gic.haoban.manage.service.service.TabHaobanRenewalUserService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TabHaobanRenewalUser)表服务实现类
 *
 * @author makejava
 * @since 2023-06-08 15:11:49
 */
@Service("tabHaobanRenewalUserService")
public class TabHaobanRenewalUserServiceImpl implements TabHaobanRenewalUserService {
    @Resource
    private TabHaobanRenewalUserDao tabHaobanRenewalUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param renewalId 主键
     * @return 实例对象
     */
    @Override
    public TabHaobanRenewalUser queryById(Long renewalId) {
        return this.tabHaobanRenewalUserDao.queryById(renewalId);
    }

    /**
     * 分页查询
     *
     * @param tabHaobanRenewalUser 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TabHaobanRenewalUser> queryByPage(TabHaobanRenewalUser tabHaobanRenewalUser, PageRequest pageRequest) {
        long total = this.tabHaobanRenewalUserDao.count(tabHaobanRenewalUser);
        return new PageImpl<>(this.tabHaobanRenewalUserDao.queryAllByLimit(tabHaobanRenewalUser, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tabHaobanRenewalUser 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanRenewalUser insert(TabHaobanRenewalUser tabHaobanRenewalUser) {
        this.tabHaobanRenewalUserDao.insert(tabHaobanRenewalUser);
        return tabHaobanRenewalUser;
    }

    /**
     * 修改数据
     *
     * @param tabHaobanRenewalUser 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanRenewalUser update(TabHaobanRenewalUser tabHaobanRenewalUser) {
        this.tabHaobanRenewalUserDao.update(tabHaobanRenewalUser);
        return this.queryById(tabHaobanRenewalUser.getRenewalId());
    }

    /**
     * 通过主键删除数据
     *
     * @param renewalId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long renewalId) {
        return this.tabHaobanRenewalUserDao.deleteById(renewalId) > 0;
    }
}
