<?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.platform.yijia.dao.AppUserInfoMapper">
  <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.AppUserInfo">
    <id     column="user_id"              jdbcType="INTEGER"    property="userId" />
    <result column="user_type"            jdbcType="VARCHAR"    property="userType" />
    <result column="blog_openid"          jdbcType="VARCHAR"    property="blogOpenid" />
    <result column="mina_openid"          jdbcType="VARCHAR"    property="minaOpenid" />
    <result column="mobile_phone"         jdbcType="VARCHAR"    property="mobilePhone" />
    <result column="blog_nick_name"       jdbcType="VARCHAR"    property="blogNickName" />
    <result column="sex_flag"             jdbcType="VARCHAR"    property="sexFlag" />
    <result column="registe_date"         jdbcType="TIMESTAMP"  property="registeDate" />
    <result column="blog_profile_photo"   jdbcType="VARCHAR"    property="blogProfilePhoto" />
    <result column="update_date"          jdbcType="TIMESTAMP"  property="updateDate" />
    <result column="union_id"             jdbcType="VARCHAR"    property="unionId" />
    <result column="ali_id"               jdbcType="VARCHAR"    property="aLiId" />
    <result column="station_id"           jdbcType="INTEGER"    property="stationId" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
      user_id, user_type, blog_openid, mina_openid, mobile_phone, blog_nick_name, sex_flag,
      registe_date blog_profile_photo, update_date, union_id, ali_id, station_id
  </sql>
  <!-- 获取用户信息-->
  <select id="getAppUserInfo" parameterType="com.platform.yijia.pojo.AppUserInfo" resultMap="BaseResultMap">
    SELECT
        <include refid="Base_Column_List" />
    FROM
        app_user_info
    <where>
      <if test="userType !=null and userType !=''">
        user_type = #{userType}
      </if>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
      <if test="blogOpenid !=null and blogOpenid !=''">
        AND blog_openid = #{blogOpenid}
      </if>
      <if test="minaOpenid !=null and minaOpenid !=''">
        AND mina_openid = #{minaOpenid}
      </if>
      <if test="aLiId !=null and aLiId !=''">
        AND ali_id = #{aLiId}
      </if>
    </where>
  </select>

  <!-- selectAppUserInfoByMobilePhoneAndStationId -->
  <!-- 根据手机号和油站ID获取用户信息-->
  <select id="selectAppUserInfoByMobilePhoneAndStationId" parameterType="com.platform.yijia.pojo.AppUserInfo" resultMap="BaseResultMap">
    SELECT
        <include refid="Base_Column_List" />
    FROM
        app_user_info
    <where>
      <if test="stationId !=null and stationId !=''">
        station_id = #{stationId}
      </if>
      <if test="mobilePhone !=null and mobilePhone !=''">
        AND mobile_phone = #{mobilePhone}
      </if>
    </where>
  </select>

  <!-- 判断注册账户是否已存在-->
  <select id="isExistAppUser" parameterType="map" resultType="int">
    SELECT
        COUNT(user_id)
    FROM
        app_user_info
    <where>
      <if test="userType !=null and userType !=''">
        user_type = #{userType}
      </if>
      <if test="userType !=null and userType ==1 ">
        AND blog_openid = #{openId}
      </if>
      <if test="userType !=null and userType ==2 ">
        AND mina_openid = #{openId}
      </if>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
    </where>
  </select>


  <select id="selectByExample" parameterType="com.platform.yijia.pojo.AppUserInfoExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from app_user_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <include refid="Base_Column_List" />
    from app_user_info
    where user_id = #{userId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from app_user_info
    where user_id = #{userId,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.platform.yijia.pojo.AppUserInfoExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from app_user_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.platform.yijia.pojo.AppUserInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into app_user_info (user_id, user_type, blog_openid,
      mina_openid, mobile_phone, blog_nick_name,
      sex_flag, registe_date, blog_token,
      mina_token, blog_profile_photo, update_date, union_id,station_id
      )
    values (#{userId,jdbcType=INTEGER}, #{userType,jdbcType=VARCHAR}, #{blogOpenid,jdbcType=VARCHAR},
      #{minaOpenid,jdbcType=VARCHAR}, #{mobilePhone,jdbcType=VARCHAR}, #{blogNickName,jdbcType=VARCHAR},
      #{sexFlag,jdbcType=VARCHAR}, #{registeDate,jdbcType=TIMESTAMP}, #{blogToken,jdbcType=VARCHAR},
      #{minaToken,jdbcType=VARCHAR}, #{blogProfilePhoto,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP},
      #{unionId,jdbcType=VARCHAR},#{stationId,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.platform.yijia.pojo.AppUserInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into app_user_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        user_id,
      </if>
      <if test="userType != null">
        user_type,
      </if>
      <if test="blogOpenid != null">
        blog_openid,
      </if>
      <if test="minaOpenid != null">
        mina_openid,
      </if>
      <if test="mobilePhone != null">
        mobile_phone,
      </if>
      <if test="blogNickName != null">
        blog_nick_name,
      </if>
      <if test="sexFlag != null">
        sex_flag,
      </if>
      <if test="registeDate != null">
        registe_date,
      </if>
      <if test="blogToken != null">
        blog_token,
      </if>
      <if test="minaToken != null">
        mina_token,
      </if>
      <if test="blogProfilePhoto != null">
        blog_profile_photo,
      </if>
      <if test="updateDate != null">
        update_date,
      </if>
      <if test="unionId != null">
        union_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="userType != null">
        #{userType,jdbcType=VARCHAR},
      </if>
      <if test="blogOpenid != null">
        #{blogOpenid,jdbcType=VARCHAR},
      </if>
      <if test="minaOpenid != null">
        #{minaOpenid,jdbcType=VARCHAR},
      </if>
      <if test="mobilePhone != null">
        #{mobilePhone,jdbcType=VARCHAR},
      </if>
      <if test="blogNickName != null">
        #{blogNickName,jdbcType=VARCHAR},
      </if>
      <if test="sexFlag != null">
        #{sexFlag,jdbcType=VARCHAR},
      </if>
      <if test="registeDate != null">
        #{registeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="blogToken != null">
        #{blogToken,jdbcType=VARCHAR},
      </if>
      <if test="minaToken != null">
        #{minaToken,jdbcType=VARCHAR},
      </if>
      <if test="blogProfilePhoto != null">
        #{blogProfilePhoto,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="unionId != null">
        #{unionId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.platform.yijia.pojo.AppUserInfoExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from app_user_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update app_user_info
    <set>
      <if test="record.userId != null">
        user_id = #{record.userId,jdbcType=INTEGER},
      </if>
      <if test="record.userType != null">
        user_type = #{record.userType,jdbcType=VARCHAR},
      </if>
      <if test="record.blogOpenid != null">
        blog_openid = #{record.blogOpenid,jdbcType=VARCHAR},
      </if>
      <if test="record.minaOpenid != null">
        mina_openid = #{record.minaOpenid,jdbcType=VARCHAR},
      </if>
      <if test="record.mobilePhone != null">
        mobile_phone = #{record.mobilePhone,jdbcType=VARCHAR},
      </if>
      <if test="record.blogNickName != null">
        blog_nick_name = #{record.blogNickName,jdbcType=VARCHAR},
      </if>
      <if test="record.sexFlag != null">
        sex_flag = #{record.sexFlag,jdbcType=VARCHAR},
      </if>
      <if test="record.registeDate != null">
        registe_date = #{record.registeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.blogToken != null">
        blog_token = #{record.blogToken,jdbcType=VARCHAR},
      </if>
      <if test="record.minaToken != null">
        mina_token = #{record.minaToken,jdbcType=VARCHAR},
      </if>
      <if test="record.blogProfilePhoto != null">
        blog_profile_photo = #{record.blogProfilePhoto,jdbcType=VARCHAR},
      </if>
      <if test="record.updateDate != null">
        update_date = #{record.updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.unionId != null">
        union_id = #{record.unionId,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update app_user_info
    set user_id = #{record.userId,jdbcType=INTEGER},
      user_type = #{record.userType,jdbcType=VARCHAR},
      blog_openid = #{record.blogOpenid,jdbcType=VARCHAR},
      mina_openid = #{record.minaOpenid,jdbcType=VARCHAR},
      mobile_phone = #{record.mobilePhone,jdbcType=VARCHAR},
      blog_nick_name = #{record.blogNickName,jdbcType=VARCHAR},
      sex_flag = #{record.sexFlag,jdbcType=VARCHAR},
      registe_date = #{record.registeDate,jdbcType=TIMESTAMP},
      blog_token = #{record.blogToken,jdbcType=VARCHAR},
      mina_token = #{record.minaToken,jdbcType=VARCHAR},
      blog_profile_photo = #{record.blogProfilePhoto,jdbcType=VARCHAR},
      update_date = #{record.updateDate,jdbcType=TIMESTAMP}
      union_id = #{record.unionId,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.platform.yijia.pojo.AppUserInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update app_user_info
    <set>
      <if test="userType != null">
        user_type = #{userType,jdbcType=VARCHAR},
      </if>
      <if test="blogOpenid != null">
        blog_openid = #{blogOpenid,jdbcType=VARCHAR},
      </if>
      <if test="minaOpenid != null">
        mina_openid = #{minaOpenid,jdbcType=VARCHAR},
      </if>
      <if test="mobilePhone != null">
        mobile_phone = #{mobilePhone,jdbcType=VARCHAR},
      </if>
      <if test="blogNickName != null">
        blog_nick_name = #{blogNickName,jdbcType=VARCHAR},
      </if>
      <if test="sexFlag != null">
        sex_flag = #{sexFlag,jdbcType=VARCHAR},
      </if>
      <if test="registeDate != null">
        registe_date = #{registeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="blogToken != null">
        blog_token = #{blogToken,jdbcType=VARCHAR},
      </if>
      <if test="minaToken != null">
        mina_token = #{minaToken,jdbcType=VARCHAR},
      </if>
      <if test="blogProfilePhoto != null">
        blog_profile_photo = #{blogProfilePhoto,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="unionId != null">
        union_id = #{unionId,jdbcType=VARCHAR},
      </if>
    </set>
    where user_id = #{userId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.platform.yijia.pojo.AppUserInfo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update app_user_info
    set user_type = #{userType,jdbcType=VARCHAR},
      blog_openid = #{blogOpenid,jdbcType=VARCHAR},
      mina_openid = #{minaOpenid,jdbcType=VARCHAR},
      mobile_phone = #{mobilePhone,jdbcType=VARCHAR},
      blog_nick_name = #{blogNickName,jdbcType=VARCHAR},
      sex_flag = #{sexFlag,jdbcType=VARCHAR},
      registe_date = #{registeDate,jdbcType=TIMESTAMP},
      blog_token = #{blogToken,jdbcType=VARCHAR},
      mina_token = #{minaToken,jdbcType=VARCHAR},
      blog_profile_photo = #{blogProfilePhoto,jdbcType=VARCHAR},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      union_id = #{unionId,jdbcType=VARCHAR}
    where user_id = #{userId,jdbcType=INTEGER}
  </update>


  <!--查询客户unionId-->
  <select id="getUserInfo" parameterType="com.platform.yijia.pojo.AppUserInfo" resultMap="BaseResultMap">
    SELECT
        <include refid="Base_Column_List" />
    FROM app_user_info
    <where>
      <if test="userType !=null and userType !=''">
        user_type = #{userType}
      </if>
      <if test="stationId !=null and stationId !=''">
        station_id = #{stationId}
      </if>
      <if test="blogOpenid !=null and blogOpenid !=''">
        AND blog_openid = #{blogOpenid}
      </if>
      <if test="minaOpenid !=null and minaOpenid !=''">
        AND mina_openid = #{minaOpenid}
      </if>
      <if test="mobilePhone !=null and mobilePhone !=''">
        AND mobile_phone = #{mobilePhone}
      </if>
    </where>
  </select>

  <!--更新用户信息-->
  <update id="updateAppUserInfo" parameterType="com.platform.yijia.pojo.AppUserInfo">
    UPDATE app_user_info
    <set>
      <if test="userType != null">
        user_type = #{userType},
      </if>
      <if test="blogOpenid != null">
        blog_openid = #{blogOpenid},
      </if>
      <if test="minaOpenid != null">
        mina_openid = #{minaOpenid},
      </if>
      <if test="mobilePhone != null">
        mobile_phone = #{mobilePhone},
      </if>
      <if test="blogNickName != null">
        blog_nick_name = #{blogNickName},
      </if>
      <if test="sexFlag != null">
        sex_flag = #{sexFlag},
      </if>
      <if test="registeDate != null">
        registe_date = #{registeDate},
      </if>
      <if test="blogToken != null">
        blog_token = #{blogToken},
      </if>
      <if test="minaToken != null">
        mina_token = #{minaToken},
      </if>
      <if test="blogProfilePhoto != null">
        blog_profile_photo = #{blogProfilePhoto},
      </if>
      <if test="updateDate != null">
        update_date = #{updateDate},
      </if>
      <if test="unionId !=null">
        union_id = #{unionId}
      </if>
    </set>
    <where>
      <if test="userType !=null and userType !=''">
        user_type = #{userType}
      </if>
      <if test="blogOpenid !=null and blogOpenid !=''">
        AND blog_openid = #{blogOpenid}
      </if>
      <if test="minaOpenid !=null and minaOpenid !=''">
        AND mina_openid = #{minaOpenid}
      </if>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
    </where>
  </update>

  <!-- 判断使用小程序支付的用户是否关注公众号-->
  <select id="whetherFollowGzh" parameterType="map" resultType="String">
    SELECT
        blog_openid AS openId
    FROM
        app_user_info
    <where>
      <if test="userType !=null and userType !=''">
        user_type = #{userType}
      </if>
      <if test="unionId !=null and unionId !=''">
        AND union_id = #{unionId}
      </if>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
    </where>

  </select>


</mapper>
