<?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.CwBdVouchtempFMapper">
  <resultMap id="BaseResultMap" type="com.dhcc.finance.main.domain.CwBdVouchtempF">
    <id column="PK_VOUCHTEMP_F" jdbcType="VARCHAR" property="pkVouchtempF" />
    <result column="PK_VOUCHTEMP_B" jdbcType="VARCHAR" property="pkVouchtempB" />
    <result column="ASSORDER" jdbcType="INTEGER" property="assorder" />
    <result column="PK_ACCASS" jdbcType="VARCHAR" property="pkAccass" />
    <result column="ASSVALUE" jdbcType="VARCHAR" property="assvalue" />
    <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" />
    <result column="REMARK" jdbcType="VARCHAR" property="remark" />
  </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_VOUCHTEMP_F, PK_VOUCHTEMP_B, ASSORDER, PK_ACCASS, ASSVALUE, USE_STATE, CREATE_USER, 
    CREATE_TIME, UPDATE_USER, UPDATE_TIME, REMARK
  </sql>
  <select id="selectByExample" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempFExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cw_bd_vouchtemp_f
    <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_bd_vouchtemp_f
    where PK_VOUCHTEMP_F = #{pkVouchtempF,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from cw_bd_vouchtemp_f
    where PK_VOUCHTEMP_F = #{pkVouchtempF,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempFExample">
    delete from cw_bd_vouchtemp_f
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempF">
    insert into cw_bd_vouchtemp_f (PK_VOUCHTEMP_F, PK_VOUCHTEMP_B, ASSORDER, 
      PK_ACCASS, ASSVALUE, USE_STATE, 
      CREATE_USER, CREATE_TIME, UPDATE_USER, 
      UPDATE_TIME, REMARK)
    values (#{pkVouchtempF,jdbcType=VARCHAR}, #{pkVouchtempB,jdbcType=VARCHAR}, #{assorder,jdbcType=INTEGER}, 
      #{pkAccass,jdbcType=VARCHAR}, #{assvalue,jdbcType=VARCHAR}, #{useState,jdbcType=VARCHAR}, 
      #{createUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempF">
    insert into cw_bd_vouchtemp_f
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pkVouchtempF != null">
        PK_VOUCHTEMP_F,
      </if>
      <if test="pkVouchtempB != null">
        PK_VOUCHTEMP_B,
      </if>
      <if test="assorder != null">
        ASSORDER,
      </if>
      <if test="pkAccass != null">
        PK_ACCASS,
      </if>
      <if test="assvalue != null">
        ASSVALUE,
      </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>
      <if test="remark != null">
        REMARK,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="pkVouchtempF != null">
        #{pkVouchtempF,jdbcType=VARCHAR},
      </if>
      <if test="pkVouchtempB != null">
        #{pkVouchtempB,jdbcType=VARCHAR},
      </if>
      <if test="assorder != null">
        #{assorder,jdbcType=INTEGER},
      </if>
      <if test="pkAccass != null">
        #{pkAccass,jdbcType=VARCHAR},
      </if>
      <if test="assvalue != null">
        #{assvalue,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>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempFExample" resultType="java.lang.Long">
    select count(*) from cw_bd_vouchtemp_f
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update cw_bd_vouchtemp_f
    <set>
      <if test="record.pkVouchtempF != null">
        PK_VOUCHTEMP_F = #{record.pkVouchtempF,jdbcType=VARCHAR},
      </if>
      <if test="record.pkVouchtempB != null">
        PK_VOUCHTEMP_B = #{record.pkVouchtempB,jdbcType=VARCHAR},
      </if>
      <if test="record.assorder != null">
        ASSORDER = #{record.assorder,jdbcType=INTEGER},
      </if>
      <if test="record.pkAccass != null">
        PK_ACCASS = #{record.pkAccass,jdbcType=VARCHAR},
      </if>
      <if test="record.assvalue != null">
        ASSVALUE = #{record.assvalue,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>
      <if test="record.remark != null">
        REMARK = #{record.remark,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update cw_bd_vouchtemp_f
    set PK_VOUCHTEMP_F = #{record.pkVouchtempF,jdbcType=VARCHAR},
      PK_VOUCHTEMP_B = #{record.pkVouchtempB,jdbcType=VARCHAR},
      ASSORDER = #{record.assorder,jdbcType=INTEGER},
      PK_ACCASS = #{record.pkAccass,jdbcType=VARCHAR},
      ASSVALUE = #{record.assvalue,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},
      REMARK = #{record.remark,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempF">
    update cw_bd_vouchtemp_f
    <set>
      <if test="pkVouchtempB != null">
        PK_VOUCHTEMP_B = #{pkVouchtempB,jdbcType=VARCHAR},
      </if>
      <if test="assorder != null">
        ASSORDER = #{assorder,jdbcType=INTEGER},
      </if>
      <if test="pkAccass != null">
        PK_ACCASS = #{pkAccass,jdbcType=VARCHAR},
      </if>
      <if test="assvalue != null">
        ASSVALUE = #{assvalue,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>
      <if test="remark != null">
        REMARK = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where PK_VOUCHTEMP_F = #{pkVouchtempF,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempF">
    update cw_bd_vouchtemp_f
    set PK_VOUCHTEMP_B = #{pkVouchtempB,jdbcType=VARCHAR},
      ASSORDER = #{assorder,jdbcType=INTEGER},
      PK_ACCASS = #{pkAccass,jdbcType=VARCHAR},
      ASSVALUE = #{assvalue,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},
      REMARK = #{remark,jdbcType=VARCHAR}
    where PK_VOUCHTEMP_F = #{pkVouchtempF,jdbcType=VARCHAR}
  </update>
  <!--根据科目编号新增辅助信息  --> 
  <insert id="insertCwBdVouchtempF" parameterType="java.util.List">
    insert into cw_bd_vouchtemp_f (PK_VOUCHTEMP_F, PK_VOUCHTEMP_B, ASSORDER, 
      PK_ACCASS, ASSVALUE, USE_STATE, 
      CREATE_USER, CREATE_TIME)
    select temp.PK_VOUCHTEMP_F, temp.PK_VOUCHTEMP_B, temp.ASSORDER, temp.PK_ACCASS, temp.ASSVALUE, temp.USE_STATE, temp.CREATE_USER, temp.CREATE_TIME from (
    <foreach collection="list" item="item" index="index"  separator="union all">
    select 
      MD5(uuid()) as PK_VOUCHTEMP_F,
      #{item.pkVouchtempB,jdbcType=VARCHAR} as PK_VOUCHTEMP_B, 
      ASSORDER, 
      PK_ACCASSITEM as PK_ACCASS,
      '' as ASSVALUE, 
      '1' as USE_STATE, 
      #{item.createUser,jdbcType=VARCHAR} as CREATE_USER, 
      #{item.createTime,jdbcType=TIMESTAMP} as CREATE_TIME
     from CW_BD_ACCASS where PK_ACCSUBJ = #{item.pkAccsubj,jdbcType=VARCHAR} and USE_STATE='1'
     and exists (select 1 from CW_BD_ACCSUBJ where  PK_ACCSUBJ = #{item.pkAccsubj,jdbcType=VARCHAR} and AUXFLAG='1' )
   </foreach> 
      ) temp
  </insert>
  <!--查询某分录下全部辅助信息  -->
  <select id="searchCwBdVouchtempF" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempF" resultMap="BaseResultMap">
	 select    c.PK_VOUCHTEMP_F, c.PK_VOUCHTEMP_B, c.ASSORDER,
	 (select  NAME from cw_bd_accassitem where PK_ACCASSITEM= c.PK_ACCASS ) as PK_ACCASS, 
	  c.ASSVALUE, c.USE_STATE, 
      c.CREATE_USER, c.CREATE_TIME, c.UPDATE_USER, 
      c.UPDATE_TIME, c.REMARK
	 from cw_bd_vouchtemp_f c where c.USE_STATE='1' and PK_VOUCHTEMP_B = #{pkVouchtempB,jdbcType=VARCHAR}
  </select>
  <!--逻辑删除某分录信息下全部辅助信息 -->
  <update id="deleteCwBdVouchtempF" parameterType="com.dhcc.finance.main.domain.CwBdVouchtempB">
    update cw_bd_vouchtemp_f
    set 
      USE_STATE = '0'
    where PK_VOUCHTEMP_B = #{pkVouchtempB,jdbcType=VARCHAR}
  </update>
  <select id="selectByPkVouchtempB" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from cw_bd_vouchtemp_f
    where USE_STATE='1' AND  PK_VOUCHTEMP_B = #{pkVouchtempB,jdbcType=VARCHAR}
  </select>
</mapper>