tasks.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. const _ = require('lodash');
  3. const uuid = require('uuid');
  4. const { CrudService } = require('naf-framework-mongoose/lib/service');
  5. class TasksService extends CrudService {
  6. constructor(ctx) {
  7. super(ctx);
  8. this.model = this.ctx.model.Tasks;
  9. }
  10. async create(requestBody) {
  11. // this.ctx.model.create
  12. const mqid = uuid();
  13. const newdata = { ...requestBody, mqid };
  14. const result = await this.model.create(newdata);
  15. const pathStu = this.ctx.app.config.baseUrl + '/enrollments/dataimp?type=' + requestBody.type + '&content=' + requestBody.content;
  16. const res = await this.ctx.curl(pathStu, {
  17. method: 'GET',
  18. dataType: 'json',
  19. });
  20. if (res) {
  21. const task = await this.model.findById(result.id);
  22. if (res.data.data.errcount === 0) {
  23. task.status = '1';
  24. } else {
  25. task.status = '2';
  26. task.errmsg = res.data.data.errmsg;
  27. }
  28. task.save();
  29. }
  30. // const result = await this.ctx.model.Tasks.create(newdata);
  31. if (result) {
  32. // const pathStu = this.ctx.app.config.baseUrl + 'stud/enrollments/dataimp';
  33. // const data = { type: newdata.type, content: newdata.content };
  34. // const res = await this.ctx.curl(pathStu, {
  35. // method: 'GET',
  36. // dataType: 'json',
  37. // data: JSON.stringify(data),
  38. // });
  39. // TODO mq暂时不用,解决后使用mq导入数据
  40. // const { mq } = this.ctx;
  41. // if (mq) {
  42. // const msg = requestBody.name + '上传文件' + requestBody.content;
  43. // const parm = {
  44. // durable: true,
  45. // headers: {
  46. // userid: requestBody.userid,
  47. // mqid,
  48. // } };
  49. // console.log(parm);
  50. // console.log(msg);
  51. // await mq.topic('stu_import', requestBody.userid, msg, parm);
  52. // } else {
  53. // this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
  54. // }
  55. }
  56. }
  57. }
  58. module.exports = TasksService;