Commit 5b295d56b6ebeda635cfaa0ff98afe890e98de98

Authored by Wanwan
1 parent 2915b46f

feat: CRM 客户限制

Showing 21 changed files with 754 additions and 3 deletions
sql/mysql/crm_menu.sql
  1 +-- ----------------------------
  2 +-- 客户公海配置
  3 +-- ----------------------------
1 4 -- 菜单 SQL
2 5 INSERT INTO system_menu(
3 6 name, permission, type, sort, parent_id,
... ... @@ -20,4 +23,66 @@ INSERT INTO system_menu(
20 23 VALUES (
21 24 '客户公海配置保存', 'crm:customer-pool-config:update', 3, 1, @parentId,
22 25 '', '', '', 0
23   -);
24 26 \ No newline at end of file
  27 +);
  28 +
  29 +
  30 +
  31 +
  32 +-- ----------------------------
  33 +-- 客户限制配置管理
  34 +-- ----------------------------
  35 +-- 菜单 SQL
  36 +INSERT INTO system_menu(
  37 + name, permission, type, sort, parent_id,
  38 + path, icon, component, status, component_name
  39 +)
  40 +VALUES (
  41 + '客户限制配置管理', '', 2, 0, 2397,
  42 + 'customer-limit-config', '', 'crm/customerLimitConfig/index', 0, 'CrmCustomerLimitConfig'
  43 +);
  44 +
  45 +-- 按钮父菜单ID
  46 +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  47 +SELECT @parentId := LAST_INSERT_ID();
  48 +
  49 +-- 按钮 SQL
  50 +INSERT INTO system_menu(
  51 + name, permission, type, sort, parent_id,
  52 + path, icon, component, status
  53 +)
  54 +VALUES (
  55 + '客户限制配置查询', 'crm:customer-limit-config:query', 3, 1, @parentId,
  56 + '', '', '', 0
  57 +);
  58 +INSERT INTO system_menu(
  59 + name, permission, type, sort, parent_id,
  60 + path, icon, component, status
  61 +)
  62 +VALUES (
  63 + '客户限制配置创建', 'crm:customer-limit-config:create', 3, 2, @parentId,
  64 + '', '', '', 0
  65 +);
  66 +INSERT INTO system_menu(
  67 + name, permission, type, sort, parent_id,
  68 + path, icon, component, status
  69 +)
  70 +VALUES (
  71 + '客户限制配置更新', 'crm:customer-limit-config:update', 3, 3, @parentId,
  72 + '', '', '', 0
  73 +);
  74 +INSERT INTO system_menu(
  75 + name, permission, type, sort, parent_id,
  76 + path, icon, component, status
  77 +)
  78 +VALUES (
  79 + '客户限制配置删除', 'crm:customer-limit-config:delete', 3, 4, @parentId,
  80 + '', '', '', 0
  81 +);
  82 +INSERT INTO system_menu(
  83 + name, permission, type, sort, parent_id,
  84 + path, icon, component, status
  85 +)
  86 +VALUES (
  87 + '客户限制配置导出', 'crm:customer-limit-config:export', 3, 5, @parentId,
  88 + '', '', '', 0
  89 +);
... ...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
... ... @@ -276,6 +276,15 @@ public class CollectionUtils {
276 276 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
277 277 }
278 278  
  279 + public static <T, U, R> List<R> convertListByFlatMap(Collection<T> from,
  280 + Function<? super T, ? extends U> mapper,
  281 + Function<U, ? extends Stream<? extends R>> func) {
  282 + if (CollUtil.isEmpty(from)) {
  283 + return new ArrayList<>();
  284 + }
  285 + return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
  286 + }
  287 +
279 288 public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from,
280 289 Function<T, ? extends Stream<? extends U>> func) {
281 290 if (CollUtil.isEmpty(from)) {
... ... @@ -284,4 +293,13 @@ public class CollectionUtils {
284 293 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
285 294 }
286 295  
  296 + public static <T, U, R> Set<R> convertSetByFlatMap(Collection<T> from,
  297 + Function<? super T, ? extends U> mapper,
  298 + Function<U, ? extends Stream<? extends R>> func) {
  299 + if (CollUtil.isEmpty(from)) {
  300 + return new HashSet<>();
  301 + }
  302 + return from.stream().map(mapper).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
  303 + }
  304 +
287 305 }
... ...
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
... ... @@ -35,6 +35,7 @@ public interface ErrorCodeConstants {
35 35 // ========== 客户管理 1_020_006_000 ==========
36 36 ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
37 37 ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
  38 + ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
38 39  
39 40 // ========== 权限管理 1_020_007_000 ==========
40 41 ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerLimitConfigController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
  8 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigRespVO;
  9 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
  10 +import cn.iocoder.yudao.module.crm.convert.customerlimitconfig.CrmCustomerLimitConfigConvert;
  11 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  12 +import cn.iocoder.yudao.module.crm.service.customerlimitconfig.CrmCustomerLimitConfigService;
  13 +import cn.iocoder.yudao.module.system.api.dept.DeptApi;
  14 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
  15 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  16 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  17 +import io.swagger.v3.oas.annotations.Operation;
  18 +import io.swagger.v3.oas.annotations.Parameter;
  19 +import io.swagger.v3.oas.annotations.tags.Tag;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.validation.annotation.Validated;
  22 +import org.springframework.web.bind.annotation.*;
  23 +
  24 +import javax.annotation.Resource;
  25 +import javax.validation.Valid;
  26 +import java.util.Collection;
  27 +import java.util.HashSet;
  28 +import java.util.Map;
  29 +import java.util.Set;
  30 +import java.util.stream.Collectors;
  31 +
  32 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  33 +
  34 +@Tag(name = "管理后台 - 客户限制配置")
  35 +@RestController
  36 +@RequestMapping("/crm/customer-limit-config")
  37 +@Validated
  38 +public class CrmCustomerLimitConfigController {
  39 +
  40 + @Resource
  41 + private CrmCustomerLimitConfigService customerLimitConfigService;
  42 + @Resource
  43 + private DeptApi deptApi;
  44 + @Resource
  45 + private AdminUserApi adminUserApi;
  46 +
  47 + @PostMapping("/create")
  48 + @Operation(summary = "创建客户限制配置")
  49 + @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:create')")
  50 + public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigCreateReqVO createReqVO) {
  51 + return success(customerLimitConfigService.createCustomerLimitConfig(createReqVO));
  52 + }
  53 +
  54 + @PutMapping("/update")
  55 + @Operation(summary = "更新客户限制配置")
  56 + @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:update')")
  57 + public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
  58 + customerLimitConfigService.updateCustomerLimitConfig(updateReqVO);
  59 + return success(true);
  60 + }
  61 +
  62 + @DeleteMapping("/delete")
  63 + @Operation(summary = "删除客户限制配置")
  64 + @Parameter(name = "id", description = "编号", required = true)
  65 + @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:delete')")
  66 + public CommonResult<Boolean> deleteCustomerLimitConfig(@RequestParam("id") Long id) {
  67 + customerLimitConfigService.deleteCustomerLimitConfig(id);
  68 + return success(true);
  69 + }
  70 +
  71 + @GetMapping("/get")
  72 + @Operation(summary = "获得客户限制配置")
  73 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  74 + @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:query')")
  75 + public CommonResult<CrmCustomerLimitConfigRespVO> getCustomerLimitConfig(@RequestParam("id") Long id) {
  76 + CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigService.getCustomerLimitConfig(id);
  77 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(new HashSet<>(customerLimitConfig.getUserIds()));
  78 + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(new HashSet<>(customerLimitConfig.getDeptIds()));
  79 + return success(CrmCustomerLimitConfigConvert.INSTANCE.convert(customerLimitConfig, userMap, deptMap));
  80 + }
  81 +
  82 + @GetMapping("/page")
  83 + @Operation(summary = "获得客户限制配置分页")
  84 + @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:query')")
  85 + public CommonResult<PageResult<CrmCustomerLimitConfigRespVO>> getCustomerLimitConfigPage(@Valid CrmCustomerLimitConfigPageReqVO pageVO) {
  86 + PageResult<CrmCustomerLimitConfigDO> pageResult = customerLimitConfigService.getCustomerLimitConfigPage(pageVO);
  87 + Set<Long> userIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmCustomerLimitConfigDO::getUserIds, Collection::stream);
  88 + Set<Long> deptIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmCustomerLimitConfigDO::getDeptIds, Collection::stream);
  89 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
  90 + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
  91 + return success(CrmCustomerLimitConfigConvert.INSTANCE.convertPage(pageResult, userMap, deptMap));
  92 + }
  93 +
  94 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLimitConfigBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 客户限制配置 Base VO,提供给添加、修改、详细的子 VO 使用
  11 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  12 + */
  13 +@Data
  14 +public class CrmCustomerLimitConfigBaseVO {
  15 +
  16 + @Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  17 + @NotNull(message = "规则类型不能为空")
  18 + private Integer type;
  19 +
  20 + @Schema(description = "规则适用人群")
  21 + private List<Long> userIds;
  22 +
  23 + @Schema(description = "规则适用部门")
  24 + private List<Long> deptIds;
  25 +
  26 + @Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
  27 + @NotNull(message = "数量上限不能为空")
  28 + private Integer maxCount;
  29 +
  30 + @Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
  31 + private Boolean dealCountEnabled;
  32 +
  33 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLimitConfigCreateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
  13 +
  14 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLimitConfigPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +@Schema(description = "管理后台 - 客户限制配置分页 Request VO")
  10 +@Data
  11 +@EqualsAndHashCode(callSuper = true)
  12 +@ToString(callSuper = true)
  13 +public class CrmCustomerLimitConfigPageReqVO extends PageParam {
  14 +
  15 + @Schema(description = "规则类型", example = "1")
  16 + private Integer type;
  17 +
  18 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLimitConfigRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import java.time.LocalDateTime;
  9 +import java.util.List;
  10 +
  11 +@Schema(description = "管理后台 - 客户限制配置 Response VO")
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@ToString(callSuper = true)
  15 +public class CrmCustomerLimitConfigRespVO extends CrmCustomerLimitConfigBaseVO {
  16 +
  17 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
  18 + private Long id;
  19 +
  20 + @Schema(description = "规则适用人群名称")
  21 + private String userNames;
  22 +
  23 + @Schema(description = "规则适用部门名称")
  24 + private String deptNames;
  25 +
  26 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  27 + private LocalDateTime createTime;
  28 +
  29 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerLimitConfigUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import javax.validation.constraints.NotNull;
  9 +
  10 +@Schema(description = "管理后台 - 客户限制配置更新 Request VO")
  11 +@Data
  12 +@EqualsAndHashCode(callSuper = true)
  13 +@ToString(callSuper = true)
  14 +public class CrmCustomerLimitConfigUpdateReqVO extends CrmCustomerLimitConfigBaseVO {
  15 +
  16 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
  17 + @NotNull(message = "编号不能为空")
  18 + private Long id;
  19 +
  20 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customerlimitconfig/CrmCustomerLimitConfigConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.convert.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigRespVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
  7 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  8 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
  9 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  10 +import org.mapstruct.Mapper;
  11 +import org.mapstruct.factory.Mappers;
  12 +
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +import java.util.Objects;
  16 +import java.util.stream.Collectors;
  17 +
  18 +/**
  19 + * 客户限制配置 Convert
  20 + *
  21 + * @author Wanwan
  22 + */
  23 +@Mapper
  24 +public interface CrmCustomerLimitConfigConvert {
  25 +
  26 + CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
  27 +
  28 + CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
  29 +
  30 + CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigUpdateReqVO bean);
  31 +
  32 + CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);
  33 +
  34 + List<CrmCustomerLimitConfigRespVO> convertList(List<CrmCustomerLimitConfigDO> list);
  35 +
  36 + PageResult<CrmCustomerLimitConfigRespVO> convertPage(PageResult<CrmCustomerLimitConfigDO> page);
  37 +
  38 + default PageResult<CrmCustomerLimitConfigRespVO> convertPage(PageResult<CrmCustomerLimitConfigDO> pageResult,
  39 + Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
  40 + PageResult<CrmCustomerLimitConfigRespVO> result = convertPage(pageResult);
  41 + result.getList().forEach(respVo -> fillNameField(userMap, deptMap, respVo));
  42 + return result;
  43 + }
  44 +
  45 + default CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO customerLimitConfig,
  46 + Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
  47 + CrmCustomerLimitConfigRespVO respVo = convert(customerLimitConfig);
  48 + fillNameField(userMap, deptMap, respVo);
  49 + return respVo;
  50 + }
  51 +
  52 + /**
  53 + * 填充名称字段
  54 + *
  55 + * @param userMap 用户映射
  56 + * @param deptMap 部门映射
  57 + * @param respVo 响应实体
  58 + */
  59 + static void fillNameField(Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap, CrmCustomerLimitConfigRespVO respVo) {
  60 + respVo.setUserNames(respVo.getUserIds().stream().map(userMap::get)
  61 + .filter(Objects::nonNull).map(AdminUserRespDTO::getNickname).collect(Collectors.joining(",")));
  62 + respVo.setDeptNames(respVo.getDeptIds().stream().map(deptMap::get)
  63 + .filter(Objects::nonNull).map(DeptRespDTO::getName).collect(Collectors.joining(",")));
  64 + }
  65 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/customerlimitconfig/CrmCustomerLimitConfigDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
  5 +import com.baomidou.mybatisplus.annotation.KeySequence;
  6 +import com.baomidou.mybatisplus.annotation.TableField;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
  8 +import com.baomidou.mybatisplus.annotation.TableName;
  9 +import lombok.*;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 客户限制配置 DO
  15 + *
  16 + * @author Wanwan
  17 + */
  18 +@TableName(value = "crm_customer_limit_config", autoResultMap = true)
  19 +@KeySequence("crm_customer_limit_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class CrmCustomerLimitConfigDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号
  30 + */
  31 + @TableId
  32 + private Long id;
  33 + /**
  34 + * 规则类型
  35 + */
  36 + private Integer type;
  37 + /**
  38 + * 规则适用人群
  39 + */
  40 + @TableField(typeHandler = LongListTypeHandler.class)
  41 + private List<Long> userIds;
  42 + /**
  43 + * 规则适用部门
  44 + */
  45 + @TableField(typeHandler = LongListTypeHandler.class)
  46 + private List<Long> deptIds;
  47 + /**
  48 + * 数量上限
  49 + */
  50 + private Integer maxCount;
  51 + /**
  52 + * 成交客户是否占有拥有客户数(当 type = 1 时)
  53 + */
  54 + private Boolean dealCountEnabled;
  55 +
  56 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customerlimitconfig/CrmCustomerLimitConfigMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
  7 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * 客户限制配置 Mapper
  12 + *
  13 + * @author Wanwan
  14 + */
  15 +@Mapper
  16 +public interface CrmCustomerLimitConfigMapper extends BaseMapperX<CrmCustomerLimitConfigDO> {
  17 +
  18 + default PageResult<CrmCustomerLimitConfigDO> selectPage(CrmCustomerLimitConfigPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<CrmCustomerLimitConfigDO>()
  20 + .eqIfPresent(CrmCustomerLimitConfigDO::getType, reqVO.getType())
  21 + .orderByDesc(CrmCustomerLimitConfigDO::getId));
  22 + }
  23 +
  24 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customerlimitconfig/CrmCustomerLimitConfigService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
  7 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  8 +
  9 +import javax.validation.Valid;
  10 +
  11 +/**
  12 + * 客户限制配置 Service 接口
  13 + *
  14 + * @author Wanwan
  15 + */
  16 +public interface CrmCustomerLimitConfigService {
  17 +
  18 + /**
  19 + * 创建客户限制配置
  20 + *
  21 + * @param createReqVO 创建信息
  22 + * @return 编号
  23 + */
  24 + Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigCreateReqVO createReqVO);
  25 +
  26 + /**
  27 + * 更新客户限制配置
  28 + *
  29 + * @param updateReqVO 更新信息
  30 + */
  31 + void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigUpdateReqVO updateReqVO);
  32 +
  33 + /**
  34 + * 删除客户限制配置
  35 + *
  36 + * @param id 编号
  37 + */
  38 + void deleteCustomerLimitConfig(Long id);
  39 +
  40 + /**
  41 + * 获得客户限制配置
  42 + *
  43 + * @param id 编号
  44 + * @return 客户限制配置
  45 + */
  46 + CrmCustomerLimitConfigDO getCustomerLimitConfig(Long id);
  47 +
  48 + /**
  49 + * 获得客户限制配置分页
  50 + *
  51 + * @param pageReqVO 分页查询
  52 + * @return 客户限制配置分页
  53 + */
  54 + PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO);
  55 +
  56 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customerlimitconfig/CrmCustomerLimitConfigServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
  7 +import cn.iocoder.yudao.module.crm.convert.customerlimitconfig.CrmCustomerLimitConfigConvert;
  8 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  9 +import cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper;
  10 +import org.springframework.stereotype.Service;
  11 +import org.springframework.validation.annotation.Validated;
  12 +
  13 +import javax.annotation.Resource;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
  17 +
  18 +/**
  19 + * 客户限制配置 Service 实现类
  20 + *
  21 + * @author Wanwan
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfigService {
  26 +
  27 + @Resource
  28 + private CrmCustomerLimitConfigMapper customerLimitConfigMapper;
  29 +
  30 + @Override
  31 + public Long createCustomerLimitConfig(CrmCustomerLimitConfigCreateReqVO createReqVO) {
  32 + // 插入
  33 + CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
  34 + customerLimitConfigMapper.insert(customerLimitConfig);
  35 + // 返回
  36 + return customerLimitConfig.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateCustomerLimitConfig(CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
  41 + // 校验存在
  42 + validateCustomerLimitConfigExists(updateReqVO.getId());
  43 + // 更新
  44 + CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
  45 + customerLimitConfigMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteCustomerLimitConfig(Long id) {
  50 + // 校验存在
  51 + validateCustomerLimitConfigExists(id);
  52 + // 删除
  53 + customerLimitConfigMapper.deleteById(id);
  54 + }
  55 +
  56 + @Override
  57 + public CrmCustomerLimitConfigDO getCustomerLimitConfig(Long id) {
  58 + return customerLimitConfigMapper.selectById(id);
  59 + }
  60 +
  61 + @Override
  62 + public PageResult<CrmCustomerLimitConfigDO> getCustomerLimitConfigPage(CrmCustomerLimitConfigPageReqVO pageReqVO) {
  63 + return customerLimitConfigMapper.selectPage(pageReqVO);
  64 + }
  65 +
  66 + private void validateCustomerLimitConfigExists(Long id) {
  67 + if (customerLimitConfigMapper.selectById(id) == null) {
  68 + throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
  69 + }
  70 + }
  71 +
  72 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/customerlimitconfig/CrmCustomerLimitConfigMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
... ...
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customerlimitconfig/CrmCustomerLimitConfigServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigCreateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigPageReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLimitConfigUpdateReqVO;
  8 +import cn.iocoder.yudao.module.crm.dal.dataobject.customerlimitconfig.CrmCustomerLimitConfigDO;
  9 +import cn.iocoder.yudao.module.crm.dal.mysql.customerlimitconfig.CrmCustomerLimitConfigMapper;
  10 +import org.junit.jupiter.api.Disabled;
  11 +import org.junit.jupiter.api.Test;
  12 +import org.springframework.context.annotation.Import;
  13 +
  14 +import javax.annotation.Resource;
  15 +
  16 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  17 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
  18 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  20 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
  21 +import static org.junit.jupiter.api.Assertions.*;
  22 +
  23 +/**
  24 + * {@link CrmCustomerLimitConfigServiceImpl} 的单元测试类
  25 + *
  26 + * @author Wanwan
  27 + */
  28 +@Import(CrmCustomerLimitConfigServiceImpl.class)
  29 +public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
  30 +
  31 + @Resource
  32 + private CrmCustomerLimitConfigServiceImpl customerLimitConfigService;
  33 +
  34 + @Resource
  35 + private CrmCustomerLimitConfigMapper customerLimitConfigMapper;
  36 +
  37 + @Test
  38 + public void testCreateCustomerLimitConfig_success() {
  39 + // 准备参数
  40 + CrmCustomerLimitConfigCreateReqVO reqVO = randomPojo(CrmCustomerLimitConfigCreateReqVO.class);
  41 +
  42 + // 调用
  43 + Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
  44 + // 断言
  45 + assertNotNull(customerLimitConfigId);
  46 + // 校验记录的属性是否正确
  47 + CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(customerLimitConfigId);
  48 + assertPojoEquals(reqVO, customerLimitConfig);
  49 + }
  50 +
  51 + @Test
  52 + public void testUpdateCustomerLimitConfig_success() {
  53 + // mock 数据
  54 + CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
  55 + customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
  56 + // 准备参数
  57 + CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class, o -> {
  58 + o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
  59 + });
  60 +
  61 + // 调用
  62 + customerLimitConfigService.updateCustomerLimitConfig(reqVO);
  63 + // 校验是否更新正确
  64 + CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(reqVO.getId()); // 获取最新的
  65 + assertPojoEquals(reqVO, customerLimitConfig);
  66 + }
  67 +
  68 + @Test
  69 + public void testUpdateCustomerLimitConfig_notExists() {
  70 + // 准备参数
  71 + CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class);
  72 +
  73 + // 调用, 并断言异常
  74 + assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
  75 + }
  76 +
  77 + @Test
  78 + public void testDeleteCustomerLimitConfig_success() {
  79 + // mock 数据
  80 + CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
  81 + customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
  82 + // 准备参数
  83 + Long id = dbCustomerLimitConfig.getId();
  84 +
  85 + // 调用
  86 + customerLimitConfigService.deleteCustomerLimitConfig(id);
  87 + // 校验数据不存在了
  88 + assertNull(customerLimitConfigMapper.selectById(id));
  89 + }
  90 +
  91 + @Test
  92 + public void testDeleteCustomerLimitConfig_notExists() {
  93 + // 准备参数
  94 + Long id = randomLongId();
  95 +
  96 + // 调用, 并断言异常
  97 + assertServiceException(() -> customerLimitConfigService.deleteCustomerLimitConfig(id), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
  98 + }
  99 +
  100 + @Test
  101 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  102 + public void testGetCustomerLimitConfigPage() {
  103 + // mock 数据
  104 + CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class, o -> { // 等会查询到
  105 + });
  106 + customerLimitConfigMapper.insert(dbCustomerLimitConfig);
  107 + // 准备参数
  108 + CrmCustomerLimitConfigPageReqVO reqVO = new CrmCustomerLimitConfigPageReqVO();
  109 +
  110 + // 调用
  111 + PageResult<CrmCustomerLimitConfigDO> pageResult = customerLimitConfigService.getCustomerLimitConfigPage(reqVO);
  112 + // 断言
  113 + assertEquals(1, pageResult.getTotal());
  114 + assertEquals(1, pageResult.getList().size());
  115 + assertPojoEquals(dbCustomerLimitConfig, pageResult.getList().get(0));
  116 + }
  117 +
  118 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/test/resources/sql/clean.sql
... ... @@ -6,4 +6,6 @@ DELETE FROM &quot;crm_receivable&quot;;
6 6  
7 7 DELETE FROM "crm_receivable_plan";
8 8  
9   -DELETE FROM "crm_customer";
10 9 \ No newline at end of file
  10 +DELETE FROM "crm_customer";
  11 +
  12 +DELETE FROM "crm_customer_limit_config";
11 13 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-crm-biz/src/test/resources/sql/create_tables.sql
... ... @@ -122,4 +122,20 @@ CREATE TABLE IF NOT EXISTS &quot;crm_customer&quot; (
122 122 "deleted" bit NOT NULL DEFAULT FALSE,
123 123 "tenant_id" bigint NOT NULL,
124 124 PRIMARY KEY ("id")
125   -) COMMENT '客户表';
126 125 \ No newline at end of file
  126 +) COMMENT '客户表';
  127 +
  128 +CREATE TABLE IF NOT EXISTS "crm_customer_limit_config" (
  129 + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  130 + "type" int NOT NULL,
  131 + "user_ids" varchar,
  132 + "dept_ids" varchar,
  133 + "max_count" int NOT NULL,
  134 + "deal_count_enabled" varchar,
  135 + "creator" varchar DEFAULT '',
  136 + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  137 + "updater" varchar DEFAULT '',
  138 + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  139 + "deleted" bit NOT NULL DEFAULT FALSE,
  140 + "tenant_id" bigint NOT NULL,
  141 + PRIMARY KEY ("id")
  142 +) COMMENT '客户限制配置表';
127 143 \ No newline at end of file
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
... ... @@ -109,6 +109,28 @@ public class UserController {
109 109 return success(new PageResult<>(userList, pageResult.getTotal()));
110 110 }
111 111  
  112 + @GetMapping("/all")
  113 + @Operation(summary = "查询所有用户列表")
  114 + public CommonResult<List<UserPageItemRespVO>> getAllUser() {
  115 + // 获得用户分页列表
  116 + List<AdminUserDO> pageResult = userService.getUserList();
  117 + if (CollUtil.isEmpty(pageResult)) {
  118 + return success(Collections.emptyList()); // 返回空
  119 + }
  120 +
  121 + // 获得拼接需要的数据
  122 + Collection<Long> deptIds = convertList(pageResult, AdminUserDO::getDeptId);
  123 + Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
  124 + // 拼接结果返回
  125 + List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.size());
  126 + pageResult.forEach(user -> {
  127 + UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user);
  128 + respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId())));
  129 + userList.add(respVO);
  130 + });
  131 + return success(userList);
  132 + }
  133 +
112 134 @GetMapping("/list-all-simple")
113 135 @Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项")
114 136 public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
... ... @@ -209,4 +209,10 @@ public interface AdminUserService {
209 209 */
210 210 boolean isPasswordMatch(String rawPassword, String encodedPassword);
211 211  
  212 + /**
  213 + * 获取所有用户列表
  214 + *
  215 + * @return 用户列表
  216 + */
  217 + List<AdminUserDO> getUserList();
212 218 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
... ... @@ -444,6 +444,16 @@ public class AdminUserServiceImpl implements AdminUserService {
444 444 }
445 445  
446 446 /**
  447 + * 获取所有用户列表
  448 + *
  449 + * @return 用户列表
  450 + */
  451 + @Override
  452 + public List<AdminUserDO> getUserList() {
  453 + return userMapper.selectList();
  454 + }
  455 +
  456 + /**
447 457 * 对密码进行加密
448 458 *
449 459 * @param password 密码
... ...