Commit 9c1687dc251f042a25b20cb9bfe36486a5c69131
1 parent
72969e92
CRM: 新增关注数据模块
Showing
6 changed files
with
236 additions
and
1 deletions
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 { | @@ -63,7 +63,10 @@ public interface ErrorCodeConstants { | ||
| 63 | // ========== 商机状态 1_020_011_000 ========== | 63 | // ========== 商机状态 1_020_011_000 ========== |
| 64 | ErrorCode BUSINESS_STATUS_NOT_EXISTS = new ErrorCode(1_020_011_000, "商机状态不存在"); | 64 | ErrorCode BUSINESS_STATUS_NOT_EXISTS = new ErrorCode(1_020_011_000, "商机状态不存在"); |
| 65 | 65 | ||
| 66 | - // ========== 客户公海规则设置 1_020_011_000 ========== | 66 | + // ========== 客户公海规则设置 1_020_012_000 ========== |
| 67 | ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_012_000, "客户限制配置不存在"); | 67 | ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_012_000, "客户限制配置不存在"); |
| 68 | 68 | ||
| 69 | + // ========== 关注的数据 1_020_013_000 ========== | ||
| 70 | + ErrorCode CRM_CONCERNED_NOT_EXISTS = new ErrorCode(1_020_013_000, "关注数据不存在"); | ||
| 71 | + | ||
| 69 | } | 72 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/concerned/CrmConcernedDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.dataobject.concerned; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | +import lombok.*; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * CRM 关注的数据 DO | ||
| 12 | + * | ||
| 13 | + * @author HUIHUI | ||
| 14 | + */ | ||
| 15 | +@TableName("crm_concerned") | ||
| 16 | +@KeySequence("crm_concerned_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 17 | +@Data | ||
| 18 | +@EqualsAndHashCode(callSuper = true) | ||
| 19 | +@ToString(callSuper = true) | ||
| 20 | +@Builder | ||
| 21 | +@NoArgsConstructor | ||
| 22 | +@AllArgsConstructor | ||
| 23 | +public class CrmConcernedDO extends BaseDO { | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 编号,主键自增 | ||
| 27 | + */ | ||
| 28 | + @TableId | ||
| 29 | + private Long id; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 数据类型 | ||
| 33 | + * | ||
| 34 | + * 枚举 {@link CrmBizTypeEnum} | ||
| 35 | + */ | ||
| 36 | + private Integer bizType; | ||
| 37 | + /** | ||
| 38 | + * 数据编号 | ||
| 39 | + * | ||
| 40 | + * 关联 {@link CrmBizTypeEnum} 对应模块 DO 的 id 字段 | ||
| 41 | + */ | ||
| 42 | + private Long bizId; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 用户编号 | ||
| 46 | + * | ||
| 47 | + * 关联 AdminUser 的 id 字段 | ||
| 48 | + */ | ||
| 49 | + private Long userId; | ||
| 50 | + | ||
| 51 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/concerned/CrmConcernedMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.mysql.concerned; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 5 | +import cn.iocoder.yudao.module.crm.dal.dataobject.concerned.CrmConcernedDO; | ||
| 6 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 7 | +import org.apache.ibatis.annotations.Mapper; | ||
| 8 | + | ||
| 9 | +import java.util.Collection; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * CRM 关注的数据 Mapper | ||
| 14 | + * | ||
| 15 | + * @author HUIHUI | ||
| 16 | + */ | ||
| 17 | +@Mapper | ||
| 18 | +public interface CrmConcernedMapper extends BaseMapperX<CrmConcernedDO> { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 查询用户关注的数据 | ||
| 22 | + * | ||
| 23 | + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | ||
| 24 | + * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | ||
| 25 | + * @param userId 用户编号 | ||
| 26 | + * @return 关注的数据 | ||
| 27 | + */ | ||
| 28 | + default List<CrmConcernedDO> selectList(Integer bizType, Collection<Long> bizIds, Long userId) { | ||
| 29 | + return selectList(new LambdaQueryWrapperX<CrmConcernedDO>() | ||
| 30 | + .eq(CrmConcernedDO::getBizType, bizType) | ||
| 31 | + .in(CrmConcernedDO::getBizId, bizIds) | ||
| 32 | + .eq(CrmConcernedDO::getUserId, userId)); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | +} | ||
| 0 | \ No newline at end of file | 36 | \ No newline at end of file |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.concerned; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 4 | +import cn.iocoder.yudao.module.crm.service.concerned.bo.CrmConcernedCreateReqBO; | ||
| 5 | + | ||
| 6 | +import javax.validation.Valid; | ||
| 7 | +import java.util.Collection; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * CRM 关注的数据 Service 接口 | ||
| 11 | + * | ||
| 12 | + * @author HUIHUI | ||
| 13 | + */ | ||
| 14 | +public interface CrmConcernedService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 创建关注数据 | ||
| 18 | + * | ||
| 19 | + * @param createReqBO 创建请求 | ||
| 20 | + * @return 编号 | ||
| 21 | + */ | ||
| 22 | + Long createConcerned(@Valid CrmConcernedCreateReqBO createReqBO); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 批量创建关注数据 | ||
| 26 | + * | ||
| 27 | + * @param createReqBO 创建请求 | ||
| 28 | + */ | ||
| 29 | + void createConcernedBatch(@Valid Collection<CrmConcernedCreateReqBO> createReqBO); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 删除关注数据 | ||
| 33 | + * | ||
| 34 | + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} | ||
| 35 | + * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() | ||
| 36 | + * @param userId 用户编号 | ||
| 37 | + */ | ||
| 38 | + void deleteConcerned(Integer bizType, Collection<Long> bizIds, Long userId); | ||
| 39 | + | ||
| 40 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/CrmConcernedServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.concerned; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.ObjUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | +import cn.iocoder.yudao.module.crm.dal.dataobject.concerned.CrmConcernedDO; | ||
| 6 | +import cn.iocoder.yudao.module.crm.dal.mysql.concerned.CrmConcernedMapper; | ||
| 7 | +import cn.iocoder.yudao.module.crm.service.concerned.bo.CrmConcernedCreateReqBO; | ||
| 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | +import org.springframework.transaction.annotation.Transactional; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Collection; | ||
| 15 | +import java.util.Collections; | ||
| 16 | +import java.util.List; | ||
| 17 | + | ||
| 18 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 21 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_CONCERNED_NOT_EXISTS; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * CRM 关注的数据 Service 接口实现类 | ||
| 25 | + * | ||
| 26 | + * @author HUIHUI | ||
| 27 | + */ | ||
| 28 | +@Service | ||
| 29 | +@Validated | ||
| 30 | +public class CrmConcernedServiceImpl implements CrmConcernedService { | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private CrmConcernedMapper concernedMapper; | ||
| 34 | + @Resource | ||
| 35 | + private AdminUserApi adminUserApi; | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + @Transactional(rollbackFor = Exception.class) | ||
| 39 | + public Long createConcerned(CrmConcernedCreateReqBO createReqBO) { | ||
| 40 | + // 1. 校验用户是否存在 | ||
| 41 | + adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId())); | ||
| 42 | + | ||
| 43 | + // 2. 创建 | ||
| 44 | + CrmConcernedDO concerned = BeanUtils.toBean(createReqBO, CrmConcernedDO.class); | ||
| 45 | + concernedMapper.insert(concerned); | ||
| 46 | + return concerned.getId(); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public void createConcernedBatch(Collection<CrmConcernedCreateReqBO> createReqBO) { | ||
| 51 | + // 1. 校验用户是否存在 | ||
| 52 | + adminUserApi.validateUserList(convertSet(createReqBO, CrmConcernedCreateReqBO::getUserId)); | ||
| 53 | + | ||
| 54 | + // 2. 创建 | ||
| 55 | + List<CrmConcernedDO> concernedList = convertList(createReqBO, item -> BeanUtils.toBean(item, CrmConcernedDO.class)); | ||
| 56 | + concernedMapper.insertBatch(concernedList); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void deleteConcerned(Integer bizType, Collection<Long> bizIds, Long userId) { | ||
| 61 | + // 1. 查询关注数据 | ||
| 62 | + List<CrmConcernedDO> concernedList = concernedMapper.selectList(bizType, bizIds, userId); | ||
| 63 | + if (ObjUtil.notEqual(bizIds.size(), concernedList.size())) { | ||
| 64 | + throw exception(CRM_CONCERNED_NOT_EXISTS); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + // 2. 删除 | ||
| 68 | + concernedMapper.deleteBatchIds(convertList(concernedList, CrmConcernedDO::getId)); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/concerned/bo/CrmConcernedCreateReqBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.concerned.bo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import javax.validation.constraints.NotNull; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * CRM 关注的数据 Create Req BO | ||
| 11 | + * | ||
| 12 | + * @author HUIHUI | ||
| 13 | + */ | ||
| 14 | +@Data | ||
| 15 | +public class CrmConcernedCreateReqBO { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 当前登录用户编号 | ||
| 19 | + */ | ||
| 20 | + @NotNull(message = "用户编号不能为空") | ||
| 21 | + private Long userId; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Crm 类型 | ||
| 25 | + */ | ||
| 26 | + @NotNull(message = "Crm 类型不能为空") | ||
| 27 | + @InEnum(CrmBizTypeEnum.class) | ||
| 28 | + private Integer bizType; | ||
| 29 | + /** | ||
| 30 | + * 数据编号 | ||
| 31 | + */ | ||
| 32 | + @NotNull(message = "Crm 数据编号不能为空") | ||
| 33 | + private Long bizId; | ||
| 34 | + | ||
| 35 | +} |