crm-客户:完善 code review 提到的问题

This commit is contained in:
puhui999 2023-11-27 12:00:53 +08:00
parent 7f569f3299
commit 8f06d02293
11 changed files with 157 additions and 708 deletions

View File

@ -32,12 +32,12 @@ public interface ErrorCodeConstants {
// ========== 客户管理 1_020_006_000 ==========
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人");
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定");
ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户【{}】已存在所属负责人");
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户【{}】状态已锁定");
ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易");
ErrorCode CUSTOMER_NOT_IN_POOL = new ErrorCode(1_020_006_004, "客户领取失败,原因:不是公海客户");
ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_005, "客户放入公海失败,原因:已经是公海客户");
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_006, "客户放入公海失败,原因:客户已锁定");
ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_004, "客户【{}】放入公海失败,原因:已经是公海客户");
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
// TODO @wanwan 2 个单独配置段噢
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
@ -47,7 +47,7 @@ public interface ErrorCodeConstants {
ErrorCode CRM_PERMISSION_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限");
ErrorCode CRM_PERMISSION_MODEL_NOT_EXISTS = new ErrorCode(1_020_007_002, "{}不存在");
ErrorCode CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS = new ErrorCode(1_020_007_003, "{}操作失败,原因:转移对象已经是该负责人");
ErrorCode CRM_PERMISSION_DELETE_FAIL = new ErrorCode(1_020_007_004, "删除数据权限失败,原因:参数异常");
ErrorCode CRM_PERMISSION_DELETE_FAIL = new ErrorCode(1_020_007_004, "删除数据权限失败,原因:批量删除权限的时候,只能属于同一个 bizId 下");
ErrorCode CRM_PERMISSION_DELETE_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_005, "删除数据权限失败,原因:存在负责人");
ErrorCode CRM_PERMISSION_DELETE_DENIED = new ErrorCode(1_020_007_006, "删除数据权限失败,原因:没有权限");
ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人");

View File

@ -7,7 +7,7 @@ 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.module.crm.controller.admin.contact.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@ -33,6 +33,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -83,7 +84,7 @@ public class ContactController {
public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) {
ContactDO contact = contactService.getContact(id);
// TODO @zyna需要考虑 null 的情况
ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
// TODO @zyna可以把数据读完后convert 统一交给 ContactConvert controller 更简洁 convert 专门去做一些转换逻辑
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
NumberUtil.parseLong(contact.getCreator()))));
@ -107,12 +108,14 @@ public class ContactController {
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
PageResult<ContactDO> pageData = contactService.getContactPage(pageVO);
PageResult<ContactRespVO> pageResult =ContactConvert.INSTANCE.convertPage(pageData);
PageResult<ContactRespVO> pageResult = ContactConvert.INSTANCE.convertPage(pageData);
// TODO @zyna需要考虑 null 的情况
// TODO @zyna可以把数据读完后convert 统一交给 ContactConvert controller 更简洁 convert 专门去做一些转换逻辑
//待接口实现后修改
List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(new CrmCustomerExportReqVO());
Map<Long,CrmCustomerDO> crmCustomerDOMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
reqVO.setPageSize(PAGE_SIZE_NONE);
List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerPage(reqVO, getLoginUserId()).getList();
Map<Long, CrmCustomerDO> crmCustomerDOMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId, v -> v));
pageResult.getList().forEach(item -> {
item.setCustomerName(Optional.ofNullable(crmCustomerDOMap.get(item.getCustomerId())).map(CrmCustomerDO::getName).orElse(null));
});
@ -125,7 +128,7 @@ public class ContactController {
@PreAuthorize("@ss.hasPermission('crm:contact:export')")
@OperateLog(type = EXPORT)
public void exportContactExcel(@Valid ContactExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
List<ContactDO> list = contactService.getContactList(exportReqVO);
// 导出 Excel
List<ContactExcelVO> datas = ContactConvert.INSTANCE.convertList02(list);

View File

@ -91,16 +91,6 @@ public class CrmCustomerController {
return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
}
// TODO @puhui999合并到 receiveCustomer
@PutMapping("/receive-")
@Operation(summary = "领取客户公海数据")
@Parameter(name = "id", description = "客户编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> receive(@RequestParam("id") Long id) {
customerService.receive(id, getLoginUserId());
return success(true);
}
@GetMapping("/page")
@Operation(summary = "获得客户分页")
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
@ -122,9 +112,9 @@ public class CrmCustomerController {
@Operation(summary = "导出客户 Excel")
@PreAuthorize("@ss.hasPermission('crm:customer:export')")
@OperateLog(type = EXPORT)
public void exportCustomerExcel(@Valid CrmCustomerExportReqVO exportReqVO,
public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO,
HttpServletResponse response) throws IOException {
List<CrmCustomerDO> list = customerService.getCustomerList(exportReqVO);
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
// 导出 Excel
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
@ -160,9 +150,9 @@ public class CrmCustomerController {
@PutMapping("/receive")
@Operation(summary = "领取公海客户")
@Parameter(name = "ids", description = "编号数组", required = true,example = "1,2,3")
@Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
@PreAuthorize("@ss.hasPermission('crm:customer:receive')")
public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids){
public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids) {
customerService.receiveCustomer(ids, getLoginUserId());
return success(true);
}
@ -175,8 +165,11 @@ public class CrmCustomerController {
})
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
@RequestParam(value = "ownerUserId") Long ownerUserId){
customerService.distributeCustomer(ids, ownerUserId);
@RequestParam(value = "ownerUserId") Long ownerUserId) {
// 校验负责人是否存在
adminUserApi.validateUserList(java.util.Collections.singletonList(ownerUserId));
// 领取公海数据
customerService.receiveCustomer(ids, ownerUserId);
return success(true);
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO 芋艿导出最后做等基本确认的差不多之后
@Schema(description = "管理后台 - CRM 客户 Excel 导出 Request VO参数和 CrmCustomerPageReqVO 是一致的")
@Data
public class CrmCustomerExportReqVO {
@Schema(description = "客户名称", example = "赵六")
private String name;
@Schema(description = "手机", example = "18000000000")
private String mobile;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.dal.mysql.customer;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -14,6 +15,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 客户 Mapper
*
@ -22,74 +25,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO) {
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
if (pageReqVO.getPool()) { // 情况一公海
queryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else {// 情况一不是公海
queryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
return selectPage(pageReqVO, queryWrapperX
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
}
// TODO @puhui999这个方法还要哇
default PageResult<CrmCustomerDO> selectPage1(CrmCustomerPageReqVO pageReqVO, Long userId) {
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
//queryWrapperX.sql
if (pageReqVO.getPool()) { // 情况一公海
queryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else {// 情况一不是公海
queryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
return selectPage(pageReqVO, queryWrapperX
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
}
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO);
MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件
//CrmPermissionUtils.builderRightJoinQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CUSTOMER.getType(), userId);
mpjLambdaWrapperX
//.rightJoin("(SELECT t1.biz_id FROM crm_permission t1 WHERE (t1.biz_type = 1 AND t1.user_id = 1)) t2 on t.id = t2.biz_id");
.rightJoin(CrmPermissionDO.class, CrmPermissionDO::getBizId, CrmCustomerDO::getId) // TODO @puhui999应该是 inner join
.eq(CrmPermissionDO::getBizType, CrmBizTypeEnum.CRM_CUSTOMER.getType())
.eq(CrmPermissionDO::getUserId, userId);
/** TODO @芋艿
-- 常规连表-查询正常
| ==> Preparing:
SELECT t.id, t.name, t.follow_up_status, t.lock_status, t.deal_status,
t.industry_id, t.level, t.source, t.mobile, t.telephone, t.website,
t.qq, t.wechat, t.email, t.description, t.remark, t.owner_user_id,
t.area_id, t.detail_address, t.contact_last_time, t.contact_next_time,
t.create_time, t.update_time, t.creator, t.updater, t.deleted
FROM crm_customer t RIGHT JOIN crm_permission t1 ON (t1.biz_id = t.id) AND t.tenant_id = 1
WHERE t.deleted = 0 AND t1.deleted = 0
AND (t1.biz_type = ? AND t1.user_id = ?
AND t.owner_user_id IS NOT NULL AND t.level = ?) AND t1.tenant_id = 1 LIMIT ?
| ==> Parameters: 2(Integer), 1(Long), 3(Integer), 10(Long)
-- 连接子查询-报错但是复制到 navicat 是可以正常执行的
-- 区别点常规连表会自动拼接租户 AND t.tenant_id = 1
SELECT
t.id,t.name,t.follow_up_status,t.lock_status,t.deal_status,t.industry_id,t.level,
t.source,t.mobile,t.telephone,t.website,t.qq,t.wechat,t.email,t.description,t.remark,
t.owner_user_id,t.area_id,t.detail_address,t.contact_last_time,t.contact_next_time,
t.create_time,t.update_time,t.creator,t.updater,t.deleted
FROM crm_customer t
RIGHT JOIN (SELECT t1.biz_id FROM crm_permission t1 WHERE (t1.biz_type = 2 AND t1.user_id = 1)) t2 on t.id = t2.biz_id
WHERE t.deleted=0
AND (t.owner_user_id IS NOT NULL)
*/
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
@ -99,20 +35,60 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
mpPage = selectJoinPage(mpPage, CrmCustomerDO.class, mpjLambdaWrapperX
}
static void appendQueryParams(LambdaQueryWrapperX<CrmCustomerDO> lambdaQueryWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
lambdaQueryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
lambdaQueryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
// TODO 场景数据过滤
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
lambdaQueryWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
}
default int updateOwnerUserIdById(Long id, Long ownerUserId) {
return update(new LambdaUpdateWrapper<CrmCustomerDO>()
.eq(CrmCustomerDO::getId, id)
.set(CrmCustomerDO::getOwnerUserId, ownerUserId));
}
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId, Boolean admin) {
if (admin) { // 情况一管理员查看
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
appendQueryParams(queryWrapperX, pageReqVO, userId);
return selectPage(pageReqVO, queryWrapperX
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
}
// 情况二获取当前用户能看的分页数据
IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO);
MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件
mpjLambdaWrapperX
.innerJoin(CrmPermissionDO.class, CrmPermissionDO::getBizId, CrmCustomerDO::getId)
.eq(CrmPermissionDO::getBizType, CrmBizTypeEnum.CRM_CUSTOMER.getType())
.eq(CrmPermissionDO::getUserId, userId);
appendQueryParams(mpjLambdaWrapperX, pageReqVO, userId);
mpjLambdaWrapperX
.selectAll(CrmCustomerDO.class)
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource());
// 特殊不分页直接查询全部
if (PageParam.PAGE_SIZE_NONE.equals(pageReqVO.getPageNo())) {
List<CrmCustomerDO> list = selectJoinList(CrmCustomerDO.class, mpjLambdaWrapperX);
return new PageResult<>(list, (long) list.size());
}
mpPage = selectJoinPage(mpPage, CrmCustomerDO.class, mpjLambdaWrapperX);
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
}
default void updateCustomerByOwnerUserIdIsNull(Long id, CrmCustomerDO updateObj) {
update(updateObj, new LambdaUpdateWrapper<CrmCustomerDO>()
.eq(CrmCustomerDO::getId, id)
.isNull(CrmCustomerDO::getOwnerUserId));
}
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import javax.validation.Valid;
@ -50,8 +53,8 @@ public interface CrmCustomerService {
* 获得客户列表
*
* @param ids 客户编号数组
* @author ljlleo
* @return 客户列表
* @author ljlleo
*/
List<CrmCustomerDO> getCustomerList(Collection<Long> ids);
@ -64,14 +67,6 @@ public interface CrmCustomerService {
*/
PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId);
/**
* 获得客户列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 客户列表
*/
List<CrmCustomerDO> getCustomerList(CrmCustomerExportReqVO exportReqVO);
/**
* 校验客户是否存在
*
@ -107,25 +102,9 @@ public interface CrmCustomerService {
/**
* 领取公海客户
*
* @param ids 要领取的客户编号数组
* @param ids 要领取的客户编号数组
* @param ownerUserId 负责人
*/
void receiveCustomer(List<Long>ids, Long ownerUserId);
/**
* 分配公海客户
*
* @param ids 要分配的客户编号数组
* @param ownerUserId 分配的负责人编号
* @author xiaqing
*/
void distributeCustomer(List<Long>ids, Long ownerUserId);
/**
* 领取公海客户
*
* @param id 编号
* @param userId 用户编号
*/
void receive(Long id, Long userId);
void receiveCustomer(List<Long> ids, Long ownerUserId);
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
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.mysql.customer.CrmCustomerMapper;
@ -15,8 +18,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -95,18 +98,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
// 1.1. TODO 如果是超级管理员
boolean admin = false;
if (admin) {
return customerMapper.selectPage(pageReqVO);
}
// 1.2. 获取当前用户能看的分页数据
return customerMapper.selectPage(pageReqVO, userId);
}
@Override
public List<CrmCustomerDO> getCustomerList(CrmCustomerExportReqVO exportReqVO) {
//return customerMapper.selectList(exportReqVO);
// TODO puhui999: 等数据权限完善后再实现
return Collections.emptyList();
return customerMapper.selectPage(pageReqVO, userId, admin);
}
/**
@ -152,54 +144,81 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
public void receiveCustomer(List <Long> ids,Long ownerUserId) {
transferCustomerOwner(ids, ownerUserId);
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putCustomerPool(Long id) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验是否为公海数据
validateCustomerOwnerExists(customer, true);
// 1.3. 校验客户是否锁定
validateCustomerIsLocked(customer, true);
// 2. 设置负责人为 NULL
int updateOwnerUserIncr = customerMapper.updateOwnerUserIdById(customer.getId(), null);
if (updateOwnerUserIncr == 0) {
throw exception(CUSTOMER_UPDATE_OWNER_USER_FAIL);
}
// 3. 删除负责人数据权限
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
CrmPermissionLevelEnum.OWNER.getLevel());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void distributeCustomer(List <Long> ids, Long ownerUserId) {
transferCustomerOwner(ids, ownerUserId);
}
/**
* 转移客户负责人
*
* @param ids 客户编号数组
* @param ownerUserId 负责人编号
*/
private void transferCustomerOwner(List <Long> ids, Long ownerUserId) {
// 先一次性加载所有数据校验客户是否可用
List <CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
for (CrmCustomerDO customer : customers) {
public void receiveCustomer(List<Long> ids, Long ownerUserId) {
// 1. 校验存在
List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
if (customers.size() != ids.size()) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验状态
customers.forEach(customer -> {
// 校验是否已有负责人
validateCustomerOwnerExists(customer);
validateCustomerOwnerExists(customer, false);
// 校验是否锁定
validateCustomerIsLocked(customer);
validateCustomerIsLocked(customer, false);
// 校验成交状态
validateCustomerDeal(customer);
}
});
// TODO @QingX这里是不是改成一次性更新不然如果有 20 个客户就要执行 20 SQL
// 统一修改状态
CrmCustomerDO updateDo = new CrmCustomerDO();
updateDo.setOwnerUserId(ownerUserId);
// TODO @QingX如果更新的数量不对则应该抛出异常回滚并错误提示
for (Long id : ids) {
customerMapper.updateCustomerByOwnerUserIdIsNull(id,updateDo);
}
// 2. 领取公海数据
List<CrmCustomerDO> updateCustomers = new ArrayList<>();
List<CrmPermissionCreateReqBO> createPermissions = new ArrayList<>();
customers.forEach(customer -> {
// 2.1. 设置负责人
updateCustomers.add(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(ownerUserId));
// 2.2. 创建负责人数据权限
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(ownerUserId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
});
// 3.1 更新客户负责人
customerMapper.updateBatch(updateCustomers);
// 3.2 创建负责人数据权限
crmPermissionService.createPermissionBatch(createPermissions);
}
// TODO @QingX错误提示里面可以把客户的名字带上哈不然不知道是谁
private void validateCustomerOwnerExists(CrmCustomerDO customer) {
private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
if (customer == null) { // 防御一下
throw exception(CUSTOMER_NOT_EXISTS);
}
// 校验是否为公海数据
if (pool && customer.getOwnerUserId() == null) {
throw exception(CUSTOMER_IN_POOL, customer.getName());
}
// 负责人已存在
if (customer.getOwnerUserId() != null) {
throw exception(CUSTOMER_OWNER_EXISTS);
throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
}
}
private void validateCustomerIsLocked(CrmCustomerDO customer) {
private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
if (customer.getLockStatus()) {
throw exception(CUSTOMER_LOCKED);
throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
}
}
@ -209,52 +228,4 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
}
}
// TODO @puhui999合并到 receiveCustomer
@Override
@Transactional(rollbackFor = Exception.class)
public void receive(Long id, Long userId) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验是否为公海数据
if (customer.getOwnerUserId() != null) {
throw exception(CUSTOMER_NOT_IN_POOL);
}
// 2. 领取公海数据-设置负责人
customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(userId));
// 3. 创建负责人数据权限
crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
}
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putCustomerPool(Long id) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// TODO puhui999校验合并到 validateCustomerOwnerExistsvalidateCustomerIsLocked
// 1.2. 校验是否为公海数据
if (customer.getOwnerUserId() == null) {
throw exception(CUSTOMER_IN_POOL);
}
// 1.3. 校验客户是否锁定
if (customer.getLockStatus()) {
throw exception(CUSTOMER_LOCKED_PUT_POOL_FAIL);
}
// 2. 设置负责人为 NULL
// TODO @puhui999updateById 这么操作是无法设置 null
customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null));
// 3. 删除负责人数据权限
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
CrmPermissionLevelEnum.OWNER.getLevel());
}
}

View File

@ -1,117 +0,0 @@
package cn.iocoder.yudao.module.crm.service.business;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.BusinessStatusTypePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.BusinessStatusTypeSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.BusinessStatusTypeDO;
import cn.iocoder.yudao.module.crm.dal.mysql.business.BusinessStatusTypeMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_STATUS_TYPE_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link BusinessStatusTypeServiceImpl} 的单元测试类
*
* @author ljlleo
*/
@Import(BusinessStatusTypeServiceImpl.class)
public class BusinessStatusTypeServiceImplTest extends BaseDbUnitTest {
@Resource
private BusinessStatusTypeServiceImpl businessStatusTypeService;
@Resource
private BusinessStatusTypeMapper businessStatusTypeMapper;
@Test
public void testCreateBusinessStatusType_success() {
// 准备参数
BusinessStatusTypeSaveReqVO createReqVO = randomPojo(BusinessStatusTypeSaveReqVO.class).setId(null);
// 调用
Long businessStatusTypeId = businessStatusTypeService.createBusinessStatusType(createReqVO);
// 断言
assertNotNull(businessStatusTypeId);
// 校验记录的属性是否正确
BusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(businessStatusTypeId);
assertPojoEquals(createReqVO, businessStatusType, "id");
}
@Test
public void testUpdateBusinessStatusType_success() {
// mock 数据
BusinessStatusTypeDO dbBusinessStatusType = randomPojo(BusinessStatusTypeDO.class);
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
// 准备参数
BusinessStatusTypeSaveReqVO updateReqVO = randomPojo(BusinessStatusTypeSaveReqVO.class, o -> {
o.setId(dbBusinessStatusType.getId()); // 设置更新的 ID
});
// 调用
businessStatusTypeService.updateBusinessStatusType(updateReqVO);
// 校验是否更新正确
BusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, businessStatusType);
}
@Test
public void testUpdateBusinessStatusType_notExists() {
// 准备参数
BusinessStatusTypeSaveReqVO updateReqVO = randomPojo(BusinessStatusTypeSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> businessStatusTypeService.updateBusinessStatusType(updateReqVO), BUSINESS_STATUS_TYPE_NOT_EXISTS);
}
@Test
public void testDeleteBusinessStatusType_success() {
// mock 数据
BusinessStatusTypeDO dbBusinessStatusType = randomPojo(BusinessStatusTypeDO.class);
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbBusinessStatusType.getId();
// 调用
businessStatusTypeService.deleteBusinessStatusType(id);
// 校验数据不存在了
assertNull(businessStatusTypeMapper.selectById(id));
}
@Test
public void testDeleteBusinessStatusType_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> businessStatusTypeService.deleteBusinessStatusType(id), BUSINESS_STATUS_TYPE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBusinessStatusTypePage() {
// mock 数据
BusinessStatusTypeDO dbBusinessStatusType = randomPojo(BusinessStatusTypeDO.class, o -> { // 等会查询到
});
businessStatusTypeMapper.insert(dbBusinessStatusType);
// 准备参数
BusinessStatusTypePageReqVO reqVO = new BusinessStatusTypePageReqVO();
// 调用
PageResult<BusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbBusinessStatusType, pageResult.getList().get(0));
}
}

View File

@ -1,168 +0,0 @@
package cn.iocoder.yudao.module.crm.service.businessstatus;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatus.vo.CrmBusinessStatusCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatus.vo.CrmBusinessStatusExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatus.vo.CrmBusinessStatusUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatus.CrmBusinessStatusDO;
import cn.iocoder.yudao.module.crm.dal.mysql.businessstatus.CrmBusinessStatusMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_STATUS_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link CrmBusinessStatusServiceImpl} 的单元测试类
*
* @author ljlleo
*/
@Import(CrmBusinessStatusServiceImpl.class)
public class CrmBusinessStatusServiceImplTest extends BaseDbUnitTest {
@Resource
private CrmBusinessStatusServiceImpl businessStatusService;
@Resource
private CrmBusinessStatusMapper businessStatusMapper;
@Test
public void testCreateBusinessStatus_success() {
// 准备参数
CrmBusinessStatusCreateReqVO reqVO = randomPojo(CrmBusinessStatusCreateReqVO.class);
// 调用
Long businessStatusId = businessStatusService.createBusinessStatus(reqVO);
// 断言
assertNotNull(businessStatusId);
// 校验记录的属性是否正确
CrmBusinessStatusDO businessStatus = businessStatusMapper.selectById(businessStatusId);
assertPojoEquals(reqVO, businessStatus);
}
@Test
public void testUpdateBusinessStatus_success() {
// mock 数据
CrmBusinessStatusDO dbBusinessStatus = randomPojo(CrmBusinessStatusDO.class);
businessStatusMapper.insert(dbBusinessStatus);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmBusinessStatusUpdateReqVO reqVO = randomPojo(CrmBusinessStatusUpdateReqVO.class, o -> {
o.setId(dbBusinessStatus.getId()); // 设置更新的 ID
});
// 调用
businessStatusService.updateBusinessStatus(reqVO);
// 校验是否更新正确
CrmBusinessStatusDO businessStatus = businessStatusMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, businessStatus);
}
@Test
public void testUpdateBusinessStatus_notExists() {
// 准备参数
CrmBusinessStatusUpdateReqVO reqVO = randomPojo(CrmBusinessStatusUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> businessStatusService.updateBusinessStatus(reqVO), BUSINESS_STATUS_NOT_EXISTS);
}
@Test
public void testDeleteBusinessStatus_success() {
// mock 数据
CrmBusinessStatusDO dbBusinessStatus = randomPojo(CrmBusinessStatusDO.class);
businessStatusMapper.insert(dbBusinessStatus);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbBusinessStatus.getId();
// 调用
businessStatusService.deleteBusinessStatus(id);
// 校验数据不存在了
assertNull(businessStatusMapper.selectById(id));
}
@Test
public void testDeleteBusinessStatus_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> businessStatusService.deleteBusinessStatus(id), BUSINESS_STATUS_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBusinessStatusPage() {
// mock 数据
CrmBusinessStatusDO dbBusinessStatus = randomPojo(CrmBusinessStatusDO.class, o -> { // 等会查询到
o.setTypeId(null);
o.setName(null);
o.setPercent(null);
o.setSort(null);
});
businessStatusMapper.insert(dbBusinessStatus);
// 测试 typeId 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setTypeId(null)));
// 测试 name 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setName(null)));
// 测试 percent 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setPercent(null)));
// 测试 sort 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setSort(null)));
// 准备参数
//CrmBusinessStatusPageReqVO reqVO = new CrmBusinessStatusPageReqVO();
//reqVO.setTypeId(null);
//reqVO.setName(null);
//reqVO.setPercent(null);
//reqVO.setSort(null);
//
//// 调用
//PageResult<CrmBusinessStatusDO> pageResult = businessStatusService.getBusinessStatusPage(reqVO);
//// 断言
//assertEquals(1, pageResult.getTotal());
//assertEquals(1, pageResult.getList().size());
//assertPojoEquals(dbBusinessStatus, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBusinessStatusList() {
// mock 数据
CrmBusinessStatusDO dbBusinessStatus = randomPojo(CrmBusinessStatusDO.class, o -> { // 等会查询到
o.setTypeId(null);
o.setName(null);
o.setPercent(null);
o.setSort(null);
});
businessStatusMapper.insert(dbBusinessStatus);
// 测试 typeId 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setTypeId(null)));
// 测试 name 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setName(null)));
// 测试 percent 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setPercent(null)));
// 测试 sort 不匹配
businessStatusMapper.insert(cloneIgnoreId(dbBusinessStatus, o -> o.setSort(null)));
// 准备参数
CrmBusinessStatusExportReqVO reqVO = new CrmBusinessStatusExportReqVO();
reqVO.setTypeId(null);
reqVO.setName(null);
reqVO.setPercent(null);
reqVO.setSort(null);
// 调用
List<CrmBusinessStatusDO> list = businessStatusService.getBusinessStatusList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbBusinessStatus, list.get(0));
}
}

View File

@ -1,171 +0,0 @@
package cn.iocoder.yudao.module.crm.service.businessstatustype;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatustype.vo.CrmBusinessStatusTypeCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatustype.vo.CrmBusinessStatusTypeExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatustype.vo.CrmBusinessStatusTypePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.businessstatustype.vo.CrmBusinessStatusTypeUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatustype.CrmBusinessStatusTypeDO;
import cn.iocoder.yudao.module.crm.dal.mysql.businessstatustype.CrmBusinessStatusTypeMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_STATUS_TYPE_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link CrmBusinessStatusTypeServiceImpl} 的单元测试类
*
* @author ljlleo
*/
@Import(CrmBusinessStatusTypeServiceImpl.class)
public class CrmBusinessStatusTypeServiceImplTest extends BaseDbUnitTest {
@Resource
private CrmBusinessStatusTypeServiceImpl businessStatusTypeService;
@Resource
private CrmBusinessStatusTypeMapper businessStatusTypeMapper;
@Test
public void testCreateBusinessStatusType_success() {
// 准备参数
CrmBusinessStatusTypeCreateReqVO reqVO = randomPojo(CrmBusinessStatusTypeCreateReqVO.class);
// 调用
Long businessStatusTypeId = businessStatusTypeService.createBusinessStatusType(reqVO);
// 断言
assertNotNull(businessStatusTypeId);
// 校验记录的属性是否正确
CrmBusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(businessStatusTypeId);
assertPojoEquals(reqVO, businessStatusType);
}
@Test
public void testUpdateBusinessStatusType_success() {
// mock 数据
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class);
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmBusinessStatusTypeUpdateReqVO reqVO = randomPojo(CrmBusinessStatusTypeUpdateReqVO.class, o -> {
o.setId(dbBusinessStatusType.getId()); // 设置更新的 ID
});
// 调用
businessStatusTypeService.updateBusinessStatusType(reqVO);
// 校验是否更新正确
CrmBusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, businessStatusType);
}
@Test
public void testUpdateBusinessStatusType_notExists() {
// 准备参数
CrmBusinessStatusTypeUpdateReqVO reqVO = randomPojo(CrmBusinessStatusTypeUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> businessStatusTypeService.updateBusinessStatusType(reqVO), BUSINESS_STATUS_TYPE_NOT_EXISTS);
}
@Test
public void testDeleteBusinessStatusType_success() {
// mock 数据
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class);
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbBusinessStatusType.getId();
// 调用
businessStatusTypeService.deleteBusinessStatusType(id);
// 校验数据不存在了
assertNull(businessStatusTypeMapper.selectById(id));
}
@Test
public void testDeleteBusinessStatusType_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> businessStatusTypeService.deleteBusinessStatusType(id), BUSINESS_STATUS_TYPE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBusinessStatusTypePage() {
// mock 数据
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class, o -> { // 等会查询到
o.setName(null);
o.setDeptIds(null);
o.setStatus(null);
//o.setCreateTime(null);
});
businessStatusTypeMapper.insert(dbBusinessStatusType);
// 测试 name 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setName(null)));
// 测试 deptIds 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setDeptIds(null)));
// 测试 status 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setStatus(null)));
// 测试 createTime 不匹配
//businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setCreateTime(null)));
// 准备参数
CrmBusinessStatusTypePageReqVO reqVO = new CrmBusinessStatusTypePageReqVO();
reqVO.setName(null);
//reqVO.setDeptIds(null);
reqVO.setStatus(null);
//reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbBusinessStatusType, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetBusinessStatusTypeList() {
// mock 数据
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class, o -> { // 等会查询到
o.setName(null);
o.setDeptIds(null);
o.setStatus(null);
//o.setCreateTime(null);
});
businessStatusTypeMapper.insert(dbBusinessStatusType);
// 测试 name 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setName(null)));
// 测试 deptIds 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setDeptIds(null)));
// 测试 status 不匹配
businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setStatus(null)));
// 测试 createTime 不匹配
//businessStatusTypeMapper.insert(cloneIgnoreId(dbBusinessStatusType, o -> o.setCreateTime(null)));
// 准备参数
CrmBusinessStatusTypeExportReqVO reqVO = new CrmBusinessStatusTypeExportReqVO();
reqVO.setName(null);
reqVO.setDeptIds(null);
reqVO.setStatus(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<CrmBusinessStatusTypeDO> list = businessStatusTypeService.getBusinessStatusTypeList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbBusinessStatusType, list.get(0));
}
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@ -15,8 +14,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
@ -160,17 +159,18 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
// 测试 website 不匹配
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setWebsite(null)));
// 准备参数
CrmCustomerExportReqVO reqVO = new CrmCustomerExportReqVO();
reqVO.setName(null);
reqVO.setMobile(null);
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
reqVO.setName("张三");
reqVO.setMobile("13888888888");
reqVO.setPageSize(PAGE_SIZE_NONE);
//reqVO.setTelephone(null);
//reqVO.setWebsite(null);
// 调用
List<CrmCustomerDO> list = customerService.getCustomerList(reqVO);
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(reqVO, 1L);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbCustomer, list.get(0));
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbCustomer, pageResult.getList().get(0));
}
}