<?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.steerinfo.ems.trmtimegran.mapper.TRmTimegranMapper">
  <resultMap id="BaseResultMap2" type="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="REMARK" jdbcType="VARCHAR" property="remark" />
    <result column="FMTEXP" jdbcType="VARCHAR" property="fmtexp" />
    <result column="BCODE" jdbcType="VARCHAR" property="bcode" />
    <result column="BDESC1" jdbcType="VARCHAR" property="bdesc1" />
    <result column="BDESC2" jdbcType="VARCHAR" property="bdesc2" />
    <result column="ISDEFAULT" jdbcType="VARCHAR" property="isdefault" />
    <result column="SUMGRAN" jdbcType="VARCHAR" property="sumgran" />
    <result column="INIT_OFFSET" jdbcType="VARCHAR" property="initOffset" />
    <result column="CREATEMAN" jdbcType="VARCHAR" property="createman" />
    <result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
    <result column="UPDATEMAN" jdbcType="VARCHAR" property="updateman" />
    <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
  </resultMap>
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="REMARK" jdbcType="VARCHAR" property="remark" />
    <result column="FMTEXP" jdbcType="VARCHAR" property="fmtexp" />
    <result column="BCODE" jdbcType="VARCHAR" property="bcode" />
    <result column="BDESC1" jdbcType="VARCHAR" property="bdesc1" />
    <result column="BDESC2" jdbcType="VARCHAR" property="bdesc2" />
    <result column="ISDEFAULT" jdbcType="VARCHAR" property="isdefault" />
    <result column="SUMGRAN" jdbcType="VARCHAR" property="sumgran" />
    <result column="INIT_OFFSET" jdbcType="VARCHAR" property="initOffset" />
      <association property="tCmDatasourceTimegran"  javaType="com.steerinfo.ems.tcmdatasourcetimegran.model.TCmDatasourceTimegran">
          <id column="RECORDID" jdbcType="VARCHAR" property="recordid" />
          <result column="DATASOURCENAME" jdbcType="VARCHAR" property="datasourcename" />
          <result column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
          <result column="CALCMODE" jdbcType="VARCHAR" property="calcmode" />
          <result column="CALCGRAN" jdbcType="VARCHAR" property="calcgran" />
          <result column="SUMENABLED" jdbcType="VARCHAR" property="sumenabled" />
          <result column="SUMGRAN" jdbcType="VARCHAR" property="sumgran" />
          <result column="AUTOCPMODE" jdbcType="VARCHAR" property="autocpmode" />
          <result column="UCENABLED" jdbcType="VARCHAR" property="ucenabled" />
          <result column="DIGITS" jdbcType="DECIMAL" property="digits" />
          <result column="SUMDIGITS" jdbcType="DECIMAL" property="sumdigits" />
          <result column="UCDIGITS" jdbcType="DECIMAL" property="ucdigits" />
          <result column="SUMUCDIGITS" jdbcType="DECIMAL" property="sumucdigits" />
          <result column="STDDIGITS" jdbcType="DECIMAL" property="stddigits" />
          <result column="SUMSTDDIGITS" jdbcType="DECIMAL" property="sumstddigits" />
          <result column="ENABLESUMFMLA" jdbcType="VARCHAR" property="enablesumfmla" />
          <result column="INIT_OFFSET" jdbcType="VARCHAR" property="initOffset" />
          <result column="CREATEMAN" jdbcType="VARCHAR" property="createman" />
          <result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
          <result column="UPDATEMAN" jdbcType="VARCHAR" property="updateman" />
         <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
      </association>
  </resultMap>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_RM_TIMEGRAN
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_TIMEGRAN
    where 1=1
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="remark != null and remark != ''">
        and REMARK = #{remark}
      </if>
      <if test="fmtexp != null and fmtexp != ''">
        and FMTEXP = #{fmtexp}
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE = #{bcode}
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 = #{bdesc1}
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 = #{bdesc2}
      </if>
      <if test="isdefault != null and isdefault != ''">
        and ISDEFAULT = #{isdefault}
      </if>
      <if test="sumgran != null and sumgran != ''">
        and SUMGRAN = #{sumgran}
      </if>
      <if test="initOffset != null and initOffset != ''">
        and INIT_OFFSET = #{initOffset}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    insert into T_RM_TIMEGRAN (ID, NAME, REMARK, 
      FMTEXP, BCODE, BDESC1, 
      BDESC2, ISDEFAULT, SUMGRAN, 
      INIT_OFFSET, CREATEMAN, CREATETIME)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, 
      #{fmtexp,jdbcType=VARCHAR}, #{bcode,jdbcType=VARCHAR}, #{bdesc1,jdbcType=VARCHAR}, 
      #{bdesc2,jdbcType=VARCHAR}, #{isdefault,jdbcType=VARCHAR}, #{sumgran,jdbcType=VARCHAR}, 
      #{initOffset,jdbcType=VARCHAR}, #{createman,jdbcType=VARCHAR}, SYSDATE)
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    insert into T_RM_TIMEGRAN
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="name != null">
        NAME,
      </if>
      <if test="remark != null">
        REMARK,
      </if>
      <if test="fmtexp != null">
        FMTEXP,
      </if>
      <if test="bcode != null">
        BCODE,
      </if>
      <if test="bdesc1 != null">
        BDESC1,
      </if>
      <if test="bdesc2 != null">
        BDESC2,
      </if>
      <if test="isdefault != null">
        ISDEFAULT,
      </if>
      <if test="sumgran != null">
        SUMGRAN,
      </if>
      <if test="initOffset != null">
        INIT_OFFSET,
      </if>
        CREATEMAN,
        CREATETIME
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="fmtexp != null">
        #{fmtexp,jdbcType=VARCHAR},
      </if>
      <if test="bcode != null">
        #{bcode,jdbcType=VARCHAR},
      </if>
      <if test="bdesc1 != null">
        #{bdesc1,jdbcType=VARCHAR},
      </if>
      <if test="bdesc2 != null">
        #{bdesc2,jdbcType=VARCHAR},
      </if>
      <if test="isdefault != null">
        #{isdefault,jdbcType=VARCHAR},
      </if>
      <if test="sumgran != null">
        #{sumgran,jdbcType=VARCHAR},
      </if>
      <if test="initOffset != null">
        #{initOffset,jdbcType=VARCHAR},
      </if>
        #{createman,jdbcType=VARCHAR},
        SYSDATE
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    update T_RM_TIMEGRAN
    set NAME = #{name,jdbcType=VARCHAR},
      REMARK = #{remark,jdbcType=VARCHAR},
      FMTEXP = #{fmtexp,jdbcType=VARCHAR},
      BCODE = #{bcode,jdbcType=VARCHAR},
      BDESC1 = #{bdesc1,jdbcType=VARCHAR},
      BDESC2 = #{bdesc2,jdbcType=VARCHAR},
      ISDEFAULT = #{isdefault,jdbcType=VARCHAR},
      SUMGRAN = #{sumgran,jdbcType=VARCHAR},
      INIT_OFFSET = #{initOffset,jdbcType=VARCHAR},
      UPDATEMAN = #{updateman, jdbcType=VARCHAR},
      UPDATETIME = SYSDATE
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmtimegran.model.TRmTimegran">
    update T_RM_TIMEGRAN
    <set>
      <if test="name != null">
        NAME = #{name,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        REMARK = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="fmtexp != null">
        FMTEXP = #{fmtexp,jdbcType=VARCHAR},
      </if>
      <if test="bcode != null">
        BCODE = #{bcode,jdbcType=VARCHAR},
      </if>
      <if test="bdesc1 != null">
        BDESC1 = #{bdesc1,jdbcType=VARCHAR},
      </if>
      <if test="bdesc2 != null">
        BDESC2 = #{bdesc2,jdbcType=VARCHAR},
      </if>
      <if test="isdefault != null">
        ISDEFAULT = #{isdefault,jdbcType=VARCHAR},
      </if>
      <if test="sumgran != null">
        SUMGRAN = #{sumgran,jdbcType=VARCHAR},
      </if>
      <if test="initOffset != null">
        INIT_OFFSET = #{initOffset,jdbcType=VARCHAR},
      </if>
        UPDATEMAN = #{updateman, jdbcType=VARCHAR},
        UPDATETIME = SYSDATE
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap2">
    select ID, NAME, REMARK, FMTEXP, BCODE, BDESC1, BDESC2, ISDEFAULT, SUMGRAN, INIT_OFFSET, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_TIMEGRAN
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap2">
    select ID, NAME, REMARK, FMTEXP, BCODE, BDESC1, BDESC2, ISDEFAULT, SUMGRAN, INIT_OFFSET, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_TIMEGRAN
    <where>
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="name != null and name != ''">
        and NAME = #{name}
      </if>
      <if test="remark != null and remark != ''">
        and REMARK = #{remark}
      </if>
      <if test="fmtexp != null and fmtexp != ''">
        and FMTEXP = #{fmtexp}
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE = #{bcode}
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 = #{bdesc1}
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 = #{bdesc2}
      </if>
      <if test="isdefault != null and isdefault != ''">
        and ISDEFAULT = #{isdefault}
      </if>
      <if test="sumgran != null and sumgran != ''">
        and SUMGRAN = #{sumgran}
      </if>
      <if test="initOffset != null and initOffset != ''">
        and INIT_OFFSET = #{initOffset}
      </if>
    </where>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap2">
    select ID, NAME, REMARK, FMTEXP, BCODE, BDESC1, BDESC2, ISDEFAULT, SUMGRAN, INIT_OFFSET, CREATEMAN, CREATETIME, UPDATEMAN, UPDATETIME
    from T_RM_TIMEGRAN
    <where>
      <if test="id != null and id != ''">
        and ID LIKE '%${id}%'
      </if>
      <if test="name != null and name != ''">
        and NAME LIKE '%${name}%'
      </if>
      <if test="remark != null and remark != ''">
        and REMARK LIKE '%${remark}%'
      </if>
      <if test="fmtexp != null and fmtexp != ''">
        and FMTEXP LIKE '%${fmtexp}%'
      </if>
      <if test="bcode != null and bcode != ''">
        and BCODE LIKE '%${bcode}%'
      </if>
      <if test="bdesc1 != null and bdesc1 != ''">
        and BDESC1 LIKE '%${bdesc1}%'
      </if>
      <if test="bdesc2 != null and bdesc2 != ''">
        and BDESC2 LIKE '%${bdesc2}%'
      </if>
      <if test="isdefault != null and isdefault != ''">
        and ISDEFAULT LIKE '%${isdefault}%'
      </if>
      <if test="sumgran != null and sumgran != ''">
        and SUMGRAN LIKE '%${sumgran}%'
      </if>
      <if test="initOffset != null and initOffset != ''">
        and INIT_OFFSET LIKE '%${initOffset}%'
      </if>
    </where>
    order by TO_NUMBER(BCODE),NAME
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_TIMEGRAN 
      (ID, 
      NAME, REMARK, FMTEXP, 
      BCODE, BDESC1, BDESC2, 
      ISDEFAULT, SUMGRAN, INIT_OFFSET, CREATEMAN, CREATETIME
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.name,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR}, #{item.fmtexp,jdbcType=VARCHAR}, 
      #{item.bcode,jdbcType=VARCHAR}, #{item.bdesc1,jdbcType=VARCHAR}, #{item.bdesc2,jdbcType=VARCHAR}, 
      #{item.isdefault,jdbcType=VARCHAR}, #{item.sumgran,jdbcType=VARCHAR}, #{item.initOffset,jdbcType=VARCHAR},
       #{item.createman,jdbcType=VARCHAR}, SYSDATE
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_TIMEGRAN
     set
       ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.id,jdbcType=VARCHAR}
       </foreach>
       ,NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
       </foreach>
       ,REMARK=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.remark,jdbcType=VARCHAR}
       </foreach>
       ,FMTEXP=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.fmtexp,jdbcType=VARCHAR}
       </foreach>
       ,BCODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bcode,jdbcType=VARCHAR}
       </foreach>
       ,BDESC1=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bdesc1,jdbcType=VARCHAR}
       </foreach>
       ,BDESC2=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.bdesc2,jdbcType=VARCHAR}
       </foreach>
       ,ISDEFAULT=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.isdefault,jdbcType=VARCHAR}
       </foreach>
       ,SUMGRAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.sumgran,jdbcType=VARCHAR}
       </foreach>
       ,INIT_OFFSET=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.initOffset,jdbcType=VARCHAR}
       </foreach>
        ,UPDATEMAN=
        <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
            when #{item.id,jdbcType=VARCHAR} then #{item.updateman,jdbcType=VARCHAR}
        </foreach>
        ,UPDATETIME=
        <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
            when #{item.id,jdbcType=VARCHAR} then SYSDATE
        </foreach>
     where ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.id,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_RM_TIMEGRAN
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

  <select id="getNameAndId" resultMap="BaseResultMap2">
    select ID, NAME from T_RM_TIMEGRAN order by NAME
  </select>

    <select id="getIdAndName" resultMap="BaseResultMap">
      SELECT TCD.RECORDID,TCD.DATASOURCENAME,TCD.TIMEGRANID,TCD.CALCMODE,TCD.SUMENABLED,TCD.SUMGRAN,TCD.AUTOCPMODE,TCD.INIT_OFFSET,
      TRT.ID,TRT.NAME,TRT.REMARK,TRT.ISDEFAULT
      FROM T_CM_DATASOURCE_TIMEGRAN TCD
      LEFT JOIN T_RM_TIMEGRAN TRT
      ON TCD.TIMEGRANID = TRT.ID
      WHERE DATASOURCENAME = 'T_RM_PLAN_VALUE.P'
      ORDER BY TIMEGRANID
    </select>
    <!-- 获得最大顺序号 -->
    <select id="getMaxBcode" resultType="java.lang.Integer">
      select MAX(TO_NUMBER(BCODE)) from T_RM_TIMEGRAN
    </select>
</mapper>