<?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.UiElementMapper">

    <resultMap type="UiElement" id="UiElementResult">
        <result property="id"    column="id"    />
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="locType"    column="loc_type"    />
        <result property="elementLoc"    column="element_loc"    />
        <result property="description"    column="description"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectUiElementVo">
        select id, group_id, name, loc_type, element_loc, description, create_by, create_time, update_by, update_time, del_flag from ui_element
    </sql>

    <select id="selectUiElementListNew" parameterType="UiElementQO" resultMap="UiElementResult">
        <include refid="selectUiElementVo"/>
        <where>
            <!-- 修改group_id条件为IN查询 -->
            <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>
        </where>
    </select>


    <select id="selectUiElementList" parameterType="UiElement" resultMap="UiElementResult">
        <include refid="selectUiElementVo"/>
        <where>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="locType != null  and locType != ''"> and loc_type = #{locType}</if>
            <if test="elementLoc != null  and elementLoc != ''"> and element_loc = #{elementLoc}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
        </where>
    </select>

    <select id="selectUiElementById" parameterType="Long" resultMap="UiElementResult">
        <include refid="selectUiElementVo"/>
        where id = #{id}
    </select>

    <insert id="insertUiElement" parameterType="UiElement" useGeneratedKeys="true" keyProperty="id">
        insert into ui_element
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupId != null">group_id,</if>
            <if test="name != null">name,</if>
            <if test="locType != null">loc_type,</if>
            <if test="elementLoc != null">element_loc,</if>
            <if test="description != null">description,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">#{groupId},</if>
            <if test="name != null">#{name},</if>
            <if test="locType != null">#{locType},</if>
            <if test="elementLoc != null">#{elementLoc},</if>
            <if test="description != null">#{description},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateUiElement" parameterType="UiElement">
        update ui_element
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="locType != null">loc_type = #{locType},</if>
            <if test="elementLoc != null">element_loc = #{elementLoc},</if>
            <if test="description != null">description = #{description},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

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

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


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