提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.controller.admin.config; |
H |
2 |
|
|
3 |
import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.framework.common.pojo.PageParam; |
|
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
|
8 |
import com.iailab.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
|
9 |
import com.iailab.module.infra.controller.admin.config.vo.ConfigRespVO; |
|
10 |
import com.iailab.module.infra.controller.admin.config.vo.ConfigSaveReqVO; |
|
11 |
import com.iailab.module.infra.convert.config.ConfigConvert; |
|
12 |
import com.iailab.module.infra.dal.dataobject.config.ConfigDO; |
|
13 |
import com.iailab.module.infra.enums.ErrorCodeConstants; |
|
14 |
import com.iailab.module.infra.service.config.ConfigService; |
|
15 |
import io.swagger.v3.oas.annotations.Operation; |
|
16 |
import io.swagger.v3.oas.annotations.Parameter; |
|
17 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
18 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
19 |
import org.springframework.validation.annotation.Validated; |
|
20 |
import org.springframework.web.bind.annotation.*; |
|
21 |
|
|
22 |
import javax.annotation.Resource; |
|
23 |
import javax.servlet.http.HttpServletResponse; |
|
24 |
import javax.validation.Valid; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
|
29 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
30 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
31 |
|
|
32 |
@Tag(name = "管理后台 - 参数配置") |
|
33 |
@RestController |
|
34 |
@RequestMapping("/infra/config") |
|
35 |
@Validated |
|
36 |
public class ConfigController { |
|
37 |
|
|
38 |
@Resource |
|
39 |
private ConfigService configService; |
|
40 |
|
|
41 |
@PostMapping("/create") |
|
42 |
@Operation(summary = "创建参数配置") |
|
43 |
@PreAuthorize("@ss.hasPermission('infra:config:create')") |
|
44 |
public CommonResult<Long> createConfig(@Valid @RequestBody ConfigSaveReqVO createReqVO) { |
|
45 |
return success(configService.createConfig(createReqVO)); |
|
46 |
} |
|
47 |
|
|
48 |
@PutMapping("/update") |
|
49 |
@Operation(summary = "修改参数配置") |
|
50 |
@PreAuthorize("@ss.hasPermission('infra:config:update')") |
|
51 |
public CommonResult<Boolean> updateConfig(@Valid @RequestBody ConfigSaveReqVO updateReqVO) { |
|
52 |
configService.updateConfig(updateReqVO); |
|
53 |
return success(true); |
|
54 |
} |
|
55 |
|
|
56 |
@DeleteMapping("/delete") |
|
57 |
@Operation(summary = "删除参数配置") |
|
58 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
59 |
@PreAuthorize("@ss.hasPermission('infra:config:delete')") |
|
60 |
public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) { |
|
61 |
configService.deleteConfig(id); |
|
62 |
return success(true); |
|
63 |
} |
|
64 |
|
|
65 |
@GetMapping(value = "/get") |
|
66 |
@Operation(summary = "获得参数配置") |
|
67 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
68 |
@PreAuthorize("@ss.hasPermission('infra:config:query')") |
|
69 |
public CommonResult<ConfigRespVO> getConfig(@RequestParam("id") Long id) { |
|
70 |
return success(ConfigConvert.INSTANCE.convert(configService.getConfig(id))); |
|
71 |
} |
|
72 |
|
|
73 |
@GetMapping(value = "/get-value-by-key") |
|
74 |
@Operation(summary = "根据参数键名查询参数值", description = "不可见的配置,不允许返回给前端") |
|
75 |
@Parameter(name = "key", description = "参数键", required = true, example = "yunai.biz.username") |
|
76 |
public CommonResult<String> getConfigKey(@RequestParam("key") String key) { |
|
77 |
ConfigDO config = configService.getConfigByKey(key); |
|
78 |
if (config == null) { |
|
79 |
return success(null); |
|
80 |
} |
|
81 |
if (!config.getVisible()) { |
|
82 |
throw exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE); |
|
83 |
} |
|
84 |
return success(config.getValue()); |
|
85 |
} |
|
86 |
|
|
87 |
@GetMapping("/page") |
|
88 |
@Operation(summary = "获取参数配置分页") |
|
89 |
@PreAuthorize("@ss.hasPermission('infra:config:query')") |
|
90 |
public CommonResult<PageResult<ConfigRespVO>> getConfigPage(@Valid ConfigPageReqVO pageReqVO) { |
|
91 |
PageResult<ConfigDO> page = configService.getConfigPage(pageReqVO); |
|
92 |
return success(ConfigConvert.INSTANCE.convertPage(page)); |
|
93 |
} |
|
94 |
|
|
95 |
@GetMapping("/export") |
|
96 |
@Operation(summary = "导出参数配置") |
|
97 |
@PreAuthorize("@ss.hasPermission('infra:config:export')") |
|
98 |
@ApiAccessLog(operateType = EXPORT) |
|
99 |
public void exportConfig(@Valid ConfigPageReqVO exportReqVO, |
|
100 |
HttpServletResponse response) throws IOException { |
|
101 |
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
102 |
List<ConfigDO> list = configService.getConfigPage(exportReqVO).getList(); |
|
103 |
// 输出 |
|
104 |
ExcelUtils.write(response, "参数配置.xls", "数据", ConfigRespVO.class, |
|
105 |
ConfigConvert.INSTANCE.convertList(list)); |
|
106 |
} |
|
107 |
|
|
108 |
} |