SysConfigController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package com.ruoyi.web.controller.system;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import jdk.nashorn.api.scripting.AbstractJSObject;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.security.access.prepost.PreAuthorize;
  7. import org.springframework.validation.annotation.Validated;
  8. import org.springframework.web.bind.annotation.DeleteMapping;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.PutMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import com.ruoyi.common.annotation.Log;
  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 (!configService.checkConfigKeyUnique(config))
  81. {
  82. return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
  83. }
  84. config.setCreateBy(getUsername());
  85. configService.insertConfig(config);
  86. configService.resetConfigCache();
  87. return AjaxResult.success();
  88. }
  89. /**
  90. * 修改参数配置
  91. */
  92. @PreAuthorize("@ss.hasPermi('system:config:edit')")
  93. @Log(title = "参数管理", businessType = BusinessType.UPDATE)
  94. @PutMapping
  95. public AjaxResult edit(@Validated @RequestBody SysConfig config)
  96. {
  97. if (!configService.checkConfigKeyUnique(config))
  98. {
  99. return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
  100. }
  101. config.setUpdateBy(getUsername());
  102. configService.updateConfig(config);
  103. configService.resetConfigCache();
  104. return AjaxResult.success();
  105. }
  106. /**
  107. * 删除参数配置
  108. */
  109. @PreAuthorize("@ss.hasPermi('system:config:remove')")
  110. @Log(title = "参数管理", businessType = BusinessType.DELETE)
  111. @DeleteMapping("/{configIds}")
  112. public AjaxResult remove(@PathVariable Long[] configIds)
  113. {
  114. configService.deleteConfigByIds(configIds);
  115. configService.resetConfigCache();
  116. return success();
  117. }
  118. /**
  119. * 刷新参数缓存
  120. */
  121. @PreAuthorize("@ss.hasPermi('system:config:remove')")
  122. @Log(title = "参数管理", businessType = BusinessType.CLEAN)
  123. @DeleteMapping("/refreshCache")
  124. public AjaxResult refreshCache()
  125. {
  126. configService.resetConfigCache();
  127. return success();
  128. }
  129. }