CRM:增加商机关联联系人

This commit is contained in:
YunaiV 2024-02-24 19:35:32 +08:00
parent 53ebd39c73
commit e7bd2a568d
6 changed files with 102 additions and 3 deletions

View File

@ -199,6 +199,15 @@ public class CrmContactController {
return success(true);
}
@PostMapping("/create-business-list2")
@Operation(summary = "创建联系人与商机的关联")
@PreAuthorize("@ss.hasPermission('crm:contact:create-business')")
public CommonResult<Boolean> createContactBusinessList2(@Valid @RequestBody CrmContactBusiness2ReqVO createReqVO) {
contactBusinessLinkService.createContactBusinessList2(createReqVO);
return success(true);
}
@DeleteMapping("/delete-business-list")
@Operation(summary = "删除联系人与联系人的关联")
@PreAuthorize("@ss.hasPermission('crm:contact:delete-business')")
@ -207,4 +216,12 @@ public class CrmContactController {
return success(true);
}
@DeleteMapping("/delete-business-list2")
@Operation(summary = "删除联系人与联系人的关联")
@PreAuthorize("@ss.hasPermission('crm:contact:delete-business')")
public CommonResult<Boolean> deleteContactBusinessList(@Valid @RequestBody CrmContactBusiness2ReqVO deleteReqVO) {
contactBusinessLinkService.deleteContactBusinessList2(deleteReqVO);
return success(true);
}
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 商机关联联系人用于关联取消关联的操作
@Data
public class CrmContactBusiness2ReqVO {
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7638")
@NotNull(message="商机不能为空")
private Long businessId;
@Schema(description = "联系人编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "20878")
@NotEmpty(message="联系人数组不能为空")
private List<Long> contactIds;
}

View File

@ -7,7 +7,7 @@ import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 用于关联取消关联的操作
@Schema(description = "管理后台 - CRM 联系人商机 Request VO") // 联系人关联商机用于关联取消关联的操作
@Data
public class CrmContactBusinessReqVO {

View File

@ -27,6 +27,12 @@ public interface CrmContactBusinessMapper extends BaseMapperX<CrmContactBusiness
.in(CrmContactBusinessDO::getBusinessId, businessIds));
}
default void deleteByBusinessIdAndContactId(Long businessId, List<Long> contactIds) {
delete(new LambdaQueryWrapper<CrmContactBusinessDO>()
.eq(CrmContactBusinessDO::getBusinessId, businessId)
.in(CrmContactBusinessDO::getContactId, contactIds));
}
default List<CrmContactBusinessDO> selectListByContactId(Long contactId) {
return selectList(CrmContactBusinessDO::getContactId, contactId);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.service.contact;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusiness2ReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
import jakarta.validation.Valid;
@ -14,19 +15,33 @@ import java.util.List;
public interface CrmContactBusinessService {
/**
* 创建联系人与商机的关联
* 创建联系人与商机的关联通过联系人关联商机
*
* @param createReqVO 创建信息
*/
void createContactBusinessList(@Valid CrmContactBusinessReqVO createReqVO);
/**
* 删除联系人与商机的关联
* 创建联系人与商机的关联通过商机关联联系人
*
* @param createReqVO 创建信息
*/
void createContactBusinessList2(@Valid CrmContactBusiness2ReqVO createReqVO);
/**
* 删除联系人与商机的关联通过联系人取关商机
*
* @param deleteReqVO 删除信息
*/
void deleteContactBusinessList(@Valid CrmContactBusinessReqVO deleteReqVO);
/**
* 删除联系人与商机的关联通过商机取关联系人
*
* @param deleteReqVO 删除信息
*/
void deleteContactBusinessList2(@Valid CrmContactBusiness2ReqVO deleteReqVO);
/**
* 删除联系人与商机的关联基于联系人编号
*

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.service.contact;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusiness2ReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
@ -67,6 +68,32 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
}
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#createReqVO.businessId", level = CrmPermissionLevelEnum.WRITE)
public void createContactBusinessList2(CrmContactBusiness2ReqVO createReqVO) {
CrmBusinessDO business = businessService.getBusiness(createReqVO.getBusinessId());
if (business == null) {
throw exception(BUSINESS_NOT_EXISTS);
}
// 遍历处理考虑到一般数量不会太多代码处理简单
List<CrmContactBusinessDO> saveDOList = new ArrayList<>();
createReqVO.getContactIds().forEach(contactId -> {
CrmContactDO contact = contactService.getContact(contactId);
if (contact == null) {
throw exception(CONTACT_NOT_EXISTS);
}
// 关联判重
if (contactBusinessMapper.selectByContactIdAndBusinessId(contactId, createReqVO.getBusinessId()) != null) {
return;
}
saveDOList.add(new CrmContactBusinessDO(null, contactId, createReqVO.getBusinessId()));
});
// 批量插入
if (CollUtil.isNotEmpty(saveDOList)) {
contactBusinessMapper.insertBatch(saveDOList);
}
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#deleteReqVO.contactId", level = CrmPermissionLevelEnum.WRITE)
public void deleteContactBusinessList(CrmContactBusinessReqVO deleteReqVO) {
@ -79,6 +106,18 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
deleteReqVO.getContactId(), deleteReqVO.getBusinessIds());
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#deleteReqVO.businessId", level = CrmPermissionLevelEnum.WRITE)
public void deleteContactBusinessList2(CrmContactBusiness2ReqVO deleteReqVO) {
CrmBusinessDO business = businessService.getBusiness(deleteReqVO.getBusinessId());
if (business == null) {
throw exception(BUSINESS_NOT_EXISTS);
}
// 直接删除
contactBusinessMapper.deleteByBusinessIdAndContactId(
deleteReqVO.getBusinessId(), deleteReqVO.getContactIds());
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#contactId", level = CrmPermissionLevelEnum.WRITE)
public void deleteContactBusinessByContactId(Long contactId) {