<?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.TWarehousebillsitemsElabelMapper">

    <resultMap type="TWarehousebillsitemsElabel" id="ElabelResult">
        <result property="fId"    column="f_id"    />
        <result property="fGPid"    column="f_g_pid"    />
        <result property="fPid"    column="f_pid"    />
        <result property="fContent"    column="f_content"    />
        <result property="fQty"    column="f_qty"    />
        <result property="fWeight"    column="f_weight"    />
        <result property="fType"    column="f_type"    />
        <result property="fStatus"    column="f_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectElabel">
        select f_id,
               f_g_pid,
               f_pid,
               f_content,
               f_qty,
               f_weight,
               f_type,
               f_status,
               create_by,
               create_time,
               update_by,
               update_time
        from t_warehousebillsitems_elabel
    </sql>

    <select id="selectList" parameterType="TWarehousebillsitemsElabel" resultMap="ElabelResult">
        <include refid="selectElabel"/>
        <where>
            <if test="fGPid != null">and f_g_pid = #{fGPid}</if>
            <if test="fPid != null">and f_pid = #{fPid}</if>
            <if test="fContent != null and fContent != ''">and f_content = #{fContent}</if>
            <if test="fType != null">and f_type = #{fType}</if>
            <if test="fStatus != null">and f_status = #{fStatus}</if>
        </where>
    </select>

    <insert id="insert" parameterType="TWarehousebillsitemsElabel" useGeneratedKeys="true" keyProperty="fId">
        insert into t_warehousebillsitems_elabel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fGPid != null">f_g_pid,</if>
            <if test="fPid != null">f_pid,</if>
            <if test="fContent != null">f_content,</if>
            <if test="fQty != null">f_qty,</if>
            <if test="fWeight != null">f_weight,</if>
            <if test="fType != null">f_type,</if>
            <if test="fStatus != null">f_status,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fGPid != null">#{fGPid},</if>
            <if test="fPid != null">#{fPid},</if>
            <if test="fContent != null">#{fContent},</if>
            <if test="fQty != null">#{fQty},</if>
            <if test="fWeight != null">#{fWeight},</if>
            <if test="fType != null">#{fType},</if>
            <if test="fStatus != null">#{fStatus},</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>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel">
        UPDATE
        t_warehousebillsitems_elabel
        <trim prefix="SET" suffixOverrides=",">
            <if test="fGPid != null">f_g_pid = #{fGPid},</if>
            <if test="fPid != null">f_pid = #{fPid},</if>
            <if test="fContent != null">f_content = #{fContent},</if>
            <if test="fQty != null">f_qty = #{fQty},</if>
            <if test="fWeight != null">f_weight = #{fWeight},</if>
            <if test="fType != null">f_type = #{fType},</if>
            <if test="fStatus != null">f_status = #{fStatus},</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>
        </trim>
        WHERE
            f_id = #{fId}
    </update>

    <update id="updateStatus" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel">
        update t_warehousebillsitems_elabel set f_status = #{fStatus} where f_content = #{fContent} and f_type = #{fType}
    </update>

    <delete id="deleteById" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel">
        delete from t_warehousebillsitems_elabel where f_id = #{id}
    </delete>

    <delete id="deleteByFPid" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel">
        delete from t_warehousebillsitems_elabel where f_pid = #{fPid}
    </delete>

    <select id="selectById" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel" resultMap="ElabelResult">
        <include refid="selectElabel"/>
        WHERE f_id = #{fId}
    </select>

    <select id="selectByfContent" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel" resultMap="ElabelResult">
        <include refid="selectElabel"/>
        WHERE f_content = #{fContent}
    </select>

    <select id="selectByfPid" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel" resultMap="ElabelResult">
        <include refid="selectElabel"/>
        WHERE f_pid = #{fPid}
    </select>

    <select id="selectByfGPid" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehousebillsitemsElabel" resultMap="ElabelResult">
        <include refid="selectElabel"/>
        WHERE f_g_pid = #{fGPid}
    </select>

    <select id="getLabel" parameterType="string" resultType="string">
        select t1.f_content
        from t_warehousebillsitems_elabel t1
            left join t_whgenleg t2 on t2.f_id = t1.f_pid
        where t2.f_originalbillno = #{billNo} and t1.f_type = 3 and t1.f_status = 0
    </select>

    <select id="getLabelByTop" parameterType="long" resultType="string">
        select t1.f_content
        from t_warehousebillsitems_elabel t1
                 left join t_warehousebills t2 on t2.f_id = t1.f_g_pid
        where t1.f_g_pid = #{topId}
    </select>

    <select id="getLabelByPid" parameterType="long" resultType="string">
        select t1.f_content
        from t_warehousebillsitems_elabel t1
                 left join t_warehousebillsitems t2 on t2.f_id = t1.f_pid
        where t1.f_pid = #{pid}
    </select>

    <select id="selectByStockId" parameterType="long" resultMap="ElabelResult">
        select
            t1.*
        from t_warehousebillsitems_elabel t1
                 left join t_warehousebillsitems t2 on t2.f_id = t1.f_pid
                 left join t_whgenleg t3 on t3.f_originalbillno = t2.f_billno
        where t3.f_id = #{stockId}
    </select>
</mapper>
