liuyu 5 years ago
parent
commit
c2fc1577b9
2 changed files with 6 additions and 9 deletions
  1. 1 1
      app/model/tasks.js
  2. 5 8
      app/service/tasks.js

+ 1 - 1
app/model/tasks.js

@@ -10,7 +10,7 @@ const TasksSchema = {
   type: { type: String, required: false, maxLength: 64 }, // 类别
   content: { type: String, required: false, maxLength: 64 }, // 内容
   status: { type: String, required: false, maxLength: 2 }, // 状态
-  sendstatus: { type: String, required: false, maxLength: 2, default: '0' }, // 发送
+  mqid: { type: String, required: false }, // 发送
   errmsg: { type: String, required: false }, // 导入错误信息
 };
 

+ 5 - 8
app/service/tasks.js

@@ -14,28 +14,25 @@ class TasksService extends CrudService {
   async create(requestBody) {
     console.log(requestBody);
     // this.ctx.model.create
-    const result = await this.ctx.model.Tasks.create(requestBody);
+    const mqid = uuid();
+    const newdata = { ...requestBody, mqid };
+    const result = await this.ctx.model.Tasks.create(newdata);
     console.log(result);
-    if (result != null) {
+    if (result) {
       const { mq } = this.ctx;
-      const task = await this.model.findById(result.id);
       if (mq) {
         const msg = requestBody.name + '上传文件' + requestBody.content;
         const parm = {
           durable: true,
           headers: {
             userid: requestBody.userid,
-            mqid: uuid(),
+            mqid,
           } };
         console.log(parm);
         console.log(msg);
         await mq.topic('stu_import', requestBody.userid, msg, parm);
-        task.sendstatus = '1';
-        await task.save();
       } else {
         this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
-        task.sendstatus = '2';
-        await task.save();
       }
     }
   }