整理启动逻辑
This commit is contained in:
@@ -2,12 +2,12 @@ import { Application, ChannelService, HandlerService, } from 'pinus';
|
||||
import { ActivityModel, ActivityModelType } from '../../../db/Activity';
|
||||
import { ServerlistModel } from '../../../db/Serverlist';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { _getActivitiesByType, _getActivityById, _getActivities, _getActivitiesByServerId } from '../../../services/activity/activityService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { taflush } from '../../../services/sdkService';
|
||||
import { ActivityInRemote } from '../../../domain/activityField/activityField';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
import { ActivityGroupModel } from '../../../db/ActivityGroup';
|
||||
import { deleteActivities, loadActivities, saveActivitiesToGroup, updateActivities, _getActivityById, _getActivitiesByType, _getActivities, _getActivitiesByServerId } from '../../../services/activity/activityRemoteService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -22,10 +22,6 @@ export class ActivityRemote {
|
||||
}
|
||||
|
||||
private channelService: ChannelService;
|
||||
private activityByServer: Map<number, number[]> = new Map(); // serverId => activityId[];
|
||||
private activities: Map<number, ActivityInRemote> = new Map(); // activityId => activity
|
||||
private activityByType: Map<number, Map<number, number[]>> = new Map(); // serverId => type => activityId[];
|
||||
private groupToServer: Map<number, number[]> = new Map(); // group => serverId[];
|
||||
|
||||
/**
|
||||
* 重载json资源
|
||||
@@ -38,86 +34,19 @@ export class ActivityRemote {
|
||||
}
|
||||
}
|
||||
|
||||
private clearData() {
|
||||
this.activityByServer.clear();
|
||||
this.activities.clear();
|
||||
this.activityByType.clear();
|
||||
this.groupToServer.clear();
|
||||
}
|
||||
|
||||
public async loadActivities() {
|
||||
try {
|
||||
this.clearData();
|
||||
let activityGroup = await ActivityGroupModel.findAllActivityGroup();
|
||||
for(let { groupId, serverIds } of activityGroup) {
|
||||
for(let serverId of serverIds) {
|
||||
if(!this.groupToServer.has(groupId)) {
|
||||
this.groupToServer.set(groupId, []);
|
||||
}
|
||||
this.groupToServer.get(groupId).push(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
let activities = await ActivityModel.findOpenAndComingActivityes();
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, new ActivityInRemote(activity));
|
||||
activityIds.push(activity.activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
// console.log('****** loadActivities')
|
||||
await loadActivities();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
private setActivityTypeAndServer() {
|
||||
this.activityByServer.clear();
|
||||
this.activityByType.clear();
|
||||
|
||||
for(let [_, activity] of this.activities) {
|
||||
let servers = this.groupToServer.get(activity.groupId)||[];
|
||||
for(let serverId of servers) {
|
||||
if(!this.activityByServer.has(serverId)) {
|
||||
this.activityByServer.set(serverId, []);
|
||||
}
|
||||
this.activityByServer.get(serverId).push(activity.activityId);
|
||||
|
||||
if(!this.activityByType.has(serverId)) {
|
||||
this.activityByType.set(serverId, new Map());
|
||||
}
|
||||
if(!this.activityByType.get(serverId).has(activity.type)) {
|
||||
this.activityByType.get(serverId).set(activity.type, []);
|
||||
}
|
||||
this.activityByType.get(serverId).get(activity.type).push(activity.activityId);
|
||||
}
|
||||
}
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
}
|
||||
|
||||
public async updateActivities(activities: ActivityInRemote[]) {
|
||||
try {
|
||||
// console.log('******* activities', activities)
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, activity);
|
||||
activityIds.push(activity.activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
updateActivities(activities);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
@@ -125,15 +54,7 @@ export class ActivityRemote {
|
||||
|
||||
public async deleteActivities(activityIds: number[]) {
|
||||
try {
|
||||
for(let activityId of activityIds) {
|
||||
this.activities.delete(activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
deleteActivities(activityIds);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
@@ -141,13 +62,7 @@ export class ActivityRemote {
|
||||
|
||||
public async saveGroupToServer(groupId: number, serverIds: number[]) {
|
||||
try {
|
||||
this.groupToServer.set(groupId, serverIds);
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
this.saveGroupToServer(groupId, serverIds);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
@@ -155,12 +70,7 @@ export class ActivityRemote {
|
||||
|
||||
public async saveActivitiesToGroup(groupId: number, activities: number[]) {
|
||||
try {
|
||||
for(let activityId of activities) {
|
||||
if(this.activities.get(activityId)) {
|
||||
this.activities.get(activityId).groupId = groupId;
|
||||
}
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
saveActivitiesToGroup(groupId, activities);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user