Commit 87778f7fd96082eefda83354ba93ddf2d9423f8b
1 parent
f589881d
客户的公海领取和分配,按照要修调整代码格式
Showing
4 changed files
with
62 additions
and
54 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | ||
| 9 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; | 10 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; |
| 10 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; | 11 | import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; |
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| @@ -20,6 +21,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | @@ -20,6 +21,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 20 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 21 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 21 | import io.swagger.v3.oas.annotations.Operation; | 22 | import io.swagger.v3.oas.annotations.Operation; |
| 22 | import io.swagger.v3.oas.annotations.Parameter; | 23 | import io.swagger.v3.oas.annotations.Parameter; |
| 24 | +import io.swagger.v3.oas.annotations.Parameters; | ||
| 23 | import io.swagger.v3.oas.annotations.tags.Tag; | 25 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 24 | import org.springframework.security.access.prepost.PreAuthorize; | 26 | import org.springframework.security.access.prepost.PreAuthorize; |
| 25 | import org.springframework.util.CollectionUtils; | 27 | import org.springframework.util.CollectionUtils; |
| @@ -183,28 +185,25 @@ public class CrmCustomerController { | @@ -183,28 +185,25 @@ public class CrmCustomerController { | ||
| 183 | 185 | ||
| 184 | @PutMapping("/receive") | 186 | @PutMapping("/receive") |
| 185 | @Operation(summary = "领取公海客户") | 187 | @Operation(summary = "领取公海客户") |
| 186 | - // TODO @xiaqing:1)receiveCustomer 方法名字;2)cIds 改成 ids,要加下 @RequestParam,还有 swagger 注解;3)参数非空,使用 validator 校验;4)返回 true 即可; | 188 | + @Parameter(name = "ids", description = "批量领取公海的客户id集合", required = true,example = "1,2,3") |
| 187 | @PreAuthorize("@ss.hasPermission('crm:customer:receive')") | 189 | @PreAuthorize("@ss.hasPermission('crm:customer:receive')") |
| 188 | - public CommonResult<String> receiveByIds(List<Long> cIds){ | ||
| 189 | - // 判断是否为空 | ||
| 190 | - if(CollectionUtils.isEmpty(cIds)) | ||
| 191 | - return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg()); | 190 | + public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids){ |
| 192 | // 领取公海任务 | 191 | // 领取公海任务 |
| 193 | - // TODO @xiaqing:userid,通过 controller 传递给 service,不要在 service 里面获取,无状态 | ||
| 194 | - customerService.receive(cIds); | ||
| 195 | - return success("领取成功"); | 192 | + customerService.receiveCustomer(ids, SecurityFrameworkUtils.getLoginUserId()); |
| 193 | + return success(true); | ||
| 196 | } | 194 | } |
| 197 | 195 | ||
| 198 | - // TODO @xiaqing:1)distributeCustomer 方法名;2)cIds 同上;3)参数校验,同上;4)ownerId 改成 ownerUserId,和别的模块统一;5)返回 true 即可; | ||
| 199 | @PutMapping("/distributeByIds") | 196 | @PutMapping("/distributeByIds") |
| 200 | @Operation(summary = "分配公海给对应负责人") | 197 | @Operation(summary = "分配公海给对应负责人") |
| 201 | - @PreAuthorize("@ss.hasPermission('crm:customer:distributeByIds')") | ||
| 202 | - public CommonResult<String> distributeByIds(Long ownerId,List<Long>cIds){ | ||
| 203 | - //判断参数不能为空 | ||
| 204 | - if(ownerId==null || CollectionUtils.isEmpty(cIds)) | ||
| 205 | - return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),GlobalErrorCodeConstants.BAD_REQUEST.getMsg()); | ||
| 206 | - customerService.distributeByIds(cIds,ownerId); | ||
| 207 | - return success("分配成功"); | 198 | + @Parameters({ |
| 199 | + @Parameter(name = "ownerUserId", description = "分配的负责人id", required = true,example = "12345"), | ||
| 200 | + @Parameter(name = "ids", description = "批量分配的公海的客户id集合", required = true,example = "1,2,3") | ||
| 201 | + }) | ||
| 202 | + @PreAuthorize("@ss.hasPermission('crm:customer:distribute')") | ||
| 203 | + public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ownerUserId") Long ownerUserId, | ||
| 204 | + @RequestParam(value = "ids") List<Long>ids){ | ||
| 205 | + customerService.distributeCustomer(ids,ownerUserId); | ||
| 206 | + return success(true); | ||
| 208 | } | 207 | } |
| 209 | 208 | ||
| 210 | } | 209 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; |
| 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 8 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 10 | ||
| 10 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -27,4 +28,10 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> { | @@ -27,4 +28,10 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> { | ||
| 27 | .eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource())); | 28 | .eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource())); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 31 | + default void updateCustomerOwnerUser(Long id,CrmCustomerDO customerDO){ | ||
| 32 | + update(customerDO,new LambdaUpdateWrapper <CrmCustomerDO>() | ||
| 33 | + .eq(CrmCustomerDO::getId,id) | ||
| 34 | + .isNull(CrmCustomerDO::getOwnerUserId) | ||
| 35 | + ); | ||
| 36 | + } | ||
| 30 | } | 37 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
| @@ -85,22 +85,20 @@ public interface CrmCustomerService { | @@ -85,22 +85,20 @@ public interface CrmCustomerService { | ||
| 85 | */ | 85 | */ |
| 86 | void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); | 86 | void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); |
| 87 | 87 | ||
| 88 | - // TODO @xiaqing:根据 controller 的建议,改下 | ||
| 89 | /** | 88 | /** |
| 90 | * 领取公海客户 | 89 | * 领取公海客户 |
| 91 | * | 90 | * |
| 92 | * @param ids 要领取的客户 id | 91 | * @param ids 要领取的客户 id |
| 93 | */ | 92 | */ |
| 94 | - void receive(List<Long>ids); | 93 | + void receiveCustomer(List<Long>ids, Long ownerUserId); |
| 95 | 94 | ||
| 96 | - // TODO @xiaqing:根据 controller 的建议,改下 | ||
| 97 | /** | 95 | /** |
| 98 | * 分配公海客户 | 96 | * 分配公海客户 |
| 99 | * | 97 | * |
| 100 | - * @param cIds 要分配的客户 id | ||
| 101 | - * @param ownerId 分配的负责人id | 98 | + * @param ids 要分配的客户 id |
| 99 | + * @param ownerUserId 分配的负责人id | ||
| 102 | * @author xiaqing | 100 | * @author xiaqing |
| 103 | */ | 101 | */ |
| 104 | - void distributeByIds(List<Long>cIds,Long ownerId); | 102 | + void distributeCustomer(List<Long>ids,Long ownerUserId); |
| 105 | 103 | ||
| 106 | } | 104 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| @@ -83,6 +83,11 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -83,6 +83,11 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 83 | throw exception(CUSTOMER_NOT_EXISTS); | 83 | throw exception(CUSTOMER_NOT_EXISTS); |
| 84 | } | 84 | } |
| 85 | } | 85 | } |
| 86 | + private void validateCustomerExists(CrmCustomerDO customerDO){ | ||
| 87 | + if (customerDO == null) { | ||
| 88 | + throw exception(CUSTOMER_NOT_EXISTS); | ||
| 89 | + } | ||
| 90 | + } | ||
| 86 | 91 | ||
| 87 | @Override | 92 | @Override |
| 88 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ) | 93 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ) |
| @@ -162,53 +167,52 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -162,53 +167,52 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 162 | 167 | ||
| 163 | @Override | 168 | @Override |
| 164 | @Transactional(rollbackFor = Exception.class) | 169 | @Transactional(rollbackFor = Exception.class) |
| 165 | - public void receive(List <Long> ids) { | ||
| 166 | - transferCustomerOwner(ids,SecurityFrameworkUtils.getLoginUserId()); | 170 | + public void receiveCustomer(List <Long> ids,Long ownerUserId) { |
| 171 | + transferCustomerOwner(ids,ownerUserId); | ||
| 167 | } | 172 | } |
| 168 | 173 | ||
| 169 | @Override | 174 | @Override |
| 170 | - public void distributeByIds(List <Long> cIds, Long ownerId) { | ||
| 171 | - transferCustomerOwner(cIds,ownerId); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - private void transferCustomerOwner(List <Long> cIds, Long ownerId){ | ||
| 175 | - // 先一次性校验完成客户是否可用 | ||
| 176 | - // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验; | ||
| 177 | - for (Long cId : cIds) { | ||
| 178 | - //校验是否存在 | ||
| 179 | - validateCustomerExists(cId); | ||
| 180 | - //todo 校验是否已有负责人 | ||
| 181 | - validCustomerOwnerExist(cId); | ||
| 182 | - //todo 校验是否锁定 | ||
| 183 | - validCustomerIsLocked(cId); | ||
| 184 | - //todo 校验成交状态 | ||
| 185 | - validCustomerDeal(cId); | ||
| 186 | - } | ||
| 187 | - // TODO @xiaqing:每个客户更新的时候,where 条件,加上 owner_user_id is null,防止并发问题; | ||
| 188 | - List<CrmCustomerDO> updateDos = new ArrayList <>(); | ||
| 189 | - for (Long cId : cIds){ | ||
| 190 | - CrmCustomerDO customerDO = new CrmCustomerDO(); | ||
| 191 | - customerDO.setId(cId); | ||
| 192 | - customerDO.setOwnerUserId(SecurityFrameworkUtils.getLoginUserId()); | 175 | + public void distributeCustomer(List <Long> ids, Long ownerUserId) { |
| 176 | + transferCustomerOwner(ids,ownerUserId); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + private void transferCustomerOwner(List <Long> ids, Long ownerUserId) { | ||
| 180 | + // 先一次性加载所有数据,校验客户是否可用 | ||
| 181 | + List <CrmCustomerDO> customerDOList = customerMapper.selectBatchIds(ids); | ||
| 182 | + for (CrmCustomerDO customerDO : customerDOList) { | ||
| 183 | + // 校验客户是否存在 | ||
| 184 | + validateCustomerExists(customerDO); | ||
| 185 | + // 校验是否已有负责人 | ||
| 186 | + validCustomerOwnerExist(customerDO); | ||
| 187 | + // 校验是否锁定 | ||
| 188 | + validCustomerIsLocked(customerDO); | ||
| 189 | + // 校验成交状态 | ||
| 190 | + validCustomerDeal(customerDO); | ||
| 193 | } | 191 | } |
| 192 | + | ||
| 194 | // 统一修改状态 | 193 | // 统一修改状态 |
| 195 | - customerMapper.updateBatch(updateDos); | 194 | + CrmCustomerDO updateDo = new CrmCustomerDO(); |
| 195 | + updateDo.setOwnerUserId(ownerUserId); | ||
| 196 | + for (Long id : ids) { | ||
| 197 | + customerMapper.updateCustomerOwnerUser(id,updateDo); | ||
| 198 | + } | ||
| 199 | + | ||
| 196 | } | 200 | } |
| 197 | 201 | ||
| 198 | - private void validCustomerOwnerExist(Long id) { | ||
| 199 | - if (customerMapper.selectById(id).getOwnerUserId()!=null) { | 202 | + private void validCustomerOwnerExist(CrmCustomerDO customerDO) { |
| 203 | + if (customerDO.getOwnerUserId()!=null) { | ||
| 200 | throw exception(CUSTOMER_OWNER_EXISTS); | 204 | throw exception(CUSTOMER_OWNER_EXISTS); |
| 201 | } | 205 | } |
| 202 | } | 206 | } |
| 203 | 207 | ||
| 204 | - private void validCustomerIsLocked(Long id) { | ||
| 205 | - if (customerMapper.selectById(id).getLockStatus() ==true) { | 208 | + private void validCustomerIsLocked(CrmCustomerDO customerDO) { |
| 209 | + if (customerDO.getLockStatus() ==true) { | ||
| 206 | throw exception(CUSTOMER_LOCKED); | 210 | throw exception(CUSTOMER_LOCKED); |
| 207 | } | 211 | } |
| 208 | } | 212 | } |
| 209 | 213 | ||
| 210 | - private void validCustomerDeal(Long id) { | ||
| 211 | - if (customerMapper.selectById(id).getDealStatus() ==true) { | 214 | + private void validCustomerDeal(CrmCustomerDO customerDO) { |
| 215 | + if (customerDO.getDealStatus() ==true) { | ||
| 212 | throw exception(CUSTOMER_ALREADY_DEAL); | 216 | throw exception(CUSTOMER_ALREADY_DEAL); |
| 213 | } | 217 | } |
| 214 | } | 218 | } |