<?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.pcloud.book.group.mapper.WeworkTeacherBookBindMapper">
  <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.WeworkTeacherBookBind">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="book_id" jdbcType="BIGINT" property="bookId" />
    <result column="book_name" jdbcType="VARCHAR" property="bookName" />
    <result column="isbn" jdbcType="VARCHAR" property="isbn" />
    <result column="wework_teacher_arr" jdbcType="VARCHAR" property="weworkTeacherArr" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, book_id, book_name, isbn, wework_teacher_arr, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from wework_teacher_book_bind
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from wework_teacher_book_bind
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.pcloud.book.group.entity.WeworkTeacherBookBind" useGeneratedKeys="true">
    insert into wework_teacher_book_bind (book_id, book_name, isbn, 
      wework_teacher_arr, create_time, update_time
      )
    values (#{bookId,jdbcType=BIGINT}, #{bookName,jdbcType=VARCHAR}, #{isbn,jdbcType=VARCHAR}, 
      #{weworkTeacherArr,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.pcloud.book.group.entity.WeworkTeacherBookBind" useGeneratedKeys="true">
    insert into wework_teacher_book_bind
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="bookId != null">
        book_id,
      </if>
      <if test="bookName != null">
        book_name,
      </if>
      <if test="isbn != null">
        isbn,
      </if>
      <if test="weworkTeacherArr != null">
        wework_teacher_arr,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="bookId != null">
        #{bookId,jdbcType=BIGINT},
      </if>
      <if test="bookName != null">
        #{bookName,jdbcType=VARCHAR},
      </if>
      <if test="isbn != null">
        #{isbn,jdbcType=VARCHAR},
      </if>
      <if test="weworkTeacherArr != null">
        #{weworkTeacherArr,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.group.entity.WeworkTeacherBookBind">
    update wework_teacher_book_bind
    <set>
      <if test="bookId != null">
        book_id = #{bookId,jdbcType=BIGINT},
      </if>
      <if test="bookName != null">
        book_name = #{bookName,jdbcType=VARCHAR},
      </if>
      <if test="isbn != null">
        isbn = #{isbn,jdbcType=VARCHAR},
      </if>
      <if test="weworkTeacherArr != null">
        wework_teacher_arr = #{weworkTeacherArr,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.group.entity.WeworkTeacherBookBind">
    update wework_teacher_book_bind
    set book_id = #{bookId,jdbcType=BIGINT},
      book_name = #{bookName,jdbcType=VARCHAR},
      isbn = #{isbn,jdbcType=VARCHAR},
      wework_teacher_arr = #{weworkTeacherArr,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <insert id="insertOrUpdate">
    insert into wework_teacher_book_bind (book_id, book_name, isbn, wework_teacher_arr,
                                        <if test="createTime != null">create_time,</if>
                                          update_time)
    values(
           #{bookId},#{bookName},#{isbn},#{weworkTeacherArr},
            <if test="createTime != null">#{createTime},</if>
            update_time = #{updateTime,jdbcType=TIMESTAMP}
    )
    on duplicate key update
     book_id = values(book_id),
     book_name = values(book_name),
     isbn = values(isbn),
     wework_teacher_arr = values(wework_teacher_arr),
     update_time = values(update_time)
  </insert>

  <delete id="deleteByBookId">
    delete from wework_teacher_book_bind
    where book_id = #{bookId,jdbcType=BIGINT}
  </delete>

  <select id="count4BookWxworkTeacherList" resultType="java.lang.Integer">
    select count(0) from wework_teacher_book_bind
    <where>
      <if test="name != null">
        book_name like concat('%',#{name},'%') OR isbn like concat('%',#{name},'%')
      </if>
    </where>
  </select>

  <select id="getBookWxworkTeacherList" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from wework_teacher_book_bind
    <where>
      <if test="name != null">
        book_name like concat('%',#{name},'%') OR isbn like concat('%',#{name},'%')
      </if>
    </where>
    limit #{offset},#{limit}
  </select>

  <select id="getByBookId" resultMap="BaseResultMap" >
    select <include refid="Base_Column_List"/>
    from wework_teacher_book_bind
    where book_id = #{bookId}
  </select>


</mapper>