From e23268b048c22d00639f979869aece74a99a71bb Mon Sep 17 00:00:00 2001 From: wenlele Date: Mon, 18 Dec 2023 13:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E8=B7=AF=E6=8A=BD=E6=9F=A5=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/report/index.js | 59 ++++++++++++++++++++----- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index da07caf1..08412723 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -523,16 +523,17 @@ async function roadSpotPrepare (ctx) { where: { checked: true }, - attributes: ['id', 'countyPercentage', 'date',], + // attributes: ['id', 'countyPercentage', 'date',], order: [['date', 'DESC']], - include: [{ - model: models.RoadSpotCheck, - include: [{ - model: models.Road, - // attributes: ['id', 'name'] - }] - }] + // include: [{ + // model: models.RoadSpotCheck, + // include: [{ + // model: models.Road, + // // attributes: ['id', 'name'] + // }] + // }] }) + let lastCountyPercentage = 0 // 最后一次的县道百分比 let lastCountyRoadIds = [] // 上次查得的县道id @@ -542,11 +543,45 @@ async function roadSpotPrepare (ctx) { if (lastSpotRes) { lastCountyPercentage = lastSpotRes.countyPercentage - // 遍历 RoadSpotCheck,保存上次查询的路的id lastCountyRoadIds = lastSpotRes.countyRoadId || [] - lastTownRoadIds = lastSpotRes.townshipRoadId || [] - lastVillageRoadRoadIds = lastSpotRes.villageRoadId || [] - lastVillageIds = lastSpotRes.villageId || [] + + let lastCounty = await models.RoadSpotCheckPreview.findAll({ + where: { + checked: true, + id: { $lt: lastSpotRes.id } + }, + limit: 3, + order: [['date', 'DESC']], + }) + + if (lastCounty) { + lastCounty.forEach(d => { + lastTownRoadIds = lastTownRoadIds.concat(d.townshipRoadId) || [] + + }) + } + + let lastVillage = await models.RoadSpotCheckPreview.findAll({ + where: { + checked: true, + id: { $lt: lastSpotRes.id } + }, + limit: 9, + order: [['date', 'DESC']], + }) + + if (lastVillage) { + lastVillage.forEach(d => { + lastVillageRoadRoadIds = lastVillageRoadRoadIds.concat(d.villageRoadId) || [] + lastVillageIds = lastVillageIds.concat(d.villageId) || [] + + }) + } + + + // lastTownRoadIds = lastSpotRes.townshipRoadId || [] + // lastVillageRoadRoadIds = lastSpotRes.villageRoadId || [] + // lastVillageIds = lastSpotRes.villageId || [] } // 先查上次没查的范围内的 然后比较百分比 如果重叠 再查上次查过的