diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java index c6fededc9..d23595290 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*; import cn.iocoder.yudao.module.crm.controller.admin.business.vo.status.CrmBusinessStatusQueryVO; import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypeQueryVO; -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.business.CrmBusinessStatusDO; @@ -121,9 +120,9 @@ public class CrmBusinessController { @GetMapping("/page-by-customer") @Operation(summary = "获得商机分页,基于指定客户") - public CommonResult> getBusinessPageByCustomer(@Valid CrmContractPageReqVO pageReqVO) { + public CommonResult> getBusinessPageByCustomer(@Valid CrmBusinessPageReqVO pageReqVO) { Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空"); - PageResult pageResult = businessService.getBusinessPageByCustomer(pageReqVO); + PageResult pageResult = businessService.getBusinessPageByCustomer(pageReqVO, getLoginUserId()); // 处理客户名称回显 // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; Set customerIds = pageResult.getList().stream() 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 d39b318da..dbdc0663d 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 @@ -125,7 +125,7 @@ public class CrmContactController { @Operation(summary = "获得联系人分页,基于指定客户") public CommonResult> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); - PageResult pageResult = contactService.getContactPage(pageVO, getLoginUserId()); + PageResult pageResult = contactService.getContactPageByCustomerId(pageVO, getLoginUserId()); return success(convertDetailContactPage(pageResult)); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java index 24426cd5a..623a9ab91 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java @@ -87,7 +87,7 @@ public class CrmContractController { @Operation(summary = "获得合同分页") @PreAuthorize("@ss.hasPermission('crm:contract:query')") public CommonResult> getContractPage(@Valid CrmContractPageReqVO pageVO) { - PageResult pageResult = contractService.getContractPage(pageVO); + PageResult pageResult = contractService.getContractPage(pageVO, getLoginUserId()); return success(convertDetailContractPage(pageResult)); } @@ -95,7 +95,7 @@ public class CrmContractController { @Operation(summary = "获得联系人分页,基于指定客户") public CommonResult> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) { Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); - PageResult pageResult = contractService.getContractPageByCustomer(pageVO); + PageResult pageResult = contractService.getContractPageByCustomer(pageVO, getLoginUserId()); return success(convertDetailContractPage(pageResult)); } @@ -105,7 +105,7 @@ public class CrmContractController { @OperateLog(type = EXPORT) public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - PageResult pageResult = contractService.getContractPage(exportReqVO); + PageResult pageResult = contractService.getContractPage(exportReqVO, getLoginUserId()); // 导出 Excel ExcelUtils.write(response, "合同.xls", "数据", CrmContractExcelVO.class, ContractConvert.INSTANCE.convertList02(pageResult.getList())); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java index 3074094b4..8e5d6750a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java @@ -33,7 +33,7 @@ public interface CrmBusinessMapper extends BaseMapperX { CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_BUSINESS.getType(), CrmBusinessDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool()); mpjLambdaWrapperX.selectAll(CrmBusinessDO.class) - .eq(CrmBusinessDO::getCustomerId, pageReqVO.getCustomerId()) // 必须传递 + .eqIfPresent(CrmBusinessDO::getCustomerId, pageReqVO.getCustomerId()) // 指定客户编号 .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) .orderByDesc(CrmBusinessDO::getId); return selectJoinPage(pageReqVO, CrmBusinessDO.class, mpjLambdaWrapperX); 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 0ea93ab41..266aceaa6 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 @@ -33,7 +33,7 @@ public interface CrmContactMapper extends BaseMapperX { CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContactDO::getId, userId, pageReqVO.getSceneType(), pageReqVO.getPool()); mpjLambdaWrapperX.selectAll(CrmContactDO.class) - .eq(CrmContactDO::getCustomerId, pageReqVO.getCustomerId()) // 必须传递 + .eqIfPresent(CrmContactDO::getCustomerId, pageReqVO.getCustomerId()) // 指定客户编号 .likeIfPresent(CrmContactDO::getName, pageReqVO.getName()) .eqIfPresent(CrmContactDO::getMobile, pageReqVO.getMobile()) .eqIfPresent(CrmContactDO::getTelephone, pageReqVO.getTelephone()) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java index a22912162..37452feb7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java @@ -2,11 +2,17 @@ package cn.iocoder.yudao.module.crm.dal.mysql.contract; 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.contract.vo.CrmContractPageReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; +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,22 +21,32 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface CrmContractMapper extends BaseMapperX { - default PageResult selectPage(CrmContractPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(CrmContractDO::getNo, reqVO.getNo()) - .likeIfPresent(CrmContractDO::getName, reqVO.getName()) - .eqIfPresent(CrmContractDO::getCustomerId, reqVO.getCustomerId()) - .eqIfPresent(CrmContractDO::getBusinessId, reqVO.getBusinessId()) - .orderByDesc(CrmContractDO::getId)); + default int updateOwnerUserIdById(Long id, Long ownerUserId) { + return update(new LambdaUpdateWrapper() + .eq(CrmContractDO::getId, id) + .set(CrmContractDO::getOwnerUserId, ownerUserId)); } - default PageResult selectPageByCustomer(CrmContractPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(CrmContractDO::getCustomerId, reqVO.getCustomerId()) // 必须传递 - .likeIfPresent(CrmContractDO::getNo, reqVO.getNo()) - .likeIfPresent(CrmContractDO::getName, reqVO.getName()) - .eqIfPresent(CrmContractDO::getBusinessId, reqVO.getBusinessId()) - .orderByDesc(CrmContractDO::getId)); + default PageResult selectPage(CrmContractPageReqVO pageReqVO, Long userId) { + MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); + // 构建数据权限连表条件 + CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), CrmContractDO::getId, + userId, pageReqVO.getSceneType(), pageReqVO.getPool()); + mpjLambdaWrapperX.selectAll(CrmContractDO.class) + .eqIfPresent(CrmContractDO::getCustomerId, pageReqVO.getCustomerId()) + .likeIfPresent(CrmContractDO::getNo, pageReqVO.getNo()) + .likeIfPresent(CrmContractDO::getName, pageReqVO.getName()) + .eqIfPresent(CrmContractDO::getCustomerId, pageReqVO.getCustomerId()) + .eqIfPresent(CrmContractDO::getBusinessId, pageReqVO.getBusinessId()) + .orderByDesc(CrmContractDO::getId); + return selectJoinPage(pageReqVO, CrmContractDO.class, mpjLambdaWrapperX); + } + + default List selectBatchIds(Collection ids, Long userId) { + MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); + // 构建数据权限连表条件 + CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId); + return selectJoinList(CrmContractDO.class, mpjLambdaWrapperX); } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java index 3c4a21cd4..c46f5f0bf 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusi 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.dal.dataobject.business.CrmBusinessDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import jakarta.validation.Valid; @@ -76,9 +75,10 @@ public interface CrmBusinessService { * 数据权限:基于 {@link CrmCustomerDO} 读取 * * @param pageReqVO 分页查询 + * @param userId 用户编号 * @return 联系人分页 */ - PageResult getBusinessPageByCustomer(CrmContractPageReqVO pageReqVO); + PageResult getBusinessPageByCustomer(CrmBusinessPageReqVO pageReqVO, Long userId); /** * 商机转移 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 6b63c905d..6e43944eb 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -7,13 +7,13 @@ import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusi 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.mysql.business.CrmBusinessMapper; 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 jakarta.annotation.Resource; @@ -38,6 +38,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { @Resource private CrmBusinessMapper businessMapper; + @Resource + private CrmCustomerService customerService; @Resource private CrmPermissionService crmPermissionService; @@ -109,10 +111,11 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { } @Override - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ) - public PageResult getBusinessPageByCustomer(CrmContractPageReqVO pageReqVO) { - //return businessMapper.selectPageByCustomer(pageReqVO); - return null; // TODO puhui999: 可以跟分页合并吗? + public PageResult getBusinessPageByCustomer(CrmBusinessPageReqVO pageReqVO, Long userId) { + // 校验客户存在 + customerService.validateCustomer(pageReqVO.getCustomerId()); + + return businessMapper.selectPage(pageReqVO, userId); } @Override 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 a37b96962..4306d8aea 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 @@ -68,4 +68,15 @@ public interface CrmContactService { */ PageResult getContactPage(CrmContactPageReqVO pageReqVO, Long userId); + /** + * 获得联系人分页 + * + * 数据权限:基于 {@link CrmContactDO} + * + * @param pageVO 分页查询 + * @param userId 用户编号 + * @return 联系人分页 + */ + PageResult getContactPageByCustomerId(CrmContactPageReqVO pageVO, 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 a4ca31072..9220a9e66 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 @@ -133,4 +133,12 @@ public class CrmContactServiceImpl implements CrmContactService { return contactMapper.selectPage(pageReqVO, userId); } + @Override + public PageResult getContactPageByCustomerId(CrmContactPageReqVO pageVO, Long userId) { + // 校验用户存在 + customerService.validateCustomer(pageVO.getCustomerId()); + + return contactMapper.selectPage(pageVO, userId); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java index e9162b1ca..0531dbe38 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java @@ -3,12 +3,12 @@ package cn.iocoder.yudao.module.crm.service.contract; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractCreateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; - import jakarta.validation.Valid; + import java.util.Collection; import java.util.List; @@ -64,9 +64,10 @@ public interface CrmContractService { * 数据权限:基于 {@link CrmContractDO} 读取 * * @param pageReqVO 分页查询 + * @param userId 用户编号 * @return 合同分页 */ - PageResult getContractPage(CrmContractPageReqVO pageReqVO); + PageResult getContractPage(CrmContractPageReqVO pageReqVO, Long userId); /** * 获得合同分页,基于指定客户 @@ -74,9 +75,12 @@ public interface CrmContractService { * 数据权限:基于 {@link CrmCustomerDO} 读取 * * @param pageReqVO 分页查询 + * @param userId 用户编号 * @return 联系人分页 */ - PageResult getContractPageByCustomer(CrmContractPageReqVO pageReqVO); + default PageResult getContractPageByCustomer(CrmContractPageReqVO pageReqVO, Long userId) { + return getContractPage(pageReqVO, userId); + } /** * 合同转移 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java index 731711a3a..23795f94e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java @@ -5,8 +5,8 @@ import cn.hutool.core.collection.ListUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractCreateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO; import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper; @@ -15,11 +15,11 @@ 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; @@ -56,7 +56,7 @@ public class CrmContractServiceImpl implements CrmContractService { @Override @Transactional(rollbackFor = Exception.class) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, level = CrmPermissionLevelEnum.WRITE) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) public void updateContract(CrmContractUpdateReqVO updateReqVO) { // 校验存在 validateContractExists(updateReqVO.getId()); @@ -67,12 +67,14 @@ public class CrmContractServiceImpl implements CrmContractService { @Override @Transactional(rollbackFor = Exception.class) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) public void deleteContract(Long id) { // 校验存在 validateContractExists(id); // 删除 contractMapper.deleteById(id); + // 删除数据权限 + crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTRACT.getType(), id); } private CrmContractDO validateContractExists(Long id) { @@ -83,7 +85,6 @@ public class CrmContractServiceImpl implements CrmContractService { return contract; } - // TODO 芋艿:是否要做数据权限的校验??? @Override @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.READ) public CrmContractDO getContract(Long id) { @@ -99,27 +100,24 @@ public class CrmContractServiceImpl implements CrmContractService { } @Override - public PageResult getContractPage(CrmContractPageReqVO pageReqVO) { - return contractMapper.selectPage(pageReqVO); - } - - @Override - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ) - public PageResult getContractPageByCustomer(CrmContractPageReqVO pageReqVO) { - return contractMapper.selectPageByCustomer(pageReqVO); + public PageResult getContractPage(CrmContractPageReqVO pageReqVO, Long userId) { + return contractMapper.selectPage(pageReqVO, userId); } @Override @Transactional(rollbackFor = Exception.class) public void transferContract(CrmContractTransferReqVO reqVO, Long userId) { - // 1 校验合同是否存在 + // 1. 校验合同是否存在 validateContractExists(reqVO.getId()); - // 2. 数据权限转移 + // 2.1 数据权限转移 crmPermissionService.transferPermission( ContractConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType())); + // 2.2 设置负责人 + contractMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); // 3. TODO 记录转移日志 + } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java index 1bd1fee47..73be18951 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java @@ -71,9 +71,8 @@ public interface CrmCustomerService { * 校验客户是否存在 * * @param customerId 客户 id - * @return 客户 */ - CrmCustomerDO validateCustomer(Long customerId); + void validateCustomer(Long customerId); /** * 客户转移 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index 24d9612e2..93589a5b0 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java @@ -111,15 +111,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { * 校验客户是否存在 * * @param customerId 客户 id - * @return 客户 */ @Override - public CrmCustomerDO validateCustomer(Long customerId) { - CrmCustomerDO customer = getCustomer(customerId); + public void validateCustomer(Long customerId) { + // TODO puhui999: 不返回客户不走校验应该可行 + // 校验客户是否存在 + if (customerId == null) { + throw exception(CUSTOMER_NOT_EXISTS); + } + CrmCustomerDO customer = customerMapper.selectById(customerId); if (Objects.isNull(customer)) { throw exception(CUSTOMER_NOT_EXISTS); } - return customer; } @Override diff --git a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java index 1ff32be15..8b07804c2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java @@ -147,7 +147,7 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest { reqVO.setMobile(null); // 调用 - PageResult pageResult = clueService.getCluePage(reqVO, getLoginUserId()); + PageResult pageResult = clueService.getCluePage(reqVO, 1L); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImplTest.java b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImplTest.java index 35825df19..145d75325 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImplTest.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImplTest.java @@ -7,12 +7,11 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageR import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper; +import jakarta.annotation.Resource; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; -import jakarta.annotation.Resource; - import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; @@ -127,7 +126,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest { reqVO.setNo(null); // 调用 - PageResult pageResult = contractService.getContractPage(reqVO); + PageResult pageResult = contractService.getContractPage(reqVO, getLoginUserId()); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size());