<?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.CwReverseOperationMapper">
  <resultMap id="BaseResultMap" type="com.dhcc.finance.main.domain.CwReverseOperation">
    <id column="PK_REVERSE" jdbcType="VARCHAR" property="pkReverse" />
    <result column="PK_GLORGBOOK" jdbcType="VARCHAR" property="pkGlorgbook" />
    <result column="PERIOD" jdbcType="VARCHAR" property="period" />
    <result column="PK_VOUCHER" jdbcType="VARCHAR" property="pkVoucher" />
    <result column="REVERSE_TYPE" jdbcType="VARCHAR" property="reverseType" />
    <result column="OPERATOR" jdbcType="VARCHAR" property="operator" />
    <result column="OPERATIONTIME" jdbcType="TIMESTAMP" property="operationtime" />
  </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_REVERSE, PK_GLORGBOOK, PERIOD, PK_VOUCHER, REVERSE_TYPE, OPERATOR, OPERATIONTIME
  </sql>
  <select id="selectByExample" parameterType="com.dhcc.finance.main.domain.CwReverseOperationExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cw_reverse_operation
    <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_reverse_operation
    where PK_REVERSE = #{pkReverse,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from cw_reverse_operation
    where PK_REVERSE = #{pkReverse,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.dhcc.finance.main.domain.CwReverseOperationExample">
    delete from cw_reverse_operation
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.dhcc.finance.main.domain.CwReverseOperation">
    insert into cw_reverse_operation (PK_REVERSE, PK_GLORGBOOK, PERIOD, 
      PK_VOUCHER, REVERSE_TYPE, OPERATOR, 
      OPERATIONTIME)
    values (#{pkReverse,jdbcType=VARCHAR}, #{pkGlorgbook,jdbcType=VARCHAR}, #{period,jdbcType=VARCHAR}, 
      #{pkVoucher,jdbcType=VARCHAR}, #{reverseType,jdbcType=VARCHAR}, #{operator,jdbcType=VARCHAR}, 
      #{operationtime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.dhcc.finance.main.domain.CwReverseOperation">
    insert into cw_reverse_operation
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pkReverse != null">
        PK_REVERSE,
      </if>
      <if test="pkGlorgbook != null">
        PK_GLORGBOOK,
      </if>
      <if test="period != null">
        PERIOD,
      </if>
      <if test="pkVoucher != null">
        PK_VOUCHER,
      </if>
      <if test="reverseType != null">
        REVERSE_TYPE,
      </if>
      <if test="operator != null">
        OPERATOR,
      </if>
      <if test="operationtime != null">
        OPERATIONTIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="pkReverse != null">
        #{pkReverse,jdbcType=VARCHAR},
      </if>
      <if test="pkGlorgbook != null">
        #{pkGlorgbook,jdbcType=VARCHAR},
      </if>
      <if test="period != null">
        #{period,jdbcType=VARCHAR},
      </if>
      <if test="pkVoucher != null">
        #{pkVoucher,jdbcType=VARCHAR},
      </if>
      <if test="reverseType != null">
        #{reverseType,jdbcType=VARCHAR},
      </if>
      <if test="operator != null">
        #{operator,jdbcType=VARCHAR},
      </if>
      <if test="operationtime != null">
        #{operationtime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.dhcc.finance.main.domain.CwReverseOperationExample" resultType="java.lang.Long">
    select count(*) from cw_reverse_operation
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update cw_reverse_operation
    <set>
      <if test="record.pkReverse != null">
        PK_REVERSE = #{record.pkReverse,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.pkVoucher != null">
        PK_VOUCHER = #{record.pkVoucher,jdbcType=VARCHAR},
      </if>
      <if test="record.reverseType != null">
        REVERSE_TYPE = #{record.reverseType,jdbcType=VARCHAR},
      </if>
      <if test="record.operator != null">
        OPERATOR = #{record.operator,jdbcType=VARCHAR},
      </if>
      <if test="record.operationtime != null">
        OPERATIONTIME = #{record.operationtime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update cw_reverse_operation
    set PK_REVERSE = #{record.pkReverse,jdbcType=VARCHAR},
      PK_GLORGBOOK = #{record.pkGlorgbook,jdbcType=VARCHAR},
      PERIOD = #{record.period,jdbcType=VARCHAR},
      PK_VOUCHER = #{record.pkVoucher,jdbcType=VARCHAR},
      REVERSE_TYPE = #{record.reverseType,jdbcType=VARCHAR},
      OPERATOR = #{record.operator,jdbcType=VARCHAR},
      OPERATIONTIME = #{record.operationtime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.dhcc.finance.main.domain.CwReverseOperation">
    update cw_reverse_operation
    <set>
      <if test="pkGlorgbook != null">
        PK_GLORGBOOK = #{pkGlorgbook,jdbcType=VARCHAR},
      </if>
      <if test="period != null">
        PERIOD = #{period,jdbcType=VARCHAR},
      </if>
      <if test="pkVoucher != null">
        PK_VOUCHER = #{pkVoucher,jdbcType=VARCHAR},
      </if>
      <if test="reverseType != null">
        REVERSE_TYPE = #{reverseType,jdbcType=VARCHAR},
      </if>
      <if test="operator != null">
        OPERATOR = #{operator,jdbcType=VARCHAR},
      </if>
      <if test="operationtime != null">
        OPERATIONTIME = #{operationtime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where PK_REVERSE = #{pkReverse,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dhcc.finance.main.domain.CwReverseOperation">
    update cw_reverse_operation
    set PK_GLORGBOOK = #{pkGlorgbook,jdbcType=VARCHAR},
      PERIOD = #{period,jdbcType=VARCHAR},
      PK_VOUCHER = #{pkVoucher,jdbcType=VARCHAR},
      REVERSE_TYPE = #{reverseType,jdbcType=VARCHAR},
      OPERATOR = #{operator,jdbcType=VARCHAR},
      OPERATIONTIME = #{operationtime,jdbcType=TIMESTAMP}
    where PK_REVERSE = #{pkReverse,jdbcType=VARCHAR}
  </update>
  <select id="searchCwReverseOperationCount" parameterType="java.lang.String" resultType="java.lang.Integer">
   select count(*) from (
		select PK_REVERSE, PK_GLORGBOOK, PERIOD, PK_VOUCHER, REVERSE_TYPE, OPERATOR, DATE_FORMAT(OPERATIONTIME,'%Y-%m-%d') as OPERATIONTIME 
		from cw_reverse_operation ) cro
 		where  REVERSE_TYPE= #{reverseType,jdbcType=VARCHAR}
		  <if test="reverseType != null">
		  <![CDATA[  and (PK_VOUCHER is not null and PK_VOUCHER <>'')]]>
		  and  OPERATIONTIME = #{today,jdbcType=VARCHAR}
		   </if>
  </select>
   <insert id="insertBatch" parameterType="java.util.List">
    insert into cw_reverse_operation (PK_REVERSE, PK_GLORGBOOK, PERIOD, 
      PK_VOUCHER, REVERSE_TYPE, OPERATOR, 
      OPERATIONTIME)
    values 
    <foreach collection="list" item="item" index="index" separator="," >
    (#{item.pkReverse,jdbcType=VARCHAR}, #{item.pkGlorgbook,jdbcType=VARCHAR}, #{item.period,jdbcType=VARCHAR}, 
      #{item.pkVoucher,jdbcType=VARCHAR}, #{item.reverseType,jdbcType=VARCHAR}, #{item.operator,jdbcType=VARCHAR}, 
      #{item.operationtime,jdbcType=TIMESTAMP})
   </foreach>
  </insert>
</mapper>