CRM-客户: 完善一些 TODO

This commit is contained in:
puhui999 2024-01-06 15:28:10 +08:00
parent 3170e7fd97
commit 68f5edaa88
7 changed files with 53 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
/** /**
@ -121,4 +122,8 @@ public class LocalDateTimeUtils {
return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
} }
public static Long between(LocalDateTime dateTime) {
return LocalDateTimeUtil.between(dateTime, LocalDateTime.now(), ChronoUnit.DAYS);
}
} }

View File

@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@ -35,8 +38,7 @@ import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE; import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE;
@ -49,7 +51,8 @@ public class CrmCustomerController {
@Resource @Resource
private CrmCustomerService customerService; private CrmCustomerService customerService;
@Resource
private CrmCustomerPoolConfigService customerPoolConfigService;
@Resource @Resource
private DeptApi deptApi; private DeptApi deptApi;
@Resource @Resource
@ -109,11 +112,28 @@ public class CrmCustomerController {
} }
// 2. 拼接数据 // 2. 拼接数据
// TODO @puhui999距离进入公海的时间 // 距离进入公海的时间
Map<Long, Long> poolDayMap = getPoolDayMap(pageResult);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId()))); convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap)); return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
}
private Map<Long, Long> getPoolDayMap(PageResult<CrmCustomerDO> pageResult) {
Map<Long, Long> poolDayMap = null;
CrmCustomerPoolConfigDO customerPoolConfig = customerPoolConfigService.getCustomerPoolConfig();
if (customerPoolConfig != null && customerPoolConfig.getEnabled()) { // 有公海配置的情况
poolDayMap = convertMap(pageResult.getList(), CrmCustomerDO::getId, item -> {
long dealExpireDay = 0;
if (!item.getDealStatus()) { // 检查是否成交
dealExpireDay = customerPoolConfig.getDealExpireDays() - LocalDateTimeUtils.between(item.getCreateTime());
}
long contactExpireDay = customerPoolConfig.getContactExpireDays() - LocalDateTimeUtils.between(item.getContactLastTime());
return dealExpireDay == 0 ? contactExpireDay : Math.min(dealExpireDay, contactExpireDay);
});
}
return poolDayMap;
} }
@GetMapping(value = "/list-all-simple") @GetMapping(value = "/list-all-simple")

View File

@ -132,4 +132,7 @@ public class CrmCustomerRespVO {
@ExcelProperty("创建人名字") @ExcelProperty("创建人名字")
private String creatorName; private String creatorName;
@Schema(description = "距离加入公海时间", example = "1")
private Long poolDay;
} }

View File

@ -103,7 +103,6 @@ public class CrmPermissionController {
// 拼接数据 // 拼接数据
List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId)); List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId)); Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
// TODO @puhui999可能 postIds 为空的时候会导致报错看看怎么 fix
Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream); Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream);
Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds); Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds);
return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap)); return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap));

View File

@ -38,9 +38,9 @@ public interface CrmCustomerConvert {
/** /**
* 设置用户信息 * 设置用户信息
* *
* @param customer CRM 客户 Response VO * @param customer CRM 客户 Response VO
* @param userMap 用户信息 map * @param userMap 用户信息 map
* @param deptMap 用户部门信息 map * @param deptMap 用户部门信息 map
*/ */
static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) { static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
customer.setAreaName(AreaUtils.format(customer.getAreaId())); customer.setAreaName(AreaUtils.format(customer.getAreaId()));
@ -66,9 +66,12 @@ public interface CrmCustomerConvert {
} }
default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap, default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) { Map<Long, DeptRespDTO> deptMap, Map<Long, Long> poolDayMap) {
PageResult<CrmCustomerRespVO> result = convertPage(pageResult); PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
result.getList().forEach(item -> setUserInfo(item, userMap, deptMap)); result.getList().forEach(item -> {
setUserInfo(item, userMap, deptMap);
findAndThen(poolDayMap, item.getId(), item::setPoolDay);
});
return result; return result;
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.convert.permission; package cn.iocoder.yudao.module.crm.convert.permission;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,6 +52,10 @@ public interface CrmPermissionConvert {
item.setDeptName(deptRespDTO.getName()); item.setDeptName(deptRespDTO.getName());
}); });
List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds()); List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
if (CollUtil.isEmpty(postRespList)) {
item.setPostNames(Collections.emptySet());
return;
}
item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName)); item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName));
}); });
return item; return item;

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.system.api.dept; package cn.iocoder.yudao.module.system.api.dept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
@ -26,6 +28,10 @@ public interface PostApi {
List<PostRespDTO> getPostList(Collection<Long> ids); List<PostRespDTO> getPostList(Collection<Long> ids);
default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) { default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return MapUtil.empty();
}
List<PostRespDTO> list = getPostList(ids); List<PostRespDTO> list = getPostList(ids);
return CollectionUtils.convertMap(list, PostRespDTO::getId); return CollectionUtils.convertMap(list, PostRespDTO::getId);
} }