feat: CRM 线索表 crud

This commit is contained in:
913752709@qq.com 2023-10-18 19:53:15 +08:00
parent b133acd8cd
commit a09ee495b6
20 changed files with 1065 additions and 3 deletions

View File

@ -37,3 +37,27 @@ CREATE TABLE `crm_contract`
) ENGINE = InnoDB
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='合同表';
DROP TABLE IF EXISTS `crm_clue`;
CREATE TABLE `crm_clue` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号主键自增',
`transform_status` tinyint NOT NULL COMMENT '转化状态',
`follow_up_status` tinyint NOT NULL COMMENT '跟进状态',
`name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '线索名称',
`customer_id` bigint NOT NULL COMMENT '客户id',
`contact_next_time` datetime NULL DEFAULT NULL COMMENT '下次联系时间',
`telephone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '电话',
`mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '手机号',
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '地址',
`owner_user_id` bigint NULL DEFAULT NULL COMMENT '负责人的用户编号',
`contact_last_time` datetime NULL DEFAULT NULL COMMENT '最后跟进时间',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '线索表' ROW_FORMAT = Dynamic;

View File

@ -59,5 +59,61 @@ VALUES (
);
-- ----------------------------
-- ...菜单
-- 线索菜单
-- ----------------------------
-- 菜单 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status, component_name
)
VALUES (
'线索管理', '', 2, 0, 2375,
'clue', '', 'crm/clue/index', 0, 'CrmClue'
);
-- 按钮父菜单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:clue:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'线索创建', 'crm:clue:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'线索更新', 'crm:clue:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'线索删除', 'crm:clue:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'线索导出', 'crm:clue:export', 3, 5, @parentId,
'', '', '', 0
);

View File

@ -12,4 +12,6 @@ public interface ErrorCodeConstants {
// ========== 合同管理 1-020-000-000 ==========
ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_000_001, "线索不存在");
}

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert;
import cn.iocoder.yudao.module.crm.service.clue.CrmClueService;
@Tag(name = "管理后台 - 线索")
@RestController
@RequestMapping("/crm/clue")
@Validated
public class CrmClueController {
@Resource
private CrmClueService clueService;
@PostMapping("/create")
@Operation(summary = "创建线索")
@PreAuthorize("@ss.hasPermission('crm:clue:create')")
public CommonResult<Long> createClue(@Valid @RequestBody CrmClueCreateReqVO createReqVO) {
return success(clueService.createClue(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新线索")
@PreAuthorize("@ss.hasPermission('crm:clue:update')")
public CommonResult<Boolean> updateClue(@Valid @RequestBody CrmClueUpdateReqVO updateReqVO) {
clueService.updateClue(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除线索")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:clue:delete')")
public CommonResult<Boolean> deleteClue(@RequestParam("id") Long id) {
clueService.deleteClue(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得线索")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:clue:query')")
public CommonResult<CrmClueRespVO> getClue(@RequestParam("id") Long id) {
CrmClueDO clue = clueService.getClue(id);
return success(CrmClueConvert.INSTANCE.convert(clue));
}
@GetMapping("/list")
@Operation(summary = "获得线索列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('crm:clue:query')")
public CommonResult<List<CrmClueRespVO>> getClueList(@RequestParam("ids") Collection<Long> ids) {
List<CrmClueDO> list = clueService.getClueList(ids);
return success(CrmClueConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得线索分页")
@PreAuthorize("@ss.hasPermission('crm:clue:query')")
public CommonResult<PageResult<CrmClueRespVO>> getCluePage(@Valid CrmCluePageReqVO pageVO) {
PageResult<CrmClueDO> pageResult = clueService.getCluePage(pageVO);
return success(CrmClueConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出线索 Excel")
@PreAuthorize("@ss.hasPermission('crm:clue:export')")
@OperateLog(type = EXPORT)
public void exportClueExcel(@Valid CrmClueExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<CrmClueDO> list = clueService.getClueList(exportReqVO);
// 导出 Excel
List<CrmClueExcelVO> datas = CrmClueConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "线索.xls", "数据", CrmClueExcelVO.class, datas);
}
}

View File

@ -0,0 +1,64 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 线索 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class CrmClueBaseVO {
@Schema(description = "转化状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "转化状态不能为空")
private Boolean transformStatus;
@Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "跟进状态不能为空")
private Boolean followUpStatus;
@Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx")
@NotNull(message = "线索名称不能为空")
private String name;
@Schema(description = "客户id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520")
@NotNull(message = "客户id不能为空")
private Long customerId;
@Schema(description = "下次联系时间", example = "2023-10-18 01:00:00")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime contactNextTime;
@Mobile(message = "电话格式不正确")
@Schema(description = "电话", example = "18000000000")
private String telephone;
@Mobile(message = "手机号格式不正确")
@Schema(description = "手机号", example = "18000000000")
private String mobile;
@Schema(description = "地址", example = "北京市海淀区")
private String address;
@Schema(description = "负责人的用户编号", example = "27199")
private Long ownerUserId;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime contactLastTime;
@Schema(description = "备注", example = "随便")
private String remark;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 线索创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmClueCreateReqVO extends CrmClueBaseVO {
}

View File

@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.ExcelProperty;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
/**
* 线索 Excel VO
*
* @author Wanwan
*/
@Data
public class CrmClueExcelVO {
@ExcelProperty("编号,主键自增")
private Long id;
@ExcelProperty(value = "转化状态", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化建议设置到对应的 XXXDictTypeConstants 枚举类中
private Boolean transformStatus;
@ExcelProperty(value = "跟进状态", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化建议设置到对应的 XXXDictTypeConstants 枚举类中
private Boolean followUpStatus;
@ExcelProperty("线索名称")
private String name;
@ExcelProperty("客户id")
private Long customerId;
@ExcelProperty("下次联系时间")
private LocalDateTime contactNextTime;
@ExcelProperty("电话")
private String telephone;
@ExcelProperty("手机号")
private String mobile;
@ExcelProperty("地址")
private String address;
@ExcelProperty("负责人的用户编号")
private Long ownerUserId;
@ExcelProperty("最后跟进时间")
private LocalDateTime contactLastTime;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 线索 Excel 导出 Request VO参数和 CrmCluePageReqVO 是一致的")
@Data
public class CrmClueExportReqVO {
@Schema(description = "转化状态", example = "true")
private Boolean transformStatus;
@Schema(description = "跟进状态", example = "true")
private Boolean followUpStatus;
@Schema(description = "线索名称", example = "线索xxx")
private String name;
@Schema(description = "客户id", example = "520")
private Long customerId;
@Schema(description = "下次联系时间", example = "2023-10-18 01:00:00")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] contactNextTime;
@Schema(description = "电话", example = "18000000000")
private String telephone;
@Schema(description = "手机号", example = "18000000000")
private String mobile;
@Schema(description = "地址", example = "北京市海淀区")
private String address;
@Schema(description = "负责人的用户编号", example = "27199")
private Long ownerUserId;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] contactLastTime;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 线索分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCluePageReqVO extends PageParam {
@Schema(description = "转化状态", example = "true")
private Boolean transformStatus;
@Schema(description = "跟进状态", example = "true")
private Boolean followUpStatus;
@Schema(description = "线索名称", example = "线索xxx")
private String name;
@Schema(description = "客户id", example = "520")
private Long customerId;
@Schema(description = "下次联系时间", example = "2023-10-18 01:00:00")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] contactNextTime;
@Schema(description = "电话", example = "18000000000")
private String telephone;
@Schema(description = "手机号", example = "18000000000")
private String mobile;
@Schema(description = "地址", example = "北京市海淀区")
private String address;
@Schema(description = "负责人的用户编号", example = "27199")
private Long ownerUserId;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] contactLastTime;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 线索 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmClueRespVO extends CrmClueBaseVO {
@Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 线索更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmClueUpdateReqVO extends CrmClueBaseVO {
@Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969")
@NotNull(message = "编号,主键自增不能为空")
private Long id;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.crm.convert.clue;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
/**
* 线索 Convert
*
* @author Wanwan
*/
@Mapper
public interface CrmClueConvert {
CrmClueConvert INSTANCE = Mappers.getMapper(CrmClueConvert.class);
CrmClueDO convert(CrmClueCreateReqVO bean);
CrmClueDO convert(CrmClueUpdateReqVO bean);
CrmClueRespVO convert(CrmClueDO bean);
List<CrmClueRespVO> convertList(List<CrmClueDO> list);
PageResult<CrmClueRespVO> convertPage(PageResult<CrmClueDO> page);
List<CrmClueExcelVO> convertList02(List<CrmClueDO> list);
}

View File

@ -0,0 +1,81 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.clue;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 线索 DO
*
* @author Wanwan
*/
@TableName("crm_clue")
@KeySequence("crm_clue_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CrmClueDO extends BaseDO {
/**
* 编号主键自增
*/
@TableId
private Long id;
/**
* 转化状态
*
* 枚举 {@link TODO infra_boolean_string 对应的类}
*/
private Boolean transformStatus;
/**
* 跟进状态
*
* 枚举 {@link TODO infra_boolean_string 对应的类}
*/
private Boolean followUpStatus;
/**
* 线索名称
*/
private String name;
/**
* 客户id
*/
private Long customerId;
/**
* 下次联系时间
*/
private LocalDateTime contactNextTime;
/**
* 电话
*/
private String telephone;
/**
* 手机号
*/
private String mobile;
/**
* 地址
*/
private String address;
/**
* 负责人的用户编号
*/
private Long ownerUserId;
/**
* 最后跟进时间
*/
private LocalDateTime contactLastTime;
/**
* 备注
*/
private String remark;
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.crm.dal.mysql.clue;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
/**
* 线索 Mapper
*
* @author Wanwan
*/
@Mapper
public interface CrmClueMapper extends BaseMapperX<CrmClueDO> {
default PageResult<CrmClueDO> selectPage(CrmCluePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmClueDO>()
.eqIfPresent(CrmClueDO::getTransformStatus, reqVO.getTransformStatus())
.eqIfPresent(CrmClueDO::getFollowUpStatus, reqVO.getFollowUpStatus())
.likeIfPresent(CrmClueDO::getName, reqVO.getName())
.eqIfPresent(CrmClueDO::getCustomerId, reqVO.getCustomerId())
.betweenIfPresent(CrmClueDO::getContactNextTime, reqVO.getContactNextTime())
.likeIfPresent(CrmClueDO::getTelephone, reqVO.getTelephone())
.likeIfPresent(CrmClueDO::getMobile, reqVO.getMobile())
.likeIfPresent(CrmClueDO::getAddress, reqVO.getAddress())
.eqIfPresent(CrmClueDO::getOwnerUserId, reqVO.getOwnerUserId())
.betweenIfPresent(CrmClueDO::getContactLastTime, reqVO.getContactLastTime())
.betweenIfPresent(CrmClueDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(CrmClueDO::getId));
}
default List<CrmClueDO> selectList(CrmClueExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<CrmClueDO>()
.eqIfPresent(CrmClueDO::getTransformStatus, reqVO.getTransformStatus())
.eqIfPresent(CrmClueDO::getFollowUpStatus, reqVO.getFollowUpStatus())
.likeIfPresent(CrmClueDO::getName, reqVO.getName())
.eqIfPresent(CrmClueDO::getCustomerId, reqVO.getCustomerId())
.betweenIfPresent(CrmClueDO::getContactNextTime, reqVO.getContactNextTime())
.likeIfPresent(CrmClueDO::getTelephone, reqVO.getTelephone())
.likeIfPresent(CrmClueDO::getMobile, reqVO.getMobile())
.likeIfPresent(CrmClueDO::getAddress, reqVO.getAddress())
.eqIfPresent(CrmClueDO::getOwnerUserId, reqVO.getOwnerUserId())
.betweenIfPresent(CrmClueDO::getContactLastTime, reqVO.getContactLastTime())
.betweenIfPresent(CrmClueDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(CrmClueDO::getId));
}
}

View File

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.crm.service.clue;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
/**
* 线索 Service 接口
*
* @author Wanwan
*/
public interface CrmClueService {
/**
* 创建线索
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createClue(@Valid CrmClueCreateReqVO createReqVO);
/**
* 更新线索
*
* @param updateReqVO 更新信息
*/
void updateClue(@Valid CrmClueUpdateReqVO updateReqVO);
/**
* 删除线索
*
* @param id 编号
*/
void deleteClue(Long id);
/**
* 获得线索
*
* @param id 编号
* @return 线索
*/
CrmClueDO getClue(Long id);
/**
* 获得线索列表
*
* @param ids 编号
* @return 线索列表
*/
List<CrmClueDO> getClueList(Collection<Long> ids);
/**
* 获得线索分页
*
* @param pageReqVO 分页查询
* @return 线索分页
*/
PageResult<CrmClueDO> getCluePage(CrmCluePageReqVO pageReqVO);
/**
* 获得线索列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 线索列表
*/
List<CrmClueDO> getClueList(CrmClueExportReqVO exportReqVO);
}

View File

@ -0,0 +1,88 @@
package cn.iocoder.yudao.module.crm.service.clue;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert;
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
/**
* 线索 Service 实现类
*
* @author Wanwan
*/
@Service
@Validated
public class CrmClueServiceImpl implements CrmClueService {
@Resource
private CrmClueMapper clueMapper;
@Override
public Long createClue(CrmClueCreateReqVO createReqVO) {
// 插入
CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO);
clueMapper.insert(clue);
// 返回
return clue.getId();
}
@Override
public void updateClue(CrmClueUpdateReqVO updateReqVO) {
// 校验存在
validateClueExists(updateReqVO.getId());
// 更新
CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO);
clueMapper.updateById(updateObj);
}
@Override
public void deleteClue(Long id) {
// 校验存在
validateClueExists(id);
// 删除
clueMapper.deleteById(id);
}
private void validateClueExists(Long id) {
if (clueMapper.selectById(id) == null) {
throw exception(CLUE_NOT_EXISTS);
}
}
@Override
public CrmClueDO getClue(Long id) {
return clueMapper.selectById(id);
}
@Override
public List<CrmClueDO> getClueList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return clueMapper.selectBatchIds(ids);
}
@Override
public PageResult<CrmClueDO> getCluePage(CrmCluePageReqVO pageReqVO) {
return clueMapper.selectPage(pageReqVO);
}
@Override
public List<CrmClueDO> getClueList(CrmClueExportReqVO exportReqVO) {
return clueMapper.selectList(exportReqVO);
}
}

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.clue.CrmClueMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -0,0 +1,231 @@
package cn.iocoder.yudao.module.crm.service.clue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link CrmClueServiceImpl} 的单元测试类
*
* @author Wanwan
*/
@Import(CrmClueServiceImpl.class)
public class CrmClueServiceImplTest extends BaseDbUnitTest {
@Resource
private CrmClueServiceImpl clueService;
@Resource
private CrmClueMapper clueMapper;
@Test
public void testCreateClue_success() {
// 准备参数
CrmClueCreateReqVO reqVO = randomPojo(CrmClueCreateReqVO.class);
// 调用
Long clueId = clueService.createClue(reqVO);
// 断言
assertNotNull(clueId);
// 校验记录的属性是否正确
CrmClueDO clue = clueMapper.selectById(clueId);
assertPojoEquals(reqVO, clue);
}
@Test
public void testUpdateClue_success() {
// mock 数据
CrmClueDO dbClue = randomPojo(CrmClueDO.class);
clueMapper.insert(dbClue);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmClueUpdateReqVO reqVO = randomPojo(CrmClueUpdateReqVO.class, o -> {
o.setId(dbClue.getId()); // 设置更新的 ID
});
// 调用
clueService.updateClue(reqVO);
// 校验是否更新正确
CrmClueDO clue = clueMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, clue);
}
@Test
public void testUpdateClue_notExists() {
// 准备参数
CrmClueUpdateReqVO reqVO = randomPojo(CrmClueUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> clueService.updateClue(reqVO), CLUE_NOT_EXISTS);
}
@Test
public void testDeleteClue_success() {
// mock 数据
CrmClueDO dbClue = randomPojo(CrmClueDO.class);
clueMapper.insert(dbClue);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbClue.getId();
// 调用
clueService.deleteClue(id);
// 校验数据不存在了
assertNull(clueMapper.selectById(id));
}
@Test
public void testDeleteClue_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> clueService.deleteClue(id), CLUE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetCluePage() {
// mock 数据
CrmClueDO dbClue = randomPojo(CrmClueDO.class, o -> { // 等会查询到
o.setTransformStatus(null);
o.setFollowUpStatus(null);
o.setName(null);
o.setCustomerId(null);
o.setContactNextTime(null);
o.setTelephone(null);
o.setMobile(null);
o.setAddress(null);
o.setOwnerUserId(null);
o.setContactLastTime(null);
o.setCreateTime(null);
});
clueMapper.insert(dbClue);
// 测试 transformStatus 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTransformStatus(null)));
// 测试 followUpStatus 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setFollowUpStatus(null)));
// 测试 name 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setName(null)));
// 测试 customerId 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCustomerId(null)));
// 测试 contactNextTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactNextTime(null)));
// 测试 telephone 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTelephone(null)));
// 测试 mobile 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
// 测试 address 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
// 测试 ownerUserId 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setOwnerUserId(null)));
// 测试 contactLastTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
// 测试 createTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCreateTime(null)));
// 准备参数
CrmCluePageReqVO reqVO = new CrmCluePageReqVO();
reqVO.setTransformStatus(null);
reqVO.setFollowUpStatus(null);
reqVO.setName(null);
reqVO.setCustomerId(null);
reqVO.setContactNextTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setTelephone(null);
reqVO.setMobile(null);
reqVO.setAddress(null);
reqVO.setOwnerUserId(null);
reqVO.setContactLastTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<CrmClueDO> pageResult = clueService.getCluePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbClue, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetClueList() {
// mock 数据
CrmClueDO dbClue = randomPojo(CrmClueDO.class, o -> { // 等会查询到
o.setTransformStatus(null);
o.setFollowUpStatus(null);
o.setName(null);
o.setCustomerId(null);
o.setContactNextTime(null);
o.setTelephone(null);
o.setMobile(null);
o.setAddress(null);
o.setOwnerUserId(null);
o.setContactLastTime(null);
o.setCreateTime(null);
});
clueMapper.insert(dbClue);
// 测试 transformStatus 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTransformStatus(null)));
// 测试 followUpStatus 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setFollowUpStatus(null)));
// 测试 name 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setName(null)));
// 测试 customerId 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCustomerId(null)));
// 测试 contactNextTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactNextTime(null)));
// 测试 telephone 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTelephone(null)));
// 测试 mobile 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
// 测试 address 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
// 测试 ownerUserId 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setOwnerUserId(null)));
// 测试 contactLastTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
// 测试 createTime 不匹配
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCreateTime(null)));
// 准备参数
CrmClueExportReqVO reqVO = new CrmClueExportReqVO();
reqVO.setTransformStatus(null);
reqVO.setFollowUpStatus(null);
reqVO.setName(null);
reqVO.setCustomerId(null);
reqVO.setContactNextTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setTelephone(null);
reqVO.setMobile(null);
reqVO.setAddress(null);
reqVO.setOwnerUserId(null);
reqVO.setContactLastTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<CrmClueDO> list = clueService.getClueList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbClue, list.get(0));
}
}

View File

@ -1 +1,3 @@
DELETE FROM "crm_contract";
DELETE FROM "crm_clue";

View File

@ -25,3 +25,25 @@ CREATE TABLE IF NOT EXISTS "crm_contract" (
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '合同表';
CREATE TABLE IF NOT EXISTS "crm_clue" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"transform_status" bit NOT NULL,
"follow_up_status" bit NOT NULL,
"name" varchar NOT NULL,
"customer_id" bigint NOT NULL,
"contact_next_time" varchar,
"telephone" varchar,
"mobile" varchar,
"address" varchar,
"owner_user_id" bigint,
"contact_last_time" varchar,
"remark" 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 '线索表';