You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
exam/sys/config/controller/SysConfigController.java

93 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.yf.exam.modules.sys.config.controller;
// 导入 API 响应结果类,用于封装接口返回数据
import com.yf.exam.core.api.ApiRest;
// 导入基础控制器类,提供一些通用的控制器方法
import com.yf.exam.core.api.controller.BaseController;
// 导入基础 ID 响应数据传输对象类
import com.yf.exam.core.api.dto.BaseIdRespDTO;
// 导入 Bean 映射工具类,用于对象属性的复制
import com.yf.exam.core.utils.BeanMapper;
// 导入图片校验工具类
import com.yf.exam.modules.qu.utils.ImageCheckUtils;
// 导入系统配置数据传输对象类
import com.yf.exam.modules.sys.config.dto.SysConfigDTO;
// 导入系统配置实体类
import com.yf.exam.modules.sys.config.entity.SysConfig;
// 导入系统配置服务接口
import com.yf.exam.modules.sys.config.service.SysConfigService;
// 导入 Swagger 注解,用于生成 API 文档,标记控制器的标签
import io.swagger.annotations.Api;
// 导入 Swagger 注解,用于生成 API 文档,标记接口的操作描述
import io.swagger.annotations.ApiOperation;
// 导入 Shiro 注解,用于权限控制,要求用户具有指定角色才能访问接口
import org.apache.shiro.authz.annotation.RequiresRoles;
// 导入 Spring 依赖注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 请求体注解,用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入 Spring 请求映射注解,用于映射请求路径
import org.springframework.web.bind.annotation.RequestMapping;
// 导入 Spring 请求方法注解,用于指定请求的 HTTP 方法
import org.springframework.web.bind.annotation.RequestMethod;
// 导入 Spring 控制器注解,标记该类为 RESTful 风格的控制器
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 通用配置控制器,处理与系统通用配置相关的接口请求
* </p>
*
* @author 聪明笨狗
* @since 2020-04-17 09:12
*/
@Api(tags={"通用配置"})
@RestController
@RequestMapping("/exam/api/sys/config")
public class SysConfigController extends BaseController {
// 自动注入系统配置服务实例,用于调用系统配置相关的业务逻辑
@Autowired
private SysConfigService baseService;
// 自动注入图片校验工具实例,用于校验图片地址
@Autowired
private ImageCheckUtils imageCheckUtils;
/**
* 添加或修改系统配置信息
* @param reqDTO 系统配置数据传输对象,包含要添加或修改的配置信息
* @return 封装了操作结果和配置 ID 的 API 响应对象
*/
@RequiresRoles("sa")
@ApiOperation(value = "添加或修改")
@RequestMapping(value = "/save", method = { RequestMethod.POST})
public ApiRest<BaseIdRespDTO> save(@RequestBody SysConfigDTO reqDTO) {
// 复制请求数据传输对象中的属性到系统配置实体对象中
SysConfig entity = new SysConfig();
BeanMapper.copy(reqDTO, entity);
// 调用图片校验工具类的方法,校验系统配置中的背景 LOGO 地址是否合法
imageCheckUtils.checkImage(entity.getBackLogo(), "系统LOGO地址错误");
// 调用系统配置服务的方法,保存或更新系统配置信息
baseService.saveOrUpdate(entity);
// 调用父类的成功响应方法,返回包含配置 ID 的响应对象
return super.success(new BaseIdRespDTO(entity.getId()));
}
/**
* 查找系统配置详情
* @return 封装了系统配置详情数据传输对象的 API 响应对象
*/
@ApiOperation(value = "查找详情")
@RequestMapping(value = "/detail", method = { RequestMethod.POST})
public ApiRest<SysConfigDTO> find() {
// 调用系统配置服务的方法,获取系统配置详情数据传输对象
SysConfigDTO dto = baseService.find();
// 调用父类的成功响应方法,返回包含系统配置详情的响应对象
return super.success(dto);
}
}