package com.liang.service.impl;

import com.liang.entity.PrjResponsible;
import com.liang.dao.PrjResponsibleDao;
import com.liang.service.PrjResponsibleService;
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;

/**
 * (PrjResponsible)表服务实现类
 *
 * @author makejava
 * @since 2023-02-16 08:28:41
 */
@Service("prjResponsibleService")
public class PrjResponsibleServiceImpl implements PrjResponsibleService {
    @Resource
    private PrjResponsibleDao prjResponsibleDao;

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

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

    /**
     * 新增数据
     *
     * @param prjResponsible 实例对象
     * @return 实例对象
     */
    @Override
    public PrjResponsible insert(PrjResponsible prjResponsible) {
        this.prjResponsibleDao.insert(prjResponsible);
        return prjResponsible;
    }

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

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