package cn.iocoder.yudao.module.mes.dal.mysql.devicetype;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
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.mes.dal.dataobject.devicetype.DeviceTypeDO;
import cn.iocoder.yudao.module.mes.controller.admin.devicetype.vo.*;

import java.util.List;

/**
 * 设备类型 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface DeviceTypeMapper extends BaseMapperX<DeviceTypeDO> {

    default PageResult<DeviceTypeDO> selectPage(DeviceTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceTypeDO>()
                .eqIfPresent(DeviceTypeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(DeviceTypeDO::getParentChain, reqVO.getParentChain())
                .eqIfPresent(DeviceTypeDO::getCode, reqVO.getCode())
                .likeIfPresent(DeviceTypeDO::getName, reqVO.getName())
                .eqIfPresent(DeviceTypeDO::getRemark, reqVO.getRemark())
                .eqIfPresent(DeviceTypeDO::getSort, reqVO.getSort())
                .betweenIfPresent(DeviceTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(DeviceTypeDO::getSort)
                .orderByDesc(DeviceTypeDO::getId));
    }

    default List<DeviceTypeDO> selectList(DeviceTypeListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceTypeDO>()
                .eqIfPresent(DeviceTypeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(DeviceTypeDO::getParentChain, reqVO.getParentChain())
                .likeIfPresent(DeviceTypeDO::getCode, reqVO.getCode())
                .likeIfPresent(DeviceTypeDO::getName, reqVO.getName())
                .betweenIfPresent(DeviceTypeDO::getCreateTime, reqVO.getCreateStartTime(), reqVO.getCreateEndTime())
                .orderByAsc(DeviceTypeDO::getSort)
                .orderByDesc(DeviceTypeDO::getId));
    }

    default List<DeviceTypeDO> selectList() {
        return selectList(new LambdaQueryWrapper<DeviceTypeDO>()
                .orderByAsc(DeviceTypeDO::getSort)
                .orderByDesc(DeviceTypeDO::getId));
    }
}