<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.platform.mapper.RayDao">
    <insert id="save">
        insert into ray(name, description, dataset, model, code_config, main_py, num_samples, parameters, points_to_evaluate, storage_path,
                        search_alg, scheduler, metric, mode, max_t,
                        min_samples_required, resource, image, create_by, update_by)
        values (#{ray.name}, #{ray.description}, #{ray.dataset}, #{ray.model}, #{ray.codeConfig}, #{ray.mainPy}, #{ray.numSamples}, #{ray.parameters},
                #{ray.pointsToEvaluate}, #{ray.storagePath},
                #{ray.searchAlg}, #{ray.scheduler}, #{ray.metric}, #{ray.mode}, #{ray.maxT}, #{ray.minSamplesRequired},
                 #{ray.resource}, #{ray.image}, #{ray.createBy}, #{ray.updateBy})
    </insert>

    <update id="edit">
        update ray
        <set>
            <if test="ray.name != null and ray.name !=''">
                name = #{ray.name},
            </if>
            <if test="ray.description != null and ray.description !=''">
                description = #{ray.description},
            </if>
            <if test="ray.dataset != null and ray.dataset !=''">
                dataset = #{ray.dataset},
            </if>
            <if test="ray.model != null and ray.model !=''">
                model = #{ray.model},
            </if>
            <if test="ray.codeConfig != null and ray.codeConfig !=''">
                code_config = #{ray.codeConfig},
            </if>
            <if test="ray.image != null and ray.image !=''">
                image = #{ray.image},
            </if>
            <if test="ray.mainPy != null and ray.mainPy !=''">
                main_py = #{ray.mainPy},
            </if>
            <if test="ray.numSamples != null">
                num_samples = #{ray.numSamples},
            </if>
            <if test="ray.parameters != null and ray.parameters !=''">
                parameters = #{ray.parameters},
            </if>
            <if test="ray.pointsToEvaluate != null and ray.pointsToEvaluate !=''">
                points_to_evaluate = #{ray.pointsToEvaluate},
            </if>
            <if test="ray.storagePath != null and ray.storagePath !=''">
                storage_path = #{ray.storagePath},
            </if>
            <if test="ray.searchAlg != null and ray.searchAlg !=''">
                search_alg = #{ray.searchAlg},
            </if>
            <if test="ray.scheduler != null and ray.scheduler !=''">
                scheduler = #{ray.scheduler},
            </if>
            <if test="ray.metric != null and ray.metric !=''">
                metric = #{ray.metric},
            </if>
            <if test="ray.mode != null and ray.mode !=''">
                mode = #{ray.mode},
            </if>
            <if test="ray.maxT != null">
                max_t = #{ray.maxT},
            </if>
            <if test="ray.minSamplesRequired != null">
                min_samples_required = #{ray.minSamplesRequired},
            </if>
            <if test="ray.resource != null">
                resource = #{ray.resource},
            </if>
            <if test="ray.updateBy != null and ray.updateBy !=''">
                update_by = #{ray.updateBy},
            </if>
            <if test="ray.statusList != null and ray.statusList !=''">
                status_list = #{ray.statusList},
            </if>
            <if test="ray.state != null">
                state = #{ray.state},
            </if>
        </set>
        where id = #{ray.id}
    </update>

    <select id="count" resultType="java.lang.Long">
        select count(1) from ray
        <include refid="common_condition"></include>
    </select>

    <select id="queryByPage" resultType="com.ruoyi.platform.domain.Ray">
        select * from ray
        <include refid="common_condition"></include>
    </select>

    <select id="getRayByName" resultType="com.ruoyi.platform.domain.Ray">
        select *
        from ray _
        where name = #{name}
          and state = 1
    </select>

    <select id="getRayById" resultType="com.ruoyi.platform.domain.Ray">
        select *
        from ray
        where id = #{id}
    </select>

    <sql id="common_condition">
        <where>
            state = 1
            <if test="name != null and name != ''">
                and name like concat('%', #{name}, '%')
            </if>
        </where>
    </sql>
</mapper>