数据字典,新增动态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.*;
|
||||
|
||||
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys/dict/type")
|
||||
@Tag(name="字典类型")
|
||||
@Tag(name = "字典类型")
|
||||
@AllArgsConstructor
|
||||
public class SysDictTypeController {
|
||||
private final SysDictTypeService sysDictTypeService;
|
||||
|
@ -32,16 +32,27 @@ public class SysDictTypeController {
|
|||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('sys:dict:page')")
|
||||
public Result<PageResult<SysDictTypeVO>> page(@Valid SysDictTypeQuery query){
|
||||
public Result<PageResult<SysDictTypeVO>> page(@Valid SysDictTypeQuery query) {
|
||||
PageResult<SysDictTypeVO> page = sysDictTypeService.page(query);
|
||||
|
||||
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')")
|
||||
public Result<SysDictTypeVO> get(@PathVariable("id") Long id){
|
||||
public Result<SysDictTypeVO> get(@PathVariable("id") Long id) {
|
||||
SysDictTypeEntity entity = sysDictTypeService.getById(id);
|
||||
|
||||
return Result.ok(SysDictTypeConvert.INSTANCE.convert(entity));
|
||||
|
@ -50,7 +61,7 @@ public class SysDictTypeController {
|
|||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
public Result<String> save(@RequestBody @Valid SysDictTypeVO vo){
|
||||
public Result<String> save(@RequestBody @Valid SysDictTypeVO vo) {
|
||||
sysDictTypeService.save(vo);
|
||||
|
||||
return Result.ok();
|
||||
|
@ -59,7 +70,7 @@ public class SysDictTypeController {
|
|||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
public Result<String> update(@RequestBody @Valid SysDictTypeVO vo){
|
||||
public Result<String> update(@RequestBody @Valid SysDictTypeVO vo) {
|
||||
sysDictTypeService.update(vo);
|
||||
|
||||
return Result.ok();
|
||||
|
@ -68,7 +79,7 @@ public class SysDictTypeController {
|
|||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('sys:dict:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
public Result<String> delete(@RequestBody List<Long> idList) {
|
||||
sysDictTypeService.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
|
@ -76,7 +87,7 @@ public class SysDictTypeController {
|
|||
|
||||
@GetMapping("all")
|
||||
@Operation(summary = "全部字典数据")
|
||||
public Result<List<SysDictVO>> all(){
|
||||
public Result<List<SysDictVO>> all() {
|
||||
List<SysDictVO> dictList = sysDictTypeService.getDictList();
|
||||
|
||||
return Result.ok(dictList);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -14,28 +14,28 @@ import net.maku.framework.common.entity.BaseEntity;
|
|||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_dict_type")
|
||||
public class SysDictTypeEntity extends BaseEntity {
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dictName;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 类型:1 静态常量 2 动态SQL
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 动态sql
|
||||
*/
|
||||
private String sourceSql;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dictName;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 来源 0:字典数据 1:动态SQL
|
||||
*/
|
||||
private Integer dictSource;
|
||||
/**
|
||||
* 动态sql
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysD
|
|||
return new PageResult<>(SysDictTypeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
private Wrapper<SysDictTypeEntity> getWrapper(SysDictTypeQuery query){
|
||||
private Wrapper<SysDictTypeEntity> getWrapper(SysDictTypeQuery query) {
|
||||
LambdaQueryWrapper<SysDictTypeEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.like(StrUtil.isNotBlank(query.getDictType()), SysDictTypeEntity::getDictType, query.getDictType());
|
||||
wrapper.like(StrUtil.isNotBlank(query.getDictName()), SysDictTypeEntity::getDictName, query.getDictName());
|
||||
|
@ -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());
|
||||
|
@ -83,25 +94,24 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysD
|
|||
|
||||
// 全部字典列表
|
||||
List<SysDictVO> dictList = new ArrayList<>(typeList.size());
|
||||
for (SysDictTypeEntity type : typeList){
|
||||
for (SysDictTypeEntity type : typeList) {
|
||||
SysDictVO dict = new SysDictVO();
|
||||
dict.setDictType(type.getDictType());
|
||||
|
||||
for (SysDictDataEntity data : dataList){
|
||||
if(type.getId().equals(data.getDictTypeId())){
|
||||
for (SysDictDataEntity data : dataList) {
|
||||
if (type.getId().equals(data.getDictTypeId())) {
|
||||
dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue()));
|
||||
}
|
||||
}
|
||||
|
||||
if(type.getType() == 2){
|
||||
// 数据来源动态SQL
|
||||
if (type.getDictSource() == DictSourceEnum.SQL.getValue()) {
|
||||
// 增加动态列表
|
||||
String sql = type.getSourceSql();
|
||||
if(StringUtils.isNotBlank(sql)){
|
||||
try {
|
||||
dict.setDataList(sysDictDataDao.selectListForSql(sql));
|
||||
} catch (Exception e) {
|
||||
log.error("增加动态字典异常: type=" + type, e);
|
||||
}
|
||||
String sql = type.getDictSql();
|
||||
try {
|
||||
dict.setDataList(sysDictDataDao.getListForSql(sql));
|
||||
} catch (Exception e) {
|
||||
log.error("增加动态字典异常: type=" + type, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,37 +18,37 @@ import java.util.Date;
|
|||
@Data
|
||||
@Schema(description = "字典类型")
|
||||
public class SysDictTypeVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "字典类型", required = true)
|
||||
@NotBlank(message = "字典类型不能为空")
|
||||
private String dictType;
|
||||
@Schema(description = "字典类型", required = true)
|
||||
@NotBlank(message = "字典类型不能为空")
|
||||
private String dictType;
|
||||
|
||||
@Schema(description = "字典名称", required = true)
|
||||
@NotBlank(message = "字典名称不能为空")
|
||||
private String dictName;
|
||||
@Schema(description = "字典名称", required = true)
|
||||
@NotBlank(message = "字典名称不能为空")
|
||||
private String dictName;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "排序", required = true)
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
@Schema(description = "排序", required = true)
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date updateTime;
|
||||
@Schema(description = "更新时间")
|
||||
@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;
|
||||
@Schema(description = "动态sql")
|
||||
private String dictSql;
|
||||
}
|
Loading…
Reference in New Issue
Block a user