package cn.iocoder.yudao.module.mes.dal.mysql.workteam;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.workteam.WorkTeamDetailDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 班组成员 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface WorkTeamDetailMapper extends BaseMapperX<WorkTeamDetailDO> {

    default PageResult<WorkTeamDetailDO> selectPage(PageParam reqVO, Long workTeamId) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WorkTeamDetailDO>()
                .eq(WorkTeamDetailDO::getWorkTeamId, workTeamId)
                .orderByDesc(WorkTeamDetailDO::getId));
    }

    default int deleteByWorkTeamId(Long workTeamId) {
        return delete(WorkTeamDetailDO::getWorkTeamId, workTeamId);
    }
    default List<WorkTeamDetailDO> selectBy(WorkTeamDetailDO detailDO) {
        return selectList(new LambdaQueryWrapperX<WorkTeamDetailDO>()
                .eqIfPresent(WorkTeamDetailDO::getUserId, detailDO.getUserId())
                .eqIfPresent(WorkTeamDetailDO::getUserRole, detailDO.getUserRole())
                .eqIfPresent(WorkTeamDetailDO::getWorkTeamId, detailDO.getWorkTeamId()));
    }
    default List<WorkTeamDetailDO> selectByTeamId(List<Long> teamIds) {
        return selectList(new LambdaQueryWrapperX<WorkTeamDetailDO>()
                .inIfPresent(WorkTeamDetailDO::getWorkTeamId, teamIds));
    }
    default List<WorkTeamDetailDO> getUserWorkTeamDetail(Long workerId, Integer userRole){
        return selectList(new LambdaQueryWrapperX<WorkTeamDetailDO>()
                .eqIfPresent(WorkTeamDetailDO::getUserRole, userRole)
                .eqIfPresent(WorkTeamDetailDO::getUserId, workerId));
    }
    default List<WorkTeamDetailDO> getDetailByWorkTeamIds(List<Long> workTeamIds){
        return selectList(new LambdaQueryWrapperX<WorkTeamDetailDO>()
                .in(workTeamIds!=null&& workTeamIds.size()>0,WorkTeamDetailDO::getWorkTeamId, workTeamIds));
    }
}