package com.liang.service.impl;

import com.liang.entity.BaseEconomicsector;
import com.liang.dao.BaseEconomicsectorDao;
import com.liang.service.BaseEconomicsectorService;
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;

/**
 * (BaseEconomicsector)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 11:45:27
 */
@Service("baseEconomicsectorService")
public class BaseEconomicsectorServiceImpl implements BaseEconomicsectorService {
    @Resource
    private BaseEconomicsectorDao baseEconomicsectorDao;

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

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

    /**
     * 新增数据
     *
     * @param baseEconomicsector 实例对象
     * @return 实例对象
     */
    @Override
    public BaseEconomicsector insert(BaseEconomicsector baseEconomicsector) {
        this.baseEconomicsectorDao.insert(baseEconomicsector);
        return baseEconomicsector;
    }

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

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

    @Override
    public List<BaseEconomicsector> queryAll() {
        return this.baseEconomicsectorDao.queryAll();
    }
}
