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

import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper;
import com.gic.haoban.manage.service.service.content.TabHaobanInteractRecordService;
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;

/**
 * 互动记录明细(TabHaobanInteractRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-03-28 10:32:48
 */
@Service("tabHaobanInteractRecordService")
public class TabHaobanInteractRecordServiceImpl implements TabHaobanInteractRecordService {
    @Resource
    private TabHaobanInteractRecordMapper tabHaobanInteractRecordMapper;

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

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

    /**
     * 新增数据
     *
     * @param tabHaobanInteractRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TabHaobanInteractRecord insert(TabHaobanInteractRecord tabHaobanInteractRecord) {
        this.tabHaobanInteractRecordMapper.insert(tabHaobanInteractRecord);
        return tabHaobanInteractRecord;
    }

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

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