Commit a24919e55506bf5cdf98d40563a31fecfe04892d
1 parent
ecf72896
style: 客户 review 修改
Showing
2 changed files
with
27 additions
and
17 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| @@ -5,6 +5,8 @@ import cn.hutool.core.util.NumberUtil; | @@ -5,6 +5,8 @@ import cn.hutool.core.util.NumberUtil; | ||
| 5 | import cn.hutool.core.util.ObjectUtil; | 5 | import cn.hutool.core.util.ObjectUtil; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 9 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 10 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 9 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; | 11 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 10 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 12 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| @@ -101,25 +103,10 @@ public class CrmCustomerController { | @@ -101,25 +103,10 @@ public class CrmCustomerController { | ||
| 101 | @PreAuthorize("@ss.hasPermission('crm:customer:query')") | 103 | @PreAuthorize("@ss.hasPermission('crm:customer:query')") |
| 102 | public CommonResult<PageResult<CrmCustomerRespVO>> getCustomerPage(@Valid CrmCustomerPageReqVO pageVO) { | 104 | public CommonResult<PageResult<CrmCustomerRespVO>> getCustomerPage(@Valid CrmCustomerPageReqVO pageVO) { |
| 103 | PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(pageVO); | 105 | PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(pageVO); |
| 104 | - PageResult<CrmCustomerRespVO> pageVo = CrmCustomerConvert.INSTANCE.convertPage(pageResult); | ||
| 105 | - // TODO @wanwan: 可以参考 CollectionUtils.convertListByFlatMap(),目的是简洁 | ||
| 106 | - Set<Long> userSet = pageVo.getList().stream().flatMap(i -> Stream.of(NumberUtil.parseLong(i.getCreator()), i.getOwnerUserId())).collect(Collectors.toSet()); | 106 | + Set<Long> userSet = CollectionUtils.convertSetByFlatMap(pageResult.getList(), i -> Stream.of(NumberUtil.parseLong(i.getCreator()), i.getOwnerUserId())); |
| 107 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userSet); | 107 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userSet); |
| 108 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(userMap.values().stream().map(AdminUserRespDTO::getDeptId).collect(Collectors.toSet())); | 108 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(userMap.values().stream().map(AdminUserRespDTO::getDeptId).collect(Collectors.toSet())); |
| 109 | - // TODO @wanwan:这块可以形成一个 convertPage 方法,default 实现; | ||
| 110 | - pageVo.getList().forEach(customerRespVO -> { | ||
| 111 | - customerRespVO.setAreaName(AreaUtils.format(customerRespVO.getAreaId())); | ||
| 112 | - customerRespVO.setCreatorName(Optional.ofNullable(userMap.get(NumberUtil.parseLong(customerRespVO.getCreator()))).map(AdminUserRespDTO::getNickname).orElse(null)); | ||
| 113 | - // TODO @wanwan:可以使用 MapUtils.findAndThen | ||
| 114 | - AdminUserRespDTO ownerUser = userMap.get(customerRespVO.getOwnerUserId()); | ||
| 115 | - if (Objects.nonNull(ownerUser)) { | ||
| 116 | - customerRespVO.setOwnerUserName(ownerUser.getNickname()); | ||
| 117 | - DeptRespDTO dept = deptMap.get(ownerUser.getDeptId()); | ||
| 118 | - if (Objects.nonNull(dept)) { | ||
| 119 | - customerRespVO.setOwnerUserDept(dept.getName()); | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | - }); | 109 | + PageResult<CrmCustomerRespVO> pageVo = CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap); |
| 123 | return success(pageVo); | 110 | return success(pageVo); |
| 124 | } | 111 | } |
| 125 | 112 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
| 1 | package cn.iocoder.yudao.module.crm.convert.customer; | 1 | package cn.iocoder.yudao.module.crm.convert.customer; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.NumberUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 6 | +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; | ||
| 4 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 6 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmTransferPermissionReqBO; | 9 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmTransferPermissionReqBO; |
| 10 | +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; | ||
| 11 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 7 | import org.mapstruct.Mapper; | 12 | import org.mapstruct.Mapper; |
| 8 | import org.mapstruct.Mapping; | 13 | import org.mapstruct.Mapping; |
| 9 | import org.mapstruct.Mappings; | 14 | import org.mapstruct.Mappings; |
| 10 | import org.mapstruct.factory.Mappers; | 15 | import org.mapstruct.factory.Mappers; |
| 11 | 16 | ||
| 12 | import java.util.List; | 17 | import java.util.List; |
| 18 | +import java.util.Map; | ||
| 19 | +import java.util.Objects; | ||
| 20 | +import java.util.Optional; | ||
| 13 | 21 | ||
| 14 | /** | 22 | /** |
| 15 | * 客户 Convert | 23 | * 客户 Convert |
| @@ -29,6 +37,21 @@ public interface CrmCustomerConvert { | @@ -29,6 +37,21 @@ public interface CrmCustomerConvert { | ||
| 29 | 37 | ||
| 30 | PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page); | 38 | PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page); |
| 31 | 39 | ||
| 40 | + default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) { | ||
| 41 | + PageResult<CrmCustomerRespVO> result = convertPage(page); | ||
| 42 | + result.getList().forEach(customerRespVO -> { | ||
| 43 | + customerRespVO.setAreaName(AreaUtils.format(customerRespVO.getAreaId())); | ||
| 44 | + MapUtils.findAndThen(userMap, NumberUtil.parseLong(customerRespVO.getCreator()), creator -> | ||
| 45 | + customerRespVO.setCreatorName(creator.getNickname())); | ||
| 46 | + MapUtils.findAndThen(userMap, customerRespVO.getOwnerUserId(), ownerUser -> { | ||
| 47 | + customerRespVO.setOwnerUserName(ownerUser.getNickname()); | ||
| 48 | + MapUtils.findAndThen(deptMap, ownerUser.getDeptId(), dept -> | ||
| 49 | + customerRespVO.setOwnerUserDept(dept.getName())); | ||
| 50 | + }); | ||
| 51 | + }); | ||
| 52 | + return result; | ||
| 53 | + } | ||
| 54 | + | ||
| 32 | List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list); | 55 | List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list); |
| 33 | 56 | ||
| 34 | @Mappings({ | 57 | @Mappings({ |