diff --git a/api/app/lib/schedule/work_notice.js b/api/app/lib/schedule/work_notice.js index d61c2c9..dd01330 100644 --- a/api/app/lib/schedule/work_notice.js +++ b/api/app/lib/schedule/work_notice.js @@ -27,8 +27,9 @@ module.exports = function (app, opts) { async () => { try { //前一次执行时间 + const phone = opts.phone//运维部门审批工单的负责人的电话号码 console.log('运维中台售后问题处理工单数据抽取开始', moment().format('YYYY-MM-DD HH:mm:ss')) - const { parseProcessData,getUserId,sendWechat } = app.fs.utils + const { parseProcessData, getUserId, sendWechat } = app.fs.utils const startTime = moment().format('YYYY-MM-DD HH:mm:ss') const { models } = app.fs.dc const { clickHouse } = app.fs @@ -76,8 +77,8 @@ module.exports = function (app, opts) { procinstId: f.procinstId, } }) - //没有计划完成时间,没有处理人,没有是否解决,都不推送通知 - if (parseData.processing_personnel.value && parseData.planTime.value && parseData.solution_status.value) { + //没有计划完成时间,没有处理人,都不推送通知 + if (parseData.processing_personnel.value && parseData.planTime.value) { user = await clickHouse.pepEmis.query(`select * from user where id=${Number(parseData.processing_personnel.value)}`).toPromise() if (!rlst) { await models.WorkOrderNotice.create({ @@ -86,11 +87,11 @@ module.exports = function (app, opts) { processingPersonnelId: parseData.processing_personnel.value, processingPersonnelPhone: user && user.length && user[0].phone, isSend: false, - haveDone: parseData.solution_status.value === '否' ? false : true, + haveDone: parseData.solution_status.value && parseData.solution_status.value === '否' ? false : true || false, }) } } else { - console.log('没有对应的处理人', f.procinstId) + console.log('没有对应的处理人,没有计划完成时间', f.procinstId) } } @@ -104,72 +105,55 @@ module.exports = function (app, opts) { // 计算当前时间之后一天的日期 const lastDay = moment().subtract(1, 'days') //需要发送提醒的数据 - const sendRslt=await models.WorkOrderNotice.findAll({ + const sendRslt = await models.WorkOrderNotice.findAll({ where: { isSend: false,//未发送 haveDone: false,//未完成 - planTime:{ + planTime: { $gte: lastDay } - } + } }) //发送企业微信通知 - if(sendRslt&&sendRslt.length){ + if (sendRslt && sendRslt.length) { for (let { dataValues: c } of sendRslt) { //根据电话号码查询企业微信对应的userId - //15083558812,兰邦夫的电话号码 - if(c.processingPersonnelPhone==='15083558812'){ - const userId=await getUserId(opts,c.processingPersonnelPhone) - if(userId){ - const res= await sendWechat({ - opts, msgtype: sendType["mini"], - data: { userId:userId, touser: [userId] } - }) - if(res.body.errmsg==='ok'){ - //将已发送的记录的isSend修改为true(已发送) - await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) - }else{ - console.log('发送消息失败',res.body.errmsg) - } - }else{ - console.log('查询不到对应的userId',c.processingPersonnelPhone) - } - } - const userId=await getUserId(opts,c.processingPersonnelPhone) - const userLan=await getUserId(opts,'15083558812') + //phone,兰邦夫的电话号码(2024-1-9) + const userId = await getUserId(opts, c.processingPersonnelPhone) + const manager = await getUserId(opts, phone) //根据查询的userId发送通知 - if(userId){ - const res= await sendWechat({ + if (userId) { + const res = await sendWechat({ opts, msgtype: sendType["mini"], - data: { userId:userId, touser: [userId] } - }) - if(res.body.errmsg==='ok'){ + data: { userId: userId, touser: [userId] } + }) + if (res.body.errmsg === 'ok') { //将已发送的记录的isSend修改为true(已发送) - await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) - }else{ - console.log('发送消息失败',res.body.errmsg) - } - }else{ - console.log('查询不到对应的userId',c.processingPersonnelPhone) + await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) + } else { + console.log('发送消息失败', res.body.errmsg) + } + } else { + console.log('查询不到对应的userId', c.processingPersonnelPhone) } - if(userLan){ - const res= await sendWechat({ - opts, msgtype: sendType["mini"], - data: { userId:userLan, touser: [userLan] } - }) - if(res.body.errmsg==='ok'){ - //将已发送的记录的isSend修改为true(已发送) - console.log('已发送给兰邦夫') + if (manager) { + const res = await sendWechat({ + opts, msgtype: sendType["mini"], + data: { userId: manager, touser: [manager] } + }) + if (res.body.errmsg === 'ok') { + //将已发送的记录的isSend修改为true(已发送) + console.log('已发送给运维部门主管') // await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) - }else{ - console.log('发送消息失败',res.body.errmsg) - } - }else{ - console.log('查询不到对应的userId','15083558812') - } + } else { + console.log('发送消息失败', res.body.errmsg) + } + } else { + console.log('查询不到对应的userId', phone) + } + - } } diff --git a/api/config.js b/api/config.js index 243f330..8a6ac36 100644 --- a/api/config.js +++ b/api/config.js @@ -86,7 +86,7 @@ const WXCHAT_CORPID = process.env.WXCHAT_CORPID || 'wwb729be4a7f781f75'; const WXCHAT_CORPSECRET = process.env.WXCHAT_CORPSECRET || "JkzFbnl9fX0EvwSmV8inWir5vjV_m7lKyrjKwWft1gs"; const WXCHAT_ADDRESS_CORPSECRET = process.env.WXCHAT_ADDRESS_CORPSECRET || "GmgiT4Fjjm4SD_2tI8zH1ucpuDUqM7Eh00LkPxCs9ZE";//企业微信通讯录同步secret const WXCHAT_REDIRECT_URL = process.env.WXCHAT_REDIRECT_URL || `https://open.weixin.qq.com/connect/oauth2/authorize?appid={corpid}&redirect_uri={redirectUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`; - +const PHONE=process.env.PHONE||'15083558812'//运维工单部门主管人的电话号码 // Redis 参数 const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 @@ -193,7 +193,8 @@ const requireParams = { VCMP_APP_ID, VCMP_APP_SECRET, API_CRAW_URL, CLICKHOUST_DATA_ALARM_LOCAL, - TYPES + TYPES, + PHONE } Object.keys(requireParams).forEach(key => { @@ -218,7 +219,8 @@ const product = { secretKey: QINIU_SK }, maxSize: 104857600, // 100M - types: TYPES + types: TYPES, + phone: PHONE } }, { entry: require('./app').entry,