mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 15:51: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.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 @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')")
|
@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 @xiaqing:userid,通过 controller 传递给 service,不要在 service 里面获取,无状态
|
customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId());
|
||||||
customerService.receive(cIds);
|
return success(true);
|
||||||
return success("领取成功");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @xiaqing:1)distributeCustomer 方法名;2)cIds 同上;3)参数校验,同上;4)ownerId 改成 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user