CRM-商机:完善数据权限,新增权限关联、场景分页查询,新增权限关联批量查询

This commit is contained in:
puhui999 2023-12-08 17:16:34 +08:00
parent 5c395fc1c4
commit 9ea0607339
7 changed files with 67 additions and 47 deletions

View File

@ -36,6 +36,7 @@ import java.util.Set;
import java.util.stream.Collectors;
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.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -143,20 +144,13 @@ public class CrmBusinessController {
return success(CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList));
}
@GetMapping("/pool-page")
@Operation(summary = "获得商机公海分页")
@PreAuthorize("@ss.hasPermission('crm:business:query')")
public CommonResult<PageResult<CrmBusinessRespVO>> getBusinessPoolPage(@Valid CrmBusinessPageReqVO pageVO) {
// TODO puhui999: 等数据权限完善后再实现
return null;
}
@GetMapping("/export-excel")
@Operation(summary = "导出商机 Excel")
@PreAuthorize("@ss.hasPermission('crm:business:export')")
@OperateLog(type = EXPORT)
public void exportBusinessExcel(@Valid CrmBusinessPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PAGE_SIZE_NONE);
PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(exportReqVO, getLoginUserId());
// 导出 Excel
ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class,

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -18,4 +20,14 @@ public class CrmBusinessPageReqVO extends PageParam {
@Schema(description = "客户编号", example = "10795")
private Long customerId;
/**
* 场景类型 null 时则表示全部
*/
@Schema(description = "场景类型", example = "1")
@InEnum(CrmSceneTypeEnum.class)
private Integer sceneType;
@Schema(description = "是否为公海数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
private Boolean pool; // null 则表示为不是公海数据
}

View File

@ -39,8 +39,7 @@ public interface CrmBusinessConvert {
List<CrmBusinessExcelVO> convertList02(List<CrmBusinessDO> list);
@Mappings({
@Mapping(target = "bizId", source = "reqVO.id"),
@Mapping(target = "newOwnerUserId", source = "reqVO.id")
@Mapping(target = "bizId", source = "reqVO.id")
})
CrmPermissionTransferReqBO convert(CrmBusinessTransferReqVO reqVO, Long userId);

View File

@ -97,4 +97,11 @@ public class CrmBusinessDO extends BaseDO {
*/
private Integer followUpStatus;
/**
* 负责人的用户编号
*
* 关联 AdminUserDO id 字段
*/
private Long ownerUserId;
}

View File

@ -2,13 +2,16 @@ 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.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
* 商机 Mapper
@ -18,18 +21,29 @@ import java.util.Collection;
@Mapper
public interface CrmBusinessMapper extends BaseMapperX<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 int updateOwnerUserIdById(Long id, Long ownerUserId) {
return update(new LambdaUpdateWrapper<CrmBusinessDO>()
.eq(CrmBusinessDO::getId, id)
.set(CrmBusinessDO::getOwnerUserId, ownerUserId));
}
default PageResult<CrmBusinessDO> selectPageByCustomer(CrmContractPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmBusinessDO>()
.eq(CrmBusinessDO::getCustomerId, reqVO.getCustomerId()) // 必须传递
.likeIfPresent(CrmBusinessDO::getName, reqVO.getName())
.orderByDesc(CrmBusinessDO::getId));
default PageResult<CrmBusinessDO> selectPage(CrmBusinessPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmBusinessDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件
CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_BUSINESS.getType(), CrmBusinessDO::getId,
userId, pageReqVO.getSceneType(), pageReqVO.getPool());
mpjLambdaWrapperX.selectAll(CrmBusinessDO.class)
.eq(CrmBusinessDO::getCustomerId, pageReqVO.getCustomerId()) // 必须传递
.likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName())
.orderByDesc(CrmBusinessDO::getId);
return selectJoinPage(pageReqVO, CrmBusinessDO.class, mpjLambdaWrapperX);
}
default List<CrmBusinessDO> selectBatchIds(Collection<Long> ids, Long userId) {
MPJLambdaWrapperX<CrmBusinessDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件
CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_BUSINESS.getType(), ids, userId);
return selectJoinList(CrmBusinessDO.class, mpjLambdaWrapperX);
}
}

View File

@ -8,8 +8,8 @@ import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusi
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.List;
@ -57,7 +57,7 @@ public interface CrmBusinessService {
* @param ids 编号
* @return 商机列表
*/
List<CrmBusinessDO> getBusinessList(Collection<Long> ids);
List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId);
/**
* 获得商机分页

View File

@ -3,28 +3,28 @@ package cn.iocoder.yudao.module.crm.service.business;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.Collection;
import java.util.List;
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.BUSINESS_NOT_EXISTS;
/**
@ -71,7 +71,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, level = CrmPermissionLevelEnum.OWNER)
public void deleteBusiness(Long id) {
// 校验存在
validateBusinessExists(id);
@ -88,38 +88,29 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS,bizId = "#id", level = CrmPermissionLevelEnum.READ)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#id", level = CrmPermissionLevelEnum.READ)
public CrmBusinessDO getBusiness(Long id) {
return businessMapper.selectById(id);
}
@Override
public List<CrmBusinessDO> getBusinessList(Collection<Long> ids) {
public List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return businessMapper.selectBatchIds(ids);
return businessMapper.selectBatchIds(ids, userId);
}
@Override
public PageResult<CrmBusinessDO> getBusinessPage(CrmBusinessPageReqVO pageReqVO, Long userId) {
// 1. 获取当前用户能看的分页数据
// TODO @puhui999如果业务的数据量比较大in 太多可能有性能问题噢看看是不是搞成 join 连表了可以微信讨论下
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. 获取商机分页数据
return businessMapper.selectPage(pageReqVO, ids);
return businessMapper.selectPage(pageReqVO, userId);
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ)
public PageResult<CrmBusinessDO> getBusinessPageByCustomer(CrmContractPageReqVO pageReqVO) {
return businessMapper.selectPageByCustomer(pageReqVO);
//return businessMapper.selectPageByCustomer(pageReqVO);
return null; // TODO puhui999: 可以跟分页合并吗
}
@Override
@ -128,10 +119,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
// 1 校验商机是否存在
validateBusinessExists(reqVO.getId());
// 2. 数据权限转移
// 2.1 数据权限转移
crmPermissionService.transferPermission(
CrmBusinessConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()));
// 2.2 设置新的负责人
businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
// 3. TODO 记录转移日志
}