<?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.cool.store.mapper.HyPartnerClerkMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerClerkDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="partner_line_id" jdbcType="BIGINT" property="partnerLineId" />
    <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="relationship" jdbcType="VARCHAR" property="relationship" />
    <result column="age" jdbcType="INTEGER" property="age" />
    <result column="choose_reason" jdbcType="VARCHAR" property="chooseReason" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, partner_line_id, partner_id, username, relationship, age, choose_reason, create_time, 
    update_time
  </sql>
  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into hy_partner_clerk
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="record.partnerLineId != null">
        partner_line_id,
      </if>
      <if test="record.partnerId != null">
        partner_id,
      </if>
      <if test="record.username != null">
        username,
      </if>
      <if test="record.relationship != null">
        relationship,
      </if>
      <if test="record.age != null">
        age,
      </if>
      <if test="record.chooseReason != null">
        choose_reason,
      </if>
      <if test="record.createTime != null">
        create_time,
      </if>
      <if test="record.updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="record.partnerLineId != null">
        #{record.partnerLineId},
      </if>
      <if test="record.partnerId != null">
        #{record.partnerId},
      </if>
      <if test="record.username != null">
        #{record.username},
      </if>
      <if test="record.relationship != null">
        #{record.relationship},
      </if>
      <if test="record.age != null">
        #{record.age},
      </if>
      <if test="record.chooseReason != null">
        #{record.chooseReason},
      </if>
      <if test="record.createTime != null">
        #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        #{record.updateTime},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective">
    update hy_partner_clerk
    <set>
      <if test="record.partnerLineId != null">
        partner_line_id = #{record.partnerLineId},
      </if>
      <if test="record.partnerId != null">
        partner_id = #{record.partnerId},
      </if>
      <if test="record.username != null">
        username = #{record.username},
      </if>
      <if test="record.relationship != null">
        relationship = #{record.relationship},
      </if>
      <if test="record.age != null">
        age = #{record.age},
      </if>
      <if test="record.chooseReason != null">
        choose_reason = #{record.chooseReason},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <select id="getHyPartnerClerkList" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>
    from hy_partner_clerk
    where partner_line_id = #{lineId}
  </select>

  <insert id="batchInsert">
    insert into
    hy_partner_clerk
    (
    partner_line_id,
    partner_id,
    username,
    relationship,
    age,
    choose_reason
    )
    values
    <foreach collection="recordList" item="record" separator=",">
      (#{record.partnerLineId},
      #{record.partnerId},
      #{record.username},
      #{record.relationship},
      #{record.age},
      #{record.chooseReason})
    </foreach>
  </insert>

  <delete id="deleteByPartnerIdAndLineId">
		delete from hy_partner_clerk where partner_id = #{partnerId} and partner_line_id = #{partnerLineId}
  </delete>

  <select id="listByPartnerIdAndLineId" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"></include> from
    hy_partner_clerk
    where partner_id = #{partnerId} and partner_line_id = #{partnerLineId}
  </select>

  <update id="updateLineId">
    update hy_partner_clerk
    set partner_line_id = #{newLineId} , partner_id = #{newPartnerId}
    where partner_line_id = #{oldLineId}
  </update>


</mapper>