package com.liang.service.impl;

import com.liang.entity.BaseSubjectname;
import com.liang.dao.BaseSubjectnameDao;
import com.liang.service.BaseSubjectnameService;
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;

/**
 * (BaseSubjectname)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 10:54:02
 */
@Service("baseSubjectnameService")
public class BaseSubjectnameServiceImpl implements BaseSubjectnameService {
    @Resource
    private BaseSubjectnameDao baseSubjectnameDao;

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

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

    /**
     * 新增数据
     *
     * @param baseSubjectname 实例对象
     * @return 实例对象
     */
    @Override
    public BaseSubjectname insert(BaseSubjectname baseSubjectname) {
        this.baseSubjectnameDao.insert(baseSubjectname);
        return baseSubjectname;
    }

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

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

    /**
     * 获取所有数据
     *
     * @return
     */
    @Override
    public List<BaseSubjectname> queryAll() {
        return this.baseSubjectnameDao.queryAll();
    }

    @Override
    public List<BaseSubjectname> queryListById(String id) {
        return this.baseSubjectnameDao.queryListById(id);
    }

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