Commit 6086dbe0 by zhouhb

[+]权限问题

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