EventController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.benyun.controller;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.benyun.boot.core.vo.Result;
  4. import com.benyun.entity.Event;
  5. import com.benyun.service.EventService;
  6. import com.benyun.vo.EventPageVo;
  7. import lombok.RequiredArgsConstructor;
  8. import org.beetl.sql.core.engine.PageQuery;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. /**
  13. * @author makejava
  14. * create on 2023-03-17 09:06:58
  15. */
  16. @RestController
  17. @RequestMapping("event")
  18. @RequiredArgsConstructor(onConstructor_ = {@Autowired})
  19. @CrossOrigin
  20. public class EventController {
  21. /**
  22. * 服务对象
  23. */
  24. private final EventService eventService;
  25. /**
  26. * 查询所有数据
  27. *
  28. * @return 所有数据
  29. */
  30. @GetMapping("/queryAll")
  31. public Result<List<Event>> queryAll() {
  32. return Result.success(eventService.queryAll());
  33. }
  34. /**
  35. * 分页查询数据
  36. *
  37. * @return 所有数据
  38. */
  39. @GetMapping("/queryPage")
  40. public Result<EventPageVo> queryPage(@RequestParam Integer pageNum,
  41. @RequestParam Integer pageSize,
  42. @RequestParam String applyId,
  43. @RequestParam(required = false) String eventName,
  44. @RequestParam(required = false) String eventType) {
  45. PageQuery<Event> pageQuery = new PageQuery<Event>();
  46. pageQuery.setPageSize(pageSize);
  47. pageQuery.setPageNumber(pageNum);
  48. pageQuery.setPara("applyId", applyId);
  49. if (StrUtil.isNotBlank(eventName))
  50. pageQuery.setPara("eventName", "%" + eventName + "%");
  51. if (StrUtil.isNotBlank(eventType))
  52. pageQuery.setPara("eventType", "%" + eventType + "%");
  53. EventPageVo eventPageVo = eventService.queryByPage(pageQuery);
  54. return Result.success(eventPageVo);
  55. }
  56. /**
  57. * 通过主键查询单条数据
  58. *
  59. * @param id 主键
  60. * @return 单条数据
  61. */
  62. @GetMapping("/queryOne")
  63. public Result<Event> queryOne(@RequestParam("id") String id, @RequestParam("applyId") String applyId) {
  64. return Result.success(eventService.queryById(id, applyId));
  65. }
  66. /**
  67. * 新增数据
  68. *
  69. * @param event 实体对象
  70. * @return 新增结果
  71. */
  72. @PostMapping("/create")
  73. public Result<?> create(@RequestBody Event event) {
  74. eventService.insert(event);
  75. return Result.success(event);
  76. }
  77. /**
  78. * 修改数据
  79. *
  80. * @param event 实体对象
  81. * @return 修改结果
  82. */
  83. @PostMapping("/update")
  84. public Result<?> update(@RequestBody Event event) {
  85. return eventService.updateById(event) ? Result.success() : Result.failure();
  86. }
  87. /**
  88. * 修改数据2
  89. *
  90. * @param event 实体对象
  91. * @return 修改结果
  92. */
  93. @PostMapping("/update2")
  94. public Result<?> update2(@RequestBody Event event) {
  95. return eventService.updateById2(event) ? Result.success() : Result.failure();
  96. }
  97. /**
  98. * 删除数据
  99. *
  100. * @param id 主键
  101. * @return 删除结果
  102. */
  103. @PostMapping("/delete")
  104. public Result<Boolean> delete(@RequestParam("id") String id, @RequestParam("applyId") String applyId) {
  105. return Result.success(this.eventService.deleteById(id, applyId));
  106. }
  107. }