From d0c5eb96b9aea4cd59baebe58ad477539fdfdb7b Mon Sep 17 00:00:00 2001 From: zhaobing Date: Wed, 10 Jan 2024 13:52:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/models/work_order_notice.js | 8 ++++++++ api/app/lib/schedule/work_notice.js | 13 ++++++++----- api/app/lib/utils/qy.js | 7 +++++++ script/4.3/schema/1.create_work_order_notice.sql | 9 ++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/api/app/lib/models/work_order_notice.js b/api/app/lib/models/work_order_notice.js index 5855edd..fc144d8 100644 --- a/api/app/lib/models/work_order_notice.js +++ b/api/app/lib/models/work_order_notice.js @@ -23,6 +23,14 @@ module.exports = dc => { primaryKey: false, autoIncrement: false, }, + createTime: { + field: 'create_time', + type: DataTypes.DATE, + allowNull: true, + comment: '', + primaryKey: false, + autoIncrement: false, + }, processingPersonnelId: { field: 'processing_personnel_id', type: DataTypes.INTEGER, diff --git a/api/app/lib/schedule/work_notice.js b/api/app/lib/schedule/work_notice.js index fb0afda..39d537c 100644 --- a/api/app/lib/schedule/work_notice.js +++ b/api/app/lib/schedule/work_notice.js @@ -12,11 +12,10 @@ const schedule = require('node-schedule') const moment = require('moment') const request = require('superagent') let isDev = false -isDev = true +// isDev = true const sendType = { 'mini': 'miniprogram_notice', } - module.exports = function (app, opts) { const workOrderNotice = app.fs.scheduleInit( { @@ -63,7 +62,8 @@ module.exports = function (app, opts) { ON fgroup.id = fprocess.group_id INNER JOIN ${camWorkflow}.act_hi_procinst AS procin ON procin.id_ = story.procinst_id - AND procin.state_ in ('COMPLETED','ACTIVE')` + AND procin.state_ in ('COMPLETED','ACTIVE') + WHERE story.apply_user in ('731')` ).toPromise() if (formRes && formRes.length > 0) { for (let f of formRes) { @@ -88,6 +88,7 @@ module.exports = function (app, opts) { processingPersonnelPhone: user && user.length && user[0].phone, isSend: false, haveDone: parseData.solution_status.value && parseData.solution_status.value === '否' ? false : true || false, + createTime: moment(f.createTime).format('YYYY-MM-DD'), }) } } else { @@ -119,15 +120,17 @@ module.exports = function (app, opts) { if (sendRslt && sendRslt.length) { console.log('sendRslt发送通知的数据',sendRslt) for (let { dataValues: c } of sendRslt) { + await new Promise(resolve => setTimeout(resolve, 5000)); // 这里的5000是等待时间,单位为毫秒,您可以根据需要调整 //根据电话号码查询企业微信对应的userId //phone,兰邦夫的电话号码(2024-1-9) const userId = await getUserId(opts, c.processingPersonnelPhone) + await new Promise(resolve => setTimeout(resolve, 5000)); // 这里的5000是等待时间,单位为毫秒,您可以根据需要调整 const manager = await getUserId(opts, phone) //根据查询的userId发送通知 if (userId) { const res = await sendWechat({ opts, msgtype: sendType["mini"], - data: { userId: userId, touser: [userId] } + data: { userId: userId, touser: [userId],content:`你有一个表单《运维中台售后工单问题处理工单 ${c.createTime}》,修复时间即将超期,请尽快处理` } }) if (res.body.errmsg === 'ok') { //将已发送的记录的isSend修改为true(已发送) @@ -141,7 +144,7 @@ module.exports = function (app, opts) { if (manager) { const res = await sendWechat({ opts, msgtype: sendType["mini"], - data: { userId: manager, touser: [manager] } + data: { userId: manager, touser: [manager],content:`你有一个表单《运维中台售后工单问题处理工单 ${c.createTime}》,修复时间即将超期,请尽快处理` } }) if (res.body.errmsg === 'ok') { //将已发送的记录的isSend修改为true(已发送) diff --git a/api/app/lib/utils/qy.js b/api/app/lib/utils/qy.js index 8edca0b..1e43e2d 100644 --- a/api/app/lib/utils/qy.js +++ b/api/app/lib/utils/qy.js @@ -15,6 +15,9 @@ const WechatApi = { const sendType = { 'mini': 'miniprogram_notice', } +const userIds={ + +} module.exports = function (app, opts) { const getGetToken = async (opts) => { @@ -42,11 +45,15 @@ module.exports = function (app, opts) { //获取用户id const getUserId = async (opts, phoneNum) => { + if (userIds[phoneNum]) { + return userIds[phoneNum]; + } console.log(`info: getGetToken--start-- `) await getGetToken(opts) console.log(`info: getGetToken--end-- `) const res = await request.post(`${opts.weChat.reqUrl}${WechatApi.getUserId}?access_token=${wechatExpires.accessToken}`, { mobile: phoneNum }) if(res.body.errmsg==='ok'){ + userIds[phoneNum] = res.body.userid return res.body.userid }else{ diff --git a/script/4.3/schema/1.create_work_order_notice.sql b/script/4.3/schema/1.create_work_order_notice.sql index 85eec84..b73608a 100644 --- a/script/4.3/schema/1.create_work_order_notice.sql +++ b/script/4.3/schema/1.create_work_order_notice.sql @@ -23,4 +23,11 @@ comment on column work_order_notice.is_send is '是否已发送'; comment on column work_order_notice.procinst_id is '表单实例id'; -comment on column work_order_notice.have_done is '是否解决'; \ No newline at end of file +comment on column work_order_notice.have_done is '是否解决'; + + + +alter table work_order_notice + add create_time timestamp without time zone; + +comment on column public.work_order_notice.create_time is '表单发起时间'; \ No newline at end of file