BasicTemplateController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.qmth.distributed.print.api;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.qmth.boot.api.constant.ApiConstant;
  4. import com.qmth.distributed.print.business.bean.dto.TemplateDto;
  5. import com.qmth.distributed.print.business.entity.BasicTemplate;
  6. import com.qmth.distributed.print.business.service.BasicTemplateService;
  7. import com.qmth.teachcloud.common.contant.SystemConstant;
  8. import com.qmth.teachcloud.common.util.Result;
  9. import com.qmth.teachcloud.common.util.ResultUtil;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.validation.constraints.Max;
  16. import javax.validation.constraints.Min;
  17. /**
  18. * <p>
  19. * 通用模板 前端控制器
  20. * </p>
  21. *
  22. * @author xf
  23. * @since 2021-03-23
  24. */
  25. @Api(tags = "通用模板Controller")
  26. @RestController
  27. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.basic}/template")
  28. @Validated
  29. public class BasicTemplateController {
  30. @Autowired
  31. private BasicTemplateService basicTemplateService;
  32. /**
  33. * 查询
  34. *
  35. * @param enable
  36. * @param type
  37. * @param name
  38. * @param startTime
  39. * @param endTime
  40. * @param pageNumber
  41. * @param pageSize
  42. * @return
  43. */
  44. @ApiOperation(value = "查询")
  45. @RequestMapping(value = "/list", method = RequestMethod.POST)
  46. public Result list(@RequestParam(value = "enable", required = false) Boolean enable,
  47. @RequestParam(value = "type", required = false) String type,
  48. @RequestParam(value = "name", required = false) String name,
  49. @RequestParam(value = "startTime", required = false) Long startTime,
  50. @RequestParam(value = "endTime", required = false) Long endTime,
  51. @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  52. @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  53. IPage<TemplateDto> templateDtoIPage = basicTemplateService.list(enable, type, name, startTime, endTime, pageNumber, pageSize);
  54. return ResultUtil.ok(templateDtoIPage);
  55. }
  56. /**
  57. * 根据ID查询单个信息
  58. *
  59. * @param id
  60. * @return
  61. */
  62. @ApiOperation(value = "根据ID查询单个信息")
  63. @RequestMapping(value = "/get_one", method = RequestMethod.POST)
  64. public Result getOne(@RequestParam("id") Long id) {
  65. BasicTemplate basicTemplate = basicTemplateService.getOne(id);
  66. return ResultUtil.ok(basicTemplate);
  67. }
  68. /**
  69. * 新增/修改
  70. *
  71. * @param template
  72. * @return
  73. */
  74. @ApiOperation(value = "新增/修改")
  75. @RequestMapping(value = "/save", method = RequestMethod.POST)
  76. public Result save(@RequestBody BasicTemplate template) throws Exception {
  77. boolean isSuccess = basicTemplateService.saveTemplate(template);
  78. return ResultUtil.ok(isSuccess);
  79. }
  80. /**
  81. * 启用/禁用
  82. *
  83. * @param template
  84. * @return
  85. */
  86. @ApiOperation(value = "启用/禁用")
  87. @RequestMapping(value = "/enable", method = RequestMethod.POST)
  88. public Result enable(@RequestBody BasicTemplate template) {
  89. boolean isSuccess = basicTemplateService.enable(template);
  90. return ResultUtil.ok(isSuccess);
  91. }
  92. /**
  93. * 读取模板内容
  94. *
  95. * @param attachmentId
  96. * @return
  97. */
  98. @ApiOperation(value = "读取模板内容")
  99. @RequestMapping(value = "/read_content", method = RequestMethod.POST)
  100. public Result enable(@RequestParam("attachmentId") Long attachmentId) {
  101. Object content = basicTemplateService.readContent(attachmentId);
  102. return ResultUtil.ok(content);
  103. }
  104. }