From e5879a6b6a2c92b506cc03128a464edd4dcde2fa Mon Sep 17 00:00:00 2001 From: wenlele Date: Fri, 22 Dec 2023 13:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=BD=E6=9F=A5=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/report/index.js | 93 ++++++++++++------- api/utils/xlsxDownload.js | 16 +++- .../containers/maintenanceSpotCheck-new.js | 37 +++++++- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index c124f3e8..b668bc67 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -4,7 +4,7 @@ const moment = require('moment'); const xlsxDownload = require('../../../../utils/xlsxDownload.js'); const fs = require('fs'); const data = require('../../routes/data/index.js'); -async function reportList(ctx) { +async function reportList (ctx) { try { const models = ctx.fs.dc.models; 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 { const models = ctx.fs.dc.models; const { startTime, endTime, userId, reportType } = ctx.query @@ -200,7 +200,7 @@ async function reportPosition(ctx) { } } -async function reportDetail(ctx) { +async function reportDetail (ctx) { try { const models = ctx.fs.dc.models; const { reportId } = ctx.params @@ -229,7 +229,7 @@ async function reportDetail(ctx) { } } -async function reportHandle(ctx) { +async function reportHandle (ctx) { try { const { models } = ctx.fs.dc; @@ -259,7 +259,7 @@ async function reportHandle(ctx) { } } -async function createReport(ctx) { +async function createReport (ctx) { try { const { userId } = ctx.fs.api const models = ctx.fs.dc.models; @@ -281,7 +281,7 @@ async function createReport(ctx) { } } -async function deleteReport(ctx) { +async function deleteReport (ctx) { try { const models = ctx.fs.dc.models; const { reportId } = ctx.params; @@ -303,7 +303,7 @@ async function deleteReport(ctx) { } // TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回 -async function spotPrepare(ctx) { +async function spotPrepare (ctx) { try { const { models } = ctx.fs.dc; 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(); try { 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 { startTime, endTime } = ctx.query try { @@ -516,7 +516,7 @@ async function spotCheckDetail(ctx) { } -async function roadSpotPrepare(ctx) { +async function roadSpotPrepare (ctx) { try { const { models } = ctx.fs.dc; const sequelize = ctx.fs.dc.orm; @@ -593,7 +593,7 @@ async function roadSpotPrepare(ctx) { '乡': `route_code LIKE 'Y%'`, '村': `route_code LIKE 'C%'` } - async function getRoadTotalMileage(key, otherWhere = [], spot) { + async function getRoadTotalMileage (key, otherWhere = [], spot) { let res = await sequelize.query(` SELECT 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 } - async function getRoadSpot(key, lastRoadIds = [], inOrNot, otherWhere = []) { + async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { if (!lastRoadIds.length && !inOrNot) { return [] } @@ -624,11 +624,11 @@ async function roadSpotPrepare(ctx) { `, { type: QueryTypes.SELECT }); } - async function spotRoadId(key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { + async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { let spotRoadIds = [] let accumulationMileage = 0 - async function filterRoad(otherWhere, getRepeat = true) { + async function filterRoad (otherWhere, getRepeat = true) { if (key == '村' && getRepeat == true) { @@ -728,7 +728,7 @@ async function roadSpotPrepare(ctx) { let otherWhere = [`township_code='${t.township_code}'`] const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere, true) 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 spotTownRoadIds_ = spotTownRoadIdsArr[0] @@ -740,7 +740,7 @@ async function roadSpotPrepare(ctx) { // 抽村 const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere, true) const villageRoadTotalHide = await getRoadTotalMileage('村', otherWhere, false) - const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 + const villageRoadNeedMileage = villageRoadTotalMileage * (countyPercentage == 75 ? 20 : 10) / 100 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(); try { const { models } = ctx.fs.dc; @@ -920,7 +920,7 @@ async function confirmRoadSpot(ctx) { } } -async function roadSpotList(ctx) { +async function roadSpotList (ctx) { try { const { models } = ctx.fs.dc; const { startTime, endTime, page, limit } = ctx.query @@ -974,7 +974,7 @@ async function roadSpotList(ctx) { } } -async function roadSpotDetail(ctx) { +async function roadSpotDetail (ctx) { try { const { models } = ctx.fs.dc; 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(); try { const { models } = ctx.fs.dc; @@ -1033,7 +1033,7 @@ async function roadSpotChange(ctx) { } let previewUpdated = false - async function updatePreview(key) { + async function updatePreview (key) { if (previewUpdated) return if (previewRes[key] && previewRes[key].includes(originRoadId)) { @@ -1077,12 +1077,39 @@ async function roadSpotChange(ctx) { let curChangeRoad = roadRes.find(item => item.id == changeRoadId) const level = curChangeRoad.level; let milData = {} + let differenceValue = (parseFloat(curChangeRoad.chainageMileage) - parseFloat(curOriginRoad.chainageMileage)) || 0 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 == '乡') { - 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 == '村') { - 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({ @@ -1136,7 +1163,7 @@ async function roadSpotChange(ctx) { } } -async function roadSpotChangList(ctx) { +async function roadSpotChangList (ctx) { try { const { models } = ctx.fs.dc; const { startTime, endTime, page, limit } = ctx.query @@ -1189,7 +1216,7 @@ async function roadSpotChangList(ctx) { } } -async function exportSpotRode(ctx) { +async function exportSpotRode (ctx) { try { const { models } = ctx.fs.dc; const { previewId } = ctx.query @@ -1276,21 +1303,21 @@ async function exportSpotRode(ctx) { villageId: (village.find(d => road.villageId == d.id) || {}).name || '--', routeName: road.routeName, routeCode: road.routeCode, - startStation: road.startStation, - stopStation: road.stopStation, + startStation: road.startStation || 0, + stopStation: road.stopStation || 0, technicalLevel: road.technicalLevel, pavementType: road.pavementType, - pavementWidth: road.pavementWidth, - subgradeWidth: road.subgradeWidth, - chainageMileage: road.chainageMileage, + pavementWidth: road.pavementWidth || 0, + subgradeWidth: road.subgradeWidth || 0, + chainageMileage: road.chainageMileage || 0, maintenanceCount: item.maintenanceCount, } }) const fileName = `${moment(previewRes.date).format('YYYY年MM月DD日HH时mm分')}道路抽查记录` + '.csv' const filePath = await xlsxDownload.simpleExcelDown({ - data: exportData, header, fileName: fileName - // data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] } + // data: exportData, header, fileName: fileName + data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] } }) const fileData = fs.readFileSync(filePath); diff --git a/api/utils/xlsxDownload.js b/api/utils/xlsxDownload.js index af046879..7818222b 100644 --- a/api/utils/xlsxDownload.js +++ b/api/utils/xlsxDownload.js @@ -42,10 +42,10 @@ async function gatherSheet ({ sheet_2, data = [] }) { for (let h of ['县道', '', '', '', '乡道', '', '', '', '村道', '', '', '',]) { const cell = headerRow2.addCell(); - + cell.value = h; cell.style = headerStyle - if(h){ + if (h) { cell.hMerge = 3 } @@ -54,7 +54,7 @@ async function gatherSheet ({ sheet_2, data = [] }) { const header = [{ key: 'name', title: '', - },{ + }, { key: 'county', title: '总里程', }, { @@ -107,13 +107,19 @@ async function gatherSheet ({ sheet_2, data = [] }) { style.border.rightColor = '#000000'; style.border.bottom = 'thin'; style.border.bottomColor = '#000000'; - + + let rowGather = sheet_2.addRow(); + for (let h of header) { + const cell = rowGather.addCell(); + cell.value = h.key == 'name' ? '汇总' : data.reduce((a, b) => a + (b[h.key] || 0), 0) + cell.style = style + } for (let i = 0; i < data.length; i++) { const row = sheet_2.addRow(); for (let h of header) { const cell = row.addCell(); - cell.value = data[i][h.key]; + cell.value = data[i][h.key] cell.style = style } } diff --git a/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js b/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js index a447e19b..ff4e7ad9 100644 --- a/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js +++ b/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js @@ -29,6 +29,7 @@ const MaintenanceSpotCheck = (props) => { const [isAdjustment, setIsAdjustment] = useState(false) const [editData, setEditData] = useState({}) const [keyword, setKeyword] = useState("") + const [show, setShow] = useState() const roadCode = [ @@ -153,6 +154,7 @@ const MaintenanceSpotCheck = (props) => { const cancelHandler = () => { setVis(false) form.resetFields() + setShow("") } @@ -295,6 +297,7 @@ const MaintenanceSpotCheck = (props) => { queryData({ startTime: dateRange[0], endTime: dateRange[1] }) form.resetFields() setVis(false) + setShow("") } }) }) @@ -302,9 +305,7 @@ const MaintenanceSpotCheck = (props) => {
抽取县道比例(%) - - } + label={'抽取县道比例(%)'} name="percentValue" rules={[ { required: true, message: '请选择抽取比例' }, @@ -314,8 +315,34 @@ const MaintenanceSpotCheck = (props) => { // }, ]} > - { + setShow(v) + form.setFieldsValue({ + 'town': v == 75 ? 50 : 25, + 'village': v == 75 ? 20 : 10, + }) + }} /> + { + show && <> + + + + + } + { ) } -function mapStateToProps(state) { +function mapStateToProps (state) { const { auth, roadSpotList, reportDetail, roadSpotDetail } = state //('state1', state) return {