<?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.tpmcaseact.mapper.TPmCaseActMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    <id column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
    <id column="ITEMID" jdbcType="VARCHAR" property="itemid" />
    <result column="CASEID" jdbcType="VARCHAR" property="caseid" />
    <result column="SEQNO" jdbcType="VARCHAR" property="seqno" />
  </resultMap>

  <delete id="deleteByCompositePrimaryKey" parameterType="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    delete from T_PM_CASE_ACT
    where  ITEMID = #{itemid,jdbcType=VARCHAR} AND TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    insert into T_PM_CASE_ACT (TIMEGRANID, ITEMID, CASEID, 
      SEQNO)
    values (#{timegranid,jdbcType=VARCHAR}, #{itemid,jdbcType=VARCHAR}, #{caseid,jdbcType=VARCHAR}, 
      #{seqno,jdbcType=VARCHAR})
  </insert>

  <insert id="insertSelective" parameterType="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    insert into T_PM_CASE_ACT
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="timegranid != null">
        TIMEGRANID,
      </if>
      <if test="itemid != null">
        ITEMID,
      </if>
      <if test="caseid != null">
        CASEID,
      </if>
      <if test="seqno != null">
        SEQNO,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="timegranid != null">
        #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="itemid != null">
        #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="caseid != null">
        #{caseid,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        #{seqno,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    update T_PM_CASE_ACT
    set CASEID = #{caseid,jdbcType=VARCHAR},
        SEQNO = #{seqno,jdbcType=VARCHAR}
     where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </update>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tpmcaseact.model.TPmCaseAct">
    update T_PM_CASE_ACT
    <set>
      <if test="caseid != null">
        CASEID = #{caseid,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        SEQNO = #{seqno,jdbcType=VARCHAR},
      </if>
    </set>
    where
     ITEMID = #{itemid,jdbcType=VARCHAR} AND TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    select TIMEGRANID, ITEMID, CASEID, SEQNO
    from T_PM_CASE_ACT
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </select>

  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select TIMEGRANID, ITEMID, CASEID, SEQNO
    from T_PM_CASE_ACT
    <where> 
      <if test="itemid != null and itemid != ''">
        and ITEMID = #{itemid}
      </if>
      <if test="caseid != null and caseid != ''">
        and CASEID = #{caseid}
      </if>
      <if test="seqno != null and seqno != ''">
        and SEQNO = #{seqno}
      </if>
    </where>
  </select>

  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select TIMEGRANID, ITEMID, CASEID, SEQNO
    from T_PM_CASE_ACT
    <where>
     <if test="timegranid != null and timegranid !=''">
           and TIMEGRANID LIKE  '%${timegranid}%'
     </if>
      <if test="itemid != null and itemid != ''">
        and ITEMID LIKE '%${itemid}%'
      </if>
      <if test="caseid != null and caseid != ''">
        and CASEID LIKE '%${caseid}%'
      </if>
    </where>
  </select>

  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_PM_CASE_ACT 
      (TIMEGRANID, 
      ITEMID, CASEID, SEQNO
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.timegranid,jdbcType=VARCHAR}, 
      #{item.itemid,jdbcType=VARCHAR}, #{item.caseid,jdbcType=VARCHAR}, #{item.seqno,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>

	<select id="CompositePrimaryKey" resultType="java.lang.String">
	    select TIMEGRANID || ITEMID from T_PM_CASE_ACT
	</select>

</mapper>