|
@ -541,6 +541,7 @@ async function roadSpotPrepare(ctx) { |
|
|
let lastTownRoadIds = [] // 上次查得的乡镇道id
|
|
|
let lastTownRoadIds = [] // 上次查得的乡镇道id
|
|
|
let lastVillageRoadRoadIds = [] // 上次查得的村道id
|
|
|
let lastVillageRoadRoadIds = [] // 上次查得的村道id
|
|
|
let lastVillageIds = [] |
|
|
let lastVillageIds = [] |
|
|
|
|
|
let gather = [] //汇总
|
|
|
|
|
|
|
|
|
if (lastSpotRes) { |
|
|
if (lastSpotRes) { |
|
|
lastCountyPercentage = lastSpotRes.countyPercentage |
|
|
lastCountyPercentage = lastSpotRes.countyPercentage |
|
@ -591,16 +592,16 @@ async function roadSpotPrepare(ctx) { |
|
|
'乡': `route_code LIKE 'Y%'`, |
|
|
'乡': `route_code LIKE 'Y%'`, |
|
|
'村': `route_code LIKE 'C%'` |
|
|
'村': `route_code LIKE 'C%'` |
|
|
} |
|
|
} |
|
|
async function getRoadTotalMileage(key, otherWhere = []) { |
|
|
async function getRoadTotalMileage (key, otherWhere = [], spot) { |
|
|
let res = await sequelize.query(` |
|
|
let res = await sequelize.query(` |
|
|
SELECT |
|
|
SELECT |
|
|
SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage |
|
|
SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage |
|
|
FROM road |
|
|
FROM road |
|
|
WHERE del = false |
|
|
WHERE del = false |
|
|
AND spot = true |
|
|
AND spot = ${spot} |
|
|
AND ${keyMap[key]} ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''} |
|
|
AND ${keyMap[key]} ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''} |
|
|
`)
|
|
|
`)
|
|
|
return res[0][0].total_mileage |
|
|
return res[0][0].total_mileage || 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { |
|
|
async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { |
|
@ -687,13 +688,25 @@ async function roadSpotPrepare(ctx) { |
|
|
let villageMil = 0, townMil = 0, countryMil = 0; |
|
|
let villageMil = 0, townMil = 0, countryMil = 0; |
|
|
|
|
|
|
|
|
// 抽县
|
|
|
// 抽县
|
|
|
const countryRoadTotalMileage = await getRoadTotalMileage('县') |
|
|
const countryRoadTotalMileage = await getRoadTotalMileage('县', '', true) |
|
|
|
|
|
const countryRoadHide = await getRoadTotalMileage('县', '', false) |
|
|
const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100 |
|
|
const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100 |
|
|
let spotCountyRoadIdsArr = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, []) |
|
|
let spotCountyRoadIdsArr = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, []) |
|
|
let spotCountyRoadIds = spotCountyRoadIdsArr[0] |
|
|
let spotCountyRoadIds = spotCountyRoadIdsArr[0] |
|
|
let countryMil_ = spotCountyRoadIdsArr[1] |
|
|
let countryMil_ = spotCountyRoadIdsArr[1] || 0 |
|
|
if (countryMil_) countryMil += countryMil_; |
|
|
if (countryMil_) countryMil += countryMil_; |
|
|
|
|
|
|
|
|
|
|
|
gather.push({ |
|
|
|
|
|
name: '南昌县交通运输局', |
|
|
|
|
|
county: countryRoadTotalMileage + countryRoadHide, |
|
|
|
|
|
countyParticipate: countryRoadTotalMileage, |
|
|
|
|
|
countyPresent: countryMil_, |
|
|
|
|
|
countyDifferenceValue: countryMil_ - countryRoadNeedMileage |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
let town = await models.Town.findAll() || [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 抽乡
|
|
|
// 抽乡
|
|
|
const allTownCodeRes = await sequelize.query(` |
|
|
const allTownCodeRes = await sequelize.query(` |
|
|
SELECT |
|
|
SELECT |
|
@ -708,10 +721,12 @@ async function roadSpotPrepare(ctx) { |
|
|
let spotVillageRoadIds = [] |
|
|
let spotVillageRoadIds = [] |
|
|
let spotVillageIds = [] |
|
|
let spotVillageIds = [] |
|
|
|
|
|
|
|
|
|
|
|
let allTownCodeResTown = [] |
|
|
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}'`] |
|
|
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere) |
|
|
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere, true) |
|
|
|
|
|
const townRoadHide = await getRoadTotalMileage('乡', otherWhere, false) |
|
|
const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 |
|
|
const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 |
|
|
|
|
|
|
|
|
let spotTownRoadIdsArr = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) |
|
|
let spotTownRoadIdsArr = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) |
|
@ -719,8 +734,11 @@ async function roadSpotPrepare(ctx) { |
|
|
let townMil_ = spotTownRoadIdsArr[1] |
|
|
let townMil_ = spotTownRoadIdsArr[1] |
|
|
spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_) |
|
|
spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_) |
|
|
if (townMil_) townMil += townMil_ |
|
|
if (townMil_) townMil += townMil_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 抽村
|
|
|
// 抽村
|
|
|
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere) |
|
|
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere, true) |
|
|
|
|
|
const villageRoadTotalHide = await getRoadTotalMileage('村', otherWhere, false) |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 |
|
|
|
|
|
|
|
|
let spotFirstVillageId = -1 |
|
|
let spotFirstVillageId = -1 |
|
@ -747,6 +765,17 @@ async function roadSpotPrepare(ctx) { |
|
|
spotVillageIds.push(villageRes[0].id) |
|
|
spotVillageIds.push(villageRes[0].id) |
|
|
spotFirstVillageId = villageRes[0].id |
|
|
spotFirstVillageId = villageRes[0].id |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
allTownCodeResTown.push({ |
|
|
|
|
|
code: t.township_code, |
|
|
|
|
|
township: townRoadTotalMileage + townRoadHide, |
|
|
|
|
|
townshipParticipate: townRoadTotalMileage, |
|
|
|
|
|
townshipPresent: townMil_, |
|
|
|
|
|
townshipDifferenceValue: townMil_ - townRoadNeedMileage, |
|
|
|
|
|
village: villageRoadTotalMileage + villageRoadTotalHide, |
|
|
|
|
|
villageParticipate: villageRoadTotalMileage, |
|
|
|
|
|
villagePresent: 0, |
|
|
|
|
|
villageDifferenceValue: 0 |
|
|
|
|
|
}) |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -765,8 +794,35 @@ async function roadSpotPrepare(ctx) { |
|
|
let villageMil_ = spotVillageRoadIdsArr[1] |
|
|
let villageMil_ = spotVillageRoadIdsArr[1] |
|
|
spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) |
|
|
spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) |
|
|
if (villageMil_) villageMil += villageMil_ |
|
|
if (villageMil_) villageMil += villageMil_ |
|
|
|
|
|
|
|
|
|
|
|
allTownCodeResTown.push({ |
|
|
|
|
|
code: t.township_code, |
|
|
|
|
|
township: townRoadTotalMileage + townRoadHide, |
|
|
|
|
|
townshipParticipate: townRoadTotalMileage, |
|
|
|
|
|
townshipPresent: townMil_, |
|
|
|
|
|
townshipDifferenceValue: townMil_ - townRoadNeedMileage, |
|
|
|
|
|
village: villageRoadTotalMileage + villageRoadTotalHide, |
|
|
|
|
|
villageParticipate: villageRoadTotalMileage, |
|
|
|
|
|
villagePresent: villageMil_, |
|
|
|
|
|
villageDifferenceValue: villageMil_ - villageRoadNeedMileage |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
town.forEach(async d => { |
|
|
|
|
|
if (allTownCodeResTown.find(c => c.code == d.code)) { |
|
|
|
|
|
gather.push({ ...(allTownCodeResTown.find(c => c.code == d.code) || {}), name: d.name }) |
|
|
|
|
|
} else { |
|
|
|
|
|
gather.push({ |
|
|
|
|
|
name: d.name, |
|
|
|
|
|
township: await getRoadTotalMileage('乡', [`township_code='${d.code}'`], false), |
|
|
|
|
|
village: await getRoadTotalMileage('村', [`township_code='${d.code}'`], false), |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const previewRes = await models.RoadSpotCheckPreview.create({ |
|
|
const previewRes = await models.RoadSpotCheckPreview.create({ |
|
|
countyPercentage: countyPercentage, |
|
|
countyPercentage: countyPercentage, |
|
|
date: moment().format(), |
|
|
date: moment().format(), |
|
@ -777,9 +833,12 @@ async function roadSpotPrepare(ctx) { |
|
|
checked: false, |
|
|
checked: false, |
|
|
villageMil, |
|
|
villageMil, |
|
|
townMil, |
|
|
townMil, |
|
|
countryMil |
|
|
countryMil, |
|
|
|
|
|
gather |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
ctx.status = 200; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
previewId: previewRes.id, |
|
|
previewId: previewRes.id, |
|
@ -1194,7 +1253,8 @@ async function exportSpotRode (ctx) { |
|
|
|
|
|
|
|
|
const fileName = `${moment(previewRes.date).format('YYYY年MM月DD日HH时mm分')}道路抽查记录` + '.csv' |
|
|
const fileName = `${moment(previewRes.date).format('YYYY年MM月DD日HH时mm分')}道路抽查记录` + '.csv' |
|
|
const filePath = await xlsxDownload.simpleExcelDown({ |
|
|
const filePath = await xlsxDownload.simpleExcelDown({ |
|
|
data: exportData, header, fileName: fileName, gather:{data: exportData, header} |
|
|
// data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] }
|
|
|
|
|
|
data: exportData, header, fileName: fileName, |
|
|
}) |
|
|
}) |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
|
|
|
|
|