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.
153 lines
4.6 KiB
153 lines
4.6 KiB
'use strict';
|
|
|
|
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 roadState = {
|
|
// 在建数量
|
|
buildingRoad: 0,
|
|
// 已建数量
|
|
buildedRoad: 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)
|
|
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
|
|
}
|
|
}
|
|
|
|
roadState.greenMileage[r.level].canBeGreen += (Number(r.greeningMileage) || 0)
|
|
roadState.greenMileage[r.level].isGreen += (Number(r.greeningMileaged) || 0)
|
|
}
|
|
for (let p of projectRoadRes) {
|
|
if (p.type == 'road') {
|
|
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,
|
|
};
|