|
@@ -1,35 +1,135 @@
|
|
|
package com.dragoninfo.dcuc.auth.auth.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.dragoninfo.dcuc.auth.auth.bpo.DataAuthBPO;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.dto.DataAuthDTO;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.dto.SubDataAuthDTO;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.dto.SubDataDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.business.IDataAuthBusiness;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.*;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.*;
|
|
|
import com.dragoninfo.dcuc.auth.auth.entity.DataAuth;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.IBusService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IDataAuthService;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.BusResultVO;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.ResourceCatalogItemVO;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.ResourceCatalogVO;
|
|
|
+import com.dragoninfo.dcuc.user.user.entity.UserInfo;
|
|
|
+import com.dragoninfo.dcuc.user.user.facade.IUserFacade;
|
|
|
+import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
+import com.dragonsoft.duceap.base.entity.security.BaseSecurityUser;
|
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
+import com.dragonsoft.duceap.commons.util.MapUtils;
|
|
|
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
|
+import com.dragonsoft.duceap.core.context.ContextUtils;
|
|
|
import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
+import com.dragonsoft.duceap.core.search.filter.Condition;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StopWatch;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 数据权限serviceImpl
|
|
|
+ *
|
|
|
* @author mazq
|
|
|
* @date 2021/4/9
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private DataAuthBPO dataAuthBPO;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBusService busService;
|
|
|
+ @Autowired
|
|
|
+ private IDataAuthBusiness dataAuthBusiness;
|
|
|
+ @Autowired
|
|
|
+ private IUserFacade userFacade;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 字段分类字符串
|
|
|
+ */
|
|
|
+ public static final String columnClassifyStr = "columnClassify";
|
|
|
+ /**
|
|
|
+ * 安全等级字符串
|
|
|
+ */
|
|
|
+ public static final String dataSecurityLevelStr = "dataSecurityLevel";
|
|
|
+ /**
|
|
|
+ * 数据组织一级分类代码
|
|
|
+ */
|
|
|
+ public static final String dataClassifyOneCodeStr = "RESOURCE_SJZZYJFL";
|
|
|
+ /**
|
|
|
+ * 数据组织二级分类代码
|
|
|
+ */
|
|
|
+ public static final String dataClassifyTwoCodeStr = "RESOURCE_SJZZEJFL";
|
|
|
+ /**
|
|
|
+ * 数据标签1代码
|
|
|
+ */
|
|
|
+ public static final String dataLabelOneCodeStr = "RESOURCE_SJZYBQ1";
|
|
|
+ /**
|
|
|
+ * 数据标签2代码
|
|
|
+ */
|
|
|
+ public static final String dataLabelTwoCodeStr = "RESOURCE_SJZYBQ2";
|
|
|
+ /**
|
|
|
+ * 数据标签3代码
|
|
|
+ */
|
|
|
+ public static final String dataLabelThreeCodeStr = "RESOURCE_SJZYBQ3";
|
|
|
+ /**
|
|
|
+ * 数据标签4代码
|
|
|
+ */
|
|
|
+ public static final String dataLabelFourCodeStr = "RESOURCE_SJZYBQ4";
|
|
|
+ /**
|
|
|
+ * 数据标签5代码
|
|
|
+ */
|
|
|
+ public static final String dataLabelFiveCodeStr = "RESOURCE_SJZYBQ5";
|
|
|
+ /**
|
|
|
+ * 数据组织类型数组(按顺序。数据标签1-5为同级)
|
|
|
+ */
|
|
|
+ public static final String[] dataStrArr = new String[]{dataClassifyOneCodeStr, dataClassifyTwoCodeStr, dataLabelOneCodeStr, dataLabelTwoCodeStr, dataLabelThreeCodeStr, dataLabelFourCodeStr, dataLabelFiveCodeStr};
|
|
|
+ /**
|
|
|
+ * 数据分级
|
|
|
+ */
|
|
|
+ public static final String dataLevelStr = "DATA_LEVEL";
|
|
|
+ /**
|
|
|
+ * 数组资源分类对应实体属性key数组
|
|
|
+ */
|
|
|
+ private volatile LinkedHashMap<String, String> dataMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 字段一级分类
|
|
|
+ */
|
|
|
+ public static final String columnOneClassifyStr = "LEVEL_1_COLUMN_CLASSIFY";
|
|
|
+ /**
|
|
|
+ * 字段二级分类
|
|
|
+ */
|
|
|
+ public static final String columnTwoClassifyStr = "LEVEL_2_COLUMN_CLASSIFY";
|
|
|
+ /**
|
|
|
+ * 数据安全级别
|
|
|
+ */
|
|
|
+ public static final String dataSecurityLevelTypeStr = "DATA_SECURITY_LEVEL";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * codeDataTypeStr分隔符
|
|
|
+ */
|
|
|
+ public static final String CODE_DATA_TYPE_SEPARATOR = "\\|";
|
|
|
+
|
|
|
+ private static final String[] dataResourceClassifyLable = new String[]{dataLabelOneCodeStr,dataLabelTwoCodeStr,dataLabelThreeCodeStr,dataLabelFourCodeStr,dataLabelFiveCodeStr};
|
|
|
+
|
|
|
@Override
|
|
|
public DataAuthDTO add(DataAuthDTO dataAuthDTO) {
|
|
|
String userId = UserContextUtils.getCurrentUser().getId();
|
|
@@ -37,7 +137,7 @@ public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
Date date = new Date();
|
|
|
dataAuthDTO.setCreateUser(userId);
|
|
|
dataAuthDTO.setCreateTime(date);
|
|
|
- BeanUtils.copyProperties(dataAuthDTO,dataAuth);
|
|
|
+ BeanUtils.copyProperties(dataAuthDTO, dataAuth);
|
|
|
dataAuthBPO.save(dataAuth);
|
|
|
dataAuthDTO.setId(dataAuth.getId());
|
|
|
return dataAuthDTO;
|
|
@@ -51,7 +151,7 @@ public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
dataAuth.setDeleteTime(new Date());
|
|
|
dataAuth.setDeleteUser(userId);
|
|
|
DataAuthDTO dto = new DataAuthDTO();
|
|
|
- BeanUtils.copyProperties(dataAuth,dto);
|
|
|
+ BeanUtils.copyProperties(dataAuth, dto);
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
@@ -59,14 +159,14 @@ public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
public DataAuthDTO get(String id) {
|
|
|
DataAuthDTO dataAuthDTO = new DataAuthDTO();
|
|
|
DataAuth dataAuth = dataAuthBPO.get(id);
|
|
|
- BeanUtils.copyProperties(dataAuth,dataAuthDTO);
|
|
|
+ BeanUtils.copyProperties(dataAuth, dataAuthDTO);
|
|
|
return dataAuthDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean update(DataAuthDTO dataAuthDTO) {
|
|
|
DataAuth dataAuth = new DataAuth();
|
|
|
- BeanUtils.copyProperties(dataAuthDTO,dataAuth);
|
|
|
+ BeanUtils.copyProperties(dataAuthDTO, dataAuth);
|
|
|
dataAuthBPO.update(dataAuth);
|
|
|
return true;
|
|
|
}
|
|
@@ -74,7 +174,6 @@ public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
@Override
|
|
|
public List<DataAuthDTO> search(SearchDTO searchDTO) {
|
|
|
Searchable searchable = Searchable.toSearchable(searchDTO);
|
|
|
- searchable.addSearchFilter("deleted",SearchOperator.eq,BooleanEnum.FALSE.getValue());
|
|
|
List<DataAuth> dataAuths = dataAuthBPO.find(DataAuth.class, searchable);
|
|
|
List<DataAuthDTO> dtos = convertToDTOS(dataAuths);
|
|
|
return dtos;
|
|
@@ -82,88 +181,444 @@ public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
|
|
|
private List<DataAuthDTO> convertToDTOS(List<DataAuth> dataAuths) {
|
|
|
return dataAuths.stream().map(item -> {
|
|
|
- DataAuthDTO dto = new DataAuthDTO();
|
|
|
- BeanUtils.copyProperties(item, dto);
|
|
|
- return dto;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ DataAuthDTO dto = new DataAuthDTO();
|
|
|
+ BeanUtils.copyProperties(item, dto);
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
@Override
|
|
|
public boolean subDataAuthAdd(SubDataAuthDTO subDataAuthDTO) {
|
|
|
- String userId = UserContextUtils.getCurrentUser().getId();
|
|
|
+ List<SubDataDTO> subDataList = subDataAuthDTO.getDataAuthList();
|
|
|
+ //过滤哪些权限需要删除,哪些权限需要新增
|
|
|
Date date = new Date();
|
|
|
String subId = subDataAuthDTO.getSubId();
|
|
|
String subType = subDataAuthDTO.getSubType();
|
|
|
- List<SubDataDTO> dataAuthList = subDataAuthDTO.getDataAuthList();
|
|
|
- //过滤哪些权限需要删除,哪些权限需要新增
|
|
|
- List<DataAuth> existDataAuths = getDataAuthsBySub(subId, subType, null);
|
|
|
+ String authType = subDataAuthDTO.getAuthType();
|
|
|
+ String userId = null;
|
|
|
+ BaseSecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
+ if (null != currentUser) {
|
|
|
+ userId = currentUser.getId();
|
|
|
+ }
|
|
|
+ //传入权限为空时
|
|
|
+ //删除该主体下所有的权限
|
|
|
+ List<DataAuth> existDataAuths = getDataAuthsBySub(subId, subType, authType);
|
|
|
+ if (CollectionUtils.isEmpty(subDataList)) {
|
|
|
+ delDataAuthList(date, userId, existDataAuths);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
Set<String> existSet = existDataAuths.stream()
|
|
|
- .map(item -> item.getDataCode() +";"+ item.getDataType() + ";" + item.getAuthType())
|
|
|
+ .map(item -> item.getDataId() + ";" + item.getDataType())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Set<String> lastSet = subDataList.stream()
|
|
|
+ .map(item -> item.getDataId() + ";" + item.getDataType())
|
|
|
.collect(Collectors.toSet());
|
|
|
- Set<String> lastSet = dataAuthList.stream()
|
|
|
- .map(item -> {
|
|
|
- String dataType = item.getDataType();
|
|
|
- List<String> dataCodes = item.getDataCodes();
|
|
|
- String authType = item.getAuthType();
|
|
|
- dataCodes.forEach(code -> code =code+ ";" + dataType + ";" + authType);
|
|
|
- return dataCodes;
|
|
|
- }).flatMap(List::stream).collect(Collectors.toSet());
|
|
|
Set<String> addCollect = lastSet.stream().filter(s -> !existSet.contains(s)).collect(Collectors.toSet());
|
|
|
Set<String> delCollect = existSet.stream().filter(s -> !lastSet.contains(s)).collect(Collectors.toSet());
|
|
|
//新增
|
|
|
- for (String codeType : addCollect) {
|
|
|
- String[] arr = codeType.split(";");
|
|
|
+ List<SubDataDTO> addList = subDataList.stream()
|
|
|
+ .filter(item -> addCollect.contains(item.getDataId() + ";" + item.getDataType()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ addDataAuthList(date, subId, subType, authType, userId, addList);
|
|
|
+ //删除
|
|
|
+ List<DataAuth> delList = existDataAuths.stream()
|
|
|
+ .filter(item -> delCollect.contains(item.getDataId() + ";" + item.getDataType()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ delDataAuthList(date, userId, delList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addDataAuthList(Date date, String subId, String subType, String authType, String userId, List<SubDataDTO> addList) {
|
|
|
+ for (SubDataDTO dto : addList) {
|
|
|
DataAuth dataAuth = new DataAuth();
|
|
|
- dataAuth.setDataCode(arr[0]);
|
|
|
- dataAuth.setDataType(arr[1]);
|
|
|
+ dataAuth.setDataCode(dto.getDataCode());
|
|
|
+ dataAuth.setDataType(dto.getDataType());
|
|
|
+ dataAuth.setClassifyCode(dto.getClassifyCode());
|
|
|
+ dataAuth.setDataId(dto.getDataId());
|
|
|
dataAuth.setCreateUser(userId);
|
|
|
dataAuth.setCreateTime(date);
|
|
|
dataAuth.setSubId(subId);
|
|
|
dataAuth.setSubType(subType);
|
|
|
- dataAuth.setAuthType(arr[2]);
|
|
|
+ dataAuth.setAuthType(authType);
|
|
|
+ dataAuth.setDeleted(YesNotEnum.NO.getValue());
|
|
|
dataAuthBPO.save(dataAuth);
|
|
|
}
|
|
|
- //删除
|
|
|
- List<DataAuth> delList = existDataAuths.stream()
|
|
|
- .filter(item -> delCollect.contains(item.getDataCode() + ";" + item.getDataType()))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delDataAuthList(Date date, String userId, List<DataAuth> delList) {
|
|
|
for (DataAuth dataAuth : delList) {
|
|
|
dataAuth.setDeleteUser(userId);
|
|
|
dataAuth.setDeleteTime(date);
|
|
|
dataAuth.setDeleted(BooleanEnum.TRUE.getValue());
|
|
|
dataAuthBPO.update(dataAuth);
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
- public List<DataAuth> getDataAuthsBySub(String subId, String subType,String authType) {
|
|
|
+ @Override
|
|
|
+ public List<DataAuthDTO> getSubDataAuthList(List<SubDataAuthQueryDTO> list) {
|
|
|
+ //批量主体查询
|
|
|
+ List<DataAuth> result = new ArrayList<>();
|
|
|
+ //多次查询和concat(subId,subType)查询选用
|
|
|
+ //如果查询太慢应该拼接subId_subType作为冗余字段建立索引
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start("getSubDataAuthList");
|
|
|
+ for (SubDataAuthQueryDTO dto : list) {
|
|
|
+ List<DataAuth> dataAuths = getDataAuthsBySub(dto.getSubId(), dto.getSubType(), dto.getAuthType());
|
|
|
+ result.addAll(dataAuths);
|
|
|
+ }
|
|
|
+ stopWatch.stop();
|
|
|
+ log.info("getSubDataAuthList cost time:{}",stopWatch.getTotalTimeMillis());
|
|
|
+ //去除重复的数据全资源
|
|
|
+ result = result.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.collectingAndThen(
|
|
|
+ Collectors.toCollection(
|
|
|
+ () -> new TreeSet<>(
|
|
|
+ Comparator.comparing(da -> da.getDataId() + ";" + da.getDataType())
|
|
|
+ )
|
|
|
+ )
|
|
|
+ , ArrayList::new)
|
|
|
+ );
|
|
|
+ return convertToDTOS(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<DataAuth> getDataAuthsBySub(String subId, String subType, String authType) {
|
|
|
Searchable searchable = Searchable.newSearchable();
|
|
|
- searchable.addSearchFilter("subId", SearchOperator.eq,subId);
|
|
|
- searchable.addSearchFilter("subType", SearchOperator.eq,subType);
|
|
|
- searchable.addSearchFilter("deleted",SearchOperator.eq, BooleanEnum.FALSE.getValue());
|
|
|
- if(StringUtils.isNotBlank(authType)){
|
|
|
- searchable.addSearchFilter("authType",SearchOperator.eq,authType);
|
|
|
+ searchable.addSearchFilter("subId", SearchOperator.eq, subId);
|
|
|
+ searchable.addSearchFilter("subType", SearchOperator.eq, subType);
|
|
|
+ searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.getValue());
|
|
|
+ if (StringUtils.isNotBlank(authType)) {
|
|
|
+ searchable.addSearchFilter("authType", SearchOperator.eq, authType);
|
|
|
}
|
|
|
return dataAuthBPO.find(DataAuth.class, searchable);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询是否拥有数据项权限接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseDTO dataItemsCheck(DataItemsCheckDto dataItemsCheckDto) {
|
|
|
+ initDataMap();
|
|
|
+ UserInfo userInfo = userFacade.detailBySfzh(dataItemsCheckDto.getIdcard());
|
|
|
+ if (userInfo == null){
|
|
|
+ return ResponseDTO.fail("用户不存在", (Object) null);
|
|
|
+ }
|
|
|
+ //获取用户所有的数据分级分类
|
|
|
+ List<DataClassifyDTO> dataClassifyDTOList = dataAuthBusiness.userDataAuthInfoByUser(userInfo);
|
|
|
+ if (CollectionUtils.isNotEmpty(dataClassifyDTOList)){
|
|
|
+ Map<String, List<String>> listMap = new HashMap<>();
|
|
|
+ LinkedHashMap<String, List<String>> dataListMap = new LinkedHashMap<>();
|
|
|
+ List<String> dataStrList = Arrays.asList(dataStrArr);
|
|
|
+
|
|
|
+ for (DataClassifyDTO dataClassifyDTO : dataClassifyDTOList) {
|
|
|
+ for (SubDataDTO subDataDTO : dataClassifyDTO.getTickedDatas()) {
|
|
|
+ //获取每个类型对应的code数组
|
|
|
+ listMap = buildDataCodeMap(subDataDTO, listMap);
|
|
|
+ //数据资源分类需要构建父级的code数组
|
|
|
+ if (dataStrList.contains(subDataDTO.getDataType())) {
|
|
|
+ dataListMap = buildDataParentCodeMap(subDataDTO, dataListMap);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //先获取每个数据标识符下的数据项
|
|
|
+ for (DataItemsDto dataItemsDto : dataItemsCheckDto.getDataItemsDtoList()) {
|
|
|
+ try {
|
|
|
+ //数据项的分类代码、安全等级
|
|
|
+ getDataItemClassify(dataItemsDto, listMap, dataListMap, dataItemsCheckDto.getCurrentIdcard());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return ResponseDTO.fail(e.getMessage(), (Object) null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseDTO.newInstance(dataItemsCheckDto.getDataItemsDtoList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public SubDataAuthDTO getSubDataAuth(String subId, String subType,String authType) {
|
|
|
- List<DataAuth> dataAuths = getDataAuthsBySub(subId, subType,authType);
|
|
|
- List<SubDataDTO> subDataList = new ArrayList<>();
|
|
|
- SubDataAuthDTO subDataAuthDTO = new SubDataAuthDTO(subId,subType);
|
|
|
- Map<String, List<DataAuth>> map = dataAuths.stream().collect(Collectors.groupingBy(DataAuth::getDataType));
|
|
|
- for (Map.Entry<String, List<DataAuth>> entry : map.entrySet()) {
|
|
|
- String dataType = entry.getKey();
|
|
|
- List<DataAuth> dataAuthList = entry.getValue();
|
|
|
- List<String> codes = dataAuthList.stream().map(item -> item.getDataCode()).collect(Collectors.toList());
|
|
|
- SubDataDTO subDataDTO = new SubDataDTO();
|
|
|
- subDataDTO.setDataType(dataType);
|
|
|
- subDataDTO.setDataCodes(codes);
|
|
|
- subDataList.add(subDataDTO);
|
|
|
- }
|
|
|
- subDataAuthDTO.setDataAuthList(subDataList);
|
|
|
- return subDataAuthDTO;
|
|
|
+ public BusResultVO dataDetailList(SearchDTO searchDTO) {
|
|
|
+ DataDetailQueryDTO queryDTO = new DataDetailQueryDTO();
|
|
|
+ queryDTO.setPage(Integer.valueOf(searchDTO.getPage()) + 1);
|
|
|
+ queryDTO.setPageSize(Integer.valueOf(searchDTO.getSize()));
|
|
|
+ DataDetailConditionDTO condition = new DataDetailConditionDTO();
|
|
|
+ Searchable searchable = Searchable.toSearchable(searchDTO);
|
|
|
+ Condition resourceNameCondition = searchable.getSearchFilter("resourceName", SearchOperator.like);
|
|
|
+ if (resourceNameCondition != null && resourceNameCondition.getValue() != null){
|
|
|
+ condition.setResourceName(String.valueOf(resourceNameCondition.getValue()));
|
|
|
+ }
|
|
|
+ Condition codeDataTypeStrCondition = searchable.getSearchFilter("codeDataTypeStr", SearchOperator.eq);
|
|
|
+ if (codeDataTypeStrCondition != null && codeDataTypeStrCondition.getValue() != null){
|
|
|
+ String resourceTypes = String.valueOf(codeDataTypeStrCondition.getValue());
|
|
|
+ String[] resourceTypesArr = resourceTypes.split(CODE_DATA_TYPE_SEPARATOR);
|
|
|
+ List<ResourceTypeQueryDTO> resourceTypesList = new ArrayList<>();
|
|
|
+ ResourceTypeQueryDTO resourceTypeQueryDTO = new ResourceTypeQueryDTO();
|
|
|
+ resourceTypeQueryDTO.setCodeValue(resourceTypesArr[1]);
|
|
|
+ List<String> list = Arrays.asList(dataResourceClassifyLable);
|
|
|
+ if (resourceTypesArr.length >= 3 && !list.contains(resourceTypesArr[2])){
|
|
|
+ resourceTypeQueryDTO.setTypeCode(resourceTypesArr[2]);
|
|
|
+ }
|
|
|
+ resourceTypesList.add(resourceTypeQueryDTO);
|
|
|
+ condition.setResourceTypes(resourceTypesList);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(resourceNameCondition != null || codeDataTypeStrCondition != null){
|
|
|
+ queryDTO.setCondition(condition);
|
|
|
+ }
|
|
|
+ String query = JSON.toJSONString(queryDTO);
|
|
|
+ log.info("dataDetailList >> query:{}", query);
|
|
|
+ BusResultVO resultVO = busService.resourceDataItemsQuery(JSON.parseObject(query, new TypeReference<Map<String,Object>>(){{}}), "");
|
|
|
+
|
|
|
+ String idcard = ContextUtils.getUserInfo() == null ? "" : ContextUtils.getUserInfo().getIdcard();
|
|
|
+
|
|
|
+
|
|
|
+ Condition idcardCondition = searchable.getSearchFilter("idcard", SearchOperator.eq);
|
|
|
+ if (idcardCondition != null && idcardCondition.getValue() != null){
|
|
|
+ idcard = String.valueOf(idcardCondition.getValue());
|
|
|
+ }
|
|
|
+ List<DataClassifyDTO> dataClassifyDTOList = dataAuthBusiness.userDataAuthInfoByIdcard(idcard, null);
|
|
|
+ Map<String, List<String>> listMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (DataClassifyDTO dataClassifyDTO : dataClassifyDTOList) {
|
|
|
+ for (SubDataDTO subDataDTO : dataClassifyDTO.getTickedDatas()) {
|
|
|
+ //获取每个类型对应的code数组
|
|
|
+ listMap = buildDataCodeMap(subDataDTO, listMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ResourceCatalogVO resourceCatalogVO:resultVO.getResultData().getDataList()){
|
|
|
+ List<ResourceCatalogItemVO> list = new ArrayList<>();
|
|
|
+ for (ResourceCatalogItemVO resourceCatalogItemVO: resourceCatalogVO.getDataItems()){
|
|
|
+ ResourceCatalogVO catalogItemVO = new ResourceCatalogVO();
|
|
|
+ BeanUtils.copyProperties(resourceCatalogVO, catalogItemVO);
|
|
|
+ DataItemsDto dataItemsDto = new DataItemsDto();
|
|
|
+ dataItemsDto.setDataItemCode(resourceCatalogItemVO.getDataItemCode());
|
|
|
+ dataItemsDto.setResourceCode(resourceCatalogVO.getResourceCode());
|
|
|
+ Boolean isAuth = buildColumnAuth(catalogItemVO, dataItemsDto, listMap);
|
|
|
+ if (isAuth){
|
|
|
+ list.add(resourceCatalogItemVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resourceCatalogVO.setDataItems(list);
|
|
|
+ }
|
|
|
+ return resultVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据资源分类需要构建父级的code数组
|
|
|
+ * @param subDataDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private LinkedHashMap<String, List<String>> buildDataParentCodeMap(SubDataDTO subDataDTO, LinkedHashMap<String, List<String>> dataListMap) {
|
|
|
+
|
|
|
+ //dataId为父级和子级code通过|拼接,所以转换成数组
|
|
|
+ String[] dataArr = subDataDTO.getDataId().split(CODE_DATA_TYPE_SEPARATOR);
|
|
|
+ for (int i = 0; i < dataArr.length; i++) {
|
|
|
+ //数据授权时,构建的dataId为(01|01|RESOURCE_SJZYBQ1|1),第3个一定是标签类型。不是具体code值。所以跳过不处理
|
|
|
+ if (dataArr.length > 3 && i == 2){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //数组的前两个顺序和dataStrArr前两个一致,代表数据组织一级和二级,
|
|
|
+ String value = dataArr[i];
|
|
|
+ String key = dataStrArr[i];
|
|
|
+ //当数组最后一个值时。key应该为当前codeType。因为标签级是同级的。不重新赋值都永远是标签1的类型
|
|
|
+ if (i == (dataArr.length-1)){
|
|
|
+ key = subDataDTO.getDataType();
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(dataListMap.get(key))) {
|
|
|
+ dataListMap.put(key, new ArrayList<String>() {{
|
|
|
+ add(value);
|
|
|
+ }});
|
|
|
+ } else {
|
|
|
+ List<String> list = dataListMap.get(key);
|
|
|
+ //去重
|
|
|
+ if (!list.contains(value)){
|
|
|
+ list.add(value);
|
|
|
+ }
|
|
|
+ dataListMap.put(key, list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dataListMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取类型下的code数组
|
|
|
+ * @param subDataDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, List<String>> buildDataCodeMap(SubDataDTO subDataDTO, Map<String, List<String>> map) {
|
|
|
+ if (CollectionUtils.isEmpty(map.get(subDataDTO.getDataType()))) {
|
|
|
+ map.put(subDataDTO.getDataType(), new ArrayList<String>() {{
|
|
|
+ add(subDataDTO.getDataCode());
|
|
|
+ }});
|
|
|
+ } else {
|
|
|
+ List<String> mapList = map.get(subDataDTO.getDataType());
|
|
|
+ mapList.add(subDataDTO.getDataCode());
|
|
|
+ map.put(subDataDTO.getDataType(), mapList);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据项的分类代码、安全等级
|
|
|
+ *
|
|
|
+ * @param dataItemsDto
|
|
|
+ * @param currentIdcard
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void getDataItemClassify(DataItemsDto dataItemsDto, Map<String, List<String>> listMap, LinkedHashMap<String, List<String>> dataListMap, String currentIdcard) {
|
|
|
+
|
|
|
+ //构建参数
|
|
|
+ Map<String, Object> paramMap = buildSearcher(dataItemsDto.getResourceCode());
|
|
|
+ BusResultVO busResultVO = busService.resourceDataItemsQuery(paramMap, currentIdcard);
|
|
|
+ List<ResourceCatalogVO> resourceCatalogVOList = busResultVO.getResultData().getDataList();
|
|
|
+ if (CollectionUtils.isNotEmpty(resourceCatalogVOList)){
|
|
|
+ //数据资源标识符只可能对应一条数据
|
|
|
+ ResourceCatalogVO resourceCatalogVO = resourceCatalogVOList.get(0);
|
|
|
+
|
|
|
+ Boolean isAuth;
|
|
|
+ if (StringUtils.isNotBlank(dataItemsDto.getDataItemCode())) {
|
|
|
+ isAuth = buildColumnAuth(resourceCatalogVO, dataItemsDto, listMap);
|
|
|
+ } else {
|
|
|
+ isAuth = buildTableAuth(resourceCatalogVOList, dataItemsDto, dataListMap, listMap);
|
|
|
+ }
|
|
|
+ dataItemsDto.setAuth(isAuth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断表级权限
|
|
|
+ * @param resourceCatalogVOList
|
|
|
+ * @param dataItemsDto
|
|
|
+ * @param dataListMap
|
|
|
+ * @param listMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean buildTableAuth(List<ResourceCatalogVO> resourceCatalogVOList, DataItemsDto dataItemsDto, LinkedHashMap<String, List<String>> dataListMap, Map<String, List<String>> listMap) {
|
|
|
+ boolean isAuth = true;
|
|
|
+ //数据资源标识符只可能对应一条数据
|
|
|
+ ResourceCatalogVO resourceCatalogVO = resourceCatalogVOList.get(0);
|
|
|
+ //循环数组,获取对应的类型和对象属性key的关系
|
|
|
+ for (Map.Entry<String, String> map : dataMap.entrySet()) {
|
|
|
+ //获取属性值
|
|
|
+ String value = getFieldValueByName(map.getValue(), resourceCatalogVO);
|
|
|
+ //类型key
|
|
|
+ String key = map.getKey();
|
|
|
+ if (StringUtils.isNotBlank(value)) {
|
|
|
+ if (CollectionUtils.isNotEmpty(dataListMap.get(key))) {
|
|
|
+ //用户拥有的权限是否包含数据资源返回的值
|
|
|
+ if (!dataListMap.get(key).contains(value)) {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isAuth && StringUtils.isNotBlank(resourceCatalogVO.getDataClassification()) && !listMap.get(dataLevelStr).contains(resourceCatalogVO.getDataClassification())) {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ return isAuth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断列级权限
|
|
|
+ * @param resourceCatalogVO
|
|
|
+ * @param dataItemsDto
|
|
|
+ * @param listMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean buildColumnAuth(ResourceCatalogVO resourceCatalogVO, DataItemsDto dataItemsDto, Map<String, List<String>> listMap) {
|
|
|
+ boolean isAuth = true;
|
|
|
+ Map<String, String> columnResultMap = new HashMap<>();
|
|
|
+ //具体数据项值不为空,则循环获取全部数据项进行判断处理
|
|
|
+ if (resourceCatalogVO != null ) {
|
|
|
+ //数据项数组
|
|
|
+ List<ResourceCatalogItemVO> resourceCatalogItemVOList = resourceCatalogVO.getDataItems();
|
|
|
+ for (ResourceCatalogItemVO resourceCatalogItemVO : resourceCatalogItemVOList) {
|
|
|
+ if (resourceCatalogItemVO.getDataItemCode().equals(dataItemsDto.getDataItemCode())) {
|
|
|
+ columnResultMap.put(columnClassifyStr, resourceCatalogItemVO.getColumnClassify());
|
|
|
+ columnResultMap.put(dataSecurityLevelStr, resourceCatalogItemVO.getDataSecurityLevel());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //将数据项的分类代码、安全等级与用户所有的数据分级分类比对,有则说明有权限。无则说明无权限
|
|
|
+ if (StringUtils.isNotBlank(columnResultMap.get(columnClassifyStr))) {
|
|
|
+ List<String> stringList = new ArrayList<String>() {{add(columnOneClassifyStr);}{add(columnTwoClassifyStr);}};
|
|
|
+ for (String key : stringList) {
|
|
|
+ isAuth = true;
|
|
|
+ if (CollectionUtils.isNotEmpty(listMap.get(key))) {
|
|
|
+ if (!listMap.get(key).contains(columnResultMap.get(columnClassifyStr))) {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isAuth && StringUtils.isNotBlank(columnResultMap.get(dataSecurityLevelStr)) && !listMap.get(dataSecurityLevelTypeStr).contains(columnResultMap.get(dataSecurityLevelStr))) {
|
|
|
+ isAuth = false;
|
|
|
+ }
|
|
|
+ return isAuth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取对象属性值
|
|
|
+ * @param fieldName
|
|
|
+ * @param o
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String getFieldValueByName(String fieldName, Object o) {
|
|
|
+ try {
|
|
|
+ String firstLetter = fieldName.substring(0, 1).toUpperCase();
|
|
|
+ String getter = "get" + firstLetter + fieldName.substring(1);
|
|
|
+ Method method = o.getClass().getMethod(getter, new Class[]{});
|
|
|
+ Object value = method.invoke(o, new Object[]{});
|
|
|
+ if (value != null) {
|
|
|
+ return String.valueOf(value);
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建请求参数
|
|
|
+ *
|
|
|
+ * @param resourceCode
|
|
|
+ */
|
|
|
+ private Map<String, Object> buildSearcher(String resourceCode) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Map<String, Object> conditionParam = new HashMap<>();
|
|
|
+ conditionParam.put("resourceCode", resourceCode);
|
|
|
+ param.put("condition", conditionParam);
|
|
|
+ param.put("page", 1);
|
|
|
+ param.put("pageSize", 1);
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数组资源分类对应实体属性key数组
|
|
|
+ */
|
|
|
+ private void initDataMap() {
|
|
|
+ if (MapUtils.isEmpty(dataMap)) {
|
|
|
+ dataMap.put(dataClassifyOneCodeStr, "dataClassifyOneCode");
|
|
|
+ dataMap.put(dataClassifyTwoCodeStr, "dataClassifyTwoCode");
|
|
|
+ dataMap.put(dataLabelOneCodeStr, "dataLabelOneCode");
|
|
|
+ dataMap.put(dataLabelTwoCodeStr, "dataLabelTwoCode");
|
|
|
+ dataMap.put(dataLabelThreeCodeStr, "dataLabelThreeCode");
|
|
|
+ dataMap.put(dataLabelFourCodeStr, "dataLabelFourCode");
|
|
|
+ dataMap.put(dataLabelFiveCodeStr, "dataLabelFiveCode");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|