Compare commits

...

2 Commits

  1. 287
      api/app/lib/controllers/report/index.js
  2. 4
      api/app/lib/routes/report/index.js
  3. 52
      api/utils/xlsxDownload.js
  4. 12
      web/client/src/sections/fillion/actions/spotCheck.js
  5. 8
      web/client/src/sections/fillion/components/spotCheck.js
  6. 58
      web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js

287
api/app/lib/controllers/report/index.js

@ -1297,6 +1297,13 @@ async function roadSpotPrepare (ctx) {
const sequelize = ctx.fs.dc.orm;
const { countyPercentage, drawPeople, level, code } = ctx.request.body;
//获取最新的一次
const lastSpotRes = await models.RoadSpotCheckPreview.findOne({
where: {
checked: true
},
order: [['date', 'DESC']],
})
// 先查上次没查的范围内的 然后比较百分比 如果重叠 再查上次查过的
@ -1318,9 +1325,9 @@ async function roadSpotPrepare (ctx) {
}
async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) {
if (!lastRoadIds.length && !inOrNot) {
return []
}
// if (!lastRoadIds.length && !inOrNot) {
// return []
// }
return await sequelize.query(`
SELECT id, chainage_mileage,route_code FROM road
WHERE del = false
@ -1342,131 +1349,92 @@ async function roadSpotPrepare (ctx) {
let last = null
let spotVillageIds = []
async function filterRoad (otherWhere, getRepeat = true) {
//县道乡道随机抽取
async function extractRandomElement (arr) {
if (!arr.length || accumulationMileage >= targetMileage) {
return
}
const index = Math.floor(Math.random() * arr.length);
const extracted = arr.splice(index, 1)[0];
if (key == '村' && getRepeat == true) {
spotRoadIds.push(extracted.id)
accumulationMileage += parseFloat(extracted.chainage_mileage)
if (accumulationMileage >= targetMileage) {
return
} else {
let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, otherWhere)
if (key == '乡') {
if (code == '360121201000') {
let townY002 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y002') != -1)
if (townY002[0] && !spotRoadIds.length) {
spotRoadIds.push(townY002[0].id)
accumulationMileage += parseFloat(townY002[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY002[1] && !spotRoadIds.length) {
spotRoadIds.push(townY002[1].id)
accumulationMileage += parseFloat(townY002[1].chainage_mileage)
}
}
roadUnSpotedRes = roadUnSpotedRes.filter(d => !(d.route_code.indexOf('Y002') != -1))
}
if (code == '360121105000') {
let townY031 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y031') != -1)
let townY032 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y032') != -1)
if (townY031[0] && !spotRoadIds.length) {
spotRoadIds.push(townY031[0].id)
accumulationMileage += parseFloat(townY031[0].chainage_mileage)
}
if (townY032[0] && !spotRoadIds.length) {
spotRoadIds.push(townY032[0].id)
accumulationMileage += parseFloat(townY032[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY031[1] && !spotRoadIds.length) {
spotRoadIds.push(townY031[1].id)
accumulationMileage += parseFloat(townY031[1].chainage_mileage)
}
if (townY032[1] && !spotRoadIds.length) {
spotRoadIds.push(townY032[1].id)
accumulationMileage += parseFloat(townY032[1].chainage_mileage)
}
}
roadUnSpotedRes = roadUnSpotedRes.filter(d => !(d.route_code.indexOf('Y031') != -1) || !(d.route_code.indexOf('Y032') != -1))
return await extractRandomElement(arr)
}
}
if (key == '县') {
let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, otherWhere) || []
await extractRandomElement(roadUnSpotedRes)
if (accumulationMileage < targetMileage) {
// 还小于 说明没取够
let roadUnSpotedRepeatRes = await getRoadSpot(key, lastRoadIds, true, otherWhere)
await extractRandomElement(roadUnSpotedRepeatRes)
}
} else if (key == '乡') {
let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, otherWhere)
if (code == '360121201000') {
let townY002 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y002') != -1)
if (townY002[0]) {
spotRoadIds.push(townY002[0].id)
accumulationMileage += parseFloat(townY002[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY002[1]) {
spotRoadIds.push(townY002[1].id)
accumulationMileage += parseFloat(townY002[1].chainage_mileage)
}
}
for (let r of roadUnSpotedRes) {
if (accumulationMileage >= targetMileage) {
break;
roadUnSpotedRes = roadUnSpotedRes.filter(d => !(d.route_code.indexOf('Y002') != -1))
}
if (code == '360121105000') {
let townY031 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y031') != -1)
let townY032 = roadUnSpotedRes.filter(d => d.route_code.indexOf('Y032') != -1)
if (townY031[0]) {
spotRoadIds.push(townY031[0].id)
accumulationMileage += parseFloat(townY031[0].chainage_mileage)
}
if (townY032[0]) {
spotRoadIds.push(townY032[0].id)
accumulationMileage += parseFloat(townY032[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY031[1]) {
spotRoadIds.push(townY031[1].id)
accumulationMileage += parseFloat(townY031[1].chainage_mileage)
}
spotRoadIds.push(r.id)
accumulationMileage += parseFloat(r.chainage_mileage)
if (accumulationMileage >= targetMileage) {
break;
if (townY032[1]) {
spotRoadIds.push(townY032[1].id)
accumulationMileage += parseFloat(townY032[1].chainage_mileage)
}
}
roadUnSpotedRes = roadUnSpotedRes.filter(d => !(d.route_code.indexOf('Y031') != -1) && !(d.route_code.indexOf('Y032') != -1))
}
if (accumulationMileage < targetMileage && getRepeat) {
await extractRandomElement(roadUnSpotedRes)
if (accumulationMileage < targetMileage) {
// 还小于 说明没取够
let roadUnSpotedRepeatRes = await getRoadSpot(key, lastRoadIds, true, otherWhere)
if (key == '乡') {
if (code == '360121201000') {
let townY002 = roadUnSpotedRepeatRes.filter(d => d.route_code.indexOf('Y002') != -1)
if (townY002[0] && !spotRoadIds.length) {
spotRoadIds.push(townY002[0].id)
accumulationMileage += parseFloat(townY002[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY002[1] && !spotRoadIds.length) {
spotRoadIds.push(townY002[1].id)
accumulationMileage += parseFloat(townY002[1].chainage_mileage)
}
}
roadUnSpotedRepeatRes = roadUnSpotedRepeatRes.filter(d => !(d.route_code.indexOf('Y002') != -1))
}
if (code == '360121105000') {
let townY031 = roadUnSpotedRepeatRes.filter(d => d.route_code.indexOf('Y031') != -1)
let townY032 = roadUnSpotedRepeatRes.filter(d => d.route_code.indexOf('Y032') != -1)
if (townY031[0] && !spotRoadIds.length) {
spotRoadIds.push(townY031[0].id)
accumulationMileage += parseFloat(townY031[0].chainage_mileage)
}
if (townY032[0] && !spotRoadIds.length) {
spotRoadIds.push(townY032[0].id)
accumulationMileage += parseFloat(townY032[0].chainage_mileage)
}
if (countyPercentage == 75) {
if (townY031[1] && !spotRoadIds.length) {
spotRoadIds.push(townY031[1].id)
accumulationMileage += parseFloat(townY031[1].chainage_mileage)
}
if (townY032[1] && !spotRoadIds.length) {
spotRoadIds.push(townY032[1].id)
accumulationMileage += parseFloat(townY032[1].chainage_mileage)
}
}
roadUnSpotedRepeatRes = roadUnSpotedRepeatRes.filter(d => !(d.route_code.indexOf('Y031') != -1) || !(d.route_code.indexOf('Y032') != -1))
let roadUnSpotedRepeatRes = await getRoadSpot(key, lastRoadIds, true, [...otherWhere, `route_code not Like 'Y032%'`, `route_code not Like 'Y002%'`, `route_code not Like 'Y031%'`])
await extractRandomElement(roadUnSpotedRepeatRes)
}
}
}
} else if (key == '村') {
for (let r of roadUnSpotedRepeatRes) {
if (accumulationMileage >= targetMileage) {
break;
}
for await (let villageId of villageIdList) {
let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, [...otherWhere, `village_id=${villageId}`])
for (let r of roadUnSpotedRes) {
spotRoadIds.push(r.id)
accumulationMileage += parseFloat(r.chainage_mileage)
if (accumulationMileage >= targetMileage) {
break;
}
}
}
}
if (key == '村') {
for await (let villageId of villageIdList) {
await filterRoad([
...otherWhere,
`village_id=${villageId}`
], false)
spotVillageIds.push(villageId)
last = villageId
@ -1479,10 +1447,14 @@ async function roadSpotPrepare (ctx) {
// await filterRoad(otherWhere, true)
for await (let villageId of villageIdList.reverse()) {
await filterRoad([
...otherWhere,
`village_id=${villageId}`
], true)
let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, true, [...otherWhere, `village_id=${villageId}`])
for (let r of roadUnSpotedRes) {
spotRoadIds.push(r.id)
accumulationMileage += parseFloat(r.chainage_mileage)
if (accumulationMileage >= targetMileage) {
break;
}
}
spotVillageIds.push(villageId)
last = villageId
@ -1492,10 +1464,10 @@ async function roadSpotPrepare (ctx) {
}
}
}
} else {
await filterRoad(otherWhere, true)
}
return [spotRoadIds, accumulationMileage, last, spotVillageIds]
}
@ -1528,20 +1500,9 @@ async function roadSpotPrepare (ctx) {
//获取最新的一次
const lastSpotRes = await models.RoadSpotCheckPreview.findOne({
where: {
checked: true
},
order: [['date', 'DESC']],
})
let gather = {} //汇总
if (level == '县') {
let lastCountyRoadIds = [] // 上次查得的县道id
@ -1564,6 +1525,7 @@ async function roadSpotPrepare (ctx) {
gather.countyRoad = {
id: 'countyRoad',
name: '南昌县交通运输局',
//总里程
county: countryRoadTotalMileage + countryRoadHide,
@ -1667,7 +1629,7 @@ async function roadSpotPrepare (ctx) {
let spotVillageIds = lastSpotRes.villageId || []
let lastEndVillage = lastSpotRes.lastAbstractVillage || {} //获取每个乡镇最后一个被抽取的村
let villageMil = lastSpotRes.villageMil || 0 //已抽取的村道公里数
let allTownCodeResTown = []
@ -1715,19 +1677,6 @@ async function roadSpotPrepare (ctx) {
// spotVillageIds.push(villageRes[0].id)
spotFirstVillageId = villageRes[0].id
} else {
allTownCodeResTown.push({
code: code,
township: townRoadTotalMileage + townRoadHide,
townshipParticipate: townRoadTotalMileage,
townshipPresent: townMil_,
townshipDifferenceValue: townMil_ - townRoadNeedMileage,
village: villageRoadTotalMileage + villageRoadTotalHide,
villageParticipate: villageRoadTotalMileage,
villagePresent: 0,
villageDifferenceValue: 0
})
}
//按照与当前村距离排序获取村id
@ -1755,6 +1704,7 @@ async function roadSpotPrepare (ctx) {
let fidOne = town.find(d => d.code == code)
gather[code] = {
id: code,
name: fidOne.name,
//总里程 乡
township: townRoadTotalMileage + townRoadHide,
@ -1767,7 +1717,7 @@ async function roadSpotPrepare (ctx) {
//本次抽取的乡道id
townRoadId: spotTownRoadIds_,
//总里程 村
village: townRoadTotalMileage + townRoadHide,
village: villageRoadTotalMileage + villageRoadTotalHide,
//纳入考核里程 村
villageParticipate: villageRoadNeedMileage,
//本次考核里程 村
@ -1838,7 +1788,7 @@ async function roadSpotPrepare (ctx) {
async function exportSpotRode (ctx) {
try {
const { models } = ctx.fs.dc;
const { previewId, roadId, isgather } = ctx.query
const { previewId, roadId, isgather, code } = ctx.query
const previewRes = await models.RoadSpotCheckPreview.findOne({
where: {
@ -1904,7 +1854,11 @@ async function exportSpotRode (ctx) {
}, {
key: 'maintenanceCount',
title: '养护次数(次)',
},]
},
{
key: 'remark',
title: '备注',
}]
let exportData = listRes.map(({ dataValues: item }) => {
@ -1922,6 +1876,7 @@ async function exportSpotRode (ctx) {
subgradeWidth: road.subgradeWidth || 0,
chainageMileage: road.chainageMileage || 0,
maintenanceCount: item.maintenanceCount,
remark: true
}
})
@ -1961,11 +1916,55 @@ async function exportSpotRode (ctx) {
}
async function postRoadSpotNext (ctx) {
try {
const { models } = ctx.fs.dc;
const { previewId, level, roadId } = ctx.request.body
const previewRes = await models.RoadSpotCheckPreview.findOne({
where: {
id: previewId
}
})
let nextAbstract = previewRes && previewRes.nextAbstract || {}
if (level == '县') {
nextAbstract.county = [...(nextAbstract.county || []), roadId]
}
if (level == '乡') {
nextAbstract.town = [...(nextAbstract.town || []), roadId]
}
if (level == '村') {
nextAbstract.village = [...(nextAbstract.village || []), roadId]
}
await models.RoadSpotCheckPreview.update({
nextAbstract
}, {
where: {
id: previewId
},
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
reportList,
reportPosition,
reportDetail, createReport, deleteReport, reportHandle,
spotPrepare, spotCheck, spotCheckDetail,
roadSpotPrepare, confirmRoadSpot, roadSpotList, roadSpotDetail, roadSpotChange, roadSpotChangList, exportSpotRode,
town
town, postRoadSpotNext
};

4
api/app/lib/routes/report/index.js

@ -58,4 +58,8 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/town'] = { content: '获取乡镇', visible: false };
router.get('/town', report.town)
app.fs.api.logAttr['POST/road/spot/next'] = { content: '纳入下次抽查', visible: false };
router.post('/road/spot/next', report.postRoadSpotNext)
}

52
api/utils/xlsxDownload.js

@ -185,34 +185,40 @@ async function simpleExcelDown ({ data = [], header = [], fileName = moment().fo
indexCell.style = headerStyle
for (let h of header) {
const cell = row.addCell();
cell.value = data[i][h.key];
if (exp == 'patrol' || exp == 'maintenance') {
if (h.key == 'projectType') {
let type = data[i][h.key]
if (type == 'road') {
cell.value = '道路'
} else if (type == 'bridge') {
cell.value = '桥梁'
} else if (type == 'culvert') {
cell.value = '涵洞'
} else if (type == 'other') {
cell.value = '其他'
}
continue
if (h.key == 'remark') {
if (data[i][h.key]) {
cell.value = '回头看'
}
if (h.key == 'reportType') {
let type = data[i][h.key]
if (type == 'patrol') {
cell.value = '巡查'
} else if (type == 'conserve') {
cell.value = '养护'
} else {
cell.value = data[i][h.key];
if (exp == 'patrol' || exp == 'maintenance') {
if (h.key == 'projectType') {
let type = data[i][h.key]
if (type == 'road') {
cell.value = '道路'
} else if (type == 'bridge') {
cell.value = '桥梁'
} else if (type == 'culvert') {
cell.value = '涵洞'
} else if (type == 'other') {
cell.value = '其他'
}
continue
}
if (h.key == 'reportType') {
let type = data[i][h.key]
if (type == 'patrol') {
cell.value = '巡查'
} else if (type == 'conserve') {
cell.value = '养护'
}
continue
}
continue
}
}
cell.style = style
}
}

12
web/client/src/sections/fillion/actions/spotCheck.js

@ -99,4 +99,16 @@ export function getTown (query = {}) {
msg: { error: '获取乡镇code失败' },
reducer: { name: 'town' }
});
}
export function postRoadSpotNext (data = {}) {
return dispatch => basicAction({
type: 'post',
dispatch: dispatch,
data,
actionType: 'POST_ROAD_SPOT_NEXT',
url: 'road/spot/next',
msg: { option: '纳入下次抽查' },
reducer: { name: '' }
});
}

8
web/client/src/sections/fillion/components/spotCheck.js

@ -154,9 +154,9 @@ const SpotCheck = ({ dispatch, user, loading, reportDetail, editData, onCancel,
if (r.name == '南昌县交通运输局') {
roadId = r.countyRoadId || []
} else {
roadId = [...r.townRoadId, ...r.villageRoadId]
roadId = [...r.townRoadId, ...r.villageRoadId]
}
return <a href={`/_api/road/spot/export?token=${user?.token}&previewId=${editData.id}&roadId=${roadId.join()}`}> 导出</a>
return <a href={`/_api/road/spot/export?token=${user?.token}&code=${r.id}&previewId=${editData.id}&roadId=${roadId.join()}`}> 导出</a>
}
},
]
@ -212,7 +212,7 @@ const SpotCheck = ({ dispatch, user, loading, reportDetail, editData, onCancel,
</Form.Item>
<Form.Item >
<Button disabled={countyRoadTime} style={{}} type='primary' >
<a href={`/_api/road/spot/export?token=${user?.token}&previewId=${currentValue.id}&roadId=${currentValue?.gather && currentValue?.gather['countyRoad']?.countyRoadId?.join()}`}> 导出</a>
<a href={`/_api/road/spot/export?token=${user?.token}&previewId=${currentValue.id}&code='countyRoad'&roadId=${currentValue?.gather && currentValue?.gather['countyRoad']?.countyRoadId?.join()}`}> 导出</a>
</Button>
</Form.Item>
</div>
@ -286,7 +286,7 @@ const SpotCheck = ({ dispatch, user, loading, reportDetail, editData, onCancel,
</Form.Item>
<Form.Item >
<Button disabled={townDisabled[d.code] ? false : true} style={{}} type='primary'>
<a href={`/_api/road/spot/export?token=${user?.token}&previewId=${currentValue.id}&roadId=${currentValue?.gather
<a href={`/_api/road/spot/export?token=${user?.token}&previewId=${currentValue.id}&code=${d.code}&roadId=${currentValue?.gather
&& [...(currentValue?.gather[d.code]?.townRoadId || []), ...(currentValue?.gather[d.code]?.villageRoadId
|| [])].join()}`}> 导出</a>
</Button>

58
web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js

@ -1,9 +1,9 @@
import { connect } from 'react-redux'
import React, { useEffect, useState } from 'react'
import { Button, Modal, Form, Input, Divider, Spin, Select, DatePicker, Tooltip, Table, } from 'antd'
import { Button, Modal, Form, Input, Divider, Spin, Select, DatePicker, Tooltip, Table, Popconfirm } from 'antd'
import { ExclamationCircleOutlined } from '@ant-design/icons'
import { getVillageList } from "../actions/infor"
import { roadSpotList, roadSpotDetail, roadSpotPrepare, confirmRoadSpot, exportSpotRode, getTown } from '../actions/spotCheck'
import { roadSpotList, roadSpotDetail, roadSpotPrepare, confirmRoadSpot, exportSpotRode, getTown, postRoadSpotNext } from '../actions/spotCheck'
import moment from 'moment'
import Adjustment from '../components/adjustment'
import SpotCheck from '../components/spotCheck'
@ -106,19 +106,23 @@ const MaintenanceSpotCheck = (props) => {
},
]
const queryData = (data = {}) => {
const queryData = (data = {}, next = true) => {
dispatch(roadSpotList(data)).then(res => {
if (res.success) {
setReportData(res?.payload.data)
setKeyword("")
if (next) {
setKeyword("")
}
}
})
}
const detailData = (data = {}) => {
const detailData = (data = {}, next = true) => {
dispatch(roadSpotDetail(data)).then(res => {
if (res.success) {
setInnerPage(1)
if (next) {
setInnerPage(1)
}
setDetailList(res?.payload.data)
}
})
@ -260,16 +264,40 @@ const MaintenanceSpotCheck = (props) => {
{
title: '操作',
key: 'action',
width: 210,
dataIndex: 'action',
render: (_, r, index) => <Button disabled={(reportData[0]?.id == record?.id && !r.roadSpotCheckPreview?.roadSpotCheckChangeLogs?.some(s => s.changeRoadId == r.roadId)) ? false : true} type="link" onClick={() => {
setEditData({
...r, alterId: r?.road?.level == '县' ? record?.countyRoadId
: r?.road?.level == '乡' ? record?.townshipRoadId
: r?.road?.level == '村' ? record?.villageId : [],
previewId: record?.id
})
setIsAdjustment(true)
}}> 调整 </Button >
render: (_, r, index) => <>
<Popconfirm
title="是否确认纳入下次抽查?"
onConfirm={() => {
dispatch(postRoadSpotNext({ previewId: record?.id, level: r.road?.level, roadId: r.roadId })).then(async res => {
if (res.success) {
queryData({ startTime: dateRange[0], endTime: dateRange[1] }, false)
detailData({ previewId: record?.id, keyword: keyword }, false)
}
})
}}
okText="确认"
cancelText="取消"
>
<Button disabled={(reportData[0]?.id == record?.id && (
!record?.nextAbstract?.town?.includes(r.roadId)
&& !record?.nextAbstract?.village?.includes(r.roadId)
&& !record?.nextAbstract?.county?.includes(r.roadId))) ? false : true}
type="link"
> 纳入下次抽查 </Button >
</Popconfirm>
<Button disabled={(reportData[0]?.id == record?.id && !r.roadSpotCheckPreview?.roadSpotCheckChangeLogs?.some(s => s.changeRoadId == r.roadId)) ? false : true} type="link" onClick={() => {
setEditData({
...r, alterId: r?.road?.level == '县' ? record?.countyRoadId
: r?.road?.level == '乡' ? record?.townshipRoadId
: r?.road?.level == '村' ? record?.villageId : [],
previewId: record?.id
})
setIsAdjustment(true)
}}> 调整 </Button >
</>
},
]}

Loading…
Cancel
Save