package com.liang.service.impl;

import com.liang.entity.PrjProjectrole;
import com.liang.dao.PrjProjectroleDao;
import com.liang.service.PrjProjectroleService;
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;
import java.util.Map;

/**
 * 项目角色(PrjProjectrole)表服务实现类
 *
 * @author makejava
 * @since 2023-03-28 17:50:27
 */
@Service("prjProjectroleService")
public class PrjProjectroleServiceImpl implements PrjProjectroleService {
    @Resource
    private PrjProjectroleDao prjProjectroleDao;

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

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

    /**
     * 新增数据
     *
     * @param prjProjectrole 实例对象
     * @return 实例对象
     */
    @Override
    public PrjProjectrole insert(PrjProjectrole prjProjectrole) {
        this.prjProjectroleDao.insert(prjProjectrole);
        return prjProjectrole;
    }

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

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

    @Override
    public List<Map<String, String>> getProjectRole() {
        return this.prjProjectroleDao.getProjectRole();
    }
}
