tasks.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 pathStu = this.ctx.app.config.baseUrl + '/enrollments/dataimp?type=' + requestBody.type + '&content=' + requestBody.content;
  14. const res = await this.ctx.curl(pathStu, {
  15. method: 'GET',
  16. dataType: 'json',
  17. });
  18. const newdata = { ...requestBody, mqid };
  19. if (res) {
  20. if (res.data.data.errcount === 0) {
  21. newdata.status = '1';
  22. } else {
  23. newdata.status = '2';
  24. newdata.errmsg = res.data.data.errmsg;
  25. }
  26. }
  27. const result = await this.ctx.model.Tasks.create(newdata);
  28. if (result) {
  29. // const pathStu = this.ctx.app.config.baseUrl + 'stud/enrollments/dataimp';
  30. // const data = { type: newdata.type, content: newdata.content };
  31. // const res = await this.ctx.curl(pathStu, {
  32. // method: 'GET',
  33. // dataType: 'json',
  34. // data: JSON.stringify(data),
  35. // });
  36. // TODO mq暂时不用,解决后使用mq导入数据
  37. // const { mq } = this.ctx;
  38. // if (mq) {
  39. // const msg = requestBody.name + '上传文件' + requestBody.content;
  40. // const parm = {
  41. // durable: true,
  42. // headers: {
  43. // userid: requestBody.userid,
  44. // mqid,
  45. // } };
  46. // console.log(parm);
  47. // console.log(msg);
  48. // await mq.topic('stu_import', requestBody.userid, msg, parm);
  49. // } else {
  50. // this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
  51. // }
  52. }
  53. }
  54. }
  55. module.exports = TasksService;