!739 客户的公海领取和分配,按照要修调整代码格式

Merge pull request !739 from QingX/feature/crm
This commit is contained in:
芋道源码 2023-11-24 14:58:23 +00:00 committed by Gitee
commit 9a5f6f13b4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 60 additions and 52 deletions

View File

@ -6,6 +6,7 @@ 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;
@ -20,6 +21,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
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;
@ -183,28 +185,25 @@ public class CrmCustomerController {
@PutMapping("/receive")
@Operation(summary = "领取公海客户")
// TODO @xiaqing1receiveCustomer 方法名字2cIds 改成 ids要加下 @RequestParam还有 swagger 注解3参数非空使用 validator 校验4返回 true 即可
@Parameter(name = "ids", description = "批量领取公海的客户id集合", required = true,example = "1,2,3")
@PreAuthorize("@ss.hasPermission('crm:customer:receive')")
public CommonResult<String> receiveByIds(List<Long> cIds){
// 判断是否为空
if(CollectionUtils.isEmpty(cIds))
return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids){
// 领取公海任务
// TODO @xiaqinguserid通过 controller 传递给 service不要在 service 里面获取无状态
customerService.receive(cIds);
return success("领取成功");
customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId());
return success(true);
}
// TODO @xiaqing1distributeCustomer 方法名2cIds 同上3参数校验同上4ownerId 改成 ownerUserId和别的模块统一5返回 true 即可
@PutMapping("/distributeByIds")
@Operation(summary = "分配公海给对应负责人")
@PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')")
public CommonResult<String> distributeByIds(Long ownerId,List<Long>cIds){
//判断参数不能为空
if(ownerId==null || CollectionUtils.isEmpty(cIds))
return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
customerService.distributeByIds(cIds,ownerId);
return success("分配成功");
@Parameters({
@Parameter(name = "ownerUserId", description = "分配的负责人id", required = true,example = "12345"),
@Parameter(name = "ids", description = "批量分配的公海的客户id集合", 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);
return success(true);
}
}

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
@ -27,4 +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)
);
}
}

View File

@ -85,22 +85,20 @@ public interface CrmCustomerService {
*/
void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
// TODO @xiaqing根据 controller 的建议改下
/**
* 领取公海客户
*
* @param ids 要领取的客户 id
*/
void receive(List<Long>ids);
void receiveCustomer(List<Long>ids, Long ownerUserId);
// TODO @xiaqing根据 controller 的建议改下
/**
* 分配公海客户
*
* @param cIds 要分配的客户 id
* @param ownerId 分配的负责人id
* @param ids 要分配的客户 id
* @param ownerUserId 分配的负责人id
* @author xiaqing
*/
void distributeByIds(List<Long>cIds,Long ownerId);
void distributeCustomer(List<Long>ids,Long ownerUserId);
}

View File

@ -83,6 +83,11 @@ 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)
@ -162,53 +167,52 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
public void receive(List <Long> ids) {
transferCustomerOwner(ids,SecurityFrameworkUtils.getLoginUserId());
public void receiveCustomer(List <Long> ids,Long ownerUserId) {
transferCustomerOwner(ids,ownerUserId);
}
@Override
public void distributeByIds(List <Long> cIds, Long ownerId) {
transferCustomerOwner(cIds,ownerId);
public void distributeCustomer(List <Long> ids, Long ownerUserId) {
transferCustomerOwner(ids,ownerUserId);
}
private void transferCustomerOwner(List <Long> cIds, Long ownerId){
// 先一次性校验完成客户是否可用
// TODO @xiaqing批量一次性加载客户列表然后去逐个校验
for (Long cId : cIds) {
//校验是否存在
validateCustomerExists(cId);
//todo 校验是否已有负责人
validCustomerOwnerExist(cId);
//todo 校验是否锁定
validCustomerIsLocked(cId);
//todo 校验成交状态
validCustomerDeal(cId);
}
// TODO @xiaqing每个客户更新的时候where 条件加上 owner_user_id is null防止并发问题
List<CrmCustomerDO> updateDos = new ArrayList <>();
for (Long cId : cIds){
CrmCustomerDO customerDO = new CrmCustomerDO();
customerDO.setId(cId);
customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId());
private void transferCustomerOwner(List <Long> ids, Long ownerUserId) {
// 先一次性加载所有数据校验客户是否可用
List <CrmCustomerDO> customerDOList = customerMapper.selectBatchIds(ids);
for (CrmCustomerDO customerDO : customerDOList) {
// 校验客户是否存在
validateCustomerExists(customerDO);
// 校验是否已有负责人
validCustomerOwnerExist(customerDO);
// 校验是否锁定
validCustomerIsLocked(customerDO);
// 校验成交状态
validCustomerDeal(customerDO);
}
// 统一修改状态
customerMapper.updateBatch(updateDos);
CrmCustomerDO updateDo = new CrmCustomerDO();
updateDo.setOwnerUserId(ownerUserId);
for (Long id : ids) {
customerMapper.updateCustomerOwnerUser(id,updateDo);
}
}
private void validCustomerOwnerExist(Long id) {
if (customerMapper.selectById(id).getOwnerUserId()!=null) {
private void validCustomerOwnerExist(CrmCustomerDO customerDO) {
if (customerDO.getOwnerUserId()!=null) {
throw exception(CUSTOMER_OWNER_EXISTS);
}
}
private void validCustomerIsLocked(Long id) {
if (customerMapper.selectById(id).getLockStatus() ==true) {
private void validCustomerIsLocked(CrmCustomerDO customerDO) {
if (customerDO.getLockStatus() ==true) {
throw exception(CUSTOMER_LOCKED);
}
}
private void validCustomerDeal(Long id) {
if (customerMapper.selectById(id).getDealStatus() ==true) {
private void validCustomerDeal(CrmCustomerDO customerDO) {
if (customerDO.getDealStatus() ==true) {
throw exception(CUSTOMER_ALREADY_DEAL);
}
}