| | |
| | | package cn.iocoder.yudao.module.crm.service.customer; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.progress.CrmCustomerProgressSaveReqVO; |
| | | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| | | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerProgressDO; |
| | | import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerProgressMapper; |
| | | 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.permission.core.annotations.CrmPermission; |
| | | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| | | import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Resource |
| | | @Lazy |
| | | private CrmPermissionService permissionService; |
| | | |
| | | @Resource |
| | | private CrmCustomerService customerService; |
| | | |
| | | @Override |
| | | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#createReqVO.customerId", |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 异常提示里用的客户名称:解析失败时回退为 ID,避免异常分支再抛二次异常 |
| | | */ |
| | | private String getCustomerDisplayName(Long customerId) { |
| | | try { |
| | | CrmCustomerDO customer = customerService.getCustomer(customerId); |
| | | return customer != null && StrUtil.isNotBlank(customer.getName()) |
| | | ? customer.getName() : "ID=" + customerId; |
| | | } catch (Exception ex) { |
| | | return "ID=" + customerId; |
| | | } |
| | | } |
| | | |
| | | private CrmCustomerProgressDO validateProgressExists(Long id) { |
| | | CrmCustomerProgressDO progress = customerProgressMapper.selectById(id); |
| | | if (progress == null) { |
| | |
| | | } |
| | | |
| | | private void validateCustomerWritePermission(Long customerId) { |
| | | // 超管 / CRM 管理员与 @CrmPermission 切面保持一致,直接放行 |
| | | if (CrmPermissionUtils.isCrmAdmin()) { |
| | | return; |
| | | } |
| | | if (!permissionService.hasPermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customerId, |
| | | getLoginUserId(), CrmPermissionLevelEnum.WRITE)) { |
| | | throw exception(CRM_PERMISSION_DENIED, "客户洽谈进度"); |
| | | throw new ServiceException(CRM_PERMISSION_DENIED.getCode(), |
| | | "没有权限修改/删除客户[" + getCustomerDisplayName(customerId) |
| | | + "]的洽谈进度:您不是该客户的负责人或团队成员。请让客户负责人在客户详情「团队成员」中把您加入," |
| | | + "或切换到该客户负责人账号后重试。"); |
| | | } |
| | | } |
| | | |