You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
6.3 KiB
200 lines
6.3 KiB
'use strict';
|
|
|
|
const moment = require("moment");
|
|
|
|
const areaCode = {
|
|
"360121100000": "莲塘镇",
|
|
"360121101000": "向塘镇",
|
|
"360121102000": "三江镇",
|
|
"360121103000": "塘南镇",
|
|
"360121104000": "幽兰镇",
|
|
"360121105000": "蒋巷镇",
|
|
"360121106000": "武阳镇",
|
|
"360121107000": "冈上镇",
|
|
"360121108000": "广福镇",
|
|
"360121191000": "昌东镇",
|
|
"360121192000": "麻丘镇",
|
|
"360121200000": "泾口乡",
|
|
"360121201000": "南新乡",
|
|
"360121202000": "塔城乡",
|
|
"360121203000": "黄马乡",
|
|
"360121204000": "富山乡",
|
|
"360121205000": "东新乡",
|
|
"360121206000": "八一乡",
|
|
"360121403000": "小蓝经济开发区",
|
|
"360121471000": "银三角管理委员会",
|
|
"360121501000": "五星垦殖场",
|
|
"360121572000": "良种繁殖场",
|
|
}
|
|
|
|
async function roadState (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const { userId } = ctx.fs.api;
|
|
|
|
const roadRes = await models.Road.findAll({})
|
|
const projectRoadRes = await models.Project.findAll({
|
|
type: 'road',
|
|
})
|
|
|
|
const bridgeCount = await models.Bridge.count({})
|
|
|
|
let constructionYear = []
|
|
for (let i = 0; constructionYear.length < 4; i++) {
|
|
constructionYear.push(moment().subtract(i, 'year').format('YYYY'))
|
|
}
|
|
constructionYear.reverse()
|
|
|
|
const roadState = {
|
|
// 在建数量
|
|
buildingRoad: 0,
|
|
// 已建数量
|
|
buildedRoad: 0,
|
|
// 桥梁数量
|
|
bridgeCount: bridgeCount,
|
|
// 涵洞数量
|
|
culvertCount: 0,
|
|
// 施工统计
|
|
construction: constructionYear.map(year => {
|
|
return {
|
|
year,
|
|
count: 0,
|
|
}
|
|
}),
|
|
// 乡镇统计
|
|
townRoad: {
|
|
|
|
},
|
|
// 类型统计
|
|
roadType: {
|
|
'县': 0,
|
|
'乡': 0,
|
|
'村': 0,
|
|
},
|
|
// 在建项目统计
|
|
townProject: {
|
|
|
|
},
|
|
// 等级统计
|
|
roadLevel: {
|
|
|
|
},
|
|
// 养护周期
|
|
curingPeriod: {
|
|
frequent: 0,
|
|
season: 0,
|
|
},
|
|
// 绿化里程
|
|
greenMileage: {
|
|
'县': {
|
|
canBeGreen: 0,
|
|
isGreen: 0,
|
|
},
|
|
'乡': {
|
|
canBeGreen: 0,
|
|
isGreen: 0,
|
|
},
|
|
'村': {
|
|
canBeGreen: 0,
|
|
isGreen: 0,
|
|
},
|
|
}
|
|
}
|
|
|
|
let roadCode = new Set()
|
|
|
|
for (let r of roadRes) {
|
|
roadCode.add(r.routeCode)
|
|
|
|
roadState.culvertCount += Number(r.numberOfCulverts) || 0;
|
|
|
|
// 建成年份
|
|
let buildYear = r.completionTime ? moment(r.completionTime).format('YYYY') : null
|
|
// 改建年份
|
|
let rebuildYear = r.reconstructionTime ? moment(r.reconstructionTime).format('YYYY') : null
|
|
let corBuildConstruction = roadState.construction.find(item => item.year === buildYear)
|
|
if (corBuildConstruction) {
|
|
corBuildConstruction.count += Number(r.chainageMileage) || 0
|
|
}
|
|
let corReBuildConstruction = roadState.construction.find(item => item.year === rebuildYear)
|
|
if (corReBuildConstruction) {
|
|
corReBuildConstruction.count += Number(r.chainageMileage) || 0
|
|
}
|
|
|
|
let townName = areaCode[r.townshipCode] || '其他'
|
|
if (roadState.townRoad[townName]) {
|
|
roadState.townRoad[townName].roadCode.add(r.routeCode)
|
|
roadState.townRoad[townName].mileage += Number(r.chainageMileage) || 0
|
|
} else {
|
|
roadState.townRoad[townName] = {
|
|
roadCode: new Set([r.routeCode]),
|
|
mileage: Number(r.chainageMileage) || 0,
|
|
}
|
|
}
|
|
|
|
roadState.roadType[r.level] = (roadState.roadType[r.level] || 0) + (Number(r.chainageMileage) || 0)
|
|
|
|
if (roadState.roadLevel[r.technicalLevel]) {
|
|
roadState.roadLevel[r.technicalLevel] += 1
|
|
} else {
|
|
roadState.roadLevel[r.technicalLevel] = 1
|
|
}
|
|
|
|
if (r.curingTime) {
|
|
if (r.curingTime.indexOf('经常') > -1) {
|
|
roadState.curingPeriod.frequent += 1
|
|
} else if (r.curingTime.indexOf('季节') > -1) {
|
|
roadState.curingPeriod.season += 1
|
|
}
|
|
}
|
|
|
|
if (r.level && roadState.greenMileage[r.level]) {
|
|
roadState.greenMileage[r.level].canBeGreen += (Number(r.greeningMileage) || 0)
|
|
roadState.greenMileage[r.level].isGreen += (Number(r.greeningMileaged) || 0)
|
|
}
|
|
}
|
|
|
|
let corBuildConstruction2022 = roadState.construction.find(item => item.year == 2022)
|
|
|
|
for (let p of projectRoadRes) {
|
|
if (p.type == 'road') {
|
|
|
|
if (corBuildConstruction2022) {
|
|
corBuildConstruction2022.count += Number(p.projectMileage) || 0
|
|
}
|
|
|
|
if (p.done) {
|
|
roadState.buildedRoad += 1
|
|
} else {
|
|
roadState.buildingRoad += 1
|
|
}
|
|
}
|
|
|
|
let townName = p.buildUnit.replace('人民政府', '').replace('南昌县', '').replace('管委会', '')
|
|
if (roadState.townProject[townName]) {
|
|
roadState.townProject[townName] += 1
|
|
} else {
|
|
roadState.townProject[townName] = 1
|
|
}
|
|
}
|
|
|
|
roadState.buildedRoad += roadCode.size
|
|
for (let t of Object.keys(roadState.townRoad)) {
|
|
roadState.townRoad[t].roadCount = roadState.townRoad[t].roadCode.size
|
|
delete roadState.townRoad[t].roadCode
|
|
}
|
|
|
|
ctx.status = 200
|
|
ctx.body = roadState
|
|
} catch (error) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error == 'string' ? error : undefined
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
roadState,
|
|
};
|