forked from github/dataease
feat: 增加系统变量功能
This commit is contained in:
parent
8d99bc6328
commit
e452437e5d
@ -8,6 +8,8 @@ import io.dataease.api.permissions.dataset.api.ColumnPermissionsApi;
|
||||
import io.dataease.api.permissions.dataset.api.RowPermissionsApi;
|
||||
import io.dataease.api.permissions.dataset.dto.*;
|
||||
import io.dataease.api.permissions.user.vo.UserFormVO;
|
||||
import io.dataease.api.permissions.variable.dto.SysVariableValueDto;
|
||||
import io.dataease.api.permissions.variable.dto.SysVariableValueItem;
|
||||
import io.dataease.constant.ColumnPermissionConstants;
|
||||
import io.dataease.dto.dataset.DatasetTableFieldDTO;
|
||||
import io.dataease.utils.AuthUtils;
|
||||
@ -188,18 +190,27 @@ public class PermissionManage {
|
||||
}
|
||||
// 替换系统变量
|
||||
if (StringUtils.equalsIgnoreCase(record.getAuthTargetType(), "sysParams")) {
|
||||
String expressionTree = record.getExpressionTree();
|
||||
if (StringUtils.isNotEmpty(userEntity.getAccount())) {
|
||||
expressionTree = expressionTree.replaceAll("\\$\\{sysParams\\.userId}", userEntity.getAccount());
|
||||
DatasetRowPermissionsTreeObj tree = JsonUtil.parseObject(record.getExpressionTree(), DatasetRowPermissionsTreeObj.class);
|
||||
List<DatasetRowPermissionsTreeItem> items = new ArrayList<>();
|
||||
for (DatasetRowPermissionsTreeItem datasetRowPermissionsTreeItem : tree.getItems()) {
|
||||
if (StringUtils.isNotEmpty(userEntity.getAccount()) && datasetRowPermissionsTreeItem.getValue().equalsIgnoreCase("\\$\\{sysParams\\.userId}")) {
|
||||
datasetRowPermissionsTreeItem.setValue(userEntity.getAccount());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userEntity.getEmail()) && datasetRowPermissionsTreeItem.getValue().equalsIgnoreCase("\\$\\{sysParams\\.userEmail}")) {
|
||||
datasetRowPermissionsTreeItem.setValue(userEntity.getEmail());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userEntity.getName()) && datasetRowPermissionsTreeItem.getValue().equalsIgnoreCase("\\$\\{sysParams\\.userName}")) {
|
||||
datasetRowPermissionsTreeItem.setValue(userEntity.getName());
|
||||
}
|
||||
String value = handleSysVariable(userEntity, datasetRowPermissionsTreeItem.getValue());
|
||||
if (value == null) {
|
||||
continue;
|
||||
} else {
|
||||
datasetRowPermissionsTreeItem.setValue(value);
|
||||
}
|
||||
items.add(datasetRowPermissionsTreeItem);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userEntity.getEmail())) {
|
||||
expressionTree = expressionTree.replaceAll("\\$\\{sysParams\\.userEmail}", userEntity.getEmail());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(userEntity.getName())) {
|
||||
expressionTree = expressionTree.replaceAll("\\$\\{sysParams\\.userName}", userEntity.getName());
|
||||
}
|
||||
record.setExpressionTree(expressionTree);
|
||||
DatasetRowPermissionsTreeObj tree = JsonUtil.parseObject(expressionTree, DatasetRowPermissionsTreeObj.class);
|
||||
tree.setItems(items);
|
||||
record.setTree(tree);
|
||||
}
|
||||
result.add(record);
|
||||
@ -207,6 +218,28 @@ public class PermissionManage {
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleSysVariable(UserFormVO userEntity, String sysVariable) {
|
||||
String value = null;
|
||||
if (StringUtils.isNotBlank(sysVariable) && sysVariable.startsWith("${") && sysVariable.endsWith("}")) {
|
||||
String variableId = sysVariable.substring(2, sysVariable.length() - 1);
|
||||
for (SysVariableValueItem variable : userEntity.getVariables()) {
|
||||
if (variableId.equalsIgnoreCase(variable.getVariableId())) {
|
||||
if (variable.getSysVariableDto().getType().equalsIgnoreCase("text")) {
|
||||
for (SysVariableValueDto sysVariableValueDto : variable.getValueList()) {
|
||||
if (sysVariableValueDto.getId().toString().equals(variable.getVariableValueId())) {
|
||||
value = sysVariableValueDto.getValue();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value = variable.getVariableValue();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private List<Long> intersectionForList(List<Long> list1, List<Long> list2) {
|
||||
List<Long> result = new ArrayList<>();
|
||||
for (Long id : list1) {
|
||||
|
@ -8,14 +8,18 @@ export const variableDetailApi = id => request.get({ url: '/sysVariable/detail/'
|
||||
|
||||
export const variableDeletelApi = id => request.get({ url: '/sysVariable/delete/' + id })
|
||||
|
||||
export const searchVariableApi = data => request.post({ url: '/sysVariable/query', data })
|
||||
export const searchVariableApi = async data => request.post({ url: '/sysVariable/query', data })
|
||||
|
||||
export const valueSelectedForVaribleApi = (page: number, limit: number, data) =>
|
||||
export const valueSelectedForVariableApi = (page: number, limit: number, data) =>
|
||||
request.post({ url: `/sysVariable/value/selected/${page}/${limit}`, data })
|
||||
|
||||
export const valueForVariable = id => request.get({ url: '/sysVariable/value/selected/' + id })
|
||||
|
||||
export const variableValueCreateApi = data =>
|
||||
request.post({ url: '/sysVariable/value/create', data })
|
||||
|
||||
export const variableValueDeletelApi = id => request.get({ url: '/sysVariable/value/delete/' + id })
|
||||
|
||||
export const variableValueEditApi = data => request.post({ url: '/sysVariable/value/edit', data })
|
||||
|
||||
export const batchDelApi = data => request.post({ url: '/sysVariable/value/batchDel', data })
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.dataease.api.permissions.user.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.dataease.api.permissions.variable.dto.SysVariableValueItem;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@ -32,5 +33,5 @@ public class UserCreator implements Serializable {
|
||||
@JsonIgnore
|
||||
private Long uid;
|
||||
@Schema(description = "系统变量")
|
||||
private String sysVariable;
|
||||
private List<SysVariableValueItem> variables;
|
||||
}
|
||||
|
@ -54,10 +54,14 @@ public interface SysVariablesApi {
|
||||
@GetMapping("/value/delete/{id}")
|
||||
void deleteValue(@PathVariable String id);
|
||||
|
||||
// @PostMapping("/value/selected/{id}")
|
||||
// List<SysVariableValueDto> selectVariableValue(@PathVariable("id") String id, @PathVariable("pageSize") int pageSize, @RequestBody SysVariableDto request);
|
||||
@GetMapping("/value/selected/{id}")
|
||||
List<SysVariableValueDto> selectVariableValue(@PathVariable("id") String id);
|
||||
|
||||
@PostMapping("/value/selected/{goPage}/{pageSize}")
|
||||
IPage<SysVariableValueDto> selectPage(@PathVariable("goPage") int goPage, @PathVariable("pageSize") int pageSize, @RequestBody SysVariableDto request);
|
||||
IPage<SysVariableValueDto> selectPage(@PathVariable("goPage") int goPage, @PathVariable("pageSize") int pageSize, @RequestBody SysVariableValueDto sysVariableValueDto);
|
||||
|
||||
@Operation(summary = "批量删除")
|
||||
@PostMapping("/value/batchDel")
|
||||
void batchDel(@RequestBody List<Long> ids);
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ public class SysVariableDto {
|
||||
private Long id;
|
||||
private String type;
|
||||
private String name;
|
||||
private Long min;
|
||||
private Long max;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private boolean root = false;
|
||||
private boolean disabled = false;
|
||||
}
|
||||
|
@ -2,9 +2,13 @@ package io.dataease.api.permissions.variable.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SysVariableValueItem {
|
||||
private String variable;
|
||||
private String variableValue;
|
||||
private SysVariableDto sysVariableDto;
|
||||
private String variableId;
|
||||
private String variableValueId;
|
||||
private String variableValue;
|
||||
private List<SysVariableValueDto> valueList;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user