<?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.hzs.scm.no.mapper.ScmBillNoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.scm.no.ScmBillNo">
        <id column="PK_ID" property="pkId" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PREFIX_CODE" property="prefixCode" />
        <result column="BILL_NAME" property="billName" />
        <result column="ORDER_TYPE" property="orderType" />
        <result column="CONTAIN_YEAR" property="containYear" />
        <result column="CONTAIN_MONTH" property="containMonth" />
        <result column="CONTAIN_DAY" property="containDay" />
        <result column="END_DIGIT" property="endDigit" />
        <result column="RESET_TYPE" property="resetType" />
        <result column="INITIAL_VALUE" property="initialValue" />
        <result column="NEXT_VALUE" property="nextValue" />
    </resultMap>
    <update id="updateScmBillNo">
        update SCM_BILL_NO set MODIFIED_TIME=sysdate,NEXT_VALUE=NEXT_VALUE+1
        where pk_id=#{pkId} and del_flag=0
    </update>
    <update id="updateScmBillNoNextValue">
        merge into SCM_BILL_NO a
        using (
        <foreach collection="dayBillNoList" item="item" open=" " separator=" union " close=" ">
            select #{item.pkId} pk_id,#{item.initialValue} initial_value from dual
        </foreach>
            ) b
        on (a.pk_id=b.pk_id)
        when matched then
            update set a.next_value=b.initial_value
    </update>

</mapper>
