Commit 866eaedfeba5b3f6a038c106fc8e53285434b3d0

Authored by Wanwan
1 parent 04613af0

feat: 客户表的 crud

yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/clue/CrmClueDO.java
1 1 package cn.iocoder.yudao.module.crm.dal.dataobject.clue;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
4 5 import com.baomidou.mybatisplus.annotation.KeySequence;
5 6 import com.baomidou.mybatisplus.annotation.TableId;
6 7 import com.baomidou.mybatisplus.annotation.TableName;
... ... @@ -43,8 +44,7 @@ public class CrmClueDO extends BaseDO {
43 44 private String name;
44 45 /**
45 46 * 客户 id
46   - *
47   - * // TODO @wanwan:要写下关联的实体,以及对应的属性哈
  47 + * 对应 {@link CrmCustomerDO#getId()}
48 48 */
49 49 private Long customerId;
50 50 /**
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java
... ... @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueUpdateReqVO;
10 10 import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert;
11 11 import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
12 12 import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
  13 +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
13 14 import org.springframework.stereotype.Service;
14 15 import org.springframework.validation.annotation.Validated;
15 16  
... ... @@ -19,6 +20,7 @@ import java.util.List;
19 20  
20 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21 22 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS;
  23 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
22 24  
23 25 /**
24 26 * 线索 Service 实现类
... ... @@ -31,10 +33,13 @@ public class CrmClueServiceImpl implements CrmClueService {
31 33  
32 34 @Resource
33 35 private CrmClueMapper clueMapper;
  36 + @Resource
  37 + private CrmCustomerService customerService;
34 38  
35 39 @Override
36 40 public Long createClue(CrmClueCreateReqVO createReqVO) {
37   - // TODO @wanwan:校验客户是否存在;以及类似的逻辑哈;如果目前还缺对应的模块的 service,可以先给自己写 todo;
  41 + // 校验客户是否存在
  42 + validateCustomerExists(createReqVO.getCustomerId());
38 43 // 插入
39 44 CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO);
40 45 clueMapper.insert(clue);
... ... @@ -44,9 +49,10 @@ public class CrmClueServiceImpl implements CrmClueService {
44 49  
45 50 @Override
46 51 public void updateClue(CrmClueUpdateReqVO updateReqVO) {
47   - // TODO @wanwan:校验客户是否存在;以及类似的逻辑哈;如果目前还缺对应的模块的 service,可以先给自己写 todo;
48 52 // 校验存在
49 53 validateClueExists(updateReqVO.getId());
  54 + // 校验客户是否存在
  55 + validateCustomerExists(updateReqVO.getCustomerId());
50 56  
51 57 // 更新
52 58 CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO);
... ... @@ -90,4 +96,15 @@ public class CrmClueServiceImpl implements CrmClueService {
90 96 return clueMapper.selectList(exportReqVO);
91 97 }
92 98  
  99 + /**
  100 + * 校验客户是否存在
  101 + *
  102 + * @param customerId 客户id
  103 + */
  104 + private void validateCustomerExists(Long customerId) {
  105 + if (customerService.getCustomer(customerId) == null) {
  106 + throw exception(CUSTOMER_NOT_EXISTS);
  107 + }
  108 + }
  109 +
93 110 }
... ...