package com.liang.service.impl;

import com.liang.entity.PrjProjectcontacts;
import com.liang.dao.PrjProjectcontactsDao;
import com.liang.service.PrjProjectcontactsService;
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;

/**
 * (PrjProjectcontacts)表服务实现类
 *
 * @author makejava
 * @since 2023-02-16 08:28:41
 */
@Service("prjProjectcontactsService")
public class PrjProjectcontactsServiceImpl implements PrjProjectcontactsService {
    @Resource
    private PrjProjectcontactsDao prjProjectcontactsDao;

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

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

    /**
     * 新增数据
     *
     * @param prjProjectcontacts 实例对象
     * @return 实例对象
     */
    @Override
    public PrjProjectcontacts insert(PrjProjectcontacts prjProjectcontacts) {
        this.prjProjectcontactsDao.insert(prjProjectcontacts);
        return prjProjectcontacts;
    }

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

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