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


    <sql id = "BaseSql">
    PSO.ID,
    PSO.ORDER_NO,
    PSO.SG_SIGN,
    PSO.ST_NO,
    PSO.ORDER_THICK,
    PSO.ORDER_WIDTH,
    PSO.LEN_AIM,
    PSO.DELIVY_DATE,
    PSO.AXIS_ORD,
    PSO.LACK_NUM,
    PSO.OVER_NUM,
    PSO.ORDER_SEQ_NO,
    PSO.TENANT_ID,
    PSO.ATTRIBUTE1,
    PSO.ATTRIBUTE2,
    PSO.ATTRIBUTE3,
    PSO.ATTRIBUTE4,
    PSO.ATTRIBUTE5,
    PSO.VIRTUAL_SLAB_NO,
    PSO.POS_X,
    PSO.POS_Y,
    PSO.creation_date,    PSO.created_by,    PSO.last_updated_by,    PSO.last_update_date,    PSO.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmSubOrd">
        select
        <include refid = "BaseSql"/>
        from PM_SUB_ORD PSO
        <where>
            <if test="id !=null">
                and PSO.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="orderNo !=null">
                and PSO.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PSO.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="stNo !=null">
                and PSO.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="orderThick !=null">
                and PSO.ORDER_THICK = #{orderThick,jdbcType = INTEGER}
            </if>
            <if test="orderWidth !=null">
                and PSO.ORDER_WIDTH = #{orderWidth,jdbcType = INTEGER}
            </if>
            <if test="lenAim !=null">
                and PSO.LEN_AIM = #{lenAim,jdbcType = INTEGER}
            </if>
            <if test="delivyDate !=null">
                and PSO.DELIVY_DATE = #{delivyDate,jdbcType = OTHER}
            </if>
            <if test="axisOrd !=null">
                and PSO.AXIS_ORD = #{axisOrd,jdbcType = VARCHAR}
            </if>
            <if test="lackNum !=null">
                and PSO.LACK_NUM = #{lackNum,jdbcType = INTEGER}
            </if>
            <if test="overNum !=null">
                and PSO.OVER_NUM = #{overNum,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and PSO.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSO.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSO.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSO.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSO.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSO.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
            <if test="virtualSlabNo !=null">
                and PSO.VIRTUAL_SLAB_NO = #{virtualSlabNo,jdbcType = VARCHAR}
            </if>
            <if test="posX !=null">
                and PSO.POS_X = #{posX,jdbcType = INTEGER}
            </if>
            <if test="posY !=null">
                and PSO.POS_Y = #{posY,jdbcType = INTEGER}
            </if>
        </where>
    </select>

    <select id = "selectOrdList" parameterType = "com.xisc.pm.domain.entity.PmSubOrd" resultType="com.xisc.pm.api.dto.PmSubOrdResponseDTO">
        select
        DENSE_RANK() OVER (ORDER BY PSO.ORDER_NO) AS ORDER_GROUP,
        <include refid = "BaseSql"/>
        from PM_SUB_ORD PSO
        <where>
            <if test="id !=null">
                and PSO.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="orderNo !=null">
                and PSO.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PSO.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="stNo !=null">
                and PSO.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="orderThick !=null">
                and PSO.ORDER_THICK = #{orderThick,jdbcType = INTEGER}
            </if>
            <if test="orderWidth !=null">
                and PSO.ORDER_WIDTH = #{orderWidth,jdbcType = INTEGER}
            </if>
            <if test="lenAim !=null">
                and PSO.LEN_AIM = #{lenAim,jdbcType = INTEGER}
            </if>
            <if test="delivyDate !=null">
                and PSO.DELIVY_DATE = #{delivyDate,jdbcType = OTHER}
            </if>
            <if test="axisOrd !=null">
                and PSO.AXIS_ORD = #{axisOrd,jdbcType = VARCHAR}
            </if>
            <if test="lackNum !=null">
                and PSO.LACK_NUM = #{lackNum,jdbcType = INTEGER}
            </if>
            <if test="overNum !=null">
                and PSO.OVER_NUM = #{overNum,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and PSO.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSO.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSO.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSO.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSO.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSO.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
            <if test="virtualSlabNo !=null">
                and PSO.VIRTUAL_SLAB_NO = #{virtualSlabNo,jdbcType = VARCHAR}
            </if>
            <if test="posX !=null">
                and PSO.POS_X = #{posX,jdbcType = INTEGER}
            </if>
            <if test="posY !=null">
                and PSO.POS_Y = #{posY,jdbcType = INTEGER}
            </if>
        </where>
    </select>
</mapper>

