123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 'use strict';
- const _ = require('lodash');
- const uuid = require('uuid');
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- class TasksService extends CrudService {
- constructor(ctx) {
- super(ctx);
- this.model = this.ctx.model.Tasks;
- }
- 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',
- });
- if (res) {
- const task = await this.model.findById(result.id);
- if (res.data.data.errcount === 0) {
- task.status = '1';
- } else {
- task.status = '2';
- task.errmsg = res.data.data.errmsg;
- }
- task.save();
- }
- // 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插件!!!!!!');
- // }
- }
- }
- }
- module.exports = TasksService;
|