<?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.HyPartnerUserInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerUserInfoDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
    <result column="mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="user_channel_id" jdbcType="BIGINT" property="userChannelId" />
    <result column="crm_create_time" jdbcType="TIMESTAMP" property="crmCreateTime" />
    <result column="openid" jdbcType="VARCHAR" property="openid" />
  </resultMap>
  <sql id="Base_Column_List">
    id, partner_id, mobile, create_time, update_time, user_channel_id, crm_create_time, openid
  </sql>
  <select id="selectByPartnerId" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List"></include>
    from xfsg_partner_user_info
    where partner_id = #{partnerId}
  </select>

  <select id="selectByMobile" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List"></include>
    from xfsg_partner_user_info
    where mobile = #{mobile}
  </select>

  <select id="selectByOpenid" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List"></include>
    from xfsg_partner_user_info
    where openid = #{openid}
  </select>

  <select id="selectByPartnerIds" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List"></include>
    from xfsg_partner_user_info
    <where>
      <if test="partnerIdList!=null and partnerIdList.size>0">
        <foreach collection="partnerIdList" open="and partner_id in (" close=")" separator="," item="partnerId">
          #{partnerId}
        </foreach>
      </if>
    </where>
  </select>

    <select id="selectLastCrmCreateTime" resultType="java.lang.String">
      SELECT  crm_create_time as  crmCreateTime FROM  xfsg_partner_user_info   ORDER BY crm_create_time desc  limit  1
    </select>

  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into xfsg_partner_user_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="record.partnerId != null">
        partner_id,
      </if>
      <if test="record.mobile != null">
        mobile,
      </if>
      <if test="record.createTime != null">
        create_time,
      </if>
      <if test="record.updateTime != null">
        update_time,
      </if>
      <if test="record.userChannelId!=null">
        user_channel_id,
      </if>
      <if test="record.ecWantShopArea!=null">
        ec_want_shop_area,
      </if>
      <if test="record.crmCreateTime!=null">
        crm_create_time,
      </if>
      <if test="record.openid!=null">
        openid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="record.partnerId != null">
        #{record.partnerId},
      </if>
      <if test="record.mobile != null">
        #{record.mobile},
      </if>
      <if test="record.createTime != null">
        #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        #{record.updateTime},
      </if>
      <if test="record.userChannelId != null">
        #{record.userChannelId},
      </if>
      <if test="record.ecWantShopArea != null">
        #{record.ecWantShopArea},
      </if>
      <if test="record.crmCreateTime != null">
        #{record.crmCreateTime},
      </if>
      <if test="record.openid != null">
        #{record.openid},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective">
    update xfsg_partner_user_info
    <set>
      <if test="record.partnerId != null">
        partner_id = #{record.partnerId},
      </if>
      <if test="record.mobile != null">
        mobile = #{record.mobile},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
      <if test="record.ecWantShopArea != null">
        ec_want_shop_area = #{record.ecWantShopArea},
      </if>
      <if test="record.openid != null">
        openid = #{record.openid},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <update id="updateByPartnerId">
    update xfsg_partner_user_info
    <set>
      <if test="record.mobile != null">
        mobile = #{record.mobile},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    where partner_id = #{record.partnerId}
  </update>

</mapper>