SysConfigController.java 4.5 KB

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