mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
!739 客户的公海领取和分配,按照要修调整代码格式
Merge pull request !739 from QingX/feature/crm
This commit is contained in:
commit
9a5f6f13b4
@ -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 @xiaqing:1)receiveCustomer 方法名字;2)cIds 改成 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 @xiaqing:userid,通过 controller 传递给 service,不要在 service 里面获取,无状态
|
||||
customerService.receive(cIds);
|
||||
return success("领取成功");
|
||||
customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
// TODO @xiaqing:1)distributeCustomer 方法名;2)cIds 同上;3)参数校验,同上;4)ownerId 改成 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user