Browse Source

提交巡查 -默认gis轨迹

release_0.0.4
LUCAS 2 years ago
parent
commit
98ca3e7ba6
  1. 24
      api/app/lib/controllers/report/index.js
  2. 28
      web/client/src/sections/fillion/components/gis/patrolGis.js
  3. 17
      web/client/src/sections/fillion/components/patrolTable.js

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

@ -1,15 +1,15 @@
'use strict'; 'use strict';
const { QueryTypes } = require('sequelize'); const { QueryTypes } = require('sequelize');
async function reportList (ctx) { async function reportList(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { limit, page, startTime, endTime, keyword, userId, reportType } = ctx.query const { limit, page, startTime, endTime, keyword, userId, reportType, isTop } = ctx.query
let findOption = { let findOption = {
where: { where: {
}, },
attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'roadSectionEnd', 'reportType', 'content', 'longitude','latitude'], attributes: ['id', 'road', 'time', 'projectType', 'roadSectionStart', 'roadSectionEnd', 'reportType', 'content', 'longitude', 'latitude'],
include: [{ include: [{
model: models.User, model: models.User,
attributes: ['name'] attributes: ['name']
@ -39,7 +39,15 @@ async function reportList (ctx) {
if (reportType) { if (reportType) {
findOption.where.reportType = 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.status = 200;
ctx.body = reportRes ctx.body = reportRes
@ -52,7 +60,7 @@ async function reportList (ctx) {
} }
} }
async function reportPosition (ctx) { async function reportPosition(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { startTime, endTime, userId, reportType } = ctx.query const { startTime, endTime, userId, reportType } = ctx.query
@ -102,7 +110,7 @@ async function reportPosition (ctx) {
} }
} }
async function reportDetail (ctx) { async function reportDetail(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { reportId } = ctx.params const { reportId } = ctx.params
@ -124,7 +132,7 @@ async function reportDetail (ctx) {
} }
} }
async function createReport (ctx) { async function createReport(ctx) {
try { try {
const { userId } = ctx.fs.api const { userId } = ctx.fs.api
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
@ -146,7 +154,7 @@ async function createReport (ctx) {
} }
} }
async function deleteReport (ctx) { async function deleteReport(ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { reportId } = ctx.params; const { reportId } = ctx.params;

28
web/client/src/sections/fillion/components/gis/patrolGis.js

@ -5,13 +5,15 @@ import { useState } from 'react';
import { DatePicker } from 'antd'; import { DatePicker } from 'antd';
import Bounds from './bounds'; import Bounds from './bounds';
import moment from 'moment'; import moment from 'moment';
import { getReportList } from '../../actions/patrol'
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
function PatrolGis(props) { function PatrolGis(props) {
const { reportList, userId, dispatch } = props; const { reportList, userId, dispatch } = props;
const [mapComplete, setMapComplete] = useState(false); const [mapComplete, setMapComplete] = useState(false);
const [mapObj, setMapObj] = useState(); const [mapObj, setMapObj] = useState();
const [dateRange, setDateRange] = useState(); const [dateRange, setDateRange] = useState();
let markers = [];
let PATH = [];
useEffect(() => { useEffect(() => {
if (AMap) loadMap(); if (AMap) loadMap();
return () => { return () => {
@ -24,8 +26,20 @@ function PatrolGis(props) {
}, [true]) }, [true])
useEffect(() => { useEffect(() => {
if (mapObj) {
mapObj.remove(markers);
mapObj.remove(PATH);
}
let query = { userId, reportType: 'patrol' }
if (userId) { 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]) }, [userId, dateRange])
@ -91,6 +105,7 @@ function PatrolGis(props) {
} }
}); });
// marker.setTitle(s.name); // marker.setTitle(s.name);
markers.push(marker);
map.add(marker); map.add(marker);
}) })
} }
@ -111,6 +126,7 @@ function PatrolGis(props) {
if (longitude && latitude) if (longitude && latitude)
path.push([item.longitude, item.latitude]) path.push([item.longitude, item.latitude])
}); });
PATH = path;
var polyline1 = new AMap.Polyline({ var polyline1 = new AMap.Polyline({
map: map, map: map,
path: path, // 设置线覆盖物路径 path: path, // 设置线覆盖物路径
@ -122,9 +138,13 @@ function PatrolGis(props) {
} }
return ( return (
<div style={{ width: '100%', backgroundColor: '#101824', height: '100%', minHeight: 700 }}> <div style={{ width: '100%', backgroundColor: '#101824', height: '100%', minHeight: 700, position: 'relative' }}>
<div id='amapId' style={{ width: '100%', height: '100%', background: "#101824", minHeight: 700 }} /> <div id='amapId' style={{ width: '100%', height: '100%', background: "#101824", minHeight: 700 }} />
<RangePicker onChange={(date, dateString) => { setDateRange(dateString) }} /> <div style={{ position: 'absolute', top: 8, left: 20, display: userId ? 'block' : 'none' }}>
<RangePicker
onChange={(date, dateString) => { setDateRange(dateString) }}
/>
</div>
{mapObj ? <Bounds map={mapObj} /> : ''} {mapObj ? <Bounds map={mapObj} /> : ''}
</div > </div >
) )

17
web/client/src/sections/fillion/components/patrolTable.js

@ -301,16 +301,29 @@ const PatrolTable = (props) => {
<DetailList reportList={reportList} record={record} loading={reportListLoading} dispatch={dispatch} handleOpen={handleOpen} handelRefresh={handelRefresh} /> <DetailList reportList={reportList} record={record} loading={reportListLoading} dispatch={dispatch} handleOpen={handleOpen} handelRefresh={handelRefresh} />
</Card> </Card>
</div>], </div>],
tab2: <PatrolGis userId={(record ||{}).id} dispatch={dispatch} /> tab2: <PatrolGis userId={(record || {}).id} dispatch={dispatch} reportList={reportList} />
}; };
const [activeTabKey1, setActiveTabKey1] = useState('tab1'); const [activeTabKey1, setActiveTabKey1] = useState('tab1');
const onTab1Change = (key) => { const onTab1Change = (key) => {
setActiveTabKey1(key); setActiveTabKey1(key);
}; };
const handleChangeRecord = (newRecord) => {
let target = null;
if (!record || newRecord.id != record.id) {
target = newRecord;
}
setRecord(target);
}
return ( return (
<div className='card-protable'> <div className='card-protable'>
<Card > <Card >
<PatrolNameList onChange={(record) => setRecord(record)} record={record} userList={userList} loading={userLoading} /> <PatrolNameList
onChange={(record) => handleChangeRecord(record)}
record={record}
userList={userList}
loading={userLoading} />
</Card> </Card>
<Card <Card
style={{ flex: 1 }} style={{ flex: 1 }}

Loading…
Cancel
Save