From 36b4b24114dbce0810ef7343f6efca5d6241456e Mon Sep 17 00:00:00 2001 From: wenlele Date: Wed, 27 Dec 2023 10:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=91=E6=8A=BD=E6=9F=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 2 +- api/app/lib/controllers/report/index.js | 96 +++++++++++++----- api/app/lib/models/road_spot_check_preview.js | 9 ++ .../no_exist_village.txt | Bin 4158 -> 62 bytes .../1.4.2/5.alter_road_spot_check_preview.sql | 5 + web/client/src/components/README.txt | Bin 4148 -> 52 bytes 6 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 scripts/1.4.2/5.alter_road_spot_check_preview.sql diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 70665660..bc790728 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -17,7 +17,7 @@ "-f http://localhost:13400", // "-g postgres://FashionAdmin:123456@10.8.16.184:5432/sihaogonglu", // "-g postgres://postgres:123@10.8.30.32:5432/highways4good", - "-g postgres://postgres:123@10.8.30.32:5432/highway4test", + "-g postgres://postgres:123@10.8.30.32:5432/highwaytest1226", // "-g postgres://FashionAdmin:123456@10.8.30.156:5432/highway4goodn0728", "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index 49363ae7..c0446dd0 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -540,13 +540,17 @@ async function roadSpotPrepare (ctx) { let lastCountyPercentage = 0 // 最后一次的县道百分比 let lastCountyRoadIds = [] // 上次查得的县道id let lastTownRoadIds = [] // 上次查得的乡镇道id - let lastVillageRoadRoadIds = [] // 上次查得的村道id + let lastVillageRoadRoadIds = [-1] // 上次查得的村道id let lastVillageIds = [] + let lastAbstractVillage = {} let gather = [] //汇总 if (lastSpotRes) { lastCountyPercentage = lastSpotRes.countyPercentage lastCountyRoadIds = lastSpotRes.countyRoadId || [] + lastAbstractVillage = lastSpotRes.lastAbstractVillage || {} + + let lastCounty = await models.RoadSpotCheckPreview.findAll({ where: { @@ -558,9 +562,12 @@ async function roadSpotPrepare (ctx) { }) if (lastCounty) { + let countyNnmter = 0 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) { + let villageNnmter = 0 lastVillage.forEach(d => { - lastVillageRoadRoadIds = lastVillageRoadRoadIds.concat(d.villageRoadId) || [] - lastVillageIds = lastVillageIds.concat(d.villageId) || [] + if (villageNnmter < (100 - (countyPercentage == 75 ? 20 : 10))) { + 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 = []) { let spotRoadIds = [] let accumulationMileage = 0 + let last = null async function filterRoad (otherWhere, getRepeat = true) { @@ -671,6 +683,7 @@ async function roadSpotPrepare (ctx) { ], false) spotVillageIds.push(villageId) + last = villageId if (accumulationMileage >= targetMileage) { break; @@ -678,13 +691,27 @@ async function roadSpotPrepare (ctx) { } 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 { await filterRoad(otherWhere, true) } - return [spotRoadIds, accumulationMileage] + return [spotRoadIds, accumulationMileage, last] } let villageMil = 0, townMil = 0, countryMil = 0; @@ -723,6 +750,8 @@ async function roadSpotPrepare (ctx) { let spotVillageIds = [] let allTownCodeResTown = [] + let lastEndVillage = {} //获取每个乡镇最后一个被抽取的村 + for await (let t of allTownCodeRes) { // 遍历每个乡镇并抽取 let otherWhere = [`township_code='${t.township_code}'`] @@ -743,26 +772,36 @@ async function roadSpotPrepare (ctx) { const villageRoadNeedMileage = villageRoadTotalMileage * (countyPercentage == 75 ? 20 : 10) / 100 let spotFirstVillageId = -1 - // 随机选取一个不在上次查过的村 - let villageRes = await sequelize.query(` - SELECT id FROM village - WHERE township_code = '${t.township_code}' - ${lastVillageIds.length ? `AND id NOT IN ( - ${lastVillageIds.map(item => `'${item}'`).join(',')},-1 - )`: ''} - ORDER BY RANDOM() - LIMIT 1 - `, { type: QueryTypes.SELECT }); - if (!villageRes.length) { - // 没有村了,随机选一个 + + let villageRes = [] + if (lastAbstractVillage[t.township_code]) { + + } else { + // 随机选取一个不在上次查过的村 villageRes = await sequelize.query(` - SELECT id FROM village - WHERE township_code = '${t.township_code}' - ORDER BY RANDOM() - LIMIT 1 - `, { type: QueryTypes.SELECT }); + SELECT id FROM village + WHERE township_code = '${t.township_code}' + ${lastVillageIds.length ? `AND id NOT IN ( + ${lastVillageIds.map(item => `'${item}'`).join(',')},-1 + )`: ''} + 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) spotFirstVillageId = villageRes[0].id } else { @@ -793,6 +832,8 @@ async function roadSpotPrepare (ctx) { let spotVillageRoadIdsArr = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList) let spotVillageRoadIds_ = spotVillageRoadIdsArr[0] let villageMil_ = spotVillageRoadIdsArr[1] + lastEndVillage[t.township_code] = spotVillageRoadIdsArr[2] + spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) if (villageMil_) villageMil += villageMil_ @@ -808,6 +849,8 @@ async function roadSpotPrepare (ctx) { villageDifferenceValue: villageMil_ - villageRoadNeedMileage }) + + } for (let index = 0; index < town.length; index++) { @@ -846,7 +889,8 @@ async function roadSpotPrepare (ctx) { villageMil, townMil, countryMil, - gather + gather, + lastAbstractVillage: lastEndVillage }) diff --git a/api/app/lib/models/road_spot_check_preview.js b/api/app/lib/models/road_spot_check_preview.js index 43438889..553f305c 100644 --- a/api/app/lib/models/road_spot_check_preview.js +++ b/api/app/lib/models/road_spot_check_preview.js @@ -114,6 +114,15 @@ module.exports = dc => { field: "gather", autoIncrement: false }, + lastAbstractVillage:{ + type: DataTypes.JSONB, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "last_abstract_village", + autoIncrement: false + } }, { tableName: "road_spot_check_preview", comment: "", diff --git a/scripts/1.4.0/data/2_update_road_data_无需执行/no_exist_village.txt b/scripts/1.4.0/data/2_update_road_data_无需执行/no_exist_village.txt index c214fb3c0d198ab4e85701a3619ce3fd5f323c45..41acf02d4880c99806e3a88f399c6c272aedca3a 100644 GIT binary patch literal 62 zcmaDlzv=0cEzjmo)P1pV`jZ`9Ko-~2MJt|e+=wdnY}y8(01!Q$)bng>^Rr#6Kq>(g C)F|Nq literal 4158 zcmeH|`8U+>8^+&+QX*s-gqA_}Z6=0j5E;f!NzII5h@miJ-?KH1&{#t;C=rn;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sf>=%f&L{%-Zu4KdOfKmV?mBu6aV+dNaR*QgnughPOUSsr(I$ zRjC5ZeJSRt&u5MI8T}K@lrvE!*Gg+Qn`Kq;I9ah)jvmRntHlxA zA5e%An0fR#7j)J$uzja|obOySA4Q|HvLg<1$30`%)2&z6Bebj}6Q4+t3D}-#X31lR zGJOouC-aTud{U5`{=(MBa*fDt(_V>j+hZc;x`DI_wN6^eL4Bw&{!AU|+6A`!q$lOp zJdv)J?rPHjJ|{yBnRvJ2-`k~A zHrK<1b8;fwb0Xp#y!<_gj9CosywxUSd4$nd>y1JAv+Q=_*u~yw_q^)2_mx(5W(K8R qm2|m|#nY#$lR1u2)=#AQ<#{K5?k+q!@zrn#-yvJ5S@j{YqUS%lpVAlr diff --git a/scripts/1.4.2/5.alter_road_spot_check_preview.sql b/scripts/1.4.2/5.alter_road_spot_check_preview.sql new file mode 100644 index 00000000..016e4fcd --- /dev/null +++ b/scripts/1.4.2/5.alter_road_spot_check_preview.sql @@ -0,0 +1,5 @@ +alter table road_spot_check_preview + add last_abstract_village jsonb; + +comment on column road_spot_check_preview.last_abstract_village is '每个乡上次抽查的最后一个村'; + diff --git a/web/client/src/components/README.txt b/web/client/src/components/README.txt index 1035e6175eab5b2bd1ed0d9aa14fa326b9afbe26..cff16c829918e0e41670d0bb51959eb5a2a4e0c3 100644 GIT binary patch literal 52 hcmaFAfA9PKdynitvTz4FE~?DPjNs literal 4148 zcmeH|`8(8o7stN{SyPrMYD9*SC8j$@ZrMgGw7$u6V@Wz8;=wXtUjN$yc@ z`yjU^A~HO7S;CF1G0%AZfafppd0(G%o%25DT%YTD{qg|-8(=Or61R%#_2H77as=C-j(6V$*|R_-Gq~$&foQ zBbfXI+m7A!PsK#|54p$M_mW*-@-lW}W#f>Jr>r=9Sr~TA*Yp5=zzi@1(10<30u-2; zApixCfCnNncRsWIapz;$NS2jKs6j(u&WcRZ!Slro^m?B8Tcky+hf>bO>C zZrTAS=Y+rsffE8J1WpK?5I7<5{|T_M?a0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