feat: CRM 客户限制

This commit is contained in:
Wanwan 2023-11-11 20:49:52 +08:00
parent 2915b46fa5
commit 5b295d56b6
21 changed files with 754 additions and 3 deletions

View File

@ -1,3 +1,6 @@
-- ----------------------------
-- 客户公海配置
-- ----------------------------
-- 菜单 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
@ -20,4 +23,66 @@ INSERT INTO system_menu(
VALUES (
'客户公海配置保存', 'crm:customer-pool-config:update', 3, 1, @parentId,
'', '', '', 0
);
);
-- ----------------------------
-- 客户限制配置管理
-- ----------------------------
-- 菜单 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status, component_name
)
VALUES (
'客户限制配置管理', '', 2, 0, 2397,
'customer-limit-config', '', 'crm/customerLimitConfig/index', 0, 'CrmCustomerLimitConfig'
);
-- 按钮父菜单ID
-- 暂时只支持 MySQL如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'客户限制配置查询', 'crm:customer-limit-config:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'客户限制配置创建', 'crm:customer-limit-config:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'客户限制配置更新', 'crm:customer-limit-config:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'客户限制配置删除', 'crm:customer-limit-config:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'客户限制配置导出', 'crm:customer-limit-config:export', 3, 5, @parentId,
'', '', '', 0
);

View File

@ -276,6 +276,15 @@ public class CollectionUtils {
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
}
public static <T, U, R> List<R> convertListByFlatMap(Collection<T> from,
Function<? super T, ? extends U> mapper,
Function<U, ? extends Stream<? extends R>> func) {
if (CollUtil.isEmpty(from)) {
return new ArrayList<>();
}
return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
}
public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from,
Function<T, ? extends Stream<? extends U>> func) {
if (CollUtil.isEmpty(from)) {
@ -284,4 +293,13 @@ public class CollectionUtils {
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
}
public static <T, U, R> Set<R> convertSetByFlatMap(Collection<T> from,
Function<? super T, ? extends U> mapper,
Function<U, ? extends Stream<? extends R>> func) {
if (CollUtil.isEmpty(from)) {
return new HashSet<>();
}
return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
}
}

View File

@ -35,6 +35,7 @@ public interface ErrorCodeConstants {
// ========== 客户管理 1_020_006_000 ==========
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
// ========== 权限管理 1_020_007_000 ==========
ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");

View File

@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.convert.customerlimitconfig.CrmCustomerLimitConfigConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.service.customerlimitconfig.CrmCustomerLimitConfigService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 客户限制配置")
@RestController
@RequestMapping("/crm/customer-limit-config")
@Validated
public class CrmCustomerLimitConfigController {
@Resource
private CrmCustomerLimitConfigService customerLimitConfigService;
@Resource
private DeptApi deptApi;
@Resource
private AdminUserApi adminUserApi;
@PostMapping("/create")
@Operation(summary = "创建客户限制配置")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:create')")
public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigCreateReqVO createReqVO) {
return success(customerLimitConfigService.createCustomerLimitConfig(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新客户限制配置")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:update')")
public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
customerLimitConfigService.updateCustomerLimitConfig(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除客户限制配置")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:delete')")
public CommonResult<Boolean> deleteCustomerLimitConfig(@RequestParam("id") Long id) {
customerLimitConfigService.deleteCustomerLimitConfig(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得客户限制配置")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:query')")
public CommonResult<CrmCustomerLimitConfigRespVO> getCustomerLimitConfig(@RequestParam("id") Long id) {
CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigService.getCustomerLimitConfig(id);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(new HashSet<>(customerLimitConfig.getUserIds()));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(new HashSet<>(customerLimitConfig.getDeptIds()));
return success(CrmCustomerLimitConfigConvert.INSTANCE.convert(customerLimitConfig, userMap, deptMap));
}
@GetMapping("/page")
@Operation(summary = "获得客户限制配置分页")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:query')")
public CommonResult<PageResult<CrmCustomerLimitConfigRespVO>> getCustomerLimitConfigPage(@Valid CrmCustomerLimitConfigPageReqVO pageVO) {
PageResult<CrmCustomerLimitConfigDO> pageResult = customerLimitConfigService.getCustomerLimitConfigPage(pageVO);
Set<Long> userIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmCustomerLimitConfigDO::getUserIds, Collection::stream);
Set<Long> deptIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmCustomerLimitConfigDO::getDeptIds, Collection::stream);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
return success(CrmCustomerLimitConfigConvert.INSTANCE.convertPage(pageResult, userMap, deptMap));
}
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 客户限制配置 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class CrmCustomerLimitConfigBaseVO {
@Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "规则类型不能为空")
private Integer type;
@Schema(description = "规则适用人群")
private List<Long> userIds;
@Schema(description = "规则适用部门")
private List<Long> deptIds;
@Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
@NotNull(message = "数量上限不能为空")
private Integer maxCount;
@Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
private Boolean dealCountEnabled;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 客户限制配置分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigPageReqVO extends PageParam {
@Schema(description = "规则类型", example = "1")
private Integer type;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 客户限制配置 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigRespVO extends CrmCustomerLimitConfigBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
private Long id;
@Schema(description = "规则适用人群名称")
private String userNames;
@Schema(description = "规则适用部门名称")
private String deptNames;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 客户限制配置更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigUpdateReqVO extends CrmCustomerLimitConfigBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.crm.convert.customerlimitconfig;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 客户限制配置 Convert
*
* @author Wanwan
*/
@Mapper
public interface CrmCustomerLimitConfigConvert {
CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigUpdateReqVO bean);
CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);
List<CrmCustomerLimitConfigRespVO> convertList(List<CrmCustomerLimitConfigDO> list);
PageResult<CrmCustomerLimitConfigRespVO> convertPage(PageResult<CrmCustomerLimitConfigDO> page);
default PageResult<CrmCustomerLimitConfigRespVO> convertPage(PageResult<CrmCustomerLimitConfigDO> pageResult,
Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
PageResult<CrmCustomerLimitConfigRespVO> result = convertPage(pageResult);
result.getList().forEach(respVo -> fillNameField(userMap, deptMap, respVo));
return result;
}
default CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO customerLimitConfig,
Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
CrmCustomerLimitConfigRespVO respVo = convert(customerLimitConfig);
fillNameField(userMap, deptMap, respVo);
return respVo;
}
/**
* 填充名称字段
*
* @param userMap 用户映射
* @param deptMap 部门映射
* @param respVo 响应实体
*/
static void fillNameField(Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap, CrmCustomerLimitConfigRespVO respVo) {
respVo.setUserNames(respVo.getUserIds().stream().map(userMap::get)
.filter(Objects::nonNull).map(AdminUserRespDTO::getNickname).collect(Collectors.joining("")));
respVo.setDeptNames(respVo.getDeptIds().stream().map(deptMap::get)
.filter(Objects::nonNull).map(DeptRespDTO::getName).collect(Collectors.joining("")));
}
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.List;
/**
* 客户限制配置 DO
*
* @author Wanwan
*/
@TableName(value = "crm_customer_limit_config", autoResultMap = true)
@KeySequence("crm_customer_limit_config_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CrmCustomerLimitConfigDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 规则类型
*/
private Integer type;
/**
* 规则适用人群
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> userIds;
/**
* 规则适用部门
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> deptIds;
/**
* 数量上限
*/
private Integer maxCount;
/**
* 成交客户是否占有拥有客户数( type = 1 )
*/
private Boolean dealCountEnabled;
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig;
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;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 客户限制配置 Mapper
*
* @author Wanwan
*/
@Mapper
public interface CrmCustomerLimitConfigMapper extends BaseMapperX<CrmCustomerLimitConfigDO> {
default PageResult<CrmCustomerLimitConfigDO> selectPage(CrmCustomerLimitConfigPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmCustomerLimitConfigDO>()
.eqIfPresent(CrmCustomerLimitConfigDO::getType, reqVO.getType())
.orderByDesc(CrmCustomerLimitConfigDO::getId));
}
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import javax.validation.Valid;
/**
* 客户限制配置 Service 接口
*
* @author Wanwan
*/
public interface CrmCustomerLimitConfigService {
/**
* 创建客户限制配置
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigCreateReqVO createReqVO);
/**
* 更新客户限制配置
*
* @param updateReqVO 更新信息
*/
void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigUpdateReqVO updateReqVO);
/**
* 删除客户限制配置
*
* @param id 编号
*/
void deleteCustomerLimitConfig(Long id);
/**
* 获得客户限制配置
*
* @param id 编号
* @return 客户限制配置
*/
CrmCustomerLimitConfigDO getCustomerLimitConfig(Long id);
/**
* 获得客户限制配置分页
*
* @param pageReqVO 分页查询
* @return 客户限制配置分页
*/
PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO);
}

View File

@ -0,0 +1,72 @@
package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.convert.customerlimitconfig.CrmCustomerLimitConfigConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
/**
* 客户限制配置 Service 实现类
*
* @author Wanwan
*/
@Service
@Validated
public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfigService {
@Resource
private CrmCustomerLimitConfigMapper customerLimitConfigMapper;
@Override
public Long createCustomerLimitConfig(CrmCustomerLimitConfigCreateReqVO createReqVO) {
// 插入
CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
customerLimitConfigMapper.insert(customerLimitConfig);
// 返回
return customerLimitConfig.getId();
}
@Override
public void updateCustomerLimitConfig(CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
// 校验存在
validateCustomerLimitConfigExists(updateReqVO.getId());
// 更新
CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
customerLimitConfigMapper.updateById(updateObj);
}
@Override
public void deleteCustomerLimitConfig(Long id) {
// 校验存在
validateCustomerLimitConfigExists(id);
// 删除
customerLimitConfigMapper.deleteById(id);
}
@Override
public CrmCustomerLimitConfigDO getCustomerLimitConfig(Long id) {
return customerLimitConfigMapper.selectById(id);
}
@Override
public PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO) {
return customerLimitConfigMapper.selectPage(pageReqVO);
}
private void validateCustomerLimitConfigExists(Long id) {
if (customerLimitConfigMapper.selectById(id) == null) {
throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
}
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -0,0 +1,118 @@
package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
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.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper;
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.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link CrmCustomerLimitConfigServiceImpl} 的单元测试类
*
* @author Wanwan
*/
@Import(CrmCustomerLimitConfigServiceImpl.class)
public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
@Resource
private CrmCustomerLimitConfigServiceImpl customerLimitConfigService;
@Resource
private CrmCustomerLimitConfigMapper customerLimitConfigMapper;
@Test
public void testCreateCustomerLimitConfig_success() {
// 准备参数
CrmCustomerLimitConfigCreateReqVO reqVO = randomPojo(CrmCustomerLimitConfigCreateReqVO.class);
// 调用
Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
// 断言
assertNotNull(customerLimitConfigId);
// 校验记录的属性是否正确
CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(customerLimitConfigId);
assertPojoEquals(reqVO, customerLimitConfig);
}
@Test
public void testUpdateCustomerLimitConfig_success() {
// mock 数据
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class, o -> {
o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
});
// 调用
customerLimitConfigService.updateCustomerLimitConfig(reqVO);
// 校验是否更新正确
CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, customerLimitConfig);
}
@Test
public void testUpdateCustomerLimitConfig_notExists() {
// 准备参数
CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
}
@Test
public void testDeleteCustomerLimitConfig_success() {
// mock 数据
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbCustomerLimitConfig.getId();
// 调用
customerLimitConfigService.deleteCustomerLimitConfig(id);
// 校验数据不存在了
assertNull(customerLimitConfigMapper.selectById(id));
}
@Test
public void testDeleteCustomerLimitConfig_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> customerLimitConfigService.deleteCustomerLimitConfig(id), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetCustomerLimitConfigPage() {
// mock 数据
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class, o -> { // 等会查询到
});
customerLimitConfigMapper.insert(dbCustomerLimitConfig);
// 准备参数
CrmCustomerLimitConfigPageReqVO reqVO = new CrmCustomerLimitConfigPageReqVO();
// 调用
PageResult<CrmCustomerLimitConfigDO> pageResult = customerLimitConfigService.getCustomerLimitConfigPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbCustomerLimitConfig, pageResult.getList().get(0));
}
}

View File

@ -6,4 +6,6 @@ DELETE FROM "crm_receivable";
DELETE FROM "crm_receivable_plan";
DELETE FROM "crm_customer";
DELETE FROM "crm_customer";
DELETE FROM "crm_customer_limit_config";

View File

@ -122,4 +122,20 @@ CREATE TABLE IF NOT EXISTS "crm_customer" (
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '客户表';
) COMMENT '客户表';
CREATE TABLE IF NOT EXISTS "crm_customer_limit_config" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"type" int NOT NULL,
"user_ids" varchar,
"dept_ids" varchar,
"max_count" int NOT NULL,
"deal_count_enabled" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '客户限制配置表';

View File

@ -109,6 +109,28 @@ public class UserController {
return success(new PageResult<>(userList, pageResult.getTotal()));
}
@GetMapping("/all")
@Operation(summary = "查询所有用户列表")
public CommonResult<List<UserPageItemRespVO>> getAllUser() {
// 获得用户分页列表
List<AdminUserDO> pageResult = userService.getUserList();
if (CollUtil.isEmpty(pageResult)) {
return success(Collections.emptyList()); // 返回空
}
// 获得拼接需要的数据
Collection<Long> deptIds = convertList(pageResult, AdminUserDO::getDeptId);
Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
// 拼接结果返回
List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.size());
pageResult.forEach(user -> {
UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user);
respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId())));
userList.add(respVO);
});
return success(userList);
}
@GetMapping("/list-all-simple")
@Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项")
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {

View File

@ -209,4 +209,10 @@ public interface AdminUserService {
*/
boolean isPasswordMatch(String rawPassword, String encodedPassword);
/**
* 获取所有用户列表
*
* @return 用户列表
*/
List<AdminUserDO> getUserList();
}

View File

@ -443,6 +443,16 @@ public class AdminUserServiceImpl implements AdminUserService {
return passwordEncoder.matches(rawPassword, encodedPassword);
}
/**
* 获取所有用户列表
*
* @return 用户列表
*/
@Override
public List<AdminUserDO> getUserList() {
return userMapper.selectList();
}
/**
* 对密码进行加密
*