package com.liang.service.impl;

import com.liang.entity.BaseSpeciality;
import com.liang.dao.BaseSpecialityDao;
import com.liang.service.BaseSpecialityService;
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;

/**
 * 专业专长(BaseSpeciality)表服务实现类
 *
 * @author makejava
 * @since 2023-03-27 14:55:38
 */
@Service("baseSpecialityService")
public class BaseSpecialityServiceImpl implements BaseSpecialityService {
    @Resource
    private BaseSpecialityDao baseSpecialityDao;

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

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

    /**
     * 新增数据
     *
     * @param baseSpeciality 实例对象
     * @return 实例对象
     */
    @Override
    public BaseSpeciality insert(BaseSpeciality baseSpeciality) {
        this.baseSpecialityDao.insert(baseSpeciality);
        return baseSpeciality;
    }

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

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

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