<?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.ruoyi.model.mapper.AppUsersMapper">
    
    <resultMap type="AppUsers" id="AppUsersResult">
        <result property="userId" column="user_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="remark" column="remark"/>
        <result property="updateTime" column="update_time"/>
        <result property="updatorBy" column="updator_by"/>
        <result property="userImage" column="user_image"/>
        <result property="userName" column="user_name"/>
        <result property="userState" column="user_state"/>
        <result property="userTelephone" column="user_telephone"/>
        <result property="unionid" column="unionid"/>
        <result property="openid" column="openid"/>
        <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="userHh" column="user_hh"/>
        <result property="userBcs" column="user_bcs"/>
        <result property="price" column="price"/>
        <result property="invitationCode" column="invitation_code"/>
        <result property="baoPrice" column="bao_price"/>
        <result property="userBcsRole" column="user_bcs_role"/>
        <result property="userHhRole" column="user_hh_role"/>
        <result property="money" column="money"/>
        <result property="hhStartTime" column="hh_start_time"/>
    </resultMap>

    <sql id="selectAppUsersVo">
        select user_id, create_by, create_time, del_flag, remark, update_time, updator_by, user_image, user_name, user_state, user_telephone, unionid, openid, access_token, expires_in, refresh_token, expire_time, user_hh, user_bcs, price, invitation_code, bao_price, user_bcs_role,user_hh_role, money, hh_start_time  from app_users
    </sql>

    <select id="selectAppUsersList" parameterType="AppUsers" resultMap="AppUsersResult">
        <include refid="selectAppUsersVo"/>
        <where>
            <if test="updatorBy != null  and updatorBy != ''"> and updator_by = #{updatorBy}</if>
            <if test="userImage != null  and userImage != ''"> and user_image = #{userImage}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userState != null "> and user_state = #{userState}</if>
            <if test="userTelephone != null  and userTelephone != ''"> and user_telephone = #{userTelephone}</if>
            <if test="unionid != null  and unionid != ''"> and unionid = #{unionid}</if>
            <if test="openid != null  and openid != ''"> and openid = #{openid}</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>
            <if test="userHh != null "> and user_hh = #{userHh}</if>
            <if test="userBcs != null "> and user_bcs = #{userBcs}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="invitationCode != null  and invitationCode != ''"> and invitation_code = #{invitationCode}</if>
            <if test="baoPrice != null "> and bao_price = #{baoPrice}</if>
            <if test="userBcsRole != null "> and user_bcs_role = #{userBcsRole}</if>
            <if test="userHhRole != null "> and user_hh_role = #{userHhRole}</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="hhStartTime != null "> and hh_start_time = #{hhStartTime}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectAppUsersByUserId" parameterType="Long" resultMap="AppUsersResult">
        <include refid="selectAppUsersVo"/>
        where user_id = #{userId}
    </select>
    <select id="selectAppUsersByOpenId" parameterType="AppUsers" resultMap="AppUsersResult">
        <include refid="selectAppUsersVo"/>
        where openid = #{openid}
    </select>

    <insert id="insertAppUsers" parameterType="AppUsers">
        insert into app_users
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updatorBy != null">updator_by,</if>
            <if test="userImage != null">user_image,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="userState != null">user_state,</if>
            <if test="userTelephone != null">user_telephone,</if>
            <if test="unionid != null">unionid,</if>
            <if test="openid != null">openid,</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="userHh != null">user_hh,</if>
            <if test="userBcs != null">user_bcs,</if>
            <if test="price != null">price,</if>
            <if test="invitationCode != null">invitation_code,</if>
            <if test="baoPrice != null">bao_price,</if>
            <if test="userBcsRole != null">user_bcs_role,</if>
            <if test="userHhRole != null">user_hh_role,</if>
            <if test="money != null">money,</if>
            <if test="hhStartTime != null">hh_start_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updatorBy != null">#{updatorBy},</if>
            <if test="userImage != null">#{userImage},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="userState != null">#{userState},</if>
            <if test="userTelephone != null">#{userTelephone},</if>
            <if test="unionid != null">#{unionid},</if>
            <if test="openid != null">#{openid},</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="userHh != null">#{userHh},</if>
            <if test="userBcs != null">#{userBcs},</if>
            <if test="price != null">#{price},</if>
            <if test="invitationCode != null">#{invitationCode},</if>
            <if test="baoPrice != null">#{baoPrice},</if>
            <if test="userBcsRole != null">#{userBcsRole},</if>
            <if test="userHhRole != null">#{userHhRole},</if>
            <if test="money != null">#{money},</if>
            <if test="hhStartTime != null">#{hhStartTime},</if>

        </trim>
    </insert>

    <update id="updateAppUsers" parameterType="AppUsers">
        update app_users
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updatorBy != null">updator_by = #{updatorBy},</if>
            <if test="userImage != null">user_image = #{userImage},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="userState != null">user_state = #{userState},</if>
            <if test="userTelephone != null">user_telephone = #{userTelephone},</if>
            <if test="unionid != null">unionid = #{unionid},</if>
            <if test="openid != null">openid = #{openid},</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="userHh != null">user_hh = #{userHh},</if>
            <if test="userBcs != null">user_bcs = #{userBcs},</if>
            <if test="price != null">price = #{price},</if>
            <if test="invitationCode != null">invitation_code = #{invitationCode},</if>
            <if test="baoPrice != null">bao_price = #{baoPrice},</if>
            <if test="userBcsRole != null">user_bcs_role = #{userBcsRole},</if>
            <if test="userHhRole != null">user_hh_role = #{userHhRole},</if>
            <if test="money != null">money = #{money},</if>
            <if test="hhStartTime != null">hh_start_time = #{hhStartTime},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteAppUsersByUserId" parameterType="Long">
        delete from app_users where user_id = #{userId}
    </delete>

    <delete id="deleteAppUsersByUserIds" parameterType="String">
        delete from app_users where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>