package cn.iocoder.yudao.module.system.dal.mysql.biz;

/**
 * @Author: jinyd
 * @CreateTime: 2024/8/19  11:34
 * @Description:
 * @Version: 4.0
 */

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.system.controller.admin.biz.vo.DeviceModelPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ModelFieldPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ModelTableFieldVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.DeviceModelDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ModelFieldDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface ModelFieldMapper extends BaseMapperX<ModelFieldDO> {

    default PageResult<ModelFieldDO> selectPage(ModelFieldPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ModelFieldDO>()
                .eqIfPresent(ModelFieldDO::getDeviceModelId, reqVO.getDeviceModelId())
                .likeIfPresent(ModelFieldDO::getOriginalColumnName, reqVO.getOriginalColumnName())
                .eqIfPresent(ModelFieldDO::getOriginalDataType, reqVO.getOriginalDataType())
                .eqIfPresent(ModelFieldDO::getOriginalColumnComment, reqVO.getOriginalColumnComment())
                .likeIfPresent(ModelFieldDO::getColumnName, reqVO.getColumnName())
                .eqIfPresent(ModelFieldDO::getDataType, reqVO.getDataType())
                .eqIfPresent(ModelFieldDO::getColumnComment, reqVO.getColumnComment())
                .eqIfPresent(ModelFieldDO::getSort, reqVO.getSort())
                .likeIfPresent(ModelFieldDO::getTableName, reqVO.getTableName())
                .eqIfPresent(ModelFieldDO::getModelType, reqVO.getModelType())
                .betweenIfPresent(ModelFieldDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ModelFieldDO::getId));
    }


    List<ModelTableFieldVO> selectTableInfo(@Param("tableName") String tableName);
}
