<?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.PatentLogMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.PatentLog" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="VARCHAR" />
    <result column="record_time" property="recordTime" jdbcType="TIMESTAMP" />
    <result column="state" property="state" 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, pid, record_time, state, principal, operator, comment
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from patent_log
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from patent_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.PatentLog" >
    insert into patent_log (id, pid, record_time, 
      state, principal, operator, 
      comment)
    values (#{id,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{recordTime,jdbcType=TIMESTAMP}, 
      #{state,jdbcType=INTEGER}, #{principal,jdbcType=VARCHAR}, #{operator,jdbcType=VARCHAR}, 
      #{comment,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.PatentLog" >
    insert into patent_log
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="pid != null" >
        pid,
      </if>
      <if test="recordTime != null" >
        record_time,
      </if>
      <if test="state != null" >
        state,
      </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="pid != null" >
        #{pid,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="state != null" >
        #{state,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.PatentLog" >
    update patent_log
    <set >
      <if test="pid != null" >
        pid = #{pid,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        record_time = #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="state != null" >
        state = #{state,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.PatentLog" >
    update patent_log
    set pid = #{pid,jdbcType=VARCHAR},
      record_time = #{recordTime,jdbcType=TIMESTAMP},
      state = #{state,jdbcType=INTEGER},
      principal = #{principal,jdbcType=VARCHAR},
      operator = #{operator,jdbcType=VARCHAR},
      comment = #{comment,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="selectProcessByPid"  parameterType="java.lang.String" resultMap="BaseResultMap">
     select a.name as principal, b.name as operator, pl.record_time as recordTime, pl.state, pl.comment as comment
    from patent_log pl
   	left join admin a on pl.principal = a.id
   	left join admin b on pl.operator = b.id
    where pl.pid = #{pid,jdbcType=VARCHAR} 
    order by pl.record_time 
  </select>
  
   <insert id="batchInsert" parameterType="com.goafanti.common.model.PatentLog">
    insert into patent_log (id, pid, record_time, state, principal, operator, comment)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (
      	#{item.id,jdbcType=VARCHAR}, #{item.pid,jdbcType=VARCHAR}, #{item.recordTime,jdbcType=TIMESTAMP},
      	#{item.state,jdbcType=INTEGER}, #{item.principal,jdbcType=VARCHAR}, #{item.operator,jdbcType=VARCHAR},
      	#{item.comment,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>
</mapper>