<?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.warehouseBusiness.mapper.TEnclosureMapper">

    <resultMap type="TEnclosure" id="TEnclosureResult">
        <result property="fId" column="f_id"/>
        <result property="fPid" column="f_pid"/>
        <result property="srcId" column="src_id"/>
        <result property="fLineno" column="f_lineno"/>
        <result property="fName" column="f_name"/>
        <result property="fDesc" column="f_desc"/>
        <result property="fUrl" column="f_url"/>
        <result property="fType" column="f_type"/>
        <result property="fStatus" column="f_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTEnclosureVo">
        select f_id, f_pid, src_id, f_lineno, f_name, f_desc, f_url, f_type, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_enclosure
    </sql>

    <select id="selectTEnclosureList" parameterType="TEnclosure" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        <where>
            <if test="fPid != null ">and f_pid = #{fPid}</if>
            <if test="srcId != null ">and src_id = #{srcId}</if>
            <if test="fLineno != null ">and f_lineno = #{fLineno}</if>
            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
            <if test="fDesc != null  and fDesc != ''">and f_desc = #{fDesc}</if>
            <if test="fUrl != null  and fUrl != ''">and f_url = #{fUrl}</if>
            <if test="fType != null  and fType != ''">and f_type = #{fType}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
        </where>
    </select>

    <select id="selectTEnclosureById" parameterType="Long" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        where f_id = #{fId}
    </select>

    <select id="selectWarehouseAccessoriesList" parameterType="TEnclosure" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        where f_pid = #{fPid}
        order by create_time desc
        limit 0, 5
    </select>

    <select id="selectTEnclosureByPId" parameterType="long" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        where f_pid = #{fPid}
    </select>

    <insert id="insertTEnclosure" parameterType="TEnclosure" useGeneratedKeys="true" keyProperty="fId">
        insert into t_enclosure
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fPid != null">f_pid,</if>
            <if test="srcId != null">src_id,</if>
            <if test="fLineno != null">f_lineno,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fDesc != null and fDesc != ''">f_desc,</if>
            <if test="fUrl != null and fUrl != ''">f_url,</if>
            <if test="fType != null and fType != ''">f_type,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fPid != null">#{fPid},</if>
            <if test="srcId != null">#{srcId},</if>
            <if test="fLineno != null">#{fLineno},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fDesc != null and fDesc != ''">#{fDesc},</if>
            <if test="fUrl != null and fUrl != ''">#{fUrl},</if>
            <if test="fType != null and fType != ''">#{fType},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTEnclosure" parameterType="TEnclosure">
        update t_enclosure
        <trim prefix="SET" suffixOverrides=",">
            <if test="fPid != null">f_pid = #{fPid},</if>
            <if test="srcId != null">src_id = #{srcId},</if>
            <if test="fLineno != null">f_lineno = #{fLineno},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fDesc != null and fDesc != ''">f_desc = #{fDesc},</if>
            <if test="fUrl != null and fUrl != ''">f_url = #{fUrl},</if>
            <if test="fType != null and fType != ''">f_type = #{fType},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</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 f_id = #{fId}
    </update>

    <delete id="deleteTEnclosureById" parameterType="Long">
        delete from t_enclosure where f_id = #{fId}
    </delete>

    <delete id="deleteByFPid" parameterType="Long">
        delete from t_enclosure where f_pid = #{fId}
    </delete>

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

    <select id="selectUrlByPId" parameterType="long" resultType="string">
        select f_url from t_enclosure where f_pid = #{fPid} and src_id is null
    </select>

    <select id="selectTEnclosureListByPId" parameterType="long" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        where f_pid = #{fPid} and src_id is null
    </select>

    <select id="selectTEnclosureListBySrcId" parameterType="long" resultMap="TEnclosureResult">
        <include refid="selectTEnclosureVo"/>
        where src_id = #{srcId}
    </select>

</mapper>
