新增 CRM-数据权限 service

This commit is contained in:
puhui999 2023-10-30 11:17:43 +08:00
parent bec8a27a21
commit 19c9b6ae93
9 changed files with 298 additions and 0 deletions

View File

@ -41,4 +41,7 @@ public interface ErrorCodeConstants {
// ========== 客户管理 1_020_006_000 ==========
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
// ========== 客户管理 1_020_007_000 ==========
ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.crm.convert.permission;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* Crm 数据权限 Convert
*
* @author Wanwan
*/
@Mapper
public interface CrmPermissionConvert {
CrmPermissionConvert INSTANCE = Mappers.getMapper(CrmPermissionConvert.class);
CrmPermissionDO convert(CrmPermissionCreateBO createBO);
CrmPermissionDO convert(CrmPermissionUpdateBO updateBO);
}

View File

@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.permission;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.Set;
/**
* crm 数据权限 DO
*
* @author HUIHUI
*/
@TableName("crm_receivable")
@KeySequence("crm_receivable_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CrmPermissionDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
* 数据类型 关联 {@link CrmEnum}
*/
private Integer crmType;
/**
* 数据编号 关联 {@link CrmEnum} 对应模块 DO#id
*/
private Integer crmDataId;
/**
* 负责人的用户编号 关联 AdminUser#id
*/
private Long ownerUserId;
/**
* 只读权限的用户编号数组
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> roUserIds;
/**
* 读写权限的用户编号数组
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> rwUserIds;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.crm.dal.mysql.permission;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import org.apache.ibatis.annotations.Mapper;
/**
* crm 数据权限 mapper
*
* @author HUIHUI
*/
@Mapper
public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
}

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.crm.dal.mysql.permission;

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.crm.service.permission;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO;
import javax.validation.Valid;
/**
* crm 数据权限 Service 接口
*
* @author HUIHUI
*/
public interface CrmPermissionService {
/**
* 创建数据权限
*
* @param createBO 创建信息
* @return 编号
*/
Long createCrmPermission(@Valid CrmPermissionCreateBO createBO);
/**
* 更新数据权限
*
* @param updateBO 更新信息
*/
void updateCrmPermission(@Valid CrmPermissionUpdateBO updateBO);
/**
* 删除数据权限
*
* @param id 编号
*/
void deleteCrmPermission(Long id);
/**
* 获得数据权限
*
* @param id 编号
* @return 数据权限
*/
CrmPermissionDO getCrmPermission(Long id);
}

View File

@ -0,0 +1,66 @@
package cn.iocoder.yudao.module.crm.service.permission;
import cn.iocoder.yudao.module.crm.convert.permission.CrmPermissionConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_NOT_EXISTS;
/**
* crm 数据权限 Service 接口实现类
*
* @author HUIHUI
*/
@Service
@Validated
public class CrmPermissionServiceImpl implements CrmPermissionService {
@Resource
private CrmPermissionMapper crmPermissionMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createCrmPermission(CrmPermissionCreateBO createBO) {
CrmPermissionDO createDO = CrmPermissionConvert.INSTANCE.convert(createBO);
crmPermissionMapper.insert(createDO);
return createDO.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCrmPermission(CrmPermissionUpdateBO updateBO) {
validateCrmPermissionExists(updateBO.getId());
CrmPermissionDO updateDO = CrmPermissionConvert.INSTANCE.convert(updateBO);
crmPermissionMapper.updateById(updateDO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteCrmPermission(Long id) {
validateCrmPermissionExists(id);
crmPermissionMapper.deleteById(id);
}
private void validateCrmPermissionExists(Long id) {
if (crmPermissionMapper.selectById(id) == null) {
throw exception(CRM_PERMISSION_NOT_EXISTS);
}
}
@Override
public CrmPermissionDO getCrmPermission(Long id) {
return crmPermissionMapper.selectById(id);
}
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.crm.service.permission.bo;
import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Set;
/**
* crm 数据权限 Create BO
*
* @author HUIHUI
*/
@Data
public class CrmPermissionCreateBO {
/**
* Crm 类型 关联 {@link CrmEnum}
*/
@NotNull(message = "Crm 类型不能为空")
private Integer crmType;
/**
* 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId()
*/
@NotNull(message = "Crm 数据编号不能为空")
private Integer crmDataId;
/**
* 负责人的用户编号 关联 AdminUser#id, null 则为公海数据
*/
private Long ownerUserId;
/**
* 只读权限的用户编号数组
*/
private Set<Long> roUserIds;
/**
* 读写权限的用户编号数组
*/
private Set<Long> rwUserIds;
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.crm.service.permission.bo;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Set;
/**
* crm 数据权限 Update BO
*
* @author HUIHUI
*/
@Data
public class CrmPermissionUpdateBO {
/**
* 数据权限编号 {@link CrmPermissionDO#getId()}
*/
@NotNull(message = "Crm 数据权限编号不能为空")
private Long id;
/**
* Crm 类型 关联 {@link CrmEnum}
*/
@NotNull(message = "Crm 类型不能为空")
private Integer crmType;
/**
* 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId()
*/
@NotNull(message = "Crm 数据编号不能为空")
private Integer crmDataId;
/**
* 负责人的用户编号 关联 AdminUser#id, null 则为公海数据
*/
private Long ownerUserId;
/**
* 只读权限的用户编号数组
*/
private Set<Long> roUserIds;
/**
* 读写权限的用户编号数组
*/
private Set<Long> rwUserIds;
}