EventController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.ruoyi.web.controller.system;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.ruoyi.common.core.controller.BaseController;
  6. import com.ruoyi.common.core.domain.AjaxResult;
  7. import com.ruoyi.web.domain.dto.event.EventAddRequest;
  8. import com.ruoyi.web.domain.dto.event.EventHandleRequest;
  9. import com.ruoyi.web.domain.dto.event.EventQueryRequest;
  10. import com.ruoyi.web.domain.dto.event.EventReassignRequest;
  11. import com.ruoyi.web.domain.entity.Event;
  12. import com.ruoyi.web.domain.vo.PersonInfoVO;
  13. import com.ruoyi.web.domain.vo.event.EventVO;
  14. import com.ruoyi.web.service.EventService;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.security.access.prepost.PreAuthorize;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.Date;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * 事件管理控制器
  25. */
  26. @Api(tags = "事件管理")
  27. @RestController
  28. @RequestMapping("/system/event")
  29. public class EventController extends BaseController {
  30. @Autowired
  31. private EventService eventService;
  32. /**
  33. * 添加事件
  34. */
  35. @ApiOperation("添加事件(村民提交事件)")
  36. @PostMapping("/add")
  37. public AjaxResult addEvent(@RequestBody EventAddRequest eventAddRequest) {
  38. if (eventAddRequest == null) {
  39. return error("请求参数为空");
  40. }
  41. Integer id = eventService.addEvent(eventAddRequest);
  42. return success(id);
  43. }
  44. /**
  45. * 删除事件
  46. */
  47. @ApiOperation("删除事件")
  48. @PostMapping("/delete")
  49. public AjaxResult deleteEvent(@RequestBody Map<String, String> paramsMap) {
  50. String ids = paramsMap.get("ids");
  51. if (StrUtil.isBlank(ids)) {
  52. return error("请求参数为空");
  53. }
  54. boolean b = eventService.deleteEvent(ids);
  55. if (b) {
  56. return success("删除成功");
  57. }
  58. return error("删除失败");
  59. }
  60. // /**
  61. // * 编辑事件
  62. // */
  63. // @ApiOperation("编辑事件")
  64. // @PostMapping("/edit")
  65. // public AjaxResult editEvent(@RequestBody EventEditRequest eventEditRequest) {
  66. // if (eventEditRequest == null) {
  67. // return error("请求参数为空");
  68. // }
  69. // eventService.editEvent(eventEditRequest);
  70. // return AjaxResult.success();
  71. // }
  72. /**
  73. * 根据ID查询事件详情(支持管理员和负责人查询)
  74. */
  75. @ApiOperation("根据ID查询事件详情(支持管理员和负责人查询)")
  76. @GetMapping("/get")
  77. public AjaxResult getEventById(@RequestParam int id) {
  78. if (ObjectUtil.isEmpty(id)) {
  79. return error("请求参数为空");
  80. }
  81. EventVO eventVO = eventService.getEventById(id);
  82. return success(eventVO);
  83. }
  84. /**
  85. * 分页查询事件列表(支持管理员和负责人查询)
  86. */
  87. @ApiOperation("分页查询事件列表")
  88. @PostMapping("/list/page")
  89. public AjaxResult listEventByPage(@RequestBody EventQueryRequest eventQueryRequest) {
  90. if (eventQueryRequest == null) {
  91. return error("请求参数为空");
  92. }
  93. Page<EventVO> listEventVOByPage = eventService.getListEventByPage(eventQueryRequest);
  94. return AjaxResult.success(listEventVOByPage);
  95. }
  96. /**
  97. * 根据事件类型获取负责人列表(管理员)
  98. */
  99. @ApiOperation("根据事件类型获取负责人列表(管理员)")
  100. @GetMapping("/list/user")
  101. @PreAuthorize("@ss.hasPermi('system:role:admin')")
  102. public AjaxResult listSysUserByType(@RequestParam Integer type) {
  103. if (type == null) {
  104. return error("请求参数为空");
  105. }
  106. List<PersonInfoVO> personInfoVOByEventType = eventService.getPersonInfoVOByEventType(type);
  107. return AjaxResult.success(personInfoVOByEventType);
  108. }
  109. /**
  110. * 处理事件
  111. */
  112. @ApiOperation("处理事件")
  113. @PostMapping("/handle")
  114. public AjaxResult handleEvent(@RequestBody EventHandleRequest eventHandleRequest) {
  115. try {
  116. Integer eventId = eventHandleRequest.getEventId();
  117. String processResult = eventHandleRequest.getProcessResult();
  118. Date processTime = eventHandleRequest.getProcessTime();
  119. Event event = eventService.getById(eventId);
  120. if(ObjectUtil.isEmpty(event)){
  121. return error("事件不存在");
  122. }
  123. boolean result = eventService.handleEvent(eventId, processResult,processTime);
  124. if (result) {
  125. return success("事件处理成功");
  126. } else {
  127. return error("事件已被他人处理");
  128. }
  129. } catch (Exception e) {
  130. return error(e.getMessage());
  131. }
  132. }
  133. /**
  134. * 重新派发事件
  135. */
  136. @ApiOperation("重新派发事件")
  137. @PostMapping("/reassign")
  138. @PreAuthorize("@ss.hasPermi('system:role:admin')")
  139. public AjaxResult reassignEvent(@RequestBody EventReassignRequest eventReassignRequest) {
  140. try {
  141. Integer eventId = eventReassignRequest.getEventId();
  142. List<Integer> personIds = eventReassignRequest.getPersonIds();
  143. eventService.reassignEvent(eventId, personIds);
  144. return success("重新派发成功");
  145. } catch (Exception e) {
  146. return error(e.getMessage());
  147. }
  148. }
  149. }