mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
crm-客户:完善 code review 提到的问题
This commit is contained in:
parent
7f569f3299
commit
8f06d02293
@ -32,12 +32,12 @@ public interface ErrorCodeConstants {
|
|||||||
|
|
||||||
// ========== 客户管理 1_020_006_000 ==========
|
// ========== 客户管理 1_020_006_000 ==========
|
||||||
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(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_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户【{}】已存在所属负责人");
|
||||||
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定");
|
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户【{}】状态已锁定");
|
||||||
ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易");
|
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_004, "客户【{}】放入公海失败,原因:已经是公海客户");
|
||||||
ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_005, "客户放入公海失败,原因:已经是公海客户");
|
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
|
||||||
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_006, "客户放入公海失败,原因:客户已锁定");
|
ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
|
||||||
// TODO @wanwan:这 2 个单独配置段噢
|
// TODO @wanwan:这 2 个单独配置段噢
|
||||||
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
|
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
|
||||||
ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
|
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_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限");
|
||||||
ErrorCode CRM_PERMISSION_MODEL_NOT_EXISTS = new ErrorCode(1_020_007_002, "{}不存在");
|
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_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_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_005, "删除数据权限失败,原因:存在负责人");
|
||||||
ErrorCode CRM_PERMISSION_DELETE_DENIED = new ErrorCode(1_020_007_006, "删除数据权限失败,原因:没有权限");
|
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, "删除数据权限失败,原因:不能删除负责人");
|
ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人");
|
||||||
|
@ -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.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.module.crm.controller.admin.contact.vo.*;
|
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.convert.contact.ContactConvert;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||||
@ -33,6 +33,7 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
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.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
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) {
|
public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) {
|
||||||
ContactDO contact = contactService.getContact(id);
|
ContactDO contact = contactService.getContact(id);
|
||||||
// TODO @zyna:需要考虑 null 的情况;
|
// TODO @zyna:需要考虑 null 的情况;
|
||||||
ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
|
ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
|
||||||
// TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
// TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
||||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
|
||||||
NumberUtil.parseLong(contact.getCreator()))));
|
NumberUtil.parseLong(contact.getCreator()))));
|
||||||
@ -107,12 +108,14 @@ public class ContactController {
|
|||||||
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
||||||
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
|
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
|
||||||
PageResult<ContactDO> pageData = contactService.getContactPage(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:需要考虑 null 的情况;
|
||||||
// TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
// TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
||||||
//待接口实现后修改
|
//待接口实现后修改
|
||||||
List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(new CrmCustomerExportReqVO());
|
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
|
||||||
Map<Long,CrmCustomerDO> crmCustomerDOMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
|
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 -> {
|
pageResult.getList().forEach(item -> {
|
||||||
item.setCustomerName(Optional.ofNullable(crmCustomerDOMap.get(item.getCustomerId())).map(CrmCustomerDO::getName).orElse(null));
|
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')")
|
@PreAuthorize("@ss.hasPermission('crm:contact:export')")
|
||||||
@OperateLog(type = EXPORT)
|
@OperateLog(type = EXPORT)
|
||||||
public void exportContactExcel(@Valid ContactExportReqVO exportReqVO,
|
public void exportContactExcel(@Valid ContactExportReqVO exportReqVO,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
List<ContactDO> list = contactService.getContactList(exportReqVO);
|
List<ContactDO> list = contactService.getContactList(exportReqVO);
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
List<ContactExcelVO> datas = ContactConvert.INSTANCE.convertList02(list);
|
List<ContactExcelVO> datas = ContactConvert.INSTANCE.convertList02(list);
|
||||||
|
@ -91,16 +91,6 @@ public class CrmCustomerController {
|
|||||||
return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
|
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")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获得客户分页")
|
@Operation(summary = "获得客户分页")
|
||||||
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
|
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
|
||||||
@ -122,9 +112,9 @@ public class CrmCustomerController {
|
|||||||
@Operation(summary = "导出客户 Excel")
|
@Operation(summary = "导出客户 Excel")
|
||||||
@PreAuthorize("@ss.hasPermission('crm:customer:export')")
|
@PreAuthorize("@ss.hasPermission('crm:customer:export')")
|
||||||
@OperateLog(type = EXPORT)
|
@OperateLog(type = EXPORT)
|
||||||
public void exportCustomerExcel(@Valid CrmCustomerExportReqVO exportReqVO,
|
public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
List<CrmCustomerDO> list = customerService.getCustomerList(exportReqVO);
|
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
|
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
|
||||||
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
|
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
|
||||||
@ -160,9 +150,9 @@ public class CrmCustomerController {
|
|||||||
|
|
||||||
@PutMapping("/receive")
|
@PutMapping("/receive")
|
||||||
@Operation(summary = "领取公海客户")
|
@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')")
|
@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());
|
customerService.receiveCustomer(ids, getLoginUserId());
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
@ -175,8 +165,11 @@ public class CrmCustomerController {
|
|||||||
})
|
})
|
||||||
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
|
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
|
||||||
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
|
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
|
||||||
@RequestParam(value = "ownerUserId") Long ownerUserId){
|
@RequestParam(value = "ownerUserId") Long ownerUserId) {
|
||||||
customerService.distributeCustomer(ids, ownerUserId);
|
// 校验负责人是否存在
|
||||||
|
adminUserApi.validateUserList(java.util.Collections.singletonList(ownerUserId));
|
||||||
|
// 领取公海数据
|
||||||
|
customerService.receiveCustomer(ids, ownerUserId);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.crm.dal.mysql.customer;
|
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.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
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;
|
||||||
@ -14,6 +15,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户 Mapper
|
* 客户 Mapper
|
||||||
*
|
*
|
||||||
@ -22,74 +25,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
||||||
|
|
||||||
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO) {
|
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
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)
|
|
||||||
*/
|
|
||||||
if (pageReqVO.getPool()) { // 情况一:公海
|
if (pageReqVO.getPool()) { // 情况一:公海
|
||||||
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
|
||||||
} else { // 情况二:不是公海
|
} else { // 情况二:不是公海
|
||||||
@ -99,20 +35,60 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
|||||||
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一:我负责的数据
|
||||||
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
|
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)
|
.selectAll(CrmCustomerDO.class)
|
||||||
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
|
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
|
||||||
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
|
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
|
||||||
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
|
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
|
||||||
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
|
.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());
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.crm.service.customer;
|
package cn.iocoder.yudao.module.crm.service.customer;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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 cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -50,8 +53,8 @@ public interface CrmCustomerService {
|
|||||||
* 获得客户列表
|
* 获得客户列表
|
||||||
*
|
*
|
||||||
* @param ids 客户编号数组
|
* @param ids 客户编号数组
|
||||||
* @author ljlleo
|
|
||||||
* @return 客户列表
|
* @return 客户列表
|
||||||
|
* @author ljlleo
|
||||||
*/
|
*/
|
||||||
List<CrmCustomerDO> getCustomerList(Collection<Long> ids);
|
List<CrmCustomerDO> getCustomerList(Collection<Long> ids);
|
||||||
|
|
||||||
@ -64,14 +67,6 @@ public interface CrmCustomerService {
|
|||||||
*/
|
*/
|
||||||
PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId);
|
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);
|
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.crm.service.customer;
|
package cn.iocoder.yudao.module.crm.service.customer;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.convert.customer.CrmCustomerConvert;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
|
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 org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -95,18 +98,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|||||||
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
|
||||||
// 1.1. TODO 如果是超级管理员
|
// 1.1. TODO 如果是超级管理员
|
||||||
boolean admin = false;
|
boolean admin = false;
|
||||||
if (admin) {
|
return customerMapper.selectPage(pageReqVO, userId, 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,54 +144,81 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void receiveCustomer(List <Long> ids,Long ownerUserId) {
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||||
transferCustomerOwner(ids, ownerUserId);
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void distributeCustomer(List <Long> ids, Long ownerUserId) {
|
public void receiveCustomer(List<Long> ids, Long ownerUserId) {
|
||||||
transferCustomerOwner(ids, ownerUserId);
|
// 1. 校验存在
|
||||||
}
|
List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
|
||||||
|
if (customers.size() != ids.size()) {
|
||||||
/**
|
throw exception(CUSTOMER_NOT_EXISTS);
|
||||||
* 转移客户负责人
|
}
|
||||||
*
|
// 1.2. 校验状态
|
||||||
* @param ids 客户编号数组
|
customers.forEach(customer -> {
|
||||||
* @param ownerUserId 负责人编号
|
|
||||||
*/
|
|
||||||
private void transferCustomerOwner(List <Long> ids, Long ownerUserId) {
|
|
||||||
// 先一次性加载所有数据,校验客户是否可用
|
|
||||||
List <CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
|
|
||||||
for (CrmCustomerDO customer : customers) {
|
|
||||||
// 校验是否已有负责人
|
// 校验是否已有负责人
|
||||||
validateCustomerOwnerExists(customer);
|
validateCustomerOwnerExists(customer, false);
|
||||||
// 校验是否锁定
|
// 校验是否锁定
|
||||||
validateCustomerIsLocked(customer);
|
validateCustomerIsLocked(customer, false);
|
||||||
// 校验成交状态
|
// 校验成交状态
|
||||||
validateCustomerDeal(customer);
|
validateCustomerDeal(customer);
|
||||||
}
|
});
|
||||||
|
|
||||||
// TODO @QingX:这里是不是改成一次性更新;不然,如果有 20 个客户,就要执行 20 次 SQL 了;
|
// 2. 领取公海数据
|
||||||
// 统一修改状态
|
List<CrmCustomerDO> updateCustomers = new ArrayList<>();
|
||||||
CrmCustomerDO updateDo = new CrmCustomerDO();
|
List<CrmPermissionCreateReqBO> createPermissions = new ArrayList<>();
|
||||||
updateDo.setOwnerUserId(ownerUserId);
|
customers.forEach(customer -> {
|
||||||
// TODO @QingX:如果更新的数量不对,则应该抛出异常,回滚,并错误提示;
|
// 2.1. 设置负责人
|
||||||
for (Long id : ids) {
|
updateCustomers.add(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(ownerUserId));
|
||||||
customerMapper.updateCustomerByOwnerUserIdIsNull(id,updateDo);
|
// 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, Boolean pool) {
|
||||||
private void validateCustomerOwnerExists(CrmCustomerDO customer) {
|
if (customer == null) { // 防御一下
|
||||||
|
throw exception(CUSTOMER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
// 校验是否为公海数据
|
||||||
|
if (pool && customer.getOwnerUserId() == null) {
|
||||||
|
throw exception(CUSTOMER_IN_POOL, customer.getName());
|
||||||
|
}
|
||||||
|
// 负责人已存在
|
||||||
if (customer.getOwnerUserId() != null) {
|
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()) {
|
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:校验合并到 validateCustomerOwnerExists、validateCustomerIsLocked
|
|
||||||
// 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 @puhui999:updateById 这么操作,是无法设置 null 的;
|
|
||||||
customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null));
|
|
||||||
// 3. 删除负责人数据权限
|
|
||||||
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
|
|
||||||
CrmPermissionLevelEnum.OWNER.getLevel());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
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.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.CrmCustomerPageReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
|
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
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 org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
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.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||||
@ -160,17 +159,18 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
|
|||||||
// 测试 website 不匹配
|
// 测试 website 不匹配
|
||||||
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setWebsite(null)));
|
customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setWebsite(null)));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
CrmCustomerExportReqVO reqVO = new CrmCustomerExportReqVO();
|
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
|
||||||
reqVO.setName(null);
|
reqVO.setName("张三");
|
||||||
reqVO.setMobile(null);
|
reqVO.setMobile("13888888888");
|
||||||
|
reqVO.setPageSize(PAGE_SIZE_NONE);
|
||||||
//reqVO.setTelephone(null);
|
//reqVO.setTelephone(null);
|
||||||
//reqVO.setWebsite(null);
|
//reqVO.setWebsite(null);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
List<CrmCustomerDO> list = customerService.getCustomerList(reqVO);
|
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(reqVO, 1L);
|
||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, pageResult.getList().size());
|
||||||
assertPojoEquals(dbCustomer, list.get(0));
|
assertPojoEquals(dbCustomer, pageResult.getList().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user