Browse Source

feat:修改发送通知逻辑

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

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

@ -27,6 +27,7 @@ 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 startTime = moment().format('YYYY-MM-DD HH:mm:ss')
@ -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)
}
}
@ -118,26 +119,9 @@ module.exports = function (app, opts) {
if (sendRslt && sendRslt.length) {
for (let { dataValues: c } of sendRslt) {
//根据电话号码查询企业微信对应的userId
//15083558812,兰邦夫的电话号码
if(c.processingPersonnelPhone==='15083558812'){
//phone,兰邦夫的电话号码(2024-1-9)
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')
const manager = await getUserId(opts, phone)
//根据查询的userId发送通知
if (userId) {
const res = await sendWechat({
@ -153,20 +137,20 @@ module.exports = function (app, opts) {
} else {
console.log('查询不到对应的userId', c.processingPersonnelPhone)
}
if(userLan){
if (manager) {
const res = await sendWechat({
opts, msgtype: sendType["mini"],
data: { userId:userLan, touser: [userLan] }
data: { userId: manager, touser: [manager] }
})
if (res.body.errmsg === 'ok') {
//将已发送的记录的isSend修改为true(已发送)
console.log('已发送给兰邦夫')
console.log('已发送给运维部门主管')
// await models.WorkOrderNotice.update({ isSend: true }, { where: { id: c.id } })
} else {
console.log('发送消息失败', res.body.errmsg)
}
} 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_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,

Loading…
Cancel
Save