<?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.ematou.wxservice.mapper.UserInfoMapper">

    <sql id="Base_Column_List">
        open_id,union_id,tell_phone_number,validate_code,group_id,nick_name,sex,city,country,province,user_language,headimgurl,subscribe_time,tagid_list,
        subscribe,remark,subscribe_scene,qr_scene,qr_scene_str,creator_id,create_time,moder_id,mod_time,tmst
    </sql>

    <insert id="insertUserInfo" >
        insert into user_info ( <include refid="Base_Column_List"/> )
        values (#{userInfo.openId}, #{userInfo.unionId}, #{userInfo.tellPhoneNumber}, #{userInfo.validateCode}, #{userInfo.groupId}, #{userInfo.nickName},
        #{userInfo.sex}, #{userInfo.city}, #{userInfo.country}, #{userInfo.province}, #{userInfo.userLanguage}, #{userInfo.headimgurl}, #{userInfo.subscribeTime},
        #{userInfo.tagidList}, #{userInfo.subscribe}, #{userInfo.remark}, #{userInfo.subscribeScene}, #{userInfo.qrScene}, #{userInfo.qrSceneStr},
        #{userInfo.creatorId}, #{userInfo.createTime}, #{userInfo.moderId}, #{userInfo.modTime}, #{userInfo.tmst})
    </insert>


    <update id="updateOrInsertUserInfo">
        update user_info
        <set>
            <if test="userInfo.openId != null">
                open_id=#{userInfo.openId},
            </if>
            <if test="userInfo.unionId != null">
                union_id=#{userInfo.unionId},
            </if>
            <if test="userInfo.validateCode != null">
                validate_code=#{userInfo.validateCode},
            </if>
            <if test="userInfo.groupId != null">
                group_id=#{userInfo.groupId},
            </if>
            <if test="userInfo.nickName != null">
                nick_name=#{userInfo.nickName},
            </if>
            <if test="userInfo.sex != null">
                sex=#{userInfo.sex},
            </if>
            <if test="userInfo.city != null">
                city=#{userInfo.city},
            </if>
            <if test="userInfo.country != null">
                country=#{userInfo.country},
            </if>
            <if test="userInfo.province != null">
                province=#{userInfo.province},
            </if>
            <if test="userInfo.userLanguage != null">
                user_language=#{userInfo.userLanguage},
            </if>
            <if test="userInfo.headimgurl != null">
                headimgurl=#{userInfo.headimgurl},
            </if>
            <if test="userInfo.subscribeTime != null">
                subscribe_time=#{userInfo.subscribeTime},
            </if>
            <if test="userInfo.tagidList != null">
                tagid_list=#{userInfo.tagidList},
            </if>
            <if test="userInfo.subscribe != null">
                subscribe=#{userInfo.subscribe},
            </if>
            <if test="userInfo.remark != null">
                remark=#{userInfo.remark},
            </if>
            <if test="userInfo.subscribeScene != null">
                subscribe_scene=#{userInfo.subscribeScene},
            </if>
            <if test="userInfo.qrScene != null">
                qr_scene=#{userInfo.qrScene},
            </if>
            <if test="userInfo.qrSceneStr != null">
                qr_scene_str=#{userInfo.qrSceneStr},
            </if>
            <if test="userInfo.moderId != null">
                moder_id=#{userInfo.moderId},
            </if>
            <if test="userInfo.modTime != null">
                mod_time=#{userInfo.modTime},
            </if>
            <if test="userInfo.tmst != null">
                tmst=#{userInfo.tmst},
            </if>
        </set>
        <if test="userInfo.tellPhoneNumber">
            where tell_phone_number=#{userInfo.tellPhoneNumber}
        </if>
    </update>

    <select id="queryUserInfoByOpenIdOrPhoneNumber" resultType="com.ematou.wxservice.entity.pojo.UserInfo">
        select
        <include refid="Base_Column_List"/>
        from user_info
        where 1=1
        <if test="param.openId != null">
            and open_id = #{param.openId}
        </if>
        <if test="param.phoneNumber != null">
            and tell_phone_number = #{param.phoneNumber}
        </if>
    </select>

    <select id="queryUserInfoByPhoneNumber" resultType="com.ematou.wxservice.entity.pojo.UserInfo">
        select <include refid="Base_Column_List"/> from user_info where tell_phone_number=#{phoneNumber}
    </select>

    <select id="queryUserInfoByOpenId" resultType="com.ematou.wxservice.entity.pojo.UserInfo">
        select <include refid="Base_Column_List"/> from user_info where open_id=#{openId} and subscribe_scene is not null
    </select>

    <delete id="deleUserInfoService" >
        delete from user_info where open_id=#{openId}
    </delete>

</mapper>
