From 294a9137d1dfb311ab6f1143c1fcf8d0d4191604 Mon Sep 17 00:00:00 2001 From: wenlele Date: Tue, 23 Jan 2024 16:23:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E6=9F=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/report/index.js | 287 +++++++++--------- api/app/lib/routes/report/index.js | 4 + api/utils/xlsxDownload.js | 52 ++-- .../src/sections/fillion/actions/spotCheck.js | 12 + .../sections/fillion/components/spotCheck.js | 8 +- .../containers/maintenanceSpotCheck-new.js | 58 +++- 6 files changed, 235 insertions(+), 186 deletions(-) diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index 29734463..fe77f8e5 100644 --- a/api/app/lib/controllers/report/index.js +++ b/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 }; \ No newline at end of file diff --git a/api/app/lib/routes/report/index.js b/api/app/lib/routes/report/index.js index 6c6449b4..62119d07 100644 --- a/api/app/lib/routes/report/index.js +++ b/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) + } \ No newline at end of file diff --git a/api/utils/xlsxDownload.js b/api/utils/xlsxDownload.js index 6323e73c..689a0b4d 100644 --- a/api/utils/xlsxDownload.js +++ b/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 } } diff --git a/web/client/src/sections/fillion/actions/spotCheck.js b/web/client/src/sections/fillion/actions/spotCheck.js index e617ab06..43eaea69 100644 --- a/web/client/src/sections/fillion/actions/spotCheck.js +++ b/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: '' } + }); } \ No newline at end of file diff --git a/web/client/src/sections/fillion/components/spotCheck.js b/web/client/src/sections/fillion/components/spotCheck.js index 8563a5f4..26ca121a 100644 --- a/web/client/src/sections/fillion/components/spotCheck.js +++ b/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 导出 + return 导出 } }, ] @@ -212,7 +212,7 @@ const SpotCheck = ({ dispatch, user, loading, reportDetail, editData, onCancel, @@ -286,7 +286,7 @@ const SpotCheck = ({ dispatch, user, loading, reportDetail, editData, onCancel, diff --git a/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js b/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js index a1b86655..c6228c02 100644 --- a/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js +++ b/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) => + render: (_, r, index) => <> + { + 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="取消" + > + + + + + }, ]}