course.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. const await = require('await-stream-ready/lib/await');
  3. const { bodyHandleByService } = require('../../extend/context');
  4. const Controller = require('egg').Controller;
  5. class CourseController extends Controller {
  6. async list() {
  7. const {ctx, service} = this;
  8. let query = ctx.request.query;
  9. let ret = await service.course.adminList(query);
  10. ctx.adminOK(ret);
  11. }
  12. async delete() {
  13. const {ctx, service} = this;
  14. let id = ctx.request.query.id;
  15. let ret = await service.course.delete(id);
  16. ctx.adminOK(ret, "删除成功");
  17. }
  18. async edit() {
  19. const {ctx, service} = this;
  20. let data = ctx.request.body;
  21. let ret = await service.course.edit( data );
  22. ctx.adminOK(ret, "更新成功");
  23. }
  24. async add() {
  25. const {ctx, service} = this;
  26. let data = ctx.request.body;
  27. let ret = await service.course.add( data );
  28. ctx.adminOK(ret, "添加成功");
  29. }
  30. async exportXls() {
  31. const {ctx, service} = this;
  32. ctx.set("Content-Type", "application/vnd.openxmlformats");
  33. ctx.set("Content-Disposition","attachment;filename*=UTF-8 xx.xlsx");
  34. let ret = await service.course.exportXls( ctx.request.query );
  35. ctx.body = ret;
  36. }
  37. async lock () {
  38. const {ctx, service} = this;
  39. await ctx.bodyHandleByService(service.course, "lock", "操作成功");
  40. }
  41. }
  42. module.exports = CourseController;