CRM--首页数据--商机转化龙虎榜 (接口实现)

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

 

需求:

在一段时间范围内,统计哪些部门员工将商机转合同的最多,并计算转化率

对于商机总数来说这里的时间范围指的是商机的创建时间

对于每个用户转化了多少个商机来说,时间范围指的是合同的创建时间

合同的创建时间即商机转合同的时间

注意:最多展示10条

难度级别 B级

接口名/index/businessChangeStatistics

请求方式Get

参数列表

传入参数:

/index/businessChangeStatistics?beginCreateTime=2021-02-02&endCreateTime=2022-02-17

beginCreateTime 开始时间

endCreateTime 结束时间

返回值:

{
    "msg":"操作成功",
    "code":200,
    "data":[
        {
            "create_by":"zhangkai",			   		用户名称
            "deptName":"商机部",					  部门名称
            "num":100,								转化数量
            "radio":31.65							转化率
        },
        {
            "create_by":"admin",
            "deptName":"研发部门",
            "num":9,
            "radio":2.85
        },
        {
            "create_by":"shangji",
            "deptName":"新人创建演示用部门",
            "num":1,
            "radio":0.32
        },
        {
            "create_by":"shangji1",
            "deptName":"销售部门",
            "num":1,
            "radio":0.32
        }
    ]
}

步骤:

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

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

3.编写mapper层操作数据库

4.编写service层操作数据

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

TbBusinessMapper.xml

 <select id="countAllBusiness" resultType="int">
       select count(id) from tb_business
        <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>

TbBusinessMapper

	public int countAllBusiness(@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);

ReportServiceImpl

 /**
     * 商机转换龙虎榜
     * @param request
     * @return
     */
    @Override
    public List<Map<String, Object>> businessChangeStatisticsForIndex(IndexStatisticsVo request) {
        int allBusiness=  businessMapper.countAllBusiness(request.getBeginCreateTime(),request.getEndCreateTime());
        List<Map<String,Object>> list= businessMapper.countAllContractByUser(request);
        for (Map<String, Object> datum : list) {
            Long num= (Long) datum.get("num");
            datum.put("radio",getRadio(allBusiness,num));
        }
        return list;
    }

IReportService

 public List<Map<String,Object>> businessChangeStatisticsForIndex(IndexStatisticsVo request);

 IndexController

@GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= reportService.businessChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }