style: 客户 review 修改

This commit is contained in:
Wanwan 2023-11-06 21:59:23 +08:00
parent ecf728966f
commit a24919e555
2 changed files with 27 additions and 17 deletions

View File

@ -5,6 +5,8 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
@ -101,25 +103,10 @@ public class CrmCustomerController {
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
public CommonResult<PageResult<CrmCustomerRespVO>> getCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(pageVO);
PageResult<CrmCustomerRespVO> pageVo = CrmCustomerConvert.INSTANCE.convertPage(pageResult);
// TODO @wanwan 可以参考 CollectionUtils.convertListByFlatMap()目的是简洁
Set<Long> userSet = pageVo.getList().stream().flatMap(i -> Stream.of(NumberUtil.parseLong(i.getCreator()), i.getOwnerUserId())).collect(Collectors.toSet());
Set<Long> userSet = CollectionUtils.convertSetByFlatMap(pageResult.getList(), i -> Stream.of(NumberUtil.parseLong(i.getCreator()), i.getOwnerUserId()));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userSet);
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(userMap.values().stream().map(AdminUserRespDTO::getDeptId).collect(Collectors.toSet()));
// TODO @wanwan这块可以形成一个 convertPage 方法default 实现
pageVo.getList().forEach(customerRespVO -> {
customerRespVO.setAreaName(AreaUtils.format(customerRespVO.getAreaId()));
customerRespVO.setCreatorName(Optional.ofNullable(userMap.get(NumberUtil.parseLong(customerRespVO.getCreator()))).map(AdminUserRespDTO::getNickname).orElse(null));
// TODO @wanwan可以使用 MapUtils.findAndThen
AdminUserRespDTO ownerUser = userMap.get(customerRespVO.getOwnerUserId());
if (Objects.nonNull(ownerUser)) {
customerRespVO.setOwnerUserName(ownerUser.getNickname());
DeptRespDTO dept = deptMap.get(ownerUser.getDeptId());
if (Objects.nonNull(dept)) {
customerRespVO.setOwnerUserDept(dept.getName());
}
}
});
PageResult<CrmCustomerRespVO> pageVo = CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap);
return success(pageVo);
}

View File

@ -1,15 +1,23 @@
package cn.iocoder.yudao.module.crm.convert.customer;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmTransferPermissionReqBO;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* 客户 Convert
@ -29,6 +37,21 @@ public interface CrmCustomerConvert {
PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page);
default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
PageResult<CrmCustomerRespVO> result = convertPage(page);
result.getList().forEach(customerRespVO -> {
customerRespVO.setAreaName(AreaUtils.format(customerRespVO.getAreaId()));
MapUtils.findAndThen(userMap, NumberUtil.parseLong(customerRespVO.getCreator()), creator ->
customerRespVO.setCreatorName(creator.getNickname()));
MapUtils.findAndThen(userMap, customerRespVO.getOwnerUserId(), ownerUser -> {
customerRespVO.setOwnerUserName(ownerUser.getNickname());
MapUtils.findAndThen(deptMap, ownerUser.getDeptId(), dept ->
customerRespVO.setOwnerUserDept(dept.getName()));
});
});
return result;
}
List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
@Mappings({