<?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.TpParabarDetailValueMapper">
    
    <resultMap type="TpParabarDetailValue" id="TpParabarDetailValueResult">
        <result property="id"    column="id"    />
        <result property="parabarDetailId"    column="parabar_detail_id"    />
        <result property="paraCode"    column="para_code"    />
        <result property="paraValue"    column="para_value"    />
        <result property="status"    column="status"    />
        <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="TpParabarDetailValue" id="TpParabarDetailValueResult2">
        <result property="paraId"    column="id"    />
        <result property="paraCode"    column="para_code"    />
        <result property="paraCategory"    column="para_category"    />
        <result property="inputType"    column="input_type"    />
        <result property="paraValue"    column="para_value"    />
        <result property="paraName"    column="para_name"    />
        <result property="paraNameUS"    column="para_nameUS"    />
        <result property="paraNameRU"    column="para_nameRU"    />
        <result property="paraNameES"    column="para_nameES"    />
    </resultMap>

    <sql id="selectTpParabarDetailValueVo">
        select id, parabar_detail_id, para_code, para_value, status, del_flag, create_time, create_by, update_time, update_by, remark from tp_parabar_detail_value
    </sql>

    <select id="selectTpParabarDetailValueList" parameterType="TpParabarDetailValue" resultMap="TpParabarDetailValueResult">
        <include refid="selectTpParabarDetailValueVo"/>
        <where>  
            <if test="parabarDetailId != null "> and parabar_detail_id = #{parabarDetailId}</if>
            <if test="paraCode != null  and paraCode != ''"> and para_code = #{paraCode}</if>
            <if test="paraValue != null  and paraValue != ''"> and para_value = #{paraValue}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectTpParabarDetailValueByParaDetailId" parameterType="Long" resultMap="TpParabarDetailValueResult">
        <include refid="selectTpParabarDetailValueVo"/>
        where id = #{id}
    </select>
    
    <select id="selectDetailValueByParabarDetailId" parameterType="Long" resultMap="TpParabarDetailValueResult2">
        SELECT
            T3.id,
            T3.para_code,
            T3.para_category,
            T3.input_type,
            T1.para_value,
            T3.para_name,
            T3.para_nameUS,
            T3.para_nameRU,
            T3.para_nameES
        FROM
            tp_parabar_detail_value T1
                INNER JOIN tp_para_library T3 ON T3.para_code = T1.para_code
        WHERE T1.parabar_detail_id = #{parabarDetailId}
    </select>
        
    <insert id="insertTpParabarDetailValue" parameterType="TpParabarDetailValue" useGeneratedKeys="true" keyProperty="id">
        insert into tp_parabar_detail_value
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parabarDetailId != null">parabar_detail_id,</if>
            <if test="parabarId != null">parabar_id,</if>
            <if test="paraCode != null">para_code,</if>
            <if test="paraValue != null">para_value,</if>
            <if test="status != null">status,</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="parabarDetailId != null">#{parabarDetailId},</if>
            <if test="parabarId != null">#{parabarId},</if>
            <if test="paraCode != null">#{paraCode},</if>
            <if test="paraValue != null">#{paraValue},</if>
            <if test="status != null">#{status},</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="updateTpParabarDetailValue" parameterType="TpParabarDetailValue">
        update tp_parabar_detail_value
        <trim prefix="SET" suffixOverrides=",">
            <if test="parabarDetailId != null">parabar_detail_id = #{parabarDetailId},</if>
            <if test="paraCode != null">para_code = #{paraCode},</if>
            <if test="paraValue != null">para_value = #{paraValue},</if>
            <if test="status != null">status = #{status},</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="deleteTpParabarDetailValueById" parameterType="Long">
        delete from tp_parabar_detail_value where id = #{id}
    </delete>

    <delete id="deleteTpParabarDetailValueByParabarId" parameterType="Long">
        delete from tp_parabar_detail_value where parabar_id = #{parabarId}
    </delete>
    <delete id="softDeleteTpParabarDetailValueByParabarId" parameterType="Long">
        update tp_parabar_detail_value set  del_flag = 1 where parabar_id  in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

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

    <select id="selectBarCount" parameterType="Long" resultType="int">
        SELECT
        count(*)
        FROM tp_parabar_detail_value dtl
        left join tp_para_library lib on lib.para_code = dtl.para_code and lib.del_flag = 0
        where lib.id = #{paraId} and dtl.del_flag = 0
    </select>


</mapper>