|
@ -540,13 +540,17 @@ async function roadSpotPrepare (ctx) { |
|
|
let lastCountyPercentage = 0 // 最后一次的县道百分比
|
|
|
let lastCountyPercentage = 0 // 最后一次的县道百分比
|
|
|
let lastCountyRoadIds = [] // 上次查得的县道id
|
|
|
let lastCountyRoadIds = [] // 上次查得的县道id
|
|
|
let lastTownRoadIds = [] // 上次查得的乡镇道id
|
|
|
let lastTownRoadIds = [] // 上次查得的乡镇道id
|
|
|
let lastVillageRoadRoadIds = [] // 上次查得的村道id
|
|
|
let lastVillageRoadRoadIds = [-1] // 上次查得的村道id
|
|
|
let lastVillageIds = [] |
|
|
let lastVillageIds = [] |
|
|
|
|
|
let lastAbstractVillage = {} |
|
|
let gather = [] //汇总
|
|
|
let gather = [] //汇总
|
|
|
|
|
|
|
|
|
if (lastSpotRes) { |
|
|
if (lastSpotRes) { |
|
|
lastCountyPercentage = lastSpotRes.countyPercentage |
|
|
lastCountyPercentage = lastSpotRes.countyPercentage |
|
|
lastCountyRoadIds = lastSpotRes.countyRoadId || [] |
|
|
lastCountyRoadIds = lastSpotRes.countyRoadId || [] |
|
|
|
|
|
lastAbstractVillage = lastSpotRes.lastAbstractVillage || {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let lastCounty = await models.RoadSpotCheckPreview.findAll({ |
|
|
let lastCounty = await models.RoadSpotCheckPreview.findAll({ |
|
|
where: { |
|
|
where: { |
|
@ -558,9 +562,12 @@ async function roadSpotPrepare (ctx) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (lastCounty) { |
|
|
if (lastCounty) { |
|
|
|
|
|
let countyNnmter = 0 |
|
|
lastCounty.forEach(d => { |
|
|
lastCounty.forEach(d => { |
|
|
lastTownRoadIds = lastTownRoadIds.concat(d.townshipRoadId) || [] |
|
|
if (countyNnmter < (100 - (countyPercentage == 75 ? 50 : 25))) { |
|
|
|
|
|
lastTownRoadIds = lastTownRoadIds.concat(d.townshipRoadId) || [] |
|
|
|
|
|
countyNnmter += (d.countyPercentage == 75 ? 50 : 25) |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -574,10 +581,14 @@ async function roadSpotPrepare (ctx) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (lastVillage) { |
|
|
if (lastVillage) { |
|
|
|
|
|
let villageNnmter = 0 |
|
|
lastVillage.forEach(d => { |
|
|
lastVillage.forEach(d => { |
|
|
lastVillageRoadRoadIds = lastVillageRoadRoadIds.concat(d.villageRoadId) || [] |
|
|
if (villageNnmter < (100 - (countyPercentage == 75 ? 20 : 10))) { |
|
|
lastVillageIds = lastVillageIds.concat(d.villageId) || [] |
|
|
lastVillageRoadRoadIds = lastVillageRoadRoadIds.concat(d.villageRoadId) || [] |
|
|
|
|
|
lastVillageIds = lastVillageIds.concat(d.villageId) || [] |
|
|
|
|
|
|
|
|
|
|
|
villageNnmter += (d.countyPercentage == 75 ? 20 : 10) |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -627,6 +638,7 @@ async function roadSpotPrepare (ctx) { |
|
|
async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { |
|
|
async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { |
|
|
let spotRoadIds = [] |
|
|
let spotRoadIds = [] |
|
|
let accumulationMileage = 0 |
|
|
let accumulationMileage = 0 |
|
|
|
|
|
let last = null |
|
|
|
|
|
|
|
|
async function filterRoad (otherWhere, getRepeat = true) { |
|
|
async function filterRoad (otherWhere, getRepeat = true) { |
|
|
|
|
|
|
|
@ -671,6 +683,7 @@ async function roadSpotPrepare (ctx) { |
|
|
], false) |
|
|
], false) |
|
|
|
|
|
|
|
|
spotVillageIds.push(villageId) |
|
|
spotVillageIds.push(villageId) |
|
|
|
|
|
last = villageId |
|
|
|
|
|
|
|
|
if (accumulationMileage >= targetMileage) { |
|
|
if (accumulationMileage >= targetMileage) { |
|
|
break; |
|
|
break; |
|
@ -678,13 +691,27 @@ async function roadSpotPrepare (ctx) { |
|
|
} |
|
|
} |
|
|
if (accumulationMileage < targetMileage) { |
|
|
if (accumulationMileage < targetMileage) { |
|
|
// 还小于 说明没取够
|
|
|
// 还小于 说明没取够
|
|
|
await filterRoad(otherWhere, true) |
|
|
// await filterRoad(otherWhere, true)
|
|
|
|
|
|
|
|
|
|
|
|
for await (let villageId of villageIdList.reverse()) { |
|
|
|
|
|
await filterRoad([ |
|
|
|
|
|
...otherWhere, |
|
|
|
|
|
`village_id=${villageId}` |
|
|
|
|
|
], true) |
|
|
|
|
|
|
|
|
|
|
|
spotVillageIds.push(villageId) |
|
|
|
|
|
last = villageId |
|
|
|
|
|
|
|
|
|
|
|
if (accumulationMileage >= targetMileage) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
await filterRoad(otherWhere, true) |
|
|
await filterRoad(otherWhere, true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return [spotRoadIds, accumulationMileage] |
|
|
return [spotRoadIds, accumulationMileage, last] |
|
|
} |
|
|
} |
|
|
let villageMil = 0, townMil = 0, countryMil = 0; |
|
|
let villageMil = 0, townMil = 0, countryMil = 0; |
|
|
|
|
|
|
|
@ -723,6 +750,8 @@ async function roadSpotPrepare (ctx) { |
|
|
let spotVillageIds = [] |
|
|
let spotVillageIds = [] |
|
|
|
|
|
|
|
|
let allTownCodeResTown = [] |
|
|
let allTownCodeResTown = [] |
|
|
|
|
|
let lastEndVillage = {} //获取每个乡镇最后一个被抽取的村
|
|
|
|
|
|
|
|
|
for await (let t of allTownCodeRes) { |
|
|
for await (let t of allTownCodeRes) { |
|
|
// 遍历每个乡镇并抽取
|
|
|
// 遍历每个乡镇并抽取
|
|
|
let otherWhere = [`township_code='${t.township_code}'`] |
|
|
let otherWhere = [`township_code='${t.township_code}'`] |
|
@ -743,26 +772,36 @@ async function roadSpotPrepare (ctx) { |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * (countyPercentage == 75 ? 20 : 10) / 100 |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * (countyPercentage == 75 ? 20 : 10) / 100 |
|
|
|
|
|
|
|
|
let spotFirstVillageId = -1 |
|
|
let spotFirstVillageId = -1 |
|
|
// 随机选取一个不在上次查过的村
|
|
|
|
|
|
let villageRes = await sequelize.query(` |
|
|
let villageRes = [] |
|
|
SELECT id FROM village |
|
|
if (lastAbstractVillage[t.township_code]) { |
|
|
WHERE township_code = '${t.township_code}' |
|
|
|
|
|
${lastVillageIds.length ? `AND id NOT IN (
|
|
|
} else { |
|
|
${lastVillageIds.map(item => `'${item}'`).join(',')},-1 |
|
|
// 随机选取一个不在上次查过的村
|
|
|
)`: ''}
|
|
|
|
|
|
ORDER BY RANDOM() |
|
|
|
|
|
LIMIT 1 |
|
|
|
|
|
`, { type: QueryTypes.SELECT });
|
|
|
|
|
|
if (!villageRes.length) { |
|
|
|
|
|
// 没有村了,随机选一个
|
|
|
|
|
|
villageRes = await sequelize.query(` |
|
|
villageRes = await sequelize.query(` |
|
|
SELECT id FROM village |
|
|
SELECT id FROM village |
|
|
WHERE township_code = '${t.township_code}' |
|
|
WHERE township_code = '${t.township_code}' |
|
|
ORDER BY RANDOM() |
|
|
${lastVillageIds.length ? `AND id NOT IN (
|
|
|
LIMIT 1 |
|
|
${lastVillageIds.map(item => `'${item}'`).join(',')},-1 |
|
|
`, { type: QueryTypes.SELECT });
|
|
|
)`: ''}
|
|
|
|
|
|
ORDER BY RANDOM() |
|
|
|
|
|
LIMIT 1 |
|
|
|
|
|
`, { type: QueryTypes.SELECT });
|
|
|
|
|
|
if (!villageRes.length) { |
|
|
|
|
|
// 没有村了,随机选一个
|
|
|
|
|
|
villageRes = await sequelize.query(` |
|
|
|
|
|
SELECT id FROM village |
|
|
|
|
|
WHERE township_code = '${t.township_code}' |
|
|
|
|
|
ORDER BY RANDOM() |
|
|
|
|
|
LIMIT 1 |
|
|
|
|
|
`, { type: QueryTypes.SELECT });
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (villageRes.length) { |
|
|
|
|
|
|
|
|
if (lastAbstractVillage[t.township_code]) { |
|
|
|
|
|
spotVillageIds.push(lastAbstractVillage[t.township_code]) |
|
|
|
|
|
spotFirstVillageId = lastAbstractVillage[t.township_code] |
|
|
|
|
|
} else if (villageRes.length) { |
|
|
spotVillageIds.push(villageRes[0].id) |
|
|
spotVillageIds.push(villageRes[0].id) |
|
|
spotFirstVillageId = villageRes[0].id |
|
|
spotFirstVillageId = villageRes[0].id |
|
|
} else { |
|
|
} else { |
|
@ -793,6 +832,8 @@ async function roadSpotPrepare (ctx) { |
|
|
let spotVillageRoadIdsArr = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList) |
|
|
let spotVillageRoadIdsArr = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList) |
|
|
let spotVillageRoadIds_ = spotVillageRoadIdsArr[0] |
|
|
let spotVillageRoadIds_ = spotVillageRoadIdsArr[0] |
|
|
let villageMil_ = spotVillageRoadIdsArr[1] |
|
|
let villageMil_ = spotVillageRoadIdsArr[1] |
|
|
|
|
|
lastEndVillage[t.township_code] = spotVillageRoadIdsArr[2] |
|
|
|
|
|
|
|
|
spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) |
|
|
spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) |
|
|
if (villageMil_) villageMil += villageMil_ |
|
|
if (villageMil_) villageMil += villageMil_ |
|
|
|
|
|
|
|
@ -808,6 +849,8 @@ async function roadSpotPrepare (ctx) { |
|
|
villageDifferenceValue: villageMil_ - villageRoadNeedMileage |
|
|
villageDifferenceValue: villageMil_ - villageRoadNeedMileage |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (let index = 0; index < town.length; index++) { |
|
|
for (let index = 0; index < town.length; index++) { |
|
@ -846,7 +889,8 @@ async function roadSpotPrepare (ctx) { |
|
|
villageMil, |
|
|
villageMil, |
|
|
townMil, |
|
|
townMil, |
|
|
countryMil, |
|
|
countryMil, |
|
|
gather |
|
|
gather, |
|
|
|
|
|
lastAbstractVillage: lastEndVillage |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|