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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotTreeListReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotTreePageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.IotTreeDO;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * pms树 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface IotTreeMapper extends BaseMapperX<IotTreeDO> {
    default List<IotTreeDO> selectListByParentId(Collection<Long> parentIds) {
        return selectList(IotTreeDO::getParentId, parentIds);
    }
    default List<IotTreeDO> selectList(IotTreeListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IotTreeDO>()
                .likeIfPresent(IotTreeDO::getName, reqVO.getName())
                .eqIfPresent(IotTreeDO::getOriginId, reqVO.getOriginId())
                .eqIfPresent(IotTreeDO::getType, reqVO.getType())
                .eqIfPresent(IotTreeDO::getStatus, reqVO.getStatus()));
    }
    default PageResult<IotTreeDO> selectPage(IotTreePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotTreeDO>()
                .eqIfPresent(IotTreeDO::getOriginId, reqVO.getOriginId())
                .eqIfPresent(IotTreeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(IotTreeDO::getName, reqVO.getName())
                .eqIfPresent(IotTreeDO::getType, reqVO.getType())
                .eqIfPresent(IotTreeDO::getSort, reqVO.getSort())
                .eqIfPresent(IotTreeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(IotTreeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(IotTreeDO::getRemark, reqVO.getRemark())
                .orderByDesc(IotTreeDO::getId));
    }
    default List<IotTreeDO> selectListByOriginId(Long originId, String type) {
        return selectList(new LambdaQueryWrapperX<IotTreeDO>()
                .eq(IotTreeDO::getOriginId, originId)
                .eq(IotTreeDO::getType, type)
        );
    }
}
