From 19c9b6ae93d42b440c87a505b8e4a82ac9c4edb8 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 30 Oct 2023 11:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20CRM-=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/crm/enums/ErrorCodeConstants.java | 3 + .../permission/CrmPermissionConvert.java | 23 +++++++ .../permission/CrmPermissionDO.java | 57 ++++++++++++++++ .../mysql/permission/CrmPermissionMapper.java | 14 ++++ .../dal/mysql/permission/package-info.java | 1 + .../permission/CrmPermissionService.java | 47 +++++++++++++ .../permission/CrmPermissionServiceImpl.java | 66 +++++++++++++++++++ .../permission/bo/CrmPermissionCreateBO.java | 40 +++++++++++ .../permission/bo/CrmPermissionUpdateBO.java | 47 +++++++++++++ 9 files changed, 298 insertions(+) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/package-info.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index b4f909a8b..bde7a3df5 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/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 { // ========== 客户管理 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, "数据权限不存在"); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java new file mode 100644 index 000000000..0fc6f61cc --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java @@ -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); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java new file mode 100644 index 000000000..44a44fa6d --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java @@ -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") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 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 roUserIds; + /** + * 读写权限的用户编号数组 + */ + @TableField(typeHandler = JsonLongSetTypeHandler.class) + private Set rwUserIds; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java new file mode 100644 index 000000000..44b7b270b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java @@ -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 { +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/package-info.java new file mode 100644 index 000000000..ff0e16b90 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.permission; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java new file mode 100644 index 000000000..ef064fd87 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java @@ -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); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java new file mode 100644 index 000000000..d0df3eee7 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java @@ -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); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java new file mode 100644 index 000000000..8c9b16376 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java @@ -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 roUserIds; + /** + * 读写权限的用户编号数组 + */ + private Set rwUserIds; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java new file mode 100644 index 000000000..3b00eb644 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java @@ -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 roUserIds; + /** + * 读写权限的用户编号数组 + */ + private Set rwUserIds; + +}