Browse Source

村抽查修改

dev
wenlele 10 months ago
parent
commit
36b4b24114
  1. 2
      api/.vscode/launch.json
  2. 96
      api/app/lib/controllers/report/index.js
  3. 9
      api/app/lib/models/road_spot_check_preview.js
  4. BIN
      scripts/1.4.0/data/2_update_road_data_无需执行/no_exist_village.txt
  5. 5
      scripts/1.4.2/5.alter_road_spot_check_preview.sql
  6. BIN
      web/client/src/components/README.txt

2
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",

96
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
})

9
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: "",

BIN
scripts/1.4.0/data/2_update_road_data_无需执行/no_exist_village.txt

Binary file not shown.

5
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 '每个乡上次抽查的最后一个村';

BIN
web/client/src/components/README.txt

Binary file not shown.
Loading…
Cancel
Save