From 9c1687dc251f042a25b20cb9bfe36486a5c69131 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 5 Dec 2023 11:00:34 +0800 Subject: [PATCH] =?UTF-8?q?CRM:=20=E6=96=B0=E5=A2=9E=E5=85=B3=E6=B3=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/crm/enums/ErrorCodeConstants.java | 5 +- .../dataobject/concerned/CrmConcernedDO.java | 51 +++++++++++++ .../mysql/concerned/CrmConcernedMapper.java | 35 +++++++++ .../concerned/CrmConcernedService.java | 40 +++++++++++ .../concerned/CrmConcernedServiceImpl.java | 71 +++++++++++++++++++ .../concerned/bo/CrmConcernedCreateReqBO.java | 35 +++++++++ 6 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/concerned/CrmConcernedDO.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/concerned/CrmConcernedMapper.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedService.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedServiceImpl.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/bo/CrmConcernedCreateReqBO.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 ea5b7aaa0..da5023fa9 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 @@ -63,7 +63,10 @@ public interface ErrorCodeConstants { // ========== 商机状态 1_020_011_000 ========== ErrorCode BUSINESS_STATUS_NOT_EXISTS = new ErrorCode(1_020_011_000, "商机状态不存在"); - // ========== 客户公海规则设置 1_020_011_000 ========== + // ========== 客户公海规则设置 1_020_012_000 ========== ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_012_000, "客户限制配置不存在"); + // ========== 关注的数据 1_020_013_000 ========== + ErrorCode CRM_CONCERNED_NOT_EXISTS = new ErrorCode(1_020_013_000, "关注数据不存在"); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/concerned/CrmConcernedDO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/concerned/CrmConcernedDO.java new file mode 100644 index 000000000..14c02687b --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/concerned/CrmConcernedDO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.crm.dal.dataobject.concerned; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +/** + * CRM 关注的数据 DO + * + * @author HUIHUI + */ +@TableName("crm_concerned") +@KeySequence("crm_concerned_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CrmConcernedDO extends BaseDO { + + /** + * 编号,主键自增 + */ + @TableId + private Long id; + + /** + * 数据类型 + * + * 枚举 {@link CrmBizTypeEnum} + */ + private Integer bizType; + /** + * 数据编号 + * + * 关联 {@link CrmBizTypeEnum} 对应模块 DO 的 id 字段 + */ + private Long bizId; + + /** + * 用户编号 + * + * 关联 AdminUser 的 id 字段 + */ + private Long userId; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/concerned/CrmConcernedMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/concerned/CrmConcernedMapper.java new file mode 100644 index 000000000..5812d4546 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/concerned/CrmConcernedMapper.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.concerned; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.crm.dal.dataobject.concerned.CrmConcernedDO; +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import org.apache.ibatis.annotations.Mapper; + +import java.util.Collection; +import java.util.List; + +/** + * CRM 关注的数据 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CrmConcernedMapper extends BaseMapperX { + + /** + * 查询用户关注的数据 + * + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} + * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() + * @param userId 用户编号 + * @return 关注的数据 + */ + default List selectList(Integer bizType, Collection bizIds, Long userId) { + return selectList(new LambdaQueryWrapperX() + .eq(CrmConcernedDO::getBizType, bizType) + .in(CrmConcernedDO::getBizId, bizIds) + .eq(CrmConcernedDO::getUserId, userId)); + } + +} \ 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/concerned/CrmConcernedService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedService.java new file mode 100644 index 000000000..4c24b6a15 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedService.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.crm.service.concerned; + +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import cn.iocoder.yudao.module.crm.service.concerned.bo.CrmConcernedCreateReqBO; + +import javax.validation.Valid; +import java.util.Collection; + +/** + * CRM 关注的数据 Service 接口 + * + * @author HUIHUI + */ +public interface CrmConcernedService { + + /** + * 创建关注数据 + * + * @param createReqBO 创建请求 + * @return 编号 + */ + Long createConcerned(@Valid CrmConcernedCreateReqBO createReqBO); + + /** + * 批量创建关注数据 + * + * @param createReqBO 创建请求 + */ + void createConcernedBatch(@Valid Collection createReqBO); + + /** + * 删除关注数据 + * + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} + * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() + * @param userId 用户编号 + */ + void deleteConcerned(Integer bizType, Collection bizIds, Long userId); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedServiceImpl.java new file mode 100644 index 000000000..62a91694e --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedServiceImpl.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.module.crm.service.concerned; + +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.crm.dal.dataobject.concerned.CrmConcernedDO; +import cn.iocoder.yudao.module.crm.dal.mysql.concerned.CrmConcernedMapper; +import cn.iocoder.yudao.module.crm.service.concerned.bo.CrmConcernedCreateReqBO; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_CONCERNED_NOT_EXISTS; + +/** + * CRM 关注的数据 Service 接口实现类 + * + * @author HUIHUI + */ +@Service +@Validated +public class CrmConcernedServiceImpl implements CrmConcernedService { + + @Resource + private CrmConcernedMapper concernedMapper; + @Resource + private AdminUserApi adminUserApi; + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createConcerned(CrmConcernedCreateReqBO createReqBO) { + // 1. 校验用户是否存在 + adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId())); + + // 2. 创建 + CrmConcernedDO concerned = BeanUtils.toBean(createReqBO, CrmConcernedDO.class); + concernedMapper.insert(concerned); + return concerned.getId(); + } + + @Override + public void createConcernedBatch(Collection createReqBO) { + // 1. 校验用户是否存在 + adminUserApi.validateUserList(convertSet(createReqBO, CrmConcernedCreateReqBO::getUserId)); + + // 2. 创建 + List concernedList = convertList(createReqBO, item -> BeanUtils.toBean(item, CrmConcernedDO.class)); + concernedMapper.insertBatch(concernedList); + } + + @Override + public void deleteConcerned(Integer bizType, Collection bizIds, Long userId) { + // 1. 查询关注数据 + List concernedList = concernedMapper.selectList(bizType, bizIds, userId); + if (ObjUtil.notEqual(bizIds.size(), concernedList.size())) { + throw exception(CRM_CONCERNED_NOT_EXISTS); + } + + // 2. 删除 + concernedMapper.deleteBatchIds(convertList(concernedList, CrmConcernedDO::getId)); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/bo/CrmConcernedCreateReqBO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/bo/CrmConcernedCreateReqBO.java new file mode 100644 index 000000000..aa6ff2642 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/bo/CrmConcernedCreateReqBO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.crm.service.concerned.bo; + +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * CRM 关注的数据 Create Req BO + * + * @author HUIHUI + */ +@Data +public class CrmConcernedCreateReqBO { + + /** + * 当前登录用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Long userId; + + /** + * Crm 类型 + */ + @NotNull(message = "Crm 类型不能为空") + @InEnum(CrmBizTypeEnum.class) + private Integer bizType; + /** + * 数据编号 + */ + @NotNull(message = "Crm 数据编号不能为空") + private Long bizId; + +}