package com.liang.service.impl;

import com.liang.entity.BaseYkl;
import com.liang.dao.BaseYklDao;
import com.liang.service.BaseYklService;
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;

/**
 * (BaseYkl)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 11:46:02
 */
@Service("baseYklService")
public class BaseYklServiceImpl implements BaseYklService {
    @Resource
    private BaseYklDao baseYklDao;

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

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

    /**
     * 新增数据
     *
     * @param baseYkl 实例对象
     * @return 实例对象
     */
    @Override
    public BaseYkl insert(BaseYkl baseYkl) {
        this.baseYklDao.insert(baseYkl);
        return baseYkl;
    }

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

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

    @Override
    public List<BaseYkl> queryAll() {
        return this.baseYklDao.queryAll();
    }
}
