mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
CRM:完善数据权限,实现数据权限同时添加、同时转移
This commit is contained in:
parent
f56fab932a
commit
ba1b028001
@ -3,15 +3,19 @@ package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - 商机转移 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CrmBusinessTransferReqVO {
|
||||
|
||||
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "商机编号不能为空")
|
||||
private Long id;
|
||||
private Long bizId;
|
||||
|
||||
/**
|
||||
* 新负责人的用户编号
|
||||
|
@ -12,7 +12,7 @@ public class CrmClueTransferReqVO {
|
||||
|
||||
@Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "线索编号不能为空")
|
||||
private Long id;
|
||||
private Long bizId;
|
||||
|
||||
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "新负责人的用户编号不能为空")
|
||||
|
@ -2,17 +2,21 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 联系人转移 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CrmContactTransferReqVO {
|
||||
|
||||
@Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "联系人编号不能为空")
|
||||
private Long id;
|
||||
private Long bizId;
|
||||
|
||||
/**
|
||||
* 新负责人的用户编号
|
||||
|
@ -3,17 +3,21 @@ package cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 合同转移 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CrmContractTransferReqVO {
|
||||
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "联系人编号不能为空")
|
||||
private Long id;
|
||||
private Long bizId;
|
||||
|
||||
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "新负责人的用户编号不能为空")
|
||||
|
@ -62,8 +62,6 @@ public class CrmCustomerController {
|
||||
private DeptApi deptApi;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private DictDataApi dictDataApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户")
|
||||
|
@ -5,13 +5,15 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 客户转移 Request VO")
|
||||
@Data
|
||||
public class CrmCustomerTransferReqVO {
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@NotNull(message = "客户编号不能为空")
|
||||
private Long id;
|
||||
private Long bizId;
|
||||
|
||||
/**
|
||||
* 新负责人的用户编号
|
||||
@ -28,4 +30,10 @@ public class CrmCustomerTransferReqVO {
|
||||
@Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer oldOwnerPermissionLevel;
|
||||
|
||||
/**
|
||||
* 转移客户时,需要额外有【联系人】【商机】【合同】的 checkbox 选择
|
||||
*/
|
||||
@Schema(description = "同时转移", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
private List<Integer> toBizTypes;
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,19 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO;
|
||||
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.contract.CrmContractDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
@ -27,13 +34,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@ -50,7 +55,12 @@ public class CrmPermissionController {
|
||||
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private CrmContactService contactService;
|
||||
@Resource
|
||||
private CrmBusinessService businessService;
|
||||
@Resource
|
||||
private CrmContractService contractService;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
@ -60,13 +70,47 @@ public class CrmPermissionController {
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建数据权限")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@PreAuthorize("@ss.hasPermission('crm:permission:create')")
|
||||
@CrmPermission(bizTypeValue = "#reqVO.bizType", bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public CommonResult<Boolean> addPermission(@Valid @RequestBody CrmPermissionCreateReqVO reqVO) {
|
||||
public CommonResult<Boolean> addPermission(@Valid @RequestBody CrmPermissionSaveReqVO reqVO) {
|
||||
permissionService.createPermission(BeanUtils.toBean(reqVO, CrmPermissionCreateReqBO.class));
|
||||
if (CollUtil.isNotEmpty(reqVO.getToBizTypes())) {
|
||||
createBizTypePermissions(reqVO);
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
private void createBizTypePermissions(CrmPermissionSaveReqVO reqVO) {
|
||||
List<CrmPermissionCreateReqBO> createPermissions = new ArrayList<>();
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) {
|
||||
List<CrmContactDO> contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId());
|
||||
contactList.forEach(item -> {
|
||||
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTACT.getType())
|
||||
.setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel()));
|
||||
});
|
||||
}
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) {
|
||||
List<CrmBusinessDO> businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId());
|
||||
businessList.forEach(item -> {
|
||||
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
|
||||
.setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel()));
|
||||
});
|
||||
}
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) {
|
||||
List<CrmContractDO> contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId());
|
||||
contractList.forEach(item -> {
|
||||
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType())
|
||||
.setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel()));
|
||||
});
|
||||
}
|
||||
if (CollUtil.isEmpty(createPermissions)) {
|
||||
return;
|
||||
}
|
||||
permissionService.createPermissionBatch(createPermissions);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "编辑数据权限")
|
||||
@PreAuthorize("@ss.hasPermission('crm:permission:update')")
|
||||
|
@ -1,14 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.permission.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 数据权限创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmPermissionCreateReqVO extends CrmPermissionBaseVO {
|
||||
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.permission.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -8,11 +12,29 @@ import java.util.Set;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 数据权限 Response VO")
|
||||
@Data
|
||||
public class CrmPermissionRespVO extends CrmPermissionBaseVO {
|
||||
public class CrmPermissionRespVO {
|
||||
|
||||
@Schema(description = "数据权限编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "CRM 类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@InEnum(CrmBizTypeEnum.class)
|
||||
@NotNull(message = "CRM 类型不能为空")
|
||||
private Integer bizType;
|
||||
|
||||
@Schema(description = "CRM 类型数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "CRM 类型数据编号不能为空")
|
||||
private Long bizId;
|
||||
|
||||
@Schema(description = "权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@InEnum(CrmPermissionLevelEnum.class)
|
||||
@NotNull(message = "权限级别不能为空")
|
||||
private Integer level;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
private String nickname;
|
||||
|
||||
|
@ -8,14 +8,11 @@ import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 数据权限 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 数据权限创建/更新 Request VO")
|
||||
@Data
|
||||
public class CrmPermissionBaseVO {
|
||||
public class CrmPermissionSaveReqVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
@ -35,4 +32,10 @@ public class CrmPermissionBaseVO {
|
||||
@NotNull(message = "权限级别不能为空")
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 添加客户团队成员时,需要额外有【联系人】【商机】【合同】的 checkbox 选择
|
||||
*/
|
||||
@Schema(description = "同时添加", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
private List<Integer> toBizTypes;
|
||||
|
||||
}
|
@ -6,12 +6,14 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
||||
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商机 Mapper
|
||||
@ -57,4 +59,10 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> {
|
||||
return selectCount(CrmBusinessDO::getStatusTypeId, statusTypeId);
|
||||
}
|
||||
|
||||
default List<CrmBusinessDO> selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId){
|
||||
return selectList(new LambdaQueryWrapperX<CrmBusinessDO>()
|
||||
.eq(CrmBusinessDO::getCustomerId, customerId)
|
||||
.eq(CrmBusinessDO::getOwnerUserId, ownerUserId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -73,4 +73,10 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
|
||||
return selectList(CrmContactDO::getCustomerId, customerId);
|
||||
}
|
||||
|
||||
default List<CrmContactDO> selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmContactDO>()
|
||||
.eq(CrmContactDO::getCustomerId, customerId)
|
||||
.eq(CrmContactDO::getOwnerUserId, ownerUserId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,4 +117,10 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> {
|
||||
return selectCount(query);
|
||||
}
|
||||
|
||||
default List<CrmContractDO> selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmContractDO>()
|
||||
.eq(CrmContractDO::getCustomerId, customerId)
|
||||
.eq(CrmContractDO::getOwnerUserId, ownerUserId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ public interface CrmBusinessService {
|
||||
/**
|
||||
* 更新商机相关跟进信息
|
||||
*
|
||||
* @param id 编号
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param id 编号
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param contactLastContent 最后联系内容
|
||||
*/
|
||||
void updateBusinessFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent);
|
||||
@ -55,7 +55,7 @@ public interface CrmBusinessService {
|
||||
/**
|
||||
* 更新商机的下次联系时间
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @param ids 编号数组
|
||||
* @param contactNextTime 下次联系时间
|
||||
*/
|
||||
void updateBusinessContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime);
|
||||
@ -185,4 +185,13 @@ public interface CrmBusinessService {
|
||||
return status.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商机列表
|
||||
*
|
||||
* @param customerId 客户编号
|
||||
* @param ownerUserId 负责人编号
|
||||
* @return 商机列表
|
||||
*/
|
||||
List<CrmBusinessDO> getBusinessListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.service.business;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
@ -23,6 +24,7 @@ import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
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.CrmCustomerServiceImpl;
|
||||
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.CrmPermissionTransferReqBO;
|
||||
@ -204,7 +206,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
|
||||
private List<CrmBusinessProductDO> validateBusinessProducts(List<CrmBusinessSaveReqVO.Product> list) {
|
||||
// 1. 校验产品存在
|
||||
productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId));
|
||||
productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId));
|
||||
// 2. 转化为 CrmBusinessProductDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, CrmBusinessProductDO.class,
|
||||
item -> item.setTotalPrice(MoneyUtils.priceMultiply(item.getBusinessPrice(), item.getCount()))));
|
||||
@ -234,7 +236,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
}
|
||||
// 1.4 校验是不是状态没变更
|
||||
if ((reqVO.getStatusId() != null && reqVO.getStatusId().equals(business.getStatusId()))
|
||||
|| (reqVO.getEndStatus() != null && reqVO.getEndStatus().equals(business.getEndStatus()))) {
|
||||
|| (reqVO.getEndStatus() != null && reqVO.getEndStatus().equals(business.getEndStatus()))) {
|
||||
throw exception(BUSINESS_UPDATE_STATUS_FAIL_STATUS_EQUALS);
|
||||
}
|
||||
|
||||
@ -292,18 +294,18 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
|
||||
success = CRM_BUSINESS_TRANSFER_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId) {
|
||||
// 1 校验商机是否存在
|
||||
CrmBusinessDO business = validateBusinessExists(reqVO.getId());
|
||||
CrmBusinessDO business = validateBusinessExists(reqVO.getBizId());
|
||||
|
||||
// 2.1 数据权限转移
|
||||
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_BUSINESS.getType(),
|
||||
reqVO.getNewOwnerUserId(), reqVO.getId(), CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||
reqVO.getBizId(), reqVO.getNewOwnerUserId(), CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||
// 2.2 设置新的负责人
|
||||
businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
||||
businessMapper.updateOwnerUserIdById(reqVO.getBizId(), reqVO.getNewOwnerUserId());
|
||||
|
||||
// 记录操作日志上下文
|
||||
LogRecordContext.putVariable("business", business);
|
||||
@ -370,4 +372,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
return businessMapper.selectCountByStatusTypeId(statusTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmBusinessDO> getBusinessListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
|
||||
return businessMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -159,18 +159,18 @@ public class CrmClueServiceImpl implements CrmClueService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
||||
@LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
|
||||
success = CRM_CLUE_TRANSFER_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferClue(CrmClueTransferReqVO reqVO, Long userId) {
|
||||
// 1 校验线索是否存在
|
||||
CrmClueDO clue = validateClueExists(reqVO.getId());
|
||||
CrmClueDO clue = validateClueExists(reqVO.getBizId());
|
||||
|
||||
// 2.1 数据权限转移
|
||||
crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CLUE.getType(),
|
||||
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
// 2.2 设置新的负责人
|
||||
clueMapper.updateById(new CrmClueDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
clueMapper.updateById(new CrmClueDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
|
||||
// 3. 记录转移日志
|
||||
LogRecordContext.putVariable("clue", clue);
|
||||
|
@ -75,8 +75,8 @@ public interface CrmContactService {
|
||||
/**
|
||||
* 更新联系人的下次联系时间
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param ids 编号数组
|
||||
* @param contactNextTime 下次联系时间
|
||||
*/
|
||||
void updateContactContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime);
|
||||
|
||||
@ -160,4 +160,13 @@ public interface CrmContactService {
|
||||
*/
|
||||
Long getContactCountByCustomerId(Long customerId);
|
||||
|
||||
/**
|
||||
* 获得联系人列表
|
||||
*
|
||||
* @param customerId 客户编号
|
||||
* @param ownerUserId 负责人编号
|
||||
* @return 联系人列表
|
||||
*/
|
||||
List<CrmContactDO> getContactListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.service.contact;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO;
|
||||
@ -17,6 +18,7 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
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.CrmCustomerServiceImpl;
|
||||
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.CrmPermissionTransferReqBO;
|
||||
@ -177,18 +179,18 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
||||
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
|
||||
success = CRM_CONTACT_TRANSFER_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferContact(CrmContactTransferReqVO reqVO, Long userId) {
|
||||
// 1 校验联系人是否存在
|
||||
CrmContactDO contact = validateContactExists(reqVO.getId());
|
||||
CrmContactDO contact = validateContactExists(reqVO.getBizId());
|
||||
|
||||
// 2.1 数据权限转移
|
||||
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTACT.getType(),
|
||||
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
// 2.2 设置新的负责人
|
||||
contactMapper.updateById(new CrmContactDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
contactMapper.updateById(new CrmContactDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
|
||||
// 3. 记录转移日志
|
||||
LogRecordContext.putVariable("contact", contact);
|
||||
@ -298,4 +300,9 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
return contactMapper.selectCount(CrmContactDO::getCustomerId, customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmContactDO> getContactListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
|
||||
return contactMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId);
|
||||
}
|
||||
|
||||
}
|
@ -58,8 +58,8 @@ public interface CrmContractService {
|
||||
/**
|
||||
* 更新合同相关的更进信息
|
||||
*
|
||||
* @param id 合同编号
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param id 合同编号
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param contactLastContent 最后联系内容
|
||||
*/
|
||||
void updateContractFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent);
|
||||
@ -75,7 +75,7 @@ public interface CrmContractService {
|
||||
/**
|
||||
* 更新合同流程审批结果
|
||||
*
|
||||
* @param id 合同编号
|
||||
* @param id 合同编号
|
||||
* @param bpmResult BPM 审批结果
|
||||
*/
|
||||
void updateContractAuditStatus(Long id, Integer bpmResult);
|
||||
@ -193,4 +193,13 @@ public interface CrmContractService {
|
||||
*/
|
||||
Long getRemindContractCount(Long userId);
|
||||
|
||||
/**
|
||||
* 获得合同列表
|
||||
*
|
||||
* @param customerId 客户编号
|
||||
* @param ownerUserId 负责人编号
|
||||
* @return 合同列表
|
||||
*/
|
||||
List<CrmContractDO> getContractListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
@ -26,6 +27,7 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerServiceImpl;
|
||||
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.CrmPermissionTransferReqBO;
|
||||
@ -252,18 +254,18 @@ public class CrmContractServiceImpl implements CrmContractService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
||||
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
|
||||
success = CRM_CONTRACT_TRANSFER_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferContract(CrmContractTransferReqVO reqVO, Long userId) {
|
||||
// 1. 校验合同是否存在
|
||||
CrmContractDO contract = validateContractExists(reqVO.getId());
|
||||
CrmContractDO contract = validateContractExists(reqVO.getBizId());
|
||||
|
||||
// 2.1 数据权限转移
|
||||
crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTRACT.getType(),
|
||||
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
// 2.2 设置负责人
|
||||
contractMapper.updateById(new CrmContractDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
contractMapper.updateById(new CrmContractDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
||||
|
||||
// 3. 记录转移日志
|
||||
LogRecordContext.putVariable("contract", contract);
|
||||
@ -407,4 +409,9 @@ public class CrmContractServiceImpl implements CrmContractService {
|
||||
return contractMapper.selectCountByRemind(userId, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmContractDO> getContractListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
|
||||
return contractMapper.selectListByCustomerIdOwnerUserId(customerId, ownerUserId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,13 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
|
||||
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.contract.CrmContractDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
|
||||
@ -193,26 +199,60 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
||||
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
|
||||
success = CRM_CUSTOMER_TRANSFER_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
|
||||
// 1.1 校验客户是否存在
|
||||
CrmCustomerDO customer = validateCustomerExists(reqVO.getId());
|
||||
CrmCustomerDO customer = validateCustomerExists(reqVO.getBizId());
|
||||
// 1.2 校验拥有客户是否到达上限
|
||||
validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1);
|
||||
|
||||
// 2.1 数据权限转移
|
||||
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
|
||||
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
||||
// 2.2 转移后重新设置负责人
|
||||
customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getId())
|
||||
customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getBizId())
|
||||
.setOwnerUserId(reqVO.getNewOwnerUserId()).setOwnerTime(LocalDateTime.now()));
|
||||
|
||||
// 2.3 同时转移
|
||||
if (CollUtil.isNotEmpty(reqVO.getToBizTypes())) {
|
||||
transfer(reqVO, userId);
|
||||
}
|
||||
|
||||
// 3. 记录转移日志
|
||||
LogRecordContext.putVariable("customer", customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转移客户时,需要额外有【联系人】【商机】【合同】
|
||||
*
|
||||
* @param reqVO 请求
|
||||
* @param userId 用户编号
|
||||
*/
|
||||
private void transfer(CrmCustomerTransferReqVO reqVO, Long userId) {
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) {
|
||||
List<CrmContactDO> contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
|
||||
contactList.forEach(item -> {
|
||||
contactService.transferContact(new CrmContactTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
|
||||
reqVO.getOldOwnerPermissionLevel()), userId);
|
||||
});
|
||||
}
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) {
|
||||
List<CrmBusinessDO> businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
|
||||
businessList.forEach(item -> {
|
||||
businessService.transferBusiness(new CrmBusinessTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
|
||||
reqVO.getOldOwnerPermissionLevel()), userId);
|
||||
});
|
||||
}
|
||||
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) {
|
||||
List<CrmContractDO> contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
|
||||
contractList.forEach(item -> {
|
||||
contractService.transferContract(new CrmContractTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
|
||||
reqVO.getOldOwnerPermissionLevel()), userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}",
|
||||
success = CRM_CUSTOMER_LOCK_SUCCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user