<?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.TScrapReportMapper">
    
    <resultMap type="TScrapReport" id="TScrapReportResult">
        <result property="goodsId"    column="GOODS_ID"    />
        <result property="goodsName"    column="GOODS_NAME"    />
        <result property="ctl"    column="CTL"    />
        <result property="location"    column="LOCATION"    />
        <result property="productlotid"    column="PRODUCTLOTID"    />
        <result property="shelfnum"    column="SHELFNUM"    />
        <result property="productiondate"    column="PRODUCTIONDATE"    />
        <result property="expirationdate"    column="EXPIRATIONDATE"    />
        <result property="createtime"    column="CREATETIME"    />
        <result property="username"    column="USERNAME"    />
        <result property="fromstatus"    column="FROMSTATUS"    />
        <result property="tostatus"    column="TOSTATUS"    />
        <result property="scrapid"    column="SCRAPID"    />
    </resultMap>

    <sql id="selectTScrapReportVo">
        select GOODS_ID, GOODS_NAME, CTL, LOCATION, PRODUCTLOTID, SHELFNUM, PRODUCTIONDATE, EXPIRATIONDATE, CREATETIME, USERNAME, FROMSTATUS, TOSTATUS, SCRAPID from t_scrap_report
    </sql>

    <select id="selectTScrapReportList" parameterType="TScrapReport" resultMap="TScrapReportResult">
        <include refid="selectTScrapReportVo"/>
        <where>  
            <if test="goodsId != null  and goodsId != ''"> and GOODS_ID = #{goodsId}</if>
            <if test="goodsName != null  and goodsName != ''"> and GOODS_NAME like concat('%', #{goodsName}, '%')</if>
            <if test="ctl != null  and ctl != ''"> and CTL = #{ctl}</if>
            <if test="location != null  and location != ''"> and LOCATION = #{location}</if>
            <if test="productlotid != null  and productlotid != ''"> and PRODUCTLOTID = #{productlotid}</if>
            <if test="shelfnum != null  and shelfnum != ''"> and SHELFNUM = #{shelfnum}</if>
            <if test="productiondate != null "> and PRODUCTIONDATE = #{productiondate}</if>
            <if test="expirationdate != null "> and EXPIRATIONDATE = #{expirationdate}</if>
            <if test="createtime != null "> and CREATETIME = #{createtime}</if>
            <if test="username != null  and username != ''"> and USERNAME like concat('%', #{username}, '%')</if>
            <if test="fromstatus != null  and fromstatus != ''"> and FROMSTATUS = #{fromstatus}</if>
            <if test="tostatus != null  and tostatus != ''"> and TOSTATUS = #{tostatus}</if>
        </where>
    </select>
    
    <select id="selectTScrapReportByScrapid" parameterType="String" resultMap="TScrapReportResult">
        <include refid="selectTScrapReportVo"/>
        where SCRAPID = #{scrapid}
    </select>
        
    <insert id="insertTScrapReport" parameterType="TScrapReport">
        insert into t_scrap_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsId != null and goodsId != ''">GOODS_ID,</if>
            <if test="goodsName != null">GOODS_NAME,</if>
            <if test="ctl != null">CTL,</if>
            <if test="location != null">LOCATION,</if>
            <if test="productlotid != null">PRODUCTLOTID,</if>
            <if test="shelfnum != null">SHELFNUM,</if>
            <if test="productiondate != null">PRODUCTIONDATE,</if>
            <if test="expirationdate != null">EXPIRATIONDATE,</if>
            <if test="createtime != null">CREATETIME,</if>
            <if test="username != null">USERNAME,</if>
            <if test="fromstatus != null">FROMSTATUS,</if>
            <if test="tostatus != null">TOSTATUS,</if>
            <if test="scrapid != null">SCRAPID,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsId != null and goodsId != ''">#{goodsId},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="ctl != null">#{ctl},</if>
            <if test="location != null">#{location},</if>
            <if test="productlotid != null">#{productlotid},</if>
            <if test="shelfnum != null">#{shelfnum},</if>
            <if test="productiondate != null">#{productiondate},</if>
            <if test="expirationdate != null">#{expirationdate},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="username != null">#{username},</if>
            <if test="fromstatus != null">#{fromstatus},</if>
            <if test="tostatus != null">#{tostatus},</if>
            <if test="scrapid != null">#{scrapid},</if>
         </trim>
    </insert>

    <update id="updateTScrapReport" parameterType="TScrapReport">
        update t_scrap_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsId != null and goodsId != ''">GOODS_ID = #{goodsId},</if>
            <if test="goodsName != null">GOODS_NAME = #{goodsName},</if>
            <if test="ctl != null">CTL = #{ctl},</if>
            <if test="location != null">LOCATION = #{location},</if>
            <if test="productlotid != null">PRODUCTLOTID = #{productlotid},</if>
            <if test="shelfnum != null">SHELFNUM = #{shelfnum},</if>
            <if test="productiondate != null">PRODUCTIONDATE = #{productiondate},</if>
            <if test="expirationdate != null">EXPIRATIONDATE = #{expirationdate},</if>
            <if test="createtime != null">CREATETIME = #{createtime},</if>
            <if test="username != null">USERNAME = #{username},</if>
            <if test="fromstatus != null">FROMSTATUS = #{fromstatus},</if>
            <if test="tostatus != null">TOSTATUS = #{tostatus},</if>
        </trim>
        where SCRAPID = #{scrapid}
    </update>

    <delete id="deleteTScrapReportByScrapid" parameterType="String">
        delete from t_scrap_report where SCRAPID = #{scrapid}
    </delete>

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

</mapper>