Commit 6086dbe0 by zhouhb

[+]权限问题

1 parent 4c62f127
...@@ -61,22 +61,23 @@ public class MerchantRoleService { ...@@ -61,22 +61,23 @@ public class MerchantRoleService {
*/ */
public RoleResponse getById(Integer id) { public RoleResponse getById(Integer id) {
RpcResponse<MerchantRoleResponse> response = roleRemote.getByIdRemote(id); RpcResponse<MerchantRoleResponse> response = roleRemote.getByIdRemote(id);
if(response.isSuccess()){ if (response.isSuccess()) {
RoleResponse roleResponse = new RoleResponse(); RoleResponse roleResponse = new RoleResponse();
dozerMapper.map(response.getResult(), roleResponse); dozerMapper.map(response.getResult(), roleResponse);
this.responseDataTransfer(roleResponse, response.getResult().getAccountList()); this.responseDataTransfer(roleResponse, response.getResult().getAccountList());
return roleResponse; return roleResponse;
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
* 响应返回给前端数据转换 * 响应返回给前端数据转换
*
* @param roleResponse * @param roleResponse
* @param accountList * @param accountList
*/ */
private void responseDataTransfer(RoleResponse roleResponse, List<RoleAccountRelationResponse> accountList){ private void responseDataTransfer(RoleResponse roleResponse, List<RoleAccountRelationResponse> accountList) {
if(CollectionUtils.isEmpty(accountList)){ if (CollectionUtils.isEmpty(accountList)) {
return; return;
} }
List<RoleAccountTypeResponse> responseList = new ArrayList<>(); List<RoleAccountTypeResponse> responseList = new ArrayList<>();
...@@ -86,31 +87,31 @@ public class MerchantRoleService { ...@@ -86,31 +87,31 @@ public class MerchantRoleService {
roleAccountType.setAccounttypeId(accountRelationResponse.getAccounttypeId()); //角色id封装 roleAccountType.setAccounttypeId(accountRelationResponse.getAccounttypeId()); //角色id封装
//角色与角色子级关系数据封装 //角色与角色子级关系数据封装
List<RoleFunctionRelationResponse> functionList = accountRelationResponse.getFunctionList(); List<RoleFunctionRelationResponse> functionList = accountRelationResponse.getFunctionList();
if(CollectionUtils.isNotEmpty(functionList)){ if (CollectionUtils.isNotEmpty(functionList)) {
List<ProductRelationResponse> productList = new ArrayList<>(); //子级数据封装对象new List<ProductRelationResponse> productList = new ArrayList<>(); //子级数据封装对象new
//根据产品id分组 //根据产品id分组
Map<Integer, List<RoleFunctionRelationResponse>> functionMap = Map<Integer, List<RoleFunctionRelationResponse>> functionMap =
functionList.stream().collect(Collectors.groupingBy(RoleFunctionRelationResponse::getProductId)); functionList.stream().collect(Collectors.groupingBy(RoleFunctionRelationResponse::getProductId));
//分组后遍历封装子级关系数据 //分组后遍历封装子级关系数据
for(Integer key : functionMap.keySet()){ for (Integer key : functionMap.keySet()) {
ProductRelationResponse relationResponse = new ProductRelationResponse(); ProductRelationResponse relationResponse = new ProductRelationResponse();
relationResponse.setProductId(key); //产品id relationResponse.setProductId(key); //产品id
List<RoleFunctionRelationResponse> list = functionMap.get(key); List<RoleFunctionRelationResponse> list = functionMap.get(key);
relationResponse.setProductName(list.get(0).getProductName()); relationResponse.setProductName(list.get(0).getProductName());
List<Integer> idList = new ArrayList<>(); List<Integer> idList = new ArrayList<>();
list.stream().forEach(index ->{ list.stream().forEach(index -> {
//功能封装 //功能封装
if(index.getFuncitonId() != null && index.getFuncitonId() > 0){ if (index.getFuncitonId() != null && index.getFuncitonId() > 0) {
idList.add(index.getFuncitonId()); idList.add(index.getFuncitonId());
String value = index.getFunctionValue(); String value = index.getFunctionValue();
if(StringUtils.isNotEmpty(value)){ if (StringUtils.isNotEmpty(value)) {
String[] arr = value.split(";"); String[] arr = value.split(";");
int size = arr.length; int size = arr.length;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
idList.add(Integer.valueOf(arr[i].split(":")[0])); idList.add(Integer.valueOf(arr[i].split(":")[0]));
} }
} }
} else{ //菜单封装 } else { //菜单封装
idList.add(index.getMenuId()); idList.add(index.getMenuId());
} }
}); });
...@@ -135,12 +136,12 @@ public class MerchantRoleService { ...@@ -135,12 +136,12 @@ public class MerchantRoleService {
ConvertRequest.convertPage(request, new MerchantRoleRequest()); ConvertRequest.convertPage(request, new MerchantRoleRequest());
RpcResponse<RpcPagination<MerchantRoleResponse>> response = RpcResponse<RpcPagination<MerchantRoleResponse>> response =
roleRemote.getRolePageRemote(pagination); roleRemote.getRolePageRemote(pagination);
if(response.isSuccess()){ if (response.isSuccess()) {
Pagination<RoleResponse> res = ConvertResponse.convertPage(response.getResult(), RoleResponse.class); Pagination<RoleResponse> res = ConvertResponse.convertPage(response.getResult(), RoleResponse.class);
res.getData().stream().forEach(index -> index.setStatusName(CommonStatusEnum.getText(index.getDelFlag()))); res.getData().stream().forEach(index -> index.setStatusName(CommonStatusEnum.getText(index.getDelFlag())));
return res; return res;
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
...@@ -155,10 +156,10 @@ public class MerchantRoleService { ...@@ -155,10 +156,10 @@ public class MerchantRoleService {
typeRequest.setDelFlag(request.getDelFlag()); typeRequest.setDelFlag(request.getDelFlag());
RpcResponse<List<MerchantRoleResponse>> response = RpcResponse<List<MerchantRoleResponse>> response =
roleRemote.getRoleListRemote(typeRequest); roleRemote.getRoleListRemote(typeRequest);
if(response.isSuccess()){ if (response.isSuccess()) {
return ConvertResponse.convertList(response.getResult(), RoleResponse.class); return ConvertResponse.convertList(response.getResult(), RoleResponse.class);
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
...@@ -172,10 +173,10 @@ public class MerchantRoleService { ...@@ -172,10 +173,10 @@ public class MerchantRoleService {
MerchantRoleRequest typeRequest = new MerchantRoleRequest(); MerchantRoleRequest typeRequest = new MerchantRoleRequest();
dozerMapper.map(request, typeRequest); dozerMapper.map(request, typeRequest);
RpcResponse<Boolean> response = roleRemote.deleteRemote(typeRequest); RpcResponse<Boolean> response = roleRemote.deleteRemote(typeRequest);
if(response.isSuccess()){ if (response.isSuccess()) {
return response.getResult(); return response.getResult();
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
...@@ -188,10 +189,10 @@ public class MerchantRoleService { ...@@ -188,10 +189,10 @@ public class MerchantRoleService {
public Boolean insert(RoleInsertRequest request) { public Boolean insert(RoleInsertRequest request) {
RpcResponse<List<MerchantRoleResponse>> rpc = roleRemote.getListByNameRemote( RpcResponse<List<MerchantRoleResponse>> rpc = roleRemote.getListByNameRemote(
request.getRoleName(), request.getMerchantId()); request.getRoleName(), request.getMerchantId());
if(!rpc.isSuccess()){ if (!rpc.isSuccess()) {
throw new RpcServiceException(rpc.getException().getErrId(),rpc.getMessage()); throw new RpcServiceException(rpc.getException().getErrId(), rpc.getMessage());
} }
if(CollectionUtils.isNotEmpty(rpc.getResult())){ if (CollectionUtils.isNotEmpty(rpc.getResult())) {
throw new RpcServiceException(BusinessExceptionEnum.ROLE_NAME_EXIT); throw new RpcServiceException(BusinessExceptionEnum.ROLE_NAME_EXIT);
} }
MerchantRoleRequest roleRequest = new MerchantRoleRequest(); MerchantRoleRequest roleRequest = new MerchantRoleRequest();
...@@ -199,10 +200,10 @@ public class MerchantRoleService { ...@@ -199,10 +200,10 @@ public class MerchantRoleService {
List<RoleAccountTypeRequest> requestList = JSON.parseArray(request.getRequestList(), RoleAccountTypeRequest.class); List<RoleAccountTypeRequest> requestList = JSON.parseArray(request.getRequestList(), RoleAccountTypeRequest.class);
this.dataTransfer(roleRequest, requestList); this.dataTransfer(roleRequest, requestList);
RpcResponse<Boolean> response = roleRemote.insertRemote(roleRequest); RpcResponse<Boolean> response = roleRemote.insertRemote(roleRequest);
if(response.isSuccess()){ if (response.isSuccess()) {
return response.getResult(); return response.getResult();
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
...@@ -215,12 +216,12 @@ public class MerchantRoleService { ...@@ -215,12 +216,12 @@ public class MerchantRoleService {
public Boolean update(RoleUpdateRequest request) { public Boolean update(RoleUpdateRequest request) {
RpcResponse<List<MerchantRoleResponse>> rpcRoleList = roleRemote.getListByNameRemote( RpcResponse<List<MerchantRoleResponse>> rpcRoleList = roleRemote.getListByNameRemote(
request.getRoleName(), request.getMerchantId()); request.getRoleName(), request.getMerchantId());
if(!rpcRoleList.isSuccess()){ if (!rpcRoleList.isSuccess()) {
throw new RpcServiceException(rpcRoleList.getException().getErrId(),rpcRoleList.getMessage()); throw new RpcServiceException(rpcRoleList.getException().getErrId(), rpcRoleList.getMessage());
} }
List<MerchantRoleResponse> list = rpcRoleList.getResult(); List<MerchantRoleResponse> list = rpcRoleList.getResult();
if(CollectionUtils.isNotEmpty(list)){ if (CollectionUtils.isNotEmpty(list)) {
if(list.size() > 1 || !(list.get(0).getId().equals(request.getId()))){ if (list.size() > 1 || !(list.get(0).getId().equals(request.getId()))) {
throw new RpcServiceException(BusinessExceptionEnum.ROLE_NAME_EXIT); throw new RpcServiceException(BusinessExceptionEnum.ROLE_NAME_EXIT);
} }
} }
...@@ -229,19 +230,20 @@ public class MerchantRoleService { ...@@ -229,19 +230,20 @@ public class MerchantRoleService {
List<RoleAccountTypeRequest> requestList = JSON.parseArray(request.getRequestList(), RoleAccountTypeRequest.class); List<RoleAccountTypeRequest> requestList = JSON.parseArray(request.getRequestList(), RoleAccountTypeRequest.class);
this.dataTransfer(roleRequest, requestList); this.dataTransfer(roleRequest, requestList);
RpcResponse<Boolean> response = roleRemote.updateRemote(roleRequest); RpcResponse<Boolean> response = roleRemote.updateRemote(roleRequest);
if(response.isSuccess()){ if (response.isSuccess()) {
return response.getResult(); return response.getResult();
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
} }
/** /**
* 保存数据转换 * 保存数据转换
* @param roleRequest 请求保存的数据 *
* @param requestList 前端传送产品菜单数据 * @param roleRequest 请求保存的数据
* @param requestList 前端传送产品菜单数据
*/ */
private void dataTransfer(MerchantRoleRequest roleRequest, List<RoleAccountTypeRequest> requestList){ private void dataTransfer(MerchantRoleRequest roleRequest, List<RoleAccountTypeRequest> requestList) {
if(CollectionUtils.isEmpty(requestList)){ if (CollectionUtils.isEmpty(requestList)) {
return; return;
} }
List<RoleAccountRelationRequest> accountList = new ArrayList<>(); List<RoleAccountRelationRequest> accountList = new ArrayList<>();
...@@ -251,24 +253,24 @@ public class MerchantRoleService { ...@@ -251,24 +253,24 @@ public class MerchantRoleService {
RoleAccountRelationRequest relationRequest = new RoleAccountRelationRequest(); RoleAccountRelationRequest relationRequest = new RoleAccountRelationRequest();
relationRequest.setAccounttypeId(roleAccountType.getAccounttypeId()); relationRequest.setAccounttypeId(roleAccountType.getAccounttypeId());
List<ProductRequest> productList = roleAccountType.getProductList(); List<ProductRequest> productList = roleAccountType.getProductList();
if(CollectionUtils.isEmpty(productList)){ if (CollectionUtils.isEmpty(productList)) {
accountList.add(relationRequest); accountList.add(relationRequest);
continue; continue;
} }
List<RoleFunctionRelationRequest> functionList = new ArrayList<>(); List<RoleFunctionRelationRequest> functionList = new ArrayList<>();
productList.stream().forEach(index ->{ productList.stream().forEach(index -> {
List<Integer> menuIdList = index.getMenuIdList(); List<Integer> menuIdList = index.getMenuIdList();
List<FunctionRequest> functionIdList = index.getFunctionIdList(); List<FunctionRequest> functionIdList = index.getFunctionIdList();
if(CollectionUtils.isNotEmpty(menuIdList)){ if (CollectionUtils.isNotEmpty(menuIdList)) {
menuIdList.stream().forEach(menuId ->{ menuIdList.stream().forEach(menuId -> {
RoleFunctionRelationRequest relation = new RoleFunctionRelationRequest(); RoleFunctionRelationRequest relation = new RoleFunctionRelationRequest();
relation.setProductId(index.getProductId()); relation.setProductId(index.getProductId());
relation.setMenuId(menuId); relation.setMenuId(menuId);
functionList.add(relation); functionList.add(relation);
}); });
} }
if(CollectionUtils.isNotEmpty(functionIdList)){ if (CollectionUtils.isNotEmpty(functionIdList)) {
functionIdList.stream().forEach(function ->{ functionIdList.stream().forEach(function -> {
RoleFunctionRelationRequest relation = new RoleFunctionRelationRequest(); RoleFunctionRelationRequest relation = new RoleFunctionRelationRequest();
relation.setProductId(index.getProductId()); relation.setProductId(index.getProductId());
relation.setMenuId(function.getMenuId()); relation.setMenuId(function.getMenuId());
...@@ -277,6 +279,11 @@ public class MerchantRoleService { ...@@ -277,6 +279,11 @@ public class MerchantRoleService {
functionList.add(relation); functionList.add(relation);
}); });
} }
if (CollectionUtils.isEmpty(menuIdList) && CollectionUtils.isEmpty(functionIdList) && index.getProductId() != null) {
RoleFunctionRelationRequest relation = new RoleFunctionRelationRequest();
relation.setProductId(index.getProductId());
functionList.add(relation);
}
}); });
relationRequest.setFunctionList(functionList); relationRequest.setFunctionList(functionList);
accountList.add(relationRequest); accountList.add(relationRequest);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!