数据字典,新增动态SQL
This commit is contained in:
parent
7f2bac7d76
commit
097194fe00
|
|
@ -275,6 +275,8 @@ create table sys_dict_type
|
|||
id bigint IDENTITY NOT NULL,
|
||||
dict_type varchar(100),
|
||||
dict_name varchar(255),
|
||||
dict_source int default 0,
|
||||
dict_sql varchar(500),
|
||||
remark varchar(255),
|
||||
sort int,
|
||||
version int,
|
||||
|
|
@ -290,6 +292,8 @@ COMMENT ON TABLE sys_dict_type IS '字典类型';
|
|||
COMMENT ON COLUMN sys_dict_type.id IS 'id';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_type IS '字典类型';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_name IS '字典名称';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_source IS '来源 0:字典数据 1:动态SQL';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_sql IS '动态SQL';
|
||||
COMMENT ON COLUMN sys_dict_type.remark IS '备注';
|
||||
COMMENT ON COLUMN sys_dict_type.sort IS '排序';
|
||||
COMMENT ON COLUMN sys_dict_type.version IS '版本号';
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ create table sys_dict_type
|
|||
id bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
dict_type varchar(100) NOT NULL COMMENT '字典类型',
|
||||
dict_name varchar(255) NOT NULL COMMENT '字典名称',
|
||||
dict_source tinyint default 0 COMMENT '来源 0:字典数据 1:动态SQL',
|
||||
dict_sql varchar(500) COMMENT '动态SQL',
|
||||
remark varchar(255) COMMENT '备注',
|
||||
sort int COMMENT '排序',
|
||||
version int COMMENT '版本号',
|
||||
|
|
|
|||
|
|
@ -275,6 +275,8 @@ create table sys_dict_type
|
|||
id bigserial NOT NULL,
|
||||
dict_type varchar(100),
|
||||
dict_name varchar(255),
|
||||
dict_source int default 0,
|
||||
dict_sql varchar(500),
|
||||
remark varchar(255),
|
||||
sort int,
|
||||
version int,
|
||||
|
|
@ -290,6 +292,8 @@ COMMENT ON TABLE sys_dict_type IS '字典类型';
|
|||
COMMENT ON COLUMN sys_dict_type.id IS 'id';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_type IS '字典类型';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_name IS '字典名称';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_source IS '来源 0:字典数据 1:动态SQL';
|
||||
COMMENT ON COLUMN sys_dict_type.dict_sql IS '动态SQL';
|
||||
COMMENT ON COLUMN sys_dict_type.remark IS '备注';
|
||||
COMMENT ON COLUMN sys_dict_type.sort IS '排序';
|
||||
COMMENT ON COLUMN sys_dict_type.version IS '版本号';
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import net.maku.framework.common.page.PageResult;
|
|||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.system.convert.SysDictTypeConvert;
|
||||
import net.maku.system.entity.SysDictTypeEntity;
|
||||
import net.maku.system.service.SysDictTypeService;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import net.maku.system.query.SysDictTypeQuery;
|
||||
import net.maku.system.service.SysDictTypeService;
|
||||
import net.maku.system.vo.SysDictTypeVO;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -38,6 +38,17 @@ public class SysDictTypeController {
|
|||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("list/sql")
|
||||
@Operation(summary = "动态SQL数据")
|
||||
@PreAuthorize("hasAuthority('sys:dict:page')")
|
||||
public Result<PageResult<SysDictVO.DictData>> listSql(Long id) {
|
||||
List<SysDictVO.DictData> list = sysDictTypeService.getDictSql(id);
|
||||
|
||||
PageResult<SysDictVO.DictData> page = new PageResult<>(list, list.size());
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('sys:dict:info')")
|
||||
|
|
|
|||
|
|
@ -18,6 +18,5 @@ import java.util.List;
|
|||
public interface SysDictDataDao extends BaseDao<SysDictDataEntity> {
|
||||
|
||||
@Select("${sql}")
|
||||
List<SysDictVO.DictData> selectListForSql(@Param("sql") String sql);
|
||||
|
||||
List<SysDictVO.DictData> getListForSql(@Param("sql") String sql);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ public class SysDictTypeEntity extends BaseEntity {
|
|||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 类型:1 静态常量 2 动态SQL
|
||||
* 来源 0:字典数据 1:动态SQL
|
||||
*/
|
||||
private Integer type;
|
||||
private Integer dictSource;
|
||||
/**
|
||||
* 动态sql
|
||||
*/
|
||||
private String sourceSql;
|
||||
private String dictSql;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package net.maku.system.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 字典数据来源
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DictSourceEnum {
|
||||
/**
|
||||
* 字典数据
|
||||
*/
|
||||
DICT(0),
|
||||
/**
|
||||
* 动态SQL
|
||||
*/
|
||||
SQL(1);
|
||||
|
||||
private final int value;
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@ package net.maku.system.service;
|
|||
import net.maku.framework.common.page.PageResult;
|
||||
import net.maku.framework.common.service.BaseService;
|
||||
import net.maku.system.entity.SysDictTypeEntity;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import net.maku.system.query.SysDictTypeQuery;
|
||||
import net.maku.system.vo.SysDictTypeVO;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -25,6 +25,11 @@ public interface SysDictTypeService extends BaseService<SysDictTypeEntity> {
|
|||
void delete(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 获取动态SQL数据
|
||||
*/
|
||||
List<SysDictVO.DictData> getDictSql(Long id);
|
||||
|
||||
/**
|
||||
* 获取全部字典列表
|
||||
*/
|
||||
List<SysDictVO> getDictList();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.exception.ServerException;
|
||||
import net.maku.framework.common.page.PageResult;
|
||||
import net.maku.framework.common.service.impl.BaseServiceImpl;
|
||||
import net.maku.system.convert.SysDictTypeConvert;
|
||||
|
|
@ -14,11 +15,11 @@ import net.maku.system.dao.SysDictDataDao;
|
|||
import net.maku.system.dao.SysDictTypeDao;
|
||||
import net.maku.system.entity.SysDictDataEntity;
|
||||
import net.maku.system.entity.SysDictTypeEntity;
|
||||
import net.maku.system.service.SysDictTypeService;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import net.maku.system.enums.DictSourceEnum;
|
||||
import net.maku.system.query.SysDictTypeQuery;
|
||||
import net.maku.system.service.SysDictTypeService;
|
||||
import net.maku.system.vo.SysDictTypeVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -73,6 +74,16 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysD
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictVO.DictData> getDictSql(Long id) {
|
||||
SysDictTypeEntity entity = this.getById(id);
|
||||
try {
|
||||
return sysDictDataDao.getListForSql(entity.getDictSql());
|
||||
} catch (Exception e) {
|
||||
throw new ServerException("动态SQL执行失败,请检查SQL是否正确!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictVO> getDictList() {
|
||||
// 全部字典类型列表
|
||||
List<SysDictTypeEntity> typeList = this.list(Wrappers.emptyWrapper());
|
||||
|
|
@ -93,17 +104,16 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysD
|
|||
}
|
||||
}
|
||||
|
||||
if(type.getType() == 2){
|
||||
// 数据来源动态SQL
|
||||
if (type.getDictSource() == DictSourceEnum.SQL.getValue()) {
|
||||
// 增加动态列表
|
||||
String sql = type.getSourceSql();
|
||||
if(StringUtils.isNotBlank(sql)){
|
||||
String sql = type.getDictSql();
|
||||
try {
|
||||
dict.setDataList(sysDictDataDao.selectListForSql(sql));
|
||||
dict.setDataList(sysDictDataDao.getListForSql(sql));
|
||||
} catch (Exception e) {
|
||||
log.error("增加动态字典异常: type=" + type, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dictList.add(dict);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ public class SysDictTypeVO implements Serializable {
|
|||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "类型:1 静态常量 2 动态SQL")
|
||||
private Integer type;
|
||||
@Schema(description = "来源 0:字典数据 1:动态SQL")
|
||||
private Integer dictSource;
|
||||
|
||||
@Schema(description = "动态sql")
|
||||
private String sourceSql;
|
||||
private String dictSql;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user