diff --git a/api/app/lib/index.js b/api/app/lib/index.js index c1bd9116..b564d4e7 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -94,6 +94,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq VillageDistance.belongsTo(Village, { foreignKey: 'calcVillage', targetKey: 'id' }); Village.hasMany(VillageDistance, { foreignKey: 'calcVillage', sourceKey: 'id' }); + + Report.belongsTo(Road, { foreignKey: 'roadId', targetKey: 'id', as: 'road_' }); + Road.hasMany(Report, { foreignKey: 'roadId', sourceKey: 'id', as: 'road_' }); }; diff --git a/api/app/lib/schedule/index.js b/api/app/lib/schedule/index.js index b976d6d8..dd7af2e5 100644 --- a/api/app/lib/schedule/index.js +++ b/api/app/lib/schedule/index.js @@ -6,34 +6,35 @@ const nodeSchedule = require('node-schedule'); // 将定时任务汇集未来可根据需要选取操作 module.exports = async function (app, opts) { - const scheduleInit = ({ - interval, immediate, proRun, disabled - }, callback) => { - if (disabled) { - return; - } - if (proRun && opts.dev) { - return; - } - const j = nodeSchedule.scheduleJob(interval, callback); - if (immediate && (!proRun || (proRun && !opts.dev))) { - setTimeout(callback, 0) - } - return j; - } + const scheduleInit = ({ + interval, immediate, proRun, disabled + }, callback) => { + if (disabled) { + return; + } + if (proRun && opts.dev) { + return; + } + const j = nodeSchedule.scheduleJob(interval, callback); + if (immediate && (!proRun || (proRun && !opts.dev))) { + console.log(22222); + setTimeout(callback, 0) + } + return j; + } - app.fs.scheduleInit = scheduleInit + app.fs.scheduleInit = scheduleInit - fs.readdirSync(__dirname).forEach((filename) => { - if (!['index.js'].some(f => filename == f)) { - const scheduleList = require(`./${filename}`)(app, opts) - for (let k of Object.keys(scheduleList)) { - console.info(`定时任务 ${k} 启动`); - } - app.fs.schedule = { - ...app.fs.schedule, - ...scheduleList, - } - } - }); + fs.readdirSync(__dirname).forEach((filename) => { + if (!['index.js'].some(f => filename == f)) { + const scheduleList = require(`./${filename}`)(app, opts) + for (let k of Object.keys(scheduleList)) { + console.info(`定时任务 ${k} 启动`); + } + app.fs.schedule = { + ...app.fs.schedule, + ...scheduleList, + } + } + }); }; diff --git a/api/app/lib/schedule/noticeAbnormal.js b/api/app/lib/schedule/noticeAbnormal.js new file mode 100644 index 00000000..edce110a --- /dev/null +++ b/api/app/lib/schedule/noticeAbnormal.js @@ -0,0 +1,55 @@ +const moment = require('moment') + +let isDev = false +isDev = true + +module.exports = function (app, opts) { + const notice = app.fs.scheduleInit( + { + interval: '0 9 */1 * * *', + immediate: isDev && opts.dev, + proRun: !isDev, + disabled: false + }, + + async () => { + try { + const { models, ORM: sequelize } = app.fs.dc + console.log(123123); + const anomalyList = await models.Report.findAll({ + where: { + handleState: null, + reportType: 'anomaly', + time: { + [sequelize.Op.lt]: moment().subtract(3, 'days').format('YYYY-MM-DD HH:mm:ss') + } + }, + include: [{ + model: models.User, + }, { + model: models.Road, + as: 'road_' + }] + }) + + for (let i = 0; i < anomalyList.length; i++) { + const anomaly = anomalyList[i] + /** + * 通过XX(反馈类型)反馈,XX(所道路)的XX(所属路段)路段,具体位置于XX,XXXX(反馈内容)。XXX(上报人)上报时间:XX。您已超过3天未处理,请至平台尽快处理。 + */ + + + } + + console.log(anomalyList); + + } catch (error) { + console.error(error); + } + } + ) + + return { + notice, + } +} \ No newline at end of file diff --git a/api/app/lib/schedule/zhidiao.js b/api/app/lib/schedule/zhidiao.js index 67d6b6db..7eeffa12 100644 --- a/api/app/lib/schedule/zhidiao.js +++ b/api/app/lib/schedule/zhidiao.js @@ -9,7 +9,7 @@ module.exports = function (app, opts) { { interval: '24 0 */1 * * *', immediate: true, - proRun: false, + proRun: true, disabled: false }, diff --git a/api/config.js b/api/config.js index 520cb01f..df76a151 100644 --- a/api/config.js +++ b/api/config.js @@ -57,6 +57,7 @@ if ( const product = { port: flags.port || 8080, staticDirs: ['static'], + dev: dev, mws: [ { entry: require('@fs/attachment').entry,