package com.liang.service.impl;

import com.liang.entity.PrjMember;
import com.liang.dao.PrjMemberDao;
import com.liang.service.PrjMemberService;
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;

/**
 * 项目人员(PrjMember)表服务实现类
 *
 * @author makejava
 * @since 2023-03-10 11:21:54
 */
@Service("prjMemberService")
public class PrjMemberServiceImpl implements PrjMemberService {
    @Resource
    private PrjMemberDao prjMemberDao;

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

    @Override
    public PrjMember queryByRyAndXm(String ryxm, Integer xm) {
        return this.prjMemberDao.queryByRyAndXm(ryxm, xm);
    }

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

    /**
     * 新增数据
     *
     * @param prjMember 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(PrjMember prjMember) {
        return this.prjMemberDao.insert(prjMember);
    }

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

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

    @Override
    public int deleteByXm(Integer xm) {
        return this.prjMemberDao.deleteByXm(xm);
    }

    @Override
    public List<PrjMember> getMemberList(Map map) {
        return this.prjMemberDao.getMemberList(map);
    }

    @Override
    public List<PrjMember> getMemberInfoList(Integer xm) {
        return this.prjMemberDao.getMemberInfoList(xm);
    }

    @Override
    public int insertBatch(List<PrjMember> memberList) {
        return this.prjMemberDao.insertBatch(memberList);
    }

    @Override
    public int batchDeleteByXm(List<Integer> xmList) {
        return this.prjMemberDao.batchDeleteByXm(xmList);
    }
}
