package com.changhong.epc.bean.tenant.system.permission; import com.changhong.ssc.data.autho.api.struct.UserPermission; import com.changhong.ssc.data.autho.base.struct.Condition; import com.changhong.ssc.data.autho.base.struct.DataPermission; import com.changhong.ssc.data.autho.base.struct.DataPermissionSet; import lombok.Data; import lombok.NoArgsConstructor; import java.util.*; import java.util.stream.Collectors; /** * 权限数据信息 */ @Data @NoArgsConstructor public class PowerValue extends UserPermission { // 表单数据 public static final String FORM_DATA_PREFIX = "list:"; // 按钮数据 public static final String BUTTON_DATA_PREFIX = "button:"; public PowerValue(UserPermission userPermission){ super.setDataPermissionMap(userPermission.getDataPermissionMap()); super.setFunctionPermissionSet(userPermission.getFunctionPermissionSet()); } /** * 获得表单数据权限信息 * @return */ public List> getFormDataPower(String prefix){ return getDataPermissionMap() .entrySet() .stream() .filter(entry->entry.getKey().trim().indexOf(prefix) == 0) .collect(Collectors.toList()); } /** * 根据表单id获得对应数据权限 * @param table * @return */ public Map> getDataPowersForTable(String table, String prefix){ List> dataPowers = getFormDataPower(prefix); Map> tablePowers = new TreeMap<>((k1, k2)->k2.length() - k1.length()); dataPowers.stream() .filter(dataPower-> table.matches(".*"+dataPower.getKey() .replace(prefix, "") .replace("*", ".*")+"$")) .forEach(dataPower->{ Collection vals = new ArrayList<>(); vals.addAll(dataPower.getValue().getCreateAllowed()); vals.addAll(dataPower.getValue().getDeleteAllowed()); vals.addAll(dataPower.getValue().getUpdateAllowed()); vals.addAll(dataPower.getValue().getRetrieveAllowed()); tablePowers.put(dataPower.getKey(), vals); }); return tablePowers; } public Collection getDataPowerConditionForFormId(String formId, String prefix){ Set conditions = new TreeSet<>((d1, d2)->d1.getColumn().compareTo(d2.getColumn())); getDataPowersForTable(formId, prefix) .values() .stream() .forEach(allData->{ allData.stream().forEach(data->{ conditions.addAll(data.getConditions()); }); }); return conditions; } public Collection getDataPowerConditionForTable(String table, String prefix){ if(table.indexOf("formdata") < 0){ return Collections.EMPTY_LIST; } return getDataPowerConditionForFormId(table, prefix); } }