package com.liang.service.impl;

import com.liang.entity.BaseCompanytype;
import com.liang.dao.BaseCompanytypeDao;
import com.liang.service.BaseCompanytypeService;
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;

/**
 * (BaseCompanytype)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 11:00:04
 */
@Service("baseCompanytypeService")
public class BaseCompanytypeServiceImpl implements BaseCompanytypeService {
    @Resource
    private BaseCompanytypeDao baseCompanytypeDao;

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

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

    /**
     * 新增数据
     *
     * @param baseCompanytype 实例对象
     * @return 实例对象
     */
    @Override
    public BaseCompanytype insert(BaseCompanytype baseCompanytype) {
        this.baseCompanytypeDao.insert(baseCompanytype);
        return baseCompanytype;
    }

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

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

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