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

import java.util.*;
import java.util.stream.Collectors;

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.iot.dal.dataobject.deviceattributetype.DeviceAttributeTypeDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.deviceattributetype.vo.*;

/**
 * 采集点分类 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface DeviceAttributeTypeMapper extends BaseMapperX<DeviceAttributeTypeDO> {


    default PageResult<DeviceAttributeTypeDO> selectPage(DeviceAttributeTypePageReqVO reqVO) {


        LambdaQueryWrapperX<DeviceAttributeTypeDO> deviceAttributeTypeDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        deviceAttributeTypeDOLambdaQueryWrapperX
                .eqIfPresent(DeviceAttributeTypeDO::getCode, reqVO.getCode())
                .likeIfPresent(DeviceAttributeTypeDO::getName, reqVO.getName())
                .eqIfPresent(DeviceAttributeTypeDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceAttributeTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(DeviceAttributeTypeDO::getSort);

        if (StringUtils.isNotBlank(reqVO.getIds())) {
            List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
                    .map(String::trim)
                    .map(Long::valueOf)
                    .collect(Collectors.toList());
            deviceAttributeTypeDOLambdaQueryWrapperX.in(DeviceAttributeTypeDO::getId, idList);
        }


        return selectPage(reqVO, deviceAttributeTypeDOLambdaQueryWrapperX);

    }

    default List<DeviceAttributeTypeDO> select() {
        return selectList();
    }
}