<?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.CwGlWeightedMapper">
  <resultMap id="BaseResultMap" type="com.dhcc.finance.main.domain.CwGlWeighted">
    <id column="PK_WEIGHTED" jdbcType="VARCHAR" property="pkWeighted" />
    <result column="XTXMBH" jdbcType="VARCHAR" property="xtxmbh" />
    <result column="XTZXMBH" jdbcType="VARCHAR" property="xtzxmbh" />
    <result column="SUBJCODE" jdbcType="VARCHAR" property="subjcode" />
    <result column="START_DATE" jdbcType="DATE" property="startDate" />
    <result column="END_DATE" jdbcType="DATE" property="endDate" />
    <result column="WEIGHTED_DAYS" jdbcType="DECIMAL" property="weightedDays" />
    <result column="WEIGHTED_BAL" jdbcType="DECIMAL" property="weightedBal" />
    <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_WEIGHTED, XTXMBH, XTZXMBH, SUBJCODE, START_DATE, END_DATE, WEIGHTED_DAYS, WEIGHTED_BAL, 
    USE_STATE, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME, REMARK
  </sql>
  <select id="selectByExample" parameterType="com.dhcc.finance.main.domain.CwGlWeightedExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cw_gl_weighted
    <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_weighted
    where PK_WEIGHTED = #{pkWeighted,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from cw_gl_weighted
    where PK_WEIGHTED = #{pkWeighted,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.dhcc.finance.main.domain.CwGlWeightedExample">
    delete from cw_gl_weighted
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.dhcc.finance.main.domain.CwGlWeighted">
    insert into cw_gl_weighted (PK_WEIGHTED, XTXMBH, XTZXMBH, 
      SUBJCODE, START_DATE, END_DATE, 
      WEIGHTED_DAYS, WEIGHTED_BAL, USE_STATE, 
      CREATE_USER, CREATE_TIME, UPDATE_USER, 
      UPDATE_TIME, REMARK)
    values (#{pkWeighted,jdbcType=VARCHAR}, #{xtxmbh,jdbcType=VARCHAR}, #{xtzxmbh,jdbcType=VARCHAR}, 
      #{subjcode,jdbcType=VARCHAR}, #{startDate,jdbcType=DATE}, #{endDate,jdbcType=DATE}, 
      #{weightedDays,jdbcType=DECIMAL}, #{weightedBal,jdbcType=DECIMAL}, #{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.CwGlWeighted">
    insert into cw_gl_weighted
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pkWeighted != null">
        PK_WEIGHTED,
      </if>
      <if test="xtxmbh != null">
        XTXMBH,
      </if>
      <if test="xtzxmbh != null">
        XTZXMBH,
      </if>
      <if test="subjcode != null">
        SUBJCODE,
      </if>
      <if test="startDate != null">
        START_DATE,
      </if>
      <if test="endDate != null">
        END_DATE,
      </if>
      <if test="weightedDays != null">
        WEIGHTED_DAYS,
      </if>
      <if test="weightedBal != null">
        WEIGHTED_BAL,
      </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="pkWeighted != null">
        #{pkWeighted,jdbcType=VARCHAR},
      </if>
      <if test="xtxmbh != null">
        #{xtxmbh,jdbcType=VARCHAR},
      </if>
      <if test="xtzxmbh != null">
        #{xtzxmbh,jdbcType=VARCHAR},
      </if>
      <if test="subjcode != null">
        #{subjcode,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        #{startDate,jdbcType=DATE},
      </if>
      <if test="endDate != null">
        #{endDate,jdbcType=DATE},
      </if>
      <if test="weightedDays != null">
        #{weightedDays,jdbcType=DECIMAL},
      </if>
      <if test="weightedBal != null">
        #{weightedBal,jdbcType=DECIMAL},
      </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.CwGlWeightedExample" resultType="java.lang.Long">
    select count(*) from cw_gl_weighted
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update cw_gl_weighted
    <set>
      <if test="record.pkWeighted != null">
        PK_WEIGHTED = #{record.pkWeighted,jdbcType=VARCHAR},
      </if>
      <if test="record.xtxmbh != null">
        XTXMBH = #{record.xtxmbh,jdbcType=VARCHAR},
      </if>
      <if test="record.xtzxmbh != null">
        XTZXMBH = #{record.xtzxmbh,jdbcType=VARCHAR},
      </if>
      <if test="record.subjcode != null">
        SUBJCODE = #{record.subjcode,jdbcType=VARCHAR},
      </if>
      <if test="record.startDate != null">
        START_DATE = #{record.startDate,jdbcType=DATE},
      </if>
      <if test="record.endDate != null">
        END_DATE = #{record.endDate,jdbcType=DATE},
      </if>
      <if test="record.weightedDays != null">
        WEIGHTED_DAYS = #{record.weightedDays,jdbcType=DECIMAL},
      </if>
      <if test="record.weightedBal != null">
        WEIGHTED_BAL = #{record.weightedBal,jdbcType=DECIMAL},
      </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_gl_weighted
    set PK_WEIGHTED = #{record.pkWeighted,jdbcType=VARCHAR},
      XTXMBH = #{record.xtxmbh,jdbcType=VARCHAR},
      XTZXMBH = #{record.xtzxmbh,jdbcType=VARCHAR},
      SUBJCODE = #{record.subjcode,jdbcType=VARCHAR},
      START_DATE = #{record.startDate,jdbcType=DATE},
      END_DATE = #{record.endDate,jdbcType=DATE},
      WEIGHTED_DAYS = #{record.weightedDays,jdbcType=DECIMAL},
      WEIGHTED_BAL = #{record.weightedBal,jdbcType=DECIMAL},
      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.CwGlWeighted">
    update cw_gl_weighted
    <set>
      <if test="xtxmbh != null">
        XTXMBH = #{xtxmbh,jdbcType=VARCHAR},
      </if>
      <if test="xtzxmbh != null">
        XTZXMBH = #{xtzxmbh,jdbcType=VARCHAR},
      </if>
      <if test="subjcode != null">
        SUBJCODE = #{subjcode,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        START_DATE = #{startDate,jdbcType=DATE},
      </if>
      <if test="endDate != null">
        END_DATE = #{endDate,jdbcType=DATE},
      </if>
      <if test="weightedDays != null">
        WEIGHTED_DAYS = #{weightedDays,jdbcType=DECIMAL},
      </if>
      <if test="weightedBal != null">
        WEIGHTED_BAL = #{weightedBal,jdbcType=DECIMAL},
      </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_WEIGHTED = #{pkWeighted,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dhcc.finance.main.domain.CwGlWeighted">
    update cw_gl_weighted
    set XTXMBH = #{xtxmbh,jdbcType=VARCHAR},
      XTZXMBH = #{xtzxmbh,jdbcType=VARCHAR},
      SUBJCODE = #{subjcode,jdbcType=VARCHAR},
      START_DATE = #{startDate,jdbcType=DATE},
      END_DATE = #{endDate,jdbcType=DATE},
      WEIGHTED_DAYS = #{weightedDays,jdbcType=DECIMAL},
      WEIGHTED_BAL = #{weightedBal,jdbcType=DECIMAL},
      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_WEIGHTED = #{pkWeighted,jdbcType=VARCHAR}
  </update>
  <insert id="initCwGlWeighted" parameterType="java.util.Map">
    insert into cw_gl_weighted (PK_WEIGHTED, XTXMBH, XTZXMBH, 
      SUBJCODE, START_DATE, END_DATE, 
      WEIGHTED_DAYS, WEIGHTED_BAL, USE_STATE, 
      CREATE_USER, CREATE_TIME)
      select MD5(uuid()) as PK_WEIGHTED, a.XTXMBH, null, a.SUBJCODE, #{startDate,jdbcType=DATE} START_DATE, #{endDate,jdbcType=DATE} END_DATE, 
      (datediff(max(REPORT_DATE),min(REPORT_DATE))+1) as WEIGHTED_DAYS, round(sum(balance)/(datediff(max(REPORT_DATE),min(REPORT_DATE))+1),2) as WEIGHTED_BAL,
       #{useState,jdbcType=VARCHAR} USE_STATE, #{createUser,jdbcType=VARCHAR}, now() CREATE_TIME 
      from  cw_gl_weighted_detail a   
      <![CDATA[ where a.REPORT_DATE>=#{startDate,jdbcType=DATE} and a.REPORT_DATE<=#{endDate,jdbcType=DATE} group by a.XTXMBH  ]]>
  </insert>
   <delete id="deleteAll" >
    truncate table cw_gl_weighted
  </delete>
</mapper>