优化这段代码 private GroupMemberResp setmenberResp(CustomerGroupMember member){ GroupMemberResp resp=new GroupMemberResp(); BeanUtil.copyProperties(member,resp); List<CustomerGroupMember> memberSize=iCustomerGroupMemberService.queryGroupMembersinfo(member.getUserId()); resp.setgroupcount(memberSize.size()); List<String> chatIdList=memberSize.stream().map(t->t.getChatId()).collect(Collectors.toList()); List<CustomerGroup> groupList=getGroupListByChatId(chatIdList); List<String> groupNameList=groupList.stream().map(t->t.getChatIName()).collect(Collectors.toList()); resp.setgroupName(groupNameList.toString().replace(“,”,”|”)); if(member.getMemberType()==1){ EmployeeOrgConfig orgConfig=employeeOrgConfigService.getEmployeeOrgConfig(member.getUserId()); if(orgConfig!=null){ resp.setMobile(orgConfig.getMobile()); resp.setIdCard(orgConfig.getIdCard()); } }else{ Customer customer=customerService.getCustomer(member.getUserId()); if(customer!=null){ resp.setMobile(customer.getMobile()); resp.setIdCard(customer.getIdCard());. resp.setStatus(customer.getStatus()); } } Return resp; }
时间: 2024-04-19 21:26:24 浏览: 77
resp-2022.1.0.0.exe
优化后的代码如下:
private GroupMemberResp setMemberResp(CustomerGroupMember member) {
GroupMemberResp resp = new GroupMemberResp();
BeanUtil.copyProperties(member, resp);
List<CustomerGroupMember> memberSize = iCustomerGroupMemberService.queryGroupMembersinfo(member.getUserId());
resp.setGroupCount(memberSize.size());
List<String> chatIdList = memberSize.stream().map(CustomerGroupMember::getChatId).collect(Collectors.toList());
List<CustomerGroup> groupList = getGroupListByChatId(chatIdList);
List<String> groupNameList = groupList.stream().map(CustomerGroup::getChatIName).collect(Collectors.toList());
resp.setGroupName(String.join("|", groupNameList));
if (member.getMemberType() == 1) {
EmployeeOrgConfig orgConfig = employeeOrgConfigService.getEmployeeOrgConfig(member.getUserId());
if (orgConfig != null) {
resp.setMobile(orgConfig.getMobile());
resp.setIdCard(orgConfig.getIdCard());
}
} else {
Customer customer = customerService.getCustomer(member.getUserId());
if (customer != null) {
resp.setMobile(customer.getMobile());
resp.setIdCard(customer.getIdCard());
resp.setStatus(customer.getStatus());
}
}
return resp;
}
阅读全文