package com.liang.service.impl;

import com.liang.entity.BaseMost;
import com.liang.dao.BaseMostDao;
import com.liang.service.BaseMostService;
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;

/**
 * (BaseMost)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 11:25:23
 */
@Service("baseMostService")
public class BaseMostServiceImpl implements BaseMostService {
    @Resource
    private BaseMostDao baseMostDao;

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

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

    /**
     * 新增数据
     *
     * @param baseMost 实例对象
     * @return 实例对象
     */
    @Override
    public BaseMost insert(BaseMost baseMost) {
        this.baseMostDao.insert(baseMost);
        return baseMost;
    }

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

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

    @Override
    public List<BaseMost> queryAll() {
        return this.baseMostDao.queryAll();
    }

}
