瀏覽代碼

模板消息更改

liuyu 5 年之前
父節點
當前提交
7202d57a57
共有 3 個文件被更改,包括 78 次插入21 次删除
  1. 2 0
      app.js
  2. 73 21
      app/service/rabbitmq.js
  3. 3 0
      app/service/wechat.js

+ 2 - 0
app.js

@@ -13,6 +13,8 @@ class AppBootHook {
     await ctx.service.rabbitmq.receiveQueueMsg('corp_apply');
     // 学生投递简历消息接收事件
     await ctx.service.rabbitmq.receiveQueueMsg('stu_apply');
+    // 企业发送面试邀请给学生
+    await ctx.service.rabbitmq.receiveQueueMsgOffer('stu_offer');
 
     // 发送模板消息
     // 学校审核企业入驻情况消息

+ 73 - 21
app/service/rabbitmq.js

@@ -69,15 +69,21 @@ class RabbitmqService extends Service {
           // const properties = msg.properties;
           const headers = msg.properties.headers;
           // 插入待办事项到数据库中。
-          const path = self.ctx.app.config.baseDirMq + self.ctx.app.config.corpsDirMq + headers.userid;
-          const corp = self.ctx.curl(path, {
+          const path = self.ctx.app.config.baseDirMq + self.ctx.app.config.corpsDirMq + headers.userId + '/users';
+          self.ctx.curl(path, {
             method: 'GET',
             dataType: 'json',
-          });
-          // 插入待办事项到数据库中。
-          if (corp != null) {
-            self.service.wechat.sendTemplateMsg(msgvalue.REVIEW_TEMPLATE_ID, corp.openid, '您的申请已经得到批复', result, headers.name, '企业申请', headers.remark);
-          }
+          }).then(
+            function(corpUser) {
+              if (corpUser != null) {
+                const _datas = corpUser.data.data;
+                const _self = self;
+                for (let i = 0; i < _datas.length; i++) {
+                  const _data = _datas[i];
+                  self.service.wechat.sendTemplateMsg(_self.ctx.app.config.REVIEW_TEMPLATE_ID, _data.openid, '您的申请已经得到批复', result, headers.name, '企业申请', headers.remark);
+                }
+              }
+            });
         }, { noAck: true });
       } catch (e) {
         console.log('==e==', e);
@@ -107,25 +113,71 @@ class RabbitmqService extends Service {
           // const properties = msg.properties;
           const headers = msg.properties.headers;
           // 插入待办事项到数据库中。
-          const path = self.ctx.app.config.baseDirMq + self.ctx.app.config.stusDirMq + headers.userid;
+          const path = self.ctx.app.config.baseDirMq + self.ctx.app.config.stusDirMq + '?corpid=' + headers.userId;
           // const path = 'http://10.16.5.15:8101/api/studentcorp' + headers.userid;
-          const stus = self.ctx.curl(path, {
+          self.ctx.curl(path, {
             method: 'GET',
             dataType: 'json',
-          });
-          for (const elem of stus.data) {
-
-            const pathStu = self.ctx.app.config.baseDirMq + self.ctx.app.config.strDirMq + elem.id;
-            const stud = self.ctx.curl(pathStu, {
-              method: 'GET',
-              dataType: 'json',
+          }).then(
+            function(stus) {
+              if (stus != null) {
+                for (const elem of stus.data.data) {
+                  const pathStu = self.ctx.app.config.baseDirMq + self.ctx.app.config.strDirMq + elem.studid;
+                  self.ctx.curl(pathStu, {
+                    method: 'GET',
+                    dataType: 'json',
+                  }).then(
+                    // eslint-disable-next-line no-loop-func
+                    function(stud) {
+                      if (stud != null) {
+                        self.service.wechat.sendTemplateMsg(self.ctx.app.config.REVIEW_TEMPLATE_ID, stud.data.data.openid, '您订阅的企业已经有新职位发布', result, headers.name, '职位发布', headers.remark);
+                      }
+                    });
+                }
+              }
             });
-            // 插入待办事项到数据库中。
-            if (stud != null) {
-              self.service.wechat.sendTemplateMsg(msgvalue.REVIEW_TEMPLATE_ID, stud.data.openid, '您订阅的企业已经有新职位发布', result, headers.name, '职位发布', headers.remark);
-            }
-          }
 
+
+        }, { noAck: true });
+      } catch (e) {
+        console.log('==e==', e);
+        await ch.close();
+      }
+    } else {
+      this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+    }
+  }
+
+  // 接收企业发送面试邀请发送给学生消息
+  async receiveQueueMsgOffer(ex) {
+    const self = this;
+    const { mq } = self.ctx;
+    if (mq) {
+      const ch = await mq.conn.createChannel();
+      try {
+        await ch.assertExchange(ex, self.exType, { durable: self.durable });
+        const q = await ch.assertQueue('', { exclusive: true });
+        console.log('==q=', q);
+        // 队列绑定 exchange
+        await ch.bindQueue(q.queue, ex, '*');
+        ch.consume(q.queue, msg => {
+          console.log('收到消息: ', msg);
+          const result = msg.content.toString();
+          // const fields = msg.fields;
+          // const properties = msg.properties;
+          const headers = msg.properties.headers;
+          // 插入待办事项到数据库中。
+          const pathStu = self.ctx.app.config.baseDirMq + self.ctx.app.config.strDirMq + headers.userId;
+          self.ctx.curl(pathStu, {
+            method: 'GET',
+            dataType: 'json',
+          }).then(
+            // eslint-disable-next-line no-loop-func
+            function(stud) {
+              if (stud != null) {
+                self.service.wechat.sendTemplateMsg(self.ctx.app.config.REVIEW_TEMPLATE_ID, stud.data.data.openid, '您有新的面试邀请,请及时查看。', result, headers.name, '面试邀请', headers.remark);
+              }
+            });
         }, { noAck: true });
       } catch (e) {
         console.log('==e==', e);

+ 3 - 0
app/service/wechat.js

@@ -39,6 +39,9 @@ class WechatService extends Service {
         },
       },
     };
+    console.log('templateid---' + templateid);
+    console.log('openid---' + openid);
+    console.log('requestData---' + JSON.stringify(requestData));
     await this.ctx.curl(url, {
       method: 'post',
       headers: {