<?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.miaxis.jsgzh.mapper.JsgzhUserMapper">

    <resultMap type="JsgzhUser" id="JsgzhUserResult">
        <result property="id"    column="id"    />
        <result property="openid"    column="openid"    />
        <result property="nickname"    column="nickname"    />
        <result property="subscribe"    column="subscribe"    />
        <result property="sex"    column="sex"    />
        <result property="city"    column="city"    />
        <result property="country"    column="country"    />
        <result property="province"    column="province"    />
        <result property="language"    column="language"    />
        <result property="headimgurl"    column="headimgurl"    />
        <result property="subscribe_time"    column="subscribe_time"    />
        <result property="unionid"    column="unionid"    />
        <result property="remark"    column="remark"    />
        <result property="groupid"    column="groupid"    />
        <result property="tagid_list"   column="tagid_list"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
        <result property="subscribe_scene"    column="subscribe_scene"    />
        <result property="create_time"    column="create_time"    />
        <result property="update_time"    column="update_time"    />
    </resultMap>

    <sql id="selectJsgzhUserVo">
        select * from jsgzh_user
    </sql>

    <select id="selectJsgzhUserList" resultMap="JsgzhUserResult">
        select * from jsgzh_user
        <where>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="subscribe != null "> and subscribe = #{subscribe}</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="country != null  and country != ''"> and country = #{country}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="language != null  and language != ''"> and language = #{language}</if>
            <if test="headimgurl != null  and headimgurl != ''"> and headimgurl = #{headimgurl}</if>
            <if test="subscribe_time != null "> and subscribe_time = #{subscribe_time}</if>
            <if test="unionid != null "> and unionid = #{unionid}</if>
            <if test="groupid != null "> and groupid = #{groupid}</if>
            <if test="tagid_list != null  and tagid_list != ''"> and tagid_list = #{tagid_list}</if>
            <if test="subscribe_scene != null  and subscribe_scene != ''"> and subscribe_scene = #{subscribe_scene}</if>
        </where>
    </select>

    <select id="selectJsgzhUserList" resultMap="JsgzhUserResult">
        select * from jsgzh_user
        <where>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
        </where>
    </select>

    <select id="selectJsgzhUserListNullName" resultType="com.miaxis.jsgzh.domain.JsgzhUser">
        select * from jsgzh_user
        <where>
           and is_get = 0
        </where>
    </select>


    <update id="updateJsgzhUserByOpenId" parameterType="JsgzhUser">
        update jsgzh_user j
        <set>
            j.update_time = now(),
            <if test="openid != null  and openid != ''"> j.openid= #{openid}, </if>
            <if test="nickname != null  and nickname != ''">  j.nickname = #{nickname}, </if>
            <if test="subscribe != null ">  j.subscribe = #{subscribe},</if>
            <if test="sex != null ">  j.sex = #{sex} ,</if>
            <if test="city != null  and city != ''">  j.city = #{city} ,</if>
            <if test="country != null  and country != ''">  j.country = #{country},</if>
            <if test="province != null  and province != ''">  j.province = #{province} ,</if>
            <if test="language != null  and language != ''">  j.language = #{language} ,</if>
            <if test="headimgurl != null  and headimgurl != ''">  j.headimgurl = #{headimgurl} ,</if>
            <if test="subscribe_time != null ">  j.subscribe_time = #{subscribe_time} ,</if>
            <if test="unionid != null ">  j.unionid = #{unionid} ,</if>
            <if test="groupid != null ">  j.groupid = #{groupid} ,</if>
            <if test="is_get != null ">  j.is_get = #{is_get} ,</if>

            <if test="tagid_list != null  and tagid_list != ''">  j.tagid_list = #{tagid_list,typeHandler=com.miaxis.common.utils.JsonTypeHandler} ,</if>

<!--
            <if test="tagid_list != null  and tagid_list != ''">  j.tagid_list = #{tagid_list,com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler} ,</if>
-->
            <if test="subscribe_scene != null  and subscribe_scene != ''">  j.subscribe_scene = #{subscribe_scene}</if>
        </set>
        where j.openid = #{openid}
    </update>

</mapper>
