<?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.cyl.mall.mapper.StaffWechatMapper">
    
    <resultMap type="StaffWechat" id="StaffWechatResult">
        <result property="id" column="id"/>
        <result property="memberId" column="member_id"/>
        <result property="unionid" column="unionid"/>
        <result property="openid" column="openid"/>
        <result property="wechatId" column="wechat_id"/>
        <result property="routineOpenid" column="routine_openid"/>
        <result property="groupid" column="groupid"/>
        <result property="tagidList" column="tagid_list"/>
        <result property="subscribe" column="subscribe"/>
        <result property="subscribeTime" column="subscribe_time"/>
        <result property="sessionKey" column="session_key"/>
        <result property="accessToken" column="access_token"/>
        <result property="expiresIn" column="expires_in"/>
        <result property="refreshToken" column="refresh_token"/>
        <result property="expireTime" column="expire_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectStaffWechatVo">
        select id, member_id, unionid, openid, wechat_id, routine_openid, groupid, tagid_list, subscribe, subscribe_time, session_key, access_token, expires_in, refresh_token, expire_time, create_by, create_time, update_by, update_time , create_by, create_time, update_by, update_time from staff_wachat
    </sql>

    <select id="selectList" parameterType="StaffWechat" resultMap="StaffWechatResult">
        <include refid="selectStaffWechatVo"/>
        <where>  
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="unionid != null  and unionid != ''"> and unionid = #{unionid}</if>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
            <if test="wechatId != null  and wechatId != ''"> and wechat_id = #{wechatId}</if>
            <if test="routineOpenid != null  and routineOpenid != ''"> and routine_openid = #{routineOpenid}</if>
            <if test="groupid != null "> and groupid = #{groupid}</if>
            <if test="tagidList != null  and tagidList != ''"> and tagid_list = #{tagidList}</if>
            <if test="subscribe != null "> and subscribe = #{subscribe}</if>
            <if test="subscribeTime != null "> and subscribe_time = #{subscribeTime}</if>
            <if test="sessionKey != null  and sessionKey != ''"> and session_key = #{sessionKey}</if>
            <if test="accessToken != null  and accessToken != ''"> and access_token = #{accessToken}</if>
            <if test="expiresIn != null "> and expires_in = #{expiresIn}</if>
            <if test="refreshToken != null  and refreshToken != ''"> and refresh_token = #{refreshToken}</if>
            <if test="expireTime != null "> and expire_time = #{expireTime}</if>
        </where>
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="StaffWechatResult">
        <include refid="selectStaffWechatVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="StaffWechat" useGeneratedKeys="true" keyProperty="id">
        insert into staff_wachat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="unionid != null">unionid,</if>
            <if test="openid != null">openid,</if>
            <if test="wechatId != null">wechat_id,</if>
            <if test="routineOpenid != null">routine_openid,</if>
            <if test="groupid != null">groupid,</if>
            <if test="tagidList != null">tagid_list,</if>
            <if test="subscribe != null">subscribe,</if>
            <if test="subscribeTime != null">subscribe_time,</if>
            <if test="sessionKey != null">session_key,</if>
            <if test="accessToken != null">access_token,</if>
            <if test="expiresIn != null">expires_in,</if>
            <if test="refreshToken != null">refresh_token,</if>
            <if test="expireTime != null">expire_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="unionid != null">#{unionid},</if>
            <if test="openid != null">#{openid},</if>
            <if test="wechatId != null">#{wechatId},</if>
            <if test="routineOpenid != null">#{routineOpenid},</if>
            <if test="groupid != null">#{groupid},</if>
            <if test="tagidList != null">#{tagidList},</if>
            <if test="subscribe != null">#{subscribe},</if>
            <if test="subscribeTime != null">#{subscribeTime},</if>
            <if test="sessionKey != null">#{sessionKey},</if>
            <if test="accessToken != null">#{accessToken},</if>
            <if test="expiresIn != null">#{expiresIn},</if>
            <if test="refreshToken != null">#{refreshToken},</if>
            <if test="expireTime != null">#{expireTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="update" parameterType="StaffWechat">
        update staff_wachat
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="unionid != null">unionid = #{unionid},</if>
            <if test="openid != null">openid = #{openid},</if>
            <if test="wechatId != null">wechat_id = #{wechatId},</if>
            <if test="routineOpenid != null">routine_openid = #{routineOpenid},</if>
            <if test="groupid != null">groupid = #{groupid},</if>
            <if test="tagidList != null">tagid_list = #{tagidList},</if>
            <if test="subscribe != null">subscribe = #{subscribe},</if>
            <if test="subscribeTime != null">subscribe_time = #{subscribeTime},</if>
            <if test="sessionKey != null">session_key = #{sessionKey},</if>
            <if test="accessToken != null">access_token = #{accessToken},</if>
            <if test="expiresIn != null">expires_in = #{expiresIn},</if>
            <if test="refreshToken != null">refresh_token = #{refreshToken},</if>
            <if test="expireTime != null">expire_time = #{expireTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from staff_wachat where id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="String">
        delete from staff_wachat where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertOrUpdate" parameterType="StaffWechat" useGeneratedKeys="true" keyProperty="id">
        insert into staff_wachat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
             member_id, unionid, openid, wechat_id, routine_openid, groupid, tagid_list, subscribe, subscribe_time, session_key, access_token, expires_in, refresh_token, expire_time, create_by, create_time, update_by, update_time,
            create_by, create_time, update_by, update_time
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id, jdbcType=BIGINT},
        </if>
        #{memberId, jdbcType=BIGINT},#{unionid, jdbcType=VARCHAR},#{openid, jdbcType=VARCHAR},#{wechatId, jdbcType=VARCHAR},#{routineOpenid, jdbcType=VARCHAR},#{groupid, jdbcType=SMALLINT},#{tagidList, jdbcType=VARCHAR},#{subscribe, jdbcType=TINYINT},#{subscribeTime, jdbcType=INTEGER},#{sessionKey, jdbcType=VARCHAR},#{accessToken, jdbcType=VARCHAR},#{expiresIn, jdbcType=INTEGER},#{refreshToken, jdbcType=VARCHAR},#{expireTime, jdbcType=DATE},#{createBy, jdbcType=BIGINT},#{createTime, jdbcType=DATE},#{updateBy, jdbcType=BIGINT},#{updateTime, jdbcType=DATE},
        #{createBy}, #{createTime}, #{updateBy}, #{updateTime}
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=BIGINT},
            </if>
            member_id = #{memberId, jdbcType=BIGINT},
            unionid = #{unionid, jdbcType=VARCHAR},
            openid = #{openid, jdbcType=VARCHAR},
            wechat_id = #{wechatId, jdbcType=VARCHAR},
            routine_openid = #{routineOpenid, jdbcType=VARCHAR},
            groupid = #{groupid, jdbcType=SMALLINT},
            tagid_list = #{tagidList, jdbcType=VARCHAR},
            subscribe = #{subscribe, jdbcType=TINYINT},
            subscribe_time = #{subscribeTime, jdbcType=INTEGER},
            session_key = #{sessionKey, jdbcType=VARCHAR},
            access_token = #{accessToken, jdbcType=VARCHAR},
            expires_in = #{expiresIn, jdbcType=INTEGER},
            refresh_token = #{refreshToken, jdbcType=VARCHAR},
            expire_time = #{expireTime, jdbcType=DATE},
            create_by = #{createBy, jdbcType=BIGINT},
            create_time = #{createTime, jdbcType=DATE},
            update_by = #{updateBy, jdbcType=BIGINT},
            update_time = #{updateTime, jdbcType=DATE},
            create_by = #{createBy},
            create_time = #{createTime},
            update_by = #{updateBy},
            update_time = #{updateTime},
        </trim>
    </insert>
</mapper>
