Commit 19c9b6ae93d42b440c87a505b8e4a82ac9c4edb8
1 parent
bec8a27a
新增 CRM-数据权限 service
Showing
9 changed files
with
298 additions
and
0 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| ... | ... | @@ -41,4 +41,7 @@ public interface ErrorCodeConstants { |
| 41 | 41 | // ========== 客户管理 1_020_006_000 ========== |
| 42 | 42 | ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在"); |
| 43 | 43 | |
| 44 | + // ========== 客户管理 1_020_007_000 ========== | |
| 45 | + ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在"); | |
| 46 | + | |
| 44 | 47 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.convert.permission; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 4 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | |
| 5 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; | |
| 6 | +import org.mapstruct.Mapper; | |
| 7 | +import org.mapstruct.factory.Mappers; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Crm 数据权限 Convert | |
| 11 | + * | |
| 12 | + * @author Wanwan | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface CrmPermissionConvert { | |
| 16 | + | |
| 17 | + CrmPermissionConvert INSTANCE = Mappers.getMapper(CrmPermissionConvert.class); | |
| 18 | + | |
| 19 | + CrmPermissionDO convert(CrmPermissionCreateBO createBO); | |
| 20 | + | |
| 21 | + CrmPermissionDO convert(CrmPermissionUpdateBO updateBO); | |
| 22 | + | |
| 23 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.dataobject.permission; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; | |
| 5 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | |
| 6 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 8 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 9 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 10 | +import lombok.*; | |
| 11 | + | |
| 12 | +import java.util.Set; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * crm 数据权限 DO | |
| 16 | + * | |
| 17 | + * @author HUIHUI | |
| 18 | + */ | |
| 19 | +@TableName("crm_receivable") | |
| 20 | +@KeySequence("crm_receivable_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 21 | +@Data | |
| 22 | +@EqualsAndHashCode(callSuper = true) | |
| 23 | +@ToString(callSuper = true) | |
| 24 | +@Builder | |
| 25 | +@NoArgsConstructor | |
| 26 | +@AllArgsConstructor | |
| 27 | +public class CrmPermissionDO extends BaseDO { | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * ID | |
| 31 | + */ | |
| 32 | + @TableId | |
| 33 | + private Long id; | |
| 34 | + /** | |
| 35 | + * 数据类型 关联 {@link CrmEnum} | |
| 36 | + */ | |
| 37 | + private Integer crmType; | |
| 38 | + /** | |
| 39 | + * 数据编号 关联 {@link CrmEnum} 对应模块 DO#id | |
| 40 | + */ | |
| 41 | + private Integer crmDataId; | |
| 42 | + /** | |
| 43 | + * 负责人的用户编号 关联 AdminUser#id | |
| 44 | + */ | |
| 45 | + private Long ownerUserId; | |
| 46 | + /** | |
| 47 | + * 只读权限的用户编号数组 | |
| 48 | + */ | |
| 49 | + @TableField(typeHandler = JsonLongSetTypeHandler.class) | |
| 50 | + private Set<Long> roUserIds; | |
| 51 | + /** | |
| 52 | + * 读写权限的用户编号数组 | |
| 53 | + */ | |
| 54 | + @TableField(typeHandler = JsonLongSetTypeHandler.class) | |
| 55 | + private Set<Long> rwUserIds; | |
| 56 | + | |
| 57 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.mysql.permission; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * crm 数据权限 mapper | |
| 9 | + * | |
| 10 | + * @author HUIHUI | |
| 11 | + */ | |
| 12 | +@Mapper | |
| 13 | +public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> { | |
| 14 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/package-info.java
0 → 100644
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.permission; | |
| 2 | + | |
| 3 | + | |
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 5 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | |
| 6 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; | |
| 7 | + | |
| 8 | +import javax.validation.Valid; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * crm 数据权限 Service 接口 | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +public interface CrmPermissionService { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 创建数据权限 | |
| 19 | + * | |
| 20 | + * @param createBO 创建信息 | |
| 21 | + * @return 编号 | |
| 22 | + */ | |
| 23 | + Long createCrmPermission(@Valid CrmPermissionCreateBO createBO); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 更新数据权限 | |
| 27 | + * | |
| 28 | + * @param updateBO 更新信息 | |
| 29 | + */ | |
| 30 | + void updateCrmPermission(@Valid CrmPermissionUpdateBO updateBO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 删除数据权限 | |
| 34 | + * | |
| 35 | + * @param id 编号 | |
| 36 | + */ | |
| 37 | + void deleteCrmPermission(Long id); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 获得数据权限 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + * @return 数据权限 | |
| 44 | + */ | |
| 45 | + CrmPermissionDO getCrmPermission(Long id); | |
| 46 | + | |
| 47 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.permission; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.crm.convert.permission.CrmPermissionConvert; | |
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 5 | +import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper; | |
| 6 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | |
| 7 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; | |
| 8 | +import org.springframework.stereotype.Service; | |
| 9 | +import org.springframework.transaction.annotation.Transactional; | |
| 10 | +import org.springframework.validation.annotation.Validated; | |
| 11 | + | |
| 12 | +import javax.annotation.Resource; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 15 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_NOT_EXISTS; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * crm 数据权限 Service 接口实现类 | |
| 19 | + * | |
| 20 | + * @author HUIHUI | |
| 21 | + */ | |
| 22 | +@Service | |
| 23 | +@Validated | |
| 24 | +public class CrmPermissionServiceImpl implements CrmPermissionService { | |
| 25 | + | |
| 26 | + @Resource | |
| 27 | + private CrmPermissionMapper crmPermissionMapper; | |
| 28 | + | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + @Transactional(rollbackFor = Exception.class) | |
| 32 | + public Long createCrmPermission(CrmPermissionCreateBO createBO) { | |
| 33 | + CrmPermissionDO createDO = CrmPermissionConvert.INSTANCE.convert(createBO); | |
| 34 | + crmPermissionMapper.insert(createDO); | |
| 35 | + return createDO.getId(); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + @Transactional(rollbackFor = Exception.class) | |
| 40 | + public void updateCrmPermission(CrmPermissionUpdateBO updateBO) { | |
| 41 | + validateCrmPermissionExists(updateBO.getId()); | |
| 42 | + | |
| 43 | + CrmPermissionDO updateDO = CrmPermissionConvert.INSTANCE.convert(updateBO); | |
| 44 | + crmPermissionMapper.updateById(updateDO); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Override | |
| 48 | + @Transactional(rollbackFor = Exception.class) | |
| 49 | + public void deleteCrmPermission(Long id) { | |
| 50 | + validateCrmPermissionExists(id); | |
| 51 | + | |
| 52 | + crmPermissionMapper.deleteById(id); | |
| 53 | + } | |
| 54 | + | |
| 55 | + private void validateCrmPermissionExists(Long id) { | |
| 56 | + if (crmPermissionMapper.selectById(id) == null) { | |
| 57 | + throw exception(CRM_PERMISSION_NOT_EXISTS); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public CrmPermissionDO getCrmPermission(Long id) { | |
| 63 | + return crmPermissionMapper.selectById(id); | |
| 64 | + } | |
| 65 | + | |
| 66 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.permission.bo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import javax.validation.constraints.NotNull; | |
| 7 | +import java.util.Set; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * crm 数据权限 Create BO | |
| 11 | + * | |
| 12 | + * @author HUIHUI | |
| 13 | + */ | |
| 14 | +@Data | |
| 15 | +public class CrmPermissionCreateBO { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Crm 类型 关联 {@link CrmEnum} | |
| 19 | + */ | |
| 20 | + @NotNull(message = "Crm 类型不能为空") | |
| 21 | + private Integer crmType; | |
| 22 | + /** | |
| 23 | + * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | |
| 24 | + */ | |
| 25 | + @NotNull(message = "Crm 数据编号不能为空") | |
| 26 | + private Integer crmDataId; | |
| 27 | + /** | |
| 28 | + * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 | |
| 29 | + */ | |
| 30 | + private Long ownerUserId; | |
| 31 | + /** | |
| 32 | + * 只读权限的用户编号数组 | |
| 33 | + */ | |
| 34 | + private Set<Long> roUserIds; | |
| 35 | + /** | |
| 36 | + * 读写权限的用户编号数组 | |
| 37 | + */ | |
| 38 | + private Set<Long> rwUserIds; | |
| 39 | + | |
| 40 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.permission.bo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 4 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | +import java.util.Set; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * crm 数据权限 Update BO | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@Data | |
| 16 | +public class CrmPermissionUpdateBO { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 数据权限编号 {@link CrmPermissionDO#getId()} | |
| 20 | + */ | |
| 21 | + @NotNull(message = "Crm 数据权限编号不能为空") | |
| 22 | + private Long id; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Crm 类型 关联 {@link CrmEnum} | |
| 26 | + */ | |
| 27 | + @NotNull(message = "Crm 类型不能为空") | |
| 28 | + private Integer crmType; | |
| 29 | + /** | |
| 30 | + * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | |
| 31 | + */ | |
| 32 | + @NotNull(message = "Crm 数据编号不能为空") | |
| 33 | + private Integer crmDataId; | |
| 34 | + /** | |
| 35 | + * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 | |
| 36 | + */ | |
| 37 | + private Long ownerUserId; | |
| 38 | + /** | |
| 39 | + * 只读权限的用户编号数组 | |
| 40 | + */ | |
| 41 | + private Set<Long> roUserIds; | |
| 42 | + /** | |
| 43 | + * 读写权限的用户编号数组 | |
| 44 | + */ | |
| 45 | + private Set<Long> rwUserIds; | |
| 46 | + | |
| 47 | +} | ... | ... |