<?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.goafanti.common.dao.ContractLogMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ContractLog" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="cid" property="cid" jdbcType="VARCHAR" />
    <result column="record_time" property="recordTime" jdbcType="TIMESTAMP" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="principal" property="principal" jdbcType="VARCHAR" />
    <result column="operator" property="operator" jdbcType="VARCHAR" />
    <result column="comment" property="comment" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, cid, record_time, status, principal, operator, comment
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from contract_log
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from contract_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.ContractLog" >
    insert into contract_log (id, cid, record_time, 
      status, principal, operator, 
      comment)
    values (#{id,jdbcType=VARCHAR}, #{cid,jdbcType=VARCHAR}, #{recordTime,jdbcType=TIMESTAMP}, 
      #{status,jdbcType=INTEGER}, #{principal,jdbcType=VARCHAR}, #{operator,jdbcType=VARCHAR}, 
      #{comment,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.ContractLog" >
    insert into contract_log
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="cid != null" >
        cid,
      </if>
      <if test="recordTime != null" >
        record_time,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="principal != null" >
        principal,
      </if>
      <if test="operator != null" >
        operator,
      </if>
      <if test="comment != null" >
        comment,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="cid != null" >
        #{cid,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
      <if test="principal != null" >
        #{principal,jdbcType=VARCHAR},
      </if>
      <if test="operator != null" >
        #{operator,jdbcType=VARCHAR},
      </if>
      <if test="comment != null" >
        #{comment,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ContractLog" >
    update contract_log
    <set >
      <if test="cid != null" >
        cid = #{cid,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        record_time = #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="principal != null" >
        principal = #{principal,jdbcType=VARCHAR},
      </if>
      <if test="operator != null" >
        operator = #{operator,jdbcType=VARCHAR},
      </if>
      <if test="comment != null" >
        comment = #{comment,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.ContractLog" >
    update contract_log
    set cid = #{cid,jdbcType=VARCHAR},
      record_time = #{recordTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=INTEGER},
      principal = #{principal,jdbcType=VARCHAR},
      operator = #{operator,jdbcType=VARCHAR},
      comment = #{comment,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <insert id="insertBatch" parameterType="com.goafanti.common.model.ContractLog">
    insert into contract_log (id, cid, record_time, status, principal, operator, comment)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (
      	#{item.id,jdbcType=VARCHAR}, #{item.cid,jdbcType=VARCHAR}, #{item.recordTime,jdbcType=TIMESTAMP},
      	#{item.status,jdbcType=INTEGER}, #{item.principal,jdbcType=VARCHAR}, #{item.operator,jdbcType=VARCHAR},
      	#{item.comment,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>
  
  <select id="selectContractLogByCid" parameterType="java.lang.String" resultMap="BaseResultMap">
    	select cl.id, cl.cid, cl.comment, cl.record_time, 
    	cl.status, aa.name as operator, a.name as principal
		FROM contract_log cl 
		LEFT JOIN admin aa on aa.id = cl.operator
		LEFT JOIN admin a on a.id = cl.principal
		where cl.cid = #{cid,jdbcType=VARCHAR}
		order by cl.record_time 
    </select>
</mapper>