|
|
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; // MyBatis-Plus的实体包装器
|
|
|
import com.entity.ConfigEntity; // 配置实体类
|
|
|
import com.service.ConfigService; // 配置服务类
|
|
|
import com.utils.MPUtil; // MyBatis-Plus工具类
|
|
|
import com.utils.PageUtils;
|
|
|
import com.utils.R;
|
|
|
import com.utils.ValidatorUtils;
|
|
|
|
|
|
/**
|
|
|
* 登录相关
|
|
|
*/
|
|
|
@RequestMapping("config") // 设置基本请求路径为"/config"
|
|
|
@RestController // 标记为REST风格的控制器
|
|
|
public class ConfigController {
|
|
|
|
|
|
@Autowired // 自动注入ConfigService
|
|
|
private ConfigService configService;
|
|
|
|
|
|
/**
|
|
|
* 列表
|
|
|
* @param params 查询参数
|
|
|
* @param config 配置信息
|
|
|
* @return 分页后的配置信息
|
|
|
*/
|
|
|
@RequestMapping("/page")
|
|
|
public R page(@RequestParam Map<String, Object> params, ConfigEntity config) {
|
|
|
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); // 创建EntityWrapper用于条件构造
|
|
|
PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 列表
|
|
|
* @param params 查询参数
|
|
|
* @param config 配置信息
|
|
|
* @return 所有配置信息的列表
|
|
|
*/
|
|
|
@IgnoreAuth // 忽略身份验证
|
|
|
@RequestMapping("/list")
|
|
|
public R list(@RequestParam Map<String, Object> params, ConfigEntity config) {
|
|
|
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); // 创建EntityWrapper用于条件构造
|
|
|
PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 信息
|
|
|
* @param id 配置ID
|
|
|
* @return 指定ID的配置信息
|
|
|
*/
|
|
|
@RequestMapping("/info/{id}") // 用于获取指定ID的配置信息
|
|
|
public R info(@PathVariable("id") String id) {
|
|
|
ConfigEntity config = configService.selectById(id); // 根据ID查询配置
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 详情
|
|
|
* @param id 配置ID
|
|
|
* @return 指定ID的配置信息,忽略身份验证
|
|
|
*/
|
|
|
@IgnoreAuth // 忽略身份验证
|
|
|
@RequestMapping("/detail/{id}") // 用于获取指定ID的配置信息详情
|
|
|
public R detail(@PathVariable("id") String id) {
|
|
|
ConfigEntity config = configService.selectById(id); // 根据ID查询配置
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据name获取信息
|
|
|
* @param name 配置名称
|
|
|
* @return 指定名称的配置信息
|
|
|
*/
|
|
|
@RequestMapping("/info") // 用于根据名称获取配置信息
|
|
|
public R infoByName(@RequestParam String name) {
|
|
|
ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile")); // 根据名称查询配置
|
|
|
return R.ok().put("data", config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
* @param config 配置信息
|
|
|
* @return 保存结果
|
|
|
*/
|
|
|
@PostMapping("/save") // 用于保存配置
|
|
|
public R save(@RequestBody ConfigEntity config) {
|
|
|
// ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用)
|
|
|
configService.insert(config); // 保存配置
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改
|
|
|
* @param config 配置信息
|
|
|
* @return 修改结果
|
|
|
*/
|
|
|
@RequestMapping("/update") // 用于修改配置
|
|
|
public R update(@RequestBody ConfigEntity config) {
|
|
|
// ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用)
|
|
|
configService.updateById(config); // 根据ID更新配置
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除
|
|
|
* @param ids 配置ID数组
|
|
|
* @return 删除结果
|
|
|
*/
|
|
|
@RequestMapping("/delete") // 用于删除配置
|
|
|
public R delete(@RequestBody Long[] ids) {
|
|
|
configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除配置
|
|
|
return R.ok();
|
|
|
}
|
|
|
}
|