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 +6,7 @@ import java.time.Duration; | ||
| 6 | import java.time.LocalDate; | 6 | import java.time.LocalDate; |
| 7 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 8 | import java.time.LocalTime; | 8 | import java.time.LocalTime; |
| 9 | +import java.time.temporal.ChronoUnit; | ||
| 9 | import java.time.temporal.TemporalAdjusters; | 10 | import java.time.temporal.TemporalAdjusters; |
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| @@ -121,4 +122,8 @@ public class LocalDateTimeUtils { | @@ -121,4 +122,8 @@ public class LocalDateTimeUtils { | ||
| 121 | return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); | 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,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | ||
| 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | 10 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 10 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; | 11 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 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 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | 15 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 13 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 16 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 14 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; | 17 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| @@ -35,8 +38,7 @@ import java.util.stream.Stream; | @@ -35,8 +38,7 @@ import java.util.stream.Stream; | ||
| 35 | 38 | ||
| 36 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 39 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 37 | import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; | 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 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 42 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 41 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 43 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 42 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE; | 44 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE; |
| @@ -49,7 +51,8 @@ public class CrmCustomerController { | @@ -49,7 +51,8 @@ public class CrmCustomerController { | ||
| 49 | 51 | ||
| 50 | @Resource | 52 | @Resource |
| 51 | private CrmCustomerService customerService; | 53 | private CrmCustomerService customerService; |
| 52 | - | 54 | + @Resource |
| 55 | + private CrmCustomerPoolConfigService customerPoolConfigService; | ||
| 53 | @Resource | 56 | @Resource |
| 54 | private DeptApi deptApi; | 57 | private DeptApi deptApi; |
| 55 | @Resource | 58 | @Resource |
| @@ -109,11 +112,28 @@ public class CrmCustomerController { | @@ -109,11 +112,28 @@ public class CrmCustomerController { | ||
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | // 2. 拼接数据 | 114 | // 2. 拼接数据 |
| 112 | - // TODO @puhui999:距离进入公海的时间 | 115 | + // 距离进入公海的时间 |
| 116 | + Map<Long, Long> poolDayMap = getPoolDayMap(pageResult); | ||
| 113 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | 117 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( |
| 114 | convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId()))); | 118 | convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId()))); |
| 115 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); | 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 | @GetMapping(value = "/list-all-simple") | 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
| @@ -132,4 +132,7 @@ public class CrmCustomerRespVO { | @@ -132,4 +132,7 @@ public class CrmCustomerRespVO { | ||
| 132 | @ExcelProperty("创建人名字") | 132 | @ExcelProperty("创建人名字") |
| 133 | private String creatorName; | 133 | private String creatorName; |
| 134 | 134 | ||
| 135 | + @Schema(description = "距离加入公海时间", example = "1") | ||
| 136 | + private Long poolDay; | ||
| 137 | + | ||
| 135 | } | 138 | } |
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,7 +103,6 @@ public class CrmPermissionController { | ||
| 103 | // 拼接数据 | 103 | // 拼接数据 |
| 104 | List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId)); | 104 | List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId)); |
| 105 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId)); | 105 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId)); |
| 106 | - // TODO @puhui999:可能 postIds 为空的时候,会导致报错,看看怎么 fix 下 | ||
| 107 | Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream); | 106 | Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream); |
| 108 | Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds); | 107 | Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds); |
| 109 | return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap)); | 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,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 | static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) { | 45 | static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) { |
| 46 | customer.setAreaName(AreaUtils.format(customer.getAreaId())); | 46 | customer.setAreaName(AreaUtils.format(customer.getAreaId())); |
| @@ -66,9 +66,12 @@ public interface CrmCustomerConvert { | @@ -66,9 +66,12 @@ public interface CrmCustomerConvert { | ||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap, | 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 | PageResult<CrmCustomerRespVO> result = convertPage(pageResult); | 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 | return result; | 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 | package cn.iocoder.yudao.module.crm.convert.permission; | 1 | package cn.iocoder.yudao.module.crm.convert.permission; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 4 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO; |
| @@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps; | @@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps; | ||
| 15 | import org.mapstruct.Mapper; | 16 | import org.mapstruct.Mapper; |
| 16 | import org.mapstruct.factory.Mappers; | 17 | import org.mapstruct.factory.Mappers; |
| 17 | 18 | ||
| 19 | +import java.util.Collections; | ||
| 18 | import java.util.List; | 20 | import java.util.List; |
| 19 | import java.util.Map; | 21 | import java.util.Map; |
| 20 | 22 | ||
| @@ -50,6 +52,10 @@ public interface CrmPermissionConvert { | @@ -50,6 +52,10 @@ public interface CrmPermissionConvert { | ||
| 50 | item.setDeptName(deptRespDTO.getName()); | 52 | item.setDeptName(deptRespDTO.getName()); |
| 51 | }); | 53 | }); |
| 52 | List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds()); | 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 | item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName)); | 59 | item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName)); |
| 54 | }); | 60 | }); |
| 55 | return item; | 61 | return item; |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java
| 1 | package cn.iocoder.yudao.module.system.api.dept; | 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 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 4 | import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; | 6 | import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; |
| 5 | 7 | ||
| @@ -26,6 +28,10 @@ public interface PostApi { | @@ -26,6 +28,10 @@ public interface PostApi { | ||
| 26 | List<PostRespDTO> getPostList(Collection<Long> ids); | 28 | List<PostRespDTO> getPostList(Collection<Long> ids); |
| 27 | 29 | ||
| 28 | default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) { | 30 | default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) { |
| 31 | + if (CollUtil.isEmpty(ids)) { | ||
| 32 | + return MapUtil.empty(); | ||
| 33 | + } | ||
| 34 | + | ||
| 29 | List<PostRespDTO> list = getPostList(ids); | 35 | List<PostRespDTO> list = getPostList(ids); |
| 30 | return CollectionUtils.convertMap(list, PostRespDTO::getId); | 36 | return CollectionUtils.convertMap(list, PostRespDTO::getId); |
| 31 | } | 37 | } |