Browse Source

修改上传学生接口

liuyu 5 years ago
parent
commit
7020a9a863
2 changed files with 38 additions and 17 deletions
  1. 36 17
      app/service/tasks.js
  2. 2 0
      config/config.default.js

+ 36 - 17
app/service/tasks.js

@@ -12,29 +12,48 @@ class TasksService extends CrudService {
   }
 
   async create(requestBody) {
-    console.log(requestBody);
     // this.ctx.model.create
     const mqid = uuid();
+    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 };
-    const result = await this.ctx.model.Tasks.create(newdata);
-    console.log(result);
-    if (result) {
-      const { mq } = this.ctx;
-      if (mq) {
-        const msg = requestBody.name + '上传文件' + requestBody.content;
-        const parm = {
-          durable: true,
-          headers: {
-            userid: requestBody.userid,
-            mqid,
-          } };
-        console.log(parm);
-        console.log(msg);
-        await mq.topic('stu_import', requestBody.userid, msg, parm);
+    if (res) {
+      if (res.data.data.errcount === 0) {
+        newdata.status = '1';
       } else {
-        this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+        newdata.status = '2';
+        newdata.errmsg = res.data.data.errmsg;
       }
     }
+    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 };
+      // const res = await this.ctx.curl(pathStu, {
+      //   method: 'GET',
+      //   dataType: 'json',
+      //   data: JSON.stringify(data),
+      // });
+      // TODO mq暂时不用,解决后使用mq导入数据
+      // const { mq } = this.ctx;
+      // if (mq) {
+      //   const msg = requestBody.name + '上传文件' + requestBody.content;
+      //   const parm = {
+      //     durable: true,
+      //     headers: {
+      //       userid: requestBody.userid,
+      //       mqid,
+      //     } };
+      //   console.log(parm);
+      //   console.log(msg);
+      //   await mq.topic('stu_import', requestBody.userid, msg, parm);
+      // } else {
+      //   this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+      // }
+    }
   }
 }
 

+ 2 - 0
config/config.default.js

@@ -37,6 +37,8 @@ module.exports = appInfo => {
     },
   };
 
+  config.baseUrl = 'http://localhost:8101/api';
+
   // mongoose config
   config.mongoose = {
     url: 'mongodb://127.0.0.1:27017/smart',