mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-02 03:34:58 +08:00
crm:code review 客户的公海领取和分配
This commit is contained in:
parent
9a5f6f13b4
commit
1842549634
@ -1,12 +1,10 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.customer;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
@ -24,7 +22,6 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -37,7 +34,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
@ -185,24 +181,23 @@ public class CrmCustomerController {
|
||||
|
||||
@PutMapping("/receive")
|
||||
@Operation(summary = "领取公海客户")
|
||||
@Parameter(name = "ids", description = "批量领取公海的客户id集合", required = true,example = "1,2,3")
|
||||
@Parameter(name = "ids", description = "编号数组", required = true,example = "1,2,3")
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:receive')")
|
||||
public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids){
|
||||
// 领取公海任务
|
||||
customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId());
|
||||
customerService.receiveCustomer(ids, getLoginUserId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/distributeByIds")
|
||||
@PutMapping("/distribute")
|
||||
@Operation(summary = "分配公海给对应负责人")
|
||||
@Parameters({
|
||||
@Parameter(name = "ownerUserId", description = "分配的负责人id", required = true,example = "12345"),
|
||||
@Parameter(name = "ids", description = "批量分配的公海的客户id集合", required = true,example = "1,2,3")
|
||||
@Parameter(name = "ownerUserId", description = "分配的负责人编号", required = true, example = "12345"),
|
||||
@Parameter(name = "ids", description = "客户编号数组", required = true, example = "1,2,3")
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
|
||||
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ownerUserId") Long ownerUserId,
|
||||
@RequestParam(value = "ids") List<Long>ids){
|
||||
customerService.distributeCustomer(ids,ownerUserId);
|
||||
@RequestParam(value = "ids") List<Long> ids){
|
||||
customerService.distributeCustomer(ids, ownerUserId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,10 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
|
||||
}
|
||||
|
||||
default void updateCustomerOwnerUser(Long id,CrmCustomerDO customerDO){
|
||||
update(customerDO,new LambdaUpdateWrapper <CrmCustomerDO>()
|
||||
.eq(CrmCustomerDO::getId,id)
|
||||
.isNull(CrmCustomerDO::getOwnerUserId)
|
||||
);
|
||||
default void updateCustomerByOwnerUserIdIsNull(Long id, CrmCustomerDO updateObj) {
|
||||
update(updateObj, new LambdaUpdateWrapper<CrmCustomerDO>()
|
||||
.eq(CrmCustomerDO::getId, id)
|
||||
.isNull(CrmCustomerDO::getOwnerUserId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,17 +88,17 @@ public interface CrmCustomerService {
|
||||
/**
|
||||
* 领取公海客户
|
||||
*
|
||||
* @param ids 要领取的客户 id
|
||||
* @param ids 要领取的客户编号数组
|
||||
*/
|
||||
void receiveCustomer(List<Long>ids, Long ownerUserId);
|
||||
|
||||
/**
|
||||
* 分配公海客户
|
||||
*
|
||||
* @param ids 要分配的客户 id
|
||||
* @param ownerUserId 分配的负责人id
|
||||
* @param ids 要分配的客户编号数组
|
||||
* @param ownerUserId 分配的负责人编号
|
||||
* @author xiaqing
|
||||
*/
|
||||
void distributeCustomer(List<Long>ids,Long ownerUserId);
|
||||
void distributeCustomer(List<Long>ids, Long ownerUserId);
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
@ -83,11 +82,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
private void validateCustomerExists(CrmCustomerDO customerDO){
|
||||
if (customerDO == null) {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
||||
@ -168,51 +162,58 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void receiveCustomer(List <Long> ids,Long ownerUserId) {
|
||||
transferCustomerOwner(ids,ownerUserId);
|
||||
transferCustomerOwner(ids, ownerUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void distributeCustomer(List <Long> ids, Long ownerUserId) {
|
||||
transferCustomerOwner(ids,ownerUserId);
|
||||
transferCustomerOwner(ids, ownerUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转移客户负责人
|
||||
*
|
||||
* @param ids 客户编号数组
|
||||
* @param ownerUserId 负责人编号
|
||||
*/
|
||||
private void transferCustomerOwner(List <Long> ids, Long ownerUserId) {
|
||||
// 先一次性加载所有数据,校验客户是否可用
|
||||
List <CrmCustomerDO> customerDOList = customerMapper.selectBatchIds(ids);
|
||||
for (CrmCustomerDO customerDO : customerDOList) {
|
||||
// 校验客户是否存在
|
||||
validateCustomerExists(customerDO);
|
||||
List <CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
|
||||
for (CrmCustomerDO customer : customers) {
|
||||
// 校验是否已有负责人
|
||||
validCustomerOwnerExist(customerDO);
|
||||
validateCustomerOwnerExists(customer);
|
||||
// 校验是否锁定
|
||||
validCustomerIsLocked(customerDO);
|
||||
validateCustomerIsLocked(customer);
|
||||
// 校验成交状态
|
||||
validCustomerDeal(customerDO);
|
||||
validateCustomerDeal(customer);
|
||||
}
|
||||
|
||||
// TODO @QingX:这里是不是改成一次性更新;不然,如果有 20 个客户,就要执行 20 次 SQL 了;
|
||||
// 统一修改状态
|
||||
CrmCustomerDO updateDo = new CrmCustomerDO();
|
||||
updateDo.setOwnerUserId(ownerUserId);
|
||||
// TODO @QingX:如果更新的数量不对,则应该抛出异常,回滚,并错误提示;
|
||||
for (Long id : ids) {
|
||||
customerMapper.updateCustomerOwnerUser(id,updateDo);
|
||||
customerMapper.updateCustomerByOwnerUserIdIsNull(id,updateDo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void validCustomerOwnerExist(CrmCustomerDO customerDO) {
|
||||
if (customerDO.getOwnerUserId()!=null) {
|
||||
// TODO @QingX:错误提示里面,可以把客户的名字带上哈;不然不知道是谁;
|
||||
private void validateCustomerOwnerExists(CrmCustomerDO customer) {
|
||||
if (customer.getOwnerUserId() != null) {
|
||||
throw exception(CUSTOMER_OWNER_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validCustomerIsLocked(CrmCustomerDO customerDO) {
|
||||
if (customerDO.getLockStatus() ==true) {
|
||||
private void validateCustomerIsLocked(CrmCustomerDO customer) {
|
||||
if (customer.getLockStatus()) {
|
||||
throw exception(CUSTOMER_LOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
private void validCustomerDeal(CrmCustomerDO customerDO) {
|
||||
if (customerDO.getDealStatus() ==true) {
|
||||
private void validateCustomerDeal(CrmCustomerDO customer) {
|
||||
if (customer.getDealStatus()) {
|
||||
throw exception(CUSTOMER_ALREADY_DEAL);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user