<?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.TpParaSelectItemMapper">
    
    <resultMap type="com.ruoyi.project.business.domain.TpParaSelectItem" id="TpParaSelectItemResult">
        <result property="id"    column="id"    />
        <result property="paraId"    column="para_id"    />
        <result property="value"    column="value"    />
        <result property="label"    column="label"    />
        <result property="labelUS"    column="labelUS"    />
        <result property="labelRU"    column="labelRU"    />
        <result property="labelES"    column="labelES"    />
        <result property="sortNumber"    column="sort_number"    />
        <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>

    <resultMap type="com.ruoyi.project.business.domain.vo.paramSelectItem.ParaSelectItemVo" id="ParaSelectItemResult">
        <result property="id"    column="id"    />
        <result property="paraId"    column="para_id"    />
        <result property="value"    column="value"    />
        <result property="label"    column="label"    />
        <result property="labelUS"    column="labelUS"    />
        <result property="labelRU"    column="labelRU"    />
        <result property="labelES"    column="labelES"    />

        <result property="paraCode"    column="para_code"    />
        <result property="paraName"    column="para_name"    />
        <result property="paraNameUS"    column="para_nameUS"    />
        <result property="paraNameRU"    column="para_nameRU"    />
        <result property="paraNameES"    column="para_nameES"    />
        <result property="paraCategory"    column="para_category"    />
        <result property="inputType"    column="input_type"    />
        <result property="elevatorType"    column="elevator_type"    />
        <result property="status"    column="status"    />

        <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="selectTpParaSelectItemVo">
        select id, para_id, value, label, labelUS, labelRU, labelES, sort_number, del_flag, create_time, create_by, update_time, update_by, remark from tp_para_select_item
    </sql>

    <select id="selectTpParaSelectItemList" parameterType="TpParaSelectItem" resultMap="TpParaSelectItemResult">
        <include refid="selectTpParaSelectItemVo"/>
        <where>
            and  del_flag = 0
            <if test="paraId != null "> and para_id = #{paraId}</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
            <if test="label != null  and label != ''"> and label like concat('%', #{label}, '%')</if>
            <if test="labelUS != null  and labelUS != ''"> and labelUS like concat('%', #{labelUS}, '%')</if>
            <if test="labelRU != null  and labelRU != ''"> and labelRU like concat('%', #{labelRU}, '%')</if>
            <if test="labelES != null  and labelES != ''"> and labelES like concat('%', #{labelES}, '%')</if>
            <if test="sortNumber != null "> and sort_number = #{sortNumber}</if>
        </where>
    </select>


    <select id="selectTpParaSelectItemListNew" parameterType="TpParaSelectItem" resultMap="TpParaSelectItemResult">
        select
          sel.id,
          para_id,
          value,
          label,
          labelUS,
          abelRU,
          labelES,
          sel.update_time,
          sel.update_by
        from tp_para_select_item sel
        left join tp_para_library library on library.id = sel.para_id

        <where>
            and  del_flag = 0
            <if test="paraId != null "> and para_id = #{paraId}</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
            <if test="label != null  and label != ''"> and label like concat('%', #{label}, '%')</if>
            <if test="labelUS != null  and labelUS != ''"> and labelUS like concat('%', #{labelUS}, '%')</if>
            <if test="labelRU != null  and labelRU != ''"> and labelRU like concat('%', #{labelRU}, '%')</if>
            <if test="labelES != null  and labelES != ''"> and labelES like concat('%', #{labelES}, '%')</if>
            <if test="sortNumber != null "> and sort_number = #{sortNumber}</if>
        </where>
    </select>
    
    <select id="selectTpParaSelectItemById" parameterType="Long" resultMap="TpParaSelectItemResult">
        <include refid="selectTpParaSelectItemVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTpParaSelectItem" parameterType="TpParaSelectItem" useGeneratedKeys="true" keyProperty="id">
        insert into tp_para_select_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paraId != null">para_id,</if>
            <if test="value != null">value,</if>
            <if test="label != null">label,</if>
            <if test="labelUS != null">labelUS,</if>
            <if test="labelRU != null">labelRU,</if>
            <if test="labelES != null">labelES,</if>
            <if test="sortNumber != null">sort_number,</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="paraId != null">#{paraId},</if>
            <if test="value != null">#{value},</if>
            <if test="label != null">#{label},</if>
            <if test="labelUS != null">#{labelUS},</if>
            <if test="labelRU != null">#{labelRU},</if>
            <if test="labelES != null">#{labelES},</if>
            <if test="sortNumber != null">#{sortNumber},</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="updateTpParaSelectItem" parameterType="TpParaSelectItem">
        update tp_para_select_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="paraId != null">para_id = #{paraId},</if>
            <if test="value != null">value = #{value},</if>
            <if test="label != null">label = #{label},</if>
            <if test="labelUS != null">labelUS = #{labelUS},</if>
            <if test="labelRU != null">labelRU = #{labelRU},</if>
            <if test="labelES != null">labelES = #{labelES},</if>
            <if test="sortNumber != null">sort_number = #{sortNumber},</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="deleteTpParaSelectItemById" parameterType="Long">
        update tp_para_select_item set del_flag = 1 where id = #{id}
    </delete>

    <delete id="deleteTpParaSelectItemByIds" parameterType="String">
        update tp_para_select_item set del_flag = 1 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_para_select_item (
        para_id,
        value,
        label,
        labelUS,
        labelRU,
        labelES,
        sort_number,
        create_time,
        create_by,
        remark
        )values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.paraId},
            #{item.value},
            #{item.label},
            #{item.labelUS},
            #{item.labelRU},
            #{item.labelES},

            #{item.sortNumber},
            #{item.createTime},
            #{item.createBy},
            #{item.remark}
            )
        </foreach>
    </insert>


    <select id="selectTpParaSelectItemWithCodeList" parameterType="com.ruoyi.project.business.domain.vo.paramSelectItem.ParaSelectItemVo" resultMap="ParaSelectItemResult">
        select sel.id,
        para_id,
        value,
        label,
        labelUS,
        labelRU,
         labelES,
        para_code,
        para_name
         from tp_para_select_item sel
         left join tp_para_library lib on lib.id = sel.para_id
        <where>
            and  sel.del_flag = 0
            <if test="paraId != null "> and para_id = #{paraId}</if>
            <if test="paraCode != null "> and lib.para_code = #{paraCode}</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
            <if test="label != null  and label != ''"> and label like concat('%', #{label}, '%')</if>
        </where>
    </select>


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