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

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.qhse.file.vo.QhseFileTreePageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotTreeListReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.file.QhseFileTreeDO;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * QHSE文件树 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface QhseFileTreeMapper extends BaseMapperX<QhseFileTreeDO> {

    default PageResult<QhseFileTreeDO> selectPage(QhseFileTreePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<QhseFileTreeDO>()
                .eqIfPresent(QhseFileTreeDO::getOriginId, reqVO.getOriginId())
                .eqIfPresent(QhseFileTreeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(QhseFileTreeDO::getName, reqVO.getName())
                .eqIfPresent(QhseFileTreeDO::getType, reqVO.getType())
                .eqIfPresent(QhseFileTreeDO::getSort, reqVO.getSort())
                .eqIfPresent(QhseFileTreeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(QhseFileTreeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(QhseFileTreeDO::getRemark, reqVO.getRemark())
                .eqIfPresent(QhseFileTreeDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(QhseFileTreeDO::getDeviceCode, reqVO.getDeviceCode())
                .likeIfPresent(QhseFileTreeDO::getDeptName, reqVO.getDeptName())
                .orderByDesc(QhseFileTreeDO::getId));
    }

    default List<QhseFileTreeDO> selectListByParentId(Collection<Long> parentIds) {
        return selectList(QhseFileTreeDO::getParentId, parentIds);
    }

    default List<QhseFileTreeDO> selectListByOriginId(Long originId, String type) {
        return selectList(new LambdaQueryWrapperX<QhseFileTreeDO>()
                .eq(QhseFileTreeDO::getOriginId, originId)
                .eq(QhseFileTreeDO::getType, type)
        );
    }

    default List<QhseFileTreeDO> selectList(IotTreeListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<QhseFileTreeDO>()
                .likeIfPresent(QhseFileTreeDO::getName, reqVO.getName())
                .eqIfPresent(QhseFileTreeDO::getOriginId, reqVO.getOriginId())
                .eqIfPresent(QhseFileTreeDO::getType, reqVO.getType())
                .eqIfPresent(QhseFileTreeDO::getStatus, reqVO.getStatus()));
    }
}