<?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.foreverwin.mesnac.common.mapper.NextNumberMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.common.model.NextNumber">
        <id column="HANDLE" property="handle" />
        <result column="SITE" property="site" />
        <result column="WORK_CENTER" property="workCenter" />
        <result column="NUMBER_TYPE" property="numberType" />
        <result column="PREFIX" property="prefix" />
        <result column="POSTFIX" property="postfix" />
        <result column="SEQUENCE_LENGTH" property="sequenceLength" />
        <result column="SAMPLE" property="sample" />
        <result column="REPETITION" property="repetition" />
        <result column="REMARKS" property="remarks" />
        <result column="START_SEQUENCE" property="startSequence" />
        <result column="SKIP_NUMBER" property="skipNumber" />
        <result column="CREATED_USER_BO" property="createdUserBo" />
        <result column="CREATED_DATE_TIME" property="createdDateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, SITE, WORK_CENTER, NUMBER_TYPE, PREFIX, POSTFIX, SEQUENCE_LENGTH, SAMPLE, REPETITION, REMARKS, START_SEQUENCE, SKIP_NUMBER, CREATED_USER_BO, CREATED_DATE_TIME
    </sql>

    <!-- BaseMapper标准查询/修改/删除 -->
    <select id="selectById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_NEXT_NUMBER WHERE HANDLE=#{handle}
    </select>

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_NEXT_NUMBER
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </select>

    <select id="selectBatchIds" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_NEXT_NUMBER WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </select>

    <select id="selectOne" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew.entity.handle!=null">
                HANDLE=#{ew.handle}
            </if>
            <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
            <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
            <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
            <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
            <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
            <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
            <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
            <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
            <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
            <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
            <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
            <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
            <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
        </where>
    </select>

    <select id="selectCount" resultType="Integer">
        SELECT COUNT(1) FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMaps" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectObjs" resultType="Object">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectPage" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMapsPage" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <insert id="insert" parameterType="com.foreverwin.mesnac.common.model.NextNumber">
        INSERT INTO Z_NEXT_NUMBER
        <trim prefix="(" suffix=")" suffixOverrides=",">
            HANDLE,
            <if test="site!=null">SITE,</if>
            <if test="workCenter!=null">WORK_CENTER,</if>
            <if test="numberType!=null">NUMBER_TYPE,</if>
            <if test="prefix!=null">PREFIX,</if>
            <if test="postfix!=null">POSTFIX,</if>
            <if test="sequenceLength!=null">SEQUENCE_LENGTH,</if>
            <if test="sample!=null">SAMPLE,</if>
            <if test="repetition!=null">REPETITION,</if>
            <if test="remarks!=null">REMARKS,</if>
            <if test="startSequence!=null">START_SEQUENCE,</if>
            <if test="skipNumber!=null">SKIP_NUMBER,</if>
            <if test="createdUserBo!=null">CREATED_USER_BO,</if>
            <if test="createdDateTime!=null">CREATED_DATE_TIME,</if>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            <if test="site!=null">#{site},</if>
            <if test="workCenter!=null">#{workCenter},</if>
            <if test="numberType!=null">#{numberType},</if>
            <if test="prefix!=null">#{prefix},</if>
            <if test="postfix!=null">#{postfix},</if>
            <if test="sequenceLength!=null">#{sequenceLength},</if>
            <if test="sample!=null">#{sample},</if>
            <if test="repetition!=null">#{repetition},</if>
            <if test="remarks!=null">#{remarks},</if>
            <if test="startSequence!=null">#{startSequence},</if>
            <if test="skipNumber!=null">#{skipNumber},</if>
            <if test="createdUserBo!=null">#{createdUserBo},</if>
            <if test="createdDateTime!=null">#{createdDateTime},</if>
        </trim>
    </insert>

    <insert id="insertAllColumn" parameterType="com.foreverwin.mesnac.common.model.NextNumber">
        INSERT INTO Z_NEXT_NUMBER
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{site},
            #{workCenter},
            #{numberType},
            #{prefix},
            #{postfix},
            #{sequenceLength},
            #{sample},
            #{repetition},
            #{remarks},
            #{startSequence},
            #{skipNumber},
            #{createdUserBo},
            #{createdDateTime},
        </trim>
    </insert>


    <update id="updateById">
        UPDATE Z_NEXT_NUMBER <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.numberType!=null">NUMBER_TYPE=#{et.numberType},</if>
        <if test="et.prefix!=null">PREFIX=#{et.prefix},</if>
        <if test="et.postfix!=null">POSTFIX=#{et.postfix},</if>
        <if test="et.sequenceLength!=null">SEQUENCE_LENGTH=#{et.sequenceLength},</if>
        <if test="et.sample!=null">SAMPLE=#{et.sample},</if>
        <if test="et.repetition!=null">REPETITION=#{et.repetition},</if>
        <if test="et.remarks!=null">REMARKS=#{et.remarks},</if>
        <if test="et.startSequence!=null">START_SEQUENCE=#{et.startSequence},</if>
        <if test="et.skipNumber!=null">SKIP_NUMBER=#{et.skipNumber},</if>
        <if test="et.createdUserBo!=null">CREATED_USER_BO=#{et.createdUserBo},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
    </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="updateAllColumnById">
        UPDATE Z_NEXT_NUMBER <trim prefix="SET" suffixOverrides=",">
        SITE=#{et.site},
        WORK_CENTER=#{et.workCenter},
        NUMBER_TYPE=#{et.numberType},
        PREFIX=#{et.prefix},
        POSTFIX=#{et.postfix},
        SEQUENCE_LENGTH=#{et.sequenceLength},
        SAMPLE=#{et.sample},
        REPETITION=#{et.repetition},
        REMARKS=#{et.remarks},
        START_SEQUENCE=#{et.startSequence},
        SKIP_NUMBER=#{et.skipNumber},
        CREATED_USER_BO=#{et.createdUserBo},
        CREATED_DATE_TIME=#{et.createdDateTime},
    </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="update">
        UPDATE Z_NEXT_NUMBER <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.numberType!=null">NUMBER_TYPE=#{et.numberType},</if>
        <if test="et.prefix!=null">PREFIX=#{et.prefix},</if>
        <if test="et.postfix!=null">POSTFIX=#{et.postfix},</if>
        <if test="et.sequenceLength!=null">SEQUENCE_LENGTH=#{et.sequenceLength},</if>
        <if test="et.sample!=null">SAMPLE=#{et.sample},</if>
        <if test="et.repetition!=null">REPETITION=#{et.repetition},</if>
        <if test="et.remarks!=null">REMARKS=#{et.remarks},</if>
        <if test="et.startSequence!=null">START_SEQUENCE=#{et.startSequence},</if>
        <if test="et.skipNumber!=null">SKIP_NUMBER=#{et.skipNumber},</if>
        <if test="et.createdUserBo!=null">CREATED_USER_BO=#{et.createdUserBo},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
    </trim>
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    HANDLE=#{ew.entity.handle}
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </update>

    <delete id="deleteById">
        DELETE FROM Z_NEXT_NUMBER WHERE HANDLE=#{handle}
    </delete>

    <delete id="deleteByMap">
        DELETE FROM Z_NEXT_NUMBER
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </delete>

    <delete id="delete">
        DELETE FROM Z_NEXT_NUMBER
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.numberType!=null"> AND NUMBER_TYPE=#{ew.entity.numberType}</if>
                    <if test="ew.entity.prefix!=null"> AND PREFIX=#{ew.entity.prefix}</if>
                    <if test="ew.entity.postfix!=null"> AND POSTFIX=#{ew.entity.postfix}</if>
                    <if test="ew.entity.sequenceLength!=null"> AND SEQUENCE_LENGTH=#{ew.entity.sequenceLength}</if>
                    <if test="ew.entity.sample!=null"> AND SAMPLE=#{ew.entity.sample}</if>
                    <if test="ew.entity.repetition!=null"> AND REPETITION=#{ew.entity.repetition}</if>
                    <if test="ew.entity.remarks!=null"> AND REMARKS=#{ew.entity.remarks}</if>
                    <if test="ew.entity.startSequence!=null"> AND START_SEQUENCE=#{ew.entity.startSequence}</if>
                    <if test="ew.entity.skipNumber!=null"> AND SKIP_NUMBER=#{ew.entity.skipNumber}</if>
                    <if test="ew.entity.createdUserBo!=null"> AND CREATED_USER_BO=#{ew.entity.createdUserBo}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </delete>

    <delete id="deleteBatchIds">
        DELETE FROM Z_NEXT_NUMBER WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </delete>
    <!-- BaseMapper标准查询/修改/删除 -->

    <!-- 查询厂区下所有的编码规则 -->
    <resultMap id="NextNumberResultMap" type="com.foreverwin.mesnac.common.dto.NextNumberDto" extends="BaseResultMap">
        <result column="CURRENT_SEQ" property="currentSeq" />
        <result column="USED" property="used" />
    </resultMap>

    <select id="selectListBySite" resultMap="NextNumberResultMap">
        SELECT NN.HANDLE,NN.SITE,NN.NUMBER_TYPE,NN.PREFIX,NN.POSTFIX,NN.SEQUENCE_LENGTH,NN.SAMPLE,NN.REPETITION,NN.REMARKS,NN.START_SEQUENCE,
             MAX(NNC.CURRENT_SEQ) CURRENT_SEQ, NN.SKIP_NUMBER, CASE WHEN MAX(NNC.CURRENT_SEQ) IS NULL THEN 'N' ELSE 'Y' END USED
        FROM Z_NEXT_NUMBER NN
        LEFT JOIN Z_NEXT_NUMBER_CODE NNC ON NNC.NEXT_NUMBER_BO = NN.HANDLE
        WHERE NN.SITE = #{site}
        GROUP BY NN.HANDLE,NN.SITE,NN.NUMBER_TYPE,NN.PREFIX,NN.POSTFIX,NN.SEQUENCE_LENGTH,NN.SAMPLE,NN.REPETITION,NN.REMARKS,NN.START_SEQUENCE,NN.SKIP_NUMBER
        ORDER BY NN.NUMBER_TYPE ASC
    </select>
</mapper>
