<?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.rj.mapper.LbUserMapper">

    <insert id="upsertBatch">
        INSERT INTO lb_user (
            id, tenant_id, pid, username, nickname, mobile, password, salt, sex, avatar,
            invite, level, birthday, money, coupon, self_bonus, share_bonus, score,
            last_time, last_ip, join_time, join_ip, token, created_at, updated_at,
            status, viptime, is_vip, contract, max_order, is_resell,
            yesterday_sell_count, today_buy_count, today_buy_total, today_sell_total,
            poor, pname, pmobile
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
                #{item.id}, #{item.tenantId}, #{item.pid}, #{item.username}, #{item.nickname},
                #{item.mobile}, #{item.password}, #{item.salt}, #{item.sex}, #{item.avatar},
                #{item.invite}, #{item.level}, #{item.birthday}, #{item.money}, #{item.coupon},
                #{item.selfBonus}, #{item.shareBonus}, #{item.score},
                #{item.lastTime}, #{item.lastIp}, #{item.joinTime}, #{item.joinIp}, #{item.token},
                #{item.createdAt}, #{item.updatedAt},
                #{item.status}, #{item.viptime}, #{item.isVip}, #{item.contract}, #{item.maxOrder},
                #{item.isResell}, #{item.yesterdaySellCount}, #{item.todayBuyCount},
                #{item.todayBuyTotal}, #{item.todaySellTotal}, #{item.poor}, #{item.pname},
                #{item.pmobile}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
            tenant_id = VALUES(tenant_id),
            pid = VALUES(pid),
            username = VALUES(username),
            nickname = VALUES(nickname),
            mobile = VALUES(mobile),
            password = VALUES(password),
            salt = VALUES(salt),
            sex = VALUES(sex),
            avatar = VALUES(avatar),
            invite = VALUES(invite),
            level = VALUES(level),
            birthday = VALUES(birthday),
            money = VALUES(money),
            coupon = VALUES(coupon),
            self_bonus = VALUES(self_bonus),
            share_bonus = VALUES(share_bonus),
            score = VALUES(score),
            last_time = VALUES(last_time),
            last_ip = VALUES(last_ip),
            join_time = VALUES(join_time),
            join_ip = VALUES(join_ip),
            token = VALUES(token),
            created_at = VALUES(created_at),
            updated_at = VALUES(updated_at),
            status = VALUES(status),
            viptime = VALUES(viptime),
            is_vip = VALUES(is_vip),
            contract = VALUES(contract),
            max_order = VALUES(max_order),
            is_resell = VALUES(is_resell),
            yesterday_sell_count = VALUES(yesterday_sell_count),
            today_buy_count = VALUES(today_buy_count),
            today_buy_total = VALUES(today_buy_total),
            today_sell_total = VALUES(today_sell_total),
            poor = VALUES(poor),
            pname = VALUES(pname),
            pmobile = VALUES(pmobile)
    </insert>

    <update id="fillPmobileByTenantId">
        UPDATE lb_user u
        LEFT JOIN lb_user p ON u.pid = p.id AND u.tenant_id = p.tenant_id
        SET u.pmobile = p.mobile
        WHERE u.tenant_id = #{tenantId}
    </update>

</mapper>
