diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerContactServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerContactServiceImpl.java index c2a50aa2..ababc8bd 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerContactServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerContactServiceImpl.java @@ -1,6 +1,9 @@ package org.dromara.oa.crm.service.impl; import cn.dev33.satoken.stp.StpUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -156,7 +159,23 @@ public class CrmCustomerContactServiceImpl implements ICrmCustomerContactService * 保存前的数据校验 */ private void validEntityBeforeSave(CrmCustomerContact entity) { - //TODO 做一些数据校验,如唯一约束 + if (entity == null) { + return; + } + if (entity.getCustomerId() == null || StringUtils.isBlank(entity.getContactName())) { + return; + } + String contactName = StringUtils.trim(entity.getContactName()); + entity.setContactName(contactName); + LambdaQueryWrapper qw = Wrappers.lambdaQuery(CrmCustomerContact.class) + .eq(CrmCustomerContact::getCustomerId, entity.getCustomerId()) + .eq(CrmCustomerContact::getContactName, contactName); + if (entity.getContactId() != null) { + qw.ne(CrmCustomerContact::getContactId, entity.getContactId()); + } + if (baseMapper.selectCount(qw) > 0) { + throw new ServiceException("同一客户下联系人姓名不能重复"); + } } /** diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerInfoServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerInfoServiceImpl.java index e7f80bf6..ed24d852 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerInfoServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmCustomerInfoServiceImpl.java @@ -8,6 +8,8 @@ import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.satoken.utils.LoginHelper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; @@ -34,7 +36,7 @@ import java.util.Collection; public class CrmCustomerInfoServiceImpl implements ICrmCustomerInfoService { /** - * 客户管理员角色权限字符 + * 客户管理员角色权限字符(sys_role.role_key),拥有后可查看/维护全部客户数据 */ private static final String CRM_CUSTOMER_ADMIN_ROLE_KEY = "KHMA"; @@ -47,6 +49,22 @@ public class CrmCustomerInfoServiceImpl implements ICrmCustomerInfoService { return LoginHelper.isSuperAdmin() || StpUtil.hasRole(CRM_CUSTOMER_ADMIN_ROLE_KEY); } + /** + * 非客户管理员仅能访问本人创建的客户(create_by 为当前用户ID) + */ + private void assertCustomerRowAccess(CrmCustomerInfo entity) { + if (entity == null) { + throw new ServiceException("客户信息不存在"); + } + if (isCrmCustomerDataAdmin()) { + return; + } + Long userId = LoginHelper.getUserId(); + if (!ObjectUtil.equal(userId, entity.getCreateBy())) { + throw new ServiceException("无权限访问该客户信息"); + } + } + /** * 无客户管理员角色时仅查询本人创建的数据 */ @@ -161,8 +179,23 @@ public class CrmCustomerInfoServiceImpl implements ICrmCustomerInfoService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(CrmCustomerInfo entity){ - //TODO 做一些数据校验,如唯一约束 + private void validEntityBeforeSave(CrmCustomerInfo entity) { + if (entity == null) { + return; + } + if (StringUtils.isBlank(entity.getCustomerName())) { + return; + } + String customerName = StringUtils.trim(entity.getCustomerName()); + entity.setCustomerName(customerName); + LambdaQueryWrapper qw = Wrappers.lambdaQuery(CrmCustomerInfo.class) + .eq(CrmCustomerInfo::getCustomerName, customerName); + if (entity.getCustomerId() != null) { + qw.ne(CrmCustomerInfo::getCustomerId, entity.getCustomerId()); + } + if (baseMapper.selectCount(qw) > 0) { + throw new ServiceException("客户名称已存在,不能重复"); + } } /**