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

    <resultMap type="com.shkj.wms.domain.BaseBarcodesIn" id="BaseBarcodesInResult">
        <result property="qrCode" column="qr_Code"/>
        <result property="vehicheModel" column="vehiche_Model"/>
        <result property="color" column="color"/>
        <result property="location" column="location"/>
        <result property="isSplit" column="is_Split"/>
        <result property="isPunching" column="is_Punching"/>
        <result property="isRepair" column="is_Repair"/>
        <result property="goodsNo" column="goods_No"/>
        <result property="locationCode" column="location_Code"/>
        <result property="orientation" column="orientation"/>
        <result property="punchingResult" column="punching_Result"/>
    </resultMap>

    <select id="getBaseBarcodesInByQuery" resultMap="BaseBarcodesInResult"
            parameterType="String">
        SELECT
        *
        FROM
        base_barcodes_in
        <if test="qrCode !=null and qrCode != '' ">
            WHERE
            base_barcodes_in.qr_code =#{qrCode}
        </if>
    </select>

    <select id="getBaseBarcodesInByDerice" resultMap="BaseBarcodesInResult"
            parameterType="com.shkj.wms.domain.BaseDerive">
        SELECT
        *
        FROM
        base_barcodes_in
        WHERE 1=1
        <if test="color != null and color != ''">
            AND color = #{color}
        </if>
        <if test="vehicheModel != null  and vehicheModel != '' ">
            AND vehiche_model = #{vehicheModel}
        </if>
        <if test="isSplit != null  and isSplit != '' ">
            AND is_split = #{isSplit}
        </if>
        <if test="isPunching != null  and isPunching != '' ">
            AND is_punching = #{isPunching}
        </if>
        <if test="orientation != null  and orientation != '' ">
            AND orientation = #{orientation}
        </if>
        <if test="locationCode != null  and locationCode != '' ">
            AND location_code = #{locationCode}
        </if>
        LIMIT 1
    </select>

    <select id="getBillInPlanData" resultMap="BaseBarcodesInResult"
            parameterType="com.shkj.wms.bo.BaseBarcodesInQueryBo">
        SELECT
        *
        FROM
        base_barcodes_in
        WHERE 1=1
        <if test="color != null  and color != '' ">
            AND color = #{color}
        </if>
        <if test="vehicheModel != null  and vehicheModel != '' ">
            AND vehiche_model = #{vehicheModel}
        </if>
        <if test="isSplit != null  and isSplit != '' ">
            AND is_split = #{isSplit}
        </if>
        <if test="isPunching != null  and isPunching != '' ">
            AND is_punching = #{isPunching}
        </if>
        <if test="orientation != null  and orientation != '' ">
            AND orientation = #{orientation}
        </if>
        <if test="locationCode != null  and locationCode != ''">
            AND location_code = #{locationCode}
        </if>
        <if test="qrCode != null  and qrCode != '' ">
            AND qr_code = #{qrCode}
        </if>

        <if test="inStatus != null  and inStatus != ''">
            AND in_status = #{inStatus}
        </if>

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

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

    </select>


    <select id="getCurrentDateInAndOutQty" resultType="com.shkj.wms.vo.BaseInOutQtyVo">
       SELECT
	    ins.in_date,ins.inqty,outs.outqty,punchings.punchingQty,repairs.repairQty
        FROM
    	(
	       SELECT count( * ) as inqty, location, in_date FROM base_barcodes_in WHERE in_Status = '4'  and in_date =CURRENT_DATE
	       GROUP BY location, in_date LIMIT 1
	    ) ins
	    LEFT JOIN
	    (
	        SELECT count( * )as outqty, out_date FROM base_barcodes_out WHERE out_status = '3'  and out_date= CURRENT_DATE
	        GROUP BY out_date
	    ) outs ON ins.in_date = outs.out_date
		left join
		(
			select count(*) as punchingQty ,in_date from base_barcodes_in where in_Status='4' and in_date= CURRENT_DATE
			and is_punching='1' and punching_result='0'
			group by in_date
		) punchings on punchings.in_date=ins.in_date
		left join(
			select count(*) as repairQty ,in_date from base_barcodes_in where in_Status='3' and in_date= CURRENT_DATE
			group by in_date
		)repairs  on repairs.in_date=ins.in_date


    </select>

</mapper>
