<?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.bonus.material.push.mapper.PushDataReceiveDetailMapper">
    <resultMap type="com.bonus.material.push.domain.PushDataReceiveDetail" id="PushDataReceiveDetailResult">
        <result property="id"    column="id"    />
        <result property="receiveId"    column="receive_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="rentTime"    column="rent_time"    />
        <result property="rentPrice"    column="rent_price"    />
        <result property="unitId"    column="unit_id"    />
        <result property="supplier"    column="supplier"    />
        <result property="outFactoryTime"    column="out_factory_time"    />
        <result property="isNew"    column="is_new"    />
        <result property="checkCode"    column="check_code"    />
        <result property="checkUnit"    column="check_unit"    />
        <result property="checkDate"    column="check_date"    />
        <result property="nextCheckDate"    column="next_check_date"    />
        <result property="maUserName"    column="ma_user_name"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPushDataReceiveDetailVo">
        select id, receive_id, type_id, ma_id, rent_time, rent_price, unit_id, supplier, out_factory_time, is_new, check_code, check_unit, check_date, next_check_date, ma_user_name, status, create_time, update_time from push_data_receive_detail
    </sql>

    <select id="selectPushDataReceiveDetailList" parameterType="com.bonus.material.push.domain.PushDataReceiveDetail" resultMap="PushDataReceiveDetailResult">
        <include refid="selectPushDataReceiveDetailVo"/>
        <where>  
            <if test="receiveId != null "> and receive_id = #{receiveId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="rentTime != null "> and rent_time = #{rentTime}</if>
            <if test="rentPrice != null "> and rent_price = #{rentPrice}</if>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="supplier != null  and supplier != ''"> and supplier = #{supplier}</if>
            <if test="outFactoryTime != null "> and out_factory_time = #{outFactoryTime}</if>
            <if test="isNew != null "> and is_new = #{isNew}</if>
            <if test="checkCode != null  and checkCode != ''"> and check_code = #{checkCode}</if>
            <if test="checkUnit != null  and checkUnit != ''"> and check_unit = #{checkUnit}</if>
            <if test="checkDate != null "> and check_date = #{checkDate}</if>
            <if test="nextCheckDate != null "> and next_check_date = #{nextCheckDate}</if>
            <if test="maUserName != null  and maUserName != ''"> and ma_user_name like concat('%', #{maUserName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectPushDataReceiveDetailById" parameterType="Long" resultMap="PushDataReceiveDetailResult">
        <include refid="selectPushDataReceiveDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPushDataReceiveDetail" parameterType="com.bonus.material.push.domain.PushDataReceiveDetail" useGeneratedKeys="true" keyProperty="id">
        insert into push_data_receive_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="receiveId != null">receive_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="rentTime != null">rent_time,</if>
            <if test="rentPrice != null">rent_price,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="supplier != null">supplier,</if>
            <if test="outFactoryTime != null">out_factory_time,</if>
            <if test="isNew != null">is_new,</if>
            <if test="checkCode != null">check_code,</if>
            <if test="checkUnit != null">check_unit,</if>
            <if test="checkDate != null">check_date,</if>
            <if test="nextCheckDate != null">next_check_date,</if>
            <if test="maUserName != null">ma_user_name,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="receiveId != null">#{receiveId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="rentTime != null">#{rentTime},</if>
            <if test="rentPrice != null">#{rentPrice},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="outFactoryTime != null">#{outFactoryTime},</if>
            <if test="isNew != null">#{isNew},</if>
            <if test="checkCode != null">#{checkCode},</if>
            <if test="checkUnit != null">#{checkUnit},</if>
            <if test="checkDate != null">#{checkDate},</if>
            <if test="nextCheckDate != null">#{nextCheckDate},</if>
            <if test="maUserName != null">#{maUserName},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePushDataReceiveDetail" parameterType="com.bonus.material.push.domain.PushDataReceiveDetail">
        update push_data_receive_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="receiveId != null">receive_id = #{receiveId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="rentTime != null">rent_time = #{rentTime},</if>
            <if test="rentPrice != null">rent_price = #{rentPrice},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="supplier != null">supplier = #{supplier},</if>
            <if test="outFactoryTime != null">out_factory_time = #{outFactoryTime},</if>
            <if test="isNew != null">is_new = #{isNew},</if>
            <if test="checkCode != null">check_code = #{checkCode},</if>
            <if test="checkUnit != null">check_unit = #{checkUnit},</if>
            <if test="checkDate != null">check_date = #{checkDate},</if>
            <if test="nextCheckDate != null">next_check_date = #{nextCheckDate},</if>
            <if test="maUserName != null">ma_user_name = #{maUserName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePushDataReceiveDetailById" parameterType="Long">
        delete from push_data_receive_detail where id = #{id}
    </delete>

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