|
@@ -15,18 +15,18 @@ class ScheduleService extends CrudService {
|
|
|
|
|
|
async checkNeedNext(id) {
|
|
|
const sch = await this.model.findById(id);
|
|
|
- const { red_branch, blue_branch, match_position, match_id } = sch;
|
|
|
+ const { red_branch, blue_branch, match_id } = sch;
|
|
|
if (!red_branch || !blue_branch) return;
|
|
|
- if (!match_position) console.error(`Schedule表: id: ${id} 数据缺少流程位置`);
|
|
|
// 有比分,有位置, 再看看同一轮其他比赛是不是有轮空的.有轮空的就不安排,没有轮空的就直接安排晋级比赛
|
|
|
// 将胜利的队伍的属性取出来,以便下面生成新数据
|
|
|
const winProp = [];
|
|
|
const propList = [ 'id', 'name', 'logo', 'members' ];
|
|
|
- let winTeam = 'blue';
|
|
|
- if (red_branch > blue_branch) winTeam = 'red';
|
|
|
+ const winTeam = this.getWinTeam(sch);
|
|
|
for (const p of propList) {
|
|
|
winProp.push({ key: p, value: sch[`${winTeam}_${p}`] });
|
|
|
}
|
|
|
+ // 随便拿一个位置,主要是下面要用轮数去做查询
|
|
|
+ const match_position = _.get(sch, 'red_position', _.get(sch, 'blue_position'));
|
|
|
const mpl = match_position.split('-');
|
|
|
const head = _.head(mpl);
|
|
|
const mpReg = new RegExp(`${head}-`);
|
|
@@ -70,7 +70,10 @@ class ScheduleService extends CrudService {
|
|
|
// 已经有了下场比赛的数据,做修改,将新数据放蓝队里
|
|
|
// 修改,一定是将数据放入蓝队中,所以需要判断下蓝队和红队是不是一个队伍,看下id就行
|
|
|
const nmRed_id = _.get(nextMatch, 'red_id');
|
|
|
- const winTeamId = _.get(winProp.find(f => f.key === 'id'), 'value');
|
|
|
+ const winTeamId = _.get(
|
|
|
+ winProp.find(f => f.key === 'id'),
|
|
|
+ 'value'
|
|
|
+ );
|
|
|
if (nmRed_id === winTeamId) return;
|
|
|
nextMatch = setTeamData('blue', nextMatch);
|
|
|
await nextMatch.save();
|
|
@@ -80,6 +83,12 @@ class ScheduleService extends CrudService {
|
|
|
await this.model.create(nextMatchCreateData);
|
|
|
}
|
|
|
}
|
|
|
+ // 根据比分Object获取胜利的队伍
|
|
|
+ getWinTeam(data) {
|
|
|
+ const { red_branch = 0, blue_branch = 0 } = data;
|
|
|
+ if (red_branch > blue_branch) return 'red';
|
|
|
+ return 'blue';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = ScheduleService;
|