myzj.controller.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Controller, Inject, Get, Param, Body, Post } from "@midwayjs/core";
  2. import { Page, Query } from "../decorator/page.decorator";
  3. import { PartsService } from "../service/parts.service";
  4. import { RF } from "../response/CustomerResponse";
  5. import { QuestionService } from "../service/v2/question.service";
  6. import { get } from "lodash";
  7. import { PageViewService } from "../service/v2/pageView.service";
  8. @Controller('/myzj', { tagName: '民意征集' })
  9. export class MyzjController {
  10. @Inject()
  11. service: PartsService;
  12. @Inject()
  13. questionService: QuestionService;
  14. @Inject()
  15. pageViewService: PageViewService
  16. @Get('/question', { routerName: '投诉与建议-查询' })
  17. async queryQuestion(@Query() query: object, @Page() page: object) {
  18. let where = {}
  19. if (Object.keys(query).length > 0) {
  20. where = { where: query }
  21. }
  22. const result = await this.questionService.query(where, { ...page })
  23. return RF.success(result)
  24. }
  25. @Get('/question/:id', { routerName: '投诉与建议-单查询' })
  26. async fetchQuestion(@Param('id') id: number) {
  27. let where = { id }
  28. const result = await this.questionService.fetch(where)
  29. return RF.success(result)
  30. }
  31. @Post('/question', { routerName: '投诉与建议-创建' })
  32. async createQuestion(@Body() body: object) {
  33. const result = await this.questionService.create(body)
  34. return RF.success(result)
  35. }
  36. @Post('/question/:id', { routerName: '投诉与建议-修改' })
  37. async updateQuestion(@Param('id') id: number, @Body() body: object) {
  38. const result = await this.questionService.update({ where: { id } }, body)
  39. return RF.success(result)
  40. }
  41. @Get('/list/rdhy', { routerName: '热点回应列表' })
  42. async list(@Query() query: object, @Page() page: object) {
  43. const channel_id = 197
  44. const { data, total } = await this.service.contentList(channel_id, query, page)
  45. const newList = []
  46. for (const i of newList) {
  47. const newObject: any = {
  48. content_id: get(i, 'content_id'),
  49. id: get(i, 'content_id'),
  50. title: get(i, 'ext.title'),
  51. release_date: get(i, 'ext.release_date'),
  52. url: get(i, 'ext.type_img')
  53. }
  54. const views = await this.pageViewService.fetch(newObject.content_id, true)
  55. newObject.views = views
  56. newList.push(newObject)
  57. }
  58. return RF.success({ data: newList, total })
  59. }
  60. @Get('/detail/:content_id', { routerName: '热点回应详情' })
  61. async detail(@Param('content_id') content_id: string) {
  62. const data = await this.service.contentDetail(content_id)
  63. return RF.success(data);
  64. }
  65. }