SysConfigController.java 5.1 KB

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