1
This commit is contained in:
parent
6419f88c63
commit
92246a6767
@ -1,107 +0,0 @@
|
||||
package com.agileboot.common.mybatis.core.page;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表格分页数据对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class TableDataInfo<T> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private long total;
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private List<T> rows;
|
||||
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataInfo(List<T> list, long total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
this.code = HttpStatus.HTTP_OK;
|
||||
this.msg = "查询成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分页对象构建表格分页数据对象
|
||||
*/
|
||||
public static <T> TableDataInfo<T> build(IPage<T> page) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(page.getRecords());
|
||||
rspData.setTotal(page.getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据列表构建表格分页数据对象
|
||||
*/
|
||||
public static <T> TableDataInfo<T> build(List<T> list) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(list.size());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建表格分页数据对象
|
||||
*/
|
||||
public static <T> TableDataInfo<T> build() {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据原始数据列表和分页参数,构建表格分页数据对象(用于假分页)
|
||||
*
|
||||
* @param list 原始数据列表(全部数据)
|
||||
* @param page 分页参数对象(包含当前页码、每页大小等)
|
||||
* @return 构造好的分页结果 TableDataInfo<T>
|
||||
*/
|
||||
public static <T> TableDataInfo<T> build(List<T> list, IPage<T> page) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return TableDataInfo.build();
|
||||
}
|
||||
List<T> pageList = CollUtil.page((int) page.getCurrent() - 1, (int) page.getSize(), list);
|
||||
return new TableDataInfo<>(pageList, list.size());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +1,16 @@
|
||||
package com.agileboot.system.config.controller;
|
||||
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.core.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.common.mybatis.core.page.PageR;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigDTO;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigQuery;
|
||||
import com.agileboot.system.config.service.ISysConfigService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author cuiJiaWang
|
||||
@ -22,7 +25,43 @@ public class SysConfigController {
|
||||
private final ISysConfigService sysConfigService;
|
||||
|
||||
@GetMapping("/test")
|
||||
@Deprecated
|
||||
public R<String> test(@RequestParam("key") String key) {
|
||||
return R.ok(sysConfigService.getConfigValueByKey(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数配置列表
|
||||
*/
|
||||
@GetMapping("/configs")
|
||||
public PageR<ConfigDTO> list(ConfigQuery query) {
|
||||
return sysConfigService.getConfigPage(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数编号获取详细信息
|
||||
*/
|
||||
@GetMapping(value = "/config/{configId}")
|
||||
public R<ConfigDTO> getInfo(@NotNull @Positive @PathVariable Long configId) {
|
||||
return R.ok(sysConfigService.getConfigInfo(configId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*/
|
||||
@PostMapping(value = "/config/{configId}")
|
||||
public R<Void> edit(@NotNull @Positive @PathVariable Long configId, @RequestBody ConfigUpdateCommand config) {
|
||||
config.setConfigId(configId);
|
||||
sysConfigService.updateConfig(config);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新参数缓存
|
||||
*/
|
||||
@PostMapping("/configs/cache")
|
||||
public R<Void> refreshCache() {
|
||||
CacheCenter.configCache.invalidateAll();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,16 @@ import java.util.List;
|
||||
@Data
|
||||
public class ConfigDTO {
|
||||
|
||||
private String configId;
|
||||
private String configName;
|
||||
private String configKey;
|
||||
private String configValue;
|
||||
private List<String> configOptions;
|
||||
private Integer isAllowChange;
|
||||
private String isAllowChangeStr;
|
||||
private String remark;
|
||||
private Date createTime;
|
||||
|
||||
public ConfigDTO(SysConfig entity) {
|
||||
if (entity != null) {
|
||||
configId = entity.getId();
|
||||
@ -32,15 +42,4 @@ public class ConfigDTO {
|
||||
createTime = entity.getCreateTime();
|
||||
}
|
||||
}
|
||||
|
||||
private String configId;
|
||||
private String configName;
|
||||
private String configKey;
|
||||
private String configValue;
|
||||
private List<String> configOptions;
|
||||
private Integer isAllowChange;
|
||||
private String isAllowChangeStr;
|
||||
private String remark;
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.agileboot.system.config.pojo.dto;
|
||||
|
||||
import com.agileboot.common.mybatis.core.page.PageQuery;
|
||||
import com.agileboot.system.config.pojo.entity.SysConfig;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 配置查询参数
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ConfigQuery extends PageQuery {
|
||||
|
||||
// 配置名称
|
||||
private String configName;
|
||||
|
||||
// 配置key
|
||||
private String configKey;
|
||||
|
||||
// 是否允许更改配置
|
||||
private Boolean isAllowChange;
|
||||
|
||||
|
||||
public QueryWrapper<SysConfig> toQueryWrapper() {
|
||||
return new QueryWrapper<SysConfig>()
|
||||
.like(StringUtils.isNotEmpty(configName), "config_name", configName)
|
||||
.eq(StringUtils.isNotEmpty(configKey), "config_key", configKey)
|
||||
.eq(isAllowChange != null, "is_allow_change", isAllowChange)
|
||||
.orderByDesc("create_time");
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,9 @@
|
||||
package com.agileboot.system.config.service;
|
||||
|
||||
import com.agileboot.common.mybatis.core.page.PageR;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigDTO;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigQuery;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 参数配置表 服务类
|
||||
@ -18,4 +22,9 @@ public interface ISysConfigService {
|
||||
*/
|
||||
String getConfigValueByKey(String key);
|
||||
|
||||
PageR<ConfigDTO> getConfigPage(ConfigQuery query);
|
||||
|
||||
ConfigDTO getConfigInfo(Long id);
|
||||
|
||||
void updateConfig(ConfigUpdateCommand updateCommand);
|
||||
}
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
package com.agileboot.system.config.service.impl;
|
||||
|
||||
import com.agileboot.common.mybatis.core.page.PageR;
|
||||
import com.agileboot.system.config.mapper.SysConfigMapper;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigDTO;
|
||||
import com.agileboot.system.config.pojo.dto.ConfigQuery;
|
||||
import com.agileboot.system.config.pojo.entity.SysConfig;
|
||||
import com.agileboot.system.config.service.ISysConfigService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 参数配置表 服务实现类
|
||||
@ -31,4 +38,24 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||
return one.getConfigValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageR<ConfigDTO> getConfigPage(ConfigQuery query) {
|
||||
Page<SysConfig> page = this.page(query.buildPage(), query.toQueryWrapper());
|
||||
List<ConfigDTO> records = page.getRecords().stream().map(ConfigDTO::new).collect(Collectors.toList());
|
||||
return PageR.build(page, records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO getConfigInfo(Long id) {
|
||||
return new ConfigDTO(this.getById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfig(ConfigUpdateCommand updateCommand) {
|
||||
ConfigModel configModel = configModelFactory.loadById(updateCommand.getConfigId());
|
||||
configModel.loadUpdateCommand(updateCommand);
|
||||
configModel.checkCanBeModify();
|
||||
configModel.updateById();
|
||||
CacheCenter.configCache.invalidate(configModel.getConfigKey());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user