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

import cn.hutool.core.collection.CollUtil;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.PageHelperUtils;
import com.gic.haoban.manage.api.dto.licence.RenewalUserDTO;
import com.gic.haoban.manage.api.dto.qdto.licence.RenewalUserQDTO;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanRenewalUserMapper;
import com.gic.haoban.manage.service.entity.TabHaobanRenewalUser;
import com.gic.haoban.manage.service.service.TabHaobanRenewalUserService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

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

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

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

    @Override
    public void insertBatch(List<TabHaobanRenewalUser> tabHaobanRenewalUserList) {
        if (CollUtil.isEmpty(tabHaobanRenewalUserList)) {
            return;
        }
        this.tabHaobanRenewalUserMapper.insertBatch(tabHaobanRenewalUserList);
    }


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

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

    @Override
    public Page<RenewalUserDTO> getRenewalUserPage(RenewalUserQDTO qdto) {
        PageHelper.startPage(qdto);
        List<TabHaobanRenewalUser> page = tabHaobanRenewalUserMapper.getRenewalUserPage(qdto);
        return PageHelperUtils.changePageHelperToCurrentPage(page, RenewalUserDTO.class);
    }
}
