From 98ca3e7ba66b486c026c830754fdd7bc73920d93 Mon Sep 17 00:00:00 2001 From: LUCAS Date: Wed, 27 Jul 2022 15:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=B7=A1=E6=9F=A5=20-?= =?UTF-8?q?=E9=BB=98=E8=AE=A4gis=E8=BD=A8=E8=BF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/report/index.js | 24 ++++++++++------ .../fillion/components/gis/patrolGis.js | 28 ++++++++++++++++--- .../fillion/components/patrolTable.js | 17 +++++++++-- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index ae26cf8f..0bede193 100644 --- a/api/app/lib/controllers/report/index.js +++ b/api/app/lib/controllers/report/index.js @@ -1,15 +1,15 @@ '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 } = ctx.query + const { limit, page, startTime, endTime, keyword, userId, reportType, isTop } = ctx.query let findOption = { where: { }, - attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'roadSectionEnd', 'reportType', 'content', 'longitude','latitude'], + attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'roadSectionEnd', 'reportType', 'content', 'longitude', 'latitude'], include: [{ model: models.User, attributes: ['name'] @@ -39,7 +39,15 @@ async function reportList (ctx) { if (reportType) { findOption.where.reportType = reportType } - const reportRes = await models.Report.findAll(findOption) + 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 sequelize = ctx.fs.dc.ORM; + reportRes = sequelize.query(sqlStr, { type: QueryTypes.SELECT }); + } else { + reportRes = await models.Report.findAll(findOption) + } ctx.status = 200; ctx.body = reportRes @@ -52,7 +60,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 @@ -102,7 +110,7 @@ async function reportPosition (ctx) { } } -async function reportDetail (ctx) { +async function reportDetail(ctx) { try { const models = ctx.fs.dc.models; const { reportId } = ctx.params @@ -124,7 +132,7 @@ async function reportDetail (ctx) { } } -async function createReport (ctx) { +async function createReport(ctx) { try { const { userId } = ctx.fs.api const models = ctx.fs.dc.models; @@ -146,7 +154,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/fillion/components/gis/patrolGis.js b/web/client/src/sections/fillion/components/gis/patrolGis.js index 7222c84e..5b6ceab1 100644 --- a/web/client/src/sections/fillion/components/gis/patrolGis.js +++ b/web/client/src/sections/fillion/components/gis/patrolGis.js @@ -5,13 +5,15 @@ import { useState } from 'react'; import { DatePicker } from 'antd'; import Bounds from './bounds'; import moment from 'moment'; +import { getReportList } from '../../actions/patrol' const { RangePicker } = DatePicker; function PatrolGis(props) { const { reportList, userId, dispatch } = props; const [mapComplete, setMapComplete] = useState(false); const [mapObj, setMapObj] = useState(); const [dateRange, setDateRange] = useState(); - + let markers = []; + let PATH = []; useEffect(() => { if (AMap) loadMap(); return () => { @@ -24,8 +26,20 @@ function PatrolGis(props) { }, [true]) useEffect(() => { + if (mapObj) { + mapObj.remove(markers); + mapObj.remove(PATH); + } + let query = { userId, reportType: 'patrol' } if (userId) { - + if ((dateRange && dateRange instanceof Array)) { + query.startTime = moment(dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss') + query.endTime = moment(dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss') + } + dispatch(getReportList(query)); + } else { + query.isTop = true; + dispatch(getReportList(query)); } }, [userId, dateRange]) @@ -91,6 +105,7 @@ function PatrolGis(props) { } }); // marker.setTitle(s.name); + markers.push(marker); map.add(marker); }) } @@ -111,6 +126,7 @@ function PatrolGis(props) { if (longitude && latitude) path.push([item.longitude, item.latitude]) }); + PATH = path; var polyline1 = new AMap.Polyline({ map: map, path: path, // 设置线覆盖物路径 @@ -122,9 +138,13 @@ function PatrolGis(props) { } return ( -
+
- { setDateRange(dateString) }} /> +
+ { setDateRange(dateString) }} + /> +
{mapObj ? : ''}
) diff --git a/web/client/src/sections/fillion/components/patrolTable.js b/web/client/src/sections/fillion/components/patrolTable.js index 049170ed..c93e0bb8 100644 --- a/web/client/src/sections/fillion/components/patrolTable.js +++ b/web/client/src/sections/fillion/components/patrolTable.js @@ -301,16 +301,29 @@ const PatrolTable = (props) => {
], - tab2: + tab2: }; const [activeTabKey1, setActiveTabKey1] = useState('tab1'); const onTab1Change = (key) => { setActiveTabKey1(key); }; + + const handleChangeRecord = (newRecord) => { + let target = null; + if (!record || newRecord.id != record.id) { + target = newRecord; + } + setRecord(target); + } + return (
- setRecord(record)} record={record} userList={userList} loading={userLoading} /> + handleChangeRecord(record)} + record={record} + userList={userList} + loading={userLoading} />