package com.liang.service.impl;

import com.liang.entity.BaseDegree;
import com.liang.dao.BaseDegreeDao;
import com.liang.service.BaseDegreeService;
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;

/**
 * (BaseDegree)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:17
 */
@Service("baseDegreeService")
public class BaseDegreeServiceImpl implements BaseDegreeService {
    @Resource
    private BaseDegreeDao baseDegreeDao;

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

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

    /**
     * 新增数据
     *
     * @param baseDegree 实例对象
     * @return 实例对象
     */
    @Override
    public BaseDegree insert(BaseDegree baseDegree) {
        this.baseDegreeDao.insert(baseDegree);
        return baseDegree;
    }

    /**
     * 修改数据
     *
     * @param baseDegree 实例对象
     * @return 实例对象
     */
    @Override
    public BaseDegree update(BaseDegree baseDegree) {
        this.baseDegreeDao.update(baseDegree);
        return this.queryById(baseDegree.getGenid());
    }

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

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