SysConfigController.java 5.4 KB

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