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


    <sql id = "BaseSql">
    PRS.ID,
    PRS.STACK_NO,
    PRS.MAIN_BACKLOG_CODE,
    PRS.DO_FLG,
    PRS.REMARK,
    PRS.TENANT_ID,
    PRS.ATTRIBUTE1,
    PRS.ATTRIBUTE2,
    PRS.ATTRIBUTE3,
    PRS.ATTRIBUTE4,
    PRS.ATTRIBUTE5,
    PRS.creation_date,    PRS.created_by,    PRS.last_updated_by,    PRS.last_update_date,    PRS.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmRetainStack">
        select
        <include refid = "BaseSql"/>
        from PM_RETAIN_STACK PRS
        <where>
            <if test="id !=null">
                and PRS.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="stackNo !=null">
                and PRS.STACK_NO like concat(concat('%',#{stackNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="mainBacklogCode !=null">
                and PRS.MAIN_BACKLOG_CODE = #{mainBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="remark !=null">
                and PRS.REMARK = #{remark,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PRS.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PRS.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PRS.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PRS.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PRS.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PRS.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id = "exportList" parameterType = "com.xisc.pm.domain.entity.PmRetainStack" resultType = "com.xisc.pm.api.dto.export.PmRetainStackDTO">
        select
        <include refid = "BaseSql"/>
        from PM_RETAIN_STACK PRS
        <where>
            <if test="id !=null">
                and PRS.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="stackNo !=null">
                and PRS.STACK_NO like concat(concat('%',#{stackNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="mainBacklogCode !=null">
                and PRS.MAIN_BACKLOG_CODE = #{mainBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="remark !=null">
                and PRS.REMARK = #{remark,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PRS.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PRS.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PRS.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PRS.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PRS.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PRS.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id = "checkList" resultType = "com.xisc.pm.domain.entity.PmRetainStack">
        select
        <include refid = "BaseSql"/>
        from PM_RETAIN_STACK PRS
        <where>
            <if test="orderNoList != null and orderNoList.size()>0">
                and  (PRS.STACK_NO || '_' || PRS.MAIN_BACKLOG_CODE in
                <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," index="index">
                    <if test="(index % 999) == 998"> NULL ) OR PRS.STACK_NO || '_' || PRS.MAIN_BACKLOG_CODE in (</if> #{orderNo}
                </foreach>)
            </if>
        </where>
    </select>
</mapper>

