You've already forked FrameTour-BE
feat(basic): 添加默认配置管理功能
- 实现了默认配置的列表获取、单个配置获取、创建、更新和删除功能- 使用日志记录操作信息- 异常处理确保错误信息返回给客户端
This commit is contained in:
@@ -0,0 +1,100 @@
|
|||||||
|
package com.ycwl.basic.controller.pc;
|
||||||
|
|
||||||
|
import com.ycwl.basic.integration.scenic.dto.config.DefaultConfigDTO;
|
||||||
|
import com.ycwl.basic.integration.scenic.service.DefaultConfigIntegrationService;
|
||||||
|
import com.ycwl.basic.utils.ApiConst;
|
||||||
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认配置管理控制器
|
||||||
|
* 提供默认配置的增删查改功能
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/default-config")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DefaultConfigController {
|
||||||
|
|
||||||
|
private final DefaultConfigIntegrationService defaultConfigIntegrationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认配置列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/")
|
||||||
|
public ApiResponse<List<DefaultConfigDTO>> listDefaultConfigs() {
|
||||||
|
log.info("获取默认配置列表");
|
||||||
|
try {
|
||||||
|
List<DefaultConfigDTO> configs = defaultConfigIntegrationService.listDefaultConfigs();
|
||||||
|
return ApiResponse.success(configs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取默认配置列表失败", e);
|
||||||
|
return ApiResponse.fail("获取默认配置列表失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据配置键获取默认配置
|
||||||
|
*/
|
||||||
|
@GetMapping("/{configKey}")
|
||||||
|
public ApiResponse<DefaultConfigDTO> getDefaultConfig(@PathVariable String configKey) {
|
||||||
|
log.info("获取默认配置, configKey: {}", configKey);
|
||||||
|
try {
|
||||||
|
DefaultConfigDTO config = defaultConfigIntegrationService.getDefaultConfig(configKey);
|
||||||
|
return ApiResponse.success(config);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取默认配置失败, configKey: {}", configKey, e);
|
||||||
|
return ApiResponse.fail("获取默认配置失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建默认配置
|
||||||
|
*/
|
||||||
|
@PostMapping("/")
|
||||||
|
public ApiResponse<DefaultConfigDTO> createDefaultConfig(@RequestBody DefaultConfigDTO request) {
|
||||||
|
log.info("创建默认配置, configKey: {}", request.getConfigKey());
|
||||||
|
try {
|
||||||
|
DefaultConfigDTO config = defaultConfigIntegrationService.createDefaultConfig(request);
|
||||||
|
return ApiResponse.success(config);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建默认配置失败, configKey: {}", request.getConfigKey(), e);
|
||||||
|
return ApiResponse.fail("创建默认配置失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新默认配置
|
||||||
|
*/
|
||||||
|
@PutMapping("/{configKey}")
|
||||||
|
public ApiResponse<DefaultConfigDTO> updateDefaultConfig(@PathVariable String configKey,
|
||||||
|
@RequestBody DefaultConfigDTO request) {
|
||||||
|
log.info("更新默认配置, configKey: {}", configKey);
|
||||||
|
try {
|
||||||
|
DefaultConfigDTO config = defaultConfigIntegrationService.updateDefaultConfig(configKey, request);
|
||||||
|
return ApiResponse.success(config);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新默认配置失败, configKey: {}", configKey, e);
|
||||||
|
return ApiResponse.fail("更新默认配置失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除默认配置
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{configKey}")
|
||||||
|
public ApiResponse<Void> deleteDefaultConfig(@PathVariable String configKey) {
|
||||||
|
log.info("删除默认配置, configKey: {}", configKey);
|
||||||
|
try {
|
||||||
|
defaultConfigIntegrationService.deleteDefaultConfig(configKey);
|
||||||
|
return ApiResponse.buildResponse(ApiConst.Code.CODE_SUCCESS.code(), null, "删除成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除默认配置失败, configKey: {}", configKey, e);
|
||||||
|
return ApiResponse.fail("删除默认配置失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user