Browse Source

feat:修改发送通知逻辑

dev
zhaobing 1 year ago
parent
commit
bc2bc37c10
  1. 94
      api/app/lib/schedule/work_notice.js
  2. 8
      api/config.js

94
api/app/lib/schedule/work_notice.js

@ -27,8 +27,9 @@ module.exports = function (app, opts) {
async () => { async () => {
try { try {
//前一次执行时间 //前一次执行时间
const phone = opts.phone//运维部门审批工单的负责人的电话号码
console.log('运维中台售后问题处理工单数据抽取开始', moment().format('YYYY-MM-DD HH:mm:ss')) 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 startTime = moment().format('YYYY-MM-DD HH:mm:ss')
const { models } = app.fs.dc const { models } = app.fs.dc
const { clickHouse } = app.fs const { clickHouse } = app.fs
@ -76,8 +77,8 @@ module.exports = function (app, opts) {
procinstId: f.procinstId, 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() user = await clickHouse.pepEmis.query(`select * from user where id=${Number(parseData.processing_personnel.value)}`).toPromise()
if (!rlst) { if (!rlst) {
await models.WorkOrderNotice.create({ await models.WorkOrderNotice.create({
@ -86,11 +87,11 @@ module.exports = function (app, opts) {
processingPersonnelId: parseData.processing_personnel.value, processingPersonnelId: parseData.processing_personnel.value,
processingPersonnelPhone: user && user.length && user[0].phone, processingPersonnelPhone: user && user.length && user[0].phone,
isSend: false, isSend: false,
haveDone: parseData.solution_status.value === '否' ? false : true, haveDone: parseData.solution_status.value && parseData.solution_status.value === '否' ? false : true || false,
}) })
} }
} else { } 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 lastDay = moment().subtract(1, 'days')
//需要发送提醒的数据 //需要发送提醒的数据
const sendRslt=await models.WorkOrderNotice.findAll({ const sendRslt = await models.WorkOrderNotice.findAll({
where: { where: {
isSend: false,//未发送 isSend: false,//未发送
haveDone: false,//未完成 haveDone: false,//未完成
planTime:{ planTime: {
$gte: lastDay $gte: lastDay
} }
} }
}) })
//发送企业微信通知 //发送企业微信通知
if(sendRslt&&sendRslt.length){ if (sendRslt && sendRslt.length) {
for (let { dataValues: c } of sendRslt) { for (let { dataValues: c } of sendRslt) {
//根据电话号码查询企业微信对应的userId //根据电话号码查询企业微信对应的userId
//15083558812,兰邦夫的电话号码 //phone,兰邦夫的电话号码(2024-1-9)
if(c.processingPersonnelPhone==='15083558812'){ const userId = await getUserId(opts, c.processingPersonnelPhone)
const userId=await getUserId(opts,c.processingPersonnelPhone) const manager = await getUserId(opts, phone)
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')
//根据查询的userId发送通知 //根据查询的userId发送通知
if(userId){ if (userId) {
const res= await sendWechat({ const res = await sendWechat({
opts, msgtype: sendType["mini"], opts, msgtype: sendType["mini"],
data: { userId:userId, touser: [userId] } data: { userId: userId, touser: [userId] }
}) })
if(res.body.errmsg==='ok'){ if (res.body.errmsg === 'ok') {
//将已发送的记录的isSend修改为true(已发送) //将已发送的记录的isSend修改为true(已发送)
await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } })
}else{ } else {
console.log('发送消息失败',res.body.errmsg) console.log('发送消息失败', res.body.errmsg)
} }
}else{ } else {
console.log('查询不到对应的userId',c.processingPersonnelPhone) console.log('查询不到对应的userId', c.processingPersonnelPhone)
} }
if(userLan){ if (manager) {
const res= await sendWechat({ const res = await sendWechat({
opts, msgtype: sendType["mini"], opts, msgtype: sendType["mini"],
data: { userId:userLan, touser: [userLan] } data: { userId: manager, touser: [manager] }
}) })
if(res.body.errmsg==='ok'){ if (res.body.errmsg === 'ok') {
//将已发送的记录的isSend修改为true(已发送) //将已发送的记录的isSend修改为true(已发送)
console.log('已发送给兰邦夫') console.log('已发送给运维部门主管')
// await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } }) // await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } })
}else{ } else {
console.log('发送消息失败',res.body.errmsg) console.log('发送消息失败', res.body.errmsg)
} }
}else{ } else {
console.log('查询不到对应的userId','15083558812') console.log('查询不到对应的userId', phone)
} }
} }
} }

8
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_CORPSECRET = process.env.WXCHAT_CORPSECRET || "JkzFbnl9fX0EvwSmV8inWir5vjV_m7lKyrjKwWft1gs";
const WXCHAT_ADDRESS_CORPSECRET = process.env.WXCHAT_ADDRESS_CORPSECRET || "GmgiT4Fjjm4SD_2tI8zH1ucpuDUqM7Eh00LkPxCs9ZE";//企业微信通讯录同步secret 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 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 参数 // Redis 参数
const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP 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 端口 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, VCMP_APP_ID, VCMP_APP_SECRET,
API_CRAW_URL, API_CRAW_URL,
CLICKHOUST_DATA_ALARM_LOCAL, CLICKHOUST_DATA_ALARM_LOCAL,
TYPES TYPES,
PHONE
} }
Object.keys(requireParams).forEach(key => { Object.keys(requireParams).forEach(key => {
@ -218,7 +219,8 @@ const product = {
secretKey: QINIU_SK secretKey: QINIU_SK
}, },
maxSize: 104857600, // 100M maxSize: 104857600, // 100M
types: TYPES types: TYPES,
phone: PHONE
} }
}, { }, {
entry: require('./app').entry, entry: require('./app').entry,

Loading…
Cancel
Save