Browse Source

异常上报之短信推送

dev
CODE 2 years ago
parent
commit
44674c2fa4
  1. 3
      api/app/lib/index.js
  2. 57
      api/app/lib/schedule/index.js
  3. 55
      api/app/lib/schedule/noticeAbnormal.js
  4. 2
      api/app/lib/schedule/zhidiao.js
  5. 1
      api/config.js

3
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' }); VillageDistance.belongsTo(Village, { foreignKey: 'calcVillage', targetKey: 'id' });
Village.hasMany(VillageDistance, { foreignKey: 'calcVillage', sourceKey: '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_' });
}; };

57
api/app/lib/schedule/index.js

@ -6,34 +6,35 @@ const nodeSchedule = require('node-schedule');
// 将定时任务汇集未来可根据需要选取操作 // 将定时任务汇集未来可根据需要选取操作
module.exports = async function (app, opts) { module.exports = async function (app, opts) {
const scheduleInit = ({ const scheduleInit = ({
interval, immediate, proRun, disabled interval, immediate, proRun, disabled
}, callback) => { }, callback) => {
if (disabled) { if (disabled) {
return; return;
} }
if (proRun && opts.dev) { if (proRun && opts.dev) {
return; return;
} }
const j = nodeSchedule.scheduleJob(interval, callback); const j = nodeSchedule.scheduleJob(interval, callback);
if (immediate && (!proRun || (proRun && !opts.dev))) { if (immediate && (!proRun || (proRun && !opts.dev))) {
setTimeout(callback, 0) console.log(22222);
} setTimeout(callback, 0)
return j; }
} return j;
}
app.fs.scheduleInit = scheduleInit app.fs.scheduleInit = scheduleInit
fs.readdirSync(__dirname).forEach((filename) => { fs.readdirSync(__dirname).forEach((filename) => {
if (!['index.js'].some(f => filename == f)) { if (!['index.js'].some(f => filename == f)) {
const scheduleList = require(`./${filename}`)(app, opts) const scheduleList = require(`./${filename}`)(app, opts)
for (let k of Object.keys(scheduleList)) { for (let k of Object.keys(scheduleList)) {
console.info(`定时任务 ${k} 启动`); console.info(`定时任务 ${k} 启动`);
} }
app.fs.schedule = { app.fs.schedule = {
...app.fs.schedule, ...app.fs.schedule,
...scheduleList, ...scheduleList,
} }
} }
}); });
}; };

55
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所属路段路段具体位置于XXXXXX反馈内容XXX上报人上报时间XX您已超过3天未处理请至平台尽快处理
*/
}
console.log(anomalyList);
} catch (error) {
console.error(error);
}
}
)
return {
notice,
}
}

2
api/app/lib/schedule/zhidiao.js

@ -9,7 +9,7 @@ module.exports = function (app, opts) {
{ {
interval: '24 0 */1 * * *', interval: '24 0 */1 * * *',
immediate: true, immediate: true,
proRun: false, proRun: true,
disabled: false disabled: false
}, },

1
api/config.js

@ -57,6 +57,7 @@ if (
const product = { const product = {
port: flags.port || 8080, port: flags.port || 8080,
staticDirs: ['static'], staticDirs: ['static'],
dev: dev,
mws: [ mws: [
{ {
entry: require('@fs/attachment').entry, entry: require('@fs/attachment').entry,

Loading…
Cancel
Save