package com.tashow.cloud.ai.dal.mysql.aisample;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagPageReqVO;
import com.tashow.cloud.ai.dal.dataobject.aisample.AiSampleTagDO;
import com.tashow.cloud.common.pojo.PageResult;
import com.tashow.cloud.mybatis.mybatis.core.mapper.BaseMapperX;
import com.tashow.cloud.mybatis.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 样本标签库 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AiSampleTagMapper extends BaseMapperX<AiSampleTagDO> {

    default PageResult<AiSampleTagDO> selectPage(AiSampleTagPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AiSampleTagDO>()
                .orderByDesc(AiSampleTagDO::getId));
    }

    @Select("<script>" +
            "SELECT t.id, t.tag_name tagName, t.tag_type tagType, t.enum_value enumValue, t.group_id groupId " +
            "FROM tz_ai_sample_tag t " +
            "<where>" +
            "    t.deleted = 0" +
            "    <if test=\"pageReqVO.groupId != null\">" +
            "        AND (t.group_id IS NULL OR FIND_IN_SET(#{pageReqVO.groupId}, t.group_id))" +
            "    </if>" +
            "    <if test=\"pageReqVO.tagName != null and pageReqVO.tagName != ''\">" +
            "        AND t.tag_name LIKE CONCAT('%',#{pageReqVO.tagName},'%')" +
            "    </if>" +
            "</where>" +
            "ORDER BY t.id DESC" +
            "</script>")
    IPage<AiSampleTagDO> getAiSampleTagPage(Page<AiSampleTagDO> page, AiSampleTagPageReqVO pageReqVO);

}