package cn.iocoder.yudao.module.pms.dal.mysql.iotdeviceperson;

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.pms.controller.admin.iotdeviceperson.vo.IotDevicePersonPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceperson.IotDevicePersonDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
 * 设备负责人分配 Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface IotDevicePersonMapper extends BaseMapperX<IotDevicePersonDO> {

    default PageResult<IotDevicePersonDO> selectPage(IotDevicePersonPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotDevicePersonDO>()
                .eqIfPresent(IotDevicePersonDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(IotDevicePersonDO::getPersonId, reqVO.getPersonId())
                .eqIfPresent(IotDevicePersonDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotDevicePersonDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(IotDevicePersonDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotDevicePersonDO::getId));
    }

    default List<IotDevicePersonDO> selectDevicePersonList(Collection<Long> ids, Collection<Long> userIds) {
        return selectList(new LambdaQueryWrapperX<IotDevicePersonDO>()
                .inIfPresent(IotDevicePersonDO::getDeviceId, ids)
                .inIfPresent(IotDevicePersonDO::getPersonId, userIds));
    }

    void deleteByDeviceIds(@Param("deviceIds") Collection<Long> deviceIds);

}