SysConfigController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.ruoyi.web.controller.system;
  2. import com.ruoyi.common.annotation.Log;
  3. import com.ruoyi.common.annotation.RepeatSubmit;
  4. import com.ruoyi.common.constant.UserConstants;
  5. import com.ruoyi.common.core.controller.BaseController;
  6. import com.ruoyi.common.core.domain.AjaxResult;
  7. import com.ruoyi.common.core.page.TableDataInfo;
  8. import com.ruoyi.common.enums.BusinessType;
  9. import com.ruoyi.common.utils.poi.ExcelUtil;
  10. import com.ruoyi.system.domain.SysConfig;
  11. import com.ruoyi.system.service.ISysConfigService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.DeleteMapping;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PathVariable;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.PutMapping;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import javax.servlet.http.HttpServletResponse;
  23. import java.util.List;
  24. /**
  25. * 参数配置 信息操作处理
  26. *
  27. * @author ruoyi
  28. */
  29. @RestController
  30. @RequestMapping("/system/config")
  31. public class SysConfigController extends BaseController {
  32. @Autowired
  33. private ISysConfigService configService;
  34. /**
  35. * 获取参数配置列表
  36. */
  37. @GetMapping("/list")
  38. public TableDataInfo list(SysConfig config) {
  39. return configService.selectPageConfigList(config);
  40. }
  41. @Log(title = "参数管理", businessType = BusinessType.EXPORT)
  42. @GetMapping("/export")
  43. public void export(SysConfig config, HttpServletResponse response) {
  44. List<SysConfig> list = configService.selectConfigList(config);
  45. ExcelUtil.exportExcel(list, "参数数据", SysConfig.class, response);
  46. }
  47. /**
  48. * 根据参数编号获取详细信息
  49. */
  50. @GetMapping(value = "/{configId}")
  51. public AjaxResult getInfo(@PathVariable Long configId) {
  52. return AjaxResult.success(configService.selectConfigById(configId));
  53. }
  54. /**
  55. * 根据参数键名查询参数值
  56. */
  57. @GetMapping(value = "/configKey/{configKey}")
  58. public AjaxResult getConfigKey(@PathVariable String configKey) {
  59. return AjaxResult.success(configService.selectConfigByKey(configKey));
  60. }
  61. /**
  62. * 新增参数配置
  63. */
  64. @Log(title = "参数管理", businessType = BusinessType.INSERT)
  65. @PostMapping
  66. @RepeatSubmit
  67. public AjaxResult add(@Validated @RequestBody SysConfig config) {
  68. if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
  69. return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
  70. }
  71. config.setCreateBy(getUsername());
  72. return toAjax(configService.insertConfig(config));
  73. }
  74. /**
  75. * 修改参数配置
  76. */
  77. @Log(title = "参数管理", businessType = BusinessType.UPDATE)
  78. @PutMapping
  79. public AjaxResult edit(@Validated @RequestBody SysConfig config) {
  80. if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
  81. return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
  82. }
  83. config.setUpdateBy(getUsername());
  84. return toAjax(configService.updateConfig(config));
  85. }
  86. /**
  87. * 删除参数配置
  88. */
  89. @Log(title = "参数管理", businessType = BusinessType.DELETE)
  90. @DeleteMapping("/{configIds}")
  91. public AjaxResult remove(@PathVariable Long[] configIds) {
  92. configService.deleteConfigByIds(configIds);
  93. return success();
  94. }
  95. /**
  96. * 刷新参数缓存
  97. */
  98. @Log(title = "参数管理", businessType = BusinessType.CLEAN)
  99. @DeleteMapping("/refreshCache")
  100. public AjaxResult refreshCache() {
  101. configService.resetConfigCache();
  102. return AjaxResult.success();
  103. }
  104. }