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

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.hazard.vo.IotHazardTypePageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.hazard.IotHazardTypeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * QHSE-隐患排查分类 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface IotHazardTypeMapper extends BaseMapperX<IotHazardTypeDO> {

    default PageResult<IotHazardTypeDO> selectPage(IotHazardTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotHazardTypeDO>()
                .eqIfPresent(IotHazardTypeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(IotHazardTypeDO::getName, reqVO.getName())
                .eqIfPresent(IotHazardTypeDO::getCode, reqVO.getCode())
                .eqIfPresent(IotHazardTypeDO::getSort, reqVO.getSort())
                .eqIfPresent(IotHazardTypeDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotHazardTypeDO::getDeptId, reqVO.getDeptId())
                .betweenIfPresent(IotHazardTypeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(IotHazardTypeDO::getRemark, reqVO.getRemark())
                .orderByDesc(IotHazardTypeDO::getId));
    }

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

    default List<IotHazardTypeDO> selectList(IotHazardTypePageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IotHazardTypeDO>()
                .likeIfPresent(IotHazardTypeDO::getName, reqVO.getName())
                .likeIfPresent(IotHazardTypeDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotHazardTypeDO::getStatus, reqVO.getStatus()));
    }
}