四好公路
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.

245 lines
7.9 KiB

3 years ago
'use strict';
3 years ago
const moment = require("moment");
3 years ago
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) {
3 years ago
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',
})
3 years ago
const bridgeRes = await models.Bridge.findAll({})
3 years ago
let constructionYear = []
for (let i = 0; constructionYear.length < 4; i++) {
constructionYear.push(moment().subtract(i, 'year').format('YYYY'))
}
constructionYear.reverse()
3 years ago
const roadState = {
//总数
projectAll: projectRoadRes.length,
3 years ago
// 在建数量
buildingRoad: 0,
// 已建数量
buildedRoad: 0,
3 years ago
// 桥梁数量
3 years ago
bridgeCount: bridgeRes.length,
3 years ago
// 涵洞数量
culvertCount: 0,
// 施工统计 已建
3 years ago
construction: constructionYear.map(year => {
return {
year,
count: 0,
}
}),
// 施工统计 改建
constructionRebuild: constructionYear.map(year => {
return {
year,
count: 0,
}
}),
3 years ago
// 乡镇统计
townRoad: {
3 years ago
},
// 县乡村涵洞 个数
townCulvert: {
'县': 0,
'乡': 0,
'村': 0,
},
// 桥大小
bridgeSize: {
'大桥': 0,
'中桥': 0,
'小桥': 0,
3 years ago
},
// 类型统计
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)
3 years ago
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.constructionRebuild.find(item => item.year === rebuildYear)
3 years ago
if (corReBuildConstruction) {
corReBuildConstruction.count += Number(r.chainageMileage) || 0
}
3 years ago
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)
3 years ago
roadState.townCulvert[r.level] = (roadState.townCulvert[r.level] || 0) + (Number(r.numberOfCulverts) || 0)
3 years ago
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
}
}
3 years ago
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)
}
3 years ago
}
3 years ago
let corBuildConstruction2022 = roadState.construction.find(item => item.year == 2022)
3 years ago
for (let p of projectRoadRes) {
if (p.type == 'road') {
3 years ago
if (corBuildConstruction2022) {
corBuildConstruction2022.count += Number(p.projectMileage) || 0
}
3 years ago
if (p.done) {
roadState.buildedRoad += 1
} else {
roadState.buildingRoad += 1
}
}
if (p.buildUnit && p.done) {
3 years ago
let townName = p.buildUnit.replace('人民政府', '').replace('南昌县', '').replace('管委会', '')
if (roadState.townProject[townName]) {
roadState.townProject[townName] += 1
} else {
roadState.townProject[townName] = 1
}
if (p.type == 'road' && p.done) {
if (roadState.townRoad[townName]) {
if (roadState.townRoad[townName].roadCount) {
roadState.townRoad[townName].roadCount += 1
} else {
roadState.townRoad[townName].roadCount = roadState.townRoad[townName].roadCode.size
roadState.townRoad[townName].roadCount += 1
}
}
}
3 years ago
}
}
3 years ago
for (let { dataValues: b } of bridgeRes) {
if (roadState.bridgeSize[b.bridgeClassification] || roadState.bridgeSize[b.bridgeClassification] == 0) {
roadState.bridgeSize[b.bridgeClassification] += 1
}
}
3 years ago
roadState.buildedRoad += roadCode.size
for (let t of Object.keys(roadState.townRoad)) {
if (roadState.townRoad[t].roadCount) {
} else {
roadState.townRoad[t].roadCount = roadState.townRoad[t].roadCode.size
}
3 years ago
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,
};