import { ApiCall } from 'tsrpc';
import { GongHuiBaoZangMsg } from '../shared/protocols/gonghuibaozang/PtlLottery';
import { PublicShared } from '../shared/public/public';

let msgListLen = 50

export class GongHuiBaoZang {
    /**插入工会宝藏抽奖数据 和 推送change */
    static async newMsg(sendData: GongHuiBaoZangMsg | GongHuiBaoZangMsg[]) {
        let conns = G.server.connections;
        if (sendData instanceof Array) {
            G.mongodb.collection('ghbzcjlog').updateOne(
                { type: "gonghuibaozang_msg" },
                { $push: { list: { $each: sendData, $slice: -msgListLen } } },
                { upsert: true }
            );
            G.server.broadcastClusterMsg('msg_s2c/GongHuiBaoZang', sendData);

        } else {
            G.mongodb.collection('ghbzcjlog').updateOne(
                { type: "gonghuibaozang_msg" },
                { $push: { list: { $each: [sendData], $slice: -msgListLen } } },
                { upsert: true }
            );

            G.server.broadcastClusterMsg('msg_s2c/GongHuiBaoZang', [sendData]);
        }

    }



}