<?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.project.business.mapper.TpAreaParaSelectItemMapper">
    
    <resultMap type="com.ruoyi.project.business.domain.TpAreaParaSelectItem" id="TpAreaParaSelectItemResult">
        <result property="id"    column="id"    />
        <result property="elevatorModelId"    column="elevator_model_id"    />
        <result property="paraId" column="para_id"/>
        <result property="paraCode"    column="para_code"    />
        <result property="paraSelectItemId"    column="para_select_item_id"    />
        <result property="paraSelectItemValue"    column="para_select_item_value"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTpAreaParaSelectItemVo"> select id, elevator_model_id, para_id, para_code, para_select_item_id, para_select_item_value, del_flag, create_time, create_by, update_time, update_by, remark from tp_area_para_select_item </sql>


    <select id="selectTpAreaParaSelectItemList" parameterType="com.ruoyi.project.business.domain.TpAreaParaSelectItem" resultMap="TpAreaParaSelectItemResult">
        <include refid="selectTpAreaParaSelectItemVo"/>
        <where>
            <if test="elevatorModelId != null "> and elevator_model_id = #{elevatorModelId}</if>
            <if test="paraId != null "> and para_id = #{paraId}</if>
            <if test="paraCode != null and paraCode != ''"> and para_code = #{paraCode}</if>
            <if test="paraSelectItemId != null "> and para_select_item_id = #{paraSelectItemId}</if>
            <if test="paraSelectItemValue != null and paraSelectItemValue != ''"> and para_select_item_value = #{paraSelectItemValue}</if>
        </where>
    </select>
    
    <select id="selectTpAreaParaSelectItemById" parameterType="Long" resultMap="TpAreaParaSelectItemResult">
        <include refid="selectTpAreaParaSelectItemVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTpAreaParaSelectItem" parameterType="com.ruoyi.project.business.domain.TpAreaParaSelectItem" useGeneratedKeys="true" keyProperty="id">
        insert into tp_area_para_select_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="elevatorModelId != null">elevator_model_id,</if>
            <if test="paraId != null">para_id,</if>
            <if test="paraCode != null">para_code,</if>
            <if test="paraSelectItemId != null">para_select_item_id,</if>
            <if test="paraSelectItemValue != null">para_select_item_value,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="elevatorModelId != null">#{elevatorModelId},</if>
            <if test="paraId != null">#{paraId},</if>
            <if test="paraCode != null">#{paraCode},</if>
            <if test="paraSelectItemId != null">#{paraSelectItemId},</if>
            <if test="paraSelectItemValue != null">#{paraSelectItemValue},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTpAreaParaSelectItem" parameterType="com.ruoyi.project.business.domain.TpAreaParaSelectItem">
        update tp_area_para_select_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="elevatorModelId != null">elevator_model_id = #{elevatorModelId},</if>
            <if test="paraId != null">para_id = #{paraId},</if>
            <if test="paraCode != null">para_code = #{paraCode},</if>
            <if test="paraSelectItemId != null">para_select_item_id = #{paraSelectItemId},</if>
            <if test="paraSelectItemValue != null">para_select_item_value = #{paraSelectItemValue},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTpAreaParaSelectItemById" parameterType="Long">
        delete from tp_area_para_select_item where id = #{id}
    </delete>

    <delete id="deleteTpAreaParaSelectItemByIds" parameterType="String">
        delete from tp_area_para_select_item where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <insert id="InsertBySql" parameterType="java.util.List"   useGeneratedKeys="true"
            keyProperty="id">
        insert into tp_area_para_select_item (
        elevator_model_id,
        para_id,
        para_code,
        para_select_item_id,
        para_select_item_value,
        create_by,
        create_time
        )values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.elevatorModelId},
            #{item.paraId},
            #{item.paraCode},
            #{item.paraSelectItemId},
            #{item.paraSelectItemValue},
            #{item.createBy},
            #{item.createTime}
            )
        </foreach>
    </insert>

    <update id="deleteTpAreaParaSelectItemByParaIds">
        update tp_area_para_select_item set del_flag = '1' where elevator_model_id = #{elevatorModelId}
        and para_id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <delete id="realDeleteTpAreaParaSelectItemByParaIds">
       delete from tp_area_para_select_item  where elevator_model_id = #{elevatorModelId}
        and para_id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectTpAreaParaSelectItemListByIds"  resultMap="TpAreaParaSelectItemResult">
        <include refid="selectTpAreaParaSelectItemVo"/>
        <where>
            del_flag = '0'
            and para_id in
            <foreach collection="ids" item="paraId" open="(" separator="," close=")">
                #{paraId}
            </foreach>
        </where>
    </select>

    <update id="deleteTpAreaParaSelectItemByElevatorModelId" parameterType="Long">
        update tp_area_para_select_item set del_flag = '1' where elevator_model_id = #{elevatorModelId}
    </update>

    <delete id="removeTpAreaParaSelectItemByElevatorModelId" parameterType="Long">
        delete from tp_area_para_select_item where elevator_model_id = #{elevatorModelId}
    </delete>

</mapper>