<?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.cultivate.dao.impl.CultivateHoldSeatDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.cultivate.entity.CultivateHoldSeat" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="cultivate_id" property="cultivateId" jdbcType="BIGINT" />
    <result column="friend_cultivate_id" property="friendCultivateId" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, cultivate_id, friend_cultivate_id, create_time,update_time
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.cultivate.entity.CultivateHoldSeat" useGeneratedKeys="true" keyProperty="id">
    insert into cultivate_hold_seat
    (
      cultivate_id,
      friend_cultivate_id,
      create_time,
      update_time
      )
    values (
      #{cultivateId},
      #{friendCultivateId},
      NOW(),
      NOW()
      )
  </insert>

  <select id="deleteById" parameterType="map">
     DELETE  from cultivate_hold_seat
     WHERE cultivate_id=#{cultivateId}
     and friend_cultivate_id=#{friendCultivateId}
  </select>

  <select id="getCultivateIdByFriendId" parameterType="map" resultType="long">
    SELECT  DISTINCT cultivate_id
    FROM cultivate_hold_seat
    where friend_cultivate_id=#{friendCultivateId}
  </select>

    <select id="getFriendCultivateIdById" parameterType="map" resultType="long">
        select friend_cultivate_id from cultivate_hold_seat
        where cultivate_id=#{cultivateId}
        limit 1
    </select>

    <select id="getById" parameterType="map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from cultivate_hold_seat
        where cultivate_id=#{cultivateId}
         and friend_cultivate_id=#{friendCultivateId}
        limit 1
    </select>



</mapper>