diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index e4fc1476..8ab4c205 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -1,7 +1,7 @@ 'use strict'; const { QueryTypes } = require('sequelize'); -async function reportList(ctx) { +async function reportList (ctx) { try { const models = ctx.fs.dc.models; const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType, handleState = '', performerId = '' } = ctx.query @@ -44,7 +44,7 @@ async function reportList(ctx) { }, attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'performerId', 'roadSectionEnd', 'reportType', - 'content', 'longitude', 'latitude', 'projectName', 'handleState', 'codeRoad', 'handleContent', 'handlePic','videoUrl'], + 'content', 'longitude', 'latitude', 'projectName', 'handleState', 'codeRoad', 'handleContent', 'handlePic', 'videoUrl'], include: [{ model: models.User, attributes: ['name'] @@ -100,8 +100,33 @@ async function reportList(ctx) { let reportRes = null; if (isTop) { - const sqlStr = 'select * from (SELECT R.*, "row_number"() OVER(PARTITION BY R.user_id ORDER BY R."time" DESC) AS NEWINDEX FROM report AS R ) AS NR WHERE NEWINDEX = 1' + 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; + ` 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) } @@ -117,7 +142,7 @@ async function reportList(ctx) { } } -async function reportPosition(ctx) { +async function reportPosition (ctx) { try { const models = ctx.fs.dc.models; const { startTime, endTime, userId, reportType } = ctx.query @@ -167,7 +192,7 @@ async function reportPosition(ctx) { } } -async function reportDetail(ctx) { +async function reportDetail (ctx) { try { const models = ctx.fs.dc.models; const { reportId } = ctx.params @@ -189,7 +214,7 @@ async function reportDetail(ctx) { } } -async function reportHandle(ctx) { +async function reportHandle (ctx) { try { const { models } = ctx.fs.dc; @@ -219,7 +244,7 @@ async function reportHandle(ctx) { } } -async function createReport(ctx) { +async function createReport (ctx) { try { const { userId } = ctx.fs.api const models = ctx.fs.dc.models; @@ -241,7 +266,7 @@ async function createReport(ctx) { } } -async function deleteReport(ctx) { +async function deleteReport (ctx) { try { const models = ctx.fs.dc.models; const { reportId } = ctx.params; diff --git a/web/client/src/sections/quanju/containers/example.js b/web/client/src/sections/quanju/containers/example.js index 030c4cc0..7d511841 100644 --- a/web/client/src/sections/quanju/containers/example.js +++ b/web/client/src/sections/quanju/containers/example.js @@ -8,17 +8,39 @@ import Footer from './footer'; import ProTable, { TableDropdown } from '@ant-design/pro-table'; import Gis from './footer/gis/gis'; import OlMap from './public/olMap' +import { getReportList } from '../../fillion/actions/patrol' const MAPID = 'screenGis' const Example = (props) => { const { dispatch, actions, user, loading } = props const [tabKey, setTabKey] = useState('leadership') - const [mapObj, setMapObj] = useState(); + const [patrolList, setPatrolList] = useState([]); + const [roadProjectList, setRoadProjectList] = useState([]); const tabChange = (tab) => { setTabKey(tab) // dispatch({ type: 'TAB-CHANGE', data: tab }) + console.log(tab); + if (tab === 'conserve') { + dispatch(getReportList({ + reportType: 'patrol', + isTop: true + })).then(res => { + console.log(res); + if (res.success) { + setPatrolList(res.payload.data || []) + } + }) + dispatch(getReportList({ + reportType: 'road', + isTop: true + })).then(res => { + if (res.success) { + setRoadProjectList(res.payload.data || []) + } + }) + } } return ( @@ -34,7 +56,7 @@ const Example = (props) => {
+ { + isRoadProject ? + pointItem.user_name || '--' + : + <> + { + pointItem.road_section_start ? pointItem.road_section_start : "" + }{ + pointItem.road_section_start && pointItem.road_section_end ? "——" : "" + }{ + pointItem.road_section_end ? pointItem.road_section_end : "" + }{ + pointItem.road_section_start || pointItem.road_section_end ? "" : "--" + } + > + } + +
++ { + isRoadProject ? '上报内容' : '养护内容' + } + + { + pointItem.content ? pointItem.content : "--" + } + +
+ { + isRoadProject ? '' : ++ 负责人 + + { + pointItem.user_name ? pointItem.user_name : "--" + } + +
+ } ++ 日期 + + { + pointItem.time ? moment(pointItem.time).format("YYYY-MM-DD") : "--" + } + +
++ {s.n} + + { + s.k == 'startTime' ? + pointItem.project[s.k] ? moment(pointItem.project[s.k]).format("YYYY-MM-DD") : "--" + : + pointItem.project[s.k] || "--" + } + +
+ ) + })} +