!762 crm:完善 code review 数据权限提到的问题
Merge pull request !762 from puhui999/feature/crm
This commit is contained in:
commit
6f882ca24e
|
@ -31,6 +31,7 @@ import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
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.util.collection.CollectionUtils.convertSet;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
|
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;
|
||||||
|
@ -115,7 +116,7 @@ public class CrmCustomerController {
|
||||||
@OperateLog(type = EXPORT)
|
@OperateLog(type = EXPORT)
|
||||||
public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO,
|
public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
// TODO @puhui999:看看复用 getCustomerPage 方法;然后可以禁用下分页;
|
pageVO.setPageSize(PAGE_SIZE_NONE); // 不分页
|
||||||
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
|
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
|
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
|
||||||
|
@ -168,9 +169,6 @@ public class CrmCustomerController {
|
||||||
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
|
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
|
||||||
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
|
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
|
||||||
@RequestParam(value = "ownerUserId") Long ownerUserId) {
|
@RequestParam(value = "ownerUserId") Long ownerUserId) {
|
||||||
// 校验负责人是否存在
|
|
||||||
// TODO @puhui999:这个校验,是不是可以收到 validateUserList
|
|
||||||
adminUserApi.validateUserList(singletonList(ownerUserId));
|
|
||||||
// 领取公海数据
|
// 领取公海数据
|
||||||
customerService.receiveCustomer(ids, ownerUserId);
|
customerService.receiveCustomer(ids, ownerUserId);
|
||||||
return success(true);
|
return success(true);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class CrmPermissionController {
|
||||||
@DeleteMapping("/delete-self")
|
@DeleteMapping("/delete-self")
|
||||||
@Operation(summary = "删除自己的数据权限")
|
@Operation(summary = "删除自己的数据权限")
|
||||||
@Parameter(name = "id", description = "数据权限编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "数据权限编号", required = true, example = "1024")
|
||||||
@PreAuthorize("@ss.hasPermission('crm:permission:delete')") // TODO puhui999: 数据权限在页面上只是已团队成员组件的形式出现,那么这个权限怎么分配?
|
@PreAuthorize("@ss.hasPermission('crm:permission:delete')")
|
||||||
public CommonResult<Boolean> deleteSelfPermission(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> deleteSelfPermission(@RequestParam("id") Long id) {
|
||||||
permissionService.deleteSelfPermission(id, getLoginUserId());
|
permissionService.deleteSelfPermission(id, getLoginUserId());
|
||||||
return success(true);
|
return success(true);
|
||||||
|
|
|
@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAnd
|
||||||
/**
|
/**
|
||||||
* Crm 数据权限 Convert
|
* Crm 数据权限 Convert
|
||||||
*
|
*
|
||||||
* @author Wanwan
|
* @author HUIHUI
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CrmPermissionConvert {
|
public interface CrmPermissionConvert {
|
||||||
|
|
|
@ -25,38 +25,14 @@ import java.util.List;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||||
|
|
||||||
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
|
|
||||||
if (pageReqVO.getPool()) { // 情况一:公海
|
|
||||||
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
|
||||||
} else { // 情况二:不是公海
|
|
||||||
mpjLambdaWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
|
|
||||||
}
|
|
||||||
// TODO 场景数据过滤
|
|
||||||
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
|
||||||
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void appendQueryParams(LambdaQueryWrapperX<CrmCustomerDO> lambdaQueryWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
|
|
||||||
if (pageReqVO.getPool()) { // 情况一:公海
|
|
||||||
lambdaQueryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
|
||||||
} else { // 情况二:不是公海
|
|
||||||
lambdaQueryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
|
|
||||||
}
|
|
||||||
// TODO 场景数据过滤
|
|
||||||
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
|
||||||
lambdaQueryWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default int updateOwnerUserIdById(Long id, Long ownerUserId) {
|
default int updateOwnerUserIdById(Long id, Long ownerUserId) {
|
||||||
return update(new LambdaUpdateWrapper<CrmCustomerDO>()
|
return update(new LambdaUpdateWrapper<CrmCustomerDO>()
|
||||||
.eq(CrmCustomerDO::getId, id)
|
.eq(CrmCustomerDO::getId, id)
|
||||||
.set(CrmCustomerDO::getOwnerUserId, ownerUserId));
|
.set(CrmCustomerDO::getOwnerUserId, ownerUserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId, Boolean admin) {
|
default PageResult<CrmCustomerDO> selectPageWithAdmin(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
if (admin) { // 情况一:管理员查看
|
// 情况一:管理员查看
|
||||||
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
|
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
|
||||||
appendQueryParams(queryWrapperX, pageReqVO, userId);
|
appendQueryParams(queryWrapperX, pageReqVO, userId);
|
||||||
return selectPage(pageReqVO, queryWrapperX
|
return selectPage(pageReqVO, queryWrapperX
|
||||||
|
@ -66,6 +42,8 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||||
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
|
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
|
||||||
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
|
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
// 情况二:获取当前用户能看的分页数据
|
// 情况二:获取当前用户能看的分页数据
|
||||||
IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO);
|
IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO);
|
||||||
MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
|
MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
|
||||||
|
@ -91,4 +69,28 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||||
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
|
if (pageReqVO.getPool()) { // 情况一:公海
|
||||||
|
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
||||||
|
} else { // 情况二:不是公海
|
||||||
|
mpjLambdaWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
|
||||||
|
}
|
||||||
|
// TODO 场景数据过滤
|
||||||
|
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
||||||
|
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void appendQueryParams(LambdaQueryWrapperX<CrmCustomerDO> lambdaQueryWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
|
if (pageReqVO.getPool()) { // 情况一:公海
|
||||||
|
lambdaQueryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
||||||
|
} else { // 情况二:不是公海
|
||||||
|
lambdaQueryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
|
||||||
|
}
|
||||||
|
// TODO 场景数据过滤
|
||||||
|
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
||||||
|
lambdaQueryWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
|
||||||
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
|
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
|
||||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -25,6 +26,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户 Service 实现类
|
* 客户 Service 实现类
|
||||||
|
@ -40,6 +42,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CrmPermissionService crmPermissionService;
|
private CrmPermissionService crmPermissionService;
|
||||||
|
@Resource
|
||||||
|
private AdminUserApi adminUserApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -96,9 +100,12 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
// 1.1. TODO 如果是超级管理员
|
|
||||||
boolean admin = false;
|
boolean admin = false;
|
||||||
return customerMapper.selectPage(pageReqVO, userId, admin);
|
if (admin) { // 1.1. 情况一: TODO 如果是管理员
|
||||||
|
customerMapper.selectPageWithAdmin(pageReqVO, userId);
|
||||||
|
}
|
||||||
|
// 1.2. 情况二:获取当前用户能看的分页数据
|
||||||
|
return customerMapper.selectPage(pageReqVO, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,7 +181,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||||
if (customers.size() != ids.size()) {
|
if (customers.size() != ids.size()) {
|
||||||
throw exception(CUSTOMER_NOT_EXISTS);
|
throw exception(CUSTOMER_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
// 1.2. 校验状态
|
// 1.2. 校验负责人是否存在
|
||||||
|
adminUserApi.validateUserList(singletonList(ownerUserId));
|
||||||
|
// 1.3. 校验状态
|
||||||
customers.forEach(customer -> {
|
customers.forEach(customer -> {
|
||||||
// 校验是否已有负责人
|
// 校验是否已有负责人
|
||||||
validateCustomerOwnerExists(customer, false);
|
validateCustomerOwnerExists(customer, false);
|
||||||
|
|
|
@ -19,11 +19,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class BannerPageReqVO extends PageParam {
|
public class BannerPageReqVO extends PageParam {
|
||||||
|
|
||||||
// TODO @puhui999:example
|
@Schema(description = "标题", example = "这是一个标题")
|
||||||
@Schema(description = "标题")
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Schema(description = "状态")
|
@Schema(description = "状态", example = "1")
|
||||||
@InEnum(CommonStatusEnum.class)
|
@InEnum(CommonStatusEnum.class)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue