<?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.ycwl.basic.mapper.RenderWorkerMapper">
    <insert id="add">
        insert into render_worker(id, `name`, platform, runtime_version, version, access_key,
                                  cpu_count, cpu_usage, memory_total, memory_available, support_feature, scenic_only, test_only, `online`, `status`)
        VALUES (#{id}, #{name}, #{platform}, #{runtimeVersion}, #{version}, #{accessKey},
                #{cpuCount}, #{cpuUsage}, #{memoryTotal}, #{memoryAvailable}, #{supportFeature}, #{scenicOnly}, #{testOnly}, #{online}, #{status})

    </insert>
    <update id="update">
        update render_worker
        <set>
            <if test="name!= null and name!= ''">
                name = #{name},
            </if>
            <if test="platform!= null and platform!= ''">
                platform = #{platform},
            </if>
            <if test="runtimeVersion!= null and runtimeVersion!= ''">
                runtime_version = #{runtimeVersion},
            </if>
            <if test="version!= null and version!= ''">
                version = #{version},
            </if>
            <if test="accessKey!= null and accessKey!= ''">
                access_key = #{accessKey},
            </if>
            <if test="cpuCount!= null">
                cpu_count = #{cpuCount},
            </if>
            <if test="cpuUsage!= null">
                cpu_usage = #{cpuUsage},
            </if>
            <if test="memoryTotal!= null">
                memory_total = #{memoryTotal},
            </if>
            <if test="memoryAvailable!= null">
                memory_available = #{memoryAvailable},
            </if>
            <if test="supportFeature!= null">
                support_feature = #{supportFeature},
            </if>
            <if test="scenicOnly!= null">
                scenic_only = #{scenicOnly},
            </if>
            <if test="testOnly!= null">
                test_only = #{testOnly},
            </if>
            <if test="online!= null">
                `online` = #{online},
            </if>
        </set>
            where id = #{id}
    </update>
    <update id="updateStatus">
        update render_worker
        set status = (CASE
            status
                          WHEN 1 THEN
                              0
                          WHEN 0 THEN
                              1
                          ELSE null
            END)
        where id = #{id}
    </update>
    <delete id="deleteById">
        delete from render_worker where id = #{id}
    </delete>

    <select id="list" resultType="com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity">
        select id, `name`, platform, runtime_version, version, access_key,
               cpu_count, cpu_usage, memory_total, memory_available, support_feature, scenic_only, test_only, `online`, `status`, create_at, update_at
        from render_worker
        <where>
            <if test="name!= null and name!= ''">
                and `name` like concat('%', #{name}, '%')
            </if>
            <if test="platform!= null and platform!= ''">
                and platform like concat('%', #{platform}, '%')
            </if>
            <if test="runtimeVersion!= null and runtimeVersion!= ''">
                and runtime_version like concat('%', #{runtimeVersion}, '%')
            </if>
            <if test="version!= null and version!= ''">
                and version like concat('%', #{version}, '%')
            </if>
            <if test="cpuCount!= null">
                and cpu_count = #{cpuCount}
            </if>
            <if test="cpuUsage!= null">
                and cpu_usage = #{cpuUsage}
            </if>
            <if test="supportFeature!= null">
                and support_feature like concat('%',#{supportFeature},'%')
            </if>
            <if test="scenicOnly!= null">
                and scenic_only = #{scenicOnly}
            </if>
            <if test="testOnly!= null">
                and test_only = #{testOnly}
            </if>
            <if test="online!= null">
                and `online` = #{online}
            </if>
            <if test="status!= null">
                and `status` = #{status}
            </if>
            <if test="startTime!=null">
                and create_at >= #{startTime}
            </if>
            <if test="endTime!=null">
                and create_at &lt;= #{endTime}
            </if>
        </where>
    </select>
    <select id="getById" resultType="com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity">
        select id, `name`, platform, runtime_version, version, access_key,
               cpu_count, cpu_usage, memory_total, memory_available, support_feature, scenic_only, test_only, `online`, `status`, create_at, update_at
        from render_worker
        where id = #{id}
    </select>
    <select id="findByAccessKey" resultType="com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity">
        select id, `name`, scenic_only, test_only, `online`, `status`, create_at, update_at
        from render_worker
        where access_key = #{accessKey} and status = 1
    </select>
</mapper>