package com.liang.service.impl;

import com.liang.entity.BaseSchool;
import com.liang.dao.BaseSchoolDao;
import com.liang.service.BaseSchoolService;
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;

/**
 * (BaseSchool)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:14
 */
@Service("baseSchoolService")
public class BaseSchoolServiceImpl implements BaseSchoolService {
    @Resource
    private BaseSchoolDao baseSchoolDao;

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

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

    /**
     * 新增数据
     *
     * @param baseSchool 实例对象
     * @return 实例对象
     */
    @Override
    public BaseSchool insert(BaseSchool baseSchool) {
        this.baseSchoolDao.insert(baseSchool);
        return baseSchool;
    }

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

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

    @Override
    public List<BaseSchool> queryAll() {
        return this.baseSchoolDao.queryAll();
    }
}
