<?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.quotation.TqSpecificationParabarDetailMapper">

    <resultMap type="TqSpecificationParabarDetail" id="TqSpecificationParabarDetailResult">
        <result property="id" column="id"/>
        <result property="specificationDetailId" column="specification_detail_id"/>
        <result property="paraCode" column="para_code"/>
        <result property="paraValue" column="para_value"/>
        <result property="paraCategory" column="para_category"/>
        <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="selectTqSpecificationParabarDetailVo">
        select id,
               specification_detail_id,
               para_code,
               para_value,
               para_category,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tq_specification_parabar_detail
    </sql>

    <select id="selectTqSpecificationParabarDetailList" parameterType="TqSpecificationParabarDetail"
        resultMap="TqSpecificationParabarDetailResult">
        <include refid="selectTqSpecificationParabarDetailVo"/>
        <where>
            <if test="specificationDetailId != null ">and specification_detail_id = #{specificationDetailId}</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="paraCategory != null  and paraCategory != ''">and para_category = #{paraCategory}</if>
        </where>
    </select>

    <select id="selectTqSpecificationParabarDetailById" parameterType="Long"
        resultMap="TqSpecificationParabarDetailResult">
        <include refid="selectTqSpecificationParabarDetailVo"/>
        where id = #{id}
    </select>

    <select id="listBySpecificationIdList" resultMap="TqSpecificationParabarDetailResult">
        <include refid="selectTqSpecificationParabarDetailVo"/>
        where del_flag = 0 and specification_detail_id in
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <insert id="insertTqSpecificationParabarDetail" parameterType="TqSpecificationParabarDetail" useGeneratedKeys="true"
        keyProperty="id">
        insert into tq_specification_parabar_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="specificationDetailId != null">specification_detail_id,</if>
            <if test="paraCode != null">para_code,</if>
            <if test="paraValue != null">para_value,</if>
            <if test="paraCategory != null">para_category,</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="specificationDetailId != null">#{specificationDetailId},</if>
            <if test="paraCode != null">#{paraCode},</if>
            <if test="paraValue != null">#{paraValue},</if>
            <if test="paraCategory != null">#{paraCategory},</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="updateTqSpecificationParabarDetail" parameterType="TqSpecificationParabarDetail">
        update tq_specification_parabar_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="specificationDetailId != null">specification_detail_id = #{specificationDetailId},</if>
            <if test="paraCode != null">para_code = #{paraCode},</if>
            <if test="paraValue != null">para_value = #{paraValue},</if>
            <if test="paraCategory != null">para_category = #{paraCategory},</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="deleteTqSpecificationParabarDetailById" parameterType="Long">
        delete
        from tq_specification_parabar_detail
        where id = #{id}
    </delete>

    <delete id="deleteTqSpecificationParabarDetailByIds" parameterType="String">
        delete from tq_specification_parabar_detail where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteByQuotationId">
        update tq_specification_parabar_detail set del_flag = 1 where specification_detail_id in (
            select id from tq_specification where quotation_id = #{quotationId} )
    </delete>
</mapper>