fix: 系统变量支持同一个变量名,变量值可以多选

This commit is contained in:
taojinlong 2024-07-22 18:20:56 +08:00
parent afa95790ee
commit 89059e00f9
2 changed files with 29 additions and 22 deletions

View File

@ -23,10 +23,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -211,7 +209,7 @@ public class PermissionManage {
continue;
}
String value = handleSysVariable(userEntity, datasetRowPermissionsTreeItem.getValue());
String value = handleSysVariable(userEntity, datasetRowPermissionsTreeItem);
if (value == null) {
continue;
} else {
@ -227,28 +225,35 @@ public class PermissionManage {
return result;
}
private String handleSysVariable(UserFormVO userEntity, String sysVariable) {
private String handleSysVariable(UserFormVO userEntity, DatasetRowPermissionsTreeItem datasetRowPermissionsTreeItem) {
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 (!variable.isValid()){
continue;
}
if (variableId.equalsIgnoreCase(variable.getVariableId().toString())) {
if (variable.getSysVariableDto().getType().equalsIgnoreCase("text")) {
for (SysVariableValueDto sysVariableValueDto : variable.getValueList()) {
if (sysVariableValueDto.getId().equals(variable.getVariableValueId())) {
value = sysVariableValueDto.getValue();
}
String sysVariable = datasetRowPermissionsTreeItem.getValue();
if (StringUtils.isEmpty(sysVariable) && !(sysVariable.startsWith("${") && sysVariable.endsWith("}"))) {
return value;
}
String variableId = sysVariable.substring(2, sysVariable.length() - 1);
for (SysVariableValueItem variable : userEntity.getVariables()) {
if (!variable.isValid()) {
continue;
}
if (!variableId.equalsIgnoreCase(variable.getVariableId().toString())) {
continue;
}
if (variable.getSysVariableDto().getType().equalsIgnoreCase("text")) {
if (Arrays.asList("in", "not in").contains(datasetRowPermissionsTreeItem.getTerm())) {
value = String.join(",", variable.getValueList().stream().filter(sysVariableValueDto -> variable.getVariableValueIds().contains(sysVariableValueDto.getId().toString())).map(SysVariableValueDto::getValue).collect(Collectors.toList()));
} else {
for (SysVariableValueDto sysVariableValueDto : variable.getValueList()) {
if (sysVariableValueDto.getId().equals(variable.getVariableValueId())) {
value = sysVariableValueDto.getValue();
}
} else {
value = variable.getVariableValue();
}
}
} else {
value = variable.getVariableValue();
}
}
return value;
}

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
@ -14,8 +15,9 @@ public class SysVariableValueItem {
private String variableType;
@JsonSerialize(using = ToStringSerializer.class)
private Long variableId;
private List<String> variableValueIds = new ArrayList<>();
@JsonSerialize(using = ToStringSerializer.class)
private Long variableValueId;
private Long variableValueId ;
private String variableName;
private boolean valid = true;
private List<SysVariableValueDto> valueList;