From c83fda9aac8c43f830c44c29fabbfa44af3a5ceb Mon Sep 17 00:00:00 2001 From: wenlele Date: Sun, 10 Dec 2023 16:33:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=85=BB=E6=8A=A4=E6=8A=BD=E6=9F=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/sections/fillion/actions/index.js | 16 +- .../src/sections/fillion/actions/spotCheck.js | 35 + .../sections/fillion/containers/adjustLog.js | 669 ++++++++++++++++++ .../src/sections/fillion/containers/index.js | 10 +- .../containers/maintenanceSpotCheck-new.js | 466 ++++++++++++ web/client/src/sections/fillion/nav-item.js | 195 ++--- web/client/src/sections/fillion/routes.js | 339 ++++----- .../organization/containers/authority.js | 492 ++++++------- 8 files changed, 1705 insertions(+), 517 deletions(-) create mode 100644 web/client/src/sections/fillion/actions/spotCheck.js create mode 100644 web/client/src/sections/fillion/containers/adjustLog.js create mode 100644 web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js diff --git a/web/client/src/sections/fillion/actions/index.js b/web/client/src/sections/fillion/actions/index.js index 8a48b86e..7b2f7462 100644 --- a/web/client/src/sections/fillion/actions/index.js +++ b/web/client/src/sections/fillion/actions/index.js @@ -7,12 +7,14 @@ import * as assess from './assess' import * as allDepUsers from './allDepUsers' import * as getReportSpotPrepare from './extract' import * as luzheng from './luzheng' +import * as spotCheck from './spotCheck' export default { - ...infor, - ...patrol, - ...file, - ...assess, - ...allDepUsers, - ...getReportSpotPrepare, - ...luzheng + ...infor, + ...patrol, + ...file, + ...assess, + ...allDepUsers, + ...getReportSpotPrepare, + ...luzheng, + ...spotCheck } \ No newline at end of file diff --git a/web/client/src/sections/fillion/actions/spotCheck.js b/web/client/src/sections/fillion/actions/spotCheck.js new file mode 100644 index 00000000..b7492f5f --- /dev/null +++ b/web/client/src/sections/fillion/actions/spotCheck.js @@ -0,0 +1,35 @@ +import { basicAction } from '@peace/utils' +import { ApiTable } from '$utils' + +// export function getAssess (query) { +// return dispatch => basicAction({ +// type: 'get', +// dispatch: dispatch, +// query: query, +// actionType: 'GET_ASSESS', +// url: ApiTable.getAssess, +// msg: { error: '获取考核评分信息' }, +// reducer: { name: 'assess' } +// }); +// } + +// export function delAssess (query) { +// return dispatch => basicAction({ +// type: 'del', +// dispatch: dispatch, +// actionType: 'DEL_ASSESS', +// url: ApiTable.delAssess.replace("{assessId}", query?.id), +// msg: { option: '删除考核评分信息' }, +// }); +// } + +// export function editAssess (query) { +// return dispatch => basicAction({ +// type: 'put', +// dispatch: dispatch, +// data: query, +// actionType: 'PUT_ASSESS', +// url: ApiTable.editAssess, +// msg: { option: '编辑/新增考核评分信息' }, +// }); +// } \ No newline at end of file diff --git a/web/client/src/sections/fillion/containers/adjustLog.js b/web/client/src/sections/fillion/containers/adjustLog.js new file mode 100644 index 00000000..b42ddf46 --- /dev/null +++ b/web/client/src/sections/fillion/containers/adjustLog.js @@ -0,0 +1,669 @@ +import { connect } from 'react-redux'; +import React, { useEffect, useState } from 'react'; +import { Button, Modal, Form, Input, Divider, Spin, Image, DatePicker, Descriptions, Table } from 'antd' +import ProTable from '@ant-design/pro-table'; +import { getReportSpotPrepare, getSpotCheck, getSpotCheckDetail } from '../actions/extract' +import { getReportDetail } from '../actions/patrol'; +import moment from 'moment' +import '../components/maintenanceTable.less' + + +const DetailForm = (props) => { + const { visible, data, handleClose, loading } = props + //console.log('data1', data) + const [qndmn] = useState(localStorage.getItem('qndmn')) + const changeBoolean = (bool) => { + // console.log('bool', bool) + return bool ? '无异常' : '有异常' + } + const reportTypeText = (text) => { + switch (text) { + case 'road': return '道路'; + // + case 'countyRoad': return '县道'; + case 'villageRoad': return '乡道'; + case 'rusticRoad': return '村道'; + // + case 'bridge': return '桥梁'; + case 'culvert': return '涵洞'; + case 'other': return '其他'; + // + case 'conserve': return '养护'; + case 'patrol': return '巡查'; + case 'construction': return '在建'; + default: return text; + } + } + const keyList = [ + { key: '路线代码', name: 'codeRoad' }, + { key: '其他', name: 'projectType' }, + { key: '道路类型', name: 'reportType' }, + { key: '路线名称', name: 'road' }, + { key: '路线代码', name: 'codeRoad' }, + { key: '养护路段', name: 'roadSectionStart' }, + { key: '具体位置', name: 'address' }, + { key: '路面类型', name: 'roadType' }, + { key: '路面宽度(米)', name: 'roadWidth' }, + { key: '错车道(个)', name: 'wrongLane' }, + { key: '行道树(棵)', name: 'roadsideTrees' }, + { key: '边沟(米)', name: 'roadsideDitch' }, + { key: '护栏(米)', name: 'guardrail' }, + { key: '标线(米)', name: 'roadMarking' }, + { key: '养护人员人数(人)', name: 'maintenanceStaffCount' }, + { key: '修整路肩(平方米)', name: 'shoulderRepair' }, + { key: '清理边沟(米)', name: 'ditchCleaning' }, + { key: '修补沥青路面(平方米)', name: 'asphaltRepair' }, + { key: '修补水泥路面(平方米)', name: 'concreteRepair' }, + { key: '除草(米)', name: 'grassMowing' }, + { key: '树刷白(株/公里)', name: 'treeWhitening' }, + { key: '桩刷白(个)', name: 'pileWhitening' }, + { key: '维护护栏(个)', name: 'guardrailMaintenance' }, + { key: '修复端头(块)', name: 'endHeadRepair' }, + { key: '其他养护内容', name: 'otherDescription' }, + { key: '养护前图片', name: 'conserveBeforePic' }, + { key: '养护中图片', name: 'conserveUnderwayPic' }, + { key: '养护后图片', name: 'conserveAfterPic' }, + { key: '上报视频', name: 'videoUrl' }, + + ]; + const keyListOld = [ + // { key: '编号', name: 'id' }, + { key: '工程类型', name: 'projectType' }, + { key: '所在路段', name: 'road' }, + { key: '具体位置', name: 'address' }, + { key: '巡查内容', name: 'content' }, + { key: '路线代码', name: 'codeRoad' }, + // { key: '病害照片', name: 'scenePic' }, + { key: '养护前', name: 'conserveBeforePic' }, + { key: '养护中', name: 'conserveUnderwayPic' }, + { key: '养护后', name: 'conserveAfterPic' }, + + ]; + const roadInfo = [ + { key: '路面类型', name: 'roadType' }, + { key: '路面宽度/米', name: 'roadWidth' }, + { key: '错车道/个', name: 'wrongLane' }, + { key: '行道树/棵', name: 'roadsideTrees' }, + { key: '边沟/米', name: 'roadsideDitch' }, + { key: '护栏/米', name: 'guardrail' }, + { key: '标线/米', name: 'roadMarking' }, + ]; + const mantenanceInfo = [ + { key: '养护人员人数/人', name: 'maintenanceStaffCount' }, + { key: '修整路肩/平方米', name: 'shoulderRepair' }, + { key: '开挖、清理边沟/米', name: 'ditchCleaning' }, + { key: '修补沥青路面/平米', name: 'asphaltRepair' }, + { key: '修补水泥路面/平米', name: 'concreteRepair' }, + { key: '除草/米', name: 'grassMowing' }, + { key: '行道树刷白/株/公里', name: 'treeWhitening' }, + { key: '公里桩/百米桩刷漆/个', name: 'pileWhitening' }, + { key: '维修护栏/米', name: 'guardrailMaintenance' }, + { key: '修复端头/块', name: 'endHeadRepair' }, + { key: '其他', name: 'otherDescription' }, + ]; + const mantenancePic = [ + { key: '养护前图片', name: 'conserveBeforePic' }, + { key: '养护中图片', name: 'conserveUnderwayPic' }, + { key: '养护后图片', name: 'conserveAfterPic' }, + ]; + const renderContent = (data) => { + if (data) { + console.log('data1111', data) + if (moment(data.time).isAfter(moment('2023-08-03 00:00:00'))) { + return
+ + {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} + {reportTypeText(data['projectType']) || ''} + {data['codeRoad'] || ''} + {data['code'] || ''} + {data['roadSectionStart'] + '-' + data['roadSectionEnd'] || ''} + {data['address'] || ''} + + + {roadInfo.map(item => ( + + {data[item.name] || ''} + + ))} + + + {mantenanceInfo.map(item => ( + + {data[item.name] || ''} + + ))} + + + {mantenancePic.map(item => ( + +
+ {data[item.name]?.map(imgSrc => { + return
+ +
+ }) || '暂无图片'} +
+
+ ))} +
+ + +
+ {data['videoUrl']?.map(videoSrc => { + return
+
+ }) || '暂无视频'} +
+
+
+
+ // if (data) { + // if (moment(data.time).isAfter(moment('2023-08-03 00:00:00'))) { + // return keyList.map(obj => { + // return
+ // {obj.key} + // { + // obj.name != 'conserveBeforePic' && obj.name != 'conserveAfterPic' && obj.name != 'roadSectionStart' && obj.name != 'videoUrl' && obj.name.indexOf('conserve') == -1 ? + // + // : obj.name != 'roadSectionStart' && obj.name != 'videoUrl' ? + //
+ // { + // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { + // return
+ // + //
+ // }) : '暂无图片' + // } + //
: obj.name != 'videoUrl' ?
+ // + + //
:
+ // { + // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(videoUrl => { + // return
+ // + //
+ // }) : '暂无视频' + // } + //
+ // } + + //
+ // }) + + // } else { + // return keyListOld.map(obj => { + // return
+ // {obj.key} + // { + // obj.name != 'scenePic' && obj.name.indexOf('conserve') == -1 ? + // + // : + //
+ // { + // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { + // return
+ // + //
+ // }) : '暂无图片' + // } + //
+ + // } + //
+ // }) + + // } + + } else { + return
+ + {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} + {data['roadSectionStart'] && data['roadSectionEnd'] ? (data['roadSectionStart'] + '-' + data['roadSectionEnd']) : ''} + {data['codeRoad'] || ''} + {/* {data['code'] || ''} */} + {data['address'] || ''} + {data['content'] || ''} + + + {mantenancePic.map(item => ( + +
+ {data[item.name]?.map(imgSrc => { + return
+ +
+ }) || '暂无图片'} +
+
+ ))} +
+ + +
+ {data['videoUrl']?.map(videoSrc => { + return
+
+ }) || '暂无视频'} +
+
+
+
+ } + } else { + return '暂无数据' + } + } + // const renderContent = (data) => { + // if (data) { + // if (data['inspectionNoException']) { + // // 当'无异常'字段为true时,显示'无异常'和其他非异常相关字段 + // return keyList.map(obj => { + // if (obj.name === 'inspectionNoException' || obj.name === 'reportType' || obj.name === 'projectType' || obj.name === 'road' || obj.name === 'roadSectionStart' || obj.name === 'address' || obj.name === 'codeRoad' || obj.name === 'scenePic' || obj.name === 'videoUrl') { + // return ( + //
+ // {obj.key} + // { + // obj.name === 'scenePic' && data[obj.name] instanceof Array ? + //
+ // { + // data[obj.name].map(imgSrc => { + // return
+ // + //
+ // }) + // } + //
+ // : obj.name === 'roadSectionStart' ? + //
+ // + //
+ // : + // + // } + //
+ // ); + // } else { + // return null; // 不渲染异常相关字段 + // } + // }); + // } else { + // // 当'无异常'字段为false或未定义时,显示其他异常相关字段 + // return keyList.map(obj => { + // if (obj.name !== 'inspectionNoException') { + // return ( + //
+ // {obj.key} + // { + // obj.name !== 'scenePic' && obj.name !== 'roadSectionStart' && obj.name.indexOf('conserve') === -1 ? + // + // : obj.name !== 'roadSectionStart' ? + //
+ // { + // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { + // return
+ // + //
+ // }) : '暂无图片' + // } + //
+ // :
+ // + //
+ // } + //
+ // ); + // } else { + // return null; // 不渲染其他异常字段 + // } + // }); + // } + // } else { + // return '暂无数据'; + // } + // } + return ( + + + {renderContent(data)} + + + ) +} +const MaintenanceSpotCheck = (props) => { + const { dispatch, user, loading, reportDetail, reportDetailLoading } = props + const [data, setData] = useState()//外层表格的数据 + const [vis, setVis] = useState(false)//模态框的显示与隐藏变量 + const [count, setCount] = useState(0) + const [depId, setDepId] = useState(0) + const [depName, setDepName] = useState('') + const [total, setTotal] = useState(0) + const [previewId, setPreviewId] = useState(0) + const [reportData, setReportData] = useState([]) + const [detailVisible, setDetailVisible] = useState(false) + const [dateRange, setDateRange] = useState(['1970-1-1', '2099-12-31']); + const { RangePicker } = DatePicker + const [expandedRowKeys, setExpandedRowKeys] = useState([]); + + //console.log('reportData', reportData) + const checkDetail = (record) => { + dispatch(getReportDetail(record?.id)) + } + const handleOpen = () => { + setDetailVisible(true) + } + const handleClose = () => { + setDetailVisible(false) + } + + //里层列名 + const columns = [ + { + title: '抽查日期', + key: 'spotDate', + dataIndex: 'spotDate', + align: 'center', + // render: (_, record) => { + // return + // } + }, + { + title: '抽查乡镇', + key: 'projectType', + dataIndex: 'depName', + align: 'center', + + }, + { + title: '抽查数量', + key: 'count', + dataIndex: 'count', + align: 'center', + + }, + { + title: '抽查总数', + key: 'reportCount', + dataIndex: 'reportCount', + align: 'center', + + }, + + ] + const queryData = (query = { startTime: '1970-1-1', endTime: '2099-12-31' }) => { + dispatch(getSpotCheckDetail(query)).then(res => { + if (res.success) { + const data = res?.payload.data?.map(item => { + return { + spotDate: moment(item.date).format('YYYY-MM-DD'), + depName: item.department?.name, + reportCount: item.reportCount, + count: Math.ceil((item.reportCount * item.percentage) / 100), + reportDetail: item.reportSpotChecks?.map(child => { + return child.report + }), + id: item.id + } + }) + //console.log('data1', data) + setReportData(data) + } + }) + } + + useEffect(() => { + queryData() + }, []) + const [form] = Form.useForm() + const addHanler = () => { + setVis(true) + } + const extractHandler = () => { + form.validateFields(['percentValue']).then(async (values) => { + if (Number(values.percentValue) > 0) { + const res = await dispatch(getReportSpotPrepare({ percentage: Number(values.percentValue) })) + // setCount(res?.payload.data?.reportCount) + // setDepId(res?.payload.data?.lukyDepartment?.id) + // setDepName(res?.payload.data?.lukyDepartment?.name) + setPreviewId(res?.payload.data?.previewId) + // setTotal(Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100))) + + form.setFieldsValue({ + 'result': res?.payload.data?.reportCount, + 'village': res?.payload.data?.lukyDepartment?.name, + 'total': Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100)) + }) + } + }) + } + const cancelHandler = () => { + setVis(false) + form.resetFields() + } + const okHandler = async () => { + if (previewId !== 0) { + const res = await dispatch(getSpotCheck({ previewId })) + const rslt = res.payload.data.map(item => { + return { + spotDate: moment(item.date).format('YYYY-MM-DD'), + depName: item.department?.name, + reportCount: item.reportCount, + count: Math.ceil((item.reportCount * item.percentage) / 100), + reportDetail: item.reportSpotChecks?.map(child => { + return child.report + }), + id: item.id + } + }) || [] + setReportData(rslt) + form.resetFields() + setVis(false) + } + } + //console.log('setReportData', reportData) + + const lookhandler = () => { + if ((dateRange && dateRange instanceof Array && dateRange[0] != '')) { + queryData({ startTime: moment(dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'), endTime: moment(dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss') }) + } + } + + return ( +
+ + { setDateRange(dateString) }} style={{ marginRight: '50px' }} /> + + + ( + < Table + pagination={false} + dataSource={record?.reportDetail} + columns={ + [ + { title: '所属道路', dataIndex: 'road' }, + { + title: '所在路段', + key: 'address', + dataIndex: 'address', + align: 'center', + render: (_, r) => { + return `${r?.roadSectionStart || ''}-${r?.roadSectionEnd || ''}` + } + }, + { title: '具体位置', dataIndex: 'address' }, + { + title: '上报人', + width: 100, + key: 'userName', + dataIndex: 'userName', + align: 'center', + render: (text, r) => { + return r?.user?.name || '' + } + }, + { + title: '上报时间', + key: 'time', + dataIndex: 'time', + valueType: 'dateTime', + align: 'center', + render: (_, r) => { + return moment(r?.time).format('YYYY-MM-DD HH:mm:ss') + } + }, + { + title: '操作', + key: 'caozuo', + align: 'center', + render: (_, r) => { + return + } + } + // { title: '', dataIndex: 'subColumn1' }, + // { title: '', dataIndex: 'subColumn2' }, + // ... 其他子表格列配置 + ]} + /> + ), + }} + pagination={{ + pageSize: 10, + defaultPageSize: 10, + showSizeChanger: false, + }} + rowKey={(record) => { return record.id }} + toolBarRender={false} + search={false} + /> + +
+ + + + + + {/* + % + */} + + + + + + + + + + + + + + +
+
+ +
+ ) +} +function mapStateToProps (state) { + const { auth, spotCheckDetail, reportDetail } = state + //('state1', state) + return { + user: auth.user, + loading: spotCheckDetail?.isRequesting, + reportDetailLoading: reportDetail.isRequesting, + reportDetail: reportDetail.data, + + } +} +export default connect(mapStateToProps)(MaintenanceSpotCheck); \ No newline at end of file diff --git a/web/client/src/sections/fillion/containers/index.js b/web/client/src/sections/fillion/containers/index.js index eac6898f..d58f7d32 100644 --- a/web/client/src/sections/fillion/containers/index.js +++ b/web/client/src/sections/fillion/containers/index.js @@ -18,9 +18,11 @@ import Assess from './assess' import VideoCenter from './videoCenter'; import Building from './building' import MaintenanceSpotCheck from './maintenanceSpotCheck' +import MaintenanceSpotCheckNew from './maintenanceSpotCheck-new' +import AdjustLog from './adjustLog' export { - Infor, transportation, BridgeTable, HigHways, - OperaTional, Enforce, Public, Videois, PromoTional, - Maintenance, Patrol, File, Jiekouguanli, - Task, Building, Assess, VideoCenter, MaintenanceSpotCheck + Infor, transportation, BridgeTable, HigHways, + OperaTional, Enforce, Public, Videois, PromoTional, + Maintenance, Patrol, File, Jiekouguanli, + Task, Building, Assess, VideoCenter, MaintenanceSpotCheck, MaintenanceSpotCheckNew, AdjustLog }; \ No newline at end of file diff --git a/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js b/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js new file mode 100644 index 00000000..bd5d2261 --- /dev/null +++ b/web/client/src/sections/fillion/containers/maintenanceSpotCheck-new.js @@ -0,0 +1,466 @@ +import { connect } from 'react-redux'; +import React, { useEffect, useState } from 'react'; +import { Button, Modal, Form, Input, Divider, Spin, Image, DatePicker, Descriptions, Table } from 'antd' +import ProTable from '@ant-design/pro-table'; +import { getReportSpotPrepare, getSpotCheck, getSpotCheckDetail } from '../actions/extract' +import { getReportDetail } from '../actions/patrol'; +import moment from 'moment' +import '../components/maintenanceTable.less' + + +const DetailForm = (props) => { + const { visible, data, handleClose, loading } = props + //console.log('data1', data) + const [qndmn] = useState(localStorage.getItem('qndmn')) + const changeBoolean = (bool) => { + // console.log('bool', bool) + return bool ? '无异常' : '有异常' + } + const reportTypeText = (text) => { + switch (text) { + case 'road': return '道路'; + // + case 'countyRoad': return '县道'; + case 'villageRoad': return '乡道'; + case 'rusticRoad': return '村道'; + // + case 'bridge': return '桥梁'; + case 'culvert': return '涵洞'; + case 'other': return '其他'; + // + case 'conserve': return '养护'; + case 'patrol': return '巡查'; + case 'construction': return '在建'; + default: return text; + } + } + + const roadInfo = [ + { key: '路面类型', name: 'roadType' }, + { key: '路面宽度/米', name: 'roadWidth' }, + { key: '错车道/个', name: 'wrongLane' }, + { key: '行道树/棵', name: 'roadsideTrees' }, + { key: '边沟/米', name: 'roadsideDitch' }, + { key: '护栏/米', name: 'guardrail' }, + { key: '标线/米', name: 'roadMarking' }, + ]; + const mantenanceInfo = [ + { key: '养护人员人数/人', name: 'maintenanceStaffCount' }, + { key: '修整路肩/平方米', name: 'shoulderRepair' }, + { key: '开挖、清理边沟/米', name: 'ditchCleaning' }, + { key: '修补沥青路面/平米', name: 'asphaltRepair' }, + { key: '修补水泥路面/平米', name: 'concreteRepair' }, + { key: '除草/米', name: 'grassMowing' }, + { key: '行道树刷白/株/公里', name: 'treeWhitening' }, + { key: '公里桩/百米桩刷漆/个', name: 'pileWhitening' }, + { key: '维修护栏/米', name: 'guardrailMaintenance' }, + { key: '修复端头/块', name: 'endHeadRepair' }, + { key: '其他', name: 'otherDescription' }, + ]; + const mantenancePic = [ + { key: '养护前图片', name: 'conserveBeforePic' }, + { key: '养护中图片', name: 'conserveUnderwayPic' }, + { key: '养护后图片', name: 'conserveAfterPic' }, + ]; + const renderContent = (data) => { + if (data) { + if (moment(data.time).isAfter(moment('2023-08-03 00:00:00'))) { + return
+ + {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} + {reportTypeText(data['projectType']) || ''} + {data['codeRoad'] || ''} + {data['code'] || ''} + {data['roadSectionStart'] + '-' + data['roadSectionEnd'] || ''} + {data['address'] || ''} + + + {roadInfo.map(item => ( + + {data[item.name] || ''} + + ))} + + + {mantenanceInfo.map(item => ( + + {data[item.name] || ''} + + ))} + + + {mantenancePic.map(item => ( + +
+ {data[item.name]?.map(imgSrc => { + return
+ +
+ }) || '暂无图片'} +
+
+ ))} +
+ + +
+ {data['videoUrl']?.map(videoSrc => { + return
+
+ }) || '暂无视频'} +
+
+
+
+ + + } else { + return
+ + {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} + {data['roadSectionStart'] && data['roadSectionEnd'] ? (data['roadSectionStart'] + '-' + data['roadSectionEnd']) : ''} + {data['codeRoad'] || ''} + {/* {data['code'] || ''} */} + {data['address'] || ''} + {data['content'] || ''} + + + {mantenancePic.map(item => ( + +
+ {data[item.name]?.map(imgSrc => { + return
+ +
+ }) || '暂无图片'} +
+
+ ))} +
+ + +
+ {data['videoUrl']?.map(videoSrc => { + return
+
+ }) || '暂无视频'} +
+
+
+
+ } + } else { + return '暂无数据' + } + } + + return ( + + + {renderContent(data)} + + + ) +} +const MaintenanceSpotCheck = (props) => { + const { dispatch, user, loading, reportDetail, reportDetailLoading } = props + const [data, setData] = useState()//外层表格的数据 + const [vis, setVis] = useState(false)//模态框的显示与隐藏变量 + const [count, setCount] = useState(0) + const [depId, setDepId] = useState(0) + const [depName, setDepName] = useState('') + const [total, setTotal] = useState(0) + const [previewId, setPreviewId] = useState(0) + const [reportData, setReportData] = useState([]) + const [detailVisible, setDetailVisible] = useState(false) + const [dateRange, setDateRange] = useState(['1970-1-1', '2099-12-31']); + const { RangePicker } = DatePicker + const [expandedRowKeys, setExpandedRowKeys] = useState([]); + + //console.log('reportData', reportData) + const checkDetail = (record) => { + dispatch(getReportDetail(record?.id)) + } + const handleOpen = () => { + setDetailVisible(true) + } + const handleClose = () => { + setDetailVisible(false) + } + + //里层列名 + const columns = [ + { + title: '抽查日期', + key: 'spotDate', + dataIndex: 'spotDate', + + }, + { + title: '抽查县道比率(%)', + key: 'projeType', + dataIndex: 'dName', + }, + { + title: '抽查县道', + key: 'proctType', + dataIndex: '', + }, + { + title: '抽查乡道', + key: 'prectTye', + dataIndex: 'depame', + }, + { + title: '抽查村道', + key: 'projeType', + dataIndex: 'dName', + }, + { + title: '操作', + key: 'operation', + dataIndex: 'operation', + // render: (_, record) => { + // return + // } + + }, + + ] + const queryData = (query = { startTime: '1970-1-1', endTime: '2099-12-31' }) => { + dispatch(getSpotCheckDetail(query)).then(res => { + if (res.success) { + const data = res?.payload.data?.map(item => { + return { + spotDate: moment(item.date).format('YYYY-MM-DD'), + depName: item.department?.name, + reportCount: item.reportCount, + count: Math.ceil((item.reportCount * item.percentage) / 100), + reportDetail: item.reportSpotChecks?.map(child => { + return child.report + }), + id: item.id + } + }) + setReportData(data) + } + }) + } + + useEffect(() => { + queryData() + }, []) + const [form] = Form.useForm() + const addHanler = () => { + setVis(true) + } + const extractHandler = () => { + form.validateFields(['percentValue']).then(async (values) => { + if (Number(values.percentValue) > 0) { + const res = await dispatch(getReportSpotPrepare({ percentage: Number(values.percentValue) })) + // setCount(res?.payload.data?.reportCount) + // setDepId(res?.payload.data?.lukyDepartment?.id) + // setDepName(res?.payload.data?.lukyDepartment?.name) + setPreviewId(res?.payload.data?.previewId) + // setTotal(Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100))) + + form.setFieldsValue({ + 'result': res?.payload.data?.reportCount, + 'village': res?.payload.data?.lukyDepartment?.name, + 'total': Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100)) + }) + } + }) + } + const cancelHandler = () => { + setVis(false) + form.resetFields() + } + const okHandler = async () => { + if (previewId !== 0) { + const res = await dispatch(getSpotCheck({ previewId })) + const rslt = res.payload.data.map(item => { + return { + spotDate: moment(item.date).format('YYYY-MM-DD'), + depName: item.department?.name, + reportCount: item.reportCount, + count: Math.ceil((item.reportCount * item.percentage) / 100), + reportDetail: item.reportSpotChecks?.map(child => { + return child.report + }), + id: item.id + } + }) || [] + setReportData(rslt) + form.resetFields() + setVis(false) + } + } + //console.log('setReportData', reportData) + + const lookhandler = () => { + if ((dateRange && dateRange instanceof Array && dateRange[0] != '')) { + queryData({ startTime: moment(dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'), endTime: moment(dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss') }) + } + } + + return ( +
+ +
+ + +
+ { setDateRange(dateString) }} style={{ marginRight: 20 }} /> + + +
+
+ + + ( + < Table + pagination={false} + dataSource={record?.reportDetail} + columns={ + [ + { title: '所属道路', dataIndex: 'road' }, + { + title: '所在路段', + key: 'address', + dataIndex: 'address', + align: 'center', + render: (_, r) => { + return `${r?.roadSectionStart || ''}-${r?.roadSectionEnd || ''}` + } + }, + { title: '具体位置', dataIndex: 'address' }, + { + title: '上报人', + width: 100, + key: 'userName', + dataIndex: 'userName', + align: 'center', + render: (text, r) => { + return r?.user?.name || '' + } + }, + { + title: '上报时间', + key: 'time', + dataIndex: 'time', + valueType: 'dateTime', + align: 'center', + render: (_, r) => { + return moment(r?.time).format('YYYY-MM-DD HH:mm:ss') + } + }, + { + title: '操作', + key: 'caozuo', + align: 'center', + render: (_, r) => { + return + } + } + // { title: '', dataIndex: 'subColumn1' }, + // { title: '', dataIndex: 'subColumn2' }, + // ... 其他子表格列配置 + ]} + /> + ), + }} + pagination={{ + pageSize: 10, + defaultPageSize: 10, + showSizeChanger: false, + }} + rowKey={(record) => { return record.id }} + // toolBarRender={false} + // search={false} + /> + +
+ + + + + + {/* + % + */} + + + + + + + + + + + + + + + +
+ + + ) +} +function mapStateToProps (state) { + const { auth, spotCheckDetail, reportDetail } = state + //('state1', state) + return { + user: auth.user, + loading: spotCheckDetail?.isRequesting, + reportDetailLoading: reportDetail.isRequesting, + reportDetail: reportDetail.data, + + } +} +export default connect(mapStateToProps)(MaintenanceSpotCheck); \ No newline at end of file diff --git a/web/client/src/sections/fillion/nav-item.js b/web/client/src/sections/fillion/nav-item.js index f8644ec0..0632ac88 100644 --- a/web/client/src/sections/fillion/nav-item.js +++ b/web/client/src/sections/fillion/nav-item.js @@ -3,113 +3,118 @@ import { Link } from 'react-router-dom'; import { Menu } from 'antd'; import { ReadOutlined } from '@ant-design/icons'; const SubMenu = Menu.SubMenu; -export function getNavItem(user, dispatch) { - const isshow = user?.userResources?. - some(i => i.resourceId === 'OVERLOADMANAGE' || - i.resourceId === 'ROADMANAGE' || - i.resourceId === 'BRIDGEMANAGE' || - i.resourceId === 'MAINTENANCEMANAGE' || - i.resourceId === 'TRANSPORTATIONMANAGE' || - i.resourceId === 'CONSERVATIONMANAGE' || - i.resourceId === 'PUBLICTRANSPORTMANAGE' || - i.resourceId === 'FILEMANAGE' || - i.resourceId === 'PUBLICITYVIDEO' || - i.resourceId === 'FEEDBACKMANAGE' || - i.resourceId === 'REPORTMANAGE' || - i.resourceId === 'PATROLMANAGE' || - i.resourceId === 'ASSESSMANAGE' || - i.resourceId === 'VIDEOCENTER' || - i.resourceId === 'BUILDINGPROJECT' || - i.resourceId === 'MAINTENANCESPOTCHECK' || - i.resourceId === 'LUZHENG' - ) +export function getNavItem (user, dispatch) { + const isshow = user?.userResources?. + some(i => i.resourceId === 'OVERLOADMANAGE' || + i.resourceId === 'ROADMANAGE' || + i.resourceId === 'BRIDGEMANAGE' || + i.resourceId === 'MAINTENANCEMANAGE' || + i.resourceId === 'TRANSPORTATIONMANAGE' || + i.resourceId === 'CONSERVATIONMANAGE' || + i.resourceId === 'PUBLICTRANSPORTMANAGE' || + i.resourceId === 'FILEMANAGE' || + i.resourceId === 'PUBLICITYVIDEO' || + i.resourceId === 'FEEDBACKMANAGE' || + i.resourceId === 'REPORTMANAGE' || + i.resourceId === 'PATROLMANAGE' || + i.resourceId === 'ASSESSMANAGE' || + i.resourceId === 'VIDEOCENTER' || + i.resourceId === 'BUILDINGPROJECT' || + i.resourceId === 'MAINTENANCESPOTCHECK' || + i.resourceId === 'LUZHENG' || + i.resourceId === 'ADJUSTLOG' + ) - return ( - user?.username == 'SuperAdmin' || isshow ? - } title={'数据管理'}> - {/* {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'OVERLOADMANAGE') ? + return ( + user?.username == 'SuperAdmin' || isshow ? + } title={'数据管理'}> + {/* {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'OVERLOADMANAGE') ? 治超管理 : ''} */} - {/* + {/* 任务管理 */} - - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'LUZHENG') ? - - 路政管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'ROADMANAGE') ? - - 道路管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'BRIDGEMANAGE') ? - - 桥梁管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'MAINTENANCEMANAGE') ? - - 管养管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'TRANSPORTATIONMANAGE') ? - - 运政管理 - : ''} - {/* + + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'LUZHENG') ? + + 路政管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'ROADMANAGE') ? + + 道路管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'BRIDGEMANAGE') ? + + 桥梁管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'MAINTENANCEMANAGE') ? + + 管养管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'TRANSPORTATIONMANAGE') ? + + 运政管理 + : ''} + {/* 执法管理 */} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'CONSERVATIONMANAGE') ? - - 养护管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PATROLMANAGE') ? - - 巡查管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'FEEDBACKMANAGE') ? - - 异常反馈 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'REPORTMANAGE') ? + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'CONSERVATIONMANAGE') ? + + 养护管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PATROLMANAGE') ? + + 巡查管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'FEEDBACKMANAGE') ? + + 异常反馈 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'REPORTMANAGE') ? - - 建设上报 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'BUILDINGPROJECT') ? - - 在建项目 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PUBLICTRANSPORTMANAGE') ? - - 公交管理 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'FILEMANAGE') ? - - 档案管理 - : ''} - {/* + + 建设上报 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'BUILDINGPROJECT') ? + + 在建项目 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PUBLICTRANSPORTMANAGE') ? + + 公交管理 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'FILEMANAGE') ? + + 档案管理 + : ''} + {/* 视频管理 */} - {/* + {/* 接口管理 */} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PUBLICITYVIDEO') ? - - 宣传视频 - : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'PUBLICITYVIDEO') ? + + 宣传视频 + : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'ASSESSMANAGE') ? - - 考核评分 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'VIDEOCENTER') ? - - 视频中心 - : ''} - {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'MAINTENANCESPOTCHECK') ? - - 养护抽查 - : ''} - : null - ); + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'ASSESSMANAGE') ? + + 考核评分 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'VIDEOCENTER') ? + + 视频中心 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'MAINTENANCESPOTCHECK') ? + + 养护抽查 + : ''} + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'ADJUSTLOG') ? + + 调整日志 + : ''} + : null + ); } diff --git a/web/client/src/sections/fillion/routes.js b/web/client/src/sections/fillion/routes.js index 9172cd69..bd4f6d1b 100644 --- a/web/client/src/sections/fillion/routes.js +++ b/web/client/src/sections/fillion/routes.js @@ -14,184 +14,193 @@ import { File } from './containers'; import { Jiekouguanli } from './containers' import { Task, Assess, VideoCenter, } from './containers' import { Building } from './containers' -import { MaintenanceSpotCheck } from './containers' +import { MaintenanceSpotCheckNew, AdjustLog } from './containers' import Luzheng from './containers/luzheng'; export default [{ - type: 'inner', - route: { - path: '/fillion', - key: 'fillion', - breadcrumb: '数据管理', - menuSelectKeys: ['fillion'], - menuOpenKeys: ['fillion'], - childRoutes: [{ - path: '/infor', - key: 'fillioninfor', - menuSelectKeys: ['fillioninfor'], - component: Infor, - breadcrumb: '治超管理', - authCode: 'OVERLOADMANAGE' - }, - { - path: '/luzheng', - key: 'luzheng', - menuSelectKeys: ['luzheng'], - component: Luzheng, - breadcrumb: '路政管理', - authCode: 'OVERLOADMANAGE' - }, - { - path: '/task', - key: 'filliontask', - menuSelectKeys: ['filliontask'], - component: Task, - breadcrumb: '任务管理', - //authCode: 'OVERLOADMANAGE' - }, { - path: '/transportation', - key: 'filliontransportation', - menuSelectKeys: ['filliontransportation'], - component: transportation, - breadcrumb: '道路管理', - authCode: 'ROADMANAGE' + type: 'inner', + route: { + path: '/fillion', + key: 'fillion', + breadcrumb: '数据管理', + menuSelectKeys: ['fillion'], + menuOpenKeys: ['fillion'], + childRoutes: [{ + path: '/infor', + key: 'fillioninfor', + menuSelectKeys: ['fillioninfor'], + component: Infor, + breadcrumb: '治超管理', + authCode: 'OVERLOADMANAGE' + }, + { + path: '/luzheng', + key: 'luzheng', + menuSelectKeys: ['luzheng'], + component: Luzheng, + breadcrumb: '路政管理', + authCode: 'OVERLOADMANAGE' + }, + { + path: '/task', + key: 'filliontask', + menuSelectKeys: ['filliontask'], + component: Task, + breadcrumb: '任务管理', + //authCode: 'OVERLOADMANAGE' + }, { + path: '/transportation', + key: 'filliontransportation', + menuSelectKeys: ['filliontransportation'], + component: transportation, + breadcrumb: '道路管理', + authCode: 'ROADMANAGE' - }, - { - path: '/processsing', - key: 'fillionprocesssing', - menuSelectKeys: ['fillionprocesssing'], - component: Building, - breadcrumb: '在建项目', - authCode: 'BUILDINGPROJECT' + }, + { + path: '/processsing', + key: 'fillionprocesssing', + menuSelectKeys: ['fillionprocesssing'], + component: Building, + breadcrumb: '在建项目', + authCode: 'BUILDINGPROJECT' - } - , { - path: '/bridge', - key: 'fillionbridge', - menuSelectKeys: ['fillionbridge'], - component: BridgeTable, - breadcrumb: '桥梁管理', - authCode: 'BRIDGEMANAGE' + } + , { + path: '/bridge', + key: 'fillionbridge', + menuSelectKeys: ['fillionbridge'], + component: BridgeTable, + breadcrumb: '桥梁管理', + authCode: 'BRIDGEMANAGE' - } - , { - path: '/highways', - key: 'fillionhighways', - menuSelectKeys: ['fillionhighways'], - component: HigHways, - breadcrumb: '管养管理', - authCode: 'MAINTENANCEMANAGE' + } + , { + path: '/highways', + key: 'fillionhighways', + menuSelectKeys: ['fillionhighways'], + component: HigHways, + breadcrumb: '管养管理', + authCode: 'MAINTENANCEMANAGE' - }, { - path: '/operational', - key: 'fillionoperational', - menuSelectKeys: ['fillionoperational'], - component: OperaTional, - breadcrumb: '运政管理', - authCode: 'TRANSPORTATIONMANAGE' + }, { + path: '/operational', + key: 'fillionoperational', + menuSelectKeys: ['fillionoperational'], + component: OperaTional, + breadcrumb: '运政管理', + authCode: 'TRANSPORTATIONMANAGE' - }, { - path: '/enforce', - key: 'fillionenforce', - menuSelectKeys: ['fillionenforce'], - component: Enforce, - breadcrumb: '执法管理', - }, { - path: '/maintenance', - key: 'fillionmaintenance', - menuSelectKeys: ['fillionmaintenance'], - component: Maintenance, - breadcrumb: '养护管理', - authCode: 'CONSERVATIONMANAGE' - }, { - path: '/patrol', - key: 'fillionpatrol', - menuSelectKeys: ['fillionpatrol'], - component: Patrol, - breadcrumb: '巡查管理', - authCode: 'PATROLMANAGE' + }, { + path: '/enforce', + key: 'fillionenforce', + menuSelectKeys: ['fillionenforce'], + component: Enforce, + breadcrumb: '执法管理', + }, { + path: '/maintenance', + key: 'fillionmaintenance', + menuSelectKeys: ['fillionmaintenance'], + component: Maintenance, + breadcrumb: '养护管理', + authCode: 'CONSERVATIONMANAGE' + }, { + path: '/patrol', + key: 'fillionpatrol', + menuSelectKeys: ['fillionpatrol'], + component: Patrol, + breadcrumb: '巡查管理', + authCode: 'PATROLMANAGE' - }, { - path: '/patrol_anomaly', - key: 'fillionpatrolanomaly', - menuSelectKeys: ['fillionpatrolanomaly'], - component: Patrol, - breadcrumb: '异常反馈', - authCode: 'FEEDBACKMANAGE' + }, { + path: '/patrol_anomaly', + key: 'fillionpatrolanomaly', + menuSelectKeys: ['fillionpatrolanomaly'], + component: Patrol, + breadcrumb: '异常反馈', + authCode: 'FEEDBACKMANAGE' - }, { - path: '/patrol_road', - key: 'fillionpatrolroad', - menuSelectKeys: ['fillionpatrolroad'], - component: Patrol, - breadcrumb: '建设上报', - authCode: 'REPORTMANAGE' + }, { + path: '/patrol_road', + key: 'fillionpatrolroad', + menuSelectKeys: ['fillionpatrolroad'], + component: Patrol, + breadcrumb: '建设上报', + authCode: 'REPORTMANAGE' - }, { - path: '/public', - key: 'fillionpublic', - menuSelectKeys: ['fillionpublic'], - component: Public, - breadcrumb: '公交管理', - authCode: 'PUBLICTRANSPORTMANAGE' + }, { + path: '/public', + key: 'fillionpublic', + menuSelectKeys: ['fillionpublic'], + component: Public, + breadcrumb: '公交管理', + authCode: 'PUBLICTRANSPORTMANAGE' - }, - { - path: '/file', - key: 'fileCont', - menuSelectKeys: ['fileCont'], - component: File, - breadcrumb: '档案管理', - authCode: 'FILEMANAGE' + }, + { + path: '/file', + key: 'fileCont', + menuSelectKeys: ['fileCont'], + component: File, + breadcrumb: '档案管理', + authCode: 'FILEMANAGE' - }, - { - path: '/videois', - key: 'fillionvideois', - menuSelectKeys: ['fillionvideois'], - component: Videois, - breadcrumb: '视频管理', - authCode: 'PUBLICITYVIDEO' + }, + { + path: '/videois', + key: 'fillionvideois', + menuSelectKeys: ['fillionvideois'], + component: Videois, + breadcrumb: '视频管理', + authCode: 'PUBLICITYVIDEO' - }, - { - path: '/jiekouguanli', - key: 'jiekouguanli', - menuSelectKeys: ['jiekouguanli'], - component: Jiekouguanli, - breadcrumb: '接口管理', - }, { - path: '/promotional', - key: 'fillionpromotional', - menuSelectKeys: ['fillionpromotional'], - component: PromoTional, - breadcrumb: '视频管理', - authCode: 'PUBLICITYVIDEO' - }, { - path: '/assess', - key: 'fillionassess', - menuSelectKeys: ['fillionassess'], - component: Assess, - breadcrumb: '考核评分', - authCode: 'ASSESSMANAGE' - }, { - path: '/videoCenter', - key: 'fillionvideoCenter', - menuSelectKeys: ['fillionvideoCenter'], - component: VideoCenter, - breadcrumb: '视频中心', - authCode: 'VIDEOCENTER' + }, + { + path: '/jiekouguanli', + key: 'jiekouguanli', + menuSelectKeys: ['jiekouguanli'], + component: Jiekouguanli, + breadcrumb: '接口管理', + }, { + path: '/promotional', + key: 'fillionpromotional', + menuSelectKeys: ['fillionpromotional'], + component: PromoTional, + breadcrumb: '视频管理', + authCode: 'PUBLICITYVIDEO' + }, { + path: '/assess', + key: 'fillionassess', + menuSelectKeys: ['fillionassess'], + component: Assess, + breadcrumb: '考核评分', + authCode: 'ASSESSMANAGE' + }, { + path: '/videoCenter', + key: 'fillionvideoCenter', + menuSelectKeys: ['fillionvideoCenter'], + component: VideoCenter, + breadcrumb: '视频中心', + authCode: 'VIDEOCENTER' - }, - { - path: '/maintenanceSpotCheck', - key: 'maintenanceSpotCheck', - menuSelectKeys: ['maintenanceSpotCheck'], - component: MaintenanceSpotCheck, - breadcrumb: '养护抽查', - authCode: 'MAINTENANCESPOTCHECK' + }, + { + path: '/maintenanceSpotCheck', + key: 'maintenanceSpotCheck', + menuSelectKeys: ['maintenanceSpotCheck'], + component: MaintenanceSpotCheckNew, + breadcrumb: '养护抽查', + authCode: 'MAINTENANCESPOTCHECK' - } - ] - } + }, + { + path: '/adjustLog', + key: 'adjustLog', + menuSelectKeys: ['adjustLog'], + component: AdjustLog, + breadcrumb: '调整日志', + authCode: 'ADJUSTLOG' + + } + ] + } }]; diff --git a/web/client/src/sections/organization/containers/authority.js b/web/client/src/sections/organization/containers/authority.js index 66b8ab89..c745e478 100644 --- a/web/client/src/sections/organization/containers/authority.js +++ b/web/client/src/sections/organization/containers/authority.js @@ -9,282 +9,282 @@ import Resource from '../components/resource'; import user from './user'; const Authority = (props) => { - const CheckboxGroup = Checkbox.Group; - const { dispatch, loading, depMessage, depUser, resource, userResource, clientHeight, user } = props - const r1 = ['USERMANAGE', 'AUTHORIMANAGE', 'OVERLOADMANAGE', 'ROADMANAGE', 'BRIDGEMANAGE', 'MAINTENANCEMANAGE', 'TRANSPORTATIONMANAGE', - 'CONSERVATIONMANAGE', 'PATROLMANAGE', 'PUBLICTRANSPORTMANAGE', 'FILEMANAGE', 'PUBLICITYVIDEO', 'FEEDBACKMANAGE', 'REPORTMANAGE', - 'ASSESSMANAGE', 'VIDEOCENTER', 'BUILDINGPROJECT', 'WXPATROLREPORT', 'WXMAINTENANCEREPORT', 'WXFEEDBACKMANAGE', 'WXBUILDINGROAD', - 'WXTODOANDONE', 'MAINTENANCESPOTCHECK' - ] - const [depUserCopy, setDepUserCopy] = useState([])//用于存放除了自己的管理的数组,即自己不能调整自己是否为管理员 - const [depSelectedKeys, setDepSelectedKeys] = useState([]) - const [userSelectedKeys, setUserSelectedKeys] = useState([]) - const [depSelected, setDepSelected] = useState() - const [userSelected, setUserSelected] = useState() - const [resCode, setResCode] = useState(userResource.map(i => i.resourceId)) - const [useName, setUseName] = useState()// 选中名字 - const [userType, setUserType] = useState() - const [depMessagedata, setdepMessagedata] = useState(depMessage) + const CheckboxGroup = Checkbox.Group; + const { dispatch, loading, depMessage, depUser, resource, userResource, clientHeight, user } = props + const r1 = ['USERMANAGE', 'AUTHORIMANAGE', 'OVERLOADMANAGE', 'ROADMANAGE', 'BRIDGEMANAGE', 'MAINTENANCEMANAGE', 'TRANSPORTATIONMANAGE', + 'CONSERVATIONMANAGE', 'PATROLMANAGE', 'PUBLICTRANSPORTMANAGE', 'FILEMANAGE', 'PUBLICITYVIDEO', 'FEEDBACKMANAGE', 'REPORTMANAGE', + 'ASSESSMANAGE', 'VIDEOCENTER', 'BUILDINGPROJECT', 'WXPATROLREPORT', 'WXMAINTENANCEREPORT', 'WXFEEDBACKMANAGE', 'WXBUILDINGROAD', + 'WXTODOANDONE', 'MAINTENANCESPOTCHECK', 'ADJUSTLOG' + ] + const [depUserCopy, setDepUserCopy] = useState([])//用于存放除了自己的管理的数组,即自己不能调整自己是否为管理员 + const [depSelectedKeys, setDepSelectedKeys] = useState([]) + const [userSelectedKeys, setUserSelectedKeys] = useState([]) + const [depSelected, setDepSelected] = useState() + const [userSelected, setUserSelected] = useState() + const [resCode, setResCode] = useState(userResource.map(i => i.resourceId)) + const [useName, setUseName] = useState()// 选中名字 + const [userType, setUserType] = useState() + const [depMessagedata, setdepMessagedata] = useState(depMessage) - const rescodeall = resource[0]?.resources?.map(i => ({ label: i.name, value: i.code })) - //console.log(resource[0]?.resources?.map(i => ({ label: i.name, value: i.code })), '这个是总的骂') - const [indeterminate, setIndeterminate] = useState(false); - const [checkAll, setCheckAll] = useState(true); - const [rescheckAll, setrescheckAll] = useState(false) - const [isshow, setisshow] = useState(false); + const rescodeall = resource[0]?.resources?.map(i => ({ label: i.name, value: i.code })) + //console.log(resource[0]?.resources?.map(i => ({ label: i.name, value: i.code })), '这个是总的骂') + const [indeterminate, setIndeterminate] = useState(false); + const [checkAll, setCheckAll] = useState(true); + const [rescheckAll, setrescheckAll] = useState(false) + const [isshow, setisshow] = useState(false); - let plainOptions = depUser.map(i => ({ label: i.name, value: i.id })); - const [checkedList, setCheckedList] = useState(depUser.map(i => i.id)); - const onChange = (list) => { - // console.log(list,'选择的') - setCheckedList(list); - setIndeterminate(!!list.length && list.length < plainOptions.length); - // setResCode(userResource.map(i=>i.resourceId)) - setCheckAll(list.length === plainOptions.length); - dispatch(getUserResource(list)) - // if(list.length === plainOptions.length){ - // setUseName('全部用户') - // } - }; + let plainOptions = depUser.map(i => ({ label: i.name, value: i.id })); + const [checkedList, setCheckedList] = useState(depUser.map(i => i.id)); + const onChange = (list) => { + // console.log(list,'选择的') + setCheckedList(list); + setIndeterminate(!!list.length && list.length < plainOptions.length); + // setResCode(userResource.map(i=>i.resourceId)) + setCheckAll(list.length === plainOptions.length); + dispatch(getUserResource(list)) + // if(list.length === plainOptions.length){ + // setUseName('全部用户') + // } + }; - // console.log(userSelectedKeys,'当前1') - const onresChange = (d) => { - setResCode(d) - setrescheckAll(d.length === r1.length) - } - const onresCheckAllChange = (d) => { - setrescheckAll(d.target.checked) - setResCode(d.target.checked ? r1 : []) + // console.log(userSelectedKeys,'当前1') + const onresChange = (d) => { + setResCode(d) + setrescheckAll(d.length === r1.length) + } + const onresCheckAllChange = (d) => { + setrescheckAll(d.target.checked) + setResCode(d.target.checked ? r1 : []) - } - const onCheckAllChange = (e) => { - setCheckedList(e.target.checked ? plainOptions.map(i => i.value) : []); - setIndeterminate(false); - // if(e.target.checked){ - // setUseName('全部用户') - // } + } + const onCheckAllChange = (e) => { + setCheckedList(e.target.checked ? plainOptions.map(i => i.value) : []); + setIndeterminate(false); + // if(e.target.checked){ + // setUseName('全部用户') + // } - setCheckAll(e.target.checked); - // setResCode(userResource.map(i=>i.resourceId)) - }; - const onshowchange = (e) => { - setisshow(e.target.checked) - } - //console.log('depMessagedata', depMessagedata) + setCheckAll(e.target.checked); + // setResCode(userResource.map(i=>i.resourceId)) + }; + const onshowchange = (e) => { + setisshow(e.target.checked) + } + //console.log('depMessagedata', depMessagedata) - useEffect(() => { - dispatch(getResource()) - if (!(depMessage && depMessage.length)) { - dispatch(getDepMessage()) - } - setResCode(userResource.map(i => i.resourceId)) - setisshow(userResource.some(i => i.isshow === "true")) - setrescheckAll(userResource.map(i => i.resourceId).length === 14) - }, []) - useEffect(() => { - setResCode(userResource.map(i => i.resourceId)) - setisshow(userResource.some(i => i.isshow === "true")) - setrescheckAll(userResource.map(i => i.resourceId).length === 14) - }, [userResource]) - useEffect(async () => { - if (depMessage.length) { - //('depMessage', depMessage) - //超级管理员展示所有部门 - if (user?.username === 'SuperAdmin') { - setdepMessagedata(depMessage) - dispatch(getDepUser(depMessage[0]?.id)) - setDepSelectedKeys([depMessage[0]?.id]) - setDepSelected([depMessage[0]?.name]) - } else { - //不是超级管理员,展示相应部门的数据 - dispatch(getDepUser(user.departmentId)) - const res = await dispatch(getDepById({ deptId: parseInt(user.departmentId) })) - //console.log('resssss', res) - setdepMessagedata(res.payload.data) - // if (authDep.length > 0) { - // dispatch(getDepUser(authDep[0]?.id)) - // setDepSelectedKeys([authDep[0]?.id]) - // setDepSelected([authDep[0]?.name]) - // } - } + useEffect(() => { + dispatch(getResource()) + if (!(depMessage && depMessage.length)) { + dispatch(getDepMessage()) + } + setResCode(userResource.map(i => i.resourceId)) + setisshow(userResource.some(i => i.isshow === "true")) + setrescheckAll(userResource.map(i => i.resourceId).length === 14) + }, []) + useEffect(() => { + setResCode(userResource.map(i => i.resourceId)) + setisshow(userResource.some(i => i.isshow === "true")) + setrescheckAll(userResource.map(i => i.resourceId).length === 14) + }, [userResource]) + useEffect(async () => { + if (depMessage.length) { + //('depMessage', depMessage) + //超级管理员展示所有部门 + if (user?.username === 'SuperAdmin') { + setdepMessagedata(depMessage) + dispatch(getDepUser(depMessage[0]?.id)) + setDepSelectedKeys([depMessage[0]?.id]) + setDepSelected([depMessage[0]?.name]) + } else { + //不是超级管理员,展示相应部门的数据 + dispatch(getDepUser(user.departmentId)) + const res = await dispatch(getDepById({ deptId: parseInt(user.departmentId) })) + //console.log('resssss', res) + setdepMessagedata(res.payload.data) + // if (authDep.length > 0) { + // dispatch(getDepUser(authDep[0]?.id)) + // setDepSelectedKeys([authDep[0]?.id]) + // setDepSelected([authDep[0]?.name]) + // } + } - } + } - }, [depMessage]) - // useEffect(() => { - // if(user.username!=='SuperAdmin'){ - // dispatch(getDepMessage(user.departmentId)) - // } - // }, [depMessage]) - useEffect(() => { - const copy = [...new Set(depUser)] - setDepUserCopy(copy) - if (copy.length) { - setUserSelectedKeys([copy[0].id]) - setUserSelected(copy[0].username) - dispatch(getUserResource(copy[0].id)) - setUseName(copy[0].name) - } - setCheckedList(copy.map(i => i.id)) - }, [depUser]) - // console.log(depUser,'用户信息') - const handleSave = () => { - // console.log( userSelectedKeys[0],'当前选中的id') - // checkedList.map(i=>{ - // dispatch(postUserRes({ userId: i, resCode: resCode,isShow:isshow })).then(res => { - // if (res.success) { - // dispatch(getUserResource(i)) - // } - // }) - // dispatch(postUserReso({ userId: i, resCode: resCode,isShow:isshow })) - // }) + }, [depMessage]) + // useEffect(() => { + // if(user.username!=='SuperAdmin'){ + // dispatch(getDepMessage(user.departmentId)) + // } + // }, [depMessage]) + useEffect(() => { + const copy = [...new Set(depUser)] + setDepUserCopy(copy) + if (copy.length) { + setUserSelectedKeys([copy[0].id]) + setUserSelected(copy[0].username) + dispatch(getUserResource(copy[0].id)) + setUseName(copy[0].name) + } + setCheckedList(copy.map(i => i.id)) + }, [depUser]) + // console.log(depUser,'用户信息') + const handleSave = () => { + // console.log( userSelectedKeys[0],'当前选中的id') + // checkedList.map(i=>{ + // dispatch(postUserRes({ userId: i, resCode: resCode,isShow:isshow })).then(res => { + // if (res.success) { + // dispatch(getUserResource(i)) + // } + // }) + // dispatch(postUserReso({ userId: i, resCode: resCode,isShow:isshow })) + // }) - dispatch(postUserRes({ userId: userSelectedKeys[0], resCode: resCode, isShow: isshow })).then(res => { - if (res.success) { - dispatch(getUserResource(userSelectedKeys[0])) - } - }) - dispatch(postUserReso({ userId: userSelectedKeys[0], resCode: resCode, isShow: isshow })) - } + dispatch(postUserRes({ userId: userSelectedKeys[0], resCode: resCode, isShow: isshow })).then(res => { + if (res.success) { + dispatch(getUserResource(userSelectedKeys[0])) + } + }) + dispatch(postUserReso({ userId: userSelectedKeys[0], resCode: resCode, isShow: isshow })) + } - return ( - - - - - { - depMessagedata.length ? - { - setUserType(selectedNodes[0].type) - setCheckedList(depUserCopy.map(i => i.id)) - // setResCode(userResource.map(i=>i.resourceId)) + return ( + + + + + { + depMessagedata.length ? + { + setUserType(selectedNodes[0].type) + setCheckedList(depUserCopy.map(i => i.id)) + // setResCode(userResource.map(i=>i.resourceId)) - if (selected) { - setCheckedList(depUserCopy.map(i => i.id)) - setDepSelectedKeys(selectedKeys) - setDepSelected(selectedNodes[0].name || "") - dispatch(getDepUser(selectedKeys[0])) + if (selected) { + setCheckedList(depUserCopy.map(i => i.id)) + setDepSelectedKeys(selectedKeys) + setDepSelected(selectedNodes[0].name || "") + dispatch(getDepUser(selectedKeys[0])) - // setResCode(userResource.map(i=>i.resourceId)) + // setResCode(userResource.map(i=>i.resourceId)) - } + } - }} - treeData={depMessagedata} - fieldNames={{ - title: 'name', - key: 'id', - children: 'subordinate' - }} - /> : '' - } - - - - - { - depUserCopy?.length ? - { - const name = node.name - setUseName(name) + }} + treeData={depMessagedata} + fieldNames={{ + title: 'name', + key: 'id', + children: 'subordinate' + }} + /> : '' + } + + + + + { + depUserCopy?.length ? + { + const name = node.name + setUseName(name) - if (selected) { - // console.log(selectedKeys,'选中的selectedKeys') - // console.log(selectedNodes[0].username || '','node') - // console.log(selectedKeys[0],'请求的值') - setUserSelectedKeys(selectedKeys) - setUserSelected(selectedNodes[0].username || '') - dispatch(getUserResource(selectedKeys[0])) - } + if (selected) { + // console.log(selectedKeys,'选中的selectedKeys') + // console.log(selectedNodes[0].username || '','node') + // console.log(selectedKeys[0],'请求的值') + setUserSelectedKeys(selectedKeys) + setUserSelected(selectedNodes[0].username || '') + dispatch(getUserResource(selectedKeys[0])) + } - }} - treeData={depUserCopy} - fieldNames={{ - title: 'name', - key: 'id' - }} - /> : + }} + treeData={depUserCopy} + fieldNames={{ + title: 'name', + key: 'id' + }} + /> : - //
- // i.resourceId==='AUTHORIMANAGE')[0].isShow==="true"?true:''}> - // 全选 - // + //
+ // i.resourceId==='AUTHORIMANAGE')[0].isShow==="true"?true:''}> + // 全选 + // - // i.resourceId==='AUTHORIMANAGE')[0].isShow==="true"?true:''}/> - //
: + // i.resourceId==='AUTHORIMANAGE')[0].isShow==="true"?true:''}/> + //
: - } -
- - - i.resourceId === 'AUTHORIMANAGE')[0]?.isshow === "true" ? true : ''}> - 不可编辑 - - {depUserCopy?.length ? - - {/* + + + i.resourceId === 'AUTHORIMANAGE')[0]?.isshow === "true" ? true : ''}> + 不可编辑 + + {depUserCopy?.length ? + + {/* i.resourceId==='AUTHORIMANAGE')[0].isShow==="true"?4:userType} /> */} -
- i.resourceId === 'AUTHORIMANAGE')[0].isshow === "true" ? true : ''} - > - 全选 - - i.resourceId === 'AUTHORIMANAGE')[0].isshow === "true" ? true : ''} - /> -
- -
- - - - : - - - } - - - - ) +
+ i.resourceId === 'AUTHORIMANAGE')[0].isshow === "true" ? true : ''} + > + 全选 + + i.resourceId === 'AUTHORIMANAGE')[0].isshow === "true" ? true : ''} + /> +
+ + + + + + : + + + } + + + + ) } -function mapStateToProps(state) { - const { userResource, resource, depMessage, depUser, global, auth } = state; - return { - clientHeight: global.clientHeight, - loading: depMessage.isRequesting || depUser.isRequesting || resource.isRequesting, - userResource: userResource.data || [], - resource: resource.data || [], - depMessage: depMessage.data || [], - depUser: depUser.data || [], - user: auth.user - }; +function mapStateToProps (state) { + const { userResource, resource, depMessage, depUser, global, auth } = state; + return { + clientHeight: global.clientHeight, + loading: depMessage.isRequesting || depUser.isRequesting || resource.isRequesting, + userResource: userResource.data || [], + resource: resource.data || [], + depMessage: depMessage.data || [], + depUser: depUser.data || [], + user: auth.user + }; } export default connect(mapStateToProps)(Authority); \ No newline at end of file From 9d19758f6291e24d4d14e53323247fd52e7a067e Mon Sep 17 00:00:00 2001 From: wenlele Date: Mon, 11 Dec 2023 11:18:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/client/src/sections/fillion/nav-item.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/client/src/sections/fillion/nav-item.js b/web/client/src/sections/fillion/nav-item.js index 0632ac88..cd1142da 100644 --- a/web/client/src/sections/fillion/nav-item.js +++ b/web/client/src/sections/fillion/nav-item.js @@ -28,10 +28,10 @@ export function getNavItem (user, dispatch) { return ( user?.username == 'SuperAdmin' || isshow ? } title={'数据管理'}> - {/* {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'OVERLOADMANAGE') ? + {user?.username == 'SuperAdmin' || user?.userResources?.some(i => i.resourceId === 'OVERLOADMANAGE') ? 治超管理 - : ''} */} + : ''} {/* 任务管理 */} From 502f6397d79767bed2bcc428cf13ee57217ef0db Mon Sep 17 00:00:00 2001 From: wenlele Date: Mon, 11 Dec 2023 11:18:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/data/road.js | 317 +-- api/app/lib/controllers/report/index.js | 1919 ++++++++--------- .../src/sections/fillion/actions/infor.js | 100 +- .../src/sections/fillion/actions/spotCheck.js | 98 +- .../sections/fillion/components/adjustment.js | 181 ++ .../sections/fillion/containers/adjustLog.js | 841 ++------ .../containers/maintenanceSpotCheck-new.js | 526 ++--- 7 files changed, 1793 insertions(+), 2189 deletions(-) create mode 100644 web/client/src/sections/fillion/components/adjustment.js diff --git a/api/app/lib/controllers/data/road.js b/api/app/lib/controllers/data/road.js index b6b34d79..5021be60 100644 --- a/api/app/lib/controllers/data/road.js +++ b/api/app/lib/controllers/data/road.js @@ -2,176 +2,179 @@ const roadKeyMap = require('./road.json') async function importIn (ctx) { - // 数据导入 - try { - const models = ctx.fs.dc.models; - const { level, } = ctx.query; - const data = ctx.request.body; - - const roadRes = await models.Road.findAll({ - where: { - level - } - }) - let preCreateArr = [] - for (let d of data) { - if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { - //repeat - } else { - // await models.Road.create(d); - } - } - - 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 - } - } + // 数据导入 + try { + const models = ctx.fs.dc.models; + const { level, } = ctx.query; + const data = ctx.request.body; + + const roadRes = await models.Road.findAll({ + where: { + level + } + }) + let preCreateArr = [] + for (let d of data) { + if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { + //repeat + } else { + // await models.Road.create(d); + } + } + + 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 + } + } } async function get (ctx) { - try { - const models = ctx.fs.dc.models; - const { codePrefix, level, road, sectionStart, sectionEnd } = ctx.query; - - let findOption = { - where: {}, - order: [['id', 'DESC']] - } - - if (codePrefix) { - findOption.where.routeCode = { $like: `${codePrefix}%` } - } - - if (level) { - findOption.where.level = level - } - if (road || sectionStart || sectionEnd) { - findOption.where['$or'] = {} - if (road) { - findOption.where['$or']. - routeName = { $like: `%${road}%` } - } - if (sectionStart) { - findOption.where['$or']. - startingPlaceName = { $like: `%${sectionStart}%` } - - } - if (sectionEnd) { - findOption.where['$or']. - stopPlaceName = { $like: `%${sectionEnd}%` } - - } - } - - const roadRes = await models.Road.findAll(findOption) - - ctx.status = 200; - ctx.body = roadRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { codePrefix, level, road, sectionStart, sectionEnd, alterId } = ctx.query; + + let findOption = { + where: {}, + order: [['id', 'DESC']] + } + if (alterId) { + findOption.where.id = { $notIn: alterId } + } + + if (codePrefix) { + findOption.where.routeCode = { $like: `${codePrefix}%` } + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or']. + routeName = { $like: `%${road}%` } + } + if (sectionStart) { + findOption.where['$or']. + startingPlaceName = { $like: `%${sectionStart}%` } + + } + if (sectionEnd) { + findOption.where['$or']. + stopPlaceName = { $like: `%${sectionEnd}%` } + + } + } + + const roadRes = await models.Road.findAll(findOption) + + ctx.status = 200; + ctx.body = roadRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function getRoadSection (ctx) { - try { - const models = ctx.fs.dc.models; - const { level, road, sectionStart, sectionEnd } = ctx.query; - let findOption = { - where: {}, - order: [['id', 'DESC']], - attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode'] - } - - if (level) { - findOption.where.level = level - } - if (road || sectionStart || sectionEnd) { - findOption.where['$or'] = {} - if (road) { - findOption.where['$or']. - routeName = { $like: `%${road}%` } - } - if (sectionStart) { - findOption.where['$or']. - startingPlaceName = { $like: `%${sectionStart}%` } - - } - if (sectionEnd) { - findOption.where['$or']. - stopPlaceName = { $like: `%${sectionEnd}%` } - } - } - - const roadRes = await models.Road.findAll(findOption) - - ctx.status = 200; - ctx.body = roadRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { level, road, sectionStart, sectionEnd } = ctx.query; + let findOption = { + where: {}, + order: [['id', 'DESC']], + attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode'] + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or']. + routeName = { $like: `%${road}%` } + } + if (sectionStart) { + findOption.where['$or']. + startingPlaceName = { $like: `%${sectionStart}%` } + + } + if (sectionEnd) { + findOption.where['$or']. + stopPlaceName = { $like: `%${sectionEnd}%` } + } + } + + const roadRes = await models.Road.findAll(findOption) + + ctx.status = 200; + ctx.body = roadRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function edit (ctx) { - try { - const models = ctx.fs.dc.models; - const data = ctx.request.body; - - if (!data.roadId) { - await models.Road.create(data) - } else { - await models.Road.update( - data, { - where: { - id: data.roadId - } - }) - } - - 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 - } - } + try { + const models = ctx.fs.dc.models; + const data = ctx.request.body; + + if (!data.roadId) { + await models.Road.create(data) + } else { + await models.Road.update( + data, { + where: { + id: data.roadId + } + }) + } + + 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 + } + } } async function del (ctx) { - try { - const models = ctx.fs.dc.models; - const { roadId } = ctx.params; - - await models.Road.destroy({ - where: { - id: roadId - } - }) - - 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 - } - } + try { + const models = ctx.fs.dc.models; + const { roadId } = ctx.params; + + await models.Road.destroy({ + where: { + id: roadId + } + }) + + 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 = { - importIn, - getRoadSection, - get, edit, del, + importIn, + getRoadSection, + get, edit, del, }; \ No newline at end of file diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index 1df99b5e..db9ade4b 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -4,21 +4,21 @@ const moment = require('moment'); const xlsxDownload = require('../../../../utils/xlsxDownload.js'); const fs = require('fs'); 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 - const { userInfo } = ctx.fs.api - const sequelize = ctx.fs.dc.orm; - - let findUsers = [] - if ( - userInfo.loginSource == 'wx' - && userInfo.isAdmin - && userInfo.phone != 'SuperAdmin' - && (!performerId && !handleState) - ) { - // 是管理员但不是超管 查自己部门及下级部门的所有用户的信息 - const sqlStr = ` + try { + const models = ctx.fs.dc.models; + const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType, handleState = '', performerId = '', codeRoad } = ctx.query + const { userInfo } = ctx.fs.api + const sequelize = ctx.fs.dc.orm; + + let findUsers = [] + if ( + userInfo.loginSource == 'wx' + && userInfo.isAdmin + && userInfo.phone != 'SuperAdmin' + && (!performerId && !handleState) + ) { + // 是管理员但不是超管 查自己部门及下级部门的所有用户的信息 + const sqlStr = ` WITH RECURSIVE sub_departments AS ( SELECT id, dependence FROM department @@ -34,288 +34,288 @@ async function reportList (ctx) { WHERE u.delete = false; ` - const res = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) - findUsers = res.map(item => { - return item.id - }) - findUsers.push(-1) - } - - let findOption = { - where: { - - }, - attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'performerId', 'roadSectionEnd', 'reportType', 'address', - 'content', 'longitude', 'latitude', 'projectName', 'handleState', 'codeRoad', 'handleContent', 'handlePic', 'videoUrl', - 'scenePic'], - include: [{ - model: models.User, - attributes: ['name'] - }], - //order: [['time', asc ? 'ASC' : 'DESC']], - order: [['time', 'DESC']], - - } - if (limit) { - findOption.limit = limit - } - if (page && limit) { - findOption.offset = page * limit - } - if (startTime && endTime) { - findOption.where = { - time: { - '$between': [startTime, endTime] - } + const res = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) + findUsers = res.map(item => { + return item.id + }) + findUsers.push(-1) + } + + let findOption = { + where: { + + }, + attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'performerId', 'roadSectionEnd', 'reportType', 'address', + 'content', 'longitude', 'latitude', 'projectName', 'handleState', 'codeRoad', 'handleContent', 'handlePic', 'videoUrl', + 'scenePic'], + include: [{ + model: models.User, + attributes: ['name'] + }], + //order: [['time', asc ? 'ASC' : 'DESC']], + order: [['time', 'DESC']], + + } + if (limit) { + findOption.limit = limit + } + if (page && limit) { + findOption.offset = page * limit + } + if (startTime && endTime) { + findOption.where = { + time: { + '$between': [startTime, endTime] } - } - if (keyword) { - if (reportType == 'road') { - findOption.where.projectName = { - '$like': `%${keyword}%` - } - } else { - findOption.where.road = { - '$like': `%${keyword}%` - } + } + } + if (keyword) { + if (reportType == 'road') { + findOption.where.projectName = { + '$like': `%${keyword}%` } - } - if (userId) { - findOption.where.userId = { $in: userId.split(',').map(Number) } - } - if (findUsers.length) { - findOption.where.userId = { $in: findUsers } - } - if (reportType) { - findOption.where.reportType = reportType - } - if (projectType) { - findOption.where.projectType = projectType - } - if (performerId) { - let performerIds = performerId.split(',') - findOption.where.performerId = { $in: performerIds } - } - if (handleState) { - let handleStates = handleState.split(',') - findOption.where.handleState = { $in: handleStates } - } - if (codeRoad) { - findOption.where.codeRoad = codeRoad - } - - let reportRes = null; - - if (isTop) { - const sqlStr = ` + } else { + findOption.where.road = { + '$like': `%${keyword}%` + } + } + } + if (userId) { + findOption.where.userId = { $in: userId.split(',').map(Number) } + } + if (findUsers.length) { + findOption.where.userId = { $in: findUsers } + } + if (reportType) { + findOption.where.reportType = reportType + } + if (projectType) { + findOption.where.projectType = projectType + } + if (performerId) { + let performerIds = performerId.split(',') + findOption.where.performerId = { $in: performerIds } + } + if (handleState) { + let handleStates = handleState.split(',') + findOption.where.handleState = { $in: handleStates } + } + if (codeRoad) { + findOption.where.codeRoad = codeRoad + } + + let reportRes = null; + + if (isTop) { + const sqlStr = ` select NR.*, "user".name as user_name from (SELECT R.*, "row_number"() OVER (PARTITION BY R.user_id ORDER BY R."time" DESC) AS NEWINDEX FROM report AS R ${reportType ? ` where report_type = '${reportType}' `: '' - } + } ) AS NR left join "user" on "user".id = NR.user_id WHERE NEWINDEX = 1 order by id desc; ` - reportRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }); - if (reportType == 'road') { - const projectNameArr = reportRes.map(item => item.project_name).filter(item => item) - const projectRes = projectNameArr.length ? await models.Project.findAll({ - where: { - entryName: { $in: projectNameArr } - } - }) : [] - for (let r of reportRes) { - let corProject = projectRes.find(item => item.entryName == r.project_name) - if (corProject) { - r.project = corProject.dataValues - } - } + reportRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }); + if (reportType == 'road') { + const projectNameArr = reportRes.map(item => item.project_name).filter(item => item) + const projectRes = projectNameArr.length ? await models.Project.findAll({ + where: { + entryName: { $in: projectNameArr } + } + }) : [] + for (let r of reportRes) { + let corProject = projectRes.find(item => item.entryName == r.project_name) + if (corProject) { + r.project = corProject.dataValues + } } - } else { - reportRes = await models.Report.findAll(findOption) - } - - ctx.status = 200; - ctx.body = reportRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + } + } else { + reportRes = await models.Report.findAll(findOption) + } + + ctx.status = 200; + ctx.body = reportRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function reportPosition (ctx) { - try { - const models = ctx.fs.dc.models; - const { startTime, endTime, userId, reportType } = ctx.query - const sequelize = ctx.fs.dc.ORM; - - let findMxTimeOption = { - attributes: [ - 'userId', - [sequelize.fn('MAX', sequelize.col('time')), 'maxTime'], - ], - where: { - - }, - group: ['report.user_id'], - } - - if (startTime && endTime) { - findMxTimeOption.where = { - time: { - '$between': [startTime, endTime] - } - } - } - - if (userId) { - findMxTimeOption.where.userId = userId - } - if (reportType) { - findMxTimeOption.where.reportType = reportType - } - - const reportMaxTimeRes = await models.Report.findAll(findMxTimeOption) - const timeArr = reportMaxTimeRes.map(item => item.dataValues.maxTime) - const reportRes = await models.Report.findAll({ - where: { - time: { '$in': timeArr } + try { + const models = ctx.fs.dc.models; + const { startTime, endTime, userId, reportType } = ctx.query + const sequelize = ctx.fs.dc.ORM; + + let findMxTimeOption = { + attributes: [ + 'userId', + [sequelize.fn('MAX', sequelize.col('time')), 'maxTime'], + ], + where: { + + }, + group: ['report.user_id'], + } + + if (startTime && endTime) { + findMxTimeOption.where = { + time: { + '$between': [startTime, endTime] } - }) - ctx.status = 200; - ctx.body = reportRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + } + } + + if (userId) { + findMxTimeOption.where.userId = userId + } + if (reportType) { + findMxTimeOption.where.reportType = reportType + } + + const reportMaxTimeRes = await models.Report.findAll(findMxTimeOption) + const timeArr = reportMaxTimeRes.map(item => item.dataValues.maxTime) + const reportRes = await models.Report.findAll({ + where: { + time: { '$in': timeArr } + } + }) + ctx.status = 200; + ctx.body = reportRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function reportDetail (ctx) { - try { - const models = ctx.fs.dc.models; - const { reportId } = ctx.params - - const reportRes = await models.Report.findOne({ - where: { - id: reportId - } - }) - - ctx.status = 200; - ctx.body = reportRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { reportId } = ctx.params + + const reportRes = await models.Report.findOne({ + where: { + id: reportId + } + }) + + ctx.status = 200; + ctx.body = reportRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function reportHandle (ctx) { - try { - const { models } = ctx.fs.dc; - - const { reportId } = ctx.params - const { handleState } = ctx.request.body - const data = ctx.request.body - /** - * data = { - * handleState, - * handleContent, - * handlePic - * } - */ - await models.Report.update(data, { - where: { - id: reportId - } - }) - - ctx.status = 200; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const { models } = ctx.fs.dc; + + const { reportId } = ctx.params + const { handleState } = ctx.request.body + const data = ctx.request.body + /** + * data = { + * handleState, + * handleContent, + * handlePic + * } + */ + await models.Report.update(data, { + where: { + id: reportId + } + }) + + ctx.status = 200; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function createReport (ctx) { - try { - const { userId } = ctx.fs.api - const models = ctx.fs.dc.models; - const data = ctx.request.body; - - await models.Report.create({ - ...data, - userId, - time: new Date(), - }) - - 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 - } - } + try { + const { userId } = ctx.fs.api + const models = ctx.fs.dc.models; + const data = ctx.request.body; + + await models.Report.create({ + ...data, + userId, + time: new Date(), + }) + + 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 + } + } } async function deleteReport (ctx) { - try { - const models = ctx.fs.dc.models; - const { reportId } = ctx.params; - - await models.Report.destroy({ - where: { - id: reportId - } - }) - - 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 - } - } + try { + const models = ctx.fs.dc.models; + const { reportId } = ctx.params; + + await models.Report.destroy({ + where: { + id: reportId + } + }) + + 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 + } + } } // TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回 async function spotPrepare (ctx) { - try { - const { models } = ctx.fs.dc; - const sequelize = ctx.fs.dc.orm; - const { percentage } = ctx.request.body; - const departmentIdRes = await models.Department.findAll({ - attributes: ['id', 'name'], - where: { - dependence: null, - delete: false, - } - }) - let lukyDepartment = '' - if (departmentIdRes.length) { - lukyDepartment = departmentIdRes[(Math.round(Math.random() * departmentIdRes.length) || 1) - 1] - } else { - throw `暂无乡镇信息` - } - - const sqlStr = ` + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + const { percentage } = ctx.request.body; + const departmentIdRes = await models.Department.findAll({ + attributes: ['id', 'name'], + where: { + dependence: null, + delete: false, + } + }) + let lukyDepartment = '' + if (departmentIdRes.length) { + lukyDepartment = departmentIdRes[(Math.round(Math.random() * departmentIdRes.length) || 1) - 1] + } else { + throw `暂无乡镇信息` + } + + const sqlStr = ` WITH RECURSIVE sub_departments AS ( SELECT id, dependence FROM department @@ -331,60 +331,60 @@ async function spotPrepare (ctx) { WHERE u.delete = false; ` - const userRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) - let findUsers = [] - findUsers = userRes.map(item => { - return item.id - }) - - const reportCount = findUsers.length ? await models.Report.count({ - where: { - reportType: 'conserve', - userId: { $in: findUsers } - } - }) : 0 - - const previewRes = await models.ReportSpotCheckPreview.create({ - percentage: percentage, - departmentId: lukyDepartment.id, - date: moment().format(), - reportCount: reportCount, - checked: false, - }) - - - ctx.status = 200; - ctx.body = { - lukyDepartment, - reportCount, - previewId: previewRes.id - } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + const userRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) + let findUsers = [] + findUsers = userRes.map(item => { + return item.id + }) + + const reportCount = findUsers.length ? await models.Report.count({ + where: { + reportType: 'conserve', + userId: { $in: findUsers } + } + }) : 0 + + const previewRes = await models.ReportSpotCheckPreview.create({ + percentage: percentage, + departmentId: lukyDepartment.id, + date: moment().format(), + reportCount: reportCount, + checked: false, + }) + + + ctx.status = 200; + ctx.body = { + lukyDepartment, + reportCount, + previewId: previewRes.id + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function spotCheck (ctx) { - const transaction = await ctx.fs.dc.orm.transaction(); - try { - const { models } = ctx.fs.dc; - const sequelize = ctx.fs.dc.orm; - const { previewId } = ctx.query - if (!previewId) { - throw '参数错误' - } - - const prepareRes = await models.ReportSpotCheckPreview.findOne({ - where: { - id: previewId - } - }) - - const sqlStr = ` + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + const { previewId } = ctx.query + if (!previewId) { + throw '参数错误' + } + + const prepareRes = await models.ReportSpotCheckPreview.findOne({ + where: { + id: previewId + } + }) + + const sqlStr = ` WITH RECURSIVE sub_departments AS ( SELECT id, dependence FROM department @@ -400,279 +400,279 @@ async function spotCheck (ctx) { WHERE u.delete = false; ` - const userRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) - let findUsers = [] - findUsers = userRes.map(item => { - return item.id - }) - let checkCount = Math.ceil(prepareRes.reportCount * (prepareRes.percentage / 100)) - - const reportRes = await findUsers.length && checkCount ? await models.Report.findAll({ - where: { - reportType: 'conserve', - userId: { $in: findUsers }, - }, - include: [{ - model: models.User, - attributes: ['name'] - }], - order: sequelize.random(), // 随机排序 - limit: checkCount, // 限制返回的记录数 - }) : [] - - await models.ReportSpotCheckPreview.update({ - checked: true - }, { - where: { - id: previewId + const userRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT }) + let findUsers = [] + findUsers = userRes.map(item => { + return item.id + }) + let checkCount = Math.ceil(prepareRes.reportCount * (prepareRes.percentage / 100)) + + const reportRes = await findUsers.length && checkCount ? await models.Report.findAll({ + where: { + reportType: 'conserve', + userId: { $in: findUsers }, + }, + include: [{ + model: models.User, + attributes: ['name'] + }], + order: sequelize.random(), // 随机排序 + limit: checkCount, // 限制返回的记录数 + }) : [] + + await models.ReportSpotCheckPreview.update({ + checked: true + }, { + where: { + id: previewId + } + }) + if (reportRes.length) { + let spotDate = moment().format('YYYY-MM-DD') + await models.ReportSpotCheck.bulkCreate(reportRes.map(r => { + return { + reportId: r.id, + spotDate: spotDate, + prepareId: previewId } - }) - if (reportRes.length) { - let spotDate = moment().format('YYYY-MM-DD') - await models.ReportSpotCheck.bulkCreate(reportRes.map(r => { - return { - reportId: r.id, - spotDate: spotDate, - prepareId: previewId - } - })) - } - const rslt = findUsers.length && checkCount ? await models.ReportSpotCheckPreview.findAll({ - where: { - checked: 'true', - id: previewId - }, + })) + } + const rslt = findUsers.length && checkCount ? await models.ReportSpotCheckPreview.findAll({ + where: { + checked: 'true', + id: previewId + }, + include: [{ + model: models.Department, + attributes: ['name'] + }, { + model: models.ReportSpotCheck, include: [{ - model: models.Department, - attributes: ['name'] - }, { - model: models.ReportSpotCheck, - include: [{ - model: models.Report, - include: [{ - model: models.User, - attributes: ['name'] - }], - }] - } - ], - }) : [] - - await transaction.commit(); - ctx.status = 200; - ctx.body = rslt - } catch (error) { - await transaction.rollback(); - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + model: models.Report, + include: [{ + model: models.User, + attributes: ['name'] + }], + }] + } + ], + }) : [] + + await transaction.commit(); + ctx.status = 200; + ctx.body = rslt + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function spotCheckDetail (ctx) { - const { models } = ctx.fs.dc - const { startTime, endTime } = ctx.query - try { - const res = await models.ReportSpotCheckPreview.findAll({ - where: { - checked: 'true' - }, - order: [['date', 'DESC']], + const { models } = ctx.fs.dc + const { startTime, endTime } = ctx.query + try { + const res = await models.ReportSpotCheckPreview.findAll({ + where: { + checked: 'true' + }, + order: [['date', 'DESC']], + include: [{ + model: models.Department, + attributes: ['name'] + }, { + model: models.ReportSpotCheck, + where: { spotDate: { $between: [moment(startTime).format('YYYY-MM-DD'), moment(endTime).format('YYYY-MM-DD')] } }, + order: [['spot_date', 'DESC']], include: [{ - model: models.Department, - attributes: ['name'] - }, { - model: models.ReportSpotCheck, - where: { spotDate: { $between: [moment(startTime).format('YYYY-MM-DD'), moment(endTime).format('YYYY-MM-DD')] } }, - order: [['spot_date', 'DESC']], - include: [{ - model: models.Report, - order: [['date', 'DESC']], - include: [{ - model: models.User, - attributes: ['name'] - }], - }] - } - ], - }) - ctx.body = res - ctx.status = 200 - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) - ctx.status = 400 - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + model: models.Report, + order: [['date', 'DESC']], + include: [{ + model: models.User, + attributes: ['name'] + }], + }] + } + ], + }) + ctx.body = res + ctx.status = 200 + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) + ctx.status = 400 + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function roadSpotPrepare (ctx) { - try { - const { models } = ctx.fs.dc; - const sequelize = ctx.fs.dc.orm; - const { countyPercentage } = ctx.request.body; - - const lastSpotRes = await models.RoadSpotCheckPreview.findOne({ - where: { - checked: true - }, - attributes: ['id', 'countyPercentage', 'date',], - order: [['date', 'DESC']], + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + const { countyPercentage } = ctx.request.body; + + const lastSpotRes = await models.RoadSpotCheckPreview.findOne({ + where: { + checked: true + }, + attributes: ['id', 'countyPercentage', 'date',], + order: [['date', 'DESC']], + include: [{ + model: models.RoadSpotCheck, include: [{ - model: models.RoadSpotCheck, - include: [{ - model: models.Road, - // attributes: ['id', 'name'] - }] + model: models.Road, + // attributes: ['id', 'name'] }] - }) - let lastCountyPercentage = 0 // 最后一次的县道百分比 - - let lastCountyRoadIds = [] // 上次查得的县道id - let lastTownRoadIds = [] // 上次查得的乡镇道id - let lastVillageRoadRoadIds = [] // 上次查得的村道id - let lastVillageIds = [] - - if (lastSpotRes) { - lastCountyPercentage = lastSpotRes.countyPercentage - // 遍历 RoadSpotCheck,保存上次查询的路的id - lastCountyRoadIds = lastSpotRes.countyRoadId || [] - lastTownRoadIds = lastSpotRes.townshipRoadId || [] - lastVillageRoadRoadIds = lastSpotRes.villageRoadId || [] - lastVillageIds = lastSpotRes.villageId || [] - } - - // 先查上次没查的范围内的 然后比较百分比 如果重叠 再查上次查过的 - - let keyMap = { - '县': `route_code LIKE 'X%'`, - '乡': `route_code LIKE 'Y%'`, - '村': `route_code LIKE 'C%'` - } - async function getRoadTotalMileage (key, otherWhere = []) { - let res = await sequelize.query(` + }] + }) + let lastCountyPercentage = 0 // 最后一次的县道百分比 + + let lastCountyRoadIds = [] // 上次查得的县道id + let lastTownRoadIds = [] // 上次查得的乡镇道id + let lastVillageRoadRoadIds = [] // 上次查得的村道id + let lastVillageIds = [] + + if (lastSpotRes) { + lastCountyPercentage = lastSpotRes.countyPercentage + // 遍历 RoadSpotCheck,保存上次查询的路的id + lastCountyRoadIds = lastSpotRes.countyRoadId || [] + lastTownRoadIds = lastSpotRes.townshipRoadId || [] + lastVillageRoadRoadIds = lastSpotRes.villageRoadId || [] + lastVillageIds = lastSpotRes.villageId || [] + } + + // 先查上次没查的范围内的 然后比较百分比 如果重叠 再查上次查过的 + + let keyMap = { + '县': `route_code LIKE 'X%'`, + '乡': `route_code LIKE 'Y%'`, + '村': `route_code LIKE 'C%'` + } + async function getRoadTotalMileage (key, otherWhere = []) { + let res = await sequelize.query(` SELECT SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage FROM road WHERE ${keyMap[key]} ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''} `) - return res[0][0].total_mileage - } - - async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { - if (!lastRoadIds.length && !inOrNot) { - return [] - } - return await sequelize.query(` + return res[0][0].total_mileage + } + + async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) { + if (!lastRoadIds.length && !inOrNot) { + return [] + } + return await sequelize.query(` SELECT id, chainage_mileage FROM road WHERE ${keyMap[key]} ${lastRoadIds.length ? - `AND id ${inOrNot ? 'IN' : 'NOT IN'} ( + `AND id ${inOrNot ? 'IN' : 'NOT IN'} ( ${lastRoadIds.map(item => `'${item}'`).join(',')},-1 )` : '' - } + } AND chainage_mileage IS NOT NULL ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''} ORDER BY RANDOM() `, { type: QueryTypes.SELECT }); - } - - async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { - let spotRoadIds = [] - let accumulationMileage = 0 - - async function filterRoad (otherWhere, getRepeat = true) { - - if (key == '村' && getRepeat == true) { - - } else { - let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, otherWhere) - - for (let r of roadUnSpotedRes) { - spotRoadIds.push(r.id) - accumulationMileage += parseFloat(r.chainage_mileage) - if (accumulationMileage >= targetMileage) { - break; - } - } - } - - if (accumulationMileage < targetMileage && getRepeat) { - // 还小于 说明没取够 - let roadUnSpotedRepeatRes = await getRoadSpot( - key, - lastRoadIds, - true, - otherWhere - ) - for (let r of roadUnSpotedRepeatRes) { - spotRoadIds.push(r.id) - accumulationMileage += parseFloat(r.chainage_mileage) - if (accumulationMileage >= targetMileage) { - break; - } - } - } - } + } + + async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) { + let spotRoadIds = [] + let accumulationMileage = 0 + + async function filterRoad (otherWhere, getRepeat = true) { + + if (key == '村' && getRepeat == true) { - if (key == '村') { - for await (let villageId of villageIdList) { - await filterRoad([ - ...otherWhere, - `village_id=${villageId}` - ], false) - - spotVillageIds.push(villageId) - - if (accumulationMileage >= targetMileage) { - break; - } - } - if (accumulationMileage < targetMileage) { - // 还小于 说明没取够 - await filterRoad(otherWhere, true) - } } else { - await filterRoad(otherWhere, true) + let roadUnSpotedRes = await getRoadSpot(key, lastRoadIds, false, otherWhere) + + for (let r of roadUnSpotedRes) { + spotRoadIds.push(r.id) + accumulationMileage += parseFloat(r.chainage_mileage) + if (accumulationMileage >= targetMileage) { + break; + } + } } - return spotRoadIds - } + if (accumulationMileage < targetMileage && getRepeat) { + // 还小于 说明没取够 + let roadUnSpotedRepeatRes = await getRoadSpot( + key, + lastRoadIds, + true, + otherWhere + ) + for (let r of roadUnSpotedRepeatRes) { + 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) - // 抽县 - const countryRoadTotalMileage = await getRoadTotalMileage('县') - const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100 - let spotCountyRoadIds = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, []) + spotVillageIds.push(villageId) - // 抽乡 - const allTownCodeRes = await sequelize.query(` + if (accumulationMileage >= targetMileage) { + break; + } + } + if (accumulationMileage < targetMileage) { + // 还小于 说明没取够 + await filterRoad(otherWhere, true) + } + } else { + await filterRoad(otherWhere, true) + } + + return spotRoadIds + } + + // 抽县 + const countryRoadTotalMileage = await getRoadTotalMileage('县') + const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100 + let spotCountyRoadIds = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, []) + + // 抽乡 + const allTownCodeRes = await sequelize.query(` SELECT DISTINCT township_code FROM road WHERE township_code IS NOT NULL `, { type: QueryTypes.SELECT }); - let spotTownRoadIds = [] - let spotVillageRoadIds = [] - let spotVillageIds = [] - for await (let t of allTownCodeRes) { - // 遍历每个乡镇并抽取 - let otherWhere = [`township_code='${t.township_code}'`] - const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere) - const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 - - let spotTownRoadIds_ = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) - spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_) - - // 抽村 - const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere) - const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 - - let spotFirstVillageId = -1 - // 随机选取一个不在上次查过的村 - let villageRes = await sequelize.query(` + let spotTownRoadIds = [] + let spotVillageRoadIds = [] + let spotVillageIds = [] + for await (let t of allTownCodeRes) { + // 遍历每个乡镇并抽取 + let otherWhere = [`township_code='${t.township_code}'`] + const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere) + const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 + + let spotTownRoadIds_ = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere) + spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_) + + // 抽村 + const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere) + const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 + + let spotFirstVillageId = -1 + // 随机选取一个不在上次查过的村 + let villageRes = await sequelize.query(` SELECT id FROM village WHERE township_code = '${t.township_code}' ${lastVillageIds.length ? `AND id NOT IN ( @@ -681,80 +681,80 @@ async function roadSpotPrepare (ctx) { ORDER BY RANDOM() LIMIT 1 `, { type: QueryTypes.SELECT }); - if (!villageRes.length) { - // 没有村了,随机选一个 - villageRes = await sequelize.query(` + if (!villageRes.length) { + // 没有村了,随机选一个 + villageRes = await sequelize.query(` SELECT id FROM village WHERE township_code = '${t.township_code}' ORDER BY RANDOM() LIMIT 1 `, { type: QueryTypes.SELECT }); - } - if (villageRes.length) { - spotVillageIds.push(villageRes[0].id) - spotFirstVillageId = villageRes[0].id - } else { - continue; - } - - const villageNearRes = await sequelize.query(` + } + if (villageRes.length) { + spotVillageIds.push(villageRes[0].id) + spotFirstVillageId = villageRes[0].id + } else { + continue; + } + + const villageNearRes = await sequelize.query(` SELECT id,calc_village,diatance FROM village_distance WHERE origin_village = ${spotFirstVillageId} ORDER BY diatance ASC `, { type: QueryTypes.SELECT }) - let villageCheckIdList = villageNearRes.map(item => item.calc_village) - villageCheckIdList.unshift(spotFirstVillageId) - villageCheckIdList = [...(new Set(villageCheckIdList))] - - let spotVillageRoadIds_ = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList) - spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) - } - - const previewRes = await models.RoadSpotCheckPreview.create({ - countyPercentage: countyPercentage, - date: moment().format(), - countyRoadId: spotCountyRoadIds, - townshipRoadId: spotTownRoadIds, - villageRoadId: spotVillageRoadIds, - villageId: spotVillageIds, - checked: false - }) - - ctx.status = 200; - ctx.body = { - previewId: previewRes.id, - spotCountyRoadCount: spotCountyRoadIds.length, - spotTownRoadCount: spotTownRoadIds.length, - spotVillageRoadCount: spotVillageRoadIds.length, - } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + let villageCheckIdList = villageNearRes.map(item => item.calc_village) + villageCheckIdList.unshift(spotFirstVillageId) + villageCheckIdList = [...(new Set(villageCheckIdList))] + + let spotVillageRoadIds_ = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList) + spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_) + } + + const previewRes = await models.RoadSpotCheckPreview.create({ + countyPercentage: countyPercentage, + date: moment().format(), + countyRoadId: spotCountyRoadIds, + townshipRoadId: spotTownRoadIds, + villageRoadId: spotVillageRoadIds, + villageId: spotVillageIds, + checked: false + }) + + ctx.status = 200; + ctx.body = { + previewId: previewRes.id, + spotCountyRoadCount: spotCountyRoadIds.length, + spotTownRoadCount: spotTownRoadIds.length, + spotVillageRoadCount: spotVillageRoadIds.length, + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function confirmRoadSpot (ctx) { - const transaction = await ctx.fs.dc.orm.transaction(); - try { - const { models } = ctx.fs.dc; - const sequelize = ctx.fs.dc.orm; - const { previewId } = ctx.request.body - - const prepareRes = await models.RoadSpotCheckPreview.findOne({ - where: { - id: previewId - } - }) - let spotedRoadIds = [] - spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.countyRoadId) - spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.townshipRoadId) - spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.villageRoadId) - - const conserveCountRes = await sequelize.query(` + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + const { previewId } = ctx.request.body + + const prepareRes = await models.RoadSpotCheckPreview.findOne({ + where: { + id: previewId + } + }) + let spotedRoadIds = [] + spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.countyRoadId) + spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.townshipRoadId) + spotedRoadIds = spotedRoadIds.concat(prepareRes.dataValues.villageRoadId) + + const conserveCountRes = await sequelize.query(` SELECT road_id, COUNT(road_id) as count FROM report WHERE road_id IN ( @@ -763,379 +763,378 @@ async function confirmRoadSpot (ctx) { GROUP BY road_id `, { type: QueryTypes.SELECT }) - let spotRslt = [] - for await (let item of spotedRoadIds) { - let corConserveCount = conserveCountRes.find(item => item.road_id == item) - spotRslt.push({ - roadId: item, - maintenanceCount: corConserveCount ? corConserveCount.count : 0, - prepareId: previewId - }) - } - - await models.RoadSpotCheck.bulkCreate(spotRslt, { - transaction - }) - await models.RoadSpotCheckPreview.update({ - checked: true - }, { - where: { - id: previewId - }, - transaction - }) - - await transaction.commit(); - ctx.status = 204; - } catch (error) { - await transaction.rollback(); - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + let spotRslt = [] + for await (let item of spotedRoadIds) { + let corConserveCount = conserveCountRes.find(item => item.road_id == item) + spotRslt.push({ + roadId: item, + maintenanceCount: corConserveCount ? corConserveCount.count : 0, + prepareId: previewId + }) + } + + await models.RoadSpotCheck.bulkCreate(spotRslt, { + transaction + }) + await models.RoadSpotCheckPreview.update({ + checked: true + }, { + where: { + id: previewId + }, + transaction + }) + + await transaction.commit(); + ctx.status = 204; + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function roadSpotList (ctx) { - try { - const { models } = ctx.fs.dc; - const { startTime, endTime, page, limit } = ctx.query - - let findOpt = { - order: [['id', 'DESC']], - where: { - checked: false - } - } - - if (startTime && endTime) { - findOpt.where = { - date: { - $between: [moment(startTime).startOf('day').format(), moment(endTime).endOf('day').format()] - } - } - } + try { + const { models } = ctx.fs.dc; + const { startTime, endTime, page, limit } = ctx.query - const listRes = await models.RoadSpotCheckPreview.findAll({ - order: [['id', 'DESC']], - where: { - checked: true, - } - }) - - if (page && limit) { - findOpt.offset = (page - 1) * limit - findOpt.limit = limit - } - - ctx.status = 200; - ctx.body = listRes.map(item => { - return { - id: item.id, - date: item.date, - countyPercentage: item.countyPercentage, - spotCountyRoadCount: item.countyRoadId ? item.countyRoadId.length : 0, - spotTownRoadCount: item.townshipRoadId ? item.townshipRoadId.length : 0, - spotVillageRoadCount: item.villageId ? item.villageId.length : 0, - } - }) - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + let findOpt = { + order: [['id', 'DESC']], + where: { + checked: true + } + } + + if (startTime && endTime) { + findOpt.where.date = { + $between: [moment(startTime).startOf('day').format(), moment(endTime).endOf('day').format()] + } + + } + + if (page && limit) { + findOpt.offset = (page - 1) * limit + findOpt.limit = limit + } + + const listRes = await models.RoadSpotCheckPreview.findAll(findOpt) + + + + ctx.status = 200; + ctx.body = listRes.map(item => { + return { + id: item.id, + date: item.date, + countyPercentage: item.countyPercentage, + spotCountyRoadCount: item.countyRoadId ? item.countyRoadId.length : 0, + spotTownRoadCount: item.townshipRoadId ? item.townshipRoadId.length : 0, + spotVillageRoadCount: item.villageId ? item.villageId.length : 0, + countyRoadId: item.countyRoadId, + townshipRoadId: item.townshipRoadId, + villageId: item.villageId, + } + }) + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function roadSpotDetail (ctx) { - try { - const { models } = ctx.fs.dc; - const { previewId } = ctx.query - - const listRes = await models.RoadSpotCheck.findAll({ - where: { - prepareId: previewId - }, - include: [{ - model: models.Road, - // required: false, - }] - }) - - - ctx.status = 200; - ctx.body = listRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const { models } = ctx.fs.dc; + const { previewId } = ctx.query + + const listRes = await models.RoadSpotCheck.findAll({ + where: { + prepareId: previewId + }, + include: [{ + model: models.Road, + // required: false, + }] + }) + + + ctx.status = 200; + ctx.body = listRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function roadSpotChange (ctx) { - const transaction = await ctx.fs.dc.orm.transaction(); - try { - const { models } = ctx.fs.dc; - const sequelize = ctx.fs.dc.orm; - const { originRoadId, changeRoadId, previewId } = ctx.request.body - - if (originRoadId == changeRoadId) { - throw '原路段与目标路段不能相同' - } - - const previewRes = await models.RoadSpotCheckPreview.findOne({ - where: { - id: previewId - } - }) - - if (!previewRes) { - throw '预览数据不存在' - } - - let previewUpdated = false - async function updatePreview (key) { - if (previewUpdated) return - - if (previewRes[key] && previewRes[key].includes(originRoadId)) { - let originRoadIds = previewRes.dataValues[key] - let originRoadIdIndex = originRoadIds.indexOf(originRoadId) - - originRoadIds.splice(originRoadIdIndex, 1, changeRoadId) - - await models.RoadSpotCheckPreview.update({ - [key]: originRoadIds - }, { - where: { - id: previewId - }, - transaction - }) - previewUpdated = true - } - } - await updatePreview('countyRoadId') - await updatePreview('townshipRoadId') - await updatePreview('villageRoadId') - - if (!previewUpdated) { - throw '更改路段不在抽查范围内' - } - - const roadRes = await models.Road.findAll({ - where: { - id: { $in: [originRoadId, changeRoadId] } - } - }) - - if (roadRes.length != 2) { - throw '路段不存在' - } - - let content = '' - let curOriginRoad = roadRes.find(item => item.id == originRoadId) - let curChangeRoad = roadRes.find(item => item.id == changeRoadId) - - content = `将${curOriginRoad.routeName}从${curOriginRoad.startingPlaceName}到${curOriginRoad.stopPlaceName}改为${curChangeRoad.routeName}从${curChangeRoad.startingPlaceName}到${curChangeRoad.stopPlaceName}` - - const maintenanceCount = await sequelize.query(` + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + const { originRoadId, changeRoadId, previewId } = ctx.request.body + + if (originRoadId == changeRoadId) { + throw '原路段与目标路段不能相同' + } + + const previewRes = await models.RoadSpotCheckPreview.findOne({ + where: { + id: previewId + } + }) + + if (!previewRes) { + throw '预览数据不存在' + } + + let previewUpdated = false + async function updatePreview (key) { + if (previewUpdated) return + + if (previewRes[key] && previewRes[key].includes(originRoadId)) { + let originRoadIds = previewRes.dataValues[key] + let originRoadIdIndex = originRoadIds.indexOf(originRoadId) + + originRoadIds.splice(originRoadIdIndex, 1, changeRoadId) + + await models.RoadSpotCheckPreview.update({ + [key]: originRoadIds + }, { + where: { + id: previewId + }, + transaction + }) + previewUpdated = true + } + } + await updatePreview('countyRoadId') + await updatePreview('townshipRoadId') + await updatePreview('villageRoadId') + + if (!previewUpdated) { + throw '更改路段不在抽查范围内' + } + + const roadRes = await models.Road.findAll({ + where: { + id: { $in: [originRoadId, changeRoadId] } + } + }) + + if (roadRes.length != 2) { + throw '路段不存在' + } + + let content = '' + let curOriginRoad = roadRes.find(item => item.id == originRoadId) + let curChangeRoad = roadRes.find(item => item.id == changeRoadId) + + content = `将${curOriginRoad.routeName}从${curOriginRoad.startingPlaceName}到${curOriginRoad.stopPlaceName}改为${curChangeRoad.routeName}从${curChangeRoad.startingPlaceName}到${curChangeRoad.stopPlaceName}` + + const maintenanceCount = await sequelize.query(` SELECT COUNT(id) as count FROM report WHERE report_type = 'conserve' AND road_id=${changeRoadId} `, { type: QueryTypes.SELECT }) - await models.RoadSpotCheck.update({ - roadId: changeRoadId, - maintenanceCount: maintenanceCount[0].count - }, { - where: { - roadId: originRoadId, - prepareId: previewId - }, - transaction - }) - await models.RoadSpotCheckChangeLog.create({ - userId: ctx.fs.api.userId, - time: moment().format(), - originRoadId: originRoadId, - changeRoadId: changeRoadId, - content: content, + await models.RoadSpotCheck.update({ + roadId: changeRoadId, + maintenanceCount: maintenanceCount[0].count + }, { + where: { + roadId: originRoadId, prepareId: previewId - }, { - transaction - }) - - - await transaction.commit(); - ctx.status = 204; - } catch (error) { - await transaction.rollback(); - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + }, + transaction + }) + await models.RoadSpotCheckChangeLog.create({ + userId: ctx.fs.api.userId, + time: moment().format(), + originRoadId: originRoadId, + changeRoadId: changeRoadId, + content: content, + prepareId: previewId + }, { + transaction + }) + + + await transaction.commit(); + ctx.status = 204; + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function roadSpotChangList (ctx) { - try { - const { models } = ctx.fs.dc; - const { startTime, endTime, page, limit } = ctx.query - - let findOptPreview = { - where: { - checked: true, - }, - attributes: ['id'] - } - - if (startTime && endTime) { - findOptPreview.where = { - date: { - $between: [moment(startTime).startOf('day').format(), moment(endTime).endOf('day').format()] - } + try { + const { models } = ctx.fs.dc; + const { startTime, endTime, page, limit } = ctx.query + + let findOptPreview = { + where: { + checked: true, + }, + attributes: ['id', 'date'] + } + + if (startTime && endTime) { + findOptPreview.where = { + date: { + $between: [moment(startTime).startOf('day').format(), moment(endTime).endOf('day').format()] } - } - - let findOpt = { - order: [['id', 'DESC']], - where: { - - }, - include: [{ - model: models.RoadSpotCheckPreview, - ...findOptPreview, - required: true, - }, { - model: models.User, - attributes: ['name'] - }] - } - - if (page && limit) { - findOpt.offset = (page - 1) * limit - findOpt.limit = limit - } - - const listRes = await models.RoadSpotCheckChangeLog.findAll(findOpt) - - ctx.status = 200; - ctx.body = listRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + } + } + + let findOpt = { + order: [['id', 'DESC']], + where: { + + }, + include: [{ + model: models.RoadSpotCheckPreview, + ...findOptPreview, + required: true, + }, { + model: models.User, + attributes: ['name'] + }] + } + + if (page && limit) { + findOpt.offset = (page - 1) * limit + findOpt.limit = limit + } + + const listRes = await models.RoadSpotCheckChangeLog.findAll(findOpt) + + ctx.status = 200; + ctx.body = listRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function exportSpotRode (ctx) { - try { - const { models } = ctx.fs.dc; - const { previewId } = ctx.query - - const previewRes = await models.RoadSpotCheckPreview.findOne({ - where: { - id: previewId - } - }) - - const listRes = await models.RoadSpotCheck.findAll({ - where: { - prepareId: previewId - }, - include: [{ - model: models.Road, - // required: false, - }] - }) - - const header = [{ - key: 'level', - title: '道路类型', - }, { - key: 'routeName', - title: '路线名称', - }, { - key: 'routeCode', - title: '路线代码', - }, { - key: 'sectionNo', - title: '路段序号', - }, { - key: 'startingPlaceName', - title: '起点名称', - }, { - key: 'stopPlaceName', - title: '止点名称', - }, { - key: '', - title: '里程', - }, { - key: '', - title: '养护次数(次)', - },] - - function judgeLevel (routeCode) { - if (routeCode) { - if (routeCode.startsWith('X')) { - return '县道' - } else if (routeCode.startsWith('Y')) { - return '乡道' - } else if (routeCode.startsWith('C')) { - return '村道' - } - return '' - } else { - return '' - } - } - - let exportData = listRes.map(({ dataValues: item }) => { - let road = item.road.dataValues - return { - level: - judgeLevel(road.routeCode) - , - routeName: road.routeName, - routeCode: road.routeCode, - sectionNo: road.sectionNo, - startingPlaceName: road.startingPlaceName, - stopPlaceName: road.stopPlaceName, - mileage: road.chainageMileage, - maintenanceCount: item.maintenanceCount, + try { + const { models } = ctx.fs.dc; + const { previewId } = ctx.query + + const previewRes = await models.RoadSpotCheckPreview.findOne({ + where: { + id: previewId + } + }) + + const listRes = await models.RoadSpotCheck.findAll({ + where: { + prepareId: previewId + }, + include: [{ + model: models.Road, + // required: false, + }] + }) + + const header = [{ + key: 'level', + title: '道路类型', + }, { + key: 'routeName', + title: '路线名称', + }, { + key: 'routeCode', + title: '路线代码', + }, { + key: 'sectionNo', + title: '路段序号', + }, { + key: 'startingPlaceName', + title: '起点名称', + }, { + key: 'stopPlaceName', + title: '止点名称', + }, { + key: '', + title: '里程', + }, { + key: '', + title: '养护次数(次)', + },] + + function judgeLevel (routeCode) { + if (routeCode) { + if (routeCode.startsWith('X')) { + return '县道' + } else if (routeCode.startsWith('Y')) { + return '乡道' + } else if (routeCode.startsWith('C')) { + return '村道' } - }) - - const fileName = `${moment(previewRes.date).format('YYYY年MM月DD日HH时mm分')}道路抽查记录` + '.csv' - const filePath = await xlsxDownload.simpleExcelDown({ - data: exportData, header, fileName: fileName - }) - const fileData = fs.readFileSync(filePath); - - ctx.status = 200; - ctx.set('Content-Type', 'application/x-xls'); - ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); - ctx.body = fileData; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + return '' + } else { + return '' + } + } + + let exportData = listRes.map(({ dataValues: item }) => { + let road = item.road.dataValues + return { + level: + judgeLevel(road.routeCode) + , + routeName: road.routeName, + routeCode: road.routeCode, + sectionNo: road.sectionNo, + startingPlaceName: road.startingPlaceName, + stopPlaceName: road.stopPlaceName, + mileage: road.chainageMileage, + 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 + }) + const fileData = fs.readFileSync(filePath); + + ctx.status = 200; + ctx.set('Content-Type', 'application/x-xls'); + ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); + ctx.body = fileData; + } 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 + reportList, + reportPosition, + reportDetail, createReport, deleteReport, reportHandle, + spotPrepare, spotCheck, spotCheckDetail, + roadSpotPrepare, confirmRoadSpot, roadSpotList, roadSpotDetail, roadSpotChange, roadSpotChangList, exportSpotRode }; \ No newline at end of file diff --git a/web/client/src/sections/fillion/actions/infor.js b/web/client/src/sections/fillion/actions/infor.js index a245f755..32df6029 100644 --- a/web/client/src/sections/fillion/actions/infor.js +++ b/web/client/src/sections/fillion/actions/infor.js @@ -2,7 +2,7 @@ import { basicAction } from '@peace/utils' import { ApiTable } from '$utils' import { Request } from '@peace/utils' -export function getDepMessage() { +export function getDepMessage () { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -24,7 +24,7 @@ export function getDepMessage() { // }); // } -export function getOperaTional(query) { +export function getOperaTional (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -35,7 +35,7 @@ export function getOperaTional(query) { }); } -export function putOperaTional(query) { +export function putOperaTional (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -46,7 +46,7 @@ export function putOperaTional(query) { }); } -export function getSpecificVehicle(query) { +export function getSpecificVehicle (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -57,7 +57,7 @@ export function getSpecificVehicle(query) { }); } -export function putSpecificVehicle(query) { +export function putSpecificVehicle (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -68,7 +68,7 @@ export function putSpecificVehicle(query) { }); } -export function putHouseholds(query) { +export function putHouseholds (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -79,7 +79,7 @@ export function putHouseholds(query) { }); } -export function getHouseholds(query) { +export function getHouseholds (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -90,7 +90,7 @@ export function getHouseholds(query) { }); } -export function getRoadway(query) { +export function getRoadway (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -98,20 +98,20 @@ export function getRoadway(query) { actionType: 'GET_ROADWAY', url: ApiTable.getRoadway, msg: { error: '获取道路信息失败' }, - + reducer: { name: 'road' } }); } -export function putRoadway(query) { +export function putRoadway (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, data: query, actionType: 'PUT_ROADWAY', url: ApiTable.putRoadway, - msg: { option: query?.roadId?'编辑':'新增' + '道路信息' }, + msg: { option: query?.roadId ? '编辑' : '新增' + '道路信息' }, }); } -export function getBridge(query) { +export function getBridge (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -122,7 +122,7 @@ export function getBridge(query) { }); } -export function putBridge(query) { +export function putBridge (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -133,7 +133,7 @@ export function putBridge(query) { }); } -export function getProject(query) { +export function getProject (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -141,10 +141,10 @@ export function getProject(query) { actionType: 'GET_PROJECT', url: ApiTable.getProject, msg: { error: '获取工程信息失败' }, - reducer: { name: 'projectList' } + reducer: { name: 'projectList' } }); } -export function putProject(query) { +export function putProject (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -155,7 +155,7 @@ export function putProject(query) { }); } -export function getHighways(query) { +export function getHighways (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -166,7 +166,7 @@ export function getHighways(query) { }); } -export function putHighways(query) { +export function putHighways (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -177,7 +177,7 @@ export function putHighways(query) { }); } -export function getCircuit(query) { +export function getCircuit (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -188,7 +188,7 @@ export function getCircuit(query) { }); } -export function putCircuit(query) { +export function putCircuit (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -199,7 +199,7 @@ export function putCircuit(query) { }); } -export function getVehicle(query) { +export function getVehicle (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -210,7 +210,7 @@ export function getVehicle(query) { }); } -export function putVehicle(query) { +export function putVehicle (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -221,7 +221,7 @@ export function putVehicle(query) { }); } -export function delRoadway(query) { +export function delRoadway (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -231,7 +231,7 @@ export function delRoadway(query) { }); } -export function delProject(query) { +export function delProject (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -241,7 +241,7 @@ export function delProject(query) { }); } -export function delBridge(query) { +export function delBridge (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -251,7 +251,7 @@ export function delBridge(query) { }); } -export function delSpecificVehicle(query) { +export function delSpecificVehicle (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -261,7 +261,7 @@ export function delSpecificVehicle(query) { }); } -export function delHouseholds(query) { +export function delHouseholds (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -271,7 +271,7 @@ export function delHouseholds(query) { }); } -export function delCircuit(query) { +export function delCircuit (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -281,7 +281,7 @@ export function delCircuit(query) { }); } -export function delVehicle(query) { +export function delVehicle (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -292,7 +292,7 @@ export function delVehicle(query) { }); } -export function getPurchase(query) { +export function getPurchase (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -303,7 +303,7 @@ export function getPurchase(query) { }); } -export function putPurchase(query) { +export function putPurchase (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -314,7 +314,7 @@ export function putPurchase(query) { }); } -export function delPurchase(query) { +export function delPurchase (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -325,7 +325,7 @@ export function delPurchase(query) { }); } -export function getPropagata(query) { +export function getPropagata (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -336,7 +336,7 @@ export function getPropagata(query) { // reducer: { name: 'reportstatistic' } }); } -export function putAddPropagata(query) { +export function putAddPropagata (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -347,7 +347,7 @@ export function putAddPropagata(query) { // reducer: { name: 'reportstatistic' } }); } -export function putEditPropagata(query) { +export function putEditPropagata (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -358,7 +358,7 @@ export function putEditPropagata(query) { // reducer: { name: 'reportstatistic' } }); } -export function delPropagata(query) { +export function delPropagata (query) { return dispatch => basicAction({ type: 'del', dispatch: dispatch, @@ -369,7 +369,7 @@ export function delPropagata(query) { }); } -export function getShippingList(query) { +export function getShippingList (query) { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -380,7 +380,7 @@ export function getShippingList(query) { }); } -export function putShippingList(query) { +export function putShippingList (query) { return dispatch => basicAction({ type: 'put', dispatch: dispatch, @@ -391,7 +391,7 @@ export function putShippingList(query) { }); } //获取管养单位概况 -export function getCustodyunit() { +export function getCustodyunit () { return dispatch => basicAction({ type: 'get', dispatch: dispatch, @@ -401,10 +401,10 @@ export function getCustodyunit() { reducer: { name: 'roadMaintenances_management' } }); } -export function getCustodyunitOne(query) { +export function getCustodyunitOne (query) { return dispatch => basicAction({ type: 'get', - query:query, + query: query, dispatch: dispatch, actionType: 'GET_CUSTODY_UNIT_ONE', url: ApiTable.getCustodyunit, @@ -412,7 +412,7 @@ export function getCustodyunitOne(query) { // reducer: { name: 'roadMaintenances_management' } }); } -export function postCustodyunit(query) { +export function postCustodyunit (query) { return dispatch => basicAction({ type: 'post', data: query, @@ -423,14 +423,14 @@ export function postCustodyunit(query) { // reducer: { name: 'roadMaintenances' } }); } -export function getxiuyangas(query) { +export function getxiuyangas (query) { return dispatch => basicAction({ - type: 'get', - query, - dispatch: dispatch, - actionType: 'GET_XIUYANG', - url: ApiTable.getXiuyang, - msg: { error: '获取信息失败' }, - reducer: { name: 'xiuyang' } + type: 'get', + query, + dispatch: dispatch, + actionType: 'GET_XIUYANG', + url: ApiTable.getXiuyang, + msg: { error: '获取信息失败' }, + reducer: { name: 'xiuyang' } }); } \ No newline at end of file diff --git a/web/client/src/sections/fillion/actions/spotCheck.js b/web/client/src/sections/fillion/actions/spotCheck.js index b7492f5f..a07add7d 100644 --- a/web/client/src/sections/fillion/actions/spotCheck.js +++ b/web/client/src/sections/fillion/actions/spotCheck.js @@ -1,17 +1,93 @@ import { basicAction } from '@peace/utils' import { ApiTable } from '$utils' -// export function getAssess (query) { -// return dispatch => basicAction({ -// type: 'get', -// dispatch: dispatch, -// query: query, -// actionType: 'GET_ASSESS', -// url: ApiTable.getAssess, -// msg: { error: '获取考核评分信息' }, -// reducer: { name: 'assess' } -// }); -// } +export function roadSpotList (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_ROAD_STOP_LIST', + url: 'road/spot/list', + msg: { error: '获取抽查列表失败' }, + reducer: { name: 'roadSpotList' } + }); +} + + +export function roadSpotDetail (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_ROAD_STOP_DETAIL', + url: 'road/spot/detail', + msg: { error: '获取抽查详情失败' }, + reducer: { name: 'roadSpotDetail' } + }); +} + + +export function roadSpotPrepare (data = {}) { + return dispatch => basicAction({ + type: 'post', + dispatch: dispatch, + data: data, + actionType: 'POST_ROAD_STOP_PREPARE', + url: 'road/spot/prepare', + msg: { option: '抽取' }, + reducer: { name: 'roadSpotPrepare' } + }); +} + + +export function confirmRoadSpot (data = {}) { + return dispatch => basicAction({ + type: 'post', + dispatch: dispatch, + data: data, + actionType: 'POST_ROAD_STOP_CONFIRM', + url: 'road/spot/confirm', + msg: { option: '确认抽取' }, + reducer: { name: 'confirmRoadSpot' } + }); +} + +export function exportSpotRode (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_ROAD_STOP_EXPORT', + url: 'road/spot/export', + msg: { option: '导出路线抽查' }, + reducer: { name: '' } + }); +} + +export function roadSpotChangList (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_ROAD_STOP_CHANG_LIST', + url: 'road/spot/change', + msg: { error: '获取抽查路线更改列表' }, + reducer: { name: 'roadSpotChangList' } + }); +} + + +export function roadSpotChange (data = {}) { + return dispatch => basicAction({ + type: 'post', + dispatch: dispatch, + data: data, + actionType: 'POST_ROAD_STOP_CHANGE', + url: 'road/spot/change', + msg: { option: '更改抽查路线' }, + reducer: { name: '' } + }); +} // export function delAssess (query) { // return dispatch => basicAction({ diff --git a/web/client/src/sections/fillion/components/adjustment.js b/web/client/src/sections/fillion/components/adjustment.js new file mode 100644 index 00000000..1658904c --- /dev/null +++ b/web/client/src/sections/fillion/components/adjustment.js @@ -0,0 +1,181 @@ +import { connect } from 'react-redux'; +import React, { useEffect, useState } from 'react'; +import { Button, Modal, Form, Input, Divider, Spin, Select, DatePicker, Descriptions, Table } from 'antd' +import { roadSpotChange } from '../actions/spotCheck'; +import { getRoadway } from "../actions/infor" + +import moment from 'moment' +import '../components/maintenanceTable.less' + + + +const Adjustment = (props) => { + const { dispatch, user, loading, reportDetail, editData, onCancel, road, onOk } = props + const [data, setData] = useState()//外层表格的数据 + const [vis, setVis] = useState(false)//模态框的显示与隐藏变量 + const [count, setCount] = useState(0) + const [page, setPage] = useState(1) + const [depName, setDepName] = useState('') + const [total, setTotal] = useState(0) + const [previewId, setPreviewId] = useState(0) + const [reportData, setReportData] = useState([]) + const [detailList, setDetailList] = useState([]) + const [detailVisible, setDetailVisible] = useState(false) + const [dateRange, setDateRange] = useState([]); + const { RangePicker } = DatePicker + const [nameList, setNameList] = useState([]); + const [codeList, setCodeList] = useState([]); + const [indexList, setIndexList] = useState([]); + const [roadFind, setRoadFind] = useState({}); + + + + + + + useEffect(() => { + if (editData?.id) { + dispatch(getRoadway({ level: editData?.road?.level, alterId: editData?.alterId })).then(res => { + if (res.success) { + let name = [] + let code = [] + let index = [] + res?.payload.data?.forEach(v => { + if (v.routeName && !name.includes(v.routeName)) { + name.push(v.routeName) + } + if (v.routeCode && !code.includes(v.routeCode)) { + code.push(v.routeCode) + } + if (v.sectionNo && !index.includes(v.sectionNo)) { + index.push(v.sectionNo) + } + }); + setNameList(name) + setCodeList(code) + setIndexList(index) + } + }) + } + }, []) + + + const [form] = Form.useForm() + + + + + + + + return ( + { + onCancel() + }} + title='调整' onOk={() => { + form.validateFields().then((values) => { + let data = road?.find(d => values?.routeName == d?.routeName + && values?.routeCode == d?.routeCode && values?.sectionNo == d?.sectionNo) + dispatch(roadSpotChange({ + previewId: editData?.previewId, + originRoadId: editData?.id, + changeRoadId: data?.id + })).then(res => { + if (res.success) { + onCancel() + onOk() + } + }); + }) + + + + + }}> +
{ + let name = [] + let code = [] + let index = [] + let data = road?.filter(d => (allValues?.routeName ? allValues?.routeName == d?.routeName : true) + && (allValues?.routeCode ? allValues?.routeCode == d?.routeCode : true) && + (allValues?.sectionNo ? allValues?.sectionNo == d?.sectionNo : true)) + + data?.forEach(v => { + if (v.routeName && !name.includes(v.routeName)) { + name.push(v.routeName) + } + if (v.routeCode && !code.includes(v.routeCode)) { + code.push(v.routeCode) + } + if (v.sectionNo && !index.includes(v.sectionNo)) { + index.push(v.sectionNo) + } + }); + setNameList(name) + setCodeList(code) + setIndexList(index) + + if (allValues?.routeName && allValues?.routeCode && allValues?.sectionNo) { + form.setFieldsValue({ + 'startingPlaceName': data[0]?.startingPlaceName, + 'stopPlaceName': data[0]?.stopPlaceName + }) + } else { + form.setFieldsValue({ + 'startingPlaceName': null, + 'stopPlaceName': null + }) + } + + }}> + + + + + ({ value: v, label: v })) || []} /> + + + + + + + + +
+ + + + + + + ) +} +function mapStateToProps (state) { + const { auth, road } = state + //('state1', state) + return { + user: auth.user, + road: road?.data || [], + } +} +export default connect(mapStateToProps)(Adjustment); \ No newline at end of file diff --git a/web/client/src/sections/fillion/containers/adjustLog.js b/web/client/src/sections/fillion/containers/adjustLog.js index b42ddf46..6fb87f1b 100644 --- a/web/client/src/sections/fillion/containers/adjustLog.js +++ b/web/client/src/sections/fillion/containers/adjustLog.js @@ -1,669 +1,190 @@ import { connect } from 'react-redux'; import React, { useEffect, useState } from 'react'; -import { Button, Modal, Form, Input, Divider, Spin, Image, DatePicker, Descriptions, Table } from 'antd' -import ProTable from '@ant-design/pro-table'; -import { getReportSpotPrepare, getSpotCheck, getSpotCheckDetail } from '../actions/extract' -import { getReportDetail } from '../actions/patrol'; +import { Button, Modal, Form, Input, Divider, Spin, Select, DatePicker, Descriptions, Table } from 'antd' +const { TextArea } = Input; +import { roadSpotChangList } from '../actions/spotCheck'; import moment from 'moment' import '../components/maintenanceTable.less' -const DetailForm = (props) => { - const { visible, data, handleClose, loading } = props - //console.log('data1', data) - const [qndmn] = useState(localStorage.getItem('qndmn')) - const changeBoolean = (bool) => { - // console.log('bool', bool) - return bool ? '无异常' : '有异常' - } - const reportTypeText = (text) => { - switch (text) { - case 'road': return '道路'; - // - case 'countyRoad': return '县道'; - case 'villageRoad': return '乡道'; - case 'rusticRoad': return '村道'; - // - case 'bridge': return '桥梁'; - case 'culvert': return '涵洞'; - case 'other': return '其他'; - // - case 'conserve': return '养护'; - case 'patrol': return '巡查'; - case 'construction': return '在建'; - default: return text; - } - } - const keyList = [ - { key: '路线代码', name: 'codeRoad' }, - { key: '其他', name: 'projectType' }, - { key: '道路类型', name: 'reportType' }, - { key: '路线名称', name: 'road' }, - { key: '路线代码', name: 'codeRoad' }, - { key: '养护路段', name: 'roadSectionStart' }, - { key: '具体位置', name: 'address' }, - { key: '路面类型', name: 'roadType' }, - { key: '路面宽度(米)', name: 'roadWidth' }, - { key: '错车道(个)', name: 'wrongLane' }, - { key: '行道树(棵)', name: 'roadsideTrees' }, - { key: '边沟(米)', name: 'roadsideDitch' }, - { key: '护栏(米)', name: 'guardrail' }, - { key: '标线(米)', name: 'roadMarking' }, - { key: '养护人员人数(人)', name: 'maintenanceStaffCount' }, - { key: '修整路肩(平方米)', name: 'shoulderRepair' }, - { key: '清理边沟(米)', name: 'ditchCleaning' }, - { key: '修补沥青路面(平方米)', name: 'asphaltRepair' }, - { key: '修补水泥路面(平方米)', name: 'concreteRepair' }, - { key: '除草(米)', name: 'grassMowing' }, - { key: '树刷白(株/公里)', name: 'treeWhitening' }, - { key: '桩刷白(个)', name: 'pileWhitening' }, - { key: '维护护栏(个)', name: 'guardrailMaintenance' }, - { key: '修复端头(块)', name: 'endHeadRepair' }, - { key: '其他养护内容', name: 'otherDescription' }, - { key: '养护前图片', name: 'conserveBeforePic' }, - { key: '养护中图片', name: 'conserveUnderwayPic' }, - { key: '养护后图片', name: 'conserveAfterPic' }, - { key: '上报视频', name: 'videoUrl' }, - - ]; - const keyListOld = [ - // { key: '编号', name: 'id' }, - { key: '工程类型', name: 'projectType' }, - { key: '所在路段', name: 'road' }, - { key: '具体位置', name: 'address' }, - { key: '巡查内容', name: 'content' }, - { key: '路线代码', name: 'codeRoad' }, - // { key: '病害照片', name: 'scenePic' }, - { key: '养护前', name: 'conserveBeforePic' }, - { key: '养护中', name: 'conserveUnderwayPic' }, - { key: '养护后', name: 'conserveAfterPic' }, - - ]; - const roadInfo = [ - { key: '路面类型', name: 'roadType' }, - { key: '路面宽度/米', name: 'roadWidth' }, - { key: '错车道/个', name: 'wrongLane' }, - { key: '行道树/棵', name: 'roadsideTrees' }, - { key: '边沟/米', name: 'roadsideDitch' }, - { key: '护栏/米', name: 'guardrail' }, - { key: '标线/米', name: 'roadMarking' }, - ]; - const mantenanceInfo = [ - { key: '养护人员人数/人', name: 'maintenanceStaffCount' }, - { key: '修整路肩/平方米', name: 'shoulderRepair' }, - { key: '开挖、清理边沟/米', name: 'ditchCleaning' }, - { key: '修补沥青路面/平米', name: 'asphaltRepair' }, - { key: '修补水泥路面/平米', name: 'concreteRepair' }, - { key: '除草/米', name: 'grassMowing' }, - { key: '行道树刷白/株/公里', name: 'treeWhitening' }, - { key: '公里桩/百米桩刷漆/个', name: 'pileWhitening' }, - { key: '维修护栏/米', name: 'guardrailMaintenance' }, - { key: '修复端头/块', name: 'endHeadRepair' }, - { key: '其他', name: 'otherDescription' }, - ]; - const mantenancePic = [ - { key: '养护前图片', name: 'conserveBeforePic' }, - { key: '养护中图片', name: 'conserveUnderwayPic' }, - { key: '养护后图片', name: 'conserveAfterPic' }, - ]; - const renderContent = (data) => { - if (data) { - console.log('data1111', data) - if (moment(data.time).isAfter(moment('2023-08-03 00:00:00'))) { - return
- - {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} - {reportTypeText(data['projectType']) || ''} - {data['codeRoad'] || ''} - {data['code'] || ''} - {data['roadSectionStart'] + '-' + data['roadSectionEnd'] || ''} - {data['address'] || ''} - - - {roadInfo.map(item => ( - - {data[item.name] || ''} - - ))} - - - {mantenanceInfo.map(item => ( - - {data[item.name] || ''} - - ))} - - - {mantenancePic.map(item => ( - -
- {data[item.name]?.map(imgSrc => { - return
- -
- }) || '暂无图片'} -
-
- ))} -
- - -
- {data['videoUrl']?.map(videoSrc => { - return
-
- }) || '暂无视频'} -
-
-
-
- // if (data) { - // if (moment(data.time).isAfter(moment('2023-08-03 00:00:00'))) { - // return keyList.map(obj => { - // return
- // {obj.key} - // { - // obj.name != 'conserveBeforePic' && obj.name != 'conserveAfterPic' && obj.name != 'roadSectionStart' && obj.name != 'videoUrl' && obj.name.indexOf('conserve') == -1 ? - // - // : obj.name != 'roadSectionStart' && obj.name != 'videoUrl' ? - //
- // { - // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { - // return
- // - //
- // }) : '暂无图片' - // } - //
: obj.name != 'videoUrl' ?
- // - - //
:
- // { - // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(videoUrl => { - // return
- // - //
- // }) : '暂无视频' - // } - //
- // } - - //
- // }) - - // } else { - // return keyListOld.map(obj => { - // return
- // {obj.key} - // { - // obj.name != 'scenePic' && obj.name.indexOf('conserve') == -1 ? - // - // : - //
- // { - // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { - // return
- // - //
- // }) : '暂无图片' - // } - //
- - // } - //
- // }) - - // } - - } else { - return
- - {data['codeRoad'] && data['codeRoad'].length ? data['codeRoad'][0] === 'X' ? '县道' : data['codeRoad'][0] === 'Y' ? '乡道' : '村道' : ''} - {data['roadSectionStart'] && data['roadSectionEnd'] ? (data['roadSectionStart'] + '-' + data['roadSectionEnd']) : ''} - {data['codeRoad'] || ''} - {/* {data['code'] || ''} */} - {data['address'] || ''} - {data['content'] || ''} - - - {mantenancePic.map(item => ( - -
- {data[item.name]?.map(imgSrc => { - return
- -
- }) || '暂无图片'} -
-
- ))} -
- - -
- {data['videoUrl']?.map(videoSrc => { - return
-
- }) || '暂无视频'} -
-
-
-
- } - } else { - return '暂无数据' - } - } - // const renderContent = (data) => { - // if (data) { - // if (data['inspectionNoException']) { - // // 当'无异常'字段为true时,显示'无异常'和其他非异常相关字段 - // return keyList.map(obj => { - // if (obj.name === 'inspectionNoException' || obj.name === 'reportType' || obj.name === 'projectType' || obj.name === 'road' || obj.name === 'roadSectionStart' || obj.name === 'address' || obj.name === 'codeRoad' || obj.name === 'scenePic' || obj.name === 'videoUrl') { - // return ( - //
- // {obj.key} - // { - // obj.name === 'scenePic' && data[obj.name] instanceof Array ? - //
- // { - // data[obj.name].map(imgSrc => { - // return
- // - //
- // }) - // } - //
- // : obj.name === 'roadSectionStart' ? - //
- // - //
- // : - // - // } - //
- // ); - // } else { - // return null; // 不渲染异常相关字段 - // } - // }); - // } else { - // // 当'无异常'字段为false或未定义时,显示其他异常相关字段 - // return keyList.map(obj => { - // if (obj.name !== 'inspectionNoException') { - // return ( - //
- // {obj.key} - // { - // obj.name !== 'scenePic' && obj.name !== 'roadSectionStart' && obj.name.indexOf('conserve') === -1 ? - // - // : obj.name !== 'roadSectionStart' ? - //
- // { - // data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => { - // return
- // - //
- // }) : '暂无图片' - // } - //
- // :
- // - //
- // } - //
- // ); - // } else { - // return null; // 不渲染其他异常字段 - // } - // }); - // } - // } else { - // return '暂无数据'; - // } - // } - return ( - - - {renderContent(data)} - - - ) -} -const MaintenanceSpotCheck = (props) => { - const { dispatch, user, loading, reportDetail, reportDetailLoading } = props - const [data, setData] = useState()//外层表格的数据 - const [vis, setVis] = useState(false)//模态框的显示与隐藏变量 - const [count, setCount] = useState(0) - const [depId, setDepId] = useState(0) - const [depName, setDepName] = useState('') - const [total, setTotal] = useState(0) - const [previewId, setPreviewId] = useState(0) - const [reportData, setReportData] = useState([]) - const [detailVisible, setDetailVisible] = useState(false) - const [dateRange, setDateRange] = useState(['1970-1-1', '2099-12-31']); - const { RangePicker } = DatePicker - const [expandedRowKeys, setExpandedRowKeys] = useState([]); - - //console.log('reportData', reportData) - const checkDetail = (record) => { - dispatch(getReportDetail(record?.id)) - } - const handleOpen = () => { - setDetailVisible(true) - } - const handleClose = () => { - setDetailVisible(false) - } - - //里层列名 - const columns = [ - { - title: '抽查日期', - key: 'spotDate', - dataIndex: 'spotDate', - align: 'center', - // render: (_, record) => { - // return - // } - }, - { - title: '抽查乡镇', - key: 'projectType', - dataIndex: 'depName', - align: 'center', - - }, - { - title: '抽查数量', - key: 'count', - dataIndex: 'count', - align: 'center', - - }, - { - title: '抽查总数', - key: 'reportCount', - dataIndex: 'reportCount', - align: 'center', - - }, - - ] - const queryData = (query = { startTime: '1970-1-1', endTime: '2099-12-31' }) => { - dispatch(getSpotCheckDetail(query)).then(res => { - if (res.success) { - const data = res?.payload.data?.map(item => { - return { - spotDate: moment(item.date).format('YYYY-MM-DD'), - depName: item.department?.name, - reportCount: item.reportCount, - count: Math.ceil((item.reportCount * item.percentage) / 100), - reportDetail: item.reportSpotChecks?.map(child => { - return child.report - }), - id: item.id - } - }) - //console.log('data1', data) - setReportData(data) - } - }) - } - - useEffect(() => { - queryData() - }, []) - const [form] = Form.useForm() - const addHanler = () => { - setVis(true) - } - const extractHandler = () => { - form.validateFields(['percentValue']).then(async (values) => { - if (Number(values.percentValue) > 0) { - const res = await dispatch(getReportSpotPrepare({ percentage: Number(values.percentValue) })) - // setCount(res?.payload.data?.reportCount) - // setDepId(res?.payload.data?.lukyDepartment?.id) - // setDepName(res?.payload.data?.lukyDepartment?.name) - setPreviewId(res?.payload.data?.previewId) - // setTotal(Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100))) - - form.setFieldsValue({ - 'result': res?.payload.data?.reportCount, - 'village': res?.payload.data?.lukyDepartment?.name, - 'total': Math.ceil((res?.payload.data?.reportCount) * (Number(values.percentValue) / 100)) - }) - } - }) - } - const cancelHandler = () => { - setVis(false) - form.resetFields() - } - const okHandler = async () => { - if (previewId !== 0) { - const res = await dispatch(getSpotCheck({ previewId })) - const rslt = res.payload.data.map(item => { - return { - spotDate: moment(item.date).format('YYYY-MM-DD'), - depName: item.department?.name, - reportCount: item.reportCount, - count: Math.ceil((item.reportCount * item.percentage) / 100), - reportDetail: item.reportSpotChecks?.map(child => { - return child.report - }), - id: item.id - } - }) || [] - setReportData(rslt) - form.resetFields() - setVis(false) - } - } - //console.log('setReportData', reportData) - - const lookhandler = () => { - if ((dateRange && dateRange instanceof Array && dateRange[0] != '')) { - queryData({ startTime: moment(dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'), endTime: moment(dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss') }) - } - } - - return ( -
- - { setDateRange(dateString) }} style={{ marginRight: '50px' }} /> - - - ( - < Table - pagination={false} - dataSource={record?.reportDetail} - columns={ - [ - { title: '所属道路', dataIndex: 'road' }, - { - title: '所在路段', - key: 'address', - dataIndex: 'address', - align: 'center', - render: (_, r) => { - return `${r?.roadSectionStart || ''}-${r?.roadSectionEnd || ''}` - } - }, - { title: '具体位置', dataIndex: 'address' }, - { - title: '上报人', - width: 100, - key: 'userName', - dataIndex: 'userName', - align: 'center', - render: (text, r) => { - return r?.user?.name || '' - } - }, - { - title: '上报时间', - key: 'time', - dataIndex: 'time', - valueType: 'dateTime', - align: 'center', - render: (_, r) => { - return moment(r?.time).format('YYYY-MM-DD HH:mm:ss') - } - }, - { - title: '操作', - key: 'caozuo', - align: 'center', - render: (_, r) => { - return - } - } - // { title: '', dataIndex: 'subColumn1' }, - // { title: '', dataIndex: 'subColumn2' }, - // ... 其他子表格列配置 - ]} - /> - ), - }} - pagination={{ - pageSize: 10, - defaultPageSize: 10, - showSizeChanger: false, - }} - rowKey={(record) => { return record.id }} - toolBarRender={false} - search={false} - /> - -
- - - - - - {/* - % - */} - - - - - - - - - - - - - - - -
- -
- ) + +const AdjustLog = (props) => { + const { dispatch, user, loading, reportDetail, reportDetailLoading, detailLoading } = props + const [data, setData] = useState()//外层表格的数据 + const [vis, setVis] = useState(false)//模态框的显示与隐藏变量 + const [count, setCount] = useState(0) + const [page, setPage] = useState(1) + const [depName, setDepName] = useState('') + const [total, setTotal] = useState(0) + const [previewId, setPreviewId] = useState(0) + const [reportData, setReportData] = useState([]) + const [detailList, setDetailList] = useState([]) + const [detailVisible, setDetailVisible] = useState(false) + const [dateRange, setDateRange] = useState([]); + const { RangePicker } = DatePicker + const [expandedRowKeys, setExpandedRowKeys] = useState([]); + + + //console.log('reportData', reportData) + const [form] = Form.useForm() + + + + //里层列名 + const columns = [ + { + title: '抽查日期', + key: 'date', + dataIndex: 'date', + render: (_, record) => record?.roadSpotCheckPreview?.date && moment(record?.roadSpotCheckPreview?.date).format('YYYY-MM-DD') || '--' + }, + { + title: '调整内容', + key: 'content', + dataIndex: 'content', + }, + { + title: '调整人员', + key: 'user', + dataIndex: 'user', + render: (_, record) => record?.user?.name || '--' + }, + { + title: '调整时间', + key: 'time', + dataIndex: 'time', + render: (_, record) => record?.time && moment(record?.time).format('YYYY-MM-DD HH:mm:ss') || '--' + + }, + { + title: '操作', + key: 'operation', + dataIndex: 'operation', + render: (_, record) => + + }, + + ] + const queryData = (data = {}) => { + dispatch(roadSpotChangList(data)).then(res => { + if (res.success) { + setReportData(res?.payload.data) + } + }) + } + + + + + useEffect(() => { + queryData() + }, []) + + + + + + const cancelHandler = () => { + setVis(false) + form.resetFields() + } + + + + return ( +
+ +
+ 抽查日期: + { + setDateRange(dateString) + }} style={{ marginRight: 20 }} /> + + + +
+ + +
{ + setPage(page) + } + }} + rowKey={(record) => { return record.id }} + /> + + + {vis && { + setVis(false) + form.resetFields() + }} > 重置 } + onOk={() => { + form.resetFields() + setVis(false) + }}> +
+ + + + + +