Commit f69a18fd230ad6bca70e7c267408e0976b03f17d
1 parent
490418a1
CRM-联系人:完善数据权限,新增权限关联、场景分页查询,新增权限关联批量查询
Showing
5 changed files
with
62 additions
and
75 deletions
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; | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | import cn.hutool.core.util.NumberUtil; | 5 | import cn.hutool.core.util.NumberUtil; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | 8 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| 10 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -38,6 +37,7 @@ import java.util.stream.Stream; | @@ -38,6 +37,7 @@ import java.util.stream.Stream; | ||
| 38 | 37 | ||
| 39 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 38 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 40 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 39 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 40 | +import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; | ||
| 41 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; | 41 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; |
| 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 43 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 43 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| @@ -98,7 +98,8 @@ public class CrmContactController { | @@ -98,7 +98,8 @@ public class CrmContactController { | ||
| 98 | List<CrmCustomerDO> customerList = customerService.getCustomerList( | 98 | List<CrmCustomerDO> customerList = customerService.getCustomerList( |
| 99 | Collections.singletonList(contact.getCustomerId()), getLoginUserId()); | 99 | Collections.singletonList(contact.getCustomerId()), getLoginUserId()); |
| 100 | // 3. 直属上级 | 100 | // 3. 直属上级 |
| 101 | - List<CrmContactDO> parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); | 101 | + List<CrmContactDO> parentContactList = contactService.getContactList( |
| 102 | + Collections.singletonList(contact.getParentId()), getLoginUserId()); | ||
| 102 | return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); | 103 | return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); |
| 103 | } | 104 | } |
| 104 | 105 | ||
| @@ -106,7 +107,9 @@ public class CrmContactController { | @@ -106,7 +107,9 @@ public class CrmContactController { | ||
| 106 | @Operation(summary = "获得联系人列表") | 107 | @Operation(summary = "获得联系人列表") |
| 107 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") | 108 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| 108 | public CommonResult<List<CrmContactSimpleRespVO>> getSimpleContactList() { | 109 | public CommonResult<List<CrmContactSimpleRespVO>> getSimpleContactList() { |
| 109 | - List<CrmContactDO> list = contactService.getContactList(); | 110 | + CrmContactPageReqVO pageReqVO = new CrmContactPageReqVO(); |
| 111 | + pageReqVO.setPageSize(PAGE_SIZE_NONE); | ||
| 112 | + List<CrmContactDO> list = contactService.getContactPage(pageReqVO, getLoginUserId()).getList(); | ||
| 110 | return success(ContactConvert.INSTANCE.convertAllList(list)); | 113 | return success(ContactConvert.INSTANCE.convertAllList(list)); |
| 111 | } | 114 | } |
| 112 | 115 | ||
| @@ -114,7 +117,7 @@ public class CrmContactController { | @@ -114,7 +117,7 @@ public class CrmContactController { | ||
| 114 | @Operation(summary = "获得联系人分页") | 117 | @Operation(summary = "获得联系人分页") |
| 115 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") | 118 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| 116 | public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) { | 119 | public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) { |
| 117 | - PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO); | 120 | + PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO, getLoginUserId()); |
| 118 | return success(convertDetailContactPage(pageResult)); | 121 | return success(convertDetailContactPage(pageResult)); |
| 119 | } | 122 | } |
| 120 | 123 | ||
| @@ -122,7 +125,7 @@ public class CrmContactController { | @@ -122,7 +125,7 @@ public class CrmContactController { | ||
| 122 | @Operation(summary = "获得联系人分页,基于指定客户") | 125 | @Operation(summary = "获得联系人分页,基于指定客户") |
| 123 | public CommonResult<PageResult<CrmContactRespVO>> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { | 126 | public CommonResult<PageResult<CrmContactRespVO>> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { |
| 124 | Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); | 127 | Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); |
| 125 | - PageResult<CrmContactDO> pageResult = contactService.getContactPageByCustomer(pageVO); | 128 | + PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO, getLoginUserId()); |
| 126 | return success(convertDetailContactPage(pageResult)); | 129 | return success(convertDetailContactPage(pageResult)); |
| 127 | } | 130 | } |
| 128 | 131 | ||
| @@ -132,8 +135,8 @@ public class CrmContactController { | @@ -132,8 +135,8 @@ public class CrmContactController { | ||
| 132 | @OperateLog(type = EXPORT) | 135 | @OperateLog(type = EXPORT) |
| 133 | public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, | 136 | public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, |
| 134 | HttpServletResponse response) throws IOException { | 137 | HttpServletResponse response) throws IOException { |
| 135 | - exportReqVO.setPageNo(PageParam.PAGE_SIZE_NONE); | ||
| 136 | - PageResult<CrmContactDO> pageResult = contactService.getContactPage(exportReqVO); | 138 | + exportReqVO.setPageNo(PAGE_SIZE_NONE); |
| 139 | + PageResult<CrmContactDO> pageResult = contactService.getContactPage(exportReqVO, getLoginUserId()); | ||
| 137 | ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, | 140 | ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, |
| 138 | convertDetailContactPage(pageResult).getList()); | 141 | convertDetailContactPage(pageResult).getList()); |
| 139 | } | 142 | } |
| @@ -157,7 +160,7 @@ public class CrmContactController { | @@ -157,7 +160,7 @@ public class CrmContactController { | ||
| 157 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | 160 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); |
| 158 | // 3. 直属上级 | 161 | // 3. 直属上级 |
| 159 | List<CrmContactDO> parentContactList = contactService.getContactList( | 162 | List<CrmContactDO> parentContactList = contactService.getContactList( |
| 160 | - convertSet(contactList, CrmContactDO::getParentId)); | 163 | + convertSet(contactList, CrmContactDO::getParentId), getLoginUserId()); |
| 161 | return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); | 164 | return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); |
| 162 | } | 165 | } |
| 163 | 166 |
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; | @@ -2,11 +2,17 @@ package cn.iocoder.yudao.module.crm.dal.mysql.contact; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; |
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; |
| 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; |
| 8 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 9 | +import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; | ||
| 10 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 11 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 12 | ||
| 13 | +import java.util.Collection; | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 10 | /** | 16 | /** |
| 11 | * CRM 联系人 Mapper | 17 | * CRM 联系人 Mapper |
| 12 | * | 18 | * |
| @@ -15,29 +21,34 @@ import org.apache.ibatis.annotations.Mapper; | @@ -15,29 +21,34 @@ import org.apache.ibatis.annotations.Mapper; | ||
| 15 | @Mapper | 21 | @Mapper |
| 16 | public interface CrmContactMapper extends BaseMapperX<CrmContactDO> { | 22 | public interface CrmContactMapper extends BaseMapperX<CrmContactDO> { |
| 17 | 23 | ||
| 18 | - // TODO @puhui999:数据权限 | ||
| 19 | - default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO reqVO) { | ||
| 20 | - return selectPage(reqVO, new LambdaQueryWrapperX<CrmContactDO>() | ||
| 21 | - .eqIfPresent(CrmContactDO::getMobile, reqVO.getMobile()) | ||
| 22 | - .eqIfPresent(CrmContactDO::getTelephone, reqVO.getTelephone()) | ||
| 23 | - .eqIfPresent(CrmContactDO::getEmail, reqVO.getEmail()) | ||
| 24 | - .eqIfPresent(CrmContactDO::getCustomerId, reqVO.getCustomerId()) | ||
| 25 | - .likeIfPresent(CrmContactDO::getName, reqVO.getName()) | ||
| 26 | - .eqIfPresent(CrmContactDO::getQq, reqVO.getQq()) | ||
| 27 | - .eqIfPresent(CrmContactDO::getWechat, reqVO.getWechat()) | ||
| 28 | - .orderByDesc(CrmContactDO::getId)); | 24 | + default int updateOwnerUserIdById(Long id, Long ownerUserId) { |
| 25 | + return update(new LambdaUpdateWrapper<CrmContactDO>() | ||
| 26 | + .eq(CrmContactDO::getId, id) | ||
| 27 | + .set(CrmContactDO::getOwnerUserId, ownerUserId)); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) { | ||
| 31 | + MPJLambdaWrapperX<CrmContactDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); | ||
| 32 | + // 构建数据权限连表条件 | ||
| 33 | + CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContactDO::getId, | ||
| 34 | + userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | ||
| 35 | + mpjLambdaWrapperX.selectAll(CrmContactDO.class) | ||
| 36 | + .eq(CrmContactDO::getCustomerId, pageReqVO.getCustomerId()) // 必须传递 | ||
| 37 | + .likeIfPresent(CrmContactDO::getName, pageReqVO.getName()) | ||
| 38 | + .eqIfPresent(CrmContactDO::getMobile, pageReqVO.getMobile()) | ||
| 39 | + .eqIfPresent(CrmContactDO::getTelephone, pageReqVO.getTelephone()) | ||
| 40 | + .eqIfPresent(CrmContactDO::getEmail, pageReqVO.getEmail()) | ||
| 41 | + .eqIfPresent(CrmContactDO::getQq, pageReqVO.getQq()) | ||
| 42 | + .eqIfPresent(CrmContactDO::getWechat, pageReqVO.getWechat()) | ||
| 43 | + .orderByDesc(CrmContactDO::getId); | ||
| 44 | + return selectJoinPage(pageReqVO, CrmContactDO.class, mpjLambdaWrapperX); | ||
| 29 | } | 45 | } |
| 30 | 46 | ||
| 31 | - default PageResult<CrmContactDO> selectPageByCustomer(CrmContactPageReqVO pageVO) { | ||
| 32 | - return selectPage(pageVO, new LambdaQueryWrapperX<CrmContactDO>() | ||
| 33 | - .eq(CrmContactDO::getCustomerId, pageVO.getCustomerId()) // 必须传递 | ||
| 34 | - .likeIfPresent(CrmContactDO::getName, pageVO.getName()) | ||
| 35 | - .eqIfPresent(CrmContactDO::getMobile, pageVO.getMobile()) | ||
| 36 | - .eqIfPresent(CrmContactDO::getTelephone, pageVO.getTelephone()) | ||
| 37 | - .eqIfPresent(CrmContactDO::getEmail, pageVO.getEmail()) | ||
| 38 | - .eqIfPresent(CrmContactDO::getQq, pageVO.getQq()) | ||
| 39 | - .eqIfPresent(CrmContactDO::getWechat, pageVO.getWechat()) | ||
| 40 | - .orderByDesc(CrmContactDO::getId)); | 47 | + default List<CrmContactDO> selectBatchIds(Collection<Long> ids, Long userId) { |
| 48 | + MPJLambdaWrapperX<CrmContactDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); | ||
| 49 | + // 构建数据权限连表条件 | ||
| 50 | + CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId); | ||
| 51 | + return selectJoinList(CrmContactDO.class, mpjLambdaWrapperX); | ||
| 41 | } | 52 | } |
| 42 | 53 | ||
| 43 | } | 54 | } |
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 | @@ -5,9 +5,8 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactCreateR | ||
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; | 5 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; |
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateReqVO; |
| 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; |
| 8 | -import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | ||
| 9 | - | ||
| 10 | import jakarta.validation.Valid; | 8 | import jakarta.validation.Valid; |
| 9 | + | ||
| 11 | import java.util.Collection; | 10 | import java.util.Collection; |
| 12 | import java.util.List; | 11 | import java.util.List; |
| 13 | 12 | ||
| @@ -22,7 +21,7 @@ public interface CrmContactService { | @@ -22,7 +21,7 @@ public interface CrmContactService { | ||
| 22 | * 创建联系人 | 21 | * 创建联系人 |
| 23 | * | 22 | * |
| 24 | * @param createReqVO 创建信息 | 23 | * @param createReqVO 创建信息 |
| 25 | - * @param userId 用户编号 | 24 | + * @param userId 用户编号 |
| 26 | * @return 编号 | 25 | * @return 编号 |
| 27 | */ | 26 | */ |
| 28 | Long createContact(@Valid CrmContactCreateReqVO createReqVO, Long userId); | 27 | Long createContact(@Valid CrmContactCreateReqVO createReqVO, Long userId); |
| @@ -52,10 +51,11 @@ public interface CrmContactService { | @@ -52,10 +51,11 @@ public interface CrmContactService { | ||
| 52 | /** | 51 | /** |
| 53 | * 获得联系人列表 | 52 | * 获得联系人列表 |
| 54 | * | 53 | * |
| 55 | - * @param ids 编号 | 54 | + * @param ids 编号 |
| 55 | + * @param userId 用户编号 | ||
| 56 | * @return 联系人列表 | 56 | * @return 联系人列表 |
| 57 | */ | 57 | */ |
| 58 | - List<CrmContactDO> getContactList(Collection<Long> ids); | 58 | + List<CrmContactDO> getContactList(Collection<Long> ids, Long userId); |
| 59 | 59 | ||
| 60 | /** | 60 | /** |
| 61 | * 获得联系人分页 | 61 | * 获得联系人分页 |
| @@ -63,25 +63,9 @@ public interface CrmContactService { | @@ -63,25 +63,9 @@ public interface CrmContactService { | ||
| 63 | * 数据权限:基于 {@link CrmContactDO} | 63 | * 数据权限:基于 {@link CrmContactDO} |
| 64 | * | 64 | * |
| 65 | * @param pageReqVO 分页查询 | 65 | * @param pageReqVO 分页查询 |
| 66 | + * @param userId 用户编号 | ||
| 66 | * @return 联系人分页 | 67 | * @return 联系人分页 |
| 67 | */ | 68 | */ |
| 68 | - PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO); | ||
| 69 | - | ||
| 70 | - /** | ||
| 71 | - * 获得联系人分页,基于指定客户 | ||
| 72 | - * | ||
| 73 | - * 数据权限:基于 {@link CrmCustomerDO} 读取 | ||
| 74 | - * | ||
| 75 | - * @param pageReqVO 分页查询 | ||
| 76 | - * @return 联系人分页 | ||
| 77 | - */ | ||
| 78 | - PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageReqVO); | ||
| 79 | - | ||
| 80 | - /** | ||
| 81 | - * 获取所有联系人列表 | ||
| 82 | - * | ||
| 83 | - * @return 所有联系人列表 | ||
| 84 | - */ | ||
| 85 | - List<CrmContactDO> getContactList(); | 69 | + PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO, Long userId); |
| 86 | 70 | ||
| 87 | } | 71 | } |
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 | @@ -10,18 +10,18 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateR | ||
| 10 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; | 10 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; |
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; |
| 12 | import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper; | 12 | import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper; |
| 13 | -import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | ||
| 14 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | 13 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 15 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; | 14 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| 15 | +import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | ||
| 16 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | 16 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 17 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | 17 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 18 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; | 18 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 19 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 19 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 20 | +import jakarta.annotation.Resource; | ||
| 20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| 23 | 24 | ||
| 24 | -import jakarta.annotation.Resource; | ||
| 25 | import java.util.Collection; | 25 | import java.util.Collection; |
| 26 | import java.util.List; | 26 | import java.util.List; |
| 27 | 27 | ||
| @@ -82,7 +82,7 @@ public class CrmContactServiceImpl implements CrmContactService { | @@ -82,7 +82,7 @@ public class CrmContactServiceImpl implements CrmContactService { | ||
| 82 | * | 82 | * |
| 83 | * @param saveReqVO 新增/修改请求 VO | 83 | * @param saveReqVO 新增/修改请求 VO |
| 84 | */ | 84 | */ |
| 85 | - private void validateRelationDataExists(CrmContactBaseVO saveReqVO){ | 85 | + private void validateRelationDataExists(CrmContactBaseVO saveReqVO) { |
| 86 | // 1. 校验客户 | 86 | // 1. 校验客户 |
| 87 | if (saveReqVO.getCustomerId() != null && customerService.getCustomer(saveReqVO.getCustomerId()) == null) { | 87 | if (saveReqVO.getCustomerId() != null && customerService.getCustomer(saveReqVO.getCustomerId()) == null) { |
| 88 | throw exception(CUSTOMER_NOT_EXISTS); | 88 | throw exception(CUSTOMER_NOT_EXISTS); |
| @@ -98,12 +98,14 @@ public class CrmContactServiceImpl implements CrmContactService { | @@ -98,12 +98,14 @@ public class CrmContactServiceImpl implements CrmContactService { | ||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Override | 100 | @Override |
| 101 | - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE) | 101 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) |
| 102 | public void deleteContact(Long id) { | 102 | public void deleteContact(Long id) { |
| 103 | // 校验存在 | 103 | // 校验存在 |
| 104 | validateContactExists(id); | 104 | validateContactExists(id); |
| 105 | // 删除 | 105 | // 删除 |
| 106 | contactMapper.deleteById(id); | 106 | contactMapper.deleteById(id); |
| 107 | + // 删除数据权限 | ||
| 108 | + crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTACT.getType(), id); | ||
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | private void validateContactExists(Long id) { | 111 | private void validateContactExists(Long id) { |
| @@ -112,7 +114,6 @@ public class CrmContactServiceImpl implements CrmContactService { | @@ -112,7 +114,6 @@ public class CrmContactServiceImpl implements CrmContactService { | ||
| 112 | } | 114 | } |
| 113 | } | 115 | } |
| 114 | 116 | ||
| 115 | - // TODO 芋艿:是否要做数据权限的校验??? | ||
| 116 | @Override | 117 | @Override |
| 117 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.READ) | 118 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.READ) |
| 118 | public CrmContactDO getContact(Long id) { | 119 | public CrmContactDO getContact(Long id) { |
| @@ -120,28 +121,16 @@ public class CrmContactServiceImpl implements CrmContactService { | @@ -120,28 +121,16 @@ public class CrmContactServiceImpl implements CrmContactService { | ||
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | @Override | 123 | @Override |
| 123 | - public List<CrmContactDO> getContactList(Collection<Long> ids) { | 124 | + public List<CrmContactDO> getContactList(Collection<Long> ids, Long userId) { |
| 124 | if (CollUtil.isEmpty(ids)) { | 125 | if (CollUtil.isEmpty(ids)) { |
| 125 | return ListUtil.empty(); | 126 | return ListUtil.empty(); |
| 126 | } | 127 | } |
| 127 | - return contactMapper.selectBatchIds(ids); | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - @Override | ||
| 131 | - public PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO) { | ||
| 132 | - // TODO puhui999:后面要改成,基于数据权限的查询 | ||
| 133 | - return contactMapper.selectPage(pageReqVO); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - @Override | ||
| 137 | - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ) | ||
| 138 | - public PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageReqVO) { | ||
| 139 | - return contactMapper.selectPageByCustomer(pageReqVO); | 128 | + return contactMapper.selectBatchIds(ids, userId); |
| 140 | } | 129 | } |
| 141 | 130 | ||
| 142 | @Override | 131 | @Override |
| 143 | - public List<CrmContactDO> getContactList() { | ||
| 144 | - return contactMapper.selectList(); | 132 | + public PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO, Long userId) { |
| 133 | + return contactMapper.selectPage(pageReqVO, userId); | ||
| 145 | } | 134 | } |
| 146 | 135 | ||
| 147 | } | 136 | } |
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 { | @@ -79,7 +79,7 @@ public class CrmQueryWrapperUtils { | ||
| 79 | if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 | 79 | if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 |
| 80 | queryMapper.innerJoin(CrmPermissionDO.class, on -> | 80 | queryMapper.innerJoin(CrmPermissionDO.class, on -> |
| 81 | on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds) | 81 | on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds) |
| 82 | - .eq(CrmPermissionDO::getUserId, userId)); | 82 | + .in(CollUtil.isNotEmpty(bizIds), CrmPermissionDO::getUserId, userId)); |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 |