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

    <sql id = "BaseSql">
    PPSB.PPTAB_ID,
    PPSB.ST_CODE,
    PPSB.FORM_PLATE_MODE,
    PPSB.AD_TYPE_MODE,
    PPSB.ROLL_MODE,
    PPSB.WHOLE_HEAT_TREATMENT_TYPE,
    PPSB.ROLL_LINE_NO,
    PPSB.PLATE_THICK_FROM,
    PPSB.PLATE_THICK_TO,
    PPSB.COMBINE_PLATE_WIDTH_FROM,
    PPSB.COMBINE_PLATE_WIDTH_TO,
    PPSB.COMBINE_PLATE_LEN_MAX,
    PPSB.REMARK,
    PPSB.TENANT_ID,
    PPSB.ATTRIBUTE1,
    PPSB.ATTRIBUTE2,
    PPSB.ATTRIBUTE3,
    PPSB.ATTRIBUTE4,
    PPSB.ATTRIBUTE5,
    PPSB.creation_date,    PPSB.created_by,    PPSB.last_updated_by,    PPSB.last_update_date,    PPSB.object_version_number
    </sql>
    
    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmPlateSpecBt">
        select
        <include refid = "BaseSql"/>
        from PM_PLATE_SPEC_BT PPSB
        <where>
            <if test="pptabId !=null">
                and PPSB.PPTAB_ID = #{pptabId,jdbcType = INTEGER}
            </if>
            <if test="stCode !=null">
                and PPSB.ST_CODE = #{stCode,jdbcType = VARCHAR}
            </if>
            <if test="formPlateMode !=null">
                <bind name="formPlateMode" value="formPlateMode + '%'"/>
                and PPSB.FORM_PLATE_MODE LIKE #{formPlateMode}
            </if>
            <if test="adTypeMode !=null">
                and PPSB.AD_TYPE_MODE = #{adTypeMode,jdbcType = VARCHAR}
            </if>
            <if test="rollMode !=null">
                and PPSB.ROLL_MODE = #{rollMode,jdbcType = VARCHAR}
            </if>
            <if test="wholeHeatTreatmentType !=null">
                <bind name="wholeHeatTreatmentType" value="'%' + wholeHeatTreatmentType + '%'"/>
                and PPSB.WHOLE_HEAT_TREATMENT_TYPE LIKE #{wholeHeatTreatmentType}
            </if>
            <if test="rollLineNo !=null">
                and PPSB.ROLL_LINE_NO = #{rollLineNo,jdbcType = VARCHAR}
            </if>
            <if test="plateThickFrom !=null">
                and PPSB.PLATE_THICK_FROM <![CDATA[ <= ]]> #{plateThickFrom}
            </if>
            <if test="plateThickTo !=null">
                and PPSB.PLATE_THICK_FROM <![CDATA[ <= ]]> #{plateThickTo}
            </if>
            <if test="plateThickTo !=null">
                and PPSB.PLATE_THICK_TO <![CDATA[ >= ]]> #{plateThickTo}
            </if>
            <if test="plateThickFrom !=null">
                and PPSB.PLATE_THICK_TO <![CDATA[ >= ]]> #{plateThickFrom}
            </if>
            <if test="combinePlateWidthFrom !=null">
                and PPSB.COMBINE_PLATE_WIDTH_FROM <![CDATA[ <= ]]> #{combinePlateWidthFrom}
            </if>
            <if test="combinePlateWidthTo !=null">
                and PPSB.COMBINE_PLATE_WIDTH_FROM <![CDATA[ <= ]]> #{combinePlateWidthTo}
            </if>
            <if test="combinePlateWidthTo !=null">
                and PPSB.COMBINE_PLATE_WIDTH_TO <![CDATA[ >= ]]> #{combinePlateWidthTo}
            </if>
            <if test="combinePlateWidthFrom !=null">
                and PPSB.COMBINE_PLATE_WIDTH_TO <![CDATA[ >= ]]> #{combinePlateWidthFrom}
            </if>
            <if test="combinePlateLenMax !=null">
                and PPSB.COMBINE_PLATE_LEN_MAX = #{combinePlateLenMax}
            </if>
            <if test="remark !=null">
                <bind name="remark" value="'%' + remark + '%'"/>
                and PPSB.REMARK like #{remark}
            </if>
            <if test="tenantId !=null">
                and PPSB.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PPSB.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PPSB.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PPSB.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PPSB.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PPSB.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>
    
    <select id="maxCombinePlateLenMax" resultType="java.math.BigDecimal">
    	select
        	max(ppsb.COMBINE_PLATE_LEN_MAX) COMBINE_PLATE_LEN_MAX
        from PM_PLATE_SPEC_BT PPSB
        where PPSB.TENANT_ID = #{tenantId}
    </select>  
</mapper>
