活动:后台修改

This commit is contained in:
luying
2021-09-11 18:22:52 +08:00
parent d3f743ab4e
commit 7d2e4de3a8
3 changed files with 162 additions and 9 deletions

View File

@@ -20,7 +20,8 @@ export class ActivityRemote {
private channelService: ChannelService;
private activityByServer: Map<number, number[]> = new Map(); // serverId => activityId[];
private activities: Map<number, ActivityModelType> = new Map(); // activityId => activity
private activityByType: Map<number, Map<number, number[]>> = new Map(); // serverId => type => activityId[]
private activityByType: Map<number, Map<number, number[]>> = new Map(); // serverId => type => activityId[];
private groupToServer: Map<number, number[]> = new Map(); // group => serverId[];
/**
* 重载json资源
@@ -31,20 +32,19 @@ export class ActivityRemote {
private async loadActivities() {
let servers = await ServerlistModel.getAllServerList();
let groupToServer = new Map<number, number[]>();
for(let { serverId, activityGroupId } of servers) {
for(let groupId of activityGroupId) {
if(!groupToServer.has(groupId)) {
groupToServer.set(groupId, []);
if(!this.groupToServer.has(groupId)) {
this.groupToServer.set(groupId, []);
}
groupToServer.get(groupId).push(serverId);
this.groupToServer.get(groupId).push(serverId);
}
}
let activities = await ActivityModel.findOpenAndComingActivityes();
for(let activity of activities) {
this.activities.set(activity.activityId, activity);
let servers = groupToServer.get(activity.activityId)||[];
let servers = this.groupToServer.get(activity.activityId)||[];
for(let serverId of servers) {
if(!this.activityByServer.has(serverId)) {
this.activityByServer.set(serverId, []);
@@ -66,6 +66,62 @@ export class ActivityRemote {
this.app.set('activities', this.activities);
}
public async updateActivities(activities: ActivityModelType[]) {
for(let activity of activities) {
let { activityId, groupId, type } = activity;
// 'activities'
this.activities.set(activityId, activity);
let serverIds = this.groupToServer.get(groupId)||[]; // 现在这个group对应的serverIds
// 'activityByServer' & 'activityByType'
// 将原来的都删掉,再塞入
for(let [serverId, activityIds] of this.activityByServer) {
let index = activityIds.indexOf(activityId);
if(index != -1) this.activityByServer.get(serverId).splice(index);
}
for(let [serverId, typeToActivities] of this.activityByType) {
for(let [type, activityIds] of typeToActivities) {
let index = activityIds.indexOf(activityId);
if(index != -1) this.activityByType.get(serverId).get(type).splice(index);
}
}
// 塞入
for(let serverId of serverIds) {
if(!this.activityByServer.has(serverId)) {
this.activityByServer.set(serverId, []);
}
this.activityByServer.get(serverId).push(activityId);
if(!this.activityByType.has(serverId)) {
this.activityByType.set(serverId, new Map());
}
if(!this.activityByType.get(serverId).has(type)) {
this.activityByType.get(serverId).set(type, []);
}
this.activityByType.get(serverId).get(type).push(activityId);
}
}
}
public async deleteActivities(activityIds: number[]) {
for(let activityId of activityIds) {
// 'activities'
this.activities.delete(activityId);
// 'activityByServer' & 'activityByType'
// 将原来的都删掉
for(let [serverId, activityIds] of this.activityByServer) {
let index = activityIds.indexOf(activityId);
if(index != -1) this.activityByServer.get(serverId).splice(index);
}
for(let [serverId, typeToActivities] of this.activityByType) {
for(let [type, activityIds] of typeToActivities) {
let index = activityIds.indexOf(activityId);
if(index != -1) this.activityByType.get(serverId).get(type).splice(index);
}
}
}
}
public getActivityById(activityId: number) {
return _getActivityById(activityId);
}