<?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.ibs.tabs.mapper.CustTabDetailMapper">
    
    <resultMap type="CustTabDetail" id="CustTabDetailResult">
        <result property="id"    column="id"    />
        <result property="tabId"    column="tab_id"    />
        <result property="tabThresholdType"    column="tab_threshold_type"    />
        <result property="tabThreshold"    column="tab_threshold"    />
        <result property="tabThresholdRule"    column="tab_threshold_rule"    />
        <result property="booleanVal"    column="boolean_val"    />
        <result property="enumVal"    column="enum_val"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="potName"    column="pot_name"    />
        <result property="potId"    column="pot_id"    />
    </resultMap>

    <sql id="selectCustTabDetailVo">
        select id, tab_id, tab_threshold_type, tab_threshold, tab_threshold_rule, boolean_val, enum_val, create_time, create_by, update_by, update_time, remark,pot_name,pot_id
        from cust_tab_detail
    </sql>

    <select id="selectCustTabDetailList" parameterType="CustTabDetail" resultMap="CustTabDetailResult">
        <include refid="selectCustTabDetailVo"/>
        <where>  
            <if test="tabId != null "> and tab_id = #{tabId}</if>
            <if test="tabThresholdType != null  and tabThresholdType != ''"> and tab_threshold_type = #{tabThresholdType}</if>
            <if test="tabThreshold != null "> and tab_threshold = #{tabThreshold}</if>
            <if test="tabThresholdRule != null  and tabThresholdRule != ''"> and tab_threshold_rule = #{tabThresholdRule}</if>
            <if test="booleanVal != null  and booleanVal != ''"> and boolean_val = #{booleanVal}</if>
            <if test="enumVal != null  and enumVal != ''"> and enum_val = #{enumVal}</if>
        </where>
    </select>
    
    <select id="selectCustTabDetailById" parameterType="Long" resultMap="CustTabDetailResult">
        <include refid="selectCustTabDetailVo"/>
        where id = #{id}  and is_delete = '1'
    </select>
    <select id="selectCustTabDetailByTabId" parameterType="Long" resultMap="CustTabDetailResult">
        <include refid="selectCustTabDetailVo"/>
        where tab_id = #{tabId} and is_delete = '1'
    </select>

    <insert id="insertCustTabDetail" parameterType="CustTabDetail" useGeneratedKeys="true" keyProperty="id">
        insert into cust_tab_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tabId != null and tabId !=''">tab_id,</if>
            <if test="tabThresholdType != null and tabThresholdType!=''">tab_threshold_type,</if>
            <if test="tabThreshold != null and tabThreshold != ''">tab_threshold,</if>
            <if test="tabThresholdRule != null and tabThresholdRule !='' ">tab_threshold_rule,</if>
            <if test="booleanVal != null and booleanVal!=''">boolean_val,</if>
            <if test="enumVal != null and enumVal!='' ">enum_val,</if>
            create_time,
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            update_time,
            <if test="remark != null">remark,</if>

            <if test="potId != null">pot_id,</if>
            <if test="potName != null">pot_name,</if>
            is_delete,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tabId != null and tabId !=''">#{tabId},</if>
            <if test="tabThresholdType != null and tabThresholdType!=''">#{tabThresholdType},</if>
            <if test="tabThreshold != null and tabThreshold != ''">#{tabThreshold},</if>
            <if test="tabThresholdRule != null and tabThresholdRule !=''">#{tabThresholdRule},</if>
            <if test="booleanVal != null and booleanVal!=''">#{booleanVal},</if>
            <if test="enumVal != null and enumVal!='' ">#{enumVal},</if>
            sysdate(),
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            sysdate(),
            <if test="remark != null">#{remark},</if>
            <if test="potId != null">#{potId},</if>
            <if test="potName != null">#{potName},</if>
            '1',
         </trim>
    </insert>

    <update id="updateCustTabDetail" parameterType="CustTabIdDetailVO">
        update cust_tab_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="tabId != null">tab_id = #{tabId},</if>
            <if test="tabThresholdType != null">tab_threshold_type = #{tabThresholdType},</if>
            <if test="tabThreshold != null">tab_threshold = #{tabThreshold},</if>
            <if test="tabThresholdRule != null">tab_threshold_rule = #{tabThresholdRule},</if>
            <if test="booleanVal != null">boolean_val = #{booleanVal},</if>
            <if test="enumVal != null">enum_val = #{enumVal},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustTabDetailById" parameterType="Long">
        delete from cust_tab_detail where id = #{id}
    </delete>

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


</mapper>