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

    <resultMap type="cn.ezhizao.project.business.domain.BizOutsourcedOrder" id="BizOutsourcedOrderResult">
        <id column="id" property="id"/>
        <collection property="returnReceiptDetails" ofType="cn.ezhizao.project.business.domain.BizReturnReceiptDetail" column="id" select="getReturnReceiptDetail"/>
    </resultMap>


    <select id="getList" parameterType="BizOutsourcedOrder" resultMap="BizOutsourcedOrderResult">
        SELECT * FROM biz_outsourced_order
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="formCode != null  and formCode != ''"> AND form_code like concat('%',#{formCode},'%')</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="freightPrice != null "> AND freight_price = #{freightPrice}</if>
            <if test="freightAmount != null "> AND freight_amount = #{freightAmount}</if>
            <if test="isFirstProcess != null "> AND is_first_process = #{isFirstProcess}</if>
            <if test="packagingMethod != null  and packagingMethod != ''"> AND packaging_method = #{packagingMethod}</if>
        </trim>
        order by create_time desc
    </select>
    <select id="getAllList" resultType="cn.ezhizao.project.business.domain.BizOutsourcedOrder">
        select t1.* from biz_outsourced_order t1  order by t1.form_code desc
    </select>
    <select id="getReturnReceiptDetail" resultType="cn.ezhizao.project.business.domain.BizReturnReceiptDetail">
        select * from biz_return_receipt_detail t1 left join biz_outsourced_order_detail t2 on t1.outsource_detail_id = t2.id
        left join biz_outsourced_order t3 on t2.master_id = t3.id where t3.id = #{id} and t1.deleted = 0 and t2.deleted = 0 and t1.deleted = 0 and t1.status = 1
    </select>

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