1.1.40 客户、客户联系人信息唯一校验

dev
yinq 1 month ago
parent dc98061b74
commit 2f1791a176

@ -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<CrmCustomerContact> 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("同一客户下联系人姓名不能重复");
}
}
/**

@ -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<CrmCustomerInfo> 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("客户名称已存在,不能重复");
}
}
/**

Loading…
Cancel
Save