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

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


    <select id="getList" parameterType="BizOutsourcedOrderDetailProcess" resultMap="BizOutsourcedOrderDetailProcessResult">
        SELECT * FROM biz_outsourced_order_detail_process
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="formCode != null  and formCode != ''"> AND form_code = #{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="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="processAlias != null  and processAlias != ''"> AND process_alias = #{processAlias}</if>
        </trim>
    </select>
    <select id="getDetailList" resultMap="BizOutsourcedOrderDetailProcessResult">
        select t1.*,t2.original_carrier,t2.new_carrier,t1.qualified_num as receipt_num,t2.original_carrier_count,t2.new_carrier_count  from biz_outsourced_order_detail_process t1
        left join biz_outsourced_order_detail t2 on t1.detail_id = t2.id
        where t1.deleted = 0 and t2.deleted = 0 and t1.detail_id = #{id} order by t1.process_step_number
    </select>

    <update id="removeByMasterIds" parameterType="java.util.List">
        UPDATE biz_outsourced_order_detail_process set deleted = 1
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            master_id in
            <foreach collection="ids" item="masterId" open="(" separator="," close=")">
                #{masterId}
            </foreach>
        </trim>
    </update>



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