|
@@ -0,0 +1,170 @@
|
|
|
|
+package com.dragoninfo.dcuc.auth.auth.service.impl;
|
|
|
|
+
|
|
|
|
+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.entity.DataAuth;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.IDataAuthService;
|
|
|
|
+import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
|
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
|
+import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
|
+import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
|
+import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 数据权限serviceImpl
|
|
|
|
+ * @author mazq
|
|
|
|
+ * @date 2021/4/9
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class DataAuthServiceImpl implements IDataAuthService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataAuthBPO dataAuthBPO;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public DataAuthDTO add(DataAuthDTO dataAuthDTO) {
|
|
|
|
+ String userId = UserContextUtils.getCurrentUser().getId();
|
|
|
|
+ DataAuth dataAuth = new DataAuth();
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ dataAuthDTO.setCreateUser(userId);
|
|
|
|
+ dataAuthDTO.setCreateTime(date);
|
|
|
|
+ BeanUtils.copyProperties(dataAuthDTO,dataAuth);
|
|
|
|
+ dataAuthBPO.save(dataAuth);
|
|
|
|
+ dataAuthDTO.setId(dataAuth.getId());
|
|
|
|
+ return dataAuthDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public DataAuthDTO del(String id) {
|
|
|
|
+ String userId = UserContextUtils.getCurrentUser().getId();
|
|
|
|
+ DataAuth dataAuth = dataAuthBPO.get(id);
|
|
|
|
+ dataAuth.setDeleted(BooleanEnum.TRUE.getValue());
|
|
|
|
+ dataAuth.setDeleteTime(new Date());
|
|
|
|
+ dataAuth.setDeleteUser(userId);
|
|
|
|
+ DataAuthDTO dto = new DataAuthDTO();
|
|
|
|
+ BeanUtils.copyProperties(dataAuth,dto);
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public DataAuthDTO get(String id) {
|
|
|
|
+ DataAuthDTO dataAuthDTO = new DataAuthDTO();
|
|
|
|
+ DataAuth dataAuth = dataAuthBPO.get(id);
|
|
|
|
+ BeanUtils.copyProperties(dataAuth,dataAuthDTO);
|
|
|
|
+ return dataAuthDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean update(DataAuthDTO dataAuthDTO) {
|
|
|
|
+ DataAuth dataAuth = new DataAuth();
|
|
|
|
+ BeanUtils.copyProperties(dataAuthDTO,dataAuth);
|
|
|
|
+ dataAuthBPO.update(dataAuth);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean subDataAuthAdd(SubDataAuthDTO subDataAuthDTO) {
|
|
|
|
+ String userId = UserContextUtils.getCurrentUser().getId();
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ String subId = subDataAuthDTO.getSubId();
|
|
|
|
+ String subType = subDataAuthDTO.getSubType();
|
|
|
|
+ List<SubDataDTO> dataAuthList = subDataAuthDTO.getDataAuthList();
|
|
|
|
+ //过滤哪些权限需要删除,哪些权限需要新增
|
|
|
|
+ List<DataAuth> existDataAuths = getDataAuthsBySub(subId, subType, null);
|
|
|
|
+ Set<String> existSet = existDataAuths.stream()
|
|
|
|
+ .map(item -> item.getDataCode() +";"+ item.getDataType() + ";" + item.getAuthType())
|
|
|
|
+ .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(";");
|
|
|
|
+ DataAuth dataAuth = new DataAuth();
|
|
|
|
+ dataAuth.setDataCode(arr[0]);
|
|
|
|
+ dataAuth.setDataType(arr[1]);
|
|
|
|
+ dataAuth.setCreateUser(userId);
|
|
|
|
+ dataAuth.setCreateTime(date);
|
|
|
|
+ dataAuth.setSubId(subId);
|
|
|
|
+ dataAuth.setSubType(subType);
|
|
|
|
+ dataAuth.setAuthType(arr[2]);
|
|
|
|
+ dataAuthBPO.save(dataAuth);
|
|
|
|
+ }
|
|
|
|
+ //删除
|
|
|
|
+ List<DataAuth> delList = existDataAuths.stream()
|
|
|
|
+ .filter(item -> delCollect.contains(item.getDataCode() + ";" + item.getDataType()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ 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) {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ return dataAuthBPO.find(DataAuth.class, searchable);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public SubDataAuthDTO getSubDataAuth(String subId, String subType,String authType) {
|
|
|
|
+ List<DataAuth> dataAuths = getDataAuthsBySub(subId, subType,authType);
|
|
|
|
+ SubDataAuthDTO subDataAuthDTO = new SubDataAuthDTO(subId,subType);
|
|
|
|
+ List<SubDataDTO> subDataList = new ArrayList<>();
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|