<?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.shkj.wms.mapper.BusinBillheadMapper">

    <resultMap type="com.shkj.wms.vo.BusinBillHeadVo" id="BusinBillHeadVoResult">
        <result property="auditFlg" column="audit_flg"/>
        <result property="qrCode" column="qr_code"/>
    </resultMap>


    <resultMap type="com.shkj.wms.domain.BusinBillhead" id="BusinBillHeadResult">
        <result property="transId" column="trans_id"/>
        <result property="transNo" column="trans_no"/>
        <result property="transQual" column="trans_qual"/>
        <result property="compno" column="compno"/>
        <result property="rushFlg" column="rush_flg"/>
        <result property="rellbillNo" column="rellbill_no"/>
        <result property="tqty" column="tqty"/>
        <result property="auditFlg" column="audit_flg"/>
        <result property="taskCode" column="task_code"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="vin" column="vin"/>
        <result property="batch" column="batch"/>
        <result property="traverseDate" column="traverse_date"/>
        <result property="isCancle" column="is_cancle"/>
        <result property="cancleDate" column="cancle_date"/>
    </resultMap>

    <select id="queryBillHeadAndBody" resultMap="BusinBillHeadVoResult"
            parameterType="com.shkj.wms.bo.BusinBillHeadBodyQueryBo">
        SELECT
        head.audit_flg,
        body.qr_code
        FROM
        busin_billbody body
        INNER JOIN busin_billhead head ON body.trans_id = head.trans_id
        <if test="qrCode !=null ">
            WHERE
            body.qr_code =#{qrCode}
        </if>
    </select>

    <select id="selectBusinBillHeadByTraverseDate" resultMap="BusinBillHeadResult"
            parameterType="String">
        SELECT
        *
        FROM busin_billhead head
        <if test="traverseDate !=null ">
            WHERE
            head.traverse_Date =#{traverseDate}
        </if>
    </select>


    <select id="selectBillHeadBodyPlanOut" resultType="com.shkj.wms.vo.BusinBillHeadPlanOutVo"
            parameterType="com.shkj.wms.bo.BusinBillHeadBodyQueryBo">
        SELECT DISTINCT
        head.rush_flg,
        head.audit_flg,
        head.batch,
        outs.bumper_type,
        outs.traverse_date,
        outs.vehicle_code,
        outs.derive,
        outs.color,
        head.create_time
        FROM
        busin_billhead head
        LEFT JOIN base_barcodes_out outs ON head.vin = outs.vin
        where head.trans_qual='-1'
        <if test="batchNo !=null and batchNo != '' ">
            AND head.batch =#{batchNo}
        </if>

        <if test="outType !=null and outType != '' ">
            AND IFNULL(head.rush_flg,0) =#{outType}
        </if>

        <if test="outStatus !=null and outStatus != '' ">
            AND IFNULL(head.audit_flg,0)  =#{outStatus}
        </if>

        <if test="createTimeS != null ">
            AND head.create_Time &gt;= #{createTimeS}
        </if>

        <if test="createTimeE != null ">
            AND head.create_Time &lt;= #{createTimeE}
        </if>

    </select>

    <select id="selectBillHeadBodyInOutData" parameterType="com.shkj.wms.bo.BusinBillHeadBodyQueryBo" resultType="com.shkj.wms.vo.BusinBillHeadbodyInVo">
        select head.vin,head.batch,head.traverse_date,head.container_code,
         body.goods_no,qr_code,branch_code,storage_code,area_code,location_code,qty,is_punching,is_repair
         ,body.storage_code
        from busin_billhead head
        inner join busin_billbody body on head.id=body.trans_id
        <where>
            <if test="taskId !=null and taskId != '' ">
                AND head.task_code =#{taskId}
            </if>
            <if test="goods !=null ">
               AND body.goods_no in
                <foreach item="goodsid" collection="goods" open="(" separator="," close=")">
                    #{goodsid}
                </foreach>
            </if>
        </where>
    </select>
<update id="updateInfoBytaskCode" parameterType="long">
    update busin_billhead
        set audit_flg = 1
    where task_code = #{arg0}
</update>
    <insert id="insertBusinBillhead" parameterType="BusinBillhead" useGeneratedKeys="true" keyProperty="id">
        insert into busin_billhead
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="transId != null">trans_id,</if>
            <if test="transNo != null">trans_no,</if>
            <if test="transQual != null">trans_qual,</if>
            <if test="compno != null">compno,</if>
            <if test="rushFlg != null">rush_flg,</if>
            <if test="rellbillNo != null">rellbill_no,</if>
            <if test="tqty != null">tqty,</if>
            <if test="auditFlg != null">audit_flg,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="vin != null">vin,</if>
            <if test="batch != null">batch,</if>
            <if test="traverseDate != null">traverse_date,</if>
            <if test="isCancle != null">is_cancle,</if>
            <if test="cancleDate != null">cancle_date,</if>
            <if test="containerCode != null">container_code,</if>
            <if test="branchId != null">branch_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="transId != null">#{transId},</if>
            <if test="transNo != null">#{transNo},</if>
            <if test="transQual != null">#{transQual},</if>
            <if test="compno != null">#{compno},</if>
            <if test="rushFlg != null">#{rushFlg},</if>
            <if test="rellbillNo != null">#{rellbillNo},</if>
            <if test="tqty != null">#{tqty},</if>
            <if test="auditFlg != null">#{auditFlg},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="vin != null">#{vin},</if>
            <if test="batch != null">#{batch},</if>
            <if test="traverseDate != null">#{traverseDate},</if>
            <if test="isCancle != null">#{isCancle},</if>
            <if test="cancleDate != null">#{cancleDate},</if>
            <if test="containerCode != null">#{containerCode},</if>
            <if test="branchId != null">#{branchId},</if>
        </trim>
        <selectKey resultType="java.lang.Long" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>
</mapper>
