Commit face0257 by wangnb

账户体系账户类型、角色响应数据转换--think.wang

1 parent 1d17d9c1
...@@ -4,6 +4,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException; ...@@ -4,6 +4,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse; import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.merchants.model.response.MerchantAccountTypeResponse; import cn.com.glsx.merchants.model.response.MerchantAccountTypeResponse;
import cn.com.glsx.merchants.request.accounttype.*; import cn.com.glsx.merchants.request.accounttype.*;
import cn.com.glsx.merchants.response.AccountTypeResponse;
import cn.com.glsx.merchants.service.MerchantAccountTypeService; import cn.com.glsx.merchants.service.MerchantAccountTypeService;
import cn.com.glsx.merchants.service.MerchantUserService; import cn.com.glsx.merchants.service.MerchantUserService;
import cn.com.glsx.merchants.util.Pagination; import cn.com.glsx.merchants.util.Pagination;
...@@ -77,7 +78,7 @@ public class MerchantAccountTypeController { ...@@ -77,7 +78,7 @@ public class MerchantAccountTypeController {
*/ */
@ServiceMethod(method = "org.ore.api.accountType.getById", needInSession = NeedInSessionType.YES) @ServiceMethod(method = "org.ore.api.accountType.getById", needInSession = NeedInSessionType.YES)
@ApiOperation("根据id获取账户类型接口") @ApiOperation("根据id获取账户类型接口")
public RopResponse<MerchantAccountTypeResponse> getById(AccountTypeSearchRequest request) { public RopResponse<AccountTypeResponse> getById(AccountTypeSearchRequest request) {
try { try {
return RopResponse.success(accountTypeService.getAccountTypeDetail(request.getId())); return RopResponse.success(accountTypeService.getAccountTypeDetail(request.getId()));
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
......
...@@ -8,6 +8,7 @@ import cn.com.glsx.merchants.request.role.RoleDeleteRequest; ...@@ -8,6 +8,7 @@ import cn.com.glsx.merchants.request.role.RoleDeleteRequest;
import cn.com.glsx.merchants.request.role.RoleInsertRequest; import cn.com.glsx.merchants.request.role.RoleInsertRequest;
import cn.com.glsx.merchants.request.role.RoleListSearchRequest; import cn.com.glsx.merchants.request.role.RoleListSearchRequest;
import cn.com.glsx.merchants.request.role.RoleUpdateRequest; import cn.com.glsx.merchants.request.role.RoleUpdateRequest;
import cn.com.glsx.merchants.response.RoleResponse;
import cn.com.glsx.merchants.service.MerchantRoleService; import cn.com.glsx.merchants.service.MerchantRoleService;
import cn.com.glsx.merchants.service.MerchantUserService; import cn.com.glsx.merchants.service.MerchantUserService;
import cn.com.glsx.merchants.util.Pagination; import cn.com.glsx.merchants.util.Pagination;
...@@ -81,7 +82,7 @@ public class MerchantRoleController { ...@@ -81,7 +82,7 @@ public class MerchantRoleController {
*/ */
@ServiceMethod(method = "org.ore.api.role.getById", needInSession = NeedInSessionType.YES) @ServiceMethod(method = "org.ore.api.role.getById", needInSession = NeedInSessionType.YES)
@ApiOperation("根据id获取角色管理接口") @ApiOperation("根据id获取角色管理接口")
public RopResponse<MerchantRoleResponse> getById(AccountTypeSearchRequest request) { public RopResponse<RoleResponse> getById(AccountTypeSearchRequest request) {
try { try {
return RopResponse.success(roleService.getById(request.getId())); return RopResponse.success(roleService.getById(request.getId()));
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
......
package cn.com.glsx.merchants.response;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
public class AccountTypeResponse implements Serializable {
private Integer id;
/**
* 账户类型名称
*/
private String accounttypeName;
/**
* 描述
*/
private String accounttypeDetail;
/**
* 创建人
*/
private Integer createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private Integer updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
/**
* 是否删除:0=正常,-1=删除 1.草稿
*/
private Byte delFlag;
/**
* 账户类型编码
*/
private String accounttypeCode;
/**
* 创建账户
*/
private String createdAccount;
/**
* 更新账户
*/
private String updatedAccount;
/**
* 账户类型功能列表
*/
private List<ProductRelationResponse> responseList;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.response;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhouhaibao
* @version 1.0
* @description: 功能关系请求
* @date 2021/7/16 16:50
*/
@Data
public class FunctionRelationResponse implements Serializable {
/**
* 功能id
*/
private Integer id;
/**
* 父级菜单id
*/
private Integer menuId;
/**
* 选中的功能值
*/
private String functionValue;
}
package cn.com.glsx.merchants.response;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author zhouhaibao
* @version 1.0
* @description: 产品菜单关系响应数据
* @date 2021/7/16 16:50
*/
@Data
public class ProductRelationResponse implements Serializable {
/**
* 产品id
*/
private Integer productId;
/**
* 菜单id列表
*/
private List<Integer> menuIdList;
/**
* 选中的功能值
*/
private List<FunctionRelationResponse> functionIdList;
}
package cn.com.glsx.merchants.response;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author zhouhaibao
* @version 1.0
* @description: 角色账户类型关系响应数据
* @date 2021/7/16 16:50
*/
@Data
public class RoleAccountTypeResponse implements Serializable {
/**
* 账户类型id
*/
private Integer accounttypeId;
/**
* 产品列表
*/
private List<ProductRelationResponse> productList;
}
package cn.com.glsx.merchants.response;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
public class RoleResponse implements Serializable {
private Integer id;
/**
* 角色名称
*/
private String roleName;
/**
* 角色描述
*/
private String roleDescription;
/**
* 所属商户id
*/
private Integer merchantId;
/**
* 创建时间
*/
private Integer createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private Integer updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
/**
* 创建账户
*/
private String createdAccount;
/**
* 更新账户
*/
private String updatedAccount;
/**
* 角色关联账户类型列表
*/
private List<RoleAccountTypeResponse> responseList;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ import cn.com.glsx.merchants.convert.ConvertRequest; ...@@ -7,6 +7,7 @@ import cn.com.glsx.merchants.convert.ConvertRequest;
import cn.com.glsx.merchants.convert.ConvertResponse; import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.model.request.AccountFunctionRelationRequest; import cn.com.glsx.merchants.model.request.AccountFunctionRelationRequest;
import cn.com.glsx.merchants.model.request.MerchantAccountTypeRequest; import cn.com.glsx.merchants.model.request.MerchantAccountTypeRequest;
import cn.com.glsx.merchants.model.response.AccountFunctionRelationResponse;
import cn.com.glsx.merchants.model.response.MerchantAccountTypeResponse; import cn.com.glsx.merchants.model.response.MerchantAccountTypeResponse;
import cn.com.glsx.merchants.remote.MerchantAccountTypeRemote; import cn.com.glsx.merchants.remote.MerchantAccountTypeRemote;
import cn.com.glsx.merchants.request.FunctionRequest; import cn.com.glsx.merchants.request.FunctionRequest;
...@@ -15,6 +16,9 @@ import cn.com.glsx.merchants.request.accounttype.AccountTypeDeleteRequest; ...@@ -15,6 +16,9 @@ import cn.com.glsx.merchants.request.accounttype.AccountTypeDeleteRequest;
import cn.com.glsx.merchants.request.accounttype.AccountTypeInsertRequest; import cn.com.glsx.merchants.request.accounttype.AccountTypeInsertRequest;
import cn.com.glsx.merchants.request.accounttype.AccountTypeListSearchRequest; import cn.com.glsx.merchants.request.accounttype.AccountTypeListSearchRequest;
import cn.com.glsx.merchants.request.accounttype.AccountTypeUpdateRequest; import cn.com.glsx.merchants.request.accounttype.AccountTypeUpdateRequest;
import cn.com.glsx.merchants.response.AccountTypeResponse;
import cn.com.glsx.merchants.response.FunctionRelationResponse;
import cn.com.glsx.merchants.response.ProductRelationResponse;
import cn.com.glsx.merchants.util.Pagination; import cn.com.glsx.merchants.util.Pagination;
import com.github.dozermapper.core.Mapper; import com.github.dozermapper.core.Mapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -25,6 +29,8 @@ import org.springframework.stereotype.Service; ...@@ -25,6 +29,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author zhouhaibao * @author zhouhaibao
...@@ -48,10 +54,13 @@ public class MerchantAccountTypeService { ...@@ -48,10 +54,13 @@ public class MerchantAccountTypeService {
* @param id * @param id
* @return * @return
*/ */
public MerchantAccountTypeResponse getAccountTypeDetail(Integer id) { public AccountTypeResponse getAccountTypeDetail(Integer id) {
RpcResponse<MerchantAccountTypeResponse> response = accountTypeRemote.getByIdRemote(id); RpcResponse<MerchantAccountTypeResponse> response = accountTypeRemote.getByIdRemote(id);
if(response.isSuccess()){ if(response.isSuccess()){
return response.getResult(); AccountTypeResponse accountTypeResponse = new AccountTypeResponse();
dozerMapper.map(response.getResult(), accountTypeResponse);
this.responseDataTransfer(accountTypeResponse, response.getResult().getFunctionList());
return accountTypeResponse;
} }
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
} }
...@@ -141,6 +150,43 @@ public class MerchantAccountTypeService { ...@@ -141,6 +150,43 @@ public class MerchantAccountTypeService {
throw new RpcServiceException(response.getException().getErrId(),response.getMessage()); throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
} }
/**
* 响应返回给前端数据转换
* @param response
* @param functionList
*/
private void responseDataTransfer(AccountTypeResponse response, List<AccountFunctionRelationResponse> functionList){
if(CollectionUtils.isEmpty(functionList)){
return;
}
//根据产品id分组
Map<Integer, List<AccountFunctionRelationResponse>> map =
functionList.stream().collect(Collectors.groupingBy(AccountFunctionRelationResponse::getProductId));
List<ProductRelationResponse> responseList = new ArrayList<>();
for(Integer key : map.keySet()){
ProductRelationResponse relationResponse = new ProductRelationResponse();
relationResponse.setProductId(key);
List<AccountFunctionRelationResponse> list = map.get(key);
List<Integer> menuList = new ArrayList<>();
List<FunctionRelationResponse> functionIdList = new ArrayList<>();
list.stream().forEach(index ->{
if(index.getFunctionId() != null && index.getFunctionId() > 0){
FunctionRelationResponse function = new FunctionRelationResponse();
function.setMenuId(index.getMenuId());
function.setId(index.getFunctionId());
function.setFunctionValue(index.getFunctionValue());
functionIdList.add(function);
} else{
menuList.add(index.getMenuId());
}
});
relationResponse.setMenuIdList(menuList);
relationResponse.setFunctionIdList(functionIdList);
responseList.add(relationResponse);
}
response.setResponseList(responseList);
}
/** /**
* 保存数据转换 * 保存数据转换
......
...@@ -9,10 +9,16 @@ import cn.com.glsx.merchants.model.request.MerchantRoleRequest; ...@@ -9,10 +9,16 @@ import cn.com.glsx.merchants.model.request.MerchantRoleRequest;
import cn.com.glsx.merchants.model.request.RoleAccountRelationRequest; import cn.com.glsx.merchants.model.request.RoleAccountRelationRequest;
import cn.com.glsx.merchants.model.request.RoleFunctionRelationRequest; import cn.com.glsx.merchants.model.request.RoleFunctionRelationRequest;
import cn.com.glsx.merchants.model.response.MerchantRoleResponse; import cn.com.glsx.merchants.model.response.MerchantRoleResponse;
import cn.com.glsx.merchants.model.response.RoleAccountRelationResponse;
import cn.com.glsx.merchants.model.response.RoleFunctionRelationResponse;
import cn.com.glsx.merchants.remote.MerchantRoleRemote; import cn.com.glsx.merchants.remote.MerchantRoleRemote;
import cn.com.glsx.merchants.request.FunctionRequest; import cn.com.glsx.merchants.request.FunctionRequest;
import cn.com.glsx.merchants.request.ProductRequest; import cn.com.glsx.merchants.request.ProductRequest;
import cn.com.glsx.merchants.request.role.*; import cn.com.glsx.merchants.request.role.*;
import cn.com.glsx.merchants.response.FunctionRelationResponse;
import cn.com.glsx.merchants.response.ProductRelationResponse;
import cn.com.glsx.merchants.response.RoleAccountTypeResponse;
import cn.com.glsx.merchants.response.RoleResponse;
import cn.com.glsx.merchants.util.Pagination; import cn.com.glsx.merchants.util.Pagination;
import com.github.dozermapper.core.Mapper; import com.github.dozermapper.core.Mapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -23,6 +29,8 @@ import org.springframework.stereotype.Service; ...@@ -23,6 +29,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author zhouhaibao * @author zhouhaibao
...@@ -46,15 +54,68 @@ public class MerchantRoleService { ...@@ -46,15 +54,68 @@ public class MerchantRoleService {
* @param id * @param id
* @return * @return
*/ */
public MerchantRoleResponse 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()){
return response.getResult(); RoleResponse roleResponse = new RoleResponse();
dozerMapper.map(response.getResult(), roleResponse);
this.responseDataTransfer(roleResponse, response.getResult().getAccountList());
} }
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)){
return;
}
List<RoleAccountTypeResponse> responseList = new ArrayList<>();
for (RoleAccountRelationResponse accountRelationResponse : accountList) {
//角色与账户类型关系数据封装
RoleAccountTypeResponse roleAccountType = new RoleAccountTypeResponse();
roleAccountType.setAccounttypeId(accountRelationResponse.getAccounttypeId()); //账户类型id封装
//角色与账户类型子级关系数据封装
List<RoleFunctionRelationResponse> functionList = accountRelationResponse.getFunctionList();
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()){
ProductRelationResponse relationResponse = new ProductRelationResponse();
relationResponse.setProductId(key); //产品id
List<RoleFunctionRelationResponse> list = functionMap.get(key);
List<Integer> menuList = new ArrayList<>();
List<FunctionRelationResponse> functionIdList = new ArrayList<>();
list.stream().forEach(index ->{
//功能封装
if(index.getFuncitonId() != null && index.getFuncitonId() > 0){
FunctionRelationResponse function = new FunctionRelationResponse();
function.setMenuId(index.getMenuId());
function.setId(index.getFuncitonId());
function.setFunctionValue(index.getFunctionValue());
functionIdList.add(function);
} else{ //菜单封装
menuList.add(index.getMenuId());
}
});
relationResponse.setMenuIdList(menuList);
relationResponse.setFunctionIdList(functionIdList);
productList.add(relationResponse); //子级菜单数据set
}
roleAccountType.setProductList(productList); //逐级封装返回
}
responseList.add(roleAccountType);
}
roleResponse.setResponseList(responseList);
}
/**
* 获取角色管理分页数据 * 获取角色管理分页数据
* *
* @param request * @param request
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!