mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
CRM-客户:完善客户详情、分页、公海数据获取
This commit is contained in:
parent
668fae9398
commit
c8ed99a5a4
@ -1,22 +1,21 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.customer;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
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.convert.customer.CrmCustomerConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
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.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -28,11 +27,14 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@ -48,6 +50,8 @@ public class CrmCustomerController {
|
||||
private DeptApi deptApi;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户")
|
||||
@ -78,49 +82,57 @@ public class CrmCustomerController {
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
|
||||
public CommonResult<CrmCustomerRespVO> getCustomer(@RequestParam("id") Long id) {
|
||||
// 1. 获取客户
|
||||
CrmCustomerDO customer = customerService.getCustomer(id);
|
||||
CrmCustomerRespVO customerRespVO = CrmCustomerConvert.INSTANCE.convert(customer);
|
||||
if (ObjectUtil.isAllNotEmpty(customer, customer.getAreaId())) {
|
||||
customerRespVO.setAreaName(AreaUtils.format(customer.getAreaId()));
|
||||
if (customer == null) {
|
||||
return success(null);
|
||||
}
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(NumberUtil.parseLong(customerRespVO.getCreator()), customerRespVO.getOwnerUserId())));
|
||||
customerRespVO.setCreatorName(Optional.ofNullable(userMap.get(NumberUtil.parseLong(customerRespVO.getCreator()))).map(AdminUserRespDTO::getNickname).orElse(null));
|
||||
AdminUserRespDTO ownerUser = userMap.get(customer.getOwnerUserId());
|
||||
if (Objects.nonNull(ownerUser)) {
|
||||
customerRespVO.setOwnerUserName(ownerUser.getNickname());
|
||||
DeptRespDTO dept = deptApi.getDept(ownerUser.getDeptId());
|
||||
if (Objects.nonNull(dept)) {
|
||||
customerRespVO.setOwnerUserDept(dept.getName());
|
||||
}
|
||||
}
|
||||
return success(customerRespVO);
|
||||
|
||||
// 2. 拼接数据
|
||||
// 2.1 获取负责人
|
||||
List<CrmPermissionDO> ownerList = permissionService.getPermissionByBizTypeAndBizIdsAndLevel(
|
||||
CrmBizTypeEnum.CRM_CUSTOMER.getType(), Collections.singletonList(customer.getId()),
|
||||
CrmPermissionLevelEnum.OWNER.getLevel());
|
||||
Map<Long, CrmPermissionDO> ownerMap = convertMap(ownerList, CrmPermissionDO::getBizId);
|
||||
// 2.2 获取负责人详情
|
||||
Set<Long> userIds = convertSet(ownerList, CrmPermissionDO::getUserId);
|
||||
userIds.add(Long.parseLong(customer.getCreator())); // 加入创建者
|
||||
List<AdminUserRespDTO> userList = adminUserApi.getUserList(userIds);
|
||||
Map<Long, AdminUserRespDTO> userMap = convertMap(userList, AdminUserRespDTO::getId);
|
||||
// 2.3 获取部门详情
|
||||
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
|
||||
return success(CrmCustomerConvert.INSTANCE.convert(customer, ownerMap, userMap, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得客户分页")
|
||||
@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());
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
return success(pageVo);
|
||||
return convertPage(customerService.getCustomerPage(pageVO, getLoginUserId()));
|
||||
}
|
||||
|
||||
@GetMapping("/pool-page")
|
||||
@Operation(summary = "获得公海客户分页")
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
|
||||
public CommonResult<PageResult<CrmCustomerRespVO>> getPoolCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
|
||||
return convertPage(customerService.getCustomerPage(pageVO, CrmPermissionDO.POOL_USER_ID));
|
||||
}
|
||||
|
||||
private CommonResult<PageResult<CrmCustomerRespVO>> convertPage(PageResult<CrmCustomerDO> pageResult) {
|
||||
// 2. 拼接数据
|
||||
Set<Long> ids = convertSet(pageResult.getList(), CrmCustomerDO::getId);
|
||||
// 2.1 获取负责人
|
||||
List<CrmPermissionDO> ownerList = permissionService.getPermissionByBizTypeAndBizIdsAndLevel(
|
||||
CrmBizTypeEnum.CRM_CUSTOMER.getType(), ids, CrmPermissionLevelEnum.OWNER.getLevel());
|
||||
Map<Long, CrmPermissionDO> ownerMap = convertMap(ownerList, CrmPermissionDO::getBizId);
|
||||
// 2.2 获取负责人详情
|
||||
Set<Long> userIds = convertSet(ownerList, CrmPermissionDO::getUserId);
|
||||
userIds.addAll(convertSet(pageResult.getList(), item -> Long.parseLong(item.getCreator()))); // 加入创建者
|
||||
List<AdminUserRespDTO> userList = adminUserApi.getUserList(userIds);
|
||||
Map<Long, AdminUserRespDTO> userMap = convertMap(userList, AdminUserRespDTO::getId);
|
||||
// 2.3 获取部门详情
|
||||
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
|
||||
return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, ownerMap, userMap, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
|
@ -33,7 +33,7 @@ public class CrmCustomerRespVO extends CrmCustomerBaseVO {
|
||||
@Schema(description = "负责人名字", example = "25682")
|
||||
private String ownerUserName;
|
||||
@Schema(description = "负责人部门")
|
||||
private String ownerUserDept;
|
||||
private String ownerUserDeptName;
|
||||
|
||||
@Schema(description = "地区名称", example = "北京市")
|
||||
private String areaName;
|
||||
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.crm.convert.business;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionPageReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
@ -38,6 +37,4 @@ public interface CrmBusinessConvert {
|
||||
})
|
||||
CrmPermissionTransferReqBO convert(CrmBusinessTransferReqVO reqVO, Long userId);
|
||||
|
||||
CrmPermissionPageReqBO convert(CrmBusinessPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,22 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.customer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
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 static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
|
||||
/**
|
||||
* 客户 Convert
|
||||
@ -27,7 +34,24 @@ public interface CrmCustomerConvert {
|
||||
|
||||
CrmCustomerRespVO convert(CrmCustomerDO bean);
|
||||
|
||||
PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page);
|
||||
default CrmCustomerRespVO convert(CrmCustomerDO customer, Map<Long, CrmPermissionDO> ownerMap,
|
||||
Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
|
||||
CrmCustomerRespVO customerResp = convert(customer);
|
||||
findAndThen(ownerMap, customerResp.getId(), owner -> {
|
||||
customerResp.setOwnerUserId(owner.getUserId());
|
||||
customerResp.setAreaName(AreaUtils.format(customerResp.getAreaId()));
|
||||
findAndThen(userMap, owner.getUserId(), user -> {
|
||||
customerResp.setOwnerUserName(user.getNickname());
|
||||
});
|
||||
findAndThen(userMap, Long.parseLong(customerResp.getCreator()), user -> {
|
||||
customerResp.setCreatorName(user.getNickname());
|
||||
});
|
||||
findAndThen(deptMap, customerResp.getOwnerUserId(), dept -> {
|
||||
customerResp.setOwnerUserDeptName(dept.getName());
|
||||
});
|
||||
});
|
||||
return customerResp;
|
||||
}
|
||||
|
||||
List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
|
||||
|
||||
@ -37,4 +61,27 @@ public interface CrmCustomerConvert {
|
||||
})
|
||||
CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId);
|
||||
|
||||
PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> page);
|
||||
|
||||
default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, CrmPermissionDO> ownerMap,
|
||||
Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
|
||||
PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
|
||||
result.getList().forEach(item -> {
|
||||
findAndThen(ownerMap, item.getId(), owner -> {
|
||||
item.setOwnerUserId(owner.getUserId());
|
||||
item.setAreaName(AreaUtils.format(item.getAreaId()));
|
||||
findAndThen(userMap, owner.getUserId(), user -> {
|
||||
item.setOwnerUserName(user.getNickname());
|
||||
});
|
||||
findAndThen(userMap, Long.parseLong(item.getCreator()), user -> {
|
||||
item.setCreatorName(user.getNickname());
|
||||
});
|
||||
findAndThen(deptMap, item.getOwnerUserId(), dept -> {
|
||||
item.setOwnerUserDeptName(dept.getName());
|
||||
});
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.dataobject.customer;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@ -49,19 +50,19 @@ public class CrmCustomerDO extends BaseDO {
|
||||
/**
|
||||
* 所属行业
|
||||
*
|
||||
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_CUSTOMER_INDUSTRY}
|
||||
* 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_INDUSTRY}
|
||||
*/
|
||||
private Integer industryId;
|
||||
/**
|
||||
* 客户等级
|
||||
*
|
||||
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_CUSTOMER_LEVEL}
|
||||
* 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_LEVEL}
|
||||
*/
|
||||
private Integer level;
|
||||
/**
|
||||
* 客户来源
|
||||
*
|
||||
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_CUSTOMER_SOURCE}
|
||||
* 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_SOURCE}
|
||||
*/
|
||||
private Integer source;
|
||||
/**
|
||||
@ -96,21 +97,6 @@ public class CrmCustomerDO extends BaseDO {
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 负责人的用户编号
|
||||
*
|
||||
* 关联 AdminUserDO 的 id 字段
|
||||
*/
|
||||
private Long ownerUserId;
|
||||
// TODO @puhui999:这块抽到 permission 里;
|
||||
/**
|
||||
* 只读权限的用户编号数组
|
||||
*/
|
||||
private String roUserIds;
|
||||
/**
|
||||
* 读写权限的用户编号数组
|
||||
*/
|
||||
private String rwUserIds;
|
||||
/**
|
||||
* 地区编号
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.mysql.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO;
|
||||
@ -18,14 +19,14 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> {
|
||||
|
||||
default List<CrmBusinessDO> selectList(CrmBusinessPageReqVO reqVO, Collection<Long> ids) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmBusinessDO>()
|
||||
default PageResult<CrmBusinessDO> selectPage(CrmBusinessPageReqVO reqVO, Collection<Long> ids) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CrmBusinessDO>()
|
||||
.in(CrmBusinessDO::getId, ids)
|
||||
.likeIfPresent(CrmBusinessDO::getName, reqVO.getName())
|
||||
.orderByDesc(CrmBusinessDO::getId));
|
||||
}
|
||||
|
||||
default List<CrmBusinessDO> selectList(CrmBusinessExportReqVO reqVO) {
|
||||
default List<CrmBusinessDO> selectPage(CrmBusinessExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmBusinessDO>()
|
||||
.likeIfPresent(CrmBusinessDO::getName, reqVO.getName())
|
||||
.eqIfPresent(CrmBusinessDO::getStatusTypeId, reqVO.getStatusTypeId())
|
||||
|
@ -3,12 +3,11 @@ package cn.iocoder.yudao.module.crm.dal.mysql.customer;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 客户 Mapper
|
||||
@ -18,21 +17,14 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||
|
||||
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CrmCustomerDO>()
|
||||
.likeIfPresent(CrmCustomerDO::getName, reqVO.getName())
|
||||
.eqIfPresent(CrmCustomerDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(CrmCustomerDO::getIndustryId, reqVO.getIndustryId())
|
||||
.eqIfPresent(CrmCustomerDO::getLevel, reqVO.getLevel())
|
||||
.eqIfPresent(CrmCustomerDO::getSource, reqVO.getSource())
|
||||
.orderByDesc(CrmCustomerDO::getId));
|
||||
}
|
||||
|
||||
default List<CrmCustomerDO> selectList(CrmCustomerExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmCustomerDO>()
|
||||
.likeIfPresent(CrmCustomerDO::getName, reqVO.getName())
|
||||
.eqIfPresent(CrmCustomerDO::getMobile, reqVO.getMobile())
|
||||
.orderByDesc(CrmCustomerDO::getId));
|
||||
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Collection<Long> ids) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<CrmCustomerDO>()
|
||||
.inIfPresent(CrmCustomerDO::getId, ids)
|
||||
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
|
||||
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
|
||||
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
|
||||
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
|
||||
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.mysql.permission;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionPageReqBO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -30,10 +29,17 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
|
||||
.eq(CrmPermissionDO::getBizId, bizId));
|
||||
}
|
||||
|
||||
default PageResult<CrmPermissionDO> selectPage(CrmPermissionPageReqBO pageReqBO) {
|
||||
return selectPage(pageReqBO, new LambdaQueryWrapperX<CrmPermissionDO>()
|
||||
.eq(CrmPermissionDO::getBizType, pageReqBO.getBizType())
|
||||
.eq(CrmPermissionDO::getUserId, pageReqBO.getUserId())); // 只要是团队成员都有读取的权限
|
||||
default List<CrmPermissionDO> selectListByBizTypeAndUserId(Integer bizType, Long userId) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
|
||||
.eq(CrmPermissionDO::getBizType, bizType)
|
||||
.eq(CrmPermissionDO::getUserId, userId));
|
||||
}
|
||||
|
||||
default List<CrmPermissionDO> selectListByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
|
||||
.eq(CrmPermissionDO::getBizType, bizType)
|
||||
.in(CrmPermissionDO::getBizId, bizIds)
|
||||
.eq(CrmPermissionDO::getLevel, level));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,21 +103,20 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
@Override
|
||||
public PageResult<CrmBusinessDO> getBusinessPage(CrmBusinessPageReqVO pageReqVO, Long userId) {
|
||||
// 1. 获取当前用户能看的分页数据
|
||||
PageResult<CrmPermissionDO> permissionPage = crmPermissionService.getPermissionPage(
|
||||
CrmBusinessConvert.INSTANCE.convert(pageReqVO).setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()).setUserId(userId));
|
||||
Set<Long> ids = convertSet(permissionPage.getList(), CrmPermissionDO::getBizId);
|
||||
List<CrmPermissionDO> permissions = crmPermissionService.getPermissionListByBizTypeAndUserId(
|
||||
CrmBizTypeEnum.CRM_BUSINESS.getType(), userId);
|
||||
Set<Long> ids = convertSet(permissions, CrmPermissionDO::getBizId);
|
||||
if (CollUtil.isEmpty(ids)) { // 没得说明没有什么给他看的
|
||||
return PageResult.empty();
|
||||
}
|
||||
|
||||
// 2. 获取商机分页数据
|
||||
List<CrmBusinessDO> businessList = businessMapper.selectList(pageReqVO, ids);
|
||||
return new PageResult<>(businessList, (long) businessList.size());
|
||||
return businessMapper.selectPage(pageReqVO, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmBusinessDO> getBusinessList(CrmBusinessExportReqVO exportReqVO) {
|
||||
return businessMapper.selectList(exportReqVO);
|
||||
return businessMapper.selectPage(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -50,9 +49,10 @@ public interface CrmCustomerService {
|
||||
* 获得客户分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @param userId 用户编号
|
||||
* @return 客户分页
|
||||
*/
|
||||
PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO);
|
||||
PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId);
|
||||
|
||||
/**
|
||||
* 获得客户列表, 用于 Excel 导出
|
||||
|
@ -1,9 +1,12 @@
|
||||
package cn.iocoder.yudao.module.crm.service.customer;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
|
||||
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||
@ -15,10 +18,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@ -51,11 +57,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, level = CrmPermissionLevelEnum.WRITE)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerExists(updateReqVO.getId());
|
||||
// TODO 芋艿:数据权限,校验是否可以操作
|
||||
|
||||
// 更新
|
||||
CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
|
||||
@ -64,11 +69,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, level = CrmPermissionLevelEnum.WRITE)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void deleteCustomer(Long id) {
|
||||
// 校验存在
|
||||
validateCustomerExists(id);
|
||||
// TODO 芋艿:数据权限,校验是否可以操作
|
||||
|
||||
// 删除
|
||||
customerMapper.deleteById(id);
|
||||
@ -81,20 +85,34 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, level = CrmPermissionLevelEnum.READ)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
||||
public CrmCustomerDO getCustomer(Long id) {
|
||||
return customerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO) {
|
||||
// TODO 芋艿:数据权限,是否可以查询到;
|
||||
return customerMapper.selectPage(pageReqVO);
|
||||
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||
// 1.1 TODO 如果是超级管理员
|
||||
boolean admin = false;
|
||||
if (admin && ObjUtil.notEqual(userId, CrmPermissionDO.POOL_USER_ID)) {
|
||||
return customerMapper.selectPage(pageReqVO, Collections.emptyList());
|
||||
}
|
||||
// 1.2 获取当前用户能看的分页数据
|
||||
List<CrmPermissionDO> permissions = crmPermissionService.getPermissionListByBizTypeAndUserId(
|
||||
CrmBizTypeEnum.CRM_CUSTOMER.getType(), userId);
|
||||
Set<Long> ids = convertSet(permissions, CrmPermissionDO::getBizId);
|
||||
if (CollUtil.isEmpty(ids)) { // 没得说明没有什么给他看的
|
||||
return PageResult.empty();
|
||||
}
|
||||
|
||||
// 2. 获取客户分页数据
|
||||
return customerMapper.selectPage(pageReqVO, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmCustomerDO> getCustomerList(CrmCustomerExportReqVO exportReqVO) {
|
||||
return customerMapper.selectList(exportReqVO);
|
||||
//return customerMapper.selectList(exportReqVO);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,15 +1,14 @@
|
||||
package cn.iocoder.yudao.module.crm.service.permission;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionPageReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateReqBO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -60,6 +59,16 @@ public interface CrmPermissionService {
|
||||
*/
|
||||
List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId);
|
||||
|
||||
/**
|
||||
* 获取数据权限列表,通过 数据类型 x 某个数据
|
||||
*
|
||||
* @param bizType 数据类型,关联 {@link CrmBizTypeEnum}
|
||||
* @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
|
||||
* @param level 权限级别
|
||||
* @return Crm 数据权限列表
|
||||
*/
|
||||
List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level);
|
||||
|
||||
/**
|
||||
* 数据权限转移
|
||||
*
|
||||
@ -68,11 +77,12 @@ public interface CrmPermissionService {
|
||||
void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO);
|
||||
|
||||
/**
|
||||
* 获取数据权限分页数据
|
||||
* 获取用户参与的模块数据列表
|
||||
*
|
||||
* @param pageReqBO 分页请求
|
||||
* @return 数据权限分页数据
|
||||
* @param bizType 模块类型
|
||||
* @param userId 用户编号
|
||||
* @return 模块数据列表
|
||||
*/
|
||||
PageResult<CrmPermissionDO> getPermissionPage(CrmPermissionPageReqBO pageReqBO);
|
||||
List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId);
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,12 @@ package cn.iocoder.yudao.module.crm.service.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.convert.permission.CrmPermissionConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionPageReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
@ -18,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -85,6 +84,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
|
||||
return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) {
|
||||
return crmPermissionMapper.selectListByBizTypeAndBizIdsAndLevel(bizType, bizIds, level);
|
||||
}
|
||||
|
||||
private void validateCrmPermissionExists(Long id) {
|
||||
if (crmPermissionMapper.selectById(id) == null) {
|
||||
throw exception(CRM_PERMISSION_NOT_EXISTS);
|
||||
@ -133,8 +137,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CrmPermissionDO> getPermissionPage(CrmPermissionPageReqBO pageReqBO) {
|
||||
return crmPermissionMapper.selectPage(pageReqBO);
|
||||
public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) {
|
||||
return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.permission.bo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 数据权限分页 Request BO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmPermissionPageReqBO extends PageParam {
|
||||
|
||||
/**
|
||||
* 当前登录用户编号
|
||||
*/
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* Crm 类型
|
||||
*/
|
||||
@NotNull(message = "Crm 类型不能为空")
|
||||
@InEnum(CrmBizTypeEnum.class)
|
||||
private Integer bizType;
|
||||
|
||||
}
|
@ -130,7 +130,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
|
||||
//reqVO.setWebsite(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(reqVO);
|
||||
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(reqVO, 1L);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
|
Loading…
Reference in New Issue
Block a user