Commit 68f5edaa88907e8e68abbfd066aa4f43050f2a71
1 parent
3170e7fd
CRM-客户: 完善一些 TODO
Showing
7 changed files
with
53 additions
and
11 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| ... | ... | @@ -6,6 +6,7 @@ import java.time.Duration; |
| 6 | 6 | import java.time.LocalDate; |
| 7 | 7 | import java.time.LocalDateTime; |
| 8 | 8 | import java.time.LocalTime; |
| 9 | +import java.time.temporal.ChronoUnit; | |
| 9 | 10 | import java.time.temporal.TemporalAdjusters; |
| 10 | 11 | |
| 11 | 12 | /** |
| ... | ... | @@ -121,4 +122,8 @@ public class LocalDateTimeUtils { |
| 121 | 122 | return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); |
| 122 | 123 | } |
| 123 | 124 | |
| 125 | + public static Long between(LocalDateTime dateTime) { | |
| 126 | + return LocalDateTimeUtil.between(dateTime, LocalDateTime.now(), ChronoUnit.DAYS); | |
| 127 | + } | |
| 128 | + | |
| 124 | 129 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| ... | ... | @@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | 10 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 10 | 11 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 11 | 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 13 | +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO; | |
| 14 | +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService; | |
| 12 | 15 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 13 | 16 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 14 | 17 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| ... | ... | @@ -35,8 +38,7 @@ import java.util.stream.Stream; |
| 35 | 38 | |
| 36 | 39 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 37 | 40 | import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; |
| 38 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 39 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; | |
| 41 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 40 | 42 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 41 | 43 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 42 | 44 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE; |
| ... | ... | @@ -49,7 +51,8 @@ public class CrmCustomerController { |
| 49 | 51 | |
| 50 | 52 | @Resource |
| 51 | 53 | private CrmCustomerService customerService; |
| 52 | - | |
| 54 | + @Resource | |
| 55 | + private CrmCustomerPoolConfigService customerPoolConfigService; | |
| 53 | 56 | @Resource |
| 54 | 57 | private DeptApi deptApi; |
| 55 | 58 | @Resource |
| ... | ... | @@ -109,11 +112,28 @@ public class CrmCustomerController { |
| 109 | 112 | } |
| 110 | 113 | |
| 111 | 114 | // 2. 拼接数据 |
| 112 | - // TODO @puhui999:距离进入公海的时间 | |
| 115 | + // 距离进入公海的时间 | |
| 116 | + Map<Long, Long> poolDayMap = getPoolDayMap(pageResult); | |
| 113 | 117 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( |
| 114 | 118 | convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId()))); |
| 115 | 119 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); |
| 116 | - return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap)); | |
| 120 | + return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap)); | |
| 121 | + } | |
| 122 | + | |
| 123 | + private Map<Long, Long> getPoolDayMap(PageResult<CrmCustomerDO> pageResult) { | |
| 124 | + Map<Long, Long> poolDayMap = null; | |
| 125 | + CrmCustomerPoolConfigDO customerPoolConfig = customerPoolConfigService.getCustomerPoolConfig(); | |
| 126 | + if (customerPoolConfig != null && customerPoolConfig.getEnabled()) { // 有公海配置的情况 | |
| 127 | + poolDayMap = convertMap(pageResult.getList(), CrmCustomerDO::getId, item -> { | |
| 128 | + long dealExpireDay = 0; | |
| 129 | + if (!item.getDealStatus()) { // 检查是否成交 | |
| 130 | + dealExpireDay = customerPoolConfig.getDealExpireDays() - LocalDateTimeUtils.between(item.getCreateTime()); | |
| 131 | + } | |
| 132 | + long contactExpireDay = customerPoolConfig.getContactExpireDays() - LocalDateTimeUtils.between(item.getContactLastTime()); | |
| 133 | + return dealExpireDay == 0 ? contactExpireDay : Math.min(dealExpireDay, contactExpireDay); | |
| 134 | + }); | |
| 135 | + } | |
| 136 | + return poolDayMap; | |
| 117 | 137 | } |
| 118 | 138 | |
| 119 | 139 | @GetMapping(value = "/list-all-simple") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerRespVO.java
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java
| ... | ... | @@ -103,7 +103,6 @@ public class CrmPermissionController { |
| 103 | 103 | // 拼接数据 |
| 104 | 104 | List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId)); |
| 105 | 105 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId)); |
| 106 | - // TODO @puhui999:可能 postIds 为空的时候,会导致报错,看看怎么 fix 下 | |
| 107 | 106 | Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream); |
| 108 | 107 | Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds); |
| 109 | 108 | return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap)); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
| ... | ... | @@ -38,9 +38,9 @@ public interface CrmCustomerConvert { |
| 38 | 38 | /** |
| 39 | 39 | * 设置用户信息 |
| 40 | 40 | * |
| 41 | - * @param customer CRM 客户 Response VO | |
| 42 | - * @param userMap 用户信息 map | |
| 43 | - * @param deptMap 用户部门信息 map | |
| 41 | + * @param customer CRM 客户 Response VO | |
| 42 | + * @param userMap 用户信息 map | |
| 43 | + * @param deptMap 用户部门信息 map | |
| 44 | 44 | */ |
| 45 | 45 | static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) { |
| 46 | 46 | customer.setAreaName(AreaUtils.format(customer.getAreaId())); |
| ... | ... | @@ -66,9 +66,12 @@ public interface CrmCustomerConvert { |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap, |
| 69 | - Map<Long, DeptRespDTO> deptMap) { | |
| 69 | + Map<Long, DeptRespDTO> deptMap, Map<Long, Long> poolDayMap) { | |
| 70 | 70 | PageResult<CrmCustomerRespVO> result = convertPage(pageResult); |
| 71 | - result.getList().forEach(item -> setUserInfo(item, userMap, deptMap)); | |
| 71 | + result.getList().forEach(item -> { | |
| 72 | + setUserInfo(item, userMap, deptMap); | |
| 73 | + findAndThen(poolDayMap, item.getId(), item::setPoolDay); | |
| 74 | + }); | |
| 72 | 75 | return result; |
| 73 | 76 | } |
| 74 | 77 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.convert.permission; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO; |
| ... | ... | @@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps; |
| 15 | 16 | import org.mapstruct.Mapper; |
| 16 | 17 | import org.mapstruct.factory.Mappers; |
| 17 | 18 | |
| 19 | +import java.util.Collections; | |
| 18 | 20 | import java.util.List; |
| 19 | 21 | import java.util.Map; |
| 20 | 22 | |
| ... | ... | @@ -50,6 +52,10 @@ public interface CrmPermissionConvert { |
| 50 | 52 | item.setDeptName(deptRespDTO.getName()); |
| 51 | 53 | }); |
| 52 | 54 | List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds()); |
| 55 | + if (CollUtil.isEmpty(postRespList)) { | |
| 56 | + item.setPostNames(Collections.emptySet()); | |
| 57 | + return; | |
| 58 | + } | |
| 53 | 59 | item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName)); |
| 54 | 60 | }); |
| 55 | 61 | return item; | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.dept; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.map.MapUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 4 | 6 | import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; |
| 5 | 7 | |
| ... | ... | @@ -26,6 +28,10 @@ public interface PostApi { |
| 26 | 28 | List<PostRespDTO> getPostList(Collection<Long> ids); |
| 27 | 29 | |
| 28 | 30 | default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) { |
| 31 | + if (CollUtil.isEmpty(ids)) { | |
| 32 | + return MapUtil.empty(); | |
| 33 | + } | |
| 34 | + | |
| 29 | 35 | List<PostRespDTO> list = getPostList(ids); |
| 30 | 36 | return CollectionUtils.convertMap(list, PostRespDTO::getId); |
| 31 | 37 | } | ... | ... |