<?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="cn.ezhizao.project.business.mapper.BizReturnReceiptDetailMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizReturnReceiptDetail" id="BizReturnReceiptDetailResult">
        <id column="id" property="id"/>
    </resultMap>

    <select id="getList" parameterType="BizReturnReceiptDetail" resultMap="BizReturnReceiptDetailResult">
        SELECT * FROM biz_return_receipt_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="formCode != null  and formCode != ''"> AND form_code = #{formCode}</if>
            <if test="masterId != null"> AND master_id = #{masterId}</if>
            <if test="formDate != null "> AND form_date = #{formDate}</if>
            <if test="supplierName != null  and supplierName != ''"> AND supplier_name like concat('%', #{supplierName}, '%')</if>
            <if test="deliveryMethod != null "> AND delivery_method = #{deliveryMethod}</if>
            <if test="packagingMethod != null  and packagingMethod != ''"> AND packaging_method = #{packagingMethod}</if>
            <if test="productDescription != null  and productDescription != ''"> AND product_description = #{productDescription}</if>
            <if test="technologyVersion != null  and technologyVersion != ''"> AND technology_version = #{technologyVersion}</if>
            <if test="originalCarrier != null  and originalCarrier != ''"> AND original_carrier = #{originalCarrier}</if>
            <if test="originalCarrierCount != null "> AND original_carrier_count = #{originalCarrierCount}</if>
            <if test="newCarrier != null  and newCarrier != ''"> AND new_carrier = #{newCarrier}</if>
            <if test="newCarrierCount != null "> AND new_carrier_count = #{newCarrierCount}</if>
        </trim>
    </select>

    <select id="getListByReceiptId" parameterType="BizReturnReceiptDetail" resultMap="BizReturnReceiptDetailResult">
        SELECT r.*,f.furnace_number as furnaceNumber,
        case when (select count(1) from biz_daywork_carrier bdc where daywork_id = r.daywork_id and bdc.deleted = 0 and bdc.is_changed = 0) > 0 then 0 else 1 end as unbind
        FROM biz_return_receipt_detail r
        LEFT JOIN  biz_furnace_no_info f ON r.daywork_id=f.daywork_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            r.deleted = 0
            <if test="masterId != null"> AND r.master_id = #{id}</if>
        </trim>
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_return_receipt_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>


</mapper>
