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

    <resultMap type="com.shkj.wms.domain.BaseDerive" id="BaseDeriveResult">
        <result property="derive" column="derive"/>
        <result property="vehicheCode" column="vehiche_code"/>
        <result property="vehicheModel" column="vehiche_model"/>
        <result property="frontLocation" column="front_location"/>
        <result property="frontSplit" column="front_split"/>
        <result property="rearLocation" column="rear_location"/>
        <result property="rearSplit" column="rear_split"/>
        <result property="frontPunching" column="front_punching"/>
        <result property="rearPunching" column="rear_punching"/>
        <result property="remark" column="remark"/>
        <result property="color" column="color"/>
    </resultMap>

    <resultMap type="java.util.HashMap" id="deriveColorResult">
        <result property="color"    column="color"  />
    </resultMap>

    <resultMap type="java.util.HashMap" id="vehicheModelResult">
        <result property="vehicheModel"    column="vehiche_model"  />
    </resultMap>

    <resultMap type="java.util.HashMap" id="vehicheCodelResult">
        <result property="vehicheCode"    column="vehiche_code"   />
    </resultMap>

    <resultMap type="java.util.HashMap" id="deriveResult">
        <result property="derive"    column="derive"  />
    </resultMap>

    <select id="selectBaseDeriveListByVehiche" resultMap="BaseDeriveResult" parameterType="com.shkj.wms.bo.BaseBarcodesOutAddBo">
            SELECT
            *
            FROM
            base_derive
            <if test="derive !=null ">
            WHERE
                base_derive.derive =#{derive}
            </if>
            <if test="vehicleCode !=null ">
                AND
                base_derive.vehiche_code =#{vehicleCode}
            </if>
    </select>


    <select id="selectBaseDeriveBybarcodes" resultMap="BaseDeriveResult" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
        SELECT * FROM  base_derive
        <where>
            <if test="derive !=null and derive !='' ">
                AND base_derive.derive =#{derive}
            </if>

            <if test="vehicheCode !=null and vehicheCode !='' ">
                AND base_derive.vehiche_code =#{vehicheCode}
            </if>

            <if test="vehicheModel !=null and vehicheModel !='' ">
              AND base_derive.vehiche_model =#{vehicheModel}
            </if>

            <if test="frontLocation !=null and frontLocation !='' ">
                AND base_derive.front_location =#{frontLocation}
            </if>

            <if test="frontSplit !=null and frontSplit !='' ">
                AND base_derive.front_split =#{frontSplit}
            </if>

            <if test="frontPunching !=null and frontPunching !='' ">
                AND base_derive.front_punching =#{frontPunching}
            </if>

            <if test="rearLocation !=null and rearLocation !='' ">
                AND base_derive.rear_location =#{rearLocation}
            </if>

            <if test="rearSplit !=null and rearSplit !='' ">
                AND base_derive.rear_split =#{rearSplit}
            </if>

            <if test="rearPunching !=null and rearPunching !='' ">
                AND base_derive.rear_punching =#{rearPunching}
            </if>
            <if test="color !=null and color !='' ">
                AND base_derive.color =#{color}
            </if>
            <if test="color !=null and color != ''">
                AND base_derive.color=#{color}
            </if>
        </where>
        limit 1

    </select>


    <select id="selectBaseDeriveList" resultMap="BaseDeriveResult" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
        SELECT
        bd.*
        FROM
        base_derive bd
        where 1 = 1
        <if test="derive !=null ">
            AND
            bd.derive =#{derive}
        </if>
        <if test="vehicheCode !=null ">
            AND
            bd.vehiche_code =#{vehicheCode}
        </if>
    </select>

    <select id="getColorInfo" resultMap="deriveColorResult" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
       select distinct color from base_derive derive
       where ifnull(color,'') !=''
        <if test="derive !=null and derive !='' ">
            AND derive.derive =#{derive}
        </if>
        <if test="vehicheModel !=null and vehicheModel !=''">
            AND (derive.vehiche_model =#{vehicheModel} or derive.vehiche_code =#{vehicheModel} )
        </if>
    </select>

    <select id="getVehicheModelInfo" resultMap="vehicheModelResult">
        select distinct vehiche_model from base_derive
    </select>

    <select id="getVehicheCodeInfo" resultMap="vehicheCodelResult" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
        select distinct vehiche_code from base_derive derive
        <where>
            <if test="derive !=null and derive !='' ">
                AND derive.derive =#{derive}
            </if>
        </where>
    </select>

    <select id="getDeriveInfo" resultMap="deriveResult" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
       select distinct derive from base_derive
        <where>
            <if test="vehicheModel !=null and vehicheModel !='' ">
                AND vehiche_model =#{vehicheModel}
            </if>
        </where>
    </select>

    <select id="getGoodsInfoByDerive" resultType="com.shkj.wms.domain.BaseGoodsData" parameterType="com.shkj.wms.bo.BaseDeriveQueryBo">
        SELECT
        goods.color,
        goods.vehiche_model,
        goods.location,
        goods.is_split,
        goods.is_punching,
        goods.location_code,
        goods.orientation,
        goods.goods_no,
        detail.location_id,detail.qr_code
        FROM
        base_goods_data goods
        INNER JOIN base_derive derive ON goods.vehiche_model = derive.vehiche_model
        AND goods.color = derive.color
        INNER JOIN sys_stock_detail detail ON goods.goods_no=detail.goods_no
        where qty>0

        <if test="derive !=null and derive !='' ">
            AND derive.derive =#{derive}
        </if>
        <if test="vehicheCode !=null and vehicheCode !='' ">
            AND derive.vehiche_code =#{vehicheCode}
        </if>

        <if test="vehicheModel !=null and vehicheModel !='' ">
            AND derive.vehiche_model =#{vehicheModel}
        </if>
        <if test="color !=null and color !='' ">
            AND derive.color =#{color}
        </if>


    </select>
</mapper>
