<?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.CopyrightLogMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.CopyrightLog">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="cid" jdbcType="VARCHAR" property="cid" />
    <result column="record_time" jdbcType="TIMESTAMP" property="recordTime" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="principal" jdbcType="VARCHAR" property="principal" />
    <result column="operator" jdbcType="VARCHAR" property="operator" />
    <result column="comment" jdbcType="VARCHAR" property="comment" />
  </resultMap>
  <sql id="Base_Column_List">
    id, cid, record_time, status, principal, operator, comment
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from copyright_log
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from copyright_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.CopyrightLog">
    insert into copyright_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.CopyrightLog">
    insert into copyright_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.CopyrightLog">
    update copyright_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.CopyrightLog">
    update copyright_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>
  <select id="findByCopyrightId" parameterType="java.lang.String" resultType="com.goafanti.copyright.bo.CopyrightLogBo">
    select a.name as principal, b.name as operator, cl.record_time as recordTime, cl.status as status, cl.comment as comment
    from copyright_log cl
   	left join admin a on cl.principal = a.id
   	left join admin b on cl.operator = b.id
    where cl.cid = #{id,jdbcType=VARCHAR} 
    order by cl.record_time 
  </select>
  
   <insert id="batchInsert" parameterType="com.goafanti.common.model.CopyrightLog">
    insert into copyright_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>
</mapper>