package com.liang.service.impl;

import com.liang.entity.BaseEducation;
import com.liang.dao.BaseEducationDao;
import com.liang.service.BaseEducationService;
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;
import java.util.Map;

/**
 * (BaseEducation)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:16
 */
@Service("baseEducationService")
public class BaseEducationServiceImpl implements BaseEducationService {
    @Resource
    private BaseEducationDao baseEducationDao;

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

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

    /**
     * 新增数据
     *
     * @param baseEducation 实例对象
     * @return 实例对象
     */
    @Override
    public BaseEducation insert(BaseEducation baseEducation) {
        this.baseEducationDao.insert(baseEducation);
        return baseEducation;
    }

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

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

    @Override
    public List<Map<String, String>> getEducationList() {
        return this.baseEducationDao.getEducationList();
    }
}
