Browse Source

添加抽查弹窗修改

dev
wenlele 1 year ago
parent
commit
e5879a6b6a
  1. 93
      api/app/lib/controllers/report/index.js
  2. 12
      api/utils/xlsxDownload.js
  3. 37
      web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js

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

@ -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);

12
api/utils/xlsxDownload.js

@ -45,7 +45,7 @@ async function gatherSheet ({ sheet_2, data = [] }) {
cell.value = h; cell.value = h;
cell.style = headerStyle cell.style = headerStyle
if(h){ if (h) {
cell.hMerge = 3 cell.hMerge = 3
} }
@ -54,7 +54,7 @@ async function gatherSheet ({ sheet_2, data = [] }) {
const header = [{ const header = [{
key: 'name', key: 'name',
title: '', title: '',
},{ }, {
key: 'county', key: 'county',
title: '总里程', title: '总里程',
}, { }, {
@ -108,12 +108,18 @@ async function gatherSheet ({ sheet_2, data = [] }) {
style.border.bottom = 'thin'; style.border.bottom = 'thin';
style.border.bottomColor = '#000000'; 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++) { for (let i = 0; i < data.length; i++) {
const row = sheet_2.addRow(); const row = sheet_2.addRow();
for (let h of header) { for (let h of header) {
const cell = row.addCell(); const cell = row.addCell();
cell.value = data[i][h.key]; cell.value = data[i][h.key]
cell.style = style cell.style = style
} }
} }

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

@ -29,6 +29,7 @@ const MaintenanceSpotCheck = (props) => {
const [isAdjustment, setIsAdjustment] = useState(false) const [isAdjustment, setIsAdjustment] = useState(false)
const [editData, setEditData] = useState({}) const [editData, setEditData] = useState({})
const [keyword, setKeyword] = useState("") const [keyword, setKeyword] = useState("")
const [show, setShow] = useState()
const roadCode = [ const roadCode = [
@ -153,6 +154,7 @@ const MaintenanceSpotCheck = (props) => {
const cancelHandler = () => { const cancelHandler = () => {
setVis(false) setVis(false)
form.resetFields() form.resetFields()
setShow("")
} }
@ -295,6 +297,7 @@ const MaintenanceSpotCheck = (props) => {
queryData({ startTime: dateRange[0], endTime: dateRange[1] }) queryData({ startTime: dateRange[0], endTime: dateRange[1] })
form.resetFields() form.resetFields()
setVis(false) setVis(false)
setShow("")
} }
}) })
}) })
@ -302,9 +305,7 @@ const MaintenanceSpotCheck = (props) => {
<Form form={form}> <Form form={form}>
<Form.Item <Form.Item
label={<div>抽取县道比例(%)<Tooltip title='默认抽查乡道比例为25%、抽查村道比例为10%'> label={'抽取县道比例(%)'}
<ExclamationCircleOutlined style={{ marginLeft: 6 }} />
</Tooltip></div>}
name="percentValue" name="percentValue"
rules={[ rules={[
{ required: true, message: '请选择抽取比例' }, { required: true, message: '请选择抽取比例' },
@ -314,8 +315,34 @@ const MaintenanceSpotCheck = (props) => {
// }, // },
]} ]}
> >
<Select style={{}} placeholder="请选择抽取比例" options={[{ value: 50, label: '50%', }, { value: 75, label: '75%', }]} /> <Select style={{}} placeholder="请选择抽取比例" options={[{ value: 50, label: '50%', }, { value: 75, label: '75%', }]}
onChange={v => {
setShow(v)
form.setFieldsValue({
'town': v == 75 ? 50 : 25,
'village': v == 75 ? 20 : 10,
})
}} />
</Form.Item>
{
show && <>
<Form.Item
label={'抽取乡道比例(%)'}
name="town"
rules={[{ required: true, message: '请选择抽取比例' }]}
>
<Select disabled placeholder="请选择抽取比例" options={[{ value: 25, label: '25%', }, { value: 50, label: '50%', }]} />
</Form.Item> </Form.Item>
<Form.Item
label={'抽取村道比例(%)'}
name="village"
rules={[{ required: true, message: '请选择抽取比例' }]}
>
<Select disabled placeholder="请选择抽取比例" options={[{ value: 10, label: '10%', }, { value: 20, label: '20%', }]} />
</Form.Item>
</>
}
<Form.Item className="ant-row" style={{ <Form.Item className="ant-row" style={{
textAlign: 'center', textAlign: 'center',
@ -355,7 +382,7 @@ const MaintenanceSpotCheck = (props) => {
</div > </div >
) )
} }
function mapStateToProps(state) { function mapStateToProps (state) {
const { auth, roadSpotList, reportDetail, roadSpotDetail } = state const { auth, roadSpotList, reportDetail, roadSpotDetail } = state
//('state1', state) //('state1', state)
return { return {

Loading…
Cancel
Save