package com.liang.service.impl;

import com.liang.entity.SysConfigure;
import com.liang.dao.SysConfigureDao;
import com.liang.service.SysConfigureService;
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;

/**
 * (SysConfigure)表服务实现类
 *
 * @author makejava
 * @since 2023-02-19 22:18:24
 */
@Service("sysConfigureService")
public class SysConfigureServiceImpl implements SysConfigureService {
    @Resource
    private SysConfigureDao sysConfigureDao;

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

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

    /**
     * 新增数据
     *
     * @param sysConfigure 实例对象
     * @return 实例对象
     */
    @Override
    public SysConfigure insert(SysConfigure sysConfigure) {
        this.sysConfigureDao.insert(sysConfigure);
        return sysConfigure;
    }

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

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