<?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.xisc.pm.infra.mapper.WmMatPileMapper">


    <sql id = "BaseSql">
    WMP.MAT_PILE_ID,
    WMP.MAT_ID,
    WMP.MAT_NO,
    WMP.STOCK_ID,
    WMP.PILE_ID,
    WMP.STOCK_CODE,
    WMP.PILE_NO,
    WMP.LAYER_NO,
    WMP.TRUCK_NO,
    WMP.CRANE_NO,
    WMP.IN_STOCK_TIME,
    WMP.IN_PILE_TIME,
    WMP.MAT_KIND,
    WMP.TRANSFER_FLAG,
    WMP.TENANT_ID,
    WMP.ATTRIBUTE1,
    WMP.ATTRIBUTE2,
    WMP.ATTRIBUTE3,
    WMP.ATTRIBUTE4,
    WMP.ATTRIBUTE5,
    WMP.creation_date,    WMP.created_by,    WMP.last_updated_by,    WMP.last_update_date,    WMP.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.vo.WmMatPileVO1">
        select
        <include refid = "BaseSql"/>
        from WM_MAT_PILE WMP
        <where>
            <if test="matPileId !=null">
                and WMP.MAT_PILE_ID = #{matPileId,jdbcType = INTEGER}
            </if>
            <if test="matId !=null">
                and WMP.MAT_ID = #{matId,jdbcType = INTEGER}
            </if>
            <if test="matNo !=null">
                and WMP.MAT_NO = #{matNo,jdbcType = VARCHAR}
            </if>
            <if test="stockId !=null">
                and WMP.STOCK_ID = #{stockId,jdbcType = INTEGER}
            </if>
            <if test="pileId !=null">
                and WMP.PILE_ID = #{pileId,jdbcType = INTEGER}
            </if>
            <if test="stockCode !=null">
                and WMP.STOCK_CODE = #{stockCode,jdbcType = VARCHAR}
            </if>
            <if test="pileNo !=null">
                and WMP.PILE_NO = #{pileNo,jdbcType = VARCHAR}
            </if>
            <if test="layerNo !=null">
                and WMP.LAYER_NO = #{layerNo,jdbcType = INTEGER}
            </if>
            <if test="truckNo !=null">
                and WMP.TRUCK_NO = #{truckNo,jdbcType = VARCHAR}
            </if>
            <if test="craneNo !=null">
                and WMP.CRANE_NO = #{craneNo,jdbcType = VARCHAR}
            </if>
            <if test="inStockTime !=null">
                and WMP.IN_STOCK_TIME = #{inStockTime,jdbcType = OTHER}
            </if>
            <if test="inPileTime !=null">
                and WMP.IN_PILE_TIME = #{inPileTime,jdbcType = OTHER}
            </if>
            <if test="matKind !=null">
                and WMP.MAT_KIND = #{matKind,jdbcType = VARCHAR}
            </if>
            <if test="transferFlag !=null">
                and WMP.TRANSFER_FLAG = #{transferFlag,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and WMP.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and WMP.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and WMP.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and WMP.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and WMP.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and WMP.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>
    
    
	
	<select id="selectWmMatPileByMatNo" resultType="com.xisc.pm.domain.vo.WmMatPileVo">
		SELECT MAT_PILE_ID,
		    MAT_ID,
		    MAT_NO,
		    STOCK_ID ,
		    PILE_ID,
		    STOCK_CODE ,
		    PILE_NO,
		    LAYER_NO,
		    TRUCK_NO,
		    CRANE_NO,
		    IN_STOCK_TIME ,
		    IN_PILE_TIME,
		    MAT_KIND,
		    TRANSFER_FLAG ,
		    TENANT_ID,
		    ATTRIBUTE1 ,
		    ATTRIBUTE2,
		    ATTRIBUTE3,
		    ATTRIBUTE4,
		    ATTRIBUTE5 FROM WM_MAT_PILE WHERE MAT_NO = #{matNo} AND TENANT_ID = #{tenantId}
	</select>
	
	<select id="getStockLineByCode" resultType="com.xisc.pm.domain.vo.WmStockInfoVO">
        SELECT
        wsi.STOCK_ID,
        wsi.STOCK_CODE,
        wsi.STOCK_DESC,
        wsi.STOCK_LINE
        FROM
        WM_STOCK_INFO wsi
        WHERE
        wsi.enable_flag = 1
        and wsi.STOCK_CODE = #{stockCode}
        AND wsi.TENANT_ID = #{tenantId}
    </select>

    <select id="getProdYearByMmSlab" resultType="com.xisc.pm.domain.vo.MmSlabVO">
        SELECT
            ms.PROD_YEAR,
            ms.SLAB_NO
        FROM
            MM_SLAB ms
        <where>
           <if test="tenantId !=null">
                and ms.TENANT_ID = #{tenantId}
           </if>
           <if test="matNoList != null and matNoList.size() > 0">
				and ms.SLAB_NO in
				<foreach collection="matNoList" item="matNo" open="(" close=")" separator="," >
					#{matNo}
				</foreach>
			</if>
        </where>
    </select>
</mapper>
