CRM--统计分析--线索统计--线索转化率漏斗图 (接口实现)

发布于:2022-07-26 ⋅ 阅读:(499) ⋅ 点赞:(0)

统计分析--线索统计--线索转化率漏斗图

需求:在一段时间范围内,查询线索数量中,哪些是有效线索,在有效线索中查询哪些被转成了商机,在商机中查询哪些被转换成了合同,有效线索的结果集要从线索中来,商机的结果要从有效线索中找,合同的结果要从商机中找

其中线索不用考虑状态有多少线索全部统计

有效线索指的是 待跟进 , 跟进中 , 转换成商机 , 转换成客户这个状态的枚举类在TbClue中

转换成商机的需要考虑状态是:待跟进, 根进中, 转换成客户

转换成合同的不用考虑状态,只要是合同统计但是结果集是要从转换成商机中的结果中取

注意:由于可以人工的添加商机和合同这部分人工的由于没有线索部分,所以这部分的数据不要统计在漏斗图中,比如我现在人工的添加了一份商机,该商机是没有线索的,所以不需要统计在漏斗图中

难度级别 B级

接口名:/report/getVulnerabilityMap

请求方式:GET

参数列表:

传入参数:

/report/getVulnerabilityMap/2021-03-08/2022-04-08

beginCreateTime 开始时间

endCreateTime 结束时间

返回值:

{
    "msg":"操作成功",
    "code":200,
    "data":{
        "cluesNums":752,				线索数量
        "effectiveCluesNums":506,       有效线索数
        "businessNums":268,    			商机数量
        "contractNums":111				合同数量
    }
}

步骤:

1.阅读产品文档(接口名,请求方式,参数列表)

2.根据产品的返回值和接收参数构建VO类

3.编写mapper层操作数据库

4.编写service层操作数据

5.编写controller层接收参数和返回数据

1.阅读产品文档

基于接口文档中的数据,编写VO对象

package com.huike.report.domain.vo;

/**
 * 漏斗图VO对象
 */
public class VulnerabilityMapVo {
    private Integer cluesNums;     //线索数
    private Integer effectiveCluesNums;  //有效线索数
    private Integer businessNums;  //商机数
    private Integer contractNums ;  //合同数

    public Integer getCluesNums() {
        return cluesNums;
    }

    public void setCluesNums(Integer cluesNums) {
        this.cluesNums = cluesNums;
    }

    public Integer getEffectiveCluesNums() {
        return effectiveCluesNums;
    }

    public void setEffectiveCluesNums(Integer effectiveCluesNums) {
        this.effectiveCluesNums = effectiveCluesNums;
    }

    public Integer getBusinessNums() {
        return businessNums;
    }

    public void setBusinessNums(Integer businessNums) {
        this.businessNums = businessNums;
    }

    public Integer getContractNums() {
        return contractNums;
    }

    public void setContractNums(Integer contractNums) {
        this.contractNums = contractNums;
    }
}

2.编写Mapper

统计所有线索

TbClueMapper.xml

<select id="countAllClues" resultType="int">
       select count(id) from tb_clue
        <where>
            <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 开始创建时间 -->
                and date_format(create_time,'%y-%m-%d') &gt;= date_format(#{beginCreateTime},'%y-%m-%d')
            </if>
            <if test="endCreateTime != null and endCreateTime != ''"><!--  -->
                and date_format(create_time,'%y-%m-%d') &lt;= date_format(#{endCreateTime},'%y-%m-%d')
            </if>
        </where>
    </select>

统计所有有效线索

TbClueMapper.xml

 <select id="effectiveCluesNums" resultType="int">
        select count(id) from tb_clue where status in ('1','2','6','7')
            <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 开始创建时间 -->
                and date_format(create_time,'%y-%m-%d') &gt;= date_format(#{beginCreateTime},'%y-%m-%d')
            </if>
            <if test="endCreateTime != null and endCreateTime != ''"><!--  -->
                and date_format(create_time,'%y-%m-%d') &lt;= date_format(#{endCreateTime},'%y-%m-%d')
            </if>
    </select>

统计从有效线索转化来的商机数

TbBusinessMapper.xml

 <select id="businessNumsFromClue"  resultType="int">
       select count(id) from tb_business where clue_id is not null AND `status` IN (1,2,4,7)
       <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 开始创建时间 -->
                and date_format(create_time,'%y-%m-%d') &gt;= date_format(#{beginCreateTime},'%y-%m-%d')
       </if>
        <if test="endCreateTime != null and endCreateTime != ''"><!--  -->
                and date_format(create_time,'%y-%m-%d') &lt;= date_format(#{endCreateTime},'%y-%m-%d')
        </if>
    </select>

 

统计从商机数转化来的合同

TbContractMapper.xml

 <!--合同统计-->
    <select id="contractNumsFromBusiness"
            resultType="int">
     select count(id) from tb_contract where business_id is not null
            <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 开始创建时间 -->
                and date_format(create_time,'%y-%m-%d') &gt;= date_format(#{beginCreateTime},'%y-%m-%d')
            </if>
            <if test="endCreateTime != null and endCreateTime != ''"><!--  -->
                and date_format(create_time,'%y-%m-%d') &lt;= date_format(#{endCreateTime},'%y-%m-%d')
            </if>
    </select>

4.编写service

IReportService

 /**
     * 漏斗统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    public VulnerabilityMapVo getVulnerabilityMap(String beginCreateTime, String endCreateTime);

ReportServiceImpl

封装每一部分的属性

@Override
    public VulnerabilityMapVo getVulnerabilityMap(String beginCreateTime, String endCreateTime) {
        VulnerabilityMapVo vulnerabilityMapDTO =new VulnerabilityMapVo();
        //线索数
        vulnerabilityMapDTO.setCluesNums(clueMapper.countAllClues(beginCreateTime,endCreateTime));
        //有效线索数
        vulnerabilityMapDTO.setEffectiveCluesNums(clueMapper.effectiveCluesNums(beginCreateTime,endCreateTime));
        //商机数
        vulnerabilityMapDTO.setBusinessNums(businessMapper.businessNumsFromClue(beginCreateTime,endCreateTime));
        //合同数
        vulnerabilityMapDTO.setContractNums(contractMapper.contractNumsFromBusiness(beginCreateTime,endCreateTime));
        return vulnerabilityMapDTO;
    }

5.编写controller

ReportController

    /**
     * 漏斗图数据
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult getVulnerabilityMap(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        VulnerabilityMapVo vulnerabilityMapDTO= reportService.getVulnerabilityMap(beginCreateTime,endCreateTime);
        return AjaxResult.success(vulnerabilityMapDTO);
    }

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到