liuyu hace 5 años
padre
commit
c61d728c6b
Se han modificado 1 ficheros con 8 adiciones y 5 borrados
  1. 8 5
      app/service/tasks.js

+ 8 - 5
app/service/tasks.js

@@ -14,21 +14,24 @@ class TasksService extends CrudService {
   async create(requestBody) {
     // this.ctx.model.create
     const mqid = uuid();
+    const newdata = { ...requestBody, mqid };
+    const result = await this.model.create(newdata);
     const pathStu = this.ctx.app.config.baseUrl + '/enrollments/dataimp?type=' + requestBody.type + '&content=' + requestBody.content;
     const res = await this.ctx.curl(pathStu, {
       method: 'GET',
       dataType: 'json',
     });
-    const newdata = { ...requestBody, mqid };
     if (res) {
+      const task = await this.model.findById(result.id);
       if (res.data.data.errcount === 0) {
-        newdata.status = '1';
+        task.status = '1';
       } else {
-        newdata.status = '2';
-        newdata.errmsg = res.data.data.errmsg;
+        task.status = '2';
+        task.errmsg = res.data.data.errmsg;
       }
+      task.save();
     }
-    const result = await this.ctx.model.Tasks.create(newdata);
+    // const result = await this.ctx.model.Tasks.create(newdata);
     if (result) {
       // const pathStu = this.ctx.app.config.baseUrl + 'stud/enrollments/dataimp';
       // const data = { type: newdata.type, content: newdata.content };