houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.controller.admin.db;
H 2
3 import com.iailab.framework.common.pojo.CommonResult;
4 import com.iailab.framework.common.util.object.BeanUtils;
5 import com.iailab.module.infra.controller.admin.db.vo.DataSourceConfigRespVO;
6 import com.iailab.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
7 import com.iailab.module.infra.dal.dataobject.db.DataSourceConfigDO;
8 import com.iailab.module.infra.service.db.DataSourceConfigService;
9 import io.swagger.v3.oas.annotations.Operation;
10 import io.swagger.v3.oas.annotations.Parameter;
11 import io.swagger.v3.oas.annotations.tags.Tag;
12 import org.springframework.security.access.prepost.PreAuthorize;
13 import org.springframework.validation.annotation.Validated;
14 import org.springframework.web.bind.annotation.*;
15
16 import javax.annotation.Resource;
17 import javax.validation.Valid;
18 import java.util.List;
19
20 import static com.iailab.framework.common.pojo.CommonResult.success;
21
22 @Tag(name = "管理后台 - 数据源配置")
23 @RestController
24 @RequestMapping("/infra/data-source-config")
25 @Validated
26 public class DataSourceConfigController {
27
28     @Resource
29     private DataSourceConfigService dataSourceConfigService;
30
31     @PostMapping("/create")
32     @Operation(summary = "创建数据源配置")
33     @PreAuthorize("@ss.hasPermission('infra:data-source-config:create')")
34     public CommonResult<Long> createDataSourceConfig(@Valid @RequestBody DataSourceConfigSaveReqVO createReqVO) {
35         return success(dataSourceConfigService.createDataSourceConfig(createReqVO));
36     }
37
38     @PutMapping("/update")
39     @Operation(summary = "更新数据源配置")
40     @PreAuthorize("@ss.hasPermission('infra:data-source-config:update')")
41     public CommonResult<Boolean> updateDataSourceConfig(@Valid @RequestBody DataSourceConfigSaveReqVO updateReqVO) {
42         dataSourceConfigService.updateDataSourceConfig(updateReqVO);
43         return success(true);
44     }
45
46     @DeleteMapping("/delete")
47     @Operation(summary = "删除数据源配置")
48     @Parameter(name = "id", description = "编号", required = true)
49     @PreAuthorize("@ss.hasPermission('infra:data-source-config:delete')")
50     public CommonResult<Boolean> deleteDataSourceConfig(@RequestParam("id") Long id) {
51         dataSourceConfigService.deleteDataSourceConfig(id);
52         return success(true);
53     }
54
55     @GetMapping("/get")
56     @Operation(summary = "获得数据源配置")
57     @Parameter(name = "id", description = "编号", required = true, example = "1024")
58     @PreAuthorize("@ss.hasPermission('infra:data-source-config:query')")
59     public CommonResult<DataSourceConfigRespVO> getDataSourceConfig(@RequestParam("id") Long id) {
60         DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(id);
61         return success(BeanUtils.toBean(config, DataSourceConfigRespVO.class));
62     }
63
64     @GetMapping("/list")
65     @Operation(summary = "获得数据源配置列表")
66     @PreAuthorize("@ss.hasPermission('infra:data-source-config:query')")
67     public CommonResult<List<DataSourceConfigRespVO>> getDataSourceConfigList() {
68         List<DataSourceConfigDO> list = dataSourceConfigService.getDataSourceConfigList();
69         return success(BeanUtils.toBean(list, DataSourceConfigRespVO.class));
70     }
71
72 }