usual.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 通常接口
  4. class UsualController extends Controller {
  5. constructor(ctx) {
  6. super(ctx);
  7. this.params = this.ctx.params;
  8. this.queryObject = this.ctx.request.query;
  9. this.service = this.ctx.service.usual;
  10. this.reqBody = this.ctx.request.body;
  11. this.queryService = this.ctx.service.query;
  12. this.fetchService = this.ctx.service.fetch;
  13. this.createService = this.ctx.service.create;
  14. this.updateService = this.ctx.service.update;
  15. this.deleteService = this.ctx.service.delete;
  16. this.importService = this.ctx.service.import;
  17. this.statisService = this.ctx.service.statis;
  18. }
  19. // 通用多查
  20. async query() {
  21. const data = await this.queryService.index(this.params, this.queryObject);
  22. this.ctx.ok(data);
  23. }
  24. // 通用单查
  25. async fetch() {
  26. const data = await this.fetchService.index(this.params, this.queryObject);
  27. this.ctx.ok(data);
  28. }
  29. // 通用创建
  30. async create() {
  31. const data = await this.createService.index(this.params, this.reqBody);
  32. this.ctx.ok(data);
  33. }
  34. // 通用修改
  35. async update() {
  36. const data = await this.updateService.index(this.params, this.queryObject, this.reqBody);
  37. this.ctx.ok(data);
  38. }
  39. // 通用删除
  40. async delete() {
  41. const data = await this.deleteService.index(this.params, this.queryObject);
  42. this.ctx.ok(data);
  43. }
  44. // 通用导入
  45. async import() {
  46. const data = await this.importService.index(this.params, this.reqBody);
  47. this.ctx.ok(data);
  48. }
  49. // 统计透传
  50. async statis() {
  51. const data = await this.statisService.index(this.params, this.queryObject);
  52. this.ctx.ok(data);
  53. }
  54. // 预约采集信息报名
  55. async reserve() {
  56. const data = await this.service.reserve(this.reqBody);
  57. this.ctx.ok(data);
  58. }
  59. // 发送消息(微信推送)
  60. async sendMessage() {
  61. const data = await this.service.sendMessage(this.reqBody);
  62. this.ctx.ok(data);
  63. }
  64. // 确认消息(微信推送)
  65. async readMessage() {
  66. const data = await this.service.readMessage(this.params);
  67. this.ctx.ok(data);
  68. }
  69. }
  70. module.exports = UsualController;