13-5-首页数据--商机转化龙虎榜 (实现)
大约 2 分钟
13-5-首页数据--商机转化龙虎榜 (实现)

需求:
在一段时间范围内,统计哪些部门员工将商机转合同的最多,并计算转化率
对于商机总数来说这里的时间范围指的是商机的创建时间
对于每个用户转化了多少个商机来说,时间范围指的是合同的创建时间
合同的创建时间即商机转合同的时间
注意:最多展示10条
接口名/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层接收参数和返回数据
商机转化龙虎榜列表查询
(1)TbBusinessMapper.xml新增SQL
<select id="countAllContractByUser" parameterType="com.huike.clues.domain.vo.IndexStatisticsVo" resultType="java.util.Map">
select c.create_by, count(c.id) as num ,d.`dept_name` as deptName from tb_contract c
LEFT JOIN `sys_dept` d
ON c.`dept_id` = d.`dept_id`
<if test="indexVo.beginCreateTime != null and indexVo.beginCreateTime != ''"><!-- 开始创建时间 -->
where c.`create_time` BETWEEN #{indexVo.beginCreateTime} AND #{indexVo.endCreateTime}
</if>
GROUP BY c.create_by
ORDER BY num DESC
LIMIT 10
</select>
(2)TbBusinessMapper新增方法定义
public List<Map<String,Object>> countAllContractByUser(@Param("indexVo")IndexStatisticsVo vo);
龙虎榜转换率计算
(1)IReportService新增方法定义
public List<Map<String,Object>> businessChangeStatisticsForIndex(IndexStatisticsVo request);
(2)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;
}
(3)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);
}