Commit e7bd2a568d466cbdfb7e1671ea3c1e8aee1c7a66
1 parent
53ebd39c
✨ CRM:增加商机关联联系人
Showing
6 changed files
with
102 additions
and
3 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java
| @@ -199,6 +199,15 @@ public class CrmContactController { | @@ -199,6 +199,15 @@ public class CrmContactController { | ||
| 199 | return success(true); | 199 | return success(true); |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | + | ||
| 203 | + @PostMapping("/create-business-list2") | ||
| 204 | + @Operation(summary = "创建联系人与商机的关联") | ||
| 205 | + @PreAuthorize("@ss.hasPermission('crm:contact:create-business')") | ||
| 206 | + public CommonResult<Boolean> createContactBusinessList2(@Valid @RequestBody CrmContactBusiness2ReqVO createReqVO) { | ||
| 207 | + contactBusinessLinkService.createContactBusinessList2(createReqVO); | ||
| 208 | + return success(true); | ||
| 209 | + } | ||
| 210 | + | ||
| 202 | @DeleteMapping("/delete-business-list") | 211 | @DeleteMapping("/delete-business-list") |
| 203 | @Operation(summary = "删除联系人与联系人的关联") | 212 | @Operation(summary = "删除联系人与联系人的关联") |
| 204 | @PreAuthorize("@ss.hasPermission('crm:contact:delete-business')") | 213 | @PreAuthorize("@ss.hasPermission('crm:contact:delete-business')") |
| @@ -207,4 +216,12 @@ public class CrmContactController { | @@ -207,4 +216,12 @@ public class CrmContactController { | ||
| 207 | return success(true); | 216 | return success(true); |
| 208 | } | 217 | } |
| 209 | 218 | ||
| 219 | + @DeleteMapping("/delete-business-list2") | ||
| 220 | + @Operation(summary = "删除联系人与联系人的关联") | ||
| 221 | + @PreAuthorize("@ss.hasPermission('crm:contact:delete-business')") | ||
| 222 | + public CommonResult<Boolean> deleteContactBusinessList(@Valid @RequestBody CrmContactBusiness2ReqVO deleteReqVO) { | ||
| 223 | + contactBusinessLinkService.deleteContactBusinessList2(deleteReqVO); | ||
| 224 | + return success(true); | ||
| 225 | + } | ||
| 226 | + | ||
| 210 | } | 227 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactBusiness2ReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import jakarta.validation.constraints.NotNull; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 【商机关联联系人】用于关联,取消关联的操作 | ||
| 11 | +@Data | ||
| 12 | +public class CrmContactBusiness2ReqVO { | ||
| 13 | + | ||
| 14 | + @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7638") | ||
| 15 | + @NotNull(message="商机不能为空") | ||
| 16 | + private Long businessId; | ||
| 17 | + | ||
| 18 | + @Schema(description = "联系人编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "20878") | ||
| 19 | + @NotEmpty(message="联系人数组不能为空") | ||
| 20 | + private List<Long> contactIds; | ||
| 21 | + | ||
| 22 | +} | ||
| 0 | \ No newline at end of file | 23 | \ No newline at end of file |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactBusinessReqVO.java
| @@ -7,7 +7,7 @@ import lombok.Data; | @@ -7,7 +7,7 @@ import lombok.Data; | ||
| 7 | 7 | ||
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | 9 | ||
| 10 | -@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 用于关联,取消关联的操作 | 10 | +@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 【联系人关联商机】用于关联,取消关联的操作 |
| 11 | @Data | 11 | @Data |
| 12 | public class CrmContactBusinessReqVO { | 12 | public class CrmContactBusinessReqVO { |
| 13 | 13 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactBusinessMapper.java
| @@ -27,6 +27,12 @@ public interface CrmContactBusinessMapper extends BaseMapperX<CrmContactBusiness | @@ -27,6 +27,12 @@ public interface CrmContactBusinessMapper extends BaseMapperX<CrmContactBusiness | ||
| 27 | .in(CrmContactBusinessDO::getBusinessId, businessIds)); | 27 | .in(CrmContactBusinessDO::getBusinessId, businessIds)); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | + default void deleteByBusinessIdAndContactId(Long businessId, List<Long> contactIds) { | ||
| 31 | + delete(new LambdaQueryWrapper<CrmContactBusinessDO>() | ||
| 32 | + .eq(CrmContactBusinessDO::getBusinessId, businessId) | ||
| 33 | + .in(CrmContactBusinessDO::getContactId, contactIds)); | ||
| 34 | + } | ||
| 35 | + | ||
| 30 | default List<CrmContactBusinessDO> selectListByContactId(Long contactId) { | 36 | default List<CrmContactBusinessDO> selectListByContactId(Long contactId) { |
| 31 | return selectList(CrmContactBusinessDO::getContactId, contactId); | 37 | return selectList(CrmContactBusinessDO::getContactId, contactId); |
| 32 | } | 38 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactBusinessService.java
| 1 | package cn.iocoder.yudao.module.crm.service.contact; | 1 | package cn.iocoder.yudao.module.crm.service.contact; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusiness2ReqVO; | ||
| 3 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO; | 4 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO; |
| 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; |
| 5 | import jakarta.validation.Valid; | 6 | import jakarta.validation.Valid; |
| @@ -14,20 +15,34 @@ import java.util.List; | @@ -14,20 +15,34 @@ import java.util.List; | ||
| 14 | public interface CrmContactBusinessService { | 15 | public interface CrmContactBusinessService { |
| 15 | 16 | ||
| 16 | /** | 17 | /** |
| 17 | - * 创建联系人与商机的关联 | 18 | + * 创建联系人与商机的关联【通过联系人,关联商机】 |
| 18 | * | 19 | * |
| 19 | * @param createReqVO 创建信息 | 20 | * @param createReqVO 创建信息 |
| 20 | */ | 21 | */ |
| 21 | void createContactBusinessList(@Valid CrmContactBusinessReqVO createReqVO); | 22 | void createContactBusinessList(@Valid CrmContactBusinessReqVO createReqVO); |
| 22 | 23 | ||
| 23 | /** | 24 | /** |
| 24 | - * 删除联系人与商机的关联 | 25 | + * 创建联系人与商机的关联【通过商机,关联联系人】 |
| 26 | + * | ||
| 27 | + * @param createReqVO 创建信息 | ||
| 28 | + */ | ||
| 29 | + void createContactBusinessList2(@Valid CrmContactBusiness2ReqVO createReqVO); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 删除联系人与商机的关联【通过联系人,取关商机】 | ||
| 25 | * | 33 | * |
| 26 | * @param deleteReqVO 删除信息 | 34 | * @param deleteReqVO 删除信息 |
| 27 | */ | 35 | */ |
| 28 | void deleteContactBusinessList(@Valid CrmContactBusinessReqVO deleteReqVO); | 36 | void deleteContactBusinessList(@Valid CrmContactBusinessReqVO deleteReqVO); |
| 29 | 37 | ||
| 30 | /** | 38 | /** |
| 39 | + * 删除联系人与商机的关联【通过商机,取关联系人】 | ||
| 40 | + * | ||
| 41 | + * @param deleteReqVO 删除信息 | ||
| 42 | + */ | ||
| 43 | + void deleteContactBusinessList2(@Valid CrmContactBusiness2ReqVO deleteReqVO); | ||
| 44 | + | ||
| 45 | + /** | ||
| 31 | * 删除联系人与商机的关联,基于联系人编号 | 46 | * 删除联系人与商机的关联,基于联系人编号 |
| 32 | * | 47 | * |
| 33 | * @param contactId 联系人编号 | 48 | * @param contactId 联系人编号 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactBusinessServiceImpl.java
| 1 | package cn.iocoder.yudao.module.crm.service.contact; | 1 | package cn.iocoder.yudao.module.crm.service.contact; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusiness2ReqVO; | ||
| 4 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO; | 5 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO; |
| 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; |
| 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; |
| @@ -68,6 +69,32 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService | @@ -68,6 +69,32 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService | ||
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | @Override | 71 | @Override |
| 72 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#createReqVO.businessId", level = CrmPermissionLevelEnum.WRITE) | ||
| 73 | + public void createContactBusinessList2(CrmContactBusiness2ReqVO createReqVO) { | ||
| 74 | + CrmBusinessDO business = businessService.getBusiness(createReqVO.getBusinessId()); | ||
| 75 | + if (business == null) { | ||
| 76 | + throw exception(BUSINESS_NOT_EXISTS); | ||
| 77 | + } | ||
| 78 | + // 遍历处理,考虑到一般数量不会太多,代码处理简单 | ||
| 79 | + List<CrmContactBusinessDO> saveDOList = new ArrayList<>(); | ||
| 80 | + createReqVO.getContactIds().forEach(contactId -> { | ||
| 81 | + CrmContactDO contact = contactService.getContact(contactId); | ||
| 82 | + if (contact == null) { | ||
| 83 | + throw exception(CONTACT_NOT_EXISTS); | ||
| 84 | + } | ||
| 85 | + // 关联判重 | ||
| 86 | + if (contactBusinessMapper.selectByContactIdAndBusinessId(contactId, createReqVO.getBusinessId()) != null) { | ||
| 87 | + return; | ||
| 88 | + } | ||
| 89 | + saveDOList.add(new CrmContactBusinessDO(null, contactId, createReqVO.getBusinessId())); | ||
| 90 | + }); | ||
| 91 | + // 批量插入 | ||
| 92 | + if (CollUtil.isNotEmpty(saveDOList)) { | ||
| 93 | + contactBusinessMapper.insertBatch(saveDOList); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 71 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#deleteReqVO.contactId", level = CrmPermissionLevelEnum.WRITE) | 98 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#deleteReqVO.contactId", level = CrmPermissionLevelEnum.WRITE) |
| 72 | public void deleteContactBusinessList(CrmContactBusinessReqVO deleteReqVO) { | 99 | public void deleteContactBusinessList(CrmContactBusinessReqVO deleteReqVO) { |
| 73 | CrmContactDO contact = contactService.getContact(deleteReqVO.getContactId()); | 100 | CrmContactDO contact = contactService.getContact(deleteReqVO.getContactId()); |
| @@ -80,6 +107,18 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService | @@ -80,6 +107,18 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService | ||
| 80 | } | 107 | } |
| 81 | 108 | ||
| 82 | @Override | 109 | @Override |
| 110 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#deleteReqVO.businessId", level = CrmPermissionLevelEnum.WRITE) | ||
| 111 | + public void deleteContactBusinessList2(CrmContactBusiness2ReqVO deleteReqVO) { | ||
| 112 | + CrmBusinessDO business = businessService.getBusiness(deleteReqVO.getBusinessId()); | ||
| 113 | + if (business == null) { | ||
| 114 | + throw exception(BUSINESS_NOT_EXISTS); | ||
| 115 | + } | ||
| 116 | + // 直接删除 | ||
| 117 | + contactBusinessMapper.deleteByBusinessIdAndContactId( | ||
| 118 | + deleteReqVO.getBusinessId(), deleteReqVO.getContactIds()); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + @Override | ||
| 83 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#contactId", level = CrmPermissionLevelEnum.WRITE) | 122 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#contactId", level = CrmPermissionLevelEnum.WRITE) |
| 84 | public void deleteContactBusinessByContactId(Long contactId) { | 123 | public void deleteContactBusinessByContactId(Long contactId) { |
| 85 | contactBusinessMapper.delete(CrmContactBusinessDO::getContactId, contactId); | 124 | contactBusinessMapper.delete(CrmContactBusinessDO::getContactId, contactId); |