diff --git a/api/app/lib/controllers/overview/operation.js b/api/app/lib/controllers/overview/operation.js index 03f9414e..7e06102d 100644 --- a/api/app/lib/controllers/overview/operation.js +++ b/api/app/lib/controllers/overview/operation.js @@ -144,6 +144,12 @@ async function busRunRealTime (ctx) { } }) + app.fs.zhidiaoData ? + app.fs.zhidiaoData.busRun = busRunRes : + app.fs.zhidiaoData = { + busRun: busRunRes + } + let now = moment() let hourBefour = now.subtract(1, 'h') ctx.status = 200; @@ -157,8 +163,35 @@ async function busRunRealTime (ctx) { } } +async function busLine (ctx) { + try { + const { models } = ctx.fs.dc; + const { app } = ctx + const { busLicence } = ctx.query + + const zhidiaoData = app.fs.zhidiaoData + let rslt = {} + if (zhidiaoData) { + let corBus = (zhidiaoData.busRun || []).find(b => b.busNoChar == busLicence) + if (corBus) { + rslt = (zhidiaoData.busLine || {})[corBus.lineNo] || {} + } + } + + ctx.status = 200; + ctx.body = rslt + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + module.exports = { busCarLevelList, vehicleStatistic, busRunRealTime, + busLine, }; \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index bf0334d8..d6b9be07 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -6,6 +6,7 @@ const path = require('path'); const authenticator = require('./middlewares/authenticator'); // const apiLog = require('./middlewares/api-log'); const paasRequest = require('./service/paasRequest'); +const schedule = require('./schedule') module.exports.entry = function (app, router, opts) { app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); @@ -18,6 +19,8 @@ module.exports.entry = function (app, router, opts) { // router.use(apiLog(app, opts)); // 实例其他平台请求方法 paasRequest(app, opts) + // 定时任务 + schedule(app, opts) router = routes(app, router, opts); }; diff --git a/api/app/lib/routes/overview/index.js b/api/app/lib/routes/overview/index.js index 9bd23c45..da38a270 100644 --- a/api/app/lib/routes/overview/index.js +++ b/api/app/lib/routes/overview/index.js @@ -26,4 +26,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/bus/run_realtime'] = { content: '获取公交实时运行信息', visible: false }; router.get('/bus/run_realtime', operation.busRunRealTime); + + app.fs.api.logAttr['GET/bus/run/line'] = { content: '获取公交运行路线', visible: false }; + router.get('/bus/run/line', operation.busLine); } \ No newline at end of file diff --git a/api/app/lib/schedule/zhidiao.js b/api/app/lib/schedule/zhidiao.js new file mode 100644 index 00000000..1245e3fe --- /dev/null +++ b/api/app/lib/schedule/zhidiao.js @@ -0,0 +1,44 @@ +const zhidiaoSystem = require('../../../utils/zhidiaoSystem.js'); +const moment = require('moment') + +let isDev = false +isDev = true + +module.exports = function (app, opts) { + const busLines = app.fs.scheduleInit( + { + interval: '24 0 */1 * * *', + immediate: true, + proRun: false, + disabled: false + }, + + async () => { + try { + const { models, ORM: sequelize } = app.fs.dc + const Authorization = zhidiaoSystem.createAuthorization() + const busRunRes = await app.fs.zhidiaoRequest.get(`getBusRunList`, { + header: { + Authorization: Authorization + } + }) + const busLineRes = await app.fs.zhidiaoRequest.get(`getLinePointList`, { + header: { + Authorization: Authorization + } + }) + console.log(`定时获取BUS路线信息`); + app.fs.zhidiaoData = { + busLine: busLineRes, + busRun: busRunRes + } + } catch (error) { + console.error(error); + } + } + ) + + return { + busLines, + } +} \ No newline at end of file diff --git a/api/package.json b/api/package.json index dabf4b39..4e66560a 100644 --- a/api/package.json +++ b/api/package.json @@ -28,6 +28,7 @@ "koa2-swagger-ui": "^5.3.0", "md5-node": "^1.0.1", "moment": "^2.24.0", + "node-schedule": "^2.1.1", "path": "^0.12.7", "path-to-regexp": "^3.0.0", "pg": "^7.9.0", diff --git a/web/client/assets/images/gis/bus.png b/web/client/assets/images/gis/bus.png new file mode 100644 index 00000000..7d9320da Binary files /dev/null and b/web/client/assets/images/gis/bus.png differ diff --git a/web/client/src/layout/index.js b/web/client/src/layout/index.js index 7b714fc8..c3824167 100644 --- a/web/client/src/layout/index.js +++ b/web/client/src/layout/index.js @@ -61,7 +61,6 @@ const Root = props => { flat(routes); //将路由信息全部放在session,方便后面拿了用(权限控制的时候) - //console.log('combineRoutes1', combineRoutes) sessionStorage.setItem('allRoutes', JSON.stringify(combineRoutes)); return combineRoutes; } diff --git a/web/client/src/sections/quanju/actions/example.js b/web/client/src/sections/quanju/actions/example.js index dd5c1ed5..180e5f1e 100644 --- a/web/client/src/sections/quanju/actions/example.js +++ b/web/client/src/sections/quanju/actions/example.js @@ -1,6 +1,6 @@ 'use strict'; -import { basicAction } from '@peace/utils' +import { basicAction, clearData } from '@peace/utils' import { ApiTable } from '$utils' export function getMembers (orgId) { @@ -180,13 +180,25 @@ export function getVideoCenterList () { }); } -export function getBusRuntTime () { +export function getBusRunTime () { return dispatch => basicAction({ type: 'get', dispatch: dispatch, - actionType: 'GET_VIDEO_CENTER_LIST', - url: ApiTable.videoCenterList, - msg: { error: '获取视频中心列表失败' }, - reducer: { name: 'videoCenterList' } + actionType: 'GET_BUS_REALTIME_LIST', + url: ApiTable.busRealtimeList, + msg: { error: '获取公交实时信息失败' }, + reducer: { name: 'busRunTime', params: { noClear: true } } + }); +} + +export const getBuslineActionType = 'GET_BUS_LINE' +export function getBusline (busLicence) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: getBuslineActionType, + url: ApiTable.busLine + `?busLicence=${busLicence}`, + msg: { error: '获取公交路线信息失败' }, + reducer: { name: 'busLine', params: { noClear: true } } }); } \ No newline at end of file diff --git a/web/client/src/sections/quanju/containers/footer/operation/index.js b/web/client/src/sections/quanju/containers/footer/operation/index.js index 1f723da9..92438b65 100644 --- a/web/client/src/sections/quanju/containers/footer/operation/index.js +++ b/web/client/src/sections/quanju/containers/footer/operation/index.js @@ -2,8 +2,9 @@ import React, { useEffect, useState } from 'react' import Left from './left' import Right from './right' import { connect } from 'react-redux' -import { getBusTierList } from '../../../actions/example' +import { getBusTierList, getBusRunTime } from '../../../actions/example' +let busRealtimeInterval = null const Operation = (props) => { const [roadData, setRoadData] = useState() @@ -14,6 +15,13 @@ const Operation = (props) => { setLoading(false) setRoadData(res.payload.data || {}) }) + busRealtimeInterval = setInterval(() => { + dispatch(getBusRunTime()) + }, 1000 * 16) + dispatch(getBusRunTime()) + return () => { + clearInterval(busRealtimeInterval) + } }, []) return ( @@ -23,7 +31,7 @@ const Operation = (props) => { ) } -function mapStateToProps(state) { +function mapStateToProps (state) { return { diff --git a/web/client/src/sections/quanju/containers/footer/operation/left.js b/web/client/src/sections/quanju/containers/footer/operation/left.js index a00da638..2b063202 100644 --- a/web/client/src/sections/quanju/containers/footer/operation/left.js +++ b/web/client/src/sections/quanju/containers/footer/operation/left.js @@ -1,11 +1,15 @@ import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; -import { Input, Tree } from 'antd' +import { Input, Tree, message } from 'antd' import Module from '../../public/module' -import { getBusTierList } from '../../../actions/example' +import { getBusTierList, getBusline, getBuslineActionType } from '../../../actions/example' +import { basicAction, clearData } from '@peace/utils' import './style.less' const Left = (props) => { + const { busTier, dispatch } = props + const style = { height: "97%", marginTop: "3%" } + const [treeData, setTreeData] = useState([]) const [treeDataList, setTreeDataList] = useState([]) const [expandedKeys, setExpandedKeys] = useState([]); @@ -20,10 +24,7 @@ const Left = (props) => { useEffect(() => { const { dispatch } = props dispatch(getBusTierList()) - }, []) - const { busTier } = props - const style = { height: "97%", marginTop: "3%" } const onChange = (e) => { const { value } = e.target; @@ -38,7 +39,6 @@ const Left = (props) => { }; const loop = (treeData) => treeData.map((item) => { - // console.log(item,'===> item -----'); const index = item.title != null && item.title.indexOf(searchValue); const beforeStr = item.title != null && item.title.substr(0, index); const afterStr = item.title != null && item.title.substr(index + searchValue.length); @@ -91,15 +91,17 @@ const Left = (props) => { title: e.name, children: e.child.map(s => { return { - key: s.name == '--' || s.name == null ? Math.ceil(Math.random() * 100) : s.name, + key: s.name == '--' || s.name == null ? Math.ceil(Math.random() * 100) : s.name, title: s.name, children: s.child.map(i => { return { - key: i.name == '--' || i.name == null ? Math.ceil(Math.random() * 100) : i.name, + key: + i.name == '--' || i.name == null ? Math.ceil(Math.random() * 100) : i.name, title: i.name, children: i.child.map(x => { return { - key: x.name == '--' || x.name == null ? Math.ceil(Math.random() * 100) : x.name, + key: 'bus_' + x.id + '_' + x.name || '--', + // key: x.name == '--' || x.name == null ? Math.ceil(Math.random() * 100) : x.name, title: x.name == null ? '--' : x.name, } }) @@ -128,7 +130,7 @@ const Left = (props) => { setTreeDataList(dataList) }, [busTier]) return ( -