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

View File

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