<?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.dhcc.finance.main.dao.CwGlVouchermaxnoMapper">
  <resultMap id="BaseResultMap" type="com.dhcc.finance.main.domain.CwGlVouchermaxno">
    <id column="PK_VOUCHERMAXNO" jdbcType="VARCHAR" property="pkVouchermaxno" />
    <result column="PK_GLORGBOOK" jdbcType="VARCHAR" property="pkGlorgbook" />
    <result column="PERIOD" jdbcType="VARCHAR" property="period" />
    <result column="PK_VOUCHERTYPE" jdbcType="VARCHAR" property="pkVouchertype" />
    <result column="MAXNO" jdbcType="VARCHAR" property="maxno" />
    <result column="USE_STATE" jdbcType="VARCHAR" property="useState" />
    <result column="CREATE_USER" jdbcType="VARCHAR" property="createUser" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_USER" jdbcType="VARCHAR" property="updateUser" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    PK_VOUCHERMAXNO, PK_GLORGBOOK, PERIOD, PK_VOUCHERTYPE, MAXNO, USE_STATE, CREATE_USER, 
    CREATE_TIME, UPDATE_USER, UPDATE_TIME
  </sql>
  <select id="selectByExample" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxnoExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cw_gl_vouchermaxno
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from cw_gl_vouchermaxno
    where PK_VOUCHERMAXNO = #{pkVouchermaxno,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from cw_gl_vouchermaxno
    where PK_VOUCHERMAXNO = #{pkVouchermaxno,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxnoExample">
    delete from cw_gl_vouchermaxno
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxno">
    insert into cw_gl_vouchermaxno (PK_VOUCHERMAXNO, PK_GLORGBOOK, PERIOD, 
      PK_VOUCHERTYPE, MAXNO, USE_STATE, 
      CREATE_USER, CREATE_TIME, UPDATE_USER, 
      UPDATE_TIME)
    values (#{pkVouchermaxno,jdbcType=VARCHAR}, #{pkGlorgbook,jdbcType=VARCHAR}, #{period,jdbcType=VARCHAR}, 
      #{pkVouchertype,jdbcType=VARCHAR}, #{maxno,jdbcType=VARCHAR}, #{useState,jdbcType=VARCHAR}, 
      #{createUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR}, 
      #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxno">
    insert into cw_gl_vouchermaxno
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pkVouchermaxno != null">
        PK_VOUCHERMAXNO,
      </if>
      <if test="pkGlorgbook != null">
        PK_GLORGBOOK,
      </if>
      <if test="period != null">
        PERIOD,
      </if>
      <if test="pkVouchertype != null">
        PK_VOUCHERTYPE,
      </if>
      <if test="maxno != null">
        MAXNO,
      </if>
      <if test="useState != null">
        USE_STATE,
      </if>
      <if test="createUser != null">
        CREATE_USER,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateUser != null">
        UPDATE_USER,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="pkVouchermaxno != null">
        #{pkVouchermaxno,jdbcType=VARCHAR},
      </if>
      <if test="pkGlorgbook != null">
        #{pkGlorgbook,jdbcType=VARCHAR},
      </if>
      <if test="period != null">
        #{period,jdbcType=VARCHAR},
      </if>
      <if test="pkVouchertype != null">
        #{pkVouchertype,jdbcType=VARCHAR},
      </if>
      <if test="maxno != null">
        #{maxno,jdbcType=VARCHAR},
      </if>
      <if test="useState != null">
        #{useState,jdbcType=VARCHAR},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null">
        #{updateUser,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxnoExample" resultType="java.lang.Long">
    select count(*) from cw_gl_vouchermaxno
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update cw_gl_vouchermaxno
    <set>
      <if test="record.pkVouchermaxno != null">
        PK_VOUCHERMAXNO = #{record.pkVouchermaxno,jdbcType=VARCHAR},
      </if>
      <if test="record.pkGlorgbook != null">
        PK_GLORGBOOK = #{record.pkGlorgbook,jdbcType=VARCHAR},
      </if>
      <if test="record.period != null">
        PERIOD = #{record.period,jdbcType=VARCHAR},
      </if>
      <if test="record.pkVouchertype != null">
        PK_VOUCHERTYPE = #{record.pkVouchertype,jdbcType=VARCHAR},
      </if>
      <if test="record.maxno != null">
        MAXNO = #{record.maxno,jdbcType=VARCHAR},
      </if>
      <if test="record.useState != null">
        USE_STATE = #{record.useState,jdbcType=VARCHAR},
      </if>
      <if test="record.createUser != null">
        CREATE_USER = #{record.createUser,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateUser != null">
        UPDATE_USER = #{record.updateUser,jdbcType=VARCHAR},
      </if>
      <if test="record.updateTime != null">
        UPDATE_TIME = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update cw_gl_vouchermaxno
    set PK_VOUCHERMAXNO = #{record.pkVouchermaxno,jdbcType=VARCHAR},
      PK_GLORGBOOK = #{record.pkGlorgbook,jdbcType=VARCHAR},
      PERIOD = #{record.period,jdbcType=VARCHAR},
      PK_VOUCHERTYPE = #{record.pkVouchertype,jdbcType=VARCHAR},
      MAXNO = #{record.maxno,jdbcType=VARCHAR},
      USE_STATE = #{record.useState,jdbcType=VARCHAR},
      CREATE_USER = #{record.createUser,jdbcType=VARCHAR},
      CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP},
      UPDATE_USER = #{record.updateUser,jdbcType=VARCHAR},
      UPDATE_TIME = #{record.updateTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxno">
    update cw_gl_vouchermaxno
    <set>
      <if test="pkGlorgbook != null">
        PK_GLORGBOOK = #{pkGlorgbook,jdbcType=VARCHAR},
      </if>
      <if test="period != null">
        PERIOD = #{period,jdbcType=VARCHAR},
      </if>
      <if test="pkVouchertype != null">
        PK_VOUCHERTYPE = #{pkVouchertype,jdbcType=VARCHAR},
      </if>
      <if test="maxno != null">
        MAXNO = #{maxno,jdbcType=VARCHAR},
      </if>
      <if test="useState != null">
        USE_STATE = #{useState,jdbcType=VARCHAR},
      </if>
      <if test="createUser != null">
        CREATE_USER = #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null">
        UPDATE_USER = #{updateUser,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where PK_VOUCHERMAXNO = #{pkVouchermaxno,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dhcc.finance.main.domain.CwGlVouchermaxno">
    update cw_gl_vouchermaxno
    set PK_GLORGBOOK = #{pkGlorgbook,jdbcType=VARCHAR},
      PERIOD = #{period,jdbcType=VARCHAR},
      PK_VOUCHERTYPE = #{pkVouchertype,jdbcType=VARCHAR},
      MAXNO = #{maxno,jdbcType=VARCHAR},
      USE_STATE = #{useState,jdbcType=VARCHAR},
      CREATE_USER = #{createUser,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      UPDATE_USER = #{updateUser,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
    where PK_VOUCHERMAXNO = #{pkVouchermaxno,jdbcType=VARCHAR}
  </update>
<!--   获取最大凭证号 -->
  <select id="selectGetMaxNo" resultMap="BaseResultMap">
  	select 
  	<include refid="Base_Column_List" />
  	 from cw_gl_vouchermaxno 
  	 where USE_STATE= '1'  
	 and PK_GLORGBOOK= #{pkGlorgbook,jdbcType=VARCHAR} 
     and PERIOD= #{period,jdbcType=VARCHAR} 
  </select>
  <!-- 查询某账套某期间全部最大凭证号信息 -->
  <select id="selectCwGlVouchermaxno" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from cw_gl_vouchermaxno
    where USE_STATE= '1'   and PK_GLORGBOOK= #{pkGlorgbook,jdbcType=VARCHAR} and PERIOD= #{period,jdbcType=VARCHAR} 
  </select>
  <!--批量插入最大凭证号信息--> 
  <insert id="insertCwGlVouchermaxnoBatch" parameterType="java.util.List">
    insert into cw_gl_vouchermaxno (PK_VOUCHERMAXNO, PK_GLORGBOOK, PERIOD, PK_VOUCHERTYPE, MAXNO, USE_STATE, CREATE_USER, 
    CREATE_TIME)
    select temp.PK_VOUCHERMAXNO, temp.PK_GLORGBOOK, temp.PERIOD, temp.PK_VOUCHERTYPE, temp.MAXNO, temp.USE_STATE, temp.CREATE_USER, temp.CREATE_TIME from (
    <foreach collection="list" item="item" index="index"  separator="union all">
    select 
      #{item.pkVouchermaxno,jdbcType=VARCHAR} as PK_VOUCHERMAXNO, 
      #{item.pkGlorgbook,jdbcType=VARCHAR} as PK_GLORGBOOK, 
      #{item.period,jdbcType=VARCHAR} as PERIOD, 
      #{item.pkVouchertype,jdbcType=VARCHAR} as PK_VOUCHERTYPE, 
      '0'  as MAXNO, 
      #{item.useState,jdbcType=VARCHAR} as USE_STATE, 
      #{item.createUser,jdbcType=VARCHAR} as CREATE_USER, 
      #{item.createTime,jdbcType=TIMESTAMP} as CREATE_TIME
     from dual
     where not exists(select 1 from cw_gl_vouchermaxno a  where  a.PK_GLORGBOOK=#{item.pkGlorgbook,jdbcType=VARCHAR} and 
     a.PERIOD=#{item.period,jdbcType=VARCHAR}  and USE_STATE= '1' )
   </foreach> 
      ) temp
  </insert>

  <select id="getVoucherMaxNo" resultMap="BaseResultMap">
    select getVoucherMaxno(#{pkGlorgbook,jdbcType=VARCHAR},#{period,jdbcType=VARCHAR}) MAXNO
  </select>
  <!--   批量获取最大凭证号 -->
  <select id="selectGetMaxNoForBatch" resultMap="BaseResultMap">
  	select 
  	<include refid="Base_Column_List" />
  	 from cw_gl_vouchermaxno 
  	 <where>
            USE_STATE = '1'
            and PK_GLORGBOOK= #{pkGlorgbook,jdbcType=VARCHAR}
            and PERIOD in
            <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                #{item,jdbcType=VARCHAR}
            </foreach>
      </where>
  </select>
</mapper>