package cn.iocoder.yudao.module.iot.dal.mysql.iotorganization;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo.IotOrganizationListReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * IOT组织 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface IotOrganizationMapper extends BaseMapperX<IotOrganizationDO> {

    default List<IotOrganizationDO> selectList(IotOrganizationListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IotOrganizationDO>()
                .eqIfPresent(IotOrganizationDO::getSort, reqVO.getSort())
                .eqIfPresent(IotOrganizationDO::getWorkerUserId, reqVO.getWorkerUserId())
                .eqIfPresent(IotOrganizationDO::getOrgId, reqVO.getOrgId())
                .betweenIfPresent(IotOrganizationDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(IotOrganizationDO::getName, reqVO.getName())
                .eqIfPresent(IotOrganizationDO::getParentId, reqVO.getParentId())
                .eqIfPresent(IotOrganizationDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotOrganizationDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(IotOrganizationDO::getOrgClass, reqVO.getOrgClass())
                .eqIfPresent(IotOrganizationDO::getMachineType, reqVO.getMachineType())
                .orderByDesc(IotOrganizationDO::getId));
    }

    default IotOrganizationDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(IotOrganizationDO::getParentId, parentId, IotOrganizationDO::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(IotOrganizationDO::getParentId, parentId);
    }

}