From f69a18fd230ad6bca70e7c267408e0976b03f17d Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 8 Dec 2023 18:08:41 +0800 Subject: [PATCH] =?UTF-8?q?CRM-=E8=81=94=E7=B3=BB=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90=E5=85=B3=E8=81=94=E3=80=81?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90=E5=85=B3=E8=81=94=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/contact/CrmContactController.java | 19 ++++--- .../dal/mysql/contact/CrmContactMapper.java | 55 +++++++++++-------- .../service/contact/CrmContactService.java | 30 +++------- .../contact/CrmContactServiceImpl.java | 31 ++++------- .../module/crm/util/CrmQueryWrapperUtils.java | 2 +- 5 files changed, 62 insertions(+), 75 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java index 811b4758e..d39b318da 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -38,6 +37,7 @@ import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 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.convertListByFlatMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @@ -98,7 +98,8 @@ public class CrmContactController { List customerList = customerService.getCustomerList( Collections.singletonList(contact.getCustomerId()), getLoginUserId()); // 3. 直属上级 - List parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); + List parentContactList = contactService.getContactList( + Collections.singletonList(contact.getParentId()), getLoginUserId()); return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); } @@ -106,7 +107,9 @@ public class CrmContactController { @Operation(summary = "获得联系人列表") @PreAuthorize("@ss.hasPermission('crm:contact:query')") public CommonResult> getSimpleContactList() { - List list = contactService.getContactList(); + CrmContactPageReqVO pageReqVO = new CrmContactPageReqVO(); + pageReqVO.setPageSize(PAGE_SIZE_NONE); + List list = contactService.getContactPage(pageReqVO, getLoginUserId()).getList(); return success(ContactConvert.INSTANCE.convertAllList(list)); } @@ -114,7 +117,7 @@ public class CrmContactController { @Operation(summary = "获得联系人分页") @PreAuthorize("@ss.hasPermission('crm:contact:query')") public CommonResult> getContactPage(@Valid CrmContactPageReqVO pageVO) { - PageResult pageResult = contactService.getContactPage(pageVO); + PageResult pageResult = contactService.getContactPage(pageVO, getLoginUserId()); return success(convertDetailContactPage(pageResult)); } @@ -122,7 +125,7 @@ public class CrmContactController { @Operation(summary = "获得联系人分页,基于指定客户") public CommonResult> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); - PageResult pageResult = contactService.getContactPageByCustomer(pageVO); + PageResult pageResult = contactService.getContactPage(pageVO, getLoginUserId()); return success(convertDetailContactPage(pageResult)); } @@ -132,8 +135,8 @@ public class CrmContactController { @OperateLog(type = EXPORT) public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - exportReqVO.setPageNo(PageParam.PAGE_SIZE_NONE); - PageResult pageResult = contactService.getContactPage(exportReqVO); + exportReqVO.setPageNo(PAGE_SIZE_NONE); + PageResult pageResult = contactService.getContactPage(exportReqVO, getLoginUserId()); ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, convertDetailContactPage(pageResult).getList()); } @@ -157,7 +160,7 @@ public class CrmContactController { contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); // 3. 直属上级 List parentContactList = contactService.getContactList( - convertSet(contactList, CrmContactDO::getParentId)); + convertSet(contactList, CrmContactDO::getParentId), getLoginUserId()); return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java index 4c8f82f1a..0ea93ab41 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java @@ -2,11 +2,17 @@ package cn.iocoder.yudao.module.crm.dal.mysql.contact; 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.contact.vo.CrmContactPageReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; +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; + /** * CRM 联系人 Mapper * @@ -15,29 +21,34 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface CrmContactMapper extends BaseMapperX { - // TODO @puhui999:数据权限 - default PageResult selectPage(CrmContactPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(CrmContactDO::getMobile, reqVO.getMobile()) - .eqIfPresent(CrmContactDO::getTelephone, reqVO.getTelephone()) - .eqIfPresent(CrmContactDO::getEmail, reqVO.getEmail()) - .eqIfPresent(CrmContactDO::getCustomerId, reqVO.getCustomerId()) - .likeIfPresent(CrmContactDO::getName, reqVO.getName()) - .eqIfPresent(CrmContactDO::getQq, reqVO.getQq()) - .eqIfPresent(CrmContactDO::getWechat, reqVO.getWechat()) - .orderByDesc(CrmContactDO::getId)); + default int updateOwnerUserIdById(Long id, Long ownerUserId) { + return update(new LambdaUpdateWrapper() + .eq(CrmContactDO::getId, id) + .set(CrmContactDO::getOwnerUserId, ownerUserId)); } - default PageResult selectPageByCustomer(CrmContactPageReqVO pageVO) { - return selectPage(pageVO, new LambdaQueryWrapperX() - .eq(CrmContactDO::getCustomerId, pageVO.getCustomerId()) // 必须传递 - .likeIfPresent(CrmContactDO::getName, pageVO.getName()) - .eqIfPresent(CrmContactDO::getMobile, pageVO.getMobile()) - .eqIfPresent(CrmContactDO::getTelephone, pageVO.getTelephone()) - .eqIfPresent(CrmContactDO::getEmail, pageVO.getEmail()) - .eqIfPresent(CrmContactDO::getQq, pageVO.getQq()) - .eqIfPresent(CrmContactDO::getWechat, pageVO.getWechat()) - .orderByDesc(CrmContactDO::getId)); + default PageResult selectPage(CrmContactPageReqVO pageReqVO, Long userId) { + MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); + // 构建数据权限连表条件 + CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContactDO::getId, + userId, pageReqVO.getSceneType(), pageReqVO.getPool()); + mpjLambdaWrapperX.selectAll(CrmContactDO.class) + .eq(CrmContactDO::getCustomerId, pageReqVO.getCustomerId()) // 必须传递 + .likeIfPresent(CrmContactDO::getName, pageReqVO.getName()) + .eqIfPresent(CrmContactDO::getMobile, pageReqVO.getMobile()) + .eqIfPresent(CrmContactDO::getTelephone, pageReqVO.getTelephone()) + .eqIfPresent(CrmContactDO::getEmail, pageReqVO.getEmail()) + .eqIfPresent(CrmContactDO::getQq, pageReqVO.getQq()) + .eqIfPresent(CrmContactDO::getWechat, pageReqVO.getWechat()) + .orderByDesc(CrmContactDO::getId); + return selectJoinPage(pageReqVO, CrmContactDO.class, mpjLambdaWrapperX); + } + + default List selectBatchIds(Collection ids, Long userId) { + MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); + // 构建数据权限连表条件 + CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId); + return selectJoinList(CrmContactDO.class, mpjLambdaWrapperX); } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java index 85aec14cc..a37b96962 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java @@ -5,9 +5,8 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactCreateR import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; -import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; - import jakarta.validation.Valid; + import java.util.Collection; import java.util.List; @@ -22,7 +21,7 @@ public interface CrmContactService { * 创建联系人 * * @param createReqVO 创建信息 - * @param userId 用户编号 + * @param userId 用户编号 * @return 编号 */ Long createContact(@Valid CrmContactCreateReqVO createReqVO, Long userId); @@ -52,10 +51,11 @@ public interface CrmContactService { /** * 获得联系人列表 * - * @param ids 编号 + * @param ids 编号 + * @param userId 用户编号 * @return 联系人列表 */ - List getContactList(Collection ids); + List getContactList(Collection ids, Long userId); /** * 获得联系人分页 @@ -63,25 +63,9 @@ public interface CrmContactService { * 数据权限:基于 {@link CrmContactDO} * * @param pageReqVO 分页查询 + * @param userId 用户编号 * @return 联系人分页 */ - PageResult getContactPage(CrmContactPageReqVO pageReqVO); - - /** - * 获得联系人分页,基于指定客户 - * - * 数据权限:基于 {@link CrmCustomerDO} 读取 - * - * @param pageReqVO 分页查询 - * @return 联系人分页 - */ - PageResult getContactPageByCustomer(CrmContactPageReqVO pageReqVO); - - /** - * 获取所有联系人列表 - * - * @return 所有联系人列表 - */ - List getContactList(); + PageResult getContactPage(CrmContactPageReqVO pageReqVO, Long userId); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java index d4c4fe9c2..a4ca31072 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java @@ -10,18 +10,18 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateR import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper; -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.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +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; @@ -82,7 +82,7 @@ public class CrmContactServiceImpl implements CrmContactService { * * @param saveReqVO 新增/修改请求 VO */ - private void validateRelationDataExists(CrmContactBaseVO saveReqVO){ + private void validateRelationDataExists(CrmContactBaseVO saveReqVO) { // 1. 校验客户 if (saveReqVO.getCustomerId() != null && customerService.getCustomer(saveReqVO.getCustomerId()) == null) { throw exception(CUSTOMER_NOT_EXISTS); @@ -98,12 +98,14 @@ public class CrmContactServiceImpl implements CrmContactService { } @Override - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) public void deleteContact(Long id) { // 校验存在 validateContactExists(id); // 删除 contactMapper.deleteById(id); + // 删除数据权限 + crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTACT.getType(), id); } private void validateContactExists(Long id) { @@ -112,7 +114,6 @@ public class CrmContactServiceImpl implements CrmContactService { } } - // TODO 芋艿:是否要做数据权限的校验??? @Override @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.READ) public CrmContactDO getContact(Long id) { @@ -120,28 +121,16 @@ public class CrmContactServiceImpl implements CrmContactService { } @Override - public List getContactList(Collection ids) { + public List getContactList(Collection ids, Long userId) { if (CollUtil.isEmpty(ids)) { return ListUtil.empty(); } - return contactMapper.selectBatchIds(ids); + return contactMapper.selectBatchIds(ids, userId); } @Override - public PageResult getContactPage(CrmContactPageReqVO pageReqVO) { - // TODO puhui999:后面要改成,基于数据权限的查询 - return contactMapper.selectPage(pageReqVO); - } - - @Override - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ) - public PageResult getContactPageByCustomer(CrmContactPageReqVO pageReqVO) { - return contactMapper.selectPageByCustomer(pageReqVO); - } - - @Override - public List getContactList() { - return contactMapper.selectList(); + public PageResult getContactPage(CrmContactPageReqVO pageReqVO, Long userId) { + return contactMapper.selectPage(pageReqVO, userId); } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java index 23e422332..0ffa8572e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java @@ -79,7 +79,7 @@ public class CrmQueryWrapperUtils { if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 queryMapper.innerJoin(CrmPermissionDO.class, on -> on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds) - .eq(CrmPermissionDO::getUserId, userId)); + .in(CollUtil.isNotEmpty(bizIds), CrmPermissionDO::getUserId, userId)); } }