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