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

import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanPotentialCustomerMapper;
import com.gic.haoban.manage.service.service.content.TabHaobanPotentialCustomerService;
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;

/**
 * 销售线索(TabHaobanPotentialCustomer)表服务实现类
 *
 * @author makejava
 * @since 2023-03-28 09:48:08
 */
@Service("tabHaobanPotentialCustomerService")
public class TabHaobanPotentialCustomerServiceImpl implements TabHaobanPotentialCustomerService {
    @Resource
    private TabHaobanPotentialCustomerMapper tabHaobanPotentialCustomerMapper;

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

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

    /**
     * 新增数据
     *
     * @param tabHaobanPotentialCustomer 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanPotentialCustomer insert(TabHaobanPotentialCustomer tabHaobanPotentialCustomer) {
        this.tabHaobanPotentialCustomerMapper.insert(tabHaobanPotentialCustomer);
        return tabHaobanPotentialCustomer;
    }

    /**
     * 修改数据
     *
     * @param tabHaobanPotentialCustomer 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanPotentialCustomer update(TabHaobanPotentialCustomer tabHaobanPotentialCustomer) {
        this.tabHaobanPotentialCustomerMapper.update(tabHaobanPotentialCustomer);
        return this.queryById(tabHaobanPotentialCustomer.getId());
    }

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