Explorar el Código

优化盘口类型分类

flyzto hace 7 meses
padre
commit
f649691f22
Se han modificado 3 ficheros con 26 adiciones y 19 borrados
  1. 20 14
      server/models/Games.js
  2. 4 4
      server/routes/triangle.js
  3. 2 1
      spider/package.json

+ 20 - 14
server/models/Games.js

@@ -18,13 +18,13 @@ const GAMES = {
   Relations: {}
 };
 
-const updateGamesList = (({ platform, type, games } = {}) => {
+const updateGamesList = (({ platform, mk, games } = {}) => {
   return new Promise((resolve, reject) => {
     if (!platform || !games) {
       return reject(new Error('PLATFORM_GAMES_INVALID'));
     }
 
-    const marketType = type == 0 ? 'early' : 'today';
+    const marketType = mk == 0 ? 'early' : 'today';
 
     let gamesList = games;
 
@@ -74,11 +74,17 @@ const updateGamesList = (({ platform, type, games } = {}) => {
     }
 
     const oldIds = new Set(oldGames.map(item => item.eventId));
+    const relatedGames = Object.values(GAMES.Relations).map(rel => rel[platform] ?? {});
+    const relatedMap = new Map(relatedGames.map(item => [item.eventId, item]));
     newGames.forEach(item => {
       if (!oldIds.has(item.eventId)) {
         oldGames.push(item);
         updateCount.add += 1;
       }
+      if (relatedMap.has(item.eventId)) {
+        const relatedGame = relatedMap.get(item.eventId);
+        relatedGame.mk = mk;
+      }
     });
 
     GAMES_LIST[platform][marketType].timestamp = timestamp;
@@ -87,15 +93,15 @@ const updateGamesList = (({ platform, type, games } = {}) => {
   });
 });
 
-const updateGamesEvents = ({ platform, type, games, outrights }) => {
+const updateGamesEvents = ({ platform, mk, games, outrights }) => {
   return new Promise((resolve, reject) => {
     if (!platform || (!games && !outrights)) {
       return reject(new Error('PLATFORM_GAMES_INVALID'));
     }
 
-    const oldGames = Object.values(GAMES.Relations).map(rel => rel[platform] ?? {}).flat();
+    const relatedGames = Object.values(GAMES.Relations).map(rel => rel[platform] ?? {});
 
-    if (!oldGames.length) {
+    if (!relatedGames.length) {
       return resolve({ update: 0 });
     }
 
@@ -103,24 +109,24 @@ const updateGamesEvents = ({ platform, type, games, outrights }) => {
       update: 0
     };
 
-    const oldMap = new Map(oldGames.map(item => [item.eventId, item]));
+    const relatedMap = new Map(relatedGames.map(item => [item.eventId, item]));
 
     games?.forEach(game => {
       const { eventId, evtime, events } = game;
-      const oldGame = oldMap.get(eventId);
-      if (oldGame) {
-        oldGame.evtime = evtime;
-        oldGame.events = events;
+      const relatedGame = relatedMap.get(eventId);
+      if (relatedGame) {
+        relatedGame.evtime = evtime;
+        relatedGame.events = events;
         updateCount.update ++;
       }
     });
 
     outrights?.forEach(outright => {
       const { parentId, sptime, special } = outright;
-      const oldGame = oldMap.get(parentId);
-      if (oldGame) {
-        oldGame.sptime = sptime;
-        oldGame.special = special;
+      const relatedGame = relatedMap.get(parentId);
+      if (relatedGame) {
+        relatedGame.sptime = sptime;
+        relatedGame.special = special;
         updateCount.update ++;
       }
     });

+ 4 - 4
server/routes/triangle.js

@@ -7,8 +7,8 @@ const Games = require('../models/Games');
 
 // 更新比赛列表
 router.post('/update_games_list', (req, res) => {
-  const { platform, type, games } = req.body ?? {};
-  Games.updateGamesList({ platform, type, games })
+  const { platform, mk, games } = req.body ?? {};
+  Games.updateGamesList({ platform, mk, games })
   .then(updateCount => {
     res.sendSuccess({ updateCount });
   })
@@ -19,8 +19,8 @@ router.post('/update_games_list', (req, res) => {
 
 // 更新比赛盘口
 router.post('/update_games_events', (req, res) => {
-  const { platform, type, games, outrights } = req.body ?? {};
-  Games.updateGamesEvents({ platform, type, games, outrights })
+  const { platform, mk, games, outrights } = req.body ?? {};
+  Games.updateGamesEvents({ platform, mk, games, outrights })
   .then(updateCount => {
     res.sendSuccess({ updateCount });
   })

+ 2 - 1
spider/package.json

@@ -3,7 +3,8 @@
   "version": "1.0.0",
   "main": "index.js",
   "scripts": {
-    "dev": "nodemon index.js"
+    "dev": "nodemon index.js",
+    "start": "pm2 start index.js --name sporttery-spider"
   },
   "author": "",
   "license": "ISC",