!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.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 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.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 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 cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -183,28 +185,25 @@ public class CrmCustomerController {
@PutMapping("/receive") @PutMapping("/receive")
@Operation(summary = "领取公海客户") @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')") @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
public CommonResult<String> receiveByIds(List<Long> cIds){ public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids){
// 判断是否为空
if(CollectionUtils.isEmpty(cIds))
return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg());
// 领取公海任务 // 领取公海任务
// TODO @xiaqinguserid通过 controller 传递给 service不要在 service 里面获取无状态 customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId());
customerService.receive(cIds); return success(true);
return success("领取成功");
} }
// TODO @xiaqing1distributeCustomer 方法名2cIds 同上3参数校验同上4ownerId 改成 ownerUserId和别的模块统一5返回 true 即可
@PutMapping("/distributeByIds") @PutMapping("/distributeByIds")
@Operation(summary = "分配公海给对应负责人") @Operation(summary = "分配公海给对应负责人")
@PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')") @Parameters({
public CommonResult<String> distributeByIds(Long ownerId,List<Long>cIds){ @Parameter(name = "ownerUserId", description = "分配的负责人id", required = true,example = "12345"),
//判断参数不能为空 @Parameter(name = "ids", description = "批量分配的公海的客户id集合", required = true,example = "1,2,3")
if(ownerId==null || CollectionUtils.isEmpty(cIds)) })
return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg()); @PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
customerService.distributeByIds(cIds,ownerId); public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ownerUserId") Long ownerUserId,
return success("分配成功"); @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.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 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 org.apache.ibatis.annotations.Mapper;
import java.util.Collection; import java.util.Collection;
@ -27,4 +28,10 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource())); .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); void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
// TODO @xiaqing根据 controller 的建议改下
/** /**
* 领取公海客户 * 领取公海客户
* *
* @param ids 要领取的客户 id * @param ids 要领取的客户 id
*/ */
void receive(List<Long>ids); void receiveCustomer(List<Long>ids, Long ownerUserId);
// TODO @xiaqing根据 controller 的建议改下
/** /**
* 分配公海客户 * 分配公海客户
* *
* @param cIds 要分配的客户 id * @param ids 要分配的客户 id
* @param ownerId 分配的负责人id * @param ownerUserId 分配的负责人id
* @author xiaqing * @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); throw exception(CUSTOMER_NOT_EXISTS);
} }
} }
private void validateCustomerExists(CrmCustomerDO customerDO){
if (customerDO == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
}
@Override @Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ) @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
@ -162,53 +167,52 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void receive(List <Long> ids) { public void receiveCustomer(List <Long> ids,Long ownerUserId) {
transferCustomerOwner(ids,SecurityFrameworkUtils.getLoginUserId()); transferCustomerOwner(ids,ownerUserId);
} }
@Override @Override
public void distributeByIds(List <Long> cIds, Long ownerId) { public void distributeCustomer(List <Long> ids, Long ownerUserId) {
transferCustomerOwner(cIds,ownerId); transferCustomerOwner(ids,ownerUserId);
} }
private void transferCustomerOwner(List <Long> cIds, Long ownerId){ private void transferCustomerOwner(List <Long> ids, Long ownerUserId) {
// 先一次性校验完成客户是否可用 // 先一次性加载所有数据校验客户是否可用
// TODO @xiaqing批量一次性加载客户列表然后去逐个校验 List <CrmCustomerDO> customerDOList = customerMapper.selectBatchIds(ids);
for (Long cId : cIds) { for (CrmCustomerDO customerDO : customerDOList) {
//校验是否存在 // 校验客户是否存在
validateCustomerExists(cId); validateCustomerExists(customerDO);
//todo 校验是否已有负责人 // 校验是否已有负责人
validCustomerOwnerExist(cId); validCustomerOwnerExist(customerDO);
//todo 校验是否锁定 // 校验是否锁定
validCustomerIsLocked(cId); validCustomerIsLocked(customerDO);
//todo 校验成交状态 // 校验成交状态
validCustomerDeal(cId); validCustomerDeal(customerDO);
}
// 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());
} }
// 统一修改状态 // 统一修改状态
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); throw exception(CUSTOMER_OWNER_EXISTS);
} }
} }
private void validCustomerIsLocked(Long id) { private void validCustomerIsLocked(CrmCustomerDO customerDO) {
if (customerMapper.selectById(id).getLockStatus() ==true) { if (customerDO.getLockStatus() ==true) {
throw exception(CUSTOMER_LOCKED); throw exception(CUSTOMER_LOCKED);
} }
} }
private void validCustomerDeal(Long id) { private void validCustomerDeal(CrmCustomerDO customerDO) {
if (customerMapper.selectById(id).getDealStatus() ==true) { if (customerDO.getDealStatus() ==true) {
throw exception(CUSTOMER_ALREADY_DEAL); throw exception(CUSTOMER_ALREADY_DEAL);
} }
} }