mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
✨ CRM:完善商机和联系人之间的关联
This commit is contained in:
parent
d9b0c9b4cf
commit
740e9297fa
@ -139,6 +139,14 @@ public class CrmContactController {
|
|||||||
return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
|
return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page-by-business")
|
||||||
|
@Operation(summary = "获得联系人分页,基于指定商机")
|
||||||
|
public CommonResult<PageResult<CrmContactRespVO>> getContactPageByBusiness(@Valid CrmContactPageReqVO pageVO) {
|
||||||
|
Assert.notNull(pageVO.getBusinessId(), "商机编号不能为空");
|
||||||
|
PageResult<CrmContactDO> pageResult = contactService.getContactPageByBusinessId(pageVO);
|
||||||
|
return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/export-excel")
|
@GetMapping("/export-excel")
|
||||||
@Operation(summary = "导出联系人 Excel")
|
@Operation(summary = "导出联系人 Excel")
|
||||||
@PreAuthorize("@ss.hasPermission('crm:contact:export')")
|
@PreAuthorize("@ss.hasPermission('crm:contact:export')")
|
||||||
|
@ -39,4 +39,7 @@ public class CrmContactPageReqVO extends PageParam {
|
|||||||
@InEnum(CrmSceneTypeEnum.class)
|
@InEnum(CrmSceneTypeEnum.class)
|
||||||
private Integer sceneType; // 场景类型,为 null 时则表示全部
|
private Integer sceneType; // 场景类型,为 null 时则表示全部
|
||||||
|
|
||||||
|
@Schema(description = "商机编号", example = "10430")
|
||||||
|
private Long businessId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.crm.convert.business;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
|
||||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商机 Convert
|
|
||||||
*
|
|
||||||
* @author ljlleo
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CrmBusinessConvert {
|
|
||||||
|
|
||||||
CrmBusinessConvert INSTANCE = Mappers.getMapper(CrmBusinessConvert.class);
|
|
||||||
|
|
||||||
@Mapping(target = "bizId", source = "reqVO.id")
|
|
||||||
CrmPermissionTransferReqBO convert(CrmBusinessTransferReqVO reqVO, Long userId);
|
|
||||||
|
|
||||||
}
|
|
@ -31,4 +31,8 @@ public interface CrmContactBusinessMapper extends BaseMapperX<CrmContactBusiness
|
|||||||
return selectList(CrmContactBusinessDO::getContactId, contactId);
|
return selectList(CrmContactBusinessDO::getContactId, contactId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<CrmContactBusinessDO> selectListByBusinessId(Long businessId) {
|
||||||
|
return selectList(CrmContactBusinessDO::getBusinessId, businessId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,18 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
|
|||||||
.orderByDesc(CrmContactDO::getId));
|
.orderByDesc(CrmContactDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default PageResult<CrmContactDO> selectPageByBusinessId(CrmContactPageReqVO pageVO, Collection<Long> ids) {
|
||||||
|
return selectPage(pageVO, new LambdaQueryWrapperX<CrmContactDO>()
|
||||||
|
.in(CrmContactDO::getId, ids) // 指定联系人编号
|
||||||
|
.likeIfPresent(CrmContactDO::getName, pageVO.getName())
|
||||||
|
.eqIfPresent(CrmContactDO::getMobile, pageVO.getMobile())
|
||||||
|
.eqIfPresent(CrmContactDO::getTelephone, pageVO.getTelephone())
|
||||||
|
.eqIfPresent(CrmContactDO::getEmail, pageVO.getEmail())
|
||||||
|
.eqIfPresent(CrmContactDO::getQq, pageVO.getQq())
|
||||||
|
.eqIfPresent(CrmContactDO::getWechat, pageVO.getWechat())
|
||||||
|
.orderByDesc(CrmContactDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) {
|
default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO pageReqVO, Long userId) {
|
||||||
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
|
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
|
||||||
// 拼接数据权限的查询条件
|
// 拼接数据权限的查询条件
|
||||||
|
@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|||||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
|
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.business.CrmBusinessDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
|
||||||
@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
|||||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||||
|
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||||
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
|
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
|
||||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
import com.mzt.logapi.context.LogRecordContext;
|
import com.mzt.logapi.context.LogRecordContext;
|
||||||
@ -38,6 +39,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
@ -100,14 +102,19 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|||||||
businessProducts.forEach(item -> item.setBusinessId(business.getId()));
|
businessProducts.forEach(item -> item.setBusinessId(business.getId()));
|
||||||
businessProductMapper.insertBatch(businessProducts);
|
businessProductMapper.insertBatch(businessProducts);
|
||||||
}
|
}
|
||||||
// 在联系人的详情页,如果直接【新建商机】,则需要关联下。
|
|
||||||
contactBusinessService.createContactBusiness(createReqVO.getContactId(), business.getId());
|
|
||||||
// 3. 创建数据权限
|
// 3. 创建数据权限
|
||||||
// 设置当前操作的人为负责人
|
// 设置当前操作的人为负责人
|
||||||
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
|
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
|
||||||
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
|
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||||
|
|
||||||
// 4. 记录操作日志上下文
|
// 4. 在联系人的详情页,如果直接【新建商机】,则需要关联下
|
||||||
|
if (createReqVO.getContactId() != null) {
|
||||||
|
contactBusinessService.createContactBusinessList(new CrmContactBusinessReqVO().setContactId(createReqVO.getContactId())
|
||||||
|
.setBusinessIds(Collections.singletonList(business.getId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 记录操作日志上下文
|
||||||
LogRecordContext.putVariable("business", business);
|
LogRecordContext.putVariable("business", business);
|
||||||
return business.getId();
|
return business.getId();
|
||||||
}
|
}
|
||||||
@ -262,8 +269,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|||||||
CrmBusinessDO business = validateBusinessExists(reqVO.getId());
|
CrmBusinessDO business = validateBusinessExists(reqVO.getId());
|
||||||
|
|
||||||
// 2.1 数据权限转移
|
// 2.1 数据权限转移
|
||||||
permissionService.transferPermission(
|
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_BUSINESS.getType(),
|
||||||
CrmBusinessConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()));
|
reqVO.getNewOwnerUserId(), reqVO.getId(), CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||||
// 2.2 设置新的负责人
|
// 2.2 设置新的负责人
|
||||||
businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
||||||
|
|
||||||
|
@ -13,15 +13,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface CrmContactBusinessService {
|
public interface CrmContactBusinessService {
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建联系人人商机关联
|
|
||||||
*
|
|
||||||
* @param contactId 联系人编号
|
|
||||||
* @param businessId 商机编号
|
|
||||||
*/
|
|
||||||
void createContactBusiness(Long contactId, Long businessId);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建联系人与商机的关联
|
* 创建联系人与商机的关联
|
||||||
*
|
*
|
||||||
@ -51,4 +42,12 @@ public interface CrmContactBusinessService {
|
|||||||
*/
|
*/
|
||||||
List<CrmContactBusinessDO> getContactBusinessListByContactId(Long contactId);
|
List<CrmContactBusinessDO> getContactBusinessListByContactId(Long contactId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得联系人与商机的关联列表,基于商机编号
|
||||||
|
*
|
||||||
|
* @param businessId 商机编号
|
||||||
|
* @return 联系人商机关联
|
||||||
|
*/
|
||||||
|
List<CrmContactBusinessDO> getContactBusinessListByBusinessId(Long businessId);
|
||||||
|
|
||||||
}
|
}
|
@ -41,22 +41,6 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
|
|||||||
@Lazy // 延迟加载,为了解决延迟加载
|
@Lazy // 延迟加载,为了解决延迟加载
|
||||||
private CrmContactService contactService;
|
private CrmContactService contactService;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createContactBusiness(Long contactId, Long businessId) {
|
|
||||||
// 校验存在
|
|
||||||
CrmContactDO contact = contactService.getContact(contactId);
|
|
||||||
if (contact == null) {
|
|
||||||
throw exception(CONTACT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
CrmBusinessDO business = businessService.getBusiness(businessId);
|
|
||||||
if (business == null) {
|
|
||||||
throw exception(BUSINESS_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 插入
|
|
||||||
contactBusinessMapper.insert(new CrmContactBusinessDO(null, contactId, businessId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#createReqVO.contactId", level = CrmPermissionLevelEnum.WRITE)
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#createReqVO.contactId", level = CrmPermissionLevelEnum.WRITE)
|
||||||
public void createContactBusinessList(CrmContactBusinessReqVO createReqVO) {
|
public void createContactBusinessList(CrmContactBusinessReqVO createReqVO) {
|
||||||
@ -107,4 +91,10 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
|
|||||||
return contactBusinessMapper.selectListByContactId(contactId);
|
return contactBusinessMapper.selectListByContactId(contactId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#businessId", level = CrmPermissionLevelEnum.READ)
|
||||||
|
public List<CrmContactBusinessDO> getContactBusinessListByBusinessId(Long businessId) {
|
||||||
|
return contactBusinessMapper.selectListByBusinessId(businessId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
||||||
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
@ -150,6 +151,16 @@ public interface CrmContactService {
|
|||||||
*/
|
*/
|
||||||
PageResult<CrmContactDO> getContactPageByCustomerId(CrmContactPageReqVO pageVO);
|
PageResult<CrmContactDO> getContactPageByCustomerId(CrmContactPageReqVO pageVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得联系人分页
|
||||||
|
*
|
||||||
|
* 数据权限:基于 {@link CrmBusinessDO}
|
||||||
|
*
|
||||||
|
* @param pageVO 分页查询
|
||||||
|
* @return 联系人分页
|
||||||
|
*/
|
||||||
|
PageResult<CrmContactDO> getContactPageByBusinessId(CrmContactPageReqVO pageVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取关联客户的联系人数量
|
* 获取关联客户的联系人数量
|
||||||
*
|
*
|
||||||
|
@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusines
|
|||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
||||||
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper;
|
import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper;
|
||||||
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
||||||
@ -36,6 +37,7 @@ import java.util.List;
|
|||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
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.*;
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
@ -289,6 +291,16 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|||||||
return contactMapper.selectPageByCustomerId(pageVO);
|
return contactMapper.selectPageByCustomerId(pageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#pageVO.businessId", level = CrmPermissionLevelEnum.READ)
|
||||||
|
public PageResult<CrmContactDO> getContactPageByBusinessId(CrmContactPageReqVO pageVO) {
|
||||||
|
List<CrmContactBusinessDO> contactBusinessList = contactBusinessService.getContactBusinessListByBusinessId(pageVO.getBusinessId());
|
||||||
|
if (CollUtil.isEmpty(contactBusinessList)) {
|
||||||
|
return PageResult.empty();
|
||||||
|
}
|
||||||
|
return contactMapper.selectPageByBusinessId(pageVO, convertSet(contactBusinessList, CrmContactBusinessDO::getContactId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getContactCountByCustomerId(Long customerId) {
|
public Long getContactCountByCustomerId(Long customerId) {
|
||||||
return contactMapper.selectCount(CrmContactDO::getCustomerId, customerId);
|
return contactMapper.selectCount(CrmContactDO::getCustomerId, customerId);
|
||||||
|
Loading…
Reference in New Issue
Block a user