🐞 fix(gvg): 批量保存数据后返回有时无法查询

This commit is contained in:
luying
2023-02-18 17:30:49 +08:00
parent cbbacd27b5
commit 8065a81988
3 changed files with 26 additions and 37 deletions
+3 -7
View File
@@ -122,9 +122,6 @@ export default class GVGTeam extends BaseModel {
@prop({ required: true, default: false })
isBroken: boolean; // 机器人是否被击破,如果没有被击破,那么这个位置上就还是机器人,如果被击破了,这个位置就空出给玩家
@prop({ required: false })
batchCode: string; // 批量编号
originPointId: number;
curTeamBreak: boolean;
@@ -319,15 +316,14 @@ export default class GVGTeam extends BaseModel {
// 投石车伤害
public static async attackByCatapult(teamCodes: string[], inc: number, rebirthAreaId: number) {
let batchCode = genCode(8);
await GVGTeamModel.updateMany({ teamCode: { $in: teamCodes } }, { $inc: { durability: -inc }, $set: { batchCode } });
let brokenTeams: GVGTeamType[] = await GVGTeamModel.find({ batchCode, durability: { $lte: 0 } }).lean();
await GVGTeamModel.updateMany({ teamCode: { $in: teamCodes } }, { $inc: { durability: -inc } });
let brokenTeams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes }, durability: { $lte: 0 } }).lean();
if(brokenTeams.length > 0) {
await GVGTeamModel.bulkWrite(brokenTeams.map(({ teamCode, maxDurability }) => {
return { updateOne: { filter: { teamCode }, update: { $set: { areaId: rebirthAreaId, pointId: 0, durability: maxDurability } }}}
}));
}
let teams: GVGTeamType[] = await GVGTeamModel.find({ batchCode }).lean();
let teams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes } }).lean();
return teams.map(team => {
let originTeam = brokenTeams.find(origin => origin.teamCode == team.teamCode);
if(originTeam) {