package com.liang.service.impl;

import com.liang.entity.BasePstasortcode;
import com.liang.dao.BasePstasortcodeDao;
import com.liang.service.BasePstasortcodeService;
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;

/**
 * (BasePstasortcode)表服务实现类
 *
 * @author makejava
 * @since 2023-03-04 13:44:02
 */
@Service("basePstasortcodeService")
public class BasePstasortcodeServiceImpl implements BasePstasortcodeService {
    @Resource
    private BasePstasortcodeDao basePstasortcodeDao;

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

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

    /**
     * 新增数据
     *
     * @param basePstasortcode 实例对象
     * @return 实例对象
     */
    @Override
    public BasePstasortcode insert(BasePstasortcode basePstasortcode) {
        this.basePstasortcodeDao.insert(basePstasortcode);
        return basePstasortcode;
    }

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

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

    @Override
    public List<BasePstasortcode> queryAll() {
        return this.basePstasortcodeDao.queryAll();
    }
}
