|
@ -4,7 +4,7 @@ const moment = require('moment'); |
|
|
const xlsxDownload = require('../../../../utils/xlsxDownload.js'); |
|
|
const xlsxDownload = require('../../../../utils/xlsxDownload.js'); |
|
|
const fs = require('fs'); |
|
|
const fs = require('fs'); |
|
|
const data = require('../../routes/data/index.js'); |
|
|
const data = require('../../routes/data/index.js'); |
|
|
async function reportList(ctx) { |
|
|
async function reportList (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType, handleState = '', performerId = '', codeRoad } = ctx.query |
|
|
const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType, handleState = '', performerId = '', codeRoad } = ctx.query |
|
@ -150,7 +150,7 @@ async function reportList(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function reportPosition(ctx) { |
|
|
async function reportPosition (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { startTime, endTime, userId, reportType } = ctx.query |
|
|
const { startTime, endTime, userId, reportType } = ctx.query |
|
@ -200,7 +200,7 @@ async function reportPosition(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function reportDetail(ctx) { |
|
|
async function reportDetail (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { reportId } = ctx.params |
|
|
const { reportId } = ctx.params |
|
@ -229,7 +229,7 @@ async function reportDetail(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function reportHandle(ctx) { |
|
|
async function reportHandle (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
|
|
|
|
|
@ -259,7 +259,7 @@ async function reportHandle(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function createReport(ctx) { |
|
|
async function createReport (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { userId } = ctx.fs.api |
|
|
const { userId } = ctx.fs.api |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
@ -281,7 +281,7 @@ async function createReport(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function deleteReport(ctx) { |
|
|
async function deleteReport (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { reportId } = ctx.params; |
|
|
const { reportId } = ctx.params; |
|
@ -303,7 +303,7 @@ async function deleteReport(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回
|
|
|
// TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回
|
|
|
async function spotPrepare(ctx) { |
|
|
async function spotPrepare (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const sequelize = ctx.fs.dc.orm; |
|
|
const sequelize = ctx.fs.dc.orm; |
|
@ -375,7 +375,7 @@ async function spotPrepare(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function spotCheck(ctx) { |
|
|
async function spotCheck (ctx) { |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
@ -477,7 +477,7 @@ async function spotCheck(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
async function spotCheckDetail(ctx) { |
|
|
async function spotCheckDetail (ctx) { |
|
|
const { models } = ctx.fs.dc |
|
|
const { models } = ctx.fs.dc |
|
|
const { startTime, endTime } = ctx.query |
|
|
const { startTime, endTime } = ctx.query |
|
|
try { |
|
|
try { |
|
@ -516,7 +516,7 @@ async function spotCheckDetail(ctx) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function roadSpotPrepare(ctx) { |
|
|
async function roadSpotPrepare (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const sequelize = ctx.fs.dc.orm; |
|
|
const sequelize = ctx.fs.dc.orm; |
|
@ -593,7 +593,7 @@ 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 = [], spot) { |
|
|
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 |
|
@ -605,7 +605,7 @@ async function roadSpotPrepare(ctx) { |
|
|
return res[0][0].total_mileage || 0 |
|
|
return res[0][0].total_mileage || 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function getRoadSpot(key, lastRoadIds = [], inOrNot, otherWhere = []) { |
|
|
async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { |
|
|
if (!lastRoadIds.length && !inOrNot) { |
|
|
if (!lastRoadIds.length && !inOrNot) { |
|
|
return [] |
|
|
return [] |
|
|
} |
|
|
} |
|
@ -624,11 +624,11 @@ async function roadSpotPrepare(ctx) { |
|
|
`, { type: QueryTypes.SELECT });
|
|
|
`, { type: QueryTypes.SELECT });
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function spotRoadId(key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { |
|
|
async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { |
|
|
let spotRoadIds = [] |
|
|
let spotRoadIds = [] |
|
|
let accumulationMileage = 0 |
|
|
let accumulationMileage = 0 |
|
|
|
|
|
|
|
|
async function filterRoad(otherWhere, getRepeat = true) { |
|
|
async function filterRoad (otherWhere, getRepeat = true) { |
|
|
|
|
|
|
|
|
if (key == '村' && getRepeat == true) { |
|
|
if (key == '村' && getRepeat == true) { |
|
|
|
|
|
|
|
@ -728,7 +728,7 @@ async function roadSpotPrepare(ctx) { |
|
|
let otherWhere = [`township_code='${t.township_code}'`] |
|
|
let otherWhere = [`township_code='${t.township_code}'`] |
|
|
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere, true) |
|
|
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere, true) |
|
|
const townRoadHide = await getRoadTotalMileage('乡', otherWhere, false) |
|
|
const townRoadHide = await getRoadTotalMileage('乡', otherWhere, false) |
|
|
const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 |
|
|
const townRoadNeedMileage = townRoadTotalMileage * (countyPercentage == 75 ? 50 : 25) / 100 |
|
|
|
|
|
|
|
|
let spotTownRoadIdsArr = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) |
|
|
let spotTownRoadIdsArr = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) |
|
|
let spotTownRoadIds_ = spotTownRoadIdsArr[0] |
|
|
let spotTownRoadIds_ = spotTownRoadIdsArr[0] |
|
@ -740,7 +740,7 @@ async function roadSpotPrepare(ctx) { |
|
|
// 抽村
|
|
|
// 抽村
|
|
|
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere, true) |
|
|
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere, true) |
|
|
const villageRoadTotalHide = await getRoadTotalMileage('村', otherWhere, false) |
|
|
const villageRoadTotalHide = await getRoadTotalMileage('村', otherWhere, false) |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 |
|
|
const villageRoadNeedMileage = villageRoadTotalMileage * (countyPercentage == 75 ? 20 : 10) / 100 |
|
|
|
|
|
|
|
|
let spotFirstVillageId = -1 |
|
|
let spotFirstVillageId = -1 |
|
|
// 随机选取一个不在上次查过的村
|
|
|
// 随机选取一个不在上次查过的村
|
|
@ -860,7 +860,7 @@ async function roadSpotPrepare(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function confirmRoadSpot(ctx) { |
|
|
async function confirmRoadSpot (ctx) { |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
@ -920,7 +920,7 @@ async function confirmRoadSpot(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function roadSpotList(ctx) { |
|
|
async function roadSpotList (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { startTime, endTime, page, limit } = ctx.query |
|
|
const { startTime, endTime, page, limit } = ctx.query |
|
@ -974,7 +974,7 @@ async function roadSpotList(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function roadSpotDetail(ctx) { |
|
|
async function roadSpotDetail (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { previewId, keyword } = ctx.query |
|
|
const { previewId, keyword } = ctx.query |
|
@ -1011,7 +1011,7 @@ async function roadSpotDetail(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function roadSpotChange(ctx) { |
|
|
async function roadSpotChange (ctx) { |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
@ -1033,7 +1033,7 @@ async function roadSpotChange(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let previewUpdated = false |
|
|
let previewUpdated = false |
|
|
async function updatePreview(key) { |
|
|
async function updatePreview (key) { |
|
|
if (previewUpdated) return |
|
|
if (previewUpdated) return |
|
|
|
|
|
|
|
|
if (previewRes[key] && previewRes[key].includes(originRoadId)) { |
|
|
if (previewRes[key] && previewRes[key].includes(originRoadId)) { |
|
@ -1077,12 +1077,39 @@ async function roadSpotChange(ctx) { |
|
|
let curChangeRoad = roadRes.find(item => item.id == changeRoadId) |
|
|
let curChangeRoad = roadRes.find(item => item.id == changeRoadId) |
|
|
const level = curChangeRoad.level; |
|
|
const level = curChangeRoad.level; |
|
|
let milData = {} |
|
|
let milData = {} |
|
|
|
|
|
let differenceValue = (parseFloat(curChangeRoad.chainageMileage) - parseFloat(curOriginRoad.chainageMileage)) || 0 |
|
|
if (level == '县') { |
|
|
if (level == '县') { |
|
|
milData = { countryMil: previewRes.countryMil + parseFloat(curChangeRoad.chainageMileage) - parseFloat(curOriginRoad.chainageMileage) } |
|
|
previewRes.gather && previewRes.gather.forEach(d => { |
|
|
|
|
|
if (!d.code) { |
|
|
|
|
|
d.countyPresent = d.countyPresent + differenceValue |
|
|
|
|
|
d.countyDifferenceValue = d.countyDifferenceValue + differenceValue |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
milData = { countryMil: previewRes.countryMil + differenceValue, gather: previewRes.gather } |
|
|
} else if (level == '乡') { |
|
|
} else if (level == '乡') { |
|
|
milData = { townMil: previewRes.townMil + parseFloat(curChangeRoad.chainageMileage) - parseFloat(curOriginRoad.chainageMileage) } |
|
|
previewRes.gather && previewRes.gather.forEach(d => { |
|
|
|
|
|
if (d.code == curOriginRoad.townshipCode) { |
|
|
|
|
|
d.townshipPresent = d.townshipPresent - parseFloat(curOriginRoad.chainageMileage) |
|
|
|
|
|
d.townshipDifferenceValue = d.townshipDifferenceValue - parseFloat(curOriginRoad.chainageMileage) |
|
|
|
|
|
} |
|
|
|
|
|
if (d.code == curOriginRoad.curChangeRoad) { |
|
|
|
|
|
d.villagePresent = d.villagePresent + parseFloat(curChangeRoad.chainageMileage) |
|
|
|
|
|
d.townshipDifferenceValue = d.townshipDifferenceValue + parseFloat(curChangeRoad.chainageMileage) |
|
|
|
|
|
} |
|
|
|
|
|
}) || [] |
|
|
|
|
|
milData = { townMil: previewRes.townMil + differenceValue, gather: previewRes.gather } |
|
|
} else if (level == '村') { |
|
|
} else if (level == '村') { |
|
|
milData = { villageMil: previewRes.villageMil + parseFloat(curChangeRoad.chainageMileage) - parseFloat(curOriginRoad.chainageMileage) } |
|
|
previewRes.gather && previewRes.gather.forEach(d => { |
|
|
|
|
|
if (d.code == curOriginRoad.townshipCode) { |
|
|
|
|
|
d.villageParticipate = d.villageParticipate - parseFloat(curOriginRoad.chainageMileage) |
|
|
|
|
|
d.villageDifferenceValue = d.villageDifferenceValue - parseFloat(curOriginRoad.chainageMileage) |
|
|
|
|
|
} |
|
|
|
|
|
if (d.code == curOriginRoad.curChangeRoad) { |
|
|
|
|
|
d.villageParticipate = d.villageParticipate + parseFloat(curChangeRoad.chainageMileage) |
|
|
|
|
|
d.villageDifferenceValue = d.villageDifferenceValue + parseFloat(curChangeRoad.chainageMileage) |
|
|
|
|
|
} |
|
|
|
|
|
}) || [] |
|
|
|
|
|
milData = { villageMil: previewRes.villageMil + differenceValue, gather: previewRes.gather } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await models.RoadSpotCheckPreview.update({ |
|
|
await models.RoadSpotCheckPreview.update({ |
|
@ -1136,7 +1163,7 @@ async function roadSpotChange(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function roadSpotChangList(ctx) { |
|
|
async function roadSpotChangList (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { startTime, endTime, page, limit } = ctx.query |
|
|
const { startTime, endTime, page, limit } = ctx.query |
|
@ -1189,7 +1216,7 @@ async function roadSpotChangList(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function exportSpotRode(ctx) { |
|
|
async function exportSpotRode (ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { previewId } = ctx.query |
|
|
const { previewId } = ctx.query |
|
@ -1276,21 +1303,21 @@ async function exportSpotRode(ctx) { |
|
|
villageId: (village.find(d => road.villageId == d.id) || {}).name || '--', |
|
|
villageId: (village.find(d => road.villageId == d.id) || {}).name || '--', |
|
|
routeName: road.routeName, |
|
|
routeName: road.routeName, |
|
|
routeCode: road.routeCode, |
|
|
routeCode: road.routeCode, |
|
|
startStation: road.startStation, |
|
|
startStation: road.startStation || 0, |
|
|
stopStation: road.stopStation, |
|
|
stopStation: road.stopStation || 0, |
|
|
technicalLevel: road.technicalLevel, |
|
|
technicalLevel: road.technicalLevel, |
|
|
pavementType: road.pavementType, |
|
|
pavementType: road.pavementType, |
|
|
pavementWidth: road.pavementWidth, |
|
|
pavementWidth: road.pavementWidth || 0, |
|
|
subgradeWidth: road.subgradeWidth, |
|
|
subgradeWidth: road.subgradeWidth || 0, |
|
|
chainageMileage: road.chainageMileage, |
|
|
chainageMileage: road.chainageMileage || 0, |
|
|
maintenanceCount: item.maintenanceCount, |
|
|
maintenanceCount: item.maintenanceCount, |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
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 |
|
|
// data: exportData, header, fileName: fileName
|
|
|
// data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] }
|
|
|
data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] } |
|
|
}) |
|
|
}) |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
|
|
|
|
|