package com.liang.service.impl;

import com.liang.entity.BaseNation;
import com.liang.dao.BaseNationDao;
import com.liang.service.BaseNationService;
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;

/**
 * (BaseNation)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:15
 */
@Service("baseNationService")
public class BaseNationServiceImpl implements BaseNationService {
    @Resource
    private BaseNationDao baseNationDao;

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

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

    /**
     * 新增数据
     *
     * @param baseNation 实例对象
     * @return 实例对象
     */
    @Override
    public BaseNation insert(BaseNation baseNation) {
        this.baseNationDao.insert(baseNation);
        return baseNation;
    }

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

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

    @Override
    public List<BaseNation> queryAll() {
        return this.baseNationDao.queryAll();
    }

    @Override
    public List<BaseNation> getNationList(Map map) {
        return this.baseNationDao.getNationList(map);
    }

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