<?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.test.test.mapper.UiAutomationMapper">

    <resultMap type="UiAutomation" id="UiAutomationResult">
        <result property="id"    column="id"    />
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="caseLevel"    column="case_level"    />
        <result property="status"    column="status"    />
        <result property="label"    column="label"    />
        <result property="createBy"    column="create_by"    />
        <result property="dutyBy"    column="duty_by"    />
        <result property="runEnvironment"    column="run_environment"    />
        <result property="updateTime"    column="update_time"    />
        <result property="stepsNumber"    column="steps_number"    />
        <result property="executionResult"    column="execution_result"    />
        <result property="passRate"    column="pass_rate"    />
        <result property="crontab"    column="crontab"    />
        <result property="crontabStatus"    column="crontab_status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="description"    column="description"    />
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectUiAutomationVo">
        select id, group_id, name, case_level, status, label, create_by, duty_by, run_environment, update_time, steps_number, execution_result, pass_rate, crontab, crontab_status, del_flag,create_time,update_by from ui_automation
    </sql>

    <select id="selectUiAutomationList" parameterType="UiAutomation" resultMap="UiAutomationResult">
        <include refid="selectUiAutomationVo"/>
        <where>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="caseLevel != null  and caseLevel != ''"> and case_level = #{caseLevel}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="label != null  and label != ''"> and label = #{label}</if>
            <if test="dutyBy != null  and dutyBy != ''"> and duty_by = #{dutyBy}</if>
            <if test="runEnvironment != null  and runEnvironment != ''"> and run_environment = #{runEnvironment}</if>
            <if test="stepsNumber != null "> and steps_number = #{stepsNumber}</if>
            <if test="executionResult != null  and executionResult != ''"> and execution_result = #{executionResult}</if>
            <if test="passRate != null  and passRate != ''"> and pass_rate = #{passRate}</if>
            <if test="crontab != null  and crontab != ''"> and crontab = #{crontab}</if>
            <if test="crontabStatus != null "> and crontab_status = #{crontabStatus}</if>
            <if test="delFlag != null "> and del_flag = #{delFlag}</if>
            <if test="description != null "> and description = #{description}</if>
        </where>
    </select>


    <select id="selectUiAutomationListNew" parameterType="UiAutomationQO" resultMap="UiAutomationResult">
        <include refid="selectUiAutomationVo"/>
        <where>

            <!-- 关键词搜索（OR条件） -->
            <if test="keyword != null and keyword != ''">
                and (
                id = #{keyword}  <!-- 假设id可以字符串匹配 -->
                or name like concat('%', #{keyword}, '%')
                or label like concat('%', #{keyword}, '%')
                <!-- 如果有其他需要搜索的字段也可以添加 -->
                )
            </if>
            <!-- 组ID条件（支持单个groupId或groupIds集合） -->
            <if test="groupIds != null and groupIds.size() > 0">
                and group_id in
                <foreach collection="groupIds" item="groupId" open="(" separator="," close=")">
                    #{groupId}
                </foreach>
            </if>

            <!-- 名称模糊查询 -->
            <if test="name != null and name != ''">
                and name like concat('%', #{name}, '%')
            </if>

            <!-- 状态条件 -->
            <if test="delFlag != null and delFlag != ''">
                and del_flag = #{delFlag}
            </if>

            <!-- 创建时间范围查询 -->
            <if test="startTime != null">
                and create_time &gt;= #{startTime}
            </if>
            <if test="endTime != null">
                and create_time &lt;= #{endTime}
            </if>

            <!-- 创建人查询 -->
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>

            <!-- 状态查询 -->
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        <!-- 可添加排序条件 -->
            order by id asc
    </select>

    <select id="selectUiAutomationById" parameterType="Long" resultMap="UiAutomationResult">
        <include refid="selectUiAutomationVo"/>
        where id = #{id}
    </select>

    <insert id="insertUiAutomation" parameterType="UiAutomation" useGeneratedKeys="true" keyProperty="id">
        insert into ui_automation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupId != null">group_id,</if>
            <if test="name != null">name,</if>
            <if test="caseLevel != null">case_level,</if>
            <if test="status != null">status,</if>
            <if test="label != null">label,</if>
            <if test="createBy != null">create_by,</if>
            <if test="dutyBy != null">duty_by,</if>
            <if test="runEnvironment != null">run_environment,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="stepsNumber != null">steps_number,</if>
            <if test="executionResult != null">execution_result,</if>
            <if test="passRate != null">pass_rate,</if>
            <if test="crontab != null">crontab,</if>
            <if test="crontabStatus != null">crontab_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="description != null">description,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">#{groupId},</if>
            <if test="name != null">#{name},</if>
            <if test="caseLevel != null">#{caseLevel},</if>
            <if test="status != null">#{status},</if>
            <if test="label != null">#{label},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="dutyBy != null">#{dutyBy},</if>
            <if test="runEnvironment != null">#{runEnvironment},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="stepsNumber != null">#{stepsNumber},</if>
            <if test="executionResult != null">#{executionResult},</if>
            <if test="passRate != null">#{passRate},</if>
            <if test="crontab != null">#{crontab},</if>
            <if test="crontabStatus != null">#{crontabStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="description != null">#{description},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateUiAutomation" parameterType="UiAutomation">
        update ui_automation
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="caseLevel != null">case_level = #{caseLevel},</if>
            <if test="status != null">status = #{status},</if>
            <if test="label != null">label = #{label},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="dutyBy != null">duty_by = #{dutyBy},</if>
            <if test="runEnvironment != null">run_environment = #{runEnvironment},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="stepsNumber != null">steps_number = #{stepsNumber},</if>
            <if test="executionResult != null">execution_result = #{executionResult},</if>
            <if test="passRate != null">pass_rate = #{passRate},</if>
            <if test="crontab != null">crontab = #{crontab},</if>
            <if test="crontabStatus != null">crontab_status = #{crontabStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="description != null">description = #{description},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUiAutomationById" parameterType="Long">
        update ui_automation set del_flag = '1' where id = #{id}
    </delete>

    <delete id="deleteUiAutomationByIds" parameterType="String">
        update ui_automation set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <delete id="deleteUiAutomationByGroupIds" parameterType="java.util.List">
        update ui_automation
        set del_flag = '1'
        where group_id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>