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