<?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.business.mapper.TReturnStockMapper">
    
    <resultMap type="TReturnStock" id="TReturnStockResult">
        <result property="stockreturnid"    column="stockReturnId"    />
        <result property="goodsid"    column="goodsId"    />
        <result property="goodsname"    column="goodsName"    />
        <result property="location"    column="location"    />
        <result property="productlotid"    column="productlotId"    />
        <result property="ctl"    column="ctl"    />
        <result property="productiondate"    column="productionDate"    />
        <result property="expirationdate"    column="expirationDate"    />
        <result property="createdate"    column="createDate"    />
        <result property="username"    column="userName"    />
        <result property="ebs"    column="ebs"    />
        <result property="shelfnum"    column="shelfNum"    />
        <result property="provider"    column="provider"    />
    </resultMap>

    <sql id="selectTReturnStockVo">
        select stockReturnId, goodsId, goodsName, location, productlotId, ctl, productionDate, expirationDate, createDate, userName, ebs, shelfNum, provider from t_return_stock
    </sql>

    <select id="selectTReturnStockList" parameterType="TReturnStock" resultMap="TReturnStockResult">
        <include refid="selectTReturnStockVo"/>
        <where>  
            <if test="goodsid != null  and goodsid != ''"> and goodsId = #{goodsid}</if>
            <if test="goodsname != null  and goodsname != ''"> and goodsName like concat('%', #{goodsname}, '%')</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="productlotid != null  and productlotid != ''"> and productlotId = #{productlotid}</if>
            <if test="ctl != null  and ctl != ''"> and ctl = #{ctl}</if>
            <if test="productiondate != null "> and productionDate = #{productiondate}</if>
            <if test="expirationdate != null "> and expirationDate = #{expirationdate}</if>
            <if test="createdate != null "> and createDate = #{createdate}</if>
            <if test="username != null  and username != ''"> and userName like concat('%', #{username}, '%')</if>
            <if test="ebs != null  and ebs != ''"> and ebs = #{ebs}</if>
            <if test="shelfnum != null  and shelfnum != ''"> and shelfNum = #{shelfnum}</if>
            <if test="provider != null  and provider != ''"> and provider = #{provider}</if>
        </where>
    </select>
    
    <select id="selectTReturnStockByStockreturnid" parameterType="String" resultMap="TReturnStockResult">
        <include refid="selectTReturnStockVo"/>
        where stockReturnId = #{stockreturnid}
    </select>
        
    <insert id="insertTReturnStock" parameterType="TReturnStock">
        insert into t_return_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stockreturnid != null">stockReturnId,</if>
            <if test="goodsid != null">goodsId,</if>
            <if test="goodsname != null">goodsName,</if>
            <if test="location != null">location,</if>
            <if test="productlotid != null">productlotId,</if>
            <if test="ctl != null">ctl,</if>
            <if test="productiondate != null">productionDate,</if>
            <if test="expirationdate != null">expirationDate,</if>
            <if test="createdate != null">createDate,</if>
            <if test="username != null">userName,</if>
            <if test="ebs != null">ebs,</if>
            <if test="shelfnum != null">shelfNum,</if>
            <if test="provider != null">provider,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stockreturnid != null">#{stockreturnid},</if>
            <if test="goodsid != null">#{goodsid},</if>
            <if test="goodsname != null">#{goodsname},</if>
            <if test="location != null">#{location},</if>
            <if test="productlotid != null">#{productlotid},</if>
            <if test="ctl != null">#{ctl},</if>
            <if test="productiondate != null">#{productiondate},</if>
            <if test="expirationdate != null">#{expirationdate},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="username != null">#{username},</if>
            <if test="ebs != null">#{ebs},</if>
            <if test="shelfnum != null">#{shelfnum},</if>
            <if test="provider != null">#{provider},</if>
         </trim>
    </insert>

    <update id="updateTReturnStock" parameterType="TReturnStock">
        update t_return_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsid != null">goodsId = #{goodsid},</if>
            <if test="goodsname != null">goodsName = #{goodsname},</if>
            <if test="location != null">location = #{location},</if>
            <if test="productlotid != null">productlotId = #{productlotid},</if>
            <if test="ctl != null">ctl = #{ctl},</if>
            <if test="productiondate != null">productionDate = #{productiondate},</if>
            <if test="expirationdate != null">expirationDate = #{expirationdate},</if>
            <if test="createdate != null">createDate = #{createdate},</if>
            <if test="username != null">userName = #{username},</if>
            <if test="ebs != null">ebs = #{ebs},</if>
            <if test="shelfnum != null">shelfNum = #{shelfnum},</if>
            <if test="provider != null">provider = #{provider},</if>
        </trim>
        where stockReturnId = #{stockreturnid}
    </update>

    <delete id="deleteTReturnStockByStockreturnid" parameterType="String">
        delete from t_return_stock where stockReturnId = #{stockreturnid}
    </delete>

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

</mapper>