package com.liang.service.impl;

import com.liang.entity.BaseFoundation;
import com.liang.dao.BaseFoundationDao;
import com.liang.service.BaseFoundationService;
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;

/**
 * (BaseFoundation)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 11:25:09
 */
@Service("baseFoundationService")
public class BaseFoundationServiceImpl implements BaseFoundationService {
    @Resource
    private BaseFoundationDao baseFoundationDao;

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

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

    /**
     * 新增数据
     *
     * @param baseFoundation 实例对象
     * @return 实例对象
     */
    @Override
    public BaseFoundation insert(BaseFoundation baseFoundation) {
        this.baseFoundationDao.insert(baseFoundation);
        return baseFoundation;
    }

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

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

    @Override
    public List<BaseFoundation> queryAll() {
        return this.baseFoundationDao.queryAll();
    }

}
