package com.liang.service.impl;

import com.liang.entity.BaseLanguage;
import com.liang.dao.BaseLanguageDao;
import com.liang.service.BaseLanguageService;
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;

/**
 * (BaseLanguage)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:16
 */
@Service("baseLanguageService")
public class BaseLanguageServiceImpl implements BaseLanguageService {
    @Resource
    private BaseLanguageDao baseLanguageDao;

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

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

    /**
     * 新增数据
     *
     * @param baseLanguage 实例对象
     * @return 实例对象
     */
    @Override
    public BaseLanguage insert(BaseLanguage baseLanguage) {
        this.baseLanguageDao.insert(baseLanguage);
        return baseLanguage;
    }

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

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

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