package com.liang.service.impl;

import com.liang.entity.BaseRequestcode;
import com.liang.dao.BaseRequestcodeDao;
import com.liang.service.BaseRequestcodeService;
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;
import java.util.List;

/**
 * (BaseRequestcode)表服务实现类
 *
 * @author makejava
 * @since 2023-03-03 22:31:21
 */
@Service("baseRequestcodeService")
public class BaseRequestcodeServiceImpl implements BaseRequestcodeService {
    @Resource
    private BaseRequestcodeDao baseRequestcodeDao;

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

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

    /**
     * 新增数据
     *
     * @param baseRequestcode 实例对象
     * @return 实例对象
     */
    @Override
    public BaseRequestcode insert(BaseRequestcode baseRequestcode) {
        this.baseRequestcodeDao.insert(baseRequestcode);
        return baseRequestcode;
    }

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

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

    @Override
    public List<BaseRequestcode> queryAll() {
        return this.baseRequestcodeDao.queryAll();
    }
}
