|
|
package com.controller;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.entity.ConfigEntity;
|
|
|
import com.service.ConfigService;
|
|
|
import com.utils.MPUtil;
|
|
|
import com.utils.PageUtils;
|
|
|
import com.utils.R;
|
|
|
import com.utils.ValidatorUtils;
|
|
|
|
|
|
/**
|
|
|
* 系统配置管理控制器
|
|
|
* 功能:提供系统配置参数的增删改查接口
|
|
|
* 注解说明:
|
|
|
* @RestController = @Controller + @ResponseBody (直接返回JSON数据)
|
|
|
* @RequestMapping("config") 定义基础路径为 /config
|
|
|
*/
|
|
|
@RequestMapping("config")
|
|
|
@RestController
|
|
|
public class ConfigController {
|
|
|
|
|
|
@Autowired // 自动注入配置服务层
|
|
|
private ConfigService configService;
|
|
|
|
|
|
// ======================== 分页查询接口 ========================
|
|
|
/**
|
|
|
* 分页查询配置列表(需认证)
|
|
|
* 路径:/config/page
|
|
|
* 参数:
|
|
|
* @RequestParam Map<String, Object> params - 分页及过滤参数(如page, limit, sort)
|
|
|
* ConfigEntity config - 配置实体(用于封装查询条件)
|
|
|
* 流程:
|
|
|
* 1. 构建EntityWrapper条件包装器
|
|
|
* 2. 调用MPUtil工具处理模糊查询(likeOrEq)、范围查询(between)、排序(sort)
|
|
|
* 3. 执行分页查询(queryPage)
|
|
|
* 4. 返回统一响应结构R,包含分页数据
|
|
|
*/
|
|
|
@RequestMapping("/page")
|
|
|
public R page(@RequestParam Map<String, Object> params, ConfigEntity config) {
|
|
|
EntityWrapper<ConfigEntity> ew = new EntityWrapper<>();
|
|
|
PageUtils page = configService.queryPage(
|
|
|
params,
|
|
|
MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)
|
|
|
);
|
|
|
return R.ok().put("data", page); // 返回分页数据
|
|
|
}
|
|
|
|
|
|
// ======================== 开放列表接口 ========================
|
|
|
/**
|
|
|
* 获取配置列表(无需认证)
|
|
|
* 路径:/config/list
|
|
|
* 说明:通过@IgnoreAuth跳过权限验证
|
|
|
* 参数与流程同/page接口
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/list")
|
|
|
public R list(@RequestParam Map<String, Object> params, ConfigEntity config) {
|
|
|
EntityWrapper<ConfigEntity> ew = new EntityWrapper<>();
|
|
|
PageUtils page = configService.queryPage(
|
|
|
params,
|
|
|
MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)
|
|
|
);
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
// ======================== 单条查询接口 ========================
|
|
|
/**
|
|
|
* 根据ID查询配置详情(需认证)
|
|
|
* 路径:/config/info/{id}
|
|
|
* 参数:@PathVariable("id") String id - 配置项ID
|
|
|
*/
|
|
|
@RequestMapping("/info/{id}")
|
|
|
public R info(@PathVariable("id") String id) {
|
|
|
ConfigEntity config = configService.selectById(id); // 根据主键查询
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据ID查询配置详情(开放接口)
|
|
|
* 路径:/config/detail/{id}
|
|
|
* 说明:公开接口,跳过权限验证
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/detail/{id}")
|
|
|
public R detail(@PathVariable("id") String id) {
|
|
|
ConfigEntity config = configService.selectById(id);
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
// ======================== 按名称查询接口 ========================
|
|
|
/**
|
|
|
* 根据name字段查询配置
|
|
|
* 路径:/config/info?name={name}
|
|
|
* 示例:查询name="faceFile"的配置项
|
|
|
* 注意:此方法硬编码查询条件为"faceFile",实际使用时需调整为动态参数
|
|
|
*/
|
|
|
@RequestMapping("/info")
|
|
|
public R infoByName(@RequestParam String name) {
|
|
|
// 创建条件构造器:WHERE name = #{name}
|
|
|
EntityWrapper<ConfigEntity> wrapper = new EntityWrapper<>();
|
|
|
wrapper.eq("name", name);
|
|
|
|
|
|
ConfigEntity config = configService.selectOne(wrapper); // 查询单条记录
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
// ======================== 数据操作接口 ========================
|
|
|
/**
|
|
|
* 新增配置项
|
|
|
* 路径:POST /config/save
|
|
|
* 参数:@RequestBody ConfigEntity config - JSON格式的配置实体
|
|
|
* 注意:ValidatorUtils.validateEntity(config) 被注释,启用后需配置校验规则
|
|
|
*/
|
|
|
@PostMapping("/save")
|
|
|
public R save(@RequestBody ConfigEntity config) {
|
|
|
// ValidatorUtils.validateEntity(config); // 启用参数校验(需配置)
|
|
|
configService.insert(config); // 插入数据
|
|
|
return R.ok(); // 返回成功标识
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改配置项
|
|
|
* 路径:PUT /config/update
|
|
|
* 参数:@RequestBody ConfigEntity config - 待更新的完整实体
|
|
|
*/
|
|
|
@RequestMapping("/update")
|
|
|
public R update(@RequestBody ConfigEntity config) {
|
|
|
// ValidatorUtils.validateEntity(config);
|
|
|
configService.updateById(config); // 根据ID全字段更新
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除配置项
|
|
|
* 路径:DELETE /config/delete
|
|
|
* 参数:@RequestBody Long[] ids - 待删除的ID数组
|
|
|
*/
|
|
|
@RequestMapping("/delete")
|
|
|
public R delete(@RequestBody Long[] ids) {
|
|
|
configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除
|
|
|
return R.ok();
|
|
|
}
|
|
|
}
|