邮件 活跃度下发

This commit is contained in:
mamengke01
2021-02-05 11:45:07 +08:00
parent 871e71ab54
commit 286eb231a6
36 changed files with 1183 additions and 439 deletions

View File

@@ -0,0 +1,38 @@
import { mailInit, setMails, GMMail } from '../gmData/gmMail';
import { nowSeconds } from '../timeUtil';
const ALL_SERVER = 0;
export let gmData:any = {};
export async function init() {
gmData.mails = await mailInit();
}
export function getGmMails(updatedMailAt: number, serverId: number) {
let list = [];
let serverIds = [serverId, ALL_SERVER];
for (let serverId of serverIds) {
if (!gmData.mails.get(serverId))
continue;
gmData.mails.get(serverId).map(({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType})=>{
if (updatedAt >= updatedMailAt || sendTime > updatedMailAt || endTime < nowSeconds() )
list.push({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType});
});
}
return list;
}
export function getGmMailById(id: string, serverId: number) {
let gmMail;
if (!!gmData.mails.get(serverId)) {
gmMail = gmData.mails.get(serverId).get(id);
}
if (!gmMail) {
if (!!gmData.mails.get(ALL_SERVER)) {
gmMail = gmData.mails.get(ALL_SERVER).get(id);
}
}
return gmMail;
}
export function setGmMails(mails: GMMail[]) {
setMails(mails, gmData.mails);
}

View File

@@ -0,0 +1,59 @@
type KeysEnum<T> = { [P in keyof Required<T>]: true };
import { RewardInter } from '../interface';
import { GMMailModel } from '../../db/GMMail';
const _ = require('lodash');
export interface GMMail {
readonly id: string;
readonly sendRoles?: Array<{roleId: string, status: number}>;
readonly goods: Array<RewardInter>;
readonly sendTime: number;
readonly endTime: number;
readonly content: string;
readonly gmMailType: number;
readonly updatedAt: number;
readonly serverId: number;
readonly sendName: string;
}
const GMMailKeys: KeysEnum<GMMail> = {
id: true,
sendRoles: true,
goods: true,
sendTime: true,
endTime: true,
content: true,
gmMailType: true,
updatedAt: true,
serverId: true,
sendName: true
};
export async function mailInit() {
let gmMail = new Map<number, any>();
let mails = await GMMailModel.getMails();
mails.map((o:any)=>{
o.id = o._id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
return gmMail;
}
export function setMails(mails:GMMail[], gmMail) {
mails.map((o:any)=>{
o.id = o._id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
}