HookController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.ruoyi.web.controller.app;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.springframework.security.access.prepost.PreAuthorize;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.validation.annotation.Validated;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.PostMapping;
  9. import org.springframework.web.bind.annotation.PutMapping;
  10. import org.springframework.web.bind.annotation.DeleteMapping;
  11. import org.springframework.web.bind.annotation.PathVariable;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import com.ruoyi.common.annotation.Log;
  16. import com.ruoyi.common.core.controller.BaseController;
  17. import com.ruoyi.common.core.domain.AjaxResult;
  18. import com.ruoyi.common.enums.BusinessType;
  19. import com.ruoyi.app.domain.Hook;
  20. import com.ruoyi.app.service.IHookService;
  21. import com.ruoyi.common.utils.poi.ExcelUtil;
  22. import com.ruoyi.common.core.page.TableDataInfo;
  23. /**
  24. * 吊钩Controller
  25. *
  26. * @author coede
  27. * @date 2025-03-19
  28. */
  29. @RestController
  30. @RequestMapping("/app/hook")
  31. public class HookController extends BaseController
  32. {
  33. @Autowired
  34. private IHookService hookService;
  35. /**
  36. * 查询吊钩列表
  37. */
  38. @GetMapping("/list")
  39. public TableDataInfo list(Hook hook)
  40. {
  41. startPage();
  42. List<Hook> list = hookService.selectHookList(hook);
  43. return getDataTable(list);
  44. }
  45. /**
  46. * 导出吊钩列表
  47. */
  48. @Log(title = "吊钩", businessType = BusinessType.EXPORT)
  49. @PostMapping("/export")
  50. public void export(HttpServletResponse response, Hook hook)
  51. {
  52. List<Hook> list = hookService.selectHookList(hook);
  53. ExcelUtil<Hook> util = new ExcelUtil<Hook>(Hook.class);
  54. util.exportExcel(response, list, "吊钩数据");
  55. }
  56. /**
  57. * 获取吊钩详细信息
  58. */
  59. @GetMapping(value = "/{id}")
  60. public AjaxResult getInfo(@PathVariable("id") Long id)
  61. {
  62. return success(hookService.selectHookById(id));
  63. }
  64. /**
  65. * 新增吊钩
  66. */
  67. @PreAuthorize("@ss.hasPermi('app:hook:add')")
  68. @Log(title = "吊钩", businessType = BusinessType.INSERT)
  69. @PostMapping
  70. public AjaxResult add(@Validated @RequestBody Hook hook)
  71. {
  72. if (!hookService.checkHookNameUnique(hook))
  73. {
  74. return error("新增吊钩'" + hook.getHookName() + "'失败,列表中存在重复的吊钩类型");
  75. }
  76. hook.setCreateBy(getUsername());
  77. return toAjax(hookService.insertHook(hook));
  78. }
  79. /**
  80. * 修改吊钩
  81. */
  82. @PreAuthorize("@ss.hasPermi('app:hook:edit')")
  83. @Log(title = "吊钩", businessType = BusinessType.UPDATE)
  84. @PutMapping
  85. public AjaxResult edit(@Validated @RequestBody Hook hook)
  86. {
  87. if (!hookService.checkHookNameUnique(hook))
  88. {
  89. return error("修改吊钩'" + hook.getHookName() + "'失败,列表中存在重复的吊钩类型");
  90. }
  91. hook.setUpdateBy(getUsername());
  92. return toAjax(hookService.updateHook(hook));
  93. }
  94. /**
  95. * 删除吊钩
  96. */
  97. @PreAuthorize("@ss.hasPermi('app:hook:remove')")
  98. @Log(title = "吊钩", businessType = BusinessType.DELETE)
  99. @DeleteMapping("/{ids}")
  100. public AjaxResult remove(@PathVariable Long[] ids)
  101. {
  102. return toAjax(hookService.deleteHookByIds(ids));
  103. }
  104. /**
  105. * 吊钩选择
  106. */
  107. @GetMapping("/optionselect")
  108. public AjaxResult optionselect()
  109. {
  110. Hook hook = new Hook();
  111. List<Hook> list = hookService.selectHookList(hook);
  112. return success(list);
  113. }
  114. }